如何运行单个RSpec测试?
如何运行单个RSpec测试?
我有以下文件:
/spec/controllers/groups_controller_spec.rb
终端上我应该使用什么命令来只运行那个测试用例?这个命令应该在哪个目录下执行?
我的gem文件:
# 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
admin 更改状态以发布 2023年5月24日
使用Rake:
rake spec SPEC=path/to/spec.rb
(感谢这个回答,给他投票。)
编辑(感谢@cirosantilli):要在规范中运行一个特定的场景,必须提供一个匹配描述的正则表达式模式。
rake spec SPEC=path/to/spec.rb \ SPEC_OPTS="-e \"should be successful and return 3 items\""
通常我会这样做:
rspec ./spec/controllers/groups_controller_spec.rb:42
其中,42
代表我想运行的测试行。
你也可以使用标签。可以看看这里.
使用 bundle exec
:
bundle exec rspec ./spec/controllers/groups_controller_spec.rb:42