Rails, Failed assertion, no message given -


when trying write unit test models keep getting same error , cant seem fix it.

this test:

require 'test_helper'  class producttest < activesupport::testcase test "product attirbutes must not empty"     product = product.new     assert product.invalid?     assert product.errors[:title].any?     assert product.errors[:description].any?     assert product.errors[:price].any?     assert product.errors[:image_url].any? end    test "product price must positive"     product = product.new(title:       "my book title",                           description: "yyy",                           image_url:   "zzz.jpg")      product.price = -1         # line number 19 below     assert product.invalid?     assert_equal ["must greater or equal 0.01"],       product.errors[:price]      product.price = 0     assert product.invalid?     assert_equal ["must greater or equal 0.01"],        product.errors[:price]      product.price = 1     assert product.valid?   end  end 

when run > rake test

i following error:

 1) failure: producttest#test_product_price_must_be_positive /test/models/product_test.rb:19]: failed assertion, no message given. 

here model:

class product < activerecord::base validates :title, :description, :image_url, presence: true validates :price, numericality: {greater_then_or_equal_to: 0.01} validates :title, uniqueness: true validates :image_url, allow_blank: true, format: {     with: %r{\.(gif|jpg|png)\z}i,     message: 'must url gif, jpg or png image.' } end 

i have no idea going on here please help!

as per minitest::assertions docs, method derived 'assert' raise exception message "failed assertion, no message given" on fail unless supply optional 'msg' paramater


a few things:

  1. you testing active record validations, these tried , tested, production ready features of library testing not necessary. become more familiar active record validations go docs , play around models in rails console

  2. active record validations performed when attempt 'create' or 'save' model. example:

    my_user = user.create(name: nil, email: nil) # try save db - fails silently my_user.valid? # => false my_user.errors.messages # => {name:["can't blank"], email:["can't blank"]} 

maybe explore futher learning on topic, ryan bate's screencasts great , free part. hope helps

note: hoped attach more links/refrences not have stackoverflow points do


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -