Class: Shoulda::Matchers::ActionController::AssignToMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/shoulda/matchers/action_controller/assign_to_matcher.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(variable) ⇒ AssignToMatcher

Returns a new instance of AssignToMatcher.



24
25
26
27
28
# File 'lib/shoulda/matchers/action_controller/assign_to_matcher.rb', line 24

def initialize(variable)
  @variable    = variable.to_s
  @options = {}
  @options[:check_value] = false
end

Instance Attribute Details

#failure_messageObject (readonly)

Returns the value of attribute failure_message.



22
23
24
# File 'lib/shoulda/matchers/action_controller/assign_to_matcher.rb', line 22

def failure_message
  @failure_message
end

#failure_message_when_negatedObject (readonly)

Returns the value of attribute failure_message_when_negated.



22
23
24
# File 'lib/shoulda/matchers/action_controller/assign_to_matcher.rb', line 22

def failure_message_when_negated
  @failure_message_when_negated
end

Instance Method Details

#descriptionObject



50
51
52
53
54
55
56
# File 'lib/shoulda/matchers/action_controller/assign_to_matcher.rb', line 50

def description
  description = "assign @#{@variable}"
  if @options.key?(:expected_class)
    description << " with a kind of #{@options[:expected_class]}"
  end
  description
end

#in_context(context) ⇒ Object



58
59
60
61
# File 'lib/shoulda/matchers/action_controller/assign_to_matcher.rb', line 58

def in_context(context)
  @context = context
  self
end

#matches?(controller) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
45
46
47
48
# File 'lib/shoulda/matchers/action_controller/assign_to_matcher.rb', line 42

def matches?(controller)
  @controller = controller
  normalize_expected_value!
  assigned_value? &&
    kind_of_expected_class? &&
    equal_to_expected_value?
end

#with(expected_value = nil, &block) ⇒ Object



35
36
37
38
39
40
# File 'lib/shoulda/matchers/action_controller/assign_to_matcher.rb', line 35

def with(expected_value = nil, &block)
  @options[:check_value] = true
  @options[:expected_value] = expected_value
  @options[:expectation_block] = block
  self
end

#with_kind_of(expected_class) ⇒ Object



30
31
32
33
# File 'lib/shoulda/matchers/action_controller/assign_to_matcher.rb', line 30

def with_kind_of(expected_class)
  @options[:expected_class] = expected_class
  self
end