Skip to content

Commit

Permalink
Use _() instead of value() for minitest expectations
Browse files Browse the repository at this point in the history
The former is just a shortened (and preferred) alias of the latter.
  • Loading branch information
pdobb committed Nov 21, 2024
1 parent dbbd4fd commit bb3d825
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 76 deletions.
2 changes: 1 addition & 1 deletion test/core_ext/big_decimal_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class BigDecimalTest < Minitest::Spec
it "returns the same as #to_s" do
[1, 1.0, 0, 99.9999].each do |val|
bd_val = BigDecimal(val, 10)
value(bd_val.inspect_lit).must_equal("<BD:#{bd_val}>")
_(bd_val.inspect_lit).must_equal("<BD:#{bd_val}>")
end
end
end
Expand Down
10 changes: 5 additions & 5 deletions test/core_ext/object_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ObjectTest < Minitest::Spec
it "calls inspect on self" do
subject.inspect_lit

value(@object_inspect_call.args).must_equal([])
_(@object_inspect_call.args).must_equal([])
end
end

Expand All @@ -30,7 +30,7 @@ class ObjectTest < Minitest::Spec
it "calls ObjectIdentifier, passing self along" do
subject.identify

value(@object_identifier_identifier_call.pargs).must_equal([subject])
_(@object_identifier_identifier_call.pargs).must_equal([subject])
end

it "also passes along args and kwargs when given" do
Expand All @@ -39,9 +39,9 @@ class ObjectTest < Minitest::Spec

subject.identify(attributes, **options)

value(@object_identifier_identifier_call.pargs).
must_equal([subject, attributes])
value(@object_identifier_identifier_call.kargs).must_equal(options)
_(@object_identifier_identifier_call.pargs).must_equal(
[subject, attributes])
_(@object_identifier_identifier_call.kargs).must_equal(options)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/core_ext/string_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class StringTest < Minitest::Spec
describe String do
describe "#inspect_lit" do
it "quotes string values" do
value("string".inspect_lit).must_equal(%("string"))
_("string".inspect_lit).must_equal(%("string"))
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/core_ext/symbol_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class SymbolTest < Minitest::Spec
describe Symbol do
describe "#inspect_lit" do
it "quotes symbol values after colon" do
value(:symbol.inspect_lit).must_equal(%(:"symbol"))
_(:symbol.inspect_lit).must_equal(%(:"symbol"))
end
end
end
Expand Down
26 changes: 11 additions & 15 deletions test/object_identifier/configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,30 @@ def call(*)
subject { unit_class }

it "returns the expected constant" do
value(subject.default_formatter_class).must_equal(
default_formatter_class)
_(subject.default_formatter_class).must_equal(default_formatter_class)
end
end

describe ".default_attributes" do
subject { unit_class }

it "returns the expected constant" do
value(subject.default_attributes).must_equal(default_attributes)
_(subject.default_attributes).must_equal(default_attributes)
end
end

describe ".configuration" do
subject { unit_class }

it "returns an ObjectInspector::Configuration object" do
value(subject.configuration).must_be_kind_of(configuration_unit_class)
_(subject.configuration).must_be_kind_of(configuration_unit_class)
end

it "contains the expected default values" do
configuration = subject.configuration

value(configuration.formatter_class).must_equal(default_formatter_class)
value(configuration.default_attributes).must_equal(default_attributes)
_(configuration.formatter_class).must_equal(default_formatter_class)
_(configuration.default_attributes).must_equal(default_attributes)
end
end

Expand All @@ -69,10 +68,8 @@ def call(*)
it "sets custom configuration and converts values to Strings" do
configuration = subject.configuration

value(configuration.formatter_class).must_equal(
custom_formatter_class)
value(configuration.default_attributes).must_equal(
custom_attributes)
_(configuration.formatter_class).must_equal(custom_formatter_class)
_(configuration.default_attributes).must_equal(custom_attributes)
end
end
end
Expand All @@ -83,9 +80,8 @@ def call(*)
it "resets the Configuration to the expected default values" do
configuration = subject.configuration

value(configuration.formatter_class).must_equal(default_formatter_class)
value(configuration.default_attributes).must_equal(
default_attributes)
_(configuration.formatter_class).must_equal(default_formatter_class)
_(configuration.default_attributes).must_equal(default_attributes)
end
end

Expand All @@ -96,13 +92,13 @@ def call(*)
context "GIVEN a Class constant" do
it "sets the value as expected" do
subject.formatter_class = custom_formatter_class
value(subject.formatter_class).must_equal(custom_formatter_class)
_(subject.formatter_class).must_equal(custom_formatter_class)
end
end

context "GIVEN a String" do
it "raises TypeError" do
value(-> { subject.formatter_class = "STRING" }).must_raise(
_(-> { subject.formatter_class = "STRING" }).must_raise(
TypeError)
end
end
Expand Down
6 changes: 3 additions & 3 deletions test/object_identifier/formatters/base_formatter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ class ObjectIdentifier::BaseFormatterTest < Minitest::Spec

it "forwards to #call" do
result = subject.call(1, parameters: [2])
value(@object_identifier_base_formatter_called_with).must_equal(
_(@object_identifier_base_formatter_called_with).must_equal(
[1, { parameters: [2] }])
value(result).must_equal("FAKE_CALL_RESULT")
_(result).must_equal("FAKE_CALL_RESULT")
end
end

describe "#call" do
subject { ObjectIdentifier::BaseFormatter.new(1, parameters: [2]) }

it "raises NotImplementedError" do
value(-> { subject.call }).must_raise(NotImplementedError)
_(-> { subject.call }).must_raise(NotImplementedError)
end
end
end
Expand Down
51 changes: 22 additions & 29 deletions test/object_identifier/formatters/string_formatter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,44 +25,44 @@ def parameterize(attributes = [], **formatter_options)
context "GIVEN a single object" do
it "quotes Strings in attributes" do
object = OpenStruct.new(name: "TestName")
value(subject.call(object, **parameterize(:name))).
must_equal(%(OpenStruct["TestName"]))
_(subject.call(object, **parameterize(:name))).must_equal(
%(OpenStruct["TestName"]))
end

it "quotes symbols in attributes" do
object = OpenStruct.new(name: "TestName", attr1: :value1)
value(subject.call(object, **parameterize(:attr1))).
must_equal(%(OpenStruct[:"value1"]))
_(subject.call(object, **parameterize(:attr1))).must_equal(
%(OpenStruct[:"value1"]))
end

it "ignores attributes that don't exist" do
object = OpenStruct.new(name: "TestName", attr1: :value1)
value(subject.call(object, **parameterize(%i[attr1 unknown_attr1]))).
_(subject.call(object, **parameterize(%i[attr1 unknown_attr1]))).
must_equal(%(OpenStruct[:"value1"]))
end

it "returns the value of instance variables" do
object = OpenStruct.new
object.instance_variable_set(:@var1, 1)
value(subject.call(object, **parameterize(:@var1))).
must_equal("OpenStruct[1]")
_(subject.call(object, **parameterize(:@var1))).must_equal(
"OpenStruct[1]")
end

it "returns '[no objects]', GIVEN object = nil" do
value(subject.call(nil)).must_equal("[no objects]")
_(subject.call(nil)).must_equal("[no objects]")
end

it "returns '[no objects]', GIVEN object = an empty Hash" do
value(subject.call({})).must_equal("[no objects]")
_(subject.call({})).must_equal("[no objects]")
end

it "returns '[no objects]', GIVEN object = an empty Array" do
value(subject.call([])).must_equal("[no objects]")
_(subject.call([])).must_equal("[no objects]")
end

it "doesn't return '[no objects]', "\
"GIVEN object = an array of blank objects" do
value(subject.call([[], {}, nil])).wont_equal("[no objects]")
_(subject.call([[], {}, nil])).wont_equal("[no objects]")
end

context "GIVEN multiple attribute to identify" do
Expand All @@ -76,44 +76,39 @@ def parameterize(attributes = [], **formatter_options)

expected_attributes_string =
%(name:"TestName", attr1::"value1", @var1:1)
value(result).must_equal(
"OpenStruct[#{expected_attributes_string}]")
_(result).must_equal("OpenStruct[#{expected_attributes_string}]")
end
end

context "GIVEN object responds to :id" do
it "returns 'Class[<id value>]', GIVEN no other attributes" do
value(subject.call(OpenStruct.new(id: 1))).
must_equal("OpenStruct[1]")
_(subject.call(OpenStruct.new(id: 1))).must_equal("OpenStruct[1]")
end
end

context "GIVEN object does not respond to :id" do
it "returns '<ClassName>[]', GIVEN no attributes" do
value(subject.call(Object.new)).must_equal("Object[]")
_(subject.call(Object.new)).must_equal("Object[]")
end
end

context "GIVEN a :klass" do
let(:object) { OpenStruct.new(id: 1) }

it "overrides object class name" do
value(
subject.call(object, **parameterize(klass: "MyClass"))).
_(subject.call(object, **parameterize(klass: "MyClass"))).
must_equal("MyClass[1]")
end

it "returns no class name, GIVEN :klass is blank" do
value(
subject.call(object, **parameterize(klass: [nil, ""].sample))).
_(subject.call(object, **parameterize(klass: [nil, ""].sample))).
must_equal("[1]")
end
end

it "ignores :limit" do
object = OpenStruct.new(id: 1)
value(
subject.call(object, **parameterize(:id, limit: 3))).
_(subject.call(object, **parameterize(:id, limit: 3))).
must_equal("OpenStruct[1]")
end
end
Expand All @@ -122,24 +117,22 @@ def parameterize(attributes = [], **formatter_options)
let(:object) { [OpenStruct.new(id: 1), Object.new] }

it "identifies each object in turn" do
value(subject.call(object)).must_equal("OpenStruct[1], Object[]")
_(subject.call(object)).must_equal("OpenStruct[1], Object[]")
end

it "overrides object class name for all objects, GIVEN a :klass" do
value(
subject.call(object, **parameterize(klass: "MyClass"))).
_(subject.call(object, **parameterize(klass: "MyClass"))).
must_equal("MyClass[1], MyClass[]")
end

it "returns no class name, GIVEN :klass is blank" do
value(
subject.call(object, **parameterize(klass: [nil, ""].sample))).
_(subject.call(object, **parameterize(klass: [nil, ""].sample))).
must_equal("[1], []")
end

it "returns truncated list, GIVEN :limit" do
object = "abcdefg".chars
value(subject.call(object, **parameterize(:upcase, limit: 3))).
_(subject.call(object, **parameterize(:upcase, limit: 3))).
must_equal(
"String[\"A\"], "\
"String[\"B\"], "\
Expand All @@ -151,7 +144,7 @@ def parameterize(attributes = [], **formatter_options)
let(:object) { TestStruct.new(1) }

it "returns the expected String" do
value(subject.call(object)).must_equal(
_(subject.call(object)).must_equal(
"ObjectIdentifier::StringFormatterTest::TestStruct[1]")
end
end
Expand Down
14 changes: 7 additions & 7 deletions test/object_identifier/object_identifier_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def call(*)
subject { unit_class }

it "has a VERSION" do
value(unit_class::VERSION).wont_be_nil
_(unit_class::VERSION).wont_be_nil
end

describe ".call" do
Expand All @@ -41,10 +41,10 @@ def call(*)

it "calls the default formatter + attributes" do
result = subject.call(objects)
value(result).must_be_instance_of(String)
_(result).must_be_instance_of(String)

value(@default_formatter_class_called).must_equal(true)
value(@parameters_build_call.kargs).must_equal({
_(@default_formatter_class_called).must_equal(true)
_(@parameters_build_call.kargs).must_equal({
attributes: [],
formatter_options: {},
})
Expand All @@ -65,10 +65,10 @@ def call(*)
custom_attributes,
formatter_class: custom_formatter_class,
**custom_formatter_options)
value(result).must_equal("FAKE_CALL_RESULT")
_(result).must_equal("FAKE_CALL_RESULT")

value(@custom_formatter_class_called).must_equal(true)
value(@parameters_build_call.kargs).must_equal(
_(@custom_formatter_class_called).must_equal(true)
_(@parameters_build_call.kargs).must_equal(
{
attributes: custom_attributes,
formatter_options: custom_formatter_options,
Expand Down
Loading

0 comments on commit bb3d825

Please sign in to comment.