Created
March 15, 2014 04:43
-
-
Save rafaellima/9561933 to your computer and use it in GitHub Desktop.
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
require 'minitest/autorun' | |
class TestDescribe < Minitest::Test | |
def test_that_it_can_pass | |
whatever "that it describes" do | |
another_block "lol" do | |
end | |
end | |
end | |
def test_it_can_have_a_nested_block_that_fails | |
assert_raises(ArgumentError) do | |
whatever "that it describes" do | |
another_block "it is another block" do | |
raise ArgumentError | |
end | |
end | |
end | |
end | |
end | |
class TestAssertion < Minitest::Test | |
def test_that_it_can_assert | |
2.should == 2 | |
end | |
def test_that_it_fails | |
assert_raises(AssertionError) do | |
1.should == 2 | |
end | |
end | |
end | |
class AssertionError < Exception; end | |
class Object | |
def should | |
DelayedAssertion.new(self) | |
end | |
end | |
class DelayedAssertion | |
def initialize(value) | |
@value = value | |
end | |
def ==(other) | |
raise AssertionError unless @value == other | |
end | |
end | |
def whatever(description, &block) | |
ExampleGroup.new(block).evaluate! | |
end | |
class ExampleGroup | |
def initialize(block) | |
@block = block | |
end | |
def evaluate! | |
instance_eval(&@block) | |
end | |
def another_block(description, &block) | |
block.call | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment