diff options
author | Neeraj Singh <neerajdotname@gmail.com> | 2010-05-18 21:47:24 -0400 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-05-19 10:18:36 +0200 |
commit | b4629528866446aa59f663a1162edbdacee85600 (patch) | |
tree | d68a0f440d552285adf99b462b8bde39d346aaa6 | |
parent | b753b4a076d7067efccbd1ad384829f77e62a064 (diff) | |
download | rails-b4629528866446aa59f663a1162edbdacee85600.tar.gz rails-b4629528866446aa59f663a1162edbdacee85600.tar.bz2 rails-b4629528866446aa59f663a1162edbdacee85600.zip |
Use better assertion methods for testing
[#4645 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
27 files changed, 116 insertions, 123 deletions
diff --git a/actionmailer/test/base_test.rb b/actionmailer/test/base_test.rb index 5506d62d6a..54bf3de6af 100644 --- a/actionmailer/test/base_test.rb +++ b/actionmailer/test/base_test.rb @@ -491,8 +491,8 @@ class BaseTest < ActiveSupport::TestCase # Class level API with method missing test "should respond to action methods" do - assert BaseMailer.respond_to?(:welcome) - assert BaseMailer.respond_to?(:implicit_multipart) + assert_respond_to BaseMailer, :welcome + assert_respond_to BaseMailer, :implicit_multipart assert !BaseMailer.respond_to?(:mail) assert !BaseMailer.respond_to?(:headers) end diff --git a/actionmailer/test/old_base/asset_host_test.rb b/actionmailer/test/old_base/asset_host_test.rb index 0ec0242f55..cc13c8a4d7 100644 --- a/actionmailer/test/old_base/asset_host_test.rb +++ b/actionmailer/test/old_base/asset_host_test.rb @@ -26,7 +26,7 @@ class AssetHostTest < Test::Unit::TestCase def test_asset_host_as_string mail = AssetHostMailer.email_with_asset - assert_equal "<img alt=\"Somelogo\" src=\"http://www.example.com/images/somelogo.png\" />", mail.body.to_s.strip + assert_equal %Q{<img alt="Somelogo" src="http://www.example.com/images/somelogo.png" />}, mail.body.to_s.strip end def test_asset_host_as_one_arguement_proc @@ -38,7 +38,7 @@ class AssetHostTest < Test::Unit::TestCase end } mail = AssetHostMailer.email_with_asset - assert_equal "<img alt=\"Somelogo\" src=\"http://images.example.com/images/somelogo.png\" />", mail.body.to_s.strip + assert_equal %Q{<img alt="Somelogo" src="http://images.example.com/images/somelogo.png" />}, mail.body.to_s.strip end def test_asset_host_as_two_arguement_proc @@ -51,6 +51,6 @@ class AssetHostTest < Test::Unit::TestCase } mail = nil assert_nothing_raised { mail = AssetHostMailer.email_with_asset } - assert_equal "<img alt=\"Somelogo\" src=\"http://www.example.com/images/somelogo.png\" />", mail.body.to_s.strip + assert_equal %Q{<img alt="Somelogo" src="http://www.example.com/images/somelogo.png" />}, mail.body.to_s.strip end -end
\ No newline at end of file +end diff --git a/actionmailer/test/old_base/mail_render_test.rb b/actionmailer/test/old_base/mail_render_test.rb index 405d43d7d3..08951833a5 100644 --- a/actionmailer/test/old_base/mail_render_test.rb +++ b/actionmailer/test/old_base/mail_render_test.rb @@ -117,7 +117,7 @@ class RenderHelperTest < Test::Unit::TestCase def test_rxml_template mail = RenderMailer.rxml_template.deliver - assert_equal "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<test/>", mail.body.to_s.strip + assert_equal %(<?xml version="1.0" encoding="UTF-8"?>\n<test/>), mail.body.to_s.strip end def test_included_subtemplate diff --git a/actionmailer/test/old_base/mail_service_test.rb b/actionmailer/test/old_base/mail_service_test.rb index f343d32019..7054e8052a 100644 --- a/actionmailer/test/old_base/mail_service_test.rb +++ b/actionmailer/test/old_base/mail_service_test.rb @@ -281,7 +281,7 @@ class TestMailer < ActionMailer::Base from "One: Two <test@example.com>" cc "Three: Four <test@example.com>" bcc "Five: Six <test@example.com>" - body "testing" + body "testing" end def custom_content_type_attributes @@ -289,7 +289,7 @@ class TestMailer < ActionMailer::Base subject "custom content types" from "some.one@somewhere.test" content_type "text/plain; format=flowed" - body "testing" + body "testing" end def return_path @@ -297,7 +297,7 @@ class TestMailer < ActionMailer::Base subject "return path test" from "some.one@somewhere.test" headers["return-path"] = "another@somewhere.test" - body "testing" + body "testing" end def subject_with_i18n(recipient) @@ -417,7 +417,7 @@ class ActionMailerTest < Test::Unit::TestCase end def test_custom_template - expected = new_mail + expected = new_mail expected.to = @recipient expected.subject = "[Signed up] Welcome #{@recipient}" expected.body = "Hello there, \n\nMr. #{@recipient}" @@ -436,7 +436,7 @@ class ActionMailerTest < Test::Unit::TestCase assert ActionView::Template.template_handler_extensions.include?("haml"), "haml extension was not registered" # N.b., custom_templating_extension.text.plain.haml is expected to be in fixtures/test_mailer directory - expected = new_mail + expected = new_mail expected.to = @recipient expected.subject = "[Signed up] Welcome #{@recipient}" expected.body = "Hello there, \n\nMr. #{@recipient}" @@ -453,7 +453,7 @@ class ActionMailerTest < Test::Unit::TestCase end def test_cancelled_account - expected = new_mail + expected = new_mail expected.to = @recipient expected.subject = "[Cancelled] Goodbye #{@recipient}" expected.body = "Goodbye, Mr. #{@recipient}" @@ -477,7 +477,7 @@ class ActionMailerTest < Test::Unit::TestCase end def test_cc_bcc - expected = new_mail + expected = new_mail expected.to = @recipient expected.subject = "testing bcc/cc" expected.body = "Nothing to see here." @@ -602,7 +602,7 @@ class ActionMailerTest < Test::Unit::TestCase def test_unencoded_subject TestMailer.delivery_method = :test - expected = new_mail + expected = new_mail expected.to = @recipient expected.subject = "testing unencoded subject" expected.body = "Nothing to see here." @@ -1151,15 +1151,15 @@ class RespondToTest < Test::Unit::TestCase end def test_should_respond_to_new - assert RespondToMailer.respond_to?(:new) + assert_respond_to RespondToMailer, :new end def test_should_respond_to_create_with_template_suffix - assert RespondToMailer.respond_to?(:create_any_old_template) + assert_respond_to RespondToMailer, :create_any_old_template end def test_should_respond_to_deliver_with_template_suffix - assert RespondToMailer.respond_to?(:deliver_any_old_template) + assert_respond_to RespondToMailer, :deliver_any_old_template end def test_should_not_respond_to_new_with_template_suffix diff --git a/actionmailer/test/test_helper_test.rb b/actionmailer/test/test_helper_test.rb index 440fb868c8..8ff604c2c7 100644 --- a/actionmailer/test/test_helper_test.rb +++ b/actionmailer/test/test_helper_test.rb @@ -18,7 +18,7 @@ class TestHelperMailerTest < ActionMailer::TestCase end def test_setup_creates_the_expected_mailer - assert @expected.is_a?(Mail::Message) + assert_kind_of Mail::Message, @expected assert_equal "1.0", @expected.mime_version assert_equal "text/plain", @expected.mime_type end @@ -121,7 +121,7 @@ class AnotherTestHelperMailerTest < ActionMailer::TestCase end def test_setup_shouldnt_conflict_with_mailer_setup - assert @expected.is_a?(Mail::Message) + assert_kind_of Mail::Message, @expected assert_equal 'a value', @test_var end end diff --git a/actionpack/test/controller/filters_test.rb b/actionpack/test/controller/filters_test.rb index ea740f7233..d5704eba78 100644 --- a/actionpack/test/controller/filters_test.rb +++ b/actionpack/test/controller/filters_test.rb @@ -515,7 +515,7 @@ class FilterTest < ActionController::TestCase assert assigns["ran_proc_filter2"] test_process(AnomolousYetValidConditionController, "show_without_filter") - assert_equal nil, assigns["ran_filter"] + assert_nil assigns["ran_filter"] assert !assigns["ran_class_filter"] assert !assigns["ran_proc_filter1"] assert !assigns["ran_proc_filter2"] @@ -530,16 +530,16 @@ class FilterTest < ActionController::TestCase test_process(ConditionalCollectionFilterController) assert_equal %w( ensure_login ), assigns["ran_filter"] test_process(ConditionalCollectionFilterController, "show_without_filter") - assert_equal nil, assigns["ran_filter"] + assert_nil assigns["ran_filter"] test_process(ConditionalCollectionFilterController, "another_action") - assert_equal nil, assigns["ran_filter"] + assert_nil assigns["ran_filter"] end def test_running_only_condition_filters test_process(OnlyConditionSymController) assert_equal %w( ensure_login ), assigns["ran_filter"] test_process(OnlyConditionSymController, "show_without_filter") - assert_equal nil, assigns["ran_filter"] + assert_nil assigns["ran_filter"] test_process(OnlyConditionProcController) assert assigns["ran_proc_filter"] @@ -556,7 +556,7 @@ class FilterTest < ActionController::TestCase test_process(ExceptConditionSymController) assert_equal %w( ensure_login ), assigns["ran_filter"] test_process(ExceptConditionSymController, "show_without_filter") - assert_equal nil, assigns["ran_filter"] + assert_nil assigns["ran_filter"] test_process(ExceptConditionProcController) assert assigns["ran_proc_filter"] @@ -573,7 +573,7 @@ class FilterTest < ActionController::TestCase test_process(BeforeAndAfterConditionController) assert_equal %w( ensure_login clean_up_tmp), assigns["ran_filter"] test_process(BeforeAndAfterConditionController, "show_without_filter") - assert_equal nil, assigns["ran_filter"] + assert_nil assigns["ran_filter"] end def test_around_filter @@ -674,7 +674,7 @@ class FilterTest < ActionController::TestCase def test_changing_the_requirements test_process(ChangingTheRequirementsController, "go_wild") - assert_equal nil, assigns['ran_filter'] + assert_nil assigns['ran_filter'] end def test_a_rescuing_around_filter diff --git a/actionpack/test/controller/new_base/bare_metal_test.rb b/actionpack/test/controller/new_base/bare_metal_test.rb index df4b39a103..8a06e8d2a0 100644 --- a/actionpack/test/controller/new_base/bare_metal_test.rb +++ b/actionpack/test/controller/new_base/bare_metal_test.rb @@ -18,10 +18,10 @@ module BareMetalTest string << part end - assert headers.is_a?(Hash), "Headers must be a Hash" + assert_kind_of Hash, headers, "Headers must be a Hash" assert headers["Content-Type"], "Content-Type must exist" assert_equal "Hello world", string end end -end
\ No newline at end of file +end diff --git a/activemodel/test/cases/attribute_methods_test.rb b/activemodel/test/cases/attribute_methods_test.rb index 5659dcbc48..c60caf90d7 100644 --- a/activemodel/test/cases/attribute_methods_test.rb +++ b/activemodel/test/cases/attribute_methods_test.rb @@ -31,7 +31,7 @@ class AttributeMethodsTest < ActiveModel::TestCase ModelWithAttributes.define_attribute_methods([:foo]) assert ModelWithAttributes.attribute_methods_generated? - assert ModelWithAttributes.new.respond_to?(:foo) + assert_respond_to ModelWithAttributes.new, :foo assert_equal "value of foo", ModelWithAttributes.new.foo end diff --git a/activemodel/test/cases/callbacks_test.rb b/activemodel/test/cases/callbacks_test.rb index b996f51d6b..9675b5d450 100644 --- a/activemodel/test/cases/callbacks_test.rb +++ b/activemodel/test/cases/callbacks_test.rb @@ -65,6 +65,6 @@ class CallbacksTest < ActiveModel::TestCase test "only selects which types of callbacks should be created" do assert !ModelCallbacks.respond_to?(:before_initialize) assert !ModelCallbacks.respond_to?(:around_initialize) - assert ModelCallbacks.respond_to?(:after_initialize) + assert_respond_to ModelCallbacks, :after_initialize end end diff --git a/activemodel/test/cases/dirty_test.rb b/activemodel/test/cases/dirty_test.rb index c910cb43d4..e1a35be384 100644 --- a/activemodel/test/cases/dirty_test.rb +++ b/activemodel/test/cases/dirty_test.rb @@ -22,8 +22,8 @@ class DirtyTest < ActiveModel::TestCase test "changes accessible through both strings and symbols" do model = DirtyModel.new model.name = "David" - assert !model.changes[:name].nil? - assert !model.changes['name'].nil? + assert_not_nil model.changes[:name] + assert_not_nil model.changes['name'] end end diff --git a/activemodel/test/cases/serializeration/xml_serialization_test.rb b/activemodel/test/cases/serializeration/xml_serialization_test.rb index 4e8e4efa25..7b9ef3e21f 100644 --- a/activemodel/test/cases/serializeration/xml_serialization_test.rb +++ b/activemodel/test/cases/serializeration/xml_serialization_test.rb @@ -69,7 +69,7 @@ class XmlSerializationTest < ActiveModel::TestCase test "should allow skipped types" do @xml = @contact.to_xml :skip_types => true - assert %r{<age>25</age>}.match(@xml) + assert_match %r{<age>25</age>}, @xml end test "should include yielded additions" do diff --git a/activerecord/test/cases/aggregations_test.rb b/activerecord/test/cases/aggregations_test.rb index 8b6ec04018..e5fc1a2046 100644 --- a/activerecord/test/cases/aggregations_test.rb +++ b/activerecord/test/cases/aggregations_test.rb @@ -58,36 +58,36 @@ class AggregationsTest < ActiveRecord::TestCase end def test_gps_equality - assert GpsLocation.new('39x110') == GpsLocation.new('39x110') + assert_equal GpsLocation.new('39x110'), GpsLocation.new('39x110') end def test_gps_inequality - assert GpsLocation.new('39x110') != GpsLocation.new('39x111') + assert_not_equal GpsLocation.new('39x110'), GpsLocation.new('39x111') end def test_allow_nil_gps_is_nil - assert_equal nil, customers(:zaphod).gps_location + assert_nil customers(:zaphod).gps_location end def test_allow_nil_gps_set_to_nil customers(:david).gps_location = nil customers(:david).save customers(:david).reload - assert_equal nil, customers(:david).gps_location + assert_nil customers(:david).gps_location end def test_allow_nil_set_address_attributes_to_nil customers(:zaphod).address = nil - assert_equal nil, customers(:zaphod).attributes[:address_street] - assert_equal nil, customers(:zaphod).attributes[:address_city] - assert_equal nil, customers(:zaphod).attributes[:address_country] + assert_nil customers(:zaphod).attributes[:address_street] + assert_nil customers(:zaphod).attributes[:address_city] + assert_nil customers(:zaphod).attributes[:address_country] end def test_allow_nil_address_set_to_nil customers(:zaphod).address = nil customers(:zaphod).save customers(:zaphod).reload - assert_equal nil, customers(:zaphod).address + assert_nil customers(:zaphod).address end def test_nil_raises_error_when_allow_nil_is_false @@ -104,9 +104,9 @@ class AggregationsTest < ActiveRecord::TestCase def test_nil_assignment_results_in_nil customers(:david).gps_location = GpsLocation.new('39x111') - assert_not_equal nil, customers(:david).gps_location + assert_not_nil customers(:david).gps_location customers(:david).gps_location = nil - assert_equal nil, customers(:david).gps_location + assert_nil customers(:david).gps_location end def test_custom_constructor diff --git a/activerecord/test/cases/associations/belongs_to_associations_test.rb b/activerecord/test/cases/associations/belongs_to_associations_test.rb index be77ee4bf3..9258c987ef 100644 --- a/activerecord/test/cases/associations/belongs_to_associations_test.rb +++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb @@ -403,7 +403,7 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase assert_equal saved_member.id, sponsor.sponsorable_id sponsor.sponsorable = new_member - assert_equal nil, sponsor.sponsorable_id + assert_nil sponsor.sponsorable_id end def test_polymorphic_assignment_with_primary_key_updates_foreign_id_field_for_new_and_saved_records @@ -415,7 +415,7 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase assert_equal saved_writer.name, essay.writer_id essay.writer = new_writer - assert_equal nil, essay.writer_id + assert_nil essay.writer_id end def test_belongs_to_proxy_should_not_respond_to_private_methods diff --git a/activerecord/test/cases/associations/eager_load_includes_full_sti_class_test.rb b/activerecord/test/cases/associations/eager_load_includes_full_sti_class_test.rb index 7c470616a5..b124a2bfc3 100644 --- a/activerecord/test/cases/associations/eager_load_includes_full_sti_class_test.rb +++ b/activerecord/test/cases/associations/eager_load_includes_full_sti_class_test.rb @@ -29,7 +29,7 @@ class EagerLoadIncludeFullStiClassNamesTest < ActiveRecord::TestCase ActiveRecord::Base.store_full_sti_class = true post = Namespaced::Post.find_by_title( 'Great stuff', :include => :tagging ) - assert_equal 'Tagging', post.tagging.class.name + assert_instance_of Tagging, post.tagging ensure ActiveRecord::Base.store_full_sti_class = old end diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb index 79e5ecf4ce..445e6889c0 100644 --- a/activerecord/test/cases/associations/eager_test.rb +++ b/activerecord/test/cases/associations/eager_test.rb @@ -110,7 +110,7 @@ class EagerAssociationTest < ActiveRecord::TestCase author = assert_queries(3) { Author.find(author_id, :include => {:posts_with_comments => :comments}) } # find the author, then find the posts, then find the comments author.posts_with_comments.each do |post_with_comments| assert_equal post_with_comments.comments.length, post_with_comments.comments.count - assert_equal nil, post_with_comments.comments.uniq! + assert_nil post_with_comments.comments.uniq! end end diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index 6e47967696..8e5bc56008 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -175,14 +175,7 @@ class HasManyAssociationsTest < ActiveRecord::TestCase c = Client.new assert_nil c.firm - if c.firm - assert false, "belongs_to failed if check" - end - - unless c.firm - else - assert false, "belongs_to failed unless check" - end + flunk "belongs_to failed if check" if c.firm end def test_find_ids @@ -620,7 +613,7 @@ class HasManyAssociationsTest < ActiveRecord::TestCase assert_equal [], Client.destroyed_client_ids[firm.id] # Should be destroyed since the association is exclusively dependent. - assert Client.find_by_id(client_id).nil? + assert_nil Client.find_by_id(client_id) end def test_dependent_association_respects_optional_conditions_on_delete @@ -669,7 +662,7 @@ class HasManyAssociationsTest < ActiveRecord::TestCase old_record = firm.clients_using_primary_key_with_delete_all.first firm = Firm.find(:first) firm.destroy - assert Client.find_by_id(old_record.id).nil? + assert_nil Client.find_by_id(old_record.id) end def test_creation_respects_hash_condition 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 ff799191c2..e4dd810732 100644 --- a/activerecord/test/cases/associations/has_many_through_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb @@ -63,8 +63,8 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase assert_queries(1) { posts(:thinking) } assert_queries(0) do - posts(:thinking).people.build(:first_name=>"Bob") - posts(:thinking).people.new(:first_name=>"Ted") + posts(:thinking).people.build(:first_name => "Bob") + posts(:thinking).people.new(:first_name => "Ted") end # Should only need to load the association once diff --git a/activerecord/test/cases/associations/has_one_associations_test.rb b/activerecord/test/cases/associations/has_one_associations_test.rb index 8f5540950e..469a21b9bf 100644 --- a/activerecord/test/cases/associations/has_one_associations_test.rb +++ b/activerecord/test/cases/associations/has_one_associations_test.rb @@ -149,7 +149,7 @@ class HasOneAssociationsTest < ActiveRecord::TestCase num_accounts = Account.count firm = Firm.find(1) - assert !firm.account.nil? + assert_not_nil firm.account account_id = firm.account.id assert_equal [], Account.destroyed_account_ids[firm.id] @@ -162,7 +162,7 @@ class HasOneAssociationsTest < ActiveRecord::TestCase num_accounts = Account.count firm = ExclusivelyDependentFirm.find(9) - assert !firm.account.nil? + assert_not_nil firm.account account_id = firm.account.id assert_equal [], Account.destroyed_account_ids[firm.id] @@ -181,7 +181,7 @@ class HasOneAssociationsTest < ActiveRecord::TestCase firm = RestrictedFirm.new(:name => 'restrict') firm.save! account = firm.create_account(:credit_limit => 10) - assert !firm.account.nil? + assert_not_nil firm.account assert_raise(ActiveRecord::DeleteRestrictionError) { firm.destroy } end @@ -246,7 +246,7 @@ class HasOneAssociationsTest < ActiveRecord::TestCase def test_dependence_with_missing_association Account.destroy_all firm = Firm.find(1) - assert firm.account.nil? + assert_nil firm.account firm.destroy end diff --git a/activerecord/test/cases/associations/inverse_associations_test.rb b/activerecord/test/cases/associations/inverse_associations_test.rb index 1d7604f52b..34d24a2948 100644 --- a/activerecord/test/cases/associations/inverse_associations_test.rb +++ b/activerecord/test/cases/associations/inverse_associations_test.rb @@ -23,39 +23,39 @@ class InverseAssociationTests < ActiveRecord::TestCase def test_should_be_able_to_ask_a_reflection_if_it_has_an_inverse has_one_with_inverse_ref = Man.reflect_on_association(:face) - assert has_one_with_inverse_ref.respond_to?(:has_inverse?) + assert_respond_to has_one_with_inverse_ref, :has_inverse? assert has_one_with_inverse_ref.has_inverse? has_many_with_inverse_ref = Man.reflect_on_association(:interests) - assert has_many_with_inverse_ref.respond_to?(:has_inverse?) + assert_respond_to has_many_with_inverse_ref, :has_inverse? assert has_many_with_inverse_ref.has_inverse? belongs_to_with_inverse_ref = Face.reflect_on_association(:man) - assert belongs_to_with_inverse_ref.respond_to?(:has_inverse?) + assert_respond_to belongs_to_with_inverse_ref, :has_inverse? assert belongs_to_with_inverse_ref.has_inverse? has_one_without_inverse_ref = Club.reflect_on_association(:sponsor) - assert has_one_without_inverse_ref.respond_to?(:has_inverse?) + assert_respond_to has_one_without_inverse_ref, :has_inverse? assert !has_one_without_inverse_ref.has_inverse? has_many_without_inverse_ref = Club.reflect_on_association(:memberships) - assert has_many_without_inverse_ref.respond_to?(:has_inverse?) + assert_respond_to has_many_without_inverse_ref, :has_inverse? assert !has_many_without_inverse_ref.has_inverse? belongs_to_without_inverse_ref = Sponsor.reflect_on_association(:sponsor_club) - assert belongs_to_without_inverse_ref.respond_to?(:has_inverse?) + assert_respond_to belongs_to_without_inverse_ref, :has_inverse? assert !belongs_to_without_inverse_ref.has_inverse? end def test_should_be_able_to_ask_a_reflection_what_it_is_the_inverse_of has_one_ref = Man.reflect_on_association(:face) - assert has_one_ref.respond_to?(:inverse_of) + assert_respond_to has_one_ref, :inverse_of has_many_ref = Man.reflect_on_association(:interests) - assert has_many_ref.respond_to?(:inverse_of) + assert_respond_to has_many_ref, :inverse_of belongs_to_ref = Face.reflect_on_association(:man) - assert belongs_to_ref.respond_to?(:inverse_of) + assert_respond_to belongs_to_ref, :inverse_of end def test_inverse_of_method_should_supply_the_actual_reflection_instance_it_is_the_inverse_of diff --git a/activerecord/test/cases/associations/join_model_test.rb b/activerecord/test/cases/associations/join_model_test.rb index dca72be4fd..447fe4d275 100644 --- a/activerecord/test/cases/associations/join_model_test.rb +++ b/activerecord/test/cases/associations/join_model_test.rb @@ -280,12 +280,12 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase def test_has_many_find_conditions assert_equal categories(:general), authors(:david).categories.find(:first, :conditions => "categories.name = 'General'") - assert_equal nil, authors(:david).categories.find(:first, :conditions => "categories.name = 'Technology'") + assert_nil authors(:david).categories.find(:first, :conditions => "categories.name = 'Technology'") end def test_has_many_class_methods_called_by_method_missing assert_equal categories(:general), authors(:david).categories.find_all_by_name('General').first - assert_equal nil, authors(:david).categories.find_by_name('Technology') + assert_nil authors(:david).categories.find_by_name('Technology') end def test_has_many_array_methods_called_by_method_missing diff --git a/activerecord/test/cases/attribute_methods_test.rb b/activerecord/test/cases/attribute_methods_test.rb index 055590da0a..d59fa0a632 100644 --- a/activerecord/test/cases/attribute_methods_test.rb +++ b/activerecord/test/cases/attribute_methods_test.rb @@ -310,7 +310,7 @@ class AttributeMethodsTest < ActiveRecord::TestCase end assert !@target.instance_method_already_implemented?(:title) topic = @target.new - assert_equal nil, topic.title + assert_nil topic.title Object.send(:undef_method, :title) # remove test method from object end diff --git a/activerecord/test/cases/autosave_association_test.rb b/activerecord/test/cases/autosave_association_test.rb index 5cc5dff633..063f0f0fb2 100644 --- a/activerecord/test/cases/autosave_association_test.rb +++ b/activerecord/test/cases/autosave_association_test.rb @@ -1236,11 +1236,11 @@ class TestAutosaveAssociationValidationMethodsGeneration < ActiveRecord::TestCas end test "should generate validation methods for has_many associations" do - assert @pirate.respond_to?(:validate_associated_records_for_birds) + assert_respond_to @pirate, :validate_associated_records_for_birds end test "should generate validation methods for has_one associations with :validate => true" do - assert @pirate.respond_to?(:validate_associated_records_for_ship) + assert_respond_to @pirate, :validate_associated_records_for_ship end test "should not generate validation methods for has_one associations without :validate => true" do @@ -1248,7 +1248,7 @@ class TestAutosaveAssociationValidationMethodsGeneration < ActiveRecord::TestCas end test "should generate validation methods for belongs_to associations with :validate => true" do - assert @pirate.respond_to?(:validate_associated_records_for_parrot) + assert_respond_to @pirate, :validate_associated_records_for_parrot end test "should not generate validation methods for belongs_to associations without :validate => true" do @@ -1256,7 +1256,7 @@ class TestAutosaveAssociationValidationMethodsGeneration < ActiveRecord::TestCas end test "should generate validation methods for HABTM associations with :validate => true" do - assert @pirate.respond_to?(:validate_associated_records_for_parrots) + assert_respond_to @pirate, :validate_associated_records_for_parrots end test "should not generate validation methods for HABTM associations without :validate => true" do diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index 7c4d92f3f8..0c7723c0e6 100755 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -111,14 +111,14 @@ class BasicsTest < ActiveRecord::TestCase def test_respond_to? topic = Topic.find(1) - assert topic.respond_to?("title") - assert topic.respond_to?("title?") - assert topic.respond_to?("title=") - assert topic.respond_to?(:title) - assert topic.respond_to?(:title?) - assert topic.respond_to?(:title=) - assert topic.respond_to?("author_name") - assert topic.respond_to?("attribute_names") + assert_respond_to topic, "title" + assert_respond_to topic, "title?" + assert_respond_to topic, "title=" + assert_respond_to topic, :title + assert_respond_to topic, :title? + assert_respond_to topic, :title= + assert_respond_to topic, "author_name" + assert_respond_to topic, "attribute_names" assert !topic.respond_to?("nothingness") assert !topic.respond_to?(:nothingness) end @@ -1038,9 +1038,9 @@ class BasicsTest < ActiveRecord::TestCase def test_mass_assignment_protection_against_class_attribute_writers [:logger, :configurations, :primary_key_prefix_type, :table_name_prefix, :table_name_suffix, :pluralize_table_names, :default_timezone, :schema_format, :lock_optimistically, :record_timestamps].each do |method| - assert Task.respond_to?(method) - assert Task.respond_to?("#{method}=") - assert Task.new.respond_to?(method) + assert_respond_to Task, method + assert_respond_to Task, "#{method}=" + assert_respond_to Task.new, method assert !Task.new.respond_to?("#{method}=") end end @@ -1369,37 +1369,37 @@ class BasicsTest < ActiveRecord::TestCase end def test_new_record_returns_boolean - assert_equal Topic.new.new_record?, true - assert_equal Topic.find(1).new_record?, false + assert_equal true, Topic.new.new_record? + assert_equal false, Topic.find(1).new_record? end def test_destroyed_returns_boolean developer = Developer.first - assert_equal developer.destroyed?, false + assert_equal false, developer.destroyed? developer.destroy - assert_equal developer.destroyed?, true + assert_equal true, developer.destroyed? developer = Developer.last - assert_equal developer.destroyed?, false + assert_equal false, developer.destroyed? developer.delete - assert_equal developer.destroyed?, true + assert_equal true, developer.destroyed? end def test_persisted_returns_boolean developer = Developer.new(:name => "Jose") - assert_equal developer.persisted?, false + assert_equal false, developer.persisted? developer.save! - assert_equal developer.persisted?, true + assert_equal true, developer.persisted? developer = Developer.first - assert_equal developer.persisted?, true + assert_equal true, developer.persisted? developer.destroy - assert_equal developer.persisted?, false + assert_equal false, developer.persisted? developer = Developer.last - assert_equal developer.persisted?, true + assert_equal true, developer.persisted? developer.delete - assert_equal developer.persisted?, false + assert_equal false, developer.persisted? end def test_clone @@ -1427,7 +1427,7 @@ class BasicsTest < ActiveRecord::TestCase # test if saved clone object differs from original cloned_topic.save assert !cloned_topic.new_record? - assert cloned_topic.id != topic.id + assert_not_equal cloned_topic.id, topic.id end def test_clone_with_aggregate_of_same_name_as_attribute @@ -1447,7 +1447,7 @@ class BasicsTest < ActiveRecord::TestCase assert clone.save assert !clone.new_record? - assert clone.id != dev.id + assert_not_equal clone.id, dev.id end def test_clone_preserves_subtype diff --git a/activerecord/test/cases/column_definition_test.rb b/activerecord/test/cases/column_definition_test.rb index 8b6c019d50..b5767344cd 100644 --- a/activerecord/test/cases/column_definition_test.rb +++ b/activerecord/test/cases/column_definition_test.rb @@ -71,17 +71,17 @@ class ColumnDefinitionTest < ActiveRecord::TestCase if current_adapter?(:PostgreSQLAdapter) def test_bigint_column_should_map_to_integer bigint_column = ActiveRecord::ConnectionAdapters::PostgreSQLColumn.new('number', nil, "bigint") - assert_equal bigint_column.type, :integer + assert_equal :integer, bigint_column.type end def test_smallint_column_should_map_to_integer smallint_column = ActiveRecord::ConnectionAdapters::PostgreSQLColumn.new('number', nil, "smallint") - assert_equal smallint_column.type, :integer + assert_equal :integer, smallint_column.type end def test_uuid_column_should_map_to_string uuid_column = ActiveRecord::ConnectionAdapters::PostgreSQLColumn.new('unique_id', nil, "uuid") - assert_equal uuid_column.type, :string + assert_equal :string, uuid_column.type end end end diff --git a/activerecord/test/cases/defaults_test.rb b/activerecord/test/cases/defaults_test.rb index bba216ae19..39aafa1ec7 100644 --- a/activerecord/test/cases/defaults_test.rb +++ b/activerecord/test/cases/defaults_test.rb @@ -67,8 +67,8 @@ if current_adapter?(:MysqlAdapter) assert_equal '', klass.columns_hash['non_null_blob'].default assert_equal '', klass.columns_hash['non_null_text'].default - assert_equal nil, klass.columns_hash['null_blob'].default - assert_equal nil, klass.columns_hash['null_text'].default + assert_nil klass.columns_hash['null_blob'].default + assert_nil klass.columns_hash['null_text'].default assert_nothing_raised do instance = klass.create! diff --git a/activerecord/test/cases/dirty_test.rb b/activerecord/test/cases/dirty_test.rb index 3ea2948f62..75f7453aa9 100644 --- a/activerecord/test/cases/dirty_test.rb +++ b/activerecord/test/cases/dirty_test.rb @@ -103,7 +103,7 @@ class DirtyTest < ActiveRecord::TestCase assert pirate.created_on_changed? # kind_of does not work because # ActiveSupport::TimeWithZone.name == 'Time' - assert_equal Time, pirate.created_on_was.class + assert_instance_of Time, pirate.created_on_was assert_equal old_created_on, pirate.created_on_was end end @@ -132,7 +132,7 @@ class DirtyTest < ActiveRecord::TestCase assert pirate.created_on_changed? # kind_of does not work because # ActiveSupport::TimeWithZone.name == 'Time' - assert_equal Time, pirate.created_on_was.class + assert_instance_of Time, pirate.created_on_was assert_equal old_created_on, pirate.created_on_was end diff --git a/activerecord/test/cases/finder_respond_to_test.rb b/activerecord/test/cases/finder_respond_to_test.rb index 4e6fecf11a..235805a67c 100644 --- a/activerecord/test/cases/finder_respond_to_test.rb +++ b/activerecord/test/cases/finder_respond_to_test.rb @@ -7,53 +7,53 @@ class FinderRespondToTest < ActiveRecord::TestCase def test_should_preserve_normal_respond_to_behaviour_and_respond_to_newly_added_method class << Topic; self; end.send(:define_method, :method_added_for_finder_respond_to_test) { } - assert Topic.respond_to?(:method_added_for_finder_respond_to_test) + assert_respond_to Topic, :method_added_for_finder_respond_to_test ensure class << Topic; self; end.send(:remove_method, :method_added_for_finder_respond_to_test) end def test_should_preserve_normal_respond_to_behaviour_and_respond_to_standard_object_method - assert Topic.respond_to?(:to_s) + assert_respond_to Topic, :to_s end def test_should_respond_to_find_by_one_attribute_before_caching ensure_topic_method_is_not_cached(:find_by_title) - assert Topic.respond_to?(:find_by_title) + assert_respond_to Topic, :find_by_title end def test_should_respond_to_find_all_by_one_attribute ensure_topic_method_is_not_cached(:find_all_by_title) - assert Topic.respond_to?(:find_all_by_title) + assert_respond_to Topic, :find_all_by_title end def test_should_respond_to_find_all_by_two_attributes ensure_topic_method_is_not_cached(:find_all_by_title_and_author_name) - assert Topic.respond_to?(:find_all_by_title_and_author_name) + assert_respond_to Topic, :find_all_by_title_and_author_name end def test_should_respond_to_find_by_two_attributes ensure_topic_method_is_not_cached(:find_by_title_and_author_name) - assert Topic.respond_to?(:find_by_title_and_author_name) + assert_respond_to Topic, :find_by_title_and_author_name end def test_should_respond_to_find_or_initialize_from_one_attribute ensure_topic_method_is_not_cached(:find_or_initialize_by_title) - assert Topic.respond_to?(:find_or_initialize_by_title) + assert_respond_to Topic, :find_or_initialize_by_title end def test_should_respond_to_find_or_initialize_from_two_attributes ensure_topic_method_is_not_cached(:find_or_initialize_by_title_and_author_name) - assert Topic.respond_to?(:find_or_initialize_by_title_and_author_name) + assert_respond_to Topic, :find_or_initialize_by_title_and_author_name end def test_should_respond_to_find_or_create_from_one_attribute ensure_topic_method_is_not_cached(:find_or_create_by_title) - assert Topic.respond_to?(:find_or_create_by_title) + assert_respond_to Topic, :find_or_create_by_title end def test_should_respond_to_find_or_create_from_two_attributes ensure_topic_method_is_not_cached(:find_or_create_by_title_and_author_name) - assert Topic.respond_to?(:find_or_create_by_title_and_author_name) + assert_respond_to Topic, :find_or_create_by_title_and_author_name end def test_should_not_respond_to_find_by_one_missing_attribute @@ -73,4 +73,4 @@ class FinderRespondToTest < ActiveRecord::TestCase class << Topic; self; end.send(:remove_method, method_id) if Topic.public_methods.any? { |m| m.to_s == method_id.to_s } end -end
\ No newline at end of file +end |