Sha256: 3b73502e81d8b299546c1ea0fa1d8035952966d1bf2cce2d2fe3e9a08a66a81d

Contents?: true

Size: 1.23 KB

Versions: 2

Compression:

Stored size: 1.23 KB

Contents

require 'digest'
require 'mimemagic'
module AllureRSpec
  module DSL
    def current_step
      if defined? @@__current_step
        @@__current_step
      else
        nil
      end
    end

    def step(step, &block)
      suite = self.example.metadata[:example_group][:description_args].first
      test = self.example.metadata[:description]
      AllureRubyApi::Builder.start_step(suite, test, step)
      __with_step step, &block
      AllureRubyApi::Builder.stop_step(suite, test, step)
    end

    def attach_file(title, file, opts = {})
      suite = self.example.metadata[:example_group][:description_args].first
      test = self.example.metadata[:description]
      step = current_step
      AllureRubyApi::Builder.add_attachment suite, test, opts.merge(:file => file, :title => title, :step => step)
    end

    private

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

    def __with_step(step, &block)
      __mutex.synchronize do
        begin
          @@__current_step = step
          AllureRSpec.context.rspec.send :run_hook, :before, :step, example
          yield
        ensure
          AllureRSpec.context.rspec.send :run_hook, :after, :step, example
          @@__current_step = nil
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
allure-rspec-0.5.1 lib/allure-rspec/dsl.rb
allure-rspec-0.5.0 lib/allure-rspec/dsl.rb