用于确保 gem 与 Rails 3.x 和 4.0 一起工作的 gem 测试策略? [英] Strategies for gem tests to ensure the gem works with Rails 3.x and 4.0?

查看:15
本文介绍了用于确保 gem 与 Rails 3.x 和 4.0 一起工作的 gem 测试策略?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我见过一些虚拟 Rails 应用程序的示例(用于测试,因此它们通常处于测试或规范目录中)与 Appraisals gem 一起使用,这些应用程序据说可以与 Rails 3.x 和 Rails 4 一起使用,但它们看起来很黑而且功能不全.这有点在意料之中,因为它是一个精简版的科学怪人,正试图与 Rails 3 和 Rails 4 的各种版本兼容.

I've seen a few examples of dummy Rails apps (for testing, so they live under test or spec dirs, typically) for use with the Appraisals gem that supposedly work with both Rails 3.x and Rails 4, but they seem hackish and not fully functional. It is somewhat expected, as it is a stripped down Frankenstein monster that is trying to be compatible with various versions of Rails 3 as well as Rails 4.

我提到过尝试进行此类测试的项目(截至 2013 年 3 月下旬),例如 less-rails 和 ember-rails,但是这种使用各种版本的 Rails 进行测试的方式似乎不太干净,尝试调试非标准 Rails 应用程序并非易事,尤其是在测试版的 Rails 中.

I've referred to projects that attempt to do this sort of testing (as of late March 2013) like less-rails and ember-rails, but this way to test with various version of Rails doesn't seem very clean, and it is non-trivial to try to debug a non-standard Rails application, especially in a beta version of Rails.

如果有一种更简洁的测试方式,让您可以为每个版本的 Rails 使用完整的 Rails 应用程序进行测试,那将是很棒的,通过一些魔法来测试它并不难设置或维护,并且不需要非-地方等的标准路径黑客

It would be great to have a cleaner way to test that allows you to have a full Rails application for each version of Rails to test with that through some magic is not that difficult to setup or maintain and don't require non-standard path hacks in places, etc.

使用不同版本的 Rails(至少包括最新的 Rails 3.1.x、3.2.x 和 4.0.0.beta1)测试 gems 的可用策略有哪些,每种策略的优缺点是什么?

What are the available strategies for testing gems with various versions of Rails (including at least latest Rails 3.1.x, 3.2.x, and 4.0.0.beta1), and what are the pros and cons of each?

推荐答案

相关线程:

Ken Collins 提到使用评估和 Rails虚拟"应用程序:

Ken Collins mentioned using appraisal and a Rails "dummy" app:

我使用混合测试了 minitest-spec-rails 对 3.0、3.1、3,2 和 4.0评估和 dummy_app 的最低配置取决于它正在测试哪个 Rails 版本.一些链接:

I test minitest-spec-rails against 3.0, 3.1, 3,2 and 4.0 using a mix of appraisal and dummy_app that minimally configures itself depending which rails version it is testing against. Some links:

https://github.com/metaskills/minitest-spec-railshttps://github.com/metaskills/minitest-spec-rails/blob/master/test/dummy_app/init.rb

less-railsember-railshigh_voltage 等.

我使用了与 high_voltage 类似的设置/rubyservices/restful_json" rel="nofollow">restful_json (v3.3.0) 但使用 4.0.0-beta1 创建的完整 Rails 应用程序,我对其进行了最小程度的修改以也适用于 Rails 3.1.x/3.2.x.

I used a similar setup to high_voltage in restful_json (v3.3.0) but with a full Rails app created with 4.0.0-beta1 that I modified minimally to also work with Rails 3.1.x/3.2.x.

更新:可能希望查看permitters以获取更多最新示例.

Update: May want to see permitters for more recent example.

优点:相当简单.可以通过命令行等方式针对各种 Rails 版本进行测试.可以是非常小的 Rails 应用配置,也可以使用具有细微差别的完整 Rails 应用.

Pros: Fairly simple. Can test against various Rails versions from command-line, etc. Can be very minimal Rails app configuration, or can use full Rails app with minor differences.

缺点:仍然为多个 Rails 版本重用相同的 Rails 应用程序,因此需要一些条件和不需要的配置.(某些文件可能存在不适用于其他版本的 Rails 等问题,但似乎不是大问题.)

Cons: Still reusing same Rails app for multiple Rails versions, so some conditionals and unneeded config. (Possible issues with some files not being applicable in another version of Rails, etc. but does not appear to be a big problem.)

Steve Klabnik 提到了一个解决方案,它适用于单个 Gemfile,一个完整的 Rails 应用程序(即使在虚拟"目录下,并且没有使用评估 gem,依靠 travis-ci 进行测试:

Steve Klabnik mentioned a solution that works with a single Gemfile, a single full Rails app (even though under "dummy" dir, and no use of the appraisal gem, by relying on travis-ci to test:

我一直想更多地讨论这个话题,因为我一直在这样做为了我最近的一堆宝石.我有两个这样做:

I've been meaning to discuss this topic more, as I've been doing it for a bunch of my gems lately. I have two that do this:

Draper:https://github.com/drapergem/draper

LocaleSetter:https://github.com/jcasimir/locale_setter/

LocaleSetter: https://github.com/jcasimir/locale_setter/

基本上,我将整个 Rails 应用程序嵌入到 gem 中,然后通过环境变量在 travis 上针对多个版本的 Rails 运行它.

Basically, I embed an entire Rails application into the gem, and then run it against multiple versions of Rails on travis via env vars.

优点:简单.不依赖评估 gem(不是说它有问题,但可能更容易维护).

Pros: Simple. No dependency on appraisal gem (not that it is a problem, but may be easier to maintain).

缺点:据我所知,仍然为多个 Rails 版本重用相同的 Rails 应用程序.除非使用 travis-ci 或以干净的 gemset 开头的东西(即,如果在命令行中运行),否则当前不区分 gemset,因此较新的 gem 可能会与较旧的 Rails 等一起使用,但 Steve 说这是否会导致问题,你可以直接吹掉锁然后重新捆绑.

Cons: Still reusing same Rails app for multiple Rails versions from what I can tell. Unless using travis-ci or something that starts with a clean gemset (i.e. if running at command-line), not currently differentiating gemsets so newer gem may be used with older Rails, etc., but Steve said if that were to cause a problem, you could just blow away the lock and re-bundle.

这篇关于用于确保 gem 与 Rails 3.x 和 4.0 一起工作的 gem 测试策略?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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