我正在阅读railstutorial 第 5.6.4 章。
根据页面,以下两个代码用于相同的测试。但是我不明白为什么没有论点它会起作用page_title
。"foo"
Rspec中的字符串有特殊含义吗?
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
spec/helpers/application_helper_spec.rb
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
spec/support/utilities.rb
include ApplicationHelper