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

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

How can I test the page title with Capybara 2.0?

I had the same issues when I upgraded to Capybara 2.0, and managed to solve them by creating the following custom RSpec matcher using Capybara.string: spec/support/utilities.rb RSpec::Matchers::define :have_title do |text| match do |page| Capybara.string(page.body).has_selector?(‘title’, text: text) end end Now, in a spec file where subject { page }, I can use: it { should have_title(“My … Read more