Class: RSpec::Rails::Matchers::BaseMatcher Private

Inherits:
Object
  • Object
show all
Includes:
Matchers::Composable, DefaultFailureMessages
Defined in:
lib/rspec/rails/matchers/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.

Base class to build matchers. Should not be instantiated directly.

Defined Under Namespace

Modules: DefaultFailureMessages

Constant Summary collapse

UNDEFINED =

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

Used to detect when no arg is passed to initialize. nil cannot be used because it's a valid value to pass.

Object.new.freeze

Instance Method Summary collapse

Methods included from DefaultFailureMessages

#failure_message, #failure_message_when_negated

Constructor Details

#initialize(expected = UNDEFINED) ⇒ 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.

21
22
23
# File 'lib/rspec/rails/matchers/base_matcher.rb', line 21
def initialize(expected = UNDEFINED)
  @expected = expected unless UNDEFINED.equal?(expected)
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.

Generates a description using Matchers::EnglishPhrasing.

Returns:

  • (String)
53
54
55
56
57
# File 'lib/rspec/rails/matchers/base_matcher.rb', line 53
def description
  desc = RSpec::Matchers::EnglishPhrasing.split_words(self.class.matcher_name)
  desc << RSpec::Matchers::EnglishPhrasing.list(@expected) if defined?(@expected)
  desc
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.

Matchers are not diffable by default. Override this to make your subclass diffable.

Returns:

  • (Boolean)
62
63
64
# File 'lib/rspec/rails/matchers/base_matcher.rb', line 62
def diffable?
  false
end

#expects_call_stack_jump?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)
75
76
77
# File 'lib/rspec/rails/matchers/base_matcher.rb', line 75
def expects_call_stack_jump?
  false
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.

Used to wrap a block of code that will indicate failure by raising one of the named exceptions.

This is used by rspec-rails for some of its matchers that wrap rails' assertions.

40
41
42
43
44
45
46
47
48
# File 'lib/rspec/rails/matchers/base_matcher.rb', line 40
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.

Indicates if the match is successful. Delegates to match, which should be defined on a subclass. Takes care of consistently initializing the actual attribute.

Returns:

  • (Boolean)
29
30
31
32
# File 'lib/rspec/rails/matchers/base_matcher.rb', line 29
def matches?(actual)
  @actual = actual
  match(expected, actual)
end

#supports_block_expectations?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.

Most matchers are value matchers (i.e. meant to work with expect(value)) rather than block matchers (i.e. meant to work with expect { }), so this defaults to false. Block matchers must override this to return true.

Returns:

  • (Boolean)
70
71
72
# File 'lib/rspec/rails/matchers/base_matcher.rb', line 70
def supports_block_expectations?
  false
end