Skip to content

Commit

Permalink
Extend the API of Cucumber::Core::Test::Result::Summary.
Browse files Browse the repository at this point in the history
When you have the status, it is easier to pass it as argument to the
Summary#total method, than to calculate which Summary#total_<status>
method to call.
  • Loading branch information
brasmusson committed May 8, 2016
1 parent 432bae9 commit e7fb8b7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
8 changes: 6 additions & 2 deletions lib/cucumber/core/test/result.rb
Expand Up @@ -227,8 +227,12 @@ def duration(duration)
self
end

def total
@totals.reduce(0) { |total, status| total += status[1] }
def total(for_status = nil)
if for_status
@totals.fetch(for_status) { 0 }
else
@totals.reduce(0) { |total, status| total += status[1] }
end
end

private
Expand Down
31 changes: 19 additions & 12 deletions spec/cucumber/core/test/result_spec.rb
Expand Up @@ -253,26 +253,30 @@ module Cucumber::Core::Test

it "counts failed results" do
failed.describe_to summary
expect( summary.total_failed ).to eq 1
expect( summary.total ).to eq 1
expect( summary.total_failed ).to eq 1
expect( summary.total(:failed) ).to eq 1
expect( summary.total ).to eq 1
end

it "counts passed results" do
passed.describe_to summary
expect( summary.total_passed ).to eq 1
expect( summary.total ).to eq 1
expect( summary.total_passed ).to eq 1
expect( summary.total(:passed) ).to eq 1
expect( summary.total ).to eq 1
end

it "counts skipped results" do
skipped.describe_to summary
expect( summary.total_skipped ).to eq 1
expect( summary.total ).to eq 1
expect( summary.total_skipped ).to eq 1
expect( summary.total(:skipped) ).to eq 1
expect( summary.total ).to eq 1
end

it "counts undefined results" do
undefined.describe_to summary
expect( summary.total_undefined ).to eq 1
expect( summary.total ).to eq 1
expect( summary.total_undefined ).to eq 1
expect( summary.total(:undefined) ).to eq 1
expect( summary.total ).to eq 1
end

it "counts abitrary raisable results" do
Expand All @@ -283,13 +287,16 @@ def describe_to(visitor, *args)
end

flickering.new.describe_to summary
expect( summary.total_flickering ).to eq 1
expect( summary.total ).to eq 1
expect( summary.total_flickering ).to eq 1
expect( summary.total(:flickering) ).to eq 1
expect( summary.total ).to eq 1
end

it "returns zero for a status where no messges have been received" do
expect( summary.total_passed ).to eq 0
expect( summary.total_ponies ).to eq 0
expect( summary.total_passed ).to eq 0
expect( summary.total(:passed) ).to eq 0
expect( summary.total_ponies ).to eq 0
expect( summary.total(:ponies) ).to eq 0
end

it "doesn't count unknown results" do
Expand Down

0 comments on commit e7fb8b7

Please sign in to comment.