带Rails的Minitest中的匿名控制器 [英] Anonymous controller in Minitest w/ Rails
本文介绍了带Rails的Minitest中的匿名控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从RSpec转换为Minitest时,我遇到了一个小问题,Google对此一无所获,这正在弄清楚该怎么做:
While converting from RSpec to Minitest I ran into a slight issue that Google has not helped with one bit, and that's figuring out how to do something like this:
describe ApplicationController do
controller do
def index
render nothing: true
end
end
it "should catch bad slugs" do
get :index, slug: "bad%20slug"
response.code.should eq("403")
end
end
使用Minitest.有没有办法在Minitest中创建像这样的匿名控制器,或者有文档可以帮助我学习如何用minitest测试控制器?
with Minitest. Is there a way to create anonymous controllers like this inside of Minitest or is there documentation that could help me learn how to test controllers with minitest?
推荐答案
我认为不支持匿名控制器.尝试在测试中定义一个控制器,而不是使用DSL创建一个控制器.
I don't think anonymous controllers are supported. Instead of using a DSL to create a controller, try defining a controller in your test.
class SlugTestController < ApplicationController
def index
render nothing: true
end
end
describe SlugTestController do
it "should catch bad slugs" do
get :index, slug: "bad%20slug"
response.code.must_equal "403"
end
end
这篇关于带Rails的Minitest中的匿名控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文