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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 10b578ef8e1e9b5cdcdc8da16ad1f01e6b022d786401cf31c0b57bfe7a90e4dc
4
- data.tar.gz: ca339ae9a8fa78e2a8d7e46a2d688f9278b146bcdd9511a88934a2530ce044de
3
+ metadata.gz: '00639ccdafa8ebe12ef425257a24af2e0dfc4e8d76ce3c70fece367f6a6565b7'
4
+ data.tar.gz: cc5ba9f480daf808165ae61bc5c0786d0014e7f1eab91d5a5c6eaea5fbe34a51
5
5
  SHA512:
6
- metadata.gz: 56295e2ac81bd5c8ffdb590228c61ba52088e46c0ee0e9e07551554debc0c386c2ee389def6ff28ed326622cd53fbe2161b770b4bc7966ab0478194bec310ca7
7
- data.tar.gz: 99769e351cd4ff99f3889dc3631c154b9e91233edf2482768b10ddbd539f0fdcd70faeae09086a6ae191321d985de30c63245f309ab99660b6cb6acdb7b34efa
6
+ metadata.gz: 4805686e88f29f9b721a02c84fc80f579291b89a403c96ede61d814999a660a0e07a8b85d044b35c1ce210d2a133b1bdadd7bfed583377a5f31b9e893e29f413
7
+ data.tar.gz: 49a27fe41ce38d2c889c2d827dc5d0556a4e06a0701dde3068308a54e517863895113350b74d89de340555a2712379084e36e60fcb89e041cd726e85373a2583
@@ -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.7.3
13
+ ruby-version: 2.6.8
14
14
  bundler-cache: true
15
- - name: Run the default task
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
@@ -1,7 +1,14 @@
1
1
  AllCops:
2
2
  NewCops: enable
3
+ SuggestExtensions: false
3
4
  TargetRubyVersion: 2.6
4
5
 
6
+ Metrics/AbcSize:
7
+ Enabled: false
8
+
9
+ Metrics/MethodLength:
10
+ Enabled: false
11
+
5
12
  Style/StringLiterals:
6
13
  Enabled: true
7
14
  EnforcedStyle: double_quotes
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- aggregate_assertions (0.1.0)
4
+ aggregate_assertions (0.1.0.pre0)
5
5
  minitest (~> 5.0)
6
6
 
7
7
  GEM
@@ -34,6 +34,7 @@ GEM
34
34
 
35
35
  PLATFORMS
36
36
  x86_64-darwin-19
37
+ x86_64-linux
37
38
 
38
39
  DEPENDENCIES
39
40
  aggregate_assertions!
data/README.md CHANGED
@@ -1,15 +1,30 @@
1
- # AggregateAssertions
1
+ # aggregate_assertions
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/aggregate_assertions`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- TODO: Delete this and the text above, and describe your gem
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
- gem 'aggregate_assertions'
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
- TODO: Write usage instructions here
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/[USERNAME]/aggregate_assertions.
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 = "Helper method to aggregate assertions for minitest"
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"
@@ -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 => ex
12
+ rescue Minitest::Assertion, StandardError => e
13
13
  raise unless AssertionAggregator.active?
14
14
 
15
- AssertionAggregator.add_error(ex)
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 => ex
26
- AssertionAggregator.add_error(ex)
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(ex)
15
- store.last.add_error(ex)
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(ex)
18
- if ex.is_a?(Minitest::Assertion)
19
- @failures << ex
17
+ def add_error(error)
18
+ if error.is_a?(Minitest::Assertion)
19
+ @failures << error
20
20
  else
21
- @other_errors << ex
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AggregateAssertions
4
- VERSION = "0.1.0.pre0"
4
+ VERSION = "0.1.0"
5
5
  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.pre0
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: Helper method to aggregate assertions for minitest
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: 1.3.1
72
+ version: '0'
73
73
  requirements: []
74
74
  rubygems_version: 3.1.6
75
75
  signing_key:
76
76
  specification_version: 4
77
- summary: Helper method to aggregate assertions for minitest
77
+ summary: Aggregate Minitest assertions
78
78
  test_files: []