Class: RSpec::SleepingKingStudios::Matchers::Core::HaveWriterMatcher
- Inherits:
-
BaseMatcher
- Object
- BaseMatcher
- RSpec::SleepingKingStudios::Matchers::Core::HaveWriterMatcher
- Includes:
- Shared::MatchProperty
- Defined in:
- lib/rspec/sleeping_king_studios/matchers/core/have_writer_matcher.rb
Overview
Matcher for testing whether an object has a specific property writer, e.g. responds to :property= and updates the state.
Constant Summary
Constants included from Description
Description::DEFAULT_EXPECTED_ITEMS
Instance Attribute Summary
Attributes inherited from BaseMatcher
Instance Method Summary collapse
-
#allow_private? ⇒ Boolean
True if the matcher matches private reader methods, otherwise false.
-
#description ⇒ String
Generates a description of the matcher expectation.
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(expected, allow_private: false) ⇒ HaveWriterMatcher
constructor
A new instance of HaveWriterMatcher.
-
#matches?(actual) ⇒ Boolean
Checks if the object responds to :expected=.
Methods inherited from BaseMatcher
Constructor Details
#initialize(expected, allow_private: false) ⇒ HaveWriterMatcher
Returns a new instance of HaveWriterMatcher.
17 18 19 20 |
# File 'lib/rspec/sleeping_king_studios/matchers/core/have_writer_matcher.rb', line 17 def initialize expected, allow_private: false @expected = expected.to_s.gsub(/=$/,'').intern @allow_private = allow_private end |
Instance Method Details
#allow_private? ⇒ Boolean
Returns True if the matcher matches private reader methods, otherwise false.
24 25 26 |
# File 'lib/rspec/sleeping_king_studios/matchers/core/have_writer_matcher.rb', line 24 def allow_private? !!@allow_private end |
#description ⇒ String
Generates a description of the matcher expectation.
31 32 33 |
# File 'lib/rspec/sleeping_king_studios/matchers/core/have_writer_matcher.rb', line 31 def description "have writer :#{@expected}" end |
#failure_message ⇒ Object
51 52 53 54 |
# File 'lib/rspec/sleeping_king_studios/matchers/core/have_writer_matcher.rb', line 51 def "expected #{@actual.inspect} to respond to :#{@expected}="\ ", but did not respond to :#{@expected}=" end |
#failure_message_when_negated ⇒ Object
57 58 59 60 |
# File 'lib/rspec/sleeping_king_studios/matchers/core/have_writer_matcher.rb', line 57 def "expected #{@actual.inspect} not to respond to :#{@expected}="\ ", but responded to :#{@expected}=" end |
#matches?(actual) ⇒ Boolean
Checks if the object responds to :expected=. Additionally, if a value expectation is set, assigns the value via :expected= and compares the subsequent value to the specified value using :expected or the block provided to #with.
44 45 46 47 48 |
# File 'lib/rspec/sleeping_king_studios/matchers/core/have_writer_matcher.rb', line 44 def matches? actual super responds_to_writer?(:allow_private => allow_private?) end |