警惕不要执行水豚测试的规格/功能

问题描述

我的防护文件经过编辑以执行写在规范/功能中的测试用例,因此,如果控制器或模型内部发生任何更改,它将执行所有规范/功能测试:

  watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { "spec/features" } ## any change made in controller it will run all tests under specs/features
  watch(%r{^app/models/(.+)\.rb$}) { "spec/features" } ## any change made in model it will run all tests under specs/features

添加了必需的gemfile

group :development,:test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug',platforms: [:mri,:mingw,:x64_mingw]
  gem 'rspec-rails','~> 3.8.3'
  gem 'faker','~> 2.13.0'
  gem 'rubocop-faker'
  gem 'guard','~> 2.16.2'   ## To automatialy run test cases
  gem 'guard-rspec','~> 4.7.3'
  gem 'guard-cucumber'
  gem 'capybara','~> 3.32.2'
end

我的文件为:

    require 'rails_helper'
    
    RSpec.feature "Create Article" do
      scenario "A user create a new article" do
        visit "/"
        click.link 'New Article'
        fill_in :Title,with: Faker::Book.title
        fill_in :Body,with: Faker::Lorem.paragraph_by_chars(number: 256)
        click_button 'Create Article'
    
        assert page.has_content? "Article was successfully created"
        # expect(:page).to have_content("Article was successfully created")
        # expect(page.current_path).to eq('/articles/*')
        assert page.current_path.match(/articles\/*/)
      end
   end

但是在运行警卫队时,它不会检测到任何书面测试用例并给出以下结果:

17:42:01 - INFO - Running: spec/features
No examples found.
Finished in 0.00035 seconds (files took 0.10616 seconds to load)
0 examples,0 failures

解决方法

功能.rb文件的名称应仅以spec.rb结尾,然后spec将开始使用防护自动执行。

enter image description here