Class: RSpec::Matchers::BeComparedTo

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

Instance Method Summary collapse

Methods included from Pretty

#_pretty_print, #split_words, #to_sentence

Constructor Details

#initialize(operand, operator) ⇒ BeComparedTo

Returns a new instance of BeComparedTo.



89
90
91
92
# File 'lib/rspec/matchers/be.rb', line 89

def initialize(operand, operator)
  @expected, @operator = operand, operator
  @args = []
end

Instance Method Details

#descriptionObject



114
115
116
# File 'lib/rspec/matchers/be.rb', line 114

def description
  "be #{@operator} #{expected_to_sentence}#{args_to_sentence}"
end

#failure_message_for_shouldObject



99
100
101
# File 'lib/rspec/matchers/be.rb', line 99

def failure_message_for_should
  "expected: #{@operator} #{@expected.inspect}\n     got: #{@operator.to_s.gsub(/./, ' ')} #{@actual.inspect}"
end

#failure_message_for_should_notObject



103
104
105
106
107
108
109
110
111
112
# File 'lib/rspec/matchers/be.rb', line 103

def failure_message_for_should_not
  message = "'should_not be \#{@operator} \#{@expected}' 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

Returns:

  • (Boolean)


94
95
96
97
# File 'lib/rspec/matchers/be.rb', line 94

def matches?(actual)
  @actual = actual
  @actual.__send__(@operator, @expected)
end