Commit c3eb6b914d235eaf7cfca56f3a283a4656e62f0b

Authored by Diego Camarinha
2 parents f87ff443 c7766f1c

Merge pull request #243 from mezuro/fix-konacha-hang

Attempt to fix Konacha test hangs on Travis by changing web server
Gemfile
... ... @@ -77,7 +77,10 @@ group :test do
77 77 gem 'mocha', require: 'mocha/api'
78 78  
79 79 # Test coverage report
80   - gem "codeclimate-test-reporter", require: nil
  80 + gem 'codeclimate-test-reporter', require: nil
  81 +
  82 + # For Konacha
  83 + gem 'thin'
81 84 end
82 85  
83 86 group :development, :test do
... ...
Gemfile.lock
... ... @@ -105,6 +105,7 @@ GEM
105 105 mime-types (>= 1.16, < 3)
106 106 nokogiri (~> 1.5)
107 107 rails (>= 3, < 5)
  108 + daemons (1.2.3)
108 109 dalli (2.7.4)
109 110 database_cleaner (1.4.1)
110 111 debug_inspector (0.0.2)
... ... @@ -120,6 +121,7 @@ GEM
120 121 domain_name (0.5.24)
121 122 unf (>= 0.0.5, < 1.0.0)
122 123 erubis (2.7.0)
  124 + eventmachine (1.0.7)
123 125 exception_notification (4.1.1)
124 126 actionmailer (>= 3.0.4)
125 127 activesupport (>= 3.0.4)
... ... @@ -293,6 +295,10 @@ GEM
293 295 therubyracer (0.12.2)
294 296 libv8 (~> 3.16.14.0)
295 297 ref
  298 + thin (1.6.3)
  299 + daemons (~> 1.0, >= 1.0.9)
  300 + eventmachine (~> 1.0)
  301 + rack (~> 1.0)
296 302 thor (0.19.1)
297 303 thread_safe (0.3.5)
298 304 tilt (1.4.1)
... ... @@ -364,6 +370,7 @@ DEPENDENCIES
364 370 sprockets
365 371 sqlite3
366 372 therubyracer
  373 + thin
367 374 turbolinks
368 375 twitter-bootstrap-rails!
369 376 uglifier (>= 1.3.0)
... ...
config/initializers/konacha.rb
1   -Konacha.configure do |config|
2   - require 'capybara/poltergeist'
  1 +if defined?(Konacha)
  2 + Konacha.configure do |config|
  3 + require 'capybara/poltergeist'
3 4  
4   - config.spec_dir = "spec/javascripts"
5   - config.spec_matcher = /_spec\.|_test\./
6   - config.stylesheets = %w(application)
7   - config.driver = :poltergeist
8   -end if defined?(Konacha)
9 5 \ No newline at end of file
  6 + config.spec_dir = "spec/javascripts"
  7 + config.spec_matcher = /_spec\.|_test\./
  8 + config.stylesheets = %w(application)
  9 + config.driver = :poltergeist
  10 + end
  11 +
  12 + # Use thin to run Konacha tests. This is needed because the tests hang frequently in Travis using the default (WEBRick)
  13 + # We can't just do 'Capybara.server' in the configure block because it will also apply to anything else run by
  14 + # Capybara. So instead, override the Konacha.run method to change the server, and restore it after completion.
  15 + module Konacha
  16 + class << self
  17 + old_run = instance_method(:run)
  18 +
  19 + define_method(:run) do
  20 + prev_server = Capybara.server
  21 + begin
  22 + Capybara.server do |app, port|
  23 + require 'rack/handler/thin'
  24 + Rack::Handler::Thin.run(app, :Port => port)
  25 + end
  26 + old_run.bind(self).call
  27 + ensure
  28 + Capybara.server(&prev_server)
  29 + end
  30 + end
  31 + end
  32 + end
  33 +end
... ...