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)>'

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

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