spec/extensions/string_spec.rb in ronin-support-0.5.1 vs spec/extensions/string_spec.rb in ronin-support-0.5.2

- old
+ new

@@ -5,175 +5,176 @@ describe "#each_substring" do subject { 'hello' } it "should enumerate over each sub-string within the String" do subject.each_substring do |sub_string| - should include(sub_string) + expect(subject).to include(sub_string) end end it "should allow passing the string index back" do subject.each_substring do |sub_string,index| - subject[index,sub_string.length].should == sub_string + expect(subject[index,sub_string.length]).to eq(sub_string) - should include(sub_string) + expect(subject).to include(sub_string) end end it "should enumerate over each sub-string of a minimum length" do subject.each_substring(2) do |sub_string| - sub_string.length.should >= 2 + expect(sub_string.length).to be >= 2 - should include(sub_string) + expect(subject).to include(sub_string) end end it "should return an Enumerator when no block is given" do substrings = subject.each_substring - substrings.all? { |sub_string| + expect(substrings.all? { |sub_string| subject.include?(sub_string) - }.should == true + }).to be(true) end end describe "#each_unique_substring" do subject { 'abablol' } it "should enumerate over each unique sub-string within the String" do seen = [] subject.each_unique_substring do |sub_string| - should include(sub_string) - seen.should_not include(sub_string) + expect(subject).to include(sub_string) + expect(seen).to_not include(sub_string) seen << sub_string end end it "should enumerate over each sub-string of a minimum length" do seen = [] subject.each_unique_substring(2) do |sub_string| - sub_string.length.should >= 2 + expect(sub_string.length).to be >= 2 - should include(sub_string) - seen.should_not include(sub_string) + expect(subject).to include(sub_string) + expect(seen).to_not include(sub_string) seen << sub_string end end it "should return an Enumerator when no block is given" do seen = subject.each_unique_substring - seen.all? { |sub_string| + expect(seen.all? { |sub_string| subject.include?(sub_string) - }.should == true + }).to be(true) seen = seen.to_a - seen.uniq.should == seen + + expect(seen.uniq).to eq(seen) end end describe "#common_prefix" do it "should find the common prefix between two Strings" do one = 'What is puzzling you is the nature of my game' two = 'What is puzzling you is the nature of my name' common = 'What is puzzling you is the nature of my ' - one.common_prefix(two).should == common + expect(one.common_prefix(two)).to eq(common) end it "should return the common prefix between two Strings with no uncommon postfix" do one = "1234" two = "12345" common = "1234" - one.common_prefix(two).should == common + expect(one.common_prefix(two)).to eq(common) end it "should return an empty String if there is no common prefix" do one = 'Tell me people' two = 'Whats my name' - one.common_prefix(two).should == '' + expect(one.common_prefix(two)).to eq('') end it "should return an empty String if one of the strings is also empty" do one = 'Haha' two = '' - one.common_prefix(two).should == '' + expect(one.common_prefix(two)).to eq('') end end describe "#common_suffix" do it "should find the common postfix between two Strings" do one = 'Tell me baby whats my name' two = "Can't you guess my name" common = 's my name' - one.common_suffix(two).should == common + expect(one.common_suffix(two)).to eq(common) end it "should return an empty String if there is no common postfix" do one = 'You got to right up, stand up' two = 'stand up for your rights' - one.common_suffix(two).should == '' + expect(one.common_suffix(two)).to eq('') end it "should return an empty String if one of the strings is also empty" do one = 'You and I must fight for our rights' two = '' - one.common_suffix(two).should == '' + expect(one.common_suffix(two)).to eq('') end end describe "#uncommon_substring" do it "should find the uncommon substring between two Strings" do one = "Tell me baby whats my name" two = "Tell me honey whats my name" uncommon = 'bab' - one.uncommon_substring(two).should == uncommon + expect(one.uncommon_substring(two)).to eq(uncommon) end it "should find the uncommon substring between two Strings with a common prefix" do one = 'You and I must fight for our rights' two = 'You and I must fight to survive' uncommon = 'for our rights' - one.uncommon_substring(two).should == uncommon + expect(one.uncommon_substring(two)).to eq(uncommon) end it "should find the uncommon substring between two Strings with a common postfix" do one = 'Tell me baby whats my name' two = "Can't you guess my name" uncommon = 'Tell me baby what' - one.uncommon_substring(two).should == uncommon + expect(one.uncommon_substring(two)).to eq(uncommon) end end if RUBY_VERSION < '1.9.' describe "#dump" do it "should dump printable strings" do - "hello".dump.should == '"hello"' + expect("hello".dump).to eq('"hello"') end it "should dump strings containing control characters" do - "hello\n\b\a".dump.should == '"hello\n\b\a"' + expect("hello\n\b\a".dump).to eq('"hello\n\b\a"') end it "should dump strings containing non-printable characters" do - "hello\x90\x05\xEF".dump.should == '"hello\x90\x05\xEF"' + expect("hello\x90\x05\xEF".dump).to eq('"hello\x90\x05\xEF"') end it "should dump the string when calling the inspect method" do - "hello\x90\x05\xEF".inspect.should == '"hello\x90\x05\xEF"' + expect("hello\x90\x05\xEF".inspect).to eq('"hello\x90\x05\xEF"') end end end end