RSpec: the deep differences between (: all) and before (: each)

Ok, so I ran into a very strange problem directly related to blocks. I am doing integration testing through Watir and RSpec. For a simple test, to check if the user can login, I create a user record in db using factory_girl.

So, I put the following code:

before(:each) do @user = Factory(:user) end if "should perform a login" do # do stuff end 

In do stuff I call the browser and see how the user is trying to log in. Unfortunately, somehow he cannot do this - "The username is invalid."

After some research, I found that if I put the code to create the user in the before(:all) block, everything works magically . Like this? What is the difference between :all and :each in this context? In addition, if I put the code to create the user in the body of the test, it still does not work (i.e. the user is somehow not added to the database or something else).

+7
rspec
source share
1 answer

Transactional devices are probably activated, so your Watir process does not see the database changes within the transaction into which each RSpec example is packaged.

Try disabling transactional functions and use something like a database cleaner to get a clean list before each example.

+3
source share

All Articles