minitest-keyword 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 88c45029ebc3e0ed80c93e43cc14c1158b2af479
4
- data.tar.gz: 151557967681a6fb8a3da72e4efac0e3f965bea7
3
+ metadata.gz: 4a6def3f236a875e344c8319d67b706fcc74b1ef
4
+ data.tar.gz: 674ed4c01d9426b89e90b08f9607b7be684666cb
5
5
  SHA512:
6
- metadata.gz: ce9eb124236528069c6658d0caf49d35aa04bcc274f14dc2e6c194be6b535615a70674cfd9c41b3bc7b362981b8c72e39c712fd9a8390d0d966ee0fa444c710c
7
- data.tar.gz: 7011f1dcc776b55a7647aba423683f6aca1eda1129c3844ca86041e42c4b3b91319b40ae3c8e6178e5cafeb021b503539f124866a83c0bfc0fb7cc612b644537
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 exp: 'foo', act: foo.inspect
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.
@@ -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
- parameters.map.with_index do |(type, arg_name), index|
33
- if args.length > index && kwargs.key?(arg_name)
34
- raise OverloadedArgumentError.new(method_name, arg_name)
35
- end
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
- # Special case for behavior like `assert_raises`, where a splat takes
49
- # all of the types of errors for rescue
50
- if parameters.length == 1 && parameters[0][0] == :rest
51
- passed_params.flatten!(1)
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)
@@ -1,5 +1,5 @@
1
1
  module Minitest
2
2
  module Keyword
3
- VERSION = '0.0.1'.freeze
3
+ VERSION = '0.0.2'.freeze
4
4
  end
5
5
  end
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.1
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-07 00:00:00.000000000 Z
11
+ date: 2017-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest