RubyMine和命令行的Ruby gem配置

时间:2014-03-18 09:03:24

标签: ruby configuration require rubymine

我正在处理我的' gravaty gem(https://rubygems.org/gems/gravaty),我在命令行和RubyMine IDE上同时遇到了一些配置问题。

我正在使用JetBrains' RubyMine IDE,有时也可以通过我的Rakefile命令。如果,从项目主目录,我通过命令行编写rake test,所有测试都正常工作(他们运行并提供结果,一个测试没有通过,但那是另一个故事......),如果我从IDE运行它们(使用运行/调试配置)我有这样的消息:

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>'"]

等等(每个测试文件一个)及其所有堆栈跟踪。

为了轻松配置正确的(?)require环境,我将语句

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

在我的test_helper.rb文件的开头,它似乎从命令行工作,但IDE不欣赏。考虑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'

IDE强调所有require 'gravaty/语句Unresolved Ruby reference。我已将lib目录添加到IDE的“加载路径”首选项中,但没有任何更改。

有没有办法让它在两种环境中都能正常工作?我应该&#34;雕刻&#34;每个文件和每个require语句中的完整require路径?

1 个答案:

答案 0 :(得分:0)

我找到了解决方案:我可以通过简单的Rake任务运行/调试配置来运行测试,而不是使用Test :: Unit / Shoulda / Minitest Run / Debug配置。 The working configuration: on the leftthe "Rake" Run/Debug configuration