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
27
# File 'lib/shoulda/action_controller/matchers/assign_to_matcher.rb', line 24

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

Instance Attribute Details

#failure_messageObject (readonly)

Returns the value of attribute failure_message.



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

def failure_message
  @failure_message
end

#negative_failure_messageObject (readonly)

Returns the value of attribute negative_failure_message.



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

def negative_failure_message
  @negative_failure_message
end

Instance Method Details

#descriptionObject



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

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

#in_context(context) ⇒ Object



55
56
57
58
# File 'lib/shoulda/action_controller/matchers/assign_to_matcher.rb', line 55

def in_context(context)
  @context = context
  self
end

#matches?(controller) ⇒ Boolean

Returns:

  • (Boolean)


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

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



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

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

#with_kind_of(expected_class) ⇒ Object



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

def with_kind_of(expected_class)
  @expected_class = expected_class
  self
end