summaryrefslogtreecommitdiff
path: root/spec/ruby/core/matchdata
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/matchdata')
-rw-r--r--spec/ruby/core/matchdata/captures_spec.rb11
-rw-r--r--spec/ruby/core/matchdata/deconstruct_spec.rb5
-rw-r--r--spec/ruby/core/matchdata/eql_spec.rb5
-rw-r--r--spec/ruby/core/matchdata/equal_value_spec.rb24
-rw-r--r--spec/ruby/core/matchdata/length_spec.rb5
-rw-r--r--spec/ruby/core/matchdata/shared/captures.rb13
-rw-r--r--spec/ruby/core/matchdata/shared/eql.rb26
-rw-r--r--spec/ruby/core/matchdata/shared/length.rb5
-rw-r--r--spec/ruby/core/matchdata/size_spec.rb5
9 files changed, 43 insertions, 56 deletions
diff --git a/spec/ruby/core/matchdata/captures_spec.rb b/spec/ruby/core/matchdata/captures_spec.rb
index f829a25481..fdbc1c4346 100644
--- a/spec/ruby/core/matchdata/captures_spec.rb
+++ b/spec/ruby/core/matchdata/captures_spec.rb
@@ -1,6 +1,13 @@
require_relative '../../spec_helper'
-require_relative 'shared/captures'
+require_relative 'fixtures/classes'
describe "MatchData#captures" do
- it_behaves_like :matchdata_captures, :captures
+ it "returns an array of the match captures" do
+ /(.)(.)(\d+)(\d)/.match("THX1138.").captures.should == ["H","X","113","8"]
+ end
+
+ it "returns instances of String when given a String subclass" do
+ str = MatchDataSpecs::MyString.new("THX1138: The Movie")
+ /(.)(.)(\d+)(\d)/.match(str).captures.each { |c| c.should.instance_of?(String) }
+ end
end
diff --git a/spec/ruby/core/matchdata/deconstruct_spec.rb b/spec/ruby/core/matchdata/deconstruct_spec.rb
index c55095665d..13ebd1848f 100644
--- a/spec/ruby/core/matchdata/deconstruct_spec.rb
+++ b/spec/ruby/core/matchdata/deconstruct_spec.rb
@@ -1,6 +1,7 @@
require_relative '../../spec_helper'
-require_relative 'shared/captures'
describe "MatchData#deconstruct" do
- it_behaves_like :matchdata_captures, :deconstruct
+ it "is an alias of MatchData#captures" do
+ MatchData.instance_method(:deconstruct).should == MatchData.instance_method(:captures)
+ end
end
diff --git a/spec/ruby/core/matchdata/eql_spec.rb b/spec/ruby/core/matchdata/eql_spec.rb
index 1d9666ebe1..937c4424aa 100644
--- a/spec/ruby/core/matchdata/eql_spec.rb
+++ b/spec/ruby/core/matchdata/eql_spec.rb
@@ -1,6 +1,7 @@
require_relative '../../spec_helper'
-require_relative 'shared/eql'
describe "MatchData#eql?" do
- it_behaves_like :matchdata_eql, :eql?
+ it "is an alias of MatchData#==" do
+ MatchData.instance_method(:eql?).should == MatchData.instance_method(:==)
+ end
end
diff --git a/spec/ruby/core/matchdata/equal_value_spec.rb b/spec/ruby/core/matchdata/equal_value_spec.rb
index a58f1277e4..74d3a5adcd 100644
--- a/spec/ruby/core/matchdata/equal_value_spec.rb
+++ b/spec/ruby/core/matchdata/equal_value_spec.rb
@@ -1,6 +1,26 @@
require_relative '../../spec_helper'
-require_relative 'shared/eql'
describe "MatchData#==" do
- it_behaves_like :matchdata_eql, :==
+ it "returns true if both operands have equal target strings, patterns, and match positions" do
+ a = 'haystack'.match(/hay/)
+ b = 'haystack'.match(/hay/)
+ a.==(b).should == true
+ end
+
+ it "returns false if the operands have different target strings" do
+ a = 'hay'.match(/hay/)
+ b = 'haystack'.match(/hay/)
+ a.==(b).should == false
+ end
+
+ it "returns false if the operands have different patterns" do
+ a = 'haystack'.match(/h.y/)
+ b = 'haystack'.match(/hay/)
+ a.==(b).should == false
+ end
+
+ it "returns false if the argument is not a MatchData object" do
+ a = 'haystack'.match(/hay/)
+ a.==(Object.new).should == false
+ end
end
diff --git a/spec/ruby/core/matchdata/length_spec.rb b/spec/ruby/core/matchdata/length_spec.rb
index 39df36df4b..72d4d80cec 100644
--- a/spec/ruby/core/matchdata/length_spec.rb
+++ b/spec/ruby/core/matchdata/length_spec.rb
@@ -1,6 +1,7 @@
require_relative '../../spec_helper'
-require_relative 'shared/length'
describe "MatchData#length" do
- it_behaves_like :matchdata_length, :length
+ it "is an alias of MatchData#size" do
+ MatchData.instance_method(:length).should == MatchData.instance_method(:size)
+ end
end
diff --git a/spec/ruby/core/matchdata/shared/captures.rb b/spec/ruby/core/matchdata/shared/captures.rb
deleted file mode 100644
index de5870f543..0000000000
--- a/spec/ruby/core/matchdata/shared/captures.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-require_relative '../../../spec_helper'
-require_relative '../fixtures/classes'
-
-describe :matchdata_captures, shared: true do
- it "returns an array of the match captures" do
- /(.)(.)(\d+)(\d)/.match("THX1138.").send(@method).should == ["H","X","113","8"]
- end
-
- it "returns instances of String when given a String subclass" do
- str = MatchDataSpecs::MyString.new("THX1138: The Movie")
- /(.)(.)(\d+)(\d)/.match(str).send(@method).each { |c| c.should.instance_of?(String) }
- end
-end
diff --git a/spec/ruby/core/matchdata/shared/eql.rb b/spec/ruby/core/matchdata/shared/eql.rb
deleted file mode 100644
index e4bb8797b7..0000000000
--- a/spec/ruby/core/matchdata/shared/eql.rb
+++ /dev/null
@@ -1,26 +0,0 @@
-require_relative '../../../spec_helper'
-
-describe :matchdata_eql, shared: true do
- it "returns true if both operands have equal target strings, patterns, and match positions" do
- a = 'haystack'.match(/hay/)
- b = 'haystack'.match(/hay/)
- a.send(@method, b).should == true
- end
-
- it "returns false if the operands have different target strings" do
- a = 'hay'.match(/hay/)
- b = 'haystack'.match(/hay/)
- a.send(@method, b).should == false
- end
-
- it "returns false if the operands have different patterns" do
- a = 'haystack'.match(/h.y/)
- b = 'haystack'.match(/hay/)
- a.send(@method, b).should == false
- end
-
- it "returns false if the argument is not a MatchData object" do
- a = 'haystack'.match(/hay/)
- a.send(@method, Object.new).should == false
- end
-end
diff --git a/spec/ruby/core/matchdata/shared/length.rb b/spec/ruby/core/matchdata/shared/length.rb
deleted file mode 100644
index 6312a7ed4c..0000000000
--- a/spec/ruby/core/matchdata/shared/length.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-describe :matchdata_length, shared: true do
- it "length should return the number of elements in the match array" do
- /(.)(.)(\d+)(\d)/.match("THX1138.").send(@method).should == 5
- end
-end
diff --git a/spec/ruby/core/matchdata/size_spec.rb b/spec/ruby/core/matchdata/size_spec.rb
index b4965db3b8..f93ded72cb 100644
--- a/spec/ruby/core/matchdata/size_spec.rb
+++ b/spec/ruby/core/matchdata/size_spec.rb
@@ -1,6 +1,7 @@
require_relative '../../spec_helper'
-require_relative 'shared/length'
describe "MatchData#size" do
- it_behaves_like :matchdata_length, :size
+ it "should return the number of elements in the match array" do
+ /(.)(.)(\d+)(\d)/.match("THX1138.").size.should == 5
+ end
end