重定向 URL 不会显示页面 capybara factorygirl

Redirect URL not going to show page capybara factorygirl

我正在尝试测试用户在表单上单击注册后的确认页面。在开发中,当用户注册时,他们会被重定向到确认页面,例如 /entrants/(some number)/confirm。但是,当我 运行 测试时,它没有到达该页面。它只命中 /entrants。我尝试使用 visit 水豚语法但没有成功。

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

问题不在于点击后的寄存器。这是因为当参赛者创建一个电子邮件地址到数据库时,当水豚填写电子邮件时,它会看到它已经被占用了。所以我只是用另一个电子邮件地址手动填写它。

fill_in('entrant_email', with: 'test@example.com')