Sha256: dcd0dcaef3c3fb3ee88730bf7f968640911641436c21037def2384f1cf38f920

Contents?: true

Size: 1.6 KB

Versions: 1

Compression:

Stored size: 1.6 KB

Contents

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sweets-0.0.1 lib/sweet/run.rb