Class: RSpec::SleepingKingStudios::Matchers::BaseMatcher

Inherits:
Object
  • Object
show all
Includes:
Description
Defined in:
lib/rspec/sleeping_king_studios/matchers/base_matcher.rb

Overview

Minimal implementation of the RSpec matcher interface.

Since:

  • 1.0.0

Constant Summary

Constants included from Description

Description::DEFAULT_EXPECTED_ITEMS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Description

#description

Instance Attribute Details

#actualObject (readonly)

Since:

  • 1.0.0



15
16
17
# File 'lib/rspec/sleeping_king_studios/matchers/base_matcher.rb', line 15

def actual
  @actual
end

Instance Method Details

#does_not_match?(actual) ⇒ Boolean

Inverse of #matches? method.

Parameters:

  • actual (Object)

    the object to test against the matcher

Returns:

  • (Boolean)

    false if the object matches, otherwise true

See Also:

Since:

  • 1.0.0



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

def does_not_match? actual
  !matches?(actual)
end

#failure_messageObject

Message for when the object does not match, but was expected to. Make sure to always call #matches? first to set up the matcher state.

Since:

  • 1.0.0



42
43
44
# File 'lib/rspec/sleeping_king_studios/matchers/base_matcher.rb', line 42

def failure_message
  "expected #{@actual.inspect} to #{description}"
end

#failure_message_when_negatedObject

Message for when the object matches, but was expected not to. Make sure to always call #matches? first to set up the matcher state.

Since:

  • 1.0.0



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

def failure_message_when_negated
  "expected #{@actual.inspect} not to #{description}"
end

#matches?(actual) ⇒ Boolean

Tests the actual object to see if it matches the defined condition(s). Invoked by RSpec expectations.

Parameters:

  • actual (Object)

    the object to test against the matcher

Returns:

  • (Boolean)

    true if the object matches, otherwise false

Since:

  • 1.0.0



34
35
36
37
38
# File 'lib/rspec/sleeping_king_studios/matchers/base_matcher.rb', line 34

def matches? actual
  @actual = actual

  true
end