pact_junit_formatter 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 44acd8262262a0d597e2c7798fce00b59626dea1
4
+ data.tar.gz: a7db7c18bc636aae701862c2df441bfa92452275
5
+ SHA512:
6
+ metadata.gz: a82a0bc73fc78d9f752c31e97b8dab55d36749cd5c8f3b55a1265aa7caa2d85e597d4d2b267a23d83ac0c3128969449f9b9864803bd8ed8f60a3da2b24621172
7
+ data.tar.gz: e796a6b70e9a1354040d6c7ea98cd583de77374c1074e256efb95667d1d1d69a2430f73828622f88310e9121cbdfe0de8ed53e3bd5d5e81ecd74239e9287b39e
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pact_junit_formatter.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Taiki Ono
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # PactJunitFormatter
2
+ Generate a pact verification report with JUnit format.
3
+ Nice to see pact verification result in Jenkins Web UI.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'pact_junit_formatter'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install pact_junit_formatter
20
+
21
+ ## Usage
22
+ Define your pact verification task by using `Pact::VerificationTask`:
23
+
24
+ ```ruby
25
+ require 'pact/tasks'
26
+ Pact::VerificationTask.new(:with_report) do |task|
27
+ task.rspec_opts = '--format PactJUnitFormatter --out pact-verfication-report.xml'
28
+ task.uri(nil) # Verify with all pact files
29
+ end
30
+ ```
31
+
32
+ ## License
33
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "pact_junit_formatter"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,136 @@
1
+ require 'time'
2
+ require 'builder'
3
+
4
+ require 'rspec/core'
5
+ require 'rspec/core/formatters/base_formatter'
6
+
7
+ require 'pact_junit_formatter/version'
8
+
9
+ class PactJUnitFormatter < RSpec::Core::Formatters::BaseFormatter
10
+ RSpec::Core::Formatters.register(self, :dump_summary)
11
+
12
+ def dump_summary(notification)
13
+ @notification = notification
14
+ examples = rearrange(notification.examples.map {|e| PactExample.new(e) })
15
+ xml_dump(examples)
16
+ end
17
+
18
+ private
19
+
20
+ def rearrange(examples)
21
+ examples.inject(Hash.new {|h, k| h[k] = [] }) do |h, example|
22
+ h[example.package_name] << example
23
+ h
24
+ end
25
+ end
26
+
27
+ def xml_dump(examples)
28
+ xml = Builder::XmlMarkup.new target: output, indent: 2
29
+ xml.instruct!
30
+ xml.testsuites(tests: @notification.examples.size, failures: @notification.failed_examples.size, time: @notification.duration) do
31
+ examples.each {|package_name, es| dump_testsuite(xml, package_name, es) }
32
+ end
33
+ end
34
+
35
+ def dump_testsuite(xml, package_name, es)
36
+ failure_count = es.select {|e| e.status == :failed }.size
37
+ duration = es.map {|e| e.run_time }.inject(0, &:+)
38
+ timestamp = es.map {|e| e.started_at }.sort.first.iso8601
39
+
40
+ xml.testsuite(name: package_name, tests: es.size, failures: failure_count, time: '%.6f' % duration, timestamp: timestamp) do
41
+ xml.properties
42
+ es.each {|e| ExampleDumper.new(xml, e).call }
43
+ end
44
+ end
45
+
46
+ class ExampleDumper
47
+ def initialize(xml, example)
48
+ @xml = xml
49
+ @example = example
50
+ end
51
+
52
+ def call
53
+ case @example.status
54
+ when :passed
55
+ dump_example(@example)
56
+ when :pending
57
+ dump_pending(@example)
58
+ when :failed
59
+ dump_failed(@example)
60
+ else
61
+ raise "Unexpected example status: #{@example.status}"
62
+ end
63
+ end
64
+
65
+ private
66
+
67
+ def dump_pending(example)
68
+ dump_example(example) { @xml.skipped }
69
+ end
70
+
71
+ def dump_failed(example)
72
+ exception = example.example.execution_result.exception
73
+ backtrace = example.example.formatted_backtrace
74
+
75
+ dump_example(example) do
76
+ @xml.failure(message: exception.to_s, type: exception.class.name) do
77
+ @xml.cdata!("#{exception.message}\n#{backtrace.join("\n")}")
78
+ end
79
+ end
80
+ end
81
+
82
+ def dump_example(example, &block)
83
+ @xml.testcase(
84
+ classname: example.classname,
85
+ name: example.description,
86
+ file: '',
87
+ time: "%.6f" % example.run_time,
88
+ &block
89
+ )
90
+ end
91
+ end
92
+
93
+ class PactExample
94
+ attr_reader :example, :contract
95
+ def initialize(example)
96
+ @example = example
97
+ @contract = JSON.parse(example.metadata[:pact_json])
98
+ end
99
+
100
+ def consumer_name
101
+ @contract['consumer']['name']
102
+ end
103
+
104
+ def provider_name
105
+ @contract['provider']['name']
106
+ end
107
+
108
+ def interaction_name
109
+ @example.metadata[:pact_interaction_example_description]
110
+ end
111
+
112
+ def description
113
+ @example.full_description.match(/(returns\s+.+)\z/)[1]
114
+ end
115
+
116
+ def package_name
117
+ "#{consumer_name}-#{provider_name}"
118
+ end
119
+
120
+ def classname
121
+ "#{package_name}.#{interaction_name}"
122
+ end
123
+
124
+ def status
125
+ @example.execution_result.status
126
+ end
127
+
128
+ def run_time
129
+ @example.execution_result.run_time
130
+ end
131
+
132
+ def started_at
133
+ @example.execution_result.started_at
134
+ end
135
+ end
136
+ end
@@ -0,0 +1,3 @@
1
+ module PactJunitFormatter
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pact_junit_formatter/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "pact_junit_formatter"
8
+ spec.version = PactJunitFormatter::VERSION
9
+ spec.authors = ["Taiki Ono"]
10
+ spec.email = ["taiks.4559@gmail.com"]
11
+
12
+ spec.summary = %q{Dump pact verification result with JUnit format.}
13
+ spec.description = spec.summary
14
+ spec.homepage = "https://github.com/taiki45/pact_junit_formatter"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency 'builder'
23
+ spec.add_development_dependency "bundler", "~> 1.12"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pact_junit_formatter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Taiki Ono
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-06-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: builder
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: Dump pact verification result with JUnit format.
56
+ email:
57
+ - taiks.4559@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - bin/console
68
+ - bin/setup
69
+ - lib/pact_junit_formatter.rb
70
+ - lib/pact_junit_formatter/version.rb
71
+ - pact_junit_formatter.gemspec
72
+ homepage: https://github.com/taiki45/pact_junit_formatter
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.6.3
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Dump pact verification result with JUnit format.
96
+ test_files: []