Skip to content

Commit 12ce292

Browse files
committed
Exposes a method (similar to routing specs) to set the routes in controller specs
1 parent 7483b26 commit 12ce292

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

lib/rspec/rails/example/controller_example_group.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,22 @@ def self.name; "AnonymousController"; end
7676
@orig_routes = nil
7777
end
7878
end
79+
80+
# Specifies the routeset that will be used for the example group. This
81+
# is most useful when testing Rails engines.
82+
#
83+
# @example
84+
#
85+
# describe MyEngine::PostsController do
86+
# routes { MyEngine::Engine.routes }
87+
#
88+
# # ...
89+
# end
90+
def routes(&blk)
91+
before do
92+
self.routes = blk.call
93+
end
94+
end
7995
end
8096

8197
attr_reader :controller, :routes

0 commit comments

Comments
 (0)