Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7742997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:25:13+00:00 2026-06-01T09:25:13+00:00

I’m having trouble with Exercise 4 in Chapter 7 of railstutorial.org . Here are

  • 0

I’m having trouble with Exercise 4 in Chapter 7 of railstutorial.org.

Here are the tests:

    describe "signup" do
    before { visit signup_path }

    describe "with invalid information" do
        it "should not create a user" do
            expect { click_button "Create my Account".not_to change(User, :count) }
        end
    end

    describe "error messages" do
        before { click_button "Create my account" }

        it { should have_selector('title', text: "Sign up") }
        it { should have_content('error') }
    end

    describe "with valid information" do
        before do
            fill_in "Name", with: "Example User"
            fill_in "Email", with: "user@example.com"
            fill_in "Password", with: "foobar"
            fill_in "Confirmation", with: "foobar"
        end

        it "should create a user" do
            expect do
                click_button "Create my account"
            end.to change(User, :count).by(1)
        end
    end

    describe "after saving the user" do
        before { click_button "Create my account" }
        let(:user) { User.find_by_email('user@example.com') }

        it { should have_selector('title', text: user.name) }
        it { should have_selector('div.alert.alert-success', text: 'Welcome') }
    end
end

Here is what it’s supposed to test, users_controller.rb:

def create
 @user = User.new(params[:user])
 if @user.save
  flash[:success] = "Welcome to the Sample App!"
  redirect_to @user
 else
    render 'new'
 end
end

Here’s the show.html.erb code as well:

<% provide(:title, @user.name) %>
<div class="row">
<aside class="span4">
    <section>
        <h1>
            <%= gravatar_for @user %>
            <%= @user.name %>
        </h1>
    </section>
</aside>
</div>

When I run my tests, I get this:

$ bundle exec rspec spec/requests/user_pages_spec.rb 
........FF

Failures:

  1) User Pages signup after saving the user 
 Failure/Error: it { should have_selector('title', text: user.name) }
 NoMethodError:
   undefined method `name' for nil:NilClass
 # ./spec/requests/user_pages_spec.rb:57:in `block (4 levels) in <top (required)>'

  2) User Pages signup after saving the user 
 Failure/Error: it { should have_selector('div.alert.alert-success', text: 'Welcome') }
   expected css "div.alert.alert-success" with text "Welcome" to return something
 # ./spec/requests/user_pages_spec.rb:58:in `block (4 levels) in <top (required)>'

Finished in 0.86152 seconds
10 examples, 2 failures

Failed examples:

rspec ./spec/requests/user_pages_spec.rb:57 # User Pages signup after saving the user 
rspec ./spec/requests/user_pages_spec.rb:58 # User Pages signup after saving the user 

It should save the test user to the test db, but for some reason, user.name is turning out nil. Any ideas?

Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T09:25:15+00:00Added an answer on June 1, 2026 at 9:25 am

    Without going over your code in detail to understand the context of everything, it’s not that user.name is returning nil, it’s that user is nil, and therefore has no method/property name as seen here:

    undefined method `name' for nil:NilClass
    

    You have this line here before the test case defining the symbol :user:

    let(:user) { User.find_by_email('user@example.com') }
    

    yet you reference the object user in your test:

    it { should have_selector('title', text: user.name) }
    

    Change the symbol :user to user in the former and your tests should pass.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.