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

Inherits:
Be show all
Defined in:
lib/rspec/matchers/built_in/be.rb

Instance Attribute Summary

Attributes inherited from BaseMatcher

#actual, #expected, #rescued_exception

Instance Method Summary collapse

Methods inherited from Be

#match

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

#descriptionObject



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_shouldObject



147
148
149
# File 'lib/rspec/matchers/built_in/be.rb', line 147

def failure_message_for_should
  "expected #{predicate}#{args_to_s} to return true, got #{@result.inspect}"
end

#failure_message_for_should_notObject



151
152
153
# File 'lib/rspec/matchers/built_in/be.rb', line 151

def failure_message_for_should_not
  "expected #{predicate}#{args_to_s} to return false, got #{@result.inspect}"
end

#matches?(actual) ⇒ Boolean

Returns:

  • (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