Class: RSpec::Matchers::BuiltIn::BePredicate

Inherits:
BaseMatcher
  • Object
show all
Includes:
BeHelpers
Defined in:
lib/rspec/matchers/built_in/be.rb

Constant Summary

Constant Summary

Constants inherited from BaseMatcher

RSpec::Matchers::BuiltIn::BaseMatcher::UNDEFINED

Instance Attribute Summary

Attributes inherited from BaseMatcher

#actual, #expected, #rescued_exception

Instance Method Summary (collapse)

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, #to_word, #underscore

Constructor Details

- (BePredicate) initialize(*args)

A new instance of BePredicate

136
137
138
139
140
# File 'lib/rspec/matchers/built_in/be.rb', line 136
def initialize(*args, &block)
  @expected = parse_expected(args.shift)
  @args = args
  @block = block
end

Instance Method Details

- (Object) description

167
168
169
# File 'lib/rspec/matchers/built_in/be.rb', line 167
def description
  "#{prefix_to_sentence}#{expected_to_sentence}#{args_to_sentence}"
end

- (Object) failure_message_for_should

159
160
161
# File 'lib/rspec/matchers/built_in/be.rb', line 159
def failure_message_for_should
  "expected #{predicate}#{args_to_s} to return true, got #{@result.inspect}"
end

- (Object) failure_message_for_should_not

163
164
165
# File 'lib/rspec/matchers/built_in/be.rb', line 163
def failure_message_for_should_not
  "expected #{predicate}#{args_to_s} to return false, got #{@result.inspect}"
end

- (Boolean) matches?(actual) Also known as: ===

Returns:

  • (Boolean)
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/rspec/matchers/built_in/be.rb', line 142
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