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.

Direct Known Subclasses

Be, BeAKindOf, BeAnInstanceOf, BeFalse, BeNil, BeTrue, Cover, Eq, Eql, Equal, Exist, Include, Match, MatchArray, StartAndEndWith, YieldControl, YieldWithNoArgs

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, #to_word, #underscore

Constructor Details

- (BaseMatcher) initialize(expected = nil)

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.

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

- (Object) actual (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

- (Object) expected (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

- (Object) rescued_exception (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

- (Object) ==(other)

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

- (Object) description

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

- (Boolean) diffable?

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

- (Object) failure_message_for_should

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

- (Object) failure_message_for_should_not

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

- (Object) match_unless_raises(*exceptions)

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

- (Boolean) matches?(actual)

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