tailor 1.0.0.alpha2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. data/.gitignore +1 -0
  2. data/.tailor +10 -2
  3. data/Gemfile.lock +2 -2
  4. data/History.rdoc +20 -0
  5. data/README.rdoc +176 -26
  6. data/features/configurable.feature +19 -39
  7. data/features/horizontal_spacing.feature +3 -2
  8. data/features/indentation.feature +2 -2
  9. data/features/indentation/bad_files_with_no_trailing_newline.feature +9 -8
  10. data/features/indentation/good_files_with_no_trailing_newline.feature +19 -6
  11. data/features/name_detection.feature +2 -2
  12. data/features/support/env.rb +0 -2
  13. data/features/support/file_cases/horizontal_spacing_cases.rb +5 -4
  14. data/features/support/file_cases/indentation_cases.rb +105 -54
  15. data/features/support/file_cases/naming_cases.rb +0 -1
  16. data/features/support/file_cases/vertical_spacing_cases.rb +0 -1
  17. data/features/support/legacy/bad_ternary_colon_spacing.rb +1 -1
  18. data/features/valid_ruby.feature +17 -0
  19. data/features/vertical_spacing.feature +40 -19
  20. data/lib/ext/string_ext.rb +12 -0
  21. data/lib/tailor/cli.rb +7 -5
  22. data/lib/tailor/cli/options.rb +13 -3
  23. data/lib/tailor/composite_observable.rb +17 -2
  24. data/lib/tailor/configuration.rb +83 -72
  25. data/lib/tailor/configuration/style.rb +85 -0
  26. data/lib/tailor/critic.rb +67 -117
  27. data/lib/tailor/formatter.rb +38 -0
  28. data/lib/tailor/formatters/text.rb +35 -10
  29. data/lib/tailor/lexed_line.rb +38 -5
  30. data/lib/tailor/lexer.rb +150 -14
  31. data/lib/tailor/{lexer_constants.rb → lexer/lexer_constants.rb} +9 -7
  32. data/lib/tailor/lexer/token.rb +6 -2
  33. data/lib/tailor/logger.rb +4 -0
  34. data/lib/tailor/problem.rb +8 -73
  35. data/lib/tailor/reporter.rb +1 -1
  36. data/lib/tailor/ruler.rb +67 -6
  37. data/lib/tailor/rulers/allow_camel_case_methods_ruler.rb +9 -1
  38. data/lib/tailor/rulers/allow_hard_tabs_ruler.rb +9 -1
  39. data/lib/tailor/rulers/allow_invalid_ruby_ruler.rb +38 -0
  40. data/lib/tailor/rulers/allow_screaming_snake_case_classes_ruler.rb +9 -2
  41. data/lib/tailor/rulers/allow_trailing_line_spaces_ruler.rb +10 -5
  42. data/lib/tailor/rulers/indentation_spaces_ruler.rb +93 -26
  43. data/lib/tailor/rulers/indentation_spaces_ruler/indentation_manager.rb +128 -84
  44. data/lib/tailor/rulers/max_code_lines_in_class_ruler.rb +9 -5
  45. data/lib/tailor/rulers/max_code_lines_in_method_ruler.rb +9 -5
  46. data/lib/tailor/rulers/max_line_length_ruler.rb +10 -5
  47. data/lib/tailor/rulers/spaces_after_comma_ruler.rb +13 -4
  48. data/lib/tailor/rulers/spaces_after_lbrace_ruler.rb +8 -4
  49. data/lib/tailor/rulers/spaces_after_lbracket_ruler.rb +8 -4
  50. data/lib/tailor/rulers/spaces_after_lparen_ruler.rb +8 -4
  51. data/lib/tailor/rulers/spaces_before_comma_ruler.rb +8 -4
  52. data/lib/tailor/rulers/spaces_before_lbrace_ruler.rb +13 -6
  53. data/lib/tailor/rulers/spaces_before_rbrace_ruler.rb +12 -8
  54. data/lib/tailor/rulers/spaces_before_rbracket_ruler.rb +12 -5
  55. data/lib/tailor/rulers/spaces_before_rparen_ruler.rb +13 -6
  56. data/lib/tailor/rulers/spaces_in_empty_braces_ruler.rb +13 -9
  57. data/lib/tailor/rulers/trailing_newlines_ruler.rb +10 -5
  58. data/lib/tailor/tailorrc.erb +3 -3
  59. data/lib/tailor/version.rb +1 -1
  60. data/m.rb +15 -0
  61. data/spec/spec_helper.rb +0 -1
  62. data/spec/tailor/cli_spec.rb +8 -9
  63. data/spec/tailor/composite_observable_spec.rb +41 -0
  64. data/spec/tailor/configuration/style_spec.rb +197 -0
  65. data/spec/tailor/configuration_spec.rb +52 -33
  66. data/spec/tailor/critic_spec.rb +7 -8
  67. data/spec/tailor/formatter_spec.rb +52 -0
  68. data/spec/tailor/lexed_line_spec.rb +236 -88
  69. data/spec/tailor/lexer_spec.rb +8 -63
  70. data/spec/tailor/problem_spec.rb +14 -46
  71. data/spec/tailor/reporter_spec.rb +8 -8
  72. data/spec/tailor/ruler_spec.rb +1 -1
  73. data/spec/tailor/rulers/indentation_spaces_ruler/indentation_manager_spec.rb +132 -176
  74. data/spec/tailor/rulers/indentation_spaces_ruler_spec.rb +41 -33
  75. data/spec/tailor/rulers/{spaces_after_comma_spec.rb → spaces_after_comma_ruler_spec.rb} +5 -5
  76. data/spec/tailor/rulers/spaces_after_lbrace_ruler_spec.rb +14 -14
  77. data/spec/tailor/rulers/spaces_before_lbrace_ruler_spec.rb +1 -1
  78. data/spec/tailor/rulers/spaces_before_rbrace_ruler_spec.rb +1 -1
  79. data/spec/tailor/version_spec.rb +1 -1
  80. data/spec/tailor_spec.rb +3 -1
  81. data/tailor.gemspec +11 -3
  82. data/uest.rb +9 -0
  83. metadata +66 -41
  84. data/features/step_definitions/spacing/commas_steps.rb +0 -14
@@ -80,9 +80,9 @@
80
80
  # Default: 1
81
81
  #
82
82
  Tailor.config do |config|
83
- config.formatters <%= formatters %>
84
- config.file_set '<%= file_list %>' do
85
- <% style.each do |rule, value| %><%= rule %> <%= value %>
83
+ config.formatters "<%= formatters.join(", ") %>"
84
+ config.file_set '<%= file_list %>' do |style|
85
+ <% style.each do |rule, value| %>style.<%= rule %> = <%= value %>
86
86
  <% end %>
87
87
  end
88
88
  end
@@ -1,3 +1,3 @@
1
1
  class Tailor
2
- VERSION = '1.0.0.alpha2'
2
+ VERSION = '1.0.0'
3
3
  end
data/m.rb ADDED
@@ -0,0 +1,15 @@
1
+ def report_turducken(results, performance_results)
2
+ stuffing[:log_files] = { "#{File.basename @logger.log_file_location}" =>
3
+ File.read(@logger.log_file_location).gsub(/(?<f><)(?<q>\/)?(?<w>\w)/,
4
+ '\k<f>!\k<q>\k<w>') }.merge remote_logs
5
+
6
+ begin
7
+ Stuffer.login(@config[:turducken_server], @config[:turducken_username],
8
+ @config[:turducken_password])
9
+ suite_result_url = Stuffer.stuff(stuffing)
10
+ rescue Errno::ECONNREFUSED
11
+ @logger.error "Unable to connect to Turducken server!"
12
+ end
13
+
14
+ suite_result_url
15
+ end
data/spec/spec_helper.rb CHANGED
@@ -6,4 +6,3 @@ SimpleCov.start
6
6
  RSpec.configure do |conf|
7
7
  conf.include FakeFS::SpecHelpers
8
8
  end
9
-
@@ -8,7 +8,7 @@ describe Tailor::CLI do
8
8
 
9
9
  let(:config) do
10
10
  double "Tailor::Configuration",
11
- file_sets: nil, formatters: nil
11
+ file_sets: nil, formatters: nil, load!: nil
12
12
  end
13
13
 
14
14
  before do
@@ -34,7 +34,7 @@ describe Tailor::CLI do
34
34
 
35
35
  describe "#initialize" do
36
36
  let(:args) { ['last'] }
37
-
37
+
38
38
  it "uses Options to parse the args" do
39
39
  Tailor::Configuration.stub(:new).and_return config
40
40
  Tailor::Critic.stub(:new)
@@ -52,15 +52,14 @@ describe Tailor::CLI do
52
52
 
53
53
  Tailor::CLI.new(args)
54
54
  end
55
-
55
+
56
56
  context "options.show_config is true" do
57
-
57
+
58
58
  end
59
-
59
+
60
60
  context "options.show_config is false" do
61
-
61
+
62
62
  end
63
-
64
63
  end
65
64
 
66
65
  describe "#execute!" do
@@ -73,7 +72,7 @@ describe Tailor::CLI do
73
72
  subject.instance_variable_set(:@critic, critic)
74
73
  subject.instance_variable_set(:@reporter, reporter)
75
74
  end
76
-
75
+
77
76
  after do
78
77
  Tailor::Critic.unstub(:new)
79
78
  Tailor::Reporter.unstub(:new)
@@ -87,7 +86,7 @@ describe Tailor::CLI do
87
86
  critic.stub(:critique).and_yield(problems_for_file, label)
88
87
  reporter.stub(:summary_report)
89
88
  reporter.should_receive(:file_report).with(problems_for_file, label)
90
-
89
+
91
90
  subject.execute!
92
91
  end
93
92
  end
@@ -0,0 +1,41 @@
1
+ require_relative '../spec_helper'
2
+ require 'tailor/composite_observable'
3
+
4
+
5
+ class Tester
6
+ include Tailor::CompositeObservable
7
+ end
8
+
9
+ describe Tailor::CompositeObservable do
10
+ subject { Tester.new }
11
+
12
+ describe ".define_observer" do
13
+ context "observer = 'pants'" do
14
+ before { Tailor::CompositeObservable.define_observer 'pants' }
15
+
16
+ context "observer responds to #pants_update" do
17
+ it "defines an instance method 'add_pants_observer' that takes 1 arg" do
18
+ observer = double "Observer", respond_to?: true
19
+ subject.add_pants_observer(observer)
20
+ end
21
+ end
22
+
23
+ context "observer does not respond to #pants_update" do
24
+ it "defines an instance method 'add_pants_observer' that takes 1 arg" do
25
+ observer = double "Observer", respond_to?: false
26
+ expect { subject.add_pants_observer(observer) }.
27
+ to raise_error NoMethodError
28
+ end
29
+ end
30
+
31
+ it "defines an instance method #notify_pants_observers" do
32
+ expect { subject.notify_pants_observers }.
33
+ to_not raise_error
34
+ end
35
+
36
+ it "defines an instance method #pants_changed" do
37
+ expect { subject.pants_changed }.to_not raise_error
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,197 @@
1
+ require_relative '../../spec_helper'
2
+ require 'tailor/configuration/style'
3
+
4
+
5
+ describe Tailor::Configuration::Style do
6
+ describe ".define_property" do
7
+ it "defines an instance method that takes 2 params" do
8
+ Tailor::Configuration::Style.define_property(:test_method)
9
+ subject.test_method(1, 2)
10
+ end
11
+
12
+ it "allows access to the values via #to_hash" do
13
+ Tailor::Configuration::Style.define_property(:test_method)
14
+ subject.test_method(1, level: :pants)
15
+ subject.to_hash.should include test_method: [1, { level: :pants }]
16
+ end
17
+ end
18
+
19
+ describe "#initialize" do
20
+ describe "sets up default values" do
21
+ describe "allow_camel_case_methods" do
22
+ specify do
23
+ subject.instance_variable_get(:@allow_camel_case_methods).should == [
24
+ false, { level: :error }]
25
+ end
26
+ end
27
+
28
+ describe "allow_hard_tabs" do
29
+ specify do
30
+ subject.instance_variable_get(:@allow_hard_tabs).should == [
31
+ false, { level: :error }]
32
+ end
33
+ end
34
+
35
+ describe "allow_screaming_snake_case_classes" do
36
+ specify do
37
+ subject.instance_variable_get(:@allow_screaming_snake_case_classes).
38
+ should == [false, { level: :error }]
39
+ end
40
+ end
41
+
42
+ describe "allow_trailing_line_spaces" do
43
+ specify do
44
+ subject.instance_variable_get(:@allow_trailing_line_spaces).
45
+ should == [false, { level: :error }]
46
+ end
47
+ end
48
+
49
+ describe "indentation_spaces" do
50
+ specify do
51
+ subject.instance_variable_get(:@indentation_spaces).should == [
52
+ 2, { level: :error }]
53
+ end
54
+ end
55
+
56
+ describe "max_code_lines_in_class" do
57
+ specify do
58
+ subject.instance_variable_get(:@max_code_lines_in_class).should == [
59
+ 300, { level: :error }]
60
+ end
61
+ end
62
+
63
+ describe "max_code_lines_in_method" do
64
+ specify do
65
+ subject.instance_variable_get(:@max_code_lines_in_method).should == [
66
+ 30, { level: :error }]
67
+ end
68
+ end
69
+
70
+ describe "max_line_length" do
71
+ specify do
72
+ subject.instance_variable_get(:@max_line_length).should == [
73
+ 80, { level: :error }]
74
+ end
75
+ end
76
+
77
+ describe "spaces_after_comma" do
78
+ specify do
79
+ subject.instance_variable_get(:@spaces_after_comma).should == [
80
+ 1, { level: :error }]
81
+ end
82
+ end
83
+
84
+ describe "spaces_after_lbrace" do
85
+ specify do
86
+ subject.instance_variable_get(:@spaces_after_lbrace).should == [
87
+ 1, { level: :error }]
88
+ end
89
+ end
90
+
91
+ describe "spaces_after_lbracket" do
92
+ specify do
93
+ subject.instance_variable_get(:@spaces_after_lbracket).should == [
94
+ 0, { level: :error }]
95
+ end
96
+ end
97
+
98
+ describe "spaces_after_lparen" do
99
+ specify do
100
+ subject.instance_variable_get(:@spaces_after_lparen).should == [
101
+ 0, { level: :error }]
102
+ end
103
+ end
104
+
105
+ describe "spaces_before_comma" do
106
+ specify do
107
+ subject.instance_variable_get(:@spaces_before_comma).should == [
108
+ 0, { level: :error }]
109
+ end
110
+ end
111
+
112
+ describe "spaces_before_lbrace" do
113
+ specify do
114
+ subject.instance_variable_get(:@spaces_before_lbrace).should == [
115
+ 1, { level: :error }]
116
+ end
117
+ end
118
+
119
+ describe "spaces_before_rbrace" do
120
+ specify do
121
+ subject.instance_variable_get(:@spaces_before_rbrace).should == [
122
+ 1, { level: :error }]
123
+ end
124
+ end
125
+
126
+ describe "spaces_before_rbracket" do
127
+ specify do
128
+ subject.instance_variable_get(:@spaces_before_rbracket).should == [
129
+ 0, { level: :error }]
130
+ end
131
+ end
132
+
133
+ describe "spaces_before_rparen" do
134
+ specify do
135
+ subject.instance_variable_get(:@spaces_before_rparen).should == [
136
+ 0, { level: :error }]
137
+ end
138
+ end
139
+
140
+ describe "spaces_in_empty_braces" do
141
+ specify do
142
+ subject.instance_variable_get(:@spaces_in_empty_braces).should == [
143
+ 0, { level: :error }]
144
+ end
145
+ end
146
+
147
+ describe "trailing_newlines" do
148
+ specify do
149
+ subject.instance_variable_get(:@trailing_newlines).should == [
150
+ 1, { level: :error }]
151
+ end
152
+ end
153
+ end
154
+ end
155
+
156
+ describe "#to_hash" do
157
+ let(:default_values) do
158
+ {
159
+ :allow_camel_case_methods => [false, { :level => :error }],
160
+ :allow_hard_tabs => [false, { :level => :error }],
161
+ :allow_screaming_snake_case_classes => [false, { :level => :error }],
162
+ :allow_trailing_line_spaces => [false, { :level => :error }],
163
+ :allow_invalid_ruby => [false, { :level => :warn }],
164
+ :indentation_spaces => [2, { :level => :error }],
165
+ :max_code_lines_in_class => [300, { :level => :error }],
166
+ :max_code_lines_in_method => [30, { :level => :error }],
167
+ :max_line_length => [80, { :level => :error }],
168
+ :spaces_after_comma => [1, { :level => :error }],
169
+ :spaces_after_lbrace => [1, { :level => :error }],
170
+ :spaces_after_lbracket => [0, { :level => :error }],
171
+ :spaces_after_lparen => [0, { :level => :error }],
172
+ :spaces_before_comma => [0, { :level => :error }],
173
+ :spaces_before_lbrace => [1, { :level => :error }],
174
+ :spaces_before_rbrace => [1, { :level => :error }],
175
+ :spaces_before_rbracket => [0, { :level => :error }],
176
+ :spaces_before_rparen => [0, { :level => :error }],
177
+ :spaces_in_empty_braces => [0, { :level => :error }],
178
+ :trailing_newlines => [1, { :level => :error }]
179
+ }
180
+ end
181
+
182
+ it "returns a Hash of all of the attributes and values" do
183
+ subject.to_hash.should == default_values
184
+ end
185
+
186
+ context "with a user-added property" do
187
+ before do
188
+ Tailor::Configuration::Style.define_property(:long_pants)
189
+ subject.long_pants(1, level: :warn)
190
+ end
191
+
192
+ it "includes the new property as part of the Hash" do
193
+ subject.to_hash.should include long_pants: [1, { level: :warn }]
194
+ end
195
+ end
196
+ end
197
+ end
@@ -28,35 +28,36 @@ describe Tailor::Configuration do
28
28
  before do
29
29
  subject.instance_variable_set(:@file_sets, {})
30
30
  end
31
-
31
+
32
32
  it "adds the set of stuff to @file_sets" do
33
- subject.file_set(:bobo) do
34
- trailing_newlines 2
33
+ subject.file_set('some_files', :bobo) do |style|
34
+ style.trailing_newlines 2
35
35
  end
36
36
 
37
37
  subject.instance_variable_get(:@file_sets).should == {
38
38
  bobo: {
39
39
  file_list: [],
40
40
  style: {
41
- :allow_camel_case_methods=>false,
42
- :allow_hard_tabs=>false,
43
- :allow_screaming_snake_case_classes=>false,
44
- :allow_trailing_line_spaces=>false,
45
- :indentation_spaces=>2,
46
- :max_code_lines_in_class=>300,
47
- :max_code_lines_in_method=>30,
48
- :max_line_length=>80,
49
- :spaces_after_comma=>1,
50
- :spaces_before_comma=>0,
51
- :spaces_before_lbrace=>1,
52
- :spaces_after_lbrace=>1,
53
- :spaces_before_rbrace=>1,
54
- :spaces_in_empty_braces=>0,
55
- :spaces_after_lbracket=>0,
56
- :spaces_before_rbracket=>0,
57
- :spaces_after_lparen=>0,
58
- :spaces_before_rparen=>0,
59
- :trailing_newlines=>2
41
+ allow_camel_case_methods: [false, { level: :error }],
42
+ allow_hard_tabs: [false, { level: :error }],
43
+ allow_screaming_snake_case_classes: [false, { level: :error }],
44
+ allow_trailing_line_spaces: [false, { level: :error }],
45
+ allow_invalid_ruby: [false, { level: :warn }],
46
+ indentation_spaces: [2, { level: :error }],
47
+ max_code_lines_in_class: [300, { level: :error }],
48
+ max_code_lines_in_method: [30, { level: :error }],
49
+ max_line_length: [80, { level: :error }],
50
+ spaces_after_comma: [1, { level: :error }],
51
+ spaces_after_lbrace: [1, { level: :error }],
52
+ spaces_after_lbracket: [0, { level: :error }],
53
+ spaces_after_lparen: [0, { level: :error }],
54
+ spaces_before_comma: [0, { level: :error }],
55
+ spaces_before_lbrace: [1, { level: :error }],
56
+ spaces_before_rbrace: [1, { level: :error }],
57
+ spaces_before_rbracket: [0, { level: :error }],
58
+ spaces_before_rparen: [0, { level: :error }],
59
+ spaces_in_empty_braces: [0, { level: :error }],
60
+ trailing_newlines: [2, { level: :error }]
60
61
  }
61
62
  }
62
63
  }
@@ -78,16 +79,33 @@ describe Tailor::Configuration do
78
79
  subject.instance_variable_get(:@config_file).should == 'pants'
79
80
  end
80
81
  end
81
-
82
+
82
83
  context "@config_file is nil" do
83
- it "returns DEFAULT_RC_FILE" do
84
- subject.config_file
85
- subject.instance_variable_get(:@config_file).should ==
86
- Tailor::Configuration::DEFAULT_RC_FILE
84
+ context "DEFAULT_PROJECT_CONFIG exists" do
85
+ before do
86
+ File.should_receive(:exists?).with(/\.tailor/).and_return true
87
+ end
88
+
89
+ it "returns Dir.pwd + './tailor'" do
90
+ subject.config_file
91
+ end
92
+ end
93
+
94
+ context "DEFAULT_PROJECT_CONFIG does not exist" do
95
+ before do
96
+ File.should_receive(:exists?).with(/\.tailor/).and_return false
97
+ File.should_receive(:exists?).with(/\.tailorrc/).and_return true
98
+ end
99
+
100
+ it "returns DEFAULT_RC_FILE" do
101
+ subject.config_file
102
+ subject.instance_variable_get(:@config_file).should ==
103
+ Tailor::Configuration::DEFAULT_RC_FILE
104
+ end
87
105
  end
88
106
  end
89
107
  end
90
-
108
+
91
109
  describe "#file_list" do
92
110
  before do
93
111
  FileUtils.mkdir_p 'one/two'
@@ -101,7 +119,7 @@ describe Tailor::Configuration do
101
119
  results.last.should match /one\/two\/three.rb/
102
120
  end
103
121
  end
104
-
122
+
105
123
  context "the Array has a directory" do
106
124
  context "the directory has files" do
107
125
  it "returns all files in the directory" do
@@ -109,7 +127,7 @@ describe Tailor::Configuration do
109
127
  results.last.should match /one\/two\/three.rb/
110
128
  end
111
129
  end
112
-
130
+
113
131
  context "the directory is empty" do
114
132
  before do
115
133
  FileUtils.mkdir 'empty'
@@ -123,7 +141,7 @@ describe Tailor::Configuration do
123
141
  end
124
142
  end
125
143
  end
126
-
144
+
127
145
  context "glob is a glob" do
128
146
  it "returns all files in the glob" do
129
147
  results = subject.file_list('one/**/*.rb')
@@ -137,10 +155,11 @@ describe Tailor::Configuration do
137
155
  results.last.should match /one\/two\/three.rb/
138
156
  end
139
157
  end
140
-
158
+
141
159
  context "glob is a file" do
142
160
  it "returns all files in the glob" do
143
- subject.file_list('one/two/three.rb').last.should match /one\/two\/three.rb/
161
+ subject.file_list('one/two/three.rb').last.
162
+ should match /one\/two\/three.rb/
144
163
  end
145
164
  end
146
165
  end