Class: RSpec::Matchers::BuiltIn::BaseMatcher Private

Inherits:
Object
  • Object
show all
Includes:
Pretty
Defined in:
lib/rspec/matchers/built_in/base_matcher.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.

Used internally as a base class for matchers that ship with rspec-expectations.

Warning:

This class is for internal use, and subject to change without notice. We strongly recommend that you do not base your custom matchers on this class. If/when this changes, we will announce it and remove this warning.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Pretty

#_pretty_print, #expected_to_sentence, #name, #name_to_sentence, #split_words, #to_sentence, #underscore

Constructor Details

#initialize(expected = nil) ⇒ BaseMatcher

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 BaseMatcher.



19
20
21
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 19

def initialize(expected = nil)
  @expected = expected
end

Instance Attribute Details

#actualObject (readonly)

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.



17
18
19
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 17

def actual
  @actual
end

#expectedObject (readonly)

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.



17
18
19
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 17

def expected
  @expected
end

#rescued_exceptionObject (readonly)

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.



17
18
19
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 17

def rescued_exception
  @rescued_exception
end

Instance Method Details

#==(other) ⇒ Object

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.



56
57
58
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 56

def ==(other)
  matches?(other)
end

#descriptionObject

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.



48
49
50
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 48

def description
  expected ? "#{name_to_sentence} #{@expected.inspect}" : name_to_sentence
end

#diffable?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)


52
53
54
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 52

def diffable?
  false
end

#failure_message_for_shouldObject

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.



38
39
40
41
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 38

def failure_message_for_should
  assert_ivars :@actual, :@expected
  "expected #{@actual.inspect} to #{name_to_sentence}#{expected_to_sentence}"
end

#failure_message_for_should_notObject

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.



43
44
45
46
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 43

def failure_message_for_should_not
  assert_ivars :@actual, :@expected
  "expected #{@actual.inspect} not to #{name_to_sentence}#{expected_to_sentence}"
end

#match_unless_raises(*exceptions) ⇒ Object

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.



28
29
30
31
32
33
34
35
36
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 28

def match_unless_raises(*exceptions)
  exceptions.unshift Exception if exceptions.empty?
  begin
    yield
    true
  rescue *exceptions => @rescued_exception
    false
  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)


23
24
25
26
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 23

def matches?(actual)
  @actual = actual
  match(expected, actual)
end