Class: RSpec::Matchers::BuiltIn::BeComparedTo
- 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, #to_word, #underscore
Constructor Details
- (BeComparedTo) initialize(operand, operator)
A new instance of BeComparedTo
95
96
97
98
|
# File 'lib/rspec/matchers/built_in/be.rb', line 95
def initialize(operand, operator)
@expected, @operator = operand, operator
@args = []
end
|
Instance Method Details
- (Object) description
120
121
122
|
# File 'lib/rspec/matchers/built_in/be.rb', line 120
def description
"be #{@operator} #{expected_to_sentence}#{args_to_sentence}"
end
|
- (Object) failure_message_for_should
105
106
107
|
# File 'lib/rspec/matchers/built_in/be.rb', line 105
def failure_message_for_should
"expected: #{@operator} #{@expected.inspect}\n got: #{@operator.to_s.gsub(/./, ' ')} #{@actual.inspect}"
end
|
- (Object) failure_message_for_should_not
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/rspec/matchers/built_in/be.rb', line 109
def failure_message_for_should_not
message = <<-MESSAGE
`#{negative_expectation_expression}` not only FAILED,
it is a bit confusing.
MESSAGE
raise message << ([:===,:==].include?(@operator) ?
"It might be more clearly expressed without the \"be\"?" :
"It might be more clearly expressed in the positive?")
end
|
- (Boolean) matches?(actual)
100
101
102
103
|
# File 'lib/rspec/matchers/built_in/be.rb', line 100
def matches?(actual)
@actual = actual
@actual.__send__ @operator, @expected
end
|
- (Object) negative_expectation_expression
124
125
126
|
# File 'lib/rspec/matchers/built_in/be.rb', line 124
def negative_expectation_expression
Expectations::Syntax.negative_expression("actual", "be #{@operator} #{@expected}")
end
|