Skip to content

Commit

Permalink
0.6.1: Improves rspec support
Browse files Browse the repository at this point in the history
- Fixes newlines in backtraces
- Find more screenshots
- More tests
  • Loading branch information
davidwessman committed Feb 27, 2022
1 parent 8e414ce commit fa71905
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 13 deletions.
12 changes: 10 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
21 changes: 13 additions & 8 deletions lib/blinka_reporter/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion lib/blinka_reporter/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module BlinkaReporter
VERSION = '0.6.0'.freeze
VERSION = '0.6.1'.freeze
end
4 changes: 2 additions & 2 deletions test/rspec.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ expected: "what"
<failure message="expected to find text &quot;Hello world&quot; in &quot;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.&quot;" type="RSpec::Expectations::ExpectationNotMetError">Failure/Error: expect(page).to have_content(&quot;Hello world&quot;)
expected to find text &quot;Hello world&quot; in &quot;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.&quot;

[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 &lt;main&gt;&apos;</failure>
Expand All @@ -85,7 +85,7 @@ expected: &quot;what&quot;
NameError:
undefined local variable or method `invalid_code&apos; for #&lt;RSpec::ExampleGroups::SignIn:0x00007fdd90d6bf08&gt;

[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 &lt;main&gt;&apos;</failure>
Expand Down
24 changes: 24 additions & 0 deletions test/test_parsing.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit fa71905

Please sign in to comment.