minitest-jsonapi 1.2.0
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 +7 -0
- data/README.md +78 -0
- data/lib/minitest/jsonapi.rb +4 -0
- data/lib/minitest/jsonapi/version.rb +5 -0
- data/lib/minitest/jsonapi_plugin.rb +164 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3a605159c706540c9fc0e55a01d43f681d6ff2248e0aa31548be02eff338a033
|
4
|
+
data.tar.gz: e904d11d84354254b9d74a18ba0f347371cb94bd1bc6f80cda94a3aa254790d9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 064fb0f5d15b40408986a66929591ec85658a5b1654deed6ee7970789446c91b1f6d006992253b97f58d63d205191c469272a0bf6d59bc518ceca41f34ff1691
|
7
|
+
data.tar.gz: 6764348523de1d95256090cbe57b30285a8c98b7631865849fc8a2e6b7420687482f54f0937df625057f9f5d4ef977612b31181fe1bb0046d7452daa8630d83d
|
data/README.md
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# Minitest::Jsonapi
|
2
|
+
|
3
|
+
Sends JSON output for Minitest runs to console or to a specific URL via `POST` with a predefined API key and value.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'minitest-jsonapi', require: false
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
> bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
> gem install minitest-jsonapi
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
### From terminal
|
24
|
+
---
|
25
|
+
|
26
|
+
To generate reports using Minitest::JsonApi, you'll need to pass `-J` or `--json` flag to Minitest on the command line.
|
27
|
+
|
28
|
+
Following will produce the output on the terminal:
|
29
|
+
|
30
|
+
> ruby test/foo_test.rb -J
|
31
|
+
|
32
|
+
Options to specify the URL and API keys & values:
|
33
|
+
|
34
|
+
> ruby test/foo_test.rb -J --addr=http://localhost:4567 --keyname=ABCD --keyvalue=EFGH
|
35
|
+
|
36
|
+
To prettify the JSON for terminal output:
|
37
|
+
|
38
|
+
> ruby test/foo_test.rb -J --pretty
|
39
|
+
|
40
|
+
All options are optional.
|
41
|
+
|
42
|
+
All the options can be viewed by using `-h` for help:
|
43
|
+
|
44
|
+
> ruby test/foo_test.rb -h
|
45
|
+
|
46
|
+
|
47
|
+
### From rakefile
|
48
|
+
---
|
49
|
+
|
50
|
+
You can set up a rake task to run all your tests by adding this to your Rakefile:
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
require "rake/testtask"
|
54
|
+
|
55
|
+
Rake::TestTask.new(:test) do |t|
|
56
|
+
t.options = '-J --addr=http://localhost:4567/ --keyname=ABCD --keyvalue=EFGH'
|
57
|
+
t.test_files = FileList["test/**/test_*.rb"]
|
58
|
+
end
|
59
|
+
|
60
|
+
task :default => :test
|
61
|
+
```
|
62
|
+
|
63
|
+
You can also switch on JSON output globally for every test run by putting the following in your test helper:
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
Minitest::JsonApi.enable!
|
67
|
+
```
|
68
|
+
|
69
|
+
|
70
|
+
## Development
|
71
|
+
|
72
|
+
This repository is a mirror of the public [fossil](https://fossil-scm.org) repository hosted at [fossil.abhij.it/repos/minitest-jsonapi](https://fossil.abhij.it/repos/minitest-jsonapi)
|
73
|
+
|
74
|
+
No pull requests are accepted through this repository. Email mail@abhij.it to discuss features.
|
75
|
+
|
76
|
+
## License
|
77
|
+
|
78
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -0,0 +1,164 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'net/http'
|
3
|
+
require 'net/https'
|
4
|
+
|
5
|
+
module Minitest
|
6
|
+
module JsonApi
|
7
|
+
class Reporter < Minitest::StatisticsReporter
|
8
|
+
attr_accessor :all_results, :addr, :apikeyname, :apikeyvalue, :pretty
|
9
|
+
|
10
|
+
def initialize(options = {})
|
11
|
+
super
|
12
|
+
self.all_results = []
|
13
|
+
|
14
|
+
self.addr = options[:addr]
|
15
|
+
self.apikeyname = options[:apikeyname]
|
16
|
+
self.apikeyvalue = options[:apikeyvalue]
|
17
|
+
self.pretty = options[:pretty] || false
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
def record(result)
|
22
|
+
super
|
23
|
+
all_results << result
|
24
|
+
end
|
25
|
+
|
26
|
+
def report
|
27
|
+
super
|
28
|
+
|
29
|
+
assertions = 0
|
30
|
+
skips = 0
|
31
|
+
errors = 0
|
32
|
+
fails = 0
|
33
|
+
passes = 0
|
34
|
+
|
35
|
+
results = all_results.collect do |result|
|
36
|
+
status = case result.failure
|
37
|
+
when Skip
|
38
|
+
skips += 1
|
39
|
+
:skip
|
40
|
+
when UnexpectedError
|
41
|
+
errors += 1
|
42
|
+
:error
|
43
|
+
when Assertion
|
44
|
+
fails += 1
|
45
|
+
:fail
|
46
|
+
else
|
47
|
+
passes += 1
|
48
|
+
:pass
|
49
|
+
end
|
50
|
+
|
51
|
+
assertions += result.assertions
|
52
|
+
|
53
|
+
result_hash = {
|
54
|
+
name: result.name,
|
55
|
+
status: status,
|
56
|
+
time: result.time,
|
57
|
+
assertions: result.assertions,
|
58
|
+
file: nil,
|
59
|
+
line: nil
|
60
|
+
}
|
61
|
+
|
62
|
+
if result.failure
|
63
|
+
result_hash.merge!({
|
64
|
+
file: result.source_location[0],
|
65
|
+
line: result.source_location[1]
|
66
|
+
})
|
67
|
+
end
|
68
|
+
|
69
|
+
result_hash
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
summary = {
|
74
|
+
tests: all_results.count,
|
75
|
+
assertions: assertions,
|
76
|
+
passes: passes,
|
77
|
+
fails: fails,
|
78
|
+
errors: errors,
|
79
|
+
skips: skips
|
80
|
+
}
|
81
|
+
|
82
|
+
|
83
|
+
full_result = {
|
84
|
+
summary: summary,
|
85
|
+
results: results
|
86
|
+
}
|
87
|
+
|
88
|
+
if addr.to_s.empty?
|
89
|
+
if self.pretty
|
90
|
+
io[:io].write(JSON.pretty_generate(full_result))
|
91
|
+
else
|
92
|
+
io[:io].write(JSON.dump(full_result))
|
93
|
+
end
|
94
|
+
else
|
95
|
+
uri = URI.parse(self.addr)
|
96
|
+
header = {'Content-Type': 'text/json'}
|
97
|
+
|
98
|
+
if self.apikeyname and self.apikeyvalue
|
99
|
+
header[self.apikeyname] = apikeyvalue
|
100
|
+
end
|
101
|
+
|
102
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
103
|
+
request = Net::HTTP::Post.new(uri.request_uri, header)
|
104
|
+
request.body = full_result.to_json
|
105
|
+
|
106
|
+
http.use_ssl = true if uri.scheme == 'https'
|
107
|
+
|
108
|
+
begin
|
109
|
+
http.request request
|
110
|
+
rescue Exception => e
|
111
|
+
puts "ERROR - #{e.message}"
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
module Minitest
|
123
|
+
def self.plugin_jsonapi_init(options)
|
124
|
+
if JsonApi.enabled?
|
125
|
+
reporter.reporters << JsonApi::Reporter.new(options)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def self.plugin_jsonapi_options(opts, options)
|
130
|
+
description = "Generate JSON to send"
|
131
|
+
opts.on "-J", "--json", description do
|
132
|
+
JsonApi.enable!
|
133
|
+
end
|
134
|
+
|
135
|
+
opts.on "--pretty", 'pretty print (for terminal output)' do
|
136
|
+
options[:pretty] = true
|
137
|
+
end
|
138
|
+
|
139
|
+
opts.on "--addr [OPTIONAL]", String, "Full URL to send JSON to (http/https) .e.g https://api.com/test/results" do |url|
|
140
|
+
options[:addr] = url
|
141
|
+
end
|
142
|
+
opts.on "--keyname [OPTIONAL]", String, "API Key Name" do |apikeyname|
|
143
|
+
options[:apikeyname] = apikeyname
|
144
|
+
end
|
145
|
+
opts.on "--keyvalue [OPTIONAL]", String, "API Key Value" do |apikeyvalue|
|
146
|
+
options[:apikeyvalue] = apikeyvalue
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
|
151
|
+
module JsonApi
|
152
|
+
@@enabled = false
|
153
|
+
|
154
|
+
def self.enabled?
|
155
|
+
@@enabled
|
156
|
+
end
|
157
|
+
|
158
|
+
def self.enable!
|
159
|
+
@@enabled = true
|
160
|
+
end
|
161
|
+
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: minitest-jsonapi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- abhijit
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-08-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: minitest
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.14'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
description: For Minitest runs, show prettified JSON output on console or send to
|
70
|
+
an API
|
71
|
+
email:
|
72
|
+
- mail@abhij.it
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- README.md
|
78
|
+
- lib/minitest/jsonapi.rb
|
79
|
+
- lib/minitest/jsonapi/version.rb
|
80
|
+
- lib/minitest/jsonapi_plugin.rb
|
81
|
+
homepage: https://fossil.abhij.it/repos/minitest-jsonapi
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
metadata: {}
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - "~>"
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '2.0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 2.7.3
|
102
|
+
signing_key:
|
103
|
+
specification_version: 4
|
104
|
+
summary: Send JSON output to API for Minitest runs
|
105
|
+
test_files: []
|