param_test 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/active_support/testing/parametrized.rb +18 -5
- data/param_test.gemspec +1 -1
- data/test/param_test_meta_test.rb +25 -4
- metadata +2 -2
@@ -28,6 +28,13 @@ module ActiveSupport
|
|
28
28
|
# end
|
29
29
|
#
|
30
30
|
def param_test(description_template, parameters, &block)
|
31
|
+
param_count = format_sequence_count(description_template)
|
32
|
+
|
33
|
+
if param_count != block.arity
|
34
|
+
raise ArgumentError, "Number of arguments expected in description template " +
|
35
|
+
"'#{description_template}', doesn't match number of argument to block (#{block.arity})"
|
36
|
+
end
|
37
|
+
|
31
38
|
parameters.each do |param_set|
|
32
39
|
# Replacing nil values with 'nil' string because nil values will
|
33
40
|
# get converted to an empty string within a test name.
|
@@ -36,17 +43,16 @@ module ActiveSupport
|
|
36
43
|
param.nil? ? 'nil' : param
|
37
44
|
end
|
38
45
|
else
|
39
|
-
sanitized_param_set = param_set.nil? ? 'nil' : param_set
|
46
|
+
sanitized_param_set = param_set.nil? ? ['nil'] : [param_set]
|
40
47
|
end
|
41
48
|
|
42
|
-
|
43
|
-
|
44
|
-
rescue ArgumentError
|
45
|
-
raise ArgumentError, "Parameter set #{param_set} doesn't match number " +
|
49
|
+
if param_count != sanitized_param_set.size
|
50
|
+
raise ArgumentError, "Parameter set #{sanitized_param_set} doesn't match number " +
|
46
51
|
"of arguments expected by description template '#{description_template}'"
|
47
52
|
end
|
48
53
|
|
49
54
|
# Make sure the description generates a unique test method name.
|
55
|
+
description = description_template % sanitized_param_set
|
50
56
|
unique_description = description
|
51
57
|
if instance_methods.include? generate_test_name(unique_description)
|
52
58
|
count = 1
|
@@ -71,6 +77,13 @@ module ActiveSupport
|
|
71
77
|
sanitized_description = description.gsub(/\s+/,'_')
|
72
78
|
"test_#{sanitized_description}".to_sym
|
73
79
|
end
|
80
|
+
|
81
|
+
def format_sequence_count(format_string)
|
82
|
+
sequences = format_string.scan(/%+/).select do |match|
|
83
|
+
match.size.odd?
|
84
|
+
end
|
85
|
+
sequences.size
|
86
|
+
end
|
74
87
|
end
|
75
88
|
end
|
76
89
|
end
|
data/param_test.gemspec
CHANGED
@@ -13,7 +13,7 @@ class ParamTestMetaTest < ActiveSupport::TestCase
|
|
13
13
|
|
14
14
|
test "empty parameters adds no tests" do
|
15
15
|
test_case = Class.new ActiveSupport::TestCase do
|
16
|
-
param_test "adds no tests", [] do
|
16
|
+
param_test "adds no tests", [] do || end
|
17
17
|
end
|
18
18
|
assert_test_method_count test_case, 0
|
19
19
|
end
|
@@ -44,11 +44,32 @@ class ParamTestMetaTest < ActiveSupport::TestCase
|
|
44
44
|
assert_has_test_method test_case, :test_with_two_params_43_44
|
45
45
|
end
|
46
46
|
|
47
|
-
|
47
|
+
param_test "mismatching parameter list %s fails for %s", [
|
48
|
+
[[[43]], "%s %s"],
|
49
|
+
[[[41, 42, 43]], "%s %s"],
|
50
|
+
] do |params, description|
|
51
|
+
assert_raise ArgumentError do
|
52
|
+
Class.new ActiveSupport::TestCase do
|
53
|
+
param_test description,
|
54
|
+
params do |first, second| end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
test "wrong block arity fails" do
|
60
|
+
assert_raise ArgumentError do
|
61
|
+
Class.new ActiveSupport::TestCase do
|
62
|
+
param_test "%s %s",
|
63
|
+
[[41, 42]] do |first| end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
test "more wrong block arity fails" do
|
48
69
|
assert_raise ArgumentError do
|
49
70
|
Class.new ActiveSupport::TestCase do
|
50
71
|
param_test "%s %s",
|
51
|
-
[[41, 42]
|
72
|
+
[[41, 42]] do |first, second, third| end
|
52
73
|
end
|
53
74
|
end
|
54
75
|
end
|
@@ -56,7 +77,7 @@ class ParamTestMetaTest < ActiveSupport::TestCase
|
|
56
77
|
test "substitutes nil string for nil" do
|
57
78
|
test_case = Class.new ActiveSupport::TestCase do
|
58
79
|
param_test "params %s %s",
|
59
|
-
[[nil, nil]] do |
|
80
|
+
[[nil, nil]] do |first, second| end
|
60
81
|
end
|
61
82
|
assert_test_method_count test_case, 1
|
62
83
|
assert_has_test_method test_case, :test_params_nil_nil
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: param_test
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|