0
How to get access to rails view helpers from rspec support files
Creat
17/12/2011 18:23:38
per
Roger Campos
Within the rspec context we already have access to a special method "helper" wich we can use like this:
it "should show the price" do
res = helper.number_to_currency 56
res.should == "56,00 €"
end
Well, only in the "request" type specs of course. The problem is that this special 'helper' method is not available to our files under the "spec/support" folder. If we want to make use of it from there we have to run our own solution. This is an easy one: Add a new support file with this content:
def helper
Helper.instance
end
class Helper
include Singleton
include ActionView::Helpers::NumberHelper
# Include the rest of view helpers you need here
end