Sha256: 1ebe0ef274939af577be4a1dec36473ef87f017a32f1dc14410be759a4c321b8

Contents?: true

Size: 1.86 KB

Versions: 3

Compression:

Stored size: 1.86 KB

Contents

require 'digest'
require 'mimemagic'

module AllureTurnip
  module DSL
    module Example

      def current_step
        if defined? @@__current_step
          @@__current_step
        else
          nil
        end
      end

      def allure_step(step, &block)
        begin
          AllureRubyAdaptorApi::Builder.start_step(__suite, __test, step)
          __with_step step, &block
          AllureRubyAdaptorApi::Builder.stop_step(__suite, __test, step)
        rescue Exception => e
          AllureRubyAdaptorApi::Builder.stop_step(__suite, __test, step, :failed)
          raise e
        end
      end

      def attach_file(title, file, opts = {})
        step = current_step
        AllureRubyAdaptorApi::Builder.add_attachment __suite, __test, opts.merge(:title => title, :file => file, :step => step)
      end

      private

      def __suite
        if AllureTurnip::Config.feature_with_filename?
          "#{File.split(metadata[:example_group][:parent_example_group][:file_path])[1]} -> #{metadata[:example_group][:parent_example_group][:description]}"
        else
          metadata[:example_group][:parent_example_group][:description]
        end
      end

      def __test
        metadata[:example_group][:full_description]
      end

      def __description(data)
        data[:full_description] || data[:description]
      end

      def __mutex
        @@__mutex ||= Mutex.new
      end

      def __with_step(step, &block)
        begin
          locked = __mutex.try_lock
          if locked
            @@__current_step = step
            AllureTurnip.context.rspec.hooks.send :run, :before, :step, self
            yield self
          end
        ensure
          if locked
            AllureTurnip.context.rspec.hooks.send :run, :after, :step, self
            @@__current_step = nil
            __mutex.unlock
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
allure_turnip-0.2.0 lib/allure_turnip/dsl.rb
allure_turnip-0.1.1 lib/allure_turnip/dsl.rb
allure_turnip-0.1.0 lib/allure_turnip/dsl.rb