Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor/fix up jUnit tests #1749

Merged
merged 2 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/cucumber/formatter/junit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def on_test_case_finished(event)
end

def on_test_run_finished(_event)
@features_data.each { |_file, data| end_feature(data) }
@features_data.each_value { |data| end_feature(data) }
end

private
Expand Down
142 changes: 72 additions & 70 deletions spec/cucumber/formatter/junit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,19 @@ def write_file(feature_filename, data)
end

define_steps do
Given(/a passing scenario/) do
Given('a passing scenario') do
Kernel.puts 'foo'
end
end

define_feature <<-FEATURE
Feature: One passing feature
define_feature <<~FEATURE
Feature: One passing feature

Scenario: Passing
Given a passing scenario
Scenario: Passing
Given a passing scenario
FEATURE

it 'will contain the file attribute' do
expect(@doc.xpath('//testsuite/testcase/@file').size).to equal 1
expect(@doc.xpath('//testsuite/testcase/@file').first.value).to eq('spec.feature')
end
end
Expand All @@ -93,20 +92,20 @@ def write_file(feature_filename, data)
end

define_steps do
Given(/a passing scenario/) do
Given('a passing scenario') do
Kernel.puts 'foo'
end
end

define_feature <<-FEATURE
Feature: One passing feature
define_feature <<~FEATURE
Feature: One passing feature

Scenario: Passing
Given a passing scenario
Scenario: Passing
Given a passing scenario
FEATURE

it 'will not contain the file attribute' do
expect(@doc.xpath('//testsuite/testcase/@file').size).to equal 0
expect(@doc.xpath('//testsuite/testcase/@file')).to be_empty
end
end
end
Expand All @@ -124,20 +123,20 @@ def write_file(feature_filename, data)
end

define_steps do
Given(/a passing scenario/) do
Given('a passing scenario') do
Kernel.puts 'foo'
end
end

define_feature <<-FEATURE
Feature: One passing scenario
define_feature <<~FEATURE
Feature: One passing feature

Scenario: Passing
Given a passing scenario
Scenario: Passing
Given a passing scenario
FEATURE

it 'will not contain the file attribute' do
expect(@doc.xpath('//testsuite/testcase/@file').size).to equal 0
expect(@doc.xpath('//testsuite/testcase/@file')).to be_empty
end
end
end
Expand All @@ -155,23 +154,23 @@ def write_file(feature_filename, data)
end

define_steps do
Given(/a passing ctrl scenario/) do
Given('a passing ctrl scenario') do
Kernel.puts "boo\b\cx\e\a\f boo "
end
end

define_feature <<-FEATURE
Feature: One passing scenario, one failing scenario
define_feature <<~FEATURE
Feature: One passing scenario, one failing scenario

Scenario: Passing
Given a passing ctrl scenario
Scenario: Passing
Given a passing ctrl scenario
FEATURE

it { expect(@doc.xpath('//testsuite/testcase/system-out').first.content).to match(/\s+boo boo\s+/) }
end

describe 'a feature with no name' do
define_feature <<-FEATURE
define_feature <<~FEATURE
Feature:
Scenario: Passing
Given a passing scenario
Expand All @@ -189,7 +188,7 @@ def write_file(feature_filename, data)
end

describe 'with a single scenario' do
define_feature <<-FEATURE
define_feature <<~FEATURE
Feature: One passing scenario, one failing scenario

Scenario: Passing
Expand All @@ -199,19 +198,19 @@ def write_file(feature_filename, data)
it { expect(@doc.to_s).to match(/One passing scenario, one failing scenario/) }

it 'has not a root system-out node' do
expect(@doc.xpath('//testsuite/system-out').size).to eq 0
expect(@doc.xpath('//testsuite/system-out')).to be_empty
end

it 'has not a root system-err node' do
expect(@doc.xpath('//testsuite/system-err').size).to eq 0
expect(@doc.xpath('//testsuite/system-err')).to be_empty
end

it 'has a system-out node under <testcase/>' do
expect(@doc.xpath('//testcase/system-out').size).to eq 1
expect(@doc.xpath('//testcase/system-out').length).to eq(1)
end

it 'has a system-err node under <testcase/>' do
expect(@doc.xpath('//testcase/system-err').size).to eq 1
expect(@doc.xpath('//testcase/system-err').length).to eq(1)
end
end

Expand All @@ -224,44 +223,45 @@ def write_file(feature_filename, data)
), File.join('features', 'some', 'path', 'spec.feature')

it 'writes the filename with absolute path' do
expect(@formatter.written_files.keys.first).to eq File.absolute_path('TEST-features-some-path-spec.xml')
expect(@formatter.written_files.keys.first).to eq(File.absolute_path('TEST-features-some-path-spec.xml'))
end
end

describe 'with a scenario outline table' do
define_steps do
Given(/.*/) {}
Given('{word}') {}
end

define_feature <<-FEATURE
define_feature <<~FEATURE
Feature: Eat things when hungry

Scenario Outline: Eat things
Given <Things>
Scenario Outline: Eat variety of things
Given <things>
And stuff:
| foo |
| bar |

Examples: Good
| Things |
| things |
| Cucumber |
| Whisky |

Examples: Evil
| Things |
| Big Mac |
| things |
| Burger |
| Whisky |
FEATURE

it { expect(@doc.to_s).to match(/Eat things when hungry/) }
it { expect(@doc.to_s).to match(/Cucumber/) }
it { expect(@doc.to_s).to match(/Burger/) }
it { expect(@doc.to_s).to match(/Whisky/) }
it { expect(@doc.to_s).to match(/Big Mac/) }
it { expect(@doc.to_s).not_to match(/Things/) }
it { expect(@doc.to_s).not_to match(/Cake/) }
it { expect(@doc.to_s).not_to match(/Good|Evil/) }
it { expect(@doc.to_s).not_to match(/type="skipped"/) }
end

describe 'scenario with skipped test in junit report' do
define_feature <<-FEATURE
define_feature <<~FEATURE
Feature: junit report with skipped test

Scenario Outline: skip a test and junit report of the same
Expand All @@ -283,7 +283,7 @@ def write_file(feature_filename, data)
Then(/I should have visited at least/) { |table| }
end

define_feature <<-FEATURE
define_feature <<~FEATURE
Feature: Shortlist

Scenario: Procure items
Expand All @@ -306,14 +306,15 @@ def write_file(feature_filename, data)
Before do
raise 'Before hook failed'
end
Given(/a passing step/) do
Given('a passing step') do
end
end
define_feature <<-FEATURE
Feature: One passing scenario

Scenario: Passing
Given a passing step
define_feature <<~FEATURE
Feature: One passing scenario

Scenario: Passing
Given a passing step
FEATURE

it { expect(@doc.to_s).to match(/Before hook at spec\/cucumber\/formatter\/junit_spec.rb:(\d+)/) }
Expand All @@ -324,14 +325,14 @@ def write_file(feature_filename, data)
After do
raise 'After hook failed'
end
Given(/a passing step/) do
Given('a passing step') do
end
end
define_feature <<-FEATURE
Feature: One passing scenario
define_feature <<~FEATURE
Feature: One passing scenario

Scenario: Passing
Given a passing step
Scenario: Passing
Given a passing step
FEATURE

it { expect(@doc.to_s).to match(/After hook at spec\/cucumber\/formatter\/junit_spec.rb:(\d+)/) }
Expand All @@ -342,14 +343,14 @@ def write_file(feature_filename, data)
AfterStep do
raise 'AfterStep hook failed'
end
Given(/a passing step/) do
Given('a passing step') do
end
end
define_feature <<-FEATURE
Feature: One passing scenario
define_feature <<~FEATURE
Feature: One passing scenario

Scenario: Passing
Given a passing step
Scenario: Passing
Given a passing step
FEATURE

it { expect(@doc.to_s).to match(/AfterStep hook at spec\/cucumber\/formatter\/junit_spec.rb:(\d+)/) }
Expand All @@ -361,14 +362,14 @@ def write_file(feature_filename, data)
block.call
raise 'Around hook failed'
end
Given(/a passing step/) do
Given('a passing step') do
end
end
define_feature <<-FEATURE
Feature: One passing scenario
define_feature <<~FEATURE
Feature: One passing scenario

Scenario: Passing
Given a passing step
Scenario: Passing
Given a passing step
FEATURE

it { expect(@doc.to_s).to match(/Around hook\n\nMessage:/) }
Expand All @@ -393,31 +394,32 @@ def write_file(feature_filename, data)

describe 'with a scenario outline table' do
define_steps do
Given(/.*/) {}
Given('{word}') {}
end

define_feature <<-FEATURE
define_feature <<~FEATURE
Feature: Eat things when hungry

Scenario Outline: Eat things
Given <Things>
Given <things>
And stuff:
| foo |
| bar |

Examples: Good
| Things |
| things |
| Cucumber |
| Whisky |

Examples: Evil
| Things |
| Big Mac |
| things |
| Burger |
| Whisky |
FEATURE

it { expect(@doc.to_s).to match(/Eat things when hungry/) }
it { expect(@doc.to_s).to match(/Cucumber/) }
it { expect(@doc.to_s).to match(/Whisky/) }
it { expect(@doc.to_s).to match(/Big Mac/) }
it { expect(@doc.to_s).to match(/Burger/) }
it { expect(@doc.to_s).not_to match(/Things/) }
it { expect(@doc.to_s).not_to match(/Good|Evil/) }
it { expect(@doc.to_s).not_to match(/type="skipped"/) }
Expand Down