我一直在努力寻找如何在我的Ruby脚本中使用slack-ruby-client
gem的方法,但显然在json方面遇到问题。
这就是我要得到的:
[user:ubuntu:~/Documents]$ irb 4:43PM/07.08
2.5.1 :001 > require 'slack-ruby-client'
Traceback (most recent call last):
11: from /home/user/.rvm/rubies/ruby-2.5.1/bin/irb:11:in `<main>'
10: from (irb):1
9: from /home/user/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:39:in `require'
8: from /home/user/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:135:in `rescue in require'
7: from /home/user/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:135:in `require'
6: from /home/user/.rvm/gems/ruby-2.5.1/gems/slack-ruby-client-0.11.1/lib/slack-ruby-client.rb:13:in `<top (required)>'
5: from /home/user/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:90:in `require'
4: from /home/user/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:90:in `each'
3: from /home/user/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:91:in `block in require'
2: from /home/user/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/specification.rb:1434:in `activate'
1: from /home/user/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/specification.rb:2315:in `check_version_conflict'
Gem::LoadError (can't activate json-1.8.6, already activated json-2.1.0)
2.5.1 :002 > exit
无论出于何种原因,我都无法卸载json v2.1.0。尽管它说它在运行gem uninstall json v2.1.0
时已成功卸载,但是当我查看gem列表并搜索json时,它仍然显示。
[user:ubuntu:~/Documents]$ gem uninstall json -v 2.1.0 4:45PM/07.08
Successfully uninstalled json-2.1.0
[user:ubuntu:~/Documents]$ gem list | grep -i json 4:47PM/07.08
json (default: 2.1.0, 1.8.6)
multi_json (1.13.1, 1.11.2)
,然后错误仍然存在。我尝试手动安装1.8.6,以查看它是否会覆盖默认值,但什么也没做。
任何建议将不胜感激。
尝试#1
[user:~/Documents]$ gem uninstall json 2:52PM/07.09
You have requested to uninstall the gem:
json-1.8.6
activesupport-4.2.4 depends on json (>= 1.7.7, ~> 1.7)
activesupport-4.2.3 depends on json (>= 1.7.7, ~> 1.7)
rdoc-4.2.0 depends on json (~> 1.4)
sdoc-0.4.2 depends on json (>= 1.7.7, ~> 1.7)
sdoc-0.4.1 depends on json (>= 1.7.7, ~> 1.7)
If you remove this gem, these dependencies will not be met.
Continue with Uninstall? [yN] y
Successfully uninstalled json-1.8.6
[user:ubuntu:~/Documents/rubyscript]$ bundle install 2:56PM/07.09
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...
Using bundler 1.16.2
Fetching json 1.8.6
Installing json 1.8.6 with native extensions
Bundle complete! 1 Gemfile dependency, 2 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
[user:ubuntu:~/Documents/rubyscript]$ irb 2:56PM/07.09
2.5.1 :001 > require 'slack-ruby-client'
Traceback (most recent call last):
11: from /home/user/.rvm/rubies/ruby-2.5.1/bin/irb:11:in `<main>'
10: from (irb):1
9: from /home/user/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:39:in `require'
8: from /home/user/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:135:in `rescue in require'
7: from /home/user/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:135:in `require'
6: from /home/user/.rvm/gems/ruby-2.5.1/gems/slack-ruby-client-0.11.1/lib/slack-ruby-client.rb:13:in `<top (required)>'
5: from /home/user/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:90:in `require'
4: from /home/user/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:90:in `each'
3: from /home/user/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:91:in `block in require'
2: from /home/user/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/specification.rb:1434:in `activate'
1: from /home/user/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/specification.rb:2315:in `check_version_conflict'
Gem::LoadError (can't activate json-1.8.6, already activated json-2.1.0)
2.5.1 :002 > exit
[user:ubuntu:~/Documents/rubyscript]$ cat Gemfile 2:56PM/07.09
source 'https://rubygems.org'
gem 'json', '=1.8.6'
答案 0 :(得分:0)
首先,尝试完全卸载所有版本的gem:
gem uninstall json
然后安装所需的特定版本,并确保您的Gemfile为gem指定了特定版本:
gem 'json', '=1.8.6'
这应该可以解决问题
答案 1 :(得分:0)
bundle exec rspec
为我解决了...就我而言,我试图在docker容器中运行rspec。 Ruby 2.6
答案 2 :(得分:-1)
请尝试
bundle exec rspec
或
bundle exec rake spec
希望这会有所帮助!