tailor 0.1.5 → 1.0.0.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. data/.gitignore +9 -1
  2. data/.rspec +2 -1
  3. data/.tailor +6 -0
  4. data/Gemfile.lock +47 -78
  5. data/{ChangeLog.rdoc → History.rdoc} +0 -0
  6. data/README.rdoc +157 -24
  7. data/Rakefile +0 -9
  8. data/bin/tailor +16 -69
  9. data/features/configurable.feature +78 -0
  10. data/features/horizontal_spacing.feature +262 -0
  11. data/features/indentation.feature +17 -21
  12. data/features/indentation/bad_files_with_no_trailing_newline.feature +90 -0
  13. data/features/indentation/good_files_with_no_trailing_newline.feature +206 -0
  14. data/features/name_detection.feature +72 -0
  15. data/features/step_definitions/indentation_steps.rb +10 -133
  16. data/features/support/env.rb +7 -15
  17. data/features/support/file_cases/horizontal_spacing_cases.rb +265 -0
  18. data/features/support/file_cases/indentation_cases.rb +972 -0
  19. data/features/support/file_cases/naming_cases.rb +52 -0
  20. data/features/support/file_cases/vertical_spacing_cases.rb +70 -0
  21. data/features/support/hooks.rb +8 -0
  22. data/features/support/{1_file_with_bad_operator_spacing → legacy}/bad_op_spacing.rb +0 -0
  23. data/features/support/{1_file_with_bad_ternary_colon_spacing → legacy}/bad_ternary_colon_spacing.rb +0 -0
  24. data/features/support/{1_long_file_with_indentation/my_project.rb → legacy/long_file_with_indentation.rb} +1 -1
  25. data/features/support/world.rb +14 -0
  26. data/features/vertical_spacing.feature +114 -0
  27. data/lib/ext/string_ext.rb +5 -0
  28. data/lib/tailor.rb +6 -252
  29. data/lib/tailor/cli.rb +49 -0
  30. data/lib/tailor/cli/options.rb +251 -0
  31. data/lib/tailor/composite_observable.rb +56 -0
  32. data/lib/tailor/configuration.rb +263 -0
  33. data/lib/tailor/critic.rb +162 -0
  34. data/lib/tailor/formatters/text.rb +126 -0
  35. data/lib/tailor/lexed_line.rb +246 -0
  36. data/lib/tailor/lexer.rb +428 -0
  37. data/lib/tailor/lexer/token.rb +103 -0
  38. data/lib/tailor/lexer_constants.rb +75 -0
  39. data/lib/tailor/logger.rb +28 -0
  40. data/lib/tailor/problem.rb +100 -0
  41. data/lib/tailor/reporter.rb +48 -0
  42. data/lib/tailor/ruler.rb +39 -0
  43. data/lib/tailor/rulers.rb +7 -0
  44. data/lib/tailor/rulers/allow_camel_case_methods_ruler.rb +30 -0
  45. data/lib/tailor/rulers/allow_hard_tabs_ruler.rb +22 -0
  46. data/lib/tailor/rulers/allow_screaming_snake_case_classes_ruler.rb +32 -0
  47. data/lib/tailor/rulers/allow_trailing_line_spaces_ruler.rb +33 -0
  48. data/lib/tailor/rulers/indentation_spaces_ruler.rb +199 -0
  49. data/lib/tailor/rulers/indentation_spaces_ruler/indentation_manager.rb +362 -0
  50. data/lib/tailor/rulers/max_code_lines_in_class_ruler.rb +84 -0
  51. data/lib/tailor/rulers/max_code_lines_in_method_ruler.rb +84 -0
  52. data/lib/tailor/rulers/max_line_length_ruler.rb +31 -0
  53. data/lib/tailor/rulers/spaces_after_comma_ruler.rb +83 -0
  54. data/lib/tailor/rulers/spaces_after_lbrace_ruler.rb +114 -0
  55. data/lib/tailor/rulers/spaces_after_lbracket_ruler.rb +123 -0
  56. data/lib/tailor/rulers/spaces_after_lparen_ruler.rb +116 -0
  57. data/lib/tailor/rulers/spaces_before_comma_ruler.rb +67 -0
  58. data/lib/tailor/rulers/spaces_before_lbrace_ruler.rb +93 -0
  59. data/lib/tailor/rulers/spaces_before_rbrace_ruler.rb +98 -0
  60. data/lib/tailor/rulers/spaces_before_rbracket_ruler.rb +70 -0
  61. data/lib/tailor/rulers/spaces_before_rparen_ruler.rb +70 -0
  62. data/lib/tailor/rulers/spaces_in_empty_braces_ruler.rb +94 -0
  63. data/lib/tailor/rulers/trailing_newlines_ruler.rb +36 -0
  64. data/lib/tailor/runtime_error.rb +3 -0
  65. data/lib/tailor/tailorrc.erb +88 -0
  66. data/lib/tailor/version.rb +2 -2
  67. data/spec/spec_helper.rb +7 -5
  68. data/spec/tailor/cli_spec.rb +94 -0
  69. data/spec/tailor/configuration_spec.rb +147 -0
  70. data/spec/tailor/critic_spec.rb +63 -0
  71. data/spec/tailor/lexed_line_spec.rb +569 -0
  72. data/spec/tailor/lexer/token_spec.rb +46 -0
  73. data/spec/tailor/lexer_spec.rb +181 -0
  74. data/spec/tailor/options_spec.rb +6 -0
  75. data/spec/tailor/problem_spec.rb +74 -0
  76. data/spec/tailor/reporter_spec.rb +53 -0
  77. data/spec/tailor/ruler_spec.rb +56 -0
  78. data/spec/tailor/rulers/indentation_spaces_ruler/indentation_manager_spec.rb +454 -0
  79. data/spec/tailor/rulers/indentation_spaces_ruler_spec.rb +128 -0
  80. data/spec/tailor/rulers/spaces_after_comma_spec.rb +31 -0
  81. data/spec/tailor/rulers/spaces_after_lbrace_ruler_spec.rb +145 -0
  82. data/spec/tailor/rulers/spaces_before_lbrace_ruler_spec.rb +63 -0
  83. data/spec/tailor/rulers/spaces_before_rbrace_ruler_spec.rb +63 -0
  84. data/spec/tailor/rulers_spec.rb +9 -0
  85. data/spec/tailor/version_spec.rb +6 -0
  86. data/spec/tailor_spec.rb +9 -21
  87. data/tailor.gemspec +22 -35
  88. data/tasks/features.rake +7 -0
  89. data/tasks/roodi.rake +9 -0
  90. data/tasks/roodi_config.yaml +14 -0
  91. data/tasks/spec.rake +16 -0
  92. data/tasks/yard.rake +14 -0
  93. metadata +224 -77
  94. data/features/case_checking.feature +0 -38
  95. data/features/spacing.feature +0 -97
  96. data/features/spacing/commas.feature +0 -44
  97. data/features/step_definitions/case_checking_steps.rb +0 -42
  98. data/features/step_definitions/spacing_steps.rb +0 -156
  99. data/features/support/1_file_with_bad_comma_spacing/bad_comma_spacing.rb +0 -43
  100. data/features/support/1_file_with_bad_curly_brace_spacing/bad_curly_brace_spacing.rb +0 -60
  101. data/features/support/1_file_with_bad_parenthesis/bad_parenthesis.rb +0 -4
  102. data/features/support/1_file_with_bad_square_brackets/bad_square_brackets.rb +0 -62
  103. data/features/support/1_file_with_camel_case_class/camel_case_class.rb +0 -5
  104. data/features/support/1_file_with_camel_case_method/camel_case_method.rb +0 -3
  105. data/features/support/1_file_with_hard_tabs/hard_tab.rb +0 -3
  106. data/features/support/1_file_with_long_lines/long_lines.rb +0 -5
  107. data/features/support/1_file_with_snake_case_class/snake_case_class.rb +0 -5
  108. data/features/support/1_file_with_snake_case_method/snake_case_method.rb +0 -3
  109. data/features/support/1_file_with_trailing_whitespace/trailing_whitespace.rb +0 -5
  110. data/features/support/1_good_simple_file/simple_project.rb +0 -5
  111. data/features/support/common.rb +0 -102
  112. data/features/support/matchers.rb +0 -11
  113. data/lib/tailor/file_line.rb +0 -220
  114. data/lib/tailor/indentation.rb +0 -245
  115. data/lib/tailor/spacing.rb +0 -237
  116. data/spec/file_line_spec.rb +0 -70
  117. data/spec/indentation_spec.rb +0 -259
  118. data/spec/spacing/colon_spacing_spec.rb +0 -71
  119. data/spec/spacing/comma_spacing_spec.rb +0 -159
  120. data/spec/spacing/curly_brace_spacing_spec.rb +0 -257
  121. data/spec/spacing/parentheses_spacing_spec.rb +0 -28
  122. data/spec/spacing/square_bracket_spacing_spec.rb +0 -116
  123. data/spec/spacing_spec.rb +0 -167
  124. data/tasks/metrics.rake +0 -23
@@ -1,257 +0,0 @@
1
- require_relative '../spec_helper'
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
- line = create_file_line "def a_method one={}", __LINE__
255
- line.spacing_problems.should == 0
256
- end
257
- end
@@ -1,28 +0,0 @@
1
- require_relative '../spec_helper'
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
@@ -1,116 +0,0 @@
1
- require_relative '../spec_helper'
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
@@ -1,167 +0,0 @@
1
- require_relative 'spec_helper'
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