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)
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)
: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)
| 归档时间: |
|
| 查看次数: |
1243 次 |
| 最近记录: |