Skip to content

Instantly share code, notes, and snippets.

@rafaellima
Created September 12, 2012 01:28
Show Gist options
  • Save rafaellima/3703518 to your computer and use it in GitHub Desktop.
Save rafaellima/3703518 to your computer and use it in GitHub Desktop.
just an example about how rspec works inside
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