Browse Source

Results to file

master
Christian Aust 7 months ago
parent
commit
1b87b3c490
  1. 2
      .gitignore
  2. 2
      README.md
  3. 20
      lib/sanity/runner.rb
  4. 4
      lib/sanity/suite.rb

2
.gitignore

@ -1,5 +1,5 @@
/*.json
/run
/coverage
# rspec failure tracking

2
README.md

@ -15,6 +15,8 @@ Taking care for a running online application requires repetitive, dull little ta
Test code is in `lib/sanity/tests` for reference and details.
Results are written to XML files, one per *application* in the targets definition. Result files are created in path `./run/*.xml`
## Example target file
Create a file `targets.json` in the base directory of this repo. It may contain multiple apps, and for each app any combination of supported tests along with any number of targets (at least one, though).

20
lib/sanity/runner.rb

@ -1,3 +1,4 @@
require 'fileutils'
require 'json'
require 'logger'
@ -5,7 +6,11 @@ module Sanity
class Runner
attr_reader :specs
def initialize(src)
DEFAULTS = {
path: 'run'
}
def initialize(src, options={})
if src.respond_to?(:read)
# general IO
@specs = JSON.load src.read
@ -40,8 +45,19 @@ module Sanity
log.error "Invalid configuration for #{name}/#{role_name}"
end
end
puts Output::Xml.new(suite.result).to_s
write(suite)
end
end
def write(suite)
path = File.join(DEFAULTS[:path], "#{suite.result_name}.xml")
dirname = File.dirname(path)
FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
File::open(path, 'w') do |f|
f << Output::Xml.new(suite.result).to_s
end
log.info("Written suite result to #{path}")
end
def self.log

4
lib/sanity/suite.rb

@ -13,6 +13,10 @@ module Sanity
@tests << val
end
def result_name
name.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
end
def result
result = Result.new(name)
@tests.each do |test|

Loading…
Cancel
Save