Prev | Current Page 293 | Next

Kevin Marshall, Chad Pytel, and Jon Yurek

"Pro Active Record: Databases with Ruby and Rails"


CHAPTER 6 ?–  ACTIVE RECORD TESTING AND DEBUGGING 129
?– Note It??™s important to remember that all values in Ruby other than the specific false and nil values
resolve to be Boolean values of true. This means that if you attempt to assert a string, it would always pass,
because strings are true values in Ruby.
The assert method accepts two parameters, the Boolean value (or expression that returns
a Boolean value) and an optional message you would like to display in the event that the
assertion fails. In the following example, we rewrite our test case using just the assert method.
The important thing to note is our use of the == operator, which makes our expression return
a Boolean value:
# test_artest.rb Unit Test example
require 'artest'
require 'test/unit'
class TestArtest < Test::Unit::TestCase
def test_simple
temp = Artest.new
assert ("Kevin Marshall is great!" == temp.appreciate(1).to_s)
end
end
assert_nil
As the name implies, this assertion method checks if the given expression or value is equal to
nil.


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