Created
September 30, 2012 14:05
-
-
Save nazgob/3806818 to your computer and use it in GitHub Desktop.
Sample rspec implementation from DestroyAllSoftware
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 'test/unit' | |
def describe(description, &block) | |
ExampleGroup.new(block).evaluate! | |
end | |
class ExampleGroup | |
def initialize(block) | |
@block = block | |
end | |
def evaluate! | |
instance_eval(&@block) | |
end | |
def it(description, &block) | |
block.call | |
end | |
end | |
class Object | |
def should | |
DelayedAssertion.new(self) | |
end | |
end | |
class DelayedAssertion | |
def initialize(subject) | |
@subject = subject | |
end | |
def ==(other) | |
raise AssertionError unless @subject == other | |
end | |
end | |
class AssertionError < Exception | |
end | |
class TestDescribe < Test::Unit::TestCase | |
def test_that_it_can_pass | |
describe 'some thing' do | |
it 'has some property' do | |
end | |
end | |
end | |
def test_that_it_can_fail | |
assert_raise(IndexError) do | |
describe 'some failing thing' do | |
it 'fails' do | |
raise IndexError | |
end | |
end | |
end | |
end | |
end | |
class TestAssertion < Test::Unit::TestCase | |
def test_it_should_pass | |
2.should == 2 | |
end | |
def test_it_can_fail | |
assert_raise(AssertionError) do | |
1.should == 2 | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment