Topic: View Specs with RSpec and Paperclip: How do I handle the show template
Howdy! I'm currently trying to teach myself RSpec and Cucumber for Rails in a really slapdash way. What one might call "Baptism by fire". Either way, I'm trying to spec the "show.html.erb" template which has three things to render:
Picture is the tricky one. Here's what the actual template looks like (very rudimentary for now):
<%=h @post.title %> <%=h @post.story %> <%= image_tag @post.picture.url %>
The picture comes from Paperclip. I've tried stubbing the image as such:
image = fixture_path + "/test.jpg" @file = ActionController::TestUploadedFile.new image, "image/jpeg"
But that doesn't seem to jive with what the view is expecting. I would honestly just rather explicitly specify the location of the image in the fixtures folder, but I don't know if that's possible.
Here's my tests so far:
require 'spec_helper' describe "posts/show.html.erb" do before :each do @image = fixture_path + "/test.jpg" assigns[:post] = stub("Post", :title => "This is the title of my post!", :story => "This is my beautiful picture.", :picture => #???? ) end it "displays the text of the title" do render response.should contain("This is the title of my post!") end it "displays the text of the story" do render response.should contain("This is my beautiful picture.") end it "displays the picture" end
I don't know what to put in the :picture symbol as part of the stub. Until I can figure that out, there's no way I can implement the actual test case (the last one, obvi).
Has anyone ever had to do this before?