Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turn on full backtrace in Ruby on Rails TestCase

Tags:

Only one line of backtrace is displayed when I run:

rake test

Output:

...

ERROR should get search for keywords (1.93s) 
  NoMethodError: undefined method `features' for #<Transcript:0x00000006243780>
  /usr/lib/ruby/gems/1.9.1/gems/activemodel-3.1.0/lib/active_model/attribute_methods.rb:385:in `method_missing'

...

I need more lines of backtrack information. I have tried

  • rake test --trace

  • Rails.backtrace_cleaner.remove_silencers! in config/initializers/backtrace_silencers.rb

  • setting global $DEBUG=true

and it didn't work.

How can I turn it on?

like image 361
Niels Tolstrup Avatar asked Oct 03 '11 10:10

Niels Tolstrup


People also ask

How do you run a Minitest in rails?

To run a Minitest test, the only setup you really need is to require the autorun file at the beginning of a test file: require 'minitest/autorun' . This is good if you'd like to keep the code small. A better way to get started with Minitest is to have Bundler create a template project for you.

How do I run a test case in Ruby?

We can run all of our tests at once by using the bin/rails test command. Or we can run a single test file by passing the bin/rails test command the filename containing the test cases. This will run all test methods from the test case.

What is stack trace Ruby?

The stack trace (usually named "backtrace" in Ruby, but also referred to as "stack backtrace" and "stack traceback") is a human-readable representation of the stack at a specific moment while running your program.

How do you test a method in Ruby?

Most methods can be tested by saying, “When I pass in argument X, I expect return value Y.” This one isn't so straightforward though. This is more like “When the user sees output X and then enters value V, expect subsequent output O.” Instead of accepting arguments, this method gets its value from user input.


1 Answers

BACKTRACE=blegga rake test

BACKTRACE=blegga rails test # rails 5+

Append --trace if you need rake related log.

like image 99
Libin Pan Avatar answered Sep 20 '22 17:09

Libin Pan