-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Description
I would like to test my named routes, but they don't seem to be available in specs defined in the spec/routing directory (though they are available in specs defined in the spec/requests directory). Here's a quick demo:
$ rails new test_app; cd test_app
Then append the following to the generated Gemfile:
group :development, :test do
gem 'rspec', '>= 2.0.0.beta.19'
gem 'rspec-rails', '>= 2.0.0.beta.19'
end
Then:
$ bundle install
$ rails g rspec:install
$ rails g scaffold User name:string
Finally, add the following route to config/routes.rb:
match "/fancy-path" => "users#index", :as => 'fancy'
Then, the following spec in spec/requests/users_spec.rb works:
require 'spec_helper'
describe "Users" do
it "should recognize the fancy_path route" do
fancy_path.should == '/fancy-path'
end
end
But the following spec in spec/routing/users_routing_spec.rb does not work:
require 'spec_helper'
describe UsersController do
describe "routing" do
it "recognizes fancy_path" do
{ :get => fancy_path }.should route_to(:controller => "users", :action => "index")
end
end
end
I get the following error:
undefined local variable or method `fancy_path' for #<RSpec::Core::ExampleGroup::Nested_5::Nested_1:0x102c17c00>
Is RSpec not loading the named routes for routing specs, or am I missing something? Any help would be much appreciated.
Metadata
Metadata
Assignees
Labels
No labels