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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:48:53+00:00 2026-06-10T04:48:53+00:00

I have the following test block in rspec: describe for signed-in users do let(:user)

  • 0

I have the following test block in rspec:

    describe "for signed-in users" do
      let(:user) { FactoryGirl.create(:user) }
      before do
        FactoryGirl.create(:micropost, user: user, content: "Lorem ipsum")
        FactoryGirl.create(:micropost, user: user, content: "Dolor sit amet")
        sign_in user
        visit root_path
      end

      describe "sidebar" do
        it { should have_selector('div.pagination')}
        it "should render the user's feed" do
          user.feed.each do |item|
            page.should have_selector("li##{item.id}", text: item.content)
          end
        end

        describe "micropost delete links" do
          let(:other_user) { FactoryGirl.create(:user, email: "other@example.com") }
          let!(:m3) {  FactoryGirl.create(:micropost, user: other_user, content: "Other MP") }

          user.feed.each do |item|
            find("li##{item.id}").should have_link('delete')
          end
        end

        it "should show the correct number of microposts" do
          page.should have_selector('span', text: '2 microposts')
          user.microposts.first.destroy
          visit root_path
          page.should have_selector('span', text: '1 micropost')
          user.microposts.first.destroy
          visit root_path
          page.should have_selector('span', text: '0 microposts')
        end
      end
    end

When I run it I get this error:

/Users/8vius/Projects/RubyDev/sample_app/spec/requests/static_pages_spec.rb:49:in `block (5 levels) in <top (required)>': undefined local variable or method `user' for #<Class:0x007fd45c8c39c0> (NameError)

This only happens after I added the “describe micropost delete links” block, any idea what the problem is?

  • 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-10T04:48:54+00:00Added an answer on June 10, 2026 at 4:48 am

    You have a describe block that is running a test outside of an it block. The user is undefined because of this.

    Yours:

    describe "micropost delete links" do
      let(:other_user) { FactoryGirl.create(:user, email: "other@example.com") }
      let!(:m3) {  FactoryGirl.create(:micropost, user: other_user, content: "Other MP") }
    
      user.feed.each do |item|
        find("li##{item.id}").should have_link('delete')
      end
    end
    

    vs:

    describe "micropost delete links" do
      let(:other_user) { FactoryGirl.create(:user, email: "other@example.com") }
      let!(:m3) {  FactoryGirl.create(:micropost, user: other_user, content: "Other MP") }
    
      it "should have delete link" do
        user.feed.each do |item|
          find("li##{item.id}").should have_link('delete')
        end
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following string: Test, User < test@test.com >, Another, Test < another@test.com >,
I have the following block of code in a makefile: param_test_dir: @if test -d
I have the following: var test = dojo.byId(clientDivision); test.style.display = 'block'; in a function
I have the following block in my JSP, which converts from ENUM values {CREATE,
I have following test.pyx cdef public class Foo[object Foo, type FooType]: cdef public char*
I have following test class @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {/services-test-config.xml}) public class MySericeTest { @Autowired
suppose I have following test/ Main.py test/one/ One.py test1.txt test/two/ Two.py test2.txt What I
I have following databases: test table1 fields: id, password, name, lastname test2 table2 fields:
I have the following code: InputStream reportFile = MyPage.this.getClass().getResourceAsStream(test.jrxml); HashMap<String, String> parameters = new
I have the following XML file: <book> <bookname child=test> <text> Works </text> <text> Doesn't

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.