gem 中的规范视图助手
我正在编写一个 Rails 3 Railtie,它定义了一些视图助手。现在我想知道如何指定视图帮助器方法,因为我无法实例化模块。我已经搜索并阅读了很多,但我就是无法让它发挥作用。
view_helper_spec.rb
require 'spec_helper'
module MyRailtie
describe ViewHelper, :type => :helper do
describe "style_tag" do
it "should return a style tag with inline css" do
helper.style_tag("body{background:#ff0}").should ==
body{background:#ff0}
EOT
end
end
end
end
它总是抱怨“helper”未定义。似乎 :type => :helper 没有任何作用。
gemspec 在开发/测试模式下需要 rspec 和 rspec-rails gem。
I'm writing a rails 3 railtie which defines some view helpers. Now I wonder how to spec the view helper methods because I cannot instantiate a module. I already searched and read a lot, but I just couldnt get it working.
view_helper_spec.rb
require 'spec_helper'
module MyRailtie
describe ViewHelper, :type => :helper do
describe "style_tag" do
it "should return a style tag with inline css" do
helper.style_tag("body{background:#ff0}").should ==
body{background:#ff0}
EOT
end
end
end
end
It always complains that "helper" is not defined. It seems that :type => :helper doesn't to anything.
The gemspec requires the rspec and the rspec-rails gems in development/ test mode.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想我找到了解决方案(一旦你仔细想想,它就很明显)。只需将其放在规范的顶部即可:
I think I found the solution (it's painfully obvious once you think about it). Just stick this at the top of your spec: