diff options
Diffstat (limited to 'spec/ruby/core/regexp/case_compare_spec.rb')
| -rw-r--r-- | spec/ruby/core/regexp/case_compare_spec.rb | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/spec/ruby/core/regexp/case_compare_spec.rb b/spec/ruby/core/regexp/case_compare_spec.rb new file mode 100644 index 0000000000..29aada70bc --- /dev/null +++ b/spec/ruby/core/regexp/case_compare_spec.rb @@ -0,0 +1,35 @@ +require_relative '../../spec_helper' + +describe "Regexp#===" do + it "is true if there is a match" do + (/abc/ === "aabcc").should == true + end + + it "is false if there is no match" do + (/abc/ === "xyz").should == false + end + + it "returns true if it matches a Symbol" do + (/a/ === :a).should == true + end + + it "returns false if it does not match a Symbol" do + (/a/ === :b).should == false + end + + # mirroring https://github.com/ruby/ruby/blob/master/test/ruby/test_regexp.rb + it "returns false if the other value cannot be coerced to a string" do + (/abc/ === nil).should == false + (/abc/ === /abc/).should == false + end + + it "uses #to_str on string-like objects" do + stringlike = Class.new do + def to_str + "abc" + end + end.new + + (/abc/ === stringlike).should == true + end +end |
