rails_best_practices 1.19.0 → 1.19.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 (133) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/Guardfile +2 -2
  4. data/Rakefile +8 -8
  5. data/bin/rails_best_practices +1 -1
  6. data/lib/rails_best_practices/analyzer.rb +45 -45
  7. data/lib/rails_best_practices/command.rb +40 -40
  8. data/lib/rails_best_practices/core/check.rb +15 -15
  9. data/lib/rails_best_practices/core/klasses.rb +1 -1
  10. data/lib/rails_best_practices/core/methods.rb +7 -7
  11. data/lib/rails_best_practices/core/model_associations.rb +3 -3
  12. data/lib/rails_best_practices/core/modules.rb +1 -1
  13. data/lib/rails_best_practices/core/routes.rb +2 -2
  14. data/lib/rails_best_practices/core/runner.rb +3 -3
  15. data/lib/rails_best_practices/core_ext/erubis.rb +4 -4
  16. data/lib/rails_best_practices/lexicals/remove_tab_check.rb +2 -2
  17. data/lib/rails_best_practices/lexicals/remove_trailing_whitespace_check.rb +2 -2
  18. data/lib/rails_best_practices/prepares/config_prepare.rb +1 -1
  19. data/lib/rails_best_practices/prepares/controller_prepare.rb +8 -8
  20. data/lib/rails_best_practices/prepares/helper_prepare.rb +1 -1
  21. data/lib/rails_best_practices/prepares/initializer_prepare.rb +4 -4
  22. data/lib/rails_best_practices/prepares/mailer_prepare.rb +1 -1
  23. data/lib/rails_best_practices/prepares/model_prepare.rb +19 -19
  24. data/lib/rails_best_practices/prepares/route_prepare.rb +34 -34
  25. data/lib/rails_best_practices/prepares/schema_prepare.rb +1 -1
  26. data/lib/rails_best_practices/reviews/add_model_virtual_attribute_review.rb +2 -2
  27. data/lib/rails_best_practices/reviews/always_add_db_index_review.rb +7 -7
  28. data/lib/rails_best_practices/reviews/check_save_return_value_review.rb +1 -1
  29. data/lib/rails_best_practices/reviews/default_scope_is_evil_review.rb +3 -3
  30. data/lib/rails_best_practices/reviews/dry_bundler_in_capistrano_review.rb +3 -3
  31. data/lib/rails_best_practices/reviews/hash_syntax_review.rb +1 -1
  32. data/lib/rails_best_practices/reviews/isolate_seed_data_review.rb +6 -6
  33. data/lib/rails_best_practices/reviews/keep_finders_on_their_own_model_review.rb +2 -2
  34. data/lib/rails_best_practices/reviews/law_of_demeter_review.rb +4 -4
  35. data/lib/rails_best_practices/reviews/move_code_into_controller_review.rb +3 -3
  36. data/lib/rails_best_practices/reviews/move_code_into_helper_review.rb +2 -2
  37. data/lib/rails_best_practices/reviews/move_code_into_model_review.rb +1 -1
  38. data/lib/rails_best_practices/reviews/move_finder_to_named_scope_review.rb +2 -2
  39. data/lib/rails_best_practices/reviews/move_model_logic_into_model_review.rb +1 -1
  40. data/lib/rails_best_practices/reviews/needless_deep_nesting_review.rb +4 -4
  41. data/lib/rails_best_practices/reviews/not_rescue_exception_review.rb +2 -2
  42. data/lib/rails_best_practices/reviews/not_use_default_route_review.rb +4 -4
  43. data/lib/rails_best_practices/reviews/not_use_time_ago_in_words_review.rb +3 -3
  44. data/lib/rails_best_practices/reviews/overuse_route_customizations_review.rb +2 -2
  45. data/lib/rails_best_practices/reviews/protect_mass_assignment_review.rb +9 -9
  46. data/lib/rails_best_practices/reviews/remove_empty_helpers_review.rb +3 -3
  47. data/lib/rails_best_practices/reviews/remove_unused_methods_in_controllers_review.rb +11 -11
  48. data/lib/rails_best_practices/reviews/remove_unused_methods_in_helpers_review.rb +1 -1
  49. data/lib/rails_best_practices/reviews/remove_unused_methods_in_models_review.rb +8 -7
  50. data/lib/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review.rb +2 -2
  51. data/lib/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review.rb +2 -2
  52. data/lib/rails_best_practices/reviews/restrict_auto_generated_routes_review.rb +22 -22
  53. data/lib/rails_best_practices/reviews/review.rb +2 -2
  54. data/lib/rails_best_practices/reviews/simplify_render_in_controllers_review.rb +3 -3
  55. data/lib/rails_best_practices/reviews/simplify_render_in_views_review.rb +4 -4
  56. data/lib/rails_best_practices/reviews/use_before_filter_review.rb +2 -2
  57. data/lib/rails_best_practices/reviews/use_model_association_review.rb +2 -2
  58. data/lib/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review.rb +2 -2
  59. data/lib/rails_best_practices/reviews/use_observer_review.rb +3 -3
  60. data/lib/rails_best_practices/reviews/use_parentheses_in_method_def_review.rb +1 -1
  61. data/lib/rails_best_practices/reviews/use_query_attribute_review.rb +3 -3
  62. data/lib/rails_best_practices/reviews/use_say_with_time_in_migrations_review.rb +2 -2
  63. data/lib/rails_best_practices/reviews/use_scope_access_review.rb +5 -5
  64. data/lib/rails_best_practices/reviews/use_turbo_sprockets_rails3_review.rb +4 -4
  65. data/lib/rails_best_practices/version.rb +1 -1
  66. data/rails_best_practices.gemspec +24 -24
  67. data/spec/rails_best_practices/analyzer_spec.rb +43 -43
  68. data/spec/rails_best_practices/core/check_spec.rb +2 -2
  69. data/spec/rails_best_practices/core/checks_loader_spec.rb +4 -4
  70. data/spec/rails_best_practices/core/error_spec.rb +16 -16
  71. data/spec/rails_best_practices/core/except_methods_spec.rb +15 -15
  72. data/spec/rails_best_practices/core/gems_spec.rb +9 -9
  73. data/spec/rails_best_practices/core/klasses_spec.rb +17 -17
  74. data/spec/rails_best_practices/core/methods_spec.rb +28 -28
  75. data/spec/rails_best_practices/core/model_associations_spec.rb +10 -10
  76. data/spec/rails_best_practices/core/model_attributes_spec.rb +10 -10
  77. data/spec/rails_best_practices/core/modules_spec.rb +10 -10
  78. data/spec/rails_best_practices/core/routes_spec.rb +10 -10
  79. data/spec/rails_best_practices/core/runner_spec.rb +4 -4
  80. data/spec/rails_best_practices/core_ext/erubis_spec.rb +7 -7
  81. data/spec/rails_best_practices/lexicals/long_line_check_spec.rb +7 -7
  82. data/spec/rails_best_practices/lexicals/remove_tab_check_spec.rb +6 -6
  83. data/spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb +6 -6
  84. data/spec/rails_best_practices/prepares/config_prepare_spec.rb +3 -3
  85. data/spec/rails_best_practices/prepares/controller_prepare_spec.rb +26 -26
  86. data/spec/rails_best_practices/prepares/gemfile_prepare_spec.rb +3 -3
  87. data/spec/rails_best_practices/prepares/helper_prepare_spec.rb +6 -6
  88. data/spec/rails_best_practices/prepares/initializer_prepare_spec.rb +5 -5
  89. data/spec/rails_best_practices/prepares/mailer_prepare_spec.rb +2 -2
  90. data/spec/rails_best_practices/prepares/model_prepare_spec.rb +108 -108
  91. data/spec/rails_best_practices/prepares/route_prepare_spec.rb +77 -77
  92. data/spec/rails_best_practices/prepares/schema_prepare_spec.rb +8 -8
  93. data/spec/rails_best_practices/reviews/add_model_virtual_attribute_review_spec.rb +10 -10
  94. data/spec/rails_best_practices/reviews/always_add_db_index_review_spec.rb +27 -27
  95. data/spec/rails_best_practices/reviews/check_destroy_return_value_review_spec.rb +11 -11
  96. data/spec/rails_best_practices/reviews/check_save_return_value_review_spec.rb +17 -17
  97. data/spec/rails_best_practices/reviews/default_scope_is_evil_review_spec.rb +6 -6
  98. data/spec/rails_best_practices/reviews/dry_bundler_in_capistrano_review_spec.rb +4 -4
  99. data/spec/rails_best_practices/reviews/hash_syntax_review_spec.rb +8 -8
  100. data/spec/rails_best_practices/reviews/isolate_seed_data_review_spec.rb +10 -10
  101. data/spec/rails_best_practices/reviews/keep_finders_on_their_own_model_review_spec.rb +9 -9
  102. data/spec/rails_best_practices/reviews/law_of_demeter_review_spec.rb +16 -16
  103. data/spec/rails_best_practices/reviews/move_code_into_controller_review_spec.rb +6 -6
  104. data/spec/rails_best_practices/reviews/move_code_into_helper_review_spec.rb +4 -4
  105. data/spec/rails_best_practices/reviews/move_code_into_model_review_spec.rb +13 -13
  106. data/spec/rails_best_practices/reviews/move_finder_to_named_scope_review_spec.rb +7 -7
  107. data/spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb +5 -5
  108. data/spec/rails_best_practices/reviews/needless_deep_nesting_review_spec.rb +10 -10
  109. data/spec/rails_best_practices/reviews/not_rescue_exception_review_spec.rb +8 -8
  110. data/spec/rails_best_practices/reviews/not_use_default_route_review_spec.rb +4 -4
  111. data/spec/rails_best_practices/reviews/not_use_time_ago_in_words_review_spec.rb +11 -11
  112. data/spec/rails_best_practices/reviews/overuse_route_customizations_review_spec.rb +7 -7
  113. data/spec/rails_best_practices/reviews/protect_mass_assignment_review_spec.rb +16 -16
  114. data/spec/rails_best_practices/reviews/remove_empty_helpers_review_spec.rb +5 -5
  115. data/spec/rails_best_practices/reviews/remove_unused_methods_in_controllers_review_spec.rb +33 -33
  116. data/spec/rails_best_practices/reviews/remove_unused_methods_in_helpers_review_spec.rb +7 -7
  117. data/spec/rails_best_practices/reviews/remove_unused_methods_in_models_review_spec.rb +106 -106
  118. data/spec/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review_spec.rb +5 -5
  119. data/spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb +8 -8
  120. data/spec/rails_best_practices/reviews/restrict_auto_generated_routes_review_spec.rb +29 -29
  121. data/spec/rails_best_practices/reviews/simplify_render_in_controllers_review_spec.rb +15 -15
  122. data/spec/rails_best_practices/reviews/simplify_render_in_views_review_spec.rb +15 -15
  123. data/spec/rails_best_practices/reviews/use_before_filter_review_spec.rb +7 -7
  124. data/spec/rails_best_practices/reviews/use_model_association_review_spec.rb +7 -7
  125. data/spec/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review_spec.rb +29 -29
  126. data/spec/rails_best_practices/reviews/use_observer_review_spec.rb +6 -6
  127. data/spec/rails_best_practices/reviews/use_parentheses_in_method_def_review_spec.rb +5 -5
  128. data/spec/rails_best_practices/reviews/use_query_attribute_review_spec.rb +28 -28
  129. data/spec/rails_best_practices/reviews/use_say_with_time_in_migrations_review_spec.rb +9 -9
  130. data/spec/rails_best_practices/reviews/use_scope_access_review_spec.rb +23 -23
  131. data/spec/rails_best_practices/reviews/use_turbo_sprockets_rails3_review_spec.rb +6 -6
  132. data/spec/spec_helper.rb +1 -1
  133. metadata +7 -7
@@ -16,7 +16,7 @@ module RailsBestPractices
16
16
  class UseSayWithTimeInMigrationsReview < Review
17
17
  interesting_nodes :defs
18
18
  interesting_files MIGRATION_FILES
19
- url "https://rails-bestpractices.com/posts/2010/08/19/use-say-and-say_with_time-in-migrations-to-make-a-useful-migration-log/"
19
+ url 'https://rails-bestpractices.com/posts/2010/08/19/use-say-and-say_with_time-in-migrations-to-make-a-useful-migration-log/'
20
20
 
21
21
  WITH_SAY_METHODS = %w(say say_with_time)
22
22
 
@@ -38,7 +38,7 @@ module RailsBestPractices
38
38
  child_node
39
39
  end
40
40
  if :call == receiver_node.sexp_type
41
- add_error("use say with time in migrations", node.file, child_node.line_number)
41
+ add_error('use say with time in migrations', node.file, child_node.line_number)
42
42
  end
43
43
  end
44
44
  end
@@ -16,7 +16,7 @@ module RailsBestPractices
16
16
  class UseScopeAccessReview < Review
17
17
  interesting_nodes :if, :unless, :elsif, :ifop, :if_mod, :unless_mod
18
18
  interesting_files CONTROLLER_FILES
19
- url "https://rails-bestpractices.com/posts/2010/07/20/use-scope-access/"
19
+ url 'https://rails-bestpractices.com/posts/2010/07/20/use-scope-access/'
20
20
 
21
21
  # check if node.
22
22
  #
@@ -24,7 +24,7 @@ module RailsBestPractices
24
24
  # and there is a redirect_to method call in the block body,
25
25
  # then it should be replaced by using scope access.
26
26
  add_callback :start_if, :start_unless, :start_elsif, :start_ifop, :start_if_mod, :start_unless_mod do |node|
27
- add_error "use scope access" if current_user_redirect?(node)
27
+ add_error 'use scope access' if current_user_redirect?(node)
28
28
  end
29
29
 
30
30
  private
@@ -41,15 +41,15 @@ module RailsBestPractices
41
41
  node.conditional_statement.all_conditions
42
42
  end
43
43
  results = all_conditions.map do |condition_node|
44
- ["==", "!="].include?(condition_node.message.to_s) &&
44
+ ['==', '!='].include?(condition_node.message.to_s) &&
45
45
  (current_user?(condition_node.argument) || current_user?(condition_node.receiver))
46
46
  end
47
- results.any? { |result| result == true } && node.body.grep_node(message: "redirect_to")
47
+ results.any? { |result| result == true } && node.body.grep_node(message: 'redirect_to')
48
48
  end
49
49
 
50
50
  # check a call node to see if it uses current_user, or current_user.id.
51
51
  def current_user?(node)
52
- "current_user" == node.to_s || ("current_user" == node.receiver.to_s && "id" == node.message.to_s)
52
+ 'current_user' == node.to_s || ('current_user' == node.receiver.to_s && 'id' == node.message.to_s)
53
53
  end
54
54
  end
55
55
  end
@@ -12,13 +12,13 @@ module RailsBestPractices
12
12
  class UseTurboSprocketsRails3Review < Review
13
13
  interesting_nodes :command
14
14
  interesting_files CAPFILE
15
- url "https://rails-bestpractices.com/posts/2012/11/23/speed-up-assets-precompile-with-turbo-sprockets-rails3/"
15
+ url 'https://rails-bestpractices.com/posts/2012/11/23/speed-up-assets-precompile-with-turbo-sprockets-rails3/'
16
16
 
17
17
  # check command node to see if load 'deploy/assets'
18
18
  add_callback :start_command do |node|
19
- if Prepares.gems.gem_version("rails").to_i == 3
20
- if !Prepares.gems.has_gem?("turbo-sprockets-rails3") && "load" == node.message.to_s && "deploy/assets" == node.arguments.to_s
21
- add_error "speed up assets precompile with turbo-sprockets-rails3"
19
+ if Prepares.gems.gem_version('rails').to_i == 3
20
+ if !Prepares.gems.has_gem?('turbo-sprockets-rails3') && 'load' == node.message.to_s && 'deploy/assets' == node.arguments.to_s
21
+ add_error 'speed up assets precompile with turbo-sprockets-rails3'
22
22
  end
23
23
  end
24
24
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module RailsBestPractices
3
- VERSION = "1.19.0"
3
+ VERSION = '1.19.1'
4
4
  end
@@ -1,40 +1,40 @@
1
1
  # -*- encoding: utf-8 -*-
2
- require File.expand_path("../lib/rails_best_practices/version", __FILE__)
2
+ require File.expand_path('../lib/rails_best_practices/version', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
- s.name = "rails_best_practices"
5
+ s.name = 'rails_best_practices'
6
6
  s.version = RailsBestPractices::VERSION
7
7
  s.platform = Gem::Platform::RUBY
8
- s.authors = ["Richard Huang"]
9
- s.email = ["flyerhzm@gmail.com"]
10
- s.homepage = "http://rails-bestpractices.com"
11
- s.summary = "a code metric tool for rails codes."
12
- s.description = "a code metric tool for rails codes, written in Ruby."
8
+ s.authors = ['Richard Huang']
9
+ s.email = ['flyerhzm@gmail.com']
10
+ s.homepage = 'http://rails-bestpractices.com'
11
+ s.summary = 'a code metric tool for rails codes.'
12
+ s.description = 'a code metric tool for rails codes, written in Ruby.'
13
13
  s.license = 'MIT'
14
14
 
15
- s.required_ruby_version = ">= 1.9.0"
16
- s.required_rubygems_version = ">= 1.3.6"
15
+ s.required_ruby_version = '>= 1.9.0'
16
+ s.required_rubygems_version = '>= 1.3.6'
17
17
 
18
- s.add_dependency("activesupport")
18
+ s.add_dependency('activesupport')
19
19
  # TODO: add a dependency for Rails >= 3 ?
20
- s.add_dependency("code_analyzer", ">= 0.4.8")
21
- s.add_dependency("erubis")
22
- s.add_dependency("i18n")
23
- s.add_dependency("require_all")
24
- s.add_dependency("ruby-progressbar")
25
- s.add_dependency("json")
26
-
27
- s.add_development_dependency("rake", '< 11.0')
28
- s.add_development_dependency("rspec")
29
- s.add_development_dependency("haml")
30
- s.add_development_dependency("slim")
31
- s.add_development_dependency("bundler")
32
- s.add_development_dependency("awesome_print")
20
+ s.add_dependency('code_analyzer', '>= 0.4.8')
21
+ s.add_dependency('erubis')
22
+ s.add_dependency('i18n')
23
+ s.add_dependency('require_all', '~> 1.5.0')
24
+ s.add_dependency('ruby-progressbar')
25
+ s.add_dependency('json')
26
+
27
+ s.add_development_dependency('rake', '< 11.0')
28
+ s.add_development_dependency('rspec')
29
+ s.add_development_dependency('haml')
30
+ s.add_development_dependency('slim')
31
+ s.add_development_dependency('bundler')
32
+ s.add_development_dependency('awesome_print')
33
33
 
34
34
  s.files = `git ls-files`.split("\n")
35
35
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
36
36
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
37
- s.require_paths = ["lib", "assets"]
37
+ s.require_paths = ['lib', 'assets']
38
38
 
39
39
  s.post_install_message = <<-POST_INSTALL_MESSAGE
40
40
  #{"*" * 80}
@@ -3,7 +3,7 @@ require 'tmpdir'
3
3
 
4
4
  module RailsBestPractices
5
5
  describe Analyzer do
6
- subject { Analyzer.new(".") }
6
+ subject { Analyzer.new('.') }
7
7
 
8
8
  describe '::new' do
9
9
  it 'should expand a relative path to an absolute' do
@@ -11,37 +11,37 @@ module RailsBestPractices
11
11
  end
12
12
  end
13
13
 
14
- describe "expand_dirs_to_files" do
15
- it "should expand all files in spec directory" do
14
+ describe 'expand_dirs_to_files' do
15
+ it 'should expand all files in spec directory' do
16
16
  dir = File.dirname(__FILE__)
17
17
  expect(subject.expand_dirs_to_files(dir)).to be_include(dir + '/analyzer_spec.rb')
18
18
  end
19
19
  end
20
20
 
21
- describe "file_sort" do
22
- it "should get models first, mailers, helpers and then others" do
23
- 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"]
24
- 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"])
21
+ describe 'file_sort' do
22
+ it 'should get models first, mailers, helpers and then others' do
23
+ 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']
24
+ 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'])
25
25
  end
26
26
  end
27
27
 
28
- describe "file_ignore" do
28
+ describe 'file_ignore' do
29
29
  before do
30
- @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"]
31
- @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"]
30
+ @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']
31
+ @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']
32
32
  end
33
33
 
34
- it "should ignore lib" do
34
+ it 'should ignore lib' do
35
35
  expect(subject.file_ignore(@all, 'lib/')).to eq(@filtered)
36
36
  end
37
37
 
38
- it "should ignore regexp patterns" do
38
+ it 'should ignore regexp patterns' do
39
39
  expect(subject.file_ignore(@all, /lib/)).to eq(@filtered)
40
40
  end
41
41
  end
42
42
 
43
- describe "output" do
44
- subject { described_class.new(".", "format" => format) }
43
+ describe 'output' do
44
+ subject { described_class.new('.', 'format' => format) }
45
45
 
46
46
  before do
47
47
  subject.stub(:output_terminal_errors)
@@ -52,49 +52,49 @@ module RailsBestPractices
52
52
  subject.output
53
53
  end
54
54
 
55
- context "when format is not set" do
55
+ context 'when format is not set' do
56
56
  let(:format) { nil }
57
57
 
58
- it "runs text output" do
58
+ it 'runs text output' do
59
59
  expect(subject).to have_received(:output_terminal_errors)
60
60
  end
61
61
  end
62
62
 
63
- context "when format is yaml" do
64
- let(:format) { "yaml" }
63
+ context 'when format is yaml' do
64
+ let(:format) { 'yaml' }
65
65
 
66
- it "runs yaml output" do
66
+ it 'runs yaml output' do
67
67
  expect(subject).to have_received(:output_yaml_errors)
68
68
  end
69
69
  end
70
70
 
71
- context "when format is html" do
72
- let(:format) { "html" }
71
+ context 'when format is html' do
72
+ let(:format) { 'html' }
73
73
 
74
- it "runs html output" do
74
+ it 'runs html output' do
75
75
  expect(subject).to have_received(:output_html_errors)
76
76
  end
77
77
  end
78
78
 
79
- context "when format is xml" do
80
- let(:format) { "xml" }
79
+ context 'when format is xml' do
80
+ let(:format) { 'xml' }
81
81
 
82
- it "runs xml output" do
82
+ it 'runs xml output' do
83
83
  expect(subject).to have_received(:output_xml_errors)
84
84
  end
85
85
  end
86
86
 
87
87
  end
88
88
 
89
- describe "output_terminal_errors" do
90
- it "should output errors in terminal" do
89
+ describe 'output_terminal_errors' do
90
+ it 'should output errors in terminal' do
91
91
  check1 = Reviews::LawOfDemeterReview.new
92
92
  check2 = Reviews::UseQueryAttributeReview.new
93
93
  runner = Core::Runner.new(reviews: [check1, check2])
94
- check1.add_error "law of demeter", "app/models/user.rb", 10
95
- check2.add_error "use query attribute", "app/models/post.rb", 100
94
+ check1.add_error 'law of demeter', 'app/models/user.rb', 10
95
+ check2.add_error 'use query attribute', 'app/models/post.rb', 100
96
96
  subject.runner = runner
97
- subject.instance_variable_set("@options", {"without-color" => false})
97
+ subject.instance_variable_set('@options', {'without-color' => false})
98
98
 
99
99
  $origin_stdout = $stdout
100
100
  $stdout = StringIO.new
@@ -109,13 +109,13 @@ module RailsBestPractices
109
109
  end
110
110
  end
111
111
 
112
- describe "output_json_errors" do
113
- let(:output_file) { "rails_best_practices_output.json" }
112
+ describe 'output_json_errors' do
113
+ let(:output_file) { 'rails_best_practices_output.json' }
114
114
 
115
115
  subject do
116
- described_class.new(".", {
117
- "format" => "json",
118
- "output-file" => output_file
116
+ described_class.new('.', {
117
+ 'format' => 'json',
118
+ 'output-file' => output_file
119
119
  })
120
120
  end
121
121
 
@@ -125,8 +125,8 @@ module RailsBestPractices
125
125
  let(:result) { File.read(output_file) }
126
126
 
127
127
  before do
128
- check1.add_error("law of demeter", "app/models/user.rb", 10)
129
- check2.add_error("use query attribute", "app/models/post.rb", 100)
128
+ check1.add_error('law of demeter', 'app/models/user.rb', 10)
129
+ check2.add_error('use query attribute', 'app/models/post.rb', 100)
130
130
  subject.runner = runner
131
131
  subject.output
132
132
  end
@@ -135,7 +135,7 @@ module RailsBestPractices
135
135
  File.delete(output_file) if File.exists?(output_file)
136
136
  end
137
137
 
138
- it "saves output as json into output file" do
138
+ it 'saves output as json into output file' do
139
139
  expect(result).to eq '[{"filename":"app/models/user.rb","line_number":"10","message":"law of demeter"},{"filename":"app/models/post.rb","line_number":"100","message":"use query attribute"}]'
140
140
  end
141
141
  end
@@ -146,7 +146,7 @@ module RailsBestPractices
146
146
  Dir.mktmpdir { |random_dir|
147
147
  Dir.mkdir(File.join(random_dir, 'vendor'))
148
148
  Dir.mkdir(File.join(random_dir, 'vendor', 'my_project'))
149
- File.open(File.join(random_dir, 'vendor', 'my_project', 'my_file.rb'), "w") { |file| file << 'woot' }
149
+ File.open(File.join(random_dir, 'vendor', 'my_project', 'my_file.rb'), 'w') { |file| file << 'woot' }
150
150
  analyzer = Analyzer.new(File.join(random_dir, 'vendor', 'my_project'))
151
151
  expect(analyzer.parse_files).to be_include File.join(random_dir, 'vendor', 'my_project', 'my_file.rb')
152
152
  }
@@ -156,7 +156,7 @@ module RailsBestPractices
156
156
  Dir.mktmpdir { |random_dir|
157
157
  Dir.mkdir(File.join(random_dir, 'spec'))
158
158
  Dir.mkdir(File.join(random_dir, 'spec', 'my_project'))
159
- File.open(File.join(random_dir, 'spec', 'my_project', 'my_file.rb'), "w") { |file| file << 'woot' }
159
+ File.open(File.join(random_dir, 'spec', 'my_project', 'my_file.rb'), 'w') { |file| file << 'woot' }
160
160
  analyzer = Analyzer.new(File.join(random_dir, 'spec', 'my_project'))
161
161
  expect(analyzer.parse_files).to be_include File.join(random_dir, 'spec', 'my_project', 'my_file.rb')
162
162
  }
@@ -166,7 +166,7 @@ module RailsBestPractices
166
166
  Dir.mktmpdir { |random_dir|
167
167
  Dir.mkdir(File.join(random_dir, 'test'))
168
168
  Dir.mkdir(File.join(random_dir, 'test', 'my_project'))
169
- File.open(File.join(random_dir, 'test', 'my_project', 'my_file.rb'), "w") { |file| file << 'woot' }
169
+ File.open(File.join(random_dir, 'test', 'my_project', 'my_file.rb'), 'w') { |file| file << 'woot' }
170
170
  analyzer = Analyzer.new(File.join(random_dir, 'test', 'my_project'))
171
171
  expect(analyzer.parse_files).to be_include File.join(random_dir, 'test', 'my_project', 'my_file.rb')
172
172
  }
@@ -176,7 +176,7 @@ module RailsBestPractices
176
176
  Dir.mktmpdir { |random_dir|
177
177
  Dir.mkdir(File.join(random_dir, 'test'))
178
178
  Dir.mkdir(File.join(random_dir, 'test', 'my_project'))
179
- File.open(File.join(random_dir, 'test', 'my_project', 'my_file.rb'), "w") { |file| file << 'woot' }
179
+ File.open(File.join(random_dir, 'test', 'my_project', 'my_file.rb'), 'w') { |file| file << 'woot' }
180
180
  analyzer = Analyzer.new(File.join(random_dir, 'test', 'my_project'))
181
181
  expect(analyzer.parse_files).to be_include File.join(random_dir, 'test', 'my_project', 'my_file.rb')
182
182
  }
@@ -186,7 +186,7 @@ module RailsBestPractices
186
186
  Dir.mktmpdir { |random_dir|
187
187
  Dir.mkdir(File.join(random_dir, 'tmp'))
188
188
  Dir.mkdir(File.join(random_dir, 'tmp', 'my_project'))
189
- File.open(File.join(random_dir, 'tmp', 'my_project', 'my_file.rb'), "w") { |file| file << 'woot' }
189
+ File.open(File.join(random_dir, 'tmp', 'my_project', 'my_file.rb'), 'w') { |file| file << 'woot' }
190
190
  analyzer = Analyzer.new(File.join(random_dir, 'tmp', 'my_project'))
191
191
  expect(analyzer.parse_files).to be_include File.join(random_dir, 'tmp', 'my_project', 'my_file.rb')
192
192
  }
@@ -4,8 +4,8 @@ module RailsBestPractices::Core
4
4
  describe Check do
5
5
  let(:check) { Check.new }
6
6
 
7
- context "debug" do
8
- it "should be debug mode" do
7
+ context 'debug' do
8
+ it 'should be debug mode' do
9
9
  Check.debug
10
10
  expect(Check).to be_debug
11
11
  Check.class_eval { @debug = false }
@@ -4,15 +4,15 @@ module RailsBestPractices::Core
4
4
  describe ChecksLoader do
5
5
  let(:checks_loader) { ChecksLoader.new(RailsBestPractices::Analyzer::DEFAULT_CONFIG) }
6
6
 
7
- describe "load_lexicals" do
8
- it "should load lexical checks from the default configuration" do
7
+ describe 'load_lexicals' do
8
+ it 'should load lexical checks from the default configuration' do
9
9
  lexicals = checks_loader.load_lexicals
10
10
  expect(lexicals.map(&:class)).to include(RailsBestPractices::Lexicals::RemoveTrailingWhitespaceCheck)
11
11
  end
12
12
  end
13
13
 
14
- describe "load_reviews" do
15
- it "should load the reviews from the default the configuration" do
14
+ describe 'load_reviews' do
15
+ it 'should load the reviews from the default the configuration' do
16
16
  reviews = checks_loader.load_reviews
17
17
  expect(reviews.map(&:class)).to include(RailsBestPractices::Reviews::AlwaysAddDbIndexReview)
18
18
  end
@@ -2,29 +2,29 @@ require 'spec_helper'
2
2
 
3
3
  module RailsBestPractices::Core
4
4
  describe Error do
5
- it "should return error with filename, line number and message" do
5
+ it 'should return error with filename, line number and message' do
6
6
  expect(Error.new(
7
- filename: "app/models/user.rb",
8
- line_number: "100",
9
- message: "not good",
10
- type: "BogusReview").to_s).to eq("app/models/user.rb:100 - not good")
7
+ filename: 'app/models/user.rb',
8
+ line_number: '100',
9
+ message: 'not good',
10
+ type: 'BogusReview').to_s).to eq('app/models/user.rb:100 - not good')
11
11
  end
12
12
 
13
- it "should return short filename" do
14
- Runner.base_path = "../rails-bestpractices.com"
13
+ it 'should return short filename' do
14
+ Runner.base_path = '../rails-bestpractices.com'
15
15
  expect(Error.new(
16
- filename: "../rails-bestpractices.com/app/models/user.rb",
17
- line_number: "100",
18
- message: "not good",
19
- type: "BogusReview").short_filename).to eq("app/models/user.rb")
16
+ filename: '../rails-bestpractices.com/app/models/user.rb',
17
+ line_number: '100',
18
+ message: 'not good',
19
+ type: 'BogusReview').short_filename).to eq('app/models/user.rb')
20
20
  end
21
21
 
22
- it "should return first line number" do
22
+ it 'should return first line number' do
23
23
  expect(Error.new(
24
- filename: "app/models/user.rb",
25
- line_number: "50,70,100",
26
- message: "not good",
27
- type: "BogusReview").first_line_number).to eq("50")
24
+ filename: 'app/models/user.rb',
25
+ line_number: '50,70,100',
26
+ message: 'not good',
27
+ type: 'BogusReview').first_line_number).to eq('50')
28
28
  end
29
29
  end
30
30
  end
@@ -2,60 +2,60 @@ require 'spec_helper'
2
2
 
3
3
  module RailsBestPractices::Core
4
4
  describe Check::Exceptable do
5
- let(:method) { Method.new "BlogPost", "approve", "public", {} }
5
+ let(:method) { Method.new 'BlogPost', 'approve', 'public', {} }
6
6
 
7
- context "wildcard class and method" do
7
+ context 'wildcard class and method' do
8
8
  let(:except_method) { '*#*' }
9
9
 
10
- it "matches" do
10
+ it 'matches' do
11
11
  expect(Check::Exceptable.matches(method, except_method)).to eql true
12
12
  end
13
13
  end
14
14
 
15
- context "wildcard class and matching explicit method" do
15
+ context 'wildcard class and matching explicit method' do
16
16
  let(:except_method) { '*#approve' }
17
17
 
18
- it "matches" do
18
+ it 'matches' do
19
19
  expect(Check::Exceptable.matches(method, except_method)).to eql true
20
20
  end
21
21
  end
22
22
 
23
- context "wildcard class and non-matching explicit method" do
23
+ context 'wildcard class and non-matching explicit method' do
24
24
  let(:except_method) { '*#disapprove' }
25
25
 
26
- it "matches" do
26
+ it 'matches' do
27
27
  expect(Check::Exceptable.matches(method, except_method)).to eql false
28
28
  end
29
29
  end
30
30
 
31
- context "matching class and wildcard method" do
31
+ context 'matching class and wildcard method' do
32
32
  let(:except_method) { 'BlogPost#*' }
33
33
 
34
- it "matches" do
34
+ it 'matches' do
35
35
  expect(Check::Exceptable.matches(method, except_method)).to eql true
36
36
  end
37
37
  end
38
38
 
39
- context "non-matching class and wildcard method" do
39
+ context 'non-matching class and wildcard method' do
40
40
  let(:except_method) { 'User#*' }
41
41
 
42
- it "matches" do
42
+ it 'matches' do
43
43
  expect(Check::Exceptable.matches(method, except_method)).to eql false
44
44
  end
45
45
  end
46
46
 
47
- context "matching class and matching method" do
47
+ context 'matching class and matching method' do
48
48
  let(:except_method) { 'BlogPost#approve' }
49
49
 
50
- it "matches" do
50
+ it 'matches' do
51
51
  expect(Check::Exceptable.matches(method, except_method)).to eql true
52
52
  end
53
53
  end
54
54
 
55
- context "non-matching class and non-matching method" do
55
+ context 'non-matching class and non-matching method' do
56
56
  let(:except_method) { 'User#disapprove' }
57
57
 
58
- it "matches" do
58
+ it 'matches' do
59
59
  expect(Check::Exceptable.matches(method, except_method)).to eql false
60
60
  end
61
61
  end