事实证明,在 Travis CI 上运行隔离测试套件的每个 VM 都预装了Node.js 和 Ruby。默认情况下,您将获得 Ruby 1.9.3 和 Node.js 0.12.2(但随着 Travis 团队更新他们的环境,这可能会发生变化),因此即使您只能在文件中指定一种语言(例如language: Ruby
).travis.yml
,您仍然可以同时运行 Ruby和 Travis CI VM 上的 Node.js 程序。
我决定使用 Node.js 语言设置并安装适当的 Ruby 版本(但我可以做相反的事情并获得相同的效果)。
这是我的.travis.yml
配置文件:
language: node_js
node_js:
- 0.12.2
addons:
postgresql: "9.4"
before_install:
- rvm install 2.2.2
install:
# run whatever you have to do here. I have a Makefile that lets you install
# all Node.js-related or Ruby-related dependencies as one step.
- make npm
- make bundler
before_script:
# My Rails app lives in a subdirectory. I want to make sure that
# my database is ready before I start running RSpec tests
- psql -c 'create database test_db;' -U postgres
# I use separate database.yml config for Travis CI
- cp webapp/config/database.travis.yml webapp/config/database.yml
script:
# `test` target executes `bundle exec rspec spec` and `npm run test`
# in all appropriate subdirectories
- make test