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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:43:22+00:00 2026-05-27T03:43:22+00:00

I believe I have some problem with scoping. I have a controller spec file

  • 0

I believe I have some problem with scoping.

I have a controller spec file which tests a brands resource.
At the start of the file, I test the resource’s access for different
users in a context block
a) not signed in
b) non-admin user signed in- I call my own helper method, login_user
c) admin user signed in – I call my own helper method,
login_admin_user
Specs there do pass successfully.

I then create another context block to just test the resource for an
admin user that’s signed in.
I tried calling login_admin_user in a before hook as per the previous
specs .

It fails and I suspect that the current scope within the before hook
does not see my custom helper method, login_admin_user.
Here is the error message:

——— Extract start —————–

/usr/local/rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/
active_support/dependencies.rb:235:in `load': /Users/anexiole/projects/
try_rails/spec/controllers/brands_controller_spec.rb:164: syntax
error, unexpected keyword_end, expecting $end (SyntaxError)
  from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/
active_support/dependencies.rb:235:in `block in load'
  from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/
active_support/dependencies.rb:227:in `load_dependency'
  from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/
active_support/dependencies.rb:235:in `load'
  from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/
rspec/core/configuration.rb:419:in `block in load_spec_files'
  from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/
rspec/core/configuration.rb:419:in `map'
  from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/
rspec/core/configuration.rb:419:in `load_spec_files'
  from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/
rspec/core/command_line.rb:18:in `run'
  from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/
rspec/core/runner.rb:80:in `run_in_process'
  from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/
rspec/core/runner.rb:69:in `run'
  from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/lib/
rspec/core/runner.rb:11:in `block in autorun'

———- Extract end ——————

My specs is as follows:

——— spec/controllers/brands_controller_spec.rb (start)

require 'spec_helper'

describe BrandsController do

  # This should return the minimal set of attributes required to create a valid
  # Brand. As you add validations to Brand, be sure to
  # update the return value of this method accordingly.
  def valid_attributes
    {
        'name' => 'J Speed',
        'description' => 'From gunsai province'
    }
  end


    context 'checking access for varying users' do
        describe 'brands access is not available to users who have not
signed in' do
            it 'users that are not logged in will be sent to the sign
in page' do
                get :index
                response.should redirect_to(new_user_session_path)
            end
        end

        describe 'brands access is not available to regular users' do
            login_user

            it 'regular users that are logged in will be sent to home
page' do
                get :index
                response.should redirect_to(root_path)
            end
        end

        describe 'brands access is available only to admin users' do
            login_admin_user

            it 'admin users that are logged in can access the index
page' do
                get :index
                response.should render_template('index')
            end
        end
    end

    context 'with an admin user signed in' do    # <----- starts
failing in this context
        before(:each) do
            login_admin_user
        end

        describe "creates a new brand entry" do
            it "assigns a new brand as @brand" do
                get :new
                assigns(:brand).should be_a_new(Brand)
            end
        end
    end
end

——— spec/controllers/brands_controller_spec.rb (end)

  • 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-05-27T03:43:23+00:00Added an answer on May 27, 2026 at 3:43 am

    login_admin_user creates a before hook, but here it’s inside a before
    hook. That doesn’t work. Try:

    context 'with an admin user signed in' do
      login_admin_user # not inside a before hook
    
      describe "creates a new brand entry" do
        it "assigns a new brand as @brand" do
          get :new
          assigns(:brand).should be_a_new(Brand)
        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 a problem with some code and I believe it is because of
I have a very strange bug, which I believe is caused by some code
I have a Spring application that I believe has some bottlenecks, so I'd like
Here is the problem: We have some pdf files with youtube videos embedded in
I have some Kind of Question about FFT (Actually I believe it's more about
I believe I'm getting bitten by some combination of nested scoping rules and list
i have made a program in which i make a file in the data/data/mypackagename/
I believe I have disabled the view state on all controls as well as
I believe I have a potential threading issue. I have a user control that
I believe I have found a weird bug as follow: I want to delete

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.