【发布时间】:2016-12-14 20:30:00
【问题描述】:
导轨 5.0.0.1 Rspec 3.5.4 红宝石 2.3.1
我们一直在尝试为我们的 rails 应用程序提供测试覆盖率。我们在 Rspec 没有达到的私有方法中进行了救援。
Rspec:
it 'returns 200 after 404 from GET #edit error' do
allow(controller).to receive(:getpackages).and_return(URI::InvalidURIError)
expect(response.code).to eq(200) # => covers the 200
expect(response).to render_template('errors/5xx') # => doesn't read
end
导轨:
private
def set_package
@package = PackageServices.getpackage params[:id]
rescue URI::InvalidURIError
render 'errors/5xx'
end
错误信息:
expecting <"errors/5xx"> but rendering with <[]>
./spec/controllers/packages_controller_spec.rb:139:in `block (3 levels) in <top (required)>'
-e:1:in `load'
-e:1:in `<main>'
我们尝试过 assert_template,尝试使用 stub_template 对其进行存根,安装了 gem rails-controller-testing(不是 rspec),但我们已经没有想法了,每个 google 链接都是紫色的。这是 Rspec 中的一个错误,还是我们以错误的方式处理它?
【问题讨论】:
标签: ruby-on-rails ruby unit-testing rspec