哈特尔第5章full_title未找到

时间:2013-03-10 20:09:29

标签: ruby ruby-on-rails-3

我参加了第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

1 个答案:

答案 0 :(得分:0)

Tutorial似乎在与你不同的地方添加了{{3}}。 full_title上使用的spec已在spec/support/utilities.rb上定义。在application_helper.rb中使用app/views/layouts/application.html.erb上定义的那个。