Prev | Current Page 305 | Next

Kevin Marshall, Chad Pytel, and Jon Yurek

"Pro Active Record: Databases with Ruby and Rails"

It accomplishes
that comparison via the Ruby send method. The method accepts four parameters: the
first object you want to compare, the operator as a symbol that you want to use to compare
CHAPTER 6 ?–  ACTIVE RECORD TESTING AND DEBUGGING 136
the objects, the second object you want to compare, and an optional message to display in the
event that the assertion fails.
The important thing to remember with this method is that you should pass the operator
as a symbol (otherwise, you will get a syntax error). It??™s also important to remember that this
method is the equivalent of running object1.send(operator, object2) and treating the Boolean
response value as the assertion result.
In our example, we create two distinct objects and use assert_operator to check that the
values of the objects are equal.
# test_artest.rb Unit Test example
require 'artest'
require 'test/unit'
class TestArtest < Test::Unit::TestCase
def test_simple
obj1 = Artest.new
obj3 = Artest.new
assert_operator obj1, :==, obj2
end
end
assert_throws
This method checks that a given symbol is thrown during the execution of the block.


Pages:
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317