Where are the factory records?

I am trying to perform an integration test through Watir and RSpec . So, I created a test file inside / integration and wrote a test that adds a test user to the database through factory_girl .

The problem is that I cannot login with my test user. The test I wrote is as follows:

...

before(:each)
  @user = Factory(:user)
  @browser = FireWatir::Firefox.new
end

it "should login"
  @browser.text_field(:id, "username").set(@user.username)
  @browser.text_field(:id, "password").set(@user.password)
  @browser.button(:id, "get_in").click
end

...

When I run a test and see "performance" in the browser, it always launches an error Username is not valid.

I started an investigation and did a little trick. First of all, I had doubts if the factory actually creates the user in the database. So after an immediate factory call, I added stuff puts User.findjust to find that the user . , , , .

sleep factory , . , , ! ? , , - . , , factory_girl ? test dev DB? .

10 , Mongrel test ( ? , , ), database.yml .

authlogic, (no, put activate_authlogic ).

+3
3

- : (: all), , .

+2

, RSpec, , . RSpec . , (.. SQL-).

, Factory Girl, - :

before(:each)
  @user = Factory(:user)
  User.find_by_username(@user.username).should_not be_nil
  @browser = FireWatir::Firefox.new
end
+4

Factory Girl is going to create temporary database records in a test database. Your test database will be cleared after each test.

-1
source

Source: https://habr.com/ru/post/1738555/


All Articles