I'm getting started with rspec, capybara, etc, and I want to do some test driven development in Rails.
The specification I'm working with has very precise definitions for the appearance of the headers and the footers, and I figure that these are a good place to start learning.
For the footer, I want to have the following rule:
If the user is logged in, then the header contains just a logo image. The logo image should be a link to the user's landing page, which is determined by the rights the user has. If the user is not logged in, then the image is not a link, and four other links should appear in the footer as well, in a table.
Coding this is actually fairly straightfoward in erb, but I'm trying to Do The Right Thing, and make a series of tests here. My problems is that I can't seem to be able to test whether or not an image is shown on the screen. I've read the rspec book, but I don't see where it says something like 'shows this image found in the assets directory.'
So my setup is, in the views/layouts directory, _header.html.erb _footer.html.erb _shim.html.erb application.html.erb
I would think that I could test the footer partial directly, using something like:
require "spec_helper"
describe "rendering views/layouts/_footer.html.erb" do
#from https://www.relishapp.com/rspec/rspec-rails/v/2-8/docs/view-specs/view-spec
it "shows the logo" do
render :template => "layouts/_footer.html.erb"
rendered.should =~ "/images/mainlogo.png"
end
describe "rendering views/layouts/_footer.html.erb as admin" do
before do
FactoryGirl.create(:admin_user)
end
it "links to landing from the logo"
render :template => "layouts/_footer.html.erb"
rendered.should contain("link/to/admin/landing")
end
end
#repeat landing tests for various user types
And then, in other pages, I can simply test for the presence of the footer itself using something like
it should contain("footer")
My problem is, I can't even get off the ground to check to see if the image has been shown, much less if the image matches the right one in the assets directory. What should I be doing here?
The above code for testing the presence of the image (just the first describe/it block, not the stuff with the 'as admin' or the 'should contain') gives me the following warning and error:
DEPRECATION WARNING: Passing a template handler in the template name is deprecated.
TypeError:
type mismatch: String given
The first is probably due to me using syntax I don't understand, but the second seems to suggest that the comparison is with strings rather than assets. What's the syntax to compare images? Is there one?