Skip to content

Commit

Permalink
Fix dry-run generation
Browse files Browse the repository at this point in the history
  • Loading branch information
bayandin committed Dec 29, 2015
1 parent 1740f80 commit 0bc1311
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
parallel_cucumber (0.1.19)
parallel_cucumber (0.1.20)
cucumber
parallel (~> 1.6)

Expand Down
35 changes: 23 additions & 12 deletions lib/parallel_cucumber/grouper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require 'English'
require 'erb'
require 'json'
require 'open3'
require 'tempfile'
require 'yaml'

module ParallelCucumber
Expand Down Expand Up @@ -48,21 +50,30 @@ def generate_dry_run_report(options)
cucumber_options = options[:cucumber_options]
cucumber_options = expand_profiles(cucumber_options) unless cucumber_config_file.nil?
cucumber_options = cucumber_options.gsub(/(--format|-f|--out|-o)\s+[^\s]+/, '')
result = nil

cmd = "cucumber #{cucumber_options} --dry-run --format json #{options[:cucumber_args].join(' ')}"
dry_run_report = `#{cmd} 2>/dev/null`
exit_status = $CHILD_STATUS.exitstatus
if exit_status != 0 || dry_run_report.empty?
cmd = "bundle exec #{cmd}" if ENV['BUNDLE_BIN_PATH']
fail("Can't generate dry run report, command exited with #{exit_status}:\n\t#{cmd}")
end
Tempfile.open(%w(dry-run .json)) do |f|
dry_run_options = "--dry-run --format json --out #{f.path}"

cmd = "cucumber #{cucumber_options} #{dry_run_options} #{options[:cucumber_args].join(' ')}"
_stdout, stderr, status = Open3.capture3(cmd)
f.close

if status != 0
cmd = "bundle exec #{cmd}" if ENV['BUNDLE_BIN_PATH']
fail("Can't generate dry run report, command exited with #{status}:\n\t#{cmd}\n\t#{stderr}")
end

content = File.read(f.path)

begin
JSON.parse(dry_run_report)
rescue JSON::ParserError
stdout = dry_run_report.length > 1024 ? "#{dry_run_report[0...1000]} ...[TRUNCATED]..." : dry_run_report
raise("Can't parse JSON from dry run:\n#{stdout}")
result = begin
JSON.parse(content)
rescue JSON::ParserError
content = content.length > 1024 ? "#{content[0...1000]} ...[TRUNCATED]..." : content
raise("Can't parse JSON from dry run:\n#{content}")
end
end
result
end

def cucumber_config_file
Expand Down
2 changes: 1 addition & 1 deletion lib/parallel_cucumber/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ParallelCucumber
VERSION = '0.1.19'
VERSION = '0.1.20'
end # ParallelCucumber

0 comments on commit 0bc1311

Please sign in to comment.