5

我正在尝试将 Minitest 用于现有的 Rails 应用程序(3.2),但运行路由测试没有任何运气。我试过 rspec 语法(应该 route_to)和 TestUnit 语法(assert_routing),但没有运气。

关于让它工作的任何建议?我需要包含的特定模块等?

谢谢

4

2 回答 2

16

如果您使用的是minitest-rails,您可以通过将以下内容放入来创建路由测试test/routes/homepage_test.rb

require "minitest_helper"

class HomepageRouteTest < ActionDispatch::IntegrationTest
  def test_homepage
    assert_routing "/", :controller => "home", :action => "index"
  end
end

或者,您可以使用 Minitest Spec DSL:

require "minitest_helper"

describe "Homepage Route Acceptance Test" do
  it "resolves the homepage" do
    assert_routing "/", :controller => "home", :action => "index"
  end
end

您可以使用以下 rake 任务运行这些测试:

rake minitest:routes
于 2012-07-27T17:00:12.577 回答
3

@blowmage 的回答帮助了我,但看起来语法发生了一些变化。

使用 Rails 4:

require "test_helper"

class HomepageRouteTest < ActionDispatch::IntegrationTest
  def test_messages
    assert_generates '/messages', :controller => "messages", :action => "index"
  end
end
于 2014-01-16T04:13:10.417 回答