Skip to content

Commit

Permalink
Improve inspection of Module (#263)
Browse files Browse the repository at this point in the history
A module's inspection (used e.g. generate a description of an RSpec
example) has been improved to now include the module's name, which
identifies the module better than the previous string.

Old: `#<Module:0x0000000107f7a0a0>`
New (e.g.): `SuperDiff::Test`.

Closes #255.
  • Loading branch information
phorsuedzie authored Sep 25, 2024
1 parent 02ab80d commit 7d1a4ce
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/super_diff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def self.date_like?(value)

def self.primitive?(value)
case value
when true, false, nil, Symbol, Numeric, Regexp, Class, String
when true, false, nil, Symbol, Numeric, Regexp, Class, Module, String
true
else
false
Expand Down
31 changes: 31 additions & 0 deletions spec/unit/super_diff_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,37 @@
end
end

context "given a module" do
context "given as_lines: false" do
it "returns the module's name" do
string =
described_class.inspect_object(SuperDiff::Test, as_lines: false)
expect(string).to eq("SuperDiff::Test")
end
end

context "given as_lines: true" do
it "returns the module's name as value" do
tiered_lines =
described_class.inspect_object(
SuperDiff::Test,
as_lines: true,
type: :delete,
indentation_level: 1
)
expect(tiered_lines).to match(
[
an_object_having_attributes(
type: :delete,
indentation_level: 1,
value: "SuperDiff::Test"
)
]
)
end
end
end

# TODO: Add when empty
context "given a custom object" do
context "containing only primitive values" do
Expand Down

0 comments on commit 7d1a4ce

Please sign in to comment.