Reputation: 10898
I have recently started using FactoryGirl instead of Fixtures in my application. Below is a spec i wrote to test if the data saved using factorygirl appears in a separate page
describe "Tasks" do
describe "GET /Ajax add", :focus do
it "checks ajax js", :js => true do
task = FactoryGirl.create(:task, :name => "writing test task")
visit "/list"
end
end
end
in the page /list
i have written code to retrieve all the data in the tasks
table (Task model)
.
I can see output when i am running the page by starting server, but when running through the test, it always shows empty page.
Is this because FactoryGirl deletes all the data after use? Or what should I do to persist data even when I visit multiple pages in a test?
Upvotes: 1
Views: 756
Reputation: 2469
I had similar issues where using Fabricator (FactoryGirl alternative) would not persist to my Capybara sessions. The guys at plataformatec wrote a solution to this. http://blog.plataformatec.com.br/2011/12/three-tips-to-improve-the-performance-of-your-test-suite/
Upvotes: 0
Reputation: 1885
1) Are you using something like DatabaseCleaner? Have a look at your test_helper to see if you're doing anything to clean the database
2) Check the return value on task to see that it's actually creating successfully.
Upvotes: 1