Skip to content
Permalink
Browse files

Use the new should.predicate style for #start_with specs

  • Loading branch information...
eregon committed Sep 29, 2019
1 parent e69a14c commit a3c52de2cf5858ae452feddb4fd77c9f69e2f6c8
Showing with 19 additions and 19 deletions.
  1. +18 −18 core/string/start_with_spec.rb
  2. +1 −1 library/tmpdir/dir/mktmpdir_spec.rb
@@ -5,29 +5,29 @@
describe "String#start_with?" do
it "returns true only if beginning match" do
s = "hello"
s.start_with?('h').should be_true
s.start_with?('hel').should be_true
s.start_with?('el').should be_false
s.should.start_with?('h')
s.should.start_with?('hel')
s.should_not.start_with?('el')
end

it "returns true only if any beginning match" do
"hello".start_with?('x', 'y', 'he', 'z').should be_true
"hello".should.start_with?('x', 'y', 'he', 'z')
end

it "returns true if the search string is empty" do
"hello".start_with?("").should be_true
"".start_with?("").should be_true
"hello".should.start_with?("")
"".should.start_with?("")
end

it "converts its argument using :to_str" do
s = "hello"
find = mock('h')
find.should_receive(:to_str).and_return("h")
s.start_with?(find).should be_true
s.should.start_with?(find)
end

it "ignores arguments not convertible to string" do
"hello".start_with?().should be_false
"hello".should_not.start_with?()
-> { "hello".start_with?(1) }.should raise_error(TypeError)
-> { "hello".start_with?(["h"]) }.should raise_error(TypeError)
-> { "hello".start_with?(1, nil, "h") }.should raise_error(TypeError)
@@ -36,29 +36,29 @@
it "uses only the needed arguments" do
find = mock('h')
find.should_not_receive(:to_str)
"hello".start_with?("h",find).should be_true
"hello".should.start_with?("h",find)
end

it "works for multibyte strings" do
"céréale".start_with?("cér").should be_true
"céréale".should.start_with?("cér")
end

ruby_version_is "2.5" do
it "supports regexps" do
regexp = /[h1]/
"hello".start_with?(regexp).should be_true
"1337".start_with?(regexp).should be_true
"foxes are 1337".start_with?(regexp).should be_false
"chunky\n12bacon".start_with?(/12/).should be_false
"hello".should.start_with?(regexp)
"1337".should.start_with?(regexp)
"foxes are 1337".should_not.start_with?(regexp)
"chunky\n12bacon".should_not.start_with?(/12/)
end

it "supports regexps with ^ and $ modifiers" do
regexp1 = /^\d{2}/
regexp2 = /\d{2}$/
"12test".start_with?(regexp1).should be_true
"test12".start_with?(regexp1).should be_false
"12test".start_with?(regexp2).should be_false
"test12".start_with?(regexp2).should be_false
"12test".should.start_with?(regexp1)
"test12".should_not.start_with?(regexp1)
"12test".should_not.start_with?(regexp2)
"test12".should_not.start_with?(regexp2)
end

it "sets Regexp.last_match if it returns true" do
@@ -39,7 +39,7 @@
Dir.mktmpdir do |path|
@tmpdir = path
called = true
path.start_with?(@real_tmp_root).should be_true
path.should.start_with?(@real_tmp_root)
end
called.should be_true
end

0 comments on commit a3c52de

Please sign in to comment.
You can’t perform that action at this time.