Home Asset_path在rspec中的使用(useasset_pathinrspec)
Post
Cancel

Asset_path在rspec中的使用(useasset_pathinrspec)

今天很奇怪,我在测试 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
 end

原因:(reason) "asset_path" isn't a routing URL helper, it's a Sprocket helper. 出自:http://rubyforge.org/pipermail/rspec-users/2011-September/020619.html

This post is licensed under CC BY 4.0 by the author.