Rubymine 和单元测试的问题

发布于 2025-01-07 13:26:42 字数 1101 浏览 2 评论 0原文

免责声明:我对 ruby​​ 很陌生,仍在尝试入门,所以这可能是一个非常愚蠢的问题。

我试图让一个非常简单的项目和一个单元测试工作,并且宇宙正在抛出一个 LifeException (我只是无法弄清楚)

在 Mac OS X 10.7.3 上使用 Rubymine 4.0.1。 启动 RubyMine 并创建一个新项目(不是 Rails)“TestExample” 创建了一个新的 Ruby 类,文件是 my_class.rb。

class MyClass
   def say_hi
      puts "Hi!"
   end
end

my = MyClass.new
my.say_hi

创建一个新的 TestUnit 测试模板,文件是“my_test.rb”

require "test/unit"

class MyTest < Test::Unit::TestCase
   def test_create
      #my = MyClass.new
   end
end

此时我有两个问题: 1. 我如何在测试中“要求”我的班级?如果我将上述测试用例更改为:

require "test/unit"
require "my_class"

class MyTest < Test::Unit::TestCase
   def test_create
      #my = MyClass.new
   end
end

并尝试运行“所有测试:TestExample”配置,我会收到“异常消息:无法加载这样的文件 - my_class”。 Tests 文件夹和工作目录指向文件的位置。 (每个文件都位于同一文件夹中)

  1. 另一个是“无法将测试报告器附加到测试框架”。

我用谷歌搜索并试图弄清楚这一点但无济于事。我意识到这是两个问题合而为一,如果我能让测试正常工作,我会很高兴。

感谢您的任何意见,不要嘲笑我的超级红宝石菜鸟。

[更新] - 仅当使用 RVM:ruby-1-9.3-p125 SDK 时才会发生这种情况。如果我使用 ruby​​-1.8.7-p249(/usr/bin/ruby),它确实有效。这一定是一些配置问题。

DISCLAIMER: I am very new to ruby, still trying to get my feet wet, so this could be hugely stupid issue.

I'm trying to get a very simple project and one unit test working, and the Universe is throwing a LifeException (I just can't figure this out)

Using Rubymine 4.0.1 on Mac OS X, 10.7.3.
Launched RubyMine and created a new project (not Rails) "TestExample"
Created a new Ruby Class, file is my_class.rb.

class MyClass
   def say_hi
      puts "Hi!"
   end
end

my = MyClass.new
my.say_hi

Create a new TestUnit Test Template, file is "my_test.rb"

require "test/unit"

class MyTest < Test::Unit::TestCase
   def test_create
      #my = MyClass.new
   end
end

At this point I have two issues:
1. How do I 'require' my class in my tests? If I change the above test case to:

require "test/unit"
require "my_class"

class MyTest < Test::Unit::TestCase
   def test_create
      #my = MyClass.new
   end
end

and attempt to run my "All tests in: TestExample" configuration, I get a "Exception message: cannot load such a file -- my_class". The Tests folder and working directory are pointed to the location of the files. (every file is in the same folder)

  1. The other is a "Unable to attach test reporter to test framework".

I've googled and attempted to figure this out to no avail. I realize this is two questions in one, and if I could just get tests working, I'd be happy.

Thanks for any input and don't laugh to hard at my uber-ruby-noobness.

[Update] - This only happens when using the RVM: ruby-1-9.3-p125 SDK. If I use the ruby-1.8.7-p249(/usr/bin/ruby), it does work. This has to be some configuration issue.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沫离伤花 2025-01-14 13:26:42

对于第一个问题,尝试:

require_relative 'my_class'

我无法回答第二个问题。

For the first question, try:

require_relative 'my_class'

I can't answer the second.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文