# encoding: utf-8 require 'spec_helper' require 'cucumber/rb_support/rb_step_definition' require 'cucumber/rb_support/rb_language' module Cucumber describe StepMatch do WORD = '[[:word:]]' before do @rb_language = RbSupport::RbLanguage.new(nil) end def stepdef(regexp) RbSupport::RbStepDefinition.new(@rb_language, regexp, lambda{}, {}) end def step_match(regexp, name) stepdef = stepdef(regexp) StepMatch.new(stepdef, name, nil, stepdef.arguments_from(name)) end it "formats one group when we use Unicode" do m = step_match(/I (#{WORD}+) ok/, "I æøåÆØÅæøåÆØÅæøåÆØÅæøåÆØÅ ok") expect(m.format_args("%s")).to eq "I æøåÆØÅæøåÆØÅæøåÆØÅæøåÆØÅ ok" end it "formats several groups when we use Unicode" do m = step_match(/I (#{WORD}+) (#{WORD}+) (#{WORD}+) this (#{WORD}+)/, "I ate æøåÆØÅæøåÆØÅæøåÆØÅæøåÆØÅ egg this morning") expect(m.format_args("%s")).to eq "I ate æøåÆØÅæøåÆØÅæøåÆØÅæøåÆØÅ egg this morning" end it "deals with Unicode both inside and outside arguments" do expect("Jæ vø ålsker døtte løndet").to match /Jæ (.+) ålsker (.+) løndet/ m = step_match(/Jæ (#{WORD}+) ålsker (#{WORD}+) løndet/, "Jæ vø ålsker døtte løndet") expect(m.format_args("%s")).to eq "Jæ ålsker døtte løndet" end it "formats groups with format string" do m = step_match(/I (#{WORD}+) (\d+) (#{WORD}+) this (#{WORD}+)/, "I ate 1 egg this morning") expect(m.format_args("%s")).to eq "I ate 1 egg this morning" end it "formats groups with format string when there are dupes" do m = step_match(/I (#{WORD}+) (\d+) (#{WORD}+) this (#{WORD}+)/, "I bob 1 bo this bobs") expect(m.format_args("%s")).to eq "I bob 1 bo this bobs" end it "formats groups with block" do m = step_match(/I (#{WORD}+) (\d+) (#{WORD}+) this (#{WORD}+)/, "I ate 1 egg this morning") expect(m.format_args(&lambda{|m| "#{m}"})).to eq "I ate 1 egg this morning" end it "formats groups with proc object" do m = step_match(/I (#{WORD}+) (\d+) (#{WORD}+) this (#{WORD}+)/, "I ate 1 egg this morning") expect(m.format_args(lambda{|m| "#{m}"})).to eq "I ate 1 egg this morning" end it "formats groups even when first group is optional and not matched" do m = step_match(/should( not)? be flashed '([^']*?)'$/, "I should be flashed 'Login failed.'") expect(m.format_args("%s")).to eq "I should be flashed 'Login failed.'" end it "formats embedded groups" do m = step_match(/running( (\d+) times)? (\d+) meters/, "running 5 times 10 meters") expect(m.format_args("%s")).to eq "running 5 times 10 meters" end end end