Sha256: 13fea81cc7088e4641b19648da5090a9f5edeae86c08fab5d480a29883cf34e2

Contents?: true

Size: 1.13 KB

Versions: 2

Compression:

Stored size: 1.13 KB

Contents

module ElabsMatchers
  module Cucumber
    module Common
      ##
      #
      # Matches a comma or the word 'and'.
      #
      # Example:
      # ,
      # and

      LIST_SEPARATOR = %r{(?:,\s|\sand\s)}

      ##
      #
      # Matches a list seperated by LIST_SEPARATOR (, or the word 'and')
      #
      # Example:
      # "foo", "bar" and "baz"

      LIST_REGEXP = %r{(?:"(?:[^\"]*)"#{LIST_SEPARATOR}?)+}

    private

      def human_list_to_array(list)
        list.gsub('"', '').split(LIST_SEPARATOR)
      end
    end
  end
end

module Cucumber
  include ElabsMatchers::Cucumber::Common
end

RSpec.configure do |config|
  config.include ElabsMatchers::Cucumber::Common
end

if defined? World
  ##
  #
  # Transforms a cucumber step so that the list it includes turns into an array
  #
  # Example:
  # Step: Then I should see "Bart", "Lisa" and "Homer"
  # Definition: 
  #   Then /^I should see (#{LIST_REGEXP})$/ do |names|
  #     # names == ["Bart", "Lisa", "Homer"]
  #   end

  Transform /^#{LIST_REGEXP}$/ do |list|
    ElabsMatchers::Cucumber::Common::human_list_to_array(list)
  end

  World(ElabsMatchers::Cucumber::Common)
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
elabs_matchers-0.0.3 lib/elabs_matchers/cucumber/common.rb
elabs_matchers-0.0.1 lib/elabs_matchers/cucumber/common.rb