Test Recipe: How to Test Ruby Pearls with Rail Dependencies

I am developing a ruby ​​stone that provides some methods that can be mixed with an ActiveRecord model, such as acts_as_taggable, for example.

My question is: how do I write, for example? unit tests for my code without rails app? My model relies, for example, on an existing database / connection that sets up rails. If there is no connection, the test fails.

I also need to copy some files from my gem directory to the rails application, for example RAILS_ROOT, in order to detect the rails directory. Environment variables are also not available.

What will be your approach? Can the rails application somehow "simulate" during test runs?

Thanks in advance for any tips.

+4
source share
1 answer

I had the same question: Rspec, test Gems

In my own answer you will see interesting resources.

I ended up creating a rails application in the test directory of my gem. In the gem file of my application, I referred to my stone in development with its relative path.

In a few words: I test the stone through the application.

Take a look: https://github.com/apneadiving/Google-Maps-for-Rails

I have a dummy Rails application with all the Rspec tests.

+4
source

Source: https://habr.com/ru/post/1345682/


All Articles