On 2010-03-25 1:42 PM, Phillip Koebbe wrote:
 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?


Right after I sent that message, I discovered I could set a variable before the initial describe statement and reuse it. This works:

base_path = 'web/admin/merchants'
describe "#{base_path}/show.html.haml" do
    ...
    partial_path = call_some_method(:details, base_path)
    ...
end

But I'd really rather have the value coming from somewhere else. This method depends on me creating a variable, which I don't like.

Peace,
Phillip


Thanks,
Phillip

_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to