Chr*_*yer 4 plugins rspec ruby-on-rails
我正在编写一个Rails插件,可以在视图中构建菜单.我正在使用link_to
构建链接并在当前页面上current_page?
设置class="active"
.
我include
ð ActionView::Helpers::UrlHelper
这样我就可以使用link_to
.
为了current_page?
在视图中工作,我必须继承当前的类(显然ActionView::Base
)并且它非常有效.不幸的是,这完全打破了RSpec的测试.
我打电话link_to
和current_page?
这样的:
def menu(options = {}, &block)
carte = my_menu.new(self)
yield carte
carte.to_s unless carte.empty?
end
class my_menu
include ActionView::Helpers::TagHelper
include ActionView::Helpers::UrlHelper
def initialize(base)
@base = base
end
def link
@base.link_to(name, url_options, html_options)
@base.current_page?(url_options)
end
end
Run Code Online (Sandbox Code Playgroud)
我用RSpec得到了这个错误:未定义的方法`link_to'用于#<Spec :: Rails :: Example :: RailsExampleGroup :: Subclass_1:0x24afa90>
任何线索?
include ActionView::Helpers::UrlHelper
Run Code Online (Sandbox Code Playgroud)
在你的规范中应该解决问题.或者在spec_helper.rb中.我认为这基本上是默认情况下的视图规范.