2. Call the Fixtures.create_fixtures method. This method accepts three parameters:
the directory where your fixture files are located, the table names the fixtures relate to
within your database, and the class names to associate with your tables (the class names
parameter is optional). Additionally, if you want to create fixtures for more than one
table at a time, you can pass in the table names as an array.
In the following example, we update our test case to use a fixture for our account data.
Here, we are running our tests on aWindows client directly from the Ruby root (in this case
C:\ruby) primarily to show that tests with fixtures can be run anywhere using this approach:
# test_artest.rb Unit Test example
require 'artest'
require 'test/unit'
require 'active_record/fixtures'
Fixtures.create_fixtures("c:\\ruby\\", :accounts)
class TestArtest < Test::Unit::TestCase
def test_simple
temp = Artest.new
assert_equal("Kevin is great!", temp.appreciate(1))
end
end
Before we can actually run this test (with any success), we need to make sure we create
the fixture file that we are referring to.
Pages:
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324