我希望能够运行单个规范文件的测试—例如,对于我正在编辑的一个文件。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

当前回答

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

其他回答

您可以在测试文件中运行特定的行

rspec spec/models/model_spec.rb:47

假设,您正在运行创建todo的测试。您总是可以使用文件crete_spec运行特定的todo规范代码。Rb文件如下。

      rspec/spec/features/controller/spec_file_name.rb

   Example:

   Creating  rspec spec/features/todos/create_spec.rb
   Editing   rspec spec/features/todos/edit_spec.rb
   Deleting  rspec spec/features/todos/destroy_spec.rb

如果你想在一个简短的。

   rspec 

如果你想在一个特定的控制器用户运行所有的规格。

  rspec/spec/feaures/controller_name

  Example:   rspec/spec/features/todos

希望它能给你更多的理解!

我有麻烦得到这些例子中的任何一个工作,也许是因为帖子是旧的,命令已经改变了?

经过一番调查,我发现这是可行的:

rspec spec/models/user_spec.rb

这将只运行单个文件,并在终端中提供有用的输出。

Ruby 1.9.2和Rails 3有一个简单的方法来运行一个规范文件:

  ruby -I spec spec/models/user_spec.rb

解释:

Ruby命令往往比rake命令快 -I spec的意思是“在查找文件时包含'spec'目录” 规范/模型/ user_spec。Rb是我们要运行的文件。