Verified Commit c6126641 authored by Hercules Merscher's avatar Hercules Merscher
Browse files

feat: DRY with completable method

parent e45a8ab9
Loading
Loading
Loading
Loading
+15 −18
Original line number Diff line number Diff line
@@ -84,15 +84,7 @@ module Labkit

        return self unless block_given?

        begin
          yield self
          self
        rescue StandardError => e
          error!(e)
          raise
        ensure
          complete(**extra)
        end
        completable(**extra, &)
      end

      # Checkpoint the Covered Experience.
@@ -121,15 +113,7 @@ module Labkit

        return self unless block_given?

        begin
          yield self
          self
        rescue StandardError => e
          error!(e)
          raise
        ensure
          complete(**extra)
        end
        completable(**extra, &)
      end

      # Complete the Covered Experience.
@@ -188,6 +172,19 @@ module Labkit
        raise(err) if %w[development test].include?(ENV['RAILS_ENV'])
      end

      def completable(**extra, &)
        begin
          yield self
        rescue StandardError => e
          error!(e)
          raise
        ensure
          complete(**extra)
        end

        self
      end

      def ensure_incomplete!
        return true if @end_time.nil?