環境
- Rails 4.1.5
- PostgreSQL 9.3.5
- pg 0.17.1
- poltergeist-1.5.1
- capybara-2.4.1
- rspec-3.0.0
- Qt 4.8.6
- Phantomjs 1.9.7
エラー内容
以下のエラーが不規則に発生する。
Poltergeist・Webkitどちらでも発生。
An error occurred in an after hook
ActiveModel::MissingAttributeError: missing attribute: encrypted_password
NoMethodError:
undefined method `fields' for nil:NilClass
An error occurred in an after hook
ActiveRecord::StatementInvalid: PG::UnableToSend: extraneous data in "T" message
PG::UnableToSend: another command is already in progress
その他、テスト実行時にハングアップする。postgresのプロセスを強制終了でテストを終了できる。
(PG::ConnectionBad: PQsocket() can't get socket descriptor: SAVEPOINT active_record_1
)
確認できているIssueなど
試したこと・対応策
Javascriptの処理の終了を待つ
上記のIssueにも載っているが、以下のメソッドを追加し、テスト中にwait_for_ajax
を実行することで
処理が正常に行われるようになった。
module WaitForAjax
def wait_for_ajax
Timeout.timeout(Capybara.default_wait_time) do
loop until finished_all_ajax_requests?
end
end
def finished_all_ajax_requests?
page.evaluate_script('jQuery.active').zero?
end
end
gem pg のアップデートを待ってみる
最初はPotergeistで発生し、Webkitに変更しても発生したことから、PostgreSQL依存のエラーかもしれない。
と思って、pgのリポジトリを覗いてみるとバージョン0.18がもうすぐでそうな感じ。
関係ありそうなissue(PG.connect ignores connect_timeout)もあるので、gemのアップデートを待ってみようと思う。