Skip to content

Commit 4053399

Browse files
committed
handle background scenario failures [fix #22]
1 parent 453cf2f commit 4053399

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

lib/guard/cucumber/notification_formatter.rb

+4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ def initialize(step_mother, _path_or_io, options)
4343
@step_mother = step_mother
4444
end
4545

46+
def before_background(background)
47+
@feature_name = background.feature.name
48+
end
49+
4650
# Notification after all features have completed.
4751
#
4852
# @param [Array[Cucumber::Ast::Feature]] features the ran features

spec/guard/cucumber/notification_formatter_spec.rb

+20
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,24 @@
2323
subject.after_features(nil)
2424
end
2525
end
26+
27+
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
38+
end
39+
40+
it "notifies with a valid feature name" do
41+
expect(Guard::Compat::UI).to receive(:notify).with("*step_name1*", hash_including(title: "feature1"))
42+
subject.step_name(nil, step_match, :failed, nil, nil, nil)
43+
end
44+
end
45+
end
2646
end

0 commit comments

Comments
 (0)