minitest-keyword 0.0.1 → 0.0.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 +4 -4
- data/README.md +44 -1
- data/lib/minitest/keyword.rb +30 -19
- data/lib/minitest/keyword/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a6def3f236a875e344c8319d67b706fcc74b1ef
|
4
|
+
data.tar.gz: 674ed4c01d9426b89e90b08f9607b7be684666cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d80dbaa4353678dc91da6e60f44858a427f5ac8148eed53840c85657717135e0fdb051396118497f6ea12f951b5059f373c24b8c3d4fc694ef142763b63b4f3
|
7
|
+
data.tar.gz: ee43f67179591e194469a161d88307dc2ce4ebd904f1b00f199b98a772c1284da111587ee2d97d4c28df81285f9bfd53e8881934baf8c9ef6804e71b1842ca3b
|
data/README.md
CHANGED
@@ -33,11 +33,54 @@ assert_equal 'foo', foo.inspect
|
|
33
33
|
to:
|
34
34
|
|
35
35
|
```ruby
|
36
|
-
assert_equal
|
36
|
+
assert_equal expected: 'foo', actual: foo.inspect
|
37
37
|
```
|
38
38
|
|
39
39
|
All of the standard Minitest assertions can now be used with keyword arguments. Note that this gem is still backwards-compatible with Minitest itself, so your existing tests won't break.
|
40
40
|
|
41
|
+
## Cheat Sheet
|
42
|
+
|
43
|
+
The actual keyword method creation is done through introspection, but the equivalent method signatures are listed below. Note that when you see `message: nil` it effectively means that you can pass through a message or it will use whatever standard Minitest message is configured for that assertion.
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
assert test:, message: nil
|
47
|
+
assert_empty object:, message: nil
|
48
|
+
assert_equal expected:, actual:, message: nil
|
49
|
+
assert_in_delta expected:, actual:, delta:, message: nil
|
50
|
+
assert_in_epsilon a:, b:, epsilon:, message: nil
|
51
|
+
assert_includes collection:, object:, message: nil
|
52
|
+
assert_instance_of class:, object:, message: nil
|
53
|
+
assert_kind_of class:, object:, message: nil
|
54
|
+
assert_match matcher:, object:, message: nil
|
55
|
+
assert_nil object:, message: nil
|
56
|
+
assert_operator o1:, op:, o2:, message: nil
|
57
|
+
assert_output stdout:, stderr:
|
58
|
+
assert_predicate o1:, op:, message: nil
|
59
|
+
assert_raises expected:
|
60
|
+
assert_respond_to object:, method:, message: nil
|
61
|
+
assert_same expected:, actual:, message: nil
|
62
|
+
assert_throws symbol:, message: nil
|
63
|
+
```
|
64
|
+
|
65
|
+
The associated refutations are also overridden, with the below signatures.
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
refute test:, message: nil
|
69
|
+
refute_empty object:, message: nil
|
70
|
+
refute_equal expected:, actual:, message: nil
|
71
|
+
refute_in_delta expected:, actual:, delta:, message: nil
|
72
|
+
refute_in_epsilon a:, b:, epsilon:, message: nil
|
73
|
+
refute_includes collection:, object:, message: nil
|
74
|
+
refute_instance_of class:, object:, message: nil
|
75
|
+
refute_kind_of class:, object:, message: nil
|
76
|
+
refute_match matcher:, object:, message: nil
|
77
|
+
refute_nil object:, message: nil
|
78
|
+
refute_operator o1:, op:, o2:, message: nil
|
79
|
+
refute_predicate o1:, op:, message: nil
|
80
|
+
refute_respond_to object:, method:, message: nil
|
81
|
+
refute_same expected:, actual:, message: nil
|
82
|
+
```
|
83
|
+
|
41
84
|
## Development
|
42
85
|
|
43
86
|
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.
|
data/lib/minitest/keyword.rb
CHANGED
@@ -5,6 +5,17 @@ module Minitest
|
|
5
5
|
# The module containing overridden assertion methods that will be prepended
|
6
6
|
# into the Test class
|
7
7
|
module Keyword
|
8
|
+
# Longer names so that the keywords make more sense
|
9
|
+
ALIASES = {
|
10
|
+
act: :actual,
|
11
|
+
cls: :class,
|
12
|
+
exp: :expected,
|
13
|
+
meth: :method,
|
14
|
+
msg: :message,
|
15
|
+
obj: :object,
|
16
|
+
sym: :symbol
|
17
|
+
}.freeze
|
18
|
+
|
8
19
|
# Raised if someone tries to pass both the regular arguments and the
|
9
20
|
# keyword arguments
|
10
21
|
class OverloadedArgumentError < ArgumentError
|
@@ -28,27 +39,27 @@ module Minitest
|
|
28
39
|
next if parameters.empty?
|
29
40
|
|
30
41
|
define_method(method_name) do |*args, **kwargs, &block|
|
31
|
-
passed_params =
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
if args.length <= index && !kwargs.key?(arg_name) && type == :req
|
38
|
-
raise MissingRequiredArgumentError.new(method_name, arg_name)
|
39
|
-
end
|
40
|
-
|
41
|
-
if type == :rest
|
42
|
-
args.any? ? args[index..-1] : kwargs[arg_name]
|
43
|
-
else
|
44
|
-
args[index] || kwargs[arg_name]
|
45
|
-
end
|
42
|
+
passed_params = []
|
43
|
+
|
44
|
+
parameters.each.with_index do |(type, arg_name), index|
|
45
|
+
if args.length > index &&
|
46
|
+
(kwargs.key?(arg_name) || kwargs.key?(ALIASES[arg_name]))
|
47
|
+
raise OverloadedArgumentError.new(method_name, arg_name)
|
46
48
|
end
|
47
49
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
50
|
+
if type == :req && args.length <= index &&
|
51
|
+
!kwargs.key?(arg_name) && !kwargs.key?(ALIASES[arg_name])
|
52
|
+
raise MissingRequiredArgumentError.new(method_name, arg_name)
|
53
|
+
end
|
54
|
+
|
55
|
+
if type == :rest && args.any?
|
56
|
+
passed_params += args[index..-1]
|
57
|
+
elsif type == :rest
|
58
|
+
passed_params += (kwargs[arg_name] || kwargs[ALIASES[arg_name]])
|
59
|
+
else
|
60
|
+
passed_params <<
|
61
|
+
(args[index] || kwargs[arg_name] || kwargs[ALIASES[arg_name]])
|
62
|
+
end
|
52
63
|
end
|
53
64
|
|
54
65
|
super(*passed_params, &block)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minitest-keyword
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Deisz
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|