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.99.23 spec/cucumber/core_ext/string_spec.rb
aslakhellesoy-cucumber-0.1.99.3 spec/cucumber/core_ext/string_spec.rb
aslakhellesoy-cucumber-0.1.99.5 spec/cucumber/core_ext/string_spec.rb
aslakhellesoy-cucumber-0.1.99.6 spec/cucumber/core_ext/string_spec.rb
aslakhellesoy-cucumber-0.1.99.7 spec/cucumber/core_ext/string_spec.rb
aslakhellesoy-cucumber-0.1.99.8 spec/cucumber/core_ext/string_spec.rb
aslakhellesoy-cucumber-0.1.99.9 spec/cucumber/core_ext/string_spec.rb
aslakhellesoy-cucumber-0.2.0.1 spec/cucumber/core_ext/string_spec.rb
aslakhellesoy-cucumber-0.2.0.2 spec/cucumber/core_ext/string_spec.rb
aslakhellesoy-cucumber-0.2.0.3 spec/cucumber/core_ext/string_spec.rb
aslakhellesoy-cucumber-0.2.0.4 spec/cucumber/core_ext/string_spec.rb
aslakhellesoy-cucumber-0.2.0 spec/cucumber/core_ext/string_spec.rb
aslakhellesoy-cucumber-0.2.1 spec/cucumber/core_ext/string_spec.rb
aslakhellesoy-cucumber-0.2.2.1 spec/cucumber/core_ext/string_spec.rb
aslakhellesoy-cucumber-0.2.2.2 spec/cucumber/core_ext/string_spec.rb
aslakhellesoy-cucumber-0.2.2 spec/cucumber/core_ext/string_spec.rb
aslakhellesoy-cucumber-0.2.3.1 specs/cucumber/core_ext/string_spec.rb
aslakhellesoy-cucumber-0.2.3.2 spec/cucumber/core_ext/string_spec.rb
aslakhellesoy-cucumber-0.2.3.3 spec/cucumber/core_ext/string_spec.rb
aslakhellesoy-cucumber-0.2.3.4 spec/cucumber/core_ext/string_spec.rb