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

当前回答

您还可以使用*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'

这里不需要耙子。

其他回答

原始调用:

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

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

或者你可以跳过rake,使用'rspec'命令:

bundle exec rspec path/to/spec/file.rb

在你的情况下,我认为只要你的。/spec/db_spec。Rb文件包括适当的帮助,它应该工作良好。

如果你正在使用rspec的旧版本,它是:

bundle exec spec path/to/spec/file.rb

虽然这个问题有很多很好的答案,但没有一个使用Rspec标记方法。

我使用标记在不同的文件中运行一个或多个规范——只运行与当前开发任务相关的规范。

例如,我添加了标签“dev”,值为“current”:

it "creates an user", dev: :current do
  user = create(:user)
  expect(user.persisted?).to be_truthy
end

然后我就跑

bundle exec rspec . --tag dev:current

可以在单个规格或组中设置不同的标签/值。

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

rspec spec/models/model_spec.rb:47