guard / guard-rspec

Guard::RSpec automatically run your specs (much like autotest)
https://rubygems.org/gems/guard-rspec
MIT License
1.31k stars 241 forks source link

JSON already initialized #395

Open cmer opened 7 years ago

cmer commented 7 years ago

Whenever I run my specs in Guard, I get a bunch of "constant already initialized" errors for json. When I run my specs directly in the terminal, I don't get this. Any idea what could be going on? I like at the Guard and Guard-Rspec code but I couldn't find anything obvious.

Thanks

0:31:43 - INFO - Run all
20:31:43 - INFO - Bundle already up-to-date
20:31:43 - INFO - Running all specs
/Users/cmer/.rbenv/versions/2.4.0/lib/ruby/2.4.0/json/version.rb:4: warning: already initialized constant JSON::VERSION
/Users/cmer/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/json-2.0.3/lib/json/version.rb:4: warning: previous definition of VERSION was here
/Users/cmer/.rbenv/versions/2.4.0/lib/ruby/2.4.0/json/version.rb:5: warning: already initialized constant JSON::VERSION_ARRAY
/Users/cmer/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/json-2.0.3/lib/json/version.rb:5: warning: previous definition of VERSION_ARRAY was here
/Users/cmer/.rbenv/versions/2.4.0/lib/ruby/2.4.0/json/version.rb:6: warning: already initialized constant JSON::VERSION_MAJOR
/Users/cmer/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/json-2.0.3/lib/json/version.rb:6: warning: previous definition of VERSION_MAJOR was here
/Users/cmer/.rbenv/versions/2.4.0/lib/ruby/2.4.0/json/version.rb:7: warning: already initialized constant JSON::VERSION_MINOR
/Users/cmer/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/json-2.0.3/lib/json/version.rb:7: warning: previous definition of VERSION_MINOR was here
/Users/cmer/.rbenv/versions/2.4.0/lib/ruby/2.4.0/json/version.rb:8: warning: already initialized constant JSON::VERSION_BUILD
/Users/cmer/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/json-2.0.3/lib/json/version.rb:8: warning: previous definition of VERSION_BUILD was here
/Users/cmer/.rbenv/versions/2.4.0/lib/ruby/2.4.0/json/common.rb:100: warning: already initialized constant JSON::NaN
/Users/cmer/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/json-2.0.3/lib/json/common.rb:100: warning: previous definition of NaN was here
/Users/cmer/.rbenv/versions/2.4.0/lib/ruby/2.4.0/json/common.rb:102: warning: already initialized constant JSON::Infinity
/Users/cmer/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/json-2.0.3/lib/json/common.rb:102: warning: previous definition of Infinity was here
/Users/cmer/.rbenv/versions/2.4.0/lib/ruby/2.4.0/json/common.rb:104: warning: already initialized constant JSON::MinusInfinity
/Users/cmer/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/json-2.0.3/lib/json/common.rb:104: warning: previous definition of MinusInfinity was here
/Users/cmer/.rbenv/versions/2.4.0/lib/ruby/2.4.0/json/common.rb:129: warning: already initialized constant JSON::UnparserError
/Users/cmer/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/json-2.0.3/lib/json/common.rb:129: warning: previous definition of UnparserError was here
cmer commented 7 years ago

I found a workaround to this problem if anybody ever runs into the same issue.

I simply added gem 'json' to my Gemfile. I still have no idea what really causes the issue, however.

ky1ejs commented 7 years ago

I found that I had multiple versions of json installed. After I uninstalled them both this stopped happening:

$ gem uninstall json

Select gem to uninstall:
 1. json-1.8.6
 2. json-2.0.3
 3. All versions
> 3
Successfully uninstalled json-1.8.6
Successfully uninstalled json-2.0.3

I'm an iOS dev, quite new to Ruby, so I'm not 100% on why this error is happening. From looking around the web it seems that json was being loaded twice somehow? But I don't really get why removing it completely doesn't cause an error too. ¯_(ツ)_/¯

If I can help debug, let me know :)

AlexWayfer commented 6 years ago

Uninstalling non-bundled versions of json is working work-around, but they're installing again by bundle update (because newer versions of json than bundled are available).

normanrs commented 5 years ago

I've started avoiding ever doing a bundle update because of dependency issues. If you uninstall previous versions as described above, only install one version of the JSON gem, and add it to the Gemfile, the VERSION error goes away.