我已经在the normal fashion中创建了一个Rails引擎,安装了RSpec,并为一个模型生成了一个脚手架,但是我无法获得任何路由规范可以通过。所有路由示例都失败了Rails 3.2引擎RSpec 2.10
这里有一个例子:
describe Licensing::LicensesController do
it 'routes to #index' do
get('/licensing/licenses').should route_to('licensing/licenses#index')
end
end
我运行的实例在虚拟应用程序是这样的:
$ cd spec/dummy
$ rake spec
/Users/brandan/.rvm/rubies/ruby-1.9.3-p194/bin/ruby -S rspec ../routing/licensing/licenses_routing_spec.rb
F
Failures:
1) Licensing::LicensesController routes to #index
Failure/Error: get('/licensing/licenses').should route_to('licensing/licenses#index')
No route matches "/licensing/licenses"
# /Users/brandan/repos/licensing/spec/routing/licensing/licenses_routing_spec.rb:5:in `block (2 levels) in <top (required)>'
Finished in 0.04345 seconds
1 example, 1 failure
发动机能正常安装在虚拟应用程序:
# spec/dummy/config/routes.rb
Rails.application.routes.draw do
mount Licensing::Engine => "/licensing"
end
我可以进入虚拟应用程序并启动控制台并获取该路线:
1.9.3p194 :001 > app.get('/licensing/licenses')
Licensing::License Load (0.3ms) SELECT "licensing_licenses".* FROM "licensing_licenses"
200
1.9.3p194 :002 > app.response.body
"<!DOCTYPE html>..."
虚拟应用程序和RSpec之间存在一些差异,我无法弄清楚它是什么。我发现几篇文章,声称能解决这个问题,但他们都没有帮助,而且其中有几个具体到Rails 3.1:
- Ryan Bigg's article on generating and testing engines
- Matthew Ratzloff's article on testing engine routes in Rails 3.1
- Stefan Wienert's article on mountable engines
- A mailing list message about testing routing helpers in Rails 3.2
有没有人在Rails 3.2/RSpec 2.10中解决了这个问题?
我假设你对一个虚拟应用程序,能够将您的发动机测试。你确定引擎是安装在虚拟应用程序的路线上吗?如果是的话,你确定你的规范是':type =>:routing'? – 2012-08-02 03:36:51
@TanzeebKhalili我确定路由是正确的,因为他们在控制台和浏览器中工作。我从虚拟应用内运行规格。这些文件在'spec/routing'下,并且明确指定':type =>:routing'不会导致这些例子通过。还有什么想法? : -/ – Brandan 2012-08-02 15:39:09
以下更改如何:1)描述的不同对象:“描述”路径“do ...”和2)不同的语法:'{:get =>'/ licensing/licenses'} .should be_routable' – 2012-08-03 07:17:51