RSpec标题测试失败,变量为full_title,但是传递了字符串文本变量full_title提供给标题

ATS*_*iem 5 rspec railstutorial.org

我正在阅读RailsTutorial.org的第5章.

无论我做什么,我都有一项无法上班的测试.它在我输入变量传递的字符串时传递,但是当我放入变量本身时它不会传递.

该错误表示未定义的方法'full_title'(在输入相关问题30分钟后我无法找到答案.)

做一个肤浅的测试,在应用程序中显示所需的内容,标题包括"注册"的完整标题.

这是我的代码:

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
Run Code Online (Sandbox Code Playgroud)

这是错误说未定义的方法'full_title'

它在我使用此代码时通过:

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: 'Ruby on Rails Tutorial Sample App | Sign up') }
  end
end
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助!亚当

And*_*huk 11

重新启动Guard可以解决问题.


ATS*_*iem 7

要使full_title测试工作,请确保spec/support/utilities.rb从代码清单5.26创建

我偶然跳过它,因为它看起来与第3章中的重复方法完全相同.


小智 6

我遇到了同样的问题,这就是我解决它的方法.确保该文件/spec/support/utilities.rb包含以下代码:

include ApplicationHelper
Run Code Online (Sandbox Code Playgroud)

这将解决您的问题.