我的控制器看起来像这样的输出:轨,MINITEST:如何测试控制器
class CalculatorController < ApplicationController
def calculate
money = params[:money].to_f
@worktime = divide(money, 25)
end
private
def divide(money, worktime)
output = money/worktime
end
end
我写了这样一个测试:
require 'test_helper'
class CalculatorControllerTest < ActionDispatch::IntegrationTest
test "response" do
get calculate_path
assert_equal 200, response.status
end
end
该测试通过。现在,我想编写一个测试,检查输出是否正确。我尝试这样做:
require 'test_helper'
class CalculatorControllerTest < ActionDispatch::IntegrationTest
test "response" do
get calculate_path(money: 25)
assert_equal 200, response.status
assert_equal 1, @response.worktime
end
end
但出现此错误:NoMethodError: undefined method
worktime'`
如何测试控制器的输出? (在我的情况@worktime)
您使用的是哪个版本的Rails?在Rails 4中,你可以检查它。在Rails 5中,你必须带上另一块来做你想做的事情。 –
@MichaelChaney Rails 5.0.0.1我需要带什么?谢谢 – Metaphysiker
看到我的回答如下,太多评论:) –