Sha256: a1b449b0f1553f81df3de95f21434017611ec6c23d0977e0c14a35aadc737cb3

Contents?: true

Size: 919 Bytes

Versions: 8

Compression:

Stored size: 919 Bytes

Contents

require 'hyperion'
require 'rspec/core'

module TestFrameworkHooks
  def teardown_registered?
    rspec_after_example_hooks.any? do |hook_proc|
      hook_proc.source_location == method(:teardown).to_proc.source_location
    end
  end

  def can_hook_teardown?
    RSpec.current_example
  end

  def hook_teardown
    hyperion = self
    rspec_hooks.register(:prepend, :after, :each) { hyperion.teardown }
  end

  def rspec_after_example_hooks
    if rspec_hooks.respond_to?(:[]) # approximately rspec 3.1.0
      rspec_hooks[:after][:example].to_a.map(&:block)
    else # approximately rspec 3.3.0
      default_if_no_hooks = nil
      hook_collection = rspec_hooks.send(:hooks_for, :after, :example) {default_if_no_hooks}
      return [] unless hook_collection
      hook_collection.items_and_filters.map(&:first).map(&:block)
    end
  end

  def rspec_hooks
    RSpec.current_example.example_group.hooks
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
hyperion_http-0.1.9 lib/hyperion_test/test_framework_hooks.rb
hyperion_http-0.1.8 lib/hyperion_test/test_framework_hooks.rb
hyperion_http-0.1.7 lib/hyperion_test/test_framework_hooks.rb
hyperion_http-0.1.6 lib/hyperion_test/test_framework_hooks.rb
hyperion_http-0.1.5 lib/hyperion_test/test_framework_hooks.rb
hyperion_http-0.1.4 lib/hyperion_test/test_framework_hooks.rb
hyperion_http-0.1.3 lib/hyperion_test/test_framework_hooks.rb
hyperion_http-0.1.2 lib/hyperion_test/test_framework_hooks.rb