Use respond_to test helpers

This commit is contained in:
Daniel Colson 2018-01-24 21:14:10 -05:00
parent 8baca31dbe
commit 0d50cae996
43 changed files with 158 additions and 158 deletions

View File

@ -506,8 +506,8 @@ class BaseTest < ActiveSupport::TestCase
test "should respond to action methods" do test "should respond to action methods" do
assert_respond_to BaseMailer, :welcome assert_respond_to BaseMailer, :welcome
assert_respond_to BaseMailer, :implicit_multipart assert_respond_to BaseMailer, :implicit_multipart
assert !BaseMailer.respond_to?(:mail) assert_not_respond_to BaseMailer, :mail
assert !BaseMailer.respond_to?(:headers) assert_not_respond_to BaseMailer, :headers
end end
test "calling just the action should return the generated mail object" do test "calling just the action should return the generated mail object" do

View File

@ -289,7 +289,7 @@ class ParametersAccessorsTest < ActiveSupport::TestCase
else else
test "ActionController::Parameters does not respond to #dig on Ruby 2.2" do test "ActionController::Parameters does not respond to #dig on Ruby 2.2" do
assert_not ActionController::Parameters.method_defined?(:dig) assert_not ActionController::Parameters.method_defined?(:dig)
assert_not @params.respond_to?(:dig) assert_not_respond_to @params, :dig
end end
end end
end end

View File

@ -17,8 +17,8 @@ module ActionDispatch
def test_respond_to? def test_respond_to?
runner = MyRunner.new(Class.new { def x; end }.new) runner = MyRunner.new(Class.new { def x; end }.new)
assert runner.respond_to?(:hi) assert_respond_to runner, :hi
assert runner.respond_to?(:x) assert_respond_to runner, :x
end end
end end
end end

View File

@ -838,7 +838,7 @@ XML
def test_fixture_file_upload_should_be_able_access_to_tempfile def test_fixture_file_upload_should_be_able_access_to_tempfile
file = fixture_file_upload(FILES_DIR + "/ruby_on_rails.jpg", "image/jpg") file = fixture_file_upload(FILES_DIR + "/ruby_on_rails.jpg", "image/jpg")
assert file.respond_to?(:tempfile), "expected tempfile should respond on fixture file object, got nothing" assert_respond_to file, :tempfile
end end
def test_fixture_file_upload def test_fixture_file_upload

View File

@ -288,7 +288,7 @@ module AbstractController
kls = Class.new { include set.url_helpers } kls = Class.new { include set.url_helpers }
controller = kls.new controller = kls.new
assert controller.respond_to?(:home_url) assert_respond_to controller, :home_url
assert_equal "http://www.basecamphq.com/home/sweet/home/again", assert_equal "http://www.basecamphq.com/home/sweet/home/again",
controller.send(:home_url, host: "www.basecamphq.com", user: "again") controller.send(:home_url, host: "www.basecamphq.com", user: "again")

View File

@ -159,7 +159,7 @@ class MimeTypeTest < ActiveSupport::TestCase
types.each do |type| types.each do |type|
mime = Mime[type] mime = Mime[type]
assert mime.respond_to?("#{type}?"), "#{mime.inspect} does not respond to #{type}?" assert_respond_to mime, "#{type}?"
assert_equal type, mime.symbol, "#{mime.inspect} is not #{type}?" assert_equal type, mime.symbol, "#{mime.inspect} is not #{type}?"
invalid_types = types - [type] invalid_types = types - [type]
invalid_types.delete(:html) invalid_types.delete(:html)

View File

@ -356,7 +356,7 @@ class ResponseTest < ActiveSupport::TestCase
end end
test "respond_to? accepts include_private" do test "respond_to? accepts include_private" do
assert_not @response.respond_to?(:method_missing) assert_not_respond_to @response, :method_missing
assert @response.respond_to?(:method_missing, true) assert @response.respond_to?(:method_missing, true)
end end

View File

@ -106,8 +106,8 @@ module ActionDispatch
def test_respond_to? def test_respond_to?
tf = Class.new { def read; yield end } tf = Class.new { def read; yield end }
uf = Http::UploadedFile.new(tempfile: tf.new) uf = Http::UploadedFile.new(tempfile: tf.new)
assert uf.respond_to?(:headers), "responds to headers" assert_respond_to uf, :headers
assert uf.respond_to?(:read), "responds to read" assert_respond_to uf, :read
end end
end end
end end

View File

@ -29,7 +29,7 @@ module ActiveModel
# <tt>to_key</tt> returns an Enumerable of all (primary) key attributes # <tt>to_key</tt> returns an Enumerable of all (primary) key attributes
# of the model, and is used to a generate unique DOM id for the object. # of the model, and is used to a generate unique DOM id for the object.
def test_to_key def test_to_key
assert model.respond_to?(:to_key), "The model should respond to to_key" assert_respond_to model, :to_key
def model.persisted?() false end def model.persisted?() false end
assert model.to_key.nil?, "to_key should return nil when `persisted?` returns false" assert model.to_key.nil?, "to_key should return nil when `persisted?` returns false"
end end
@ -44,7 +44,7 @@ module ActiveModel
# tests for this behavior in lint because it doesn't make sense to force # tests for this behavior in lint because it doesn't make sense to force
# any of the possible implementation strategies on the implementer. # any of the possible implementation strategies on the implementer.
def test_to_param def test_to_param
assert model.respond_to?(:to_param), "The model should respond to to_param" assert_respond_to model, :to_param
def model.to_key() [1] end def model.to_key() [1] end
def model.persisted?() false end def model.persisted?() false end
assert model.to_param.nil?, "to_param should return nil when `persisted?` returns false" assert model.to_param.nil?, "to_param should return nil when `persisted?` returns false"
@ -56,7 +56,7 @@ module ActiveModel
# <tt>to_partial_path</tt> is used for looking up partials. For example, # <tt>to_partial_path</tt> is used for looking up partials. For example,
# a BlogPost model might return "blog_posts/blog_post". # a BlogPost model might return "blog_posts/blog_post".
def test_to_partial_path def test_to_partial_path
assert model.respond_to?(:to_partial_path), "The model should respond to to_partial_path" assert_respond_to model, :to_partial_path
assert_kind_of String, model.to_partial_path assert_kind_of String, model.to_partial_path
end end
@ -68,7 +68,7 @@ module ActiveModel
# will route to the create action. If it is persisted, a form for the # will route to the create action. If it is persisted, a form for the
# object will route to the update action. # object will route to the update action.
def test_persisted? def test_persisted?
assert model.respond_to?(:persisted?), "The model should respond to persisted?" assert_respond_to model, :persisted?
assert_boolean model.persisted?, "persisted?" assert_boolean model.persisted?, "persisted?"
end end
@ -79,14 +79,14 @@ module ActiveModel
# #
# Check ActiveModel::Naming for more information. # Check ActiveModel::Naming for more information.
def test_model_naming def test_model_naming
assert model.class.respond_to?(:model_name), "The model class should respond to model_name" assert_respond_to model.class, :model_name
model_name = model.class.model_name model_name = model.class.model_name
assert model_name.respond_to?(:to_str) assert_respond_to model_name, :to_str
assert model_name.human.respond_to?(:to_str) assert_respond_to model_name.human, :to_str
assert model_name.singular.respond_to?(:to_str) assert_respond_to model_name.singular, :to_str
assert model_name.plural.respond_to?(:to_str) assert_respond_to model_name.plural, :to_str
assert model.respond_to?(:model_name), "The model instance should respond to model_name" assert_respond_to model, :model_name
assert_equal model.model_name, model.class.model_name assert_equal model.model_name, model.class.model_name
end end
@ -100,13 +100,13 @@ module ActiveModel
# If localization is used, the strings should be localized for the current # If localization is used, the strings should be localized for the current
# locale. If no error is present, the method should return an empty array. # locale. If no error is present, the method should return an empty array.
def test_errors_aref def test_errors_aref
assert model.respond_to?(:errors), "The model should respond to errors" assert_respond_to model, :errors
assert model.errors[:hello].is_a?(Array), "errors#[] should return an Array" assert model.errors[:hello].is_a?(Array), "errors#[] should return an Array"
end end
private private
def model def model
assert @model.respond_to?(:to_model), "The object should respond to to_model" assert_respond_to @model, :to_model
@model.to_model @model.to_model
end end

View File

@ -220,7 +220,7 @@ class AttributeMethodsTest < ActiveModel::TestCase
ModelWithAttributes.define_attribute_methods(:foo) ModelWithAttributes.define_attribute_methods(:foo)
ModelWithAttributes.undefine_attribute_methods ModelWithAttributes.undefine_attribute_methods
assert !ModelWithAttributes.new.respond_to?(:foo) assert_not_respond_to ModelWithAttributes.new, :foo
assert_raises(NoMethodError) { ModelWithAttributes.new.foo } assert_raises(NoMethodError) { ModelWithAttributes.new.foo }
end end
@ -255,7 +255,7 @@ class AttributeMethodsTest < ActiveModel::TestCase
m = ModelWithAttributes2.new m = ModelWithAttributes2.new
m.attributes = { "private_method" => "<3", "protected_method" => "O_o" } m.attributes = { "private_method" => "<3", "protected_method" => "O_o" }
assert !m.respond_to?(:private_method) assert_not_respond_to m, :private_method
assert m.respond_to?(:private_method, true) assert m.respond_to?(:private_method, true)
c = ClassWithProtected.new c = ClassWithProtected.new

View File

@ -85,21 +85,21 @@ class CallbacksTest < ActiveModel::TestCase
end end
test "only selects which types of callbacks should be created" do test "only selects which types of callbacks should be created" do
assert !ModelCallbacks.respond_to?(:before_initialize) assert_not_respond_to ModelCallbacks, :before_initialize
assert !ModelCallbacks.respond_to?(:around_initialize) assert_not_respond_to ModelCallbacks, :around_initialize
assert_respond_to ModelCallbacks, :after_initialize assert_respond_to ModelCallbacks, :after_initialize
end end
test "only selects which types of callbacks should be created from an array list" do test "only selects which types of callbacks should be created from an array list" do
assert_respond_to ModelCallbacks, :before_multiple assert_respond_to ModelCallbacks, :before_multiple
assert_respond_to ModelCallbacks, :around_multiple assert_respond_to ModelCallbacks, :around_multiple
assert !ModelCallbacks.respond_to?(:after_multiple) assert_not_respond_to ModelCallbacks, :after_multiple
end end
test "no callbacks should be created" do test "no callbacks should be created" do
assert !ModelCallbacks.respond_to?(:before_empty) assert_not_respond_to ModelCallbacks, :before_empty
assert !ModelCallbacks.respond_to?(:around_empty) assert_not_respond_to ModelCallbacks, :around_empty
assert !ModelCallbacks.respond_to?(:after_empty) assert_not_respond_to ModelCallbacks, :after_empty
end end
class Violin class Violin

View File

@ -320,7 +320,7 @@ class ErrorsTest < ActiveModel::TestCase
test "generate_message works without i18n_scope" do test "generate_message works without i18n_scope" do
person = Person.new person = Person.new
assert !Person.respond_to?(:i18n_scope) assert_not_respond_to Person, :i18n_scope
assert_nothing_raised { assert_nothing_raised {
person.errors.generate_message(:name, :blank) person.errors.generate_message(:name, :blank)
} }

View File

@ -40,7 +40,7 @@ class PostgresqlHstoreTest < ActiveRecord::PostgreSQLTestCase
end end
def test_hstore_included_in_extensions def test_hstore_included_in_extensions
assert @connection.respond_to?(:extensions), "connection should have a list of extensions" assert_respond_to @connection, :extensions
assert_includes @connection.extensions, "hstore", "extension list should include hstore" assert_includes @connection.extensions, "hstore", "extension list should include hstore"
end end

View File

@ -475,11 +475,11 @@ module ActiveRecord
end end
def test_respond_to_enable_extension def test_respond_to_enable_extension
assert @conn.respond_to?(:enable_extension) assert_respond_to @conn, :enable_extension
end end
def test_respond_to_disable_extension def test_respond_to_disable_extension
assert @conn.respond_to?(:disable_extension) assert_respond_to @conn, :disable_extension
end end
def test_statement_closed def test_statement_closed

View File

@ -77,7 +77,7 @@ class LeftOuterJoinAssociationTest < ActiveRecord::TestCase
def test_does_not_override_select def test_does_not_override_select
authors = Author.select("authors.name, #{%{(authors.author_address_id || ' ' || authors.author_address_extra_id) as addr_id}}").left_outer_joins(:posts) authors = Author.select("authors.name, #{%{(authors.author_address_id || ' ' || authors.author_address_extra_id) as addr_id}}").left_outer_joins(:posts)
assert authors.any? assert authors.any?
assert authors.first.respond_to?(:addr_id) assert_respond_to authors.first, :addr_id
end end
test "the default scope of the target is applied when joining associations" do test "the default scope of the target is applied when joining associations" do

View File

@ -142,16 +142,16 @@ class AttributeMethodsTest < ActiveRecord::TestCase
assert_respond_to topic, :title= assert_respond_to topic, :title=
assert_respond_to topic, "author_name" assert_respond_to topic, "author_name"
assert_respond_to topic, "attribute_names" assert_respond_to topic, "attribute_names"
assert !topic.respond_to?("nothingness") assert_not_respond_to topic, "nothingness"
assert !topic.respond_to?(:nothingness) assert_not_respond_to topic, :nothingness
end end
test "respond_to? with a custom primary key" do test "respond_to? with a custom primary key" do
keyboard = Keyboard.create keyboard = Keyboard.create
assert_not_nil keyboard.key_number assert_not_nil keyboard.key_number
assert_equal keyboard.key_number, keyboard.id assert_equal keyboard.key_number, keyboard.id
assert keyboard.respond_to?("key_number") assert_respond_to keyboard, "key_number"
assert keyboard.respond_to?("id") assert_respond_to keyboard, "id"
end end
test "id_before_type_cast with a custom primary key" do test "id_before_type_cast with a custom primary key" do
@ -170,8 +170,8 @@ class AttributeMethodsTest < ActiveRecord::TestCase
end end
topic = klass.allocate topic = klass.allocate
assert !topic.respond_to?("nothingness") assert_not_respond_to topic, "nothingness"
assert !topic.respond_to?(:nothingness) assert_not_respond_to topic, :nothingness
assert_respond_to topic, "title" assert_respond_to topic, "title"
assert_respond_to topic, :title assert_respond_to topic, :title
end end
@ -471,16 +471,16 @@ class AttributeMethodsTest < ActiveRecord::TestCase
test "non-attribute read and write" do test "non-attribute read and write" do
topic = Topic.new topic = Topic.new
assert !topic.respond_to?("mumbo") assert_not_respond_to topic, "mumbo"
assert_raise(NoMethodError) { topic.mumbo } assert_raise(NoMethodError) { topic.mumbo }
assert_raise(NoMethodError) { topic.mumbo = 5 } assert_raise(NoMethodError) { topic.mumbo = 5 }
end end
test "undeclared attribute method does not affect respond_to? and method_missing" do test "undeclared attribute method does not affect respond_to? and method_missing" do
topic = @target.new(title: "Budget") topic = @target.new(title: "Budget")
assert topic.respond_to?("title") assert_respond_to topic, "title"
assert_equal "Budget", topic.title assert_equal "Budget", topic.title
assert !topic.respond_to?("title_hello_world") assert_not_respond_to topic, "title_hello_world"
assert_raise(NoMethodError) { topic.title_hello_world } assert_raise(NoMethodError) { topic.title_hello_world }
end end
@ -491,7 +491,7 @@ class AttributeMethodsTest < ActiveRecord::TestCase
@target.attribute_method_prefix prefix @target.attribute_method_prefix prefix
meth = "#{prefix}title" meth = "#{prefix}title"
assert topic.respond_to?(meth) assert_respond_to topic, meth
assert_equal ["title"], topic.send(meth) assert_equal ["title"], topic.send(meth)
assert_equal ["title", "a"], topic.send(meth, "a") assert_equal ["title", "a"], topic.send(meth, "a")
assert_equal ["title", 1, 2, 3], topic.send(meth, 1, 2, 3) assert_equal ["title", 1, 2, 3], topic.send(meth, 1, 2, 3)
@ -505,7 +505,7 @@ class AttributeMethodsTest < ActiveRecord::TestCase
topic = @target.new(title: "Budget") topic = @target.new(title: "Budget")
meth = "title#{suffix}" meth = "title#{suffix}"
assert topic.respond_to?(meth) assert_respond_to topic, meth
assert_equal ["title"], topic.send(meth) assert_equal ["title"], topic.send(meth)
assert_equal ["title", "a"], topic.send(meth, "a") assert_equal ["title", "a"], topic.send(meth, "a")
assert_equal ["title", 1, 2, 3], topic.send(meth, 1, 2, 3) assert_equal ["title", 1, 2, 3], topic.send(meth, 1, 2, 3)
@ -519,7 +519,7 @@ class AttributeMethodsTest < ActiveRecord::TestCase
topic = @target.new(title: "Budget") topic = @target.new(title: "Budget")
meth = "#{prefix}title#{suffix}" meth = "#{prefix}title#{suffix}"
assert topic.respond_to?(meth) assert_respond_to topic, meth
assert_equal ["title"], topic.send(meth) assert_equal ["title"], topic.send(meth)
assert_equal ["title", "a"], topic.send(meth, "a") assert_equal ["title", "a"], topic.send(meth, "a")
assert_equal ["title", 1, 2, 3], topic.send(meth, 1, 2, 3) assert_equal ["title", 1, 2, 3], topic.send(meth, 1, 2, 3)
@ -767,7 +767,7 @@ class AttributeMethodsTest < ActiveRecord::TestCase
privatize("title") privatize("title")
topic = @target.new(title: "The pros and cons of programming naked.") topic = @target.new(title: "The pros and cons of programming naked.")
assert !topic.respond_to?(:title) assert_not_respond_to topic, :title
exception = assert_raise(NoMethodError) { topic.title } exception = assert_raise(NoMethodError) { topic.title }
assert_includes exception.message, "private method" assert_includes exception.message, "private method"
assert_equal "I'm private", topic.send(:title) assert_equal "I'm private", topic.send(:title)
@ -777,7 +777,7 @@ class AttributeMethodsTest < ActiveRecord::TestCase
privatize("title=(value)") privatize("title=(value)")
topic = @target.new topic = @target.new
assert !topic.respond_to?(:title=) assert_not_respond_to topic, :title=
exception = assert_raise(NoMethodError) { topic.title = "Pants" } exception = assert_raise(NoMethodError) { topic.title = "Pants" }
assert_includes exception.message, "private method" assert_includes exception.message, "private method"
topic.send(:title=, "Very large pants") topic.send(:title=, "Very large pants")
@ -787,7 +787,7 @@ class AttributeMethodsTest < ActiveRecord::TestCase
privatize("title?") privatize("title?")
topic = @target.new(title: "Isaac Newton's pants") topic = @target.new(title: "Isaac Newton's pants")
assert !topic.respond_to?(:title?) assert_not_respond_to topic, :title?
exception = assert_raise(NoMethodError) { topic.title? } exception = assert_raise(NoMethodError) { topic.title? }
assert_includes exception.message, "private method" assert_includes exception.message, "private method"
assert topic.send(:title?) assert topic.send(:title?)

View File

@ -1686,7 +1686,7 @@ class TestAutosaveAssociationValidationMethodsGeneration < ActiveRecord::TestCas
end end
test "should not generate validation methods for has_one associations without :validate => true" do test "should not generate validation methods for has_one associations without :validate => true" do
assert !@pirate.respond_to?(:validate_associated_records_for_non_validated_ship) assert_not_respond_to @pirate, :validate_associated_records_for_non_validated_ship
end end
test "should generate validation methods for belongs_to associations with :validate => true" do test "should generate validation methods for belongs_to associations with :validate => true" do
@ -1694,7 +1694,7 @@ class TestAutosaveAssociationValidationMethodsGeneration < ActiveRecord::TestCas
end end
test "should not generate validation methods for belongs_to associations without :validate => true" do test "should not generate validation methods for belongs_to associations without :validate => true" do
assert !@pirate.respond_to?(:validate_associated_records_for_non_validated_parrot) assert_not_respond_to @pirate, :validate_associated_records_for_non_validated_parrot
end end
test "should generate validation methods for HABTM associations with :validate => true" do test "should generate validation methods for HABTM associations with :validate => true" do

View File

@ -1447,27 +1447,27 @@ class BasicsTest < ActiveRecord::TestCase
end end
test "ignored columns have no attribute methods" do test "ignored columns have no attribute methods" do
refute Developer.new.respond_to?(:first_name) assert_not_respond_to Developer.new, :first_name
refute Developer.new.respond_to?(:first_name=) assert_not_respond_to Developer.new, :first_name=
refute Developer.new.respond_to?(:first_name?) assert_not_respond_to Developer.new, :first_name?
refute SubDeveloper.new.respond_to?(:first_name) assert_not_respond_to SubDeveloper.new, :first_name
refute SubDeveloper.new.respond_to?(:first_name=) assert_not_respond_to SubDeveloper.new, :first_name=
refute SubDeveloper.new.respond_to?(:first_name?) assert_not_respond_to SubDeveloper.new, :first_name?
refute SymbolIgnoredDeveloper.new.respond_to?(:first_name) assert_not_respond_to SymbolIgnoredDeveloper.new, :first_name
refute SymbolIgnoredDeveloper.new.respond_to?(:first_name=) assert_not_respond_to SymbolIgnoredDeveloper.new, :first_name=
refute SymbolIgnoredDeveloper.new.respond_to?(:first_name?) assert_not_respond_to SymbolIgnoredDeveloper.new, :first_name?
end end
test "ignored columns don't prevent explicit declaration of attribute methods" do test "ignored columns don't prevent explicit declaration of attribute methods" do
assert Developer.new.respond_to?(:last_name) assert_respond_to Developer.new, :last_name
assert Developer.new.respond_to?(:last_name=) assert_respond_to Developer.new, :last_name=
assert Developer.new.respond_to?(:last_name?) assert_respond_to Developer.new, :last_name?
assert SubDeveloper.new.respond_to?(:last_name) assert_respond_to SubDeveloper.new, :last_name
assert SubDeveloper.new.respond_to?(:last_name=) assert_respond_to SubDeveloper.new, :last_name=
assert SubDeveloper.new.respond_to?(:last_name?) assert_respond_to SubDeveloper.new, :last_name?
assert SymbolIgnoredDeveloper.new.respond_to?(:last_name) assert_respond_to SymbolIgnoredDeveloper.new, :last_name
assert SymbolIgnoredDeveloper.new.respond_to?(:last_name=) assert_respond_to SymbolIgnoredDeveloper.new, :last_name=
assert SymbolIgnoredDeveloper.new.respond_to?(:last_name?) assert_respond_to SymbolIgnoredDeveloper.new, :last_name?
end end
test "ignored columns are stored as an array of string" do test "ignored columns are stored as an array of string" do
@ -1477,13 +1477,13 @@ class BasicsTest < ActiveRecord::TestCase
test "when #reload called, ignored columns' attribute methods are not defined" do test "when #reload called, ignored columns' attribute methods are not defined" do
developer = Developer.create!(name: "Developer") developer = Developer.create!(name: "Developer")
refute developer.respond_to?(:first_name) assert_not_respond_to developer, :first_name
refute developer.respond_to?(:first_name=) assert_not_respond_to developer, :first_name=
developer.reload developer.reload
refute developer.respond_to?(:first_name) assert_not_respond_to developer, :first_name
refute developer.respond_to?(:first_name=) assert_not_respond_to developer, :first_name=
end end
test "ignored columns not included in SELECT" do test "ignored columns not included in SELECT" do

View File

@ -85,7 +85,7 @@ module ActiveRecord
body = Class.new(String) { def to_path; "/path"; end }.new body = Class.new(String) { def to_path; "/path"; end }.new
app = lambda { |_| [200, {}, body] } app = lambda { |_| [200, {}, body] }
response_body = middleware(app).call(@env)[2] response_body = middleware(app).call(@env)[2]
assert response_body.respond_to?(:to_path) assert_respond_to response_body, :to_path
assert_equal "/path", response_body.to_path assert_equal "/path", response_body.to_path
end end

View File

@ -459,17 +459,17 @@ class EnumTest < ActiveRecord::TestCase
end end
test "enum methods with custom suffix defined" do test "enum methods with custom suffix defined" do
assert @book.class.respond_to?(:easy_to_read) assert_respond_to @book.class, :easy_to_read
assert @book.class.respond_to?(:medium_to_read) assert_respond_to @book.class, :medium_to_read
assert @book.class.respond_to?(:hard_to_read) assert_respond_to @book.class, :hard_to_read
assert @book.respond_to?(:easy_to_read?) assert_respond_to @book, :easy_to_read?
assert @book.respond_to?(:medium_to_read?) assert_respond_to @book, :medium_to_read?
assert @book.respond_to?(:hard_to_read?) assert_respond_to @book, :hard_to_read?
assert @book.respond_to?(:easy_to_read!) assert_respond_to @book, :easy_to_read!
assert @book.respond_to?(:medium_to_read!) assert_respond_to @book, :medium_to_read!
assert @book.respond_to?(:hard_to_read!) assert_respond_to @book, :hard_to_read!
end end
test "update enum attributes with custom suffix" do test "update enum attributes with custom suffix" do

View File

@ -8,7 +8,7 @@ class FinderRespondToTest < ActiveRecord::TestCase
def test_should_preserve_normal_respond_to_behaviour_on_base def test_should_preserve_normal_respond_to_behaviour_on_base
assert_respond_to ActiveRecord::Base, :new assert_respond_to ActiveRecord::Base, :new
assert !ActiveRecord::Base.respond_to?(:find_by_something) assert_not_respond_to ActiveRecord::Base, :find_by_something
end end
def test_should_preserve_normal_respond_to_behaviour_and_respond_to_newly_added_method def test_should_preserve_normal_respond_to_behaviour_and_respond_to_newly_added_method
@ -43,14 +43,14 @@ class FinderRespondToTest < ActiveRecord::TestCase
end end
def test_should_not_respond_to_find_by_one_missing_attribute def test_should_not_respond_to_find_by_one_missing_attribute
assert !Topic.respond_to?(:find_by_undertitle) assert_not_respond_to Topic, :find_by_undertitle
end end
def test_should_not_respond_to_find_by_invalid_method_syntax def test_should_not_respond_to_find_by_invalid_method_syntax
assert !Topic.respond_to?(:fail_to_find_by_title) assert_not_respond_to Topic, :fail_to_find_by_title
assert !Topic.respond_to?(:find_by_title?) assert_not_respond_to Topic, :find_by_title?
assert !Topic.respond_to?(:fail_to_find_or_create_by_title) assert_not_respond_to Topic, :fail_to_find_or_create_by_title
assert !Topic.respond_to?(:find_or_create_by_title?) assert_not_respond_to Topic, :find_or_create_by_title?
end end
private private

View File

@ -252,7 +252,7 @@ class DatabaseConnectedJsonEncodingTest < ActiveRecord::TestCase
def @david.favorite_quote; "Constraints are liberating"; end def @david.favorite_quote; "Constraints are liberating"; end
json = @david.to_json(include: :posts, methods: :favorite_quote) json = @david.to_json(include: :posts, methods: :favorite_quote)
assert !@david.posts.first.respond_to?(:favorite_quote) assert_not_respond_to @david.posts.first, :favorite_quote
assert_match %r{"favorite_quote":"Constraints are liberating"}, json assert_match %r{"favorite_quote":"Constraints are liberating"}, json
assert_equal 1, %r{"favorite_quote":}.match(json).size assert_equal 1, %r{"favorite_quote":}.match(json).size
end end

View File

@ -14,7 +14,7 @@ module ActiveRecord
recorder = CommandRecorder.new(Class.new { recorder = CommandRecorder.new(Class.new {
def america; end def america; end
}.new) }.new)
assert recorder.respond_to?(:america) assert_respond_to recorder, :america
end end
def test_send_calls_super def test_send_calls_super
@ -27,7 +27,7 @@ module ActiveRecord
recorder = CommandRecorder.new(Class.new { recorder = CommandRecorder.new(Class.new {
def create_table(name); end def create_table(name); end
}.new) }.new)
assert recorder.respond_to?(:create_table), "respond_to? create_table" assert_respond_to recorder, :create_table
recorder.send(:create_table, :horses) recorder.send(:create_table, :horses)
assert_equal [[:create_table, [:horses], nil]], recorder.commands assert_equal [[:create_table, [:horses], nil]], recorder.commands
end end

View File

@ -227,7 +227,7 @@ class MultiParameterAttributeTest < ActiveRecord::TestCase
topic = Topic.find(1) topic = Topic.find(1)
topic.attributes = attributes topic.attributes = attributes
assert_equal Time.local(2004, 6, 24, 16, 24, 0), topic.written_on assert_equal Time.local(2004, 6, 24, 16, 24, 0), topic.written_on
assert_equal false, topic.written_on.respond_to?(:time_zone) assert_not_respond_to topic.written_on, :time_zone
end end
end end
@ -242,7 +242,7 @@ class MultiParameterAttributeTest < ActiveRecord::TestCase
topic = Topic.find(1) topic = Topic.find(1)
topic.attributes = attributes topic.attributes = attributes
assert_equal Time.utc(2004, 6, 24, 16, 24, 0), topic.written_on assert_equal Time.utc(2004, 6, 24, 16, 24, 0), topic.written_on
assert_equal false, topic.written_on.respond_to?(:time_zone) assert_not_respond_to topic.written_on, :time_zone
end end
ensure ensure
Topic.skip_time_zone_conversion_for_attributes = [] Topic.skip_time_zone_conversion_for_attributes = []

View File

@ -242,10 +242,10 @@ module ActiveRecord
def test_respond_to_for_non_selected_element def test_respond_to_for_non_selected_element
post = Post.select(:title).first post = Post.select(:title).first
assert_equal false, post.respond_to?(:body), "post should not respond_to?(:body) since invoking it raises exception" assert_not_respond_to post, :body, "post should not respond_to?(:body) since invoking it raises exception"
silence_warnings { post = Post.select("'title' as post_title").first } silence_warnings { post = Post.select("'title' as post_title").first }
assert_equal false, post.respond_to?(:title), "post should not respond_to?(:body) since invoking it raises exception" assert_not_respond_to post, :title, "post should not respond_to?(:body) since invoking it raises exception"
end end
def test_select_quotes_when_using_from_clause def test_select_quotes_when_using_from_clause

View File

@ -56,7 +56,7 @@ class RelationTest < ActiveRecord::TestCase
def test_dynamic_finder def test_dynamic_finder
x = Post.where("author_id = ?", 1) x = Post.where("author_id = ?", 1)
assert x.klass.respond_to?(:find_by_id), "@klass should handle dynamic finders" assert_respond_to x.klass, :find_by_id
end end
def test_multivalue_where def test_multivalue_where
@ -501,12 +501,12 @@ class RelationTest < ActiveRecord::TestCase
relation = Topic.all relation = Topic.all
["find_by_title", "find_by_title_and_author_name"].each do |method| ["find_by_title", "find_by_title_and_author_name"].each do |method|
assert_respond_to relation, method, "Topic.all should respond to #{method.inspect}" assert_respond_to relation, method
end end
end end
def test_respond_to_class_methods_and_scopes def test_respond_to_class_methods_and_scopes
assert Topic.all.respond_to?(:by_lifo) assert_respond_to Topic.all, :by_lifo
end end
def test_find_with_readonly_option def test_find_with_readonly_option
@ -601,7 +601,7 @@ class RelationTest < ActiveRecord::TestCase
reader = Reader.create! post_id: post.id, person_id: 1 reader = Reader.create! post_id: post.id, person_id: 1
comment = Comment.create! post_id: post.id, body: "body" comment = Comment.create! post_id: post.id, body: "body"
assert !comment.respond_to?(:readers) assert_not_respond_to comment, :readers
post_rel = Post.preload(:readers).joins(:readers).where(title: "Uhuu") post_rel = Post.preload(:readers).joins(:readers).where(title: "Uhuu")
result_comment = Comment.joins(:post).merge(post_rel).to_a.first result_comment = Comment.joins(:post).merge(post_rel).to_a.first
@ -1846,7 +1846,7 @@ class RelationTest < ActiveRecord::TestCase
test "delegations do not leak to other classes" do test "delegations do not leak to other classes" do
Topic.all.by_lifo Topic.all.by_lifo
assert Topic.all.class.method_defined?(:by_lifo) assert Topic.all.class.method_defined?(:by_lifo)
assert !Post.all.respond_to?(:by_lifo) assert_not_respond_to Post.all, :by_lifo
end end
def test_unscope_with_subquery def test_unscope_with_subquery

View File

@ -65,9 +65,9 @@ class NamedScopingTest < ActiveRecord::TestCase
end end
def test_scope_should_respond_to_own_methods_and_methods_of_the_proxy def test_scope_should_respond_to_own_methods_and_methods_of_the_proxy
assert Topic.approved.respond_to?(:limit) assert_respond_to Topic.approved, :limit
assert Topic.approved.respond_to?(:count) assert_respond_to Topic.approved, :count
assert Topic.approved.respond_to?(:length) assert_respond_to Topic.approved, :length
end end
def test_scopes_with_options_limit_finds_to_those_matching_the_criteria_specified def test_scopes_with_options_limit_finds_to_those_matching_the_criteria_specified

View File

@ -91,7 +91,7 @@ class ConcernTest < ActiveSupport::TestCase
end end
end end
@klass.include test_module @klass.include test_module
assert_equal false, Object.respond_to?(:test) assert_not_respond_to Object, :test
Qux.class_eval do Qux.class_eval do
remove_const :ClassMethods remove_const :ClassMethods
end end

View File

@ -43,11 +43,11 @@ class ConfigurableActiveSupport < ActiveSupport::TestCase
test "configuration accessors are not available on instance" do test "configuration accessors are not available on instance" do
instance = Parent.new instance = Parent.new
assert !instance.respond_to?(:bar) assert_not_respond_to instance, :bar
assert !instance.respond_to?(:bar=) assert_not_respond_to instance, :bar=
assert !instance.respond_to?(:baz) assert_not_respond_to instance, :baz
assert !instance.respond_to?(:baz=) assert_not_respond_to instance, :baz=
end end
test "configuration accessors can take a default value" do test "configuration accessors can take a default value" do

View File

@ -43,22 +43,22 @@ class ModuleAttributeAccessorPerThreadTest < ActiveSupport::TestCase
assert_respond_to @class, :foo assert_respond_to @class, :foo
assert_respond_to @class, :foo= assert_respond_to @class, :foo=
assert_respond_to @object, :bar assert_respond_to @object, :bar
assert !@object.respond_to?(:bar=) assert_not_respond_to @object, :bar=
end.join end.join
end end
def test_should_not_create_instance_reader def test_should_not_create_instance_reader
Thread.new do Thread.new do
assert_respond_to @class, :shaq assert_respond_to @class, :shaq
assert !@object.respond_to?(:shaq) assert_not_respond_to @object, :shaq
end.join end.join
end end
def test_should_not_create_instance_accessors def test_should_not_create_instance_accessors
Thread.new do Thread.new do
assert_respond_to @class, :camp assert_respond_to @class, :camp
assert !@object.respond_to?(:camp) assert_not_respond_to @object, :camp
assert !@object.respond_to?(:camp=) assert_not_respond_to @object, :camp=
end.join end.join
end end

View File

@ -65,18 +65,18 @@ class ModuleAttributeAccessorTest < ActiveSupport::TestCase
assert_respond_to @module, :foo assert_respond_to @module, :foo
assert_respond_to @module, :foo= assert_respond_to @module, :foo=
assert_respond_to @object, :bar assert_respond_to @object, :bar
assert !@object.respond_to?(:bar=) assert_not_respond_to @object, :bar=
end end
def test_should_not_create_instance_reader def test_should_not_create_instance_reader
assert_respond_to @module, :shaq assert_respond_to @module, :shaq
assert !@object.respond_to?(:shaq) assert_not_respond_to @object, :shaq
end end
def test_should_not_create_instance_accessors def test_should_not_create_instance_accessors
assert_respond_to @module, :camp assert_respond_to @module, :camp
assert !@object.respond_to?(:camp) assert_not_respond_to @object, :camp
assert !@object.respond_to?(:camp=) assert_not_respond_to @object, :camp=
end end
def test_should_raise_name_error_if_attribute_name_is_invalid def test_should_raise_name_error_if_attribute_name_is_invalid

View File

@ -55,10 +55,10 @@ class ModuleConcernTest < ActiveSupport::TestCase
end end
def test_using_class_methods_blocks_instead_of_ClassMethods_module def test_using_class_methods_blocks_instead_of_ClassMethods_module
assert !Foo.respond_to?(:will_be_orphaned) assert_not_respond_to Foo, :will_be_orphaned
assert Foo.respond_to?(:hacked_on) assert_respond_to Foo, :hacked_on
assert Foo.respond_to?(:nicer_dsl) assert_respond_to Foo, :nicer_dsl
assert Foo.respond_to?(:doesnt_clobber) assert_respond_to Foo, :doesnt_clobber
# Orphan in Foo::ClassMethods, not Bar::ClassMethods. # Orphan in Foo::ClassMethods, not Bar::ClassMethods.
assert Foo.const_defined?(:ClassMethods) assert Foo.const_defined?(:ClassMethods)

View File

@ -32,14 +32,14 @@ class RemoveMethodTest < ActiveSupport::TestCase
RemoveMethodTests::A.class_eval { RemoveMethodTests::A.class_eval {
remove_possible_method(:do_something) remove_possible_method(:do_something)
} }
assert !RemoveMethodTests::A.new.respond_to?(:do_something) assert_not_respond_to RemoveMethodTests::A.new, :do_something
end end
def test_remove_singleton_method_from_an_object def test_remove_singleton_method_from_an_object
RemoveMethodTests::A.class_eval { RemoveMethodTests::A.class_eval {
remove_possible_singleton_method(:do_something_else) remove_possible_singleton_method(:do_something_else)
} }
assert !RemoveMethodTests::A.respond_to?(:do_something_else) assert_not_respond_to RemoveMethodTests::A, :do_something_else
end end
def test_redefine_method_in_an_object def test_redefine_method_in_an_object

View File

@ -383,9 +383,9 @@ class ModuleTest < ActiveSupport::TestCase
end end
def test_delegate_missing_to_affects_respond_to def test_delegate_missing_to_affects_respond_to
assert DecoratedTester.new(@david).respond_to?(:name) assert_respond_to DecoratedTester.new(@david), :name
assert_not DecoratedTester.new(@david).respond_to?(:private_name) assert_not_respond_to DecoratedTester.new(@david), :private_name
assert_not DecoratedTester.new(@david).respond_to?(:my_fake_method) assert_not_respond_to DecoratedTester.new(@david), :my_fake_method
assert DecoratedTester.new(@david).respond_to?(:name, true) assert DecoratedTester.new(@david).respond_to?(:name, true)
assert_not DecoratedTester.new(@david).respond_to?(:private_name, true) assert_not DecoratedTester.new(@david).respond_to?(:private_name, true)
@ -414,8 +414,8 @@ class ModuleTest < ActiveSupport::TestCase
place = location.new(Somewhere.new("Such street", "Sad city")) place = location.new(Somewhere.new("Such street", "Sad city"))
assert_not place.respond_to?(:street) assert_not_respond_to place, :street
assert_not place.respond_to?(:city) assert_not_respond_to place, :city
assert place.respond_to?(:street, true) # Asking for private method assert place.respond_to?(:street, true) # Asking for private method
assert place.respond_to?(:city, true) assert place.respond_to?(:city, true)
@ -432,12 +432,12 @@ class ModuleTest < ActiveSupport::TestCase
place = location.new(Somewhere.new("Such street", "Sad city")) place = location.new(Somewhere.new("Such street", "Sad city"))
assert_not place.respond_to?(:street) assert_not_respond_to place, :street
assert_not place.respond_to?(:city) assert_not_respond_to place, :city
assert_not place.respond_to?(:the_street) assert_not_respond_to place, :the_street
assert place.respond_to?(:the_street, true) assert place.respond_to?(:the_street, true)
assert_not place.respond_to?(:the_city) assert_not_respond_to place, :the_city
assert place.respond_to?(:the_city, true) assert place.respond_to?(:the_city, true)
end end
end end

View File

@ -10,25 +10,25 @@ class ObjectTryTest < ActiveSupport::TestCase
def test_nonexisting_method def test_nonexisting_method
method = :undefined_method method = :undefined_method
assert !@string.respond_to?(method) assert_not_respond_to @string, method
assert_nil @string.try(method) assert_nil @string.try(method)
end end
def test_nonexisting_method_with_arguments def test_nonexisting_method_with_arguments
method = :undefined_method method = :undefined_method
assert !@string.respond_to?(method) assert_not_respond_to @string, method
assert_nil @string.try(method, "llo", "y") assert_nil @string.try(method, "llo", "y")
end end
def test_nonexisting_method_bang def test_nonexisting_method_bang
method = :undefined_method method = :undefined_method
assert !@string.respond_to?(method) assert_not_respond_to @string, method
assert_raise(NoMethodError) { @string.try!(method) } assert_raise(NoMethodError) { @string.try!(method) }
end end
def test_nonexisting_method_with_arguments_bang def test_nonexisting_method_with_arguments_bang
method = :undefined_method method = :undefined_method
assert !@string.respond_to?(method) assert_not_respond_to @string, method
assert_raise(NoMethodError) { @string.try!(method, "llo", "y") } assert_raise(NoMethodError) { @string.try!(method, "llo", "y") }
end end

View File

@ -1035,8 +1035,8 @@ class TimeWithZoneMethodsForTimeAndDateTimeTest < ActiveSupport::TestCase
def test_nil_time_zone def test_nil_time_zone
Time.use_zone nil do Time.use_zone nil do
assert !@t.in_time_zone.respond_to?(:period), "no period method" assert_not_respond_to @t.in_time_zone, :period, "no period method"
assert !@dt.in_time_zone.respond_to?(:period), "no period method" assert_not_respond_to @dt.in_time_zone, :period, "no period method"
end end
end end
@ -1224,7 +1224,7 @@ class TimeWithZoneMethodsForDate < ActiveSupport::TestCase
def test_nil_time_zone def test_nil_time_zone
with_tz_default nil do with_tz_default nil do
assert !@d.in_time_zone.respond_to?(:period), "no period method" assert_not_respond_to @d.in_time_zone, :period, "no period method"
end end
end end
@ -1273,9 +1273,9 @@ class TimeWithZoneMethodsForString < ActiveSupport::TestCase
def test_nil_time_zone def test_nil_time_zone
with_tz_default nil do with_tz_default nil do
assert !@s.in_time_zone.respond_to?(:period), "no period method" assert_not_respond_to @s.in_time_zone, :period, "no period method"
assert !@u.in_time_zone.respond_to?(:period), "no period method" assert_not_respond_to @u.in_time_zone, :period, "no period method"
assert !@z.in_time_zone.respond_to?(:period), "no period method" assert_not_respond_to @z.in_time_zone, :period, "no period method"
end end
end end

View File

@ -752,7 +752,7 @@ class DependenciesTest < ActiveSupport::TestCase
Object.const_set :C, Class.new { def self.before_remove_const; end } Object.const_set :C, Class.new { def self.before_remove_const; end }
C.unloadable C.unloadable
assert_called(C, :before_remove_const, times: 1) do assert_called(C, :before_remove_const, times: 1) do
assert C.respond_to?(:before_remove_const) assert_respond_to C, :before_remove_const
ActiveSupport::Dependencies.clear ActiveSupport::Dependencies.clear
assert !defined?(C) assert !defined?(C)
end end

View File

@ -469,10 +469,10 @@ class MultibyteCharsUTF8BehaviourTest < ActiveSupport::TestCase
end end
def test_respond_to_knows_which_methods_the_proxy_responds_to def test_respond_to_knows_which_methods_the_proxy_responds_to
assert "".mb_chars.respond_to?(:slice) # Defined on Chars assert_respond_to "".mb_chars, :slice # Defined on Chars
assert "".mb_chars.respond_to?(:capitalize!) # Defined on Chars assert_respond_to "".mb_chars, :capitalize! # Defined on Chars
assert "".mb_chars.respond_to?(:gsub) # Defined on String assert_respond_to "".mb_chars, :gsub # Defined on String
assert !"".mb_chars.respond_to?(:undefined_method) # Not defined assert_not_respond_to "".mb_chars, :undefined_method # Not defined
end end
def test_method_works_for_proxyed_methods def test_method_works_for_proxyed_methods

View File

@ -82,8 +82,8 @@ class OrderedOptionsTest < ActiveSupport::TestCase
def test_introspection def test_introspection
a = ActiveSupport::OrderedOptions.new a = ActiveSupport::OrderedOptions.new
assert a.respond_to?(:blah) assert_respond_to a, :blah
assert a.respond_to?(:blah=) assert_respond_to a, :blah=
assert_equal 42, a.method(:blah=).call(42) assert_equal 42, a.method(:blah=).call(42)
assert_equal 42, a.method(:blah).call assert_equal 42, a.method(:blah).call
end end
@ -91,7 +91,7 @@ class OrderedOptionsTest < ActiveSupport::TestCase
def test_raises_with_bang def test_raises_with_bang
a = ActiveSupport::OrderedOptions.new a = ActiveSupport::OrderedOptions.new
a[:foo] = :bar a[:foo] = :bar
assert a.respond_to?(:foo!) assert_respond_to a, :foo!
assert_nothing_raised { a.foo! } assert_nothing_raised { a.foo! }
assert_equal a.foo, a.foo! assert_equal a.foo, a.foo!

View File

@ -21,7 +21,7 @@ class TaggedLoggingTest < ActiveSupport::TestCase
assert_nil logger.formatter assert_nil logger.formatter
ActiveSupport::TaggedLogging.new(logger) ActiveSupport::TaggedLogging.new(logger)
assert_not_nil logger.formatter assert_not_nil logger.formatter
assert logger.formatter.respond_to?(:tagged) assert_respond_to logger.formatter, :tagged
end end
test "tagged once" do test "tagged once" do

View File

@ -33,7 +33,7 @@ module ApplicationTests
assert_nil x.i_do_not_exist.zomg assert_nil x.i_do_not_exist.zomg
# test that custom configuration responds to all messages # test that custom configuration responds to all messages
assert_equal true, x.respond_to?(:i_do_not_exist) assert_respond_to x, :i_do_not_exist
assert_kind_of Method, x.method(:i_do_not_exist) assert_kind_of Method, x.method(:i_do_not_exist)
assert_kind_of ActiveSupport::OrderedOptions, x.i_do_not_exist assert_kind_of ActiveSupport::OrderedOptions, x.i_do_not_exist
end end

View File

@ -1478,7 +1478,7 @@ module ApplicationTests
test "respond_to? accepts include_private" do test "respond_to? accepts include_private" do
make_basic_app make_basic_app
assert_not Rails.configuration.respond_to?(:method_missing) assert_not_respond_to Rails.configuration, :method_missing
assert Rails.configuration.respond_to?(:method_missing, true) assert Rails.configuration.respond_to?(:method_missing, true)
end end

View File

@ -73,7 +73,7 @@ class ConsoleTest < ActiveSupport::TestCase
MODEL MODEL
load_environment load_environment
assert User.new.respond_to?(:name) assert_respond_to User.new, :name
app_file "app/models/user.rb", <<-MODEL app_file "app/models/user.rb", <<-MODEL
class User class User
@ -81,9 +81,9 @@ class ConsoleTest < ActiveSupport::TestCase
end end
MODEL MODEL
assert !User.new.respond_to?(:age) assert_not_respond_to User.new, :age
irb_context.reload!(false) irb_context.reload!(false)
assert User.new.respond_to?(:age) assert_respond_to User.new, :age
end end
def test_access_to_helpers def test_access_to_helpers