I am confused by Chap 5 Exercise 3 here , which replaces the need for a full_title validation assistant
Specification / Support / utilities.rb:
def full_title(page_title) base_title = "Ruby on Rails Tutorial Sample App" if page_title.empty? base_title else "#{base_title} | #{page_title}" end end
There is also a helper function rails with the same name:
module ApplicationHelper # Returns the full title on a per-page basis. def full_title(page_title) base_title = "Ruby on Rails Tutorial Sample App" if page_title.empty? base_title else "#{base_title} | #{page_title}" end end end
by creating an application helper that directly checks the function: specifications / helpers / application_helper_spec.rb
require 'spec_helper' describe ApplicationHelper do describe "full_title" do it "should include the page title" do full_title("foo").should =~ /foo/ end it "should include the base title" do full_title("foo").should =~ /^Ruby on Rails Tutorial Sample App/ end it "should not include a bar for the home page" do full_title("").should_not =~ /\|/ end end end
It's great that he tests the rails helpers function directly, but I thought the full title function in the .rb utility is for use in Rspec code. Therefore, how can we eliminate the above code in utilities.rb and replace it simply:
include ApplicationHelper
I made a swap and it still worked. I was expecting Rspec code, which, although I used the rspec function as shown below, but it is not:
it "should have the right links on the layout" do visit root_path click_link "About" page.should have_selector 'title', text: full_title('About Us') ...
Is the above function call always called with a pointer to the actual rails function, and not with the respec function? If I could eliminate it, what was it first for? I feel that something is missing here. Thanks for any help. It seems like a bad idea to make changes, I donβt understand when my goal is to learn Rails.
Thanks Mark