diff --git a/lib/guard/cucumber/notification_formatter.rb b/lib/guard/cucumber/notification_formatter.rb index 59d5b67..f683719 100644 --- a/lib/guard/cucumber/notification_formatter.rb +++ b/lib/guard/cucumber/notification_formatter.rb @@ -43,6 +43,10 @@ def initialize(step_mother, _path_or_io, options) @step_mother = step_mother end + def before_background(background) + @feature_name = background.feature.name + end + # Notification after all features have completed. # # @param [Array[Cucumber::Ast::Feature]] features the ran features diff --git a/spec/guard/cucumber/notification_formatter_spec.rb b/spec/guard/cucumber/notification_formatter_spec.rb index 1b3800a..6ac6e3b 100644 --- a/spec/guard/cucumber/notification_formatter_spec.rb +++ b/spec/guard/cucumber/notification_formatter_spec.rb @@ -23,4 +23,24 @@ subject.after_features(nil) end end + + describe "#step_name" do + context "when failure is in a background step" do + let(:step_match) { instance_double(Cucumber::StepMatch) } + let(:feature) { instance_double(Cucumber::Ast::Feature, name: "feature1") } + let(:background) { instance_double(Cucumber::Ast::Background, feature: feature) } + + before do + subject.before_background(background) + allow(step_match).to receive(:format_args) do |block| + block.call "step_name1" + end + end + + it "notifies with a valid feature name" do + expect(Guard::Compat::UI).to receive(:notify).with("*step_name1*", hash_including(title: "feature1")) + subject.step_name(nil, step_match, :failed, nil, nil, nil) + end + end + end end