Sha256: 62b91949f20db98e8962f619b8db9ce878df9860d5e2424dc29375f7871417dd

Contents?: true

Size: 1.34 KB

Versions: 2

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

require 'delegate'

module Cucumber
  # Represents the current status of a running test case.
  #
  # This wraps a `Cucumber::Core::Test::Case` and delegates
  # many methods to that object.
  #
  # We decorete the core object with the current result.
  # In the first Before hook of a scenario, this will be an
  # instance of `Cucumber::Core::Test::Result::Unknown`
  # but as the scenario runs, it will be updated to reflect
  # the passed / failed / undefined / skipped status of
  # the test case.
  #
  module RunningTestCase
    def self.new(test_case)
      TestCase.new(test_case)
    end

    class TestCase < SimpleDelegator
      def initialize(test_case, result = Core::Test::Result::Unknown.new)
        @test_case = test_case
        @result = result
        super test_case
      end

      def accept_hook?(hook)
        hook.tag_expressions.all? { |expression| @test_case.match_tags?(expression) }
      end

      def exception
        return unless @result.failed?

        @result.exception
      end

      def status
        @result.to_sym
      end

      def failed?
        @result.failed?
      end

      def passed?
        !failed?
      end

      def source_tag_names
        tags.map(&:name)
      end

      def with_result(result)
        self.class.new(@test_case, result)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cucumber-9.2.0 lib/cucumber/running_test_case.rb
cucumber-9.1.2 lib/cucumber/running_test_case.rb