Skip to content

Instantly share code, notes, and snippets.

@thomasfedb
Last active January 2, 2016 10:09
Show Gist options
  • Select an option

  • Save thomasfedb/8288477 to your computer and use it in GitHub Desktop.

Select an option

Save thomasfedb/8288477 to your computer and use it in GitHub Desktop.
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 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment