diff --git a/CHANGELOG.md b/CHANGELOG.md index f49e0da..32c6a21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.6.1] - 2022-02-27 + +- Rspec + - Improve handling of newlines in backtrace + - Adds more testing + - Handles multiple screenshot tags + ## [0.6.0] - 2022-02-20 - Adds support for Rspec. @@ -130,8 +137,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Handle inconsistency in source_location of test result in Minitest for different versions. -[unreleased]: https://github.com/davidwessman/blinka_reporter/compare/v0.6.0...HEAD -[0.5.2]: https://github.com/davidwessman/blinka_reporter/compare/v0.5.2...v0.6.0 +[unreleased]: https://github.com/davidwessman/blinka_reporter/compare/v0.6.1...HEAD +[0.6.1]: https://github.com/davidwessman/blinka_reporter/compare/v0.6.0...v0.6.1 +[0.6.0]: https://github.com/davidwessman/blinka_reporter/compare/v0.5.2...v0.6.0 [0.5.2]: https://github.com/davidwessman/blinka_reporter/compare/v0.5.1...v0.5.2 [0.5.1]: https://github.com/davidwessman/blinka_reporter/compare/v0.5.0...v0.5.1 [0.5.0]: https://github.com/davidwessman/blinka_reporter/compare/v0.4.0...v0.5.0 diff --git a/lib/blinka_reporter/client.rb b/lib/blinka_reporter/client.rb index ce47225..fac6ce4 100644 --- a/lib/blinka_reporter/client.rb +++ b/lib/blinka_reporter/client.rb @@ -86,9 +86,11 @@ def self.xml_test_cases(test_cases) failure = test_case.nodes.select { |node| node.name == 'failure' }.first if failure - result[:image] = get_image_path(failure.text) result[:result] = 'fail' - result[:backtrace] = failure.text.split('\n') + + # Needs to be double quotation marks to work properly + result[:backtrace] = failure.text.split("\n") + result[:image] = get_image_path(result[:backtrace]) result[:message] = failure.attributes[:message] end else @@ -98,12 +100,15 @@ def self.xml_test_cases(test_cases) end end - def self.get_image_path(text) - path = /^\[Screenshot\]:\s([\S]*)$/.match(text) - return if path.nil? - path = path[1] - return unless File.exists?(path) - path + def self.get_image_path(backtrace) + backtrace.each do |text| + path = /^(\[Screenshot\]|\[Screenshot Image\]):\s([\S]*)$/.match(text) + next if path.nil? + path = path[-1] + next unless File.exist?(path) + return path + end + nil end end end diff --git a/lib/blinka_reporter/version.rb b/lib/blinka_reporter/version.rb index 1556448..0513f48 100644 --- a/lib/blinka_reporter/version.rb +++ b/lib/blinka_reporter/version.rb @@ -1,3 +1,3 @@ module BlinkaReporter - VERSION = '0.6.0'.freeze + VERSION = '0.6.1'.freeze end diff --git a/test/rspec.xml b/test/rspec.xml index f1c3444..c762cf1 100644 --- a/test/rspec.xml +++ b/test/rspec.xml @@ -70,7 +70,7 @@ expected: "what" Failure/Error: expect(page).to have_content("Hello world") expected to find text "Hello world" in "Hem\nKarta\nOm oss\nAnslut företag\nLogga in\nLogga in på ditt konto\nHar du inget konto? Anslut idag!\nEmail\nPassword\nGlömt lösenord?\nEtt Ställe Där Du Kan Hitta Certiferade Kontrollansvariga\nLÄNKAR\nKarta\nKontakt\nAnslut företag\nOm oss\nLogga in\nApti.se © 2020. All rights reserved." -[Screenshot]: ./spec/tmp/screenshots/failures_r_spec_example_groups_sign_in_failure_200.png +[Screenshot Image]: ./test/tmp/screenshots/failures_r_spec_example_groups_sign_in_failure_200.png ./spec/system/sign_in_spec.rb:12:in `block (2 levels) in <main>' @@ -85,7 +85,7 @@ expected: "what" NameError: undefined local variable or method `invalid_code' for #<RSpec::ExampleGroups::SignIn:0x00007fdd90d6bf08> -[Screenshot]: ./spec/tmp/screenshots/failures_r_spec_example_groups_sign_in_error_848.png +[Screenshot]: ./test/tmp/screenshots/failures_r_spec_example_groups_sign_in_error_848.png ./spec/system/sign_in_spec.rb:27:in `block (2 levels) in <main>' diff --git a/test/test_parsing.rb b/test/test_parsing.rb new file mode 100644 index 0000000..f2ddc01 --- /dev/null +++ b/test/test_parsing.rb @@ -0,0 +1,24 @@ +require 'minitest/autorun' +require 'mocha/minitest' + +require 'blinka_reporter/client' + +class BlinkaParsingTest < Minitest::Test + def test_parse_xml + data = BlinkaReporter::Client.parse_xml(path: 'test/rspec.xml') + + assert_equal(54, data[:results].size) + + first_failure = data[:results][50] + refute_nil(first_failure) + assert_equal('fail', first_failure[:result]) + assert_equal(7, first_failure[:backtrace].size) + refute_nil(first_failure[:image]) + + last_failure = data[:results][53] + refute_nil(last_failure) + assert_equal('fail', last_failure[:result]) + assert_equal(9, last_failure[:backtrace].size) + refute_nil(last_failure[:image]) + end +end