我在練習Ruby on Rails Tutorial,我有一個關於rspec的問題。Rspec自動加載文件
在測試中應用程序/傭工/ 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
你不必include ApplicationHelper
在規格/助理/ application_helper_spec.rb。雖然在spec/requests/static_pages_spec.rb,你必須include ApplicationHelper
,否則測試將失敗的undefined method
full_title'`。
在我看來,rspec會自動加載文件app/helpers/application_helper.rb,你不必再包含它。這兩個測試例子有什麼不同?