Sha256: ec4d221cadc91418e7653795b371639cd8c474f8d1a422408f30eb139d1247c9

Contents?: true

Size: 758 Bytes

Versions: 1

Compression:

Stored size: 758 Bytes

Contents

module WithContextsHelpers
  class WithContextsBuilder
    attr_accessor :contexts, :examples, :group

    delegate :let, :before, :after, :subject, to: :group

    def initialize(group)
      @contexts = {}
      @group = group
    end

    def context(name, &blk)
      self.contexts[name] = blk
    end

    def describe(name, &blk)
      self.contexts[name] = blk
    end

    def behaviour(&blk)
      self.examples = blk
    end

    def execute
      contexts.each do |name, blk|
        context = group.context(name)
        context.instance_eval(&blk)
        context.instance_eval(&examples)
      end
    end
  end

  def with_contexts(&blk)
    builder = WithContextsBuilder.new(self)
    builder.instance_eval(&blk)
    builder.execute
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
warp-1.1.0 spec/support/with_contexts_helpers.rb