Sha256: 212eaa9639416ac0ffa921a02a3171652e517faaea6c000d5a3ae2ad8840fea9

Contents?: true

Size: 1.69 KB

Versions: 2

Compression:

Stored size: 1.69 KB

Contents

require File.dirname(__FILE__) + '/../../spec_helper'
require 'cucumber/core_ext/string'
require 'cucumber/rb_support/rb_group'

describe String, "#gzub" do
  def groups(a)
    a.map{|c| Cucumber::RbSupport::RbGroup.new(c[0], c[1])}
  end
  
  it "should format groups with format string" do
    "I ate 1 egg this morning".gzub(groups([['ate', 2], ['1', 6], ['egg', 8],  ['morning', 17]]), "<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(groups([['bob', 2], ['1', 6], ['bo', 8],  ['bobs', 16]]), "<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(groups([['ate', 2], ['1', 6], ['egg', 8],  ['morning', 17]])) 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(groups([['ate', 2], ['1', 6], ['egg', 8],  ['morning', 17]]), 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(groups([['another', 0], ['member', 8], ['Bob', 21]])) do |m|
      "<span>#{m}</span>"
    end
    f.should == "<span>another</span> <span>member</span> named <span>Bob</span> joins the group"
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
aslakhellesoy-cucumber-0.3.102 spec/cucumber/core_ext/string_spec.rb
cucumber-0.3.102 spec/cucumber/core_ext/string_spec.rb