Sign in through GitHub

Please read for an updated status on RailsCasts:

Learn more or hide this

Vojtěch Kusý's Profile

GitHub User: wojtha

Site: http://www.vojtechkusy.com

Comments by Vojtěch Kusý

Avatar

You can use build_stubbed, that will build object with stubbed associations.

Avatar

Thank you for the link to ActiveModel::Serializers! It is awesome. I've built the needed JSON outputs in 5 mins for our all entities.

Avatar

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_UJ
  class ActiveRecord::Base
    mattr_accessor :shared_connection
    @@shared_connection = nil

    def self.connection
      @@shared_connection || retrieve_connection
    end
  end

  # 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 = 1
  Rails.logger.level = 4

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

Edit: Ooops. Ryan created an episode about PhantomJS 3 weeks ago. And he encourages to use this hack too ;-)