我正在填写开源Rails项目的规范,需要在浏览器中运行应用程序以获取我的一些功能规范。我想在Travis CI上使用Sauce Labs,但没有不得不重写我的规范以在本地使用Sauce Labs,因为:
我找不到详细说明此方案的文档。实现这一目标的最佳方式是什么?
答案 0 :(得分:4)
对于那些有类似需求的人来说,这就是我最终要做的事情:
<强> .travis.yml 强>:
env:
global:
- secure: "encrypted sauce username"
- secure: "encrypted sauce secret key"
addons:
sauce_connect: true
before_install:
# install the ed text editor which we use to append
# file contents to a specific line of another file
- sudo apt-get install -y ed
# appends contents of travis/Gemfile.travis to Gemfile
- cat travis/Gemfile.travis >> Gemfile
# adds contents of travis/rails_helper.rb.travis to line 12 of spec/rails_helper.rb
- ed -s spec/rails_helper.rb <<< '12r travis/rails_helper.rb.travis'$'\nw'
<强>特拉维斯/ Gemfile.travis 强>:
group :test, :development do
gem 'sauce', '~> 3.1.1'
gem 'sauce-connect'
gem 'parallel_tests'
end
<强>特拉维斯/ rails_helper.rb.travis 强>:
require 'sauce'
require 'sauce/capybara'
# change to "Capybara.default_driver = :sauce" to use sauce
# for ALL feature specs, not just ones marked with "js: true"
Capybara.javascript_driver = :sauce
Sauce.config do |config|
config[:browsers] = [
['Linux', 'Chrome', nil],
# and other OS/browser combos you want to support...
]
end
我最终在最终解决方案中使用了略微不同的配置。我不喜欢插入行号的脆弱性。我没有在单独的文件中包含特殊的Sauce包含,而是在条件中嵌套特殊配置,具体取决于环境变量SAUCY
是否设置为true。
<强> .travis.yml 强>:
env:
global:
- secure: "encrypted sauce username"
- secure: "encrypted sauce secret key"
- SAUCY: true
addons:
sauce_connect: true
<强>的Gemfile 强>:
group :development, :test do
# other gems...
if ENV['SAUCY']
# gems for sauce
gem 'sauce', '~> 3.1.1'
gem 'sauce-connect'
gem 'parallel_tests'
end
end
<强>规格/ rails_helper.rb 强>:
# after other requires
if ENV['SAUCY']
require 'sauce'
require 'sauce/capybara'
# change to "Capybara.default_driver = :sauce" to use sauce
# for ALL feature specs, not just ones marked with "js: true"
Capybara.javascript_driver = :sauce
Sauce.config do |config|
config[:browsers] = [
['Linux', 'Chrome', nil],
# and other OS/browser combos you want to support...
]
end
end
这样,如果我选择使用,我也可以在本地轻松使用Sauce:
SAUCY=true bundle install
SAUCY=true SAUCE_USERNAME=username SAUCE_ACCESS_KEY=access_key bundle exec rspec