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

  • SEARCH
  • Home
  • 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 9270511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:23:18+00:00 2026-06-18T15:23:18+00:00

Ruby newbie here trying to get to grips with rspec, rails, cucumber. I’m not

  • 0

Ruby newbie here trying to get to grips with rspec, rails, cucumber.

I’m not sure why this is returning the following error:

1) User can be found by username
Failure/Error: user.should_not be_valid
NoMethodError:
    undefined method `valid?' for nil:NilClass
    # ./spec/models/user_spec.rb:26:in `block (2 levels) in <top (required)>'

From the following model spec file:

require 'spec_helper'

describe User do
  let(:user) { User.new(
      :username => 'username',
      :password => 'password'
    )
  }

  it "should be createable" do
    user.should be_valid
  end

  it "cannot have an empty username" do
    user.username = nil
    user.should_not be_valid
  end

  it "cannot have an empty password" do
    user.password = nil
    user.should_not be_valid
  end

  it "can be found by username" do
    user = User.find_by_username('username')
    user.should be_valid  
  end
  it "can be deleted"
end

I’m sure it’s something simple but I can’t figure it out?

  • 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-18T15:23:19+00:00Added an answer on June 18, 2026 at 3:23 pm

    In your let call you need to actually “create” the user. You just built it without saving. So when you call

    user = User.find_by_username('username')
    

    That is returning nil as the record is not saved and can’t be found.

    Also, #find_by_username is part of Rails, you don’t really need to be testing that.

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

Sidebar

Related Questions

I'm Ruby/Rails newbie and trying to get the laika tool ( http://github.com/CCHIT/laika/tree/master ) running
I am newbie in Ruby. I installed by following this tutorial: http://udooz.net/blog/2011/02/facebook-app-using-rails-koala/ Now, when
Ruby newbie here. I'm following the Rails Tutorial and got stuck around 5.3 re:
I am a newbie with ruby and was trying out something small. So this
I'm a newbie Rails developer who is getting the following error when trying to
hey I am newbie to ruby on rails and I am trying run a
I'm just learning Ruby so apologies if this is too newbie for around here,
Still a rails and ruby newbie, and I'm trying to figure out why adding
I´m newbie in Ruby on rails, and I´m trying to display a select with
Ok, total Cucumber newbie here so please be gentle. As a learning Ruby/Cucumber/MongoDB endeavor

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.