3
我有一个无法直接访问的控制器,而是以传统的RESTful方式直接访问,而只能通过特定的URL访问。测试无法直接访问的RSpec控制器动作
通常我习惯于在我的控制器规格中使用get和post来调用控制器动作。有没有一种方法可以通过访问特定的URL来锻炼我的控制器?
编辑:
这里是我的路线:
Larzworld::Application.routes.draw do
match '/auth/:provider/callback' => 'authentications#create'
devise_for :users, :controllers => {:registrations => "registrations"}
root :to => 'pages#home'
end
这里是我的规格:
require 'spec_helper'
describe AuthenticationsController do
before(:each) do
request.env["omniauth.auth"] = {"provider" => "twitter", "uid" => "12345678"}
end
describe 'POST create' do
it "should find the Authentication using the uid and provider from omniauth" do
Authentication.should_receive(:find_by_provider_and_uid)
post 'auth/twitter/callback'
end
end
end
和以下是错误我收到:
Failures:
1) AuthenticationsController POST create should find the Authentication using the uid and provider from omniauth
Failure/Error: post 'auth/twitter/callback'
No route matches {:action=>"auth/twitter/callback", :controller=>"authentications"}
# ./spec/controllers/authentications_controller_spec.rb:13
Finished in 0.04878 seconds
1 example, 1 failure
OK,那是我的想法,但看看我编辑的职位,我发布我的路线,我的测试和我的错误。我不明白为什么它没有将其映射到正确的行动。 – TheDelChop 2010-11-19 19:59:40
看我的编辑。我想,你真的想在这里进行路由测试。 – zetetic 2010-11-19 21:18:30