ATSiem
ATSiem

Reputation: 1204

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

Upvotes: 5

Views: 3684

Answers (5)

Oleksii Dz
Oleksii Dz

Reputation: 71

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)

Upvotes: 1

wikichen
wikichen

Reputation: 2253

I ran into the exact same problem... except after 20 minutes of banging my head against the wall, I finally saw what was wrong: I named the rspec/support folder suppport. No wonder spec_helper.rb couldn't find it. *facepalm*

Upvotes: 0

Moe Hassan
Moe Hassan

Reputation: 61

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.

Upvotes: 6

Andrii Yurchuk
Andrii Yurchuk

Reputation: 3270

Restarting Guard fixes the problem.

Upvotes: 11

ATSiem
ATSiem

Reputation: 1204

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.

Upvotes: 7

Related Questions