Ruby on Rails/第14回勉強会 - Rails上でRspecを使う http://www.ark-web.jp/sandbox/wiki/253.html

Ruby on Rails/第14回勉強会 - Rails上でRspecを使う

どうも、SEの小沼です。

[edit]

このページは?

下記のネタを元にRspecについて勉強してみるページです。

今回は第3回ということで前回までの続きです。
前回でRspecの使い方までをご説明しました。
今回はRspecをRuby on Rails上で使う方法をご紹介します。

[edit]

動画

http://www.screencast.com/t/b4eymGMn

[edit]

目次

[edit]

日時

[edit]

参加者

[edit]

動画

[edit]

本編

[edit]

インストール

$ ./script/plugin install svn://rubyforge.org/var/svn/rspec/tags/REL_1_0_8/rspec
...略...
$ ./script/plugin install svn://rubyforge.org/var/svn/rspec/tags/REL_1_0_8/rspec_on_rails
...略...
[edit]

必要なファイルの生成

[edit]

サンプルを動かしてみる

[edit]

今回のサンプルについて

[edit]

準備

[edit]

モデルの開発

モデルのビヘイビア駆動開発は以下のようなフローになる。

[edit]

重要な点

change マッチャ
処理の実行前と実行後での変化を定義するマッチャ

lambda {
  team.add_player(player)
}.should change(roster, :count)
//teamにadd_playerするとteamのcoutの値が変化するということを定義

以下のような使い方が可能

[edit]

問題

/home/staff/konuma/test/rails/rspec_test/vendor/plugins/rspec_on_rails/lib/spec/rails/extensions/action_controller/rescue.rb:19: undefined method `alias_method_chain' for ActionController::Rescue:Module (NoMethodError)

   from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
   from /usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:147:in `require'
   from /home/staff/konuma/test/rails/rspec_test/vendor/plugins/rspec_on_rails/lib/spec/rails/extensions.rb:6
   from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
   from /usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:147:in `require'
   from /home/staff/konuma/test/rails/rspec_test/config/../vendor/plugins/rspec_on_rails/lib/spec/rails.rb:17
   from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
   from /usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:147:in `require'
   from ./spec/models/../spec_helper.rb:5
   from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
   from ./spec/models/blog_spec.rb:1
   from /home/staff/konuma/test/rails/rspec_test/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:106:in `load_specs'
   from /home/staff/konuma/test/rails/rspec_test/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:105:in `load_specs'
   from /home/staff/konuma/test/rails/rspec_test/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:49:in `prepare!'
   from /home/staff/konuma/test/rails/rspec_test/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:19:in `run'
   from /home/staff/konuma/test/rails/rspec_test/vendor/plugins/rspec/lib/spec/runner/command_line.rb:17:in `run'
[edit]

まとめ

投稿者小沼 | パーマリンク

| append.gif

tag: Ruby on Rails, 勉強会,テスト


トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2007-10-30 (火) 18:44:01 (5995d)

アークウェブのサービスやソリューションはこちら