I would like to test the following helper module function:
module UploadsHelper
def custom_img_tag(upload, width, height, id)
if width > Upload::MAX_CROP_WIDTH
image_tag(upload.photo.url(:original), :id => "box", :width => Upload::MAX_CROP_WIDTH, :height => (height*Upload::MAX_CROP_WIDTH/width).to_i)
else
image_tag(upload.photo.url(:original), :id => "box")
end
end
end
However when I run the following test:
describe UploadsController do
include UploadsHelper
describe "custom_img_tag(upload, width, height, id)" do
before(:each) do
@upload = Factory(:upload)
geo = Paperclip::Geometry.from_file(@upload.photo.to_file(:original))
@width = geo.width
@height = geo.height
end
it "should return the original image tag for an image that is not wider than MAX_CROP_WIDTH" do
#custom_img_tag(@upload,@width, @heigth, "cropbox" ).should == '<img id="cropbox" width="500" height="375" src="/system/photos/10/original/avatar.jpg?1311044917" alt="Avatar" style="display: none;">'
end
end
I get the following error:
Failure/Error: custom_img_tag(@upload,@width, @heigth, "cropbox" ).should == '<img id="cropbox" width="500" height="375" src="/system/photos/10/original/avatar.jpg?1311044917" alt="Avatar" style="display: none;">'
NoMethodError:
You have a nil object when you didn't expect it!
Why do I get this error and how can I test this method?
Update:
I added the following to the spec test file:
include ActionView::Helpers
Which produces the following error:
NameError:
undefined local variable or method `config' for #<RSpec
How can I get rid of this error and what is the cause?
Thanks for any assistance.
I also got hit with the error working with Rails 3.1 RC
Some Rails source tracing and I discovered the missing include ActionView::AssetPaths.