【问题标题】:hartl chapter 5 full_title not found未找到 hartl 第 5 章 full_title
【发布时间】:2013-02-25 22:40:47
【问题描述】:

我在第 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)>'

为简洁起见,我已在故障排除时注释掉了其他“未找到完整标题”错误。

我已经确认该方法在 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

【问题讨论】:

    标签: ruby ruby-on-rails-3


    【解决方案1】:

    Tutorial 似乎将它添加到了与您不同的位置。在spec 上使用的full_titlespec/support/utilities.rb 上定义。在application_helper.rb 上定义的那个在app/views/layouts/application.html.erb 中使用。

    【讨论】:

    • 非常感谢。我不知道我是怎么错过的。我已经看了好几个小时了。这解决了我的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-08
    相关资源
    最近更新 更多