Answer the question
In order to leave comments, you need to log in
How does this code from "RoR Tutorial" (Rspec) work?
Explain how the code works ( railstutorial.ru/chapters/4_0/filling-in-the-layyou...
Here it is:
require 'spec_helper'
describe ApplicationHelper do
describe "full_title" do
it "should include the page title" do
expect(full_title("foo")).to match(/foo/)
end
it "should include the base title" do
expect( full_title("foo")).to match(/^Ruby on Rails Tutorial Sample App/)
end
it "should not include a bar for the home page" do
expect(full_title("")).not_to match(/\| /)
end
end
end
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
Answer the question
In order to leave comments, you need to log in
omg
1) The string foo is a parameter that you pass to the full_title function, expecting that in this case the result will return something that will match the regexp with foo
2) There is absolutely no advantage. It's just that the first code is the code from the test suite, the second a is the definition of the method
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question