Skip to content

Instantly share code, notes, and snippets.

@nruth
Created July 30, 2010 20:48
Show Gist options
  • Save nruth/501296 to your computer and use it in GitHub Desktop.
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)
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
@nruth
Copy link
Author

nruth commented Jul 30, 2010

6 of the specs should fail

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment