Skip to content

Commit

Permalink
Merge pull request netzpirat#13 from guard/use_guard_compat
Browse files Browse the repository at this point in the history
Use guard compat
  • Loading branch information
e2 committed Dec 5, 2014
2 parents 7d51180 + 62b288f commit 0690e54
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 72 deletions.
13 changes: 7 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ gem "rspec", "~> 3.1"
# installed on Travis CI.
#
group :development do
gem "guard-rspec"
gem "guard-bundler"
gem "yard"
gem "redcarpet"
gem "transpec", require: false
gem "guard-rubocop"
gem "guard-rspec", require: false
gem "guard-bundler", require: false
gem "yard", require: false
gem "redcarpet", require: false
gem "guard-rubocop", require: false
gem "rubocop", github: "bbatsov/rubocop", branch: "master"
gem "guard-compat", require: false
end

platforms :rbx do
Expand Down
3 changes: 0 additions & 3 deletions lib/guard/cucumber.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "guard"
require "guard/plugin"
require "cucumber"
require "guard/cucumber/version"
require "guard/cucumber/runner"
Expand All @@ -11,7 +9,6 @@ module Guard
# Guard events: `start`, `stop`, `reload`, `run_all` and `run_on_change`.
#
class Cucumber < Plugin

attr_accessor :last_failed, :failed_path

# Initialize Guard::Cucumber.
Expand Down
2 changes: 1 addition & 1 deletion lib/guard/cucumber/inspector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def cucumber_file?(path, feature_sets)
# @return [Array<String>] the valid files
#
def cucumber_files(feature_sets)
glob = "#{ feature_sets.join(",") }/**/*.feature"
glob = "#{ feature_sets.join(',') }/**/*.feature"
@cucumber_files ||= Dir.glob(glob)
end

Expand Down
27 changes: 12 additions & 15 deletions lib/guard/cucumber/notification_formatter.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "guard"
require "guard/notifier"
require "cucumber/formatter/console"
require "cucumber/formatter/io"

Expand Down Expand Up @@ -84,17 +82,13 @@ def step_name(_keyword, step_match, status, _src_indent, _bckgnd, _loc)
# result of the feature tests.
#
def notify_summary
icon, messages = nil, []

[:failed, :skipped, :undefined, :pending, :passed].reverse.
each do |status|
if step_mother.steps(status).any?
step_icon = icon_for(status)
icon = step_icon if step_icon
len = step_mother.steps(status).length
messages << dump_count(len, "step", status.to_s)
end
end
statuses = [:failed, :skipped, :undefined, :pending, :passed]
statuses = statuses.reverse
statuses.select! { |status| step_mother.steps(status).any? }

messages = statuses.map { |status| _status_to_message(status) }

icon = statuses.reverse.detect { |status| icon_for(status) }

msg = messages.reverse.join(", ")
::Guard::Notifier.notify msg, title: "Cucumber Results", image: icon
Expand All @@ -121,10 +115,13 @@ def icon_for(status)
:pending
when :failed
:failed
else
nil
end
end

def status_to_message(status)
len = step_mother.steps(status).length
dump_count(len, "step", status.to_s)
end
end
end
end
35 changes: 24 additions & 11 deletions lib/guard/cucumber/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,12 @@ def run(paths, options = {})
#
def cucumber_command(paths, options)
cmd = []
cmd << options[:command_prefix] if options[:command_prefix]
if options[:rvm].is_a?(Array)
cmd << "rvm #{ options[:rvm].join(",") } exec"
end

cmd << "bundle exec" if bundler? && options[:bundler] != false
_add_cmd_prefix(cmd, options[:command_prefix])
_add_rvm_options(cmd, options[:rvm])
_add_bundler_options(cmd, options[:bundler])
cmd << cucumber_exec(options)
cmd << options[:cli] if options[:cli]

if options[:notification] != false
_add_notification(cmd, options)
end
_add_cli_options(cmd, options[:cli])
_add_notification(cmd, options)

(cmd + paths).join(" ")
end
Expand Down Expand Up @@ -99,6 +93,8 @@ def null_device
private

def _add_notification(cmd, options)
return unless options[:notification] != false

this_dir = File.dirname(__FILE__)
formatter_path = File.join(this_dir, "notification_formatter.rb")
notification_formatter_path = File.expand_path(formatter_path)
Expand All @@ -110,6 +106,23 @@ def _add_notification(cmd, options)
"--require #{ path }"
end.join(" ")
end

def _add_rvm_options(cmd, rvm_args)
return unless rvm_args.is_a?(Array)
cmd << "rvm #{ rvm_args.join(',') } exec"
end

def _add_bundler_options(cmd, bundler)
cmd << "bundle exec" if bundler? && bundler != false
end

def _add_cli_options(cmd, cli)
cmd << cli if cli
end

def _add_cmd_prefix(cmd, prefix)
cmd << prefix if prefix
end
end
end
end
Expand Down
3 changes: 0 additions & 3 deletions spec/guard/cucumber/focuser_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
require "spec_helper"

require "guard/cucumber/focuser"

RSpec.describe Guard::Cucumber::Focuser do

let(:focuser) { Guard::Cucumber::Focuser }
let(:focus_tag) { "@focus" }
let(:null_device) { RUBY_PLATFORM.index("mswin") ? "NUL" : "/dev/null" }
Expand Down
39 changes: 18 additions & 21 deletions spec/guard/cucumber/inspector_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
require "spec_helper"

require "guard/cucumber/inspector"

RSpec.describe Guard::Cucumber::Inspector do

let(:inspector) { Guard::Cucumber::Inspector }

describe ".clean" do
Expand All @@ -22,7 +19,7 @@
expect(inspector.clean(
%w(features/a.feature features/x.feature),
%w(features))).
to eq(%w(features/a.feature))
to eq(%w(features/a.feature))
end

it "keeps a feature folder" do
Expand Down Expand Up @@ -61,11 +58,11 @@
context "with an additional feature set" do
before do
allow(Dir).to receive(:glob).
and_return(%w(
feature_set_1/a.feature
feature_set_1/subfolder/b.feature
feature_set_2/c.feature
feature_set_2/subfolder/d.feature))
and_return(%w(
feature_set_1/a.feature
feature_set_1/subfolder/b.feature
feature_set_2/c.feature
feature_set_2/subfolder/d.feature))
end

it "removes non-feature files" do
Expand All @@ -83,7 +80,7 @@
feature_set_2/c.feature
feature_set_2/y.feature),
%w(feature_set_1 feature_set_2))).
to eq(%w(feature_set_1/a.feature feature_set_2/c.feature))
to eq(%w(feature_set_1/a.feature feature_set_2/c.feature))
end

it "keeps the feature folders" do
Expand All @@ -94,11 +91,11 @@
feature_set_2/c.feature
feature_set_2/subfolder),
%w(feature_set_1 feature_set_2))).
to eq(%w(
feature_set_1/a.feature
feature_set_1/subfolder
feature_set_2/c.feature
feature_set_2/subfolder))
to eq(%w(
feature_set_1/a.feature
feature_set_1/subfolder
feature_set_2/c.feature
feature_set_2/subfolder))
end

it "removes duplicate paths" do
Expand All @@ -109,7 +106,7 @@
feature_set_2
feature_set_2),
%w(feature_set_1 feature_set_2))).
to eq(%w(feature_set_1 feature_set_2))
to eq(%w(feature_set_1 feature_set_2))
end

it "removes individual feature tests if the path is already "\
Expand All @@ -132,17 +129,17 @@
feature_set_2/subfolder
feature_set_2),
%w(feature_set_1 feature_set_2))).
to eq(%w(feature_set_1 feature_set_2))
to eq(%w(feature_set_1 feature_set_2))

expect(inspector.clean(
%w(feature_set_1 feature_set_2/subfolder),
%w(feature_set_1 feature_set_2))).
to eq(%w(feature_set_1 feature_set_2/subfolder))
to eq(%w(feature_set_1 feature_set_2/subfolder))

expect(inspector.clean(
%w(feature_set_2 feature_set_1/subfolder),
%w(feature_set_1 feature_set_2))).
to eq(%w(feature_set_2 feature_set_1/subfolder))
to eq(%w(feature_set_2 feature_set_1/subfolder))
end

it "removes feature files includes in feature folder" do
Expand All @@ -160,12 +157,12 @@
%w(feature_set_1/subfolder/b.feature feature_set_2),

%w(feature_set_1 feature_set_2))).
to eq(%w(feature_set_1/subfolder/b.feature feature_set_2))
to eq(%w(feature_set_1/subfolder/b.feature feature_set_2))

expect(inspector.clean(
%w(feature_set_2/subfolder/d.feature feature_set_1),
%w(feature_set_1 feature_set_2))).
to eq(%w( feature_set_2/subfolder/d.feature feature_set_1))
to eq(%w( feature_set_2/subfolder/d.feature feature_set_1))
end
end
end
Expand Down
7 changes: 0 additions & 7 deletions spec/guard/cucumber/runner_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "spec_helper"

require "guard/cucumber/runner"

RSpec.describe Guard::Cucumber::Runner do
Expand All @@ -19,7 +17,6 @@
end

context "with a paths argument" do

it "runs the given paths" do
expect(runner).to receive(:system).with(
/features\/foo\.feature features\/bar\.feature$/
Expand Down Expand Up @@ -138,7 +135,6 @@

it "runs with Bundler and binstubs with bundler option unset, "\
"binstubs option to true and all_after_pass option to true" do

req = @lib_path.join("guard/cucumber/notification_formatter.rb")
expect(subject).to receive(:system).with(
"bundle exec bin/cucumber"\
Expand All @@ -152,7 +148,6 @@

it "runs with Bundler and binstubs with bundler option unset, "\
"binstubs option to true and all_on_start option to true" do

req = @lib_path.join("guard/cucumber/notification_formatter.rb")
expect(subject).to receive(:system).with(
"bundle exec bin/cucumber --require #{ req } "\
Expand All @@ -165,7 +160,6 @@
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

req = @lib_path.join("guard/cucumber/notification_formatter.rb")

expect(subject).to receive(:system).with(
Expand Down Expand Up @@ -202,5 +196,4 @@
end
end
end

end
2 changes: 0 additions & 2 deletions spec/guard/cucumber/version_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "spec_helper"

RSpec.describe Guard::CucumberVersion do
describe "VERSION" do
it "defines the version" do
Expand Down
3 changes: 0 additions & 3 deletions spec/guard/cucumber_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "spec_helper"

RSpec.describe Guard::Cucumber do
subject { Guard::Cucumber.new(options) }

Expand Down Expand Up @@ -82,7 +80,6 @@
it "sets the provided :focus_on option" do
expect(subject.options[:focus_on]).to eql "@focus"
end

end
end

Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require "guard/compat/test/helper"
require "guard/cucumber"

# This file was generated by the `rspec --init` command. Conventionally, all
Expand Down

0 comments on commit 0690e54

Please sign in to comment.