title: Rails cucumber uninitialized constant User (NameError)
body: <p>I'm starting with BDD (cucumber + capybara + selenium chromedriver) and TDD (rspec) with factory_bot and I'm getting an error on cucumber features - step_definitions.</p>
  
  <blockquote>
    <p>uninitialized constant User (NameError)</p>
  </blockquote>
  
  <p>With TDD, everything is ok, the factory bot is working fine. The problem is with the cucumber.</p>
  
  <p><em>factories.rb</em></p>
  
  <pre><code>FactoryBot.define do
  
      factory :user_role do
          name {"Admin"}
          query_name {"admin"}
      end
  
      factory :user do
          id {1}
          first_name {"Mary"}
          last_name {"Jane"}
          email {"mary_jane@gmail.com"}
          password {"123"}
          user_role_id {1}
          created_at {'1/04/2020'}
      end
  end
  </code></pre>
  
  <p><em>support/env.rb</em></p>
  
  <pre><code>require 'capybara'
  require 'capybara/cucumber'
  require 'selenium-webdriver'
  require 'factory_bot_rails'
  
  Capybara.register_driver :selenium do |app|
      Capybara::Selenium::Driver.new(app, browser: :chrome)
  end
  
  Capybara.configure do |config|
      config.default_driver = :selenium
  end
  
  Capybara.javascript_driver = :chrome
  
  World(FactoryBot::Syntax::Methods)
  </code></pre>
  
  <p>And the problem is happening here</p>
  
  <p><em>support/hooks.rb</em></p>
  
  <pre><code>Before '@admin_login' do
      @user = create(:user)
  end
  </code></pre>
  
  <p><em>step_definitions/admin_login.rb</em></p>
  
  <pre><code>Given("a registered user with the email {string} with password {string} exists") do |email, password|
      @user
  end
  </code></pre>
  
  <p>I don't know why, but I can't access the user using cucumber and factory_bot.</p>
  
  <p>Anybody could help me please?</p>
  
  <p>I think I need to configure something on the cucumber.</p>
  
  <p>What do you think guys?</p>
  
  <hr>