class Cuesmash::Cucumber

Provides a nice interface to cucumber, allowing us to run the cucumber test suite

@author [alexfish]

Attributes

format[RW]

Public: the output format for the tests

output[RW]

Public: the output directory for the tests

profile[RW]

Public: the cucumber profile to use for the tests

quiet[RW]

Public: the cucumber quiet flag

Public Class Methods

new(tags, profile, quiet) click to toggle source

Create a new instance of Cucumber @param ios [String] The iOS version cucumber will run @param tags [Array] The tags cucumber will run with @param profile [String] the cucumber profile to use for the tests @param quiet [Boolean]

# File lib/cuesmash/cucumber.rb, line 31
def initialize(tags, profile, quiet)
  @tags = tags
  @profile = profile
  @quiet = quiet
end

Public Instance Methods

test() click to toggle source

Run the cucumber tests

# File lib/cuesmash/cucumber.rb, line 40
def test
  started

  status = nil

  Open3.popen3(command) do |_stdin, stdout, stderr, wait_thr|
    [stdout, stderr].each do |stream|
      Thread.new do
        until (line = stream.gets).nil?
          Logger.info "[Cucumber] #{line}"
        end
      end
    end
    wait_thr.join
    status = wait_thr.value.exitstatus
  end
  
  if status != 0
    Logger.info 'Cucumber failed'
    status
  else
    completed
  end
end

Private Instance Methods

command() click to toggle source

Figure out what the cucumber command is and return it

@return [String] The cucumber command string

# File lib/cuesmash/cucumber.rb, line 86
def command
  command_string = 'cucumber'
  command_string += " --format #{format}" if format
  command_string += " --out #{output}" if output
  command_string += " --profile #{profile}" if profile
  command_string += @tags.to_a.empty? ? '' : tag_arguments
  command_string += ' --quiet' if quiet
  command_string += ' -c'

  Logger.debug "cucumber command == #{command_string}"

  command_string
end
completed() click to toggle source

Output a nice message for completing

# File lib/cuesmash/cucumber.rb, line 77
def completed
  Logger.info 'Cucumber Completed 👌'
end
started() click to toggle source

Output a nice message for starting

# File lib/cuesmash/cucumber.rb, line 70
def started
  Logger.info 'Running Cucumber'
end
tag_arguments() click to toggle source

Generate the –tags arguments for the cucumber command

@return [String] The –tags commands ready to go

# File lib/cuesmash/cucumber.rb, line 105
def tag_arguments
  command_tag = ''
  @tags.each do |tag_set|
    command_tag = '' unless command_tag
    command_tag += " --tags #{tag_set}"
  end

  command_tag
end