Preface to this edition
Acknowledgements
1. Introduction
- Confident testing
- Why RSpec?
- Who should read this book
- My testing philosophy
- How the book is organized
- Downloading the sample code
- Code conventions
- Discussion and errata
- A note about gem versions
- A note about styling
- About the sample application
2. Setting up RSpec
- Dependencies
- Test database
- RSpec configuration
- The
rspecbinstub - Try it out!
- Summary
- Exercises
3. Model specs
- Anatomy of a model spec
- Creating a model spec
- The RSpec syntax
- Testing validations
- Testing instance methods
- Testing class methods and scopes
- Testing all the cases
- More about matchers
- Summary
- Exercises
4. DRY enough specs
- Describing contexts in RSpec
- DRYer test setup and teardown
- How DRY is too DRY?
- Summary
- Exercises
5. Creating meaningful test data
- Factories or fixtures?
- Installing factory_bot
- Adding factories to the application
- Generating unique data with sequences
- Associations in factories
- Using factories safely
- Summary
- Exercises
6. Testing controllers
- Basic request specs
- Testing user authentication
- Testing user authorization
- Testing user input
- Summary
- Exercises
7. Next level request specs
- Testing invalid user input
- Simplifying test data with factory_bot traits
- Testing non-HTML requests and responses
- Summary
- Exercises
8. Testing the user interface with system specs
- Why system specs?
- System spec dependencies
- A basic system spec
- Simulating browser interactions with Capybara
- Debugging system specs
- Testing JavaScript interactions
- System testing strategies
- Summary
- Exercises
9. More DRY testing techniques
- Support modules
- Lazy-loading with
let - Shared contexts
- Custom matchers
- Aggregating failures
- Summary
- Exercise
10. Testing in isolation
- Mocks, stubs, doubles, fakes, and spies, defined
- Testing edge cases with mocks
- Simulating external systems
- Recording HTTP transactions with VCR
- Mocking methods in factories
- When mocking goes too far
- Summary
- Exercises
11. Testing the rest
- Testing file uploads
- Testing email delivery
- Testing background jobs
- Measuring test coverage
- Summary
- Exercises
12. Toward test-driven development
- Requirements
- Top-down testing
- Digging for clues
- Dropping a level
- Summary
- Excercises
13. Parting advice
- Practice testing the small things
- Be aware of what you’re doing
- Short spikes are OK
- Write a little, test a little is also OK
- Try to write integration specs first
- Make time for testing
- Keep it simple
- Don’t revert to old habits!
- Use your tests to make your code better
- Sell others on the benefits of automated testing
- Keep practicing
- Goodbye, for now
