2016-07-07 90 views
3

我只是試圖使用下面的代碼來測試通過Rspec Request規範中的Devise路徑更新用戶的電子郵件,我想知道爲什麼它給我的錯誤:ActionController::UnknownFormat:測試設計用Rspec更新用戶註冊信息並獲取:ActionController :: UnknownFormat:Error

require 'rails_helper' 

RSpec.describe "UsersEdits", type: :request do 
    let(:user) { FactoryGirl.create(:user) } 

    it "my test" do 
    email = "[email protected]" 

    params = { "user[email]" => email, "user[current_password]" => 'foobar' } 
    put user_registration_path(user), params 

    user.reload 
    expect(user.email).to eq(email) 
    end 
end 

這裏是錯誤:

Failure/Error: patch user_registration_path(user), params 

ActionController::UnknownFormat: 
    ActionController::UnknownFormat 

任何幫助將不勝感激,謝謝!

回答

1

剛剛完成跟蹤這個自己。

user_registration_path(user)將生成"/users.980190962"這導致ActionController::UnknownFormat錯誤。在某些控制器設置中,您可能會修補"https://stackoverflow.com/users/980790962",但直接設計修補程序"/users"。我猜想,無論登錄用戶是誰,也不需要用戶ID,就可以製作出設計/標準補丁。因此,而不是:

patch user_registration_path, params: { user: { 
     .... 
     } } 

或RSpec的:

put user_registration_path, params