Created
September 12, 2012 01:28
-
-
Save rafaellima/3703518 to your computer and use it in GitHub Desktop.
just an example about how rspec works inside
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' | |
class TestDescribe < Test::Unit::TestCase | |
def test_that_it_can_pass | |
describe "something" do | |
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 | |
#Implementation | |
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 | |
end | |
class TestAssertion < Test::Unit::TestCase | |
def test_that_it_can_pass | |
2.should == 2 | |
end | |
end | |
class Object | |
def should | |
DelayedAssertion.new(self) | |
end | |
end | |
class DelayedAssertion | |
def initialize(subject) | |
@subject = subject | |
end | |
def ==(other) | |
self == other | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment