【发布时间】:2015-12-31 02:13:46
【问题描述】:
使用 Rails 4.2、Minitest 和 Shoulda...
student_phone_numbers_controller_test.rb
class StudentPhoneNumbersControllerTest < ActionController::TestCase
context "deleting to remove" do
context "when the phone number doesn't belong to the student" do
setup do
log_in_as(teachers(:schmidt))
delete :remove,
format: "js",
student_id: students(:two).id,
id: phone_numbers(:one_one).id
end
should use_before_action :logged_in_teacher
should use_before_action :set_student
should respond_with :redirect
should redirect_to { student_path students(:two) }
end
end
end
一般来说,Shouda 和 Rails 测试的新手,我的代码似乎与 the Minitest documentation for redirect_to 平行。但是,我在运行测试时遇到了这个错误......
$ rake test:controllers
rake aborted!
ArgumentError: wrong number of arguments (0 for 1)
...指向should redirect_to 行。我假设它想要控制器/动作哈希?
以下行按预期工作:
should redirect_to(controller: :students, action: :show) { student_url students(:two) }
...这样...
should redirect_to({}) { student_url students(:two) }
第一个修复完全是多余的。第二个似乎是多余的。我意识到the source for this method 没有单个参数的默认值。应该吗?
或者,我是否明显遗漏了有关此助手的目的/工作原理的其他内容?
【问题讨论】:
标签: ruby-on-rails minitest shoulda