最近、アプリを Rails 3.0.12 から 3.1.4 にアップグレードしようとしましたが、JS テストに capybara-webkit を使用する多くの受け入れ仕様がハングしたり、さまざまなデータベース エラーを伴う一時的な障害を表示したりしています。
spec_helper.rb にはかなり一般的なハックがあり、spec 自体と capybara-webkit がスポーンするサーバーとの間で DB 接続を共有しています。これらのスレッド間で何らかのデッドロックや競合状態が発生している可能性があります。
グーグルで調べてみると、このハックでは Unicorn がうまく機能しないことがわかりました (以前はうまくいきましたが)。そのため、thin と WEBrick に順番に切り替えてみました。
Gemfile.lock は次のとおりです。
GEM
remote: http://rubygems.org/
specs:
abstract (1.0.0)
actionmailer (3.0.12)
actionpack (= 3.0.12)
mail (~> 2.2.19)
actionpack (3.0.12)
activemodel (= 3.0.12)
activesupport (= 3.0.12)
builder (~> 2.1.2)
erubis (~> 2.6.6)
i18n (~> 0.5.0)
rack (~> 1.2.5)
rack-mount (~> 0.6.14)
rack-test (~> 0.5.7)
tzinfo (~> 0.3.23)
activemodel (3.0.12)
activesupport (= 3.0.12)
builder (~> 2.1.2)
i18n (~> 0.5.0)
activerecord (3.0.12)
activemodel (= 3.0.12)
activesupport (= 3.0.12)
arel (~> 2.0.10)
tzinfo (~> 0.3.23)
activeresource (3.0.12)
activemodel (= 3.0.12)
activesupport (= 3.0.12)
activesupport (3.0.12)
addressable (2.2.8)
airbrake (3.0.9)
activesupport
builder
archive-tar-minitar (0.5.2)
arel (2.0.10)
aws-s3 (0.6.2)
builder
mime-types
xml-simple
aws-sdk (1.4.1)
httparty (~> 0.7)
json (~> 1.4)
nokogiri (>= 1.4.4)
uuidtools (~> 2.1)
bourne (1.1.2)
mocha (= 0.10.5)
bson (1.6.2)
bson_ext (1.6.2)
bson (~> 1.6.2)
builder (2.1.2)
capybara (1.1.2)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
selenium-webdriver (~> 2.0)
xpath (~> 0.1.4)
capybara-webkit (0.11.0)
capybara (>= 1.0.0, < 1.2)
json
childprocess (0.3.2)
ffi (~> 1.0.6)
chronic (0.6.7)
clearance (0.16.1)
diesel (~> 0.1.5)
rails (>= 3.0)
cocaine (0.2.1)
coderay (1.0.6)
columnize (0.3.6)
cucumber (1.2.0)
builder (>= 2.1.2)
diff-lcs (>= 1.1.3)
gherkin (~> 2.10.0)
json (>= 1.4.6)
cucumber-rails (1.3.0)
capybara (>= 1.1.2)
cucumber (>= 1.1.8)
nokogiri (>= 1.5.0)
database_cleaner (0.7.2)
debugger (1.1.3)
columnize (>= 0.3.1)
debugger-linecache (~> 1.1.1)
debugger-ruby_core_source (~> 1.1.2)
debugger-linecache (1.1.1)
debugger-ruby_core_source (>= 1.1.1)
debugger-ruby_core_source (1.1.2)
delayed_job (3.0.2)
activesupport (~> 3.0)
delayed_job_active_record (0.3.2)
activerecord (> 2.1.0)
delayed_job (~> 3.0.0)
diesel (0.1.5)
railties
diff-lcs (1.1.3)
dynamic_form (1.1.4)
email_spec (1.2.1)
mail (~> 2.2)
rspec (~> 2.0)
erubis (2.6.6)
abstract (>= 1.0.0)
escape (0.0.4)
excon (0.13.4)
factory_girl (3.2.0)
activesupport (>= 3.0.0)
factory_girl_rails (3.2.0)
factory_girl (~> 3.2.0)
railties (>= 3.0.0)
fakeweb (1.3.0)
ffi (1.0.11)
flay (1.4.3)
ruby_parser (~> 2.0)
sexp_processor (~> 3.0)
flog (2.5.3)
ruby_parser (~> 2.0)
sexp_processor (~> 3.0)
flutie (1.3.3)
formtastic (1.2.2)
actionpack (>= 2.3.7)
activesupport (>= 2.3.7)
i18n (>= 0.4.0)
gherkin (2.10.0)
json (>= 1.4.6)
haml (3.1.5)
haml-rails (0.3.4)
actionpack (~> 3.0)
activesupport (~> 3.0)
haml (~> 3.0)
railties (~> 3.0)
heroku (2.25.0)
launchy (>= 0.3.2)
netrc (~> 0.7.1)
rest-client (~> 1.6.1)
rubyzip
heroku-api (0.1.3)
excon (~> 0.13.3)
heroku_san (2.2.2)
heroku (>= 2)
heroku-api (>= 0.1.2)
rake
high_voltage (1.1.1)
httparty (0.8.3)
multi_json (~> 1.0)
multi_xml
i18n (0.5.0)
json (1.7.1)
jwt (0.1.4)
json (>= 1.2.4)
kgio (2.7.4)
launchy (2.1.0)
addressable (~> 2.2.6)
libwebsocket (0.1.3)
addressable
linecache (0.46)
rbx-require-relative (> 0.0.4)
linecache19 (0.5.12)
ruby_core_source (>= 0.1.4)
mail (2.2.19)
activesupport (>= 2.3.6)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
metaclass (0.0.1)
method_source (0.7.1)
mime-types (1.18)
mixpanel (1.1.3)
escape
json
rack
mixpanel_client (2.2.1)
json (~> 1.6)
mocha (0.10.5)
metaclass (~> 0.0.1)
mongo (1.6.2)
bson (~> 1.6.2)
mongoid (2.2.6)
activemodel (~> 3.0.0)
mongo (~> 1.3)
tzinfo (~> 0.3.22)
multi_json (1.3.4)
multi_xml (0.5.0)
netrc (0.7.1)
newrelic_rpm (3.3.4.1)
nokogiri (1.5.2)
paperclip (3.0.3)
activemodel (>= 3.0.0)
activerecord (>= 3.0.0)
activesupport (>= 3.0.0)
cocaine (>= 0.0.2)
mime-types
parallel (0.5.16)
parallel_tests (0.8.1)
parallel
pg (0.13.2)
polyglot (0.3.3)
pry (0.9.9.4)
coderay (~> 1.0.5)
method_source (~> 0.7.1)
slop (>= 2.4.4, < 3)
pry-doc (0.4.1)
pry (>= 0.9.0)
yard (~> 0.7.4)
pry_debug (0.0.1)
pry (~> 0.9.0)
rack (1.2.5)
rack-mount (0.6.14)
rack (>= 1.0.0)
rack-test (0.5.7)
rack (>= 1.0)
rails (3.0.12)
actionmailer (= 3.0.12)
actionpack (= 3.0.12)
activerecord (= 3.0.12)
activeresource (= 3.0.12)
activesupport (= 3.0.12)
bundler (~> 1.0)
railties (= 3.0.12)
railties (3.0.12)
actionpack (= 3.0.12)
activesupport (= 3.0.12)
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (~> 0.14.4)
raindrops (0.8.0)
rake (0.9.2.2)
rbx-require-relative (0.0.9)
rdoc (3.12)
json (~> 1.4)
reek (1.2.8)
ruby2ruby (~> 1.2)
ruby_parser (~> 2.0)
sexp_processor (~> 3.0)
rest-client (1.6.7)
mime-types (>= 1.16)
rspec (2.10.0)
rspec-core (~> 2.10.0)
rspec-expectations (~> 2.10.0)
rspec-mocks (~> 2.10.0)
rspec-core (2.10.0)
rspec-expectations (2.10.0)
diff-lcs (~> 1.1.3)
rspec-mocks (2.10.1)
rspec-rails (2.10.1)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec (~> 2.10.0)
ruby-debug (0.10.4)
columnize (>= 0.1)
ruby-debug-base (~> 0.10.4.0)
ruby-debug-base (0.10.4)
linecache (>= 0.3)
ruby2ruby (1.3.1)
ruby_parser (~> 2.0)
sexp_processor (~> 3.0)
ruby_core_source (0.1.5)
archive-tar-minitar (>= 0.5.2)
ruby_parser (2.3.1)
sexp_processor (~> 3.0)
rubyzip (0.9.8)
sass (3.1.17)
selenium-webdriver (2.21.2)
childprocess (>= 0.2.5)
ffi (~> 1.0)
libwebsocket (~> 0.1.3)
multi_json (~> 1.0)
rubyzip
sexp_processor (3.2.0)
sham_rack (1.3.4)
rack
shoulda (2.11.3)
shoulda-matchers (1.1.0)
activesupport (>= 3.0.0)
show_me_the_cookies (1.1.0)
capybara (~> 1.0)
sinatra (1.2.8)
rack (~> 1.1)
tilt (>= 1.2.2, < 2.0)
slop (2.4.4)
steak (2.0.0)
capybara (>= 1.0.0)
rspec-rails (>= 2.5.0)
thor (0.14.6)
tilt (1.3.3)
timecop (0.3.5)
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
twilio-rb (2.2.0)
activesupport (>= 3.0.0)
builder (>= 2.1.2)
httparty (>= 0.6.1)
i18n (~> 0.5)
jwt (>= 0.1.3)
tzinfo (0.3.33)
unicorn (4.3.1)
kgio (~> 2.6)
rack
raindrops (~> 0.7)
uuidtools (2.1.2)
validation_reflection (1.0.0)
will_paginate (3.0.3)
xml-simple (1.1.1)
xpath (0.1.4)
nokogiri (~> 1.3)
yard (0.7.5)
PLATFORMS
ruby
DEPENDENCIES
airbrake
aws-s3
aws-sdk
bourne
bson_ext
capybara
capybara-webkit
chronic
clearance
cucumber-rails
database_cleaner
debugger
delayed_job
delayed_job_active_record
dynamic_form
email_spec (~> 1.1)
factory_girl_rails
fakeweb
flay
flog
flutie
formtastic (= 1.2.2)
haml-rails
heroku_san
high_voltage
linecache
linecache19
mixpanel
mixpanel_client
mongoid
newrelic_rpm
nokogiri
paperclip
parallel_tests
pg
pry
pry-doc
pry_debug
rack
rails (~> 3.0.12)
reek
rspec-rails
ruby-debug
sass
sham_rack
shoulda
shoulda-matchers
show_me_the_cookies
sinatra
steak
timecop
twilio-rb
unicorn
validation_reflection
will_paginate
そして、spec_helper.rb は次のとおりです。
# 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 'clearance/testing'
require 'rspec/autorun'
# 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}
RSpec.configure do |config|
# == Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
config.mock_with :mocha
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
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.
config.use_transactional_fixtures = true
config.before(:each) do
Mixpanel::Tracker.stubs(:new).with(MIXPANEL_TOKEN, Mocha::ParameterMatchers::KindOf.new(Hash)).returns(FakeMixpanelTracker)
FakeMixpanelTracker.clear_tracked_events
end
config.before(:each) do
User::SegmentationData.delete_all
User::SegmentationResults.delete_all
end
end
# Big Fat Hack (TM) so the ActiveRecord connections are shared across threads.
# This is a variation of a hack you can find all over the web to make
# capybara usable without having to switch to non transactional
# fixtures.
# http://groups.google.com/group/ruby-capybara/browse_thread/thread/248e89ae2acbf603/e5da9e9bfac733e0
Thread.main[:activerecord_connection] = ActiveRecord::Base.retrieve_connection
def (ActiveRecord::Base).connection
Thread.main[:activerecord_connection]
end
require 'capybara-webkit'
Capybara.javascript_driver = :webkit
# Hack to allow us to use regular controller tests to test SmsController
# (which is an ActionController::Metal).
def metal_testing_hack(klass)
klass.class_eval do
include ActionController::UrlFor
include ActionController::Testing
include Rails.application.routes.url_helpers
include ActionController::Compatibility
end
end
require 'ruby-debug'
Rails.logger.level = 4
どんなアドバイスでも大歓迎です。