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

assert_equal takes expectation first

This commit is contained in:
Akira Matsuda 2016-12-26 11:04:41 +09:00
parent e813a9f860
commit a46b2f8911
18 changed files with 73 additions and 73 deletions

View file

@ -50,7 +50,7 @@ class ParamsWrapperTest < ActionController::TestCase
with_default_wrapper_options do
@request.env["CONTENT_TYPE"] = "application/json"
post :parse, params: { "username" => "sikachu" }
assert_equal @request.filtered_parameters, "controller" => "params_wrapper_test/users", "action" => "parse", "username" => "sikachu", "user" => { "username" => "sikachu" }
assert_equal({"controller" => "params_wrapper_test/users", "action" => "parse", "username" => "sikachu", "user" => { "username" => "sikachu" }}, @request.filtered_parameters)
end
end

View file

@ -17,8 +17,8 @@ class ActionController::TestRequestTest < ActionController::TestCase
@request.set_header "CONTENT_TYPE", "application/json"
@request.assign_parameters(@routes, "test", "create", non_ascii_parameters,
"/test", [:data, :controller, :action])
assert_equal(@request.get_header("CONTENT_LENGTH"),
StringIO.new(non_ascii_parameters.to_json).length.to_s)
assert_equal(StringIO.new(non_ascii_parameters.to_json).length.to_s,
@request.get_header("CONTENT_LENGTH"))
end
ActionDispatch::Session::AbstractStore::DEFAULT_OPTIONS.each_key do |option|

View file

@ -694,31 +694,31 @@ class FormTagHelperTest < ActionView::TestCase
def test_text_area_tag_options_symbolize_keys_side_effects
options = { option: "random_option" }
text_area_tag "body", "hello world", options
assert_equal options, option: "random_option"
assert_equal({option: "random_option"}, options)
end
def test_submit_tag_options_symbolize_keys_side_effects
options = { option: "random_option" }
submit_tag "submit value", options
assert_equal options, option: "random_option"
assert_equal({option: "random_option"}, options)
end
def test_button_tag_options_symbolize_keys_side_effects
options = { option: "random_option" }
button_tag "button value", options
assert_equal options, option: "random_option"
assert_equal({option: "random_option"}, options)
end
def test_image_submit_tag_options_symbolize_keys_side_effects
options = { option: "random_option" }
image_submit_tag "submit source", options
assert_equal options, option: "random_option"
assert_equal({option: "random_option"}, options)
end
def test_image_label_tag_options_symbolize_keys_side_effects
options = { option: "random_option" }
label_tag "submit source", "title", options
assert_equal options, option: "random_option"
assert_equal({option: "random_option"}, options)
end
def protect_against_forgery?

View file

@ -449,7 +449,7 @@ class CallbacksTest < ActiveRecord::TestCase
assert david.valid?
assert !david.save
exc = assert_raise(ActiveRecord::RecordNotSaved) { david.save! }
assert_equal exc.record, david
assert_equal david, exc.record
assert_equal "Failed to save the record", exc.message
end
@ -493,7 +493,7 @@ class CallbacksTest < ActiveRecord::TestCase
assert_deprecated do
assert !david.destroy
exc = assert_raise(ActiveRecord::RecordNotDestroyed) { david.destroy! }
assert_equal exc.record, david
assert_equal david, exc.record
assert_equal "Failed to destroy the record", exc.message
end
assert_not_nil ImmutableDeveloper.find_by_id(1)
@ -527,7 +527,7 @@ class CallbacksTest < ActiveRecord::TestCase
assert david.valid?
assert !david.save
exc = assert_raise(ActiveRecord::RecordNotSaved) { david.save! }
assert_equal exc.record, david
assert_equal david, exc.record
david = DeveloperWithCanceledCallbacks.find(1)
david.salary = 10_000_000
@ -554,7 +554,7 @@ class CallbacksTest < ActiveRecord::TestCase
david = DeveloperWithCanceledCallbacks.find(1)
assert !david.destroy
exc = assert_raise(ActiveRecord::RecordNotDestroyed) { david.destroy! }
assert_equal exc.record, david
assert_equal david, exc.record
assert_not_nil ImmutableDeveloper.find_by_id(1)
someone = CallbackHaltedDeveloper.find(1)

View file

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

View file

@ -79,7 +79,7 @@ module ActiveRecord
expected = Post.where("id = 1 or id = 2").to_a
p = Post.where("id = 1")
p.load
assert_equal p.loaded?, true
assert_equal true, p.loaded?
assert_equal expected, p.or(Post.where("id = 2")).to_a
end

View file

@ -27,6 +27,6 @@ class SecureTokenTest < ActiveRecord::TestCase
@user.token = "custom-secure-token"
@user.save
assert_equal @user.token, "custom-secure-token"
assert_equal "custom-secure-token", @user.token
end
end

View file

@ -185,14 +185,14 @@ class SerializedAttributeTest < ActiveRecord::TestCase
topic = Topic.new(content: true)
assert topic.save
topic = topic.reload
assert_equal topic.content, true
assert_equal true, topic.content
end
def test_serialized_boolean_value_false
topic = Topic.new(content: false)
assert topic.save
topic = topic.reload
assert_equal topic.content, false
assert_equal false, topic.content
end
def test_serialize_with_coder
@ -211,7 +211,7 @@ class SerializedAttributeTest < ActiveRecord::TestCase
topic.save!
topic.reload
assert_kind_of some_class, topic.content
assert_equal topic.content, some_class.new("my value")
assert_equal some_class.new("my value"), topic.content
end
def test_serialize_attribute_via_select_method_when_time_zone_available

View file

@ -59,7 +59,7 @@ if current_adapter?(:Mysql2Adapter)
def test_when_database_created_successfully_outputs_info_to_stdout
ActiveRecord::Tasks::DatabaseTasks.create @configuration
assert_equal $stdout.string, "Created database 'my-app-db'\n"
assert_equal "Created database 'my-app-db'\n", $stdout.string
end
def test_create_when_database_exists_outputs_info_to_stderr
@ -69,7 +69,7 @@ if current_adapter?(:Mysql2Adapter)
ActiveRecord::Tasks::DatabaseTasks.create @configuration
assert_equal $stderr.string, "Database 'my-app-db' already exists\n"
assert_equal "Database 'my-app-db' already exists\n", $stderr.string
end
end
@ -205,7 +205,7 @@ if current_adapter?(:Mysql2Adapter)
def test_when_database_dropped_successfully_outputs_info_to_stdout
ActiveRecord::Tasks::DatabaseTasks.drop @configuration
assert_equal $stdout.string, "Dropped database 'my-app-db'\n"
assert_equal "Dropped database 'my-app-db'\n", $stdout.string
end
end

View file

@ -74,7 +74,7 @@ if current_adapter?(:PostgreSQLAdapter)
def test_when_database_created_successfully_outputs_info_to_stdout
ActiveRecord::Tasks::DatabaseTasks.create @configuration
assert_equal $stdout.string, "Created database 'my-app-db'\n"
assert_equal "Created database 'my-app-db'\n", $stdout.string
end
def test_create_when_database_exists_outputs_info_to_stderr
@ -84,7 +84,7 @@ if current_adapter?(:PostgreSQLAdapter)
ActiveRecord::Tasks::DatabaseTasks.create @configuration
assert_equal $stderr.string, "Database 'my-app-db' already exists\n"
assert_equal "Database 'my-app-db' already exists\n", $stderr.string
end
end
@ -126,7 +126,7 @@ if current_adapter?(:PostgreSQLAdapter)
def test_when_database_dropped_successfully_outputs_info_to_stdout
ActiveRecord::Tasks::DatabaseTasks.drop @configuration
assert_equal $stdout.string, "Dropped database 'my-app-db'\n"
assert_equal "Dropped database 'my-app-db'\n", $stdout.string
end
end

View file

@ -34,7 +34,7 @@ if current_adapter?(:SQLite3Adapter)
def test_when_db_created_successfully_outputs_info_to_stdout
ActiveRecord::Tasks::DatabaseTasks.create @configuration, "/rails/root"
assert_equal $stdout.string, "Created database '#{@database}'\n"
assert_equal "Created database '#{@database}'\n", $stdout.string
end
def test_db_create_when_file_exists
@ -42,7 +42,7 @@ if current_adapter?(:SQLite3Adapter)
ActiveRecord::Tasks::DatabaseTasks.create @configuration, "/rails/root"
assert_equal $stderr.string, "Database '#{@database}' already exists\n"
assert_equal "Database '#{@database}' already exists\n", $stderr.string
end
def test_db_create_with_file_does_nothing
@ -128,7 +128,7 @@ if current_adapter?(:SQLite3Adapter)
def test_when_db_dropped_successfully_outputs_info_to_stdout
ActiveRecord::Tasks::DatabaseTasks.drop @configuration, "/rails/root"
assert_equal $stdout.string, "Dropped database '#{@database}'\n"
assert_equal "Dropped database '#{@database}'\n", $stdout.string
end
end

View file

@ -196,7 +196,7 @@ class DurationTest < ActiveSupport::TestCase
assert_nothing_raised do
1.minute.times { counter += 1 }
end
assert_equal counter, 60
assert_equal 60, counter
end
def test_as_json
@ -213,7 +213,7 @@ class DurationTest < ActiveSupport::TestCase
when 1.day
"ok"
end
assert_equal cased, "ok"
assert_equal "ok", cased
end
def test_respond_to

View file

@ -111,7 +111,7 @@ class HashExtTest < ActiveSupport::TestCase
transformed_hash = @mixed.dup
transformed_hash.transform_keys! { |key| key.to_s.upcase }
assert_equal @upcase_strings, transformed_hash
assert_equal @mixed, :a => 1, "b" => 2
assert_equal({ :a => 1, "b" => 2 }, @mixed)
end
def test_deep_transform_keys!
@ -127,7 +127,7 @@ class HashExtTest < ActiveSupport::TestCase
transformed_hash = @nested_mixed.deep_dup
transformed_hash.deep_transform_keys! { |key| key.to_s.upcase }
assert_equal @nested_upcase_strings, transformed_hash
assert_equal @nested_mixed, "a" => { b: { "c" => 3 } }
assert_equal({"a" => { b: { "c" => 3 } } }, @nested_mixed)
end
def test_symbolize_keys
@ -167,7 +167,7 @@ class HashExtTest < ActiveSupport::TestCase
transformed_hash = @mixed.dup
transformed_hash.deep_symbolize_keys!
assert_equal @symbols, transformed_hash
assert_equal @mixed, :a => 1, "b" => 2
assert_equal({ :a => 1, "b" => 2 }, @mixed)
end
def test_deep_symbolize_keys!
@ -183,7 +183,7 @@ class HashExtTest < ActiveSupport::TestCase
transformed_hash = @nested_mixed.deep_dup
transformed_hash.deep_symbolize_keys!
assert_equal @nested_symbols, transformed_hash
assert_equal @nested_mixed, "a" => { b: { "c" => 3 } }
assert_equal({ "a" => { b: { "c" => 3 } } }, @nested_mixed)
end
def test_symbolize_keys_preserves_keys_that_cant_be_symbolized
@ -243,7 +243,7 @@ class HashExtTest < ActiveSupport::TestCase
transformed_hash = @mixed.dup
transformed_hash.stringify_keys!
assert_equal @strings, transformed_hash
assert_equal @mixed, :a => 1, "b" => 2
assert_equal({ :a => 1, "b" => 2 }, @mixed)
end
def test_deep_stringify_keys!
@ -259,7 +259,7 @@ class HashExtTest < ActiveSupport::TestCase
transformed_hash = @nested_mixed.deep_dup
transformed_hash.deep_stringify_keys!
assert_equal @nested_strings, transformed_hash
assert_equal @nested_mixed, "a" => { b: { "c" => 3 } }
assert_equal({ "a" => { b: { "c" => 3 } } }, @nested_mixed)
end
def test_symbolize_keys_for_hash_with_indifferent_access
@ -414,11 +414,11 @@ class HashExtTest < ActiveSupport::TestCase
hash["b"] = 2
hash[3] = 3
assert_equal hash["a"], 1
assert_equal hash["b"], 2
assert_equal hash[:a], 1
assert_equal hash[:b], 2
assert_equal hash[3], 3
assert_equal 1, hash["a"]
assert_equal 2, hash["b"]
assert_equal 1, hash[:a]
assert_equal 2, hash[:b]
assert_equal 3, hash[3]
end
def test_indifferent_update
@ -430,16 +430,16 @@ class HashExtTest < ActiveSupport::TestCase
updated_with_symbols = hash.update(@symbols)
updated_with_mixed = hash.update(@mixed)
assert_equal updated_with_strings[:a], 1
assert_equal updated_with_strings["a"], 1
assert_equal updated_with_strings["b"], 2
assert_equal 1, updated_with_strings[:a]
assert_equal 1, updated_with_strings["a"]
assert_equal 2, updated_with_strings["b"]
assert_equal updated_with_symbols[:a], 1
assert_equal updated_with_symbols["b"], 2
assert_equal updated_with_symbols[:b], 2
assert_equal 1, updated_with_symbols[:a]
assert_equal 2, updated_with_symbols["b"]
assert_equal 2, updated_with_symbols[:b]
assert_equal updated_with_mixed[:a], 1
assert_equal updated_with_mixed["b"], 2
assert_equal 1, updated_with_mixed[:a]
assert_equal 2, updated_with_mixed["b"]
assert [updated_with_strings, updated_with_symbols, updated_with_mixed].all? { |h| h.keys.size == 2 }
end
@ -447,7 +447,7 @@ class HashExtTest < ActiveSupport::TestCase
def test_update_with_to_hash_conversion
hash = HashWithIndifferentAccess.new
hash.update HashByConversion.new(a: 1)
assert_equal hash["a"], 1
assert_equal 1, hash["a"]
end
def test_indifferent_merging
@ -472,7 +472,7 @@ class HashExtTest < ActiveSupport::TestCase
def test_merge_with_to_hash_conversion
hash = HashWithIndifferentAccess.new
merged = hash.merge HashByConversion.new(a: 1)
assert_equal merged["a"], 1
assert_equal 1, merged["a"]
end
def test_indifferent_replace

View file

@ -121,11 +121,11 @@ class ModuleAttributeAccessorPerThreadTest < ActiveSupport::TestCase
def test_should_not_affect_superclass_if_subclass_set_value
@class.foo = "super"
assert_equal @class.foo, "super"
assert_equal "super", @class.foo
assert_nil @subclass.foo
@subclass.foo = "sub"
assert_equal @class.foo, "super"
assert_equal @subclass.foo, "sub"
assert_equal "super", @class.foo
assert_equal "sub", @subclass.foo
end
end

View file

@ -210,21 +210,21 @@ class ModuleTest < ActiveSupport::TestCase
def test_delegation_prefix
invoice = Invoice.new(@david)
assert_equal invoice.client_name, "David"
assert_equal invoice.client_street, "Paulina"
assert_equal invoice.client_city, "Chicago"
assert_equal "David", invoice.client_name
assert_equal "Paulina", invoice.client_street
assert_equal "Chicago", invoice.client_city
end
def test_delegation_custom_prefix
invoice = Invoice.new(@david)
assert_equal invoice.customer_name, "David"
assert_equal invoice.customer_street, "Paulina"
assert_equal invoice.customer_city, "Chicago"
assert_equal "David", invoice.customer_name
assert_equal "Paulina", invoice.customer_street
assert_equal "Chicago", invoice.customer_city
end
def test_delegation_prefix_with_nil_or_false
assert_equal Developer.new(@david).name, "David"
assert_equal Tester.new(@david).name, "David"
assert_equal "David", Developer.new(@david).name
assert_equal "David", Tester.new(@david).name
end
def test_delegation_prefix_with_instance_variable
@ -240,7 +240,7 @@ class ModuleTest < ActiveSupport::TestCase
def test_delegation_with_allow_nil
rails = Project.new("Rails", Someone.new("David"))
assert_equal rails.name, "David"
assert_equal "David", rails.name
end
def test_delegation_with_allow_nil_and_nil_value

View file

@ -152,37 +152,37 @@ class StringInflectionsTest < ActiveSupport::TestCase
def test_string_parameterized_normal
StringToParameterized.each do |normal, slugged|
assert_equal(normal.parameterize, slugged)
assert_equal(slugged, normal.parameterize)
end
end
def test_string_parameterized_normal_preserve_case
StringToParameterizedPreserveCase.each do |normal, slugged|
assert_equal(normal.parameterize(preserve_case: true), slugged)
assert_equal(slugged, normal.parameterize(preserve_case: true))
end
end
def test_string_parameterized_no_separator
StringToParameterizeWithNoSeparator.each do |normal, slugged|
assert_equal(normal.parameterize(separator: ""), slugged)
assert_equal(slugged, normal.parameterize(separator: ""))
end
end
def test_string_parameterized_no_separator_preserve_case
StringToParameterizePreserveCaseWithNoSeparator.each do |normal, slugged|
assert_equal(normal.parameterize(separator: "", preserve_case: true), slugged)
assert_equal(slugged, normal.parameterize(separator: "", preserve_case: true))
end
end
def test_string_parameterized_underscore
StringToParameterizeWithUnderscore.each do |normal, slugged|
assert_equal(normal.parameterize(separator: "_"), slugged)
assert_equal(slugged, normal.parameterize(separator: "_"))
end
end
def test_string_parameterized_underscore_preserve_case
StringToParameterizePreserceCaseWithUnderscore.each do |normal, slugged|
assert_equal(normal.parameterize(separator: "_", preserve_case: true), slugged)
assert_equal(slugged, normal.parameterize(separator: "_", preserve_case: true))
end
end
@ -283,7 +283,7 @@ class StringInflectionsTest < ActiveSupport::TestCase
def test_truncate_words_with_complex_string
Timeout.timeout(10) do
complex_string = "aa aa aaa aa aaa aaa aaa aa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaaa aaaaa aaaaa aaaaaa aa aa aa aaa aa aaa aa aa aa aa a aaa aaa \n a aaa <<s"
assert_equal complex_string.truncate_words(80), complex_string
assert_equal complex_string, complex_string.truncate_words(80)
end
rescue Timeout::Error
assert false
@ -710,14 +710,14 @@ class OutputSafetyTest < ActiveSupport::TestCase
test "Prepending safe onto unsafe yields unsafe" do
@string.prepend "other".html_safe
assert !@string.html_safe?
assert_equal @string, "otherhello"
assert_equal "otherhello", @string
end
test "Prepending unsafe onto safe yields escaped safe" do
other = "other".html_safe
other.prepend "<foo>"
assert other.html_safe?
assert_equal other, "&lt;foo&gt;other"
assert_equal "&lt;foo&gt;other", other
end
test "Concatting safe onto unsafe yields unsafe" do

View file

@ -80,6 +80,6 @@ class MessageVerifierTest < ActiveSupport::TestCase
exception = assert_raise(ArgumentError) do
ActiveSupport::MessageVerifier.new(nil)
end
assert_equal exception.message, "Secret should not be nil."
assert_equal "Secret should not be nil.", exception.message
end
end

View file

@ -890,7 +890,7 @@ YAML
boot_rails
assert_equal AppTemplate.railtie_namespace, AppTemplate::Engine
assert_equal AppTemplate::Engine, AppTemplate.railtie_namespace
end
test "properly reload routes" do