我已經在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