From 1fdb9deb7c1b158fe3f5f230bb3c941b620fcf7d Mon Sep 17 00:00:00 2001 From: Matt Duncan Date: Sat, 30 Jan 2010 10:34:45 -0500 Subject: [PATCH] Remove usages of assert_raises and use assert_raise instead --- actionpack/test/abstract/layouts_test.rb | 8 ++++---- .../test/controller/new_base/render_layout_test.rb | 2 +- actionpack/test/controller/new_base/render_test.rb | 6 +++--- activemodel/test/cases/attribute_methods_test.rb | 2 +- activerecord/test/cases/adapter_test.rb | 4 ++-- .../has_many_through_associations_test.rb | 12 ++++++------ activerecord/test/cases/named_scope_test.rb | 2 +- activerecord/test/cases/nested_attributes_test.rb | 2 +- activerecord/test/cases/relations_test.rb | 10 +++++----- activeresource/test/cases/base/schema_test.rb | 12 ++++++------ activesupport/test/core_ext/string_ext_test.rb | 8 ++++---- activesupport/test/multibyte_utils_test.rb | 2 +- railties/test/application/configuration_test.rb | 4 ++-- .../initializers/check_ruby_version_test.rb | 2 +- .../application/initializers/frameworks_test.rb | 2 +- railties/test/paths_test.rb | 4 ++-- railties/test/railties/shared_tests.rb | 2 +- 17 files changed, 42 insertions(+), 42 deletions(-) diff --git a/actionpack/test/abstract/layouts_test.rb b/actionpack/test/abstract/layouts_test.rb index bf02e5a..7992b1e 100644 --- a/actionpack/test/abstract/layouts_test.rb +++ b/actionpack/test/abstract/layouts_test.rb @@ -191,7 +191,7 @@ module AbstractControllerTests end test "when layout is specified as a string, but the layout is missing, raise an exception" do - assert_raises(ActionView::MissingTemplate) { WithMissingLayout.new.process(:index) } + assert_raise(ActionView::MissingTemplate) { WithMissingLayout.new.process(:index) } end test "when layout is specified as false, do not use a layout" do @@ -225,11 +225,11 @@ module AbstractControllerTests end test "when the layout is specified as a symbol and the method doesn't exist, raise an exception" do - assert_raises(NoMethodError) { WithSymbolAndNoMethod.new.process(:index) } + assert_raise(NoMethodError) { WithSymbolAndNoMethod.new.process(:index) } end test "when the layout is specified as a symbol and the method returns something besides a string/false/nil, raise an exception" do - assert_raises(ArgumentError) { WithSymbolReturningObj.new.process(:index) } + assert_raise(ArgumentError) { WithSymbolReturningObj.new.process(:index) } end test "when a child controller does not have a layout, use the parent controller layout" do @@ -264,7 +264,7 @@ module AbstractControllerTests end test "raises an exception when specifying layout true" do - assert_raises ArgumentError do + assert_raise ArgumentError do Object.class_eval do class ::BadOmgFailLolLayout < AbstractControllerTests::Layouts::Base layout true diff --git a/actionpack/test/controller/new_base/render_layout_test.rb b/actionpack/test/controller/new_base/render_layout_test.rb index 6a9668b..409f381 100644 --- a/actionpack/test/controller/new_base/render_layout_test.rb +++ b/actionpack/test/controller/new_base/render_layout_test.rb @@ -93,7 +93,7 @@ module ControllerLayouts end test "if an HTML template is explicitly provides for a JS template, an error is raised" do - assert_raises ActionView::MissingTemplate do + assert_raise ActionView::MissingTemplate do get :explicit, {}, "action_dispatch.show_exceptions" => false end end diff --git a/actionpack/test/controller/new_base/render_test.rb b/actionpack/test/controller/new_base/render_test.rb index d985d9f..2afb029 100644 --- a/actionpack/test/controller/new_base/render_test.rb +++ b/actionpack/test/controller/new_base/render_test.rb @@ -44,7 +44,7 @@ module Render end test "rendering more than once raises an exception" do - assert_raises(AbstractController::DoubleRenderError) do + assert_raise(AbstractController::DoubleRenderError) do get "/render/double_render", {}, "action_dispatch.show_exceptions" => false end end @@ -54,13 +54,13 @@ module Render describe "Only public methods on actual controllers are callable actions" test "raises an exception when a method of Object is called" do - assert_raises(AbstractController::ActionNotFound) do + assert_raise(AbstractController::ActionNotFound) do get "/render/blank_render/clone", {}, "action_dispatch.show_exceptions" => false end end test "raises an exception when a private method is called" do - assert_raises(AbstractController::ActionNotFound) do + assert_raise(AbstractController::ActionNotFound) do get "/render/blank_render/secretz", {}, "action_dispatch.show_exceptions" => false end end diff --git a/activemodel/test/cases/attribute_methods_test.rb b/activemodel/test/cases/attribute_methods_test.rb index 5659dcb..13beef6 100644 --- a/activemodel/test/cases/attribute_methods_test.rb +++ b/activemodel/test/cases/attribute_methods_test.rb @@ -41,6 +41,6 @@ class AttributeMethodsTest < ActiveModel::TestCase assert !ModelWithAttributes.attribute_methods_generated? assert !ModelWithAttributes.new.respond_to?(:foo) - assert_raises(NoMethodError) { ModelWithAttributes.new.foo } + assert_raise(NoMethodError) { ModelWithAttributes.new.foo } end end diff --git a/activerecord/test/cases/adapter_test.rb b/activerecord/test/cases/adapter_test.rb index c59be26..02ce8b7 100644 --- a/activerecord/test/cases/adapter_test.rb +++ b/activerecord/test/cases/adapter_test.rb @@ -124,14 +124,14 @@ class AdapterTest < ActiveRecord::TestCase def test_uniqueness_violations_are_translated_to_specific_exception @connection.execute "INSERT INTO subscribers(nick) VALUES('me')" - assert_raises(ActiveRecord::RecordNotUnique) do + assert_raise(ActiveRecord::RecordNotUnique) do @connection.execute "INSERT INTO subscribers(nick) VALUES('me')" end end def test_foreign_key_violations_are_translated_to_specific_exception unless @connection.adapter_name == 'SQLite' - assert_raises(ActiveRecord::InvalidForeignKey) do + assert_raise(ActiveRecord::InvalidForeignKey) do # Oracle adapter uses prefetched primary key values from sequence and passes them to connection adapter insert method if @connection.prefetch_primary_key? id_value = @connection.next_sequence_value(@connection.default_sequence_name("fk_test_has_fk", "id")) diff --git a/activerecord/test/cases/associations/has_many_through_associations_test.rb b/activerecord/test/cases/associations/has_many_through_associations_test.rb index 608d5a3..d0e4c3f 100644 --- a/activerecord/test/cases/associations/has_many_through_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb @@ -197,8 +197,8 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase def test_create_on_new_record p = Post.new - assert_raises(ActiveRecord::RecordNotSaved) { p.people.create(:first_name => "mew") } - assert_raises(ActiveRecord::RecordNotSaved) { p.people.create!(:first_name => "snow") } + assert_raise(ActiveRecord::RecordNotSaved) { p.people.create(:first_name => "mew") } + assert_raise(ActiveRecord::RecordNotSaved) { p.people.create!(:first_name => "snow") } end def test_associate_with_create_and_invalid_options @@ -213,7 +213,7 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase def test_associate_with_create_bang_and_invalid_options firm = companies(:first_firm) - assert_no_difference('firm.developers.count') { assert_raises(ActiveRecord::RecordInvalid) { firm.developers.create!(:name => '0') } } + assert_no_difference('firm.developers.count') { assert_raise(ActiveRecord::RecordInvalid) { firm.developers.create!(:name => '0') } } end def test_associate_with_create_bang_and_valid_options @@ -223,7 +223,7 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase def test_push_with_invalid_record firm = companies(:first_firm) - assert_raises(ActiveRecord::RecordInvalid) { firm.developers << Developer.new(:name => '0') } + assert_raise(ActiveRecord::RecordInvalid) { firm.developers << Developer.new(:name => '0') } end def test_push_with_invalid_join_record @@ -232,10 +232,10 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase firm = companies(:first_firm) lifo = Developer.new(:name => 'lifo') - assert_raises(ActiveRecord::RecordInvalid) { firm.developers << lifo } + assert_raise(ActiveRecord::RecordInvalid) { firm.developers << lifo } lifo = Developer.create!(:name => 'lifo') - assert_raises(ActiveRecord::RecordInvalid) { firm.developers << lifo } + assert_raise(ActiveRecord::RecordInvalid) { firm.developers << lifo } end end diff --git a/activerecord/test/cases/named_scope_test.rb b/activerecord/test/cases/named_scope_test.rb index 894d963..e667793 100644 --- a/activerecord/test/cases/named_scope_test.rb +++ b/activerecord/test/cases/named_scope_test.rb @@ -372,7 +372,7 @@ class NamedScopeTest < ActiveRecord::TestCase def test_named_scopes_with_reserved_names [:where, :with_scope].each do |protected_method| - assert_raises(ArgumentError) { Topic.scope protected_method } + assert_raise(ArgumentError) { Topic.scope protected_method } end end diff --git a/activerecord/test/cases/nested_attributes_test.rb b/activerecord/test/cases/nested_attributes_test.rb index 7ca9c41..f5f3dab 100644 --- a/activerecord/test/cases/nested_attributes_test.rb +++ b/activerecord/test/cases/nested_attributes_test.rb @@ -690,7 +690,7 @@ class TestNestedAttributesLimit < ActiveRecord::TestCase end def test_limit_with_exceeding_records - assert_raises(ActiveRecord::NestedAttributes::TooManyRecords) do + assert_raise(ActiveRecord::NestedAttributes::TooManyRecords) do @pirate.attributes = { :parrots_attributes => { 'foo' => { :name => 'Lovely Day' }, 'bar' => { :name => 'Blown Away' }, 'car' => { :name => 'The Happening' }} } diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index 1e34539..24d2f42 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -290,7 +290,7 @@ class RelationTest < ActiveRecord::TestCase author = Author.scoped.find_by_id!(authors(:david).id) assert_equal "David", author.name - assert_raises(ActiveRecord::RecordNotFound) { Author.scoped.find_by_id_and_name!(20, 'invalid') } + assert_raise(ActiveRecord::RecordNotFound) { Author.scoped.find_by_id_and_name!(20, 'invalid') } end def test_dynamic_find_all_by_attributes @@ -327,7 +327,7 @@ class RelationTest < ActiveRecord::TestCase david = authors.find(authors(:david).id) assert_equal 'David', david.name - assert_raises(ActiveRecord::RecordNotFound) { authors.where(:name => 'lifo').find('42') } + assert_raise(ActiveRecord::RecordNotFound) { authors.where(:name => 'lifo').find('42') } end def test_find_ids @@ -340,8 +340,8 @@ class RelationTest < ActiveRecord::TestCase assert_equal 'Mary', results[1].name assert_equal results, authors.find([authors(:david).id, authors(:mary).id]) - assert_raises(ActiveRecord::RecordNotFound) { authors.where(:name => 'lifo').find(authors(:david).id, '42') } - assert_raises(ActiveRecord::RecordNotFound) { authors.find(['42', 43]) } + assert_raise(ActiveRecord::RecordNotFound) { authors.where(:name => 'lifo').find(authors(:david).id, '42') } + assert_raise(ActiveRecord::RecordNotFound) { authors.find(['42', 43]) } end def test_find_in_empty_array @@ -545,7 +545,7 @@ class RelationTest < ActiveRecord::TestCase def test_create_bang birds = Bird.scoped - assert_raises(ActiveRecord::RecordInvalid) { birds.create! } + assert_raise(ActiveRecord::RecordInvalid) { birds.create! } hen = birds.where(:name => 'hen').create! assert_kind_of Bird, hen diff --git a/activeresource/test/cases/base/schema_test.rb b/activeresource/test/cases/base/schema_test.rb index d9dc679..ce2d60b 100644 --- a/activeresource/test/cases/base/schema_test.rb +++ b/activeresource/test/cases/base/schema_test.rb @@ -71,7 +71,7 @@ class SchemaTest < ActiveModel::TestCase test "schema should only accept a hash" do ["blahblah", ['one','two'], [:age, :name], Person.new].each do |bad_schema| - assert_raises(ArgumentError,"should only accept a hash (or nil), but accepted: #{bad_schema.inspect}") do + assert_raise(ArgumentError,"should only accept a hash (or nil), but accepted: #{bad_schema.inspect}") do Person.schema = bad_schema end end @@ -102,7 +102,7 @@ class SchemaTest < ActiveModel::TestCase bad_values = [ :oogle, :blob, 'thing'] bad_values.each do |bad_value| - assert_raises(ArgumentError,"should only accept a known attribute type, but accepted: #{bad_value.inspect}") do + assert_raise(ArgumentError,"should only accept a known attribute type, but accepted: #{bad_value.inspect}") do Person.schema = {'key' => bad_value} end end @@ -248,14 +248,14 @@ class SchemaTest < ActiveModel::TestCase bad_values.each do |bad_value| s = nil - assert_raises(ArgumentError,"should only accept a known attribute type, but accepted: #{bad_value.inspect}") do + assert_raise(ArgumentError,"should only accept a known attribute type, but accepted: #{bad_value.inspect}") do Person.schema do s = self attribute 'key', bad_value end end assert !self.respond_to?(bad_value), "should only respond to a known attribute type, but accepted: #{bad_value.inspect}" - assert_raises(NoMethodError,"should only have methods for known attribute types, but accepted: #{bad_value.inspect}") do + assert_raise(NoMethodError,"should only have methods for known attribute types, but accepted: #{bad_value.inspect}") do Person.schema do send bad_value, 'key' end @@ -338,10 +338,10 @@ class SchemaTest < ActiveModel::TestCase assert Person.schema.blank?, "sanity check - should have a blank class schema" - assert_raises(NoMethodError, "should not have found the attribute: #{new_attr_name} as a method") do + assert_raise(NoMethodError, "should not have found the attribute: #{new_attr_name} as a method") do Person.new.send(new_attr_name) end - assert_raises(NoMethodError, "should not have found the attribute: #{new_attr_name_two} as a method") do + assert_raise(NoMethodError, "should not have found the attribute: #{new_attr_name_two} as a method") do Person.new.send(new_attr_name_two) end diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb index 9a805bc..ee83667 100644 --- a/activesupport/test/core_ext/string_ext_test.rb +++ b/activesupport/test/core_ext/string_ext_test.rb @@ -293,8 +293,8 @@ class TestGetTextString < Test::Unit::TestCase end def test_sprintf_lack_argument - assert_raises(KeyError) { "%{num}, %{record}" % {:record => "test"} } - assert_raises(KeyError) { "%{record}" % {:num => 1} } + assert_raise(KeyError) { "%{num}, %{record}" % {:record => "test"} } + assert_raise(KeyError) { "%{record}" % {:num => 1} } end def test_no_placeholder @@ -327,8 +327,8 @@ class TestGetTextString < Test::Unit::TestCase end def test_string_interpolation_raises_an_argument_error_when_mixing_named_and_unnamed_placeholders - assert_raises(ArgumentError) { "%{name} %f" % [1.0] } - assert_raises(ArgumentError) { "%{name} %f" % [1.0, 2.0] } + assert_raise(ArgumentError) { "%{name} %f" % [1.0] } + assert_raise(ArgumentError) { "%{name} %f" % [1.0, 2.0] } end end diff --git a/activesupport/test/multibyte_utils_test.rb b/activesupport/test/multibyte_utils_test.rb index 1dff944..f905fc6 100644 --- a/activesupport/test/multibyte_utils_test.rb +++ b/activesupport/test/multibyte_utils_test.rb @@ -43,7 +43,7 @@ class MultibyteUtilsTest < ActiveSupport::TestCase test "verify! raises an exception when it finds an invalid character" do with_encoding('UTF8') do - assert_raises(ActiveSupport::Multibyte::EncodingError) do + assert_raise(ActiveSupport::Multibyte::EncodingError) do ActiveSupport::Multibyte.verify!(example('invalid UTF-8')) end end diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 60d644b..7ab557a 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -128,7 +128,7 @@ module ApplicationTests test "runtime error is raised if config.frameworks= is used" do add_to_config "config.frameworks = []" - assert_raises RuntimeError do + assert_raise RuntimeError do require "#{app_path}/config/environment" end end @@ -136,7 +136,7 @@ module ApplicationTests test "runtime error is raised if config.frameworks is used" do add_to_config "config.frameworks -= []" - assert_raises RuntimeError do + assert_raise RuntimeError do require "#{app_path}/config/environment" end end diff --git a/railties/test/application/initializers/check_ruby_version_test.rb b/railties/test/application/initializers/check_ruby_version_test.rb index 58782b2..7cb477a 100644 --- a/railties/test/application/initializers/check_ruby_version_test.rb +++ b/railties/test/application/initializers/check_ruby_version_test.rb @@ -25,7 +25,7 @@ module ApplicationTests def assert_rails_does_not_boot $stderr = File.open("/dev/null", "w") - assert_raises(SystemExit) do + assert_raise(SystemExit) do require "rails/all" end end diff --git a/railties/test/application/initializers/frameworks_test.rb b/railties/test/application/initializers/frameworks_test.rb index 1e7b9c9..3d18ce1 100644 --- a/railties/test/application/initializers/frameworks_test.rb +++ b/railties/test/application/initializers/frameworks_test.rb @@ -46,7 +46,7 @@ module ApplicationTests Dir.chdir("#{app_path}/app") do require "#{app_path}/config/environment" - assert_raises(NoMethodError) { [1,2,3].rand } + assert_raise(NoMethodError) { [1,2,3].rand } end end diff --git a/railties/test/paths_test.rb b/railties/test/paths_test.rb index 92c7b2b..cd87e74 100644 --- a/railties/test/paths_test.rb +++ b/railties/test/paths_test.rb @@ -33,7 +33,7 @@ class PathsTest < ActiveSupport::TestCase test "raises exception if root path never set" do root = Rails::Paths::Root.new(nil) root.app = "app" - assert_raises RuntimeError do + assert_raise RuntimeError do root.app.to_a end end @@ -44,7 +44,7 @@ class PathsTest < ActiveSupport::TestCase end test "trying to access a path that does not exist raises NoMethodError" do - assert_raises(NoMethodError) { @root.app } + assert_raise(NoMethodError) { @root.app } end test "relative paths are relative to the paths root" do diff --git a/railties/test/railties/shared_tests.rb b/railties/test/railties/shared_tests.rb index d51a0d1..9f183af 100644 --- a/railties/test/railties/shared_tests.rb +++ b/railties/test/railties/shared_tests.rb @@ -39,7 +39,7 @@ module RailtiesTest assert_equal "Another", Another.name ActiveSupport::Dependencies.clear @plugin.delete("lib/another.rb") - assert_raises(NameError) { Another } + assert_raise(NameError) { Another } end def test_plugin_puts_its_models_directory_on_load_path -- 1.6.0