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,13 +5,14 @@ require 'spec_helper'
5
5
  module RailsBestPractices
6
6
  module Reviews
7
7
  describe RemoveUnusedMethodsInModelsReview do
8
- let(:runner) { Core::Runner.new(
9
- prepares: Prepares::ModelPrepare.new,
10
- reviews: RemoveUnusedMethodsInModelsReview.new('except_methods' => ['*#set_cache'])
11
- ) }
8
+ let(:runner) do
9
+ Core::Runner.new(
10
+ prepares: Prepares::ModelPrepare.new, reviews: described_class.new('except_methods' => ['*#set_cache'])
11
+ )
12
+ end
12
13
 
13
14
  context 'private' do
14
- it 'should remove unused methods' do
15
+ it 'removes unused methods' do
15
16
  content = <<-EOF
16
17
  class Post < ActiveRecord::Base
17
18
  def find; end
@@ -34,7 +35,7 @@ module RailsBestPractices
34
35
  expect(runner.errors[0].to_s).to eq('app/models/post.rb:4 - remove unused methods (Post#find_by_sql)')
35
36
  end
36
37
 
37
- it 'should not remove unused methods with except_methods' do
38
+ it 'does not remove unused methods with except_methods' do
38
39
  content = <<-EOF
39
40
  class Post < ActiveRecord::Base
40
41
  def set_cache; end
@@ -46,7 +47,7 @@ module RailsBestPractices
46
47
  expect(runner.errors.size).to eq(0)
47
48
  end
48
49
 
49
- it 'should not remove unused methods with var_ref' do
50
+ it 'does not remove unused methods with var_ref' do
50
51
  content = <<-EOF
51
52
  class Post < ActiveRecord::Base
52
53
  def find
@@ -70,7 +71,7 @@ module RailsBestPractices
70
71
  expect(runner.errors.size).to eq(0)
71
72
  end
72
73
 
73
- it 'should not remove unused methods with callback' do
74
+ it 'does not remove unused methods with callback' do
74
75
  content = <<-EOF
75
76
  class Post < ActiveRecord::Base
76
77
  after_save :expire_cache
@@ -84,7 +85,7 @@ module RailsBestPractices
84
85
  expect(runner.errors.size).to eq(0)
85
86
  end
86
87
 
87
- it 'should not remove unused method with command' do
88
+ it 'does not remove unused method with command' do
88
89
  content = <<-EOF
89
90
  class Post < ActiveRecord::Base
90
91
  def fetch
@@ -108,7 +109,7 @@ module RailsBestPractices
108
109
  expect(runner.errors.size).to eq(0)
109
110
  end
110
111
 
111
- it 'should not remove unused method with call' do
112
+ it 'does not remove unused method with call' do
112
113
  content = <<-EOF
113
114
  class Post < ActiveRecord::Base
114
115
  def conditions
@@ -132,7 +133,7 @@ module RailsBestPractices
132
133
  expect(runner.errors.size).to eq(0)
133
134
  end
134
135
 
135
- it 'should not remove unused method with message' do
136
+ it 'does not remove unused method with message' do
136
137
  content = <<-EOF
137
138
  class Post < ActiveRecord::Base
138
139
  def save
@@ -158,7 +159,7 @@ module RailsBestPractices
158
159
  expect(runner.errors.size).to eq(0)
159
160
  end
160
161
 
161
- it 'should not remove unused method with validation condition' do
162
+ it 'does not remove unused method with validation condition' do
162
163
  content = <<-EOF
163
164
  class Post < ActiveRecord::Base
164
165
  validates_uniqueness_of :login, if: :email_blank?
@@ -172,7 +173,7 @@ module RailsBestPractices
172
173
  expect(runner.errors.size).to eq(0)
173
174
  end
174
175
 
175
- it 'should not remove unused method with aasm' do
176
+ it 'does not remove unused method with aasm' do
176
177
  content = <<-EOF
177
178
  class Post < ActiveRecord::Base
178
179
  aasm_state :accepted, enter: [:update_datetime]
@@ -186,7 +187,7 @@ module RailsBestPractices
186
187
  expect(runner.errors.size).to eq(0)
187
188
  end
188
189
 
189
- it 'should not remove unused method with initialize' do
190
+ it 'does not remove unused method with initialize' do
190
191
  content = <<-EOF
191
192
  class Post < ActiveRecord::Base
192
193
  private
@@ -201,7 +202,7 @@ module RailsBestPractices
201
202
  end
202
203
 
203
204
  context 'public' do
204
- it 'should remove unused methods' do
205
+ it 'removes unused methods' do
205
206
  content = <<-EOF
206
207
  class Post < ActiveRecord::Base
207
208
  def fetch; end
@@ -213,7 +214,7 @@ module RailsBestPractices
213
214
  expect(runner.errors[0].to_s).to eq('app/models/post.rb:2 - remove unused methods (Post#fetch)')
214
215
  end
215
216
 
216
- it 'should not remove unused methods' do
217
+ it 'does not remove unused methods' do
217
218
  content = <<-EOF
218
219
  class Post < ActiveRecord::Base
219
220
  def fetch; end
@@ -232,7 +233,7 @@ module RailsBestPractices
232
233
  expect(runner.errors.size).to eq(0)
233
234
  end
234
235
 
235
- it 'should not remove unused methods for attribute assignment' do
236
+ it 'does not remove unused methods for attribute assignment' do
236
237
  content = <<-EOF
237
238
  class Post < ActiveRecord::Base
238
239
  def user=(user); end
@@ -244,7 +245,7 @@ module RailsBestPractices
244
245
  expect(runner.errors.size).to eq(0)
245
246
  end
246
247
 
247
- it 'should not remove unused methods for try' do
248
+ it 'does not remove unused methods for try' do
248
249
  content = <<-EOF
249
250
  class Post < ActiveRecord::Base
250
251
  def find(user_id); end
@@ -264,7 +265,7 @@ module RailsBestPractices
264
265
  expect(runner.errors.size).to eq(0)
265
266
  end
266
267
 
267
- it 'should not remove unused methods for send' do
268
+ it 'does not remove unused methods for send' do
268
269
  content = <<-EOF
269
270
  class Post < ActiveRecord::Base
270
271
  def find(user_id); end
@@ -284,7 +285,7 @@ module RailsBestPractices
284
285
  expect(runner.errors.size).to eq(0)
285
286
  end
286
287
 
287
- it 'should remove unused methods for send string_embexpre' do
288
+ it 'removes unused methods for send string_embexpre' do
288
289
  content = <<-EOF
289
290
  class Post < ActiveRecord::Base
290
291
  def find_first; end
@@ -305,7 +306,7 @@ module RailsBestPractices
305
306
  expect(runner.errors.size).to eq(1)
306
307
  end
307
308
 
308
- it 'should remove unused methods for send variable' do
309
+ it 'removes unused methods for send variable' do
309
310
  content = <<-EOF
310
311
  class Post < ActiveRecord::Base
311
312
  def first; end
@@ -328,7 +329,7 @@ module RailsBestPractices
328
329
  end
329
330
 
330
331
  context 'protected' do
331
- it 'should not remove unused methods' do
332
+ it 'does not remove unused methods' do
332
333
  content = <<-EOF
333
334
  class Post < ActiveRecord::Base
334
335
  protected
@@ -350,7 +351,7 @@ module RailsBestPractices
350
351
  expect(runner.errors[0].to_s).to eq('app/models/post.rb:3 - remove unused methods (Post#test)')
351
352
  end
352
353
 
353
- it 'should not remove unused methods' do
354
+ it 'does not remove unused methods' do
354
355
  post_content = <<-EOF
355
356
  class Post < ActiveRecord::Base
356
357
  protected
@@ -382,7 +383,7 @@ module RailsBestPractices
382
383
  end
383
384
 
384
385
  context 'named_scope' do
385
- it 'should not remove unused named_scope' do
386
+ it 'does not remove unused named_scope' do
386
387
  content = <<-EOF
387
388
  class Post < ActiveRecord::Base
388
389
  named_scope :active, conditions: {active: true}
@@ -402,7 +403,7 @@ module RailsBestPractices
402
403
  expect(runner.errors.size).to eq(0)
403
404
  end
404
405
 
405
- it 'should remove unused named_scope' do
406
+ it 'removes unused named_scope' do
406
407
  content = <<-EOF
407
408
  class Post < ActiveRecord::Base
408
409
  named_scope :active, conditions: {active: true}
@@ -417,7 +418,7 @@ module RailsBestPractices
417
418
  end
418
419
 
419
420
  context 'scope' do
420
- it 'should not remove unused scope' do
421
+ it 'does not remove unused scope' do
421
422
  content = <<-EOF
422
423
  class Post < ActiveRecord::Base
423
424
  scope :active, where(active: true)
@@ -437,7 +438,7 @@ module RailsBestPractices
437
438
  expect(runner.errors.size).to eq(0)
438
439
  end
439
440
 
440
- it 'should remove unused named_scope' do
441
+ it 'removes unused named_scope' do
441
442
  content = <<-EOF
442
443
  class Post < ActiveRecord::Base
443
444
  scope :active, where(active: true)
@@ -452,7 +453,7 @@ module RailsBestPractices
452
453
  end
453
454
 
454
455
  context 'alias' do
455
- it 'should not remove unused method with alias' do
456
+ it 'does not remove unused method with alias' do
456
457
  content = <<-EOF
457
458
  class Post < ActiveRecord::Base
458
459
  def old; end
@@ -473,7 +474,7 @@ module RailsBestPractices
473
474
  expect(runner.errors.size).to eq(0)
474
475
  end
475
476
 
476
- it 'should not remove unused method with symbol alias' do
477
+ it 'does not remove unused method with symbol alias' do
477
478
  content = <<-EOF
478
479
  class Post < ActiveRecord::Base
479
480
  def old; end
@@ -494,7 +495,7 @@ module RailsBestPractices
494
495
  expect(runner.errors.size).to eq(0)
495
496
  end
496
497
 
497
- it 'should not remove unused method with alias_method' do
498
+ it 'does not remove unused method with alias_method' do
498
499
  content = <<-EOF
499
500
  class Post < ActiveRecord::Base
500
501
  def old; end
@@ -515,7 +516,7 @@ module RailsBestPractices
515
516
  expect(runner.errors.size).to eq(0)
516
517
  end
517
518
 
518
- it 'should not remove unused method with alias_method_chain' do
519
+ it 'does not remove unused method with alias_method_chain' do
519
520
  content = <<-EOF
520
521
  class Post < ActiveRecord::Base
521
522
  def method_with_feature; end
@@ -538,7 +539,7 @@ module RailsBestPractices
538
539
  end
539
540
 
540
541
  context 'methods hash' do
541
- it 'should not remove unused method with methods hash' do
542
+ it 'does not remove unused method with methods hash' do
542
543
  content = <<-EOF
543
544
  class Post < ActiveRecord::Base
544
545
  def to_xml(options = {})
@@ -556,7 +557,7 @@ module RailsBestPractices
556
557
  end
557
558
 
558
559
  context 'callbacks' do
559
- it 'should not remove unused method' do
560
+ it 'does not remove unused method' do
560
561
  content = <<-EOF
561
562
  class Post < ActiveRecord::Base
562
563
  before_save :init_columns
@@ -575,7 +576,7 @@ module RailsBestPractices
575
576
  end
576
577
 
577
578
  context 'validates' do
578
- it 'should not remove unused method' do
579
+ it 'does not remove unused method' do
579
580
  content = <<-EOF
580
581
  class Post < ActiveRecord::Base
581
582
  validate :valid_birth_date
@@ -590,7 +591,7 @@ module RailsBestPractices
590
591
  expect(runner.errors.size).to eq(0)
591
592
  end
592
593
 
593
- it 'should not remove unused method for validate_on_create and validate_on_update' do
594
+ it 'does not remove unused method for validate_on_create and validate_on_update' do
594
595
  content = <<-EOF
595
596
  class Post < ActiveRecord::Base
596
597
  validate_on_create :valid_email
@@ -607,7 +608,7 @@ module RailsBestPractices
607
608
  expect(runner.errors.size).to eq(0)
608
609
  end
609
610
 
610
- it 'should not remove unused methods for to_param' do
611
+ it 'does not remove unused methods for to_param' do
611
612
  content = <<-EOF
612
613
  class Post < ActiveRecord::Base
613
614
  def to_param
@@ -623,7 +624,7 @@ module RailsBestPractices
623
624
  end
624
625
 
625
626
  context 'helper method' do
626
- it 'should not remove unused method for coommand_call collection_select' do
627
+ it 'does not remove unused method for coommand_call collection_select' do
627
628
  content = <<-EOF
628
629
  class Category < ActiveRecord::Base
629
630
  def indented_name; end
@@ -639,7 +640,7 @@ module RailsBestPractices
639
640
  expect(runner.errors.size).to eq(0)
640
641
  end
641
642
 
642
- it 'should not remove unused method for command collection_select' do
643
+ it 'does not remove unused method for command collection_select' do
643
644
  content = <<-EOF
644
645
  class Category < ActiveRecord::Base
645
646
  def indented_name; end
@@ -655,7 +656,7 @@ module RailsBestPractices
655
656
  expect(runner.errors.size).to eq(0)
656
657
  end
657
658
 
658
- it 'should not remove unused method for options_from_collection_for_select' do
659
+ it 'does not remove unused method for options_from_collection_for_select' do
659
660
  content = <<-EOF
660
661
  class Category < ActiveRecord::Base
661
662
  def indented_name; end
@@ -672,7 +673,7 @@ module RailsBestPractices
672
673
  end
673
674
  end
674
675
 
675
- it 'should not remove unused methods for rabl view' do
676
+ it 'does not remove unused methods for rabl view' do
676
677
  content = <<-EOF
677
678
  class User
678
679
  def first_name; end
@@ -691,7 +692,7 @@ module RailsBestPractices
691
692
  expect(runner.errors.size).to eq(0)
692
693
  end
693
694
 
694
- it 'should not skip :call as call message' do
695
+ it 'does not skip :call as call message' do
695
696
  content = <<-EOF
696
697
  module DateRange
697
698
  RANGES = lambda {
@@ -706,29 +707,32 @@ module RailsBestPractices
706
707
  runner.review('app/mixins/date_range.rb', content)
707
708
  end
708
709
 
709
- it 'should not check ignored files' do
710
- runner = Core::Runner.new(prepares: Prepares::ModelPrepare.new,
711
- reviews: RemoveUnusedMethodsInModelsReview.new(except_methods: [], ignored_files: /post/))
710
+ it 'does not check ignored files' do
711
+ runner =
712
+ Core::Runner.new(
713
+ prepares: Prepares::ModelPrepare.new,
714
+ reviews: described_class.new(except_methods: [], ignored_files: /post/)
715
+ )
712
716
 
713
- content = <<-EOF
717
+ content = <<-EOF
714
718
  class Post < ActiveRecord::Base
715
719
  def find; end
716
720
  private
717
721
  def find_by_sql; end
718
722
  end
719
- EOF
720
- runner.prepare('app/models/post.rb', content)
721
- runner.review('app/models/post.rb', content)
722
- content = <<-EOF
723
+ EOF
724
+ runner.prepare('app/models/post.rb', content)
725
+ runner.review('app/models/post.rb', content)
726
+ content = <<-EOF
723
727
  class PostsController < ApplicationController
724
728
  def get
725
729
  Post.new.find
726
730
  end
727
731
  end
728
- EOF
729
- runner.review('app/controllers/posts_controller.rb', content)
730
- runner.after_review
731
- expect(runner.errors.size).to eq(0)
732
+ EOF
733
+ runner.review('app/controllers/posts_controller.rb', content)
734
+ runner.after_review
735
+ expect(runner.errors.size).to eq(0)
732
736
  end
733
737
  end
734
738
  end
@@ -5,9 +5,9 @@ require 'spec_helper'
5
5
  module RailsBestPractices
6
6
  module Reviews
7
7
  describe ReplaceComplexCreationWithFactoryMethodReview do
8
- let(:runner) { Core::Runner.new(reviews: ReplaceComplexCreationWithFactoryMethodReview.new) }
8
+ let(:runner) { Core::Runner.new(reviews: described_class.new) }
9
9
 
10
- it 'should replace complex creation with factory method' do
10
+ it 'replaces complex creation with factory method' do
11
11
  content = <<-EOF
12
12
  class InvoiceController < ApplicationController
13
13
  def create
@@ -28,10 +28,12 @@ module RailsBestPractices
28
28
  EOF
29
29
  runner.review('app/controllers/invoices_controller.rb', content)
30
30
  expect(runner.errors.size).to eq(1)
31
- expect(runner.errors[0].to_s).to eq('app/controllers/invoices_controller.rb:2 - replace complex creation with factory method (@invoice attribute_assignment_count > 2)')
31
+ expect(runner.errors[0].to_s).to eq(
32
+ 'app/controllers/invoices_controller.rb:2 - replace complex creation with factory method (@invoice attribute_assignment_count > 2)'
33
+ )
32
34
  end
33
35
 
34
- it 'should not replace complex creation with factory method with simple creation' do
36
+ it 'does not replace complex creation with factory method with simple creation' do
35
37
  content = <<-EOF
36
38
  class InvoiceController < ApplicationController
37
39
  def create
@@ -46,7 +48,7 @@ module RailsBestPractices
46
48
  expect(runner.errors.size).to eq(0)
47
49
  end
48
50
 
49
- it 'should not replace complex creation with factory method when attrasgn_count is 5' do
51
+ it 'does not replace complex creation with factory method when attrasgn_count is 5' do
50
52
  content = <<-EOF
51
53
  class InvoiceController < ApplicationController
52
54
  def create
@@ -65,13 +67,13 @@ module RailsBestPractices
65
67
  end
66
68
  end
67
69
  EOF
68
- runner = Core::Runner.new(reviews: ReplaceComplexCreationWithFactoryMethodReview.new('attribute_assignment_count' => 5))
70
+ runner = Core::Runner.new(reviews: described_class.new('attribute_assignment_count' => 5))
69
71
  runner.review('app/controllers/invoices_controller.rb', content)
70
72
  expect(runner.errors.size).to eq(0)
71
73
  end
72
74
 
73
- it 'should not check ignored files' do
74
- runner = Core::Runner.new(reviews: ReplaceComplexCreationWithFactoryMethodReview.new(ignored_files: /invoices_controller/))
75
+ it 'does not check ignored files' do
76
+ runner = Core::Runner.new(reviews: described_class.new(ignored_files: /invoices_controller/))
75
77
  content = <<-EOF
76
78
  class InvoiceController < ApplicationController
77
79
  def create
@@ -5,36 +5,42 @@ require 'spec_helper'
5
5
  module RailsBestPractices
6
6
  module Reviews
7
7
  describe ReplaceInstanceVariableWithLocalVariableReview do
8
- let(:runner) { Core::Runner.new(reviews: ReplaceInstanceVariableWithLocalVariableReview.new) }
8
+ let(:runner) { Core::Runner.new(reviews: described_class.new) }
9
9
 
10
- it 'should replace instance variable with local varialbe' do
10
+ it 'replaces instance variable with local varialbe' do
11
11
  content = <<-EOF
12
12
  <%= @post.title %>
13
13
  EOF
14
14
  runner.review('app/views/posts/_post.html.erb', content)
15
15
  expect(runner.errors.size).to eq(1)
16
- expect(runner.errors[0].to_s).to eq('app/views/posts/_post.html.erb:1 - replace instance variable with local variable')
16
+ expect(runner.errors[0].to_s).to eq(
17
+ 'app/views/posts/_post.html.erb:1 - replace instance variable with local variable'
18
+ )
17
19
  end
18
20
 
19
- it 'should replace instance variable with local varialbe in haml file' do
20
- content = <<-EOF
21
- = @post.title
21
+ it 'replaces instance variable with local varialbe in haml file' do
22
+ content = <<~EOF
23
+ = @post.title
22
24
  EOF
23
25
  runner.review('app/views/posts/_post.html.haml', content)
24
26
  expect(runner.errors.size).to eq(1)
25
- expect(runner.errors[0].to_s).to eq('app/views/posts/_post.html.haml:1 - replace instance variable with local variable')
27
+ expect(runner.errors[0].to_s).to eq(
28
+ 'app/views/posts/_post.html.haml:1 - replace instance variable with local variable'
29
+ )
26
30
  end
27
31
 
28
- it 'should replace instance variable with local varialbe in slim file' do
29
- content = <<-EOF
30
- = @post.title
32
+ it 'replaces instance variable with local varialbe in slim file' do
33
+ content = <<~EOF
34
+ = @post.title
31
35
  EOF
32
36
  runner.review('app/views/posts/_post.html.slim', content)
33
37
  expect(runner.errors.size).to eq(1)
34
- expect(runner.errors[0].to_s).to eq('app/views/posts/_post.html.slim:1 - replace instance variable with local variable')
38
+ expect(runner.errors[0].to_s).to eq(
39
+ 'app/views/posts/_post.html.slim:1 - replace instance variable with local variable'
40
+ )
35
41
  end
36
42
 
37
- it 'should not replace instance variable with local varialbe' do
43
+ it 'does not replace instance variable with local varialbe' do
38
44
  content = <<-EOF
39
45
  <%= post.title %>
40
46
  EOF
@@ -42,8 +48,8 @@ module RailsBestPractices
42
48
  expect(runner.errors.size).to eq(0)
43
49
  end
44
50
 
45
- it 'should not check ignored files' do
46
- runner = Core::Runner.new(reviews: ReplaceInstanceVariableWithLocalVariableReview.new(ignored_files: /views\/posts/))
51
+ it 'does not check ignored files' do
52
+ runner = Core::Runner.new(reviews: described_class.new(ignored_files: %r{views/posts}))
47
53
  content = <<-EOF
48
54
  <%= @post.title %>
49
55
  EOF