Skip to content

Instantly share code, notes, and snippets.

@itspriddle
Created June 2, 2011 19:11
Show Gist options
  • Save itspriddle/1005075 to your computer and use it in GitHub Desktop.
Save itspriddle/1005075 to your computer and use it in GitHub Desktop.
RSpec::Matchers.define :have_attr_accessor do |attribute|
match do |object|
object.respond_to?(attribute) && object.respond_to?("#{attribute}=")
end
description do
"have attr_writer :#{attribute}"
end
end
RSpec::Matchers.define :have_attr_reader do |attribute|
match do |object|
object.respond_to? attribute
end
description do
"have attr_reader :#{attribute}"
end
end
RSpec::Matchers.define :have_attr_writer do |attribute|
match do |object|
object.respond_to? "#{attribute}="
end
description do
"have attr_writer :#{attribute}"
end
end
@itspriddle
Copy link
Author

class Foo
  attr_accessor :bar
end

describe Foo do
  it { Foo.new.should have_attr_accessor :bar }
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment