tailor 1.4.0 → 1.4.1

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 (70) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -3
  3. data/Gemfile.lock +39 -31
  4. data/History.md +220 -207
  5. data/README.md +58 -45
  6. data/features/step_definitions/indentation_steps.rb +1 -1
  7. data/lib/tailor/reporter.rb +19 -7
  8. data/lib/tailor/rulers/spaces_before_lbrace_ruler.rb +0 -1
  9. data/lib/tailor/rulers/spaces_before_rbrace_ruler.rb +0 -1
  10. data/lib/tailor/rulers/spaces_in_empty_braces_ruler.rb +0 -1
  11. data/lib/tailor/version.rb +1 -1
  12. data/spec/functional/conditional_parentheses_spec.rb +1 -1
  13. data/spec/functional/conditional_spacing_spec.rb +1 -1
  14. data/spec/functional/configuration_spec.rb +61 -52
  15. data/spec/functional/horizontal_spacing/braces_spec.rb +134 -134
  16. data/spec/functional/horizontal_spacing/brackets_spec.rb +34 -36
  17. data/spec/functional/horizontal_spacing/comma_spacing_spec.rb +25 -27
  18. data/spec/functional/horizontal_spacing/hard_tabs_spec.rb +42 -42
  19. data/spec/functional/horizontal_spacing/long_lines_spec.rb +15 -17
  20. data/spec/functional/horizontal_spacing/long_methods_spec.rb +4 -4
  21. data/spec/functional/horizontal_spacing/parens_spec.rb +45 -45
  22. data/spec/functional/horizontal_spacing/trailing_whitespace_spec.rb +7 -8
  23. data/spec/functional/horizontal_spacing_spec.rb +10 -11
  24. data/spec/functional/indentation_spacing/argument_alignment_spec.rb +33 -62
  25. data/spec/functional/indentation_spacing/bad_indentation_spec.rb +176 -179
  26. data/spec/functional/indentation_spacing_spec.rb +13 -14
  27. data/spec/functional/naming/camel_case_methods_spec.rb +4 -6
  28. data/spec/functional/naming/screaming_snake_case_classes_spec.rb +28 -31
  29. data/spec/functional/naming_spec.rb +3 -3
  30. data/spec/functional/rake_task_spec.rb +9 -28
  31. data/spec/functional/string_interpolation_spec.rb +1 -1
  32. data/spec/functional/string_quoting_spec.rb +1 -1
  33. data/spec/functional/vertical_spacing/class_length_spec.rb +4 -6
  34. data/spec/functional/vertical_spacing/method_length_spec.rb +15 -17
  35. data/spec/functional/vertical_spacing_spec.rb +3 -3
  36. data/spec/spec_helper.rb +2 -0
  37. data/spec/support/argument_alignment_cases.rb +32 -32
  38. data/spec/support/conditional_parentheses_cases.rb +26 -26
  39. data/spec/support/good_indentation_cases.rb +205 -205
  40. data/spec/support/horizontal_spacing_cases.rb +53 -54
  41. data/spec/support/line_indentation_cases.rb +20 -20
  42. data/spec/support/naming_cases.rb +12 -12
  43. data/spec/support/string_interpolation_cases.rb +17 -17
  44. data/spec/support/string_quoting_cases.rb +12 -12
  45. data/spec/support/vertical_spacing_cases.rb +8 -8
  46. data/spec/unit/tailor/cli/options_spec.rb +20 -14
  47. data/spec/unit/tailor/cli_spec.rb +29 -43
  48. data/spec/unit/tailor/composite_observable_spec.rb +1 -1
  49. data/spec/unit/tailor/configuration/file_set_spec.rb +10 -11
  50. data/spec/unit/tailor/configuration/style_spec.rb +41 -42
  51. data/spec/unit/tailor/configuration_spec.rb +14 -12
  52. data/spec/unit/tailor/formatter_spec.rb +3 -3
  53. data/spec/unit/tailor/formatters/yaml_spec.rb +12 -13
  54. data/spec/unit/tailor/lexed_line_spec.rb +67 -69
  55. data/spec/unit/tailor/lexer/token_spec.rb +7 -7
  56. data/spec/unit/tailor/lexer_spec.rb +24 -24
  57. data/spec/unit/tailor/problem_spec.rb +12 -12
  58. data/spec/unit/tailor/reporter_spec.rb +8 -9
  59. data/spec/unit/tailor/ruler_spec.rb +10 -10
  60. data/spec/unit/tailor/rulers/indentation_spaces_ruler/indentation_manager_spec.rb +90 -86
  61. data/spec/unit/tailor/rulers/indentation_spaces_ruler_spec.rb +13 -13
  62. data/spec/unit/tailor/rulers/spaces_after_comma_ruler_spec.rb +4 -4
  63. data/spec/unit/tailor/rulers/spaces_after_lbrace_ruler_spec.rb +19 -19
  64. data/spec/unit/tailor/rulers/spaces_before_lbrace_ruler_spec.rb +6 -6
  65. data/spec/unit/tailor/rulers/spaces_before_rbrace_ruler_spec.rb +6 -6
  66. data/spec/unit/tailor/rulers_spec.rb +1 -1
  67. data/spec/unit/tailor/version_spec.rb +1 -2
  68. data/spec/unit/tailor_spec.rb +2 -2
  69. data/tailor.gemspec +3 -3
  70. metadata +20 -6
@@ -3,10 +3,9 @@ require_relative '../support/good_indentation_cases'
3
3
  require 'tailor/critic'
4
4
  require 'tailor/configuration/style'
5
5
 
6
-
7
6
  describe 'Indentation spacing problem detection' do
8
7
  before do
9
- Tailor::Logger.stub(:log)
8
+ allow(Tailor::Logger).to receive(:log)
10
9
  FakeFS.activate!
11
10
  end
12
11
 
@@ -30,9 +29,9 @@ describe 'Indentation spacing problem detection' do
30
29
  File.open(file_name, 'w') { |f| f.write contents }
31
30
  end
32
31
 
33
- it 'should be OK' do
32
+ it 'is OK' do
34
33
  critic.check_file(file_name, style.to_hash)
35
- critic.problems.should == { file_name => [] }
34
+ expect(critic.problems).to eq(file_name => [])
36
35
  end
37
36
  end
38
37
 
@@ -40,18 +39,18 @@ describe 'Indentation spacing problem detection' do
40
39
  let(:file_name) { 'case_whens_in' }
41
40
 
42
41
  let(:contents) do
43
- %Q{def my_method
42
+ %(def my_method
44
43
  case true
45
44
  when true
46
45
  puts "stuff"
47
46
  when false
48
47
  puts "blah blah"
49
48
  end
50
- end}
49
+ end)
51
50
  end
52
51
 
53
52
  it 'is OK' do
54
- pending 'Implementation of the option to allow for this'
53
+ skip 'Implementation of the option to allow for this'
55
54
  end
56
55
  end
57
56
 
@@ -59,13 +58,13 @@ end}
59
58
  let(:file_name) { 'method_closing_lonely_paren' }
60
59
 
61
60
  let(:contents) do
62
- %Q{def your_thing(one
61
+ %{def your_thing(one
63
62
  )
64
63
  end}
65
64
  end
66
65
 
67
66
  it 'is OK' do
68
- pending
67
+ skip 'Implementation'
69
68
  end
70
69
  end
71
70
 
@@ -73,14 +72,14 @@ end}
73
72
  let(:file_name) { 'rparen_and_do_same_line' }
74
73
 
75
74
  let(:contents) do
76
- %Q{opt.on('-c', '--config-file FILE',
75
+ %{opt.on('-c', '--config-file FILE',
77
76
  "Use a specific config file.") do |config|
78
77
  options.config_file = config
79
78
  end}
80
79
  end
81
80
 
82
81
  it 'is OK' do
83
- pending
82
+ skip 'Implementation'
84
83
  end
85
84
  end
86
85
 
@@ -88,16 +87,16 @@ end}
88
87
  let(:file_name) { 'block_chain' }
89
88
 
90
89
  let(:contents) do
91
- %Q{{
90
+ %({
92
91
  a: 1
93
92
  }.each do |k, v|
94
93
  puts k, v
95
- end}
94
+ end)
96
95
  end
97
96
 
98
97
  it 'is OK' do
99
98
  critic.check_file(file_name, style.to_hash)
100
- critic.problems.should == { file_name => [] }
99
+ expect(critic.problems).to eq(file_name => [])
101
100
  end
102
101
  end
103
102
  end
@@ -2,17 +2,15 @@ require 'spec_helper'
2
2
  require 'tailor/critic'
3
3
  require 'tailor/configuration/style'
4
4
 
5
-
6
5
  CAMEL_CASE_METHODS = {}
7
6
 
8
7
  CAMEL_CASE_METHODS['one_caps_camel_case_method'] =
9
- %Q{def thingOne
10
- end}
8
+ %(def thingOne
9
+ end)
11
10
 
12
11
  CAMEL_CASE_METHODS['one_caps_camel_case_method_trailing_comment'] =
13
- %Q{def thingOne # comment
14
- end}
15
-
12
+ %(def thingOne # comment
13
+ end)
16
14
 
17
15
  describe 'Detection of camel case methods' do
18
16
  before do
@@ -2,26 +2,23 @@ require 'spec_helper'
2
2
  require 'tailor/critic'
3
3
  require 'tailor/configuration/style'
4
4
 
5
-
6
5
  SCREAMING_SNAKE_CASE_CLASSES = {}
7
6
 
8
7
  SCREAMING_SNAKE_CASE_CLASSES['one_screaming_snake_case_class'] =
9
- %Q{class Thing_One
10
- end}
8
+ %(class Thing_One
9
+ end)
11
10
 
12
11
  SCREAMING_SNAKE_CASE_CLASSES['one_screaming_snake_case_module'] =
13
- %Q{module Thing_One
14
- end}
12
+ %(module Thing_One
13
+ end)
15
14
 
16
15
  SCREAMING_SNAKE_CASE_CLASSES['double_screaming_snake_case_class'] =
17
- %Q{class Thing_One_Again
18
- end}
16
+ %(class Thing_One_Again
17
+ end)
19
18
 
20
19
  SCREAMING_SNAKE_CASE_CLASSES['double_screaming_snake_case_module'] =
21
- %Q{module Thing_One_Again
22
- end}
23
-
24
-
20
+ %(module Thing_One_Again
21
+ end)
25
22
 
26
23
  describe 'Detection of camel case methods' do
27
24
  before do
@@ -47,37 +44,37 @@ describe 'Detection of camel case methods' do
47
44
 
48
45
  context 'standard screaming snake case class' do
49
46
  let(:file_name) { 'one_screaming_snake_case_class' }
50
- specify { critic.problems[file_name].size.should be 1 }
51
- specify { critic.problems[file_name].first[:type].should == 'allow_screaming_snake_case_classes' }
52
- specify { critic.problems[file_name].first[:line].should be 1 }
53
- specify { critic.problems[file_name].first[:column].should be 6 }
54
- specify { critic.problems[file_name].first[:level].should be :error }
47
+ specify { expect(critic.problems[file_name].size).to eq 1 }
48
+ specify { expect(critic.problems[file_name].first[:type]).to eq 'allow_screaming_snake_case_classes' }
49
+ specify { expect(critic.problems[file_name].first[:line]).to eq 1 }
50
+ specify { expect(critic.problems[file_name].first[:column]).to eq 6 }
51
+ specify { expect(critic.problems[file_name].first[:level]).to eq :error }
55
52
  end
56
53
 
57
54
  context 'standard screaming snake case module' do
58
55
  let(:file_name) { 'one_screaming_snake_case_module' }
59
- specify { critic.problems[file_name].size.should be 1 }
60
- specify { critic.problems[file_name].first[:type].should == 'allow_screaming_snake_case_classes' }
61
- specify { critic.problems[file_name].first[:line].should be 1 }
62
- specify { critic.problems[file_name].first[:column].should be 7 }
63
- specify { critic.problems[file_name].first[:level].should be :error }
56
+ specify { expect(critic.problems[file_name].size).to eq 1 }
57
+ specify { expect(critic.problems[file_name].first[:type]).to eq 'allow_screaming_snake_case_classes' }
58
+ specify { expect(critic.problems[file_name].first[:line]).to eq 1 }
59
+ specify { expect(critic.problems[file_name].first[:column]).to eq 7 }
60
+ specify { expect(critic.problems[file_name].first[:level]).to eq :error }
64
61
  end
65
62
 
66
63
  context 'double screaming snake case class' do
67
64
  let(:file_name) { 'double_screaming_snake_case_class' }
68
- specify { critic.problems[file_name].size.should be 1 }
69
- specify { critic.problems[file_name].first[:type].should == 'allow_screaming_snake_case_classes' }
70
- specify { critic.problems[file_name].first[:line].should be 1 }
71
- specify { critic.problems[file_name].first[:column].should be 6 }
72
- specify { critic.problems[file_name].first[:level].should be :error }
65
+ specify { expect(critic.problems[file_name].size).to eq 1 }
66
+ specify { expect(critic.problems[file_name].first[:type]).to eq 'allow_screaming_snake_case_classes' }
67
+ specify { expect(critic.problems[file_name].first[:line]).to eq 1 }
68
+ specify { expect(critic.problems[file_name].first[:column]).to eq 6 }
69
+ specify { expect(critic.problems[file_name].first[:level]).to eq :error }
73
70
  end
74
71
 
75
72
  context 'double screaming snake case module' do
76
73
  let(:file_name) { 'double_screaming_snake_case_module' }
77
- specify { critic.problems[file_name].size.should be 1 }
78
- specify { critic.problems[file_name].first[:type].should == 'allow_screaming_snake_case_classes' }
79
- specify { critic.problems[file_name].first[:line].should be 1 }
80
- specify { critic.problems[file_name].first[:column].should be 7 }
81
- specify { critic.problems[file_name].first[:level].should be :error }
74
+ specify { expect(critic.problems[file_name].size).to eq 1 }
75
+ specify { expect(critic.problems[file_name].first[:type]).to eq 'allow_screaming_snake_case_classes' }
76
+ specify { expect(critic.problems[file_name].first[:line]).to eq 1 }
77
+ specify { expect(critic.problems[file_name].first[:column]).to eq 7 }
78
+ specify { expect(critic.problems[file_name].first[:level]).to eq :error }
82
79
  end
83
80
  end
@@ -6,7 +6,7 @@ require 'tailor/configuration/style'
6
6
 
7
7
  describe 'Naming problem detection' do
8
8
  before do
9
- Tailor::Logger.stub(:log)
9
+ allow(Tailor::Logger).to receive(:log)
10
10
  FakeFS.activate!
11
11
  end
12
12
 
@@ -28,9 +28,9 @@ describe 'Naming problem detection' do
28
28
  File.open(file_name, 'w') { |f| f.write contents }
29
29
  end
30
30
 
31
- it 'should be OK' do
31
+ it 'is OK' do
32
32
  critic.check_file(file_name, style.to_hash)
33
- critic.problems.should == { file_name => [] }
33
+ expect(critic.problems).to eq(file_name => [])
34
34
  end
35
35
  end
36
36
  end
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
  require 'tailor/rake_task'
3
3
 
4
-
5
4
  describe Tailor::RakeTask do
6
5
  let(:rake) do
7
6
  Rake::Application.new
@@ -22,10 +21,7 @@ describe Tailor::RakeTask do
22
21
 
23
22
  it 'finds problems' do
24
23
  subject
25
-
26
- expect {
27
- rake['tailor'].invoke
28
- }.to raise_error SystemExit
24
+ expect { rake['tailor'].invoke }.to raise_error SystemExit
29
25
  end
30
26
  end
31
27
 
@@ -38,10 +34,7 @@ describe Tailor::RakeTask do
38
34
 
39
35
  it 'does not find problems' do
40
36
  subject
41
-
42
- expect {
43
- rake['tailor'].invoke
44
- }.to_not raise_error
37
+ expect { rake['tailor'].invoke }.to_not raise_error
45
38
  end
46
39
  end
47
40
  end
@@ -57,10 +50,7 @@ describe Tailor::RakeTask do
57
50
 
58
51
  it 'runs the task' do
59
52
  subject
60
-
61
- expect {
62
- rake[task_name].invoke
63
- }.to_not raise_error RuntimeError, "Don't know how to build task '#{task_name}''"
53
+ expect { rake[task_name].invoke }.to raise_exception SystemExit
64
54
  end
65
55
  end
66
56
 
@@ -68,16 +58,13 @@ describe Tailor::RakeTask do
68
58
  subject do
69
59
  Tailor::RakeTask.new do |t|
70
60
  t.config_file = File.expand_path 'spec/support/rake_task_config_problems.rb'
71
- t.tailor_opts = %w[--max-line-length=1000]
61
+ t.tailor_opts = %w(--max-line-length=1000)
72
62
  end
73
63
  end
74
64
 
75
65
  it 'uses the options from the rake task' do
76
66
  subject
77
-
78
- expect {
79
- rake['tailor'].invoke
80
- }.to_not raise_error
67
+ expect { rake['tailor'].invoke }.to_not raise_error
81
68
  end
82
69
  end
83
70
 
@@ -89,11 +76,8 @@ describe Tailor::RakeTask do
89
76
  before do
90
77
  require 'fileutils'
91
78
 
92
- unless File.exists?(test_dir)
93
- FileUtils.mkdir(test_dir)
94
- end
95
-
96
- File.directory?(test_dir).should be_true
79
+ FileUtils.mkdir(test_dir) unless File.exist?(test_dir)
80
+ expect(File.directory?(test_dir)).to eq true
97
81
 
98
82
  File.open(test_dir + '/test.rb', 'w') do |f|
99
83
  f.write <<-CONTENTS
@@ -101,7 +85,7 @@ puts 'I no have end quote
101
85
  CONTENTS
102
86
  end
103
87
 
104
- File.exists?(test_dir + '/test.rb').should be_true
88
+ expect(File.exist?(test_dir + '/test.rb')).to eq true
105
89
  end
106
90
 
107
91
  after do
@@ -120,10 +104,7 @@ puts 'I no have end quote
120
104
 
121
105
  it 'uses the options from the rake task' do
122
106
  subject
123
-
124
- expect {
125
- rake['tailor'].invoke
126
- }.to raise_error
107
+ expect { rake['tailor'].invoke }.to raise_error
127
108
  end
128
109
  end
129
110
  end
@@ -15,7 +15,7 @@ describe 'String interpolation cases' do
15
15
  end
16
16
 
17
17
  before do
18
- Tailor::Logger.stub(:log)
18
+ allow(Tailor::Logger).to receive(:log)
19
19
  FakeFS.activate!
20
20
  FileUtils.touch file_name
21
21
  File.open(file_name, 'w') { |f| f.write contents }
@@ -16,7 +16,7 @@ describe 'String Quoting' do
16
16
  end
17
17
 
18
18
  before do
19
- Tailor::Logger.stub(:log)
19
+ allow(Tailor::Logger).to receive(:log)
20
20
  FakeFS.activate!
21
21
  FileUtils.touch file_name
22
22
  File.open(file_name, 'w') { |f| f.write contents }
@@ -2,27 +2,25 @@ require 'spec_helper'
2
2
  require 'tailor/critic'
3
3
  require 'tailor/configuration/style'
4
4
 
5
-
6
5
  CLASS_LENGTH = {}
7
6
  CLASS_LENGTH['class_too_long'] =
8
- %Q{class Party
7
+ %(class Party
9
8
  include Clowns
10
9
  include Pizza
11
10
 
12
11
  def barrel_roll
13
12
  puts 'DOABARRELROLL!'
14
13
  end
15
- end}
14
+ end)
16
15
 
17
16
  CLASS_LENGTH['parent_class_too_long'] =
18
- %Q{class Party
17
+ %(class Party
19
18
 
20
19
  class Pizza
21
20
  include Cheese
22
21
  include Yumminess
23
22
  end
24
- end}
25
-
23
+ end)
26
24
 
27
25
  describe 'Detection of class length' do
28
26
  before do
@@ -2,25 +2,23 @@ require 'spec_helper'
2
2
  require 'tailor/critic'
3
3
  require 'tailor/configuration/style'
4
4
 
5
-
6
5
  METHOD_LENGTH = {}
7
6
  METHOD_LENGTH['method_too_long'] =
8
- %Q{def thing
7
+ %(def thing
9
8
  puts
10
9
  puts
11
- end}
10
+ end)
12
11
 
13
12
  METHOD_LENGTH['parent_method_too_long'] =
14
- %Q{def thing
13
+ %(def thing
15
14
  puts
16
15
  def inner_thing; print '1'; end
17
16
  puts
18
- end}
19
-
17
+ end)
20
18
 
21
19
  describe 'Detection of method length' do
22
20
  before do
23
- Tailor::Logger.stub(:log)
21
+ allow(Tailor::Logger).to receive(:log)
24
22
  FakeFS.activate!
25
23
  File.open(file_name, 'w') { |f| f.write contents }
26
24
  critic.check_file(file_name, style.to_hash)
@@ -43,19 +41,19 @@ describe 'Detection of method length' do
43
41
 
44
42
  context 'single class too long' do
45
43
  let(:file_name) { 'method_too_long' }
46
- specify { critic.problems[file_name].size.should be 1 }
47
- specify { critic.problems[file_name].first[:type].should == 'max_code_lines_in_method' }
48
- specify { critic.problems[file_name].first[:line].should be 1 }
49
- specify { critic.problems[file_name].first[:column].should be 0 }
50
- specify { critic.problems[file_name].first[:level].should be :error }
44
+ specify { expect(critic.problems[file_name].size).to eq 1 }
45
+ specify { expect(critic.problems[file_name].first[:type]).to eq 'max_code_lines_in_method' }
46
+ specify { expect(critic.problems[file_name].first[:line]).to eq 1 }
47
+ specify { expect(critic.problems[file_name].first[:column]).to eq 0 }
48
+ specify { expect(critic.problems[file_name].first[:level]).to eq :error }
51
49
  end
52
50
 
53
51
  context 'method in a method' do
54
52
  let(:file_name) { 'method_too_long' }
55
- specify { critic.problems[file_name].size.should be 1 }
56
- specify { critic.problems[file_name].first[:type].should == 'max_code_lines_in_method' }
57
- specify { critic.problems[file_name].first[:line].should be 1 }
58
- specify { critic.problems[file_name].first[:column].should be 0 }
59
- specify { critic.problems[file_name].first[:level].should be :error }
53
+ specify { expect(critic.problems[file_name].size).to eq 1 }
54
+ specify { expect(critic.problems[file_name].first[:type]).to eq 'max_code_lines_in_method' }
55
+ specify { expect(critic.problems[file_name].first[:line]).to eq 1 }
56
+ specify { expect(critic.problems[file_name].first[:column]).to eq 0 }
57
+ specify { expect(critic.problems[file_name].first[:level]).to eq :error }
60
58
  end
61
59
  end
@@ -6,7 +6,7 @@ require 'tailor/configuration/style'
6
6
 
7
7
  describe 'Vertical Space problem detection' do
8
8
  before do
9
- Tailor::Logger.stub(:log)
9
+ allow(Tailor::Logger).to receive(:log)
10
10
  FakeFS.activate!
11
11
  end
12
12
 
@@ -28,9 +28,9 @@ describe 'Vertical Space problem detection' do
28
28
  File.open(file_name, 'w') { |f| f.write contents }
29
29
  end
30
30
 
31
- it 'should be OK' do
31
+ it 'is OK' do
32
32
  critic.check_file(file_name, style.to_hash)
33
- critic.problems.should == { file_name => [] }
33
+ expect(critic.problems).to eq(file_name => [])
34
34
  end
35
35
  end
36
36
  end