RSpec

RSpec is a framework to test Ruby code that allows you to use a domain-specific language to provide tests, much in the same way Chef provides a domain-specific language to manipulate an infrastructure. Instead of using a DSL to manage systems, RSpec's DSL provides a number of components to express the expectations of code and simulate the execution of portions of the system (also known as mocking).

The following examples in RSpec should give you a high-level idea of what RSpec can do:

# simple expectation it 'should add 2 and 2 together' do x = 2 + 2 expect(x).to eq 4 end # Ensure any instance of Object receives a call to 'foo' # and return a pre-defined value (mocking) it 'verifies that an instance receives :foo' do expect_any_instance_of(Object) ...

Get Chef: Powerful Infrastructure Automation now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.