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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:59:09+00:00 2026-05-31T09:59:09+00:00

I keep getting this strange error when I use capybara methods outside of a

  • 0

I keep getting this strange error when I use capybara methods outside of a before block:

$ rspec . -e "PasswordResets"
/spec/requests/password_resets_spec.rb:9:in `block (2 levels) in <top (required)>': undefined local variable or method `root_path' for #<Class:0x00000003bfa100> (NameError)

root_path does exists. I have multiple other tests that work. But it appears I can only use Capybara when the methods are inside a before block. This works:

require 'spec_helper'
describe "PasswordResets" do
  subject { page }
  describe "it emails user when requesting a password reset" do
    before do
      visit root_path
    end
  end
end

This produces the error:

require 'spec_helper'
describe "PasswordResets" do
  subject { page }
  describe "it emails user when requesting a password reset" do
    visit root_path
  end
end

This works:

require 'spec_helper'
describe "PasswordResets" do
  it "emails user when requesting a password reset" do
    visit root_path
  end
end

What I want to do is use the subject { page } but be able to use capybara without having to use a before do end block. Any idea what I’m doing wrong?

My spec_helper.rb file:

ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'capybara/rspec'

Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

RSpec.configure do |config|
  config.fixture_path = "#{::Rails.root}/spec/fixtures"
  config.use_transactional_fixtures = true
  config.infer_base_class_for_anonymous_controllers = false
end

I’m on Rails 3.2 with Capybara 1.1.2, Rspec 2.8.1.

  • 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-31T09:59:10+00:00Added an answer on May 31, 2026 at 9:59 am

    You can’t put test code directly in a describe. The scope is different. Put it in a before or an it block.

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

Sidebar

Related Questions

Trying to install pear package and keep getting this strange error. Can you shed
Keep getting this error after inserting a subdatasheet into a query and trying to
I keep getting this error System.Web.HttpException was unhandled by user code Message=Validation of viewstate
I keep getting this error when I try to commit a group of executed
I keep getting this error when I try to call Find() public void findTxt(string
I keep getting this error all over the place where I only have jquery
I keep getting this error whenever I call gethostbyname() in my C code. ==7983==
I keep getting this error, although the file still gets moved into the correct
I keep getting this Magento error emailed to myself: URL: http://mysite.com/sendfriend/product/send/id/1/ IP Address: 66.249.65.69
I keep getting this error when I try to build my solution. I've tried

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.