Last active
October 3, 2017 12:48
-
-
Save ahmadina/9ee44abbe79d07f5cb5ad057b0abf327 to your computer and use it in GitHub Desktop.
RSpec attr accessor check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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