Created
March 7, 2014 00:01
-
-
Save jayzes/9402376 to your computer and use it in GitHub Desktop.
Short implementation of a style similar to rspec-given
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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