summaryrefslogtreecommitdiff
path: root/spec/ruby/core/set
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/set')
-rw-r--r--spec/ruby/core/set/add_spec.rb14
-rw-r--r--spec/ruby/core/set/append_spec.rb5
-rw-r--r--spec/ruby/core/set/case_compare_spec.rb8
-rw-r--r--spec/ruby/core/set/case_equality_spec.rb6
-rw-r--r--spec/ruby/core/set/collect_spec.rb5
-rw-r--r--spec/ruby/core/set/difference_spec.rb5
-rw-r--r--spec/ruby/core/set/eql_spec.rb24
-rw-r--r--spec/ruby/core/set/filter_spec.rb5
-rw-r--r--spec/ruby/core/set/gt_spec.rb7
-rw-r--r--spec/ruby/core/set/gte_spec.rb7
-rw-r--r--spec/ruby/core/set/include_spec.rb29
-rw-r--r--spec/ruby/core/set/inspect_spec.rb5
-rw-r--r--spec/ruby/core/set/intersection_spec.rb19
-rw-r--r--spec/ruby/core/set/length_spec.rb5
-rw-r--r--spec/ruby/core/set/lt_spec.rb7
-rw-r--r--spec/ruby/core/set/lte_spec.rb7
-rw-r--r--spec/ruby/core/set/map_spec.rb20
-rw-r--r--spec/ruby/core/set/member_spec.rb5
-rw-r--r--spec/ruby/core/set/minus_spec.rb15
-rw-r--r--spec/ruby/core/set/plus_spec.rb5
-rw-r--r--spec/ruby/core/set/select_spec.rb39
-rw-r--r--spec/ruby/core/set/shared/add.rb14
-rw-r--r--spec/ruby/core/set/shared/collect.rb20
-rw-r--r--spec/ruby/core/set/shared/difference.rb15
-rw-r--r--spec/ruby/core/set/shared/include.rb29
-rw-r--r--spec/ruby/core/set/shared/inspect.rb45
-rw-r--r--spec/ruby/core/set/shared/intersection.rb15
-rw-r--r--spec/ruby/core/set/shared/length.rb6
-rw-r--r--spec/ruby/core/set/shared/select.rb41
-rw-r--r--spec/ruby/core/set/shared/union.rb15
-rw-r--r--spec/ruby/core/set/size_spec.rb6
-rw-r--r--spec/ruby/core/set/to_s_spec.rb46
-rw-r--r--spec/ruby/core/set/union_spec.rb19
33 files changed, 254 insertions, 259 deletions
diff --git a/spec/ruby/core/set/add_spec.rb b/spec/ruby/core/set/add_spec.rb
index 1ce03b1eab..1a018b186a 100644
--- a/spec/ruby/core/set/add_spec.rb
+++ b/spec/ruby/core/set/add_spec.rb
@@ -1,8 +1,18 @@
require_relative '../../spec_helper'
-require_relative 'shared/add'
describe "Set#add" do
- it_behaves_like :set_add, :add
+ before :each do
+ @set = Set.new
+ end
+
+ it "adds the passed Object to self" do
+ @set.add("dog")
+ @set.should.include?("dog")
+ end
+
+ it "returns self" do
+ @set.add("dog").should.equal?(@set)
+ end
end
describe "Set#add?" do
diff --git a/spec/ruby/core/set/append_spec.rb b/spec/ruby/core/set/append_spec.rb
index 82d34d9130..4f4e2351e2 100644
--- a/spec/ruby/core/set/append_spec.rb
+++ b/spec/ruby/core/set/append_spec.rb
@@ -1,6 +1,7 @@
require_relative '../../spec_helper'
-require_relative 'shared/add'
describe "Set#<<" do
- it_behaves_like :set_add, :<<
+ it "is an alias of Set#add" do
+ Set.instance_method(:<<).should == Set.instance_method(:add)
+ end
end
diff --git a/spec/ruby/core/set/case_compare_spec.rb b/spec/ruby/core/set/case_compare_spec.rb
index 3781b1b963..6fe749c79b 100644
--- a/spec/ruby/core/set/case_compare_spec.rb
+++ b/spec/ruby/core/set/case_compare_spec.rb
@@ -1,11 +1,7 @@
require_relative '../../spec_helper'
-require_relative 'shared/include'
describe "Set#===" do
- it_behaves_like :set_include, :===
-
- it "is an alias for include?" do
- set = Set.new
- set.method(:===).should == set.method(:include?)
+ it "is an alias of Set#include?" do
+ Set.instance_method(:===).should == Set.instance_method(:include?)
end
end
diff --git a/spec/ruby/core/set/case_equality_spec.rb b/spec/ruby/core/set/case_equality_spec.rb
deleted file mode 100644
index 19c1fb6b9c..0000000000
--- a/spec/ruby/core/set/case_equality_spec.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-require_relative '../../spec_helper'
-require_relative 'shared/include'
-
-describe "Set#===" do
- it_behaves_like :set_include, :===
-end
diff --git a/spec/ruby/core/set/collect_spec.rb b/spec/ruby/core/set/collect_spec.rb
index d186f1a0d9..b78ee493d4 100644
--- a/spec/ruby/core/set/collect_spec.rb
+++ b/spec/ruby/core/set/collect_spec.rb
@@ -1,6 +1,7 @@
require_relative '../../spec_helper'
-require_relative 'shared/collect'
describe "Set#collect!" do
- it_behaves_like :set_collect_bang, :collect!
+ it "is an alias of Set#map!" do
+ Set.instance_method(:collect!).should == Set.instance_method(:map!)
+ end
end
diff --git a/spec/ruby/core/set/difference_spec.rb b/spec/ruby/core/set/difference_spec.rb
index 149f946592..22d89973a8 100644
--- a/spec/ruby/core/set/difference_spec.rb
+++ b/spec/ruby/core/set/difference_spec.rb
@@ -1,6 +1,7 @@
require_relative '../../spec_helper'
-require_relative 'shared/difference'
describe "Set#difference" do
- it_behaves_like :set_difference, :difference
+ it "is an alias of Set#-" do
+ Set.instance_method(:difference).should == Set.instance_method(:-)
+ end
end
diff --git a/spec/ruby/core/set/eql_spec.rb b/spec/ruby/core/set/eql_spec.rb
index 6862ed4eda..e7eacf2999 100644
--- a/spec/ruby/core/set/eql_spec.rb
+++ b/spec/ruby/core/set/eql_spec.rb
@@ -1,14 +1,22 @@
require_relative '../../spec_helper'
describe "Set#eql?" do
- it "returns true when the passed argument is a Set and contains the same elements" do
- Set[].should.eql?(Set[])
- Set[1, 2, 3].should.eql?(Set[1, 2, 3])
- Set[1, 2, 3].should.eql?(Set[3, 2, 1])
- Set["a", :b, ?c].should.eql?(Set[?c, :b, "a"])
+ ruby_version_is ""..."4.0" do
+ it "returns true when the passed argument is a Set and contains the same elements" do
+ Set[].should.eql?(Set[])
+ Set[1, 2, 3].should.eql?(Set[1, 2, 3])
+ Set[1, 2, 3].should.eql?(Set[3, 2, 1])
+ Set["a", :b, ?c].should.eql?(Set[?c, :b, "a"])
- Set[1, 2, 3].should_not.eql?(Set[1.0, 2, 3])
- Set[1, 2, 3].should_not.eql?(Set[2, 3])
- Set[1, 2, 3].should_not.eql?(Set[])
+ Set[1, 2, 3].should_not.eql?(Set[1.0, 2, 3])
+ Set[1, 2, 3].should_not.eql?(Set[2, 3])
+ Set[1, 2, 3].should_not.eql?(Set[])
+ end
+ end
+
+ ruby_version_is "4.0" do
+ it "is an alias of Set#==" do
+ Set.instance_method(:eql?).should == Set.instance_method(:==)
+ end
end
end
diff --git a/spec/ruby/core/set/filter_spec.rb b/spec/ruby/core/set/filter_spec.rb
index 779254ad68..d0c294c27f 100644
--- a/spec/ruby/core/set/filter_spec.rb
+++ b/spec/ruby/core/set/filter_spec.rb
@@ -1,6 +1,7 @@
require_relative '../../spec_helper'
-require_relative 'shared/select'
describe "Set#filter!" do
- it_behaves_like :set_select_bang, :filter!
+ it "is an alias of Set#select!" do
+ Set.instance_method(:filter!).should == Set.instance_method(:select!)
+ end
end
diff --git a/spec/ruby/core/set/gt_spec.rb b/spec/ruby/core/set/gt_spec.rb
new file mode 100644
index 0000000000..8a7e421e40
--- /dev/null
+++ b/spec/ruby/core/set/gt_spec.rb
@@ -0,0 +1,7 @@
+require_relative '../../spec_helper'
+
+describe "Set#>" do
+ it "is an alias of Set#proper_superset?" do
+ Set.instance_method(:>).should == Set.instance_method(:proper_superset?)
+ end
+end
diff --git a/spec/ruby/core/set/gte_spec.rb b/spec/ruby/core/set/gte_spec.rb
new file mode 100644
index 0000000000..e98c3cb1e2
--- /dev/null
+++ b/spec/ruby/core/set/gte_spec.rb
@@ -0,0 +1,7 @@
+require_relative '../../spec_helper'
+
+describe "Set#>=" do
+ it "is an alias of Set#superset?" do
+ Set.instance_method(:>=).should == Set.instance_method(:superset?)
+ end
+end
diff --git a/spec/ruby/core/set/include_spec.rb b/spec/ruby/core/set/include_spec.rb
index dd33bbc3bd..92a6ca04e6 100644
--- a/spec/ruby/core/set/include_spec.rb
+++ b/spec/ruby/core/set/include_spec.rb
@@ -1,6 +1,31 @@
require_relative '../../spec_helper'
-require_relative 'shared/include'
describe "Set#include?" do
- it_behaves_like :set_include, :include?
+ it "returns true when self contains the passed Object" do
+ set = Set[:a, :b, :c]
+ set.include?(:a).should == true
+ set.include?(:e).should == false
+ end
+
+ describe "member equality" do
+ it "is checked using both #hash and #eql?" do
+ obj = Object.new
+ obj_another = Object.new
+
+ def obj.hash; 42 end
+ def obj_another.hash; 42 end
+ def obj_another.eql?(o) hash == o.hash end
+
+ set = Set["a", "b", "c", obj]
+ set.include?(obj_another).should == true
+ end
+
+ it "is not checked using #==" do
+ obj = Object.new
+ set = Set["a", "b", "c"]
+
+ obj.should_not_receive(:==)
+ set.include?(obj)
+ end
+ end
end
diff --git a/spec/ruby/core/set/inspect_spec.rb b/spec/ruby/core/set/inspect_spec.rb
index 0dcce83eb6..45aeed280e 100644
--- a/spec/ruby/core/set/inspect_spec.rb
+++ b/spec/ruby/core/set/inspect_spec.rb
@@ -1,6 +1,7 @@
require_relative '../../spec_helper'
-require_relative 'shared/inspect'
describe "Set#inspect" do
- it_behaves_like :set_inspect, :inspect
+ it "is an alias of Set#to_s" do
+ Set.instance_method(:inspect).should == Set.instance_method(:to_s)
+ end
end
diff --git a/spec/ruby/core/set/intersection_spec.rb b/spec/ruby/core/set/intersection_spec.rb
index 136b886775..c14e1f62ad 100644
--- a/spec/ruby/core/set/intersection_spec.rb
+++ b/spec/ruby/core/set/intersection_spec.rb
@@ -1,10 +1,23 @@
require_relative '../../spec_helper'
-require_relative 'shared/intersection'
describe "Set#intersection" do
- it_behaves_like :set_intersection, :intersection
+ it "is an alias of Set#&" do
+ Set.instance_method(:intersection).should == Set.instance_method(:&)
+ end
end
describe "Set#&" do
- it_behaves_like :set_intersection, :&
+ before :each do
+ @set = Set[:a, :b, :c]
+ end
+
+ it "returns a new Set containing only elements shared by self and the passed Enumerable" do
+ (@set & Set[:b, :c, :d, :e]).should == Set[:b, :c]
+ (@set & [:b, :c, :d]).should == Set[:b, :c]
+ end
+
+ it "raises an ArgumentError when passed a non-Enumerable" do
+ -> { @set & 1 }.should.raise(ArgumentError)
+ -> { @set & Object.new }.should.raise(ArgumentError)
+ end
end
diff --git a/spec/ruby/core/set/length_spec.rb b/spec/ruby/core/set/length_spec.rb
index 6bb697b4ca..9b0d3622b8 100644
--- a/spec/ruby/core/set/length_spec.rb
+++ b/spec/ruby/core/set/length_spec.rb
@@ -1,6 +1,7 @@
require_relative '../../spec_helper'
-require_relative 'shared/length'
describe "Set#length" do
- it_behaves_like :set_length, :length
+ it "is an alias of Set#size" do
+ Set.instance_method(:length).should == Set.instance_method(:size)
+ end
end
diff --git a/spec/ruby/core/set/lt_spec.rb b/spec/ruby/core/set/lt_spec.rb
new file mode 100644
index 0000000000..0f5bc9c642
--- /dev/null
+++ b/spec/ruby/core/set/lt_spec.rb
@@ -0,0 +1,7 @@
+require_relative '../../spec_helper'
+
+describe "Set#<" do
+ it "is an alias of Set#proper_subset?" do
+ Set.instance_method(:<).should == Set.instance_method(:proper_subset?)
+ end
+end
diff --git a/spec/ruby/core/set/lte_spec.rb b/spec/ruby/core/set/lte_spec.rb
new file mode 100644
index 0000000000..291d582240
--- /dev/null
+++ b/spec/ruby/core/set/lte_spec.rb
@@ -0,0 +1,7 @@
+require_relative '../../spec_helper'
+
+describe "Set#<=" do
+ it "is an alias of Set#subset?" do
+ Set.instance_method(:<=).should == Set.instance_method(:subset?)
+ end
+end
diff --git a/spec/ruby/core/set/map_spec.rb b/spec/ruby/core/set/map_spec.rb
index 996191b0a8..fd04a8bde1 100644
--- a/spec/ruby/core/set/map_spec.rb
+++ b/spec/ruby/core/set/map_spec.rb
@@ -1,6 +1,22 @@
require_relative '../../spec_helper'
-require_relative 'shared/collect'
describe "Set#map!" do
- it_behaves_like :set_collect_bang, :map!
+ before :each do
+ @set = Set[1, 2, 3, 4, 5]
+ end
+
+ it "yields each Object in self" do
+ res = []
+ @set.map! { |x| res << x }
+ res.sort.should == [1, 2, 3, 4, 5].sort
+ end
+
+ it "returns self" do
+ @set.map! { |x| x }.should.equal?(@set)
+ end
+
+ it "replaces self with the return values of the block" do
+ @set.map! { |x| x * 2 }
+ @set.should == Set[2, 4, 6, 8, 10]
+ end
end
diff --git a/spec/ruby/core/set/member_spec.rb b/spec/ruby/core/set/member_spec.rb
index 5c82e8f826..a36308eec7 100644
--- a/spec/ruby/core/set/member_spec.rb
+++ b/spec/ruby/core/set/member_spec.rb
@@ -1,6 +1,7 @@
require_relative '../../spec_helper'
-require_relative 'shared/include'
describe "Set#member?" do
- it_behaves_like :set_include, :member?
+ it "is an alias of Set#include?" do
+ Set.instance_method(:member?).should == Set.instance_method(:include?)
+ end
end
diff --git a/spec/ruby/core/set/minus_spec.rb b/spec/ruby/core/set/minus_spec.rb
index 72f98f985e..8574708559 100644
--- a/spec/ruby/core/set/minus_spec.rb
+++ b/spec/ruby/core/set/minus_spec.rb
@@ -1,6 +1,17 @@
require_relative '../../spec_helper'
-require_relative 'shared/difference'
describe "Set#-" do
- it_behaves_like :set_difference, :-
+ before :each do
+ @set = Set[:a, :b, :c]
+ end
+
+ it "returns a new Set containing self's elements excluding the elements in the passed Enumerable" do
+ (@set - Set[:a, :b]).should == Set[:c]
+ (@set - [:b, :c]).should == Set[:a]
+ end
+
+ it "raises an ArgumentError when passed a non-Enumerable" do
+ -> { @set - 1 }.should.raise(ArgumentError)
+ -> { @set - Object.new }.should.raise(ArgumentError)
+ end
end
diff --git a/spec/ruby/core/set/plus_spec.rb b/spec/ruby/core/set/plus_spec.rb
index 7e44ff0b7e..839f77fc39 100644
--- a/spec/ruby/core/set/plus_spec.rb
+++ b/spec/ruby/core/set/plus_spec.rb
@@ -1,6 +1,7 @@
require_relative '../../spec_helper'
-require_relative 'shared/union'
describe "Set#+" do
- it_behaves_like :set_union, :+
+ it "is an alias of Set#|" do
+ Set.instance_method(:+).should == Set.instance_method(:|)
+ end
end
diff --git a/spec/ruby/core/set/select_spec.rb b/spec/ruby/core/set/select_spec.rb
index b458ffacaa..619194605b 100644
--- a/spec/ruby/core/set/select_spec.rb
+++ b/spec/ruby/core/set/select_spec.rb
@@ -1,6 +1,41 @@
require_relative '../../spec_helper'
-require_relative 'shared/select'
describe "Set#select!" do
- it_behaves_like :set_select_bang, :select!
+ before :each do
+ @set = Set["one", "two", "three"]
+ end
+
+ it "yields every element of self" do
+ ret = []
+ @set.select! { |x| ret << x }
+ ret.sort.should == ["one", "two", "three"].sort
+ end
+
+ it "keeps every element from self for which the passed block returns true" do
+ @set.select! { |x| x.size != 3 }
+ @set.size.should.eql?(1)
+
+ @set.should_not.include?("one")
+ @set.should_not.include?("two")
+ @set.should.include?("three")
+ end
+
+ it "returns self when self was modified" do
+ @set.select! { false }.should.equal?(@set)
+ end
+
+ it "returns nil when self was not modified" do
+ @set.select! { true }.should == nil
+ end
+
+ it "returns an Enumerator when passed no block" do
+ enum = @set.select!
+ enum.should.instance_of?(Enumerator)
+
+ enum.each { |x| x.size != 3 }
+
+ @set.should_not.include?("one")
+ @set.should_not.include?("two")
+ @set.should.include?("three")
+ end
end
diff --git a/spec/ruby/core/set/shared/add.rb b/spec/ruby/core/set/shared/add.rb
deleted file mode 100644
index 8d6d83434f..0000000000
--- a/spec/ruby/core/set/shared/add.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-describe :set_add, shared: true do
- before :each do
- @set = Set.new
- end
-
- it "adds the passed Object to self" do
- @set.send(@method, "dog")
- @set.should.include?("dog")
- end
-
- it "returns self" do
- @set.send(@method, "dog").should.equal?(@set)
- end
-end
diff --git a/spec/ruby/core/set/shared/collect.rb b/spec/ruby/core/set/shared/collect.rb
deleted file mode 100644
index ad5c5afa59..0000000000
--- a/spec/ruby/core/set/shared/collect.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-describe :set_collect_bang, shared: true do
- before :each do
- @set = Set[1, 2, 3, 4, 5]
- end
-
- it "yields each Object in self" do
- res = []
- @set.send(@method) { |x| res << x }
- res.sort.should == [1, 2, 3, 4, 5].sort
- end
-
- it "returns self" do
- @set.send(@method) { |x| x }.should.equal?(@set)
- end
-
- it "replaces self with the return values of the block" do
- @set.send(@method) { |x| x * 2 }
- @set.should == Set[2, 4, 6, 8, 10]
- end
-end
diff --git a/spec/ruby/core/set/shared/difference.rb b/spec/ruby/core/set/shared/difference.rb
deleted file mode 100644
index 8a17056a82..0000000000
--- a/spec/ruby/core/set/shared/difference.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-describe :set_difference, shared: true do
- before :each do
- @set = Set[:a, :b, :c]
- end
-
- it "returns a new Set containing self's elements excluding the elements in the passed Enumerable" do
- @set.send(@method, Set[:a, :b]).should == Set[:c]
- @set.send(@method, [:b, :c]).should == Set[:a]
- end
-
- it "raises an ArgumentError when passed a non-Enumerable" do
- -> { @set.send(@method, 1) }.should.raise(ArgumentError)
- -> { @set.send(@method, Object.new) }.should.raise(ArgumentError)
- end
-end
diff --git a/spec/ruby/core/set/shared/include.rb b/spec/ruby/core/set/shared/include.rb
deleted file mode 100644
index 82755ccf59..0000000000
--- a/spec/ruby/core/set/shared/include.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-describe :set_include, shared: true do
- it "returns true when self contains the passed Object" do
- set = Set[:a, :b, :c]
- set.send(@method, :a).should == true
- set.send(@method, :e).should == false
- end
-
- describe "member equality" do
- it "is checked using both #hash and #eql?" do
- obj = Object.new
- obj_another = Object.new
-
- def obj.hash; 42 end
- def obj_another.hash; 42 end
- def obj_another.eql?(o) hash == o.hash end
-
- set = Set["a", "b", "c", obj]
- set.send(@method, obj_another).should == true
- end
-
- it "is not checked using #==" do
- obj = Object.new
- set = Set["a", "b", "c"]
-
- obj.should_not_receive(:==)
- set.send(@method, obj)
- end
- end
-end
diff --git a/spec/ruby/core/set/shared/inspect.rb b/spec/ruby/core/set/shared/inspect.rb
deleted file mode 100644
index 31bd8accfd..0000000000
--- a/spec/ruby/core/set/shared/inspect.rb
+++ /dev/null
@@ -1,45 +0,0 @@
-describe :set_inspect, shared: true do
- it "returns a String representation of self" do
- Set[].send(@method).should.is_a?(String)
- Set[nil, false, true].send(@method).should.is_a?(String)
- Set[1, 2, 3].send(@method).should.is_a?(String)
- Set["1", "2", "3"].send(@method).should.is_a?(String)
- Set[:a, "b", Set[?c]].send(@method).should.is_a?(String)
- end
-
- ruby_version_is "4.0" do
- it "does include the elements of the set" do
- Set["1"].send(@method).should == 'Set["1"]'
- end
- end
-
- ruby_version_is ""..."4.0" do
- it "does include the elements of the set" do
- Set["1"].send(@method).should == '#<Set: {"1"}>'
- end
- end
-
- it "puts spaces between the elements" do
- Set["1", "2"].send(@method).should.include?('", "')
- end
-
- ruby_version_is "4.0" do
- it "correctly handles cyclic-references" do
- set1 = Set[]
- set2 = Set[set1]
- set1 << set2
- set1.send(@method).should.is_a?(String)
- set1.send(@method).should.include?("Set[...]")
- end
- end
-
- ruby_version_is ""..."4.0" do
- it "correctly handles cyclic-references" do
- set1 = Set[]
- set2 = Set[set1]
- set1 << set2
- set1.send(@method).should.is_a?(String)
- set1.send(@method).should.include?("#<Set: {...}>")
- end
- end
-end
diff --git a/spec/ruby/core/set/shared/intersection.rb b/spec/ruby/core/set/shared/intersection.rb
deleted file mode 100644
index 978a4924ef..0000000000
--- a/spec/ruby/core/set/shared/intersection.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-describe :set_intersection, shared: true do
- before :each do
- @set = Set[:a, :b, :c]
- end
-
- it "returns a new Set containing only elements shared by self and the passed Enumerable" do
- @set.send(@method, Set[:b, :c, :d, :e]).should == Set[:b, :c]
- @set.send(@method, [:b, :c, :d]).should == Set[:b, :c]
- end
-
- it "raises an ArgumentError when passed a non-Enumerable" do
- -> { @set.send(@method, 1) }.should.raise(ArgumentError)
- -> { @set.send(@method, Object.new) }.should.raise(ArgumentError)
- end
-end
diff --git a/spec/ruby/core/set/shared/length.rb b/spec/ruby/core/set/shared/length.rb
deleted file mode 100644
index a8fcee9f39..0000000000
--- a/spec/ruby/core/set/shared/length.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-describe :set_length, shared: true do
- it "returns the number of elements in the set" do
- set = Set[:a, :b, :c]
- set.send(@method).should == 3
- end
-end
diff --git a/spec/ruby/core/set/shared/select.rb b/spec/ruby/core/set/shared/select.rb
deleted file mode 100644
index 0d4a53fffd..0000000000
--- a/spec/ruby/core/set/shared/select.rb
+++ /dev/null
@@ -1,41 +0,0 @@
-require_relative '../../../spec_helper'
-
-describe :set_select_bang, shared: true do
- before :each do
- @set = Set["one", "two", "three"]
- end
-
- it "yields every element of self" do
- ret = []
- @set.send(@method) { |x| ret << x }
- ret.sort.should == ["one", "two", "three"].sort
- end
-
- it "keeps every element from self for which the passed block returns true" do
- @set.send(@method) { |x| x.size != 3 }
- @set.size.should.eql?(1)
-
- @set.should_not.include?("one")
- @set.should_not.include?("two")
- @set.should.include?("three")
- end
-
- it "returns self when self was modified" do
- @set.send(@method) { false }.should.equal?(@set)
- end
-
- it "returns nil when self was not modified" do
- @set.send(@method) { true }.should == nil
- end
-
- it "returns an Enumerator when passed no block" do
- enum = @set.send(@method)
- enum.should.instance_of?(Enumerator)
-
- enum.each { |x| x.size != 3 }
-
- @set.should_not.include?("one")
- @set.should_not.include?("two")
- @set.should.include?("three")
- end
-end
diff --git a/spec/ruby/core/set/shared/union.rb b/spec/ruby/core/set/shared/union.rb
deleted file mode 100644
index dddf1716e5..0000000000
--- a/spec/ruby/core/set/shared/union.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-describe :set_union, shared: true do
- before :each do
- @set = Set[:a, :b, :c]
- end
-
- it "returns a new Set containing all elements of self and the passed Enumerable" do
- @set.send(@method, Set[:b, :d, :e]).should == Set[:a, :b, :c, :d, :e]
- @set.send(@method, [:b, :e]).should == Set[:a, :b, :c, :e]
- end
-
- it "raises an ArgumentError when passed a non-Enumerable" do
- -> { @set.send(@method, 1) }.should.raise(ArgumentError)
- -> { @set.send(@method, Object.new) }.should.raise(ArgumentError)
- end
-end
diff --git a/spec/ruby/core/set/size_spec.rb b/spec/ruby/core/set/size_spec.rb
index 4ae22c5f0a..c57272a235 100644
--- a/spec/ruby/core/set/size_spec.rb
+++ b/spec/ruby/core/set/size_spec.rb
@@ -1,6 +1,8 @@
require_relative '../../spec_helper'
-require_relative 'shared/length'
describe "Set#size" do
- it_behaves_like :set_length, :size
+ it "returns the number of elements in the set" do
+ set = Set[:a, :b, :c]
+ set.size.should == 3
+ end
end
diff --git a/spec/ruby/core/set/to_s_spec.rb b/spec/ruby/core/set/to_s_spec.rb
index 55b8bfd9b2..7f768bdcbf 100644
--- a/spec/ruby/core/set/to_s_spec.rb
+++ b/spec/ruby/core/set/to_s_spec.rb
@@ -1,11 +1,47 @@
require_relative "../../spec_helper"
-require_relative 'shared/inspect'
describe "Set#to_s" do
- it_behaves_like :set_inspect, :to_s
+ it "returns a String representation of self" do
+ Set[].to_s.should.is_a?(String)
+ Set[nil, false, true].to_s.should.is_a?(String)
+ Set[1, 2, 3].to_s.should.is_a?(String)
+ Set["1", "2", "3"].to_s.should.is_a?(String)
+ Set[:a, "b", Set[?c]].to_s.should.is_a?(String)
+ end
+
+ ruby_version_is "4.0" do
+ it "does include the elements of the set" do
+ Set["1"].to_s.should == 'Set["1"]'
+ end
+ end
+
+ ruby_version_is ""..."4.0" do
+ it "does include the elements of the set" do
+ Set["1"].to_s.should == '#<Set: {"1"}>'
+ end
+ end
+
+ it "puts spaces between the elements" do
+ Set["1", "2"].to_s.should.include?('", "')
+ end
+
+ ruby_version_is "4.0" do
+ it "correctly handles cyclic-references" do
+ set1 = Set[]
+ set2 = Set[set1]
+ set1 << set2
+ set1.to_s.should.is_a?(String)
+ set1.to_s.should.include?("Set[...]")
+ end
+ end
- it "is an alias of inspect" do
- set = Set.new
- set.method(:to_s).should == set.method(:inspect)
+ ruby_version_is ""..."4.0" do
+ it "correctly handles cyclic-references" do
+ set1 = Set[]
+ set2 = Set[set1]
+ set1 << set2
+ set1.to_s.should.is_a?(String)
+ set1.to_s.should.include?("#<Set: {...}>")
+ end
end
end
diff --git a/spec/ruby/core/set/union_spec.rb b/spec/ruby/core/set/union_spec.rb
index 3e77022d4b..206535aae2 100644
--- a/spec/ruby/core/set/union_spec.rb
+++ b/spec/ruby/core/set/union_spec.rb
@@ -1,10 +1,23 @@
require_relative '../../spec_helper'
-require_relative 'shared/union'
describe "Set#union" do
- it_behaves_like :set_union, :union
+ it "is an alias of Set#|" do
+ Set.instance_method(:union).should == Set.instance_method(:|)
+ end
end
describe "Set#|" do
- it_behaves_like :set_union, :|
+ before :each do
+ @set = Set[:a, :b, :c]
+ end
+
+ it "returns a new Set containing all elements of self and the passed Enumerable" do
+ (@set | Set[:b, :d, :e]).should == Set[:a, :b, :c, :d, :e]
+ (@set | [:b, :e]).should == Set[:a, :b, :c, :e]
+ end
+
+ it "raises an ArgumentError when passed a non-Enumerable" do
+ -> { @set | 1 }.should.raise(ArgumentError)
+ -> { @set | Object.new }.should.raise(ArgumentError)
+ end
end