Take the tour ×

I've tried the answers to these questions: 1, 2. The first one indicates it might be a caching issue (and suggests running rake tmp:clear). The second one suggests forcing ENV['RAILS_ENV'] = 'test' in spec_helper.rb since rake is run in 'development'. I've also tried removing the vcr gem completely, but this has no effect either.

This comment gives more details on how the problem might be due to a dirty environment (since rake starts in 'development', but rspec is run in 'test').

The spec in question uses capybara and capybara-webkit. It passes when run via bundle exec rake spec:requests but fails when it's run in the suite via bundle exec rake. The html that capybara sees is different in both cases, and when run in the suite it doesn't see the element #movie_imdb_id.

I'm using gem versions rspec (2.11.0), capybara (1.1.3), and capybara-webkit (0.12.1).

Rspec message:


  1) Imdb credits get credits should have a credits table
     Failure/Error: wait_until { page.find('#movie_imdb_id').visible? }
       Unable to find css "#movie_imdb_id"
     # (eval):2:in `find'
     # ./spec/requests/imdb_credits_spec.rb:9:in `block (3 levels) in <top (required)>'
     # ./spec/requests/imdb_credits_spec.rb:9:in `block (2 levels) in <top (required)>'


ENV["RAILS_ENV"] = 'test'
require 'rspec/rails'
require 'rspec/autorun'
require 'database_cleaner'
require 'paper_trail'
require 'factory_girl'
require 'vcr'
require 'imdb_patch'
require 'capybara/rails'
# require 'capybara/rspec'
require 'capybara/webkit'

ENV['APP_DOMAIN'] = 'www.example.com'
ENV['DOMAIN'] = 'example.com'

# Require the fanatic and food factories
require Fanatic::Engine.config.root + 'spec/factories'
Dir[Rails.root.join("spec/factories/**/*.rb")].each {|f| require f}

# in spec/support/ and its subdirectories.

RSpec.configure do |config|
  config.include Warden::Test::Helpers
  config.include PostsHelper
  config.include SpecHelpers

  Capybara.javascript_driver = :webkit

  # ## Mock Framework
  # config.mock_with :mocha
  # config.mock_with :flexmock
  # config.mock_with :rr
  config.mock_with :rspec

  # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
  #config.fixture_path = "#{::Rails.root}/spec/fixtures"

  # instead of true.
  config.use_transactional_fixtures = false

  config.before(:suite) do
    DatabaseCleaner.strategy = :truncation
    PaperTrail.enabled = false

  config.before(:each) do

  config.after(:each) do

  # rspec-rails.
  config.infer_base_class_for_anonymous_controllers = false

  config.include FactoryGirl::Syntax::Methods

VCR.configure do |c|
  c.ignore_localhost = true
  c.hook_into :fakeweb
  c.cassette_library_dir = Rails.root.join('spec/fixtures/vcr_cassettes')


require 'spec_helper'

describe 'Imdb credits', :js => true do
  before(:each) do

    visit '/admin/movie/new'
    Rails.logger.debug page.html.to_yaml

    fill_in 'Title',   :with => 'Batman'
    fill_in 'Imdb id', :with => '0096895'

    VCR.use_cassette('imdb_get', :match_requests_on => [get_matcher]) do
      click_button 'Fetch Imdb credits'
      wait_until { page.find('table#imdb_credits').visible? }

  describe 'get credits' do

    it 'should have a credits table' do
      page.should have_selector('table#imdb_credits')

share|improve this question
Does bundle exec rspec spec work? –  Benjamin Tan Nov 28 '12 at 17:55
Thanks for the reply Benjamin. Yes it does. –  Luke Grecki Nov 29 '12 at 20:16
@BenjaminTan I'd still like to be able to run bundle exec rake. Any ideas? –  Luke Grecki Nov 30 '12 at 19:34
add comment

1 Answer

up vote 0 down vote accepted

The problem was actually the gem rails_admin and how it was interacting with rake. It was fixed by adding the following to spec_helper.rb:

share|improve this answer
add comment

Your Answer


