0

I have a users factory:

FactoryGirl.define do
  factory :user, :aliases => [:assignee] do
    sequence(:email) { |n| "foo#{n}@example.com" }
    sequence(:username) { |n| "foo#{n}@example.com" }
    profile

  end
end

And a jobs factory:

FactoryGirl.define do
  factory :job do
    association :assignee, factory: :user
    description "MyText"
    completion_comment "MyText"
    job_type "MyString"
    ...
  end
end

Which are loaded into my jobs_feature_spec_helper:

def add_valid_job
  click_job
  within("#add_job") do
    select 'foo1@example.com', from: 'Assignee'
    fill_in_html("job__textarea", {:with => job[:description]})
    click_button "Save"
  end
end

My feature page spec passes in RSpec on my machine, but my employer sent me an email saying that the spec failed in Jenkins. Here's the message he sent:

Unable to find option "foo1@example.com <mailto:foo1@example.com>"
./spec/support/job_feature_spec_helpers.rb:11:in `block in add_valid_job'
./spec/support/job_feature_spec_helpers.rb:10:in `add_valid_job'
./spec/features/jobs/edit_job_line_spec.rb:8:in `block (2 levels) in <top (required)>' 

So, it appears that when Jenkins runs the spec, it's not finding the assignee from the drop-down list, yet RSpec is. I have never personally used Jenkins, so if anyone has any advice that may help, I'd appreciate hearing it. Thanks!

4

2 回答 2

3

问题在于序列号。您不能'foo1@example.com'在测试中使用硬编码。

不能保证序列号会从1开始。我没有时间去弄清楚原因,只是知道事实。在我的测试中,我经常在运行几次测试后从几十处看到它。

我建议您从 db 中由 FactoryGirl 创建的现有用户那里获取电子邮件。

于 2013-04-21T13:20:51.597 回答
1

尽管这不是您的问题,但在 jenkins 和测试环境之间获得不同结果的一个可能原因是different DBs在每个环境中使用。

就我而言,我sqlite在詹金斯和postgres测试中使用,这产生了不同的结果。

在本地你可以运行

RAILS_ENV="jenkins" bundle exec rspec

在 jenkins 环境中运行规范。

于 2013-11-05T17:25:11.013 回答