Class: ClassAction::RSpec::RespondToFormatMatcher
- Inherits:
-
Object
- Object
- ClassAction::RSpec::RespondToFormatMatcher
- Defined in:
- lib/class_action/rspec/respond_to_format_matcher.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message_for_should ⇒ Object
- #failure_message_for_should_not ⇒ Object
-
#initialize(format) ⇒ RespondToFormatMatcher
constructor
A new instance of RespondToFormatMatcher.
- #matches?(action, &block) ⇒ Boolean
- #on(condition) ⇒ Object
Constructor Details
#initialize(format) ⇒ RespondToFormatMatcher
Returns a new instance of RespondToFormatMatcher.
6 7 8 |
# File 'lib/class_action/rspec/respond_to_format_matcher.rb', line 6 def initialize(format) @format = format.to_sym end |
Instance Method Details
#description ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/class_action/rspec/respond_to_format_matcher.rb', line 36 def description if @condition "respond to format :#{@format} on :#{@condition}" else "respond to format :#{@format}" end end |
#failure_message_for_should ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/class_action/rspec/respond_to_format_matcher.rb', line 44 def if @condition "expected action of class #{@action.class} to respond to format :#{@format} on :#{@condition}" else "expected action of class #{@action.class} to respond to format :#{@format}" end end |
#failure_message_for_should_not ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/class_action/rspec/respond_to_format_matcher.rb', line 52 def if @condition "expected action of class #{@action.class} not to respond to format :#{@format} on :#{@condition}" else "expected action of class #{@action.class} not to respond to format :#{@format}" end end |
#matches?(action, &block) ⇒ Boolean
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/class_action/rspec/respond_to_format_matcher.rb', line 15 def matches?(action, &block) @action = action if action.class._responders.key?([@format, @condition]) if block # Response defined, we return true but we need to also execute the block, # as it might contain additional checks. First run the action's response # block, for this. respond_block = action.class._responders[ [@format, @condition] ] action.instance_exec &respond_block if respond_block action.send :copy_assigns_to_controller block.call end true else false end end |
#on(condition) ⇒ Object
10 11 12 13 |
# File 'lib/class_action/rspec/respond_to_format_matcher.rb', line 10 def on(condition) @condition = condition self end |