【问题标题】:Ruby rake/testtask producing incorrect commandRuby rake/testtask 产生不正确的命令
【发布时间】:2011-11-12 19:41:16
【问题描述】:

我的项目测试被分成多个文件 - test/test_1.rb 和 test/test_2.rb。

运行 'rake test' 给出:

$ rake test
ruby -I"lib:test" -I"/foo/rake-0.9.2/lib" "/foo/rake_test_loader.rb" "test/test_general.rb test/test_cv.rb"
/home/rob/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/rake_test_loader.rb:11:in `require': no such file to load -- /home/rob/src/robsyme/bioruby-chado/test/test_general.rb test/test_cv.rb (LoadError)
... #you can guess the rest

注意 ruby​​ 命令中的最后一个参数:"test/test_general.rb test/test_cv.rb"

如果我删除引号(将最后一个参数分成两个参数),测试会完美运行。

  1. 为什么 rake 的测试运行程序会将这两个文件组合在一起 唯一的论点?
  2. 我在 rake 测试中做错了什么吗 设置?

环境:

$ grep -A4 TestTask Rakefile 
Rake::TestTask.new(:test) do |test|
  test.libs << 'test'
  test.pattern = FileList['test/**/test_*.rb']
  test.verbose = true
end
$ ruby -v
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux]
$ gem --version
1.8.10
$ rake --version
rake, version 0.9.2

【问题讨论】:

  • 你有一个不寻常的外壳吗?还是非标准的 $IFS 变量?
  • test.pattern.inspect 的值也可能有帮助
  • @sunkencity 明白了。我在使用 test.pattern = FileList... 而我应该使用 test.test_files = FileList...

标签: ruby testing rake


【解决方案1】:

添加:

test.test_files = FileList['test/test*.rb']

文件列表应该给测试文件而不是模式。要形成模式,我想你可以将模式作为字符串给出。

上一个答案(被误解的问题)

这就是 shell 的工作原理。如果要定位包含空格的文件名,可以引用文件名。然后它作为一个参数而不是两个参数传递。

$ cat > "foo bar"
foobar
^D
$ cat foo\ bar 
foobar
$ cat "foo bar" 
foobar

$ ls "Rakefile Gemfile"
ls: Rakefile Gemfile: No such file or directory

$ ls Rakefile Gemfile
Gemfile  Rakefile

【讨论】:

  • 你离题了,他似乎知道外壳是如何工作的。他想知道为什么rake test 将文件名分组。
  • 深层问题是为什么 rake 会生成“test/test_general.rb test/test_cv.rb”。这个解释很好。
  • 是的,错过了问题所在。更新为正确答案。如果他想使用模式,它应该是模式而不是文件列表。
猜你喜欢
  • 2014-06-22
  • 2011-11-11
  • 2015-12-14
  • 2018-06-11
  • 1970-01-01
  • 2013-12-07
  • 1970-01-01
  • 2020-11-27
  • 1970-01-01
相关资源
最近更新 更多