Class: RSpec::Matchers::BuiltIn::BeComparedTo Private

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

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Provides the implementation of be <operator> value. Not intended to be instantiated directly.

Constant Summary

Constants inherited from BaseMatcher

RSpec::Matchers::BuiltIn::BaseMatcher::UNDEFINED

Instance Method Summary collapse

Methods inherited from BaseMatcher

#diffable?, #match_unless_raises, #supports_block_expectations?

Methods included from Composable

#===, #and, #description_of, enumerable?, #or, surface_descriptions_in, #values_match?

Methods included from Pretty

#name, split_words, #to_sentence, #to_word

Constructor Details

#initialize(operand, operator) ⇒ BeComparedTo

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of BeComparedTo.



139
140
141
142
# File 'lib/rspec/matchers/built_in/be.rb', line 139

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

Instance Method Details

#descriptionString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (String)


168
169
170
# File 'lib/rspec/matchers/built_in/be.rb', line 168

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

#failure_messageString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (String)


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

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

#failure_message_when_negatedString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (String)


157
158
159
160
161
162
163
164
# File 'lib/rspec/matchers/built_in/be.rb', line 157

def failure_message_when_negated
  message = "`expect(#{@actual.inspect}).not_to be #{@operator} #{@expected.inspect}`"
  if [:<, :>, :<=, :>=].include?(@operator)
    message + " not only FAILED, it is a bit confusing."
  else
    message
  end
end

#matches?(actual) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


144
145
146
147
# File 'lib/rspec/matchers/built_in/be.rb', line 144

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