rails_best_practices 1.19.2 → 1.20.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (149) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +0 -1
  3. data/.travis.yml +2 -3
  4. data/CHANGELOG.md +7 -7
  5. data/Gemfile +3 -5
  6. data/Gemfile.lock +125 -0
  7. data/Guardfile +2 -0
  8. data/README.md +6 -6
  9. data/Rakefile +2 -17
  10. data/assets/result.html.erb +2 -0
  11. data/lib/rails_best_practices.rb +3 -2
  12. data/lib/rails_best_practices/analyzer.rb +61 -49
  13. data/lib/rails_best_practices/cli.rb +22 -0
  14. data/lib/rails_best_practices/command.rb +1 -131
  15. data/lib/rails_best_practices/core/check.rb +64 -56
  16. data/lib/rails_best_practices/core/checks_loader.rb +24 -23
  17. data/lib/rails_best_practices/core/configs.rb +1 -2
  18. data/lib/rails_best_practices/core/controllers.rb +1 -2
  19. data/lib/rails_best_practices/core/error.rb +1 -1
  20. data/lib/rails_best_practices/core/helpers.rb +1 -2
  21. data/lib/rails_best_practices/core/mailers.rb +1 -2
  22. data/lib/rails_best_practices/core/methods.rb +27 -21
  23. data/lib/rails_best_practices/core/model_associations.rb +10 -5
  24. data/lib/rails_best_practices/core/models.rb +1 -2
  25. data/lib/rails_best_practices/core/modules.rb +1 -1
  26. data/lib/rails_best_practices/core/routes.rb +2 -2
  27. data/lib/rails_best_practices/core/runner.rb +67 -73
  28. data/lib/rails_best_practices/lexicals/long_line_check.rb +7 -3
  29. data/lib/rails_best_practices/option_parser.rb +156 -0
  30. data/lib/rails_best_practices/prepares.rb +1 -1
  31. data/lib/rails_best_practices/prepares/controller_prepare.rb +24 -17
  32. data/lib/rails_best_practices/prepares/gemfile_prepare.rb +2 -2
  33. data/lib/rails_best_practices/prepares/helper_prepare.rb +6 -1
  34. data/lib/rails_best_practices/prepares/initializer_prepare.rb +3 -3
  35. data/lib/rails_best_practices/prepares/mailer_prepare.rb +2 -1
  36. data/lib/rails_best_practices/prepares/model_prepare.rb +63 -23
  37. data/lib/rails_best_practices/prepares/route_prepare.rb +28 -21
  38. data/lib/rails_best_practices/prepares/schema_prepare.rb +1 -1
  39. data/lib/rails_best_practices/reviews/add_model_virtual_attribute_review.rb +38 -34
  40. data/lib/rails_best_practices/reviews/always_add_db_index_review.rb +94 -89
  41. data/lib/rails_best_practices/reviews/check_destroy_return_value_review.rb +15 -5
  42. data/lib/rails_best_practices/reviews/check_save_return_value_review.rb +20 -8
  43. data/lib/rails_best_practices/reviews/default_scope_is_evil_review.rb +1 -1
  44. data/lib/rails_best_practices/reviews/dry_bundler_in_capistrano_review.rb +1 -1
  45. data/lib/rails_best_practices/reviews/hash_syntax_review.rb +16 -16
  46. data/lib/rails_best_practices/reviews/isolate_seed_data_review.rb +12 -12
  47. data/lib/rails_best_practices/reviews/keep_finders_on_their_own_model_review.rb +10 -11
  48. data/lib/rails_best_practices/reviews/law_of_demeter_review.rb +25 -24
  49. data/lib/rails_best_practices/reviews/move_code_into_controller_review.rb +4 -4
  50. data/lib/rails_best_practices/reviews/move_code_into_helper_review.rb +9 -10
  51. data/lib/rails_best_practices/reviews/move_finder_to_named_scope_review.rb +10 -11
  52. data/lib/rails_best_practices/reviews/needless_deep_nesting_review.rb +24 -22
  53. data/lib/rails_best_practices/reviews/not_rescue_exception_review.rb +1 -1
  54. data/lib/rails_best_practices/reviews/not_use_default_route_review.rb +1 -2
  55. data/lib/rails_best_practices/reviews/not_use_time_ago_in_words_review.rb +1 -1
  56. data/lib/rails_best_practices/reviews/overuse_route_customizations_review.rb +8 -8
  57. data/lib/rails_best_practices/reviews/protect_mass_assignment_review.rb +35 -32
  58. data/lib/rails_best_practices/reviews/remove_empty_helpers_review.rb +4 -4
  59. data/lib/rails_best_practices/reviews/remove_unused_methods_in_controllers_review.rb +26 -19
  60. data/lib/rails_best_practices/reviews/remove_unused_methods_in_helpers_review.rb +12 -10
  61. data/lib/rails_best_practices/reviews/remove_unused_methods_in_models_review.rb +38 -18
  62. data/lib/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review.rb +11 -11
  63. data/lib/rails_best_practices/reviews/restrict_auto_generated_routes_review.rb +77 -74
  64. data/lib/rails_best_practices/reviews/review.rb +2 -1
  65. data/lib/rails_best_practices/reviews/simplify_render_in_controllers_review.rb +2 -3
  66. data/lib/rails_best_practices/reviews/simplify_render_in_views_review.rb +12 -12
  67. data/lib/rails_best_practices/reviews/use_before_filter_review.rb +18 -15
  68. data/lib/rails_best_practices/reviews/use_model_association_review.rb +15 -15
  69. data/lib/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review.rb +24 -22
  70. data/lib/rails_best_practices/reviews/use_observer_review.rb +28 -28
  71. data/lib/rails_best_practices/reviews/use_parentheses_in_method_def_review.rb +6 -6
  72. data/lib/rails_best_practices/reviews/use_query_attribute_review.rb +68 -66
  73. data/lib/rails_best_practices/reviews/use_say_with_time_in_migrations_review.rb +9 -8
  74. data/lib/rails_best_practices/reviews/use_scope_access_review.rb +16 -14
  75. data/lib/rails_best_practices/reviews/use_turbo_sprockets_rails3_review.rb +2 -1
  76. data/lib/rails_best_practices/version.rb +1 -1
  77. data/rails_best_practices.gemspec +38 -43
  78. data/spec/fixtures/lib/rails_best_practices/plugins/reviews/not_use_rails_root_review.rb +1 -2
  79. data/spec/rails_best_practices/analyzer_spec.rb +73 -42
  80. data/spec/rails_best_practices/core/check_spec.rb +5 -5
  81. data/spec/rails_best_practices/core/checks_loader_spec.rb +3 -3
  82. data/spec/rails_best_practices/core/configs_spec.rb +1 -1
  83. data/spec/rails_best_practices/core/controllers_spec.rb +1 -1
  84. data/spec/rails_best_practices/core/error_spec.rb +21 -18
  85. data/spec/rails_best_practices/core/except_methods_spec.rb +7 -7
  86. data/spec/rails_best_practices/core/gems_spec.rb +4 -4
  87. data/spec/rails_best_practices/core/helpers_spec.rb +1 -1
  88. data/spec/rails_best_practices/core/klasses_spec.rb +3 -3
  89. data/spec/rails_best_practices/core/mailers_spec.rb +1 -1
  90. data/spec/rails_best_practices/core/methods_spec.rb +6 -6
  91. data/spec/rails_best_practices/core/model_associations_spec.rb +10 -6
  92. data/spec/rails_best_practices/core/model_attributes_spec.rb +4 -4
  93. data/spec/rails_best_practices/core/models_spec.rb +1 -1
  94. data/spec/rails_best_practices/core/modules_spec.rb +5 -5
  95. data/spec/rails_best_practices/core/routes_spec.rb +5 -5
  96. data/spec/rails_best_practices/core/runner_spec.rb +9 -7
  97. data/spec/rails_best_practices/core_ext/erubis_spec.rb +10 -10
  98. data/spec/rails_best_practices/lexicals/long_line_check_spec.rb +32 -31
  99. data/spec/rails_best_practices/lexicals/remove_tab_check_spec.rb +6 -6
  100. data/spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb +6 -6
  101. data/spec/rails_best_practices/prepares/config_prepare_spec.rb +2 -2
  102. data/spec/rails_best_practices/prepares/controller_prepare_spec.rb +18 -10
  103. data/spec/rails_best_practices/prepares/gemfile_prepare_spec.rb +17 -17
  104. data/spec/rails_best_practices/prepares/helper_prepare_spec.rb +3 -3
  105. data/spec/rails_best_practices/prepares/initializer_prepare_spec.rb +3 -3
  106. data/spec/rails_best_practices/prepares/mailer_prepare_spec.rb +2 -2
  107. data/spec/rails_best_practices/prepares/model_prepare_spec.rb +79 -43
  108. data/spec/rails_best_practices/prepares/route_prepare_spec.rb +141 -76
  109. data/spec/rails_best_practices/prepares/schema_prepare_spec.rb +2 -2
  110. data/spec/rails_best_practices/reviews/add_model_virtual_attribute_review_spec.rb +18 -12
  111. data/spec/rails_best_practices/reviews/always_add_db_index_review_spec.rb +28 -22
  112. data/spec/rails_best_practices/reviews/check_destroy_return_value_review_spec.rb +15 -13
  113. data/spec/rails_best_practices/reviews/check_save_return_value_review_spec.rb +31 -21
  114. data/spec/rails_best_practices/reviews/default_scope_is_evil_review_spec.rb +6 -6
  115. data/spec/rails_best_practices/reviews/dry_bundler_in_capistrano_review_spec.rb +5 -5
  116. data/spec/rails_best_practices/reviews/hash_syntax_review_spec.rb +13 -13
  117. data/spec/rails_best_practices/reviews/isolate_seed_data_review_spec.rb +7 -7
  118. data/spec/rails_best_practices/reviews/keep_finders_on_their_own_model_review_spec.rb +9 -9
  119. data/spec/rails_best_practices/reviews/law_of_demeter_review_spec.rb +29 -22
  120. data/spec/rails_best_practices/reviews/move_code_into_controller_review_spec.rb +6 -6
  121. data/spec/rails_best_practices/reviews/move_code_into_helper_review_spec.rb +11 -6
  122. data/spec/rails_best_practices/reviews/move_code_into_model_review_spec.rb +32 -22
  123. data/spec/rails_best_practices/reviews/move_finder_to_named_scope_review_spec.rb +7 -7
  124. data/spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb +9 -7
  125. data/spec/rails_best_practices/reviews/needless_deep_nesting_review_spec.rb +9 -9
  126. data/spec/rails_best_practices/reviews/not_rescue_exception_review_spec.rb +9 -9
  127. data/spec/rails_best_practices/reviews/not_use_default_route_review_spec.rb +5 -5
  128. data/spec/rails_best_practices/reviews/not_use_time_ago_in_words_review_spec.rb +7 -7
  129. data/spec/rails_best_practices/reviews/overuse_route_customizations_review_spec.rb +7 -7
  130. data/spec/rails_best_practices/reviews/protect_mass_assignment_review_spec.rb +24 -17
  131. data/spec/rails_best_practices/reviews/remove_empty_helpers_review_spec.rb +6 -6
  132. data/spec/rails_best_practices/reviews/remove_unused_methods_in_controllers_review_spec.rb +64 -31
  133. data/spec/rails_best_practices/reviews/remove_unused_methods_in_helpers_review_spec.rb +21 -14
  134. data/spec/rails_best_practices/reviews/remove_unused_methods_in_models_review_spec.rb +57 -53
  135. data/spec/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review_spec.rb +10 -8
  136. data/spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb +20 -14
  137. data/spec/rails_best_practices/reviews/restrict_auto_generated_routes_review_spec.rb +54 -31
  138. data/spec/rails_best_practices/reviews/simplify_render_in_controllers_review_spec.rb +9 -9
  139. data/spec/rails_best_practices/reviews/simplify_render_in_views_review_spec.rb +13 -13
  140. data/spec/rails_best_practices/reviews/use_before_filter_review_spec.rb +11 -9
  141. data/spec/rails_best_practices/reviews/use_model_association_review_spec.rb +7 -7
  142. data/spec/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review_spec.rb +35 -31
  143. data/spec/rails_best_practices/reviews/use_observer_review_spec.rb +6 -6
  144. data/spec/rails_best_practices/reviews/use_parentheses_in_method_def_review_spec.rb +10 -8
  145. data/spec/rails_best_practices/reviews/use_query_attribute_review_spec.rb +31 -24
  146. data/spec/rails_best_practices/reviews/use_say_with_time_in_migrations_review_spec.rb +15 -11
  147. data/spec/rails_best_practices/reviews/use_scope_access_review_spec.rb +14 -14
  148. data/spec/rails_best_practices/reviews/use_turbo_sprockets_rails3_review_spec.rb +61 -59
  149. metadata +16 -18
@@ -5,8 +5,7 @@ require 'rails_best_practices/reviews/review'
5
5
  module RailsBestPractices
6
6
  module Plugins
7
7
  module Reviews
8
- class NotUseRailsRootReview < RailsBestPractices::Reviews::Review
9
- end
8
+ class NotUseRailsRootReview < RailsBestPractices::Reviews::Review; end
10
9
  end
11
10
  end
12
11
  end
@@ -5,39 +5,70 @@ require 'tmpdir'
5
5
 
6
6
  module RailsBestPractices
7
7
  describe Analyzer do
8
- subject { Analyzer.new('.') }
8
+ subject { described_class.new('.') }
9
9
 
10
10
  describe '::new' do
11
- it 'should expand a relative path to an absolute' do
11
+ it 'expands a relative path to an absolute' do
12
12
  expect(subject.path).to eq File.expand_path('.')
13
13
  end
14
14
  end
15
15
 
16
16
  describe 'expand_dirs_to_files' do
17
- it 'should expand all files in spec directory' do
17
+ it 'expands all files in spec directory' do
18
18
  dir = File.dirname(__FILE__)
19
19
  expect(subject.expand_dirs_to_files(dir)).to be_include(dir + '/analyzer_spec.rb')
20
20
  end
21
21
  end
22
22
 
23
23
  describe 'file_sort' do
24
- it 'should get models first, mailers, helpers and then others' do
25
- files = ['app/controllers/users_controller.rb', 'app/mailers/user_mailer.rb', 'app/helpers/users_helper.rb', 'app/models/user.rb', 'app/views/users/index.html.haml', 'app/views/users/show.html.slim', 'lib/user.rb']
26
- expect(subject.file_sort(files)).to eq(['app/models/user.rb', 'app/mailers/user_mailer.rb', 'app/helpers/users_helper.rb', 'app/controllers/users_controller.rb', 'app/views/users/index.html.haml', 'app/views/users/show.html.slim', 'lib/user.rb'])
24
+ it 'gets models first, mailers, helpers and then others' do
25
+ files = [
26
+ 'app/controllers/users_controller.rb',
27
+ 'app/mailers/user_mailer.rb',
28
+ 'app/helpers/users_helper.rb',
29
+ 'app/models/user.rb',
30
+ 'app/views/users/index.html.haml',
31
+ 'app/views/users/show.html.slim',
32
+ 'lib/user.rb'
33
+ ]
34
+ expect(subject.file_sort(files)).to eq(
35
+ [
36
+ 'app/models/user.rb',
37
+ 'app/mailers/user_mailer.rb',
38
+ 'app/helpers/users_helper.rb',
39
+ 'app/controllers/users_controller.rb',
40
+ 'app/views/users/index.html.haml',
41
+ 'app/views/users/show.html.slim',
42
+ 'lib/user.rb'
43
+ ]
44
+ )
27
45
  end
28
46
  end
29
47
 
30
48
  describe 'file_ignore' do
31
49
  before do
32
- @all = ['app/controllers/users_controller.rb', 'app/mailers/user_mailer.rb', 'app/models/user.rb', 'app/views/users/index.html.haml', 'app/views/users/show.html.slim', 'lib/user.rb']
33
- @filtered = ['app/controllers/users_controller.rb', 'app/mailers/user_mailer.rb', 'app/models/user.rb', 'app/views/users/index.html.haml', 'app/views/users/show.html.slim']
34
- end
35
-
36
- it 'should ignore lib' do
50
+ @all = [
51
+ 'app/controllers/users_controller.rb',
52
+ 'app/mailers/user_mailer.rb',
53
+ 'app/models/user.rb',
54
+ 'app/views/users/index.html.haml',
55
+ 'app/views/users/show.html.slim',
56
+ 'lib/user.rb'
57
+ ]
58
+ @filtered = [
59
+ 'app/controllers/users_controller.rb',
60
+ 'app/mailers/user_mailer.rb',
61
+ 'app/models/user.rb',
62
+ 'app/views/users/index.html.haml',
63
+ 'app/views/users/show.html.slim'
64
+ ]
65
+ end
66
+
67
+ it 'ignores lib' do
37
68
  expect(subject.file_ignore(@all, 'lib/')).to eq(@filtered)
38
69
  end
39
70
 
40
- it 'should ignore regexp patterns' do
71
+ it 'ignores regexp patterns' do
41
72
  expect(subject.file_ignore(@all, /lib/)).to eq(@filtered)
42
73
  end
43
74
  end
@@ -88,7 +119,7 @@ module RailsBestPractices
88
119
  end
89
120
 
90
121
  describe 'output_terminal_errors' do
91
- it 'should output errors in terminal' do
122
+ it 'outputs errors in terminal' do
92
123
  check1 = Reviews::LawOfDemeterReview.new
93
124
  check2 = Reviews::UseQueryAttributeReview.new
94
125
  runner = Core::Runner.new(reviews: [check1, check2])
@@ -102,11 +133,14 @@ module RailsBestPractices
102
133
  subject.output_terminal_errors
103
134
  result = $stdout.string
104
135
  $stdout = $origin_stdout
105
- expect(result).to eq([
106
- "\e[31mapp/models/user.rb:10 - law of demeter\e[0m",
107
- "\e[31mapp/models/post.rb:100 - use query attribute\e[0m",
108
- "\e[32m\nPlease go to https://rails-bestpractices.com to see more useful Rails Best Practices.\e[0m",
109
- "\e[31m\nFound 2 warnings.\e[0m"].join("\n") + "\n")
136
+ expect(result).to eq(
137
+ [
138
+ "\e[31mapp/models/user.rb:10 - law of demeter\e[0m",
139
+ "\e[31mapp/models/post.rb:100 - use query attribute\e[0m",
140
+ "\e[32m\nPlease go to https://rails-bestpractices.com to see more useful Rails Best Practices.\e[0m",
141
+ "\e[31m\nFound 2 warnings.\e[0m"
142
+ ].join("\n") + "\n"
143
+ )
110
144
  end
111
145
  end
112
146
 
@@ -114,10 +148,7 @@ module RailsBestPractices
114
148
  let(:output_file) { 'rails_best_practices_output.json' }
115
149
 
116
150
  subject do
117
- described_class.new('.',
118
- 'format' => 'json',
119
- 'output-file' => output_file
120
- )
151
+ described_class.new('.', 'format' => 'json', 'output-file' => output_file)
121
152
  end
122
153
 
123
154
  let(:check1) { Reviews::LawOfDemeterReview.new }
@@ -142,54 +173,54 @@ module RailsBestPractices
142
173
  end
143
174
 
144
175
  describe 'parse_files' do
145
- it 'should not filter out all files when the path contains "vendor"' do
146
- Dir.mktmpdir { |random_dir|
176
+ it 'does not filter out all files when the path contains "vendor"' do
177
+ Dir.mktmpdir do |random_dir|
147
178
  Dir.mkdir(File.join(random_dir, 'vendor'))
148
179
  Dir.mkdir(File.join(random_dir, 'vendor', 'my_project'))
149
180
  File.open(File.join(random_dir, 'vendor', 'my_project', 'my_file.rb'), 'w') { |file| file << 'woot' }
150
- analyzer = Analyzer.new(File.join(random_dir, 'vendor', 'my_project'))
181
+ analyzer = described_class.new(File.join(random_dir, 'vendor', 'my_project'))
151
182
  expect(analyzer.parse_files).to be_include File.join(random_dir, 'vendor', 'my_project', 'my_file.rb')
152
- }
183
+ end
153
184
  end
154
185
 
155
- it 'should not filter out all files when the path contains "spec"' do
156
- Dir.mktmpdir { |random_dir|
186
+ it 'does not filter out all files when the path contains "spec"' do
187
+ Dir.mktmpdir do |random_dir|
157
188
  Dir.mkdir(File.join(random_dir, 'spec'))
158
189
  Dir.mkdir(File.join(random_dir, 'spec', 'my_project'))
159
190
  File.open(File.join(random_dir, 'spec', 'my_project', 'my_file.rb'), 'w') { |file| file << 'woot' }
160
- analyzer = Analyzer.new(File.join(random_dir, 'spec', 'my_project'))
191
+ analyzer = described_class.new(File.join(random_dir, 'spec', 'my_project'))
161
192
  expect(analyzer.parse_files).to be_include File.join(random_dir, 'spec', 'my_project', 'my_file.rb')
162
- }
193
+ end
163
194
  end
164
195
 
165
- it 'should not filter out all files when the path contains "test"' do
166
- Dir.mktmpdir { |random_dir|
196
+ it 'does not filter out all files when the path contains "test"' do
197
+ Dir.mktmpdir do |random_dir|
167
198
  Dir.mkdir(File.join(random_dir, 'test'))
168
199
  Dir.mkdir(File.join(random_dir, 'test', 'my_project'))
169
200
  File.open(File.join(random_dir, 'test', 'my_project', 'my_file.rb'), 'w') { |file| file << 'woot' }
170
- analyzer = Analyzer.new(File.join(random_dir, 'test', 'my_project'))
201
+ analyzer = described_class.new(File.join(random_dir, 'test', 'my_project'))
171
202
  expect(analyzer.parse_files).to be_include File.join(random_dir, 'test', 'my_project', 'my_file.rb')
172
- }
203
+ end
173
204
  end
174
205
 
175
- it 'should not filter out all files when the path contains "features"' do
176
- Dir.mktmpdir { |random_dir|
206
+ it 'does not filter out all files when the path contains "features"' do
207
+ Dir.mktmpdir do |random_dir|
177
208
  Dir.mkdir(File.join(random_dir, 'test'))
178
209
  Dir.mkdir(File.join(random_dir, 'test', 'my_project'))
179
210
  File.open(File.join(random_dir, 'test', 'my_project', 'my_file.rb'), 'w') { |file| file << 'woot' }
180
- analyzer = Analyzer.new(File.join(random_dir, 'test', 'my_project'))
211
+ analyzer = described_class.new(File.join(random_dir, 'test', 'my_project'))
181
212
  expect(analyzer.parse_files).to be_include File.join(random_dir, 'test', 'my_project', 'my_file.rb')
182
- }
213
+ end
183
214
  end
184
215
 
185
- it 'should not filter out all files when the path contains "tmp"' do
186
- Dir.mktmpdir { |random_dir|
216
+ it 'does not filter out all files when the path contains "tmp"' do
217
+ Dir.mktmpdir do |random_dir|
187
218
  Dir.mkdir(File.join(random_dir, 'tmp'))
188
219
  Dir.mkdir(File.join(random_dir, 'tmp', 'my_project'))
189
220
  File.open(File.join(random_dir, 'tmp', 'my_project', 'my_file.rb'), 'w') { |file| file << 'woot' }
190
- analyzer = Analyzer.new(File.join(random_dir, 'tmp', 'my_project'))
221
+ analyzer = described_class.new(File.join(random_dir, 'tmp', 'my_project'))
191
222
  expect(analyzer.parse_files).to be_include File.join(random_dir, 'tmp', 'my_project', 'my_file.rb')
192
- }
223
+ end
193
224
  end
194
225
  end
195
226
  end
@@ -4,13 +4,13 @@ require 'spec_helper'
4
4
 
5
5
  module RailsBestPractices::Core
6
6
  describe Check do
7
- let(:check) { Check.new }
7
+ let(:check) { described_class.new }
8
8
 
9
9
  context 'debug' do
10
- it 'should be debug mode' do
11
- Check.debug
12
- expect(Check).to be_debug
13
- Check.class_eval { @debug = false }
10
+ it 'is debug mode' do
11
+ described_class.debug
12
+ expect(described_class).to be_debug
13
+ described_class.class_eval { @debug = false }
14
14
  end
15
15
  end
16
16
  end
@@ -4,17 +4,17 @@ require 'spec_helper'
4
4
 
5
5
  module RailsBestPractices::Core
6
6
  describe ChecksLoader do
7
- let(:checks_loader) { ChecksLoader.new(RailsBestPractices::Analyzer::DEFAULT_CONFIG) }
7
+ let(:checks_loader) { described_class.new(RailsBestPractices::Analyzer::DEFAULT_CONFIG) }
8
8
 
9
9
  describe 'load_lexicals' do
10
- it 'should load lexical checks from the default configuration' do
10
+ it 'loads lexical checks from the default configuration' do
11
11
  lexicals = checks_loader.load_lexicals
12
12
  expect(lexicals.map(&:class)).to include(RailsBestPractices::Lexicals::RemoveTrailingWhitespaceCheck)
13
13
  end
14
14
  end
15
15
 
16
16
  describe 'load_reviews' do
17
- it 'should load the reviews from the default the configuration' do
17
+ it 'loads the reviews from the default the configuration' do
18
18
  reviews = checks_loader.load_reviews
19
19
  expect(reviews.map(&:class)).to include(RailsBestPractices::Reviews::AlwaysAddDbIndexReview)
20
20
  end
@@ -4,6 +4,6 @@ require 'spec_helper'
4
4
 
5
5
  module RailsBestPractices::Core
6
6
  describe Configs do
7
- it { should be_a_kind_of Hash }
7
+ it { is_expected.to be_a_kind_of Hash }
8
8
  end
9
9
  end
@@ -4,6 +4,6 @@ require 'spec_helper'
4
4
 
5
5
  module RailsBestPractices::Core
6
6
  describe Controllers do
7
- it { should be_a_kind_of Klasses }
7
+ it { is_expected.to be_a_kind_of Klasses }
8
8
  end
9
9
  end
@@ -4,29 +4,32 @@ require 'spec_helper'
4
4
 
5
5
  module RailsBestPractices::Core
6
6
  describe Error do
7
- it 'should return error with filename, line number and message' do
8
- expect(Error.new(
9
- filename: 'app/models/user.rb',
10
- line_number: '100',
11
- message: 'not good',
12
- type: 'BogusReview').to_s).to eq('app/models/user.rb:100 - not good')
7
+ it 'returns error with filename, line number and message' do
8
+ expect(
9
+ described_class.new(
10
+ filename: 'app/models/user.rb', line_number: '100', message: 'not good', type: 'BogusReview'
11
+ ).to_s
12
+ ).to eq('app/models/user.rb:100 - not good')
13
13
  end
14
14
 
15
- it 'should return short filename' do
15
+ it 'returns short filename' do
16
16
  Runner.base_path = '../rails-bestpractices.com'
17
- expect(Error.new(
18
- filename: '../rails-bestpractices.com/app/models/user.rb',
19
- line_number: '100',
20
- message: 'not good',
21
- type: 'BogusReview').short_filename).to eq('app/models/user.rb')
17
+ expect(
18
+ described_class.new(
19
+ filename: '../rails-bestpractices.com/app/models/user.rb',
20
+ line_number: '100',
21
+ message: 'not good',
22
+ type: 'BogusReview'
23
+ ).short_filename
24
+ ).to eq('app/models/user.rb')
22
25
  end
23
26
 
24
- it 'should return first line number' do
25
- expect(Error.new(
26
- filename: 'app/models/user.rb',
27
- line_number: '50,70,100',
28
- message: 'not good',
29
- type: 'BogusReview').first_line_number).to eq('50')
27
+ it 'returns first line number' do
28
+ expect(
29
+ described_class.new(
30
+ filename: 'app/models/user.rb', line_number: '50,70,100', message: 'not good', type: 'BogusReview'
31
+ ).first_line_number
32
+ ).to eq('50')
30
33
  end
31
34
  end
32
35
  end
@@ -10,7 +10,7 @@ module RailsBestPractices::Core
10
10
  let(:except_method) { '*#*' }
11
11
 
12
12
  it 'matches' do
13
- expect(Check::Exceptable.matches(method, except_method)).to eql true
13
+ expect(described_class.matches(method, except_method)).to eql true
14
14
  end
15
15
  end
16
16
 
@@ -18,7 +18,7 @@ module RailsBestPractices::Core
18
18
  let(:except_method) { '*#approve' }
19
19
 
20
20
  it 'matches' do
21
- expect(Check::Exceptable.matches(method, except_method)).to eql true
21
+ expect(described_class.matches(method, except_method)).to eql true
22
22
  end
23
23
  end
24
24
 
@@ -26,7 +26,7 @@ module RailsBestPractices::Core
26
26
  let(:except_method) { '*#disapprove' }
27
27
 
28
28
  it 'matches' do
29
- expect(Check::Exceptable.matches(method, except_method)).to eql false
29
+ expect(described_class.matches(method, except_method)).to eql false
30
30
  end
31
31
  end
32
32
 
@@ -34,7 +34,7 @@ module RailsBestPractices::Core
34
34
  let(:except_method) { 'BlogPost#*' }
35
35
 
36
36
  it 'matches' do
37
- expect(Check::Exceptable.matches(method, except_method)).to eql true
37
+ expect(described_class.matches(method, except_method)).to eql true
38
38
  end
39
39
  end
40
40
 
@@ -42,7 +42,7 @@ module RailsBestPractices::Core
42
42
  let(:except_method) { 'User#*' }
43
43
 
44
44
  it 'matches' do
45
- expect(Check::Exceptable.matches(method, except_method)).to eql false
45
+ expect(described_class.matches(method, except_method)).to eql false
46
46
  end
47
47
  end
48
48
 
@@ -50,7 +50,7 @@ module RailsBestPractices::Core
50
50
  let(:except_method) { 'BlogPost#approve' }
51
51
 
52
52
  it 'matches' do
53
- expect(Check::Exceptable.matches(method, except_method)).to eql true
53
+ expect(described_class.matches(method, except_method)).to eql true
54
54
  end
55
55
  end
56
56
 
@@ -58,7 +58,7 @@ module RailsBestPractices::Core
58
58
  let(:except_method) { 'User#disapprove' }
59
59
 
60
60
  it 'matches' do
61
- expect(Check::Exceptable.matches(method, except_method)).to eql false
61
+ expect(described_class.matches(method, except_method)).to eql false
62
62
  end
63
63
  end
64
64
  end
@@ -4,15 +4,15 @@ require 'spec_helper'
4
4
 
5
5
  module RailsBestPractices::Core
6
6
  describe Gems do
7
- it { should be_a_kind_of Array }
7
+ it { is_expected.to be_a_kind_of Array }
8
8
 
9
- let(:gems) { Gems.new }
9
+ let(:gems) { described_class.new }
10
10
  before do
11
11
  gems << Gem.new('rails', '4.0.0')
12
12
  gems << Gem.new('mysql2', '0.2.0')
13
13
  end
14
14
 
15
- context '#has_gem?' do
15
+ describe '#has_gem?' do
16
16
  it 'has rails gem' do
17
17
  expect(gems).to be_has_gem 'rails'
18
18
  end
@@ -22,7 +22,7 @@ module RailsBestPractices::Core
22
22
  end
23
23
  end
24
24
 
25
- context '#gem_version' do
25
+ describe '#gem_version' do
26
26
  it 'gets rails version' do
27
27
  expect(gems.gem_version('rails')).to eq '4.0.0'
28
28
  end
@@ -4,6 +4,6 @@ require 'spec_helper'
4
4
 
5
5
  module RailsBestPractices::Core
6
6
  describe Helpers do
7
- it { should be_a_kind_of Modules }
7
+ it { is_expected.to be_a_kind_of Modules }
8
8
  end
9
9
  end
@@ -4,10 +4,10 @@ require 'spec_helper'
4
4
 
5
5
  module RailsBestPractices::Core
6
6
  describe Klasses do
7
- it { should be_a_kind_of Array }
7
+ it { is_expected.to be_a_kind_of Array }
8
8
 
9
9
  context 'Klass' do
10
- context '#class_name' do
10
+ describe '#class_name' do
11
11
  it 'gets class name without module' do
12
12
  klass = Klass.new('BlogPost', 'Post', [])
13
13
  expect(klass.class_name).to eq('BlogPost')
@@ -19,7 +19,7 @@ module RailsBestPractices::Core
19
19
  end
20
20
  end
21
21
 
22
- context '#extend_class_name' do
22
+ describe '#extend_class_name' do
23
23
  it 'gets extend class name without module' do
24
24
  klass = Klass.new('BlogPost', 'Post', [])
25
25
  expect(klass.extend_class_name).to eq('Post')
@@ -4,6 +4,6 @@ require 'spec_helper'
4
4
 
5
5
  module RailsBestPractices::Core
6
6
  describe Mailers do
7
- it { should be_a_kind_of Klasses }
7
+ it { is_expected.to be_a_kind_of Klasses }
8
8
  end
9
9
  end