I’m migrating an app to Rails 3 + RSpec 2 and, as expected, a number of
specs broke. Unfortunately, I can’t really find how to fix them. For
instance, there is a spec:
describe SessionsController do
describe “route recognition” do
it “should generate params from GET /login correctly” do
params_from(:get, ‘/login’).should ==
{:controller => ‘sessions’, :action => ‘new’}
end
end
This spec is located in Rails.root +
/spec/controllers/sessions_controller_spec.rb
The error is:
SessionsController route recognition should generate params from POST
/session correctly
Failure/Error: params_from(:post, ‘/session’).should == {:controller
=> ‘sessions’, :action => ‘create’}
undefined method params_from' for #<RSpec::Core::ExampleGroup::Nested_15::Nested_2:0x458d348> # ./vendor/gems/actionpack-3.0.0.beta4/lib/action_dispatch/testing/assertions/routing.rb:175:inmethod_missing’
# ./spec/controllers/sessions_controller_spec.rb:121
Also note the ‘RSpec::Core::ExampleGroup’: it seems like it doesn’t
correctly infer it should be RSpec::Rails::ControllerExampleGroup?
This was introduced in 1.2.9, but, unfortunately, I never deprecated the
way you’re doing it now. I’ll do so in a 1.3.3 release, but that won’t
be for a little bit, and I don’t plan to forward port it to 2.x.
This spec is located in Rails.root +
/spec/controllers/sessions_controller_spec.rb
As of 2.0.0.beta.13, the route_to and be_routable matchers are only
exposed to routing specs (in spec/routing). I’ve added a github issue to
add them to controller specs as well. In the mean time, if you want to
use them in your controller specs, just do this in spec_helper.rb
RSpec.configure do |c|
c.include RSpec::Rails::RoutingSpecMatchers, :example_group => {
:file_path => /\bspec/controllers// }
end
Note that the name RSpec::Rails::RoutingSpecMatchers might change in the
next beta, so this is not a formal API or anything - just a workaround
for you to get by until the next release.
Thanks, that works fine and makes sense. Now there are also a few specs
that assert the inverse direction:
describe SessionsController do
describe “route generation” do
it “should route the destroy sessions action correctly” do
route_for(:controller => ‘sessions’, :action => ‘destroy’).should
== “/logout”
end
end
end
I understand the route_for method is similarly deprecated; what would be
the idiomatic way to spec that now?
Note that the name RSpec::Rails::RoutingSpecMatchers might change in the
next beta, so this is not a formal API or anything - just a workaround
for you to get by until the next release.
OK, thanks for the warning. As we consciously chose to move to -beta
software, these kinds of things are expected :).