Class: ProxyPacRb::RSpecMatchers::BaseMatcher Private

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

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

### 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

BeTheSameProxyPacFile

Defined Under Namespace

Modules: DefaultFailureMessages, HashFormatting

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 Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DefaultFailureMessages

#failure_message, #failure_message_when_negated, has_default_failure_messages?

Methods included from HashFormatting

improve_hash_formatting

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.



25
26
27
# File 'lib/proxy_pac_rb/rspec/matchers/base_matcher.rb', line 25

def initialize(expected = UNDEFINED)
  @expected = expected unless UNDEFINED.equal?(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.



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

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.



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

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.



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

def rescued_exception
  @rescued_exception
end

Class Method Details

.matcher_nameObject

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.



94
95
96
# File 'lib/proxy_pac_rb/rspec/matchers/base_matcher.rb', line 94

def self.matcher_name
  @matcher_name ||= underscore(name.split('::').last)
end

Instance Method Details

#actual_formattedObject

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.



89
90
91
# File 'lib/proxy_pac_rb/rspec/matchers/base_matcher.rb', line 89

def actual_formatted
  RSpec::Support::ObjectInspector.inspect(@actual)
end

#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 EnglishPhrasing.

Returns:

  • (String)


57
58
59
60
61
# File 'lib/proxy_pac_rb/rspec/matchers/base_matcher.rb', line 57

def description
  desc = self.class.matcher_name.to_s.tr('_', ' ')
  desc << Array(@expected).join(', ') if defined?(@expected) && @expected.is_a?(Array)
  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)


66
67
68
# File 'lib/proxy_pac_rb/rspec/matchers/base_matcher.rb', line 66

def diffable?
  false
end

#expected_formattedObject

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.



84
85
86
# File 'lib/proxy_pac_rb/rspec/matchers/base_matcher.rb', line 84

def expected_formatted
  RSpec::Support::ObjectInspector.inspect(@expected)
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)


79
80
81
# File 'lib/proxy_pac_rb/rspec/matchers/base_matcher.rb', line 79

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.



44
45
46
47
48
49
50
51
52
# File 'lib/proxy_pac_rb/rspec/matchers/base_matcher.rb', line 44

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)


33
34
35
36
# File 'lib/proxy_pac_rb/rspec/matchers/base_matcher.rb', line 33

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)


74
75
76
# File 'lib/proxy_pac_rb/rspec/matchers/base_matcher.rb', line 74

def supports_block_expectations?
  false
end