Skip to content

Commit

Permalink
Merge pull request #25 from guard/fixes_for_cucumber2
Browse files Browse the repository at this point in the history
Update and lock to Cucumber 2.x
  • Loading branch information
e2 committed Mar 29, 2015
2 parents a298c8c + 07f7ef2 commit cf35479
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 18 deletions.
6 changes: 3 additions & 3 deletions guard-cucumber.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ Gem::Specification.new do |s|
s.name = "guard-cucumber"
s.version = Guard::CucumberVersion::VERSION
s.platform = Gem::Platform::RUBY
s.authors = ["Michael Kessler"]
s.email = ["michi@flinkfinger.com"]
s.authors = ["Cezary Baginski", "Michael Kessler"]
s.email = ["cezary@chronomantic.net"]
s.homepage = "http://github.com/guard/guard-cucumber"
s.license = 'MIT'
s.summary = "Guard plugin for Cucumber"
Expand All @@ -18,7 +18,7 @@ Gem::Specification.new do |s|
s.required_rubygems_version = ">= 1.3.6"

s.add_dependency "guard-compat", "~> 1.0"
s.add_dependency "cucumber", ">= 1.3.0"
s.add_dependency "cucumber", "~> 2.0"
s.add_dependency "nenv", "~> 0.1"

s.add_development_dependency "bundler", "~> 1.6"
Expand Down
15 changes: 10 additions & 5 deletions lib/guard/cucumber/notification_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,15 @@ def initialize(step_mother, _path_or_io, options)
@options = options
@file_names = []
@step_mother = step_mother
@feature = nil
end

def before_background(background)
@feature_name = background.feature.name
def before_background(_background)
# NOTE: background.feature is nil on newer gherkin versions
end

def before_feature(feature)
@feature = feature
end

# Notification after all features have completed.
Expand All @@ -62,7 +67,8 @@ def after_features(_features)
#
def before_feature_element(feature_element)
@rerun = false
@feature_name = feature_element.name
# TODO: show feature element name instead?
# @feature = feature_element.name
end

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

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

options = { title: @feature_name, image: icon_for(status) }
options = { title: @feature.name, image: icon_for(status) }
Guard::Compat::UI.notify(step_name, options)
end

Expand Down
32 changes: 22 additions & 10 deletions spec/guard/cucumber/notification_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,34 @@
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
let(:step_match) { instance_double(Cucumber::StepMatch) }
let(:feature) { instance_double(Cucumber::Core::Ast::Feature, name: "feature1") }

before do
subject.before_feature(feature)
subject.before_background(background)
allow(step_match).to receive(:format_args) do |block|
block.call "step_name1"
end
end

context "when failure is in a background step" do
let(:background) { instance_double(Cucumber::Core::Ast::Background, feature: feature) }

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

# workaround for: https://github.com/cucumber/gherkin/issues/334
context "with a buggy Background implementation" do
let(:background) { instance_double(Cucumber::Core::Ast::Background, feature: nil) }

it "correctly gets the 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

0 comments on commit cf35479

Please sign in to comment.