【发布时间】:2013-12-02 19:32:38
【问题描述】:
我正在使用 rspec 文件中的 let 函数。我想使用 let 函数来替换字符串实例变量的使用,就像我在下面的 @astr 中使用的那样。
describe "Static pages" do
let (:str) { "Ruby on Rails Tutorial Sample App" }
describe "Contact Page" do
it "should have title 'Contact'" do
@astr = "Ruby on Rails Tutorial Sample App"
visit '/static_pages/contact'
expect(page).to have_title("#{@astr} | Contact")
end
end
...
变成了
it "should have title 'Contact'" do
visit '/static_pages/contact'
expect(page).to have_title("#{str} | Contact")
end
让我感到困惑的是为什么 #{str} 有效而 #{:str} 无效 - 取消引用符号 - 就像我们保留“@”一样对于#{@astr},为什么约定不适用于符号中的冒号?
【问题讨论】:
标签: ruby-on-rails