如何运行单个 RSpec 测试?
我有以下文件:
/spec/controllers/groups_controller_spec.rb
我在终端中使用什么命令来运行该规范以及在哪个目录中运行该命令?
我的宝石文件:
# Test ENVIRONMENT GEMS
group :development, :test do
gem "autotest"
gem "rspec-rails", "~> 2.4"
gem "cucumber-rails", ">=0.3.2"
gem "webrat", ">=0.7.2"
gem 'factory_girl_rails'
gem 'email_spec'
end
规格文件:
require 'spec_helper'
describe GroupsController do
include Devise::TestHelpers
describe "GET yourgroups" do
it "should be successful and return 3 items" do
Rails.logger.info 'HAIL MARRY'
get :yourgroups, :format => :json
response.should be_success
body = JSON.parse(response.body)
body.should have(3).items # @user1 has 3 permissions to 3 groups
end
end
end
-
不知道这已经可用了多长时间,但是有一个用于运行过滤的 Rspec 配置 - 所以现在您可以将其添加到您的
spec_helper.rb
:RSpec.configure do |config| config.filter_run_when_matching :focus end
然后将焦点标记添加到
it
,context
或describe
仅运行该块:it 'runs a test', :focus do ...test code end
RSpec 文档:
https://www.rubydoc.info/github/rspec/rspec-
core/RSpec/Core/Configuration#filter_run_when_matching-
instance_method
-
如何在 RSpec 中运行单个测试/规范文件?
2022-05-26 关注 0 浏览9 1答案
-
如何使用 Jest 运行单个测试?
2022-03-22 关注 0 浏览60 1答案
-
rspec:如何测试redis#subscribe代码?
2021-02-01 关注 0 浏览191 1答案
-
如何使用 phpunit 运行单个测试方法?
2022-03-22 关注 0 浏览44 1答案
-
如何在Capybara和RSpec中测试CSV文件下载?
2021-02-01 关注 0 浏览44 1答案
-
运行单个测试文件
2022-07-28 关注 0 浏览13 1答案
-
使用 maven 运行单个测试方法
2022-03-22 关注 0 浏览52 1答案
-
在Maven中运行单个测试->未执行任何测试!
2021-02-01 关注 0 浏览69 1答案
-
使用量角器时如何运行单个特定的测试用例
2021-02-01 关注 0 浏览80 1答案
-
只是运行单个测试而不是整个套件?
2021-02-01 关注 0 浏览81 1答案