我想将常见的控制器操作、索引、显示、创建等放在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}的应用程序/索引。搜索:* "#“
有人能给匿名控制器提供一种方法来解决这个问题吗?
发布于 2012-10-05 04:43:24
试试看这可能会有帮助
你的控制器就像
def index
end您的rspec测试如下
describe "GET index" do
it "should respond to index" do
get :index
response.code.should eq "200"
end
end在应用程序/文件夹中创建index.html.erb
那就试一试。
发布于 2012-10-05 07:12:39
描述“获取索引”
it "returns correct JSON" do
# @groups.should have(2).items
get :index, :format => :json
response.should be_success
body = JSON.parse(response.body)
body.should include('group')
groups = body['group']
groups.should have(2).items
groups.all? {|group| group.key?('customers_count')}.should be_true
groups.any? {|group| group.key?('customer_ids')}.should be_false
end结束
https://stackoverflow.com/questions/12739553
复制相似问题