prolog_minitest_matchers 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fab4720efbabb4f86251454fb1107c3b12b133e2
4
+ data.tar.gz: 10d7bb2ce0ce02a2308193a66d1853b89ba45d57
5
+ SHA512:
6
+ metadata.gz: e44d46dde47f14931e9056e898e6b10a9361d48f314b3ad1b810dbe8681e4d246689a6b30a9a722307601c72d8d09bee0d34a1db7d7fa9deadd67f6c9f3e9853
7
+ data.tar.gz: 488130da26e438b86938551ced8286f7fbb2252e28923fe0e27d9f03961d40e062d3a78b5371e1ff0e6024db7ffc7861448d5a0aa1e769466defb39d7bcedf91
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /o-rdoc/
11
+ !/bin/console
12
+ !/bin/setup
13
+ /bin/
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.5
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at jdickey@seven-sigma.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in prolog_minitest_matchers.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Jeff Dickey
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,109 @@
1
+ # PrologMinitestMatchers
2
+
3
+ This is an evolving collection of MiniTest and MiniTest::Spec custom matchers which we have found useful in our work. As we have built up our applications, we've seen the disparity between *tests* and *assertions* grow; often to a differential of 30% or even more. While some standard MiniTest::Spec expectations involve multiple assertions, we can police our own.
4
+
5
+ For example, we often have class API tests that look something like
6
+
7
+ ```ruby
8
+ # in foo.rb
9
+ class Foo
10
+ def initialize(foo:, bar:)
11
+ # ...
12
+ end
13
+
14
+ # ...
15
+ end
16
+
17
+ # in foo_test.rb
18
+
19
+ describe 'Foo' do
20
+ describe 'initialisation' do
21
+ describe 'requires parameters for' do
22
+ let(:params) { { foo: 'some foo', bar: 'some bar' } }
23
+
24
+ it 'foo' do
25
+ params.delete :foo
26
+ error = expect { Foo.new params }.must_raise ArgumentError
27
+ expect(error.message).must_equal 'missing keyword: foo'
28
+ end
29
+
30
+ it 'bar' do
31
+ # ...
32
+ end
33
+ end
34
+
35
+ # ... other initialisation tests
36
+ end
37
+
38
+ # ... other tests
39
+ end
40
+
41
+ ```
42
+
43
+ That parameter test has two expectations: first, that an `ArgumentError` will be raised; and second, that that error's message will be as expected. Instead, how about this:
44
+
45
+ ```ruby
46
+
47
+ # in foo_test.rb
48
+
49
+ describe 'Foo' do
50
+ describe 'initialisation' do
51
+ describe 'requires parameters for' do
52
+ let(:params) { { foo: 'some foo', bar: 'some bar' } }
53
+
54
+ it 'foo' do
55
+ expect(Foo).must_require_initialize_parameter params, :foo
56
+ end
57
+
58
+ it 'bar' do
59
+ expect(Foo).must_require_initialize_parameter params, :bar
60
+ end
61
+ end
62
+
63
+ # ... other initialisation tests
64
+ end
65
+
66
+ # ... other tests
67
+ end
68
+
69
+ ```
70
+
71
+ Two expectations; two assertions; two much more *intention-revealing* expectations.
72
+
73
+ ## Installation
74
+
75
+ Add this line to your application's Gemfile:
76
+
77
+ ```ruby
78
+ gem 'prolog_minitest_matchers'
79
+ ```
80
+
81
+ And then execute:
82
+
83
+ $ bundle
84
+
85
+ Or install it yourself as:
86
+
87
+ $ gem install prolog_minitest_matchers
88
+
89
+ ## Usage
90
+
91
+ See the discussion at the top of this page for a description of how to use the `must_require_initialize_parameter` expectation, which is a MiniTest::Spec wrapper around the `assert_requires_initialize_parameter` MiniTest assertion.
92
+
93
+ Note that this assertion will verify that the parameter expected to fail when removed must exist in the full set of parameters specified.
94
+
95
+ As other assertions/expectations are added to this Gem over the next few weeks, *including* formal test coverage of the asserters and expectations themselves, this usage information will be broken out into a separate document. Stay tuned – or open a pull request!
96
+
97
+ ## Development
98
+
99
+ After checking out the repo, run `bin/setup` to install dependencies (which as of now must already be installed on your local system). Then, run `bin/rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
100
+
101
+ To install this gem onto your local machine, run `bin/rake install`. Maintainers should be familiar with the standard procedure for releasing an updated Gem version to RubyGems.
102
+
103
+ ## Contributing
104
+
105
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/prolog_minitest_matchers. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
106
+
107
+ ## License
108
+
109
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'prolog_minitest_matchers/version'
4
+ require 'prolog_minitest_matchers/matchers/requires_initialize_parameter'
5
+
6
+ module PrologMinitestMatchers
7
+ # Your code goes here...
8
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MiniTest
4
+ # Adding custom assertions to make specs easier to read
5
+ module Assertions
6
+ # Actual test logic for `#assert_requires_initialize_parameter`.
7
+ class AssertRequiresInitializeParameter
8
+ def initialize(klass, full_params, param_key, message)
9
+ @klass = klass
10
+ @full_params = full_params
11
+ @param_key = param_key
12
+ @message = initial_message_from(message, param_key)
13
+ self
14
+ end
15
+
16
+ def call(assert)
17
+ assert.call(errors_as_expected(save_and_try_to_init), message)
18
+ end
19
+
20
+ private
21
+
22
+ attr_reader :full_params, :klass, :message, :param_key
23
+
24
+ def errors_as_expected(errors)
25
+ errors[:expected]&.message == message
26
+ end
27
+
28
+ def initial_message_from(message, param_key)
29
+ message || "missing keyword: #{param_key}"
30
+ end
31
+
32
+ def save_and_try_to_init
33
+ verify_param_in_list
34
+ saved_item = full_params[param_key]
35
+ full_params.delete param_key
36
+ errors = try_to_init
37
+ full_params[param_key] = saved_item
38
+ errors
39
+ end
40
+
41
+ def try_to_init
42
+ expected_error = nil
43
+ begin
44
+ _ = klass.new full_params
45
+ rescue ArgumentError => error
46
+ expected_error = error
47
+ rescue StandardError => error
48
+ ap [:matcher_48, 'Unexpected error', error]
49
+ end
50
+ { expected: expected_error }
51
+ end
52
+
53
+ def verify_param_in_list
54
+ no_param_message = "No key :#{param_key} in #{full_params}!"
55
+ fail KeyError, no_param_message unless full_params.key?(param_key)
56
+ end
57
+ end # class MiniTest::Assertions::AssertRequiresInitializeParameter
58
+ end
59
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'minitest/spec'
4
+
5
+ require_relative './asserters/assert_requires_initialize_parameter'
6
+
7
+ module MiniTest
8
+ # Adding custom assertions to make specs easier to read
9
+ module Assertions
10
+ def assert_requires_initialize_parameter(klass, full_params, param_key,
11
+ message = nil)
12
+ AssertRequiresInitializeParameter.new(klass, full_params, param_key,
13
+ message).call(method(:assert))
14
+ end
15
+ end
16
+
17
+ # Make it available to MiniTest::Spec
18
+ module Expectations
19
+ infect_an_assertion :assert_requires_initialize_parameter,
20
+ :must_require_initialize_parameter, :reverse
21
+ end
22
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PrologMinitestMatchers
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'prolog_minitest_matchers/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "prolog_minitest_matchers"
8
+ spec.version = PrologMinitestMatchers::VERSION
9
+ spec.authors = ["Jeff Dickey"]
10
+ spec.email = ["jdickey@seven-sigma.com"]
11
+
12
+ spec.summary = %q{Custom Minitest matcher(s) we've developed for our own use.}
13
+ # spec.description = %q{TODO: Write a longer description or delete this line.}
14
+ spec.homepage = "https://github.com/TheProlog/prolog_minitest_matchers"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ # end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.12", ">= 1.12.5"
31
+ spec.add_development_dependency "rake", "~> 11.2", ">= 11.2.2"
32
+ spec.add_development_dependency "minitest", "~> 5.9", ">= 5.9.0"
33
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: prolog_minitest_matchers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jeff Dickey
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-07-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.12.5
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.12'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.12.5
33
+ - !ruby/object:Gem::Dependency
34
+ name: rake
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '11.2'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 11.2.2
43
+ type: :development
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '11.2'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 11.2.2
53
+ - !ruby/object:Gem::Dependency
54
+ name: minitest
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '5.9'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 5.9.0
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '5.9'
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 5.9.0
73
+ description:
74
+ email:
75
+ - jdickey@seven-sigma.com
76
+ executables: []
77
+ extensions: []
78
+ extra_rdoc_files: []
79
+ files:
80
+ - ".gitignore"
81
+ - ".travis.yml"
82
+ - CODE_OF_CONDUCT.md
83
+ - Gemfile
84
+ - LICENSE.txt
85
+ - README.md
86
+ - Rakefile
87
+ - lib/prolog_minitest_matchers.rb
88
+ - lib/prolog_minitest_matchers/matchers/asserters/assert_requires_initialize_parameter.rb
89
+ - lib/prolog_minitest_matchers/matchers/requires_initialize_parameter.rb
90
+ - lib/prolog_minitest_matchers/version.rb
91
+ - prolog_minitest_matchers.gemspec
92
+ homepage: https://github.com/TheProlog/prolog_minitest_matchers
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.6.6
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Custom Minitest matcher(s) we've developed for our own use.
116
+ test_files: []