Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't test render functionality for helper methods in Rspec

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

like image 523
Dhepthi Avatar asked Sep 21 '11 11:09

Dhepthi


1 Answers

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
like image 171
Eric C Avatar answered Oct 12 '22 23:10

Eric C