minitest-set 0.1.2

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: '09646cdfc6029166a497a80db3c423ffbb825cbadf519995005ac807616a22ec'
4
+ data.tar.gz: 3644f9ae3400c445bd5afa489732066cd9da6aede703bca05c5a4c598fe9d676
5
+ SHA512:
6
+ metadata.gz: 9c8bc1a82e0dc9f16f424a311690e559c4f8d593ce3ea697d1a5fb3315d8efc8cada6c447d32ff7b489f370a4e6aa082b1f775ed349265474d8df1d161dffae2
7
+ data.tar.gz: 9dde8de8e25bff7e704f9455852d9dee27876b0e7ff2db6c924ac1ae186518266f8b5df09a634e9fdd113d0bc4e83ec35a63768feb7fbcd45d0f5f8bd02cb784
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-04-18
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in minitest-set.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "minitest", "~> 5.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,23 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ minitest-set (0.1.2)
5
+ minitest
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ minitest (5.15.0)
11
+ rake (13.0.6)
12
+
13
+ PLATFORMS
14
+ arm64-darwin-20
15
+ x86_64-linux
16
+
17
+ DEPENDENCIES
18
+ minitest (~> 5.0)
19
+ minitest-set!
20
+ rake (~> 13.0)
21
+
22
+ BUNDLED WITH
23
+ 2.2.30
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Kasper Timm Hansen
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,37 @@
1
+ # Minitest::Set
2
+
3
+ Set configurations for the duration of a test or a block with automatic reset.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'minitest-set'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install minitest-set
20
+
21
+ ## Usage
22
+
23
+ See [the test for usage](https://github.com/kaspth/minitest-set/blob/main/test/minitest/set_test.rb).
24
+
25
+ ## Development
26
+
27
+ 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.
28
+
29
+ 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).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kaspth/minitest-set.
34
+
35
+ ## License
36
+
37
+ 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,12 @@
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
+ task default: :test
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 "minitest/set"
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,25 @@
1
+ class Minitest::Set::Change
2
+ def initialize(object, **attributes)
3
+ @object, @attributes = object, attributes
4
+ end
5
+
6
+ def setup
7
+ @previous_attributes = extract_previous_attributes
8
+ set attributes
9
+ end
10
+
11
+ def teardown
12
+ set previous_attributes
13
+ end
14
+
15
+ private
16
+ attr_reader :object, :attributes, :previous_attributes
17
+
18
+ def extract_previous_attributes
19
+ attributes.keys.to_h { |name| [ name, object.public_send(name) ] }
20
+ end
21
+
22
+ def set(attributes)
23
+ attributes.each { |name, value| object.public_send("#{name}=", value) }
24
+ end
25
+ end
@@ -0,0 +1,31 @@
1
+ module Minitest::Set::TestHelper
2
+ def self.included(base)
3
+ base.extend ClassMethods
4
+ end
5
+
6
+ module ClassMethods
7
+ attr_reader :minitest_sets
8
+
9
+ def set(object, **attributes)
10
+ (@minitest_sets ||= []) << Minitest::Set::Change.new(object, **attributes)
11
+ end
12
+ end
13
+
14
+ def before_setup
15
+ super
16
+ @minitest_sets = self.class.minitest_sets&.dup
17
+ @minitest_sets&.each(&:setup)
18
+ end
19
+
20
+ def before_teardown
21
+ super
22
+ @minitest_sets&.reverse_each(&:teardown)
23
+ end
24
+
25
+ def set(object, **attributes, &block)
26
+ (@minitest_sets ||= []) << Minitest::Set::Change.new(object, **attributes).tap(&:setup)
27
+ block&.call
28
+ ensure
29
+ @minitest_sets.pop.teardown if block
30
+ end
31
+ end
@@ -0,0 +1,5 @@
1
+ module Minitest
2
+ module Set
3
+ VERSION = "0.1.2"
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ module Minitest
2
+ module Set
3
+ autoload :TestHelper, "minitest/set/test_helper"
4
+ autoload :Change, "minitest/set/change"
5
+ end
6
+
7
+ # minitest's plugin loading happens in `Minitest.autorun`'s `at_exit` hook,
8
+ # so we'd have already crashed through any class-level `set` calls by that point.
9
+ # Thus the eager include.
10
+ Test.include Set::TestHelper
11
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/minitest/set/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "minitest-set"
7
+ spec.version = Minitest::Set::VERSION
8
+ spec.authors = ["Kasper Timm Hansen"]
9
+ spec.email = ["hey@kaspth.com"]
10
+
11
+ spec.summary = "Set configurations for the duration of a test or a block with automatic reset."
12
+ spec.homepage = "https://github.com/kaspth/minitest-set"
13
+ spec.license = "MIT"
14
+ spec.required_ruby_version = ">= 2.7.0"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = spec.homepage
18
+ spec.metadata["changelog_uri"] = "https://github.com/kaspth/minitest-set/blob/main/CHANGELOG.md"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`.split("\x0").reject do |f|
24
+ (f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
25
+ end
26
+ end
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_dependency "minitest"
32
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: minitest-set
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Kasper Timm Hansen
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-04-18 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: '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
+ description:
28
+ email:
29
+ - hey@kaspth.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - CHANGELOG.md
35
+ - Gemfile
36
+ - Gemfile.lock
37
+ - LICENSE.txt
38
+ - README.md
39
+ - Rakefile
40
+ - bin/console
41
+ - bin/setup
42
+ - lib/minitest/set.rb
43
+ - lib/minitest/set/change.rb
44
+ - lib/minitest/set/test_helper.rb
45
+ - lib/minitest/set/version.rb
46
+ - minitest-set.gemspec
47
+ homepage: https://github.com/kaspth/minitest-set
48
+ licenses:
49
+ - MIT
50
+ metadata:
51
+ homepage_uri: https://github.com/kaspth/minitest-set
52
+ source_code_uri: https://github.com/kaspth/minitest-set
53
+ changelog_uri: https://github.com/kaspth/minitest-set/blob/main/CHANGELOG.md
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 2.7.0
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubygems_version: 3.2.30
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: Set configurations for the duration of a test or a block with automatic reset.
73
+ test_files: []