Class: Shoulda::Matchers::ActionController::AssignToMatcher
- Inherits:
-
Object
- Object
- Shoulda::Matchers::ActionController::AssignToMatcher
- Defined in:
- lib/shoulda/matchers/action_controller/assign_to_matcher.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#failure_message ⇒ Object
readonly
Returns the value of attribute failure_message.
-
#failure_message_when_negated ⇒ Object
readonly
Returns the value of attribute failure_message_when_negated.
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 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_message ⇒ Object (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 end |
#failure_message_when_negated ⇒ Object (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 end |
Instance Method Details
#description ⇒ Object
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
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 |