开发者

Rspec integration test: Routes not available

I was trying to write an integration test testing, if my controller raises a ActiveRecord::RecordNotFound exeption for deleted articles (which are just marked as deleted):

it "should return 404 for deleted articles" do
  @article = Factory :article, :status => "deleted"
  expect { get edit_article_path(:id => @article.id) }.to raise_error(ActiveRecord::RecordNotFound)
end

These kind of tests work fine in a controller spec, but inside of the spec/requests I get this error:

expected ActiveRecord::RecordNotFound, got #<ActionController::RoutingError: No route matches {:action=>"edit", :controller=>"articles", :id=>595}>

So it looks up my routes correctly (since it knows the controller etc.) but still raises the error. Why is that?

Thank开发者_Go百科s, Johannes


If this test is in your spec/controllers directory, then the get method you're calling isn't expecting a path, it's expecting a symbol for the controller action you want to call. So you'd need to change the expect line to something like:

expect { get :edit, :id => @article.id }.to raise_error(ActiveRecord::RecordNotFound)

Take a look at the RSpec Controller Spec documentation for more info.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜