我得到的RSpec +水豚+吵闹鬼以下错误:水豚迫不及待Ajax请求
given!(:user_owner) { create(:user) }
given!(:second_user) { create(:user) }
given!(:question) { create(:question, user: user_owner) }
describe 'as not question owner' do
before do
login_as(second_user, scope: :user, run_callbacks: false)
visit question_path(question)
end
scenario 'can upvote just one time', js: true do
first('a#question-upvote').click
expect(first('div#question-score').text).to eq '1'
first('a#question-upvote').click
expect(first('div#question-score').text).to eq '1'
end
故障/错误:期待(page.first( '#DIV问题 - 得分')文本。)。为了EQ '-1'
expected: "-1"
got: "0"
当我插入睡眠1:
scenario 'can upvote just one time', js: true do
first('a#question-upvote').click
sleep 1
expect(first('div#question-score').text).to eq '1'
first('a#question-upvote').click
sleep 1
expect(first('div#question-score').text).to eq '1'
end
试验合格。
我明白了页面没有异步请求。 如何重写测试以使其在没有睡眠的情况下正常工作?
P.S.对不起英文。
谢谢Thomas。你再次帮助我。 –