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

Inherits:
Object
  • Object
show all
Defined in:
lib/shoulda/action_controller/matchers/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
# File 'lib/shoulda/action_controller/matchers/assign_to_matcher.rb', line 24

def initialize(variable)
  @variable = variable.to_s
end

Instance Attribute Details

#failure_messageObject (readonly)

Returns the value of attribute failure_message.



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

def failure_message
  @failure_message
end

#negative_failure_messageObject (readonly)

Returns the value of attribute negative_failure_message.



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

def negative_failure_message
  @negative_failure_message
end

Instance Method Details

#descriptionObject



47
48
49
50
51
# File 'lib/shoulda/action_controller/matchers/assign_to_matcher.rb', line 47

def description
  description = "assign @#{@variable}"
  description << " with a kind of #{@expected_class}" if @expected_class
  description
end

#in_context(context) ⇒ Object



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

def in_context(context)
  @context = context
  self
end

#matches?(controller) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
42
43
# File 'lib/shoulda/action_controller/matchers/assign_to_matcher.rb', line 39

def matches?(controller)
  @controller = controller
  @expected_value = @context.instance_eval(&@expectation_block) if @expectation_block
  assigned_value? && kind_of_expected_class? && equal_to_expected_value?
end

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



33
34
35
36
37
# File 'lib/shoulda/action_controller/matchers/assign_to_matcher.rb', line 33

def with(expected_value = nil, &block)
  @expected_value = expected_value
  @expectation_block = block
  self
end

#with_kind_of(expected_class) ⇒ Object



28
29
30
31
# File 'lib/shoulda/action_controller/matchers/assign_to_matcher.rb', line 28

def with_kind_of(expected_class)
  @expected_class = expected_class
  self
end