为什么我在运行rails功能测试时得到“ArgumentError:错误的参数数量(1表示0)”?

时间:2010-05-31 22:31:53

标签: ruby-on-rails ruby unit-testing

我对导致这种情况的原因感到难过。我在所有功能测试中得到此错误和堆栈跟踪,我称之为“post”。这是完整的堆栈跟踪:

  7) Error:
test_should_validate(UsersControllerTest):
ArgumentError: wrong number of arguments (1 for 0)
    /Users/hisham/src/rails/ftuBackend/vendor/rails/actionpack/lib/action_controller/routing/route.rb:48:in `to_query'
    /Users/hisham/src/rails/ftuBackend/vendor/rails/actionpack/lib/action_controller/routing/route.rb:48:in `build_query_string'
    /Users/hisham/src/rails/ftuBackend/vendor/rails/actionpack/lib/action_controller/routing/route.rb:46:in `each'
    /Users/hisham/src/rails/ftuBackend/vendor/rails/actionpack/lib/action_controller/routing/route.rb:46:in `build_query_string'
    /Users/hisham/src/rails/ftuBackend/vendor/rails/actionpack/lib/action_controller/routing/route.rb:233:in `append_query_string'
    generated code (/Users/hisham/src/rails/ftuBackend/vendor/rails/actionpack/lib/action_controller/routing/route.rb:154):3:in `generate'
    /Users/hisham/src/rails/ftuBackend/vendor/rails/actionpack/lib/action_controller/routing/route_set.rb:365:in `__send__'
    /Users/hisham/src/rails/ftuBackend/vendor/rails/actionpack/lib/action_controller/routing/route_set.rb:365:in `generate'
    /Users/hisham/src/rails/ftuBackend/vendor/rails/actionpack/lib/action_controller/routing/route_set.rb:364:in `each'
    /Users/hisham/src/rails/ftuBackend/vendor/rails/actionpack/lib/action_controller/routing/route_set.rb:364:in `generate'
    /Users/hisham/src/rails/ftuBackend/vendor/rails/actionpack/lib/action_controller/url_rewriter.rb:208:in `rewrite_path'
    /Users/hisham/src/rails/ftuBackend/vendor/rails/actionpack/lib/action_controller/url_rewriter.rb:187:in `rewrite_url'
    /Users/hisham/src/rails/ftuBackend/vendor/rails/actionpack/lib/action_controller/url_rewriter.rb:165:in `rewrite'
    /Users/hisham/src/rails/ftuBackend/vendor/rails/actionpack/lib/action_controller/test_process.rb:450:in `build_request_uri'
    /Users/hisham/src/rails/ftuBackend/vendor/rails/actionpack/lib/action_controller/test_process.rb:406:in `process'
    /Users/hisham/src/rails/ftuBackend/vendor/rails/actionpack/lib/action_controller/test_process.rb:376:in `post'
    functional/users_controller_test.rb:57:in `test_should_validate'
    /Users/hisham/src/rails/ftuBackend/vendor/rails/activesupport/lib/active_support/testing/setup_and_teardown.rb:60:in `__send__'
    /Users/hisham/src/rails/ftuBackend/vendor/rails/activesupport/lib/active_support/testing/setup_and_teardown.rb:60:in `run'

这是我正在运行的测试:

 def test_should_validate
    post :validate, :user => { :email => 'quire@example.com',
      :password => 'quire', :password_confirmation => 'quire', :agreed_to_terms => "true" }
    assert assigns(:user).errors.empty?
    assert_response :success
  end

2 个答案:

答案 0 :(得分:0)

您使用参数UsersControllerTest调用test_should_validate,但您的test_should_validate函数被定义为不接受参数。

答案 1 :(得分:0)

原来gattaca gem破坏了我的功能测试,并且是造成这个错误的原因。