rails_best_practices 1.14.4 → 1.15.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 (86) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/.travis.yml +1 -0
  4. data/README.md +26 -6
  5. data/lib/rails_best_practices/core/check.rb +15 -2
  6. data/lib/rails_best_practices/core/klasses.rb +13 -3
  7. data/lib/rails_best_practices/core/model_associations.rb +1 -1
  8. data/lib/rails_best_practices/core/runner.rb +2 -0
  9. data/lib/rails_best_practices/lexicals/long_line_check.rb +1 -1
  10. data/lib/rails_best_practices/prepares/route_prepare.rb +17 -1
  11. data/lib/rails_best_practices/reviews/always_add_db_index_review.rb +2 -2
  12. data/lib/rails_best_practices/reviews/isolate_seed_data_review.rb +2 -2
  13. data/lib/rails_best_practices/reviews/keep_finders_on_their_own_model_review.rb +1 -1
  14. data/lib/rails_best_practices/reviews/move_code_into_helper_review.rb +1 -1
  15. data/lib/rails_best_practices/reviews/move_code_into_model_review.rb +1 -1
  16. data/lib/rails_best_practices/reviews/move_model_logic_into_model_review.rb +1 -1
  17. data/lib/rails_best_practices/reviews/needless_deep_nesting_review.rb +1 -1
  18. data/lib/rails_best_practices/reviews/overuse_route_customizations_review.rb +1 -1
  19. data/lib/rails_best_practices/reviews/remove_unused_methods_in_models_review.rb +1 -2
  20. data/lib/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review.rb +1 -1
  21. data/lib/rails_best_practices/reviews/restrict_auto_generated_routes_review.rb +2 -1
  22. data/lib/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review.rb +15 -26
  23. data/lib/rails_best_practices/reviews/use_turbo_sprockets_rails3_review.rb +4 -2
  24. data/lib/rails_best_practices/version.rb +1 -1
  25. data/spec/rails_best_practices/analyzer_spec.rb +11 -11
  26. data/spec/rails_best_practices/core/check_spec.rb +1 -1
  27. data/spec/rails_best_practices/core/error_spec.rb +6 -6
  28. data/spec/rails_best_practices/core/klasses_spec.rb +26 -2
  29. data/spec/rails_best_practices/core/methods_spec.rb +18 -18
  30. data/spec/rails_best_practices/core/model_associations_spec.rb +6 -6
  31. data/spec/rails_best_practices/core/model_attributes_spec.rb +6 -6
  32. data/spec/rails_best_practices/core/modules_spec.rb +3 -3
  33. data/spec/rails_best_practices/core/routes_spec.rb +4 -4
  34. data/spec/rails_best_practices/core/runner_spec.rb +1 -1
  35. data/spec/rails_best_practices/lexicals/long_line_check_spec.rb +18 -6
  36. data/spec/rails_best_practices/lexicals/remove_tab_check_spec.rb +18 -5
  37. data/spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb +17 -5
  38. data/spec/rails_best_practices/prepares/config_prepare_spec.rb +1 -1
  39. data/spec/rails_best_practices/prepares/controller_prepare_spec.rb +13 -13
  40. data/spec/rails_best_practices/prepares/gemfile_prepare_spec.rb +1 -1
  41. data/spec/rails_best_practices/prepares/helper_prepare_spec.rb +2 -2
  42. data/spec/rails_best_practices/prepares/initializer_prepare_spec.rb +2 -2
  43. data/spec/rails_best_practices/prepares/mailer_prepare_spec.rb +1 -1
  44. data/spec/rails_best_practices/prepares/model_prepare_spec.rb +44 -44
  45. data/spec/rails_best_practices/prepares/route_prepare_spec.rb +102 -78
  46. data/spec/rails_best_practices/prepares/schema_prepare_spec.rb +6 -6
  47. data/spec/rails_best_practices/reviews/add_model_virtual_attribute_review_spec.rb +25 -9
  48. data/spec/rails_best_practices/reviews/always_add_db_index_review_spec.rb +43 -23
  49. data/spec/rails_best_practices/reviews/check_save_return_value_spec.rb +34 -20
  50. data/spec/rails_best_practices/reviews/default_scope_is_evil_review_spec.rb +16 -5
  51. data/spec/rails_best_practices/reviews/dry_bundler_in_capistrano_review_spec.rb +25 -3
  52. data/spec/rails_best_practices/reviews/hash_syntax_review_spec.rb +18 -7
  53. data/spec/rails_best_practices/reviews/isolate_seed_data_review_spec.rb +30 -7
  54. data/spec/rails_best_practices/reviews/keep_finders_on_their_own_model_review_spec.rb +24 -8
  55. data/spec/rails_best_practices/reviews/law_of_demeter_review_spec.rb +24 -12
  56. data/spec/rails_best_practices/reviews/move_code_into_controller_review_spec.rb +17 -5
  57. data/spec/rails_best_practices/reviews/move_code_into_helper_review_spec.rb +14 -3
  58. data/spec/rails_best_practices/reviews/move_code_into_model_review_spec.rb +24 -13
  59. data/spec/rails_best_practices/reviews/move_finder_to_named_scope_review_spec.rb +25 -6
  60. data/spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb +26 -4
  61. data/spec/rails_best_practices/reviews/needless_deep_nesting_review_spec.rb +31 -18
  62. data/spec/rails_best_practices/reviews/not_rescue_exception_spec.rb +23 -10
  63. data/spec/rails_best_practices/reviews/not_use_default_route_review_spec.rb +34 -7
  64. data/spec/rails_best_practices/reviews/not_use_times_ago_in_words_review_spec.rb +19 -8
  65. data/spec/rails_best_practices/reviews/overuse_route_customizations_review_spec.rb +33 -19
  66. data/spec/rails_best_practices/reviews/protect_mass_assignment_review_spec.rb +25 -13
  67. data/spec/rails_best_practices/reviews/remove_empty_helpers_review_spec.rb +14 -4
  68. data/spec/rails_best_practices/reviews/remove_unused_methods_in_controllers_review_spec.rb +91 -23
  69. data/spec/rails_best_practices/reviews/remove_unused_methods_in_helpers_review_spec.rb +20 -5
  70. data/spec/rails_best_practices/reviews/remove_unused_methods_in_models_review_spec.rb +66 -41
  71. data/spec/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review_spec.rb +28 -4
  72. data/spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb +16 -7
  73. data/spec/rails_best_practices/reviews/restrict_auto_generated_routes_review_spec.rb +45 -32
  74. data/spec/rails_best_practices/reviews/simplify_render_in_controllers_review_spec.rb +20 -9
  75. data/spec/rails_best_practices/reviews/simplify_render_in_views_review_spec.rb +23 -14
  76. data/spec/rails_best_practices/reviews/use_before_filter_review_spec.rb +34 -7
  77. data/spec/rails_best_practices/reviews/use_model_association_review_spec.rb +21 -6
  78. data/spec/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review_spec.rb +124 -79
  79. data/spec/rails_best_practices/reviews/use_observer_review_spec.rb +12 -12
  80. data/spec/rails_best_practices/reviews/use_parenthesis_in_method_def_spec.rb +16 -4
  81. data/spec/rails_best_practices/reviews/use_query_attribute_review_spec.rb +39 -27
  82. data/spec/rails_best_practices/reviews/use_say_with_time_in_migrations_review_spec.rb +22 -8
  83. data/spec/rails_best_practices/reviews/use_scope_access_review_spec.rb +39 -21
  84. data/spec/rails_best_practices/reviews/use_turbo_sprockets_rails3_review_spec.rb +66 -7
  85. metadata +36 -37
  86. data/.ruby-gemset +0 -1
@@ -3,29 +3,32 @@ require 'spec_helper'
3
3
  module RailsBestPractices
4
4
  module Reviews
5
5
  describe UseMultipartAlternativeAsContentTypeOfEmailReview do
6
- let(:runner) { Core::Runner.new(reviews: UseMultipartAlternativeAsContentTypeOfEmailReview.new) }
7
-
8
- before(:each) { Core::Runner.stub!(:base_path).and_return(".") }
9
-
10
- def mock_email_files(entry_files, options={})
11
- Dir.stub!(:entries).with("./app/views/project_mailer").and_return(entry_files)
12
- File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.plain.erb").and_return(options["text.plain.erb"] || false)
13
- File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.html.erb").and_return(options["text.html.erb"] || false)
14
- File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.erb").and_return(options["text.erb"] || false)
15
- File.stub!(:exist?).with("./app/views/project_mailer/send_email.html.erb").and_return(options["html.erb"] || false)
16
- File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.plain.haml").and_return(options["text.plain.haml"] || false)
17
- File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.html.haml").and_return(options["text.html.haml"] || false)
18
- File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.haml").and_return(options["text.haml"] || false)
19
- File.stub!(:exist?).with("./app/views/project_mailer/send_email.html.haml").and_return(options["html.haml"] || false)
20
- File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.plain.slim").and_return(options["text.plain.slim"] || false)
21
- File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.html.slim").and_return(options["text.html.slim"] || false)
22
- File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.slim").and_return(options["text.slim"] || false)
23
- File.stub!(:exist?).with("./app/views/project_mailer/send_email.html.slim").and_return(options["html.slim"] || false)
24
- File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.plain.rhtml").and_return(options["text.plain.rhtml"] || false)
25
- File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.html.rhtml").and_return(options["text.html.rhtml"] || false)
6
+ let(:runner) { Core::Runner.new(prepares: Prepares::GemfilePrepare.new, reviews: UseMultipartAlternativeAsContentTypeOfEmailReview.new) }
7
+
8
+ before(:each) { allow(Core::Runner).to receive(:base_path).and_return(".") }
9
+
10
+ def mock_email_files(entry_files)
11
+ allow(Dir).to receive(:entries).with("./app/views/project_mailer").and_return(entry_files)
26
12
  end
27
13
 
28
14
  context "rails2" do
15
+ before do
16
+ content = <<-EOF
17
+ GEM
18
+ remote: http://rubygems.org
19
+ specs:
20
+ rails (2.3.14)
21
+ actionmailer (= 2.3.14)
22
+ actionpack (= 2.3.14)
23
+ activerecord (= 2.3.14)
24
+ activeresource (= 2.3.14)
25
+ activesupport (= 2.3.14)
26
+ bundler (~> 1.0)
27
+ railties (= 2.3.14)
28
+ EOF
29
+ runner.prepare('Gemfile.lock', content)
30
+ end
31
+
29
32
  context "project_mailer" do
30
33
  let(:content) {
31
34
  <<-EOF
@@ -43,85 +46,89 @@ module RailsBestPractices
43
46
 
44
47
  context "erb" do
45
48
  it "should use mulipart/alternative as content_type of email" do
46
- mock_email_files(["send_email.text.html.erb"], "text.html.erb" => true)
49
+ mock_email_files(["send_email.text.html.erb"])
47
50
  runner.review('app/mailers/project_mailer.rb', content)
48
- runner.should have(1).errors
49
- runner.errors[0].to_s.should == "app/mailers/project_mailer.rb:2 - use multipart/alternative as content_type of email"
51
+ expect(runner.errors.size).to eq(1)
52
+ expect(runner.errors[0].to_s).to eq("app/mailers/project_mailer.rb:2 - use multipart/alternative as content_type of email")
50
53
  end
51
54
 
52
- it "should not use multipart/alternative as content_type of email" do
53
- mock_email_files(["send_email.text.html.erb"], "text.plain.erb" => true, "text.html.erb" => true)
55
+ it "should use multiple/alternative as content_type of email when only plain text" do
56
+ mock_email_files(["send_email.text.plain.erb"])
54
57
  runner.review('app/mailers/project_mailer.rb', content)
55
- runner.should have(0).errors
58
+ expect(runner.errors.size).to eq(1)
59
+ expect(runner.errors[0].to_s).to eq("app/mailers/project_mailer.rb:2 - use multipart/alternative as content_type of email")
56
60
  end
57
61
 
58
- it "should not use multiple/alternative as content_type of email when only plain text" do
59
- mock_email_files(["send_email.text.plain.erb"], "text.plain.erb" => true)
62
+ it "should not use multipart/alternative as content_type of email" do
63
+ mock_email_files(["send_email.text.plain.erb", "send_email.text.html.erb"])
60
64
  runner.review('app/mailers/project_mailer.rb', content)
61
- runner.should have(0).errors
65
+ expect(runner.errors.size).to eq(0)
62
66
  end
63
67
  end
64
68
 
65
69
  context "haml" do
66
70
  it "should use mulipart/alternative as content_type of email" do
67
- mock_email_files(["send_email.text.html.haml"], "text.html.haml" => true)
71
+ mock_email_files(["send_email.text.html.haml"])
68
72
  runner.review('app/mailers/project_mailer.rb', content)
69
- runner.should have(1).errors
70
- runner.errors[0].to_s.should == "app/mailers/project_mailer.rb:2 - use multipart/alternative as content_type of email"
73
+ expect(runner.errors.size).to eq(1)
74
+ expect(runner.errors[0].to_s).to eq("app/mailers/project_mailer.rb:2 - use multipart/alternative as content_type of email")
71
75
  end
72
76
 
73
- it "should not use multipart/alternative as content_type of email" do
74
- mock_email_files(["send_email.text.html.haml"], "text.plain.haml" => true, "text.html.haml" => true)
77
+ it "should use multiple/alternative as content_type of email when only plain text" do
78
+ mock_email_files(["send_email.text.plain.haml"])
75
79
  runner.review('app/mailers/project_mailer.rb', content)
76
- runner.should have(0).errors
80
+ expect(runner.errors.size).to eq(1)
81
+ expect(runner.errors[0].to_s).to eq("app/mailers/project_mailer.rb:2 - use multipart/alternative as content_type of email")
77
82
  end
78
83
 
79
- it "should not use multiple/alternative as content_type of email when only plain text" do
80
- mock_email_files(["send_email.text.plain.haml"], "text.plain.haml" => true)
84
+ it "should not use multipart/alternative as content_type of email" do
85
+ mock_email_files(["send_email.text.plain.haml", "send_email.text.html.haml"])
81
86
  runner.review('app/mailers/project_mailer.rb', content)
82
- runner.should have(0).errors
87
+ expect(runner.errors.size).to eq(0)
83
88
  end
84
89
  end
85
90
 
86
91
  context "slim" do
87
92
  it "should use mulipart/alternative as content_type of email" do
88
- mock_email_files(["send_email.text.html.slim"], "text.html.slim" => true)
93
+ mock_email_files(["send_email.text.html.slim"])
89
94
  runner.review('app/mailers/project_mailer.rb', content)
90
- runner.should have(1).errors
91
- runner.errors[0].to_s.should == "app/mailers/project_mailer.rb:2 - use multipart/alternative as content_type of email"
95
+ expect(runner.errors.size).to eq(1)
96
+ expect(runner.errors[0].to_s).to eq("app/mailers/project_mailer.rb:2 - use multipart/alternative as content_type of email")
92
97
  end
93
98
 
94
- it "should not use multipart/alternative as content_type of email" do
95
- mock_email_files(["send_email.text.html.slim"], "text.plain.slim" => true, "text.html.slim" => true)
99
+ it "should use multiple/alternative as content_type of email when only plain text" do
100
+ mock_email_files(["send_email.text.plain.slim"])
96
101
  runner.review('app/mailers/project_mailer.rb', content)
97
- runner.should have(0).errors
102
+ expect(runner.errors.size).to eq(1)
103
+ expect(runner.errors[0].to_s).to eq("app/mailers/project_mailer.rb:2 - use multipart/alternative as content_type of email")
98
104
  end
99
105
 
100
- it "should not use multiple/alternative as content_type of email when only plain text" do
101
- mock_email_files(["send_email.text.plain.slim"], "text.plain.slim" => true)
106
+ it "should not use multipart/alternative as content_type of email" do
107
+ mock_email_files(["send_email.text.plain.slim", "send_email.text.html.slim"])
102
108
  runner.review('app/mailers/project_mailer.rb', content)
103
- runner.should have(0).errors
109
+ expect(runner.errors.size).to eq(0)
104
110
  end
105
111
  end
106
112
 
107
113
  context "rhtml" do
108
114
  it "should use mulipart/alternative as content_type of email" do
109
- mock_email_files(["send_email.text.html.rhtml"], "text.html.rhtml" => true)
115
+ mock_email_files(["send_email.text.html.rhtml"])
110
116
  runner.review('app/mailers/project_mailer.rb', content)
111
- runner.should have(1).errors
112
- runner.errors[0].to_s.should == "app/mailers/project_mailer.rb:2 - use multipart/alternative as content_type of email"
117
+ expect(runner.errors.size).to eq(1)
118
+ expect(runner.errors[0].to_s).to eq("app/mailers/project_mailer.rb:2 - use multipart/alternative as content_type of email")
113
119
  end
114
120
 
115
- it "should not use multipart/alternative as content_type of email" do
116
- mock_email_files(["send_email.text.html.rhtml"], "text.plain.rhtml" => true, "text.html.rhtml" => true)
121
+ it "should use multiple/alternative as content_type of email when only plain text" do
122
+ mock_email_files(["send_email.text.plain.rhtml"])
117
123
  runner.review('app/mailers/project_mailer.rb', content)
118
- runner.should have(0).errors
124
+ expect(runner.errors.size).to eq(1)
125
+ expect(runner.errors[0].to_s).to eq("app/mailers/project_mailer.rb:2 - use multipart/alternative as content_type of email")
119
126
  end
120
127
 
121
- it "should not use multiple/alternative as content_type of email when only plain text" do
122
- mock_email_files(["send_email.text.plain.rhtml"], "text.plain.rhtml" => true)
128
+ it "should not use multipart/alternative as content_type of email" do
129
+ mock_email_files(["send_email.text.plain.rhtml", "send_email.text.html.rhtml"])
123
130
  runner.review('app/mailers/project_mailer.rb', content)
124
- runner.should have(0).errors
131
+ expect(runner.errors.size).to eq(0)
125
132
  end
126
133
  end
127
134
  end
@@ -133,13 +140,30 @@ module RailsBestPractices
133
140
  end
134
141
  end
135
142
  EOF
136
- mock_email_files(["send_email.text.html.erb"])
143
+ mock_email_files([])
137
144
  runner.review('app/mailers/project_mailer.rb', content)
138
- runner.should have(0).errors
145
+ expect(runner.errors.size).to eq(0)
139
146
  end
140
147
  end
141
148
 
142
149
  context "rails3" do
150
+ before do
151
+ content = <<-EOF
152
+ GEM
153
+ remote: http://rubygems.org
154
+ specs:
155
+ rails (3.2.13)
156
+ actionmailer (= 3.2.13)
157
+ actionpack (= 3.2.13)
158
+ activerecord (= 3.2.13)
159
+ activeresource (= 3.2.13)
160
+ activesupport (= 3.2.13)
161
+ bundler (~> 1.0)
162
+ railties (= 3.2.13)
163
+ EOF
164
+ runner.prepare('Gemfile.lock', content)
165
+ end
166
+
143
167
  context "project_mailer" do
144
168
  let(:content) {
145
169
  <<-EOF
@@ -157,57 +181,78 @@ module RailsBestPractices
157
181
 
158
182
  context "erb" do
159
183
  it "should use mulipart/alternative as content_type of email" do
160
- mock_email_files(["send_email.html.erb"], "html.erb" => true)
184
+ mock_email_files(["send_email.html.erb"])
161
185
  runner.review('app/mailers/project_mailer.rb', content)
162
- runner.should have(1).errors
163
- runner.errors[0].to_s.should == "app/mailers/project_mailer.rb:2 - use multipart/alternative as content_type of email"
186
+ expect(runner.errors.size).to eq(1)
187
+ expect(runner.errors[0].to_s).to eq("app/mailers/project_mailer.rb:2 - use multipart/alternative as content_type of email")
164
188
  end
165
189
 
166
- it "should not use multipart/alternative as content_type of email" do
167
- mock_email_files(["send_email.html.erb"], "text.erb" => true, "html.erb" => true)
190
+ it "should use multiple/alternative as content_type of email when only plain text" do
191
+ mock_email_files(["send_email.text.erb"])
168
192
  runner.review('app/mailers/project_mailer.rb', content)
169
- runner.should have(0).errors
193
+ expect(runner.errors.size).to eq(1)
194
+ expect(runner.errors[0].to_s).to eq("app/mailers/project_mailer.rb:2 - use multipart/alternative as content_type of email")
170
195
  end
171
196
 
172
- it "should not use multiple/alternative as content_type of email when only plain text" do
173
- mock_email_files(["send_email.text.erb"], "text.erb" => true)
197
+ it "should not use multipart/alternative as content_type of email" do
198
+ mock_email_files(["send_email.text.erb", "send_email.html.erb"])
174
199
  runner.review('app/mailers/project_mailer.rb', content)
175
- runner.should have(0).errors
200
+ expect(runner.errors.size).to eq(0)
176
201
  end
177
202
  end
178
203
 
179
204
  context "haml" do
180
205
  it "should use mulipart/alternative as content_type of email" do
181
- mock_email_files(["send_email.html.haml"], "html.haml" => true)
206
+ mock_email_files(["send_email.html.haml"])
207
+ runner.review('app/mailers/project_mailer.rb', content)
208
+ expect(runner.errors.size).to eq(1)
209
+ expect(runner.errors[0].to_s).to eq("app/mailers/project_mailer.rb:2 - use multipart/alternative as content_type of email")
210
+ end
211
+
212
+ it "should use multiple/alternative as content_type of email when only plain text" do
213
+ mock_email_files(["send_email.text.haml"])
182
214
  runner.review('app/mailers/project_mailer.rb', content)
183
- runner.should have(1).errors
184
- runner.errors[0].to_s.should == "app/mailers/project_mailer.rb:2 - use multipart/alternative as content_type of email"
215
+ expect(runner.errors.size).to eq(1)
216
+ expect(runner.errors[0].to_s).to eq("app/mailers/project_mailer.rb:2 - use multipart/alternative as content_type of email")
185
217
  end
186
218
 
187
219
  it "should not use multipart/alternative as content_type of email" do
188
- mock_email_files(["send_email.html.haml", "send_email.text.haml"], "html.haml" => true, "text.haml" => true)
220
+ mock_email_files(["send_email.html.haml", "send_email.text.haml"])
221
+ runner.review('app/mailers/project_mailer.rb', content)
222
+ expect(runner.errors.size).to eq(0)
223
+ end
224
+
225
+ it "should not use multipart/alternative as content_type of email with text locale" do
226
+ mock_email_files(["send_email.html.haml", "send_email.de.text.haml"])
189
227
  runner.review('app/mailers/project_mailer.rb', content)
190
- runner.should have(0).errors
228
+ expect(runner.errors.size).to eq(0)
191
229
  end
192
230
 
193
- it "should not use multiple/alternative as content_type of email when only plain text" do
194
- mock_email_files(["send_email.text.haml"], "text.haml" => true)
231
+ it "should not use multipart/alternative as content_type of email with html locale" do
232
+ mock_email_files(["send_email.de.html.haml", "send_email.text.haml"])
195
233
  runner.review('app/mailers/project_mailer.rb', content)
196
- runner.should have(0).errors
234
+ expect(runner.errors.size).to eq(0)
197
235
  end
198
236
  end
199
237
 
200
238
  context "haml/erb mix" do
201
239
  it "should not suggest using multipart/alternative when mixing html.haml and text.erb" do
202
- mock_email_files(["send_email.html.haml", "send_email.text.erb"], "html.haml" => true, "text.erb" => true)
240
+ mock_email_files(["send_email.html.haml", "send_email.text.erb"])
203
241
  runner.review('app/mailers/project_mailer.rb', content)
204
- runner.should have(0).errors
242
+ expect(runner.errors.size).to eq(0)
205
243
 
206
- mock_email_files(["send_email.html.erb", "send_email.text.haml"], "html.erb" => true, "text.haml" => true)
244
+ mock_email_files(["send_email.html.erb", "send_email.text.haml"])
207
245
  runner.review('app/mailers/project_mailer.rb', content)
208
- runner.should have(0).errors
246
+ expect(runner.errors.size).to eq(0)
209
247
  end
210
248
  end
249
+
250
+ it "should not check ignored files" do
251
+ runner = Core::Runner.new(reviews: UseMultipartAlternativeAsContentTypeOfEmailReview.new(ignored_files: /project_mailer/))
252
+ mock_email_files(["send_email.html.haml"])
253
+ runner.review('app/mailers/project_mailer.rb', content)
254
+ expect(runner.errors.size).to eq(0)
255
+ end
211
256
  end
212
257
  end
213
258
  end
@@ -28,8 +28,8 @@ module RailsBestPractices
28
28
  end
29
29
  EOF
30
30
  runner.review('app/models/project.rb', content)
31
- runner.should have(1).errors
32
- runner.errors[0].to_s.should == "app/models/project.rb:5 - use observer"
31
+ expect(runner.errors.size).to eq(1)
32
+ expect(runner.errors[0].to_s).to eq("app/models/project.rb:5 - use observer")
33
33
  end
34
34
 
35
35
  it "should not use observer without callback" do
@@ -44,7 +44,7 @@ module RailsBestPractices
44
44
  end
45
45
  EOF
46
46
  runner.review('app/models/project.rb', content)
47
- runner.should have(0).errors
47
+ expect(runner.errors.size).to eq(0)
48
48
  end
49
49
 
50
50
  it "should use observer with two after_create" do
@@ -64,8 +64,8 @@ module RailsBestPractices
64
64
  end
65
65
  EOF
66
66
  runner.review('app/models/project.rb', content)
67
- runner.should have(1).errors
68
- runner.errors[0].to_s.should == "app/models/project.rb:5 - use observer"
67
+ expect(runner.errors.size).to eq(1)
68
+ expect(runner.errors[0].to_s).to eq("app/models/project.rb:5 - use observer")
69
69
  end
70
70
 
71
71
  it "should not raise when initiate an object in callback" do
@@ -74,7 +74,7 @@ module RailsBestPractices
74
74
  after_create ProjectMailer.new
75
75
  end
76
76
  EOF
77
- lambda { runner.review('app/models/project.rb', content) }.should_not raise_error
77
+ expect { runner.review('app/models/project.rb', content) }.not_to raise_error
78
78
  end
79
79
  end
80
80
 
@@ -93,8 +93,8 @@ module RailsBestPractices
93
93
  end
94
94
  EOF
95
95
  runner.review('app/models/project.rb', content)
96
- runner.should have(1).errors
97
- runner.errors[0].to_s.should == "app/models/project.rb:5 - use observer"
96
+ expect(runner.errors.size).to eq(1)
97
+ expect(runner.errors[0].to_s).to eq("app/models/project.rb:5 - use observer")
98
98
  end
99
99
 
100
100
  it "should not use observer without callback" do
@@ -109,7 +109,7 @@ module RailsBestPractices
109
109
  end
110
110
  EOF
111
111
  runner.review('app/models/project.rb', content)
112
- runner.should have(0).errors
112
+ expect(runner.errors.size).to eq(0)
113
113
  end
114
114
 
115
115
  it "should use observer with two after_create" do
@@ -129,8 +129,8 @@ module RailsBestPractices
129
129
  end
130
130
  EOF
131
131
  runner.review('app/models/project.rb', content)
132
- runner.should have(1).errors
133
- runner.errors[0].to_s.should == "app/models/project.rb:5 - use observer"
132
+ expect(runner.errors.size).to eq(1)
133
+ expect(runner.errors[0].to_s).to eq("app/models/project.rb:5 - use observer")
134
134
  end
135
135
 
136
136
  it "should not raise when initiate an object in callback" do
@@ -139,7 +139,7 @@ module RailsBestPractices
139
139
  after_create ProjectMailer.new
140
140
  end
141
141
  EOF
142
- lambda { runner.review('app/models/project.rb', content) }.should_not raise_error
142
+ expect { runner.review('app/models/project.rb', content) }.not_to raise_error
143
143
  end
144
144
  end
145
145
  end
@@ -13,8 +13,8 @@ module RailsBestPractices
13
13
  end
14
14
  EOF
15
15
  runner.review('app/controllers/posts_controller.rb', content)
16
- runner.should have(1).errors
17
- runner.errors[0].to_s.should == "app/controllers/posts_controller.rb:2 - use parentheses around parameters in method definitions"
16
+ expect(runner.errors.size).to eq(1)
17
+ expect(runner.errors[0].to_s).to eq("app/controllers/posts_controller.rb:2 - use parentheses around parameters in method definitions")
18
18
  end
19
19
  it "should find parentheses with no error" do
20
20
  content = <<-EOF
@@ -24,7 +24,7 @@ module RailsBestPractices
24
24
  end
25
25
  EOF
26
26
  runner.review('app/controllers/posts_controller.rb', content)
27
- runner.should have(0).errors
27
+ expect(runner.errors.size).to eq(0)
28
28
  end
29
29
  it "should not throw an error without parameters" do
30
30
  content = <<-EOF
@@ -34,7 +34,19 @@ module RailsBestPractices
34
34
  end
35
35
  EOF
36
36
  runner.review('app/controllers/posts_controller.rb', content)
37
- runner.should have(0).errors
37
+ expect(runner.errors.size).to eq(0)
38
+ end
39
+
40
+ it "should not check ignored files" do
41
+ runner = Core::Runner.new(reviews: UseParenthesesInMethodDefReview.new(ignored_files: /posts_controller/))
42
+ content = <<-EOF
43
+ class PostsController < ApplicationController
44
+ def edit foo, bar
45
+ end
46
+ end
47
+ EOF
48
+ runner.review('app/controllers/posts_controller.rb', content)
49
+ expect(runner.errors.size).to eq(0)
38
50
  end
39
51
  end
40
52
  end
@@ -35,8 +35,8 @@ module RailsBestPractices
35
35
  <% end %>
36
36
  EOF
37
37
  runner.review('app/views/users/show.html.erb', content)
38
- runner.should have(1).errors
39
- runner.errors[0].to_s.should == "app/views/users/show.html.erb:1 - use query attribute (@user.login?)"
38
+ expect(runner.errors.size).to eq(1)
39
+ expect(runner.errors[0].to_s).to eq("app/views/users/show.html.erb:1 - use query attribute (@user.login?)")
40
40
  end
41
41
 
42
42
  it "should use query attribute by blank call with if in one line" do
@@ -44,8 +44,8 @@ module RailsBestPractices
44
44
  <%= link_to 'login', new_session_path if @user.login.blank? %>
45
45
  EOF
46
46
  runner.review('app/views/users/show.html.erb', content)
47
- runner.should have(1).errors
48
- runner.errors[0].to_s.should == "app/views/users/show.html.erb:1 - use query attribute (@user.login?)"
47
+ expect(runner.errors.size).to eq(1)
48
+ expect(runner.errors[0].to_s).to eq("app/views/users/show.html.erb:1 - use query attribute (@user.login?)")
49
49
  end
50
50
 
51
51
  it "should use query attribute by blank call with '? :'" do
@@ -53,8 +53,8 @@ module RailsBestPractices
53
53
  <%= @user.login.blank? ? link_to('login', new_session_path) : '' %>
54
54
  EOF
55
55
  runner.review('app/views/users/show.html.erb', content)
56
- runner.should have(1).errors
57
- runner.errors[0].to_s.should == "app/views/users/show.html.erb:1 - use query attribute (@user.login?)"
56
+ expect(runner.errors.size).to eq(1)
57
+ expect(runner.errors[0].to_s).to eq("app/views/users/show.html.erb:1 - use query attribute (@user.login?)")
58
58
  end
59
59
 
60
60
  it "should use query attribute by comparing empty string" do
@@ -64,8 +64,8 @@ module RailsBestPractices
64
64
  <% end %>
65
65
  EOF
66
66
  runner.review('app/views/users/show.html.erb', content)
67
- runner.should have(1).errors
68
- runner.errors[0].to_s.should == "app/views/users/show.html.erb:1 - use query attribute (@user.login?)"
67
+ expect(runner.errors.size).to eq(1)
68
+ expect(runner.errors[0].to_s).to eq("app/views/users/show.html.erb:1 - use query attribute (@user.login?)")
69
69
  end
70
70
 
71
71
  it "should use query attribute by nil call" do
@@ -75,8 +75,8 @@ module RailsBestPractices
75
75
  <% end %>
76
76
  EOF
77
77
  runner.review('app/views/users/show.html.erb', content)
78
- runner.should have(1).errors
79
- runner.errors[0].to_s.should == "app/views/users/show.html.erb:1 - use query attribute (@user.login?)"
78
+ expect(runner.errors.size).to eq(1)
79
+ expect(runner.errors[0].to_s).to eq("app/views/users/show.html.erb:1 - use query attribute (@user.login?)")
80
80
  end
81
81
 
82
82
  it "should use query attribute by present call" do
@@ -86,8 +86,8 @@ module RailsBestPractices
86
86
  <% end %>
87
87
  EOF
88
88
  runner.review('app/views/users/show.html.erb', content)
89
- runner.should have(1).errors
90
- runner.errors[0].to_s.should == "app/views/users/show.html.erb:1 - use query attribute (@user.login?)"
89
+ expect(runner.errors.size).to eq(1)
90
+ expect(runner.errors[0].to_s).to eq("app/views/users/show.html.erb:1 - use query attribute (@user.login?)")
91
91
  end
92
92
 
93
93
  it "should use query attribute within and conditions" do
@@ -97,8 +97,8 @@ module RailsBestPractices
97
97
  <% end %>
98
98
  EOF
99
99
  runner.review('app/views/users/show.html.erb', content)
100
- runner.should have(1).errors
101
- runner.errors[0].to_s.should == "app/views/users/show.html.erb:1 - use query attribute (@user.login?)"
100
+ expect(runner.errors.size).to eq(1)
101
+ expect(runner.errors[0].to_s).to eq("app/views/users/show.html.erb:1 - use query attribute (@user.login?)")
102
102
  end
103
103
 
104
104
  it "should use query attribute within or conditions" do
@@ -108,8 +108,8 @@ module RailsBestPractices
108
108
  <% end %>
109
109
  EOF
110
110
  runner.review('app/views/users/show.html.erb', content)
111
- runner.should have(1).errors
112
- runner.errors[0].to_s.should == "app/views/users/show.html.erb:1 - use query attribute (@user.login?)"
111
+ expect(runner.errors.size).to eq(1)
112
+ expect(runner.errors[0].to_s).to eq("app/views/users/show.html.erb:1 - use query attribute (@user.login?)")
113
113
  end
114
114
 
115
115
  it "should not use query attribute" do
@@ -119,7 +119,7 @@ module RailsBestPractices
119
119
  <% end %>
120
120
  EOF
121
121
  runner.review('app/views/users/show.html.erb', content)
122
- runner.should have(0).errors
122
+ expect(runner.errors.size).to eq(0)
123
123
  end
124
124
 
125
125
  it "should not use query attribute for number" do
@@ -129,7 +129,7 @@ module RailsBestPractices
129
129
  <% end %>
130
130
  EOF
131
131
  runner.review('app/views/users/show.html.erb', content)
132
- runner.should have(0).errors
132
+ expect(runner.errors.size).to eq(0)
133
133
  end
134
134
 
135
135
  it "should not review for pluralize attribute" do
@@ -139,7 +139,7 @@ module RailsBestPractices
139
139
  <% end %>
140
140
  EOF
141
141
  runner.review('app/views/users/show.html.erb', content)
142
- runner.should have(0).errors
142
+ expect(runner.errors.size).to eq(0)
143
143
  end
144
144
 
145
145
  it "should not review non model class" do
@@ -149,7 +149,7 @@ module RailsBestPractices
149
149
  <% end %>
150
150
  EOF
151
151
  runner.review('app/views/users/show.html.erb', content)
152
- runner.should have(0).errors
152
+ expect(runner.errors.size).to eq(0)
153
153
  end
154
154
 
155
155
  context "association" do
@@ -160,7 +160,7 @@ module RailsBestPractices
160
160
  <% end %>
161
161
  EOF
162
162
  runner.review('app/views/users/show.html.erb', content)
163
- runner.should have(0).errors
163
+ expect(runner.errors.size).to eq(0)
164
164
  end
165
165
 
166
166
  it "should not review belongs_to category" do
@@ -170,7 +170,7 @@ module RailsBestPractices
170
170
  <% end %>
171
171
  EOF
172
172
  runner.review('app/views/users/show.html.erb', content)
173
- runner.should have(0).errors
173
+ expect(runner.errors.size).to eq(0)
174
174
  end
175
175
 
176
176
  it "should not review has_one association" do
@@ -180,7 +180,7 @@ module RailsBestPractices
180
180
  <% end %>
181
181
  EOF
182
182
  runner.review('app/views/users/show.html.erb', content)
183
- runner.should have(0).errors
183
+ expect(runner.errors.size).to eq(0)
184
184
  end
185
185
 
186
186
  it "should not review has_many association" do
@@ -190,7 +190,7 @@ module RailsBestPractices
190
190
  <% end %>
191
191
  EOF
192
192
  runner.review('app/views/users/show.html.erb', content)
193
- runner.should have(0).errors
193
+ expect(runner.errors.size).to eq(0)
194
194
  end
195
195
  end
196
196
 
@@ -201,7 +201,7 @@ module RailsBestPractices
201
201
  <% end %>
202
202
  EOF
203
203
  runner.review('app/views/users/show.html.erb', content)
204
- runner.should have(0).errors
204
+ expect(runner.errors.size).to eq(0)
205
205
  end
206
206
 
207
207
  it "should not review for non attribute call" do
@@ -211,7 +211,7 @@ module RailsBestPractices
211
211
  end
212
212
  EOF
213
213
  runner.review('app/models/users_controller.rb', content)
214
- runner.should have(0).errors
214
+ expect(runner.errors.size).to eq(0)
215
215
  end
216
216
 
217
217
  it "should not raise error for common conditional statement" do
@@ -220,7 +220,19 @@ module RailsBestPractices
220
220
  puts voteable.title
221
221
  end
222
222
  EOF
223
- lambda { runner.review('app/models/users_controller.rb', content) }.should_not raise_error
223
+ expect { runner.review('app/models/users_controller.rb', content) }.not_to raise_error
224
+ end
225
+
226
+ it "should not check ignored files" do
227
+ runner = Core::Runner.new(prepares: [Prepares::ModelPrepare.new, Prepares::SchemaPrepare.new],
228
+ reviews: UseQueryAttributeReview.new(ignored_files: /users\/show/))
229
+ content = <<-EOF
230
+ <% if @user.login.blank? %>
231
+ <%= link_to 'login', new_session_path %>
232
+ <% end %>
233
+ EOF
234
+ runner.review('app/views/users/show.html.erb', content)
235
+ expect(runner.errors.size).to eq(0)
224
236
  end
225
237
  end
226
238
  end