Class: RSpec::Matchers::BuiltIn::BePredicate
- Inherits:
-
Be
- Object
- BaseMatcher
- Be
- RSpec::Matchers::BuiltIn::BePredicate
- Defined in:
- lib/rspec/matchers/built_in/be.rb
Instance Attribute Summary
Attributes inherited from BaseMatcher
#actual, #expected, #rescued_exception
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message_for_should ⇒ Object
- #failure_message_for_should_not ⇒ Object
-
#initialize(*args, &block) ⇒ BePredicate
constructor
A new instance of BePredicate.
- #matches?(actual) ⇒ Boolean
Methods inherited from Be
Methods inherited from BaseMatcher
#==, #diffable?, #match_unless_raises
Methods included from Pretty
#_pretty_print, #expected_to_sentence, #name, #name_to_sentence, #split_words, #to_sentence, #underscore
Constructor Details
#initialize(*args, &block) ⇒ BePredicate
Returns a new instance of BePredicate.
126 127 128 129 130 |
# File 'lib/rspec/matchers/built_in/be.rb', line 126 def initialize(*args, &block) @expected = parse_expected(args.shift) @args = args @block = block end |
Instance Method Details
#description ⇒ Object
155 156 157 |
# File 'lib/rspec/matchers/built_in/be.rb', line 155 def description "#{prefix_to_sentence}#{expected_to_sentence}#{args_to_sentence}" end |
#failure_message_for_should ⇒ Object
147 148 149 |
# File 'lib/rspec/matchers/built_in/be.rb', line 147 def "expected #{predicate}#{args_to_s} to return true, got #{@result.inspect}" end |
#failure_message_for_should_not ⇒ Object
151 152 153 |
# File 'lib/rspec/matchers/built_in/be.rb', line 151 def "expected #{predicate}#{args_to_s} to return false, got #{@result.inspect}" end |
#matches?(actual) ⇒ Boolean
132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/rspec/matchers/built_in/be.rb', line 132 def matches?(actual) @actual = actual begin return @result = actual.__send__(predicate, *@args, &@block) rescue NameError => predicate_missing_error "this needs to be here or rcov will not count this branch even though it's executed in a code example" end begin return @result = actual.__send__(present_tense_predicate, *@args, &@block) rescue NameError raise predicate_missing_error end end |