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