diff --git a/features/api/command/run_simple.feature b/features/api/command/run_simple.feature index 795cf7843..1057f89f3 100644 --- a/features/api/command/run_simple.feature +++ b/features/api/command/run_simple.feature @@ -8,7 +8,7 @@ Feature: Run command Given this option is `true`, `aruba` fails if the `command` fails to run - exit code <> 0. For all other options see [run.feature](run.feature). - + Background: Given I use a fixture named "cli-app" @@ -107,7 +107,7 @@ Feature: Run command Given an executable named "bin/cli" with: """bash #!/usr/bin/env bash - + function initialize_script { sleep 2 } @@ -205,3 +205,38 @@ Feature: Run command """ When I run `rspec` Then the specs should all pass + + Scenario: Activate announcer channels on failure + + Given an executable named "bin/cli" with: + """bash + #!/bin/bash + echo "Hello, I'm STDOUT" + echo "Hello, I'm STDERR" 1>&2 + exit 1 + """ + And a file named "spec/run_spec.rb" with: + """ruby + require 'spec_helper' + + Aruba.configure do |config| + config.activate_announcer_on_command_failure = [:stdout, :stderr] + end + + RSpec.describe 'Run command', :type => :aruba do + it { expect { run_simple('cli', :fail_on_error => true) }.to_not raise_error } + end + """ + When I run `rspec` + Then the specs should not pass + And the output should contain: + """ + <<-STDOUT + Hello, I'm STDOUT + + STDOUT + <<-STDERR + Hello, I'm STDERR + + STDERR + """ diff --git a/features/configuration/activate_announcer_on_command_failure.feature b/features/configuration/activate_announcer_on_command_failure.feature new file mode 100644 index 000000000..49c82455d --- /dev/null +++ b/features/configuration/activate_announcer_on_command_failure.feature @@ -0,0 +1,38 @@ +Feature: Configure announcer activation on command failure + + As a developer + I want to configure which announcers should get activated on command failure + In order to understand what caused a command to fail + + Background: + Given I use the fixture "cli-app" + + Scenario: Default value + Given a file named "features/support/aruba.rb" with: + """ruby + Aruba.configure do |config| + puts %(The default value is "#{config.activate_announcer_on_command_failure}") + end + """ + When I successfully run `cucumber` + Then the output should contain: + """ruby + The default value is "[]" + """ + + Scenario: Modify value + Given a file named "features/support/aruba.rb" with: + """ruby + Aruba.configure do |config| + config.activate_announcer_on_command_failure = [:foo, :bar] + end + + Aruba.configure do |config| + puts %(The value is "#{config.activate_announcer_on_command_failure}") + end + """ + Then I successfully run `cucumber` + Then the output should contain: + """ + The value is "[:foo, :bar]" + """ diff --git a/lib/aruba/api/command.rb b/lib/aruba/api/command.rb index 2db08e594..adeceb0a9 100644 --- a/lib/aruba/api/command.rb +++ b/lib/aruba/api/command.rb @@ -277,8 +277,13 @@ def run_simple(*args) end if fail_on_error - expect(command).to have_finished_in_time - expect(command).to be_successfully_executed + begin + expect(command).to have_finished_in_time + expect(command).to be_successfully_executed + rescue RSpec::Expectations::ExpectationNotMetError => e + aruba.announcer.activate(aruba.config.activate_announcer_on_command_failure) + raise e + end end end # rubocop:enable Metrics/CyclomaticComplexity diff --git a/lib/aruba/config.rb b/lib/aruba/config.rb index 493fc075c..487a3c418 100644 --- a/lib/aruba/config.rb +++ b/lib/aruba/config.rb @@ -26,9 +26,9 @@ class Configuration < BasicConfiguration option_accessor :working_directory, :contract => { Aruba::Contracts::RelativePath => Aruba::Contracts::RelativePath }, :default => 'tmp/aruba' if RUBY_VERSION < '1.9' - option_reader :fixtures_path_prefix, :contract => { None => String }, :default => '%' + option_reader :fixtures_path_prefix, :contract => { None => String }, :default => '%' else - option_reader :fixtures_path_prefix, :contract => { None => String }, :default => ?% + option_reader :fixtures_path_prefix, :contract => { None => String }, :default => ?% end option_accessor :exit_timeout, :contract => { Num => Num }, :default => 15 @@ -64,6 +64,8 @@ class Configuration < BasicConfiguration option_accessor :physical_block_size, :contract => { Aruba::Contracts::IsPowerOfTwo => Aruba::Contracts::IsPowerOfTwo }, :default => 512 option_accessor :console_history_file, :contract => { String => String }, :default => '~/.aruba_history' + + option_accessor :activate_announcer_on_command_failure, :contract => { ArrayOf[Symbol] => ArrayOf[Symbol] }, :default => [] end end