打印

测试 问题

测试 问题

在测试一个字段为整数时遇到的问题,
1) Failure:
test_integer_field(ItouchServiceTest)
    [test/unit/itouch_service_test.rb:32:in `test_integer_field'
     c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.1/lib/active_support/testi
ng/default.rb:7:in `run']:
<"鐣欒█娆℃暟蹇呴』涓烘暣鏁帮紒"> expected but was
<nil>.
下面是我写的测试代码:
def test_integer_field
    itouch_service=ItouchService.new(
                                     :member_id=>1,
                                     :eval_result=>"2",
                                      fficial_result=>"4",
                                    # :total_leave_message_times=>5,
                                     :total_eval_times=>2,
                                     :total_revenue=>1,
                                     :total_consume_times=>3,
                                     :title=>"ddddd",
                                     :description=>"ddddsgasdgaga",
                                     :security=>"all"
                                     #:created_at=>"2008-2-19",
                                     #:updated_at=>"2008-2-20"
                                     )
                                     itouch_service.save
                                    # itouch_service.save
    itouch_service.total_leave_message_times=0.26
    assert !itouch_service.valid?
    assert_equal "留言次数必须为整数!",itouch_service.errors.on(:total_leave_message_times)
    #puts itouch_service.errors.full_messages
    itouch_service.total_leave_message_times=20

    assert itouch_service.valid?
  end
当把assert_equal "留言次数必须为整数!",itouch_service.errors.on(:total_leave_message_times)
给去掉时,出现这样的错误.
<false>is not  true
一直找不出原因!请帮忙!

TOP

问题已经解决了!关于整数问题,不用验证,如果你设置一个浮点数据,rails能自动解析为接近的整数!

TOP