A caveat here is that webmock and other net/http mockers will give you a hard time by interfering with your capybara requests with this setup. Suggestions exist to configure Selenium to use Curb instead.

I do integration testing with Rspec but instead I use Steak and Akephalos, I have created a demo https://github.com/boriscy/akephalos_steak to setup a rails app to test, it's a simple configuration. I have also created this tutorial in spanish http://www.boliviaonrails.com/2011/03/01/testeando-javascript-con-steak-y-akephalos/

Javi, thanks! Had to figure it our myself, only to discover later that you have this snippet here for over 2 years. I went a bit further with optimization, so my code is as follows:

ruby

config.before(:suite) do# Do truncation once per suite to vacuum for PostgresDatabaseCleaner.clean_with :truncation# Normally do transactions-based cleanupDatabaseCleaner.strategy = :transactionend
config.around(:each) do |spec|
if spec.metadata[:js]
# JS => run with Poltergeist/Selenium that doesn't share connections # => can't use transactions# deletion is often faster than truncation on Postgres - doesn't vacuum# no need to 'start', clean_with is sufficient for deletion
spec.run
DatabaseCleaner.clean_with :deletionelse# No JS => run with Rack::Test => transactions are okDatabaseCleaner.start
spec.run
DatabaseCleaner.clean
endend

Incredible amount of information passed on!
I'd loved to see you implementing the link_to_function in the view before you wrote the spec for it and having it fail. I know you would have had two failures, firstly the problem with the missing feature and secondly the problem with the missing :js => true. I understand that for a cast, as packed as this one, that might have been too much.
However that is just so much the workflow, that happens to me all the time.

Hmm after all, maybe this cast, which I still consider one of the greatest for my own interest and benefits, might have been worth being split into two....

But I appreciate that great balance of simple, intermediate and advanced casts.

In the past I used Cucumber with Capybara and Selenium to test my javascript. It was just like the setup in this episode, but then with Cucumber instead of Rspec. Selenium also started Firefox automatically to test the javascript. But I was wondering how I could test this on a server instead of my own machine. I mean most servers don't have a GUI and don't have Firefox installed.

Anyone know if I can test javascript also on a server using Selenium and Firefox (or another browser)?

classActiveRecord::Base
mattr_accessor :shared_connection@@shared_connection = nildefself.connection@@shared_connection || retrieve_connection
endend# Forces all threads to share the same connection. This works on# Capybara because it starts the web server in a thread.ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection

Since this screencast I use the request specs for my development.
It works great for understanding of the function and as a direct mapping with use cases from RE.
The only issues I have is speed.
As for most of the specs I need a logged in user. This is therefore created in nearly every before block. Also, the user factory creates certain associated models as well (in this case a company.)

Is there a better/faster way to do it?
Would you use fixtures for those cases?

This is really awesome, thanks for the screencast. Testing JS functionality is a huge improvement for me -- however, it seems to come at a pretty steep speed cost.

Is there a way to configure the specs (or more specifically, to configure Guard) to NOT run JS specs by default? I would prefer to only run those when I run the entire test suite, or if I've "enabled" js testing somehow.

Because guard calls the request spec whenever I do any work on the controller or other request specs, and because the request spec now runs selenium to test in firefox, my guard setup is now painfully slow when I'm working on anything that has associated js tests...

Use poltergeist headless browser driver. It is similar to webkit-capybara, but it is built on top of PhantomJS and easier to setup (no need of Xvfb virtual frame buffer) and place this code to your spec_helper.rb to speed up the tests and to fix the multiple threads issue:

ruby

# specs/spec_helper.rb # Small hack to force Selenium/Webkit tests to use single DB thread# and speed optimization# See http://blog.plataformatec.com.br/2011/12/three-tips-to-improve-the-performance-of-your-test-suite/# and https://groups.google.com/forum/#!msg/ruby-capybara/JI6JrirL9gM/R6YiXj4gi_UJclassActiveRecord::Base
mattr_accessor :shared_connection@@shared_connection = nildefself.connection@@shared_connection || retrieve_connection
endend# Forces all threads to share the same connection. This works on# Capybara because it starts the web server in a thread.ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
Devise.stretches = 1Rails.logger.level = 4

Note: If you are using Spork, place the code to "Spork.each_run" block.