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.


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

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

Instance Method Details

#descriptionObject


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

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

#failure_message_for_shouldObject


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

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

#failure_message_for_should_notObject


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

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

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)

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

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