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