[rspec-users] view spec template.base_path

Phillip Koebbe phillipkoebbe at gmail.com
Thu Mar 25 14:42:44 EDT 2010


  I have a helper method

def partial_path_for(partial, options = {})
     base_path = options[:base_path] || self.template.base_path
     "_partials/#{base_path}/#{partial}"
end

and use it in a template (haml) like

= render :partial => partial_path_for(:details)

I'd like to have a similar helper for view specs so I can do this

describe 'web/admin/merchants/show.html.haml' do
     before(:each) do
         @merchant = stub_model(Merchant, :name => 'Some Merchant')
         assigns[:merchant] = @merchant
     end

     it 'should render the details partial' do
         partial_path = partial_path_for(:details, :base_path => 
self.template.base_path)
         template.should_receive(:render).with(:partial => partial_path)
         render
     end

     it_should_behave_like 'merchant details'
end

Unfortunately, if I debug right before the template.should_receive 
statement, self.template.base_path is nil. How can I get the path to the 
template?

Thanks,
Phillip


More information about the rspec-users mailing list