我正在使用軌道上的紅寶石,我在運行「ruby -Itest測試/模型/ 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: "[email protected]
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: '[email protected]')
user.password = user.password_confirmation = 'welcome'
user.profile_name = 's_arah-1'
assert.user.valid?
end
感謝您的幫助的代碼!
你可以把代碼測試名稱** ** test_a_user_can_have_a_correctly_formatted_profile_name代碼 – Abhi
- 測試「用戶可以有一個正確格式的配置文件名稱」做 用戶= User.new(FIRST_NAME:「莎拉」,姓氏:「古普塔',email:'[email protected]') user.password = user.password_confirmation ='welcome' user.profile_name ='s_arah-1' assert.user.valid? 結束 –
檢查它是'profilename'還是'profile_name'。另外,goto ** test/models/user_test.rb第41行**並檢查正在調用的方法。您可能不會傳遞一些預期的參數 – Abhi