1
1
require "test_helper"
2
2
require 'pry'
3
3
4
- class HelloCollectorTest < Minitest ::Test
4
+ class TwoFerTest < Minitest ::Test
5
+
6
+ def test_fixtures
7
+ dir = File . expand_path ( "#{ __FILE__ } /../../fixtures/two-fer/" )
8
+ Dir . foreach ( dir ) . each do |id |
9
+ next unless File . exist? ( "#{ dir } /#{ id } /analysis.json" )
10
+
11
+ expected = TwoFer ::Analyze . ( File . read ( "#{ dir } /#{ id } /two_fer.rb" ) )
12
+ actual = JSON . parse ( File . read ( "#{ dir } /#{ id } /analysis.json" ) )
13
+
14
+ assert_equal expected [ :status ] . to_s , actual [ 'status' ]
15
+ assert_equal expected [ :comments ] , actual [ 'comments' ]
16
+ end
17
+ end
18
+
5
19
# ###
6
20
# Test the module/class
7
21
# ###
@@ -15,8 +29,8 @@ def self.two_fer(name="you")
15
29
end
16
30
}
17
31
results = TwoFer ::Analyze . ( source )
18
- assert results [ :approve ]
19
- assert_equal [ ] , results [ :messages ]
32
+ assert_equal :approve_as_optimal , results [ :status ]
33
+ assert_equal [ ] , results [ :comments ]
20
34
end
21
35
22
36
def test_simple_module_passes
@@ -29,8 +43,8 @@ def self.two_fer(name="you")
29
43
end
30
44
}
31
45
results = TwoFer ::Analyze . ( source )
32
- assert results [ :approve ]
33
- assert_equal [ ] , results [ :messages ]
46
+ assert_equal :approve_as_optimal , results [ :status ]
47
+ assert_equal [ ] , results [ :comments ]
34
48
end
35
49
36
50
def test_simple_module_with_bookkeeping_passes
@@ -47,8 +61,8 @@ module Bookkeeping
47
61
end
48
62
}
49
63
results = TwoFer ::Analyze . ( source )
50
- assert results [ :approve ]
51
- assert_equal [ ] , results [ :messages ]
64
+ assert_equal :approve_as_optimal , results [ :status ]
65
+ assert_equal [ ] , results [ :comments ]
52
66
end
53
67
54
68
def test_different_module_name_fails
@@ -61,8 +75,8 @@ def self.two_fer(name="you")
61
75
end
62
76
}
63
77
results = TwoFer ::Analyze . ( source )
64
- refute results [ :approve ]
65
- assert_equal [ "No module or class called TwoFer" ] , results [ :messages ]
78
+ assert_equal :disapprove_with_comment , results [ :status ]
79
+ assert_equal [ "No module or class called TwoFer" ] , results [ :comments ]
66
80
end
67
81
68
82
# ###
@@ -79,8 +93,8 @@ def self.foobar(name="you")
79
93
end
80
94
}
81
95
results = TwoFer ::Analyze . ( source )
82
- refute results [ :approve ]
83
- assert_equal [ "No method called two_fer" ] , results [ :messages ]
96
+ assert_equal :disapprove_with_comment , results [ :status ]
97
+ assert_equal [ "No method called two_fer" ] , results [ :comments ]
84
98
end
85
99
86
100
def test_missing_param
@@ -93,8 +107,8 @@ def self.two_fer
93
107
end
94
108
}
95
109
results = TwoFer ::Analyze . ( source )
96
- refute results [ :approve ]
97
- assert_equal [ "There is no correct default param - the tests will fail" ] , results [ :messages ]
110
+ assert_equal :disapprove_with_comment , results [ :status ]
111
+ assert_equal [ "There is no correct default param - the tests will fail" ] , results [ :comments ]
98
112
end
99
113
100
114
def test_missing_default_value_fails
@@ -107,8 +121,8 @@ def self.two_fer(name)
107
121
end
108
122
}
109
123
results = TwoFer ::Analyze . ( source )
110
- refute results [ :approve ]
111
- assert_equal [ "There is no correct default param - the tests will fail" ] , results [ :messages ]
124
+ assert_equal :disapprove_with_comment , results [ :status ]
125
+ assert_equal [ "There is no correct default param - the tests will fail" ] , results [ :comments ]
112
126
end
113
127
114
128
def test_splat_fails
@@ -121,8 +135,8 @@ def self.two_fer(*foos)
121
135
end
122
136
}
123
137
results = TwoFer ::Analyze . ( source )
124
- refute results [ :approve ]
125
- assert_equal [ "Rather than using *foos, how about actually setting a parameter called 'name'?" ] , results [ :messages ]
138
+ assert_equal :disapprove_with_comment , results [ :status ]
139
+ assert_equal [ "Rather than using *foos, how about actually setting a parameter called 'name'?" ] , results [ :comments ]
126
140
end
127
141
128
142
# ###
@@ -138,8 +152,8 @@ def self.two_fer(name="you")
138
152
end
139
153
}
140
154
results = TwoFer ::Analyze . ( source )
141
- assert results [ :approve ]
142
- assert_equal [ "Rather than using string building, use interpolation" ] , results [ :messages ]
155
+ assert_equal :approve_with_comment , results [ :status ]
156
+ assert_equal [ "Rather than using string building, use interpolation" ] , results [ :comments ]
143
157
end
144
158
145
159
def test_for_kernel_format
@@ -152,8 +166,8 @@ def self.two_fer(name="you")
152
166
end
153
167
}
154
168
results = TwoFer ::Analyze . ( source )
155
- assert results [ :approve ]
156
- assert_equal [ "Rather than using the format method, use interpolation" ] , results [ :messages ]
169
+ assert_equal :approve_with_comment , results [ :status ]
170
+ assert_equal [ "Rather than using the format method, use interpolation" ] , results [ :comments ]
157
171
end
158
172
159
173
def test_for_string_format
@@ -166,8 +180,8 @@ def self.two_fer(name="you")
166
180
end
167
181
}
168
182
results = TwoFer ::Analyze . ( source )
169
- assert results [ :approve ]
170
- assert_equal [ "Rather than using string's format/percentage method, use interpolation" ] , results [ :messages ]
183
+ assert_equal :approve_with_comment , results [ :status ]
184
+ assert_equal [ "Rather than using string's format/percentage method, use interpolation" ] , results [ :comments ]
171
185
end
172
186
173
187
def test_conditional_with_nil
@@ -184,8 +198,8 @@ def self.two_fer(name=nil)
184
198
end
185
199
}
186
200
results = TwoFer ::Analyze . ( source )
187
- refute results [ :approve ]
188
- assert_equal [ "You could set the default value to 'you' to avoid conditionals" ] , results [ :messages ]
201
+ assert_equal :disapprove_with_comment , results [ :status ]
202
+ assert_equal [ "You could set the default value to 'you' to avoid conditionals" ] , results [ :comments ]
189
203
end
190
204
191
205
def test_conditional_with_nil_reversed
@@ -202,8 +216,8 @@ def self.two_fer(name=nil)
202
216
end
203
217
}
204
218
results = TwoFer ::Analyze . ( source )
205
- refute results [ :approve ]
206
- assert_equal [ "You could set the default value to 'you' to avoid conditionals" ] , results [ :messages ]
219
+ assert_equal :disapprove_with_comment , results [ :status ]
220
+ assert_equal [ "You could set the default value to 'you' to avoid conditionals" ] , results [ :comments ]
207
221
end
208
222
209
223
def test_conditional_with_string
@@ -220,8 +234,8 @@ def self.two_fer(name='dog')
220
234
end
221
235
}
222
236
results = TwoFer ::Analyze . ( source )
223
- refute results [ :approve ]
224
- assert_equal [ "You could set the default value to 'you' to avoid conditionals" ] , results [ :messages ]
237
+ assert_equal :disapprove_with_comment , results [ :status ]
238
+ assert_equal [ "You could set the default value to 'you' to avoid conditionals" ] , results [ :comments ]
225
239
end
226
240
227
241
def test_unknown_solution
@@ -234,9 +248,8 @@ def self.two_fer(name=nil)
234
248
end
235
249
}
236
250
results = TwoFer ::Analyze . ( source )
237
- refute results [ :approve ]
238
- assert results [ :refer_to_mentor ]
239
- assert_equal [ ] , results [ :messages ]
251
+ assert_equal :refer_to_mentor , results [ :status ]
252
+ assert_equal [ ] , results [ :comments ]
240
253
end
241
254
end
242
255
0 commit comments