无法在 Rspec 中测试帮助程序方法的呈现功能



我使用Rails 2.3.4和Rspec 1.2.0。我试图测试一个试图呈现页面或部分的帮助器,我得到一个异常

未定义方法' render' for

假设我的帮助方法是

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

并从spec中调用

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

任何建议都是有用的

怎么样:

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

当你使用新的期望语法时,我会使用

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

Eric C的上述解决方案对我不起作用。如果有人发现相同的,这里是我的工作测试代码:

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

最新更新