Created
December 25, 2013 11:56
-
-
Save backpackerhh/8122601 to your computer and use it in GitHub Desktop.
Custom Rspec matcher for checking class or module for constant. Based on a David Chelimsky's answer on StackOverflow.
This file contains hidden or 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
# spec/support/matchers/have_constant.rb | |
RSpec::Matchers.define :have_constant do |constant| | |
match do |owner| | |
([Class, Module].include?(owner.class) ? owner : owner.class).const_defined?(constant) | |
end | |
failure_message_for_should do |klass| | |
"expected #{klass} to have constant #{constant}" | |
end | |
failure_message_for_should_not do |klass| | |
"expected #{klass} not to have constant #{constant}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment