Reputation: 99
I am following Michael Hartl's tutorial and came across this following codes that I am having trouble comprehending.
describe "index" do
let(:user) { FactoryGirl.create(:user) }
before(:each) do
sign_in user
visit users_path
end
it { should have_title('All users') }
it { should have_content('All users') }
describe "pagination" do
before(:all) { 30.times { FactoryGirl.create(:user) } }
after(:all) { User.delete_all }
it { should have_selector('div.pagination') }
it "should list each user" do
User.paginate(page: 1).each do |user|
expect(page).to have_selector('li', text: user.name)
end
end
end
end
My question is: is this a NESTED TEST where the test block of Pagination runs inside Index Test block? in other words, the sequence of testing flow:
thank you
Upvotes: 0
Views: 694
Reputation: 13354
Here's the flow for the above test:
The before(:each)
block is executed before each of the following:
it { should have_title('All users') }
it { should have_content('All users') }
Then, the before(:each)
is executed again, followed by the describe block
, which executes:
before(:all) { 30.times { FactoryGirl.create(:user) } }
it { should have_selector('div.pagination') }
it "should list each user" do
User.paginate(page: 1).each do |user|
expect(page).to have_selector('li', text: user.name)
end
end
Finally, after(:all) { User.delete_all }
is executed.
I hope this helps explain the flow.
Upvotes: 1