assert 2.17.0 → 2.18.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -2
  3. data/README.md +66 -41
  4. data/assert.gemspec +2 -3
  5. data/lib/assert.rb +0 -10
  6. data/lib/assert/actual_value.rb +127 -0
  7. data/lib/assert/assert_runner.rb +0 -3
  8. data/lib/assert/assertions.rb +10 -23
  9. data/lib/assert/cli.rb +30 -46
  10. data/lib/assert/config.rb +0 -4
  11. data/lib/assert/config_helpers.rb +0 -4
  12. data/lib/assert/context.rb +18 -9
  13. data/lib/assert/context/let_dsl.rb +13 -0
  14. data/lib/assert/context/method_missing.rb +19 -0
  15. data/lib/assert/context/setup_dsl.rb +0 -4
  16. data/lib/assert/context/subject_dsl.rb +23 -28
  17. data/lib/assert/context/suite_dsl.rb +0 -4
  18. data/lib/assert/context/test_dsl.rb +0 -4
  19. data/lib/assert/context_info.rb +0 -4
  20. data/lib/assert/default_runner.rb +0 -4
  21. data/lib/assert/default_suite.rb +0 -5
  22. data/lib/assert/default_view.rb +0 -4
  23. data/lib/assert/factory.rb +0 -3
  24. data/lib/assert/file_line.rb +0 -4
  25. data/lib/assert/macro.rb +0 -3
  26. data/lib/assert/macros/methods.rb +4 -10
  27. data/lib/assert/result.rb +2 -17
  28. data/lib/assert/runner.rb +0 -3
  29. data/lib/assert/stub.rb +15 -1
  30. data/lib/assert/suite.rb +0 -4
  31. data/lib/assert/test.rb +2 -7
  32. data/lib/assert/utils.rb +0 -4
  33. data/lib/assert/version.rb +1 -1
  34. data/lib/assert/view.rb +0 -3
  35. data/lib/assert/view_helpers.rb +0 -11
  36. data/log/{.gitkeep → .keep} +0 -0
  37. data/test/helper.rb +23 -29
  38. data/test/support/factory.rb +14 -0
  39. data/test/support/inherited_stuff.rb +0 -2
  40. data/test/system/stub_tests.rb +332 -352
  41. data/test/system/test_tests.rb +98 -124
  42. data/test/unit/actual_value_tests.rb +335 -0
  43. data/test/unit/assert_tests.rb +121 -46
  44. data/test/unit/assertions/assert_block_tests.rb +30 -35
  45. data/test/unit/assertions/assert_empty_tests.rb +33 -35
  46. data/test/unit/assertions/assert_equal_tests.rb +75 -83
  47. data/test/unit/assertions/assert_file_exists_tests.rb +32 -36
  48. data/test/unit/assertions/assert_includes_tests.rb +38 -41
  49. data/test/unit/assertions/assert_instance_of_tests.rb +34 -37
  50. data/test/unit/assertions/assert_kind_of_tests.rb +34 -37
  51. data/test/unit/assertions/assert_match_tests.rb +34 -37
  52. data/test/unit/assertions/assert_nil_tests.rb +30 -35
  53. data/test/unit/assertions/assert_raises_tests.rb +54 -60
  54. data/test/unit/assertions/assert_respond_to_tests.rb +36 -39
  55. data/test/unit/assertions/assert_same_tests.rb +86 -88
  56. data/test/unit/assertions/assert_true_false_tests.rb +60 -66
  57. data/test/unit/assertions_tests.rb +14 -17
  58. data/test/unit/config_helpers_tests.rb +41 -39
  59. data/test/unit/config_tests.rb +38 -37
  60. data/test/unit/context/let_dsl_tests.rb +10 -0
  61. data/test/unit/context/setup_dsl_tests.rb +68 -87
  62. data/test/unit/context/subject_dsl_tests.rb +15 -49
  63. data/test/unit/context/suite_dsl_tests.rb +15 -20
  64. data/test/unit/context/test_dsl_tests.rb +50 -57
  65. data/test/unit/context_info_tests.rb +23 -18
  66. data/test/unit/context_tests.rb +183 -194
  67. data/test/unit/default_runner_tests.rb +1 -7
  68. data/test/unit/default_suite_tests.rb +57 -56
  69. data/test/unit/factory_tests.rb +5 -6
  70. data/test/unit/file_line_tests.rb +33 -39
  71. data/test/unit/macro_tests.rb +14 -18
  72. data/test/unit/result_tests.rb +159 -196
  73. data/test/unit/runner_tests.rb +64 -71
  74. data/test/unit/suite_tests.rb +58 -59
  75. data/test/unit/test_tests.rb +125 -136
  76. data/test/unit/utils_tests.rb +43 -54
  77. data/test/unit/view_helpers_tests.rb +54 -58
  78. data/test/unit/view_tests.rb +22 -27
  79. metadata +15 -10
  80. data/tmp/.gitkeep +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9f64c7aa2c506b0fcf989763e437a103dd5401213f88bce9b7f4e7712db7fbe0
4
- data.tar.gz: 3f5c30459a2528888dc24e356e626939e1fd204e1d287f06bbedf909c2d7eee9
3
+ metadata.gz: 7ed950be1bca18deac9277678d40abc99072df13d5e23d21460c7e9b72a1c4ab
4
+ data.tar.gz: cd7c0eec0a939400f384c6e8d69b7fbb27856f3ed9fdfca25ae1ab48404c822f
5
5
  SHA512:
6
- metadata.gz: 6e9f3644f6c86856e3fd5c13560ecd6f7cadf194b158ccb3526267476745de34ca8ac87968cc5bf5f8d08d690a8cea40547e2a4dace29607916c6b558403d3c9
7
- data.tar.gz: 80eb01f4d6aa450203c6db05a33f48bc515dc8e9a71b8532cead71439dabb373455b6cfa78c718e96364a3d7562027c6dd878a2393bca50fc9a614825c2e7a8d
6
+ metadata.gz: 9a0334a2851a5b2742bab2ed51b6583e8ff47c9a89c605dfd10d84f0a20a6f17a16ba59179c53bf89b1dd0ed40673fb3909966c7476410d8ee1a52e580ec5766
7
+ data.tar.gz: a6f1f6db5d115e7e535ec0305d62970480f7b831eb8026e940011db2fcb3576244084fbf121f1ec499c61853d03dac3a76034dd7bdd3c187b778795ce0a3b5fd
data/Gemfile CHANGED
@@ -1,7 +1,7 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- ruby '> 1.8'
3
+ ruby "~>2.4"
4
4
 
5
5
  gemspec
6
6
 
7
- gem "pry", "~> 0.11.3"
7
+ gem "pry", "~> 0.12.2"
data/README.md CHANGED
@@ -8,11 +8,9 @@
8
8
  require "assert"
9
9
 
10
10
  class MyTests < Assert::Context
11
-
12
11
  test "something" do
13
- assert_equal 1, 1
12
+ assert_that(1).equals(1)
14
13
  end
15
-
16
14
  end
17
15
  ```
18
16
 
@@ -35,13 +33,13 @@ Running tests in random order, seeded with "56382"
35
33
 
36
34
  ## What Assert is not
37
35
 
38
- * **RSpec/spec-anything**: define tests using assertion statements
39
- * **Unit/Functional/Integration/etc**: Assert is agnostic - you define whatever kinds of tests you like (one or more of the above) and assert runs them in context
40
- * **Mock/Spec/BDD/etc**: Assert is the framework and there are a variety of 3rd party tools to do such things - feel free to use whatever you like
36
+ * **RSpec/spec-anything**: define tests using assertion statements.
37
+ * **Unit/Functional/Integration/etc**: Assert is agnostic - you define whatever kinds of tests you like and Assert runs them in context.
38
+ * **Mock/Spec/BDD/etc**: Assert is the framework and there are a variety of 3rd party tools to do such things. Feel free to use whatever you like.
41
39
 
42
40
  ## Description
43
41
 
44
- Assert is an assertion style testing framework, meaning you use assertion statements to define your tests and create results. Assert uses class-based contexts so if you want to nest your contexts, use inheritance.
42
+ Assert is an assertion-style testing framework, meaning you use assertion statements to define your tests and create results. Assert uses class-based contexts so if you want to nest your contexts, use inheritance.
45
43
 
46
44
  ### Features
47
45
 
@@ -52,6 +50,7 @@ Assert is an assertion style testing framework, meaning you use assertion statem
52
50
  * class-based contexts
53
51
  * multiple before/setup & after/teardown blocks
54
52
  * around blocks
53
+ * `let` value declarations
55
54
  * full backtrace for errors
56
55
  * optionally pretty print objects in failure descriptions
57
56
  * [stubbing API](https://github.com/redding/assert#stub)
@@ -73,58 +72,86 @@ Assert comes with a stubbing API - all it does is replace method calls. In gene
73
72
  * no methods are added to `Object` to support stubbing
74
73
  * stubs are auto-unstubbed on test teardown
75
74
 
76
- **Note**: Assert's stubbing logic has been extracted into a separate gem: [MuchStub](https://github.com/redding/much-stub/#muchstub). However, the main `Assert.{stub|unstub|stub_send|etc}` api is still available (it just proxies MuchStub now).
75
+ **Note**: Assert's stubbing logic has been extracted into a separate gem: [MuchStub](https://github.com/redding/much-stub/#muchstub). However, the main `Assert.{stub|unstub|stub_send|stub_tap|etc}` api is still available (it just proxies to MuchStub now).
77
76
 
78
77
  ```ruby
79
78
  myclass = Class.new do
80
- def mymeth; "meth"; end
81
- def myval(val); val; end
79
+ def my_method
80
+ "my_method"
81
+ end
82
+
83
+ def my_value(value)
84
+ value
85
+ end
82
86
  end
83
- myobj = myclass.new
87
+ my_object = myclass.new
84
88
 
85
- myobj.mymeth
86
- # => "meth"
87
- myobj.myval(123)
89
+ my_object.my_method
90
+ # => "my_method"
91
+ my_object.my_value(123)
88
92
  # => 123
89
- myobj.myval(456)
93
+ my_object.my_value(456)
90
94
  # => 456
91
95
 
92
- Assert.stub(myobj, :mymeth)
93
- myobj.mymeth
94
- # => StubError: `mymeth` not stubbed.
95
- Assert.stub(myobj, :mymeth){ "stub-meth" }
96
- myobj.mymeth
96
+ Assert.stub(my_object, :my_method)
97
+ my_object.my_method
98
+ # => StubError: `my_method` not stubbed.
99
+ Assert.stub(my_object, :my_method){ "stub-meth" }
100
+ my_object.my_method
97
101
  # => "stub-meth"
98
- myobj.mymeth(123)
102
+ my_object.my_method(123)
99
103
  # => StubError: arity mismatch
100
- Assert.stub(myobj, :mymeth).with(123){ "stub-meth" }
104
+ Assert.stub(my_object, :my_method).with(123){ "stub-meth" }
101
105
  # => StubError: arity mismatch
102
- Assert.stub_send(myobj, :mymeth) # call to the original method post-stub
103
- # => "meth"
104
106
 
105
- Assert.stub(myobj, :myval){ "stub-meth" }
107
+ # Call the original method after it has been stubbed.
108
+ Assert.stub_send(my_object, :my_method)
109
+ # => "my_method"
110
+
111
+ Assert.stub(my_object, :my_value){ "stub-meth" }
106
112
  # => StubError: arity mismatch
107
- Assert.stub(myobj, :myval).with(123){ |val| val.to_s }
108
- myobj.myval
113
+ Assert.stub(my_object, :my_value).with(123){ |val| val.to_s }
114
+ my_object.my_value
109
115
  # => StubError: arity mismatch
110
- myobj.myval(123)
116
+ my_object.my_value(123)
111
117
  # => "123"
112
- myobj.myval(456)
113
- # => StubError: `myval(456)` not stubbed.
114
- Assert.stub_send(myobj, :myval, 123) # call to the original method post-stub
118
+ my_object.my_value(456)
119
+ # => StubError: `my_value(456)` not stubbed.
120
+
121
+ # Call the original method after it has been stubbed.
122
+ Assert.stub_send(my_object, :my_value, 123)
115
123
  # => 123
116
- Assert.stub_send(myobj, :myval, 456)
124
+ Assert.stub_send(my_object, :my_value, 456)
117
125
  # => 456
118
126
 
119
- Assert.unstub(myobj, :mymeth)
120
- Assert.unstub(myobj, :myval)
127
+ # Stub a method while preserving its behavior and return value.
128
+ my_value_called_with = nil
129
+ Assert.stub_tap(my_object, :my_value) { |value, *args|
130
+ my_value_called_with = args
131
+ Assert.stub(value, :to_s) { "FIREWORKS!" }
132
+ }
133
+ value = my_object.my_value(123)
134
+ # => 123
135
+ my_value_called_with
136
+ # => [123]
137
+ value.to_s
138
+ # =>"FIREWORKS!"
139
+
140
+ # Unstub individual stubs
141
+ Assert.unstub(my_object, :my_method)
142
+ Assert.unstub(my_object, :my_value)
121
143
 
122
- myobj.mymeth
123
- # => "meth"
124
- myobj.myval(123)
144
+ # OR blanket unstub all stubs
145
+ Assert.unstub!
146
+
147
+ my_object.my_method
148
+ # => "my_method"
149
+ my_object.my_value(123)
125
150
  # => 123
126
- myobj.myval(456)
151
+ value = my_object.my_value(456)
127
152
  # => 456
153
+ value.to_s
154
+ # => "456"
128
155
  ```
129
156
 
130
157
  ## Factory
@@ -413,13 +440,11 @@ If you just want to disable this feature completely:
413
440
 
414
441
  ```ruby
415
442
  Assert.configure do |config|
416
-
417
443
  # run nothing if the `-c` flag is given
418
444
  config.changed_proc Proc.new{ |config, test_paths| [] }
419
445
 
420
446
  # run all test paths if the `-c` flag is given
421
447
  config.changed_proc Proc.new{ |config, test_paths| test_paths }
422
-
423
448
  end
424
449
  ```
425
450
 
@@ -642,4 +667,4 @@ If submitting a Pull Request, please:
642
667
 
643
668
  One note: please respect that Assert itself is intended to be the flexible, base-level, framework-type logic that should change little if at all. Pull requests for niche functionality or personal testing philosphy stuff will likely not be accepted.
644
669
 
645
- If you wish to extend Assert for your niche purpose/desire/philosophy, please do so in it's own gem (preferrably named `assert-<whatever>`) that uses Assert as a dependency.
670
+ If you wish to extend Assert for your niche purpose/desire/philosophy, please do so in its own gem (preferrably named `assert-<whatever>`) that uses Assert as a dependency.
@@ -18,9 +18,8 @@ Gem::Specification.new do |gem|
18
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
19
  gem.require_paths = ["lib"]
20
20
 
21
- gem.required_ruby_version = '> 1.8'
21
+ gem.required_ruby_version = "~> 2.5"
22
22
 
23
23
  gem.add_dependency("much-factory", ["~> 0.1.0"])
24
- gem.add_dependency("much-stub", ["~> 0.1.0"])
25
-
24
+ gem.add_dependency("much-stub", ["~> 0.1.4"])
26
25
  end
@@ -9,7 +9,6 @@ require "assert/utils"
9
9
  require "assert/view"
10
10
 
11
11
  module Assert
12
-
13
12
  def self.config; @config ||= Config.new; end
14
13
  def self.configure; yield self.config if block_given?; end
15
14
 
@@ -21,14 +20,5 @@ module Assert
21
20
  class Context
22
21
  teardown{ Assert.unstub! }
23
22
  end
24
-
25
23
  end
26
24
 
27
- # Kernel#caller_locations polyfill for pre ruby 2.0.0
28
- if RUBY_VERSION =~ /\A1\..+/ && !Kernel.respond_to?(:caller_locations)
29
- module Kernel
30
- def caller_locations(start = 1, length = nil)
31
- length ? caller[start, length] : caller[start..-1]
32
- end
33
- end
34
- end
@@ -0,0 +1,127 @@
1
+ require "much-stub"
2
+
3
+ module Assert; end
4
+ class Assert::ActualValue
5
+ def initialize(value, context:)
6
+ @value = value
7
+ @context = context
8
+ end
9
+
10
+ def returns_true(*args)
11
+ @context.assert_block(*args, &@value)
12
+ end
13
+
14
+ def does_not_return_true(*args)
15
+ @context.assert_not_block(*args, &@value)
16
+ end
17
+
18
+ def raises(*expected_exceptions)
19
+ @context.assert_raises(*expected_exceptions, &@value)
20
+ end
21
+
22
+ def does_not_raise(*expected_exceptions)
23
+ @context.assert_nothing_raised(*expected_exceptions, &@value)
24
+ end
25
+
26
+ def is_a_kind_of(expected_class, *args)
27
+ @context.assert_kind_of(expected_class, @value, *args)
28
+ end
29
+ alias_method :is_kind_of, :is_a_kind_of
30
+
31
+ def is_not_a_kind_of(expected_class, *args)
32
+ @context.assert_not_kind_of(expected_class, @value, *args)
33
+ end
34
+ alias_method :is_not_kind_of, :is_not_a_kind_of
35
+
36
+ def is_an_instance_of(expected_class, *args)
37
+ @context.assert_instance_of(expected_class, @value, *args)
38
+ end
39
+ alias_method :is_instance_of, :is_an_instance_of
40
+
41
+ def is_not_an_instance_of(expected_class, *args)
42
+ @context.assert_not_instance_of(expected_class, @value, *args)
43
+ end
44
+ alias_method :is_not_instance_of, :is_not_an_instance_of
45
+
46
+ def responds_to(expected_method_name, *args)
47
+ @context.assert_responds_to(expected_method_name, @value, *args)
48
+ end
49
+
50
+ def does_not_respond_to(expected_method_name, *args)
51
+ @context.assert_not_responds_to(expected_method_name, @value, *args)
52
+ end
53
+
54
+ def is_the_same_as(expected_object, *args)
55
+ @context.assert_same(expected_object, @value, *args)
56
+ end
57
+
58
+ def is_not_the_same_as(expected_object, *args)
59
+ @context.assert_not_same(expected_object, @value, *args)
60
+ end
61
+
62
+ def equals(expected_value, *args)
63
+ @context.assert_equal(expected_value, @value, *args)
64
+ end
65
+ alias_method :is_equal_to, :equals
66
+
67
+ def does_not_equal(expected_value, *args)
68
+ @context.assert_not_equal(expected_value, @value, *args)
69
+ end
70
+ alias_method :is_not_equal_to, :does_not_equal
71
+
72
+ def matches(expected_regex, *args)
73
+ @context.assert_match(expected_regex, @value, *args)
74
+ end
75
+
76
+ def does_not_match(expected_regex, *args)
77
+ @context.assert_not_match(expected_regex, @value, *args)
78
+ end
79
+
80
+ def is_empty(*args)
81
+ @context.assert_empty(@value, *args)
82
+ end
83
+
84
+ def is_not_empty(*args)
85
+ @context.assert_not_empty(@value, *args)
86
+ end
87
+
88
+ def includes(object, *args)
89
+ @context.assert_includes(object, @value, *args)
90
+ end
91
+
92
+ def does_not_include(object, *args)
93
+ @context.assert_not_includes(object, @value, *args)
94
+ end
95
+
96
+ def is_nil(*args)
97
+ @context.assert_nil(@value, *args)
98
+ end
99
+
100
+ def is_not_nil(*args)
101
+ @context.assert_not_nil(@value, *args)
102
+ end
103
+
104
+ def is_true(*args)
105
+ @context.assert_true(@value, *args)
106
+ end
107
+
108
+ def is_not_true(*args)
109
+ @context.assert_not_true(@value, *args)
110
+ end
111
+
112
+ def is_false(*args)
113
+ @context.assert_false(@value, *args)
114
+ end
115
+
116
+ def is_not_false(*args)
117
+ @context.assert_not_false(@value, *args)
118
+ end
119
+
120
+ def is_a_file(*args)
121
+ @context.assert_file_exists(@value, *args)
122
+ end
123
+
124
+ def is_not_a_file(*args)
125
+ @context.assert_not_file_exists(@value, *args)
126
+ end
127
+ end
@@ -1,7 +1,6 @@
1
1
  require "assert/cli"
2
2
 
3
3
  module Assert
4
-
5
4
  class AssertRunner
6
5
  USER_SETTINGS_FILE = ".assert/init.rb"
7
6
  LOCAL_SETTINGS_FILE = ".assert.rb"
@@ -117,7 +116,5 @@ module Assert
117
116
  end
118
117
 
119
118
  def segment_regex(seg); /^#{seg}$|^#{seg}\/|\/#{seg}\/|\/#{seg}$/; end
120
-
121
119
  end
122
-
123
120
  end
@@ -1,8 +1,15 @@
1
1
  require "assert/utils"
2
2
 
3
3
  module Assert
4
-
5
4
  module Assertions
5
+ IGNORED_ASSERTION_HELPERS =
6
+ [
7
+ :assert_throws, :assert_nothing_thrown,
8
+ :assert_operator, :refute_operator,
9
+ :assert_in_epsilon, :refute_in_epsilon,
10
+ :assert_in_delta, :refute_in_delta,
11
+ :assert_send
12
+ ]
6
13
 
7
14
  def assert_block(desc = nil)
8
15
  assert(yield, desc){ "Expected block to return a true value." }
@@ -27,7 +34,7 @@ module Assert
27
34
  alias_method :refute_empty, :assert_not_empty
28
35
 
29
36
  def assert_equal(exp, act, desc = nil)
30
- assert(exp == act, desc) do
37
+ assert(act == exp, desc) do
31
38
  c = __assert_config__
32
39
  exp_show = Assert::U.show_for_diff(exp, c)
33
40
  act_show = Assert::U.show_for_diff(act, c)
@@ -42,7 +49,7 @@ module Assert
42
49
  end
43
50
 
44
51
  def assert_not_equal(exp, act, desc = nil)
45
- assert(exp != act, desc) do
52
+ assert(act != exp, desc) do
46
53
  c = __assert_config__
47
54
  exp_show = Assert::U.show_for_diff(exp, c)
48
55
  act_show = Assert::U.show_for_diff(act, c)
@@ -246,24 +253,6 @@ module Assert
246
253
  end
247
254
  alias_method :refute_same, :assert_not_same
248
255
 
249
- # ignored assertion helpers
250
-
251
- IGNORED_ASSERTION_HELPERS = [
252
- :assert_throws, :assert_nothing_thrown,
253
- :assert_operator, :refute_operator,
254
- :assert_in_epsilon, :refute_in_epsilon,
255
- :assert_in_delta, :refute_in_delta,
256
- :assert_send
257
- ]
258
- def method_missing(method, *args, &block)
259
- if IGNORED_ASSERTION_HELPERS.include?(method.to_sym)
260
- ignore "The assertion `#{method}` is not supported."\
261
- " Please use another assertion or the basic `assert`."
262
- else
263
- super
264
- end
265
- end
266
-
267
256
  private
268
257
 
269
258
  def __assert_config__
@@ -328,7 +317,5 @@ module Assert
328
317
  super("exception not expected, but raised:")
329
318
  end
330
319
  end
331
-
332
320
  end
333
-
334
321
  end
@@ -4,9 +4,7 @@ require "assert/assert_runner"
4
4
  require "assert/version"
5
5
 
6
6
  module Assert
7
-
8
7
  class CLI
9
-
10
8
  def self.debug?(args)
11
9
  args.include?("-d") || args.include?("--debug")
12
10
  end
@@ -36,40 +34,29 @@ module Assert
36
34
  def initialize(*args)
37
35
  @args = args
38
36
  @cli = CLIRB.new do
39
- option "runner_seed", "use a given seed to run tests", {
40
- :abbrev => "s", :value => Fixnum
41
- }
42
- option "changed_only", "only run test files with changes", {
43
- :abbrev => "c"
44
- }
45
- option "changed_ref", "reference for changes, use with `-c` opt", {
46
- :abbrev => "r", :value => ""
47
- }
48
- option "single_test", "only run the test on the given file/line", {
49
- :abbrev => "t", :value => ""
50
- }
51
- option "pp_objects", "pretty-print objects in fail messages", {
52
- :abbrev => "p"
53
- }
54
- option "capture_output", "capture stdout and display in result details", {
55
- :abbrev => "o"
56
- }
57
- option "halt_on_fail", "halt a test when it fails", {
58
- :abbrev => "h"
59
- }
60
- option "profile", "output test profile info", {
61
- :abbrev => "e"
62
- }
63
- option "verbose", "output verbose runtime test info", {
64
- :abbrev => "v"
65
- }
66
- option "list", "list test files on $stdout", {
67
- :abbrev => "l"
68
- }
37
+ option "runner_seed", "use a given seed to run tests",
38
+ abbrev: "s", value: Integer
39
+ option "changed_only", "only run test files with changes",
40
+ abbrev: "c"
41
+ option "changed_ref", "reference for changes, use with `-c` opt",
42
+ abbrev: "r", value: ""
43
+ option "single_test", "only run the test on the given file/line",
44
+ abbrev: "t", value: ""
45
+ option "pp_objects", "pretty-print objects in fail messages",
46
+ abbrev: "p"
47
+ option "capture_output", "capture stdout and display in result details",
48
+ abbrev: "o"
49
+ option "halt_on_fail", "halt a test when it fails",
50
+ abbrev: "h"
51
+ option "profile", "output test profile info",
52
+ abbrev: "e"
53
+ option "verbose", "output verbose runtime test info",
54
+ abbrev: "v"
55
+ option "list", "list test files on $stdout",
56
+ abbrev: "l"
57
+
69
58
  # show loaded test files, cli err backtraces, etc
70
- option "debug", "run in debug mode", {
71
- :abbrev => "d"
72
- }
59
+ option "debug", "run in debug mode", abbrev: "d"
73
60
  end
74
61
  end
75
62
 
@@ -100,7 +87,6 @@ module Assert
100
87
  "Options:"\
101
88
  "#{@cli}"
102
89
  end
103
-
104
90
  end
105
91
 
106
92
  module RoundedMillisecondTime
@@ -111,7 +97,7 @@ module Assert
111
97
  end
112
98
  end
113
99
 
114
- class CLIRB # Version 1.0.0, https://github.com/redding/cli.rb
100
+ class CLIRB # Version 1.1.0, https://github.com/redding/cli.rb
115
101
  Error = Class.new(RuntimeError);
116
102
  HelpExit = Class.new(RuntimeError); VersionExit = Class.new(RuntimeError)
117
103
  attr_reader :argv, :args, :opts, :data
@@ -143,27 +129,25 @@ module Assert
143
129
  class Option
144
130
  attr_reader :name, :opt_name, :desc, :abbrev, :value, :klass, :parser_args
145
131
 
146
- def initialize(name, *args)
147
- settings, @desc = args.last.kind_of?(::Hash) ? args.pop : {}, args.pop || ""
148
- @name, @opt_name, @abbrev = parse_name_values(name, settings[:abbrev])
149
- @value, @klass = gvalinfo(settings[:value])
132
+ def initialize(name, desc = nil, abbrev: nil, value: nil)
133
+ @name, @desc = name, desc || ""
134
+ @opt_name, @abbrev = parse_name_values(name, abbrev)
135
+ @value, @klass = gvalinfo(value)
150
136
  @parser_args = if [TrueClass, FalseClass, NilClass].include?(@klass)
151
137
  ["-#{@abbrev}", "--[no-]#{@opt_name}", @desc]
152
138
  else
153
- ["-#{@abbrev}", "--#{@opt_name} #{@opt_name.upcase}", @klass, @desc]
139
+ ["-#{@abbrev}", "--#{@opt_name} VALUE", @klass, @desc]
154
140
  end
155
141
  end
156
142
 
157
143
  private
158
144
 
159
145
  def parse_name_values(name, custom_abbrev)
160
- [ (processed_name = name.to_s.strip.downcase), processed_name.gsub("_", "-"),
146
+ [ (processed_name = name.to_s.strip.downcase).gsub("_", "-"),
161
147
  custom_abbrev || processed_name.gsub(/[^a-z]/, "").chars.first || "a"
162
148
  ]
163
149
  end
164
- def gvalinfo(v); v.kind_of?(Class) ? [nil,gklass(v)] : [v,gklass(v.class)]; end
165
- def gklass(k); k == Fixnum ? Integer : k; end
150
+ def gvalinfo(v); v.kind_of?(Class) ? [nil,v] : [v,v.class]; end
166
151
  end
167
152
  end
168
-
169
153
  end