[英]Feature Spec passes every time in RSpec, Fails in Jenkins
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: 哪些已加载到我的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. 我的功能页规范通过了我的计算机上的RSpec,但是我的雇主给我发送了一封电子邮件,说规范在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. 因此,当詹金斯(Jenkins)运行规范时,似乎没有从下拉列表中找到受让人,而RSpec却是。 I have never personally used Jenkins, so if anyone has any advice that may help, I'd appreciate hearing it. 我从来没有亲自使用过詹金斯(Jenkins),因此,如果有人对您有任何帮助的建议,我将不胜感激。 Thanks! 谢谢!
The problem is about the sequence number. 问题在于序列号。 You can't use hardcorded 'foo1@example.com'
in test. 您不能在测试中使用硬编码的'foo1@example.com'
。
There is no guarantee that the sequence number will start from 1. I have no time to figure out the reason, but just know the fact. 无法保证序列号将从1开始。我没有时间弄清楚原因,但只知道事实。 In my tests I often see it from tens after running several tests. 在我的测试中,运行几次测试后,我经常会从几十个角度看到它。
I would suggest you to get the email from an existing user in db, created by FactoryGirl. 我建议您从由FactoryGirl创建的db中现有用户那里获取电子邮件。
Although this was not your issue, one possible cause of getting different results between jenkins and test environments is using different DBs
on each. 尽管这不是您的问题,但是在詹金斯和测试环境之间获得不同结果的一个可能原因是在每个数据库上使用了different DBs
。
In my case I was using sqlite
on jenkins and postgres
on test, and that was generating different results. 以我为例,我在jenkins上使用sqlite
,在测试中使用postgres
,这产生了不同的结果。
Locally you can run 您可以在本地运行
RAILS_ENV="jenkins" bundle exec rspec
to run specs on jenkins environment. 在詹金斯环境上运行规格。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.