Skip to content
This repository
Browse code

Use parentheses when using assert_match followed by a regexp to avoid…

… warnings.
  • Loading branch information...
commit 2d274a520857b159bd4dd0206fc7cd09a9356b86 1 parent be9883b
Emilio Tagua authored September 22, 2010
4  actionpack/test/activerecord/controller_runtime_test.rb
@@ -37,6 +37,6 @@ def test_log_with_active_record
37 37
     wait
38 38
 
39 39
     assert_equal 2, @logger.logged(:info).size
40  
-    assert_match /\(Views: [\d\.]+ms | ActiveRecord: [\d\.]+ms\)/, @logger.logged(:info)[1]
  40
+    assert_match(/\(Views: [\d\.]+ms | ActiveRecord: [\d\.]+ms\)/, @logger.logged(:info)[1])
41 41
   end
42  
-end
  42
+end
2  actionpack/test/controller/action_pack_assertions_test.rb
@@ -314,7 +314,7 @@ def test_client_error_response_code
314 314
   def test_redirect_url_match
315 315
     process :redirect_external
316 316
     assert @response.redirect?
317  
-    assert_match /rubyonrails/, @response.redirect_url
  317
+    assert_match(/rubyonrails/, @response.redirect_url)
318 318
     assert !/perloffrails/.match(@response.redirect_url)
319 319
   end
320 320
 
6  actionpack/test/controller/caching_test.rb
@@ -728,7 +728,7 @@ def test_fragment_caching_in_partials
728 728
     get :html_fragment_cached_with_partial
729 729
     assert_response :success
730 730
     assert_match(/Old fragment caching in a partial/, @response.body)
731  
-    assert_match "Old fragment caching in a partial", @store.read('views/test.host/functional_caching/html_fragment_cached_with_partial')
  731
+    assert_match("Old fragment caching in a partial", @store.read('views/test.host/functional_caching/html_fragment_cached_with_partial'))
732 732
   end
733 733
 
734 734
   def test_render_inline_before_fragment_caching
@@ -736,14 +736,14 @@ def test_render_inline_before_fragment_caching
736 736
     assert_response :success
737 737
     assert_match(/Some inline content/, @response.body)
738 738
     assert_match(/Some cached content/, @response.body)
739  
-    assert_match "Some cached content", @store.read('views/test.host/functional_caching/inline_fragment_cached')
  739
+    assert_match("Some cached content", @store.read('views/test.host/functional_caching/inline_fragment_cached'))
740 740
   end
741 741
 
742 742
   def test_fragment_caching_in_rjs_partials
743 743
     xhr :get, :js_fragment_cached_with_partial
744 744
     assert_response :success
745 745
     assert_match(/Old fragment caching in a partial/, @response.body)
746  
-    assert_match "Old fragment caching in a partial", @store.read('views/test.host/functional_caching/js_fragment_cached_with_partial')
  746
+    assert_match("Old fragment caching in a partial", @store.read('views/test.host/functional_caching/js_fragment_cached_with_partial'))
747 747
   end
748 748
 
749 749
   def test_html_formatted_fragment_caching
26  actionpack/test/controller/log_subscriber_test.rb
@@ -72,8 +72,8 @@ def test_process_action
72 72
     get :show
73 73
     wait
74 74
     assert_equal 2, logs.size
75  
-    assert_match /Completed/, logs.last
76  
-    assert_match /200 OK/, logs.last
  75
+    assert_match(/Completed/, logs.last)
  76
+    assert_match(/200 OK/, logs.last)
77 77
   end
78 78
 
79 79
   def test_process_action_without_parameters
@@ -93,7 +93,7 @@ def test_process_action_with_parameters
93 93
   def test_process_action_with_view_runtime
94 94
     get :show
95 95
     wait
96  
-    assert_match /\(Views: [\d\.]+ms\)/, logs[1]
  96
+    assert_match(/\(Views: [\d\.]+ms\)/, logs[1])
97 97
   end
98 98
 
99 99
   def test_process_action_with_filter_parameters
@@ -103,9 +103,9 @@ def test_process_action_with_filter_parameters
103 103
     wait
104 104
 
105 105
     params = logs[1]
106  
-    assert_match /"amount"=>"\[FILTERED\]"/, params
107  
-    assert_match /"lifo"=>"\[FILTERED\]"/, params
108  
-    assert_match /"step"=>"1"/, params
  106
+    assert_match(/"amount"=>"\[FILTERED\]"/, params)
  107
+    assert_match(/"lifo"=>"\[FILTERED\]"/, params)
  108
+    assert_match(/"step"=>"1"/, params)
109 109
   end
110 110
 
111 111
   def test_redirect_to
@@ -121,7 +121,7 @@ def test_send_data
121 121
     wait
122 122
 
123 123
     assert_equal 3, logs.size
124  
-    assert_match /Sent data file\.txt/, logs[1]
  124
+    assert_match(/Sent data file\.txt/, logs[1])
125 125
   end
126 126
 
127 127
   def test_send_file
@@ -129,8 +129,8 @@ def test_send_file
129 129
     wait
130 130
 
131 131
     assert_equal 3, logs.size
132  
-    assert_match /Sent file/, logs[1]
133  
-    assert_match /test\/fixtures\/company\.rb/, logs[1]
  132
+    assert_match(/Sent file/, logs[1])
  133
+    assert_match(/test\/fixtures\/company\.rb/, logs[1])
134 134
   end
135 135
 
136 136
   def test_with_fragment_cache
@@ -139,8 +139,8 @@ def test_with_fragment_cache
139 139
     wait
140 140
 
141 141
     assert_equal 4, logs.size
142  
-    assert_match /Exist fragment\? views\/foo/, logs[1]
143  
-    assert_match /Write fragment views\/foo/, logs[2]
  142
+    assert_match(/Exist fragment\? views\/foo/, logs[1])
  143
+    assert_match(/Write fragment views\/foo/, logs[2])
144 144
   ensure
145 145
     @controller.config.perform_caching = true
146 146
   end
@@ -163,8 +163,8 @@ def test_with_page_cache
163 163
     wait
164 164
 
165 165
     assert_equal 3, logs.size
166  
-    assert_match /Write page/, logs[1]
167  
-    assert_match /\/index\.html/, logs[1]
  166
+    assert_match(/Write page/, logs[1])
  167
+    assert_match(/\/index\.html/, logs[1])
168 168
   ensure
169 169
     @controller.config.perform_caching = true
170 170
   end
4  actionpack/test/controller/mime_responds_test.rb
@@ -784,8 +784,8 @@ def test_using_resource_with_collection
784 784
     get :using_resource_with_collection
785 785
     assert_equal "application/xml", @response.content_type
786 786
     assert_equal 200, @response.status
787  
-    assert_match /<name>david<\/name>/, @response.body
788  
-    assert_match /<name>jamis<\/name>/, @response.body
  787
+    assert_match(/<name>david<\/name>/, @response.body)
  788
+    assert_match(/<name>jamis<\/name>/, @response.body)
789 789
   end
790 790
 
791 791
   def test_using_resource_with_action
6  actionpack/test/controller/render_other_test.rb
@@ -224,15 +224,15 @@ def test_update_page_with_instance_variables
224 224
     get :update_page_with_instance_variables
225 225
     assert_template nil
226 226
     assert_equal 'text/javascript; charset=utf-8', @response.headers["Content-Type"]
227  
-    assert_match /balance/, @response.body
228  
-    assert_match /\$37/, @response.body
  227
+    assert_match(/balance/, @response.body)
  228
+    assert_match(/\$37/, @response.body)
229 229
   end
230 230
 
231 231
   def test_update_page_with_view_method
232 232
     get :update_page_with_view_method
233 233
     assert_template nil
234 234
     assert_equal 'text/javascript; charset=utf-8', @response.headers["Content-Type"]
235  
-    assert_match /2 people/, @response.body
  235
+    assert_match(/2 people/, @response.body)
236 236
   end
237 237
 
238 238
   def test_should_render_html_formatted_partial_with_rjs
2  actionpack/test/controller/test_test.rb
@@ -591,7 +591,7 @@ def test_should_detect_if_cookie_is_deleted
591 591
           assert false, "expected RuntimeError, got nothing"
592 592
         rescue RuntimeError => error
593 593
           assert true
594  
-          assert_match %r{@#{variable} is nil}, error.message
  594
+          assert_match(%r{@#{variable} is nil}, error.message)
595 595
         rescue => error
596 596
           assert false, "expected RuntimeError, got #{error.class}"
597 597
         end
2  actionpack/test/controller/url_for_test.rb
@@ -219,7 +219,7 @@ def test_hash_recursive_parameters
219 219
 
220 220
       def test_hash_recursive_and_array_parameters
221 221
         url = W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :id => 101, :query => {:person => {:name => 'Bob', :position => ['prof', 'art director']}, :hobby => 'piercing'})
222  
-        assert_match %r(^/c/a/101), url
  222
+        assert_match(%r(^/c/a/101), url)
223 223
         params = extract_params(url)
224 224
         assert_equal params[0], { 'query[hobby]'              => 'piercing'     }.to_query
225 225
         assert_equal params[1], { 'query[person][name]'       => 'Bob'          }.to_query
10  actionpack/test/dispatch/cookies_test.rb
@@ -47,7 +47,7 @@ def authenticate_with_http_only
47 47
       cookies["user_name"] = { :value => "david", :httponly => true }
48 48
       head :ok
49 49
     end
50  
-    
  50
+
51 51
     def authenticate_with_secure
52 52
       cookies["user_name"] = { :value => "david", :secure => true }
53 53
       head :ok
@@ -133,7 +133,7 @@ def test_setting_cookie_with_http_only
133 133
     assert_cookie_header "user_name=david; path=/; HttpOnly"
134 134
     assert_equal({"user_name" => "david"}, @response.cookies)
135 135
   end
136  
-  
  136
+
137 137
   def test_setting_cookie_with_secure
138 138
     get :authenticate_with_secure
139 139
     assert_cookie_header "user_name=david; path=/; secure"
@@ -169,8 +169,8 @@ def test_cookies_persist_throughout_request
169 169
 
170 170
   def test_permanent_cookie
171 171
     get :set_permanent_cookie
172  
-    assert_match /Jamie/, @response.headers["Set-Cookie"]
173  
-    assert_match %r(#{20.years.from_now.utc.year}), @response.headers["Set-Cookie"]
  172
+    assert_match(/Jamie/, @response.headers["Set-Cookie"])
  173
+    assert_match(%r(#{20.years.from_now.utc.year}), @response.headers["Set-Cookie"])
174 174
   end
175 175
 
176 176
   def test_signed_cookie
@@ -185,7 +185,7 @@ def test_accessing_nonexistant_signed_cookie_should_not_raise_an_invalid_signatu
185 185
 
186 186
   def test_permanent_signed_cookie
187 187
     get :set_permanent_signed_cookie
188  
-    assert_match %r(#{20.years.from_now.utc.year}), @response.headers["Set-Cookie"]
  188
+    assert_match(%r(#{20.years.from_now.utc.year}), @response.headers["Set-Cookie"])
189 189
     assert_equal 100, @controller.send(:cookies).signed[:remember_me]
190 190
   end
191 191
 
6  actionpack/test/dispatch/request_test.rb
@@ -45,9 +45,9 @@ class RequestTest < ActiveSupport::TestCase
45 45
     e = assert_raise(ActionDispatch::RemoteIp::IpSpoofAttackError) {
46 46
       request.remote_ip
47 47
     }
48  
-    assert_match /IP spoofing attack/, e.message
49  
-    assert_match /HTTP_X_FORWARDED_FOR="1.1.1.1"/, e.message
50  
-    assert_match /HTTP_CLIENT_IP="2.2.2.2"/, e.message
  48
+    assert_match(/IP spoofing attack/, e.message)
  49
+    assert_match(/HTTP_X_FORWARDED_FOR="1.1.1.1"/, e.message)
  50
+    assert_match(/HTTP_CLIENT_IP="2.2.2.2"/, e.message)
51 51
 
52 52
     # turn IP Spoofing detection off.
53 53
     # This is useful for sites that are aimed at non-IP clients.  The typical
2  actionpack/test/dispatch/session/cookie_store_test.rb
@@ -279,7 +279,7 @@ def test_session_store_with_expire_after
14  actionpack/test/dispatch/show_exceptions_test.rb
@@ -58,15 +58,15 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest
58 58
 
59 59
       get "/", {}, {'action_dispatch.show_exceptions' => true}
60 60
       assert_response 500
61  
-      assert_match /puke/, body
  61
+      assert_match(/puke/, body)
62 62
 
63 63
       get "/not_found", {}, {'action_dispatch.show_exceptions' => true}
64 64
       assert_response 404
65  
-      assert_match /#{ActionController::UnknownAction.name}/, body
  65
+      assert_match(/#{ActionController::UnknownAction.name}/, body)
66 66
 
67 67
       get "/method_not_allowed", {}, {'action_dispatch.show_exceptions' => true}
68 68
       assert_response 405
69  
-      assert_match /ActionController::MethodNotAllowed/, body
  69
+      assert_match(/ActionController::MethodNotAllowed/, body)
70 70
     end
71 71
   end
72 72
 
@@ -96,15 +96,15 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest
96 96
 
97 97
     get "/", {}, {'action_dispatch.show_exceptions' => true}
98 98
     assert_response 500
99  
-    assert_match /puke/, body
  99
+    assert_match(/puke/, body)
100 100
 
101 101
     get "/not_found", {}, {'action_dispatch.show_exceptions' => true}
102 102
     assert_response 404
103  
-    assert_match /#{ActionController::UnknownAction.name}/, body
  103
+    assert_match(/#{ActionController::UnknownAction.name}/, body)
104 104
 
105 105
     get "/method_not_allowed", {}, {'action_dispatch.show_exceptions' => true}
106 106
     assert_response 405
107  
-    assert_match /ActionController::MethodNotAllowed/, body
  107
+    assert_match(/ActionController::MethodNotAllowed/, body)
108 108
   end
109 109
 
110 110
   test "does not show filtered parameters" do
@@ -113,6 +113,6 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest
113 113
     get "/", {"foo"=>"bar"}, {'action_dispatch.show_exceptions' => true,
114 114
       'action_dispatch.parameter_filter' => [:foo]}
115 115
     assert_response 500
116  
-    assert_match "&quot;foo&quot;=&gt;&quot;[FILTERED]&quot;", body
  116
+    assert_match("&quot;foo&quot;=&gt;&quot;[FILTERED]&quot;", body)
117 117
   end
118 118
 end
2  actionpack/test/template/asset_tag_helper_test.rb
@@ -975,7 +975,7 @@ def test_should_ignore_asset_host_on_complete_url
975 975
 
976 976
   def test_should_wildcard_asset_host_between_zero_and_four
977 977
     @controller.config.asset_host = 'http://a%d.example.com'
978  
-    assert_match %r(http://a[0123].example.com/collaboration/hieraki/images/xml.png), image_path('xml.png')
  978
+    assert_match(%r(http://a[0123].example.com/collaboration/hieraki/images/xml.png), image_path('xml.png'))
979 979
   end
980 980
 
981 981
   def test_asset_host_without_protocol_should_use_request_protocol
2  actionpack/test/template/atom_feed_helper_test.rb
@@ -203,7 +203,7 @@ def setup
203 203
   def test_feed_should_use_default_language_if_none_is_given
204 204
     with_restful_routing(:scrolls) do
205 205
       get :index, :id => "defaults"
206  
-      assert_match %r{xml:lang="en-US"}, @response.body
  206
+      assert_match(%r{xml:lang="en-US"}, @response.body)
207 207
     end
208 208
   end
209 209
 
18  actionpack/test/template/log_subscriber_test.rb
@@ -29,7 +29,7 @@ def test_render_file_template
29 29
     wait
30 30
 
31 31
     assert_equal 1, @logger.logged(:info).size
32  
-    assert_match /Rendered test\/hello_world\.erb/, @logger.logged(:info).last
  32
+    assert_match(/Rendered test\/hello_world\.erb/, @logger.logged(:info).last)
33 33
   end
34 34
 
35 35
   def test_render_text_template
@@ -37,7 +37,7 @@ def test_render_text_template
37 37
     wait
38 38
 
39 39
     assert_equal 1, @logger.logged(:info).size
40  
-    assert_match /Rendered text template/, @logger.logged(:info).last
  40
+    assert_match(/Rendered text template/, @logger.logged(:info).last)
41 41
   end
42 42
 
43 43
   def test_render_inline_template
@@ -45,7 +45,7 @@ def test_render_inline_template
45 45
     wait
46 46
 
47 47
     assert_equal 1, @logger.logged(:info).size
48  
-    assert_match /Rendered inline template/, @logger.logged(:info).last
  48
+    assert_match(/Rendered inline template/, @logger.logged(:info).last)
49 49
   end
50 50
 
51 51
   def test_render_partial_template
@@ -53,7 +53,7 @@ def test_render_partial_template
53 53
     wait
54 54
 
55 55
     assert_equal 1, @logger.logged(:info).size
56  
-    assert_match /Rendered test\/_customer.erb/, @logger.logged(:info).last
  56
+    assert_match(/Rendered test\/_customer.erb/, @logger.logged(:info).last)
57 57
   end
58 58
 
59 59
   def test_render_partial_with_implicit_path
@@ -62,7 +62,7 @@ def test_render_partial_with_implicit_path
62 62
     wait
63 63
 
64 64
     assert_equal 1, @logger.logged(:info).size
65  
-    assert_match /Rendered customers\/_customer\.html\.erb/, @logger.logged(:info).last
  65
+    assert_match(/Rendered customers\/_customer\.html\.erb/, @logger.logged(:info).last)
66 66
   end
67 67
 
68 68
   def test_render_collection_template
@@ -70,7 +70,7 @@ def test_render_collection_template
70 70
     wait
71 71
 
72 72
     assert_equal 1, @logger.logged(:info).size
73  
-    assert_match /Rendered test\/_customer.erb/, @logger.logged(:info).last
  73
+    assert_match(/Rendered test\/_customer.erb/, @logger.logged(:info).last)
74 74
   end
75 75
 
76 76
   def test_render_collection_with_implicit_path
@@ -79,7 +79,7 @@ def test_render_collection_with_implicit_path
79 79
     wait
80 80
 
81 81
     assert_equal 1, @logger.logged(:info).size
82  
-    assert_match /Rendered customers\/_customer\.html\.erb/, @logger.logged(:info).last
  82
+    assert_match(/Rendered customers\/_customer\.html\.erb/, @logger.logged(:info).last)
83 83
   end
84 84
 
85 85
   def test_render_collection_template_without_path
@@ -88,6 +88,6 @@ def test_render_collection_template_without_path
88 88
     wait
89 89
 
90 90
     assert_equal 1, @logger.logged(:info).size
91  
-    assert_match /Rendered collection/, @logger.logged(:info).last
  91
+    assert_match(/Rendered collection/, @logger.logged(:info).last)
92 92
   end
93  
-end
  93
+end
4  actionpack/test/template/tag_helper_test.rb
@@ -11,8 +11,8 @@ def test_tag
11 11
 
12 12
   def test_tag_options
13 13
     str = tag("p", "class" => "show", :class => "elsewhere")
14  
-    assert_match /class="show"/, str
15  
-    assert_match /class="elsewhere"/, str
  14
+    assert_match(/class="show"/, str)
  15
+    assert_match(/class="elsewhere"/, str)
16 16
   end
17 17
 
18 18
   def test_tag_options_rejects_nil_option
6  actionpack/test/template/test_case_test.rb
@@ -112,7 +112,7 @@ def render_from_helper
112 112
       @controller.controller_path = 'test'
113 113
 
114 114
       @customers = [stub(:name => 'Eloy'), stub(:name => 'Manfred')]
115  
-      assert_match /Hello: EloyHello: Manfred/, render(:partial => 'test/from_helper')
  115
+      assert_match(/Hello: EloyHello: Manfred/, render(:partial => 'test/from_helper'))
116 116
     end
117 117
   end
118 118
 
@@ -201,7 +201,7 @@ def render_from_helper
201 201
       @controller.controller_path = "test"
202 202
 
203 203
       @customers = [stub(:name => 'Eloy'), stub(:name => 'Manfred')]
204  
-      assert_match /Hello: EloyHello: Manfred/, render(:file => 'test/list')
  204
+      assert_match(/Hello: EloyHello: Manfred/, render(:file => 'test/list'))
205 205
     end
206 206
 
207 207
     test "is able to render partials from templates and also use instance variables after view has been referenced" do
@@ -210,7 +210,7 @@ def render_from_helper
210 210
       view
211 211
 
212 212
       @customers = [stub(:name => 'Eloy'), stub(:name => 'Manfred')]
213  
-      assert_match /Hello: EloyHello: Manfred/, render(:file => 'test/list')
  213
+      assert_match(/Hello: EloyHello: Manfred/, render(:file => 'test/list'))
214 214
     end
215 215
 
216 216
   end

0 notes on commit 2d274a5

Please sign in to comment.
Something went wrong with that request. Please try again.