为什么我的集成测试失败了?"ArgumentError:错误的参数(预期的URI对象或URI字符串)"

Chl*_*loe 3 integration-testing ruby-on-rails ruby-on-rails-4

为什么此测试会出现此错误?

错误

  1) Error:
PostIntegrationTest#test_should_not_show_comment_box_if_not_logged_in:
ArgumentError: bad argument (expected URI object or URI string)
    test/integration/post_integration_test.rb:6:in `block in <class:PostIntegrationTest>'
Run Code Online (Sandbox Code Playgroud)

代码,post_integration_test.rb

require 'test_helper'

class PostIntegrationTest < ActionDispatch::IntegrationTest

  test "should not show comment box if not logged in" do
    get :show, 'id' => 1                       ########### LINE 6
    assert_select 'textarea', false, "Comment textarea must not exist if not logged in"
  end
Run Code Online (Sandbox Code Playgroud)

也行不通

get :show, {'id' => 1}
get :show, {id: 1}
Run Code Online (Sandbox Code Playgroud)

参考

这表示你可以传递参数.http://api.rubyonrails.org/classes/ActionController/TestCase/Behavior.html#method-i-get

这是使用参数的示例get:http://guides.rubyonrails.org/testing.html#setup-and-teardown

$ rails -v
Rails 4.0.0
Run Code Online (Sandbox Code Playgroud)

vee*_*vee 5

:show在集成测试中不可用,这些操作仅在Controller测试中可用.您需要使用_path网址的帮助或字符串表示.

test "should not show comment box if not logged in" do
  # Assuming path is /posts.  Replace accordingly.
  get "/posts/1"                      ########### LINE 6
  assert_select 'textarea', false, "Comment textarea must not exist if not logged in"
end
Run Code Online (Sandbox Code Playgroud)