Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get rspec-2 to give the full trace associated with a test failure?

Right now if I run my test suite using rake spec I get an error:

 1) SegmentsController GET 'index' should work    Failure/Error: get 'index'    undefined method `locale' for #    # ./spec/controllers/segments_controller_spec.rb:14:       in `block (3 levels) in ' 

This is normal as I do have an error :)

The problem is that the trace isn't very helpful. I know it broke in segments_controller_spec.rb, line 14, but this is just where I call the test:

### segments_controller_spec.rb:14 get 'index' 

I would prefer to have the actual line breaking and the complete trace, not the part in the spec folder.

Running with --trace doesn't help.

like image 783
marcgg Avatar asked Oct 04 '11 13:10

marcgg


People also ask

Does RSpec clean database?

I use the database_cleaner gem to scrub my test database before each test runs, ensuring a clean slate and stable baseline every time. By default, RSpec will actually do this for you, running every test with a database transaction and then rolling back that transaction after it finishes.

How do I run a RSpec test in terminal?

Open your terminal, cd into the project directory, and run rspec spec . The spec is the folder in which rspec will find the tests. You should see output saying something about “uninitialized constant Object::Book”; this just means there's no Book class.

How do I run a specific file in RSpec?

Running tests by their file or directory names is the most familiar way to run tests with RSpec. RSpec can take a file name or directory name and run the file or the contents of the directory. So you can do: rspec spec/jobs to run the tests found in the jobs directory.


2 Answers

You must run rspec with -b option to see full backtraces

like image 167
solnic Avatar answered Oct 22 '22 20:10

solnic


Another (easier) alternative is to edit the .rspec file, and add the backtrace option. It should look somewhat like this:

--colour --backtrace 

That will give you the full backtrace. Hope this helps.

like image 42
nathanvda Avatar answered Oct 22 '22 18:10

nathanvda