class Shoulda::Matchers::ActionController::AssignToMatcher
:nodoc:
def assigned_value
def assigned_value @controller.instance_variable_get("@#{@variable}") end
def assigned_value?
def assigned_value? if @controller.instance_variables.map(&:to_s).include?("@#{@variable}") @failure_message_for_should_not = "Didn't expect action to assign a value for @#{@variable}, " << "but it was assigned to #{assigned_value.inspect}" true else @failure_message_for_should = "Expected action to assign a value for @#{@variable}" false end end
def description
def description description = "assign @#{@variable}" if @options.key?(:expected_class) description << " with a kind of #{@options[:expected_class]}" end description end
def equal_to_expected_value?
def equal_to_expected_value? if @options[:check_value] if @options[:expected_value] == assigned_value @failure_message_for_should_not = "Didn't expect action to assign #{@options[:expected_value].inspect} " << "for #{@variable}, but got it anyway" true else @failure_message_for_should = "Expected action to assign #{@options[:expected_value].inspect} " << "for #{@variable}, but got #{assigned_value.inspect}" false end else true end end
def in_context(context)
def in_context(context) @context = context self end
def initialize(variable)
def initialize(variable) ActiveSupport::Deprecation.warn 'The assign_to matcher is deprecated and will be removed in 2.0' @variable = variable.to_s @options = {} @options[:check_value] = false end
def kind_of_expected_class?
def kind_of_expected_class? if @options.key?(:expected_class) if assigned_value.kind_of?(@options[:expected_class]) @failure_message_for_should_not = "Didn't expect action to assign a kind of #{@options[:expected_class]} " << "for #{@variable}, but got one anyway" true else @failure_message_for_should = "Expected action to assign a kind of #{@options[:expected_class]} " << "for #{@variable}, but got #{assigned_value.inspect} " << "(#{assigned_value.class.name})" false end else true end end
def matches?(controller)
def matches?(controller) @controller = controller normalize_expected_value! assigned_value? && kind_of_expected_class? && equal_to_expected_value? end
def normalize_expected_value!
def normalize_expected_value! if @options[:expectation_block] @options[:expected_value] = @context.instance_eval(&@options[:expectation_block]) end end
def with(expected_value = nil, &block)
def with(expected_value = nil, &block) @options[:check_value] = true @options[:expected_value] = expected_value @options[:expectation_block] = block self end
def with_kind_of(expected_class)
def with_kind_of(expected_class) @options[:expected_class] = expected_class self end