Kender
Kender provides a consistent framework for continuous integration (CI). The principles of Kender are:
-
The definition of what constitutes your CI runs is dependent on your code, so it should be managed alongside that code and not isolated in your CI server's configuration.
-
CI runs are executed the same way, wherever they run, whoever runs them. Developers should be able to execute the same, simple command on their local machines to execute a CI run as is used on a dedicated CI server. No more publishing a branch that requires a CI configuration change, unsure of whether the CI server will pass or fail.
-
CI runs are executed the same way on every branch. A single CI project configuration should be suitable for every branch. No more mysterious failures on the CI server due to branch changes being incompatible with the current CI project configuration.
The main benefit of Kender is that all test related software (e.g. Cucumber, RSpec, etc.) is run by default.
Usage
Add the following to your Gemfile
:
group :development, :test do
gem 'kender', '~> 0.5'
end
This gem and its dependencies should not be used in production, hence the group
above.
Configuring and running
The rake ci
task can be run locally in precisely the same way as it should be on a CI server:
rake ci
This executes the three sub-tasks ci:config
, ci:run
and ci:clean
. Each of these can be run in isolation.
Configuration typically requires values to be provided. Using dice_bag, this can be done through environment variables which can be passed in the same command line. For example:
DATABASE_USERNAME=root DATABASE_PASSWORD=password DATABASE_NAME=test rake ci
The ci:config
rake task creates a DB and configures the project.
It will execute the following tasks if they are defined:
config:deploy
db:migrate
db:create
db:drop
config:deploy
is defined in the DiceBag gem.
It will always overwrite the configuration files with the values in the templates.
The db
tasks are assumed to work like those found in Rails.
Run the following command to see the new tasks:
[bundle exec] rake -D ci
Running the tests without configuration
To bypass any configuration and clean-up side effects, for example if your
application is already configured, execute just the ci:run
task.
Non-Rails environments
If you are using these Kender tasks outside of a Rails project, add the following to
your Rakefile
or wherever your local rake tasks are defined:
require 'kender/tasks'
Configuring what is included in the CI run
Kender will detect the test-related gems in your Gemfile and execute whatever CI-related commands make sense. Just ensure the gem is available in at least your test and development environments.
Currently supported gems are:
Cucumber
The Cucumber features will be run. Normally no command-line parameters or switches are passed, so ensure your default profile is correct for a CI run. If the cucumber command fails, the CI run will fail.
If you want to run scenarios that require a headed web browser, you can tell Kender
to use a specific browser as part of the CI run. You can set the environment
variable HEADED_BROWSER
to the name of the browser you want to run. Verify your project
can use the HEADED_BROWSER
environment variable.
Cucumber scenarios can be spread across multiple nodes by using using the following gems:
-
knapsack
- The following environment variables must be accessible when using travis-ci:
- CI_NODE_TOTAL
- CI_NODE_INDEX
- The following environment variables must be accessible when using travis-ci:
- parallel_tests
RSpec
The RSpec specs will be run. No command-line parameters or switches are
passed, so ensure your defaults in .rspec
are correct for a CI run. If the
rspec command fails, the CI run will fail.
Rspecs can be spread across multiple nodes by using using the following gems:
-
knapsack
- The following environment variables must be accessible when using travis-ci:
- CI_NODE_TOTAL
- CI_NODE_INDEX
- The following environment variables must be accessible when using travis-ci:
Jasmine
The Jasmine rake task jasmine:phantom:ci
will be run. If the task fails,
the CI run will fail.
Additionally, you must have PhantomJS pre-installed on the system doing the CI run.
Brakeman
The Brakeman command is run in quiet mode. If any warnings are generated, the CI run will fail.
Bundler Audit
The Bundler-audit check
command is run. If any checks fail, the CI run
will fail.
Reek
The Reek command is run in quiet mode. The CI run will not fail, regardless of the output.
Consistency Fail
The Consistency Fail command is run. The CI run will not fail, regardless of the output.
I18n Tasks
The I18n Tasks commands to check for both missing and unused translations are executed. The CI run will not fail, regardless of the output.
Shamus
The Shamus command is run. If the command fails, the CI run will fail.
When Shamus is used, RSpec, Jasmine and Cucumber are not run directly by Kender
but delegated to Shamus instead. As you may not want to run Shamus by default in
a CI context, you must set the environment variable VALIDATE_PROJECT
:
rake VALIDATE_PROJECT=true ci
FactoryGirl Lint
The FactoryGirl lint command is run. If the command fails, the CI run will fail.
If there is no factory_girl_lint.rake
file in the lib/tasks
directory of the project, the command will not be run.
Cypress-Rails
Your application should include the following task rake cypress_extended:enhanced_run
which should call rake cypress:run
from Cypress-Rails.
namespace :cypress_extended do
task enhanced_run: [:environment] do
# Do other stuff
# Run the Cypress-Rails task
Rake::Task['cypress:run'].invoke
end
end