Class: Merb::Test::Rspec::RouteMatchers::ParameterMatcher
- Inherits:
-
Object
- Object
- Merb::Test::Rspec::RouteMatchers::ParameterMatcher
- Defined in:
- merb-core/lib/merb-core/test/matchers/route_matchers.rb
Instance Attribute Summary (collapse)
-
- (Object) actual
Returns the value of attribute actual.
-
- (Object) expected
Returns the value of attribute expected.
Instance Method Summary (collapse)
-
- (String) failure_message
The failure message.
-
- (ParameterMatcher) initialize(hash_or_object)
constructor
A new instance of
ParameterMatcher. -
- (Boolean) matches?(parameter_hash)
True if the route parameters match the expected ones.
-
- (String) negative_failure_message
The failure message to be displayed in negative matches.
Constructor Details
- (ParameterMatcher) initialize(hash_or_object)
A new instance of ParameterMatcher
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.
78 79 80 81 82 83 84 |
# File 'merb-core/lib/merb-core/test/matchers/route_matchers.rb', line 78 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
- (Object) actual
Returns the value of attribute actual
69 70 71 |
# File 'merb-core/lib/merb-core/test/matchers/route_matchers.rb', line 69 def actual @actual end |
- (Object) expected
Returns the value of attribute expected
69 70 71 |
# File 'merb-core/lib/merb-core/test/matchers/route_matchers.rb', line 69 def expected @expected end |
Instance Method Details
- (String) failure_message
The failure message.
97 98 99 |
# File 'merb-core/lib/merb-core/test/matchers/route_matchers.rb', line 97 def "expected the route to contain parameters #{@expected.inspect}, but instead contained #{@actual.inspect}" end |
- (Boolean) matches?(parameter_hash)
True if the route parameters match the expected ones.
89 90 91 92 93 94 |
# File 'merb-core/lib/merb-core/test/matchers/route_matchers.rb', line 89 def matches?(parameter_hash) @actual = parameter_hash.dup.except(:controller, :action) return @actual.empty? if @expected.empty? @expected.all? {|(k, v)| @actual.has_key?(k) && @actual[k] == v} end |
- (String) negative_failure_message
The failure message to be displayed in negative matches.
102 103 104 |
# File 'merb-core/lib/merb-core/test/matchers/route_matchers.rb', line 102 def "expected the route not to contain parameters #{@expected.inspect}, but it did" end |