這裏我的HTTP應用程序控制器文件的基本身份驗證(application_controller.rb)軌道/ Rspec的製作測試通過使用HTTP基本身份驗證
before_filter :authenticate
protected
def authenticate
authenticate_or_request_with_http_basic do |username, password|
username == "username" && password == "password"
end
end
和我的家庭控制器的索引動作(規格默認的測試/ controllers/home_controller_spec.rb)
require 'spec_helper'
describe HomeController do
describe "GET 'index'" do
it "should be successful" do
get 'index'
response.should be_success
end
end
由於驗證方法,測試不會運行。我可以評論「before_filter:authenticate」來運行它們,但我想知道是否有辦法讓它們適用於該方法。
謝謝!
很好的例子,謝謝。 – 2011-12-05 08:42:04
它顯示請求是零爲我。任何想法如何得到解決方法? – chourobin 2012-04-05 20:01:54
對於請求規範,你可以有多個請求,所以'request'是'nil'。相反,您需要創建一個env散列'env = {}',並將其更新到您的http_login方法中,然後像'get'/',{},env'中那樣顯式傳遞env。 – 2012-10-24 04:21:46