I have the following file:
/spec/controllers/groups_controller_spec.rb
What command in terminal do I use to run just that spec and in what directory do I run the command?
My gem file:
# 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
Spec file:
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
starting with rspec 2 you can use the following:
I use this guard gem to auto-run my test. It execute test after create or update operations on test file.
https://github.com/guard/guard-test
or usually you can run using following command
rspec spec/controllers/groups_controller_spec.rb
In rails 5,
I used this way to run single test file(all the tests in one file)
Class name can be used to match to the desired file
TopicsControllerTest
My class
class TopicsControllerTest < ActionDispatch::IntegrationTest
Output :
If You want you can tweak the regex to match to single test method
\TopicsControllerTest#test_Should_delete\
There are many options:
You can do something like this:
Given you're on a rails 3 project with rspec 2, From the rails root directory:
should definitely work. i got tired of typing that so i created an alias to shorten 'bundle exec rspec' to 'bersp'
'bundle exec' is so that it loads the exact gem environment specified in your gem file: http://gembundler.com/
Rspec2 switched from the 'spec' command to the 'rspec' command.