Sha256: 0923913048ac9ec6feba805e9fda09ece8d82a9f0c9bd0fce4e487a9951948fa

Contents?: true

Size: 1.9 KB

Versions: 5

Compression:

Stored size: 1.9 KB

Contents

module Turn

  #
  class TestCase
    include Enumerable

    # Name of test case.
    attr_accessor :name

    # Test methods.
    attr_accessor :tests

    # Some runners marshal tests per file.
    attr_accessor :files

    #attr_accessor :count_passes
    #attr_accessor :count_failures
    #attr_accessor :count_errors
    #attr_accessor :count_tests

    # This can't be calculated, so it must be
    # assigned by the runner.
    attr_accessor :count_assertions

    # Holds dump of test output (optional depending on runner).
    attr_accessor :message

    # Command used to run test (optional depending on runner).
    #attr_accessor :command

    #
    def initialize(name, *files)
      @name  = name
      @files = (files.empty? ? [name] : files)
      @tests = []

      @message = nil
      @count_assertions = 0

      #@count_tests      = 0
      #@count_failures   = 0
      #@count_errors     = 0

      #@command = command
    end

    def new_test(name)
      c = TestMethod.new(name)
      @tests << c
      c
    end

    # Whne used by a per-file runner.
    #alias_method :file, :name

    # Were there any errors?
    def error?
      count_errors != 0
    end

    # Were there any failures?
    def fail?
      count_failures != 0
    end

    # Did all tests/assertion pass?
    def pass?
      not(fail? or error?)
    end

    def count_tests
      tests.size
    end

    alias_method :size, :count_tests

    def count_failures
      sum = 0; tests.each{ |t| sum += 1 if t.fail? }; sum
    end

    def count_errors
      sum = 0; tests.each{ |t| sum += 1 if t.error? }; sum
    end

    def count_passes
      sum = 0; tests.each{ |t| sum += 1 if t.pass? }; sum
    end

    #
    def counts
      return count_tests, count_assertions, count_failures, count_errors
    end

    def message
      tests.collect{ |t| t.message }.join("\n")
    end

    def each(&block)
      tests.each(&block)
    end
  end

end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
turn-0.8.3 lib/turn/components/case.rb
turn-0.8.2 lib/turn/components/case.rb
openlogic-turn-0.8.2 lib/turn/components/case.rb
turn-0.8.1 lib/turn/components/case.rb
turn-0.8.0 lib/turn/components/case.rb