module Sweet class Run attr_accessor :name, :category, :description, :tags, :timestamp attr_accessor :tests, :passed, :failed, :skipped, :pending def initialize(opts = {}) @name = opts[:name] @category = opts[:category] @description = opts[:description] @tags = opts[:tags] || [] @duration = 0.0 @timestamp = opts[:timestamp] || Time.now @tests = [] @passed = [] @failed = [] @skipped = [] @pending = [] organize_tests opts[:tests] || [] end def duration @duration / 1_000_000_000 # nanoseconds end def total_tests @tests.count end def total_passed @passed.count end def total_failed @failed.count end def total_skipped @skipped.count end def total_pending @pending.count end private def organize_tests(tests = []) tests.each do |test| case test when Sweet::Format::Cucumber::Feature handle_feature test when Sweet::Format::Cucumber::Scenario handle_test test when Sweet::Format::RSpec::Example handle_test test end end end def handle_feature(feature) feature.scenarios.each do |scenario| handle_test scenario end end def handle_test(test) @tests << test @duration += test.duration case test.status when :passed @passed << test when :failed @failed << test when :pending @pending << test when :skipped @skipped << test end end end end