Cucumber / Aruba / Docs / 02 configure aruba
Usage of configuration
You can configure aruba in two ways:
- Using
Aruba.configure-block - Using
aruba.config.<option> = <value>
The first (1.) should be used to set defaults for ALL your tests. It changes values on loadtime. The latter (2.) should be used to change options only for specific tests during runtime. aruba.config contains the runtime configuration of aruba which is reset to the loadtime configuration before each test is run.
Background:
- Given I use a fixture named "
cli-app" - And an executable named "
bin/aruba-test-cli" with:ruby#!/usr/bin/env ruby sleep ARGV[0].to_f
Scenario: Setting default values for option for RSpec
- Given a file named "
spec/support/aruba_config.rb" with:rubyAruba.configure do |config| config.exit_timeout = 2.0 end - And a file named "
spec/usage_configuration_spec.rb" with:rubyrequire 'spec_helper' RSpec.describe 'Run command', :type => :aruba do context 'when fast command' do before { run_command('aruba-test-cli 0') } it { expect(last_command_started).to have_finished_in_time } end context 'when slow command' do before { run_command('aruba-test-cli 2') } it { expect(last_command_started).not_to have_finished_in_time } end end - When I run `rspec`
- Then the specs should all pass
Scenario: Setting option during runtime for RSpec
Maybe there are some long running tests, which need longer. You may not want to set the default timeout for all commands to the maximum value only to prevent those commands from failing.
- Given a file named "
spec/support/aruba_config.rb" with:rubyAruba.configure do |config| config.exit_timeout = 1.0 end - And a file named "
spec/support/hooks.rb" with:rubyRSpec.configure do |config| config.before :each do |example| next unless example.metadata.key? :slow_command aruba.config.exit_timeout = 2.5 end end - And a file named "
spec/usage_configuration_spec.rb" with:rubyrequire 'spec_helper' RSpec.describe 'Run command', :type => :aruba do context 'when fast command' do before { run_command('aruba-test-cli 0') } it { expect(last_command_started).to have_finished_in_time } end context 'when slow command and this is known by the developer', :slow_command => true do before { run_command('aruba-test-cli 1.1') } it { expect(last_command_started).to have_finished_in_time } end context 'when slow command, but this might be a failure' do before { run_command('aruba-test-cli 1.1') } it { expect(last_command_started).not_to have_finished_in_time } end end - When I run `rspec`
- Then the specs should all pass
Scenario: Setting default values for option for Cucumber
- Given a file named "
features/support/aruba_config.rb" with:rubyAruba.configure do |config| config.exit_timeout = 2.0 end - And a file named "
features/step_definitions/timeout_steps.rb" with:rubyThen 'the command should finish in time' do expect(last_command_started).to have_finished_in_time end Then 'the command should time out' do expect(last_command_started).to run_too_long end - And a file named "
features/run.feature" with:gherkinFeature: Run it Scenario: Fast command When I run `aruba-test-cli 0` Then the command should finish in time Scenario: Slow command When I run `aruba-test-cli 2` Then the command should time out - When I run `cucumber`
- Then the features should all pass
Scenario: Setting option during runtime for Cucumber
Maybe there are some long running tests, which need longer. You may not want to set the default timeout for all commands to the maximum value only to prevent those commands from failing.
- Given a file named "
features/support/aruba_config.rb" with:rubyAruba.configure do |config| config.exit_timeout = 2.0 end - And a file named "
features/support/hooks.rb" with:rubyBefore '@slow-command' do aruba.config.exit_timeout = 3.5 end - And a file named "
features/step_definitions/timeout_steps.rb" with:rubyThen 'the command should finish in time' do expect(last_command_started).to have_finished_in_time end Then 'the command should time out' do expect(last_command_started).to run_too_long end - And a file named "
features/usage_configuration.feature" with:gherkinFeature: Run it Scenario: Fast command When I run `aruba-test-cli 0` Then the command should finish in time @slow-command Scenario: Slow command finishes when given more time When I run `aruba-test-cli 2.1` Then the command should finish in time Scenario: Slow command fails When I run `aruba-test-cli 2.1` Then the command should time out - When I run `cucumber`
- Then the features should all pass
Source: features/02_configure_aruba/basics.feature at commit c39310a7, Aruba (MIT license).