Skip to content

Instantly share code, notes, and snippets.

@ahmadina
Last active October 3, 2017 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahmadina/9ee44abbe79d07f5cb5ad057b0abf327 to your computer and use it in GitHub Desktop.
Save ahmadina/9ee44abbe79d07f5cb5ad057b0abf327 to your computer and use it in GitHub Desktop.
RSpec attr accessor check
RSpec::Matchers.define :have_attr_accessor do |field|
match do |klass|
klass.respond_to?(field) && klass.respond_to?("#{field}=")
end
failure_message do |klass|
"expected attr_accessor for #{field} on #{klass}"
end
failure_message_when_negated do |klass|
"expected attr_accessor for #{field} not to
be defined on #{klass}"
end
description do
'checks to see if there is an attr accessor on the supplied object'
end
end
# NOTE: Store your matcher files in spec/custom/matchers/ and require them in spec/spec_helper.rb with the following line:
Dir[File.dirname(__FILE__) + "/custom/**/*.rb"].each {|f| require f}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment