module Unobtainium::Cucumber::Action::Support

Support functions for actions

Public Instance Methods

base_filename(scenario, tag = nil, timestamp = nil) click to toggle source

Given a cucumber scenario, this function returns a timestamped base filename (without extension) that reflects parts of the scenario name. Note that the optional tag is not related to cucumber tags. It's just a way to distinguish two filenames for the same scenario at the same timestamp. We use '_' as a replacement for unrenderable characters, and '-' as a separator between file name components.

# File lib/unobtainium-cucumber/action/support/naming.rb, line 26
def base_filename(scenario, tag = nil, timestamp = nil)
  # Build base name from parameters
  require 'time'
  timestamp ||= Time.now.utc.iso8601
  timestamp.tr!('-', '_')
  scenario_name = scenario.name
  base_name = [timestamp, tag, scenario_name].reject(&:nil?).join('-')

  # Make base name filename safe
  base_name.gsub!(%r{^.*(\\|/)}, '')
  base_name.gsub!(/[^0-9A-Za-z.\-]+/, '_')

  return base_name
end