<false> is not true failure in unit test

Hi, I've done as follows:

MODEL:

Assuming the failure is on the last assertion it's probably because
you've never set family_rate, but your validation asserts that it is
greater than 0.01. You could stick a breakpoint before the test fails
and poke around to see exactly why the object is not valid (or just
print the errors object to the screen or something like that.

Frederick Cheung wrote:

Assuming the failure is on the last assertion it's probably because
you've never set family_rate, but your validation asserts that it is
greater than 0.01. You could stick a breakpoint before the test fails
and poke around to see exactly why the object is not valid (or just
print the errors object to the screen or something like that.

Thanks fred. Sorry, actually I tried valdating family_rate as well
defining method test_positive_family_rate similar to
test_positive_perpersonrate method. When I tried with family_rate as
well I got two failures. And about sticking the breakpoint I'm not sure
how to do..

Frederick Cheung wrote:

Assuming the failure is on the last assertion it's probably because
you've never set family_rate, but your validation asserts that it is
greater than 0.01. You could stick a breakpoint before the test fails
and poke around to see exactly why the object is not valid (or just
print the errors object to the screen or something like that.

Thanks fred. Sorry, actually I tried valdating family_rate as well
defining method test_positive_family_rate similar to
test_positive_perpersonrate method. When I tried with family_rate as
well I got two failures. And about sticking the breakpoint I'm not
sure
how to do..

Adding an extra test isn't going to help. Your test isn't passing
because your object is not valid

Fred

Frederick Cheung wrote:

Adding an extra test isn't going to help. Your test isn't passing
because your object is not valid

Fred

Where am I wrong? Here's how I've done...

IN MODEL:

Frederick Cheung wrote:

Adding an extra test isn't going to help. Your test isn't passing
because your object is not valid

Fred

Where am I wrong? Here's how I've done...

Print out the object's errors and you'll see

Fred

Frederick Cheung wrote:

Print out the object's errors and you'll see

Fred

sorry how do i do that?

Frederick Cheung wrote:

Print out the object's errors and you'll see

Fred

sorry how do i do that?

Look at foo.errors

Something like
puts foo.errors.inspect should do the trick.

Or stick
debugger

In an appropriate part of your test. When you hit that line you'll
drop into the debugger

Frederick Cheung wrote:

Look at foo.errors

Something like
puts foo.errors.inspect should do the trick.

Or stick
debugger

In an appropriate part of your test. When you hit that line you'll
drop into the debugger

I put the fee.errors.detect at:

def test_positive_perpersonrate
fee=Fee.new
..................
..................
puts fee.errors.detect
end

but it doesn't print anything except that already showing error
message..
thanks

As Fred mentioned earlier, you need to set family_rate to
something valid, which accdg to your model validation should
be a number greater than or equal to 0.01.

Otherwise the last assert fee.valid? will return false. You may
have set a valid per_person_rate, but since family_rate is nil,
the object will not be valid.

So looking at your test again, you can do this:

def test_positive_perpersonrate
   fee=Fee.new(:family_rate => 1.0) #provide a valid value for family_rate

   fee.per_person_rate = -1.0
   assert !fee.valid?
   assert_equal "should be greater than 0", fee.errors.on(:per_person_rate)

   fee.per_person_rate = 0.0
   assert !fee.valid?
   assert_equal "should be greater than 0", fee.errors.on(:per_person_rate)

   fee.per_person_rate = 1.0
   assert fee.valid?
end

Hope this helps.

Frederick Cheung wrote:

Look at foo.errors

Something like
puts foo.errors.inspect should do the trick.

Or stick
debugger

In an appropriate part of your test. When you hit that line you'll
drop into the debugger

I put the fee.errors.detect at:

def test_positive_perpersonrate
fee=Fee.new
..................
..................
puts fee.errors.detect
end

but it doesn't print anything except that already showing error
message..

Why would it? I said inspect, not detect. Also you have to put it just
before the failing assertion.

Fred

Frederick Cheung wrote: