RSpecは面白そうだったのだけれど、なかなか移行する機会が無くて使っていなかったのですが、今は縁があってRSpecでViewのテストを書いています。

で、partialのテストをする場合のメモです。

   1  require File.join(File.dirname(__FILE__), '../../spec_helper.rb')
   2  
   3  describe '/foos/_form.html.erb' do
   4    before do
   5      render :partial => 'foos/form', :object => mock('form'),
   6        :locals => {:bar => mock('bar')}
   7    end
   8  
   9    it "should be rendered successfully" do
  10      response.should be_success
  11    end
  12  end

とりあえずこんな感じです。

See Also

posted by Png genki on Fri 16 May 2008 at 01:30 with 1 comment

Comments:

Png 瀧内元気 almost 16 years ago.

アクションのレンダリングの中から呼び出されることを期待して、 html.erbファイルの中から、controller.action_nameを参照するような場合は、

   1  @action_name = 'show'

のように設定すると良いようです。

or Preview
Social Bookmarks
  • Delicious
  • B_entry580
  • Clip_16_12_w
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ