I have a ReturnItem
class.
specs:
require \'spec_helper\'
describe ReturnItem do
#is this enough?
it { should respond_to :chosen }
i
I created a custom rspec matcher for this:
spec/custom/matchers/should_have_attr_accessor.rb
RSpec::Matchers.define :have_attr_accessor do |field|
match do |object_instance|
object_instance.respond_to?(field) &&
object_instance.respond_to?("#{field}=")
end
failure_message_for_should do |object_instance|
"expected attr_accessor for #{field} on #{object_instance}"
end
failure_message_for_should_not do |object_instance|
"expected attr_accessor for #{field} not to be defined on #{object_instance}"
end
description do
"checks to see if there is an attr accessor on the supplied object"
end
end
Then in my spec, I use it like so:
subject { described_class.new }
it { should have_attr_accessor(:foo) }