Class: Shoulda::ActionController::Matchers::AssignToMatcher
- Inherits:
-
Object
- Object
- Shoulda::ActionController::Matchers::AssignToMatcher
- Defined in:
- lib/shoulda/action_controller/matchers/assign_to_matcher.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#failure_message ⇒ Object
readonly
Returns the value of attribute failure_message.
-
#negative_failure_message ⇒ Object
readonly
Returns the value of attribute negative_failure_message.
Instance Method Summary collapse
- #description ⇒ Object
- #in_context(context) ⇒ Object
-
#initialize(variable) ⇒ AssignToMatcher
constructor
A new instance of AssignToMatcher.
- #matches?(controller) ⇒ Boolean
- #with(expected_value = nil, &block) ⇒ Object
- #with_kind_of(expected_class) ⇒ Object
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_message ⇒ Object (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 end |
#negative_failure_message ⇒ Object (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 end |
Instance Method Details
#description ⇒ Object
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
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 |