Skip to content

Commit 3d89ab4

Browse files
committed
Routing specs can access named routes
- Closes #147.
1 parent a304c0a commit 3d89ab4

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Feature: access to named routes in routing specs
2+
3+
Scenario: access existing named route
4+
Given a file named "spec/routing/widget_routes_spec.rb" with:
5+
"""
6+
require "spec_helper"
7+
8+
describe "routes to the widgets controller" do
9+
it "routes a named route" do
10+
{:get => new_widget_path}.should route_to(:controller => "widgets", :action => "new")
11+
end
12+
end
13+
"""
14+
When I run "rspec spec"
15+
Then the output should contain "1 example, 0 failures"

lib/rspec/rails/example/routing_example_group.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ module RoutingExampleGroup
1212

1313
module InstanceMethods
1414
attr_reader :routes
15+
16+
def method_missing(m, *args, &block)
17+
routes.url_helpers.respond_to?(m) ? routes.url_helpers.send(m, *args) : super
18+
end
1519
end
1620

1721
included do

spec/rspec/rails/example/routing_example_group_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,22 @@ module RSpec::Rails
1111
end
1212
group.metadata[:type].should eq(:routing)
1313
end
14+
15+
describe "named routes" do
16+
it "delegates them to the route_set" do
17+
group = RSpec::Core::ExampleGroup.describe do
18+
include RoutingExampleGroup
19+
end
20+
21+
example = group.new
22+
23+
# Yes, this is quite invasive
24+
url_helpers = double('url_helpers', :foo_path => "foo")
25+
routes = double('routes', :url_helpers => url_helpers)
26+
example.stub(:routes => routes)
27+
28+
example.foo_path.should == "foo"
29+
end
30+
end
1431
end
1532
end

0 commit comments

Comments
 (0)