0

这是我的功能测试:

require 'test_helper'

class PagesControllerTest < ActionController::TestCase
  tests Refinery::PagesController
  include Devise::TestHelpers 

  def setup
    Rails.application.load_seed 
  end

  test "about us page" do
    assert_equal "about", Refinery::Page.find_by_slug("about").slug

    get :show, { use_route: :about }
    assert_response :success
  end

end

这是我运行它时得到的:

$ rake test TEST=test/functional/pages_controller_test.rb
Run options:

# Running tests:

F

Finished tests in 3.709222s, 0.2696 tests/s, 0.8088 assertions/s.

  1) Failure:
test_access_about_page(PagesControllerTest) [test/functional/pages_controller_test.rb:17]:
Expected response to be a <:success>, but was <404>

1 tests, 3 assertions, 1 failures, 0 errors, 0 skips
rake aborted!

我应该如何在我的测试中路由get请求?

4

1 回答 1

1

Rails Engines 指南中关于功能测试的部分帮助我解决了这个问题。

这是get我需要的请求:

get :show, {use_route: :refinery, path: :about}

现在通过的完整测试:

require 'test_helper'

class PagesControllerTest < ActionController::TestCase
  tests Refinery::PagesController
  include Devise::TestHelpers 

  def setup
    Rails.application.load_seed 
  end

  test "about us page" do
    assert_equal "about", Refinery::Page.find_by_slug("about").slug

    get :show, {use_route: :refinery, path: :about}
    assert @response.body.include? "About Us"
    assert_response :success
  end

end
于 2013-08-12T16:45:32.080 回答