1
我決定寫一些請求規格,除了我的黃瓜方案。但是失敗了我的第一個例子:Rails請求規範不提出請求
所以在我goalsController這個put方法:
def achieve
@goal.update_attribute(:achieved, true)
redirect_to :back
end
這是例子:
# -*- coding: utf-8 -*-
require 'spec_helper'
describe "Achievements" do
before(:all) do
@bob = Factory(:user, :email => "[email protected]", :password => "qweqwe", :password_confirmation => "qweqwe", :money => 500)
@achieve = Factory(:goal, :user => @bob, :title => "Notebook", :price => 100, :achieved => false)
login_user('[email protected]', 'qweqwe')
end
it 'can not be achieved twice' do
visit dashboard_path
put achieve_user_goal_path(@bob, @achieve) #Passes it well
@achieve.reload #same with or without this line
@achieve.achieved.should equal true #Fails
end
end
所以之後「實現」把請求字段爲真。它在我的應用程序中完美工作,並在黃瓜步驟中完成,但不在此rspec示例中。這就像rspec只是忽略了'put'一致。
我想測試一切工作正常,如果用戶試圖再次請求這一點。例如,如果他打開兩個相同的頁面,並嘗試點擊兩者上的「實現」。 –
我沒有從你的問題得到這個;就我所知,測試競態條件並不是很容易,但如果您不需要同時執行這些請求,只需點擊路徑並單擊按鈕兩次。 – d11wtq
在下一次訪問此路徑時不會出現此按鈕,因爲目標已實現。但是,如果較早的用戶打開另一個頁面,則它將具有此按鈕,並且用戶將能夠再次點擊它。我的代碼已經安全的這種行爲(我插入不是所有的代碼#achieve行動),我只是想要測試與請求規格:) –