Ruby on rails 测试错误:-在RubyonRails中

Ruby on rails 测试错误:-在RubyonRails中,ruby-on-rails,Ruby On Rails,我正在使用RubyonRails,在运行“ruby-Itest test/models/user_test.rb”时遇到了一个问题。我在正则表达式/^[a-zA-Z0-9-]+$/中进行更改时出错,现在我陷入了这个问题,不知道如何克服它 My user.rb文件:- validates :profilename, presence: true, uniqueness: true, format: { with: /^[a-zA-Z0-9-]+$/ , multiline: true, me

我正在使用RubyonRails,在运行“ruby-Itest test/models/user_test.rb”时遇到了一个问题。我在正则表达式
/^[a-zA-Z0-9-]+$/
中进行更改时出错,现在我陷入了这个问题,不知道如何克服它

My 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

谢谢你的帮助

您的问题的答案似乎在文件
user\u test.rb
中。尝试检查
test\u a\u user\u可以在何处定义格式正确的\u profile\u name
,以及调用它的位置:根据错误,调用它时没有所需的一个或两个参数。我猜你需要给它一个测试用户名。

你能把测试名的代码放在test\u a\u user\u Can\u have\u a\u formatted\u profile\u namecode:-test“a user Can have a correct formatted profile name”do user=user.new(名字:'sarah',姓氏:'gupta',email:'sarah089@gmail.com')user.password=user.password\u confirmation='welcome'user.profile\u name='s\u arah-1'assert.user.valid?结束检查它是
profilename
还是
profile\u name
。另外,转到test/models/user_test.rb第41行,检查调用的方法。你可能没有通过一些预期的论点,你可以编辑你的原始问题,包括代码吗?正确的格式使其更易于阅读。从您的问题来看,您的正则表达式似乎没有引发此错误。你能在原始帖子中分享它吗?这段代码“assert!user.valid?”对我来说很有效,它通过了测试,没有错误。但我不知道这段代码的确切含义表示“不”,所以如果
断言!user.valid?
通过,表示该用户无效。
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