为什么 MiniTest 中有 2 种控制器测试?
Why are there 2 kinds of controller tests in MiniTest?
我正在从 RSpec 转换到 MiniTest,但遇到了一些困难。我一直在关注我发现的一些例子:
class ArticlesControllerTest < ActionController::TestCase
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:articles)
end
end
所以这是一个 class 继承自 ActionController::TestCase,这是有道理的。
但是还有其他类似的例子:
require 'test_helper'
describe ThingsController do
describe "#create" do
it do "valid"
login_user
post :create, { catalog: { name: "My Thing", description: "Description of my thing."}}
assert_redirected_to thing_path(Thing.last)
end
end
end
为什么这两种风格不同?我正在使用第二个示例,我的 none 重定向就像在我的开发系统中一样工作。试图追根究底。
第一个是 Minitest::Unit 测试语法解释 here
第二种更像 Rspec 语法,你可以使用 minitest-spec-rails gem
我正在从 RSpec 转换到 MiniTest,但遇到了一些困难。我一直在关注我发现的一些例子:
class ArticlesControllerTest < ActionController::TestCase
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:articles)
end
end
所以这是一个 class 继承自 ActionController::TestCase,这是有道理的。
但是还有其他类似的例子:
require 'test_helper'
describe ThingsController do
describe "#create" do
it do "valid"
login_user
post :create, { catalog: { name: "My Thing", description: "Description of my thing."}}
assert_redirected_to thing_path(Thing.last)
end
end
end
为什么这两种风格不同?我正在使用第二个示例,我的 none 重定向就像在我的开发系统中一样工作。试图追根究底。
第一个是 Minitest::Unit 测试语法解释 here
第二种更像 Rspec 语法,你可以使用 minitest-spec-rails gem