learn-co-curriculum / playlister-sinatra

Other
0 stars 387 forks source link

Problematic "database_cleaner" gem in the Gemfile #71

Closed Sdcrouse closed 5 years ago

Sdcrouse commented 5 years ago

Hi. First of all, this problem doesn't occur in the in-browser IDE. It only occurs in a local environment (VSCode, in my case).

TL;DR: In the Gemfile, gem 'database_cleaner', git: 'https://github.com/bmabey/database_cleaner.git' should be gem 'database_cleaner'.

Currently, there's a gem in the Gemfile that looks like this: gem 'database_cleaner', git: 'https://github.com/bmabey/database_cleaner.git'

However, when I ran one of the tests (again, from a local environment, not the in-browser IDE), I got this output:

// ♥  learn spec/models/01_artist_spec.rb
D, [2019-08-14T17:53:12.651771 #188] DEBUG -- :    (0.7ms)  SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
        Requiring the `database_cleaner` gem directly is deprecated, and will raise an error in database_cleaner 2.0. Instead, please require the specific gem (or gems) for your ORM.
        For example, replace `gem "database_cleaner"` with `gem "database_cleaner-active_record"` in your Gemfile.

An error occurred while loading ./spec/models/01_artist_spec.rb.
Failure/Error: DatabaseCleaner.strategy = :truncation

NameError:
  uninitialized constant DatabaseCleaner::ActiveRecord
# /usr/local/rvm/gems/ruby-2.6.1/bundler/gems/database_cleaner-dd3d7d8c9a8e/lib/database_cleaner/base.rb:137:in `orm_module'
# /usr/local/rvm/gems/ruby-2.6.1/bundler/gems/database_cleaner-dd3d7d8c9a8e/lib/database_cleaner/base.rb:176:in `rescue in require_orm_strategy'
# /usr/local/rvm/gems/ruby-2.6.1/bundler/gems/database_cleaner-dd3d7d8c9a8e/lib/database_cleaner/base.rb:172:in `require_orm_strategy'
# /usr/local/rvm/gems/ruby-2.6.1/bundler/gems/database_cleaner-dd3d7d8c9a8e/lib/database_cleaner/base.rb:168:in `rescue in orm_strategy'
# /usr/local/rvm/gems/ruby-2.6.1/bundler/gems/database_cleaner-dd3d7d8c9a8e/lib/database_cleaner/base.rb:161:in `orm_strategy'
# /usr/local/rvm/gems/ruby-2.6.1/bundler/gems/database_cleaner-dd3d7d8c9a8e/lib/database_cleaner/base.rb:42:in `create_strategy'
# /usr/local/rvm/gems/ruby-2.6.1/bundler/gems/database_cleaner-dd3d7d8c9a8e/lib/database_cleaner/base.rb:66:in `strategy='
# /usr/local/rvm/gems/ruby-2.6.1/bundler/gems/database_cleaner-dd3d7d8c9a8e/lib/database_cleaner/base.rb:189:in `set_default_orm_strategy'
# /usr/local/rvm/gems/ruby-2.6.1/bundler/gems/database_cleaner-dd3d7d8c9a8e/lib/database_cleaner/base.rb:19:in `initialize'
# /usr/local/rvm/gems/ruby-2.6.1/bundler/gems/database_cleaner-dd3d7d8c9a8e/lib/database_cleaner/configuration.rb:81:in `new'
# /usr/local/rvm/gems/ruby-2.6.1/bundler/gems/database_cleaner-dd3d7d8c9a8e/lib/database_cleaner/configuration.rb:81:in `connections'
# /usr/local/rvm/gems/ruby-2.6.1/bundler/gems/database_cleaner-dd3d7d8c9a8e/lib/database_cleaner/configuration.rb:31:in `strategy='
# ./spec/spec_helper.rb:23:in `block in <top (required)>'
# ./spec/spec_helper.rb:18:in `<top (required)>'
# ./spec/models/01_artist_spec.rb:1:in `require'
# ./spec/models/01_artist_spec.rb:1:in `<top (required)>'
# ------------------
# --- Caused by: ---
# NameError:
#   uninitialized constant DatabaseCleaner::ActiveRecord
#   /usr/local/rvm/gems/ruby-2.6.1/bundler/gems/database_cleaner-dd3d7d8c9a8e/lib/database_cleaner/base.rb:137:in `orm_module'
Run options: include {:focus=>true}

All examples were filtered out; ignoring {:focus=>true}
No examples found.

Finished in 0.0005 seconds (files took 5.12 seconds to load)
0 examples, 0 failures, 1 error occurred outside of examples

The error occurred at this line of code in the spec_helper.rb file: DatabaseCleaner.strategy = :truncation

After some trial and error, I discovered that the previous lab (Sinatra Complex Forms Associations) also had a "database_cleaner" gem. However, that lab worked just fine in my local environment. That's because its Gemfile had this line of code: gem 'database_cleaner'.

I went back to the Sinatra Playlister lab and replaced gem 'database_cleaner', git: 'https://github.com/bmabey/database_cleaner.git' with gem 'database_cleaner'. The tests then worked just fine in my local environment.

I think that's all that needs to be done to fix the issue; there must be something wrong with the repo at https://github.com/bmabey/database_cleaner.git, or else with the way that it's referenced in the Gemfile.

I would really appreciate it if someone looked further into this; it caused me quite the headache for a while.

--- Sdcrouse

drakeltheryuujin commented 5 years ago

Thank you for spotting this issue and providing feedback.

We have updated the materials and believe your issue to have been resolved.

We apologize for any frustration you might have encountered during this process but thank you for helping us ensure that those who follow in your path will not encounter the same problems that you faced.

If you do not believe that this issue has been addressed, please re-open this issue. 💙