Skip to content

Commit f25d4b4

Browse files
committed
Move MatchData to rely less on shared examples
1 parent c2da21f commit f25d4b4

9 files changed

Lines changed: 43 additions & 56 deletions

File tree

core/matchdata/captures_spec.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
require_relative '../../spec_helper'
2-
require_relative 'shared/captures'
2+
require_relative 'fixtures/classes'
33

44
describe "MatchData#captures" do
5-
it_behaves_like :matchdata_captures, :captures
5+
it "returns an array of the match captures" do
6+
/(.)(.)(\d+)(\d)/.match("THX1138.").captures.should == ["H","X","113","8"]
7+
end
8+
9+
it "returns instances of String when given a String subclass" do
10+
str = MatchDataSpecs::MyString.new("THX1138: The Movie")
11+
/(.)(.)(\d+)(\d)/.match(str).captures.each { |c| c.should.instance_of?(String) }
12+
end
613
end

core/matchdata/deconstruct_spec.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require_relative '../../spec_helper'
2-
require_relative 'shared/captures'
32

43
describe "MatchData#deconstruct" do
5-
it_behaves_like :matchdata_captures, :deconstruct
4+
it "is an alias of MatchData#captures" do
5+
MatchData.instance_method(:deconstruct).should == MatchData.instance_method(:captures)
6+
end
67
end

core/matchdata/eql_spec.rb

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
11
require_relative '../../spec_helper'
2-
require_relative 'shared/eql'
32

43
describe "MatchData#eql?" do
5-
it_behaves_like :matchdata_eql, :eql?
4+
it "returns true if both operands have equal target strings, patterns, and match positions" do
5+
a = 'haystack'.match(/hay/)
6+
b = 'haystack'.match(/hay/)
7+
a.eql?(b).should == true
8+
end
9+
10+
it "returns false if the operands have different target strings" do
11+
a = 'hay'.match(/hay/)
12+
b = 'haystack'.match(/hay/)
13+
a.eql?(b).should == false
14+
end
15+
16+
it "returns false if the operands have different patterns" do
17+
a = 'haystack'.match(/h.y/)
18+
b = 'haystack'.match(/hay/)
19+
a.eql?(b).should == false
20+
end
21+
22+
it "returns false if the argument is not a MatchData object" do
23+
a = 'haystack'.match(/hay/)
24+
a.eql?(Object.new).should == false
25+
end
626
end

core/matchdata/equal_value_spec.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require_relative '../../spec_helper'
2-
require_relative 'shared/eql'
32

43
describe "MatchData#==" do
5-
it_behaves_like :matchdata_eql, :==
4+
it "is an alias of MatchData#eql?" do
5+
MatchData.instance_method(:==).should == MatchData.instance_method(:eql?)
6+
end
67
end

core/matchdata/length_spec.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require_relative '../../spec_helper'
2-
require_relative 'shared/length'
32

43
describe "MatchData#length" do
5-
it_behaves_like :matchdata_length, :length
4+
it "is an alias of MatchData#size" do
5+
MatchData.instance_method(:length).should == MatchData.instance_method(:size)
6+
end
67
end

core/matchdata/shared/captures.rb

Lines changed: 0 additions & 13 deletions
This file was deleted.

core/matchdata/shared/eql.rb

Lines changed: 0 additions & 26 deletions
This file was deleted.

core/matchdata/shared/length.rb

Lines changed: 0 additions & 5 deletions
This file was deleted.

core/matchdata/size_spec.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require_relative '../../spec_helper'
2-
require_relative 'shared/length'
32

43
describe "MatchData#size" do
5-
it_behaves_like :matchdata_length, :size
4+
it "should return the number of elements in the match array" do
5+
/(.)(.)(\d+)(\d)/.match("THX1138.").size.should == 5
6+
end
67
end

0 commit comments

Comments
 (0)