2013-07-22 20 views
0

随着下面的代码我的浏览器启动测试。我可以看到呈现的页面。在应该在数据库中的页面上缺少项目。为什么我的数据库没有被填充?数据库没有得到与设置:js => true

当我摆脱“:js => true”数据库设置..但测试失败,因为我需要JavaScript来点击一个表行。

require 'spec_helper' 

feature "[user can add analysis to a line]", :js => true do 

    context "[User signed in]" do 

    scenario "[user can visit home page click on a line and add analysis]" do 

     puts "** Add analysis feature spec not working **" 

     jim = Fabricate(:user) 
     sign_in(jim) 
     nfl = Fabricate(:league, name: "NFLXX") 
     nba = Fabricate(:league, name: "NBA") 
     nhl = Fabricate(:league, name: "NHL") 
     mlb = Fabricate(:league, name: "MLB") 
     nfl_event1 = Fabricate(:event, league: nfl, home_team: "Eagles") 
     nfl_event2 = Fabricate(:event, league: nfl, home_team: "Jets") 
     nba_event = Fabricate(:event, league: nba, home_team: "Sixers") 
     nhl_event = Fabricate(:event, league: nhl, home_team: "Flyers") 
     mlb_event = Fabricate(:event, league: mlb, home_team: "Phillies") 

     visit(posts_path)  
     find('.league-text').click_link("All") 
     page.all('.vegas-line')[0].click 
     click_link("ADD Analysis") 
     fill_in('post_title', :with => "This is my analysis") 
     fill_in('post_content', :with => "This is a long analysis for this game. If you like it you should say something to me") 
     click_button('post') 
     page.should have_content "Post submitted sucessfully" 

    end 

    end 
end 
+0

[RSpec的护栏,水豚 - 不同的故障有:JS =>真实,而不]的可能重复(HTTP: //stackoverflow.com/questions/13071813/rspec-rails-capybara-different-failures-with-js-true-and-without) –

回答

1

我觉得你的问题是,当你的测试与JavaScript的测试代码和应用程​​序服务器代码运行在单独的线程中运行,因此不会共享同一个数据库连接。

如果您有使用默认配置运行的rspec-rails,您将使用数据库事务进行清理(测试包含在最后回滚的事务中)。这不适用于多个线程或进程。见https://github.com/jnicklas/capybara#transactions-and-database-setup

解决这个问题的最常见的方法是使用数据库清理宝石 - https://github.com/bmabey/database_cleaner