我的保护文件被编辑以执行在规范/功能中编写的测试用例,因此如果控制器或模型内部有任何更改,它将执行所有规范/功能测试:
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
添加了所需的gemfiles
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