Skip to content

Commit

Permalink
Add configuration option to enable activation of announcer channels w…
Browse files Browse the repository at this point in the history
…hen a command fails
  • Loading branch information
njam committed Jan 23, 2016
1 parent 1226711 commit a2a5901
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 6 deletions.
39 changes: 37 additions & 2 deletions features/api/command/run_simple.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -107,7 +107,7 @@ Feature: Run command
Given an executable named "bin/cli" with:
"""bash
#!/usr/bin/env bash
function initialize_script {
sleep 2
}
Expand Down Expand Up @@ -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
"""
Original file line number Diff line number Diff line change
@@ -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]"
"""
9 changes: 7 additions & 2 deletions lib/aruba/api/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions lib/aruba/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit a2a5901

Please sign in to comment.