如何检查兼容的Ruby版本的gem [英] How to check the compatible Ruby versions for a gem

查看:126
本文介绍了如何检查兼容的Ruby版本的gem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何确定某个特定的宝石是否与某个特定的Ruby版本兼容?

How do I find out if a particular gem is compatible with a certain Ruby version or not?

我想升级我正在处理的应用程序的Ruby版本,但是我没有看到一种了解特定gem支持哪个Ruby版本的真实方法.

I want to upgrade the Ruby version of an application I am working on, But I did not see an authentic way of knowing which Ruby version is supported by a particular gem.

我找到了gem的*.gemspec,它通常包含一个表示config.required_ruby_version ...的配置,但是我注意到并非所有的gem都包含gemspec文件.我注意到我的系统上有一些gems,例如ActiveRecord,它缺少Gemfile,而在GitHub上,我们有一个gemspec文件可用.

I found the *.gemspec of the gem, which often contains a configuration saying config.required_ruby_version ..., but I noticed not all the gems contain a gemspec file. I noticed I have a few gems on my system, ActiveRecord for example, which lack a Gemfile, whereas on GitHub, we have a gemspec file available.

这是本地计算机上ls -lrth的输出:

This is the output of ls -lrth from my local machine:

Einstiens-MacBook-Pro:activerecord-4.2.7.1 superhero$ ls -lrth
total 128
-rw-r--r--  1 superhero  jingle    51K Dec 23 00:07 CHANGELOG.md
-rw-r--r--  1 superhero  jingle   1.0K Dec 23 00:07 MIT-LICENSE
-rw-r--r--  1 superhero  jingle   6.6K Dec 23 00:07 README.rdoc
drwxr-xr-x  4 superhero  jingle   128B Dec 23 00:07 examples
drwxr-xr-x  5 superhero  jingle   160B Dec 23 00:07 lib

ActiveRecord存储库具有一个gemspec文件:

推荐答案

寻找gemspec文件并检查 RubyGems.org 是检查Ruby兼容性的好方法,但是如上所述,如果gem作者没有编写gemspec文件,这将毫无用处.

Looking for the gemspec file and checking RubyGems.org is a good way to check Ruby compatibility, but as mentioned above, it would be useless if a gem author didn't write a gemspec file.

如果使用RVM或rbenv之类的Ruby版本管理系统,则编写简单的测试脚本将是一个解决方案.如果您的本地计算机上已经安装了Ruby版本2.4.1和2.5.1,请编写类似于"

If you using a Ruby version management system like RVM or rbenv, making a simple testing script would be a solution. If Ruby version 2.4.1 and 2.5.1 have been installed on your local machine, write a script similar to "Testing With Multiple Ruby And Gem Versions" like:

#!/usr/bin/env bash

set -e

rubies=("ruby-2.4.1" "ruby-2.5.3")
for i in "${rubies[@]}"
do
  echo "====================================================="
  echo "$i: Start Test"
  echo "====================================================="
  rvm $i exec bundle
  rvm $i exec bundle exec rake test
  echo "====================================================="
  echo "$i: End Test"
  echo "====================================================="
done

RVM将选择一个Ruby版本,并为所选的Ruby版本运行测试.

RVM will select a Ruby version and run the test for the selected Ruby version.

如果gem没有任何单元测试,则该测试脚本也将毫无用处.但是没有任何单元测试的宝石将不值得使用.

If a gem doesn't have any unit tests, this test script would be useless, too. But a gem that doesn't have any unit test would not be worth using.

尽管这种解决方案也不是检查兼容Ruby版本的可靠方法,但值得您进行测试.

Although, this solution isn't an authentic way of checking for a compatible Ruby version either, it'd be worth using for your testing.

这篇关于如何检查兼容的Ruby版本的gem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆