rails_best_practices 0.6.6 → 0.6.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. data/Gemfile +0 -1
  2. data/README.md +28 -24
  3. data/Rakefile +0 -8
  4. data/install_supported_rubies.sh +2 -3
  5. data/lib/rails_best_practices.rb +8 -7
  6. data/lib/rails_best_practices/core.rb +1 -0
  7. data/lib/rails_best_practices/core/check.rb +68 -0
  8. data/lib/rails_best_practices/core/checking_visitor.rb +18 -15
  9. data/lib/rails_best_practices/core/runner.rb +22 -12
  10. data/lib/rails_best_practices/core/visitable_sexp.rb +6 -2
  11. data/lib/rails_best_practices/prepares.rb +11 -0
  12. data/lib/rails_best_practices/prepares/mailer_prepare.rb +33 -0
  13. data/lib/rails_best_practices/prepares/model_prepare.rb +60 -0
  14. data/lib/rails_best_practices/reviews.rb +23 -0
  15. data/lib/rails_best_practices/{checks/add_model_virtual_attribute_check.rb → reviews/add_model_virtual_attribute_review.rb} +6 -9
  16. data/lib/rails_best_practices/{checks/always_add_db_index_check.rb → reviews/always_add_db_index_review.rb} +9 -12
  17. data/lib/rails_best_practices/{checks/dry_bundler_in_capistrano_check.rb → reviews/dry_bundler_in_capistrano_review.rb} +8 -11
  18. data/lib/rails_best_practices/{checks/isolate_seed_data_check.rb → reviews/isolate_seed_data_review.rb} +11 -14
  19. data/lib/rails_best_practices/{checks/keep_finders_on_their_own_model_check.rb → reviews/keep_finders_on_their_own_model_review.rb} +7 -10
  20. data/lib/rails_best_practices/{checks/law_of_demeter_check.rb → reviews/law_of_demeter_review.rb} +10 -14
  21. data/lib/rails_best_practices/{checks/move_code_into_controller_check.rb → reviews/move_code_into_controller_review.rb} +8 -11
  22. data/lib/rails_best_practices/{checks/move_code_into_helper_check.rb → reviews/move_code_into_helper_review.rb} +7 -10
  23. data/lib/rails_best_practices/{checks/move_code_into_model_check.rb → reviews/move_code_into_model_review.rb} +7 -10
  24. data/lib/rails_best_practices/{checks/move_finder_to_named_scope_check.rb → reviews/move_finder_to_named_scope_review.rb} +7 -10
  25. data/lib/rails_best_practices/{checks/move_model_logic_into_model_check.rb → reviews/move_model_logic_into_model_review.rb} +8 -11
  26. data/lib/rails_best_practices/{checks/needless_deep_nesting_check.rb → reviews/needless_deep_nesting_review.rb} +8 -11
  27. data/lib/rails_best_practices/{checks/not_use_default_route_check.rb → reviews/not_use_default_route_review.rb} +7 -10
  28. data/lib/rails_best_practices/{checks/overuse_route_customizations_check.rb → reviews/overuse_route_customizations_review.rb} +10 -13
  29. data/lib/rails_best_practices/{checks/replace_complex_creation_with_factory_method_check.rb → reviews/replace_complex_creation_with_factory_method_review.rb} +8 -11
  30. data/lib/rails_best_practices/{checks/replace_instance_variable_with_local_variable_check.rb → reviews/replace_instance_variable_with_local_variable_review.rb} +7 -10
  31. data/lib/rails_best_practices/reviews/review.rb +92 -0
  32. data/lib/rails_best_practices/{checks/use_before_filter_check.rb → reviews/use_before_filter_review.rb} +8 -11
  33. data/lib/rails_best_practices/{checks/use_model_association_check.rb → reviews/use_model_association_review.rb} +8 -11
  34. data/lib/rails_best_practices/{checks/use_observer_check.rb → reviews/use_observer_review.rb} +14 -41
  35. data/lib/rails_best_practices/{checks/use_query_attribute_check.rb → reviews/use_query_attribute_review.rb} +20 -16
  36. data/lib/rails_best_practices/{checks/use_say_with_time_in_migrations_check.rb → reviews/use_say_with_time_in_migrations_review.rb} +8 -11
  37. data/lib/rails_best_practices/{checks/use_scope_access_check.rb → reviews/use_scope_access_review.rb} +8 -11
  38. data/lib/rails_best_practices/version.rb +1 -1
  39. data/rails_best_practices.gemspec +3 -2
  40. data/rails_best_practices.yml +22 -22
  41. data/rake_rubies.sh +3 -2
  42. data/spec/rails_best_practices/core/check_spec.rb +41 -0
  43. data/spec/rails_best_practices/core/checking_visitor_spec.rb +78 -0
  44. data/spec/rails_best_practices/core/visitable_sexp_spec.rb +39 -36
  45. data/spec/rails_best_practices/prepares/mailer_prepare_spec.rb +14 -0
  46. data/spec/rails_best_practices/prepares/model_prepare_spec.rb +22 -0
  47. data/spec/rails_best_practices/{checks/add_model_virtual_attribute_check_spec.rb → reviews/add_model_virtual_attribute_review_spec.rb} +17 -25
  48. data/spec/rails_best_practices/{checks/always_add_db_index_check_spec.rb → reviews/always_add_db_index_review_spec.rb} +28 -41
  49. data/spec/rails_best_practices/{checks/dry_bundler_in_capistrano_check_spec.rb → reviews/dry_bundler_in_capistrano_review_spec.rb} +7 -11
  50. data/spec/rails_best_practices/{checks/isolate_seed_data_check_spec.rb → reviews/isolate_seed_data_review_spec.rb} +13 -20
  51. data/spec/rails_best_practices/{checks/keep_finders_on_their_own_model_check_spec.rb → reviews/keep_finders_on_their_own_model_review_spec.rb} +16 -24
  52. data/spec/rails_best_practices/{checks/law_of_demeter_check_spec.rb → reviews/law_of_demeter_review_spec.rb} +24 -26
  53. data/spec/rails_best_practices/reviews/move_code_into_controller_review_spec.rb +29 -0
  54. data/spec/rails_best_practices/reviews/move_code_into_helper_review_spec.rb +24 -0
  55. data/spec/rails_best_practices/{checks/move_code_into_model_check_spec.rb → reviews/move_code_into_model_review_spec.rb} +12 -18
  56. data/spec/rails_best_practices/{checks/move_finder_to_named_scope_check_spec.rb → reviews/move_finder_to_named_scope_review_spec.rb} +12 -16
  57. data/spec/rails_best_practices/{checks/move_model_logic_into_model_check_spec.rb → reviews/move_model_logic_into_model_review_spec.rb} +7 -11
  58. data/spec/rails_best_practices/{checks/needless_deep_nesting_check_spec.rb → reviews/needless_deep_nesting_review_spec.rb} +26 -37
  59. data/spec/rails_best_practices/{checks/not_use_default_route_check_spec.rb → reviews/not_use_default_route_review_spec.rb} +13 -19
  60. data/spec/rails_best_practices/{checks/overuse_route_customizations_check_spec.rb → reviews/overuse_route_customizations_review_spec.rb} +27 -39
  61. data/spec/rails_best_practices/{checks/replace_complex_creation_with_factory_method_check_spec.rb → reviews/replace_complex_creation_with_factory_method_review_spec.rb} +10 -15
  62. data/spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb +31 -0
  63. data/spec/rails_best_practices/reviews/review_spec.rb +11 -0
  64. data/spec/rails_best_practices/{checks/use_before_filter_check_spec.rb → reviews/use_before_filter_review_spec.rb} +11 -17
  65. data/spec/rails_best_practices/{checks/use_model_association_check_spec.rb → reviews/use_model_association_review_spec.rb} +12 -18
  66. data/spec/rails_best_practices/{checks/use_observer_check_spec.rb → reviews/use_observer_review_spec.rb} +28 -29
  67. data/spec/rails_best_practices/reviews/use_query_attribute_review_spec.rb +190 -0
  68. data/spec/rails_best_practices/{checks/use_say_with_time_in_migrations_check_spec.rb → reviews/use_say_with_time_in_migrations_review_spec.rb} +14 -23
  69. data/spec/rails_best_practices/{checks/use_scope_access_check_spec.rb → reviews/use_scope_access_review_spec.rb} +28 -37
  70. data/spec/rails_best_practices_spec.rb +4 -4
  71. data/spec/spec_helper.rb +1 -0
  72. metadata +128 -102
  73. data/lib/rails_best_practices/checks.rb +0 -23
  74. data/lib/rails_best_practices/checks/check.rb +0 -203
  75. data/spec/rails_best_practices/checks/check_spec.rb +0 -57
  76. data/spec/rails_best_practices/checks/move_code_into_controller_check_spec.rb +0 -33
  77. data/spec/rails_best_practices/checks/move_code_into_helper_check_spec.rb +0 -28
  78. data/spec/rails_best_practices/checks/replace_instance_variable_with_local_variable_check_spec.rb +0 -36
  79. data/spec/rails_best_practices/checks/use_query_attribute_check_spec.rb +0 -192
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe RailsBestPractices::Reviews::MoveCodeIntoHelperReview do
4
+ let(:runner) { RailsBestPractices::Core::Runner.new(:reviews => RailsBestPractices::Reviews::MoveCodeIntoHelperReview.new('array_count' => 2)) }
5
+
6
+ it "should move code into helper" do
7
+ content = <<-EOF
8
+ <%= select_tag :state, options_for_select( [[t(:draft), "draft"],
9
+ [t(:published), "published"]],
10
+ params[:default_state] ) %>
11
+ EOF
12
+ runner.review('app/views/posts/show.html.erb', content)
13
+ runner.should have(1).errors
14
+ runner.errors[0].to_s.should == "app/views/posts/show.html.erb:3 - move code into helper (array_count >= 2)"
15
+ end
16
+
17
+ it "should not move code into helper with simple arguments" do
18
+ content = <<-EOF
19
+ <%= select_tag :state, options_for_select( Post.STATES ) %>
20
+ EOF
21
+ runner.review('app/views/posts/show.html.erb', content)
22
+ runner.should have(0).errors
23
+ end
24
+ end
@@ -1,9 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe RailsBestPractices::Checks::MoveCodeIntoModelCheck do
4
- before(:each) do
5
- @runner = RailsBestPractices::Core::Runner.new(RailsBestPractices::Checks::MoveCodeIntoModelCheck.new)
6
- end
3
+ describe RailsBestPractices::Reviews::MoveCodeIntoModelReview do
4
+ let(:runner) { RailsBestPractices::Core::Runner.new(:reviews => RailsBestPractices::Reviews::MoveCodeIntoModelReview.new) }
7
5
 
8
6
  it "should move code into model" do
9
7
  content =<<-EOF
@@ -11,10 +9,9 @@ describe RailsBestPractices::Checks::MoveCodeIntoModelCheck do
11
9
  <%= link_to 'Edit this post', edit_post_url(@post) %>
12
10
  <% end %>
13
11
  EOF
14
- @runner.review('app/views/posts/show.html.erb', content)
15
- errors = @runner.errors
16
- errors.should_not be_empty
17
- errors[0].to_s.should == "app/views/posts/show.html.erb:1 - move code into model (@post use_count > 2)"
12
+ runner.review('app/views/posts/show.html.erb', content)
13
+ runner.should have(1).errors
14
+ runner.errors[0].to_s.should == "app/views/posts/show.html.erb:1 - move code into model (@post use_count > 2)"
18
15
  end
19
16
 
20
17
  it "should move code into model with haml" do
@@ -22,10 +19,9 @@ describe RailsBestPractices::Checks::MoveCodeIntoModelCheck do
22
19
  - if current_user && (current_user == @post.user || @post.editors.include?(current_user))
23
20
  = link_to 'Edit this post', edit_post_url(@post)
24
21
  EOF
25
- @runner.review('app/views/posts/show.html.haml', content)
26
- errors = @runner.errors
27
- errors.should_not be_empty
28
- errors[0].to_s.should == "app/views/posts/show.html.haml:1 - move code into model (@post use_count > 2)"
22
+ runner.review('app/views/posts/show.html.haml', content)
23
+ runner.should have(1).errors
24
+ runner.errors[0].to_s.should == "app/views/posts/show.html.haml:1 - move code into model (@post use_count > 2)"
29
25
  end
30
26
 
31
27
  it "should move code into model only review for current if conditional statement" do
@@ -37,9 +33,8 @@ describe RailsBestPractices::Checks::MoveCodeIntoModelCheck do
37
33
  <% end %>
38
34
  <% end %>
39
35
  EOF
40
- @runner.review('app/views/posts/show.html.erb', content)
41
- errors = @runner.errors
42
- errors.should be_empty
36
+ runner.review('app/views/posts/show.html.erb', content)
37
+ runner.should have(0).errors
43
38
  end
44
39
 
45
40
  it "should not move code into model" do
@@ -48,8 +43,7 @@ describe RailsBestPractices::Checks::MoveCodeIntoModelCheck do
48
43
  <%= link_to 'Edit this post', edit_post_url(@post) %>
49
44
  <% end %>
50
45
  EOF
51
- @runner.review('app/views/posts/show.html.erb', content)
52
- errors = @runner.errors
53
- errors.should be_empty
46
+ runner.review('app/views/posts/show.html.erb', content)
47
+ runner.should have(0).errors
54
48
  end
55
49
  end
@@ -1,9 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe RailsBestPractices::Checks::MoveFinderToNamedScopeCheck do
4
- before(:each) do
5
- @runner = RailsBestPractices::Core::Runner.new(RailsBestPractices::Checks::MoveFinderToNamedScopeCheck.new)
6
- end
3
+ describe RailsBestPractices::Reviews::MoveFinderToNamedScopeReview do
4
+ let(:runner) { RailsBestPractices::Core::Runner.new(:reviews => RailsBestPractices::Reviews::MoveFinderToNamedScopeReview.new) }
7
5
 
8
6
  it "should move finder to named_scope" do
9
7
  content = <<-EOF
@@ -20,11 +18,10 @@ describe RailsBestPractices::Checks::MoveFinderToNamedScopeCheck do
20
18
  end
21
19
  end
22
20
  EOF
23
- @runner.review('app/controllers/posts_controller.rb', content)
24
- errors = @runner.errors
25
- errors.size.should == 2
26
- errors[0].to_s.should == "app/controllers/posts_controller.rb:4 - move finder to named_scope"
27
- errors[1].to_s.should == "app/controllers/posts_controller.rb:8 - move finder to named_scope"
21
+ runner.review('app/controllers/posts_controller.rb', content)
22
+ runner.should have(2).errors
23
+ runner.errors[0].to_s.should == "app/controllers/posts_controller.rb:4 - move finder to named_scope"
24
+ runner.errors[1].to_s.should == "app/controllers/posts_controller.rb:8 - move finder to named_scope"
28
25
  end
29
26
 
30
27
  it "should not move simple finder" do
@@ -41,8 +38,8 @@ describe RailsBestPractices::Checks::MoveFinderToNamedScopeCheck do
41
38
  end
42
39
  end
43
40
  EOF
44
- @runner.review('app/controllers/posts_controller.rb', content)
45
- @runner.errors.should be_empty
41
+ runner.review('app/controllers/posts_controller.rb', content)
42
+ runner.should have(0).errors
46
43
  end
47
44
 
48
45
  it "should not move namd_scope" do
@@ -55,8 +52,8 @@ describe RailsBestPractices::Checks::MoveFinderToNamedScopeCheck do
55
52
  end
56
53
  end
57
54
  EOF
58
- @runner.review('app/controllers/posts_controller.rb', content)
59
- @runner.errors.should be_empty
55
+ runner.review('app/controllers/posts_controller.rb', content)
56
+ runner.should have(0).errors
60
57
  end
61
58
 
62
59
  it "should not review model file" do
@@ -75,8 +72,7 @@ describe RailsBestPractices::Checks::MoveFinderToNamedScopeCheck do
75
72
 
76
73
  end
77
74
  EOF
78
- @runner.review('app/model/post.rb', content)
79
- @runner.errors.should be_empty
80
-
75
+ runner.review('app/model/post.rb', content)
76
+ runner.should have(0).errors
81
77
  end
82
78
  end
@@ -1,9 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe RailsBestPractices::Checks::MoveModelLogicIntoModelCheck do
4
- before(:each) do
5
- @runner = RailsBestPractices::Core::Runner.new(RailsBestPractices::Checks::MoveModelLogicIntoModelCheck.new)
6
- end
3
+ describe RailsBestPractices::Reviews::MoveModelLogicIntoModelReview do
4
+ let(:runner) { RailsBestPractices::Core::Runner.new(:reviews => RailsBestPractices::Reviews::MoveModelLogicIntoModelReview.new) }
7
5
 
8
6
  it "should move model logic into model" do
9
7
  content = <<-EOF
@@ -23,10 +21,9 @@ describe RailsBestPractices::Checks::MoveModelLogicIntoModelCheck do
23
21
  redirect_to post_url(@post)
24
22
  end
25
23
  EOF
26
- @runner.review('app/controllers/posts_controller.rb', content)
27
- errors = @runner.errors
28
- errors.should_not be_empty
29
- errors[0].to_s.should == "app/controllers/posts_controller.rb:3 - move model logic into model (@post use_count > 4)"
24
+ runner.review('app/controllers/posts_controller.rb', content)
25
+ runner.should have(1).errors
26
+ runner.errors[0].to_s.should == "app/controllers/posts_controller.rb:3 - move model logic into model (@post use_count > 4)"
30
27
  end
31
28
 
32
29
  it "should not move model logic into model with simple model calling" do
@@ -42,8 +39,7 @@ describe RailsBestPractices::Checks::MoveModelLogicIntoModelCheck do
42
39
  redirect_to post_url(@post)
43
40
  end
44
41
  EOF
45
- @runner.review('app/controllers/posts_controller.rb', content)
46
- errors = @runner.errors
47
- errors.should be_empty
42
+ runner.review('app/controllers/posts_controller.rb', content)
43
+ runner.should have(0).errors
48
44
  end
49
45
  end
@@ -1,9 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe RailsBestPractices::Checks::NeedlessDeepNestingCheck do
4
- before(:each) do
5
- @runner = RailsBestPractices::Core::Runner.new(RailsBestPractices::Checks::NeedlessDeepNestingCheck.new)
6
- end
3
+ describe RailsBestPractices::Reviews::NeedlessDeepNestingReview do
4
+ let(:runner) { RailsBestPractices::Core::Runner.new(:reviews => RailsBestPractices::Reviews::NeedlessDeepNestingReview.new) }
7
5
 
8
6
  describe "rails2" do
9
7
  it "should needless deep nesting" do
@@ -14,10 +12,9 @@ describe RailsBestPractices::Checks::NeedlessDeepNestingCheck do
14
12
  end
15
13
  end
16
14
  EOF
17
- @runner.review('config/routes.rb', content)
18
- errors = @runner.errors
19
- errors.should_not be_empty
20
- errors[0].to_s.should == "config/routes.rb:3 - needless deep nesting (nested_count > 2)"
15
+ runner.review('config/routes.rb', content)
16
+ runner.should have(1).errors
17
+ runner.errors[0].to_s.should == "config/routes.rb:3 - needless deep nesting (nested_count > 2)"
21
18
  end
22
19
 
23
20
  it "should needless deep nesting with resource" do
@@ -28,10 +25,9 @@ describe RailsBestPractices::Checks::NeedlessDeepNestingCheck do
28
25
  end
29
26
  end
30
27
  EOF
31
- @runner.review('config/routes.rb', content)
32
- errors = @runner.errors
33
- errors.should_not be_empty
34
- errors[0].to_s.should == "config/routes.rb:3 - needless deep nesting (nested_count > 2)"
28
+ runner.review('config/routes.rb', content)
29
+ runner.should have(1).errors
30
+ runner.errors[0].to_s.should == "config/routes.rb:3 - needless deep nesting (nested_count > 2)"
35
31
  end
36
32
 
37
33
  it "should needless deep nesting with block node" do
@@ -43,10 +39,9 @@ describe RailsBestPractices::Checks::NeedlessDeepNestingCheck do
43
39
  post.resources :votes
44
40
  end
45
41
  EOF
46
- @runner.review('config/routes.rb', content)
47
- errors = @runner.errors
48
- errors.should_not be_empty
49
- errors[0].to_s.should == "config/routes.rb:3 - needless deep nesting (nested_count > 2)"
42
+ runner.review('config/routes.rb', content)
43
+ runner.should have(1).errors
44
+ runner.errors[0].to_s.should == "config/routes.rb:3 - needless deep nesting (nested_count > 2)"
50
45
  end
51
46
 
52
47
  it "should no needless deep nesting" do
@@ -59,9 +54,8 @@ describe RailsBestPractices::Checks::NeedlessDeepNestingCheck do
59
54
  comment.resources :favorites
60
55
  end
61
56
  EOF
62
- @runner.review('config/routes.rb', content)
63
- errors = @runner.errors
64
- errors.should be_empty
57
+ runner.review('config/routes.rb', content)
58
+ runner.should have(0).errors
65
59
  end
66
60
 
67
61
  it "should no needless deep nesting with block node" do
@@ -71,9 +65,8 @@ describe RailsBestPractices::Checks::NeedlessDeepNestingCheck do
71
65
  comment.resources :votes
72
66
  end
73
67
  EOF
74
- @runner.review('config/routes.rb', content)
75
- errors = @runner.errors
76
- errors.should be_empty
68
+ runner.review('config/routes.rb', content)
69
+ runner.should have(0).errors
77
70
  end
78
71
  end
79
72
 
@@ -86,10 +79,9 @@ describe RailsBestPractices::Checks::NeedlessDeepNestingCheck do
86
79
  end
87
80
  end
88
81
  EOF
89
- @runner.review('config/routes.rb', content)
90
- errors = @runner.errors
91
- errors.should_not be_empty
92
- errors[0].to_s.should == "config/routes.rb:4 - needless deep nesting (nested_count > 2)"
82
+ runner.review('config/routes.rb', content)
83
+ runner.should have(1).errors
84
+ runner.errors[0].to_s.should == "config/routes.rb:4 - needless deep nesting (nested_count > 2)"
93
85
  end
94
86
 
95
87
  it "should needless deep nesting with resource" do
@@ -100,10 +92,9 @@ describe RailsBestPractices::Checks::NeedlessDeepNestingCheck do
100
92
  end
101
93
  end
102
94
  EOF
103
- @runner.review('config/routes.rb', content)
104
- errors = @runner.errors
105
- errors.should_not be_empty
106
- errors[0].to_s.should == "config/routes.rb:4 - needless deep nesting (nested_count > 2)"
95
+ runner.review('config/routes.rb', content)
96
+ runner.should have(1).errors
97
+ runner.errors[0].to_s.should == "config/routes.rb:4 - needless deep nesting (nested_count > 2)"
107
98
  end
108
99
 
109
100
  it "should needless deep nesting with block node" do
@@ -115,10 +106,9 @@ describe RailsBestPractices::Checks::NeedlessDeepNestingCheck do
115
106
  resources :votes
116
107
  end
117
108
  EOF
118
- @runner.review('config/routes.rb', content)
119
- errors = @runner.errors
120
- errors.should_not be_empty
121
- errors[0].to_s.should == "config/routes.rb:4 - needless deep nesting (nested_count > 2)"
109
+ runner.review('config/routes.rb', content)
110
+ runner.should have(1).errors
111
+ runner.errors[0].to_s.should == "config/routes.rb:4 - needless deep nesting (nested_count > 2)"
122
112
  end
123
113
 
124
114
  it "should no needless deep nesting" do
@@ -132,9 +122,8 @@ describe RailsBestPractices::Checks::NeedlessDeepNestingCheck do
132
122
  resources :favorites
133
123
  end
134
124
  EOF
135
- @runner.review('config/routes.rb', content)
136
- errors = @runner.errors
137
- errors.should be_empty
125
+ runner.review('config/routes.rb', content)
126
+ runner.should have(0).errors
138
127
  end
139
128
  end
140
129
  end
@@ -1,9 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe RailsBestPractices::Checks::NotUseDefaultRouteCheck do
4
- before(:each) do
5
- @runner = RailsBestPractices::Core::Runner.new(RailsBestPractices::Checks::NotUseDefaultRouteCheck.new)
6
- end
3
+ describe RailsBestPractices::Reviews::NotUseDefaultRouteReview do
4
+ let(:runner) { RailsBestPractices::Core::Runner.new(:reviews => RailsBestPractices::Reviews::NotUseDefaultRouteReview.new) }
7
5
 
8
6
  describe "rails2" do
9
7
  it "should not use default route" do
@@ -15,11 +13,10 @@ describe RailsBestPractices::Checks::NotUseDefaultRouteCheck do
15
13
  map.connect ':controller/:action/:id.:format'
16
14
  end
17
15
  EOF
18
- @runner.review('config/routes.rb', content)
19
- errors = @runner.errors
20
- errors.should_not be_empty
21
- errors[0].to_s.should == "config/routes.rb:4 - not use default route"
22
- errors[1].to_s.should == "config/routes.rb:5 - not use default route"
16
+ runner.review('config/routes.rb', content)
17
+ runner.should have(2).errors
18
+ runner.errors[0].to_s.should == "config/routes.rb:4 - not use default route"
19
+ runner.errors[1].to_s.should == "config/routes.rb:5 - not use default route"
23
20
  end
24
21
 
25
22
  it "should no not use default route" do
@@ -28,9 +25,8 @@ describe RailsBestPractices::Checks::NotUseDefaultRouteCheck do
28
25
  map.resources :posts, :member => { :push => :post }
29
26
  end
30
27
  EOF
31
- @runner.review('config/routes.rb', content)
32
- errors = @runner.errors
33
- errors.should be_empty
28
+ runner.review('config/routes.rb', content)
29
+ runner.should have(0).errors
34
30
  end
35
31
  end
36
32
 
@@ -43,10 +39,9 @@ describe RailsBestPractices::Checks::NotUseDefaultRouteCheck do
43
39
  match ':controller(/:action(/:id(.:format)))'
44
40
  end
45
41
  EOF
46
- @runner.review('config/routes.rb', content)
47
- errors = @runner.errors
48
- errors.should_not be_empty
49
- errors[0].to_s.should == "config/routes.rb:5 - not use default route"
42
+ runner.review('config/routes.rb', content)
43
+ runner.should have(1).errors
44
+ runner.errors[0].to_s.should == "config/routes.rb:5 - not use default route"
50
45
  end
51
46
 
52
47
  it "should no not use default route" do
@@ -55,9 +50,8 @@ describe RailsBestPractices::Checks::NotUseDefaultRouteCheck do
55
50
  resources :posts
56
51
  end
57
52
  EOF
58
- @runner.review('config/routes.rb', content)
59
- errors = @runner.errors
60
- errors.should be_empty
53
+ runner.review('config/routes.rb', content)
54
+ runner.should have(0).errors
61
55
  end
62
56
  end
63
57
  end
@@ -1,9 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe RailsBestPractices::Checks::OveruseRouteCustomizationsCheck do
4
- before(:each) do
5
- @runner = RailsBestPractices::Core::Runner.new(RailsBestPractices::Checks::OveruseRouteCustomizationsCheck.new)
6
- end
3
+ describe RailsBestPractices::Reviews::OveruseRouteCustomizationsReview do
4
+ let(:runner) { RailsBestPractices::Core::Runner.new(:reviews => RailsBestPractices::Reviews::OveruseRouteCustomizationsReview.new) }
7
5
 
8
6
  describe "rails2" do
9
7
  it "should overuse route customizations" do
@@ -15,10 +13,9 @@ describe RailsBestPractices::Checks::OveruseRouteCustomizationsCheck do
15
13
  :delete_comment => :delete }
16
14
  end
17
15
  EOF
18
- @runner.review('config/routes.rb', content)
19
- errors = @runner.errors
20
- errors.should_not be_empty
21
- errors[0].to_s.should == "config/routes.rb:2 - overuse route customizations (customize_count > 3)"
16
+ runner.review('config/routes.rb', content)
17
+ runner.should have(1).errors
18
+ runner.errors[0].to_s.should == "config/routes.rb:2 - overuse route customizations (customize_count > 3)"
22
19
  end
23
20
 
24
21
  it "should overuse route customizations with collection" do
@@ -30,10 +27,9 @@ describe RailsBestPractices::Checks::OveruseRouteCustomizationsCheck do
30
27
  :collection => { :comments => :get }
31
28
  end
32
29
  EOF
33
- @runner.review('config/routes.rb', content)
34
- errors = @runner.errors
35
- errors.should_not be_empty
36
- errors[0].to_s.should == "config/routes.rb:2 - overuse route customizations (customize_count > 3)"
30
+ runner.review('config/routes.rb', content)
31
+ runner.should have(1).errors
32
+ runner.errors[0].to_s.should == "config/routes.rb:2 - overuse route customizations (customize_count > 3)"
37
33
  end
38
34
 
39
35
  it "should overuse route customizations with collection 2" do
@@ -47,10 +43,9 @@ describe RailsBestPractices::Checks::OveruseRouteCustomizationsCheck do
47
43
  end
48
44
  end
49
45
  EOF
50
- @runner.review('config/routes.rb', content)
51
- errors = @runner.errors
52
- errors.should_not be_empty
53
- errors[0].to_s.should == "config/routes.rb:3 - overuse route customizations (customize_count > 3)"
46
+ runner.review('config/routes.rb', content)
47
+ runner.should have(1).errors
48
+ runner.errors[0].to_s.should == "config/routes.rb:3 - overuse route customizations (customize_count > 3)"
54
49
  end
55
50
 
56
51
  it "should not overuse route customizations without customization" do
@@ -59,9 +54,8 @@ describe RailsBestPractices::Checks::OveruseRouteCustomizationsCheck do
59
54
  map.resources :posts
60
55
  end
61
56
  EOF
62
- @runner.review('config/routes.rb', content)
63
- errors = @runner.errors
64
- errors.should be_empty
57
+ runner.review('config/routes.rb', content)
58
+ runner.should have(0).errors
65
59
  end
66
60
 
67
61
  it "should not overuse route customizations when customize route is only one" do
@@ -70,9 +64,8 @@ describe RailsBestPractices::Checks::OveruseRouteCustomizationsCheck do
70
64
  map.resources :posts, :member => { :vote => :post }
71
65
  end
72
66
  EOF
73
- @runner.review('config/routes.rb', content)
74
- errors = @runner.errors
75
- errors.should be_empty
67
+ runner.review('config/routes.rb', content)
68
+ runner.should have(0).errors
76
69
  end
77
70
 
78
71
  it "should not raise error for constants in routes" do
@@ -84,9 +77,8 @@ describe RailsBestPractices::Checks::OveruseRouteCustomizationsCheck do
84
77
  end
85
78
  end
86
79
  EOF
87
- @runner.review('config/routes.rb', content)
88
- errors = @runner.errors
89
- errors.should be_empty
80
+ runner.review('config/routes.rb', content)
81
+ runner.should have(0).errors
90
82
  end
91
83
  end
92
84
 
@@ -107,10 +99,9 @@ describe RailsBestPractices::Checks::OveruseRouteCustomizationsCheck do
107
99
  end
108
100
  end
109
101
  EOF
110
- @runner.review('config/routes.rb', content)
111
- errors = @runner.errors
112
- errors.should_not be_empty
113
- errors[0].to_s.should == "config/routes.rb:2 - overuse route customizations (customize_count > 3)"
102
+ runner.review('config/routes.rb', content)
103
+ runner.should have(1).errors
104
+ runner.errors[0].to_s.should == "config/routes.rb:2 - overuse route customizations (customize_count > 3)"
114
105
  end
115
106
 
116
107
  it "should overuse route customizations another way" do
@@ -124,10 +115,9 @@ describe RailsBestPractices::Checks::OveruseRouteCustomizationsCheck do
124
115
  end
125
116
  end
126
117
  EOF
127
- @runner.review('config/routes.rb', content)
128
- errors = @runner.errors
129
- errors.should_not be_empty
130
- errors[0].to_s.should == "config/routes.rb:2 - overuse route customizations (customize_count > 3)"
118
+ runner.review('config/routes.rb', content)
119
+ runner.should have(1).errors
120
+ runner.errors[0].to_s.should == "config/routes.rb:2 - overuse route customizations (customize_count > 3)"
131
121
  end
132
122
 
133
123
  it "should not overuse route customizations without customization" do
@@ -136,9 +126,8 @@ describe RailsBestPractices::Checks::OveruseRouteCustomizationsCheck do
136
126
  resources :posts
137
127
  end
138
128
  EOF
139
- @runner.review('config/routes.rb', content)
140
- errors = @runner.errors
141
- errors.should be_empty
129
+ runner.review('config/routes.rb', content)
130
+ runner.should have(0).errors
142
131
  end
143
132
 
144
133
  it "should not overuse route customizations when customize route is only one" do
@@ -151,9 +140,8 @@ describe RailsBestPractices::Checks::OveruseRouteCustomizationsCheck do
151
140
  end
152
141
  end
153
142
  EOF
154
- @runner.review('config/routes.rb', content)
155
- errors = @runner.errors
156
- errors.should be_empty
143
+ runner.review('config/routes.rb', content)
144
+ runner.should have(0).errors
157
145
  end
158
146
  end
159
147
  end