Skip to content

Commit

Permalink
Ruby 1.9 compat: rename deprecated assert_raises to assert_raise.
Browse files Browse the repository at this point in the history
[#1617 state:resolved]
  • Loading branch information
jeremy committed Mar 8, 2009
1 parent 0c40789 commit 1c36172
Show file tree
Hide file tree
Showing 59 changed files with 294 additions and 294 deletions.
Expand Up @@ -1150,7 +1150,7 @@ def test_format_style
assert_equal(Text::Format::JUSTIFY, @format_o.format_style)
assert_match(/^of freedom, and that government of the people, by the people, for the$/,
@format_o.format(GETTYSBURG).split("\n")[-3])
assert_raises(ArgumentError) { @format_o.format_style = 33 }
assert_raise(ArgumentError) { @format_o.format_style = 33 }
end

def test_tag_paragraph
Expand Down
2 changes: 1 addition & 1 deletion actionmailer/test/mail_service_test.rb
Expand Up @@ -1069,7 +1069,7 @@ def test_should_not_respond_to_method_where_deliver_is_not_a_suffix
end

def test_should_still_raise_exception_with_expected_message_when_calling_an_undefined_method
error = assert_raises NoMethodError do
error = assert_raise NoMethodError do
RespondToMailer.not_a_method
end

Expand Down
8 changes: 4 additions & 4 deletions actionmailer/test/test_helper_test.rb
Expand Up @@ -26,7 +26,7 @@ def test_mailer_class_is_correctly_inferred
end

def test_determine_default_mailer_raises_correct_error
assert_raises(ActionMailer::NonInferrableMailerError) do
assert_raise(ActionMailer::NonInferrableMailerError) do
self.class.determine_default_mailer("NotAMailerTest")
end
end
Expand Down Expand Up @@ -84,7 +84,7 @@ def test_assert_no_emails
end

def test_assert_emails_too_few_sent
error = assert_raises ActiveSupport::TestCase::Assertion do
error = assert_raise ActiveSupport::TestCase::Assertion do
assert_emails 2 do
TestHelperMailer.deliver_test
end
Expand All @@ -94,7 +94,7 @@ def test_assert_emails_too_few_sent
end

def test_assert_emails_too_many_sent
error = assert_raises ActiveSupport::TestCase::Assertion do
error = assert_raise ActiveSupport::TestCase::Assertion do
assert_emails 1 do
TestHelperMailer.deliver_test
TestHelperMailer.deliver_test
Expand All @@ -105,7 +105,7 @@ def test_assert_emails_too_many_sent
end

def test_assert_no_emails_failure
error = assert_raises ActiveSupport::TestCase::Assertion do
error = assert_raise ActiveSupport::TestCase::Assertion do
assert_no_emails do
TestHelperMailer.deliver_test
end
Expand Down
56 changes: 28 additions & 28 deletions actionpack/test/controller/assert_select_test.rb
Expand Up @@ -76,7 +76,7 @@ def teardown
end

def assert_failure(message, &block)
e = assert_raises(Assertion, &block)
e = assert_raise(Assertion, &block)
assert_match(message, e.message) if Regexp === message
assert_equal(message, e.message) if String === message
end
Expand All @@ -95,42 +95,42 @@ def test_assert_select
def test_equality_true_false
render_html %Q{<div id="1"></div><div id="2"></div>}
assert_nothing_raised { assert_select "div" }
assert_raises(Assertion) { assert_select "p" }
assert_raise(Assertion) { assert_select "p" }
assert_nothing_raised { assert_select "div", true }
assert_raises(Assertion) { assert_select "p", true }
assert_raises(Assertion) { assert_select "div", false }
assert_raise(Assertion) { assert_select "p", true }
assert_raise(Assertion) { assert_select "div", false }
assert_nothing_raised { assert_select "p", false }
end

def test_equality_string_and_regexp
render_html %Q{<div id="1">foo</div><div id="2">foo</div>}
assert_nothing_raised { assert_select "div", "foo" }
assert_raises(Assertion) { assert_select "div", "bar" }
assert_raise(Assertion) { assert_select "div", "bar" }
assert_nothing_raised { assert_select "div", :text=>"foo" }
assert_raises(Assertion) { assert_select "div", :text=>"bar" }
assert_raise(Assertion) { assert_select "div", :text=>"bar" }
assert_nothing_raised { assert_select "div", /(foo|bar)/ }
assert_raises(Assertion) { assert_select "div", /foobar/ }
assert_raise(Assertion) { assert_select "div", /foobar/ }
assert_nothing_raised { assert_select "div", :text=>/(foo|bar)/ }
assert_raises(Assertion) { assert_select "div", :text=>/foobar/ }
assert_raises(Assertion) { assert_select "p", :text=>/foobar/ }
assert_raise(Assertion) { assert_select "div", :text=>/foobar/ }
assert_raise(Assertion) { assert_select "p", :text=>/foobar/ }
end

def test_equality_of_html
render_html %Q{<p>\n<em>"This is <strong>not</strong> a big problem,"</em> he said.\n</p>}
text = "\"This is not a big problem,\" he said."
html = "<em>\"This is <strong>not</strong> a big problem,\"</em> he said."
assert_nothing_raised { assert_select "p", text }
assert_raises(Assertion) { assert_select "p", html }
assert_raise(Assertion) { assert_select "p", html }
assert_nothing_raised { assert_select "p", :html=>html }
assert_raises(Assertion) { assert_select "p", :html=>text }
assert_raise(Assertion) { assert_select "p", :html=>text }
# No stripping for pre.
render_html %Q{<pre>\n<em>"This is <strong>not</strong> a big problem,"</em> he said.\n</pre>}
text = "\n\"This is not a big problem,\" he said.\n"
html = "\n<em>\"This is <strong>not</strong> a big problem,\"</em> he said.\n"
assert_nothing_raised { assert_select "pre", text }
assert_raises(Assertion) { assert_select "pre", html }
assert_raise(Assertion) { assert_select "pre", html }
assert_nothing_raised { assert_select "pre", :html=>html }
assert_raises(Assertion) { assert_select "pre", :html=>text }
assert_raise(Assertion) { assert_select "pre", :html=>text }
end

def test_counts
Expand Down Expand Up @@ -210,12 +210,12 @@ def test_assert_select_text_match
assert_nothing_raised { assert_select "div", "bar" }
assert_nothing_raised { assert_select "div", /\w*/ }
assert_nothing_raised { assert_select "div", /\w*/, :count=>2 }
assert_raises(Assertion) { assert_select "div", :text=>"foo", :count=>2 }
assert_raise(Assertion) { assert_select "div", :text=>"foo", :count=>2 }
assert_nothing_raised { assert_select "div", :html=>"<span>bar</span>" }
assert_nothing_raised { assert_select "div", :html=>"<span>bar</span>" }
assert_nothing_raised { assert_select "div", :html=>/\w*/ }
assert_nothing_raised { assert_select "div", :html=>/\w*/, :count=>2 }
assert_raises(Assertion) { assert_select "div", :html=>"<span>foo</span>", :count=>2 }
assert_raise(Assertion) { assert_select "div", :html=>"<span>foo</span>", :count=>2 }
end
end

Expand Down Expand Up @@ -253,7 +253,7 @@ def test_assert_select_rjs_for_positioned_insert_should_fail_when_mixing_argumen
page.insert_html :top, "test1", "<div id=\"1\">foo</div>"
page.insert_html :bottom, "test2", "<div id=\"2\">foo</div>"
end
assert_raises(Assertion) {assert_select_rjs :insert, :top, "test2"}
assert_raise(Assertion) {assert_select_rjs :insert, :top, "test2"}
end

def test_elect_with_xml_namespace_attributes
Expand Down Expand Up @@ -336,7 +336,7 @@ def test_assert_select_rjs_picks_up_all_statements
# Test that we fail if there is nothing to pick.
def test_assert_select_rjs_fails_if_nothing_to_pick
render_rjs { }
assert_raises(Assertion) { assert_select_rjs }
assert_raise(Assertion) { assert_select_rjs }
end

def test_assert_select_rjs_with_unicode
Expand All @@ -351,10 +351,10 @@ def test_assert_select_rjs_with_unicode
if str.respond_to?(:force_encoding)
str.force_encoding(Encoding::UTF_8)
assert_select str, /\343\203\201..\343\203\210/u
assert_raises(Assertion) { assert_select str, /\343\203\201.\343\203\210/u }
assert_raise(Assertion) { assert_select str, /\343\203\201.\343\203\210/u }
else
assert_select str, Regexp.new("\343\203\201..\343\203\210",0,'U')
assert_raises(Assertion) { assert_select str, Regexp.new("\343\203\201.\343\203\210",0,'U') }
assert_raise(Assertion) { assert_select str, Regexp.new("\343\203\201.\343\203\210",0,'U') }
end
end
end
Expand All @@ -378,7 +378,7 @@ def test_assert_select_rjs_with_id
assert_select "div", 1
assert_select "#3"
end
assert_raises(Assertion) { assert_select_rjs "test4" }
assert_raise(Assertion) { assert_select_rjs "test4" }
end

def test_assert_select_rjs_for_replace
Expand All @@ -396,7 +396,7 @@ def test_assert_select_rjs_for_replace
assert_select "div", 1
assert_select "#1"
end
assert_raises(Assertion) { assert_select_rjs :replace, "test2" }
assert_raise(Assertion) { assert_select_rjs :replace, "test2" }
# Replace HTML.
assert_select_rjs :replace_html do
assert_select "div", 1
Expand All @@ -406,7 +406,7 @@ def test_assert_select_rjs_for_replace
assert_select "div", 1
assert_select "#2"
end
assert_raises(Assertion) { assert_select_rjs :replace_html, "test1" }
assert_raise(Assertion) { assert_select_rjs :replace_html, "test1" }
end

def test_assert_select_rjs_for_chained_replace
Expand All @@ -424,7 +424,7 @@ def test_assert_select_rjs_for_chained_replace
assert_select "div", 1
assert_select "#1"
end
assert_raises(Assertion) { assert_select_rjs :chained_replace, "test2" }
assert_raise(Assertion) { assert_select_rjs :chained_replace, "test2" }
# Replace HTML.
assert_select_rjs :chained_replace_html do
assert_select "div", 1
Expand All @@ -434,7 +434,7 @@ def test_assert_select_rjs_for_chained_replace
assert_select "div", 1
assert_select "#2"
end
assert_raises(Assertion) { assert_select_rjs :replace_html, "test1" }
assert_raise(Assertion) { assert_select_rjs :replace_html, "test1" }
end

# Simple remove
Expand Down Expand Up @@ -580,7 +580,7 @@ def test_assert_select_rjs_for_nonpositioned_insert
assert_select "div", 1
assert_select "#3"
end
assert_raises(Assertion) { assert_select_rjs :insert_html, "test1" }
assert_raise(Assertion) { assert_select_rjs :insert_html, "test1" }
end

# Positioned insert.
Expand Down Expand Up @@ -613,8 +613,8 @@ def test_assert_select_rjs_for_positioned_insert
end

def test_assert_select_rjs_raise_errors
assert_raises(ArgumentError) { assert_select_rjs(:destroy) }
assert_raises(ArgumentError) { assert_select_rjs(:insert, :left) }
assert_raise(ArgumentError) { assert_select_rjs(:destroy) }
assert_raise(ArgumentError) { assert_select_rjs(:insert, :left) }
end

# Simple selection from a single result.
Expand Down Expand Up @@ -706,7 +706,7 @@ def test_feed_item_encoded
#

def test_assert_select_email
assert_raises(Assertion) { assert_select_email {} }
assert_raise(Assertion) { assert_select_email {} }
AssertSelectMailer.deliver_test "<div><p>foo</p><p>bar</p></div>"
assert_select_email do
assert_select "div:root" do
Expand Down
2 changes: 1 addition & 1 deletion actionpack/test/controller/html-scanner/document_test.rb
Expand Up @@ -134,7 +134,7 @@ def test_parse_invalid_document
end

def test_invalid_document_raises_exception_when_strict
assert_raises RuntimeError do
assert_raise RuntimeError do
doc = HTML::Document.new("<html>
<table>
<tr>
Expand Down
2 changes: 1 addition & 1 deletion actionpack/test/controller/mime_responds_test.rb
Expand Up @@ -469,7 +469,7 @@ def test_format_with_custom_response_type_and_request_headers_with_only_one_layo
assert_equal '<html><div id="html_missing">Hello future from Firefox!</div></html>', @response.body

@request.accept = "text/iphone"
assert_raises(ActionView::MissingTemplate) { get :iphone_with_html_response_type_without_layout }
assert_raise(ActionView::MissingTemplate) { get :iphone_with_html_response_type_without_layout }
end
end

Expand Down
4 changes: 2 additions & 2 deletions actionpack/test/controller/redirect_test.rb
Expand Up @@ -212,7 +212,7 @@ def test_redirect_to_back
end

def test_redirect_to_back_with_no_referer
assert_raises(ActionController::RedirectBackError) {
assert_raise(ActionController::RedirectBackError) {
@request.env["HTTP_REFERER"] = nil
get :redirect_to_back
}
Expand All @@ -239,7 +239,7 @@ def test_redirect_with_partial_params
end

def test_redirect_to_nil
assert_raises(ActionController::ActionControllerError) do
assert_raise(ActionController::ActionControllerError) do
get :redirect_to_nil
end
end
Expand Down
14 changes: 7 additions & 7 deletions actionpack/test/controller/render_test.rb
Expand Up @@ -937,11 +937,11 @@ def test_render_nothing_with_appendix
end

def test_attempt_to_access_object_method
assert_raises(ActionController::UnknownAction, "No action responded to [clone]") { get :clone }
assert_raise(ActionController::UnknownAction, "No action responded to [clone]") { get :clone }
end

def test_private_methods
assert_raises(ActionController::UnknownAction, "No action responded to [determine_layout]") { get :determine_layout }
assert_raise(ActionController::UnknownAction, "No action responded to [determine_layout]") { get :determine_layout }
end

def test_access_to_request_in_view
Expand Down Expand Up @@ -1173,7 +1173,7 @@ def test_render_to_string_doesnt_break_assigns
end

def test_bad_render_to_string_still_throws_exception
assert_raises(ActionView::MissingTemplate) { get :render_to_string_with_exception }
assert_raise(ActionView::MissingTemplate) { get :render_to_string_with_exception }
end

def test_render_to_string_that_throws_caught_exception_doesnt_break_assigns
Expand All @@ -1198,15 +1198,15 @@ def test_render_with_explicit_string_template
end

def test_double_render
assert_raises(ActionController::DoubleRenderError) { get :double_render }
assert_raise(ActionController::DoubleRenderError) { get :double_render }
end

def test_double_redirect
assert_raises(ActionController::DoubleRenderError) { get :double_redirect }
assert_raise(ActionController::DoubleRenderError) { get :double_redirect }
end

def test_render_and_redirect
assert_raises(ActionController::DoubleRenderError) { get :render_and_redirect }
assert_raise(ActionController::DoubleRenderError) { get :render_and_redirect }
end

# specify the one exception to double render rule - render_to_string followed by render
Expand Down Expand Up @@ -1515,7 +1515,7 @@ def test_partial_with_implicit_local_assignment
end

def test_render_missing_partial_template
assert_raises(ActionView::MissingTemplate) do
assert_raise(ActionView::MissingTemplate) do
get :missing_partial
end
end
Expand Down
18 changes: 9 additions & 9 deletions actionpack/test/controller/request_forgery_protection_test.rb
Expand Up @@ -79,17 +79,17 @@ def test_should_allow_post_without_token_on_unsafe_action

def test_should_not_allow_html_post_without_token
@request.env['CONTENT_TYPE'] = Mime::URL_ENCODED_FORM.to_s
assert_raises(ActionController::InvalidAuthenticityToken) { post :index, :format => :html }
assert_raise(ActionController::InvalidAuthenticityToken) { post :index, :format => :html }
end

def test_should_not_allow_html_put_without_token
@request.env['CONTENT_TYPE'] = Mime::URL_ENCODED_FORM.to_s
assert_raises(ActionController::InvalidAuthenticityToken) { put :index, :format => :html }
assert_raise(ActionController::InvalidAuthenticityToken) { put :index, :format => :html }
end

def test_should_not_allow_html_delete_without_token
@request.env['CONTENT_TYPE'] = Mime::URL_ENCODED_FORM.to_s
assert_raises(ActionController::InvalidAuthenticityToken) { delete :index, :format => :html }
assert_raise(ActionController::InvalidAuthenticityToken) { delete :index, :format => :html }
end

def test_should_allow_api_formatted_post_without_token
Expand All @@ -111,42 +111,42 @@ def test_should_allow_api_formatted_delete_without_token
end

def test_should_not_allow_api_formatted_post_sent_as_url_encoded_form_without_token
assert_raises(ActionController::InvalidAuthenticityToken) do
assert_raise(ActionController::InvalidAuthenticityToken) do
@request.env['CONTENT_TYPE'] = Mime::URL_ENCODED_FORM.to_s
post :index, :format => 'xml'
end
end

def test_should_not_allow_api_formatted_put_sent_as_url_encoded_form_without_token
assert_raises(ActionController::InvalidAuthenticityToken) do
assert_raise(ActionController::InvalidAuthenticityToken) do
@request.env['CONTENT_TYPE'] = Mime::URL_ENCODED_FORM.to_s
put :index, :format => 'xml'
end
end

def test_should_not_allow_api_formatted_delete_sent_as_url_encoded_form_without_token
assert_raises(ActionController::InvalidAuthenticityToken) do
assert_raise(ActionController::InvalidAuthenticityToken) do
@request.env['CONTENT_TYPE'] = Mime::URL_ENCODED_FORM.to_s
delete :index, :format => 'xml'
end
end

def test_should_not_allow_api_formatted_post_sent_as_multipart_form_without_token
assert_raises(ActionController::InvalidAuthenticityToken) do
assert_raise(ActionController::InvalidAuthenticityToken) do
@request.env['CONTENT_TYPE'] = Mime::MULTIPART_FORM.to_s
post :index, :format => 'xml'
end
end

def test_should_not_allow_api_formatted_put_sent_as_multipart_form_without_token
assert_raises(ActionController::InvalidAuthenticityToken) do
assert_raise(ActionController::InvalidAuthenticityToken) do
@request.env['CONTENT_TYPE'] = Mime::MULTIPART_FORM.to_s
put :index, :format => 'xml'
end
end

def test_should_not_allow_api_formatted_delete_sent_as_multipart_form_without_token
assert_raises(ActionController::InvalidAuthenticityToken) do
assert_raise(ActionController::InvalidAuthenticityToken) do
@request.env['CONTENT_TYPE'] = Mime::MULTIPART_FORM.to_s
delete :index, :format => 'xml'
end
Expand Down

0 comments on commit 1c36172

Please sign in to comment.