Behaviour-driven testing framework for Ruby
open sourceMITself-hostablefree
RSpec is a testing framework for Ruby in which tests read like specifications: you describe an object and say what it should do with describe, context and it. It is split into gems: rspec-core runs examples and provides the rspec command with filtering and formatters, rspec-expectations gives readable matchers, rspec-mocks provides test doubles, stubs and message expectations, and rspec-support holds shared helpers. rspec-rails adds model, request, system and other spec types for Rails apps. The core gems now live in one monorepo, rspec/rspec.
Problems it solves
- write tests for my Ruby code that read like a description of how it should behave
- I need a test framework for a Rails app that covers models, requests and full browser tests
- stub out a payment client in my tests so they don't hit the real API
- check that a method gets called with the right arguments without running it
- run only the one failing test on line 42 instead of the whole suite
- share the same setup between groups of tests without copying it
- make test failures print a clear message about what was expected and what came back
- run my tests in random order to catch ones that depend on each other
- tag slow browser tests so CI can run them separately
- one test framework that runs everything from tiny unit tests to API and browser tests
- practise test-driven development in Ruby
- write my own matcher so assertions read like plain English
Features
- describe/context/it DSL
- rspec command with line, tag and example filtering
- random ordering with seeds
- custom formatters
- readable matchers and custom matchers
- test doubles, stubs and message expectations
- shared examples and contexts
- hooks (before, after, around)
- Rails spec types via rspec-rails
Capabilities
| Has a command line tool | plan not known |
|---|---|
| Takes plugins | plan not known |
Alternatives
The same job
These do what RSpec does.
- pytest pytest: helps you write better programs
