Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

guard cucumber binstubs option (matches guard-rspec behavior). #27

Merged
merged 2 commits into from
Nov 28, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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