Ruby on rails Rails小型测试,查看控制器的输出
我有一个简单的方法在我的一个Rails控制器中测试我的Ruby on rails Rails小型测试,查看控制器的输出,ruby-on-rails,minitest,Ruby On Rails,Minitest,我有一个简单的方法在我的一个Rails控制器中测试我的索引操作。在minitest中,它向GET/{resource}发送请求,就像GET:index,format::json 在我的索引的控制器操作中,我有几行放入一些变量。从命令行运行测试时,如何查看控制器操作的输出 它在向服务器发送请求时输出,但在从命令行运行测试时不显示。您需要: 控制器: class FooController < ApplicationController def bar puts 'hello'
索引
操作。在minitest中,它向GET/{resource}
发送请求,就像GET:index,format::json
在我的索引的控制器操作中,我有几行放入一些变量。从命令行运行测试时,如何查看控制器操作的输出
它在向服务器发送请求时输出,但在从命令行运行测试时不显示。您需要:
控制器:
class FooController < ApplicationController
def bar
puts 'hello'
end
end
class FooController
测试:
需要“测试助手”
类FooControllerTest
require 'test_helper'
class FooControllerTest < ActionController::TestCase
test 'outputs hello' do
assert_output(/hello/) do # use regex because "hello" will fail per http://stackoverflow.com/a/26855137/46076
post :bar
end
end
end