Class: Spec::Rails::Example::RoutingHelpers::RouteFor

Inherits:
Object
  • Object
show all
Defined in:
lib/spec/rails/example/routing_helpers.rb

Instance Method Summary collapse

Constructor Details

#initialize(example, options) ⇒ RouteFor

Returns a new instance of RouteFor.



9
10
11
# File 'lib/spec/rails/example/routing_helpers.rb', line 9

def initialize(example, options)
  @example, @options = example, options
end

Instance Method Details

#==(expected) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/spec/rails/example/routing_helpers.rb', line 13

def ==(expected)
  if Hash === expected
    path, querystring = expected[:path].split('?')
    path_string = path
    path = expected.merge(:path => path)
  else
    path, querystring = expected.split('?')
    path_string = path
    path = { :path => path, :method => :get }
  end
  params = querystring.blank? ? {} : Rack::Utils.parse_query(querystring).symbolize_keys!
  begin
    @example.assert_routing(path, @options, {}, params)
    true
  rescue ActionController::RoutingError, ::Test::Unit::AssertionFailedError => e
    raise e.class, "#{e}\nIf you're expecting this failure, we suggest {:#{path[:method]}=>\"#{path[:path]}\"}.should_not be_routable"
  end
end