Created
November 1, 2012 22:51
-
-
Save davidrhyswhite/3997251 to your computer and use it in GitHub Desktop.
Running multiple cucumber tests in parallel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'thor' | |
require 'parallel' | |
require 'cucumber' | |
require 'cucumber/cli/main' | |
require File.expand_path('./lib/thor/json_formatter') | |
require "bundler" | |
begin | |
Bundler.setup | |
rescue | |
Kernel.exit(1) | |
end | |
class Cucumber < Thor | |
desc "run", "Run cucumber scenarios" | |
method_options %w(browser -b) => "firefox" | |
method_options %w(pretty -p) => "pretty" | |
method_options %w(javascript -j) => true | |
def run | |
opts = { | |
"format" => "json" | |
}.merge! options | |
if opts["browser"] =~ /,/ | |
browsers = opts["browser"] | |
timestamp = Time.now.strftime("%Y%m%d%H%M%S") | |
FileUtils.mkdir_p "tmp/#{timestamp}" | |
Parallel.map(browsers.split(','), :in_processes => 8) do |browser| | |
opts["browser"] = browser | |
output = File.expand_path "./tmp/#{timestamp}/#{browser}.json" | |
Cucumber::Cli::Main.new(build_command.split(' '), output).execute! | |
end | |
browsers.split(',').each do |browser| | |
json = JSON.parse File.read("tmp/#{timestamp}/#{browser}.json") | |
title = "Results for: #{browser} browser" | |
puts title | |
puts "-" * title.length | |
JSONFormatter::format_json json | |
puts "-" * title.length | |
end | |
else | |
opts["format"] = "pretty" | |
Cucumber::Cli::Main.execute(build_command) | |
end | |
end | |
private | |
def build_command(opts) | |
[ | |
"features", | |
parse_options(opts) | |
].join(' ') | |
end | |
def parse_options(opts) | |
"--format #{opts["format"]} " + | |
"browser=#{opts["browser"]} " + | |
"javascript=#{opts["javascript"]}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment