tailor 1.1.5 → 1.2.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.
Files changed (54) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/.travis.yml +1 -0
  4. data/Gemfile +1 -1
  5. data/Gemfile.lock +23 -23
  6. data/History.rdoc +14 -0
  7. data/README.rdoc +42 -2
  8. data/Rakefile +7 -0
  9. data/features/continuous_integration.feature +28 -0
  10. data/lib/tailor/cli.rb +17 -4
  11. data/lib/tailor/cli/options.rb +6 -0
  12. data/lib/tailor/configuration.rb +19 -3
  13. data/lib/tailor/configuration/style.rb +7 -0
  14. data/lib/tailor/critic.rb +4 -2
  15. data/lib/tailor/formatters/yaml.rb +51 -0
  16. data/lib/tailor/lexer.rb +6 -4
  17. data/lib/tailor/rake_task.rb +44 -6
  18. data/lib/tailor/reporter.rb +9 -3
  19. data/lib/tailor/rulers/allow_invalid_ruby_ruler.rb +3 -3
  20. data/lib/tailor/rulers/indentation_spaces_ruler.rb +24 -6
  21. data/lib/tailor/rulers/indentation_spaces_ruler/indentation_manager.rb +2 -2
  22. data/lib/tailor/rulers/spaces_before_rbrace_ruler.rb +9 -6
  23. data/lib/tailor/rulers/spaces_in_empty_braces_ruler.rb +1 -1
  24. data/lib/tailor/version.rb +1 -1
  25. data/spec/functional/configuration_spec.rb +37 -0
  26. data/spec/functional/horizontal_spacing/braces_spec.rb +113 -113
  27. data/spec/functional/horizontal_spacing/brackets_spec.rb +39 -39
  28. data/spec/functional/horizontal_spacing/comma_spacing_spec.rb +27 -27
  29. data/spec/functional/horizontal_spacing/hard_tabs_spec.rb +42 -42
  30. data/spec/functional/horizontal_spacing/long_lines_spec.rb +16 -16
  31. data/spec/functional/horizontal_spacing/parens_spec.rb +48 -48
  32. data/spec/functional/horizontal_spacing/trailing_whitespace_spec.rb +23 -23
  33. data/spec/functional/horizontal_spacing_spec.rb +11 -11
  34. data/spec/functional/indentation_spacing/bad_indentation_spec.rb +212 -215
  35. data/spec/functional/indentation_spacing_spec.rb +8 -7
  36. data/spec/functional/naming/camel_case_methods_spec.rb +16 -16
  37. data/spec/functional/naming/screaming_snake_case_classes_spec.rb +30 -30
  38. data/spec/functional/naming_spec.rb +5 -4
  39. data/spec/functional/rake_task_spec.rb +56 -10
  40. data/spec/functional/vertical_spacing/class_length_spec.rb +16 -16
  41. data/spec/functional/vertical_spacing/method_length_spec.rb +16 -16
  42. data/spec/functional/vertical_spacing_spec.rb +5 -4
  43. data/spec/support/bad_indentation_cases.rb +35 -35
  44. data/spec/support/good_indentation_cases.rb +108 -108
  45. data/spec/support/horizontal_spacing_cases.rb +37 -37
  46. data/spec/support/naming_cases.rb +6 -6
  47. data/spec/support/vertical_spacing_cases.rb +4 -4
  48. data/spec/unit/tailor/cli_spec.rb +34 -12
  49. data/spec/unit/tailor/configuration_spec.rb +18 -0
  50. data/spec/unit/tailor/formatters/yaml_spec.rb +75 -0
  51. data/spec/unit/tailor/reporter_spec.rb +23 -4
  52. data/spec/unit/tailor/rulers/indentation_spaces_ruler_spec.rb +12 -10
  53. data/spec/unit/tailor/version_spec.rb +3 -2
  54. metadata +35 -63
@@ -139,20 +139,22 @@ class Tailor
139
139
  # @param [String] token The token that the lexer matched.
140
140
  def on_embexpr_beg(token)
141
141
  log "EMBEXPR_BEG: '#{token}'"
142
+ current_line = LexedLine.new(super, lineno)
142
143
  embexpr_beg_changed
143
- notify_embexpr_beg_observers
144
+ notify_embexpr_beg_observers(current_line, lineno, column)
144
145
  super(token)
145
146
  end
146
147
 
147
148
  # Called when the lexer matches the } that closes a #{. Note that as of
148
- # MRI 1.9.3-p125, this never gets called. Logged as a bug and fixed, but
149
- # not yet released: https://bugs.ruby-lang.org/issues/6211.
149
+ # MRI 1.9.3-p125, this never gets called. Logged as a bug and fixed in
150
+ # ruby 2.0.0-p0: https://bugs.ruby-lang.org/issues/6211.
150
151
  #
151
152
  # @param [String] token The token that the lexer matched.
152
153
  def on_embexpr_end(token)
153
154
  log "EMBEXPR_END: '#{token}'"
155
+ current_line = LexedLine.new(super, lineno)
154
156
  embexpr_end_changed
155
- notify_embexpr_end_observers
157
+ notify_embexpr_end_observers(current_line, lineno, column)
156
158
  super(token)
157
159
  end
158
160
 
@@ -11,6 +11,8 @@ begin
11
11
  rescue LoadError
12
12
  end
13
13
 
14
+ Tailor::Logger.log = false
15
+
14
16
  class Tailor
15
17
 
16
18
  # This class lets you define Rake tasks to drive tailor. Specifying options
@@ -29,13 +31,17 @@ class Tailor
29
31
  # end
30
32
  # end
31
33
  #
32
- # @example Use and override a configuration file
34
+ # @example Use a configuration file
33
35
  # Tailor::RakeTask.new do |task|
34
36
  # task.config_file = 'hardcore_stylin.rb'
35
- # task.file_set 'lib/**/*.rb' do |style|
36
- # style.indentation_spaces 2, level: :warn
37
- # end
38
37
  # end
38
+ #
39
+ # Note that prior to 1.1.4, you could use the #config_file option _and_
40
+ # specify file_sets or recursive_file_sets; this caused problems (and
41
+ # confusion), so the combination of these was removed in 1.2.0. If you use
42
+ # #config_file, then all file_sets and recursive_file_sets that you specify
43
+ # in the Rake task will be ignored; only those specified in the given config
44
+ # file will be used.
39
45
  class RakeTask < ::Rake::TaskLib
40
46
  include ::Rake::DSL if defined? ::Rake::DSL
41
47
 
@@ -54,11 +60,12 @@ class Tailor
54
60
 
55
61
  # @param [String] name The task name.
56
62
  # @param [String] desc Description of the task.
57
- def initialize(name = "tailor", desc = "Check style")
63
+ def initialize(name = 'tailor', desc = 'Check style')
58
64
  @name, @desc = name, desc
59
65
  @tailor_opts = []
60
66
  @file_sets = []
61
67
  @recursive_file_sets = []
68
+ @config_file = nil
62
69
 
63
70
  yield self if block_given?
64
71
 
@@ -91,8 +98,13 @@ class Tailor
91
98
  @tailor_opts.concat %W(--config-file=#{config_file})
92
99
  end
93
100
 
101
+ cli = Tailor::CLI.new(@tailor_opts)
102
+ cli.configuration.file_sets
103
+ create_file_sets_for cli.configuration
104
+ create_recursive_file_sets_for cli.configuration
105
+
94
106
  begin
95
- failure = Tailor::CLI.run(@tailor_opts)
107
+ failure = cli.execute!
96
108
  exit(1) if failure
97
109
  rescue Tailor::RuntimeError => ex
98
110
  STDERR.puts ex.message
@@ -106,5 +118,31 @@ class Tailor
106
118
  end
107
119
  end
108
120
  end
121
+
122
+ # @return [Tailor::Configuration]
123
+ def create_config
124
+ configuration = Tailor::Configuration.new([],
125
+ Tailor::CLI::Options.parse!(@tailor_opts))
126
+ configuration.load!
127
+ configuration.formatters(formatters) unless formatters.nil? || formatters.empty?
128
+
129
+ configuration
130
+ end
131
+
132
+ # @param [Tailor::Configuration] config
133
+ def create_recursive_file_sets_for config
134
+ unless @recursive_file_sets.empty?
135
+ @recursive_file_sets.each do |fs|
136
+ config.recursive_file_set(fs[0], fs[1], &fs[2])
137
+ end
138
+ end
139
+ end
140
+
141
+ # @param [Tailor::Configuration] config
142
+ def create_file_sets_for config
143
+ unless @file_sets.empty?
144
+ @file_sets.each { |fs| config.file_set(fs[0], fs[1], &fs[2]) }
145
+ end
146
+ end
109
147
  end
110
148
  end
@@ -12,6 +12,7 @@ class Tailor
12
12
  # @param [Array] formats A list of formatters to use for generating reports.
13
13
  def initialize(*formats)
14
14
  @formatters = []
15
+ formats = %w[text] if formats.nil? || formats.empty?
15
16
 
16
17
  formats.flatten.each do |formatter|
17
18
  require_relative "formatters/#{formatter}"
@@ -38,10 +39,15 @@ class Tailor
38
39
  # Sends the data to each +@formatters+ to generate the reports of problems
39
40
  # for all files that were just critiqued.
40
41
  #
41
- # @param [Hash] all_problems
42
- def summary_report(all_problems)
42
+ # @param [Hash] all_problems
43
+ def summary_report(all_problems, opts={})
43
44
  @formatters.each do |formatter|
44
- formatter.summary_report(all_problems)
45
+ summary = formatter.summary_report(all_problems)
46
+ if formatter.respond_to?(:accepts_output_file) &&
47
+ formatter.accepts_output_file &&
48
+ !opts[:output_file].empty?
49
+ File.open(opts[:output_file], "w") { |f| f.puts summary }
50
+ end
45
51
  end
46
52
  end
47
53
  end
@@ -17,7 +17,7 @@ class Tailor
17
17
  # @return [Boolean]
18
18
  def invalid_ruby?
19
19
  log "Checking for valid Ruby..."
20
- result = `ruby -c #{@file_name}`
20
+ result = `"#{Gem.ruby}" -c "#{@file_name}"`
21
21
 
22
22
  result.size.zero?
23
23
  end
@@ -26,8 +26,8 @@ class Tailor
26
26
  if invalid_ruby? && @config == false
27
27
  lineno = 0
28
28
  column = 0
29
- msg = "File contains invalid Ruby; run `ruby -c [your_file.rb]` "
30
- msg << "for more details."
29
+ msg = 'File contains invalid Ruby; run `ruby -c [your_file.rb]` '
30
+ msg << 'for more details.'
31
31
 
32
32
  @problems << Problem.new(problem_type, lineno, column, msg,
33
33
  @options[:level])
@@ -55,15 +55,31 @@ class Tailor
55
55
  end
56
56
  end
57
57
 
58
- def embexpr_beg_update
58
+ def embexpr_beg_update(lexed_line, lineno, column)
59
59
  @embexpr_nesting << true
60
+
61
+ token = Tailor::Lexer::Token.new('{')
62
+ @manager.update_for_opening_reason(:on_embexpr_beg, token, lineno)
60
63
  end
61
64
 
62
- # Due to a Ripper bug (depending on which Ruby version you have), this may
63
- # or may not get triggered.
65
+ # Due to a Ripper bug that was fixed in ruby 2.0.0-p0, this will not get
66
+ # triggered if you're using 1.9.x.
64
67
  # More info: https://bugs.ruby-lang.org/issues/6211
65
- def embexpr_end_update
68
+ def embexpr_end_update(current_lexed_line, lineno, column)
66
69
  @embexpr_nesting.pop
70
+
71
+ if @manager.multi_line_braces?(lineno)
72
+ log "End of multi-line braces!"
73
+
74
+ if current_lexed_line.only_embexpr_end?
75
+ @manager.amount_to_change_this -= 1
76
+ msg = "lonely embexpr_end. "
77
+ msg << "change_this -= 1 -> #{@manager.amount_to_change_this}"
78
+ log msg
79
+ end
80
+ end
81
+
82
+ @manager.update_for_closing_reason(:on_embexpr_end, current_lexed_line)
67
83
  end
68
84
 
69
85
  def ignored_nl_update(current_lexed_line, lineno, column)
@@ -166,7 +182,7 @@ class Tailor
166
182
  @manager.transition_lines
167
183
  end
168
184
 
169
- # Since Ripper parses the } in a #{} as :on_rbrace instead of
185
+ # Since Ripper in Ruby 1.9.x parses the } in a #{} as :on_rbrace instead of
170
186
  # :on_embexpr_end, this works around that by using +@embexpr_beg to track
171
187
  # the state of that event. As such, this should only be called from
172
188
  # #rbrace_update.
@@ -177,11 +193,13 @@ class Tailor
177
193
  end
178
194
 
179
195
  def rbrace_update(current_lexed_line, lineno, column)
180
- if in_embexpr?
196
+ # Is this an rbrace that should've been parsed as an embexpr_end?
197
+ if in_embexpr? && RUBY_VERSION < '2.0.0'
181
198
  msg = "Got :rbrace and @embexpr_beg is true. "
182
199
  msg << " Must be at an @embexpr_end."
183
200
  log msg
184
201
  @embexpr_nesting.pop
202
+ @manager.update_for_closing_reason(:on_embexpr_end, current_lexed_line)
185
203
  return
186
204
  end
187
205
 
@@ -271,8 +271,8 @@ class Tailor
271
271
  # reason", such as a +end+, +}+, +]+, +)+.
272
272
  #
273
273
  # @param [Symbol] event_type The event type that is the closing reason.
274
- # @param [Tailor::Token,String] token The token that is the closing
275
- # reason.
274
+ # @param [Tailor::LexedLine] lexed_line The line that contains the
275
+ # closing reason.
276
276
  def update_for_closing_reason(event_type, lexed_line)
277
277
  remove_continuation_keywords
278
278
  remove_appropriate_reason(event_type)
@@ -13,6 +13,7 @@ class Tailor
13
13
  super(config, options)
14
14
  add_lexer_observers :embexpr_beg, :lbrace, :rbrace
15
15
  @lbrace_nesting = []
16
+ @embexpr_nesting = []
16
17
  end
17
18
 
18
19
  # @param [LexedLine] lexed_line
@@ -47,8 +48,10 @@ class Tailor
47
48
  previous_event.last.size
48
49
  end
49
50
 
50
- def embexpr_beg_update
51
- @lbrace_nesting << :embexpr_beg
51
+ def embexpr_beg_update(lexed_line, lineno, column)
52
+ if RUBY_VERSION < '2.0.0'
53
+ @lbrace_nesting << :embexpr_beg
54
+ end
52
55
  end
53
56
 
54
57
  def lbrace_update(lexed_line, lineno, column)
@@ -71,15 +74,15 @@ class Tailor
71
74
  end
72
75
  end
73
76
 
74
- # This has to keep track of '{'s and only follow through with the check
75
- # if the '{' was an lbrace because Ripper doesn't scan the '}' of an
76
- # embedded expression (embexpr_end) as such.
77
+ # For Ruby versions < 2.0.0-p0, this has to keep track of '{'s and only
78
+ # follow through with the check if the '{' was an lbrace because Ripper
79
+ # doesn't scan the '}' of an embedded expression (embexpr_end) as such.
77
80
  #
78
81
  # @param [Tailor::LexedLine] lexed_line
79
82
  # @param [Fixnum] lineno
80
83
  # @param [Fixnum] column
81
84
  def rbrace_update(lexed_line, lineno, column)
82
- if @lbrace_nesting.last == :embexpr_beg
85
+ if RUBY_VERSION < '2.0.0' && @lbrace_nesting.last == :embexpr_beg
83
86
  @lbrace_nesting.pop
84
87
  return
85
88
  end
@@ -40,7 +40,7 @@ class Tailor
40
40
  end
41
41
  end
42
42
 
43
- def embexpr_beg_update
43
+ def embexpr_beg_update(lexed_line, lineno, column)
44
44
  @lbrace_nesting << :embexpr_beg
45
45
  end
46
46
 
@@ -1,3 +1,3 @@
1
1
  class Tailor
2
- VERSION = '1.1.5'
2
+ VERSION = '1.2.0'
3
3
  end
@@ -240,5 +240,42 @@ end
240
240
  config.file_sets[:default].file_list.first.match /lib\/tailor\.rb$/
241
241
  end
242
242
  end
243
+
244
+ context '.tailor defines a yaml formatter' do
245
+ let(:config_file) do
246
+ <<-CONFIG
247
+ Tailor.config do |config|
248
+ config.formatters 'yaml'
249
+ end
250
+ CONFIG
251
+ end
252
+
253
+ before do
254
+ File.should_receive(:read).and_return config_file
255
+ end
256
+
257
+ it "sets formatters to 'yaml'" do
258
+ config.formatters.should == %w(yaml)
259
+ end
260
+ end
261
+
262
+ context '.tailor defines a more than one formatter' do
263
+ let(:config_file) do
264
+ <<-CONFIG
265
+ Tailor.config do |config|
266
+ config.formatters 'yaml', 'text'
267
+ end
268
+ CONFIG
269
+ end
270
+
271
+ before do
272
+ File.should_receive(:read).and_return config_file
273
+ end
274
+
275
+ it "sets formatters to the defined" do
276
+ config.formatters.should == %w(yaml text)
277
+ end
278
+
279
+ end
243
280
  end
244
281
  end
@@ -3,62 +3,62 @@ require 'tailor/critic'
3
3
  require 'tailor/configuration/style'
4
4
 
5
5
  BRACES = {}
6
- BRACES[:single_line_hash_0_spaces_before_lbrace] =
6
+ BRACES['single_line_hash_0_spaces_before_lbrace'] =
7
7
  %Q{thing ={ :one => 'one' }}
8
8
 
9
- BRACES[:single_line_hash_2_spaces_before_lbrace] =
9
+ BRACES['single_line_hash_2_spaces_before_lbrace'] =
10
10
  %Q{thing = { :one => 'one' }}
11
11
 
12
- BRACES[:single_line_hash_2_spaces_before_rbrace] =
12
+ BRACES['single_line_hash_2_spaces_before_rbrace'] =
13
13
  %Q{thing = { :one => 'one' }}
14
14
 
15
- BRACES[:single_line_hash_2_spaces_after_lbrace] =
15
+ BRACES['single_line_hash_2_spaces_after_lbrace'] =
16
16
  %Q{thing = { :one => 'one' }}
17
17
 
18
- BRACES[:two_line_hash_2_spaces_before_lbrace] = %Q{thing1 =
18
+ BRACES['two_line_hash_2_spaces_before_lbrace'] = %Q{thing1 =
19
19
  thing2 = { :one => 'one' }}
20
20
 
21
- BRACES[:two_line_hash_2_spaces_before_rbrace] = %Q{thing1 =
21
+ BRACES['two_line_hash_2_spaces_before_rbrace'] = %Q{thing1 =
22
22
  thing2 = { :one => 'one' }}
23
23
 
24
- BRACES[:two_line_hash_2_spaces_before_lbrace_lonely_braces] =
24
+ BRACES['two_line_hash_2_spaces_before_lbrace_lonely_braces'] =
25
25
  %Q{thing1 =
26
26
  thing2 = {
27
27
  :one => 'one'
28
28
  }}
29
29
 
30
- BRACES[:space_in_empty_hash_in_string_in_block] =
30
+ BRACES['space_in_empty_hash_in_string_in_block'] =
31
31
  %Q{[1].map { |n| { :first => "\#{n}-\#{{ }}" } }}
32
32
 
33
- BRACES[:single_line_block_2_spaces_before_lbrace] =
33
+ BRACES['single_line_block_2_spaces_before_lbrace'] =
34
34
  %Q{1..10.times { |n| puts n }}
35
35
 
36
- BRACES[:single_line_block_in_string_interp_2_spaces_before_lbrace] =
36
+ BRACES['single_line_block_in_string_interp_2_spaces_before_lbrace'] =
37
37
  %Q{"I did this \#{1..10.times { |n| puts n }} times."}
38
38
 
39
- BRACES[:single_line_block_0_spaces_before_lbrace] =
39
+ BRACES['single_line_block_0_spaces_before_lbrace'] =
40
40
  %Q{1..10.times{ |n| puts n }}
41
41
 
42
- BRACES[:two_line_braces_block_2_spaces_before_lbrace] =
42
+ BRACES['two_line_braces_block_2_spaces_before_lbrace'] =
43
43
  %Q{1..10.times { |n|
44
44
  puts n}}
45
45
 
46
- BRACES[:two_line_braces_block_0_spaces_before_lbrace_trailing_comment] =
46
+ BRACES['two_line_braces_block_0_spaces_before_lbrace_trailing_comment'] =
47
47
  %Q{1..10.times{ |n| # comment
48
48
  puts n}}
49
49
 
50
- BRACES[:no_space_after_l_before_r_after_string_interp] =
50
+ BRACES['no_space_after_l_before_r_after_string_interp'] =
51
51
  %Q{logger.debug "from \#{current} to \#{new_ver}", {:format => :short}}
52
52
 
53
- BRACES[:no_space_before_consecutive_rbraces] =
53
+ BRACES['no_space_before_consecutive_rbraces'] =
54
54
  %Q{thing = { 'id' => "\#{source}", 'attributes' => { 'height' => "\#{height}"}}}
55
55
 
56
56
  describe "Detection of spacing around braces" do
57
57
  before do
58
58
  Tailor::Logger.stub(:log)
59
59
  FakeFS.activate!
60
- File.open(file_name.to_s, 'w') { |f| f.write contents }
61
- critic.check_file(file_name.to_s, style.to_hash)
60
+ File.open(file_name, 'w') { |f| f.write contents }
61
+ critic.check_file(file_name, style.to_hash)
62
62
  end
63
63
 
64
64
  let(:critic) do
@@ -77,45 +77,45 @@ describe "Detection of spacing around braces" do
77
77
 
78
78
  context "single-line Hash" do
79
79
  context "0 spaces before lbrace" do
80
- let(:file_name) { :single_line_hash_0_spaces_before_lbrace }
81
- specify { critic.problems[file_name.to_s].size.should be 1 }
82
- specify { critic.problems[file_name.to_s].first[:type].should == "spaces_before_lbrace" }
83
- specify { critic.problems[file_name.to_s].first[:line].should be 1 }
84
- specify { critic.problems[file_name.to_s].first[:column].should be 7 }
85
- specify { critic.problems[file_name.to_s].first[:level].should be :error }
80
+ let!(:file_name) { 'single_line_hash_0_spaces_before_lbrace' }
81
+ specify { critic.problems[file_name].size.should be 1 }
82
+ specify { critic.problems[file_name].first[:type].should == "spaces_before_lbrace" }
83
+ specify { critic.problems[file_name].first[:line].should be 1 }
84
+ specify { critic.problems[file_name].first[:column].should be 7 }
85
+ specify { critic.problems[file_name].first[:level].should be :error }
86
86
  end
87
87
 
88
88
  context "2 spaces before lbrace" do
89
- let(:file_name) { :single_line_hash_2_spaces_before_lbrace }
90
- specify { critic.problems[file_name.to_s].size.should be 1 }
91
- specify { critic.problems[file_name.to_s].first[:type].should == "spaces_before_lbrace" }
92
- specify { critic.problems[file_name.to_s].first[:line].should be 1 }
93
- specify { critic.problems[file_name.to_s].first[:column].should be 9 }
94
- specify { critic.problems[file_name.to_s].first[:level].should be :error }
89
+ let!(:file_name) { 'single_line_hash_2_spaces_before_lbrace' }
90
+ specify { critic.problems[file_name].size.should be 1 }
91
+ specify { critic.problems[file_name].first[:type].should == "spaces_before_lbrace" }
92
+ specify { critic.problems[file_name].first[:line].should be 1 }
93
+ specify { critic.problems[file_name].first[:column].should be 9 }
94
+ specify { critic.problems[file_name].first[:level].should be :error }
95
95
  end
96
96
 
97
97
  context "2 spaces after lbrace" do
98
- let(:file_name) { :single_line_hash_2_spaces_after_lbrace }
99
- specify { critic.problems[file_name.to_s].size.should be 1 }
100
- specify { critic.problems[file_name.to_s].first[:type].should == "spaces_after_lbrace" }
101
- specify { critic.problems[file_name.to_s].first[:line].should be 1 }
102
- specify { critic.problems[file_name.to_s].first[:column].should be 9 }
103
- specify { critic.problems[file_name.to_s].first[:level].should be :error }
98
+ let!(:file_name) { 'single_line_hash_2_spaces_after_lbrace' }
99
+ specify { critic.problems[file_name].size.should be 1 }
100
+ specify { critic.problems[file_name].first[:type].should == "spaces_after_lbrace" }
101
+ specify { critic.problems[file_name].first[:line].should be 1 }
102
+ specify { critic.problems[file_name].first[:column].should be 9 }
103
+ specify { critic.problems[file_name].first[:level].should be :error }
104
104
  end
105
105
 
106
106
  context "2 spaces before rbrace" do
107
- let(:file_name) { :single_line_hash_2_spaces_before_rbrace }
108
- specify { critic.problems[file_name.to_s].size.should be 1 }
109
- specify { critic.problems[file_name.to_s].first[:type].should == "spaces_before_rbrace" }
110
- specify { critic.problems[file_name.to_s].first[:line].should be 1 }
111
- specify { critic.problems[file_name.to_s].first[:column].should be 25 }
112
- specify { critic.problems[file_name.to_s].first[:level].should be :error }
107
+ let!(:file_name) { 'single_line_hash_2_spaces_before_rbrace' }
108
+ specify { critic.problems[file_name].size.should be 1 }
109
+ specify { critic.problems[file_name].first[:type].should == "spaces_before_rbrace" }
110
+ specify { critic.problems[file_name].first[:line].should be 1 }
111
+ specify { critic.problems[file_name].first[:column].should be 25 }
112
+ specify { critic.problems[file_name].first[:level].should be :error }
113
113
  end
114
114
  end
115
115
 
116
116
  context "two-line Hash" do
117
117
  context "2 spaces before lbrace" do
118
- let(:file_name) { :two_line_hash_2_spaces_before_lbrace }
118
+ let!(:file_name) { 'two_line_hash_2_spaces_before_lbrace' }
119
119
  specify { critic.problems[file_name.to_s].size.should be 1 }
120
120
  specify { critic.problems[file_name.to_s].first[:type].should == "spaces_before_lbrace" }
121
121
  specify { critic.problems[file_name.to_s].first[:line].should be 2 }
@@ -124,45 +124,45 @@ describe "Detection of spacing around braces" do
124
124
  end
125
125
 
126
126
  context "2 spaces before rbrace" do
127
- let(:file_name) { :two_line_hash_2_spaces_before_rbrace }
128
- specify { critic.problems[file_name.to_s].size.should be 1 }
129
- specify { critic.problems[file_name.to_s].first[:type].should == "spaces_before_rbrace" }
130
- specify { critic.problems[file_name.to_s].first[:line].should be 2 }
131
- specify { critic.problems[file_name.to_s].first[:column].should be 28 }
132
- specify { critic.problems[file_name.to_s].first[:level].should be :error }
127
+ let!(:file_name) { 'two_line_hash_2_spaces_before_rbrace' }
128
+ specify { critic.problems[file_name].size.should be 1 }
129
+ specify { critic.problems[file_name].first[:type].should == "spaces_before_rbrace" }
130
+ specify { critic.problems[file_name].first[:line].should be 2 }
131
+ specify { critic.problems[file_name].first[:column].should be 28 }
132
+ specify { critic.problems[file_name].first[:level].should be :error }
133
133
  end
134
134
 
135
135
  context "2 spaces before lbrace, lonely braces" do
136
- let(:file_name) { :two_line_hash_2_spaces_before_lbrace_lonely_braces }
137
- specify { critic.problems[file_name.to_s].size.should be 1 }
138
- specify { critic.problems[file_name.to_s].first[:type].should == "spaces_before_lbrace" }
139
- specify { critic.problems[file_name.to_s].first[:line].should be 2 }
140
- specify { critic.problems[file_name.to_s].first[:column].should be 12 }
141
- specify { critic.problems[file_name.to_s].first[:level].should be :error }
136
+ let!(:file_name) { 'two_line_hash_2_spaces_before_lbrace_lonely_braces' }
137
+ specify { critic.problems[file_name].size.should be 1 }
138
+ specify { critic.problems[file_name].first[:type].should == "spaces_before_lbrace" }
139
+ specify { critic.problems[file_name].first[:line].should be 2 }
140
+ specify { critic.problems[file_name].first[:column].should be 12 }
141
+ specify { critic.problems[file_name].first[:level].should be :error }
142
142
  end
143
143
  end
144
144
 
145
145
  context "single-line block" do
146
146
  context "space in empty Hash" do
147
- let(:file_name) { :space_in_empty_hash_in_string_in_block }
148
- specify { critic.problems[file_name.to_s].size.should be 1 }
149
- specify { critic.problems[file_name.to_s].first[:type].should == "spaces_in_empty_braces" }
150
- specify { critic.problems[file_name.to_s].first[:line].should be 1 }
151
- specify { critic.problems[file_name.to_s].first[:column].should be 36 }
152
- specify { critic.problems[file_name.to_s].first[:level].should be :error }
147
+ let!(:file_name) { 'space_in_empty_hash_in_string_in_block' }
148
+ specify { critic.problems[file_name].size.should be 1 }
149
+ specify { critic.problems[file_name].first[:type].should == "spaces_in_empty_braces" }
150
+ specify { critic.problems[file_name].first[:line].should be 1 }
151
+ specify { critic.problems[file_name].first[:column].should be 36 }
152
+ specify { critic.problems[file_name].first[:level].should be :error }
153
153
  end
154
154
 
155
155
  context "0 spaces before lbrace" do
156
- let(:file_name) { :single_line_block_0_spaces_before_lbrace }
157
- specify { critic.problems[file_name.to_s].size.should be 1 }
158
- specify { critic.problems[file_name.to_s].first[:type].should == "spaces_before_lbrace" }
159
- specify { critic.problems[file_name.to_s].first[:line].should be 1 }
160
- specify { critic.problems[file_name.to_s].first[:column].should be 11 }
161
- specify { critic.problems[file_name.to_s].first[:level].should be :error }
156
+ let!(:file_name) { 'single_line_block_0_spaces_before_lbrace' }
157
+ specify { critic.problems[file_name].size.should be 1 }
158
+ specify { critic.problems[file_name].first[:type].should == "spaces_before_lbrace" }
159
+ specify { critic.problems[file_name].first[:line].should be 1 }
160
+ specify { critic.problems[file_name].first[:column].should be 11 }
161
+ specify { critic.problems[file_name].first[:level].should be :error }
162
162
  end
163
163
 
164
164
  context "2 spaces before lbrace" do
165
- let(:file_name) { :single_line_block_2_spaces_before_lbrace }
165
+ let!(:file_name) { 'single_line_block_2_spaces_before_lbrace' }
166
166
  specify { critic.problems[file_name.to_s].size.should be 1 }
167
167
  specify { critic.problems[file_name.to_s].first[:type].should == "spaces_before_lbrace" }
168
168
  specify { critic.problems[file_name.to_s].first[:line].should be 1 }
@@ -171,68 +171,68 @@ describe "Detection of spacing around braces" do
171
171
  end
172
172
 
173
173
  context "in String interpolation, 2 spaces before lbrace" do
174
- let(:file_name) { :single_line_block_in_string_interp_2_spaces_before_lbrace }
175
- specify { critic.problems[file_name.to_s].size.should be 1 }
176
- specify { critic.problems[file_name.to_s].first[:type].should == "spaces_before_lbrace" }
177
- specify { critic.problems[file_name.to_s].first[:line].should be 1 }
178
- specify { critic.problems[file_name.to_s].first[:column].should be 27 }
179
- specify { critic.problems[file_name.to_s].first[:level].should be :error }
174
+ let!(:file_name) { 'single_line_block_in_string_interp_2_spaces_before_lbrace' }
175
+ specify { critic.problems[file_name].size.should be 1 }
176
+ specify { critic.problems[file_name].first[:type].should == "spaces_before_lbrace" }
177
+ specify { critic.problems[file_name].first[:line].should be 1 }
178
+ specify { critic.problems[file_name].first[:column].should be 27 }
179
+ specify { critic.problems[file_name].first[:level].should be :error }
180
180
  end
181
181
  end
182
182
 
183
183
  context "multi-line block" do
184
184
  context "2 spaces before lbrace" do
185
- let(:file_name) { :two_line_braces_block_2_spaces_before_lbrace }
186
- specify { critic.problems[file_name.to_s].size.should be 2 }
187
- specify { critic.problems[file_name.to_s].first[:type].should == "spaces_before_lbrace" }
188
- specify { critic.problems[file_name.to_s].first[:line].should be 1 }
189
- specify { critic.problems[file_name.to_s].first[:column].should be 13 }
190
- specify { critic.problems[file_name.to_s].first[:level].should be :error }
191
- specify { critic.problems[file_name.to_s].last[:type].should == "spaces_before_rbrace" }
192
- specify { critic.problems[file_name.to_s].last[:line].should be 2 }
193
- specify { critic.problems[file_name.to_s].last[:column].should be 8 }
194
- specify { critic.problems[file_name.to_s].last[:level].should be :error }
185
+ let!(:file_name) { 'two_line_braces_block_2_spaces_before_lbrace' }
186
+ specify { critic.problems[file_name].size.should be 2 }
187
+ specify { critic.problems[file_name].first[:type].should == "spaces_before_lbrace" }
188
+ specify { critic.problems[file_name].first[:line].should be 1 }
189
+ specify { critic.problems[file_name].first[:column].should be 13 }
190
+ specify { critic.problems[file_name].first[:level].should be :error }
191
+ specify { critic.problems[file_name].last[:type].should == "spaces_before_rbrace" }
192
+ specify { critic.problems[file_name].last[:line].should be 2 }
193
+ specify { critic.problems[file_name].last[:column].should be 8 }
194
+ specify { critic.problems[file_name].last[:level].should be :error }
195
195
  end
196
196
 
197
197
  context "0 spaces before lbrace, with trailing comment" do
198
- let(:file_name) { :two_line_braces_block_0_spaces_before_lbrace_trailing_comment }
199
- specify { critic.problems[file_name.to_s].size.should be 2 }
200
- specify { critic.problems[file_name.to_s].first[:type].should == "spaces_before_lbrace" }
201
- specify { critic.problems[file_name.to_s].first[:line].should be 1 }
202
- specify { critic.problems[file_name.to_s].first[:column].should be 11 }
203
- specify { critic.problems[file_name.to_s].first[:level].should be :error }
204
- specify { critic.problems[file_name.to_s].last[:type].should == "spaces_before_rbrace" }
205
- specify { critic.problems[file_name.to_s].last[:line].should be 2 }
206
- specify { critic.problems[file_name.to_s].last[:column].should be 8 }
207
- specify { critic.problems[file_name.to_s].last[:level].should be :error }
198
+ let!(:file_name) { 'two_line_braces_block_0_spaces_before_lbrace_trailing_comment' }
199
+ specify { critic.problems[file_name].size.should be 2 }
200
+ specify { critic.problems[file_name].first[:type].should == "spaces_before_lbrace" }
201
+ specify { critic.problems[file_name].first[:line].should be 1 }
202
+ specify { critic.problems[file_name].first[:column].should be 11 }
203
+ specify { critic.problems[file_name].first[:level].should be :error }
204
+ specify { critic.problems[file_name].last[:type].should == "spaces_before_rbrace" }
205
+ specify { critic.problems[file_name].last[:line].should be 2 }
206
+ specify { critic.problems[file_name].last[:column].should be 8 }
207
+ specify { critic.problems[file_name].last[:level].should be :error }
208
208
  end
209
209
  end
210
210
 
211
211
  context "String interpolation" do
212
212
  context "0 spaces after lbrace or before rbrace" do
213
- let(:file_name) { :no_space_after_l_before_r_after_string_interp }
214
- specify { critic.problems[file_name.to_s].size.should be 2 }
215
- specify { critic.problems[file_name.to_s].first[:type].should == "spaces_after_lbrace" }
216
- specify { critic.problems[file_name.to_s].first[:line].should be 1 }
217
- specify { critic.problems[file_name.to_s].first[:column].should be 47 }
218
- specify { critic.problems[file_name.to_s].first[:level].should be :error }
219
- specify { critic.problems[file_name.to_s].last[:type].should == "spaces_before_rbrace" }
220
- specify { critic.problems[file_name.to_s].last[:line].should be 1 }
221
- specify { critic.problems[file_name.to_s].last[:column].should be 64 }
222
- specify { critic.problems[file_name.to_s].last[:level].should be :error }
213
+ let!(:file_name) { 'no_space_after_l_before_r_after_string_interp' }
214
+ specify { critic.problems[file_name].size.should be 2 }
215
+ specify { critic.problems[file_name].first[:type].should == "spaces_after_lbrace" }
216
+ specify { critic.problems[file_name].first[:line].should be 1 }
217
+ specify { critic.problems[file_name].first[:column].should be 47 }
218
+ specify { critic.problems[file_name].first[:level].should be :error }
219
+ specify { critic.problems[file_name].last[:type].should == "spaces_before_rbrace" }
220
+ specify { critic.problems[file_name].last[:line].should be 1 }
221
+ specify { critic.problems[file_name].last[:column].should be 64 }
222
+ specify { critic.problems[file_name].last[:level].should be :error }
223
223
  end
224
224
 
225
225
  context "no space before consecutive rbraces" do
226
- let(:file_name) { :no_space_before_consecutive_rbraces }
227
- specify { critic.problems[file_name.to_s].size.should be 2 }
228
- specify { critic.problems[file_name.to_s].first[:type].should == "spaces_before_rbrace" }
229
- specify { critic.problems[file_name.to_s].first[:line].should be 1 }
230
- specify { critic.problems[file_name.to_s].first[:column].should be 72 }
231
- specify { critic.problems[file_name.to_s].first[:level].should be :error }
232
- specify { critic.problems[file_name.to_s].last[:type].should == "spaces_before_rbrace" }
233
- specify { critic.problems[file_name.to_s].last[:line].should be 1 }
234
- specify { critic.problems[file_name.to_s].last[:column].should be 73 }
235
- specify { critic.problems[file_name.to_s].last[:level].should be :error }
226
+ let(:file_name) { 'no_space_before_consecutive_rbraces' }
227
+ specify { critic.problems[file_name].size.should be 2 }
228
+ specify { critic.problems[file_name].first[:type].should == "spaces_before_rbrace" }
229
+ specify { critic.problems[file_name].first[:line].should be 1 }
230
+ specify { critic.problems[file_name].first[:column].should be 72 }
231
+ specify { critic.problems[file_name].first[:level].should be :error }
232
+ specify { critic.problems[file_name].last[:type].should == "spaces_before_rbrace" }
233
+ specify { critic.problems[file_name].last[:line].should be 1 }
234
+ specify { critic.problems[file_name].last[:column].should be 73 }
235
+ specify { critic.problems[file_name].last[:level].should be :error }
236
236
  end
237
237
  end
238
238
  end