Skip to content

Commit

Permalink
Final iteration of use better testing methods
Browse files Browse the repository at this point in the history
[#4652 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information
Neeraj Singh authored and josevalim committed May 19, 2010
1 parent bdb2871 commit 39a246f
Show file tree
Hide file tree
Showing 25 changed files with 82 additions and 82 deletions.
2 changes: 1 addition & 1 deletion activerecord/test/cases/finder_test.rb
Expand Up @@ -255,7 +255,7 @@ def test_find_only_some_columns
assert !topic.attribute_present?("title")
#assert !topic.respond_to?("title")
assert topic.attribute_present?("author_name")
assert topic.respond_to?("author_name")
assert_respond_to topic, "author_name"
end

def test_find_on_blank_conditions
Expand Down
14 changes: 7 additions & 7 deletions activerecord/test/cases/inheritance_test.rb
Expand Up @@ -72,10 +72,10 @@ def test_a_bad_type_column
end

def test_inheritance_find
assert Company.find(1).kind_of?(Firm), "37signals should be a firm"
assert Firm.find(1).kind_of?(Firm), "37signals should be a firm"
assert Company.find(2).kind_of?(Client), "Summit should be a client"
assert Client.find(2).kind_of?(Client), "Summit should be a client"
assert_kind_of Firm, Company.find(1), "37signals should be a firm"
assert_kind_of Firm, Firm.find(1), "37signals should be a firm"
assert_kind_of Client, Company.find(2), "Summit should be a client"
assert_kind_of Client, Client.find(2), "Summit should be a client"
end

def test_alt_inheritance_find
Expand All @@ -86,8 +86,8 @@ def test_alt_inheritance_find

def test_inheritance_find_all
companies = Company.find(:all, :order => 'id')
assert companies[0].kind_of?(Firm), "37signals should be a firm"
assert companies[1].kind_of?(Client), "Summit should be a client"
assert_kind_of Firm, companies[0], "37signals should be a firm"
assert_kind_of Client, companies[1], "Summit should be a client"
end

def test_alt_inheritance_find_all
Expand All @@ -102,7 +102,7 @@ def test_inheritance_save
firm.save

next_angle = Company.find(firm.id)
assert next_angle.kind_of?(Firm), "Next Angle should be a firm"
assert_kind_of Firm, next_angle, "Next Angle should be a firm"
end

def test_alt_inheritance_save
Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/cases/method_scoping_test.rb
Expand Up @@ -622,7 +622,7 @@ def test_default_scoping_with_inheritance
assert_equal ['salary DESC'], klass.scoped.order_values

# Parent should still have the original scope
assert_equal nil, DeveloperOrderedBySalary.scoped.limit_value
assert_nil DeveloperOrderedBySalary.scoped.limit_value
assert_equal ['salary DESC'], DeveloperOrderedBySalary.scoped.order_values
end

Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/cases/migration_test.rb
Expand Up @@ -525,7 +525,7 @@ def test_native_types
end
end

assert_equal TrueClass, bob.male?.class
assert_instance_of TrueClass, bob.male?
assert_kind_of BigDecimal, bob.wealth
end

Expand Down
4 changes: 2 additions & 2 deletions activerecord/test/cases/pk_test.rb
Expand Up @@ -18,7 +18,7 @@ def test_to_key_with_default_primary_key

def test_to_key_with_customized_primary_key
keyboard = Keyboard.new
assert keyboard.to_key.nil?
assert_nil keyboard.to_key
keyboard.save
assert_equal keyboard.to_key, [keyboard.id]
end
Expand All @@ -37,7 +37,7 @@ def test_integer_key

topic = Topic.new
topic.title = "New Topic"
assert_equal(nil, topic.id)
assert_nil topic.id
assert_nothing_raised { topic.save! }
id = topic.id

Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/cases/query_cache_test.rb
Expand Up @@ -58,7 +58,7 @@ def test_cache_does_not_wrap_string_results_in_arrays
Task.cache do
# Oracle adapter returns count() as Fixnum or Float
if current_adapter?(:OracleAdapter)
assert Task.connection.select_value("SELECT count(*) AS count_all FROM tasks").is_a?(Numeric)
assert_kind_of Numeric, Task.connection.select_value("SELECT count(*) AS count_all FROM tasks")
elsif current_adapter?(:SQLite3Adapter) && SQLite3::Version::VERSION > '1.2.5'
# Future versions of the sqlite3 adapter will return numeric
assert_instance_of Fixnum,
Expand Down
6 changes: 3 additions & 3 deletions activerecord/test/cases/relations_test.rb
Expand Up @@ -145,7 +145,7 @@ def test_scoped_responds_to_delegated_methods
relation = Topic.scoped

["map", "uniq", "sort", "insert", "delete", "update"].each do |method|
assert relation.respond_to?(method), "Topic.scoped should respond to #{method.inspect}"
assert_respond_to relation, method, "Topic.scoped should respond to #{method.inspect}"
end
end

Expand All @@ -160,7 +160,7 @@ def test_respond_to_dynamic_finders
relation = Topic.scoped

["find_by_title", "find_by_title_and_author_name", "find_or_create_by_title", "find_or_initialize_by_title_and_author_name"].each do |method|
assert relation.respond_to?(method), "Topic.scoped should respond to #{method.inspect}"
assert_respond_to relation, method, "Topic.scoped should respond to #{method.inspect}"
end
end

Expand Down Expand Up @@ -238,7 +238,7 @@ def test_find_with_included_associations

def test_default_scope_with_conditions_string
assert_equal Developer.find_all_by_name('David').map(&:id).sort, DeveloperCalledDavid.scoped.map(&:id).sort
assert_equal nil, DeveloperCalledDavid.create!.name
assert_nil DeveloperCalledDavid.create!.name
end

def test_default_scope_with_conditions_hash
Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/cases/reserved_word_test_mysql.rb
Expand Up @@ -115,7 +115,7 @@ def test_has_one_associations
create_test_fixtures :select, :distinct, :group, :values, :distincts_selects
v = nil
assert_nothing_raised { v = Group.find(1).values }
assert_equal v.id, 2
assert_equal 2, v.id
end

# belongs_to association with reserved-word table name
Expand Down
16 changes: 8 additions & 8 deletions activerecord/test/cases/timestamp_test.rb
Expand Up @@ -15,26 +15,26 @@ def test_saving_a_changed_record_updates_its_timestamp
@developer.name = "Jack Bauer"
@developer.save!

assert @previously_updated_at != @developer.updated_at
assert_not_equal @previously_updated_at, @developer.updated_at
end

def test_saving_a_unchanged_record_doesnt_update_its_timestamp
@developer.save!

assert @previously_updated_at == @developer.updated_at
assert_equal @previously_updated_at, @developer.updated_at
end

def test_touching_a_record_updates_its_timestamp
@developer.touch

assert @previously_updated_at != @developer.updated_at
assert_not_equal @previously_updated_at, @developer.updated_at
end

def test_touching_a_different_attribute
previously_created_at = @developer.created_at
@developer.touch(:created_at)

assert previously_created_at != @developer.created_at
assert_not_equal previously_created_at, @developer.created_at
end

def test_saving_a_record_with_a_belongs_to_that_specifies_touching_the_parent_should_update_the_parent_updated_at
Expand All @@ -45,7 +45,7 @@ def test_saving_a_record_with_a_belongs_to_that_specifies_touching_the_parent_sh
pet.name = "Fluffy the Third"
pet.save

assert previously_owner_updated_at != pet.owner.updated_at
assert_not_equal previously_owner_updated_at, pet.owner.updated_at
end

def test_destroying_a_record_with_a_belongs_to_that_specifies_touching_the_parent_should_update_the_parent_updated_at
Expand All @@ -55,7 +55,7 @@ def test_destroying_a_record_with_a_belongs_to_that_specifies_touching_the_paren

pet.destroy

assert previously_owner_updated_at != pet.owner.updated_at
assert_not_equal previously_owner_updated_at, pet.owner.updated_at
end

def test_saving_a_record_with_a_belongs_to_that_specifies_touching_a_specific_attribute_the_parent_should_update_that_attribute
Expand All @@ -68,8 +68,8 @@ def test_saving_a_record_with_a_belongs_to_that_specifies_touching_a_specific_at
pet.name = "Fluffy the Third"
pet.save

assert previously_owner_happy_at != pet.owner.happy_at
assert_not_equal previously_owner_happy_at, pet.owner.happy_at
ensure
Pet.belongs_to :owner, :touch => true
end
end
end
12 changes: 6 additions & 6 deletions activeresource/test/cases/base/schema_test.rb
Expand Up @@ -185,7 +185,7 @@ def teardown
####

test "should be able to use schema" do
assert Person.respond_to?(:schema), "should at least respond to the schema method"
assert_respond_to Person, :schema, "should at least respond to the schema method"

assert_nothing_raised("Should allow the schema to take a block") do
Person.schema { }
Expand All @@ -199,7 +199,7 @@ def teardown
s = self
attribute :foo, :string
end
assert s.respond_to?(:attrs), "should return attributes in theory"
assert_respond_to s, :attrs, "should return attributes in theory"
assert_equal({'foo' => 'string' }, s.attrs, "should return attributes in practice")
end
end
Expand Down Expand Up @@ -308,8 +308,8 @@ def teardown
Person.schema { string new_attr_name_two }
end

assert Person.new.respond_to?(new_attr_name), "should respond to the attribute in a passed-in schema, but failed on: #{new_attr_name}"
assert Person.new.respond_to?(new_attr_name_two), "should respond to the attribute from the schema, but failed on: #{new_attr_name_two}"
assert_respond_to Person.new, new_attr_name, "should respond to the attribute in a passed-in schema, but failed on: #{new_attr_name}"
assert_respond_to Person.new, new_attr_name_two, "should respond to the attribute from the schema, but failed on: #{new_attr_name_two}"
end

test "should not care about ordering of schema definitions" do
Expand All @@ -326,8 +326,8 @@ def teardown
Person.schema = {new_attr_name.to_s => 'string'}
end

assert Person.new.respond_to?(new_attr_name), "should respond to the attribute in a passed-in schema, but failed on: #{new_attr_name}"
assert Person.new.respond_to?(new_attr_name_two), "should respond to the attribute from the schema, but failed on: #{new_attr_name_two}"
assert_respond_to Person.new, new_attr_name, "should respond to the attribute in a passed-in schema, but failed on: #{new_attr_name}"
assert_respond_to Person.new, new_attr_name_two, "should respond to the attribute from the schema, but failed on: #{new_attr_name_two}"
end

# method_missing effects
Expand Down
10 changes: 5 additions & 5 deletions activeresource/test/cases/base_test.rb
Expand Up @@ -671,9 +671,9 @@ def test_custom_prefix
########################################################################
def test_respond_to
matz = Person.find(1)
assert matz.respond_to?(:name)
assert matz.respond_to?(:name=)
assert matz.respond_to?(:name?)
assert_respond_to matz, :name
assert_respond_to matz, :name=
assert_respond_to matz, :name?
assert !matz.respond_to?(:super_scalable_stuff)
end

Expand Down Expand Up @@ -708,7 +708,7 @@ def test_id_from_response
def test_id_from_response_without_location
p = Person.new
resp = {}
assert_equal nil, p.__send__(:id_from_response, resp)
assert_nil p.__send__(:id_from_response, resp)
end

def test_create_with_custom_prefix
Expand Down Expand Up @@ -775,7 +775,7 @@ def test_create_without_location
mock.post "/people.xml", {}, nil, 201
end
person = Person.create(:name => 'Rick')
assert_equal nil, person.id
assert_nil person.id
end

def test_clone
Expand Down
2 changes: 1 addition & 1 deletion activesupport/test/callbacks_test.rb
Expand Up @@ -521,7 +521,7 @@ class HyphenatedKeyTest < Test::Unit::TestCase
def test_save
obj = HyphenatedCallbacks.new
obj.save
assert_equal obj.stuff, "ACTION"
assert_equal "ACTION", obj.stuff
end
end
end
8 changes: 4 additions & 4 deletions activesupport/test/core_ext/class/attribute_accessor_test.rb
Expand Up @@ -25,14 +25,14 @@ def test_should_set_mattr_value
end

def test_should_not_create_instance_writer
assert @class.respond_to?(:foo)
assert @class.respond_to?(:foo=)
assert @object.respond_to?(:bar)
assert_respond_to @class, :foo
assert_respond_to @class, :foo=
assert_respond_to @object, :bar
assert !@object.respond_to?(:bar=)
end

def test_should_not_create_instance_reader
assert @class.respond_to?(:shaq)
assert_respond_to @class, :shaq
assert !@object.respond_to?(:shaq)
end
end
Expand Up @@ -219,7 +219,7 @@ def test_reset_inheritable_attributes
@klass.reset_inheritable_attributes
@sub = eval("class NotInheriting < @klass; end; NotInheriting")

assert_equal nil, @klass.a
assert_equal nil, @sub.a
assert_nil @klass.a
assert_nil @sub.a
end
end
Expand Up @@ -32,16 +32,16 @@ def test_simple_accessor_declaration
single_class.superclass_delegating_accessor :both
# Class should have accessor and mutator
# the instance should have an accessor only
assert single_class.respond_to?(:both)
assert single_class.respond_to?(:both=)
assert_respond_to single_class, :both
assert_respond_to single_class, :both=
assert single_class.public_instance_methods.map(&:to_s).include?("both")
assert !single_class.public_instance_methods.map(&:to_s).include?("both=")
end

def test_simple_accessor_declaration_with_instance_reader_false
single_class.superclass_delegating_accessor :no_instance_reader, :instance_reader => false
assert single_class.respond_to?(:no_instance_reader)
assert single_class.respond_to?(:no_instance_reader=)
assert_respond_to single_class, :no_instance_reader
assert_respond_to single_class, :no_instance_reader=
assert !single_class.public_instance_methods.map(&:to_s).include?("no_instance_reader")
end

Expand Down
4 changes: 2 additions & 2 deletions activesupport/test/core_ext/date_time_ext_test.rb
Expand Up @@ -275,12 +275,12 @@ def test_current_returns_time_zone_today_when_zone_default_set
end

def test_current_without_time_zone
assert DateTime.current.is_a?(DateTime)
assert_kind_of DateTime, DateTime.current
end

def test_current_with_time_zone
with_env_tz 'US/Eastern' do
assert DateTime.current.is_a?(DateTime)
assert_kind_of DateTime, DateTime.current
end
end

Expand Down
4 changes: 2 additions & 2 deletions activesupport/test/core_ext/duration_test.rb
Expand Up @@ -5,8 +5,8 @@ class DurationTest < ActiveSupport::TestCase
def test_is_a
d = 1.day
assert d.is_a?(ActiveSupport::Duration)
assert d.is_a?(Numeric)
assert d.is_a?(Fixnum)
assert_kind_of Numeric, d
assert_kind_of Fixnum, d
assert !d.is_a?(Hash)

k = Class.new
Expand Down
8 changes: 4 additions & 4 deletions activesupport/test/core_ext/module/attribute_accessor_test.rb
Expand Up @@ -27,14 +27,14 @@ def test_should_set_mattr_value
end

def test_should_not_create_instance_writer
assert @module.respond_to?(:foo)
assert @module.respond_to?(:foo=)
assert @object.respond_to?(:bar)
assert_respond_to @module, :foo
assert_respond_to @module, :foo=
assert_respond_to @object, :bar
assert !@object.respond_to?(:bar=)
end

def test_should_not_create_instance_reader
assert @module.respond_to?(:shaq)
assert_respond_to @module, :shaq
assert !@object.respond_to?(:shaq)
end
end
6 changes: 3 additions & 3 deletions activesupport/test/core_ext/module/synchronization_test.rb
Expand Up @@ -16,8 +16,8 @@ def test_synchronize_aliases_method_chain_with_synchronize
attr_accessor :value
synchronize :value, :with => :mutex
end
assert @instance.respond_to?(:value_with_synchronization)
assert @instance.respond_to?(:value_without_synchronization)
assert_respond_to @instance, :value_with_synchronization
assert_respond_to @instance, :value_without_synchronization
end

def test_synchronize_does_not_change_behavior
Expand Down Expand Up @@ -81,7 +81,7 @@ def test_can_synchronize_singleton_methods
class << @target
synchronize :to_s, :with => :mutex
end
assert @target.respond_to?(:to_s_without_synchronization)
assert_respond_to @target, :to_s_without_synchronization
assert_nothing_raised { @target.to_s; @target.to_s }
assert_equal 2, @target.mutex.sync_count
end
Expand Down

0 comments on commit 39a246f

Please sign in to comment.