Factory Girl / Capybara deleting records from database mid-test?

前端 未结 4 1349
野趣味
野趣味 2021-02-19 10:10

Working with RSpec & Capybara, I\'m getting an interesting test failure mode which goes away with a few subtle rearrangements of lines in the test case...stuff that shouldn\

4条回答
  •  我寻月下人不归
    2021-02-19 10:31

    I think the user variable in RSpec has overwritten the one in the controller so it didn't work ? (couldn't get right user.email in the test)

    Before :

    user = Factory(:user)
    user.password! '2468'
    
    visit '/sessions/index' # user gets overwritten
    
    fill_in 'Email', :with => user.email # can't get user.email
    

    After :

    visit '/sessions/index' # Execute action
    
    user = Factory(:user) # user gets overwritten
    user.password! '2468'
    
    fill_in 'Email', :with => user.email  # user.email works
    

提交回复
热议问题