Skip to content

Instantly share code, notes, and snippets.

@danielvlopes
Created September 29, 2010 13:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielvlopes/602750 to your computer and use it in GitHub Desktop.
Save danielvlopes/602750 to your computer and use it in GitHub Desktop.
require 'spec_helper'
require 'steak'
require 'capybara/rails'
require 'database_cleaner'
require 'akephalos'
DatabaseCleaner.strategy = :truncation
Capybara.default_selector = :css
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
Spec::Runner.configure do |config|
config.include Capybara
config.use_transactional_fixtures = false
config.before(:each) { DatabaseCleaner.start; }
config.after(:each) { DatabaseCleaner.clean; }
config.before(:each) do
account.update_attribute(:domain, "acceptance")
Capybara.default_host = account.full_domain
if options[:js]
Capybara.app_host = "http://#{account.full_domain}:9887"
Capybara.current_driver = :akephalos
end
end
config.after(:each) do
Capybara.use_default_driver if options[:js]
Capybara.reset_sessions!
end
end
# Put your acceptance spec helpers inside /spec/acceptance/support
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
@diegorv
Copy link

diegorv commented Sep 29, 2010

Só pra constar no Rspec 2, não se usa mais options[:js] e sim example.metadata[:js]

thanks!

@sobrinho
Copy link

sobrinho commented Oct 7, 2010

Daniel,

O Akephalos está funcionando bem aí?

Acabei indo pro Selenium porque estava dando uns bugs estranhos no gc_sweep() do Ruby.

@danielvlopes
Copy link
Author

@diegorv no Rspec 2 faço assim: example.options[:js]

@sobrinho, sai do Akephalos pelos mesmos motivos.

@sobrinho
Copy link

Só por curiosidade... Porque fez esse lance da conexão no ActiveRecord?

@danielvlopes
Copy link
Author

Foi uma dica do Carlos Antonio e do Valim... isso mantém a conexão entre os specs em test de integração e tornar os tests um pouco mais rápidos.

@sobrinho
Copy link

Vou testar na minha suíte aqui mas você teve um ganho significativo?

@danielvlopes
Copy link
Author

Sim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment