O'Reilly logo

Effective Testing with RSpec 3 by Myron Marston, Ian Dees

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Understanding Failure

To try your specs, run the rspec command from your project directory. RSpec will look inside the spec subdirectory for files named «something»_spec.rb and run them:

 $ ​​rspec
 F
 
 Failures:
 
  1) An ideal sandwich is delicious
  Failure/Error: sandwich = Sandwich.new(’delicious’, [])
 
  NameError:
  uninitialized constant Sandwich
  # ./spec/sandwich_spec.rb:4:in ‘block (2 levels) in <top (required)>’
 
 Finished in 0.00076 seconds (files took 0.08517 seconds to load)
 1 example, 1 failure
 
 Failed examples:
 
 rspec ./spec/sandwich_spec.rb:3 # An ideal sandwich is delicious

RSpec gives us a detailed report showing which spec failed, the line of code where the error occurred, and a description of the problem. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required