我希望能够运行单个规范文件的测试—例如,对于我正在编辑的一个文件。Rake spec执行所有的规范。我的项目不是Rails项目,所以rake spec:doc不起作用。

不知道这是否重要,但这是我的目录结构。

./Rakefile
./lib
./lib/cushion.rb
./lib/cushion
./lib/cushion/doc.rb
./lib/cushion/db.rb
./spec
./spec/spec.opts
./spec/spec_helper.rb
./spec/db_spec.rb

当前回答

从帮助(spec -h):

-l, --line LINE_NUMBER           Execute example group or example at given line.
                                 (does not work for dynamically generated examples)

示例:spec spec/runner_spec。Rb -l 162

其他回答

如果您将rspec作为插件而不是gem安装,那么您将无法获得规范可执行文件。

无论如何,您所需要做的就是使用ruby运行该文件。rspec代码足够聪明,可以为您运行测试。

eg:

ruby myclass_spec.rb

原始调用:

rake spec SPEC=spec/controllers/sessions_controller_spec.rb \
          SPEC_OPTS="-e \"should log in with cookie\""

现在弄清楚如何将其嵌入到编辑器中。

您还可以使用*e*示例测试用例的实际文本-e !

所以对于:

it "shows the plane arrival time"

你可以使用

rspec path/to/spec/file.rb -e 'shows the plane arrival time'
./scripts/spec path/to/spec/file.rb -e 'shows the plane arrival time'

这里不需要耙子。

或者,看看autotest。

在命令窗口中运行autotest意味着在保存规范文件时将执行它。而且,只要您指定的文件运行,它就会运行。

例如,如果您有一个名为person_spec的模型规范文件。Rb,和一个模型文件,它被指定为person。Rb,那么当您从编辑器中保存这些文件时,规范文件将被执行。

http://github.com/grosser/single_test让你做的事情…

rake spec:user          #run spec/model/user_spec.rb (searches for user*_spec.rb)
rake test:users_c       #run test/functional/users_controller_test.rb
rake spec:user:token    #run the first spec in user_spec.rb that matches /token/
rake test:user:token    #run all tests in user_test.rb that match /token/
rake test:last
rake spec:last