Class: Merb::Test::Rspec::RouteMatchers::ParameterMatcher

Inherits:
Object
  • Object
show all
Defined in:
merb-core/lib/merb-core/test/matchers/route_matchers.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

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.

Parameters:

  • hash_or_object (Hash, #to_param)

    The parameters to match.



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

Returns The failure message.

Returns:

  • (String)

    The failure message.



97
98
99
# File 'merb-core/lib/merb-core/test/matchers/route_matchers.rb', line 97

def failure_message
  "expected the route to contain parameters #{@expected.inspect}, but instead contained #{@actual.inspect}"
end

- (Boolean) matches?(parameter_hash)

Returns True if the route parameters match the expected ones.

Parameters:

  • parameter_hash (Hash)

    The route parameters to match.

Returns:

  • (Boolean)

    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

Returns The failure message to be displayed in negative matches.

Returns:

  • (String)

    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 negative_failure_message
  "expected the route not to contain parameters #{@expected.inspect}, but it did"
end