對於那些有類似需求的,這是我落得這樣做:
.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
travis/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
更新(2014年11月25日):
最後我用我的最終解決方案略有不同的配置。我不喜歡插入行號的脆弱性。而不是在單獨的文件中包含特殊的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
釷是方式,我也可以在本地方便地使用醬如果我選擇與:
SAUCY=true bundle install
SAUCY=true SAUCE_USERNAME=username SAUCE_ACCESS_KEY=access_key bundle exec rspec
我是醬寶石的維護者;我喜歡這個只在Travis上使用Sauce的解決方案!在[Sauce Gem Wiki](https://github.com/saucelabs/sauce_ruby/wiki/Swappable-Sauce)上有一個迷你指南,用於使用環境變量交換Sauce進出;在Travis上,你可以使用'TRAVIS'環境變量。 – 2014-11-24 23:06:48