summaryrefslogtreecommitdiff
path: root/spec/ruby/core/range/to_set_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/range/to_set_spec.rb')
-rw-r--r--spec/ruby/core/range/to_set_spec.rb59
1 files changed, 29 insertions, 30 deletions
diff --git a/spec/ruby/core/range/to_set_spec.rb b/spec/ruby/core/range/to_set_spec.rb
index 589c0e9aed..14e0ce1e31 100644
--- a/spec/ruby/core/range/to_set_spec.rb
+++ b/spec/ruby/core/range/to_set_spec.rb
@@ -1,7 +1,7 @@
require_relative '../../spec_helper'
require_relative '../enumerable/fixtures/classes'
-describe "Enumerable#to_set" do
+describe "Range#to_set" do
it "returns a new Set created from self" do
(1..4).to_set.should == Set[1, 2, 3, 4]
(1...4).to_set.should == Set[1, 2, 3]
@@ -11,45 +11,44 @@ describe "Enumerable#to_set" do
(1..3).to_set { |x| x * x }.should == Set[1, 4, 9]
end
+ it "raises a TypeError for a beginningless range" do
+ -> {
+ (..0).to_set
+ }.should raise_error(TypeError, "can't iterate from NilClass")
+ end
+
ruby_version_is "4.0" do
- it "raises a RangeError if the range is infinite" do
+ it "raises a RangeError if the range is endless" do
-> { (1..).to_set }.should raise_error(RangeError, "cannot convert endless range to a set")
-> { (1...).to_set }.should raise_error(RangeError, "cannot convert endless range to a set")
end
end
- ruby_version_is ""..."4.0" do
- it "instantiates an object of provided as the first argument set class" do
- set = (1..3).to_set(EnumerableSpecs::SetSubclass)
- set.should be_kind_of(EnumerableSpecs::SetSubclass)
- set.to_a.sort.should == [1, 2, 3]
- end
- end
-
- ruby_version_is "4.0"..."4.1" do
- it "instantiates an object of provided as the first argument set class and warns" do
- set = nil
- proc {
+ context "given positional arguments" do
+ ruby_version_is ""..."4.0" do
+ it "instantiates an object of provided as the first argument set class" do
set = (1..3).to_set(EnumerableSpecs::SetSubclass)
- }.should complain(/Enumerable#to_set/)
- set.should be_kind_of(EnumerableSpecs::SetSubclass)
- set.to_a.sort.should == [1, 2, 3]
+ set.should be_kind_of(EnumerableSpecs::SetSubclass)
+ set.to_a.sort.should == [1, 2, 3]
+ end
end
- end
- ruby_version_is "4.1" do
- it "does not accept any positional argument" do
- -> {
- (1..3).to_set(EnumerableSpecs::SetSubclass)
- }.should raise_error(ArgumentError, 'wrong number of arguments (given 1, expected 0)')
+ ruby_version_is "4.0"..."4.1" do
+ it "instantiates an object of provided as the first argument set class and warns" do
+ -> {
+ set = (1..3).to_set(EnumerableSpecs::SetSubclass)
+ set.should be_kind_of(EnumerableSpecs::SetSubclass)
+ set.to_a.sort.should == [1, 2, 3]
+ }.should complain(/warning: passing arguments to Enumerable#to_set is deprecated/)
+ end
end
- end
- it "does not need explicit `require 'set'`" do
- output = ruby_exe(<<~RUBY, options: '--disable-gems', args: '2>&1')
- puts (1..3).to_set.to_a.inspect
- RUBY
-
- output.chomp.should == "[1, 2, 3]"
+ ruby_version_is "4.1" do
+ it "does not accept any positional argument" do
+ -> {
+ (1..3).to_set(EnumerableSpecs::SetSubclass)
+ }.should raise_error(ArgumentError, "wrong number of arguments (given 1, expected 0)")
+ end
+ end
end
end