Skip to content

Commit

Permalink
Added some RDoc and a better spec
Browse files Browse the repository at this point in the history
  • Loading branch information
aslakhellesoy committed Sep 23, 2009
1 parent c531f4a commit d1cf53e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 18 deletions.
8 changes: 8 additions & 0 deletions lib/cucumber/rb_support/rb_group.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
module Cucumber
module RbSupport
# A Group encapsulates data from a regexp match.
# A Group instance has to attributes:
#
# * The value of the group
# * The start index from the matched string where the group value starts
#
# See rb_group_spec.rb for examples
#
class RbGroup
attr_reader :val, :start

Expand Down
45 changes: 27 additions & 18 deletions spec/cucumber/rb_support/rb_group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,37 @@
module Cucumber
module RbSupport
describe RbGroup do
it "should format groups with format string" do
d = RbStepDefinition.new(nil, /I (\w+) (\d+) (\w+) this (\w+)/, lambda{})
m = d.step_match("I ate 1 egg this morning", nil)
m.format_args("<span>%s</span>").should == "I <span>ate</span> <span>1</span> <span>egg</span> this <span>morning</span>"
context "Creating groups" do
it "should create 2 groups" do
groups = RbGroup.groups_from(/I (\w+) (\w+)/, "I like fish")
groups.map{|group| [group.val, group.start]}.should == [["like", 2], ["fish", 7]]
end
end

context "Formatting arguments" do
it "should format groups with format string" do
d = RbStepDefinition.new(nil, /I (\w+) (\d+) (\w+) this (\w+)/, lambda{})
m = d.step_match("I ate 1 egg this morning", nil)
m.format_args("<span>%s</span>").should == "I <span>ate</span> <span>1</span> <span>egg</span> this <span>morning</span>"
end

it "should format groups with format string when there are dupes" do
d = RbStepDefinition.new(nil, /I (\w+) (\d+) (\w+) this (\w+)/, lambda{})
m = d.step_match("I bob 1 bo this bobs", nil)
m.format_args("<span>%s</span>").should == "I <span>bob</span> <span>1</span> <span>bo</span> this <span>bobs</span>"
end
it "should format groups with format string when there are dupes" do
d = RbStepDefinition.new(nil, /I (\w+) (\d+) (\w+) this (\w+)/, lambda{})
m = d.step_match("I bob 1 bo this bobs", nil)
m.format_args("<span>%s</span>").should == "I <span>bob</span> <span>1</span> <span>bo</span> this <span>bobs</span>"
end

it "should format groups with block" do
d = RbStepDefinition.new(nil, /I (\w+) (\d+) (\w+) this (\w+)/, lambda{})
m = d.step_match("I ate 1 egg this morning", nil)
m.format_args(&lambda{|m| "<span>#{m}</span>"}).should == "I <span>ate</span> <span>1</span> <span>egg</span> this <span>morning</span>"
end
it "should format groups with block" do
d = RbStepDefinition.new(nil, /I (\w+) (\d+) (\w+) this (\w+)/, lambda{})
m = d.step_match("I ate 1 egg this morning", nil)
m.format_args(&lambda{|m| "<span>#{m}</span>"}).should == "I <span>ate</span> <span>1</span> <span>egg</span> this <span>morning</span>"
end

it "should format groups with proc object" do
d = RbStepDefinition.new(nil, /I (\w+) (\d+) (\w+) this (\w+)/, lambda{})
m = d.step_match("I ate 1 egg this morning", nil)
m.format_args(lambda{|m| "<span>#{m}</span>"}).should == "I <span>ate</span> <span>1</span> <span>egg</span> this <span>morning</span>"
it "should format groups with proc object" do
d = RbStepDefinition.new(nil, /I (\w+) (\d+) (\w+) this (\w+)/, lambda{})
m = d.step_match("I ate 1 egg this morning", nil)
m.format_args(lambda{|m| "<span>#{m}</span>"}).should == "I <span>ate</span> <span>1</span> <span>egg</span> this <span>morning</span>"
end
end
end
end
Expand Down

0 comments on commit d1cf53e

Please sign in to comment.