Sha256: fccdfbe58453dfe0d3a5549a7a114218c6026aaa2d89c1e9921d046b817aefdc

Contents?: true

Size: 899 Bytes

Versions: 10

Compression:

Stored size: 899 Bytes

Contents

module WithContextsHelpers
  class WithContextsBuilder
    attr_accessor :contexts, :examples, :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 let(*args, &blk)
      group.let(*args, &blk)
    end

    def before(*args, &blk)
      group.before(*args, &blk)
    end

    def after(*args, &blk)
      group.after(*args, &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

10 entries across 10 versions & 1 rubygems

Version Path
warp-1.5.0 spec/support/with_contexts_helpers.rb
warp-1.4.0 spec/support/with_contexts_helpers.rb
warp-1.3.3 spec/support/with_contexts_helpers.rb
warp-1.3.2 spec/support/with_contexts_helpers.rb
warp-1.3.1 spec/support/with_contexts_helpers.rb
warp-1.3.0 spec/support/with_contexts_helpers.rb
warp-1.2.3 spec/support/with_contexts_helpers.rb
warp-1.2.2 spec/support/with_contexts_helpers.rb
warp-1.2.1 spec/support/with_contexts_helpers.rb
warp-1.2.0 spec/support/with_contexts_helpers.rb