The right way to test gems

If a gemstone has dependencies on rails, do you think that it is better to write tests of gemstones so that they can work autonomously or run them under the rails project?

+7
ruby ruby-on-rails rubygems gem
source share
2 answers

A gem must be part of a code that acts autonomously. Otherwise, it is part of the application, so tests should also be autonomously created. Thus, others (hypothetically) may also perform tests. If the tests depend on your application, others cannot test your gem.

In addition, if you want to test your stone, it should not fail, because your application fails. After your gem has passed the test, you can check the application, knowing that your gem is working well (provided that you have tested everything).

Whether this stone is Rails dependent or not is not a problem since Rails has also been tested (and you can assume that it works correctly). Thus, these dependencies do not (/ should) affect your gem.

+6
source share

I would say that it depends on the type of dependencies the gem needs. For example. if it's just ActiveRecord, it's pretty easy to include it in your test suite. In more complex cases, you can always make fun of some of the necessary functions. In really complex cases, creating a test application is better than nothing (IMO).

0
source share

All Articles