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 9222503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:50:53+00:00 2026-06-18T03:50:53+00:00

In my spec/models/user_spec.rb I have the next: require ‘spec_helper’ describe User do before {

  • 0

In my spec/models/user_spec.rb I have the next:

require 'spec_helper'

describe User do

  before { 5.times { FactoryGirl.create(:sport) } }
  before { let(:user) { FactoryGirl.create(:user) } }

  ...

end

But when running my user_spec.rb I’m getting this error:

Failure/Error: before { let(:user) { FactoryGirl.create(:user) } }
 NoMethodError:
   undefined method `let' for #<RSpec::Core::ExampleGroup::Nested_1:0x000001043033b0>

Which is weird because my specs have been working until now, and I haven’t changed anything…

Here is my gemfile: https://gist.github.com/4690919

Here is my spec_helper.rb: https://gist.github.com/4690935

I’d appreciate any help, thanks

  • 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-18T03:50:53+00:00Added an answer on June 18, 2026 at 3:50 am

    I don’t know why it was working before, but you should never have a let block inside of a before block. It should be called from within a describe (or context) block, like this:

    describe User do
      let(:user) { FactoryGirl.create(:user) }
      before { 5.times { FactoryGirl.create(:sport) } }
      ....
    

    See the documentation for details.

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

Sidebar

Related Questions

My spec require 'spec_helper' describe 'user_sessions/new.html.erb' do let (:user_session) { mock_model(UserSession).as_null_object } before do
I get following error when running rspec: bundle exec rspec spec/models/user_spec.rb Failures: 1) User
I have one spec: require 'spec_helper' # hmm... I need to include it here
I have two models. class User has_one :spec, :dependent => :destroy # returns true
I am working on a Rail webapp. I have two models, User, which contains
I have the following block of code in my User_spec.rb: @user = { username:'newuser',
I'm following the Ruby on Rails 3 tutorial, chapter 6. Inside my directory spec/models/user_spec.rb
Here are my Factories: spec/factories.rb FactoryGirl.define do factory :user do username 'user1' time_zone 'Eastern
I have the following models class User < ActiveRecord::Base devise :database_authenticatable, :registerable, :recoverable, :rememberable,
I've run into this problem with testing. Let's assume I have two models, User

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.