简体   繁体   English

Rails中的单元测试问题

[英]problems with unit test in rails

I'm trying to run my simple UserTest 我正在尝试运行我的简单UserTest

require 'test_helper'

class UserTest < ActiveSupport::TestCase

  fixtures :users

  test "user attributes must not be empty" do
    user = users(:valid_user)
    assert user.invalid?
    assert user.errors[:nome].any?
    assert user.errors[:cognome].any?
    assert user.errors[:localita].any?
    assert user.errors[:provincia].any?
    assert user.errors[:nazione].any?
    assert user.errors[:cap].any?
    assert user.errors[:indirizzo].any?
    assert user.errors[:civico].any?
    assert user.errors[:telefono].any?
    assert user.errors[:mail].any?
    assert user.errors[:username].any?
    assert user.errors[:password].any?
  end

end

with this users.yaml 与这个users.yaml

valid_user:
  nome: prova
  cognome: prova
  localita: prova
  provincia: prova
  nazione: prova
  cap: 00000
  indirizzo: strada di prova
  civico: 1
  telefono: 1111111111
  mail: prova@prova.com
  username: prova
  password: prova

but it returns this error: 但它返回此错误:

Loaded suite /var/lib/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/rake_test_loader Started F Finished in 0.182523 seconds. 已加载的套件/var/lib/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/rake_test_loader开始F在0.182523秒内完成。

1) Failure: test_user_attributes_must_not_be_empty(UserTest) [../unit/user_test.rb: 10]: Failed assertion, no message given. 1)失败:test_user_attributes_must_not_be_empty(UserTest)[../unit/user_test.rb:10]:声明失败,未给出消息。

1 tests, 2 assertions, 1 failures, 0 errors, 0 skips 1个测试,2个断言,1个失败,0个错误,0个跳过

What's the problem? 有什么问题?

well, Failed assertion is 好吧,断言是

assert user.errors[:nome].any?

which means that there are no errors on attribute :nome 这意味着属性:nome没有错误

why are you asserting that there should be errors on that attribute is a complete mystery to me 您为什么断言该属性应该有错误对我来说是一个完全的谜

maybe you wanted to use errors[:nome].none? 也许您想使用errors[:nome].none? ?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM