Jan - 1st
Rails2.0.2のヘルプ、中身拝見(3)
Posted at 11:29 pm | Filed Under Ruby
さて、コントローラまで作成した。
$ rails test $ cd test $ ruby script/generate controller list index create edit delete
すると、testディレクトリに何やら作られている。
$ cd test $ tree . |-- fixtures |-- functional | `-- list_controller_test.rb |-- mocks | |-- development | `-- test |-- test_helper.rb `-- unit 7 directories, 2 files
list_controllerを作成すると、自動的にテスト用にtest/functional/list_controller_test.rbも作られたようだ。しかし中身はまだない。
$ cat test/functional/list_controller_test.rb
require File.dirname(__FILE__) + '/../test_helper'
class ListControllerTest < ActionController::TestCase
# Replace this with your real tests.
def test_truth
assert true
end
end
Railsのすごいところはテストの面倒をフレームワークがみる(みようとする)という点で、Railsをちゃんと覚えようと思ったのもこれがあるからだ。generateスクリプトには、integration_testなるものがあり、テスト用のスタブ作成を請け負ってくれる。
integration_test
でも、これはさっきみたテスト用のスクリプトと何がどう違うんだろうか。
$ ruby script/generate integration_test DemoTest $ cd test $ tree . |-- fixtures |-- functional | `-- list_controller_test.rb |-- integration | `-- demo_test_test.rb |-- mocks | |-- development | `-- test |-- test_helper.rb `-- unit 7 directories, 3 files
test/integrationというディレクトリと、demo_test_test.rbというファイルが作成されている。中身を拝見。
$ cat test/integration/demo_test_test.rb
require "#{File.dirname(__FILE__)}/../test_helper"
class DemoTestTest < ActionController::IntegrationTest
# fixtures :your, :models
# Replace this with your real tests.
def test_truth
assert true
end
end
全然中身はない。いったい何が違うのか調べてみると、どうやら先ほどコントローラを作成した際に勝手に追加されていたのは、そのコントローラを単体でテストする場合に使うやつで、integration_testはその名の通り複数のコントローラを使ってシナリオ通りのテストパターンを試すような用途で利用されるためのスタブだとのこと。
実際に動かすにはやはり何らかのアプリケーションを作成してからになる。というわけで、この機能についてはここまで。
« go back