Rails Tutorial Chap 5 Exercise 3 - What did the original full_title function do? -
i confused chap 5 exercise 3 here replaces need full_title test helper
spec/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 rails helper function same name:
module applicationhelper # returns full title on 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 application helper test function directly with: spec/helpers/application_helper_spec.rb
require 'spec_helper' describe applicationhelper describe "full_title" "should include page title" full_title("foo").should =~ /foo/ end "should include base title" full_title("foo").should =~ /^ruby on rails tutorial sample app/ end "should not include bar home page" full_title("").should_not =~ /\|/ end end end this great tests rails helper function directly thought full title function in utilities.rb use in rspec code. therefore, how come can eliminate above code in utilities.rb , replace just:
include applicationhelper i made swap , still worked. expecting rspec code though using rspec function following error not:
it "should have right links on layout" visit root_path click_link "about" page.should have_selector 'title', text: full_title('about us') ... has the above function call pointed actual rails function , not respec function? if able eliminate in first place? feel missing here. help. seems bad idea making changes not understand when goal learn rails.
thanks, mark
full_title in specs always calls spec/support/utilities.rb.
before replaced code include applicationhelper, full_title in specs calling function found in 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 by replacing code just
include applicationhelper to clear, including
module applicationhelper from helpers/application_helper.rb.
this has nothing describe applicationhelper in spec/helpers/application_helper_spec.rb
what happens full_title function module applicationhelper mixed in (see mixins) utilities.rb. hence, utilities.rb gains access function full_title module applicationhelper(helpers/application_helper.rb).
so, when specs call full_title function, called utilities.rb, possible because function has been mixed in via use of include applicationhelper.
Comments
Post a Comment