require File.dirname(__FILE__) + '/../spec_helper'
require 'cucumber/rb_support/rb_step_definition'
require 'cucumber/rb_support/rb_language'
module Cucumber
describe StepMatch do
before do
@rb_language = RbSupport::RbLanguage.new(nil)
end
def stepdef(regexp)
RbSupport::RbStepDefinition.new(@rb_language, regexp, lambda{})
end
it "should format groups with format string" do
m = stepdef(/I (\w+) (\d+) (\w+) this (\w+)/).step_match("I ate 1 egg this morning", nil)
m.format_args("%s").should == "I ate 1 egg this morning"
end
it "should format groups with format string when there are dupes" do
m = stepdef(/I (\w+) (\d+) (\w+) this (\w+)/).step_match("I bob 1 bo this bobs", nil)
m.format_args("%s").should == "I bob 1 bo this bobs"
end
it "should format groups with block" do
m = stepdef(/I (\w+) (\d+) (\w+) this (\w+)/).step_match("I ate 1 egg this morning", nil)
m.format_args(&lambda{|m| "#{m}"}).should == "I ate 1 egg this morning"
end
it "should format groups with proc object" do
m = stepdef(/I (\w+) (\d+) (\w+) this (\w+)/).step_match("I ate 1 egg this morning", nil)
m.format_args(lambda{|m| "#{m}"}).should == "I ate 1 egg this morning"
end
it "should format groups even when first group is optional and not matched" do
m = stepdef(/should( not)? be flashed '([^']*?)'$/).step_match("I should be flashed 'Login failed.'", nil)
m.format_args("%s").should == "I should be flashed 'Login failed.'"
end
end
end