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,70 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
- require 'tailor/file_line'
3
- require 'pathname'
4
-
5
- include Tailor
6
-
7
- describe Tailor::FileLine do
8
-
9
- describe "with method definitions" do
10
- it "should detect when the method name is camel case" do
11
- line = create_file_line "def doSomething", __LINE__
12
- line.camel_case_method?.should be_true
13
- end
14
-
15
- it "should be OK when the method name is snake case" do
16
- line = create_file_line "def do_something", __LINE__
17
- line.camel_case_method?.should be_false
18
- end
19
- end
20
-
21
- describe "with class names" do
22
- it " should be OK when the class name is camel case" do
23
- line = create_file_line "class AClass", __LINE__
24
- line.snake_case_class?.should be_false
25
- end
26
-
27
- it "should dectect the class name is snake case" do
28
- line = create_file_line "class A_Class", __LINE__
29
- line.snake_case_class?.should be_true
30
- end
31
- end
32
-
33
- describe "with comments" do
34
- it "should detect a regular full line comment" do
35
- line = create_file_line " # This is a comment.", __LINE__
36
- line.comment_line?.should be_true
37
- end
38
-
39
- it "should skip code that's not a full line comment" do
40
- line = create_file_line " puts 'this is some code.'", __LINE__
41
- line.comment_line?.should be_false
42
- end
43
- end
44
-
45
- context "line length" do
46
- it "should detect greater than 80 characters" do
47
- string_81_chars = '#' * 81
48
- line = create_file_line string_81_chars, __LINE__
49
- line.too_long?.should be_true
50
- end
51
-
52
- it "should detect greater than 80 spaces" do
53
- string_81_spaces = ' ' * 81
54
- line = create_file_line string_81_spaces, __LINE__
55
- line.too_long?.should be_true
56
- end
57
-
58
- it "should be OK with 80 chars" do
59
- string_80_chars = '#' * 80
60
- line = create_file_line string_80_chars, __LINE__
61
- line.too_long?.should be_false
62
- end
63
-
64
- it "should be OK with 80 spaces" do
65
- string_80_spaces = ' ' * 80
66
- line = create_file_line string_80_spaces, __LINE__
67
- line.too_long?.should be_false
68
- end
69
- end
70
- end
@@ -1,259 +0,0 @@
1
- require_relative 'spec_helper'
2
- require 'tailor/file_line'
3
- require 'pathname'
4
-
5
- include Tailor
6
-
7
- def strip_regex regexp
8
- original_regexp = regexp.source
9
-
10
- case original_regexp
11
- when /\\b\w+\\b/
12
- return original_regexp.gsub!("\\b", '')
13
- when /\w+{2,}/
14
- return original_regexp.scan(/\w+{2,}/).first
15
- when /\\\{\[/
16
- return '{'
17
- when /\*\\\}/
18
- return '}'
19
- when /\\\[\[/
20
- return '['
21
- when /\*\\\]/
22
- return ']'
23
- end
24
- end
25
-
26
- describe Tailor::Indentation do
27
- include Tailor::Indentation
28
-
29
- context "should return the number of leading spaces in a line" do
30
- it "when the line is not indented" do
31
- line = create_file_line "def do_something", __LINE__
32
- line.indented_spaces.should == 0
33
- end
34
-
35
- it "when the line is indented 1 space" do
36
- line = create_file_line " def do_something", __LINE__
37
- line.indented_spaces.should == 1
38
- end
39
-
40
- it "when the line is indented 1 space and a hard tab" do
41
- line = create_file_line " \tdef do_something", __LINE__
42
- line.indented_spaces.should == 1
43
- end
44
- end
45
-
46
- context "should know what level of indentation a line is at" do
47
- context "for indent expressions" do
48
- Tailor::Indentation::INDENT_EXPRESSIONS.each do |regexp|
49
- expression = strip_regex(regexp)
50
-
51
- it "when the '#{expression }' line is not indented" do
52
- line = create_file_line "#{expression}", __LINE__
53
- line.is_at_level.should == 0.0
54
- end
55
-
56
- it "when the '#{expression}' line is indented only 1 space" do
57
- line = create_file_line " #{expression}", __LINE__
58
- line.is_at_level.should == 0.5
59
- end
60
-
61
- it "when the '#{expression}' line is indented 2 spaces" do
62
- line = create_file_line " #{expression}", __LINE__
63
- line.is_at_level.should == 1.0
64
- end
65
- end
66
- end
67
-
68
- context "for outdent expressions" do
69
- Tailor::Indentation::OUTDENT_EXPRESSIONS.each do |regexp|
70
- expression = strip_regex(regexp)
71
-
72
- it "when the '#{expression }' line is not indented" do
73
- line = create_file_line "#{expression}", __LINE__
74
- line.is_at_level.should == 0.0
75
- end
76
-
77
- it "when the '#{expression}' line is indented only 1 space" do
78
- line = create_file_line " #{expression}", __LINE__
79
- line.is_at_level.should == 0.5
80
- end
81
-
82
- it "when the '#{expression}' line is indented 2 spaces" do
83
- line = create_file_line " #{expression}", __LINE__
84
- line.is_at_level.should == 1.0
85
- end
86
- end
87
- end
88
-
89
- context "for end expressions" do
90
- Tailor::Indentation::END_EXPRESSIONS.each do |regexp|
91
- expression = strip_regex(regexp)
92
-
93
- it "when the '#{expression }' line is not indented" do
94
- line = create_file_line "#{expression}", __LINE__
95
- line.is_at_level.should == 0.0
96
- end
97
-
98
- it "when the '#{expression}' line is indented only 1 space" do
99
- line = create_file_line " #{expression}", __LINE__
100
- line.is_at_level.should == 0.5
101
- end
102
-
103
- it "when the '#{expression}' line is indented 2 spaces" do
104
- line = create_file_line " #{expression}", __LINE__
105
- line.is_at_level.should == 1.0
106
- end
107
- end
108
- end
109
- end
110
-
111
- context "#indent?" do
112
- Tailor::Indentation::INDENT_EXPRESSIONS.each do |regexp|
113
- expression = strip_regex(regexp)
114
-
115
- it "should return true if the line contains #{expression}" do
116
- line = create_file_line "#{expression}", __LINE__
117
- line.indent?.should be_true
118
- end
119
- end
120
- end
121
-
122
- context "#outdent?" do
123
- Tailor::Indentation::OUTDENT_EXPRESSIONS.each do |regexp|
124
- expression = strip_regex(regexp)
125
-
126
- it "should return true if the line contains #{expression}" do
127
- line = create_file_line "#{expression}", __LINE__
128
- line.outdent?.should be_true
129
- end
130
- end
131
- end
132
-
133
- context "#contains_end?" do
134
- Tailor::Indentation::END_EXPRESSIONS.each do |regexp|
135
- expression = strip_regex(regexp)
136
-
137
- it "should return true if the line contains #{expression}" do
138
- line = create_file_line "#{expression}", __LINE__
139
- line.contains_end?.should be_true
140
- end
141
- end
142
- end
143
-
144
- context "#at_improper_level?" do
145
- it "should return true if the line is at the wrong level" do
146
- proper_level = 1.0
147
- line = create_file_line "class SomeClass", __LINE__
148
- line.at_improper_level?(proper_level).should be_true
149
- end
150
-
151
- it "should return false if the line is at the right level" do
152
- proper_level = 0.0
153
- line = create_file_line "class SomeClass", __LINE__
154
- line.at_improper_level?(proper_level).should be_false
155
- end
156
- end
157
-
158
- context "#ends_with_operator?" do
159
- OPERATORS.each_pair do |op_family, op_values|
160
- op_values.each do |op|
161
- it "should return true if the line ends with a #{op}" do
162
- line = create_file_line "1 #{op}", __LINE__
163
- line.ends_with_operator?.should be_true
164
- end
165
-
166
- it "should return true if the line ends with a #{op} plus spaces" do
167
- line = create_file_line "1 #{op} ", __LINE__
168
- line.ends_with_operator?.should be_true
169
- end
170
-
171
- it "should return true if the line ends with a #{op} plus tabs" do
172
- line = create_file_line "1 #{op}\t\t", __LINE__
173
- line.ends_with_operator?.should be_true
174
- end
175
-
176
- it "should return true if the line only has spaces plus a #{op}" do
177
- line = create_file_line " #{op}", __LINE__
178
- line.ends_with_operator?.should be_true
179
- end
180
- end
181
- end
182
-
183
- it "should return false if the line doesn't contain an operator" do
184
- line = create_file_line " def some_method(thing)", __LINE__
185
- line.ends_with_operator?.should be_false
186
- end
187
- end
188
-
189
- context "#ends_with_comma?" do
190
- it "should return true if it ends with a ," do
191
- line = create_file_line " def some_method(thing,", __LINE__
192
- line.ends_with_comma?.should be_true
193
- end
194
-
195
- it "should return true if it ends with a , and spaces" do
196
- line = create_file_line " def some_method(thing, ", __LINE__
197
- line.ends_with_comma?.should be_true
198
- end
199
-
200
- it "should return true if it ends with a , and tabs" do
201
- line = create_file_line " def some_method(thing,\t", __LINE__
202
- line.ends_with_comma?.should be_true
203
- end
204
-
205
- it "should return false if it doesn't end with a ," do
206
- line = create_file_line " def some_method(thing)", __LINE__
207
- line.ends_with_comma?.should be_false
208
- end
209
-
210
- it "should return false if it has a , but doesn't end with one" do
211
- line = create_file_line " def some_method(thing, other)", __LINE__
212
- line.ends_with_comma?.should be_false
213
- end
214
- end
215
-
216
- context "#ends_with_backslash?" do
217
- it "should return true if it ends with a \\" do
218
- line = create_file_line " def some_method(thing,\\", __LINE__
219
- line.ends_with_backslash?.should be_true
220
- end
221
-
222
- it "should return true if it ends with a \\ and spaces" do
223
- line = create_file_line " def some_method(thing,\\ ", __LINE__
224
- line.ends_with_backslash?.should be_true
225
- end
226
-
227
- it "should return true if it ends with a \\ and tabs" do
228
- line = create_file_line " def some_method(thing,\\\t", __LINE__
229
- line.ends_with_backslash?.should be_true
230
- end
231
-
232
- it "should return false if it doesn't end with a \\" do
233
- line = create_file_line " def some_method(thing)", __LINE__
234
- line.ends_with_backslash?.should be_false
235
- end
236
- end
237
-
238
- context "#unclosed_parenthesis?" do
239
- it "should return true if it has a ( but no )" do
240
- line = create_file_line " def some_method(thing,", __LINE__
241
- line.unclosed_parenthesis?.should be_true
242
- end
243
-
244
- it "should return true if it has a ( but no ) and spaces" do
245
- line = create_file_line " def some_method(thing, ", __LINE__
246
- line.unclosed_parenthesis?.should be_true
247
- end
248
-
249
- it "should return true if it has a ( but no ) and tabs" do
250
- line = create_file_line " def some_method(thing,\t\t", __LINE__
251
- line.unclosed_parenthesis?.should be_true
252
- end
253
-
254
- it "should return false if it has a ( and a )" do
255
- line = create_file_line " def some_method(thing)", __LINE__
256
- line.unclosed_parenthesis?.should be_false
257
- end
258
- end
259
- end
@@ -1,71 +0,0 @@
1
- require_relative '../spec_helper'
2
- require 'tailor/file_line'
3
-
4
- include Tailor
5
-
6
- describe Tailor::FileLine, "spacing around colons" do
7
- context "in ternary statments" do
8
- it "should be OK with 1 space around colon" do
9
- line = create_file_line " bobo = true ? true : false", __LINE__
10
- line.spacing_problems.should == 0
11
- end
12
-
13
- it "should detect 0 space after colon" do
14
- line = create_file_line " bobo = true ? true :false", __LINE__
15
- line.spacing_problems.should == 1
16
- end
17
-
18
- it "should detect 0 space before colon" do
19
- line = create_file_line " bobo = true ? true: false", __LINE__
20
- line.spacing_problems.should == 1
21
- end
22
-
23
- it "should detect 0 space before and after colon" do
24
- line = create_file_line " bobo = true ? true:false", __LINE__
25
- line.spacing_problems.should == 1
26
- end
27
-
28
- it "should detect 2 spaces after colon" do
29
- line = create_file_line " bobo = true ? true : false", __LINE__
30
- line.spacing_problems.should == 1
31
- end
32
-
33
- it "should detect 2 spaces before colon" do
34
- line = create_file_line " bobo = true ? true : false", __LINE__
35
- line.spacing_problems.should == 1
36
- end
37
-
38
- it "should detect 2 spaces before and after colon" do
39
- line = create_file_line " bobo = true ? true : false", __LINE__
40
- line.spacing_problems.should == 1
41
- end
42
- end
43
-
44
- context "in symbols" do
45
- it "should be OK with 1 space before" do
46
- line = create_file_line " bobo = { :thing => :clown }", __LINE__
47
- line.spacing_problems.should == 0
48
- end
49
-
50
- it "should be OK when Hash key, method with ? and symbol" do
51
- line = create_file_line " bobo[:thing].eql? :clown", __LINE__
52
- line.spacing_problems.should == 0
53
- end
54
- end
55
-
56
- it "should be OK in namespace operators" do
57
- line = create_file_line "bobo[:thing] == :dog ? bobo[:thing] : Class::String",
58
- __LINE__
59
- line.spacing_problems.should == 0
60
- end
61
-
62
- it "should be OK in Regexp classes" do
63
- line = create_file_line "bobo[:thing].scan(/[:alpha:]/)", __LINE__
64
- line.spacing_problems.should == 0
65
- end
66
-
67
- it "should be OK in setting the global load path" do
68
- line = create_file_line "$:.unshift File.dirname(__FILE__)", __LINE__
69
- line.spacing_problems.should == 0
70
- end
71
- end
@@ -1,159 +0,0 @@
1
- require_relative '../spec_helper'
2
- require 'tailor/file_line'
3
-
4
- include Tailor
5
-
6
- describe Tailor::FileLine, "spacing around commas" do
7
- it "should be OK when followed by a \\ to signify line-continue" do
8
- line = create_file_line "string = 'One, two, three,'\\", __LINE__
9
- line.spacing_problems.should == 0
10
- end
11
-
12
- context "in a method line" do
13
- it "should be OK when no commas" do
14
- line = create_file_line " def do_something this", __LINE__
15
- line.spacing_problems.should == 0
16
- end
17
-
18
- it "should be OK when 0 spaces before and 1 space after a comma" do
19
- line = create_file_line " def do_something this, that", __LINE__
20
- line.spacing_problems.should == 0
21
- end
22
-
23
- it "should detect 2 spaces after a comma" do
24
- line = create_file_line " def do_something this, that", __LINE__
25
- line.spacing_problems.should == 1
26
- end
27
-
28
- it "should detect 0 spaces after a comma" do
29
- line = create_file_line " def do_something this,that", __LINE__
30
- line.spacing_problems.should == 1
31
- end
32
-
33
- it "should detect 1 space before a comma" do
34
- line = create_file_line " def do_something this , that", __LINE__
35
- line.spacing_problems.should == 1
36
- end
37
-
38
- it "should detect 1 space before a comma and 0 spaces after" do
39
- line = create_file_line " def do_something this ,that", __LINE__
40
- line.spacing_problems.should == 2
41
- end
42
- end
43
-
44
- context "in a comment line" do
45
- it "should be OK when no commas" do
46
- line = create_file_line " # Comment line", __LINE__
47
- line.spacing_problems.should == 0
48
- end
49
-
50
- it "should be OK when 1 space after a comma" do
51
- line = create_file_line " # Comment line, and stuff", __LINE__
52
- line.spacing_problems.should == 0
53
- end
54
-
55
- it "should detect 2 spaces after a comma" do
56
- line = create_file_line " # Comment line, and stuff", __LINE__
57
- line.spacing_problems.should == 1
58
- end
59
-
60
- it "should detect 0 spaces after a comma" do
61
- line = create_file_line " # Comment line,and stuff", __LINE__
62
- line.spacing_problems.should == 1
63
- end
64
-
65
- it "should detect 1 space before a comma" do
66
- line = create_file_line " # Comment line , and stuff", __LINE__
67
- line.spacing_problems.should == 1
68
- end
69
-
70
- it "should detect 1 space before a comma and 0 spaces after" do
71
- line = create_file_line " # Comment line ,and stuff", __LINE__
72
- line.spacing_problems.should == 2
73
- end
74
-
75
- it "should be OK when 0 spaces after a comma, but end of the line" do
76
- line = create_file_line " # This is a comment that,\n", __LINE__
77
- line.spacing_problems.should == 0
78
- end
79
-
80
- it "should detect 2 spaces after a comma when at the end of a line" do
81
- line = create_file_line " # This is a comment that, \n", __LINE__
82
- line.spacing_problems.should == 1 # 1 for whitespace
83
- end
84
-
85
- it "should detect 2 spaces after a comma" do
86
- line = create_file_line " # This is a comment that, meows", __LINE__
87
- line.spacing_problems.should == 1
88
- end
89
- end
90
-
91
- context "in a statement with an Array" do
92
- it "should be OK when no commas" do
93
- line = create_file_line " bobo = ['hi']", __LINE__
94
- line.spacing_problems.should == 0
95
- end
96
-
97
- it "should be OK when 1 space after a comma" do
98
- line = create_file_line " bobo = ['hi', 'meow']", __LINE__
99
- line.spacing_problems.should == 0
100
- end
101
-
102
- it "should detect 2 spaces after a comma" do
103
- line = create_file_line " bobo = ['hi', 'meow']", __LINE__
104
- line.spacing_problems.should == 1
105
- end
106
-
107
- it "should detect 0 spaces after a comma" do
108
- line = create_file_line " bobo = ['hi','meow']", __LINE__
109
- line.spacing_problems.should == 1
110
- end
111
-
112
- it "should detect 1 space before a comma" do
113
- line = create_file_line " bobo = ['hi' , 'meow']", __LINE__
114
- line.spacing_problems.should == 1
115
- end
116
-
117
- it "should detect 1 space before a comma and 0 spaces after" do
118
- line = create_file_line " bobo = ['hi' ,'meow']", __LINE__
119
- line.spacing_problems.should == 2
120
- end
121
- end
122
-
123
- context "in a statement with a Hash" do
124
- it "should be OK when no commas" do
125
- line = create_file_line "bobo = { :hi => 'meow' }", __LINE__
126
- line.spacing_problems.should == 0
127
- end
128
-
129
- it "should be OK when 1 space after a comma" do
130
- line = create_file_line "bobo = { :hi => 'meow', :bye => 'meow' }",
131
- __LINE__
132
- line.spacing_problems.should == 0
133
- end
134
-
135
- it "should detect 2 spaces after a comma" do
136
- line = create_file_line "bobo = { :hi => 'meow', :bye => 'meow' }",
137
- __LINE__
138
- line.spacing_problems.should == 1
139
- end
140
-
141
- it "should detect 0 spaces after a comma" do
142
- line = create_file_line "bobo = { :hi => 'meow',:bye => 'meow' }",
143
- __LINE__
144
- line.spacing_problems.should == 1
145
- end
146
-
147
- it "should detect 1 space before a comma" do
148
- line = create_file_line "bobo = { :hi => 'meow' , :bye => 'meow' }",
149
- __LINE__
150
- line.spacing_problems.should == 1
151
- end
152
-
153
- it "should detect 1 space before a comma and 0 spaces after" do
154
- line = create_file_line "bobo = { :hi => 'meow' ,:bye => 'meow' }",
155
- __LINE__
156
- line.spacing_problems.should == 2
157
- end
158
- end
159
- end