class Calasmash::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

Public Class Methods

new(ios, tags) 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

# File lib/calasmash/cucumber.rb, line 25
def initialize(ios, tags)
  @ios = ios
  @tags = tags
end

Public Instance Methods

test() click to toggle source

Run the cucumber tests

# File lib/calasmash/cucumber.rb, line 33
def test
  started

  status = nil
  output = ""
  Open3.popen3 command do |stdin, out, err, wait_thr|

    [out, err].each do |stream|
      Thread.new do
        until (line = stream.gets).nil? do
          puts line
        end
      end
    end

    wait_thr.join
    status = wait_thr.value.exitstatus
  end

  if status != 0
    puts "\n Cucumber failed"
    exit 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/calasmash/cucumber.rb, line 82
def command
  command = "cucumber"
  command += " OS=ios#{@ios.to_i} SDK_VERSION=#{@ios}" if @ios
  command += " --format #{self.format}" if self.format
  command += " --out #{self.output}" if self.output
  command += @tags.to_a.empty? ? "" : tag_arguments
  command += " -c"

  command
end
completed() click to toggle source

Output a nice message for completing

# File lib/calasmash/cucumber.rb, line 73
def completed
  puts "\nCucumber Completed 👌"
end
started() click to toggle source

Output a nice message for starting

# File lib/calasmash/cucumber.rb, line 65
def started
  puts "\nRunning Cucumber"
  puts "================\n"
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/calasmash/cucumber.rb, line 98
def tag_arguments
  command = ""
  @tags.each do |tag_set|
    command = "" unless command
    command += " --tags #{tag_set}"
  end
  command
end