如何在调试和测试 gem 时包含目录
有人能给我一条线吗?
具体来说,我在需要文件时在测试实施中遇到问题。
我正在开发一个名为 mme_tools 的 gem,它具有这样的目录树。最初的脚手架是使用jeweler 生成的。
mme_tools
|-- examples
| |-- demo_enumerable.rb
| `-- demo_print_debug.rb
|-- Gemfile
|-- Gemfile.lock
|-- lib
| |-- mme_tools
| | |-- concurrent.rb
| | |-- debug.rb
| | |-- enumerable.rb
| | |-- version.rb
| | `-- webparse.rb
| `-- mme_tools.rb
|-- LICENSE.txt
|-- Rakefile
|-- README.rdoc
`-- test
`-- test_mme_tools.rb
其中,mme_tools.rb 只是一个容器,需要 mme_tools 子目录中的所有文件(即 require 'mme_tools/debug.rb'
)。
在 examples 目录中,我可以随着进度进行一些杂乱的测试(演示)。只需将 require 'mme_tools'
放在每个演示的顶部,然后使用选项 -I../lib
运行 ruby 就可以了。事实上,我使用 Netbeans 进行开发,因此我在每次运行中都包含该选项。
我的问题是在测试时出现的。在 test_mme_tools.rb 的顶部,我有
require 'test/unit'
require 'mme_tools'
,但我的测试不起作用,因为我认为找不到 mme_tools.rb 。我从 shell 运行的 rake 任务的输出是:
$ rake test
rake/rdoctask is deprecated. Use rdoc/task instead (in RDoc 2.4.2+)
/usr/bin/ruby1.8 -I"lib:lib:test" -I"/usr/lib/ruby/gems/1.8/gems/rake-0.9.2/lib" "/usr/lib/ruby/gems/1.8/gems/rake-0.9.2/lib/rake/rake_test_loader.rb" "test/**/test_*.rb"
Loaded suite /usr/lib/ruby/gems/1.8/gems/rake-0.9.2/lib/rake/rake_test_loader
Started
E
Finished in 0.02176 seconds.
1) Error:
test_compose(TC_MMETools):
NoMethodError: undefined method `compose' for MMETools::Enumerable:Module
/mnt/dropbox/DESENVOLUPAMENT/Gems/mme_tools/test/test_mme_tools.rb:19:in `test_compose'
1 tests, 0 assertions, 0 failures, 1 errors
rake aborted!
Command failed with status (1): [/usr/bin/ruby1.8 -I"lib:lib:test" -I"/usr/...]
Tasks: TOP => test
(See full trace by running task with --trace)
当然,来自 Netbeans 的输出是相同的,只是它显示了完整的跟踪
文件 test_mme_tools.rb 如下:
require 'test/unit'
require 'mme_tools'
class TC_MMETools < Test::Unit::TestCase
def setup
@a=(1..12)
@b=("A".."M")
@c=%w{tantmateix adhuc nogensmenys urgell pocassolta carrincló bajanada casundena Massalcoreig}
end
def test_compose
assert_equal [2,"B","adhuc"], MMETools::Enumerable.compose(@a,@b,@c)[1]
end
end
知道吗?
Can anybody throw me a line?
I'm having problems in tests implementation, concretely, while requiring files.
I am developing a gem called mme_tools with a directory tree like this. The initial scaffold was generated using jeweler.
mme_tools
|-- examples
| |-- demo_enumerable.rb
| `-- demo_print_debug.rb
|-- Gemfile
|-- Gemfile.lock
|-- lib
| |-- mme_tools
| | |-- concurrent.rb
| | |-- debug.rb
| | |-- enumerable.rb
| | |-- version.rb
| | `-- webparse.rb
| `-- mme_tools.rb
|-- LICENSE.txt
|-- Rakefile
|-- README.rdoc
`-- test
`-- test_mme_tools.rb
where, mme_tools.rb is simply a container that requires all the files in mme_tools subdir (i.e. require 'mme_tools/debug.rb'
).
In the examples dir I can make some untidy tests (demos) as I progress. Simply putting a require 'mme_tools'
at the top of each of those demos, and running ruby with option -I../lib
works OK. In fact, I use Netbeans to develop so I include that option in every run.
My problem arises while testing. At the top of test_mme_tools.rb I have
require 'test/unit'
require 'mme_tools'
but my tests don't work because I think mme_tools.rb isn't found. The output from the rake task that I run from the shell is:
$ rake test
rake/rdoctask is deprecated. Use rdoc/task instead (in RDoc 2.4.2+)
/usr/bin/ruby1.8 -I"lib:lib:test" -I"/usr/lib/ruby/gems/1.8/gems/rake-0.9.2/lib" "/usr/lib/ruby/gems/1.8/gems/rake-0.9.2/lib/rake/rake_test_loader.rb" "test/**/test_*.rb"
Loaded suite /usr/lib/ruby/gems/1.8/gems/rake-0.9.2/lib/rake/rake_test_loader
Started
E
Finished in 0.02176 seconds.
1) Error:
test_compose(TC_MMETools):
NoMethodError: undefined method `compose' for MMETools::Enumerable:Module
/mnt/dropbox/DESENVOLUPAMENT/Gems/mme_tools/test/test_mme_tools.rb:19:in `test_compose'
1 tests, 0 assertions, 0 failures, 1 errors
rake aborted!
Command failed with status (1): [/usr/bin/ruby1.8 -I"lib:lib:test" -I"/usr/...]
Tasks: TOP => test
(See full trace by running task with --trace)
Of course, from Netbeans occurs the same, exceptuating that it shows the full trace
The file test_mme_tools.rb is as follows:
require 'test/unit'
require 'mme_tools'
class TC_MMETools < Test::Unit::TestCase
def setup
@a=(1..12)
@b=("A".."M")
@c=%w{tantmateix adhuc nogensmenys urgell pocassolta carrincló bajanada casundena Massalcoreig}
end
def test_compose
assert_equal [2,"B","adhuc"], MMETools::Enumerable.compose(@a,@b,@c)[1]
end
end
Any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您继续使用 Rake,并更新为使用 minitest,您可以使用如下所示的 Rakefile:
Assuming you continue with Rake, and update to use minitest, you can use a Rakefile that looks like this: