Skip to content

Commit e7cfd34

Browse files
committed
Remove use of OpenStruct + Fix up test suite
We no longer use OpenStruct as it is slow and the library (ostrcut) is being removed from Ruby core in v3.5 Also, add `issues` to the CombiningFormatter. This doesn't really effect anything/anyone since this formatter was not being used and, being slower, there's no reason to believe anyone was opting into using it over the TemplatingFormatter. But... it was a incongruity in the test suite so I wanted to clean it up. Also, fix up the test suite: - Remove use of OpenStruct, which was plentiful - Refactor `klazz` -> `unit_class`, as has been my new standard for a while now - Add missing tests for inclusion of `issues` in output Strings
1 parent 3c4de2e commit e7cfd34

File tree

12 files changed

+177
-109
lines changed

12 files changed

+177
-109
lines changed

.rubocop.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,3 @@ inherit_gem:
99

1010
AllCops:
1111
TargetRubyVersion: 3.2
12-
13-
Performance/OpenStruct:
14-
Enabled: false # Reconsider later.

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## [Unreleased]
22

3+
- Add `issues` to the (probably never-used) CombiningFormatter + Internal refactoring/cleanup.
34
- Update benchmark code + results info for Ruby v3.4 in README
45

56
### 0.8.2 - 2025-1-4

bin/console

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
require "bundler/setup"
55
require "object_inspector"
66
require "object_identifier"
7-
require "ostruct"
87

98
# You can add fixtures and/or initialization code here to make experimenting
109
# with your gem easier. You can also use a different console, if you like.

lib/object_inspector/formatters/combining_formatter.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def strings
3838
[
3939
build_identification_string,
4040
build_flags_string,
41+
build_issues_string,
4142
build_info_string,
4243
build_name_string,
4344
].compact
@@ -51,6 +52,10 @@ def build_flags_string
5152
"(#{flags.to_s.upcase})" if flags
5253
end
5354

55+
def build_issues_string
56+
" !!#{issues.to_s.upcase}!!" if issues
57+
end
58+
5459
def build_info_string
5560
" #{info}" if info
5661
end

test/object_inspector/conversions_test.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@
44

55
class ObjectInspector::ConversionsTest < Minitest::Spec
66
describe "ObjectInspector::Conversions" do
7-
let(:klazz) { ObjectInspector::Conversions }
7+
let(:unit_class) { ObjectInspector::Conversions }
88

99
let(:scope1) { ObjectInspector::Scope.new }
1010

1111
describe ".Scope" do
12-
subject { klazz }
12+
subject { unit_class }
1313

1414
context "GIVEN an ObjectInspector::Scope" do
1515
it "returns the same ObjectInspector::Scope" do
16-
_(klazz.Scope(scope1).object_id).must_equal(scope1.object_id)
16+
_(unit_class.Scope(scope1).object_id).must_equal(scope1.object_id)
1717
end
1818
end
1919

2020
context "GIVEN a Symbol" do
2121
it "returns a new Scope for the given Symbol" do
22-
new_scope = klazz.Scope(:verbose)
22+
new_scope = unit_class.Scope(:verbose)
2323
_(new_scope.names).must_include("verbose")
2424
end
2525
end

test/object_inspector/formatters/base_formatter_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
class ObjectInspector::BaseFormatterTest < Minitest::Spec
66
describe "ObjectInspector::BaseFormatter" do
7-
let(:klazz) { ObjectInspector::BaseFormatter }
7+
let(:unit_class) { ObjectInspector::BaseFormatter }
88

99
describe "#call" do
1010
it "raises NotImplementedError" do
11-
_(-> { klazz.new(Object.new).call }).must_raise(
11+
_(-> { unit_class.new(Object.new).call }).must_raise(
1212
NotImplementedError)
1313
end
1414
end

test/object_inspector/formatters/combining_formatter_test.rb

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,58 +7,87 @@ class SimpleTestObject
77
def inspect_identification; "SIMPLE_TEST_OBJECT" end
88
end
99

10+
InspectableTestClass =
11+
Struct.new(
12+
:identification,
13+
:flags,
14+
:issues,
15+
:info,
16+
:name,
17+
:wrapped_object_inspection_result,
18+
keyword_init: true) do
19+
# :reek:LongParameterList
20+
def initialize(
21+
identification: nil,
22+
flags: nil,
23+
issues: nil,
24+
info: nil,
25+
name: nil,
26+
wrapped_object_inspection_result: nil)
27+
super
28+
end
29+
end
30+
1031
describe "ObjectInspector::CombiningFormatter" do
1132
let(:klazz) { ObjectInspector::CombiningFormatter }
1233
let(:inspector_klazz) { ObjectInspector::Inspector }
1334

1435
let(:inspector_with_wrapped_object) {
15-
OpenStruct.new(
36+
InspectableTestClass.new(
1637
identification: "WRAPPER",
1738
wrapped_object_inspection_result:
1839
inspector_klazz.new(SimpleTestObject.new))
1940
}
41+
let(:inspector_with_flags_and_issues_and_info_and_name) {
42+
InspectableTestClass.new(
43+
identification: "IDENTIFICATION",
44+
flags: "FLAG1 | FLAG2",
45+
issues: "ISSUE1 | ISSUE2",
46+
info: "INFO",
47+
name: "NAME")
48+
}
2049
let(:inspector_with_flags_and_info_and_name) {
21-
OpenStruct.new(
50+
InspectableTestClass.new(
2251
identification: "IDENTIFICATION",
2352
flags: "FLAG1 | FLAG2",
2453
info: "INFO",
2554
name: "NAME")
2655
}
2756
let(:inspector_with_flags_and_info) {
28-
OpenStruct.new(
57+
InspectableTestClass.new(
2958
identification: "IDENTIFICATION",
3059
flags: "FLAG1 | FLAG2",
3160
info: "INFO")
3261
}
3362
let(:inspector_with_flags_and_name) {
34-
OpenStruct.new(
63+
InspectableTestClass.new(
3564
identification: "IDENTIFICATION",
3665
flags: "FLAG1 | FLAG2",
3766
name: "NAME")
3867
}
3968
let(:inspector_with_info_and_name) {
40-
OpenStruct.new(
69+
InspectableTestClass.new(
4170
identification: "IDENTIFICATION",
4271
info: "INFO",
4372
name: "NAME")
4473
}
4574
let(:inspector_with_name) {
46-
OpenStruct.new(
75+
InspectableTestClass.new(
4776
identification: "IDENTIFICATION",
4877
name: "NAME")
4978
}
5079
let(:inspector_with_flags) {
51-
OpenStruct.new(
80+
InspectableTestClass.new(
5281
identification: "IDENTIFICATION",
5382
flags: "FLAG1 | FLAG2")
5483
}
5584
let(:inspector_with_info) {
56-
OpenStruct.new(
85+
InspectableTestClass.new(
5786
identification: "IDENTIFICATION",
5887
info: "INFO")
5988
}
6089
let(:inspector_with_base) {
61-
OpenStruct.new(
90+
InspectableTestClass.new(
6291
identification: "IDENTIFICATION")
6392
}
6493

@@ -83,6 +112,15 @@ def inspect_identification; "SIMPLE_TEST_OBJECT" end
83112
end
84113
end
85114

115+
context "GIVEN an Inspector with #flags #issues and #info and #name" do
116+
subject { klazz.new(inspector_with_flags_and_issues_and_info_and_name) }
117+
118+
it "returns the expected String" do
119+
_(subject.call).must_equal(
120+
"<IDENTIFICATION(FLAG1 | FLAG2) !!ISSUE1 | ISSUE2!! INFO :: NAME>")
121+
end
122+
end
123+
86124
context "GIVEN an Inspector with #flags and #info" do
87125
subject { klazz.new(inspector_with_flags_and_info) }
88126

0 commit comments

Comments
 (0)