require File.dirname(__FILE__) + '/../../../lib/cucumber/core_ext/string'
describe String, "#gzub" do
it "should format groups with format string" do
"I ate 1 egg this morning".gzub(/I (\w+) (\d+) (\w+) this (\w+)/, "%s").should ==
"I ate 1 egg this morning"
end
it "should format groups with format string when there are dupes" do
"I bob 1 bo this bobs".gzub(/I (\w+) (\d+) (\w+) this (\w+)/, "%s").should ==
"I bob 1 bo this bobs"
end
it "should format groups with block" do
f = "I ate 1 egg this morning".gzub(/I (\w+) (\d+) (\w+) this (\w+)/) do |m|
"#{m}"
end
f.should == "I ate 1 egg this morning"
end
it "should format groups with proc object" do
proc = lambda do |m|
"#{m}"
end
f = "I ate 1 egg this morning".gzub(/I (\w+) (\d+) (\w+) this (\w+)/, proc)
f.should == "I ate 1 egg this morning"
end
it "should format groups with block with not all placeholders having a value" do
f = "another member named Bob joins the group".gzub(/(a|another) (user|member) named ([^ ]+)( who is not logged in)?/) do |m|
"#{m}"
end
f.should == "another member named Bob joins the group"
end
it "should format match groups in a textile table row" do
f = "I ate 1 egg this morning".gzub(/I (\w+) (\d+) (\w+) this (\w+)/) do |m|
"#{m}"
end
f.should == "I ate 1 egg this morning"
end
end