Ruby Testing

0 views
Skip to first unread message

Manjula Rajendran

unread,
Dec 12, 2007, 5:36:46 AM12/12/07
to rubyonra...@googlegroups.com
Hi,

How do i write unit test without writing the validations? Is it possible
to write the unit test or functional test before writing the validation
and controller code?

manjula
--
Posted via http://www.ruby-forum.com/.

Frederick Cheung

unread,
Dec 12, 2007, 6:03:33 AM12/12/07
to rubyonra...@googlegroups.com

On 12 Dec 2007, at 10:36, Manjula Rajendran wrote:

>
> Hi,
>
> How do i write unit test without writing the validations? Is it
> possible
> to write the unit test or functional test before writing the
> validation
> and controller code?

You can definitely write a test without having written the controller/
model code. Obviously the test should at that point fail (if not your
test is broken).
People sometimes call this test-first development. It does require
that you think about what your model should be doing before having
actually written it (which in my book is a good thing).

Fred

Manjula Rajendran

unread,
Dec 12, 2007, 11:52:40 PM12/12/07
to rubyonra...@googlegroups.com
Hi,


how do i write the test case for checking the length.

def test_for_ssn_no
contact = Contact.new
contact.ssn_no = '-123f4'
assert !contact.valid?
assert_equal '-123f456e7t', contact.ssn_no, "Pass"
end

This is my test case. I want to check the length of ssn_no should be not
more than 10 digits. How do i write. And the above code is the right
way to write the test case? Please help me out to write a good test
cases.

Reply all
Reply to author
Forward
0 new messages