Class: Merb::Test::Rspec::RouteMatchers::ParameterMatcher
- Defined in:
- lib/merb-core/test/matchers/route_matchers.rb
Instance Attribute Summary collapse
-
#actual ⇒ Object
Returns the value of attribute actual.
-
#expected ⇒ Object
Returns the value of attribute expected.
Instance Method Summary collapse
-
#failure_message ⇒ Object
Returns String:: The failure message.
-
#initialize(hash_or_object) ⇒ ParameterMatcher
constructor
Parameters hash_or_object<Hash, ~to_param>:: The parameters to match.
-
#matches?(parameter_hash) ⇒ Boolean
Parameters parameter_hash<Hash>:: The route parameters to match.
-
#negative_failure_message ⇒ Object
Returns String:: The failure message to be displayed in negative matches.
Constructor Details
#initialize(hash_or_object) ⇒ ParameterMatcher
Parameters
- hash_or_object<Hash, ~to_param>
-
The parameters to match.
Alternatives
If hash_or_object is an object, then a new expected hash will be constructed with the key :id set to hash_or_object.to_param.
86 87 88 89 90 91 92 |
# File 'lib/merb-core/test/matchers/route_matchers.rb', line 86 def initialize(hash_or_object) @expected = {} case hash_or_object when Hash then @expected = hash_or_object else @expected[:id] = hash_or_object.to_param end end |
Instance Attribute Details
#actual ⇒ Object
Returns the value of attribute actual.
78 79 80 |
# File 'lib/merb-core/test/matchers/route_matchers.rb', line 78 def actual @actual end |
#expected ⇒ Object
Returns the value of attribute expected.
78 79 80 |
# File 'lib/merb-core/test/matchers/route_matchers.rb', line 78 def expected @expected end |
Instance Method Details
#failure_message ⇒ Object
Returns
- String
-
The failure message.
107 108 109 |
# File 'lib/merb-core/test/matchers/route_matchers.rb', line 107 def "expected the route to contain parameters #{@expected.inspect}, but instead contained #{@actual.inspect}" end |
#matches?(parameter_hash) ⇒ Boolean
Parameters
- parameter_hash<Hash>
-
The route parameters to match.
Returns
- Boolean
-
True if the route parameters match the expected ones.
99 100 101 102 103 |
# File 'lib/merb-core/test/matchers/route_matchers.rb', line 99 def matches?(parameter_hash) @actual = parameter_hash.dup.except(:controller, :action) @expected.all? {|(k, v)| @actual.has_key?(k) && @actual[k] == v} end |
#negative_failure_message ⇒ Object
Returns
- String
-
The failure message to be displayed in negative matches.
113 114 115 |
# File 'lib/merb-core/test/matchers/route_matchers.rb', line 113 def "expected the route not to contain parameters #{@expected.inspect}, but it did" end |