我尝试在用户点击表单上的注册后测试确认页面。在开发中,当用户注册时,他们被重定向到确认页面,例如/entrants/(some number)/confirm
。但是,当我运行测试时,它并没有点击该页面。它只会点击/entrants
。我尝试使用visit
capybara语法但没有成功。
sign_in_steps.rb
Given(/^there is a entrant sign in page$/) do
@campaign = create(:campaign)
@entrant = create(:entrant, campaign: @campaign)
@entry = create(:entry, campaign: @campaign, entrant: @entrant)
end
Then(/^I should see confirmation login when I click the register button$/) do
within '#entrant_create' do
fill_in('entrant_first_name', with: @entrant.first_name)
fill_in('entrant_last_name', with: @entrant.last_name)
fill_in('entrant_email', with: @entrant.email)
fill_in('entrant_password', with: @entrant.password)
fill_in('entrant_password_confirmation', with: @entrant.password)
fill_in('entrant_dob', with: @entrant.dob)
end
click_button('REGISTER')
expect(current_path).to eq "/entrants/#{@entrant.id}/confirm"
end
运行黄瓜功能后
expected: "/entrants/1/confirm"
got: "/entrants"
entrant.rb
FactoryGirl.define do
factory :entrant do
first_name 'John'
last_name 'Smith'
email "test@msn.com"
dob Time.now - 60.years
password 'password'
end
end
参赛者
def confirm
@entrant = Entrant.find params[:id]
set_confirmation_message
end
def set_confirmation_message
if @entrant.entries.present?
@title = "Complete Your Contest Entry"
@message = 'Thank you for your entry! To complete submission, please check your email and click the confirmation link.'
else
@message = "To be allowed to enter this contest, please check your email and click the confirmation link."
end
end
答案 0 :(得分:0)
问题不在于点击后注册。这是因为当参赛者为数据库创建了一个电子邮件地址时,当水豚填写电子邮件时,它会看到它已被占用。所以我只需用另一个电子邮件地址手动填写它。
fill_in('entrant_email', with: 'test@example.com')