2013-03-04 69 views
2

我正在嘗試編寫RSpec請求規範以測試我的服務API,並且我需要用戶進行身份驗證。 我發現在網絡上的一些例子,但沒有什麼工作,爲我堅持這個時刻:RSpec,驗證請求規範中的設計用戶

require "spec_helper" 

include Warden::Test::Helpers 
Warden.test_mode! 

describe "My requests" do 

    it "creates an imaginary object" do 
    user = FactoryGirl.create(:user) 
    login_as(user, :scope => :user) 
    post "/my_service", :my_data=> {:some => "data"} 
    expect(response.body).to include("success") 
    end 

end 

而我得到的錯誤是:

ArgumentError: uncaught throw :warden 

謝謝您的幫助。

回答

4

實際上你需要在用戶登錄(即用戶需要提交登錄表單,或至少做你的登錄操作一個POST)按如下說明:Stubbing authentication in request spec

+0

這正是我想要像你所看到的那樣使用監獄長,無濟於事。 – 2013-03-05 09:35:05

+0

相關答案幫助我找出了一種可行的替代方法,所以非常感謝。 – 2013-03-05 09:54:08

+0

@AdnanDoric知道你發現了一個神奇的解決方案,讓我的問題解決自己。太棒了 – Benj 2015-09-01 09:13:29

相關問題