Skip to content

Instantly share code, notes, and snippets.

@jayzes
Created March 7, 2014 00:01
Show Gist options
  • Save jayzes/9402376 to your computer and use it in GitHub Desktop.
Save jayzes/9402376 to your computer and use it in GitHub Desktop.
Short implementation of a style similar to rspec-given
module GivenWhenThen
def Given(*args, &block)
if args.first.is_a?(Symbol)
let(*args, &block)
else
before(&block)
end
end
def Given!(*args, &block)
let!(*args, &block)
end
def When(*args, &block)
before(&block)
end
def Then(&block)
unless @queued_examples
@queued_examples = []
__examples = @queued_examples
it '' do
__examples.map { |e| self.instance_exec(&e) }
end
end
@queued_examples << block
end
alias_method :And, :Then
end
RSpec::Core::ExampleGroup.send :extend, GivenWhenThen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment