Rspec-rails-capybara js:true导致Mailers延迟导致测试失败

时间:2015-05-26 10:59:46

标签: ruby rspec capybara

describe 'salary acceptance email' do
  let!(:effective_date)  { Date.current.next_week }
  let(:salary) { FactoryGirl.create(:salary) } 

  it 'displays admin selected effective_date', js: true do

    page.visit approval_path(salary)
    page.uncheck('default_effective_date')
    select effective_date.year.to_s, from: 'offer_effective_date_date_1i'
    select I18n.t("date.month_names")[effective_date.month] , from: 'offer_effective_date_date_2i'
    select effective_date.day.to_s, from: 'offer_effective_date_date_3i'
    click_on 'Accept'
    #binding.pry or wait_for_ajax - hack to let the test pass

    expect(mail.body).to include_in_each_part(salary.amount)
    expect(mail.body).to include_in_each_part(effective_date.strftime('%Y-%m-%d'))
  end
end

除了有一个隐藏/显示effective_date date_select标记的javascript之外,这部分代码中没有任何ajax请求。 当我将js:true添加到spec邮件[=>的ActionMailer :: Base.deliveries .last]返回nil,但是如果测试被允许等待一两秒钟就可以了。如何在没有HACK的情况下解决这个问题! :(

Capybara版本:Capybara(1.1.3)
Webkit版本:capybara-webkit(0.13.0)

1 个答案:

答案 0 :(得分:0)

我能够通过添加对该页面上某些内容的检查来实现此功能,该内容在单击“接受”后发生更改

describe 'salary acceptance email' do
 let!(:effective_date)  { Date.current.next_week }
 let(:salary) { FactoryGirl.create(:salary) } 

 it 'displays admin selected effective_date', js: true do

  page.visit approval_path(salary)
  page.uncheck('default_effective_date')
  select effective_date.year.to_s, from: 'offer_effective_date_date_1i'
  select I18n.t("date.month_names")[effective_date.month] , from: 'offer_effective_date_date_2i'
  select effective_date.day.to_s, from: 'offer_effective_date_date_3i'
  click_on 'Accept'

  expect(page).to have_content("Acceptance Completed Successfully")
  expect(mail.body).to include_in_each_part(salary.amount)
  expect(mail.body).to include_in_each_part(effective_date.strftime('%Y-%m-%d'))
 end
end

所有对水豚队的信用:明星:。查看https://groups.google.com/forum/#!topic/ruby-capybara/EpbORzw7rq8

中的更多详情
相关问题