Class: ClassAction::RSpec::RespondWithMatcher
- Inherits:
-
Object
- Object
- ClassAction::RSpec::RespondWithMatcher
- Defined in:
- lib/class_action/rspec/respond_with_matcher.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(expected) ⇒ RespondWithMatcher
constructor
A new instance of RespondWithMatcher.
- #matches?(action) ⇒ Boolean
- #on(condition) ⇒ Object
Constructor Details
#initialize(expected) ⇒ RespondWithMatcher
Returns a new instance of RespondWithMatcher.
6 7 8 |
# File 'lib/class_action/rspec/respond_with_matcher.rb', line 6 def initialize(expected) @expected = expected.to_sym end |
Instance Method Details
#description ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/class_action/rspec/respond_with_matcher.rb', line 21 def description if @condition "respond with method :#{@expected} on :#{@condition}" else "respond with method :#{@expected}" end end |
#failure_message ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/class_action/rspec/respond_with_matcher.rb', line 29 def suffix = if @actual ", but it responds with :#{@actual}" else ", but it has no response method" end if @condition "expected action of class #{@action.class} to respond with :#{@expected} on :#{@condition}#{suffix}" else "expected action of class #{@action.class} to respond with :#{@expected}#{suffix}" end end |
#failure_message_when_negated ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/class_action/rspec/respond_with_matcher.rb', line 43 def if @condition "expected action of class #{@action.class} not to respond with :#{@expected} on :#{@condition}" else "expected action of class #{@action.class} not to respond with :#{@expected}" end end |
#matches?(action) ⇒ Boolean
15 16 17 18 19 |
# File 'lib/class_action/rspec/respond_with_matcher.rb', line 15 def matches?(action) @action = action @actual = action.class._responses[@condition].try(:to_sym) @actual == @expected end |
#on(condition) ⇒ Object
10 11 12 13 |
# File 'lib/class_action/rspec/respond_with_matcher.rb', line 10 def on(condition) @condition = condition self end |