Prev | Current Page 292 | Next

Kevin Marshall, Chad Pytel, and Jon Yurek

"Pro Active Record: Databases with Ruby and Rails"

Still, it should help you to see the basic concepts
of unit testing with assertion methods, and we can build from here.
Before we dive into more realistic examples, though, let??™s take a minute to cover the various
assertion methods we have available to us.
Assertions
As we mentioned, the basic concept of unit testing is to attempt various assertions against our
code. These assertions should either pass or fail, that is, they will be either true or false, and as
such, provide us with details about how our code is actually executing in real-world situations.
There are currently 18 assertion methods to choose from when writing our tests. The
functionality of most is fairly obvious thanks to logical naming. Still, we??™ll show an example of
each in an effort to be complete (and to show just how easy and painless unit testing is).
assert
The most basic of all assertion methods is simply the assert method, which evaluates
a Boolean value. It will pass all cases except for Boolean values that are false or result in nil.


Pages:
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304