Class: CucumberJunitToJson::App
- Inherits:
-
Object
- Object
- CucumberJunitToJson::App
- Defined in:
- lib/cucumber_junit_to_json/app.rb
Overview
The Cucumber Junit to Json app class that handles std inputs and command line args
Constant Summary collapse
- Error =
Class.new(RuntimeError)
Instance Attribute Summary collapse
-
#feature_parser ⇒ Object
readonly
Returns the value of attribute feature_parser.
-
#junit_parser ⇒ Object
readonly
Returns the value of attribute junit_parser.
-
#stderr ⇒ Object
readonly
Returns the value of attribute stderr.
-
#stdin ⇒ Object
readonly
Returns the value of attribute stdin.
-
#stdout ⇒ Object
readonly
Returns the value of attribute stdout.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ App
constructor
A new instance of App.
- #run(*args) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ App
Returns a new instance of App.
22 23 24 25 26 27 28 |
# File 'lib/cucumber_junit_to_json/app.rb', line 22 def initialize( = {}) @stdin = [:stdin] || STDIN @stdout = [:stdout] || STDOUT @stderr = [:stderr] || STDERR @feature_id = 1 @scenario_id = 1 end |
Instance Attribute Details
#feature_parser ⇒ Object (readonly)
Returns the value of attribute feature_parser.
30 31 32 |
# File 'lib/cucumber_junit_to_json/app.rb', line 30 def feature_parser @feature_parser end |
#junit_parser ⇒ Object (readonly)
Returns the value of attribute junit_parser.
30 31 32 |
# File 'lib/cucumber_junit_to_json/app.rb', line 30 def junit_parser @junit_parser end |
#stderr ⇒ Object (readonly)
Returns the value of attribute stderr.
30 31 32 |
# File 'lib/cucumber_junit_to_json/app.rb', line 30 def stderr @stderr end |
#stdin ⇒ Object (readonly)
Returns the value of attribute stdin.
30 31 32 |
# File 'lib/cucumber_junit_to_json/app.rb', line 30 def stdin @stdin end |
#stdout ⇒ Object (readonly)
Returns the value of attribute stdout.
30 31 32 |
# File 'lib/cucumber_junit_to_json/app.rb', line 30 def stdout @stdout end |
Instance Method Details
#run(*args) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/cucumber_junit_to_json/app.rb', line 32 def run(*args) = parse_args(args) @junit_parser = CucumberJunitToJson::Parsers::JunitParser.new(.junit_dir) @feature_parser = CucumberJunitToJson::Parsers::FeatureParser.new(.feature_dir) output_file = .output_file || 'cucumber.json' features = [] unless File.file?(output_file) output_directory = File.dirname(output_file) FileUtils.mkdir_p(output_directory) unless File.directory?(output_directory) FileUtils.touch(output_file) raise Error, "Could not create output file #{output_file}" unless File.file?(output_file) end # if we are dealing with a directory of xml files if File.directory?(junit_parser.path_to_junit) Find.find(junit_parser.path_to_junit) do |path_to_file| next unless File.file?(path_to_file) && File.extname(path_to_file) == '.xml' features.push(convert_to_json(path_to_file)) end # if we are dealing with just a single xml file elsif File.exist?(junit_parser.path_to_junit) features.push(convert_to_json(junit_parser.path_to_junit)) end open(output_file, 'w') { |f| f.write(features.to_json) } 0 rescue Error, OptionParser::ParseError => error stderr.puts error. 1 end |