Why are RSpec specs using Capybara, Poltergeist, and Javascript incompatible?

Greetings to the software developers,

I have a Rails application with the usual test suite (RSpec, Capybara, Poltergeist, jQuery, Rails). I am using small Javascript (jQuery) for remote queries. This basically works, and I still don't understand my problem. Therefore, I can clarify the issue with further knowledge.

Perhaps you could give me some tips on what to research before I post a lot of unnecessary code and configuration.

Inconsistent and unexpected behavior in the specification of a function that checks through the Poltergeist in Capybara that user interaction (clicking forms and links) hides and shows HTML elements through AJAX using jQuery.

It seemed to work correctly if I test manually. Setting the Capybara timeout to wait only changed for the time when I had to wait until the mileage spec =). I have not yet found another appropriate configuration or use.

So any help / idea is greatly appreciated. Thanks in advance.

My spec_helper:

require 'simplecov' require 'rubygems' ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../../config/environment", __FILE__) require 'email_spec' require 'rspec/autorun' require 'rspec/rails' require 'capybara/rspec' require 'capybara/poltergeist' require 'capybara/rails' Capybara.javascript_driver = :poltergeist Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} RSpec.configure do |config| config.include(EmailSpec::Helpers) config.include(EmailSpec::Matchers) config.include Capybara::DSL #config.include Capybara::RSpecMatchers config.mock_with :rspec config.fixture_path = "#{::Rails.root}/spec/fixtures" # If you're not using ActiveRecord, or you'd prefer not to run each of your # examples within a transaction, remove the following line or assign false # instead of true. # set to false with Capybara + Database Cleaner # set to true with ActiveRecord::Base patch from Jose Valim and without Database Cleaner config.use_transactional_fixtures = false config.infer_base_class_for_anonymous_controllers = true config.order = "random" config.include FactoryGirl::Syntax::Methods config.after(:each) do # some model deletion model.delete_all end config.include FeatureHelpers end 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 FactoryGirl.reload 
+6
source share
1 answer

This is the new capybara-poltergeist setting for the rails app, can you check the difference between this and your versions? (I'm too lazy ^ _ ^)

Gemfile

 group :development, :test do gem 'rspec-rails' end group :test do gem 'capybara' gem 'database_cleaner' gem 'poltergeist' gem 'phantomjs', require: 'phantomjs/poltergeist' end 

specifications / spec_helper.rb

 ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' require 'rspec/rails' require 'capybara/rspec' require 'capybara/rails' require 'capybara/poltergeist' Capybara.javascript_driver = :poltergeist Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration) RSpec.configure do |config| config.include FactoryGirl::Syntax::Methods config.order = "random" config.fixture_path = "#{::Rails.root}/spec/fixtures" config.use_transactional_fixtures = false config.infer_base_class_for_anonymous_controllers = false end 

Specification / Support / database_cleaner.rb

 require "database_cleaner" RSpec.configure do |config| config.before(:suite) do DatabaseCleaner.clean_with(:truncation) end config.before(:each) do DatabaseCleaner.strategy = :transaction end config.before(:each, :js => true) do DatabaseCleaner.strategy = :truncation end config.before(:each) do DatabaseCleaner.start end config.after(:each) do DatabaseCleaner.clean end end 

specifications / features / posts_spec.rb

 require "spec_helper" describe "Posts pages" do let!(:post) { create :post } # Factory girl it "has post", js: true do visit posts_path expect(page).to have_content post.title end end 
+6
source

All Articles