提交 b86e313d 编写于 作者: P Pat Allan

Make ActiveRecord frozen string literal friendly.

上级 4ff30d9b
...@@ -197,8 +197,7 @@ def construct_tables!(parent, node) ...@@ -197,8 +197,7 @@ def construct_tables!(parent, node)
def table_alias_for(reflection, parent, join) def table_alias_for(reflection, parent, join)
name = "#{reflection.plural_name}_#{parent.table_name}" name = "#{reflection.plural_name}_#{parent.table_name}"
name << "_join" if join join ? "#{name}_join" : name
name
end end
def walk(left, right) def walk(left, right)
......
...@@ -679,7 +679,7 @@ def checkout_for_exclusive_access(checkout_timeout) ...@@ -679,7 +679,7 @@ def checkout_for_exclusive_access(checkout_timeout)
# this block can't be easily moved into attempt_to_checkout_all_existing_connections's # this block can't be easily moved into attempt_to_checkout_all_existing_connections's
# rescue block, because doing so would put it outside of synchronize section, without # rescue block, because doing so would put it outside of synchronize section, without
# being in a critical section thread_report might become inaccurate # being in a critical section thread_report might become inaccurate
msg = "could not obtain ownership of all database connections in #{checkout_timeout} seconds" msg = "could not obtain ownership of all database connections in #{checkout_timeout} seconds".dup
thread_report = [] thread_report = []
@connections.each do |conn| @connections.each do |conn|
......
...@@ -22,7 +22,7 @@ def accept(o) ...@@ -22,7 +22,7 @@ def accept(o)
private private
def visit_AlterTable(o) def visit_AlterTable(o)
sql = "ALTER TABLE #{quote_table_name(o.name)} " sql = "ALTER TABLE #{quote_table_name(o.name)} ".dup
sql << o.adds.map { |col| accept col }.join(" ") sql << o.adds.map { |col| accept col }.join(" ")
sql << o.foreign_key_adds.map { |fk| visit_AddForeignKey fk }.join(" ") sql << o.foreign_key_adds.map { |fk| visit_AddForeignKey fk }.join(" ")
sql << o.foreign_key_drops.map { |fk| visit_DropForeignKey fk }.join(" ") sql << o.foreign_key_drops.map { |fk| visit_DropForeignKey fk }.join(" ")
...@@ -30,17 +30,17 @@ def visit_AlterTable(o) ...@@ -30,17 +30,17 @@ def visit_AlterTable(o)
def visit_ColumnDefinition(o) def visit_ColumnDefinition(o)
o.sql_type = type_to_sql(o.type, o.options) o.sql_type = type_to_sql(o.type, o.options)
column_sql = "#{quote_column_name(o.name)} #{o.sql_type}" column_sql = "#{quote_column_name(o.name)} #{o.sql_type}".dup
add_column_options!(column_sql, column_options(o)) unless o.type == :primary_key add_column_options!(column_sql, column_options(o)) unless o.type == :primary_key
column_sql column_sql
end end
def visit_AddColumnDefinition(o) def visit_AddColumnDefinition(o)
"ADD #{accept(o.column)}" "ADD #{accept(o.column)}".dup
end end
def visit_TableDefinition(o) def visit_TableDefinition(o)
create_sql = "CREATE#{' TEMPORARY' if o.temporary} TABLE #{quote_table_name(o.name)} " create_sql = "CREATE#{' TEMPORARY' if o.temporary} TABLE #{quote_table_name(o.name)} ".dup
statements = o.columns.map { |c| accept c } statements = o.columns.map { |c| accept c }
statements << accept(o.primary_keys) if o.primary_keys statements << accept(o.primary_keys) if o.primary_keys
......
...@@ -1348,7 +1348,7 @@ def insert_versions_sql(versions) ...@@ -1348,7 +1348,7 @@ def insert_versions_sql(versions)
sm_table = quote_table_name(ActiveRecord::SchemaMigration.table_name) sm_table = quote_table_name(ActiveRecord::SchemaMigration.table_name)
if versions.is_a?(Array) if versions.is_a?(Array)
sql = "INSERT INTO #{sm_table} (version) VALUES\n" sql = "INSERT INTO #{sm_table} (version) VALUES\n".dup
sql << versions.map { |v| "(#{quote(v)})" }.join(",\n") sql << versions.map { |v| "(#{quote(v)})" }.join(",\n")
sql << ";\n\n" sql << ";\n\n"
sql sql
......
...@@ -147,7 +147,7 @@ def valid_type?(type) # :nodoc: ...@@ -147,7 +147,7 @@ def valid_type?(type) # :nodoc:
# this method must only be called while holding connection pool's mutex # this method must only be called while holding connection pool's mutex
def lease def lease
if in_use? if in_use?
msg = "Cannot lease connection, " msg = "Cannot lease connection, ".dup
if @owner == Thread.current if @owner == Thread.current
msg << "it is already leased by the current thread." msg << "it is already leased by the current thread."
else else
......
...@@ -132,7 +132,7 @@ def native_database_types ...@@ -132,7 +132,7 @@ def native_database_types
end end
def index_algorithms def index_algorithms
{ default: "ALGORITHM = DEFAULT", copy: "ALGORITHM = COPY", inplace: "ALGORITHM = INPLACE" } { default: "ALGORITHM = DEFAULT".dup, copy: "ALGORITHM = COPY".dup, inplace: "ALGORITHM = INPLACE".dup }
end end
# HELPER METHODS =========================================== # HELPER METHODS ===========================================
...@@ -379,7 +379,7 @@ def rename_column(table_name, column_name, new_column_name) #:nodoc: ...@@ -379,7 +379,7 @@ def rename_column(table_name, column_name, new_column_name) #:nodoc:
def add_index(table_name, column_name, options = {}) #:nodoc: def add_index(table_name, column_name, options = {}) #:nodoc:
index_name, index_type, index_columns, _, index_algorithm, index_using, comment = add_index_options(table_name, column_name, options) index_name, index_type, index_columns, _, index_algorithm, index_using, comment = add_index_options(table_name, column_name, options)
sql = "CREATE #{index_type} INDEX #{quote_column_name(index_name)} #{index_using} ON #{quote_table_name(table_name)} (#{index_columns}) #{index_algorithm}" sql = "CREATE #{index_type} INDEX #{quote_column_name(index_name)} #{index_using} ON #{quote_table_name(table_name)} (#{index_columns}) #{index_algorithm}".dup
execute add_sql_comment!(sql, comment) execute add_sql_comment!(sql, comment)
end end
...@@ -464,7 +464,7 @@ def type_to_sql(type, limit: nil, precision: nil, scale: nil, unsigned: nil, **) ...@@ -464,7 +464,7 @@ def type_to_sql(type, limit: nil, precision: nil, scale: nil, unsigned: nil, **)
super super
end end
sql << " unsigned" if unsigned && type != :primary_key sql = "#{sql} unsigned" if unsigned && type != :primary_key
sql sql
end end
...@@ -761,7 +761,7 @@ def configure_connection ...@@ -761,7 +761,7 @@ def configure_connection
# http://dev.mysql.com/doc/refman/5.7/en/set-statement.html#id944430 # http://dev.mysql.com/doc/refman/5.7/en/set-statement.html#id944430
# (trailing comma because variable_assignments will always have content) # (trailing comma because variable_assignments will always have content)
if @config[:encoding] if @config[:encoding]
encoding = "NAMES #{@config[:encoding]}" encoding = "NAMES #{@config[:encoding]}".dup
encoding << " COLLATE #{@config[:collation]}" if @config[:collation] encoding << " COLLATE #{@config[:collation]}" if @config[:collation]
encoding << ", " encoding << ", "
end end
......
...@@ -16,7 +16,7 @@ def visit_AddColumnDefinition(o) ...@@ -16,7 +16,7 @@ def visit_AddColumnDefinition(o)
end end
def visit_ChangeColumnDefinition(o) def visit_ChangeColumnDefinition(o)
change_column_sql = "CHANGE #{quote_column_name(o.name)} #{accept(o.column)}" change_column_sql = "CHANGE #{quote_column_name(o.name)} #{accept(o.column)}".dup
add_column_position!(change_column_sql, column_options(o.column)) add_column_position!(change_column_sql, column_options(o.column))
end end
...@@ -63,7 +63,7 @@ def add_column_position!(sql, options) ...@@ -63,7 +63,7 @@ def add_column_position!(sql, options)
def index_in_create(table_name, column_name, options) def index_in_create(table_name, column_name, options)
index_name, index_type, index_columns, _, _, index_using, comment = @conn.add_index_options(table_name, column_name, options) index_name, index_type, index_columns, _, _, index_using, comment = @conn.add_index_options(table_name, column_name, options)
add_sql_comment!("#{index_type} INDEX #{quote_column_name(index_name)} #{index_using} (#{index_columns})", comment) add_sql_comment!("#{index_type} INDEX #{quote_column_name(index_name)} #{index_using} (#{index_columns})".dup, comment)
end end
end end
end end
......
...@@ -102,7 +102,7 @@ def extract_foreign_key_action(specifier) ...@@ -102,7 +102,7 @@ def extract_foreign_key_action(specifier)
def data_source_sql(name = nil, type: nil) def data_source_sql(name = nil, type: nil)
scope = quoted_scope(name, type: type) scope = quoted_scope(name, type: type)
sql = "SELECT table_name FROM information_schema.tables" sql = "SELECT table_name FROM information_schema.tables".dup
sql << " WHERE table_schema = #{scope[:schema]}" sql << " WHERE table_schema = #{scope[:schema]}"
sql << " AND table_name = #{scope[:name]}" if scope[:name] sql << " AND table_name = #{scope[:name]}" if scope[:name]
sql << " AND table_type = #{scope[:type]}" if scope[:type] sql << " AND table_type = #{scope[:type]}" if scope[:type]
......
...@@ -408,7 +408,7 @@ def change_column(table_name, column_name, type, options = {}) #:nodoc: ...@@ -408,7 +408,7 @@ def change_column(table_name, column_name, type, options = {}) #:nodoc:
quoted_table_name = quote_table_name(table_name) quoted_table_name = quote_table_name(table_name)
quoted_column_name = quote_column_name(column_name) quoted_column_name = quote_column_name(column_name)
sql_type = type_to_sql(type, options) sql_type = type_to_sql(type, options)
sql = "ALTER TABLE #{quoted_table_name} ALTER COLUMN #{quoted_column_name} TYPE #{sql_type}" sql = "ALTER TABLE #{quoted_table_name} ALTER COLUMN #{quoted_column_name} TYPE #{sql_type}".dup
if options[:collation] if options[:collation]
sql << " COLLATE \"#{options[:collation]}\"" sql << " COLLATE \"#{options[:collation]}\""
end end
...@@ -568,7 +568,7 @@ def type_to_sql(type, limit: nil, precision: nil, scale: nil, array: nil, **) # ...@@ -568,7 +568,7 @@ def type_to_sql(type, limit: nil, precision: nil, scale: nil, array: nil, **) #
super super
end end
sql << "[]" if array && type != :primary_key sql = "#{sql}[]" if array && type != :primary_key
sql sql
end end
...@@ -637,7 +637,7 @@ def data_source_sql(name = nil, type: nil) ...@@ -637,7 +637,7 @@ def data_source_sql(name = nil, type: nil)
scope = quoted_scope(name, type: type) scope = quoted_scope(name, type: type)
scope[:type] ||= "'r','v','m'" # (r)elation/table, (v)iew, (m)aterialized view scope[:type] ||= "'r','v','m'" # (r)elation/table, (v)iew, (m)aterialized view
sql = "SELECT c.relname FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = c.relnamespace" sql = "SELECT c.relname FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = c.relnamespace".dup
sql << " WHERE n.nspname = #{scope[:schema]}" sql << " WHERE n.nspname = #{scope[:schema]}"
sql << " AND c.relname = #{scope[:name]}" if scope[:name] sql << " AND c.relname = #{scope[:name]}" if scope[:name]
sql << " AND c.relkind IN (#{scope[:type]})" sql << " AND c.relkind IN (#{scope[:type]})"
......
...@@ -67,7 +67,7 @@ def data_source_sql(name = nil, type: nil) ...@@ -67,7 +67,7 @@ def data_source_sql(name = nil, type: nil)
scope = quoted_scope(name, type: type) scope = quoted_scope(name, type: type)
scope[:type] ||= "'table','view'" scope[:type] ||= "'table','view'"
sql = "SELECT name FROM sqlite_master WHERE name <> 'sqlite_sequence'" sql = "SELECT name FROM sqlite_master WHERE name <> 'sqlite_sequence'".dup
sql << " AND name = #{scope[:name]}" if scope[:name] sql << " AND name = #{scope[:name]}" if scope[:name]
sql << " AND type IN (#{scope[:type]})" sql << " AND type IN (#{scope[:type]})"
sql sql
......
...@@ -16,7 +16,7 @@ def collecting_queries_for_explain # :nodoc: ...@@ -16,7 +16,7 @@ def collecting_queries_for_explain # :nodoc:
# Returns a formatted string ready to be logged. # Returns a formatted string ready to be logged.
def exec_explain(queries) # :nodoc: def exec_explain(queries) # :nodoc:
str = queries.map do |sql, binds| str = queries.map do |sql, binds|
msg = "EXPLAIN for: #{sql}" msg = "EXPLAIN for: #{sql}".dup
unless binds.empty? unless binds.empty?
msg << " " msg << " "
msg << binds.map { |attr| render_bind(attr) }.inspect msg << binds.map { |attr| render_bind(attr) }.inspect
......
...@@ -157,7 +157,7 @@ def initialize ...@@ -157,7 +157,7 @@ def initialize
class ProtectedEnvironmentError < ActiveRecordError #:nodoc: class ProtectedEnvironmentError < ActiveRecordError #:nodoc:
def initialize(env = "production") def initialize(env = "production")
msg = "You are attempting to run a destructive action against your '#{env}' database.\n" msg = "You are attempting to run a destructive action against your '#{env}' database.\n".dup
msg << "If you are sure you want to continue, run the same command with the environment variable:\n" msg << "If you are sure you want to continue, run the same command with the environment variable:\n"
msg << "DISABLE_DATABASE_ENVIRONMENT_CHECK=1" msg << "DISABLE_DATABASE_ENVIRONMENT_CHECK=1"
super(msg) super(msg)
...@@ -166,7 +166,7 @@ def initialize(env = "production") ...@@ -166,7 +166,7 @@ def initialize(env = "production")
class EnvironmentMismatchError < ActiveRecordError class EnvironmentMismatchError < ActiveRecordError
def initialize(current: nil, stored: nil) def initialize(current: nil, stored: nil)
msg = "You are attempting to modify a database that was last run in `#{ stored }` environment.\n" msg = "You are attempting to modify a database that was last run in `#{ stored }` environment.\n".dup
msg << "You are running in `#{ current }` environment. " msg << "You are running in `#{ current }` environment. "
msg << "If you are sure you want to continue, first set the environment using:\n\n" msg << "If you are sure you want to continue, first set the environment using:\n\n"
msg << " bin/rails db:environment:set" msg << " bin/rails db:environment:set"
...@@ -1239,7 +1239,7 @@ def execute_migration_in_transaction(migration, direction) ...@@ -1239,7 +1239,7 @@ def execute_migration_in_transaction(migration, direction)
record_version_state_after_migrating(migration.version) record_version_state_after_migrating(migration.version)
end end
rescue => e rescue => e
msg = "An error has occurred, " msg = "An error has occurred, ".dup
msg << "this and " if use_transaction?(migration) msg << "this and " if use_transaction?(migration)
msg << "all later migrations canceled:\n\n#{e}" msg << "all later migrations canceled:\n\n#{e}"
raise StandardError, msg, e.backtrace raise StandardError, msg, e.backtrace
......
...@@ -335,14 +335,14 @@ def raise_record_not_found_exception!(ids = nil, result_size = nil, expected_siz ...@@ -335,14 +335,14 @@ def raise_record_not_found_exception!(ids = nil, result_size = nil, expected_siz
name = @klass.name name = @klass.name
if ids.nil? if ids.nil?
error = "Couldn't find #{name}" error = "Couldn't find #{name}".dup
error << " with#{conditions}" if conditions error << " with#{conditions}" if conditions
raise RecordNotFound.new(error, name) raise RecordNotFound.new(error, name)
elsif Array(ids).size == 1 elsif Array(ids).size == 1
error = "Couldn't find #{name} with '#{key}'=#{ids}#{conditions}" error = "Couldn't find #{name} with '#{key}'=#{ids}#{conditions}"
raise RecordNotFound.new(error, name, key, ids) raise RecordNotFound.new(error, name, key, ids)
else else
error = "Couldn't find all #{name.pluralize} with '#{key}': " error = "Couldn't find all #{name.pluralize} with '#{key}': ".dup
error << "(#{ids.join(", ")})#{conditions} (found #{result_size} results, but was looking for #{expected_size})" error << "(#{ids.join(", ")})#{conditions} (found #{result_size} results, but was looking for #{expected_size})"
raise RecordNotFound.new(error, name, primary_key, ids) raise RecordNotFound.new(error, name, primary_key, ids)
......
...@@ -151,7 +151,7 @@ def run_cmd(cmd, args, action) ...@@ -151,7 +151,7 @@ def run_cmd(cmd, args, action)
end end
def run_cmd_error(cmd, args, action) def run_cmd_error(cmd, args, action)
msg = "failed to execute: `#{cmd}`\n" msg = "failed to execute: `#{cmd}`\n".dup
msg << "Please check the output above for any errors and make sure that `#{cmd}` is installed in your PATH and has proper permissions.\n\n" msg << "Please check the output above for any errors and make sure that `#{cmd}` is installed in your PATH and has proper permissions.\n\n"
msg msg
end end
......
...@@ -47,7 +47,7 @@ def test_type_cast_binary_converts_the_encoding ...@@ -47,7 +47,7 @@ def test_type_cast_binary_converts_the_encoding
end end
def test_type_cast_binary_value def test_type_cast_binary_value
data = "\u001F\x8B".force_encoding("BINARY") data = "\u001F\x8B".dup.force_encoding("BINARY")
assert_equal(data, @type.deserialize(data)) assert_equal(data, @type.deserialize(data))
end end
......
...@@ -47,10 +47,10 @@ def test_money_values ...@@ -47,10 +47,10 @@ def test_money_values
def test_money_type_cast def test_money_type_cast
type = PostgresqlMoney.type_for_attribute("wealth") type = PostgresqlMoney.type_for_attribute("wealth")
assert_equal(12345678.12, type.cast("$12,345,678.12")) assert_equal(12345678.12, type.cast("$12,345,678.12".dup))
assert_equal(12345678.12, type.cast("$12.345.678,12")) assert_equal(12345678.12, type.cast("$12.345.678,12".dup))
assert_equal(-1.15, type.cast("-$1.15")) assert_equal(-1.15, type.cast("-$1.15".dup))
assert_equal(-2.25, type.cast("($2.25)")) assert_equal(-2.25, type.cast("($2.25)".dup))
end end
def test_schema_dumping def test_schema_dumping
...@@ -60,7 +60,7 @@ def test_schema_dumping ...@@ -60,7 +60,7 @@ def test_schema_dumping
end end
def test_create_and_update_money def test_create_and_update_money
money = PostgresqlMoney.create(wealth: "987.65") money = PostgresqlMoney.create(wealth: "987.65".dup)
assert_equal 987.65, money.wealth assert_equal 987.65, money.wealth
new_value = BigDecimal.new("123.45") new_value = BigDecimal.new("123.45")
......
...@@ -165,7 +165,7 @@ def test_quote_binary_column_escapes_it ...@@ -165,7 +165,7 @@ def test_quote_binary_column_escapes_it
data binary data binary
) )
eosql eosql
str = "\x80".force_encoding("ASCII-8BIT") str = "\x80".dup.force_encoding("ASCII-8BIT")
binary = DualEncoding.new name: "いただきます!", data: str binary = DualEncoding.new name: "いただきます!", data: str
binary.save! binary.save!
assert_equal str, binary.data assert_equal str, binary.data
...@@ -174,7 +174,7 @@ def test_quote_binary_column_escapes_it ...@@ -174,7 +174,7 @@ def test_quote_binary_column_escapes_it
end end
def test_type_cast_should_not_mutate_encoding def test_type_cast_should_not_mutate_encoding
name = "hello".force_encoding(Encoding::ASCII_8BIT) name = "hello".dup.force_encoding(Encoding::ASCII_8BIT)
Owner.create(name: name) Owner.create(name: name)
assert_equal Encoding::ASCII_8BIT, name.encoding assert_equal Encoding::ASCII_8BIT, name.encoding
ensure ensure
......
...@@ -76,7 +76,7 @@ class AttributeTest < ActiveRecord::TestCase ...@@ -76,7 +76,7 @@ class AttributeTest < ActiveRecord::TestCase
end end
test "duping dups the value" do test "duping dups the value" do
@type.expect(:deserialize, "type cast", ["a value"]) @type.expect(:deserialize, "type cast".dup, ["a value"])
attribute = Attribute.from_database(nil, "a value", @type) attribute = Attribute.from_database(nil, "a value", @type)
value_from_orig = attribute.value value_from_orig = attribute.value
...@@ -244,7 +244,7 @@ def assert_valid_value(*) ...@@ -244,7 +244,7 @@ def assert_valid_value(*)
end end
test "with_type preserves mutations" do test "with_type preserves mutations" do
attribute = Attribute.from_database(:foo, "", Type::Value.new) attribute = Attribute.from_database(:foo, "".dup, Type::Value.new)
attribute.value << "1" attribute.value << "1"
assert_equal 1, attribute.with_type(Type::Integer.new).value assert_equal 1, attribute.with_type(Type::Integer.new).value
......
...@@ -152,7 +152,7 @@ def test_find_in_batches_should_quote_batch_order ...@@ -152,7 +152,7 @@ def test_find_in_batches_should_quote_batch_order
end end
def test_find_in_batches_should_not_use_records_after_yielding_them_in_case_original_array_is_modified def test_find_in_batches_should_not_use_records_after_yielding_them_in_case_original_array_is_modified
not_a_post = "not a post" not_a_post = "not a post".dup
def not_a_post.id; end def not_a_post.id; end
not_a_post.stub(:id, -> { raise StandardError.new("not_a_post had #id called on it") }) do not_a_post.stub(:id, -> { raise StandardError.new("not_a_post had #id called on it") }) do
assert_nothing_raised do assert_nothing_raised do
...@@ -417,7 +417,7 @@ def test_in_batches_should_quote_batch_order ...@@ -417,7 +417,7 @@ def test_in_batches_should_quote_batch_order
end end
def test_in_batches_should_not_use_records_after_yielding_them_in_case_original_array_is_modified def test_in_batches_should_not_use_records_after_yielding_them_in_case_original_array_is_modified
not_a_post = "not a post" not_a_post = "not a post".dup
def not_a_post.id def not_a_post.id
raise StandardError.new("not_a_post had #id called on it") raise StandardError.new("not_a_post had #id called on it")
end end
......
...@@ -10,7 +10,7 @@ class BinaryTest < ActiveRecord::TestCase ...@@ -10,7 +10,7 @@ class BinaryTest < ActiveRecord::TestCase
FIXTURES = %w(flowers.jpg example.log test.txt) FIXTURES = %w(flowers.jpg example.log test.txt)
def test_mixed_encoding def test_mixed_encoding
str = "\x80" str = "\x80".dup
str.force_encoding("ASCII-8BIT") str.force_encoding("ASCII-8BIT")
binary = Binary.new name: "いただきます!", data: str binary = Binary.new name: "いただきます!", data: str
......
...@@ -35,7 +35,7 @@ def test_inspect_class_without_table ...@@ -35,7 +35,7 @@ def test_inspect_class_without_table
def test_pretty_print_new def test_pretty_print_new
topic = Topic.new topic = Topic.new
actual = "" actual = "".dup
PP.pp(topic, StringIO.new(actual)) PP.pp(topic, StringIO.new(actual))
expected = <<-PRETTY.strip_heredoc expected = <<-PRETTY.strip_heredoc
#<Topic:0xXXXXXX #<Topic:0xXXXXXX
...@@ -64,7 +64,7 @@ def test_pretty_print_new ...@@ -64,7 +64,7 @@ def test_pretty_print_new
def test_pretty_print_persisted def test_pretty_print_persisted
topic = topics(:first) topic = topics(:first)
actual = "" actual = "".dup
PP.pp(topic, StringIO.new(actual)) PP.pp(topic, StringIO.new(actual))
expected = <<-PRETTY.strip_heredoc expected = <<-PRETTY.strip_heredoc
#<Topic:0x\\w+ #<Topic:0x\\w+
...@@ -92,7 +92,7 @@ def test_pretty_print_persisted ...@@ -92,7 +92,7 @@ def test_pretty_print_persisted
def test_pretty_print_uninitialized def test_pretty_print_uninitialized
topic = Topic.allocate topic = Topic.allocate
actual = "" actual = "".dup
PP.pp(topic, StringIO.new(actual)) PP.pp(topic, StringIO.new(actual))
expected = "#<Topic:XXXXXX not initialized>\n" expected = "#<Topic:XXXXXX not initialized>\n"
assert actual.start_with?(expected.split("XXXXXX").first) assert actual.start_with?(expected.split("XXXXXX").first)
...@@ -105,7 +105,7 @@ def inspect ...@@ -105,7 +105,7 @@ def inspect
"inspecting topic" "inspecting topic"
end end
end end
actual = "" actual = "".dup
PP.pp(subtopic.new, StringIO.new(actual)) PP.pp(subtopic.new, StringIO.new(actual))
assert_equal "inspecting topic\n", actual assert_equal "inspecting topic\n", actual
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册