ruby on rails - Why do RSpec feature specs using Capybara, Poltergeist and Javascript fail inconsistently? -


hi fellow software developers,

i have rails app usual testsuite set (rspec, capybara, poltergeist, jquery, rails). use little javascript(jquery) remote requests. works , don't understand problem yet. may update question further knowledge.

maybe give me hints investigate before post lots of irrelevant code , config.

the inconsistent , unexpected behaviour in feature spec tests via poltergeist in capybara user interaction (clicking forms , links) hides , shows html-elements via ajax jquery.

it seemed works correctly if test manually. setting capybara default time wait changed time had wait until spec run =). found no other relevant configuration or usage yet.

so help/idea appreciated. 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 |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 run each of   # examples within transaction, remove following line or assign false   # instead of true.   # set false capybara + database cleaner   # set true activerecord::base patch jose valim , 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)     # 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 threads share same connection. works on capybara # # because starts web server in thread activerecord::base.shared_connection = activerecord::base.connection  factorygirl.reload 

this fresh setup of capybara-poltergeist rails app, check difference between , versions? (i'm lazy ^_^ )

gemfile

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

spec/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 |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 

spec/support/database_cleaner.rb

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

spec/features/posts_spec.rb

require "spec_helper"  describe "posts pages"   let!(:post) { create :post } # factory girl    "has post", js: true     visit posts_path     expect(page).to have_content post.title   end end 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -