asset_path 在rspec中的使用 ( use asset_path in rspec )

发布时间: 2013-01-08 09:45:00

今天很奇怪,我在测试 helper 时,居然遇到了 这个问题: ( today I met a strange problem when testing a Rails helper which called asset_path )

undefined method `asset_path' for #<rspec::core::examplegroup::nested_2:0x8b35aa8>

解决办法很简单: 加上下面这句就好了 ( the solution is simple: add the line of code to the spec_helper file, shown as below )

# spec_helper.rb 
 RSpec.configure do |config|
   config.include Sprockets::Helpers::RailsHelper

原因:(reason) "asset_path" isn't a routing URL helper, it's a Sprocket helper. 出自: