Search code examples
rubyconfigurationrequirerubymine

Ruby gem configuration for RubyMine and command line


I'm working on my 'gravaty gem (https://rubygems.org/gems/gravaty) and I have some configuration issues working on command line and RubyMine IDE at the same time.

I'm using JetBrains' RubyMine IDE and sometimes also command like through my Rakefile. If, from project main dir, I wrote rake test via command line, all tests work properly (they run and provide results, one test is not passing but that's another story...) while, if I run them from the IDE (with a Run/Debug configuration) I have this message:

1. B:/Programmi/gravaty/test/gravaty/locales/test_locales.rb:1
Fail to load: B:/Programmi/gravaty/test/gravaty/parsers/test_avatar.rb:1
      Exception message: cannot load such file -- gravaty/test_parsable_duck_type
["B:/Programmi/gravaty/test/test_helper.rb:34:in `require'", "B:/Programmi/gravaty/test/test_helper.rb:34:in `<top (required)>'", "B:/Programmi/gravaty/test/gravaty/parsers/test_avatar.rb:15:in `require_relative'", "B:/Programmi/gravaty/test/gravaty/parsers/test_avatar.rb:15:in `<top (required)>'", "C:/Program Files (x86)/JetBrains/RubyMine 6.0.3/rb/testing/runner/tunit_or_minitest_in_folder_runner.rb:51:in `require'", "C:/Program Files (x86)/JetBrains/RubyMine 6.0.3/rb/testing/runner/tunit_or_minitest_in_folder_runner.rb:51:in `block in require_all_test_scripts'", "C:/Program Files (x86)/JetBrains/RubyMine 6.0.3/rb/testing/runner/tunit_or_minitest_in_folder_runner.rb:44:in `each'", "C:/Program Files (x86)/JetBrains/RubyMine 6.0.3/rb/testing/runner/tunit_or_minitest_in_folder_runner.rb:44:in `require_all_test_scripts'", "C:/Program Files (x86)/JetBrains/RubyMine 6.0.3/rb/testing/runner/tunit_or_minitest_in_folder_runner.rb:138:in `<top (required)>'", "-e:1:in `load'", "-e:1:in `<main>'"]

and so on (one for each test file) with all its stacktrace.

In order to easily configure the correct (?) require environment, I put the statements

lib_dir = File.dirname(__FILE__) '/../lib'
$:.unshift lib_dir unless $:.include?(lib_dir)

at the beginning of my test_helper.rb file and it seems working from the command line, but the IDE does not appreciate. Considering this statements in the test_helper.rb,

require 'minitest/autorun'
require 'minitest/spec'

lib_dir = File.dirname(__FILE__) + '/../lib'
$:.unshift lib_dir unless $:.include?(lib_dir)

require 'gravaty'
require 'gravaty/constants'
require 'gravaty/parsers/avatar'
require 'gravaty/parsers/callback'
require 'gravaty/parsers/default'
require 'gravaty/parsers/force'
require 'gravaty/parsers/format'
require 'gravaty/parsers/pixelsize'
require 'gravaty/parsers/rating'
require 'gravaty/parsers/secure'
require 'gravaty/parsers/type'
require 'gravaty/test_parsable_duck_type'

the IDE underlines all the require 'gravaty/ statements saying Unresolved Ruby reference. I've added my lib directory to the Load Path preference of the IDE, but nothing changes.

Is there a way to make it work in both environments? Should I "carve" the full require path in each file and in each require statement?


Solution

  • I've found the solution: instead of using the Test::Unit/Shoulda/Minitest Run/Debug configuration, I can just run the tests through a simple Rake task Run/Debug configuration. The working configuration: on the leftthe "Rake" Run/Debug configuration