From 2608faeddfaa9879bed32517dc8fccd9406ce592 Mon Sep 17 00:00:00 2001 From: Syed Aslam Date: Fri, 8 Oct 2021 01:31:37 +0200 Subject: [PATCH 1/2] add Set#join spec --- library/set/join_spec.rb | 13 +++++++++++++ library/set/shared/join.rb | 25 +++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 library/set/join_spec.rb create mode 100644 library/set/shared/join.rb diff --git a/library/set/join_spec.rb b/library/set/join_spec.rb new file mode 100644 index 0000000000..cba7d39aef --- /dev/null +++ b/library/set/join_spec.rb @@ -0,0 +1,13 @@ +require_relative '../../spec_helper' +require_relative 'shared/join' +require 'set' + +ruby_version_is "3.0" do + describe "Set#join" do + it "returns an empty string if the Set is empty" do + Set[].join.should == '' + end + + it_behaves_like :set_join, :join + end +end diff --git a/library/set/shared/join.rb b/library/set/shared/join.rb new file mode 100644 index 0000000000..c48f3ab143 --- /dev/null +++ b/library/set/shared/join.rb @@ -0,0 +1,25 @@ +require_relative '../../../spec_helper' +require 'set' + +describe :set_join, shared: true do + before :each do + @set = Set[:a, :b, :c] + end + + it "returns a new string formed by joining elements after conversion" do + @set.send(@method).should == "abc" + end + + it "does not separate elements when the passed separator is nil" do + @set.send(@method, nil).should == "abc" + end + + it "returns a string formed by concatenating each element separated by the separator" do + @set.send(@method, ' | ').should == "a | b | c" + end + + it "calls #to_a to convert the Set in to an Array" do + @set.should_receive(:to_a).and_return([:a, :b, :c]) + @set.send(@method).should == "abc" + end +end From 9072fd853684db7b699dfa096df6b950be234920 Mon Sep 17 00:00:00 2001 From: Syed Aslam Date: Fri, 8 Oct 2021 14:22:34 +0200 Subject: [PATCH 2/2] remove shared/join --- library/set/join_spec.rb | 22 ++++++++++++++++++++-- library/set/shared/join.rb | 25 ------------------------- 2 files changed, 20 insertions(+), 27 deletions(-) delete mode 100644 library/set/shared/join.rb diff --git a/library/set/join_spec.rb b/library/set/join_spec.rb index cba7d39aef..7498a91d98 100644 --- a/library/set/join_spec.rb +++ b/library/set/join_spec.rb @@ -1,5 +1,4 @@ require_relative '../../spec_helper' -require_relative 'shared/join' require 'set' ruby_version_is "3.0" do @@ -8,6 +7,25 @@ Set[].join.should == '' end - it_behaves_like :set_join, :join + it "returns a new string formed by joining elements after conversion" do + set = Set[:a, :b, :c] + set.join.should == "abc" + end + + it "does not separate elements when the passed separator is nil" do + set = Set[:a, :b, :c] + set.join(nil).should == "abc" + end + + it "returns a string formed by concatenating each element separated by the separator" do + set = Set[:a, :b, :c] + set.join(' | ').should == "a | b | c" + end + + it "calls #to_a to convert the Set in to an Array" do + set = Set[:a, :b, :c] + set.should_receive(:to_a).and_return([:a, :b, :c]) + set.join.should == "abc" + end end end diff --git a/library/set/shared/join.rb b/library/set/shared/join.rb deleted file mode 100644 index c48f3ab143..0000000000 --- a/library/set/shared/join.rb +++ /dev/null @@ -1,25 +0,0 @@ -require_relative '../../../spec_helper' -require 'set' - -describe :set_join, shared: true do - before :each do - @set = Set[:a, :b, :c] - end - - it "returns a new string formed by joining elements after conversion" do - @set.send(@method).should == "abc" - end - - it "does not separate elements when the passed separator is nil" do - @set.send(@method, nil).should == "abc" - end - - it "returns a string formed by concatenating each element separated by the separator" do - @set.send(@method, ' | ').should == "a | b | c" - end - - it "calls #to_a to convert the Set in to an Array" do - @set.should_receive(:to_a).and_return([:a, :b, :c]) - @set.send(@method).should == "abc" - end -end