paramesan 0.1.1 → 1.0.0

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
- SHA1:
3
- metadata.gz: 0bfb52b50a307d046717c886e122aa64c680768b
4
- data.tar.gz: f0fdd9c4a90297441214fd2b751a95e508c7d90e
2
+ SHA256:
3
+ metadata.gz: e00f05f91468e4240889bb7c976377cd0189a1892e4a5c7f0abfa9bc6abba7e1
4
+ data.tar.gz: 077f992190dc1ec5c72d70f0825df780c3e069a2116ab74856b4c3dcd7c8cf25
5
5
  SHA512:
6
- metadata.gz: e8f0a813d29eb2f5ecdb4710d0a7f08a42853d8faadb1faf7929b841d3b1522f96def9b17ea44a25138f4b75e9c27615ceb9b79f78fd1659c5db236f34eabef0
7
- data.tar.gz: acd88b9b4b37e7f510fbff09f498129124b44c3954d3efc5d870d25ae4214b6889939a749cf5ec8a9ba7dff57727cb035a7edefaeee73d77209c3e9f3444e29c
6
+ metadata.gz: 650e9a7d8d17e5304d4c6189e649c78e5d2fac4612a6db1d721fb600a23b56e6d9ba2cc487f4871163270cdfb858d5d9c477f827cfd77bffd273674d17dbf4bc
7
+ data.tar.gz: 12d4110cb1102045ec4d81a8a0cae71d24ff80debb1c7688252804026dba72ffc74e9844d32c48b5d3d4e890a12e337bad3cb21dcdc9a7c1fb316afa724dd1ca
data/README.md CHANGED
@@ -13,58 +13,86 @@ unit tests, which initially focused on the behavior (the process or code), then
13
13
  and output as data that go through the process.
14
14
 
15
15
  I looked for the equivalent in Ruby, and the closest that I found was
16
- [param_test](https://www.ruby-toolbox.com/projects/param_test). That, however, uses activesupport,
17
- which is included in Rails, but I wanted a version that ran in a pure Ruby environment, using only
18
- Test::Unit, which I prefer over Minitest, mainly because the latter uses notifications that don't
19
- work especially well with Emacs, such as changing the mode line to show the success/failure status,
20
- but do not afterward change back to the default settings.
16
+ [param_test](https://www.ruby-toolbox.com/projects/param_test). That uses activesupport, which is
17
+ included in Rails, but I wanted a version that ran in a pure Ruby environment, using only the
18
+ test-unit gem. I prefer that over Minitest, mainly because the latter uses notifications that don't
19
+ work especially well with Emacs.
21
20
 
22
- Ergo, paramesan, which as of this writing, allows a very primitive set of options for parameterized
23
- tests.
21
+ Ergo, Paramesan, which as of this writing, supports a set of options for parameterized tests.
24
22
 
25
23
  # Example
26
24
 
27
25
  ## Before
28
26
 
29
- 31 lines.
27
+ 58 lines.
30
28
 
31
29
  ```ruby
32
30
  require 'pvn/log/options'
33
31
  require 'test/unit'
34
32
 
35
33
  class FormatOptionTest < Test::Unit::TestCase
36
- def assert_formatter expected, *types
37
- types.each do |type|
38
- fmtr = Pvn::Log::FormatOption.new type
39
- assert_kind_of expected, fmtr.formatter, "type: #{type}"
40
- end
34
+ def assert_formatter expected, type
35
+ fmtr = Pvn2::Log::FormatOption.new type
36
+ assert_kind_of expected, fmtr.formatter, "type: #{type}"
41
37
  end
42
38
 
43
- def test_oneline
44
- assert_formatter Pvn::Log::FormatOneLine, "single", "single-line", "si", "oneline"
39
+ def test_oneline_single
40
+ assert_formatter Pvn2::Log::FormatOneLine, "single"
41
+ end
42
+
43
+ def test_oneline_si
44
+ assert_formatter Pvn2::Log::FormatOneLine, "si"
45
+ end
46
+
47
+ def test_oneline_oneline
48
+ assert_formatter Pvn2::Log::FormatOneLine, "oneline"
49
+ end
50
+
51
+ def test_summary_summary
52
+ assert_formatter Pvn2::Log::FormatSummary, "summary"
53
+ end
54
+
55
+ def test_summary_su
56
+ assert_formatter Pvn2::Log::FormatSummary, "su"
57
+ end
58
+
59
+ def test_revision_revision
60
+ assert_formatter Pvn2::Log::FormatRevision, "revision"
61
+ end
62
+
63
+ def test_revision_author_revauthor
64
+ assert_formatter Pvn2::Log::FormatRevisionAuthor, "revauthor"
45
65
  end
46
66
 
47
- def test_summary
48
- assert_formatter Pvn::Log::FormatSummary, "summary", "su"
67
+ def test_revision_author_revauth
68
+ assert_formatter Pvn2::Log::FormatRevisionAuthor, "revauth"
49
69
  end
50
70
 
51
- def test_revision_only
52
- assert_formatter Pvn::Log::FormatRevisionOnly, "revision", "rev", "revisiononly"
71
+ def test_revision_author_revisionauthor
72
+ assert_formatter Pvn2::Log::FormatRevisionAuthor, "revisionauthor"
53
73
  end
54
74
 
55
- def test_revision_author
56
- assert_formatter Pvn::Log::FormatRevisionAuthor, "revauthor", "revauth", "revisionauthor"
75
+ def test_colorized_color
76
+ assert_formatter Pvn2::Log::FormatColorized, "color"
57
77
  end
58
78
 
59
- def test_colorized
60
- assert_formatter Pvn::Log::FormatColorized, "color", "colorized"
79
+ def test_colorized_colorized
80
+ assert_formatter Pvn2::Log::FormatColorized, "colorized"
81
+ end
82
+
83
+ def test_tree_tree
84
+ assert_formatter Pvn2::Log::FormatTree, "tree"
85
+ end
86
+
87
+ def test_tree_zzz
88
+ assert_formatter Pvn2::Log::FormatTree, "zzz"
61
89
  end
62
90
  end
63
91
  ```
64
92
 
65
93
  ## After
66
94
 
67
- 20 lines, 35% fewer.
95
+ 17 lines.
68
96
 
69
97
  ```ruby
70
98
  require 'pvn/log/options'
@@ -73,19 +101,89 @@ require 'paramesan'
73
101
 
74
102
  class FormatOptionTest < Test::Unit::TestCase
75
103
  extend Paramesan
76
-
104
+
77
105
  param_test [
78
- [ Pvn::Log::FormatOneLine, "single", "single-line", "si", "oneline" ],
79
- [ Pvn::Log::FormatSummary, "summary", "su" ],
80
- [ Pvn::Log::FormatRevisionOnly, "revision", "rev", "revisiononly" ],
81
- [ Pvn::Log::FormatRevisionAuthor, "revauthor", "revauth", "revisionauthor" ],
82
- [ Pvn::Log::FormatColorized, "color", "colorized" ],
106
+ [ Pvn2::Log::FormatOneLine, "oneline", "single", "si" ],
107
+ [ Pvn2::Log::FormatSummary, "summary", "sum" ],
108
+ [ Pvn2::Log::FormatRevision, "revision" ],
109
+ [ Pvn2::Log::FormatRevisionAuthor, "revisionauthor", "revauthor", "revauth" ],
110
+ [ Pvn2::Log::FormatColorized, "colorized", "color", "full" ],
111
+ [ Pvn2::Log::FormatMessage, "message" ],
112
+ [ Pvn2::Log::FormatTree, "tree", "zzz" ],
83
113
  ] do |exp, *types|
84
- fmts = Pvn::Log::Formats.new
114
+ types.each do |type|
115
+ assert_kind_of exp, Pvn2::Log::FormatOption.new(type).formatter, "type: #{type}"
116
+ end
117
+ end
118
+ end
119
+ ```
120
+
121
+ The Paramesan code generates a test method for each parameter set, as for example, with the last
122
+ test case, which fails:
123
+
124
+ ```text
125
+ Error: test__Pvn2_Log_FormatTree_tree_zzz_(FormatsTest): RuntimeError: invalid format zzz not one of: author colorized full message oneline revauthor revision revisionauthor single summary tree
126
+ /opt/proj/pvn2/lib/pvn2/log/formats.rb:46:in `class_for'
127
+ /opt/proj/pvn2/lib/pvn2/log/options.rb:19:in `initialize'
128
+ /opt/proj/pvn2/test/pvn2/log/formats_test.rb:134:in `new'
129
+ /opt/proj/pvn2/test/pvn2/log/formats_test.rb:134:in `block (2 levels) in <class:FormatsTest>'
130
+ /opt/proj/pvn2/test/pvn2/log/formats_test.rb:133:in `each'
131
+ /opt/proj/pvn2/test/pvn2/log/formats_test.rb:133:in `block in <class:FormatsTest>'
132
+ /home/jpace/.rvm/gems/ruby-2.3.0/gems/paramesan-0.1.1/lib/paramesan.rb:19:in `instance_exec'
133
+ /home/jpace/.rvm/gems/ruby-2.3.0/gems/paramesan-0.1.1/lib/paramesan.rb:19:in `block (2 levels) in param_test'
134
+ ```
135
+
136
+ # Common Parameters
137
+
138
+ Sometimes the same set of parameters is used in multiple tests. To do that with Paramesan, simply
139
+ define a class method returning those parameters, and adjust the param_test blocks:
140
+
141
+ ```ruby
142
+ class FormatsTest < Test::Unit::TestCase
143
+ include Paramesan
144
+
145
+ def self.build_class_types_params
146
+ [
147
+ [ Pvn2::Log::FormatOneLine, "oneline", "single", "si" ],
148
+ [ Pvn2::Log::FormatSummary, "summary", "sum" ],
149
+ [ Pvn2::Log::FormatRevision, "revision" ],
150
+ [ Pvn2::Log::FormatRevisionAuthor, "revisionauthor", "revauthor", "revauth" ],
151
+ [ Pvn2::Log::FormatColorized, "colorized", "color", "full" ],
152
+ [ Pvn2::Log::FormatMessage, "message" ],
153
+ [ Pvn2::Log::FormatTree, "tree", "zzz" ],
154
+ ]
155
+ end
156
+
157
+ param_test build_class_types_params do |exp, *types|
158
+ fmts = Pvn2::Log::Formats.new
85
159
  types.each do |type|
86
160
  assert_equal exp, fmts.class_for(type), "type: #{type}"
87
161
  end
88
162
  end
163
+
164
+ param_test build_class_types_params do |exp, *types|
165
+ types.each do |type|
166
+ assert_kind_of exp, Pvn2::Log::FormatOption.new(type).formatter, "type: #{type}"
167
+ end
168
+ end
169
+ end
170
+ ```
171
+
172
+ # Non Arrays
173
+
174
+ The set of parameters does not have to consist of arrays. For example, using strings:
175
+
176
+ ```ruby
177
+ class FormatsTest < Test::Unit::TestCase
178
+ include Paramesan
179
+
180
+ param_test %w{ abc def } do |str|
181
+ fmts = Pvn2::Log::Formats.new
182
+ expfmts = "author colorized full message oneline revauthor revision revisionauthor single summary tree"
183
+ assert_raise(RuntimeError.new "invalid format #{str} not one of: #{expfmts}") do
184
+ fmts.class_for str
185
+ end
186
+ end
89
187
  end
90
188
  ```
91
189
 
@@ -6,13 +6,15 @@ require "paramesan/version"
6
6
  module Paramesan
7
7
  module ClassMethods
8
8
  def param_test paramlist, &blk
9
- paramlist.each do |params|
10
- basename = "test_" + params.to_s.gsub(Regexp.new('[^\w]+'), '_')
11
- mname = basename
9
+ count = paramlist.count
10
+ paramlist.each_with_index do |params, idx|
11
+ name = param_test_name params, idx, count
12
12
 
13
- count = 1
13
+ mname = name.to_sym
14
+ i = 0
14
15
  while instance_methods.include? mname.to_sym
15
- mname += "_#{count}"
16
+ i += 1
17
+ mname = name + "_#{i}"
16
18
  end
17
19
 
18
20
  define_method mname do
@@ -20,6 +22,12 @@ module Paramesan
20
22
  end
21
23
  end
22
24
  end
25
+
26
+ def param_test_name params, idx, count
27
+ nonword = Regexp.new '[^\w]+'
28
+ elements = params.collect { |param| param.to_s.gsub nonword, '_' }
29
+ "test_" + idx.to_s + "_of_" + count.to_s + "__" + elements.join('_')
30
+ end
23
31
  end
24
32
 
25
33
  extend ClassMethods
@@ -4,5 +4,5 @@
4
4
  require 'pathname'
5
5
 
6
6
  module Paramesan
7
- VERSION = "0.1.1"
7
+ VERSION = "1.0.0"
8
8
  end
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
27
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
28
  spec.require_paths = ["lib"]
29
29
 
30
- spec.add_development_dependency "bundler", "~> 1.12"
31
- spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency "bundler", ">= 2.0"
31
+ spec.add_development_dependency "rake", ">= 13.0"
32
32
  spec.add_development_dependency "test-unit", "~> 3.1.5"
33
33
  end
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paramesan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Pace
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-29 00:00:00.000000000 Z
11
+ date: 2020-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.12'
19
+ version: '2.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.12'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '13.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '13.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: test-unit
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -90,8 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
90
  - !ruby/object:Gem::Version
91
91
  version: '0'
92
92
  requirements: []
93
- rubyforge_project:
94
- rubygems_version: 2.6.3
93
+ rubygems_version: 3.0.8
95
94
  signing_key:
96
95
  specification_version: 4
97
96
  summary: Parameterized tests