Skip to content

spec for "no longer try to call #to_ary method on elements beyond the given level." #307

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions core/array/flatten_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@
[1, z, 6].flatten.should == [1, 2, 3, 4, 5, 6]
end

ruby_version_is "2.3" do
it "does not call #to_ary on elements beyond the given level" do
obj = mock("1")
obj.should_not_receive(:to_ary)
[[obj]].flatten(1)
end
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could add a version guard since this is only fixed from 2.3 and later? See this example.


it "returns subclass instance for Array subclasses" do
ArraySpecs::MyArray[].flatten.should be_an_instance_of(ArraySpecs::MyArray)
ArraySpecs::MyArray[1, 2, 3].flatten.should be_an_instance_of(ArraySpecs::MyArray)
Expand Down
8 changes: 5 additions & 3 deletions core/array/shared/inspect.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,20 @@
ruby_version_is ''...'2.3' do
it "raises if inspected result is not default external encoding" do
utf_16be = mock("utf_16be")
utf_16be.should_receive(:inspect).and_return(%<"utf_16be \u3042">.encode!(Encoding::UTF_16BE))
utf_16be.should_receive(:inspect).at_least(1).and_return(%<"utf_16be \u3042">.encode!(Encoding::UTF_16BE))

lambda { [utf_16be].send(@method) }.should raise_error(Encoding::CompatibilityError)
lambda { {a: utf_16be}.send(@method) }.should raise_error(Encoding::CompatibilityError)
end
end

ruby_version_is '2.3' do
it "raises if inspected result is not default external encoding" do
it "does not raise if inspected result is not default external encoding" do
utf_16be = mock("utf_16be")
utf_16be.should_receive(:inspect).and_return(%<"utf_16be \u3042">.encode!(Encoding::UTF_16BE))
utf_16be.should_receive(:inspect).at_least(1).and_return(%<"utf_16be \u3042">.encode!(Encoding::UTF_16BE))

[utf_16be].send(@method).should == '["utf_16be \u3042"]'
{a: utf_16be}.send(@method).should == '{:a=>"utf_16be \u3042"}'
end
end
end
Expand Down