Hi, I have a simple model and written a testcase. class Product < ActiveRecord::Base validates_presense_of :name end ------------- class ProductTest < Test::Unit::TestCase fixtures :products def test_invalid product = Product.new assert !product.valid? end end ------------- The testcase fails with a message, <false> is not true. What is wrong with the testcase? I can see it ruby console that "product.valid?" returns false...so "assert !product.valid?" should return true... Any clues what is wrong? Thanks. -- Posted via http://www.ruby-forum.com/.
The test case is telling you that product.valid? is returning true. Have you actually checked the return value? Cheers, Pete Yandell http://9cays.com/ On 12/07/2006, at 8:08 AM, Guest wrote:> Hi, > > I have a simple model and written a testcase. > > class Product < ActiveRecord::Base > validates_presense_of :name > end > ------------- > class ProductTest < Test::Unit::TestCase > fixtures :products > > def test_invalid > product = Product.new > assert !product.valid? > end > end > ------------- > The testcase fails with a message, > <false> is not true. > > What is wrong with the testcase? I can see it ruby console that > "product.valid?" returns false...so "assert !product.valid?" should > return true... > > Any clues what is wrong? > > Thanks. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Guest wrote:> Hi, > > I have a simple model and written a testcase. > > class Product < ActiveRecord::Base > validates_presense_of :name > end > ------------- > class ProductTest < Test::Unit::TestCase > fixtures :products > > def test_invalid > product = Product.new > assert !product.valid? > end > end > ------------- > The testcase fails with a message, > <false> is not true.Hi, I think you need to have it read product = Product.create not product = Product.new Chris -- ruby -e ''$_=[1667523425, 1920230770, 539828333, 1634956389, 1914728294, 543387502, 1667591796, 1918989417, 1869509492, 1969514863, 1932419951, 109];$/="";11.times{$/<<78.chr};1.times{$/<<99.chr};puts$_.pack($/)'' -- Posted via http://www.ruby-forum.com/.
Hi, "assert_valid product" passes...meaning the product.valid? is returning "true" in the test case. :( But if I check this in ruby console, product.valid? returns "false" and I can see all "invalid" errors...but something is weird! Any ideas what else I should check? Thanks. Chris Carter wrote:> Guest wrote: >> Hi, >> >> I have a simple model and written a testcase. >> >> class Product < ActiveRecord::Base >> validates_presense_of :name >> end >> ------------- >> class ProductTest < Test::Unit::TestCase >> fixtures :products >> >> def test_invalid >> product = Product.new >> assert !product.valid? >> end >> end >> ------------- >> The testcase fails with a message, >> <false> is not true. > > Hi, > > I think you need to have it read > product = Product.create > not > product = Product.new > > Chris > -- > ruby -e ''$_=[1667523425, 1920230770, 539828333, 1634956389, 1914728294, > 543387502, 1667591796, 1918989417, 1869509492, 1969514863, 1932419951, > 109];$/="";11.times{$/<<78.chr};1.times{$/<<99.chr};puts$_.pack($/)''-- Posted via http://www.ruby-forum.com/.