2011-09-16 25 views
4

rspec2 & capybaraを使用してHTTP基本認証でレール3.1アプリにログインする方法をテストしますか?rails rspec http基本認証テスト

私はこれを使用しています。

describe "GET 'index'" do 
     it "should be successful" do 
     request.env["HTTP_AUTHORIZATION"] = "Basic " + Base64::encode64("username:password") 
     get 'index' 
     response.should be_success 
     end 
    end 

しかし、このエラーが表示されます。

NoMethodError: 
      undefined method `env' for nil:NilClass 
+0

がhttp://stackoverflow.com/questions/4329985/http-basic-auth-for-capybara – zetetic

答えて

-1
@request.env["HTTP_AUTHORIZATION"] = "Basic " + Base64::encode64("username:password") 

これがなければならない:requestとして

request.env["HTTP_AUTHORIZATION"] = "Basic " + Base64::encode64("username:password") 

は、インスタンス変数ではありません。

+0

を参照してください私は、全体のファイルを投稿してください –

+0

同じエラーを取得します。 – Gazler

+0

私はここのソリューションを使用しています。http://stackoverflow.com/questions/3768718/rails-rspec-make-tests-to-pass-with-http-basic-authentication –