Rspec 2 - "rspec" command gives no outpu - rspec2

With Rspec 2 the "rspec"command is supposed to run the tests, replacing "spec" from previous versions.
I tried running it on a new app and no tests were run (despite having a set of specs created). Regular rake spec works fine to run the tests so the issue is with the command
jack$ rspec
Finished in 0.00003 seconds
0 examples, 0 failures
Using Rails 3
rspec-2.0.1
Any ideas?

you need to tell it where your specs are. Try
rspec spec/

Related

how to rails test all cases together like a test suite

I have few test case files in test/functional and they all need to be executed seperately.
ruby -Itest test/functional/abc.rb
It takes 30 secs just for rails to load and 5 secs to do tests.
Is there a way to just load rails once and run all the case files in that session?
This is a very bad working solution as it is loading rails 5 times.
find test/functional -name '*.rb'|xargs -L 1 ruby -Itest
I need a solution for old rails 3.2 with ruby 1.9.
Just to try I had written all.rb but I guess constructors need args so it did not work.
require 'test_helper'
require 'functional/api_controller_test.rb'
ApiControllerTest.new()
Make sure you name the test files with that ending: *_test.rb
In Rails 3 you can run the whole testsuite like the following:
-
$ rake test
or
$ bundle exec rake test
Read more: http://guides.rubyonrails.org/v3.2/testing.html#rake-tasks-for-running-your-tests

Rails 5.1 run system tests and normal tests with one command

In Rails 5.1, you can do bin/rails test to run normal tests, and bin/rails test:system. What is the Rails sanctioned way of running both at the same time?
bin/rails test:system test
Specifying test:system before test will run both system and ordinary tests. The opposite order will only run the ordinary tests however.
rails test:all (Rails 6.1+)
Rails 6.1 introduces a new command - rails test:all.
It runs all test files in the test directory, including system tests.
Here is a link to PR.
And also a link to the docs (please, scroll down to yellow box).
In case anyone else is looking for the answer:
bin/rails test test/*
If it is your intention to run it using just $ rake or $rake test you can add into your Rakefile:
task test: 'test:system'
This will makes 'test:system' a "prerequisites" for "test" task
At least from the official rails guide, it seems there is no way of doing it:
By default, running bin/rails test won't run your system tests. Make sure to run bin/rails test:system to actually run them.
Ref: rails guide
You can also add this snippet in your lib/tasks folder, that will give you the option to do rake test:all
namespace :test do
desc "Run both regular tests and system tests"
task :all => 'test' do
Minitest.after_run {system('rake test:system')}
end
end
Summary of all the answers for easy reference:
System tests Only
bin/rails test:system
Ordinary tests Only
bin/rails test .
ALL tests
bin/rails test:all

How to run only controller tests in MiniTest?

What is the rake command for running only controller tests in minitest?
rake test:controller doesn't do the trick.
Try making it plural. This is the typical command:
rake test:controllers
http://guides.rubyonrails.org/testing.html#rake-tasks-for-running-your-tests
Section 6 covers the rake commands for testing.
Has to be plural rake test:controllers as you're running all of them.
Please take a look at http://guides.rubyonrails.org/testing.html#rake-tasks-for-running-your-tests for more rake commands.
If you want to run a specific file, then use the TEST argument:
rake test TEST=test/controllers/application_controller_test.rb
As an update:
rails test path/to/test/file.rb has become my go-to solution.
rails test path/to/test/file.rb:123 lets you pick the test via line number as well.

`rspec` with `spring` doesn't work

I wanted to use spring instead of spork.
I installed spring and spring-commands-rspec, and after installing I created binstubs by bundle exec spring binstub --all.
When I run bin/rspec, I get only this result.
No examples found.
Finished in 0.00099 seconds
bin/rake routes gives me proper result. And bundle exec rspec tests all example I have like this.
Finished in 6.63 seconds
20 examples, 2 failures, 11 pending
Failed examples:
What am I missing? Where should I configure the place of test directories?
Try specifiying the directory:
$ bin/rspec spec/

Rails - rspec - How can I run all the integration tests, similar to rake spec:models

The following commands work:
rake spec:models
rake spec:controllers
rake spec:requests
but the following does not:
rake spec:integration
rake spec:integrations
How can I run all the integration tests alone?
One option is to use rspec spec/integration/* I guess.
I was hoping for an answer that worked with rake like the other methods.
Actually, request specs are integration tests in rspec. Were some of the tests inherited from test::unit?
Test::Unit is the default test library for a new rails application created using the generator (unless -T is specified which skips the creation of test::unit files), so it will come with spec/integration, whereas for Rspec, the convention is to use spec/requests. In fact if you try to generate a new integration_test now by rails g integration_test testname, that will go into requests.

Resources