Railsアプリに、RSpec+Capybaraでテストを書いています。
JavaScriptのドライバはPoltergeistです。
内容
問題はCapybaraでのテスト中に起こります。
以下のように、link_to
からAjaxでpostした際、なぜかhtmlとしてリクエストしてしまうのです。
View
lang
1link_to ‘Button’, xxx_path, method: :post, remote: true
Controller
lang
1class XxxController < ApplicationController 2 def create 3 # : 4 5 render ‘create’ # create.js.coffee を呼び出す 6 end 7end
RSpec+Capybara
lang
1it ‘xxx’, js: true do 2 find(‘.xxx a').click 3end
エラー内容
Failure/Error: find(‘.xxx a').click ActionView::MissingTemplate: Missing template xxx/create with {:locale=>[:ja], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee, :haml]}.
:formats=>[:html]
とあるので、.js.coffee
ではなく.html.haml
を要求していることになっていると認識しています。
備考
上記は、投票機能のように、リンクを押したらAjaxで投票する、という機能の一部です。
普通にブラウザから確認した際は問題なくcreate.js.coffee
の結果が反映されます。
テストの際だけ上記エラーが出てしまいます。
なにかヒントでもいただければ幸いです。
よろしくお願いいたします。
あなたの回答
tips
プレビュー