Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you use gems, when you execute a Ruby script in embedded JRuby?

It so happened that I need to unit-test this Ruby script. It's a Sinatra-based web application that uses several gems.

I have more experience in Java than in Ruby, time is very important (and elegance isn't), and so I thought I may be faster, if I execute that script in a JUnit class and mock all subsystems it depends on (web server, database). That way I could use my Java skills to test a Ruby system. It looks like you can embed Ruby in a Java program.

Question: Can I use gems in embedded Ruby, i. e. create a Java program that could execute the tests on any machine (Windows, Linux, Mac) and wouldn't require that I install several gems on it manually? If yes, how?

Note: They need to be real gems, mocks are fine.

Update 1 (25.01.2017 13:14): One obvious solution is to extract the logic of that script into a separate Ruby file without dependencies. That probably would be 80 % of the code. Then I could test that logic file even without having the gems.

like image 506
Dmitrii Pisarenko Avatar asked Jan 25 '17 09:01

Dmitrii Pisarenko


1 Answers

I am assuming you are using JRuby. Check this and this out. With this maybe you can do the opposite and use Junit from within Jruby itself.

like image 179
Zach Tuttle Avatar answered Sep 30 '22 04:09

Zach Tuttle