lucaspiller/espec — pull request #7 by benmmurphy (2011-12-26 13:46:39+00:00)
Title: Rspec like before after

also support for multiple before/after each/all

here is example to show them matching:

require 'rspec'

describe "stuff" do
before :each do
puts "output:before outer"
end

it "should do stuff" do
puts "output:should do stuff"
end

describe "nested" do
before :each do
puts "output:before inner"
end

it "should do stuff inner" do
puts "output:should do stuff inner"
end

it "should do stuff inner2" do
puts "output:should do stuff inner2"
end
end
end

-module(test_spec).
-include("espec.hrl").

spec() ->
describe("stuff", fun() ->
before_each(fun() ->
io:format("output:before outer~n", [])
end),

it("should do stuff", fun() ->
io:format("output:should do stuff~n", [])
end),

describe("nested", fun() ->
before_each(fun() ->
io:format("output:before inner~n", [])
end),

it("should do stuff inner", fun() ->
io:format("output:should do stuff inner~n", [])
end),

it("should do stuff inner2", fun() ->
io:format("output:should do stuff inner2~n", [])
end)
end)
end).

rspec runs the full chain of before each functions before running the example while espec only runs the current level of before each functions before running the example.

rspec:
output:before outer
output:should do stuff
output:before outer
output:before inner
output:should do stuff inner
output:before outer
output:before inner
output:should do stuff inner2

espec:
output:before outer
output:should do stuff
output:before outer
output:before inner
output:should do stuff inner
output:before inner
output:should do stuff inner2