Undefined local variable or capybara rspec method

I keep getting this weird error when I use capybara methods outside the 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_pathexist. I have several other tests that work. But it looks like I can use Capybara when the methods are inside the block before. It 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 results in an error:

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

It works:

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

I want to use subject { page }, but you can use capybara without using a block before do end. Any idea what I'm doing wrong?

My spec_helper.rbfile:

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 am on Rails 3.2 with Capybara 1.1.2, Rspec 2.8.1.

+5
source share
1 answer

describe. . before it.

+8

All Articles