jkl*_*ina 4 ruby-on-rails ruby-on-rails-3 draper
目前在我的spec/decorators/product_decorator_spec.rb中,我有以下内容:
require 'spec_helper'
describe ProductDecorator do
let(:product) { FactoryGirl.create(:product) }
subject do
ProductDecorator.first
end
before do
product
end
it 'should render the name attribute with a link to the product page' do
subject.name.should == h.link_to(product.name, 'test')
end
end
Run Code Online (Sandbox Code Playgroud)
当我运行我的规范时,我得到以下内容:
F.....
Failures:
1) ProductDecorator should render the name attribute with a link to the product page
Failure/Error: subject.name.should == h.link_to(product.name, 'resr')
NameError:
undefined local variable or method `h' for #<RSpec::Core::ExampleGroup::Nested_2:0x007fbbf212c8b0>
# ./spec/decorators/product_decorator_spec.rb:15:in `block (2 levels) in <top (required)>'
Finished in 0.98531 seconds
6 examples, 1 failure
Failed examples:
rspec ./spec/decorators/product_decorator_spec.rb:14 # ProductDecorator should render the name attribute with a link to the product page
Run Code Online (Sandbox Code Playgroud)
根据文档,装饰器文件夹中的规范应该可以访问辅助方法,但是我的规范没有.我也试过手动标记我的规格,但似乎没有任何影响.
谢谢你的期待.
如果你想访问帮助器,你可以通过它来完成your_decorator.h.link_to.
当你设置主题时,你需要确保你正在调用的东西将被路由到帮助器,你的rspec示例中没有注入任何内容!
在你的例子中,它将subject.h.link_to用于调用辅助方法.
我还认为你的规范中有很多有线的东西.您的使用let,subject并且before是一种打扰我...
这里有一篇关于如何写清洁rspec的好文章:http://eggsonbread.com/2010/03/28/my-rspec-best-practices-and-tips/
| 归档时间: |
|
| 查看次数: |
3781 次 |
| 最近记录: |