I have a simple view and helper that defines the title. Everything works fine if I pull the view in the browser, but the rspec tests fail. Here is what I have:
Here are my tests:
describe PagesController do render_views before(:each) do @base_title = "RoR Sample App" end describe "GET 'home'" do it "should be successful" do get 'home' response.should be_success end it "should have the right title" do get 'home' response.should have_selector("title", :content => @base_title + " | Home") end end end
Page Controller:
class PagesController < ApplicationController def home @title = "Home" end def contact @title = "Contact" end def about @title = "About" end def help @title = "Help" end end
Assistant:
module ApplicationHelper
And the view:
<!DOCTYPE html> <html> <head> <title><%= title %></title> <%= stylesheet_link_tag :all %> <%= javascript_include_tag :defaults %> <%= csrf_meta_tag %> </head> <body> <%= yield %> </body> </html>
All of this displays correctly in the browser, but tests fail when they fall into the string <%= title %> .
1) PagesController GET 'home' should be successful Failure/Error: get 'home' ActionView::Template::Error: undefined local variable or method `title' for #<#<Class:0xabf0b1c>:0xabeec18> # ./app/views/layouts/application.html.erb:4:in `_app_views_layouts_application_html_erb___418990135_90147100_123793781'
Any idea what I'm doing wrong?
Swift source share