-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add event to broadcast all test cases
- Loading branch information
Showing
7 changed files
with
116 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
Feature: Test Run Starting Event | ||
|
||
This event is fired once all test cases have been filtered, just before | ||
the first one is executed. | ||
|
||
See [the API documentation](http://www.rubydoc.info/github/cucumber/cucumber-ruby/Cucumber/Events/TestRunStarting) for more information about the data available on this event. | ||
|
||
Background: | ||
Given the standard step definitions | ||
And a file named "features/foo.feature" with: | ||
""" | ||
Feature: Foo | ||
Scenario: | ||
Given a passing step | ||
""" | ||
And a file named "features/bar.feature" with: | ||
""" | ||
Feature: Foo | ||
Scenario: | ||
Given a passing step | ||
""" | ||
And a file named "features/support/events.rb" with: | ||
""" | ||
AfterConfiguration do |config| | ||
config.on_event :test_run_starting do |event| | ||
config.out_stream.puts "test run starting" | ||
config.out_stream.puts event.test_cases.map(&:location) | ||
end | ||
end | ||
""" | ||
|
||
Scenario: Run the test case | ||
When I run `cucumber -q` | ||
Then it should pass with: | ||
""" | ||
test run starting | ||
features/bar.feature:2 | ||
features/foo.feature:2 | ||
""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
require 'cucumber/core/events' | ||
|
||
module Cucumber | ||
module Events | ||
|
||
# Event fired once all test cases have been filtered before | ||
# the first one is executed. | ||
class TestRunStarting < Core::Event.new(:test_cases) | ||
|
||
# @return [Array<Cucumber::Core::Test::Case>] the test cases to be executed | ||
attr_reader :test_cases | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
module Cucumber | ||
module Filters | ||
# Added at the end of the filter chain to broadcast a list of | ||
# all of the test cases that have made it through the filters. | ||
class BroadcastTestRunStartingEvent < Core::Filter.new(:config) | ||
def initialize(config, receiver=nil) | ||
super | ||
@test_cases = [] | ||
end | ||
|
||
def test_case(test_case) | ||
@test_cases << test_case | ||
self | ||
end | ||
|
||
def done | ||
config.notify :test_run_starting, @test_cases | ||
@test_cases.map do |test_case| | ||
test_case.describe_to(@receiver) | ||
end | ||
super | ||
self | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require 'securerandom' | ||
|
||
module Cucumber | ||
module Formatter | ||
class EventStream | ||
|
||
def initialize(config) | ||
@config, @io = config, config.out_stream | ||
@series = SecureRandom.uuid | ||
write_event type: "start" | ||
config.on_event :test_case_finished, -> (event) { | ||
write_event type: "test-case-finished", location: event.test_case.location, result: event.result.to_sym.to_s | ||
} | ||
end | ||
|
||
private | ||
|
||
def write_event(attributes) | ||
data = attributes.merge({ | ||
series: @series, | ||
timestamp: Time.now.to_i | ||
}) | ||
@io.puts data.to_json | ||
end | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters