How can I access helper methods in my decorator specifier files using Draper 0.14.0

Currently in my spec / decorators / product_decorator_spec.rb I have the following:

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 

When I run my spec, I get the following:

 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 

According to the documentation, the specifications placed in the decorator folder should have access to the helper method, however my specification does not work. I also tried manually tagging my specifications, but it seems to have no effect.

Thanks for watching.

+4
source share
2 answers

if you want to access the assistant, you can do this through your_decorator.h.link_to .

when you set up the theme, you need to make sure that the item you are calling will be redirected to the assistant, nothing will be entered into your rspec example!

in your example, it will be subject.h.link_to to call the helper method.

I also find that your specification has a lot of wired stuff. your use of let , subject and before bothers me ...

here is a good entry on how to write pure rspec: http://eggsonbread.com/2010/03/28/my-rspec-best-practices-and-tips/

+7
source

I ran into the same problem where calling helper methods in the helper-helper-decorator (.h) does not work in the test (in Draper 1.3). I ended up working on this, although I'm not very happy with this:

 my_decorated_object.h.extend ApplicationHelper 

Your mileage may vary depending on how many controller functions you get in your assistant.

+1
source

All Articles