Make inspecting collections a bit more friendly

Fixes #3474
This commit is contained in:
Andrew Cholakian 2015-06-19 14:14:33 -05:00 committed by Jordan Sissel
parent 90de9b7f9e
commit f0e5bcd597
2 changed files with 21 additions and 0 deletions

View file

@ -92,4 +92,8 @@ module java::util::Collection
duped.addAll(other)
duped
end
def inspect
"<#{self.class.name}:#{self.hashCode} #{self.to_a(&:inspect)}>"
end
end

View file

@ -82,6 +82,23 @@ describe "Java integration" do
context "Java::JavaUtil::Collection" do
subject{Java::JavaUtil::ArrayList.new(initial_array)}
context "when inspecting" do
let(:items) { [:a, {:b => :c}] }
subject { java.util.ArrayList.new(items) }
it "should include the contents of the Collection" do
expect(subject.inspect).to include(items.inspect)
end
it "should include the class name" do
expect(subject.inspect).to include("ArrayList")
end
it "should include the hash code of the collection" do
expect(subject.inspect).to include(subject.hashCode.to_s)
end
end
context "when deleting a unique instance" do
let(:initial_array) {["foo", "bar"]}