【发布时间】:2013-11-27 07:51:31
【问题描述】:
我正在练习Ruby on Rails Tutorial,我有一个关于 rspec 的问题。
在测试app/helpers/application_helper.rb中定义的方法full_title时,
module ApplicationHelper
def full_title(title)
base_title = "Ruby on Rails Tutorial Sample App"
if title.empty?
base_title
else
"#{base_title} | #{title}"
end
end # end of def
end
您不必在 spec/helpers/application_helper_spec.rb 中include ApplicationHelper。在 spec/requests/static_pages_spec.rb 中,您必须 include ApplicationHelper,否则 undefined methodfull_title'` 的测试将失败。
在我看来,rspec 会自动加载文件 app/helpers/application_helper.rb,您不必再次包含它。两个测试样例有什么区别?
【问题讨论】:
标签: ruby-on-rails rspec