tailor 0.0.3 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +8 -0
- data/Manifest.txt +22 -2
- data/PostInstall.txt +4 -0
- data/README.rdoc +7 -6
- data/Rakefile +7 -1
- data/bin/tailor +21 -5
- data/features/indentation.feature +22 -0
- data/features/spacing.feature +13 -18
- data/features/spacing/commas.feature +44 -0
- data/features/step_definitions/indentation_steps.rb +139 -0
- data/features/step_definitions/spacing/commas_steps.rb +14 -0
- data/features/step_definitions/spacing_steps.rb +1 -36
- data/features/support/1_file_with_bad_comma_spacing/bad_comma_spacing.rb +43 -5
- data/features/support/1_file_with_bad_curly_brace_spacing/bad_curly_brace_spacing.rb +60 -0
- data/features/support/1_file_with_bad_operator_spacing/bad_op_spacing.rb +31 -0
- data/features/support/1_file_with_bad_parenthesis/bad_parenthesis.rb +1 -3
- data/features/support/1_file_with_bad_square_brackets/bad_square_brackets.rb +62 -0
- data/features/support/1_file_with_bad_ternary_colon_spacing/bad_ternary_colon_spacing.rb +31 -0
- data/features/support/1_good_simple_file/simple_project.rb +5 -0
- data/features/support/1_long_file_with_indentation/my_project.rb +56 -0
- data/features/support/common.rb +74 -1
- data/features/support/env.rb +3 -1
- data/features/support/world.rb +0 -52
- data/lib/tailor.rb +132 -41
- data/lib/tailor/file_line.rb +66 -177
- data/lib/tailor/indentation.rb +251 -0
- data/lib/tailor/spacing.rb +243 -0
- data/lib/tasks/metrics.rake +23 -0
- data/lib/tasks/stats.rake +11 -0
- data/logic.txt +30 -0
- data/ruby-style-checker.rb +77 -46
- data/spec/file_line_spec.rb +18 -193
- data/spec/indentation_spec.rb +259 -0
- data/spec/spacing/colon_spacing_spec.rb +71 -0
- data/spec/spacing/comma_spacing_spec.rb +159 -0
- data/spec/spacing/curly_brace_spacing_spec.rb +258 -0
- data/spec/spacing/parentheses_spacing_spec.rb +28 -0
- data/spec/spacing/square_bracket_spacing_spec.rb +116 -0
- data/spec/spacing_spec.rb +167 -0
- data/spec/spec_helper.rb +4 -0
- data/spec/tailor_spec.rb +2 -2
- metadata +73 -38
- data/features/support/1_good_simple_file/my_project.rb +0 -7
- data/lib/tailor/indentation_checker.rb +0 -27
@@ -0,0 +1,258 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
|
+
require 'tailor/file_line'
|
3
|
+
|
4
|
+
include Tailor
|
5
|
+
|
6
|
+
describe Tailor::FileLine, "with curly braces" do
|
7
|
+
context "as a block" do
|
8
|
+
it "should be OK with 1 space before, 1 after {, 1 before }" do
|
9
|
+
line = create_file_line " 5.times { |num| puts num }", __LINE__
|
10
|
+
line.spacing_problems.should == 0
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should detect 0 spaces before a {" do
|
14
|
+
line = create_file_line " 5.times{ |num| puts num }", __LINE__
|
15
|
+
line.spacing_problems.should == 1
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should detect 0 spaces after a {" do
|
19
|
+
line = create_file_line " 5.times {|num| puts num }", __LINE__
|
20
|
+
line.spacing_problems.should == 1
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should detect 0 spaces before and after a {" do
|
24
|
+
line = create_file_line " 5.times{|num| puts num }", __LINE__
|
25
|
+
line.spacing_problems.should == 1
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should be OK with 1 space around a }" do
|
29
|
+
line = create_file_line " 5.times { |num| puts num } ", __LINE__
|
30
|
+
line.spacing_problems.should == 1 # Trailing whitespace
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should detect 0 spaces before a }" do
|
34
|
+
line = create_file_line " 5.times { |num| puts num}", __LINE__
|
35
|
+
line.spacing_problems.should == 1
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should detect 0 spaces before & after {, before a }" do
|
39
|
+
line = create_file_line " 5.times{|num| puts num}", __LINE__
|
40
|
+
line.spacing_problems.should == 2
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should detect >1 space after a {" do
|
44
|
+
line = create_file_line " 5.times { |num| puts num }", __LINE__
|
45
|
+
line.spacing_problems.should == 1
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should detect >1 space before a {" do
|
49
|
+
line = create_file_line " 5.times { |num| puts num }", __LINE__
|
50
|
+
line.spacing_problems.should == 1
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should detect >1 space before, no spaces after a {" do
|
54
|
+
line = create_file_line " 5.times {|num| puts num }", __LINE__
|
55
|
+
line.spacing_problems.should == 2
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should detect >1 space after, no spaces before a {" do
|
59
|
+
line = create_file_line " 5.times{ |num| puts num }", __LINE__
|
60
|
+
line.spacing_problems.should == 2
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should detect >1 space before }" do
|
64
|
+
line = create_file_line " 5.times { |num| puts num }", __LINE__
|
65
|
+
line.spacing_problems.should == 1
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "in Hashes" do
|
70
|
+
context "with symbol keys" do
|
71
|
+
it "should be OK when declaring a new Hash" do
|
72
|
+
line = create_file_line " thing = {}", __LINE__
|
73
|
+
line.spacing_problems.should == 0
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should be OK with 1 space before, 1 after {, 1 before }" do
|
77
|
+
line = create_file_line " thing = { :one => 1 }", __LINE__
|
78
|
+
line.spacing_problems.should == 0
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should be OK with proper spacing and a space at the end" do
|
82
|
+
line = create_file_line " thing = { :one => 1 } ", __LINE__
|
83
|
+
line.spacing_problems.should == 1 # Trailing whitespace
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should detect 0 spaces after {" do
|
87
|
+
line = create_file_line " thing = {:one => 1 }", __LINE__
|
88
|
+
line.spacing_problems.should == 1
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should detect 0 spaces before {" do
|
92
|
+
line = create_file_line " thing ={ :one => 1 }", __LINE__
|
93
|
+
line.spacing_problems.should == 1
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should detect 0 spaces before and after {" do
|
97
|
+
line = create_file_line " thing ={:one => 1 }", __LINE__
|
98
|
+
line.spacing_problems.should == 1
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should detect 0 spaces before }" do
|
102
|
+
line = create_file_line " thing = { :one => 1}", __LINE__
|
103
|
+
line.spacing_problems.should == 1
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should detect 0 spaces before and after { and }" do
|
107
|
+
line = create_file_line " thing ={:one => 1}", __LINE__
|
108
|
+
line.spacing_problems.should == 2
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
context "with single-quote string keys" do
|
113
|
+
it "should be OK with 1 space before, 1 after {, 1 before }" do
|
114
|
+
line = create_file_line " thing = { 'one' => 1 }", __LINE__
|
115
|
+
line.spacing_problems.should == 0
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should be OK with proper spacing and a space at the end" do
|
119
|
+
line = create_file_line " thing = { 'one' => 1 } ", __LINE__
|
120
|
+
line.spacing_problems.should == 1 # Trailing whitespace
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should detect 0 spaces after {" do
|
124
|
+
line = create_file_line " thing = {'one' => 1 }", __LINE__
|
125
|
+
line.spacing_problems.should == 1
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should detect 0 spaces before {" do
|
129
|
+
line = create_file_line " thing ={ 'one' => 1 }", __LINE__
|
130
|
+
line.spacing_problems.should == 1
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should detect 0 spaces before and after {" do
|
134
|
+
line = create_file_line " thing ={'one' => 1 }", __LINE__
|
135
|
+
line.spacing_problems.should == 1
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should detect 0 spaces before }" do
|
139
|
+
line = create_file_line " thing = { 'one' => 1}", __LINE__
|
140
|
+
line.spacing_problems.should == 1
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should detect 0 spaces before and after { and }" do
|
144
|
+
line = create_file_line " thing ={'one' => 1}", __LINE__
|
145
|
+
line.spacing_problems.should == 2
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
context "with double-quote string keys" do
|
150
|
+
it "should be OK with 1 space before, 1 after {, 1 before }" do
|
151
|
+
line = create_file_line " thing = { \"one\" => 1 }", __LINE__
|
152
|
+
line.spacing_problems.should == 0
|
153
|
+
end
|
154
|
+
|
155
|
+
it "should be OK with proper spacing and a space at the end" do
|
156
|
+
line = create_file_line " thing = { \"one\" => 1 } ", __LINE__
|
157
|
+
line.spacing_problems.should == 1 # Trailing whitespace
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should detect 0 spaces after {" do
|
161
|
+
line = create_file_line " thing = {\"one\" => 1 }", __LINE__
|
162
|
+
line.spacing_problems.should == 1
|
163
|
+
end
|
164
|
+
|
165
|
+
it "should detect 0 spaces before {" do
|
166
|
+
line = create_file_line " thing ={ \"one\" => 1 }", __LINE__
|
167
|
+
line.spacing_problems.should == 1
|
168
|
+
end
|
169
|
+
|
170
|
+
it "should detect 0 spaces before and after {" do
|
171
|
+
line = create_file_line " thing ={\"one\" => 1 }", __LINE__
|
172
|
+
line.spacing_problems.should == 1
|
173
|
+
end
|
174
|
+
|
175
|
+
it "should detect 0 spaces before }" do
|
176
|
+
line = create_file_line " thing = { \"one\" => 1}", __LINE__
|
177
|
+
line.spacing_problems.should == 1
|
178
|
+
end
|
179
|
+
|
180
|
+
it "should detect 0 spaces before and after { and }" do
|
181
|
+
line = create_file_line " thing ={\"one\" => 1}", __LINE__
|
182
|
+
line.spacing_problems.should == 2
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
context "with string substituted value" do
|
187
|
+
before do
|
188
|
+
@value = 1
|
189
|
+
end
|
190
|
+
|
191
|
+
it "should be OK with 1 space before, 1 after {, 1 before }" do
|
192
|
+
line = create_file_line " thing = { \"one\" => \"#{@value}\" }", __LINE__
|
193
|
+
line.spacing_problems.should == 0
|
194
|
+
end
|
195
|
+
|
196
|
+
it "should be OK with proper spacing and a space at the end" do
|
197
|
+
line = create_file_line " thing = { \"one\" => \"#{@value}\" } ", __LINE__
|
198
|
+
line.spacing_problems.should == 1 # Trailing whitespace
|
199
|
+
end
|
200
|
+
|
201
|
+
it "should detect 0 spaces after {" do
|
202
|
+
line = create_file_line " thing = {\"one\" => \"#{@value}\" }", __LINE__
|
203
|
+
line.spacing_problems.should == 1
|
204
|
+
end
|
205
|
+
|
206
|
+
it "should detect 0 spaces before {" do
|
207
|
+
line = create_file_line " thing ={ \"one\" => \"#{@value}\" }", __LINE__
|
208
|
+
line.spacing_problems.should == 1
|
209
|
+
end
|
210
|
+
|
211
|
+
it "should detect 0 spaces before and after {" do
|
212
|
+
line = create_file_line " thing ={\"one\" => \"#{@value}\" }", __LINE__
|
213
|
+
line.spacing_problems.should == 1
|
214
|
+
end
|
215
|
+
|
216
|
+
it "should detect 0 spaces before }" do
|
217
|
+
line = create_file_line " thing = { \"one\" => \"#{@value}\"}", __LINE__
|
218
|
+
line.spacing_problems.should == 1
|
219
|
+
end
|
220
|
+
|
221
|
+
it "should detect 0 spaces before and after { and }" do
|
222
|
+
line = create_file_line " thing ={\"one\" => \"#{@value}\"}", __LINE__
|
223
|
+
line.spacing_problems.should == 2
|
224
|
+
end
|
225
|
+
|
226
|
+
it "should detect 0 spaces after { and before }" do
|
227
|
+
line = create_file_line "thing = {'id'=>\"#{@value}\", " +
|
228
|
+
"'attributes' => { 'friendly-name' => \"#{@value}\"}}",
|
229
|
+
__LINE__
|
230
|
+
line.spacing_problems.should == 2
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
context "in Strings" do
|
236
|
+
it "should be OK when substituting a variable" do
|
237
|
+
thing = ""
|
238
|
+
line = create_file_line " a_string = \"This is a #{thing}\"", __LINE__
|
239
|
+
line.spacing_problems.should == 0
|
240
|
+
end
|
241
|
+
|
242
|
+
it "should be OK when substituting a method call" do
|
243
|
+
line = create_file_line " a_string = \"This has #{Class.methods}\"", __LINE__
|
244
|
+
line.spacing_problems.should == 0
|
245
|
+
end
|
246
|
+
|
247
|
+
it "should be OK when substituting in a heredoc" do
|
248
|
+
line = create_file_line "#{Class.methods}", __LINE__
|
249
|
+
line.spacing_problems.should == 0
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
it "should be OK when used as default params in a method definition" do
|
254
|
+
thing = ""
|
255
|
+
line = create_file_line "def a_method one={}", __LINE__
|
256
|
+
line.spacing_problems.should == 0
|
257
|
+
end
|
258
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
|
+
require 'tailor/file_line'
|
3
|
+
|
4
|
+
include Tailor
|
5
|
+
|
6
|
+
describe Tailor::FileLine, "spacing around parentheses" do
|
7
|
+
context "in a method" do
|
8
|
+
it "should be OK with no space before ) and none after (" do
|
9
|
+
line = create_file_line " def do_something(that, this)", __LINE__
|
10
|
+
line.spacing_problems.should == 0
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should be OK with no parameters" do
|
14
|
+
line = create_file_line " def do_something()", __LINE__
|
15
|
+
line.spacing_problems.should == 0
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should detect a space after (" do
|
19
|
+
line = create_file_line " def do_something( that, this)", __LINE__
|
20
|
+
line.spacing_problems.should == 1
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should detect a space before )" do
|
24
|
+
line = create_file_line " def do_something(that, this )", __LINE__
|
25
|
+
line.spacing_problems.should == 1
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
|
+
require 'tailor/file_line'
|
3
|
+
|
4
|
+
include Tailor
|
5
|
+
|
6
|
+
describe Tailor::FileLine, "with square brackets" do
|
7
|
+
context "in an Array" do
|
8
|
+
context "with 0 elements" do
|
9
|
+
it "should be OK with 0 spaces" do
|
10
|
+
line = create_file_line "bobo = []", __LINE__
|
11
|
+
line.spacing_problems.should == 0
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should detect 1 space after [" do
|
15
|
+
line = create_file_line "bobo = [ ]", __LINE__
|
16
|
+
line.spacing_problems.should == 2 # 1 after, 1 before
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "when assigning elements" do
|
21
|
+
it "should be OK with 0 spaces" do
|
22
|
+
line = create_file_line "bobo = ['clown']", __LINE__
|
23
|
+
line.spacing_problems.should == 0
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should be OK when beginning of multi-line array" do
|
27
|
+
line = create_file_line " bobo = [", __LINE__
|
28
|
+
line.spacing_problems.should == 0
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should be OK when end of multi-line array" do
|
32
|
+
line = create_file_line " ]", __LINE__
|
33
|
+
line.spacing_problems.should == 0
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should detect 1 space after [" do
|
37
|
+
line = create_file_line "bobo = [ 'clown']", __LINE__
|
38
|
+
line.spacing_problems.should == 1
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should detect 1 space before ]" do
|
42
|
+
line = create_file_line "bobo = ['clown' ]", __LINE__
|
43
|
+
line.spacing_problems.should == 1
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should detect 1 space after [ and 1 before ]" do
|
47
|
+
line = create_file_line "bobo = [ 'clown' ]", __LINE__
|
48
|
+
line.spacing_problems.should == 2
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "when referencing elements" do
|
53
|
+
it "should be OK with 0 spaces" do
|
54
|
+
line = create_file_line "bobo['clown']", __LINE__
|
55
|
+
line.spacing_problems.should == 0
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should detect 1 space after [" do
|
59
|
+
line = create_file_line "bobo[ 'clown']", __LINE__
|
60
|
+
line.spacing_problems.should == 1
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should detect 1 space before [" do
|
64
|
+
line = create_file_line "bobo ['clown']", __LINE__
|
65
|
+
line.spacing_problems.should == 1
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should detect 1 space before ]" do
|
69
|
+
line = create_file_line "bobo['clown' ]", __LINE__
|
70
|
+
line.spacing_problems.should == 1
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should detect 1 space after [ and 1 before ]" do
|
74
|
+
line = create_file_line "bobo[ 'clown' ]", __LINE__
|
75
|
+
line.spacing_problems.should == 2
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should detect 1 space before and after [ and 1 before ]" do
|
79
|
+
line = create_file_line "bobo [ 'clown' ]", __LINE__
|
80
|
+
line.spacing_problems.should == 2
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context "in Hash references" do
|
86
|
+
it "should be OK with 0 spaces" do
|
87
|
+
line = create_file_line "bobo[:clown]", __LINE__
|
88
|
+
line.spacing_problems.should == 0
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should detect 1 space after [" do
|
92
|
+
line = create_file_line "bobo[ :clown]", __LINE__
|
93
|
+
line.spacing_problems.should == 1
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should detect 1 space before [" do
|
97
|
+
line = create_file_line "bobo [:clown]", __LINE__
|
98
|
+
line.spacing_problems.should == 1
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should detect 1 space before ]" do
|
102
|
+
line = create_file_line "bobo[:clown ]", __LINE__
|
103
|
+
line.spacing_problems.should == 1
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should detect 1 space after [ and 1 before ]" do
|
107
|
+
line = create_file_line "bobo[ :clown ]", __LINE__
|
108
|
+
line.spacing_problems.should == 2
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should detect 1 space before and after [ and 1 before ]" do
|
112
|
+
line = create_file_line "bobo [ :clown ]", __LINE__
|
113
|
+
line.spacing_problems.should == 2
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,167 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
require 'tailor/file_line'
|
3
|
+
require 'pathname'
|
4
|
+
|
5
|
+
include Tailor
|
6
|
+
|
7
|
+
describe Tailor::FileLine do
|
8
|
+
|
9
|
+
# Commenting out until we fix the whitespace count problem
|
10
|
+
=begin
|
11
|
+
it "should detect the number of trailing whitespace(s)" do
|
12
|
+
line = create_file_line " puts 'This is a line.' \n", __LINE__
|
13
|
+
line.trailing_whitespace_count.should == 2
|
14
|
+
end
|
15
|
+
=end
|
16
|
+
|
17
|
+
=begin
|
18
|
+
describe "with operators" do
|
19
|
+
Tailor::OPERATORS.each_pair do |op_group, op_values|
|
20
|
+
op_values.each do |op|
|
21
|
+
context "#no_space_after?" do
|
22
|
+
it "should detect 0 spaces around a #{op} sign" do
|
23
|
+
line = create_file_line " 1#{op}1", __LINE__
|
24
|
+
line.no_space_after?(op).should be_true
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should be OK with 0 spaces before but 1 space after a #{op} sign" do
|
28
|
+
line = create_file_line " 1#{op} 1", __LINE__
|
29
|
+
line.no_space_after?(op).should be_false
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should report 0 spaces after a #{op} sign" do
|
33
|
+
line = create_file_line " 1 #{op}1", __LINE__
|
34
|
+
line.no_space_after?(op).should be_true
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should be OK with 1 space around a #{op} sign" do
|
38
|
+
line = create_file_line " 1 #{op} 1", __LINE__
|
39
|
+
line.no_space_after?(op).should be_false
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should be OK an #{op} sign isn't in the string" do
|
43
|
+
line = create_file_line " 1 plus 1", __LINE__
|
44
|
+
line.no_space_after?(op).should be_false
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "#spaces_after" do
|
49
|
+
it "should report 0 spaces after a #{op} sign" do
|
50
|
+
line = create_file_line " 1 #{op}1", __LINE__
|
51
|
+
line.spaces_after(op).first.should == 0
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should report 1 space after a #{op} sign" do
|
55
|
+
line = create_file_line " 1 #{op} 1", __LINE__
|
56
|
+
line.spaces_after(op).first.should == 1
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context "#no_space_before?" do
|
61
|
+
it "should detect 0 spaces around a #{op} sign" do
|
62
|
+
line = create_file_line " 1#{op}1", __LINE__
|
63
|
+
line.no_space_before?(op).should be_true
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should be OK with 0 spaces after but 1 space before a #{op} sign" do
|
67
|
+
line = create_file_line " 1 #{op}1", __LINE__
|
68
|
+
line.no_space_before?(op).should be_false
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should report 0 spaces before a #{op} sign" do
|
72
|
+
line = create_file_line " 1#{op} 1", __LINE__
|
73
|
+
line.no_space_before?(op).should be_true
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should be OK with 1 space around a #{op} sign" do
|
77
|
+
line = create_file_line " 1 #{op} 1", __LINE__
|
78
|
+
line.no_space_before?(op).should be_false
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should be OK an #{op} sign isn't in the string" do
|
82
|
+
line = create_file_line " 1 plus 1", __LINE__
|
83
|
+
line.no_space_before?(op).should be_false
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context "#spaces_before" do
|
88
|
+
it "should report 0 spaces before a #{op} sign" do
|
89
|
+
line = create_file_line " 1#{op} 1", __LINE__
|
90
|
+
line.spaces_before(op).first.should == 0
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should report 1 space before a #{op} sign" do
|
94
|
+
line = create_file_line " 1 #{op} 1", __LINE__
|
95
|
+
line.spaces_before(op).first.should == 1
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context "#word_is_in_string?" do
|
100
|
+
it "should report that the #{op} is in a string" do
|
101
|
+
line = create_file_line "' 1 #{op} 1'", __LINE__
|
102
|
+
line.word_is_in_string?(op).should be_true
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should report that the #{op} is NOT in a string" do
|
106
|
+
line = create_file_line " 1 #{op} 1", __LINE__
|
107
|
+
line.word_is_in_string?(op).should be_false
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context "#word_is_in_regexp?" do
|
112
|
+
it "should report that the #{op} is in a Regexp" do
|
113
|
+
line = create_file_line "/\\" + op + "$/", __LINE__
|
114
|
+
line.word_is_in_regexp?(op).should be_true
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should report that the #{op} is NOT in a Regexp" do
|
118
|
+
line = create_file_line "\\" + op + "$", __LINE__
|
119
|
+
line.word_is_in_regexp?(op).should be_false
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should be OK if the line is a method with a ?" do
|
126
|
+
line = create_file_line " def hungry?", __LINE__
|
127
|
+
line.question_mark_method?.should be_true
|
128
|
+
line.no_space_before?('?').should be_false
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should be OK if the line is a known method with a ?" do
|
132
|
+
line = create_file_line " 'string'.include?(thing)", __LINE__
|
133
|
+
line.question_mark_method?.should be_true
|
134
|
+
line.no_space_before?('?').should be_false
|
135
|
+
end
|
136
|
+
end
|
137
|
+
=end
|
138
|
+
|
139
|
+
context "question marks" do
|
140
|
+
it "should detect a word with a ?" do
|
141
|
+
line = create_file_line " thing.nil?", __LINE__
|
142
|
+
line.question_mark_method?.should be_true
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should skip a word without a ?" do
|
146
|
+
line = create_file_line " thing.strip!", __LINE__
|
147
|
+
line.question_mark_method?.should be_false
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
context "indenting by hardtabs" do
|
152
|
+
it "should find when indented by 1 hard tab" do
|
153
|
+
line = create_file_line "\tdef do_something", __LINE__
|
154
|
+
line.spacing_problems.should == 1
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should find when indented with a space and 1 hard tab" do
|
158
|
+
line = create_file_line " \tdef do_something", __LINE__
|
159
|
+
line.spacing_problems.should == 1
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should be OK when the line is not indented" do
|
163
|
+
line = create_file_line "def do_something", __LINE__
|
164
|
+
line.spacing_problems.should == 0
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|