正确的测试宝石的方法 [英] Proper way of testing gems

查看:130
本文介绍了正确的测试宝石的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果一个gem具有轨道依赖性,你认为最好是将gem测试编写成独立运行的方式,或者在rails项目下运行它们?

If a gem has rails dependencies, do you think it is better to write the gem tests in a way they can be run standalone or run them under a rails project?

推荐答案

宝石应该是一段独立运作的代码。否则它是应用程序的一部分,所以测试也应该独立创建。通过这种方式,其他人(假设)也可以执行测试。如果测试依赖于您的应用程序,其他人无法测试您的宝石。

A gem should be a piece of code which acts stand-alone. Otherwise it is part of the application, so the tests should be created stand-alone as well. In this way others (hypothetically) can perform the tests as well. If the tests depend on your application others cannot test your gem.

此外,当您想测试您的宝石时,它不应该失败,因为您的应用程序失败。在您的宝石通过测试后,您可以测试应用程序,知道您的宝石功能正常(假设您测试了所有内容)。

Furthermore when you want to test your gem it should not fail because your application is failing. After your gem passed the test, you can test the application knowing that your gem is functioning well (assuming that you tested everything).

宝石是否取决于Rails或不是不是问题,因为Rails也经过了测试(并且您可以认为它正常工作)。所以这些依赖不会(/应该)影响你的宝石。

Whether the gem is depending on Rails or not is not an issue, since Rails also has been tested (and you can assume it is working properly). So these dependencies do not (/should) influence your gem.

这篇关于正确的测试宝石的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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