Sha256: b7bc42772fd883383cc26f9d473a2f3c9efa0278c2a3b8eb9926f5f4da769333

Contents?: true

Size: 1.21 KB

Versions: 3

Compression:

Stored size: 1.21 KB

Contents

#
# Helpers for WrapIt testing
#
# @author Alexey Ovchinnikov <alexiss@cybernetlab.ru>
#
module WrappedExampleGroup
  BASE_MODULES = [WrapIt::HTML, WrapIt::Switches, WrapIt::Enums,
                  WrapIt::Renderer, WrapIt::Sections, WrapIt::Arguments]

  def self.included(base)
    base.instance_eval do
      metadata[:type] = :wrap_it

      after do
        @successor = nil
        @wrapper = nil
      end

      let(:template_wrapper) { Object.new }

      let(:successor_class) { Class.new described_class }

      let(:wrapper_class) do
        mod = described_class
        if BASE_MODULES.include? mod
          Class.new(WrapIt::Base)
        else
          Class.new(WrapIt::Base) { include mod }
        end
      end
    end
  end

  def successor(*args, &block)
    templ = respond_to?(:template) ? template : template_wrapper
    @successor ||= successor_class.new(templ, *args, &block)
  end

  def wrapper(*args, &block)
    templ = respond_to?(:template) ? template : template_wrapper
    @wrapper ||= wrapper_class.new(templ, *args, &block)
  end

  RSpec.configure do |config|
    config.include(
      self,
      type: :wrapped,
      example_group: { file_path: /spec\/(wrapped|integration)/ }
    )
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
wrap_it-1.0.2 spec/support/example_groups/wrapped_example_group.rb
wrap_it-1.0.1 spec/support/example_groups/wrapped_example_group.rb
wrap_it-1.0.0 spec/support/example_groups/wrapped_example_group.rb