Sha256: 7dd483468527c793290e462b49f3e0324f44ed375ca4b169c0aa6a12cbe90ade

Contents?: true

Size: 1 KB

Versions: 5

Compression:

Stored size: 1 KB

Contents

module Defekt
  class Test
    attr_reader :methot, :error

    def initialize(methot)
      @methot = methot
    end

    def instance
      @instance ||= methot.owner.new
    end

    def run
      @ran = true

      begin
        instance.before
        methot.bind(instance).call
        '.'
      rescue => e
        @error = e
        status.chars.first
      ensure
        instance.after
      end
    end

    def summary
      "#{methot.owner}##{methot.name} at #{methot.source_location.join(':')} #{status}"
    end

    def ran?
      !!@ran
    end

    def passed?
      ran? && error.nil?
    end

    def failed?
      ran? && !passed? && error.kind_of?(Errors::BaseError)
    end

    def errored?
      ran? && !failed? && error.kind_of?(Exception)
    end

    def broken?
      failed? || errored?
    end

    def status
      case
      when passed?
        'passed'
      when failed?
        'failed'
      when errored?
        'errored'
      else
        'did not run'
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
defekt-0.0.6 lib/defekt/test.rb
defekt-0.0.5 lib/defekt/test.rb
defekt-0.0.4 lib/defekt/test.rb
defekt-0.0.3 lib/defekt/test.rb
defekt-0.0.2 lib/defekt/test.rb