aggregate_assertions 0.1.0.pre0 → 0.1.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 +4 -4
- data/.github/workflows/main.yml +5 -3
- data/.rubocop.yml +7 -0
- data/Gemfile.lock +2 -1
- data/README.md +54 -7
- data/aggregate_assertions.gemspec +1 -1
- data/lib/aggregate_assertions.rb +4 -4
- data/lib/aggregate_assertions/assertion_aggregator.rb +3 -3
- data/lib/aggregate_assertions/error.rb +2 -1
- data/lib/aggregate_assertions/failure_group.rb +5 -5
- data/lib/aggregate_assertions/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '00639ccdafa8ebe12ef425257a24af2e0dfc4e8d76ce3c70fece367f6a6565b7'
|
4
|
+
data.tar.gz: cc5ba9f480daf808165ae61bc5c0786d0014e7f1eab91d5a5c6eaea5fbe34a51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4805686e88f29f9b721a02c84fc80f579291b89a403c96ede61d814999a660a0e07a8b85d044b35c1ce210d2a133b1bdadd7bfed583377a5f31b9e893e29f413
|
7
|
+
data.tar.gz: 49a27fe41ce38d2c889c2d827dc5d0556a4e06a0701dde3068308a54e517863895113350b74d89de340555a2712379084e36e60fcb89e041cd726e85373a2583
|
data/.github/workflows/main.yml
CHANGED
@@ -10,7 +10,9 @@ jobs:
|
|
10
10
|
- name: Set up Ruby
|
11
11
|
uses: ruby/setup-ruby@v1
|
12
12
|
with:
|
13
|
-
ruby-version: 2.
|
13
|
+
ruby-version: 2.6.8
|
14
14
|
bundler-cache: true
|
15
|
-
- name:
|
16
|
-
run: bundle exec rake
|
15
|
+
- name: Tests
|
16
|
+
run: bundle exec rake test
|
17
|
+
- name: Rubocop
|
18
|
+
run: bundle exec rubocop
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,15 +1,30 @@
|
|
1
|
-
#
|
1
|
+
# aggregate_assertions
|
2
2
|
|
3
|
-
|
3
|
+
Aggregate assertions when testing using minitest. Similar to RSpec's [aggregate_failures](https://relishapp.com/rspec/rspec-expectations/v/3-10/docs/aggregating-failures),
|
4
|
+
this gem enables the reporting failures from multiple assertions in a single test.
|
4
5
|
|
5
|
-
|
6
|
+
It is possible to use [rspec-expectations](https://github.com/rspec/rspec-expectations) with minitest, but the
|
7
|
+
`aggregate_assertions` gem adds this functionality with no dependencies beyond minitest itself when only assertions are
|
8
|
+
used.
|
9
|
+
|
10
|
+
Normally a test will stop at the first false assertion. Though we might attempt to write tests with a single assertion,
|
11
|
+
due to expensive setup it is often necessary, or more convenient, to make multiple assertions within a test.
|
12
|
+
|
13
|
+
Using the `aggregate_assertions` method from this gem with a block, all assertions from the block will be grouped and
|
14
|
+
reported as a single assertion at the completion of the block. The multiple assertion error that is reported contains
|
15
|
+
the messages from all the errors.
|
16
|
+
|
17
|
+
The `aggregate_assertions` implementation uses a thread-local variable, so assertions and other errors from different
|
18
|
+
threads will still cause a test to fail immediately.
|
6
19
|
|
7
20
|
## Installation
|
8
21
|
|
9
|
-
Add this line to your application's Gemfile:
|
22
|
+
Add this line to the test group of your application's Gemfile:
|
10
23
|
|
11
24
|
```ruby
|
12
|
-
|
25
|
+
group "test" do
|
26
|
+
gem "aggregate_assertions"
|
27
|
+
end
|
13
28
|
```
|
14
29
|
|
15
30
|
And then execute:
|
@@ -22,7 +37,37 @@ Or install it yourself as:
|
|
22
37
|
|
23
38
|
## Usage
|
24
39
|
|
25
|
-
|
40
|
+
Use `aggregate_assertions` with a block in the body of a test. An optional label may be specified that will
|
41
|
+
be included in any aggregated error message:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
def test_response_example
|
45
|
+
response = Struct.new(:status, :headers, :body).new(404, { "Content-Type" => "text/plain" }, "Not Found")
|
46
|
+
|
47
|
+
aggregate_assertions("testing response") do
|
48
|
+
assert_equal(200, response.status)
|
49
|
+
assert_equal("application/json", response.headers["Content-Type"])
|
50
|
+
assert_equal('{"message":"Success"}', response.body)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
```
|
54
|
+
The failure from this test produces the error:
|
55
|
+
```
|
56
|
+
Failure:
|
57
|
+
ExampleTest#test_response_example [test/test_example.rb:5]:
|
58
|
+
There were 3 errors in group "testing response":
|
59
|
+
1) /Users/tjwp/git/aggregate_assertions/test/aggregate_assertions_test.rb:8:
|
60
|
+
Expected: 200
|
61
|
+
Actual: 404
|
62
|
+
|
63
|
+
2) /Users/tjwp/git/aggregate_assertions/test/aggregate_assertions_test.rb:9:
|
64
|
+
Expected: "application/json"
|
65
|
+
Actual: "text/plain"
|
66
|
+
|
67
|
+
3) /Users/tjwp/git/aggregate_assertions/test/aggregate_assertions_test.rb:10:
|
68
|
+
Expected: "{\"message\":\"Success\"}"
|
69
|
+
Actual: "Not Found"
|
70
|
+
```
|
26
71
|
|
27
72
|
## Development
|
28
73
|
|
@@ -30,9 +75,11 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
30
75
|
|
31
76
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
77
|
|
78
|
+
To check code style, run `bundle exec rubocop`.
|
79
|
+
|
33
80
|
## Contributing
|
34
81
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
82
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/tjwp/aggregate_assertions.
|
36
83
|
|
37
84
|
## License
|
38
85
|
|
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.authors = ["Tim Perkins"]
|
9
9
|
spec.email = ["tjwp@users.noreply.github.com"]
|
10
10
|
|
11
|
-
spec.summary = "
|
11
|
+
spec.summary = "Aggregate Minitest assertions"
|
12
12
|
spec.description = spec.summary
|
13
13
|
spec.homepage = "https://github.com/tjwp/aggregate_assertions"
|
14
14
|
spec.license = "MIT"
|
data/lib/aggregate_assertions.rb
CHANGED
@@ -9,10 +9,10 @@ module AggregateAssertions
|
|
9
9
|
module TestPatch
|
10
10
|
def assert(test, msg = nil)
|
11
11
|
super
|
12
|
-
rescue Minitest::Assertion, StandardError =>
|
12
|
+
rescue Minitest::Assertion, StandardError => e
|
13
13
|
raise unless AssertionAggregator.active?
|
14
14
|
|
15
|
-
AssertionAggregator.add_error(
|
15
|
+
AssertionAggregator.add_error(e)
|
16
16
|
end
|
17
17
|
|
18
18
|
def aggregate_assertions(label = nil)
|
@@ -22,8 +22,8 @@ module AggregateAssertions
|
|
22
22
|
|
23
23
|
begin
|
24
24
|
yield
|
25
|
-
rescue Minitest::Assertion, StandardError =>
|
26
|
-
AssertionAggregator.add_error(
|
25
|
+
rescue Minitest::Assertion, StandardError => e
|
26
|
+
AssertionAggregator.add_error(e)
|
27
27
|
ensure
|
28
28
|
failure_group = AssertionAggregator.close_failure_group
|
29
29
|
end
|
@@ -11,8 +11,8 @@ module AggregateAssertions
|
|
11
11
|
!store.nil? && !store.empty?
|
12
12
|
end
|
13
13
|
|
14
|
-
def add_error(
|
15
|
-
store.last.add_error(
|
14
|
+
def add_error(error)
|
15
|
+
store.last.add_error(error)
|
16
16
|
end
|
17
17
|
|
18
18
|
def open_failure_group(label = nil)
|
@@ -38,4 +38,4 @@ module AggregateAssertions
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
41
|
-
end
|
41
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Minitest
|
4
|
+
# Error raised when multiple assertions are grouped together.
|
4
5
|
class MultipleAssertionError < Minitest::Assertion
|
5
6
|
attr_reader :location
|
6
7
|
|
@@ -14,4 +15,4 @@ module Minitest
|
|
14
15
|
@result_label || super
|
15
16
|
end
|
16
17
|
end
|
17
|
-
end
|
18
|
+
end
|
@@ -14,11 +14,11 @@ module AggregateAssertions
|
|
14
14
|
@other_errors = []
|
15
15
|
end
|
16
16
|
|
17
|
-
def add_error(
|
18
|
-
if
|
19
|
-
@failures <<
|
17
|
+
def add_error(error)
|
18
|
+
if error.is_a?(Minitest::Assertion)
|
19
|
+
@failures << error
|
20
20
|
else
|
21
|
-
@other_errors <<
|
21
|
+
@other_errors << error
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -70,4 +70,4 @@ module AggregateAssertions
|
|
70
70
|
string.split("\n").map { |str| "#{prefix}#{str}" }.join("\n")
|
71
71
|
end
|
72
72
|
end
|
73
|
-
end
|
73
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aggregate_assertions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Perkins
|
@@ -24,7 +24,7 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '5.0'
|
27
|
-
description:
|
27
|
+
description: Aggregate Minitest assertions
|
28
28
|
email:
|
29
29
|
- tjwp@users.noreply.github.com
|
30
30
|
executables: []
|
@@ -67,12 +67,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
67
67
|
version: 2.6.0
|
68
68
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
69
|
requirements:
|
70
|
-
- - "
|
70
|
+
- - ">="
|
71
71
|
- !ruby/object:Gem::Version
|
72
|
-
version:
|
72
|
+
version: '0'
|
73
73
|
requirements: []
|
74
74
|
rubygems_version: 3.1.6
|
75
75
|
signing_key:
|
76
76
|
specification_version: 4
|
77
|
-
summary:
|
77
|
+
summary: Aggregate Minitest assertions
|
78
78
|
test_files: []
|