test-output-parser 0.3.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 62e8801a738f5c54e2a87b487b5ed1de94801b75
4
- data.tar.gz: e130c6f72a8fcafb778c911ca68a8b3e3a9e7e2a
3
+ metadata.gz: 57d6d46a7aec97fc80f06fa6e75cf2f60cb4a5e2
4
+ data.tar.gz: b03073bd93e4f42b9771e97e5e1d5ae4cc4ef2d9
5
5
  SHA512:
6
- metadata.gz: 37e20fec72155d567da774fed81bae22c5779d14f0b47d0980ee6ee7ee7769baebcd99f4d98260edb6c0ad524a2dfe508680205fc2cb1efac22fa93ac8f71ae5
7
- data.tar.gz: 51f36e46f9688610415b9f186f2affb269c54ecd44d75edc31e1a2101cab6eee83f8e2c35f09fde23d1563d72441e631317a5acf1a493ee9d9a5e6055f8b4741
6
+ metadata.gz: df7e25944c3b9a21dfd0b06bc98921e2d2343df86a93d3e541b1bb9be2da4bddf679ef81ca63f89ebcbe4e87c2dcbb0593f3457be8cce0984d418982edb5b904
7
+ data.tar.gz: b7ec27e97035a563a4eb1a902ba53431156fcd189920943a8b05b2609bcb5675871c07a58a7a4eeeb68dc3b4ddf2eef830f7236b66cf9144c684a83be1ef4f6d
data/.gitignore CHANGED
@@ -3,7 +3,6 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
- Gemfile.lock
7
6
  InstalledFiles
8
7
  _yardoc
9
8
  coverage
data/.ruby-gemset CHANGED
@@ -1 +1 @@
1
- test-count
1
+ test-output-parser
data/Gemfile.lock ADDED
@@ -0,0 +1,34 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ test-output-parser (0.4.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.2.5)
10
+ rake (10.3.2)
11
+ rspec (3.1.0)
12
+ rspec-core (~> 3.1.0)
13
+ rspec-expectations (~> 3.1.0)
14
+ rspec-mocks (~> 3.1.0)
15
+ rspec-core (3.1.7)
16
+ rspec-support (~> 3.1.0)
17
+ rspec-expectations (3.1.2)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.1.0)
20
+ rspec-mocks (3.1.3)
21
+ rspec-support (~> 3.1.0)
22
+ rspec-support (3.1.2)
23
+
24
+ PLATFORMS
25
+ ruby
26
+
27
+ DEPENDENCIES
28
+ bundler (~> 1.3)
29
+ rake
30
+ rspec
31
+ test-output-parser!
32
+
33
+ BUNDLED WITH
34
+ 1.11.1
data/README.md CHANGED
@@ -1,12 +1,14 @@
1
- # Test::Count
1
+ [![Build Status](https://snap-ci.com/snap-ci/test-output-parser/branch/master/build_image)](https://snap-ci.com/snap-ci/test-output-parser/branch/master)
2
2
 
3
- TODO: Write a gem description
3
+ # TestOutputParser
4
+
5
+ Parses common test output formats (RSpec, Test::Unit, JUnit) and provides a way to extract information out of it.
4
6
 
5
7
  ## Installation
6
8
 
7
9
  Add this line to your application's Gemfile:
8
10
 
9
- gem 'test-count'
11
+ gem 'test-output-parser'
10
12
 
11
13
  And then execute:
12
14
 
@@ -14,7 +16,7 @@ And then execute:
14
16
 
15
17
  Or install it yourself as:
16
18
 
17
- $ gem install test-count
19
+ $ gem install test-output-parser
18
20
 
19
21
  ## Usage
20
22
 
@@ -22,7 +24,7 @@ TODO: Write usage instructions here
22
24
 
23
25
  ## Contributing
24
26
 
25
- 1. Fork it ( http://github.com/<my-github-username>/test-count/fork )
27
+ 1. Fork it ( http://github.com/snap-ci/test-output-parser/fork )
26
28
  2. Create your feature branch (`git checkout -b my-new-feature`)
27
29
  3. Commit your changes (`git commit -am 'Add some feature'`)
28
30
  4. Push to the branch (`git push origin my-new-feature`)
@@ -1,10 +1,66 @@
1
1
  require 'test_output_parser/version'
2
2
  require 'test_output_parser/framework'
3
+ require 'stringio'
3
4
 
4
5
  module TestOutputParser
6
+
7
+ class Summary
8
+
9
+ ATTRIBUTES = %w(total failed errors pending)
10
+
11
+ ATTRIBUTES.each do |suffix|
12
+ class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
13
+ attr_accessor :#{suffix}
14
+
15
+ def add_#{suffix}(to_add)
16
+ self.#{suffix} += to_add
17
+ end
18
+
19
+ def #{suffix}
20
+ @#{suffix} ||= 0
21
+ end
22
+
23
+ RUBY_EVAL
24
+ end
25
+
26
+ def add_failure_lines(lines)
27
+ return unless lines
28
+ return if lines.respond_to?(:empty?) && lines.empty?
29
+ if lines.respond_to?(:to_str)
30
+ self.failures << lines
31
+ else
32
+ self.failures << lines.join
33
+ end
34
+ end
35
+
36
+ def failures
37
+ @failures ||= StringIO.new
38
+ end
39
+
40
+ def to_hash
41
+ result = {}
42
+ ATTRIBUTES.each do |attr|
43
+ next if self.send(attr) == 0
44
+ result[attr.to_sym] = self.send(attr)
45
+ end
46
+
47
+ if failures.size != 0
48
+ result[:failures] = failures.string
49
+ end
50
+
51
+ result
52
+ end
53
+
54
+ end
55
+
5
56
  def self.count(test_output)
6
- summary = TestOutputParser::Framework::RSpec.count(test_output)
57
+ summary = Summary.new
58
+ test_output = test_output.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
59
+
60
+ TestOutputParser::Framework::RSpec.count(test_output, summary)
7
61
  TestOutputParser::Framework::TestUnit.count(test_output, summary)
8
62
  TestOutputParser::Framework::JUnit.count(test_output, summary)
63
+
64
+ summary.to_hash
9
65
  end
10
- end
66
+ end
@@ -1,30 +1,33 @@
1
1
  module TestOutputParser
2
2
  module Framework
3
3
  class JUnit
4
- def self.count(test_output, summary=Hash.new(0))
4
+ def self.count(test_output, summary=Summary.new)
5
+ # normal junit
5
6
  test_output.scan(/Running\s+.*$\nTest[s]?\s+run:\s+(\d+),\s+Failure[s]?:\s+(\d+),\s+Error[s]?:\s+(\d+),\s+Skipped:\s+(\d+)/).each do |arr|
6
- summary[:total] += arr[0].to_i
7
- summary[:failed] += arr[1].to_i
8
- summary[:errors] += arr[2].to_i
9
- summary[:pending] += arr[3].to_i
7
+ summary.add_total arr[0].to_i
8
+ summary.add_failed arr[1].to_i
9
+ summary.add_errors arr[2].to_i
10
+ summary.add_pending arr[3].to_i
10
11
  end
11
12
 
12
- failures = test_output.match(/^Failed\stests:\s+(.+\n)+\n/)
13
- summary[:failures] = failures.to_s.strip if failures
14
-
13
+ # junit on gradle
15
14
  test_output.scan(/(\d+)\s+test[s]?\s+completed,\s+(\d+)\s+failed/).each do |arr|
16
- summary[:total] += arr[0].to_i
17
- summary[:failed] += arr[1].to_i
15
+ summary.add_total arr[0].to_i
16
+ summary.add_failed arr[1].to_i
18
17
  end
19
18
 
20
- failures = test_output.scan(/^Running\stest:\s.*\n\n.*\s+FAILED\n.*/)
21
- if summary.has_key?(:failures)
22
- summary[:failures] = summary[:failures].join(failures.join("\n")) unless failures.empty?
23
- else
24
- summary[:failures] = failures.join("\n") unless failures.empty?
19
+ # normal junit
20
+ failures = test_output.scan(/^(Failed\stests:\s+.*)^Tests run/m)
21
+ summary.add_failure_lines(failures)
22
+
23
+ # gradle junit errors
24
+ if failures.empty?
25
+ failures = test_output.scan(/^Running\stest:\s.*\n\n.*\s+FAILED\n.*/)
26
+ summary.add_failure_lines(failures)
25
27
  end
28
+
26
29
  summary
27
30
  end
28
31
  end
29
32
  end
30
- end
33
+ end
@@ -1,17 +1,17 @@
1
1
  module TestOutputParser
2
2
  module Framework
3
3
  class RSpec
4
- def self.count(test_output, summary=Hash.new(0))
4
+ def self.count(test_output, summary=Summary.new)
5
5
  test_output.scan(/(\d+)\s+example[s]?,\s+(\d+)\s+failure[s]?(,\s*(\d+)\s+pending)?/).each do |arr|
6
- summary[:total] += arr[0].to_i
7
- summary[:failed] += arr[1].to_i
8
- summary[:pending] += arr[3].to_i
6
+ summary.add_total arr[0].to_i
7
+ summary.add_failed arr[1].to_i
8
+ summary.add_pending arr[3].to_i
9
9
  end
10
- failures = test_output.scan(/Failures:\n+(.*)Finished in/m)
11
- summary[:failures] = failures.flatten.first.strip unless failures.empty?
12
10
 
11
+ failures = test_output.scan(/Failures:\n+(.*)^Finished in/m)
12
+ summary.add_failure_lines(failures)
13
13
  summary
14
14
  end
15
15
  end
16
16
  end
17
- end
17
+ end
@@ -1,19 +1,20 @@
1
1
  module TestOutputParser
2
2
  module Framework
3
3
  class TestUnit
4
- def self.count(test_output, summary=Hash.new(0))
4
+ def self.count(test_output, summary=Summary.new)
5
5
  test_output.scan(/(\d+)\s+test[s]?,\s+(\d+)\s+assertion[s]?(,\s*(\d+)\s+failures)?(,\s*(\d+)\s+error[s]?)?(,\s*(\d+)\s+skip[s]?)?/).each do |arr|
6
- summary[:total] += arr[0].to_i
7
- #summary[:assertions] += arr[1].to_i
8
- summary[:failed] += arr[3].to_i
9
- summary[:errors] += arr[5].to_i
10
- summary[:pending] += arr[7].to_i
6
+ summary.add_total arr[0].to_i
7
+ summary.add_failed arr[3].to_i
8
+ summary.add_errors arr[5].to_i
9
+ summary.add_pending arr[7].to_i
11
10
  end
12
11
 
13
- failures = test_output.scan(/(^\s+\d\)\sFailure:\n+.*)+\d+\stests/m)
14
- summary[:failures] = failures.flatten.first.strip unless failures.empty?
12
+
13
+ failures = test_output.scan(/(^\s+\d+\)\sFailure:\n+.*)+\n\n^\d+\stests/m)
14
+ summary.add_failure_lines(failures)
15
+
15
16
  summary
16
17
  end
17
18
  end
18
19
  end
19
- end
20
+ end
@@ -1,3 +1,3 @@
1
1
  module TestOutputParser
2
- VERSION = "0.3.0"
3
- end
2
+ VERSION = '0.4.1'
3
+ end
@@ -1,20 +1,42 @@
1
- $ bundle exec rake test
2
- /opt/local/ruby/1.9.3-p484/bin/ruby -I"lib:test" -I"/opt/local/ruby/1.9.3-p484/lib/ruby/1.9.1" "/opt/local/ruby/1.9.3-p484/lib/ruby/1.9.1/rake/rake_test_loader.rb" "test/foo_test.rb"
3
- Run options:
1
+ $ rake test
2
+ /opt/local/ruby/1.9.3-p484/bin/ruby -I"lib:test" -I"/opt/local/ruby/1.9.3-p484/lib/ruby/1.9.1" "/opt/local/ruby/1.9.3-p484/lib/ruby/1.9.1/rake/rake_test_loader.rb" "test/packages/python_test.rb" "test/packages/nodejs_test.rb" "test/packages/heroku_toolbelt_test.rb" "test/packages/java_test.rb" "test/packages/npm_test.rb" "test/packages/aws_elastic_beanstalk_test.rb" "test/packages/xvfb_test.rb" "test/packages/sbt_test.rb" "test/packages/ruby_test.rb" "test/packages/ant_test.rb" "test/packages/terraform_test.rb" "test/packages/s3cmd_test.rb" "test/packages/maven_test.rb" "test/packages/php_test.rb" "test/packages/snap_deploy_test.rb" "test/packages/foreman_test.rb" "test/packages/lein_test.rb" "test/packages/android_test.rb" "test/packages/gradle_test.rb" "test/packages/awscli_test.rb" "test/user_environment_test.rb" "test/sudo_access_test.rb" "test/nosql/redis_test.rb" "test/nosql/couchdb_test.rb" "test/nosql/mongodb_test.rb" "test/relational_db/postgres_test.rb" "test/relational_db/sqlite_test.rb" "test/relational_db/mysql_test.rb" "test/environment_variables_test.rb"
3
+ Run options: --seed 13016
4
4
 
5
5
  # Running tests:
6
6
 
7
- .FF
7
+ .........................................................................FE....................
8
8
 
9
- Finished tests in 0.000557s, 1793.7831 tests/s, 1793.7831 assertions/s.
9
+ Finished tests in 48.599332s, 1.9548 tests/s, 5.2676 assertions/s.
10
10
 
11
11
  1) Failure:
12
- test_passes(FooTest) [/var/go/repo/test/foo_test.rb:5]:
13
- Failed assertion, no message given.
12
+ test_no_additional_rubies(RubyTest) [/var/snap-ci/repo/test/packages/ruby_test.rb:23]:
13
+ --- expected
14
+ +++ actual
15
+ @@ -1 +1 @@
16
+ -["foo", "bar"]
17
+ +["baz", "boo"]
14
18
 
15
- 2) Failure:
16
- test_passes(FooTest) [/var/go/repo/test/foo_test.rb:10]:
17
- Failed assertion, no message given.
18
19
 
19
- 3 tests, 3 assertions, 2 failures, 0 errors, 0 skips
20
- rake aborted!
20
+ 2) Error:
21
+ test_rubies_are_installed(RubyTest):
22
+ Errno::ENOENT: No such file or directory - /opt/local/ruby/2.1.4/bin/ruby --version
23
+ /tmp/.bundle-repo/ruby/1.9.1/gems/mixlib-shellout-1.2.0/lib/mixlib/shellout/unix.rb:268:in `exec'
24
+ /tmp/.bundle-repo/ruby/1.9.1/gems/mixlib-shellout-1.2.0/lib/mixlib/shellout/unix.rb:268:in `block in fork_subprocess'
25
+ /tmp/.bundle-repo/ruby/1.9.1/gems/mixlib-shellout-1.2.0/lib/mixlib/shellout/unix.rb:256:in `fork'
26
+ /tmp/.bundle-repo/ruby/1.9.1/gems/mixlib-shellout-1.2.0/lib/mixlib/shellout/unix.rb:256:in `fork_subprocess'
27
+ /tmp/.bundle-repo/ruby/1.9.1/gems/mixlib-shellout-1.2.0/lib/mixlib/shellout/unix.rb:40:in `run_command'
28
+ /tmp/.bundle-repo/ruby/1.9.1/gems/mixlib-shellout-1.2.0/lib/mixlib/shellout.rb:225:in `run_command'
29
+ /var/snap-ci/repo/test/mini_test_helper.rb:28:in `block in run_command'
30
+ /opt/local/ruby/1.9.3-p484/lib/ruby/gems/1.9.1/gems/bundler-1.6.3/lib/bundler.rb:235:in `block in with_clean_env'
31
+ /opt/local/ruby/1.9.3-p484/lib/ruby/gems/1.9.1/gems/bundler-1.6.3/lib/bundler.rb:222:in `with_original_env'
32
+ /opt/local/ruby/1.9.3-p484/lib/ruby/gems/1.9.1/gems/bundler-1.6.3/lib/bundler.rb:228:in `with_clean_env'
33
+ /var/snap-ci/repo/test/mini_test_helper.rb:23:in `run_command'
34
+ /var/snap-ci/repo/test/packages/ruby_test.rb:11:in `block in test_rubies_are_installed'
35
+ /var/snap-ci/repo/test/packages/ruby_test.rb:7:in `each'
36
+ /var/snap-ci/repo/test/packages/ruby_test.rb:7:in `test_rubies_are_installed'
37
+
38
+
39
+ 95 tests, 256 assertions, 1 failures, 1 errors, 0 skips
40
+ rake aborted!
41
+ Command failed with status (1): [/opt/local/ruby/1.9.3-p484/bin/ruby -I"lib...]
42
+
@@ -2,53 +2,63 @@ require 'spec_helper'
2
2
 
3
3
  describe TestOutputParser::Framework::JUnit do
4
4
  it 'should do nothing when there is no spec summary in the output' do
5
- TestOutputParser::Framework::JUnit.count("Tests not run").should == {}
5
+ expect(TestOutputParser::Framework::JUnit.count("Tests not run").to_hash).to eq({})
6
6
  end
7
7
 
8
8
  it 'should count the number of specs ran for one example' do
9
- TestOutputParser::Framework::JUnit.count("Running com.foo.microblog.core.ErrorResponseTest\nTests run: 1, Failures: 0, Errors: 0, Skipped: 0").should ==
10
- {:total => 1, :failed => 0, :errors => 0, :pending => 0}
9
+ actual = TestOutputParser::Framework::JUnit.count("Running com.foo.microblog.core.ErrorResponseTest\nTests run: 1, Failures: 0, Errors: 0, Skipped: 0").to_hash
10
+ expected = { :total => 1 }
11
+ expect(actual).to eq(expected)
11
12
  end
12
13
 
13
14
  it 'should count the number of specs ran for one JUnit run' do
14
- TestOutputParser::Framework::JUnit.count("Running com.foo.microblog.core.ErrorResponseTest\nTests run: 10, Failures: 1, Errors: 5, Skipped: 3").should ==
15
- {:total => 10, :failed => 1, :errors => 5, :pending => 3}
15
+ actual = TestOutputParser::Framework::JUnit.count("Running com.foo.microblog.core.ErrorResponseTest\nTests run: 10, Failures: 1, Errors: 5, Skipped: 3").to_hash
16
+ expected = { :total => 10, :failed => 1, :errors => 5, :pending => 3 }
17
+ expect(actual).to eq(expected)
16
18
  end
17
19
 
18
20
  it 'should count the number of specs ran for multiple JUnit runs' do
19
- TestOutputParser::Framework::JUnit.count("Running com.foo.microblog.core.ErrorResponseTest\nTests run: 10, Failures: 1, Errors: 5, Skipped: 3\n\n\n" \
20
- "Running com.foo.microblog.core.UserResourceTest\nTests run: 1, Failures: 0, Errors: 0, Skipped: 0").should ==
21
- {:total => 11, :failed => 1, :errors => 5, :pending => 3}
21
+ actual = TestOutputParser::Framework::JUnit.count("Running com.foo.microblog.core.ErrorResponseTest\nTests run: 10, Failures: 1, Errors: 5, Skipped: 3\n\n\n" +
22
+ "Running com.foo.microblog.core.UserResourceTest\nTests run: 1, Failures: 0, Errors: 0, Skipped: 0").to_hash
23
+
24
+ expected = { :total => 11, :failed => 1, :errors => 5, :pending => 3 }
25
+ expect(actual).to eq(expected)
22
26
  end
23
27
 
24
28
  it 'should handle gradle output' do
25
- TestOutputParser::Framework::JUnit.count("47 tests completed, 1 failed").should == {:total => 47, :failed => 1}
29
+ actual = TestOutputParser::Framework::JUnit.count("47 tests completed, 1 failed").to_hash
30
+ expected = { :total => 47, :failed => 1 }
31
+ expect(actual).to eq(expected)
26
32
  end
27
33
 
28
34
  it 'should ignore lines not related to JUnit test summary' do
29
- TestOutputParser::Framework::JUnit.count(File.read("spec/fixtures/sample-junit-output.txt")).should == {:total => 13, :failed => 0, :errors => 0, :pending => 0}
35
+ actual = TestOutputParser::Framework::JUnit.count(File.read("spec/fixtures/sample-junit-output.txt")).to_hash
36
+ expected = { :total => 13 }
37
+ expect(actual).to eq(expected)
30
38
  end
31
39
 
32
40
  it 'should include the failures in the test summary for JUnit output' do
33
- TestOutputParser::Framework::JUnit.count(File.read("spec/fixtures/sample-failed-junit-output.txt")).should ==
34
- {
35
- :total => 13,
36
- :failed => 2,
37
- :errors=>0,
38
- :pending=>0,
39
- :failures => "Failed tests: testFromExceptionWithUniqueConstraintViolation(com.snapci.microblog.core.ErrorResponseTest)\n"\
40
- " testFromException(com.snapci.microblog.core.ErrorResponseTest)"
41
- }
41
+ actual = TestOutputParser::Framework::JUnit.count(File.read("spec/fixtures/sample-failed-junit-output.txt")).to_hash
42
+ expected = {
43
+ :total => 13,
44
+ :failed => 2,
45
+ :failures => '' +
46
+ "Failed tests: testFromExceptionWithUniqueConstraintViolation(com.snapci.microblog.core.ErrorResponseTest)\n" +
47
+ " testFromException(com.snapci.microblog.core.ErrorResponseTest)\n\n"
48
+ }
49
+ expect(actual).to eq(expected)
42
50
  end
43
51
 
44
52
  it 'should include the failures in the test summary for gradle output' do
45
- TestOutputParser::Framework::JUnit.count(File.read("spec/fixtures/sample-gradle-output.txt")).should ==
46
- {
47
- :total => 47,
48
- :failed => 1,
49
- :failures => "Running test: test shouldAddBookToDBIfNotInSystem(com.thoughtworks.twu.controller.AddBookControllerTest)\n\n"\
50
- "com.thoughtworks.twu.controller.AddBookControllerTest > shouldAddBookToDBIfNotInSystem FAILED\n"\
51
- " java.lang.AssertionError at AddBookControllerTest.java:28"
52
- }
53
- end
54
- end
53
+ actual = TestOutputParser::Framework::JUnit.count(File.read("spec/fixtures/sample-gradle-output.txt")).to_hash
54
+ expected = {
55
+ :total => 47,
56
+ :failed => 1,
57
+ :failures => ''+
58
+ "Running test: test shouldAddBookToDBIfNotInSystem(com.thoughtworks.twu.controller.AddBookControllerTest)\n\n" +
59
+ "com.thoughtworks.twu.controller.AddBookControllerTest > shouldAddBookToDBIfNotInSystem FAILED\n" +
60
+ " java.lang.AssertionError at AddBookControllerTest.java:28"
61
+ }
62
+ expect(actual).to eq(expected)
63
+ end
64
+ end
@@ -2,39 +2,55 @@ require 'spec_helper'
2
2
 
3
3
  describe TestOutputParser::Framework::RSpec do
4
4
  it 'should do nothing when there is no spec summary in the output' do
5
- TestOutputParser::Framework::RSpec.count("123 foo bar examples").should == {}
5
+ actual = TestOutputParser::Framework::RSpec.count("123 foo bar examples").to_hash
6
+ expect(actual).to eq({})
6
7
  end
7
8
 
8
9
  it 'should count the number of specs ran for one example' do
9
- TestOutputParser::Framework::RSpec.count("1 example, 0 failures").should == {:total => 1, :failed => 0, :pending => 0}
10
+ actual = TestOutputParser::Framework::RSpec.count("1 example, 0 failures").to_hash
11
+ expected = { :total => 1 }
12
+ expect(actual).to eq(expected)
10
13
  end
11
14
 
12
15
  it 'should count the number of specs ran for one rspec run' do
13
- TestOutputParser::Framework::RSpec.count("25 examples, 0 failures").should == {:total => 25, :failed => 0, :pending => 0}
16
+ actual = TestOutputParser::Framework::RSpec.count("25 examples, 0 failures").to_hash
17
+ expected = { :total => 25 }
18
+ expect(actual).to eq(expected)
14
19
  end
15
20
 
16
21
  it 'should count the number of specs ran for multiple rspec runs' do
17
- TestOutputParser::Framework::RSpec.count("25 examples, 1 failure\n\n\n5 examples, 3 failures").should == {:total => 30, :failed => 4, :pending => 0}
22
+ actual = TestOutputParser::Framework::RSpec.count("25 examples, 1 failure\n\n\n5 examples, 3 failures").to_hash
23
+ expected = { :total => 30, :failed => 4 }
24
+ expect(actual).to eq(expected)
18
25
  end
19
26
 
20
27
  it 'should ignore lines not related to rspec test summary' do
21
- TestOutputParser::Framework::RSpec.count(File.read("spec/fixtures/sample-rspec-output.txt")).should == {:total => 67, :failed => 0, :pending => 0}
28
+ actual = TestOutputParser::Framework::RSpec.count(File.read("spec/fixtures/sample-rspec-output.txt")).to_hash
29
+ expected = { :total => 67 }
30
+ expect(actual).to eq(expected)
22
31
  end
23
32
 
24
33
  it 'should count the number of pending specs' do
25
- TestOutputParser::Framework::RSpec.count("16 examples, 0 failures, 1 pending").should == {:total => 16, :failed => 0, :pending => 1}
34
+ actual = TestOutputParser::Framework::RSpec.count("16 examples, 0 failures, 1 pending").to_hash
35
+ expected = { :total => 16, :pending => 1 }
36
+ expect(actual).to eq(expected)
26
37
  end
27
38
 
28
39
  it 'should count the name of the specs that failed' do
29
- TestOutputParser::Framework::RSpec.count(File.read("spec/fixtures/sample-failed-rspec-output.txt")).should ==
30
- {:total => 16, :failed => 1, :pending => 0,
31
- :failures => "1) PostsController GET index assigns all posts as @posts\n" \
32
- " Failure/Error: assert false\n" \
33
- " MiniTest::Assertion:\n" \
34
- " Failed assertion, no message given.\n" \
35
- " # (eval):2:in `assert'\n" \
36
- " # ./spec/controllers/posts_controller_spec.rb:39:in `block (3 levels) in <top (required)>'"
37
-
38
- }
40
+ expected = {
41
+ :total => 16,
42
+ :failed => 1,
43
+ :failures => '' +
44
+ " 1) PostsController GET index assigns all posts as @posts\n" +
45
+ " Failure/Error: assert false\n" +
46
+ " MiniTest::Assertion:\n" +
47
+ " Failed assertion, no message given.\n" +
48
+ " # (eval):2:in `assert'\n" +
49
+ " # ./spec/controllers/posts_controller_spec.rb:39:in `block (3 levels) in <top (required)>'\n\n"
50
+
51
+ }
52
+ actual = TestOutputParser::Framework::RSpec.count(File.read("spec/fixtures/sample-failed-rspec-output.txt")).to_hash
53
+
54
+ expect(actual).to eq(expected)
39
55
  end
40
- end
56
+ end
@@ -2,48 +2,80 @@ require 'spec_helper'
2
2
 
3
3
  describe TestOutputParser::Framework::TestUnit do
4
4
  it 'should do nothing when there is no spec summary in the output' do
5
- TestOutputParser::Framework::TestUnit.count("1 assertion").should == {}
5
+ actual = TestOutputParser::Framework::TestUnit.count("1 assertion").to_hash
6
+ expect(actual).to eq({})
6
7
  end
7
8
 
8
9
  it 'should count the number of tests ran for one test' do
9
- TestOutputParser::Framework::TestUnit.count("1 tests, 1 assertions").should == {:total => 1, :failed => 0, :errors => 0, :pending => 0}
10
+ actual = TestOutputParser::Framework::TestUnit.count("1 tests, 1 assertions").to_hash
11
+ expected = { :total => 1 }
12
+ expect(actual).to eq(expected)
10
13
  end
11
14
 
12
15
  it 'should count the number of specs ran for one test-unit run' do
13
- TestOutputParser::Framework::TestUnit.count("30 tests, 77 assertions, 3 failures, 4 errors, 2 skips").should ==
14
- {:total => 30, :failed => 3, :errors => 4, :pending => 2}
16
+ actual = TestOutputParser::Framework::TestUnit.count("30 tests, 77 assertions, 3 failures, 4 errors, 2 skips").to_hash
17
+ expected = { :total => 30, :failed => 3, :errors => 4, :pending => 2 }
18
+ expect(actual).to eq(expected)
15
19
  end
16
20
 
17
21
  it 'should count the number of specs ran for multiple test-unit runs' do
18
- TestOutputParser::Framework::TestUnit.count("30 tests, 77 assertions, 0 failures\n\n\n1 tests, 3 assertions, 1 failures, 1 errors, 1 skips").should ==
19
- {:total => 31, :failed => 1, :errors => 1, :pending => 1}
22
+ actual = TestOutputParser::Framework::TestUnit.count("30 tests, 77 assertions, 0 failures\n\n\n1 tests, 3 assertions, 1 failures, 1 errors, 1 skips").to_hash
23
+ expected = { :total => 31, :failed => 1, :errors => 1, :pending => 1 }
24
+ expect(actual).to eq(expected)
20
25
  end
21
26
 
22
27
  it 'should ignore lines not related to test-unit test summary' do
23
- TestOutputParser::Framework::TestUnit.count(File.read("spec/fixtures/sample-test-unit-output.txt")).should == {:total => 1, :failed => 0, :errors => 0, :pending => 0}
28
+ actual = TestOutputParser::Framework::TestUnit.count(File.read("spec/fixtures/sample-test-unit-output.txt")).to_hash
29
+ expected = { :total => 1 }
30
+ expect(actual).to eq(expected)
24
31
  end
25
32
 
26
33
  it 'should count the number of specs errors' do
27
- TestOutputParser::Framework::TestUnit.count(File.read("spec/fixtures/sample-error-test-unit-output.txt")).should == {:total => 1, :failed => 0, :errors => 1, :pending => 0}
34
+ actual = TestOutputParser::Framework::TestUnit.count(File.read("spec/fixtures/sample-error-test-unit-output.txt")).to_hash
35
+ expected = { :total => 1, :errors => 1, }
36
+ expect(actual).to eq(expected)
28
37
  end
29
38
 
30
39
  it 'should count the number of specs pending' do
31
- TestOutputParser::Framework::TestUnit.count(File.read("spec/fixtures/sample-pending-test-unit-output.txt")).should == {:total => 1, :failed => 0, :errors => 0, :pending => 1}
40
+ actual = TestOutputParser::Framework::TestUnit.count(File.read("spec/fixtures/sample-pending-test-unit-output.txt")).to_hash
41
+ expected = { :total => 1, :pending => 1 }
42
+ expect(actual).to eq(expected)
32
43
  end
33
44
 
34
45
  it 'should add the failures to the summary' do
35
- TestOutputParser::Framework::TestUnit.count(File.read("spec/fixtures/sample-failed-test-unit-output.txt")).should ==
36
- {
37
- :total => 3,
38
- :failed => 2,
39
- :errors => 0,
40
- :pending => 0,
41
- :failures => "1) Failure:\n" \
42
- "test_passes(FooTest) [/var/go/repo/test/foo_test.rb:5]:\n" \
43
- "Failed assertion, no message given.\n"\
44
- "\n 2) Failure:\n"\
45
- "test_passes(FooTest) [/var/go/repo/test/foo_test.rb:10]:\n"\
46
- "Failed assertion, no message given."
47
- }
48
- end
49
- end
46
+ actual = TestOutputParser::Framework::TestUnit.count(File.read("spec/fixtures/sample-failed-test-unit-output.txt")).to_hash
47
+ expected = {
48
+ :total => 95,
49
+ :failed => 1,
50
+ :errors => 1,
51
+ :failures => %Q!
52
+ 1) Failure:
53
+ test_no_additional_rubies(RubyTest) [/var/snap-ci/repo/test/packages/ruby_test.rb:23]:
54
+ --- expected
55
+ +++ actual
56
+ @@ -1 +1 @@
57
+ -["foo", "bar"]
58
+ +["baz", "boo"]
59
+
60
+
61
+ 2) Error:
62
+ test_rubies_are_installed(RubyTest):
63
+ Errno::ENOENT: No such file or directory - /opt/local/ruby/2.1.4/bin/ruby --version
64
+ /tmp/.bundle-repo/ruby/1.9.1/gems/mixlib-shellout-1.2.0/lib/mixlib/shellout/unix.rb:268:in `exec'
65
+ /tmp/.bundle-repo/ruby/1.9.1/gems/mixlib-shellout-1.2.0/lib/mixlib/shellout/unix.rb:268:in `block in fork_subprocess'
66
+ /tmp/.bundle-repo/ruby/1.9.1/gems/mixlib-shellout-1.2.0/lib/mixlib/shellout/unix.rb:256:in `fork'
67
+ /tmp/.bundle-repo/ruby/1.9.1/gems/mixlib-shellout-1.2.0/lib/mixlib/shellout/unix.rb:256:in `fork_subprocess'
68
+ /tmp/.bundle-repo/ruby/1.9.1/gems/mixlib-shellout-1.2.0/lib/mixlib/shellout/unix.rb:40:in `run_command'
69
+ /tmp/.bundle-repo/ruby/1.9.1/gems/mixlib-shellout-1.2.0/lib/mixlib/shellout.rb:225:in `run_command'
70
+ /var/snap-ci/repo/test/mini_test_helper.rb:28:in `block in run_command'
71
+ /opt/local/ruby/1.9.3-p484/lib/ruby/gems/1.9.1/gems/bundler-1.6.3/lib/bundler.rb:235:in `block in with_clean_env'
72
+ /opt/local/ruby/1.9.3-p484/lib/ruby/gems/1.9.1/gems/bundler-1.6.3/lib/bundler.rb:222:in `with_original_env'
73
+ /opt/local/ruby/1.9.3-p484/lib/ruby/gems/1.9.1/gems/bundler-1.6.3/lib/bundler.rb:228:in `with_clean_env'
74
+ /var/snap-ci/repo/test/mini_test_helper.rb:23:in `run_command'
75
+ /var/snap-ci/repo/test/packages/ruby_test.rb:11:in `block in test_rubies_are_installed'
76
+ /var/snap-ci/repo/test/packages/ruby_test.rb:7:in `each'
77
+ /var/snap-ci/repo/test/packages/ruby_test.rb:7:in `test_rubies_are_installed'
78
+ ! }
79
+ expect(actual).to eq(expected)
80
+ end
81
+ end
data/spec/spec_helper.rb CHANGED
@@ -6,7 +6,14 @@
6
6
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
7
  require 'test_output_parser'
8
8
 
9
+ module SpecHelper
10
+ def strip_heredoc(str)
11
+ str.gsub(/^#{str.scan(/^\s*/).min_by{|l|l.length}}/, "")
12
+ end
13
+ end
14
+
9
15
  RSpec.configure do |config|
16
+ config.include SpecHelper
10
17
  config.treat_symbols_as_metadata_keys_with_true_values = true
11
18
  config.run_all_when_everything_filtered = true
12
19
  config.filter_run :focus
@@ -2,56 +2,119 @@ require 'spec_helper'
2
2
 
3
3
  describe TestOutputParser do
4
4
  it 'should give the summary of specs for rspec' do
5
- TestOutputParser.count(File.read("spec/fixtures/sample-failed-rspec-output.txt")).should ==
6
- {
7
- :total=>16,
8
- :failed=>1,
9
- :pending=>0,
10
- :failures=>"1) PostsController GET index assigns all posts as @posts\n"\
11
- " Failure/Error: assert false\n"\
12
- " MiniTest::Assertion:\n"\
13
- " Failed assertion, no message given.\n"\
14
- " # (eval):2:in `assert'\n"\
15
- " # ./spec/controllers/posts_controller_spec.rb:39:in `block (3 levels) in <top (required)>'"
16
- }
5
+ actual = TestOutputParser.count(File.read("spec/fixtures/sample-failed-rspec-output.txt"))
6
+ expected = {
7
+ :total => 16,
8
+ :failed => 1,
9
+ :failures => '' +
10
+ " 1) PostsController GET index assigns all posts as @posts\n" +
11
+ " Failure/Error: assert false\n" +
12
+ " MiniTest::Assertion:\n" +
13
+ " Failed assertion, no message given.\n" +
14
+ " # (eval):2:in `assert'\n" +
15
+ " # ./spec/controllers/posts_controller_spec.rb:39:in `block (3 levels) in <top (required)>'\n\n"
16
+ }
17
+ expect(actual).to eq(expected)
17
18
  end
18
19
 
19
20
  it 'should give the summary of specs for test unit' do
20
- TestOutputParser.count(File.read("spec/fixtures/sample-failed-test-unit-output.txt")).should ==
21
- {
22
- :total=>3,
23
- :failed=>2,
24
- :errors=>0,
25
- :pending=>0,
26
- :failures=>"1) Failure:\ntest_passes(FooTest) [/var/go/repo/test/foo_test.rb:5]:\n"\
27
- "Failed assertion, no message given.\n\n"\
28
- " 2) Failure:\ntest_passes(FooTest) [/var/go/repo/test/foo_test.rb:10]:\nFailed assertion, no message given."
29
- }
21
+ actual = TestOutputParser.count(File.read("spec/fixtures/sample-failed-test-unit-output.txt"))
22
+ expected = {
23
+ :total => 95,
24
+ :failed => 1,
25
+ :errors => 1,
26
+ :failures => %Q!
27
+ 1) Failure:
28
+ test_no_additional_rubies(RubyTest) [/var/snap-ci/repo/test/packages/ruby_test.rb:23]:
29
+ --- expected
30
+ +++ actual
31
+ @@ -1 +1 @@
32
+ -["foo", "bar"]
33
+ +["baz", "boo"]
34
+
35
+
36
+ 2) Error:
37
+ test_rubies_are_installed(RubyTest):
38
+ Errno::ENOENT: No such file or directory - /opt/local/ruby/2.1.4/bin/ruby --version
39
+ /tmp/.bundle-repo/ruby/1.9.1/gems/mixlib-shellout-1.2.0/lib/mixlib/shellout/unix.rb:268:in `exec'
40
+ /tmp/.bundle-repo/ruby/1.9.1/gems/mixlib-shellout-1.2.0/lib/mixlib/shellout/unix.rb:268:in `block in fork_subprocess'
41
+ /tmp/.bundle-repo/ruby/1.9.1/gems/mixlib-shellout-1.2.0/lib/mixlib/shellout/unix.rb:256:in `fork'
42
+ /tmp/.bundle-repo/ruby/1.9.1/gems/mixlib-shellout-1.2.0/lib/mixlib/shellout/unix.rb:256:in `fork_subprocess'
43
+ /tmp/.bundle-repo/ruby/1.9.1/gems/mixlib-shellout-1.2.0/lib/mixlib/shellout/unix.rb:40:in `run_command'
44
+ /tmp/.bundle-repo/ruby/1.9.1/gems/mixlib-shellout-1.2.0/lib/mixlib/shellout.rb:225:in `run_command'
45
+ /var/snap-ci/repo/test/mini_test_helper.rb:28:in `block in run_command'
46
+ /opt/local/ruby/1.9.3-p484/lib/ruby/gems/1.9.1/gems/bundler-1.6.3/lib/bundler.rb:235:in `block in with_clean_env'
47
+ /opt/local/ruby/1.9.3-p484/lib/ruby/gems/1.9.1/gems/bundler-1.6.3/lib/bundler.rb:222:in `with_original_env'
48
+ /opt/local/ruby/1.9.3-p484/lib/ruby/gems/1.9.1/gems/bundler-1.6.3/lib/bundler.rb:228:in `with_clean_env'
49
+ /var/snap-ci/repo/test/mini_test_helper.rb:23:in `run_command'
50
+ /var/snap-ci/repo/test/packages/ruby_test.rb:11:in `block in test_rubies_are_installed'
51
+ /var/snap-ci/repo/test/packages/ruby_test.rb:7:in `each'
52
+ /var/snap-ci/repo/test/packages/ruby_test.rb:7:in `test_rubies_are_installed'
53
+ !
54
+ }
55
+ expect(actual).to eq(expected)
30
56
  end
31
57
 
32
58
  it 'should give the summary of specs for junit' do
33
- TestOutputParser.count(File.read("spec/fixtures/sample-gradle-output.txt")).should ==
34
- {
35
- :total=>47,
36
- :failed=>1,
37
- :failures=>"Running test: test shouldAddBookToDBIfNotInSystem(com.thoughtworks.twu.controller.AddBookControllerTest)\n\n"\
38
- "com.thoughtworks.twu.controller.AddBookControllerTest > shouldAddBookToDBIfNotInSystem FAILED\n"\
59
+ actual = TestOutputParser.count(File.read("spec/fixtures/sample-gradle-output.txt"))
60
+ expected = {
61
+ :total => 47,
62
+ :failed => 1,
63
+ :failures => "Running test: test shouldAddBookToDBIfNotInSystem(com.thoughtworks.twu.controller.AddBookControllerTest)\n\n" +
64
+ "com.thoughtworks.twu.controller.AddBookControllerTest > shouldAddBookToDBIfNotInSystem FAILED\n" +
39
65
  " java.lang.AssertionError at AddBookControllerTest.java:28"
40
- }
66
+ }
67
+ expect(actual).to eq(expected)
41
68
  end
42
69
 
43
70
  it 'should add up the summaries when there are specs for multiple frameworks' do
44
- TestOutputParser.count(File.read("spec/fixtures/sample-failed-test-unit-output.txt") + File.read("spec/fixtures/sample-failed-rspec-output.txt")).should ==
45
- {
46
- :total=>19,
47
- :failed=>3,
48
- :pending=>0,
49
- :failures=>"1) Failure:\n"\
50
- "test_passes(FooTest) [/var/go/repo/test/foo_test.rb:5]:\n"\
51
- "Failed assertion, no message given.\n\n"\
52
- " 2) Failure:\ntest_passes(FooTest) [/var/go/repo/test/foo_test.rb:10]:\n"\
53
- "Failed assertion, no message given.",
54
- :errors=>0
55
- }
71
+ actual = TestOutputParser.count(File.read("spec/fixtures/sample-failed-test-unit-output.txt") + "\n" + File.read("spec/fixtures/sample-failed-rspec-output.txt"))
72
+ expected = {
73
+ :total => 111,
74
+ :failed => 2,
75
+ :failures => %Q! 1) PostsController GET index assigns all posts as @posts
76
+ Failure/Error: assert false
77
+ MiniTest::Assertion:
78
+ Failed assertion, no message given.
79
+ # (eval):2:in `assert'
80
+ # ./spec/controllers/posts_controller_spec.rb:39:in `block (3 levels) in <top (required)>'
81
+
82
+
83
+ 1) Failure:
84
+ test_no_additional_rubies(RubyTest) [/var/snap-ci/repo/test/packages/ruby_test.rb:23]:
85
+ --- expected
86
+ +++ actual
87
+ @@ -1 +1 @@
88
+ -["foo", "bar"]
89
+ +["baz", "boo"]
90
+
91
+
92
+ 2) Error:
93
+ test_rubies_are_installed(RubyTest):
94
+ Errno::ENOENT: No such file or directory - /opt/local/ruby/2.1.4/bin/ruby --version
95
+ /tmp/.bundle-repo/ruby/1.9.1/gems/mixlib-shellout-1.2.0/lib/mixlib/shellout/unix.rb:268:in `exec'
96
+ /tmp/.bundle-repo/ruby/1.9.1/gems/mixlib-shellout-1.2.0/lib/mixlib/shellout/unix.rb:268:in `block in fork_subprocess'
97
+ /tmp/.bundle-repo/ruby/1.9.1/gems/mixlib-shellout-1.2.0/lib/mixlib/shellout/unix.rb:256:in `fork'
98
+ /tmp/.bundle-repo/ruby/1.9.1/gems/mixlib-shellout-1.2.0/lib/mixlib/shellout/unix.rb:256:in `fork_subprocess'
99
+ /tmp/.bundle-repo/ruby/1.9.1/gems/mixlib-shellout-1.2.0/lib/mixlib/shellout/unix.rb:40:in `run_command'
100
+ /tmp/.bundle-repo/ruby/1.9.1/gems/mixlib-shellout-1.2.0/lib/mixlib/shellout.rb:225:in `run_command'
101
+ /var/snap-ci/repo/test/mini_test_helper.rb:28:in `block in run_command'
102
+ /opt/local/ruby/1.9.3-p484/lib/ruby/gems/1.9.1/gems/bundler-1.6.3/lib/bundler.rb:235:in `block in with_clean_env'
103
+ /opt/local/ruby/1.9.3-p484/lib/ruby/gems/1.9.1/gems/bundler-1.6.3/lib/bundler.rb:222:in `with_original_env'
104
+ /opt/local/ruby/1.9.3-p484/lib/ruby/gems/1.9.1/gems/bundler-1.6.3/lib/bundler.rb:228:in `with_clean_env'
105
+ /var/snap-ci/repo/test/mini_test_helper.rb:23:in `run_command'
106
+ /var/snap-ci/repo/test/packages/ruby_test.rb:11:in `block in test_rubies_are_installed'
107
+ /var/snap-ci/repo/test/packages/ruby_test.rb:7:in `each'
108
+ /var/snap-ci/repo/test/packages/ruby_test.rb:7:in `test_rubies_are_installed'
109
+ !,
110
+ :errors => 1
111
+ }
112
+ expect(actual).to eq(expected)
113
+ end
114
+
115
+ it 'should ignore invalid UTF-8 characters' do
116
+ actual = TestOutputParser.count("16 exa\255mples, 0 failures")
117
+ expected = { :total => 16 }
118
+ expect(actual).to eq(expected)
56
119
  end
57
- end
120
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: test-output-parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akshay Karle
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-13 00:00:00.000000000 Z
11
+ date: 2016-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -64,6 +64,7 @@ files:
64
64
  - ".ruby-gemset"
65
65
  - ".ruby-version"
66
66
  - Gemfile
67
+ - Gemfile.lock
67
68
  - LICENSE.txt
68
69
  - README.md
69
70
  - Rakefile
@@ -108,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
109
  version: '0'
109
110
  requirements: []
110
111
  rubyforge_project:
111
- rubygems_version: 2.2.0
112
+ rubygems_version: 2.2.2
112
113
  signing_key:
113
114
  specification_version: 4
114
115
  summary: A gem to get the summary of test outputs for further processing