Class: Cucumber::Cli::ProfileLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/cucumber/cli/profile_loader.rb

Instance Method Summary collapse

Constructor Details

#initializeProfileLoader



8
9
10
# File 'lib/cucumber/cli/profile_loader.rb', line 8

def initialize
  @cucumber_yml = nil
end

Instance Method Details

#args_from(profile) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/cucumber/cli/profile_loader.rb', line 12

def args_from(profile)
  unless cucumber_yml.key?(profile)
    raise(ProfileNotFound, "Could not find profile: '\#{profile}'\n\nDefined profiles in cucumber.yml:\n* \#{cucumber_yml.keys.sort.join(\"\\n  * \")}\n")
  end

  args_from_yml = cucumber_yml[profile] || ''

  require 'shellwords'

  case args_from_yml
  when String
    raise YmlLoadError, "The '#{profile}' profile in cucumber.yml was blank.  Please define the command line arguments for the '#{profile}' profile in cucumber.yml.\n" if args_from_yml =~ /^\s*$/
    if Cucumber::WINDOWS
      # Shellwords treats backslash as an escape character so we have to mask it out temporarily

      placeholder = 'pseudo_unique_backslash_placeholder'
      sanitized_line = args_from_yml.gsub('\\', placeholder)

      args_from_yml = Shellwords.shellwords(sanitized_line).collect { |argument| argument.gsub(placeholder, '\\') }
    else
      args_from_yml = Shellwords.shellwords(args_from_yml)
    end
  when Array
    raise YmlLoadError, "The '#{profile}' profile in cucumber.yml was empty.  Please define the command line arguments for the '#{profile}' profile in cucumber.yml.\n" if args_from_yml.empty?
  else
    raise YmlLoadError, "The '#{profile}' profile in cucumber.yml was a #{args_from_yml.class}. It must be a String or Array"
  end

  args_from_yml
end

#cucumber_yml_defined?Boolean



52
53
54
# File 'lib/cucumber/cli/profile_loader.rb', line 52

def cucumber_yml_defined?
  cucumber_file && File.exist?(cucumber_file)
end

#has_profile?(profile) ⇒ Boolean



48
49
50
# File 'lib/cucumber/cli/profile_loader.rb', line 48

def has_profile?(profile)
  cucumber_yml.key?(profile)
end