测试错误:-in Ruby on rails

时间:2015-05-16 03:17:32

标签: ruby-on-rails

我在轨道上使用ruby并且在运行" ruby​​ -Itest test / models / user_test.rb"时遇到问题。当我在正则表达式/^[a-zA-Z0-9-]+$/中进行更改时出现错误,现在我遇到了这个问题并且我不知道如何克服它。

我的user.rb文件: -

validates :profilename, presence: true,

uniqueness: true, format: { with: /^[a-zA-Z0-9-]+$/ , multiline: true, 

message: 'Must be formatted correctly.' }

运行测试: -

$ ruby -Itest test/models/user_test.rb

DL is deprecated, please use Fiddle

Run options: --seed 50723

Running:
.....#<ActiveModel::Errors:0x4ecc8a0 @base=#<User id: nil, first_name: "sarah", last_name: "gupta", profile_name: "S_arah-1", email: "sarah089@gma
il.com", encrypted_password: "", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 0, current_sign_in_at
: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, created_at: nil, updated_at: nil>, @messages={}>
E..


Finished in 0.380267s, 15.7784 runs/s, 28.9270 assertions/s..

1) Error: UserTest#test_a_user_can_have_a_correctly_formatted_profile_name: ArgumentError: wrong number of arguments (0 for 1..2) test/models/user_test.rb:41:in `block in <class:UserTest>'

6 runs, 11 assertions, 0 failures, 1 errors, 0 skips

以下是a_user_can_have_a_correctly_formatted_profile_name的代码

test "a user can have a correctly formatted profile name" do 
  user = User.new(first_name: 'sarah', last_name: 'gupta', email: 'sarah089@gmail.com') 
  user.password = user.password_confirmation = 'welcome' 
  user.profile_name = 's_arah-1' 
  assert.user.valid? 
end

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

您的问题的答案似乎在user_test.rb文件中。尝试检查test_a_user_can_have_a_correctly_formatted_profile_name的定义位置以及调用的位置:根据错误,调用它而不需要一个或两个参数。我猜你需要给它一个测试用户名。