Skip to content

Commit cf35479

Browse files
committed
Merge pull request #25 from guard/fixes_for_cucumber2
Update and lock to Cucumber 2.x
2 parents a298c8c + 07f7ef2 commit cf35479

File tree

3 files changed

+35
-18
lines changed

3 files changed

+35
-18
lines changed

guard-cucumber.gemspec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ Gem::Specification.new do |s|
77
s.name = "guard-cucumber"
88
s.version = Guard::CucumberVersion::VERSION
99
s.platform = Gem::Platform::RUBY
10-
s.authors = ["Michael Kessler"]
11-
s.email = ["[email protected]"]
10+
s.authors = ["Cezary Baginski", "Michael Kessler"]
11+
s.email = ["[email protected]"]
1212
s.homepage = "http://github.com/guard/guard-cucumber"
1313
s.license = 'MIT'
1414
s.summary = "Guard plugin for Cucumber"
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
1818
s.required_rubygems_version = ">= 1.3.6"
1919

2020
s.add_dependency "guard-compat", "~> 1.0"
21-
s.add_dependency "cucumber", ">= 1.3.0"
21+
s.add_dependency "cucumber", "~> 2.0"
2222
s.add_dependency "nenv", "~> 0.1"
2323

2424
s.add_development_dependency "bundler", "~> 1.6"

lib/guard/cucumber/notification_formatter.rb

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,15 @@ def initialize(step_mother, _path_or_io, options)
4141
@options = options
4242
@file_names = []
4343
@step_mother = step_mother
44+
@feature = nil
4445
end
4546

46-
def before_background(background)
47-
@feature_name = background.feature.name
47+
def before_background(_background)
48+
# NOTE: background.feature is nil on newer gherkin versions
49+
end
50+
51+
def before_feature(feature)
52+
@feature = feature
4853
end
4954

5055
# Notification after all features have completed.
@@ -62,7 +67,8 @@ def after_features(_features)
6267
#
6368
def before_feature_element(feature_element)
6469
@rerun = false
65-
@feature_name = feature_element.name
70+
# TODO: show feature element name instead?
71+
# @feature = feature_element.name
6672
end
6773

6874
# After a feature gets run.
@@ -89,11 +95,10 @@ def after_feature_element(feature_element)
8995
def step_name(_keyword, step_match, status, _src_indent, _bckgnd, _loc)
9096
return unless [:failed, :pending, :undefined].index(status)
9197

92-
# TODO: NO COVERAGE HERE!
9398
@rerun = true
9499
step_name = step_match.format_args(lambda { |param| "*#{ param }*" })
95100

96-
options = { title: @feature_name, image: icon_for(status) }
101+
options = { title: @feature.name, image: icon_for(status) }
97102
Guard::Compat::UI.notify(step_name, options)
98103
end
99104

spec/guard/cucumber/notification_formatter_spec.rb

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,34 @@
2525
end
2626

2727
describe "#step_name" do
28-
context "when failure is in a background step" do
29-
let(:step_match) { instance_double(Cucumber::StepMatch) }
30-
let(:feature) { instance_double(Cucumber::Ast::Feature, name: "feature1") }
31-
let(:background) { instance_double(Cucumber::Ast::Background, feature: feature) }
32-
33-
before do
34-
subject.before_background(background)
35-
allow(step_match).to receive(:format_args) do |block|
36-
block.call "step_name1"
37-
end
28+
let(:step_match) { instance_double(Cucumber::StepMatch) }
29+
let(:feature) { instance_double(Cucumber::Core::Ast::Feature, name: "feature1") }
30+
31+
before do
32+
subject.before_feature(feature)
33+
subject.before_background(background)
34+
allow(step_match).to receive(:format_args) do |block|
35+
block.call "step_name1"
3836
end
37+
end
38+
39+
context "when failure is in a background step" do
40+
let(:background) { instance_double(Cucumber::Core::Ast::Background, feature: feature) }
3941

4042
it "notifies with a valid feature name" do
4143
expect(Guard::Compat::UI).to receive(:notify).with("*step_name1*", hash_including(title: "feature1"))
4244
subject.step_name(nil, step_match, :failed, nil, nil, nil)
4345
end
4446
end
47+
48+
# workaround for: https://github.com/cucumber/gherkin/issues/334
49+
context "with a buggy Background implementation" do
50+
let(:background) { instance_double(Cucumber::Core::Ast::Background, feature: nil) }
51+
52+
it "correctly gets the feature name" do
53+
expect(Guard::Compat::UI).to receive(:notify).with("*step_name1*", hash_including(title: "feature1"))
54+
subject.step_name(nil, step_match, :failed, nil, nil, nil)
55+
end
56+
end
4557
end
4658
end

0 commit comments

Comments
 (0)