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

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

ruby>>
require File.join(File.dirname(FILE), '../../spec_helper.rb')

describe '/foos/_form.html.erb' do
before do
render :partial => 'foos/form', :object => mock('form'),
:locals => {:bar => mock('bar')}
end

it "should be rendered successfully" do
response.should be_success
end
end
<<--

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

See Also

posted by genki genki on Fri 16 May 2008 at 01:23 with 1 comment
瀧内元気 瀧内元気 05/17 00:34
アクションのレンダリングの中から呼び出されることを期待して、
html.erbファイルの中から、`controller.action_name`を参照するような場合は、

ruby>>
@action_name = 'show'
<<--

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