jsonapi-rb / jsonapi-rspec

RSpec matchers for JSON:API spec
https://rubygems.org/gems/jsonapi-rspec
MIT License
123 stars 24 forks source link

Error initializing over rails db:schema:load #5

Closed richipargo closed 4 years ago

richipargo commented 6 years ago
$ rails db:schema:load
rails aborted!
NameError: uninitialized constant RSpec
/builds/quap/backend/vendor/ruby/2.4.0/gems/jsonapi-rspec-0.0.2/lib/jsonapi/rspec/id.rb:4:in `<module:Id>'
/builds/quap/backend/vendor/ruby/2.4.0/gems/jsonapi-rspec-0.0.2/lib/jsonapi/rspec/id.rb:3:in `<module:RSpec>'
/builds/quap/backend/vendor/ruby/2.4.0/gems/jsonapi-rspec-0.0.2/lib/jsonapi/rspec/id.rb:2:in `<module:JSONAPI>'
/builds/quap/backend/vendor/ruby/2.4.0/gems/jsonapi-rspec-0.0.2/lib/jsonapi/rspec/id.rb:1:in `<top (required)>'
/builds/quap/backend/vendor/ruby/2.4.0/gems/jsonapi-rspec-0.0.2/lib/jsonapi/rspec.rb:1:in `<top (required)>'
/builds/quap/backend/config/application.rb:17:in `<top (required)>'
/builds/quap/backend/Rakefile:4:in `require_relative'
/builds/quap/backend/Rakefile:4:in `<top (required)>'
/builds/quap/backend/vendor/ruby/2.4.0/gems/railties-5.1.4/lib/rails/commands/rake/rake_command.rb:20:in `block in perform'
/builds/quap/backend/vendor/ruby/2.4.0/gems/railties-5.1.4/lib/rails/commands/rake/rake_command.rb:18:in `perform'
/builds/quap/backend/vendor/ruby/2.4.0/gems/railties-5.1.4/lib/rails/command.rb:46:in `invoke'
/builds/quap/backend/vendor/ruby/2.4.0/gems/railties-5.1.4/lib/rails/commands.rb:16:in `<top (required)>'
bin/rails:9:in `require'
bin/rails:9:in `<main>'

Caused by:
LoadError: cannot load such file -- jsonapi-rspec
/builds/quap/backend/config/application.rb:17:in `<top (required)>'
/builds/quap/backend/Rakefile:4:in `require_relative'
/builds/quap/backend/Rakefile:4:in `<top (required)>'
/builds/quap/backend/vendor/ruby/2.4.0/gems/railties-5.1.4/lib/rails/commands/rake/rake_command.rb:20:in `block in perform'
/builds/quap/backend/vendor/ruby/2.4.0/gems/railties-5.1.4/lib/rails/commands/rake/rake_command.rb:18:in `perform'
/builds/quap/backend/vendor/ruby/2.4.0/gems/railties-5.1.4/lib/rails/command.rb:46:in `invoke'
/builds/quap/backend/vendor/ruby/2.4.0/gems/railties-5.1.4/lib/rails/commands.rb:16:in `<top (required)>'
bin/rails:9:in `require'
bin/rails:9:in `<main>'
(See full trace by running task with --trace)
ERROR: Job failed: exit code 1
stephanebruckert commented 6 years ago

Add

config.include JSONAPI::RSpec

to your spec_helper.rb, not application.rb

richipargo commented 6 years ago

Hi i've never placed it on application.rb only on my spec_helper.rb

application.rb

require_relative 'boot'

require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "action_cable/engine"
# require "sprockets/railtie"
# require "rails/test_unit/railtie"

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)

module Backend
  class Application < Rails::Application
    # Initialize configuration defaults for originally generated Rails version.
    config.load_defaults 5.1

    # Settings in config/environments/* take precedence over those specified here.
    # Application configuration should go into files in config/initializers
    # -- all .rb files in that directory are automatically loaded.

    # Only loads a smaller set of middleware suitable for API only apps.
    # Middleware like session, flash, cookies can be added back manually.
    # Skip views, helpers and assets when generating a new resource.
    config.api_only = true

    config.time_zone = 'America/Mexico_City'
  end
end

Spec helper Rspec config

RSpec.configure do |config|
  config.include Warden::Test::Helpers
  config.include Devise::Test::ControllerHelpers, type: :controller
  config.include FactoryBot::Syntax::Methods
  config.include Parser
  config.include JSONAPI::RSpec

  config.fixture_path = "#{::Rails.root}/spec/fixtures"

  config.use_transactional_fixtures = true

  config.infer_spec_type_from_file_location!

  config.filter_rails_from_backtrace!
end
somenugget commented 6 years ago

Got the same issue trying rails db:migrate RAILS_ENV=test :-( I could run migrations only after I commented line with gem 'jsonapi-rspec' in my Gemfile

dannysperry commented 6 years ago

I'm getting similar issues. The error goes away if I addgem 'jsonapi-rspec', require: false to Gemfile and require 'jsonapi/rspec' to rails_helper.rb or spec_helper.rb.

We could add lib/jsonapi-rspec.rb which would require 'jsonapi/rspec'

happycollision commented 6 years ago

Same deal here. I was getting

/Users/Don/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bootsnap-1.1.7/lib/bootsnap/load_path_cache/core_ext/active_support.rb:53:in `block in load_missing_constant': uninitialized constant RSpec::Matchers (NameError)

Then I used gem 'jsonapi-rspec', require: false in my Gemfile, and added require 'jsonapi/rspec' to spec_helper.rb. Now it all works fine.

stas commented 6 years ago

This is fixed in #8 now.

zwolf commented 4 years ago

Just ran into this today using @stas's jsonapi gem, which has this as a dependancy. I was using a few of the matchers in my own specs, as well. Dockerizing the app required the above addition to the Gemfile to run specs correctly. Looks like there's a fix in, but it's been a while since anything's merged on this repo.

stas commented 4 years ago

Closed as part of #8