7

I am using Rails 2.3.4 and Rspec 1.2.0. I m trying to test a helper that attempts to render a page or a partial, I'm getting an exception as

undefined method `render' for

Assume, my helper method is

def some_helper
 render(:partial => "some/partial", :locals => {:some => some}
end 

and calling it from spec as

it "should render the partial" do
 some_helper.should render_template("some/partial")
end

Any suggestion would be useful

2 Answers 2

8

What about:

it "should render the partial" do
  helper.should_receive("render").with("some/partial")
  some_helper
end

UPDATE

When you use the new expectation syntax I would do

it "renders the partial" do
  allow(helper).to receive(:render)
  some_helper
  expect(helper).to have_received(:render).with("some/partial")
end
0
0

The above solution by Eric C is not working for me. In case anyone is finding the same, here is my working test code:

it 'renders the template' do
  allow(helper).to receive(:render).and_call_original
  helper.helper_method(arg)
  expect(helper).to have_received(:render).with(partial: 'my/partial')
end

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.