before_cmd hooks
You can configure Aruba to run blocks of code before it runs each command.
The command will be passed to the block.
You can hook into Aruba's lifecycle just before it runs a command and after it has run the command:
ruby
Aruba.configure do |config|
config.before :command do |cmd|
puts "About to run '#{cmd}'"
end
endBackground:
- Given I use a fixture named "
cli-app"
Scenario: Run a simple command with a "before(:command)"-hook
- Given a file named "
spec/support/aruba_config.rb" with:rubyAruba.configure do |config| config.before :command do |cmd| puts "before the run of `#{cmd.commandline}`" end end - And a file named "
spec/hook_spec.rb" with:rubyrequire 'spec_helper' RSpec.describe 'Hooks', :type => :aruba do before { run_command_and_stop 'echo running' } it { expect(last_command_started.stdout.chomp).to eq 'running' } end - When I run `rspec`
- Then the specs should all pass
- And the output should contain:
text
before the run of `echo running`
Source: features/03_testing_frameworks/rspec/hooks/define_before_hook_for_commands.feature at commit c39310a7, Aruba (MIT license).