这里是应用程序控制器文件(application _ controller. rb)中的 http 基本身份验证
before_filter :authenticate
protected
def authenticate
authenticate_or_request_with_http_basic do |username, password|
username == "username" && password == "password"
end
end
以及 home 控制器的 index 操作的默认测试(spec/controller/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: enticate”来运行它们,但是我想知道是否有办法使它们与该方法一起工作。
谢谢!