Skip to content

Commit

Permalink
Merge pull request #34 from andreassimon/master
Browse files Browse the repository at this point in the history
Added a :feature_sets option to enable non-default directory layouts
  • Loading branch information
netzpirat committed Jun 6, 2012
2 parents 5247517 + 00efe28 commit 1115ba8
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 5 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ Former `:color`, `:drb`, `:port` and `:profile` options are thus deprecated and
:cli => '--profile guard -c' # Pass arbitrary Cucumber CLI arguments,
# default: '--no-profile --color --format progress --strict'

:feature_sets => # Use non-default feature directory/ies
['set_a', 'set_b'] # default: ['features']

:bundler => false # Don't use "bundle exec" to run the Cucumber command
# default: true

Expand Down
6 changes: 4 additions & 2 deletions lib/guard/cucumber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Cucumber < Guard
# @param [Array<Guard::Watcher>] watchers the watchers in the Guard block
# @param [Hash] options the options for the Guard
# @option options [String] :cli any arbitrary Cucumber CLI arguments
# @option options [Array<String>] :feature_sets a list of non-standard feature directory/ies
# @option options [Boolean] :bundler use bundler or not
# @option options [Array<String>] :rvm a list of rvm version to use for the test
# @option options [Boolean] :notification show notifications
Expand All @@ -33,7 +34,8 @@ def initialize(watchers = [], options = { })
:all_after_pass => true,
:all_on_start => true,
:keep_failed => true,
:cli => '--no-profile --color --format progress --strict'
:cli => '--no-profile --color --format progress --strict',
:feature_sets => ['features']
}.update(options)

@last_failed = false
Expand All @@ -53,7 +55,7 @@ def start
# @raise [:task_has_failed] when stop has failed
#
def run_all
passed = Runner.run(['features'], options.merge(options[:run_all] || { }).merge(:message => 'Running all features'))
passed = Runner.run(options[:feature_sets], options.merge(options[:run_all] || { }).merge(:message => 'Running all features'))

if passed
@failed_paths = []
Expand Down
3 changes: 2 additions & 1 deletion lib/guard/cucumber/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class << self
#
# @param [Array<String>] paths the feature files or directories
# @param [Hash] options the options for the execution
# @option options [Array<String>] :feature_sets a list of non-standard feature directory/ies
# @option options [Boolean] :bundler use bundler or not
# @option options [Array<String>] :rvm a list of rvm version to use for the test
# @option options [Boolean] :notification show notifications
Expand Down Expand Up @@ -47,7 +48,7 @@ def cucumber_command(paths, options)
cmd << "--require #{ notification_formatter_path }"
cmd << "--format Guard::Cucumber::NotificationFormatter"
cmd << "--out #{ null_device }"
cmd << "--require features"
cmd << (options[:feature_sets] || ['features']).map {|path| "--require #{path}"}.join(' ')
end

(cmd + paths).join(' ')
Expand Down
20 changes: 20 additions & 0 deletions spec/guard/cucumber/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,26 @@
end
end

context 'with a paths argument' do
it 'runs the given paths' do
runner.should_receive(:system).with(
/features\/foo\.feature features\/bar\.feature$/
)
runner.run(['features/foo.feature', 'features/bar.feature'])
end
end

context 'with a :feature_sets option' do
it 'requires each feature set' do
feature_sets = ['feature_set_a', 'feature_set_b']

runner.should_receive(:system).with(
/--require feature_set_a --require feature_set_b/
)
runner.run(feature_sets, {:feature_sets => feature_sets})
end
end

context 'with a :rvm option' do
it 'executes cucumber through the rvm versions' do
runner.should_receive(:system).with(
Expand Down
25 changes: 23 additions & 2 deletions spec/guard/cucumber_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
:all_after_pass => true,
:all_on_start => true,
:keep_failed => true,
:cli => '--no-profile --color --format progress --strict'
:cli => '--no-profile --color --format progress --strict',
:feature_sets => ['features']
}
end

Expand All @@ -35,13 +36,18 @@
it 'sets a default :cli option' do
guard.options[:cli].should eql '--no-profile --color --format progress --strict'
end

it 'sets a default :feature_sets option' do
guard.options[:feature_sets].should eql ['features']
end
end

context 'with other options than the default ones' do
let(:guard) { Guard::Cucumber.new(nil, { :all_after_pass => false,
:all_on_start => false,
:keep_failed => false,
:cli => '--color' }) }
:cli => '--color',
:feature_sets => ['feature_set_a', 'feature_set_b'] }) }

it 'sets the provided :all_after_pass option' do
guard.options[:all_after_pass].should be_false
Expand All @@ -58,6 +64,10 @@
it 'sets the provided :cli option' do
guard.options[:cli].should eql '--color'
end

it 'sets the provided :feature_sets option' do
guard.options[:feature_sets].should eql ['feature_set_a', 'feature_set_b']
end
end
end

Expand Down Expand Up @@ -106,6 +116,17 @@
guard.run_on_changes(['features/bar'])
end

context 'with the :feature_sets option' do
non_standard_feature_set = ['a_non_standard_feature_set']
let(:guard) { Guard::Cucumber.new([], { :feature_sets => non_standard_feature_set }) }

it 'passes the feature sets as paths to runner' do
runner.should_receive(:run).with(non_standard_feature_set, anything).and_return(true)

guard.run_all
end
end

context 'with the :cli option' do
let(:guard) { Guard::Cucumber.new([], { :cli => '--color' }) }

Expand Down

0 comments on commit 1115ba8

Please sign in to comment.