Why does adding “sleep 1” in an after hook cause this Rspec/Capybara test to pass?

I suspect that it’s possible in your application for the comment to disappear from the page (which is the last thing you’re asserting) before it’s deleted from the database. That means that the test can clean up before the deletion happens. If this is the case you can fix it by waiting for the actual … Read more

Net::ReadTimeout (Net::ReadTimeout) Selenium Ruby

Another option to use RSpec::Retry which adds a retry option for intermittently failing specs. require ‘rspec/retry’ RSpec.configure do |config| # show retry status in spec process config.verbose_retry = true # Try twice (retry once) config.default_retry_count = 2 # Only retry when Selenium raises Net::ReadTimeout config.exceptions_to_retry = [Net::ReadTimeout] end

Why not use shared ActiveRecord connections for Rspec + Selenium?

Actually there are issues with it. If you use the gem mysql2, for example, you’ll start seeing some errors like: Mysql2::Error This connection is still waiting for a result Please use this instead. It was written by Mike Perham, all credits to him. class ActiveRecord::Base mattr_accessor :shared_connection @@shared_connection = nil def self.connection @@shared_connection || ConnectionPool::Wrapper.new(:size … Read more

undefined method `visit’ when using RSpec and Capybara in rails

Try to add: config.include Capybara::DSL to your config block. # This file is copied to spec/ when you run ‘rails generate rspec:install’ ENV[“RAILS_ENV”] ||=”test” require File.expand_path(“../../config/environment”, __FILE__) require ‘rspec/rails’ require ‘rspec/autorun’ # Requires supporting ruby files with custom matchers and macros, etc, # in spec/support/ and its subdirectories. Dir[Rails.root.join(“spec/support/**/*.rb”)].each {|f| require f} RSpec.configure do |config| … Read more

How do you POST to a URL in Capybara?

More recently I found this great blog post. Which is great for the cases like Tony and where you really want to post something in your cuke: For my case this became: def send_log(file, project) proj = Project.find(:first, :conditions => “name=”#{project}””) f = File.new(File.join(::Rails.root.to_s, file)) page.driver.post(“projects/” + proj.id.to_s + “/log?upload_path=” + f.to_path) page.driver.status_code.should eql 200 … Read more

Capybara with :js => true causes test to fail

I’ve read the Capybara readme at https://github.com/jnicklas/capybara and it solved my issue. Transactional fixtures only work in the default Rack::Test driver, but not for other drivers like Selenium. Cucumber takes care of this automatically, but with Test::Unit or RSpec, you may have to use the database_cleaner gem. See this explanation (and code for solution 2 … Read more