assert_generator 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/assert_generator.rb +33 -20
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6a39a9e34de7b0029e30b7f60040d90ff67291cd25dc86db0ec6e8be9012c5e
|
4
|
+
data.tar.gz: 12b754a1426058a33f4ebd6433ce4374ef1e435740aa97f8000f7db1ca85132e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58a6244d7e2e978d9a1962f1a1ffd82d44e201403176fdb8e0c77347b207f63619db90bd9d36462bfe6b5fecc14238f0ae66e387ec22f24c1d07925daae74ba4
|
7
|
+
data.tar.gz: 66ba172a33d01d294da78df6c53e5f8e07dae7ee52f5767ddc8d1a7b73a39631572167db95f586a50f743b481d3d445cb2a7fc6c6ff5d39705bedc004ba50cd3
|
data/lib/assert_generator.rb
CHANGED
@@ -58,8 +58,14 @@ module AssertGenerator
|
|
58
58
|
return self
|
59
59
|
end
|
60
60
|
|
61
|
-
if
|
62
|
-
|
61
|
+
if source.respond_to?(:attributes)
|
62
|
+
# AR or something that quacks like it
|
63
|
+
generate_asserts_attributes(source, source_expr)
|
64
|
+
return self
|
65
|
+
end
|
66
|
+
|
67
|
+
if source.is_a?(Range)
|
68
|
+
generate_asserts_range(source, source_expr)
|
63
69
|
return self
|
64
70
|
end
|
65
71
|
|
@@ -72,7 +78,8 @@ module AssertGenerator
|
|
72
78
|
self
|
73
79
|
end
|
74
80
|
|
75
|
-
|
81
|
+
# Active Record, or anything else with an attributes hash
|
82
|
+
def generate_asserts_attributes(h, p)
|
76
83
|
h.attributes.each do |k, v|
|
77
84
|
generate_assert_drillable_item(v, ->(meth) { "#{p}.#{meth}" }, k)
|
78
85
|
end
|
@@ -95,25 +102,31 @@ module AssertGenerator
|
|
95
102
|
end
|
96
103
|
end
|
97
104
|
|
105
|
+
def generate_asserts_range(a, p)
|
106
|
+
generate_assert_drillable_item(a.first, ->(_x) { "#{p}.first" }, p)
|
107
|
+
generate_assert_drillable_item(a.last, ->(_x) { "#{p}.last" }, p)
|
108
|
+
end
|
109
|
+
|
98
110
|
def generate_assert_drillable_item(v, make_accessor, *accessor_params)
|
99
111
|
accessor = make_accessor.call(*accessor_params)
|
112
|
+
|
100
113
|
if drillable_object(v)
|
101
|
-
generate_asserts(v, accessor, nil, nil)
|
114
|
+
return generate_asserts(v, accessor, nil, nil)
|
115
|
+
end
|
116
|
+
|
117
|
+
if v.nil?
|
118
|
+
out "assert_nil #{accessor}"
|
119
|
+
elsif v.is_a?(true.class)
|
120
|
+
out "assert #{accessor}"
|
121
|
+
elsif v.is_a?(false.class)
|
122
|
+
out "refute #{accessor}"
|
123
|
+
|
124
|
+
elsif v.is_a?(DateTime) || (defined?(ActiveSupport::TimeWithZone) && v.is_a?(ActiveSupport::TimeWithZone))
|
125
|
+
generate_date_time_assert(v, accessor)
|
126
|
+
elsif v.is_a?(Date)
|
127
|
+
generate_date_assert(v, accessor)
|
102
128
|
else
|
103
|
-
|
104
|
-
out "assert_nil #{accessor}"
|
105
|
-
elsif v.is_a?(true.class)
|
106
|
-
out "assert #{accessor}"
|
107
|
-
elsif v.is_a?(false.class)
|
108
|
-
out "refute #{accessor}"
|
109
|
-
|
110
|
-
elsif v.is_a?(DateTime) || (defined?(ActiveSupport::TimeWithZone) && v.is_a?(ActiveSupport::TimeWithZone))
|
111
|
-
generate_date_time_assert(v, accessor)
|
112
|
-
elsif v.is_a?(Date)
|
113
|
-
generate_date_assert(v, accessor)
|
114
|
-
else
|
115
|
-
out "assert_equal #{v.inspect}, #{make_accessor.call(*accessor_params)}"
|
116
|
-
end
|
129
|
+
out "assert_equal #{v.inspect}, #{make_accessor.call(*accessor_params)}"
|
117
130
|
end
|
118
131
|
end
|
119
132
|
|
@@ -122,7 +135,7 @@ module AssertGenerator
|
|
122
135
|
end
|
123
136
|
|
124
137
|
def drillable_object(v)
|
125
|
-
v.is_a?(Enumerable) ||
|
138
|
+
v.is_a?(Enumerable) || v.respond_to?(:attributes)
|
126
139
|
end
|
127
140
|
|
128
141
|
def generate_date_assert(v, accessor)
|
@@ -131,7 +144,7 @@ module AssertGenerator
|
|
131
144
|
if date_diff.to_i == 0
|
132
145
|
out "assert_equal #{relative_dates}, #{accessor}"
|
133
146
|
else
|
134
|
-
out "assert_equal #{relative_dates} + #{date_diff}.days, #{accessor}"
|
147
|
+
out "assert_equal #{relative_dates} #{date_diff.to_i < 0 ? '-' : '+'} #{date_diff.to_i.abs}.days, #{accessor}"
|
135
148
|
end
|
136
149
|
else
|
137
150
|
out "assert_equal Date.new(#{v.year}, #{v.month}, #{v.day}), #{accessor}"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: assert_generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Parratt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|