2

this is my first questions online EVER, so please comment and I'll try to update my questions to clarify.

I am quite new to web development, and is currently working on a test suite for a company project. It was working nicely up to the point when I'm trying to do an integration test on a function, which involves javascript. I tried using both webkit(bundled from git) and selenium. Webkit gave the following error message.

Wrote response false "Unable to load URL: http://127.0.0.1:56618/ because of error loading http://127.0.0.1:56618/: Connection closed" 
Cleaning database...done
Received "Reset" 
Started "Reset" 
Finished "Reset" 
Wrote response true "" 
  should see invalid message (FAILED - 1)
Failures:
  1) Users GET /sign_in with invalid account should see invalid message
 Failure/Error: visit root_path
 Capybara::Webkit::InvalidResponseError:
   Unable to load URL: http://127.0.0.1:56618/ because of error loading http://127.0.0.1:56618/: Connection closed

And when using Selenium, the FireFox complain about:

Your Firefox profile cannot be loaded. It may be missing or inaccessible.

Does anybody have some clue as to what might be the problem? Thanks in advance!

my sepc_helper.rb

Spork.prefork do
  ...
  ..
  .
  RSpec.configure do |config|
    config.use_transactional_fixtures = false
    config.before(:suite) { require "#{Rails.root}/db/seeds.rb" }
    config.before(:each) do
      if Capybara.current_driver == :rack_test
        DatabaseCleaner.strategy = :transaction                                                                               
      else
        DatabaseCleaner.strategy = :truncation
      end
      DatabaseCleaner.start
    end

    config.after(:each) do
      if Capybara.current_driver == :rack_test
        DatabaseCleaner.clean
      else
        DatabaseCleaner.clean
        load "#{Rails.root}/db/seeds.rb"
      end 
    end 

  end
end

Spork.each_run do
  ActiveRecord::Schema.verbose = false
  load "#{Rails.root.to_s}/db/schema.rb"
  Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
end
Mickey
  • 501
  • 4
  • 8
  • 1
    Looks similar to this: http://stackoverflow.com/questions/11757118/capybara-webkit-invalid-response-error-how-to-debug/11879830#11879830 – Chris Salzberg Aug 19 '12 at 12:09
  • hmm, the problem seems a little bit different, but the discussion you provided seems more relevant. Thank you very much, I will read it carefully! – Mickey Aug 20 '12 at 04:14
  • Good luck! It's a nasty bug... – Chris Salzberg Aug 20 '12 at 04:16
  • I had very similar error when I had broken broken redirections in my before filters. Could you show us log/test.log output? – luacassus Oct 15 '12 at 18:47
  • Well, I no longer work there, so I don't get access to the project. However, in the end, our project manager end up finding other test for javascript testing. – Mickey Dec 05 '12 at 08:07

1 Answers1

2

I am not sure but you can try this,

Add below code in your spec_helper.rb file

require 'spork'
Spork.prefork do

   # 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'

  require 'email_spec'


  # Add this to load Capybara integration:

  require 'capybara/rspec'
  require 'capybara/rails'

  # Database Cleaner
  #require 'database_cleaner'

  # DatabaseCleaner.strategy = :truncation


  # 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}

Spork.each_run do
end

Do one thing uncomment database cleaner.

SliverNinja - MSFT
  • 31,051
  • 11
  • 110
  • 173
prasad_g
  • 139
  • 8