Sha256: 596a5429ac387f9356e5738db90f683e4487361c4638848a5f12f8454465ad82
Contents?: true
Size: 1.83 KB
Versions: 5
Compression:
Stored size: 1.83 KB
Contents
module ClassAction module RSpec class RespondToFormatMatcher def initialize(format) @format = format.to_sym end def on(condition) @condition = condition self end 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 def description if @condition "respond to format :#{@format} on :#{@condition}" else "respond to format :#{@format}" end end def failure_message_for_should 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 def failure_message_for_should_not 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 end end end RSpec::Matchers.module_eval do def respond_to_format(format) ClassAction::RSpec::RespondToFormatMatcher.new(format) end def respond_to_any_format ClassAction::RSpec::RespondToFormatMatcher.new(:any) end end
Version data entries
5 entries across 5 versions & 1 rubygems