【发布时间】:2015-05-20 21:27:06
【问题描述】:
我有一个以js 响应响应的控制器操作。这个js 响应实际上呈现了另一个部分。我想要一个控制器测试,以防部分文件或js 文件出现错误。
控制器:
class ZonesController < ApplicationController
def library_zones
end
end
library_zones.coffee:
$("#zoneSelectionPlaceholder").html("<%= j(render 'library_zones') %>")
_library_zones.html.haml(注意我称模型为 BadName,试图得到一个错误):
= collection_select(:zones, :zone_id, BadName.library_zones, :id, :description, {prompt: 'Zone to Add...'}, {id: 'zoneToAddSelection'})
routes.rb:
resources :zones do
collection do
get 'library_zones
end
end
规格:
RSpec.describe ZonesController, type: :controller do
describe 'library_zones' do
it 'renders library_zones.js template' do
xhr :get, :library_zones
expect(response).to render_template('library_zones')
expect(response.status).to eq(200)
end
end
end
我的所有规格都通过了。我尝试将haml 解析错误引入_library_zones.html.haml 文件以及尝试将js 错误引入librarys_zones.coffee 文件,但似乎没有什么会导致此测试失败。
- RSpec 3.1.7
【问题讨论】:
标签: javascript ruby-on-rails ruby-on-rails-4 rspec