aggregate_assertions 0.1.0.pre0

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
+ SHA256:
3
+ metadata.gz: 10b578ef8e1e9b5cdcdc8da16ad1f01e6b022d786401cf31c0b57bfe7a90e4dc
4
+ data.tar.gz: ca339ae9a8fa78e2a8d7e46a2d688f9278b146bcdd9511a88934a2530ce044de
5
+ SHA512:
6
+ metadata.gz: 56295e2ac81bd5c8ffdb590228c61ba52088e46c0ee0e9e07551554debc0c386c2ee389def6ff28ed326622cd53fbe2161b770b4bc7966ab0478194bec310ca7
7
+ data.tar.gz: 99769e351cd4ff99f3889dc3631c154b9e91233edf2482768b10ddbd539f0fdcd70faeae09086a6ae191321d985de30c63245f309ab99660b6cb6acdb7b34efa
@@ -0,0 +1,16 @@
1
+ name: Ruby
2
+
3
+ on: [push,pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - name: Set up Ruby
11
+ uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: 2.7.3
14
+ bundler-cache: true
15
+ - name: Run the default task
16
+ run: bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.rubocop.yml ADDED
@@ -0,0 +1,14 @@
1
+ AllCops:
2
+ NewCops: enable
3
+ TargetRubyVersion: 2.6
4
+
5
+ Style/StringLiterals:
6
+ Enabled: true
7
+ EnforcedStyle: double_quotes
8
+
9
+ Style/StringLiteralsInInterpolation:
10
+ Enabled: true
11
+ EnforcedStyle: double_quotes
12
+
13
+ Layout/LineLength:
14
+ Max: 120
data/CHANGELOG.md ADDED
@@ -0,0 +1,4 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2021-07-17
4
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in aggregate_assertions.gemspec
6
+ gemspec
7
+
8
+ gem "minitest", "~> 5.0"
9
+ gem "rake", "~> 13.0"
10
+ gem "rubocop", "~> 1.7"
11
+ gem "rubocop-minitest"
data/Gemfile.lock ADDED
@@ -0,0 +1,46 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ aggregate_assertions (0.1.0)
5
+ minitest (~> 5.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.2)
11
+ minitest (5.14.4)
12
+ parallel (1.20.1)
13
+ parser (3.0.1.1)
14
+ ast (~> 2.4.1)
15
+ rainbow (3.0.0)
16
+ rake (13.0.3)
17
+ regexp_parser (2.1.1)
18
+ rexml (3.2.5)
19
+ rubocop (1.18.2)
20
+ parallel (~> 1.10)
21
+ parser (>= 3.0.0.0)
22
+ rainbow (>= 2.2.2, < 4.0)
23
+ regexp_parser (>= 1.8, < 3.0)
24
+ rexml
25
+ rubocop-ast (>= 1.7.0, < 2.0)
26
+ ruby-progressbar (~> 1.7)
27
+ unicode-display_width (>= 1.4.0, < 3.0)
28
+ rubocop-ast (1.7.0)
29
+ parser (>= 3.0.1.1)
30
+ rubocop-minitest (0.14.0)
31
+ rubocop (>= 0.90, < 2.0)
32
+ ruby-progressbar (1.11.0)
33
+ unicode-display_width (2.0.0)
34
+
35
+ PLATFORMS
36
+ x86_64-darwin-19
37
+
38
+ DEPENDENCIES
39
+ aggregate_assertions!
40
+ minitest (~> 5.0)
41
+ rake (~> 13.0)
42
+ rubocop (~> 1.7)
43
+ rubocop-minitest
44
+
45
+ BUNDLED WITH
46
+ 2.2.19
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Tim Perkins
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,39 @@
1
+ # AggregateAssertions
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.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'aggregate_assertions'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install aggregate_assertions
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ 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
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/aggregate_assertions.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ require "rubocop/rake_task"
13
+
14
+ RuboCop::RakeTask.new
15
+
16
+ task default: %i[test rubocop]
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/aggregate_assertions/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "aggregate_assertions"
7
+ spec.version = AggregateAssertions::VERSION
8
+ spec.authors = ["Tim Perkins"]
9
+ spec.email = ["tjwp@users.noreply.github.com"]
10
+
11
+ spec.summary = "Helper method to aggregate assertions for minitest"
12
+ spec.description = spec.summary
13
+ spec.homepage = "https://github.com/tjwp/aggregate_assertions"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = spec.homepage
21
+ spec.metadata["changelog_uri"] = "https://github.com/tjwp/aggregate_assertions/blob/main/CHANGELOG.md"
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_dependency("minitest", "~> 5.0")
33
+ end
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "aggregate_assertions"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
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,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "minitest"
4
+ require_relative "aggregate_assertions/version"
5
+ require_relative "aggregate_assertions/assertion_aggregator"
6
+
7
+ module AggregateAssertions
8
+ # Contains patches to the Minitest::Test class
9
+ module TestPatch
10
+ def assert(test, msg = nil)
11
+ super
12
+ rescue Minitest::Assertion, StandardError => ex
13
+ raise unless AssertionAggregator.active?
14
+
15
+ AssertionAggregator.add_error(ex)
16
+ end
17
+
18
+ def aggregate_assertions(label = nil)
19
+ flunk "aggregate_assertions requires a block" unless block_given?
20
+
21
+ AssertionAggregator.open_failure_group(label)
22
+
23
+ begin
24
+ yield
25
+ rescue Minitest::Assertion, StandardError => ex
26
+ AssertionAggregator.add_error(ex)
27
+ ensure
28
+ failure_group = AssertionAggregator.close_failure_group
29
+ end
30
+
31
+ return if failure_group.success?
32
+
33
+ raise failure_group.error unless AssertionAggregator.active?
34
+
35
+ AssertionAggregator.add_error(failure_group.error)
36
+ end
37
+ end
38
+ end
39
+
40
+ Minitest::Test.prepend(AggregateAssertions::TestPatch)
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative("error")
4
+ require_relative("failure_group")
5
+
6
+ module AggregateAssertions
7
+ # Main entry-point for the interacting with the state of aggregation.
8
+ module AssertionAggregator
9
+ class << self
10
+ def active?
11
+ !store.nil? && !store.empty?
12
+ end
13
+
14
+ def add_error(ex)
15
+ store.last.add_error(ex)
16
+ end
17
+
18
+ def open_failure_group(label = nil)
19
+ initialize_store << FailureGroup.new(label: label, location: location)
20
+ end
21
+
22
+ def close_failure_group
23
+ store.pop
24
+ end
25
+
26
+ private
27
+
28
+ def store
29
+ Thread.current[:__mt_aggregate]
30
+ end
31
+
32
+ def initialize_store
33
+ Thread.current[:__mt_aggregate] ||= []
34
+ end
35
+
36
+ def location
37
+ caller(3, 1).first.sub(/:in .*$/, "")
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Minitest
4
+ class MultipleAssertionError < Minitest::Assertion
5
+ attr_reader :location
6
+
7
+ def initialize(msg = nil, location: nil, result_label: nil)
8
+ super(msg)
9
+ @location = location
10
+ @result_label = result_label
11
+ end
12
+
13
+ def result_label
14
+ @result_label || super
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "error"
4
+
5
+ module AggregateAssertions
6
+ # This class is used to aggregates the failures/errors for an aggregate block.
7
+ class FailureGroup
8
+ attr_reader :label, :location
9
+
10
+ def initialize(location:, label: nil)
11
+ @location = location
12
+ @label = label
13
+ @failures = []
14
+ @other_errors = []
15
+ end
16
+
17
+ def add_error(ex)
18
+ if ex.is_a?(Minitest::Assertion)
19
+ @failures << ex
20
+ else
21
+ @other_errors << ex
22
+ end
23
+ end
24
+
25
+ def error
26
+ case @failures.size + @other_errors.size
27
+ when 0
28
+ nil
29
+ when 1
30
+ @failures.first || @other_errors.first
31
+ else
32
+ group_error
33
+ end
34
+ end
35
+
36
+ def success?
37
+ @failures.empty? && @other_errors.empty?
38
+ end
39
+
40
+ private
41
+
42
+ def group_error
43
+ Minitest::MultipleAssertionError.new(message_for_errors,
44
+ location: location,
45
+ result_label: result_label)
46
+ end
47
+
48
+ def message_for_errors
49
+ errors = @failures + @other_errors
50
+ "There were #{errors.size} errors#{group_label}:\n" +
51
+ errors.map.with_index do |error, index|
52
+ if error.is_a?(Minitest::Assertion)
53
+ " #{index + 1}) #{error.location}:\n#{indent(error.message)}\n"
54
+ else
55
+ " #{index + 1}) #{error.class}: #{error.message}\n#{indent(error.backtrace.first)}\n"
56
+ end
57
+ end.join("\n")
58
+ end
59
+
60
+ def group_label
61
+ label ? " in group #{label.inspect}" : ""
62
+ end
63
+
64
+ def result_label
65
+ @other_errors.any? ? "Error" : nil
66
+ end
67
+
68
+ def indent(string, size: 6)
69
+ prefix = (" " * size)
70
+ string.split("\n").map { |str| "#{prefix}#{str}" }.join("\n")
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AggregateAssertions
4
+ VERSION = "0.1.0.pre0"
5
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aggregate_assertions
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.pre0
5
+ platform: ruby
6
+ authors:
7
+ - Tim Perkins
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-07-17 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.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.0'
27
+ description: Helper method to aggregate assertions for minitest
28
+ email:
29
+ - tjwp@users.noreply.github.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".github/workflows/main.yml"
35
+ - ".gitignore"
36
+ - ".rubocop.yml"
37
+ - CHANGELOG.md
38
+ - Gemfile
39
+ - Gemfile.lock
40
+ - LICENSE.txt
41
+ - README.md
42
+ - Rakefile
43
+ - aggregate_assertions.gemspec
44
+ - bin/console
45
+ - bin/setup
46
+ - lib/aggregate_assertions.rb
47
+ - lib/aggregate_assertions/assertion_aggregator.rb
48
+ - lib/aggregate_assertions/error.rb
49
+ - lib/aggregate_assertions/failure_group.rb
50
+ - lib/aggregate_assertions/version.rb
51
+ homepage: https://github.com/tjwp/aggregate_assertions
52
+ licenses:
53
+ - MIT
54
+ metadata:
55
+ allowed_push_host: https://rubygems.org
56
+ homepage_uri: https://github.com/tjwp/aggregate_assertions
57
+ source_code_uri: https://github.com/tjwp/aggregate_assertions
58
+ changelog_uri: https://github.com/tjwp/aggregate_assertions/blob/main/CHANGELOG.md
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: 2.6.0
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">"
71
+ - !ruby/object:Gem::Version
72
+ version: 1.3.1
73
+ requirements: []
74
+ rubygems_version: 3.1.6
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: Helper method to aggregate assertions for minitest
78
+ test_files: []