0

Following the tutorial, I created a file omniauth.rb at the path

spec/support/helpers/omniauth.rb

module Omniauth

  module Mock
    def auth_mock
      OmniAuth.config.mock_auth[:twitter] = {
        'provider' => 'twitter',
        'uid' => '123545',
        'user_info' => {
          'name' => 'mockuser'
        },
        'credentials' => {
          'token' => 'mock_token',
          'secret' => 'mock_secret'
        }
      }
    end
  end

end

But when I run rspec, I get an error with "uninitialized constant Omniauth"

rails-omniauth/spec/support/helpers.rb:2:in `block in <top (required)>': uninitialized constant Omniauth (NameError)

It seems clear that either omniauth.rb or helpers.rb should be in a different location, but I don't know where.

Update:

I subsequently tried installing the rails-omniauth via the Rails Composer app. When I run "rspec" for this app, I get exactly the same error.

wbruntra
  • 1,021
  • 1
  • 10
  • 18
  • 1
    This answer might help: http://stackoverflow.com/questions/31232281/how-to-get-rid-of-uninitialized-constant-omniauth-nameerror. YMMV. – orde Mar 11 '16 at 01:08
  • I know it seems vague but the tutorials are actually called "Railsapps". The website is here: https://tutorials.railsapps.org/ – wbruntra Mar 11 '16 at 14:52

1 Answers1

0

At one point in the tutorial you are given a choice between creating a file at at /spec/support/helpers.rb:

RSpec.configure do |config|
  config.include Omniauth::Mock
  config.include Omniauth::SessionHelpers, type: :feature
end
OmniAuth.config.test_mode = true

Or adding these same lines to /spec/rails_helper.rb.

I created the new file at /spec/support/helpers.rb. To make this work, I needed to add the line require_relative 'helpers/omniauth' at the top of the file. The Rails Composer app also adds the helpers.rb file rather than editing rails_helper.rb, so the same line is needed to make rspec run successfully for that app.

wbruntra
  • 1,021
  • 1
  • 10
  • 18