paramesan 0.0.1 → 1.0.1

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: 2ec829da8c0a763523519359e2759713f8ca3e3f
4
- data.tar.gz: c56c3ef7d36f622257e685b20e08de3920cc9fbb
2
+ SHA256:
3
+ metadata.gz: 033f2032789102c66626b25bb5f67222b067025ee299f6f98c55cf1a12073f4c
4
+ data.tar.gz: 31f2ca4d45936102ce65f0ee077477490d5028680888511a9c96c18c673cceb3
5
5
  SHA512:
6
- metadata.gz: cb0308e57a4659cc8939a28d6143fe87829594e3729ba17cbce7ce5c17e6fcb47c5c7c10130ea5c12e07a8cc215cd6c4943d4d0a10091977f51c04d3918c302b
7
- data.tar.gz: adea8068805d95b7c483102ec1baea0b2f3c778095b49053082ef6125cd08ccebd39bd2fa484198ef2c9b9b85c21800122ae8ef6b603ec1ccd4976f3b5f5743c
6
+ metadata.gz: e2393e003a09d0d6a87e3ba5136556df1368c6ef5d3f90ee22743ae2c251ead83a43bbf26ed7d800aab58d0fd50ee274ba0e3f43c75acd9c7d4f96bb1aab13a3
7
+ data.tar.gz: ce0378ef1aff1c84fec8f0c4eae63f17d9dd86233a2893e25820a9545831bc2c17b4676f7c6244aa41c1c3c8458c6bedda41f5412f2b75e663fd8dda696fbc24
data/README.md CHANGED
@@ -13,53 +13,87 @@ 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.
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.
19
20
 
20
- Ergo, paramesan, which as of this writing, allows a very primitive set of options for parameterized
21
- tests.
21
+ Ergo, Paramesan, which as of this writing, supports a set of options for parameterized tests.
22
22
 
23
23
  # Example
24
24
 
25
25
  ## Before
26
26
 
27
+ 58 lines.
28
+
27
29
  ```ruby
28
30
  require 'pvn/log/options'
29
31
  require 'test/unit'
30
32
 
31
33
  class FormatOptionTest < Test::Unit::TestCase
32
- def assert_formatter expected, *types
33
- types.each do |type|
34
- fmtr = Pvn::Log::FormatOption.new type
35
- assert_kind_of expected, fmtr.formatter, "type: #{type}"
36
- end
34
+ def assert_formatter expected, type
35
+ fmtr = Pvn2::Log::FormatOption.new type
36
+ assert_kind_of expected, fmtr.formatter, "type: #{type}"
37
37
  end
38
38
 
39
- def test_oneline
40
- 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"
41
53
  end
42
54
 
43
- def test_summary
44
- assert_formatter Pvn::Log::FormatSummary, "summary", "su"
55
+ def test_summary_su
56
+ assert_formatter Pvn2::Log::FormatSummary, "su"
45
57
  end
46
58
 
47
- def test_revision_only
48
- assert_formatter Pvn::Log::FormatRevisionOnly, "revision", "rev", "revisiononly"
59
+ def test_revision_revision
60
+ assert_formatter Pvn2::Log::FormatRevision, "revision"
49
61
  end
50
62
 
51
- def test_revision_author
52
- assert_formatter Pvn::Log::FormatRevisionAuthor, "revauthor", "revauth", "revisionauthor"
63
+ def test_revision_author_revauthor
64
+ assert_formatter Pvn2::Log::FormatRevisionAuthor, "revauthor"
53
65
  end
54
66
 
55
- def test_colorized
56
- assert_formatter Pvn::Log::FormatColorized, "color", "colorized"
67
+ def test_revision_author_revauth
68
+ assert_formatter Pvn2::Log::FormatRevisionAuthor, "revauth"
69
+ end
70
+
71
+ def test_revision_author_revisionauthor
72
+ assert_formatter Pvn2::Log::FormatRevisionAuthor, "revisionauthor"
73
+ end
74
+
75
+ def test_colorized_color
76
+ assert_formatter Pvn2::Log::FormatColorized, "color"
77
+ end
78
+
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"
57
89
  end
58
90
  end
59
91
  ```
60
92
 
61
93
  ## After
62
94
 
95
+ 17 lines.
96
+
63
97
  ```ruby
64
98
  require 'pvn/log/options'
65
99
  require 'test/unit'
@@ -67,19 +101,89 @@ require 'paramesan'
67
101
 
68
102
  class FormatOptionTest < Test::Unit::TestCase
69
103
  extend Paramesan
70
-
104
+
71
105
  param_test [
72
- [ Pvn::Log::FormatOneLine, "single", "single-line", "si", "oneline" ],
73
- [ Pvn::Log::FormatSummary, "summary", "su" ],
74
- [ Pvn::Log::FormatRevisionOnly, "revision", "rev", "revisiononly" ],
75
- [ Pvn::Log::FormatRevisionAuthor, "revauthor", "revauth", "revisionauthor" ],
76
- [ 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" ],
77
113
  ] do |exp, *types|
78
- 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
79
159
  types.each do |type|
80
160
  assert_equal exp, fmts.class_for(type), "type: #{type}"
81
161
  end
82
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
83
187
  end
84
188
  ```
85
189
 
@@ -4,22 +4,40 @@
4
4
  require "paramesan/version"
5
5
 
6
6
  module Paramesan
7
- def param_test paramlist, &blk
8
- puts "self: #{self}"
9
-
10
- paramlist.each do |params|
11
- basename = "test_" + params.to_s.gsub(Regexp.new('[^\w]+'), '_')
12
- mname = basename
7
+ module ClassMethods
8
+ def param_test paramlist, &blk
9
+ count = paramlist.count
10
+ paramlist.each_with_index do |params, idx|
11
+ name = param_test_name params, idx, count
13
12
 
14
- count = 1
15
- while instance_methods.include? mname.to_sym
16
- mname += "_#{count}"
13
+ mname = name.to_sym
14
+ i = 0
15
+ while instance_methods.include? mname.to_sym
16
+ i += 1
17
+ mname = name + "_#{i}"
18
+ end
19
+
20
+ define_method mname do
21
+ instance_exec(params, &blk)
22
+ end
17
23
  end
24
+ end
18
25
 
19
- define_method mname do
20
- instance_exec(params, &blk)
21
- puts
26
+ def param_test_name params, idx, count
27
+ name = "test_" + idx.to_s + "_of_" + count.to_s + "__"
28
+ if params.kind_of?(Enumerable)
29
+ nonword = Regexp.new '[^\w]+'
30
+ elements = params.collect { |param| param.to_s.gsub nonword, '_' }
31
+ name << elements.join('_')
32
+ else
33
+ name << params.to_s
22
34
  end
23
35
  end
24
36
  end
37
+
38
+ extend ClassMethods
39
+
40
+ def self.included other
41
+ other.extend ClassMethods
42
+ end
25
43
  end
@@ -4,5 +4,5 @@
4
4
  require 'pathname'
5
5
 
6
6
  module Paramesan
7
- VERSION = "0.0.1"
7
+ VERSION = "1.0.1"
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.0.1
4
+ version: 1.0.1
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-06-08 00:00:00.000000000 Z
11
+ date: 2020-10-10 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