Sha256: 0ab83e93d490235ab511bf8c7d333a1ba7f5daa5024cac6fcc626d27b750b7a0

Contents?: true

Size: 1.36 KB

Versions: 1

Compression:

Stored size: 1.36 KB

Contents

require "test_construct"
require "rspec"
module TestConstruct
  module RSpecIntegration
    module_function

    # the :test_construct metadata key can be either:
    # - true (for all defaults)
    # - a Hash of options
    # - false/missing (disable the construct for this test)
    def test_construct_options(example)
      options = test_construct_default_options
      options[:name] = example.full_description
      metadata_options = example.metadata[:test_construct]
      if metadata_options.is_a?(Hash)
        options.merge!(metadata_options)
      end
      options
    end

    def test_construct_enabled?(example)
      !!example.metadata[:test_construct]
    end

    def test_construct_default_options
      {
        base_dir:       TestConstruct.tmpdir,
        chdir:          true,
        keep_on_error:  true,
      }
    end
  end
end

RSpec.configure do |config|
  config.include TestConstruct::Helpers
  config.include TestConstruct::RSpecIntegration

  config.before :each do
    next unless test_construct_enabled?(example)
    options = test_construct_options(example)
    example.metadata[:construct] = setup_construct(options)
  end

  config.after :each do
    next unless test_construct_enabled?(example)
    options = test_construct_options(example)
    teardown_construct(
      example.metadata[:construct],
      example.exception,
      options)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
test_construct-2.0.0 lib/test_construct/rspec_integration.rb