Created
July 30, 2010 20:48
-
-
Save nruth/501296 to your computer and use it in GitHub Desktop.
how not to loop/nest rspec example groups (where you want to iterate diferent let/before variable values)
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
class Tests | |
SUBTESTS = %w(Abstract Decision Quantitative Verbal) | |
end | |
describe Tests do | |
describe "before assigning @ - " do | |
describe "this doesn't work because the loops are all at the same describe level (the befores override one another)" do | |
Tests::SUBTESTS.each do |test| | |
before(:each) do | |
@test = test | |
end | |
specify test do | |
@test.should == test | |
end | |
end | |
end | |
describe "this does work because there's an inner describe block isolating the examples" do | |
Tests::SUBTESTS.each do |test| | |
describe "#{test} in a block" do | |
before(:each) do | |
@test = test | |
end | |
specify test do | |
@test.should == test | |
end | |
end | |
end | |
end | |
end | |
describe "lazy-let blocks" do | |
Tests::SUBTESTS.each do |test| | |
describe "#{test} in a block" do | |
let(:thetest) {test} | |
specify test do | |
thetest.should == test | |
end | |
end | |
end | |
describe "lazy-let blocks" do | |
Tests::SUBTESTS.each do |test| | |
let(:thetest) {test} | |
specify test do | |
thetest.should == test | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
6 of the specs should fail