1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Alias refute methods to assert_not and perfer assert_not on tests

This commit is contained in:
Rafael Mendonça França 2012-12-28 20:49:41 -03:00
parent 6c0013f7cd
commit 5294ad82c6
26 changed files with 76 additions and 67 deletions

View file

@ -20,7 +20,7 @@ module ActionDispatch
def assert_dom_not_equal(expected, actual, message = "")
expected_dom = HTML::Document.new(expected).root
actual_dom = HTML::Document.new(actual).root
refute_equal expected_dom, actual_dom
assert_not_equal expected_dom, actual_dom
end
end
end

View file

@ -40,7 +40,7 @@ module ActionController
def thread_locals
tc.assert_equal 'aaron', Thread.current[:setting]
tc.refute_equal Thread.current.object_id, Thread.current[:originating_thread]
tc.assert_not_equal Thread.current.object_id, Thread.current[:originating_thread]
response.headers['Content-Type'] = 'text/event-stream'
%w{ hello world }.each do |word|

View file

@ -11,7 +11,7 @@ module ActionController
def test_header_merge
header = @response.header.merge('Foo' => 'Bar')
assert_kind_of(ActionController::Live::Response::Header, header)
refute_equal header, @response.header
assert_not_equal header, @response.header
end
def test_initialize_with_default_headers

View file

@ -24,7 +24,7 @@ module ActionDispatch
s['foo'] = 'bar'
s1 = Session.create(store, env, {})
refute_equal s, s1
assert_not_equal s, s1
assert_equal 'bar', s1['foo']
end

View file

@ -42,7 +42,7 @@ module ActionDispatch
as.call(@env)
session1 = Request::Session.find @env
refute_equal session, session1
assert_not_equal session, session1
assert_equal session.to_hash, session1.to_hash
end

View file

@ -47,7 +47,7 @@ class SSLTest < ActionDispatch::IntegrationTest
def test_disable_hsts_header
self.app = ActionDispatch::SSL.new(default_app, :hsts => false)
get "https://example.org/"
refute response.headers['Strict-Transport-Security']
assert_not response.headers['Strict-Transport-Security']
end
def test_hsts_expires

View file

@ -29,7 +29,7 @@ module ActionDispatch
}
svg = table.to_svg
assert svg
refute_match(/DOCTYPE/, svg)
assert_no_match(/DOCTYPE/, svg)
end
end
@ -53,7 +53,7 @@ module ActionDispatch
sim = simulator_for ['/foo(/bar)']
assert_match sim, '/foo'
assert_match sim, '/foo/bar'
refute_match sim, '/foo/'
assert_no_match sim, '/foo/'
end
def test_match_data

View file

@ -11,17 +11,17 @@ module ActionDispatch
def test_simulate_simple_no_match
sim = simulator_for ['/foo']
refute_match sim, 'foo'
assert_no_match sim, 'foo'
end
def test_simulate_simple_no_match_too_long
sim = simulator_for ['/foo']
refute_match sim, '/foo/bar'
assert_no_match sim, '/foo/bar'
end
def test_simulate_simple_no_match_wrong_string
sim = simulator_for ['/foo']
refute_match sim, '/bar'
assert_no_match sim, '/bar'
end
def test_simulate_regex
@ -34,14 +34,14 @@ module ActionDispatch
sim = simulator_for ['/foo', '/bar']
assert_match sim, '/bar'
assert_match sim, '/foo'
refute_match sim, '/baz'
assert_no_match sim, '/baz'
end
def test_simulate_optional
sim = simulator_for ['/foo(/bar)']
assert_match sim, '/foo'
assert_match sim, '/foo/bar'
refute_match sim, '/foo/'
assert_no_match sim, '/foo/'
end
def test_matchdata_has_memos

View file

@ -9,7 +9,7 @@ module ActionDispatch
assert sym.default_regexp?
sym.regexp = nil
refute sym.default_regexp?
assert_not sym.default_regexp?
end
end
end

View file

@ -88,7 +88,7 @@ module ActionDispatch
path = Pattern.new strexp
assert_match(path, '/page/tender')
assert_match(path, '/page/love')
refute_match(path, '/page/loving')
assert_no_match(path, '/page/loving')
end
def test_optional_names
@ -110,7 +110,7 @@ module ActionDispatch
)
path = Pattern.new strexp
assert_match(path, '/123')
refute_match(path, '/')
assert_no_match(path, '/')
end
def test_to_regexp_with_group
@ -122,7 +122,7 @@ module ActionDispatch
path = Pattern.new strexp
assert_match(path, '/page/tender')
assert_match(path, '/page/love')
refute_match(path, '/page/loving')
assert_no_match(path, '/page/loving')
end
def test_ast_sets_regular_expressions
@ -189,7 +189,7 @@ module ActionDispatch
path = Pattern.new strexp
assert_match(path, '/page/TENDER/aaron')
assert_match(path, '/page/loVE/aaron')
refute_match(path, '/page/loVE/AAron')
assert_no_match(path, '/page/loVE/AAron')
end
def test_to_regexp_with_strexp
@ -210,7 +210,7 @@ module ActionDispatch
path = Pattern.new '/:controller(/:action(/:id(.:format)))'
uri = 'content'
refute path =~ uri
assert_not path =~ uri
end
def test_match_controller

View file

@ -92,7 +92,7 @@ module ActionDispatch
routes = [specific, generic]
refute_equal specific.score(knowledge), generic.score(knowledge)
assert_not_equal specific.score(knowledge), generic.score(knowledge)
found = routes.sort_by { |r| r.score(knowledge) }.last

View file

@ -277,7 +277,7 @@ module ActionDispatch
@router.recognize(env) do |*whatever|
yielded = true
end
refute yielded
assert_not yielded
end
def test_required_part_in_recall

View file

@ -23,7 +23,7 @@ module ActionDispatch
routes.add_route nil, path, {}, {}, {}
ast = routes.ast
routes.add_route nil, path, {}, {}, {}
refute_equal ast, routes.ast
assert_not_equal ast, routes.ast
end
def test_simulator_changes
@ -33,7 +33,7 @@ module ActionDispatch
routes.add_route nil, path, {}, {}, {}
sim = routes.simulator
routes.add_route nil, path, {}, {}, {}
refute_equal sim, routes.simulator
assert_not_equal sim, routes.simulator
end
def test_first_name_wins

View file

@ -1484,7 +1484,7 @@ class BasicsTest < ActiveRecord::TestCase
def test_column_types_typecast
topic = Topic.first
refute_equal 't.lo', topic.author_name
assert_not_equal 't.lo', topic.author_name
attrs = topic.attributes.dup
attrs.delete 'id'

View file

@ -10,18 +10,18 @@ module ActiveRecord
end
def test_in_use?
refute adapter.in_use?, 'adapter is not in use'
assert_not adapter.in_use?, 'adapter is not in use'
assert adapter.lease, 'lease adapter'
assert adapter.in_use?, 'adapter is in use'
end
def test_lease_twice
assert adapter.lease, 'should lease adapter'
refute adapter.lease, 'should not lease adapter'
assert_not adapter.lease, 'should not lease adapter'
end
def test_last_use
refute adapter.last_use
assert_not adapter.last_use
adapter.lease
assert adapter.last_use
end
@ -30,7 +30,7 @@ module ActiveRecord
assert adapter.lease, 'lease adapter'
assert adapter.in_use?, 'adapter is in use'
adapter.expire
refute adapter.in_use?, 'adapter is in use'
assert_not adapter.in_use?, 'adapter is in use'
end
def test_close
@ -44,7 +44,7 @@ module ActiveRecord
# Close should put the adapter back in the pool
adapter.close
refute adapter.in_use?
assert_not adapter.in_use?
assert_equal adapter, pool.connection
end

View file

@ -293,7 +293,7 @@ module ActiveRecord
end
assert connection.column_exists?(:testings, :foo)
refute connection.column_exists?(:testings, :bar)
assert_not connection.column_exists?(:testings, :bar)
end
def test_column_exists_with_type
@ -303,10 +303,10 @@ module ActiveRecord
end
assert connection.column_exists?(:testings, :foo, :string)
refute connection.column_exists?(:testings, :foo, :integer)
assert_not connection.column_exists?(:testings, :foo, :integer)
assert connection.column_exists?(:testings, :bar, :decimal)
refute connection.column_exists?(:testings, :bar, :integer)
assert_not connection.column_exists?(:testings, :bar, :integer)
end
def test_column_exists_with_definition
@ -318,13 +318,13 @@ module ActiveRecord
end
assert connection.column_exists?(:testings, :foo, :string, limit: 100)
refute connection.column_exists?(:testings, :foo, :string, limit: nil)
assert_not connection.column_exists?(:testings, :foo, :string, limit: nil)
assert connection.column_exists?(:testings, :bar, :decimal, precision: 8, scale: 2)
refute connection.column_exists?(:testings, :bar, :decimal, precision: nil, scale: nil)
assert_not connection.column_exists?(:testings, :bar, :decimal, precision: nil, scale: nil)
assert connection.column_exists?(:testings, :taggable_id, :integer, null: false)
refute connection.column_exists?(:testings, :taggable_id, :integer, null: true)
assert_not connection.column_exists?(:testings, :taggable_id, :integer, null: true)
assert connection.column_exists?(:testings, :taggable_type, :string, default: 'Photo')
refute connection.column_exists?(:testings, :taggable_type, :string, default: nil)
assert_not connection.column_exists?(:testings, :taggable_type, :string, default: nil)
end
def test_column_exists_on_table_with_no_options_parameter_supplied

View file

@ -16,7 +16,7 @@ module ActiveRecord
end
def test_add_remove_single_field_using_string_arguments
refute TestModel.column_methods_hash.key?(:last_name)
assert_not TestModel.column_methods_hash.key?(:last_name)
add_column 'test_models', 'last_name', :string
@ -27,11 +27,11 @@ module ActiveRecord
remove_column 'test_models', 'last_name'
TestModel.reset_column_information
refute TestModel.column_methods_hash.key?(:last_name)
assert_not TestModel.column_methods_hash.key?(:last_name)
end
def test_add_remove_single_field_using_symbol_arguments
refute TestModel.column_methods_hash.key?(:last_name)
assert_not TestModel.column_methods_hash.key?(:last_name)
add_column :test_models, :last_name, :string
@ -41,7 +41,7 @@ module ActiveRecord
remove_column :test_models, :last_name
TestModel.reset_column_information
refute TestModel.column_methods_hash.key?(:last_name)
assert_not TestModel.column_methods_hash.key?(:last_name)
end
def test_unabstracted_database_dependent_types

View file

@ -35,7 +35,7 @@ module ActiveRecord
connection.rename_index(table_name, 'old_idx', 'new_idx')
# if the adapter doesn't support the indexes call, pick defaults that let the test pass
refute connection.index_name_exists?(table_name, 'old_idx', false)
assert_not connection.index_name_exists?(table_name, 'old_idx', false)
assert connection.index_name_exists?(table_name, 'new_idx', true)
end
@ -63,7 +63,7 @@ module ActiveRecord
connection.add_index(table_name, "foo", :name => too_long_index_name)
}
refute connection.index_name_exists?(table_name, too_long_index_name, false)
assert_not connection.index_name_exists?(table_name, too_long_index_name, false)
connection.add_index(table_name, "foo", :name => good_index_name)
assert connection.index_name_exists?(table_name, good_index_name, false)
@ -75,7 +75,7 @@ module ActiveRecord
assert connection.index_exists?(table_name, :foo, :name => :symbol_index_name)
connection.remove_index table_name, :name => :symbol_index_name
refute connection.index_exists?(table_name, :foo, :name => :symbol_index_name)
assert_not connection.index_exists?(table_name, :foo, :name => :symbol_index_name)
end
def test_index_exists

View file

@ -29,7 +29,7 @@ module ActiveRecord
t.references :foo
end
refute connection.index_exists?(table_name, :foo_id, :name => :index_testings_on_foo_id)
assert_not connection.index_exists?(table_name, :foo_id, :name => :index_testings_on_foo_id)
end
def test_does_not_create_index_explicit
@ -37,7 +37,7 @@ module ActiveRecord
t.references :foo, :index => false
end
refute connection.index_exists?(table_name, :foo_id, :name => :index_testings_on_foo_id)
assert_not connection.index_exists?(table_name, :foo_id, :name => :index_testings_on_foo_id)
end
def test_creates_index_with_options
@ -75,7 +75,7 @@ module ActiveRecord
t.references :foo
end
refute connection.index_exists?(table_name, :foo_id, :name => :index_testings_on_foo_id)
assert_not connection.index_exists?(table_name, :foo_id, :name => :index_testings_on_foo_id)
end
def test_does_not_create_index_for_existing_table_explicit
@ -84,7 +84,7 @@ module ActiveRecord
t.references :foo, :index => false
end
refute connection.index_exists?(table_name, :foo_id, :name => :index_testings_on_foo_id)
assert_not connection.index_exists?(table_name, :foo_id, :name => :index_testings_on_foo_id)
end
def test_creates_polymorphic_index_for_existing_table

View file

@ -22,7 +22,7 @@ module ActiveRecord
def test_does_not_create_reference_type_column
add_reference table_name, :taggable
refute column_exists?(table_name, :taggable_type, :string)
assert_not column_exists?(table_name, :taggable_type, :string)
end
def test_creates_reference_type_column
@ -37,7 +37,7 @@ module ActiveRecord
def test_does_not_create_reference_id_index
add_reference table_name, :user
refute index_exists?(table_name, :user_id)
assert_not index_exists?(table_name, :user_id)
end
def test_creates_polymorphic_index
@ -57,19 +57,19 @@ module ActiveRecord
def test_deletes_reference_id_column
remove_reference table_name, :supplier
refute column_exists?(table_name, :supplier_id, :integer)
assert_not column_exists?(table_name, :supplier_id, :integer)
end
def test_deletes_reference_id_index
remove_reference table_name, :supplier
refute index_exists?(table_name, :supplier_id)
assert_not index_exists?(table_name, :supplier_id)
end
def test_does_not_delete_reference_type_column
with_polymorphic_column do
remove_reference table_name, :supplier
refute column_exists?(table_name, :supplier_id, :integer)
assert_not column_exists?(table_name, :supplier_id, :integer)
assert column_exists?(table_name, :supplier_type, :string)
end
end
@ -77,14 +77,14 @@ module ActiveRecord
def test_deletes_reference_type_column
with_polymorphic_column do
remove_reference table_name, :supplier, polymorphic: true
refute column_exists?(table_name, :supplier_type, :string)
assert_not column_exists?(table_name, :supplier_type, :string)
end
end
def test_deletes_polymorphic_index
with_polymorphic_column do
remove_reference table_name, :supplier, polymorphic: true
refute index_exists?(table_name, [:supplier_id, :supplier_type])
assert_not index_exists?(table_name, [:supplier_id, :supplier_type])
end
end
@ -95,7 +95,7 @@ module ActiveRecord
def test_remove_belongs_to_alias
remove_belongs_to table_name, :supplier
refute column_exists?(table_name, :supplier_id, :integer)
assert_not column_exists?(table_name, :supplier_id, :integer)
end
private

View file

@ -232,7 +232,7 @@ class MigrationTest < ActiveRecord::TestCase
skip "not supported on #{ActiveRecord::Base.connection.class}"
end
refute Person.column_methods_hash.include?(:last_name)
assert_not Person.column_methods_hash.include?(:last_name)
migration = Struct.new(:name, :version) {
def migrate(x); raise 'Something broke'; end
@ -245,7 +245,7 @@ class MigrationTest < ActiveRecord::TestCase
assert_equal "An error has occurred, this and all later migrations canceled:\n\nSomething broke", e.message
Person.reset_column_information
refute Person.column_methods_hash.include?(:last_name)
assert_not Person.column_methods_hash.include?(:last_name)
end
def test_schema_migrations_table_name

View file

@ -121,11 +121,11 @@ module ActiveRecord
ActiveRecord::Migrator.new(:up, pass_one).migrate
assert pass_one.first.went_up
refute pass_one.first.went_down
assert_not pass_one.first.went_down
pass_two = [Sensor.new('One', 1), Sensor.new('Three', 3)]
ActiveRecord::Migrator.new(:up, pass_two).migrate
refute pass_two[0].went_up
assert_not pass_two[0].went_up
assert pass_two[1].went_up
assert pass_two.all? { |x| !x.went_down }
@ -135,7 +135,7 @@ module ActiveRecord
ActiveRecord::Migrator.new(:down, pass_three).migrate
assert pass_three[0].went_down
refute pass_three[1].went_down
assert_not pass_three[1].went_down
assert pass_three[2].went_down
end
@ -307,7 +307,7 @@ module ActiveRecord
_, migrator = migrator_class(3)
ActiveRecord::Base.connection.execute("DROP TABLE schema_migrations")
refute ActiveRecord::Base.connection.table_exists?('schema_migrations')
assert_not ActiveRecord::Base.connection.table_exists?('schema_migrations')
migrator.migrate("valid", 1)
assert ActiveRecord::Base.connection.table_exists?('schema_migrations')
end

View file

@ -15,7 +15,7 @@ class TransactionTest < ActiveRecord::TestCase
end
def test_raise_after_destroy
refute @first.frozen?
assert_not @first.frozen?
assert_raises(RuntimeError) {
Topic.transaction do
@ -26,7 +26,7 @@ class TransactionTest < ActiveRecord::TestCase
}
assert @first.reload
refute @first.frozen?
assert_not @first.frozen?
end
def test_successful

View file

@ -41,9 +41,18 @@ module ActiveSupport
# test/unit backwards compatibility methods
alias :assert_raise :assert_raises
alias :assert_not_nil :refute_nil
alias :assert_not_empty :refute_empty
alias :assert_not_equal :refute_equal
alias :assert_not_in_delta :refute_in_delta
alias :assert_not_in_epsilon :refute_in_epsilon
alias :assert_not_includes :refute_includes
alias :assert_not_instance_of :refute_instance_of
alias :assert_not_kind_of :refute_kind_of
alias :assert_no_match :refute_match
alias :assert_not_nil :refute_nil
alias :assert_not_operator :refute_operator
alias :assert_not_predicate :refute_predicate
alias :assert_not_respond_to :refute_respond_to
alias :assert_not_same :refute_same
# Fails if the block raises an exception.

View file

@ -39,14 +39,14 @@ class ThreadExt < ActiveSupport::TestCase
end
def test_thread_variable?
refute Thread.new { Thread.current.thread_variable?("foo") }.join.value
assert_not Thread.new { Thread.current.thread_variable?("foo") }.join.value
t = Thread.new {
Thread.current.thread_variable_set("foo", "bar")
}.join
assert t.thread_variable?("foo")
assert t.thread_variable?(:foo)
refute t.thread_variable?(:bar)
assert_not t.thread_variable?(:bar)
end
def test_thread_variable_strings_and_symbols_are_the_same_key

View file

@ -10,7 +10,7 @@ class StringInquirerTest < ActiveSupport::TestCase
end
def test_miss
refute @string_inquirer.development?
assert_not @string_inquirer.development?
end
def test_missing_question_mark