Sha256: 2f8213dadb967bbb011a920e8b0cfab366c7d062f342a599e5fbd02c56436416

Contents?: true

Size: 1.73 KB

Versions: 138

Compression:

Stored size: 1.73 KB

Contents

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+)/, "<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
    "I bob 1 bo this bobs".gzub(/I (\w+) (\d+) (\w+) this (\w+)/, "<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
    f = "I ate 1 egg this morning".gzub(/I (\w+) (\d+) (\w+) this (\w+)/) do |m|
      "<span>#{m}</span>"
    end
    f.should == "I <span>ate</span> <span>1</span> <span>egg</span> this <span>morning</span>"
  end

  it "should format groups with proc object" do
    proc = lambda do |m|
      "<span>#{m}</span>"
    end
    f = "I ate 1 egg this morning".gzub(/I (\w+) (\d+) (\w+) this (\w+)/, proc)
    f.should == "I <span>ate</span> <span>1</span> <span>egg</span> this <span>morning</span>"
  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|
      "<span>#{m}</span>"
    end
    f.should == "<span>another</span> <span>member</span> named <span>Bob</span> 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|
      "<span>#{m}</span>"
    end
    f.should == "I <span>ate</span> <span>1</span> <span>egg</span> this <span>morning</span>"
  end
end

Version data entries

138 entries across 138 versions & 10 rubygems

Version Path
aslakhellesoy-cucumber-0.1.100.1 spec/cucumber/core_ext/string_spec.rb
aslakhellesoy-cucumber-0.1.100.2 spec/cucumber/core_ext/string_spec.rb
aslakhellesoy-cucumber-0.1.100.3 spec/cucumber/core_ext/string_spec.rb
aslakhellesoy-cucumber-0.1.100.4 spec/cucumber/core_ext/string_spec.rb
aslakhellesoy-cucumber-0.1.100.5 spec/cucumber/core_ext/string_spec.rb
aslakhellesoy-cucumber-0.1.16.5 spec/cucumber/core_ext/string_spec.rb
aslakhellesoy-cucumber-0.1.99.1 spec/cucumber/core_ext/string_spec.rb
aslakhellesoy-cucumber-0.1.99.10 spec/cucumber/core_ext/string_spec.rb
aslakhellesoy-cucumber-0.1.99.11 spec/cucumber/core_ext/string_spec.rb
aslakhellesoy-cucumber-0.1.99.12 spec/cucumber/core_ext/string_spec.rb
aslakhellesoy-cucumber-0.1.99.13 spec/cucumber/core_ext/string_spec.rb
aslakhellesoy-cucumber-0.1.99.14 spec/cucumber/core_ext/string_spec.rb
aslakhellesoy-cucumber-0.1.99.15 spec/cucumber/core_ext/string_spec.rb
aslakhellesoy-cucumber-0.1.99.17 spec/cucumber/core_ext/string_spec.rb
aslakhellesoy-cucumber-0.1.99.18 spec/cucumber/core_ext/string_spec.rb
aslakhellesoy-cucumber-0.1.99.19 spec/cucumber/core_ext/string_spec.rb
aslakhellesoy-cucumber-0.1.99.2 spec/cucumber/core_ext/string_spec.rb
aslakhellesoy-cucumber-0.1.99.20 spec/cucumber/core_ext/string_spec.rb
aslakhellesoy-cucumber-0.1.99.21 spec/cucumber/core_ext/string_spec.rb
aslakhellesoy-cucumber-0.1.99.22 spec/cucumber/core_ext/string_spec.rb