【发布时间】:2012-09-26 05:08:48
【问题描述】:
我想将常用的控制器动作、索引、显示、创建等放在 ApplicationController 中,如下所示:
class ApplicationController < ActionController::Base
respond_to :json
def index
#implementation
end
def show
#implementation
end
def update
#implementation
end
end
应用只会返回 JSON。
我编写了以下规范以使用 RSPEC 的匿名控制器对此进行测试
describe ApplicationController do
controller do ; end
describe 'Get :index' do
it 'should respond to index' do
get :index
response.code.should eq "200"
end
end
end
上述规范给出以下错误:
ActionView::MissingTemplate:缺少模板匿名/索引, 应用程序/索引与 {:locale=>[:en], :formats=>[:json], :handlers=>[:erb, :builder]}。搜索:* “#”
任何人都可以提出一种使用匿名控制器进行这项工作的方法吗?
【问题讨论】:
-
使用
xhr :get :index代替get :index有帮助吗?
标签: ruby-on-rails rspec