Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RSpec title test fails with the variable full_title, but passes with string text the variable full_title provides to the title

I'm going through Chapter 5 of RailsTutorial.org.

I have one test that I can't get to work no matter what I do. It passes when I put in the string the variable passes, but not when I put in the variable itself.

The error says undefined method 'full_title' (I couldn't find an answer after 30 min of browsing related questions after typing this up.)

Doing a superficial test, the desired content displays in the app, the title includes the full title with 'Sign up.'

Here is my code:

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

This is when the error says undefined method 'full_title'

It passes when I use this code:

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

Thanks for your help! Adam

like image 860
ATSiem Avatar asked May 07 '12 23:05

ATSiem


4 Answers

Restarting Guard fixes the problem.

like image 64
Andrii Yurchuk Avatar answered Oct 14 '22 05:10

Andrii Yurchuk


To make the full_title tests work, make sure to create spec/support/utilities.rb from Listing 5.26

I skipped it by accident since it looks exactly like a duplicate method from Chapter 3.

like image 21
ATSiem Avatar answered Oct 14 '22 05:10

ATSiem


I got the same problem, and here is how I solved it. Make sure that the file /spec/support/utilities.rb has the following code:

include ApplicationHelper

This will fix your problem.

like image 40
Moe Hassan Avatar answered Oct 14 '22 06:10

Moe Hassan


If write: config.include ApplicationHelper into spec_helper.rb everything will work fine, but it that moment I don't see logic to have file utilities.rb into spec/support (everything works without it)

like image 36
Aleksey Dz Avatar answered Oct 14 '22 06:10

Aleksey Dz