Skip to content

Commit

Permalink
Merge pull request #27 from hedgehog/binstubs
Browse files Browse the repository at this point in the history
guard cucumber binstubs option (matches guard-rspec behavior).
  • Loading branch information
netzpirat committed Nov 28, 2011
2 parents fa340b3 + 82ab90b commit 88ac4da
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -70,6 +70,9 @@ Former `:color`, `:drb`, `:port` and `:profile` options are thus deprecated and
:bundler => false # Don't use "bundle exec" to run the Cucumber command
# default: true

:binstubs => true # use "bin/cucumber" to run the Cucumber command (implies :bundler => true)
# default: false

:rvm => ['1.8.7', '1.9.2'] # Directly run your features on multiple ruby versions
# default: nil

Expand Down
15 changes: 11 additions & 4 deletions lib/guard/cucumber/runner.rb
Expand Up @@ -18,7 +18,7 @@ class << self
def run(paths, options = { })
return false if paths.empty?

message = options[:message] || (paths == ['features'] ? 'Run all Cucumber features' : "Run Cucumber features #{ paths.join(' ') }")
message = options[:message] || (paths == ['features'] ? "Running all Cucumber features: #{ cucumber_command(paths, options) }" : "Running Cucumber features: #{ cucumber_command(paths, options) }")
UI.info message, :reset => true

system(cucumber_command(paths, options))
Expand All @@ -38,9 +38,8 @@ def run(paths, options = { })
def cucumber_command(paths, options)
cmd = []
cmd << "rvm #{options[:rvm].join(',')} exec" if options[:rvm].is_a?(Array)
cmd << 'bundle exec' if bundler? && options[:bundler] != false

cmd << 'cucumber'
cmd << 'bundle exec' if (bundler? && options[:bundler] != false) || (bundler? && options[:binstubs].is_a?(TrueClass))
cmd << cucumber_exec(options)
cmd << options[:cli] if options[:cli]

if options[:notification] != false
Expand All @@ -54,6 +53,14 @@ def cucumber_command(paths, options)
(cmd + paths).join(' ')
end

# Simple test if binstubs prefix should be used.
#
# @return [String] Cucumber executable
#
def cucumber_exec(options = {})
options[:binstubs] == true && ( bundler? || options[:bundler] != false ) ? "bin/cucumber" : "cucumber"
end

# Simple test if bundler should be used. it just checks for the `Gemfile`.
#
# @return [Boolean] bundler exists
Expand Down
39 changes: 39 additions & 0 deletions spec/guard/cucumber/runner_spec.rb
Expand Up @@ -29,6 +29,45 @@
end
end

describe ":binstubs" do
it "runs without Bundler with binstubs option to true and bundler option to false" do
subject.should_receive(:system).with(
"bundle exec bin/cucumber --require #{ @lib_path.join('guard/cucumber/notification_formatter.rb') } --format Guard::Cucumber::NotificationFormatter --out #{ null_device } --require features features"
).and_return(true)
subject.run(["features"], :bundler => false, :binstubs => true)
end
it "runs with Bundler and binstubs with bundler option to true and binstubs option to true" do
subject.should_receive(:system).with(
"bundle exec bin/cucumber --require #{ @lib_path.join('guard/cucumber/notification_formatter.rb') } --format Guard::Cucumber::NotificationFormatter --out #{ null_device } --require features features"
).and_return(true)
subject.run(["features"], :bundler => true, :binstubs => true)
end
it "runs with Bundler and binstubs with bundler option unset and binstubs option to true" do
subject.should_receive(:system).with(
"bundle exec bin/cucumber --require #{ @lib_path.join('guard/cucumber/notification_formatter.rb') } --format Guard::Cucumber::NotificationFormatter --out #{ null_device } --require features features"
).and_return(true)
subject.run(["features"], :binstubs => true)
end
it "runs with Bundler and binstubs with bundler option unset, binstubs option to true and all_after_pass option to true" do
subject.should_receive(:system).with(
"bundle exec bin/cucumber --require #{ @lib_path.join('guard/cucumber/notification_formatter.rb') } --format Guard::Cucumber::NotificationFormatter --out #{ null_device } --require features features"
).and_return(true)
subject.run(["features"], :binstubs => true, :all_after_pass => true)
end
it "runs with Bundler and binstubs with bundler option unset, binstubs option to true and all_on_start option to true" do
subject.should_receive(:system).with(
"bundle exec bin/cucumber --require #{ @lib_path.join('guard/cucumber/notification_formatter.rb') } --format Guard::Cucumber::NotificationFormatter --out #{ null_device } --require features features"
).and_return(true)
subject.run(["features"], :binstubs => true, :all_on_start => true)
end
it "runs with Bundler and binstubs with bundler option unset, binstubs option to true, all_on_start option to true and all_after_pass option to true" do
subject.should_receive(:system).with(
"bundle exec bin/cucumber --require #{ @lib_path.join('guard/cucumber/notification_formatter.rb') } --format Guard::Cucumber::NotificationFormatter --out #{ null_device } --require features features"
).and_return(true)
subject.run(["features"], :binstubs => true, :all_after_pass => true, :all_on_start => true)
end
end

context 'with a :cli option' do
it 'appends the cli arguments when calling cucumber' do
runner.should_receive(:system).with(
Expand Down

0 comments on commit 88ac4da

Please sign in to comment.