2013-03-10 64 views
1

我在第5章 運行測試文件時,我發現了以下錯誤Hartl的教程是:哈特爾第5章full_title

失敗:

1) User pages Signup page 
Failure/Error: it { should have_selector('title', text: full_title('Sign up')) } 
NoMethodError: 
    undefined method `full_title' for #<RSpec::Core::ExampleGroup::Nested_2::Nested_1:0xaeb792c> 
# ./spec/requests/user_pages_spec.rb:12:in `block (3 levels) in <top (required)>' 

爲了簡潔,我在排除故障時已將其他「full_title未找到」錯誤評論出來。

我已經確認該方法在app/helpers/application_helper.rb文件中。 任何想法,爲什麼它沒有被發現?這絕對是在助手文件中。

我的用戶頁面spec文件:

require 'spec_helper' 

describe "User pages" do 

    subject { page } 

    describe "Signup page" do 
    before { visit signup_path } 

    it { should have_selector('h1', text: 'Sign Up') } 
    it { should have_selector('title', text: full_title('Sign up')) } 
    end 
end 

和我application_helper.rb文件

module ApplicationHelper 

    # Returns the full title on a per-page basis. 
    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 
end 

回答

0

Tutorial似乎補充說,在不同的地方是你的。在spec上使用的full_titlespec/support/utilities.rb上定義。在application_helper.rb上定義的那個用於app/views/layouts/application.html.erb

+0

非常感謝。我不知道我是如何錯過的。我真的一直在看這個好幾個小時。這照顧了我的問題。 – 2013-03-10 21:19:54

相關問題