Skip to content

Commit

Permalink
Add #exception to the test case yielded to blocks
Browse files Browse the repository at this point in the history
Fixes #823
  • Loading branch information
mattwynne committed Apr 1, 2015
1 parent 77fd22a commit e92917c
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/cucumber/running_test_case.rb
Expand Up @@ -19,7 +19,7 @@ module Cucumber
# you get a couple of extra methods.
module RunningTestCase
def self.new(test_case)
Builder.new(test_case).result
Builder.new(test_case).running_test_case
end

class Builder
Expand All @@ -45,7 +45,7 @@ def examples_table(examples_table)
def examples_table_row(row)
end

def result
def running_test_case
@factory.new(@test_case)
end
end
Expand All @@ -62,6 +62,11 @@ def accept_hook?(hook)
hook.tag_expressions.all? { |expression| @test_case.match_tags?(expression) }
end

def exception
return unless @result.failed?
@result.exception
end

def failed?
@result.failed?
end
Expand Down
50 changes: 50 additions & 0 deletions spec/cucumber/running_test_case_spec.rb
Expand Up @@ -44,6 +44,56 @@ module Cucumber
end
end

context "for a failed scenario" do
let(:gherkin_doc) do
gherkin do
feature "feature name" do
scenario "scenario name" do
step "failed"
end
end
end
end

let(:exception) { StandardError.new }

before do
self.wrapped_test_case = self.wrapped_test_case.with_result(Core::Test::Result::Failed.new(0, exception))
end

it "is failed?" do
expect(wrapped_test_case.failed?).to be_truthy
end

it "exposes the exception" do
expect(wrapped_test_case.exception).to eq exception
end
end

context "for a passing scenario" do
let(:gherkin_doc) do
gherkin do
feature "feature name" do
scenario "scenario name" do
step "passing"
end
end
end
end

before do
self.wrapped_test_case = self.wrapped_test_case.with_result(Core::Test::Result::Passed.new(0))
end

it "is not failed?" do
expect(wrapped_test_case.failed?).to be_falsey
end

it "#exception is nil" do
expect(wrapped_test_case.exception).to be_nil
end
end

context "for a scenario outline" do
let(:gherkin_doc) do
gherkin do
Expand Down

0 comments on commit e92917c

Please sign in to comment.