Skip to content

Commit

Permalink
Merge pull request #846 from pdswan/regression/missing-scenario-status
Browse files Browse the repository at this point in the history
Expose #status on Cucumber::RunningTestCase [#836]
  • Loading branch information
mattwynne committed May 6, 2015
2 parents aadd621 + d545d3c commit 770cbe4
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ unless ENV['CUCUMBER_USE_RELEASED_CORE']
if File.exist?(core_path) && !ENV['CUCUMBER_USE_GIT_CORE']
gem 'cucumber-core', :path => core_path
else
gem 'cucumber-core', :git => "git://github.com/cucumber/cucumber-ruby-core.git"
gem 'cucumber-core', :git => "git://github.com/pdswan/cucumber-ruby-core.git", :branch => "regression/missing-scenario-status"
end
end
22 changes: 22 additions & 0 deletions features/docs/writing_support_code/after_hooks.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,28 @@ Feature: After Hooks
Background:
Given the standard step definitions

Scenario Outline: Retreive the status of a scenario as a symbol
Given a file named "features/support/debug_hook.rb" with:
"""
After do |scenario|
puts scenario.status.inspect
end
"""
And a file named "features/result.feature" with:
"""
Feature:
Scenario:
Given this step <result>
"""
When I run `cucumber -f progress`
Then the output should contain "<status symbol>"

Examples:
| result | status symbol |
| passes | :passed |
| fails | :failed |
| is pending | :pending |

Scenario: Check the failed status of a scenario in a hook
Given a file named "features/support/debug_hook.rb" with:
"""
Expand Down
8 changes: 6 additions & 2 deletions lib/cucumber/running_test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Cucumber
# Represents the current status of a running test case.
#
#
# This wraps a `Cucumber::Core::Test::Case` and delegates
# many methods to that object.
#
Expand All @@ -15,7 +15,7 @@ module Cucumber
#
# The test case might come from a regular Scenario or
# a Scenario outline. You can call the `#outline?`
# predicate to find out. If it's from an outline,
# predicate to find out. If it's from an outline,
# you get a couple of extra methods.
module RunningTestCase
def self.new(test_case)
Expand Down Expand Up @@ -67,6 +67,10 @@ def exception
@result.exception
end

def status
@result.to_sym
end

def failed?
@result.failed?
end
Expand Down
8 changes: 7 additions & 1 deletion spec/cucumber/running_test_case_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ module Cucumber

attr_accessor :wrapped_test_case, :core_test_case

let(:result) { double(:result, to_sym: :status_symbol) }

before do
receiver = double.as_null_object
allow(receiver).to receive(:test_case) { |core_test_case|
self.core_test_case = core_test_case
self.wrapped_test_case = RunningTestCase.new(core_test_case)
self.wrapped_test_case = RunningTestCase.new(core_test_case).with_result(result)
}
compile [gherkin_doc], receiver
end
Expand Down Expand Up @@ -42,6 +44,10 @@ module Cucumber
expect(wrapped_test_case.source).to eq core_test_case.source
expect(wrapped_test_case.keyword).to eq core_test_case.keyword
end

it "exposes properties of the result" do
expect(wrapped_test_case.status).to eq result.to_sym
end
end

context "for a failed scenario" do
Expand Down

0 comments on commit 770cbe4

Please sign in to comment.