1

第 5 章の Hartl チュートリアルにいます。テスト ファイルを実行すると、次のエラーが発生します。

失敗:

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 not found」エラーをコメントアウトしました。

メソッドが app/helpers/application_helper.rb ファイルにあることを確認しました。見つからない理由はありますか?それは間違いなくヘルパーファイルにあります。

私のユーザーページ仕様ファイル:

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
4

1 に答える 1

0

チュートリアルは、あなたとは別の場所にそれを追加しているようです。で使用full_titleされるspecは で定義されましたspec/support/utilities.rb。で定義されたものapplication_helper.rbが で使用されましたapp/views/layouts/application.html.erb

于 2013-03-10T21:00:52.487 に答える