Hands-on Test-Driven Development: Using Ruby, Ruby on Rails, and RSpec
- 3h 24m
- Greg Donald
- Apress
- 2024
Learn to properly test Ruby and Ruby on Rails applications by first writing failing tests, and then by implementing application code to make the failing tests pass. This book will teach you how to employ test-driven development (TDD) using RSpec while building a blog from start to finish. By the end of the book, you will be ready to deploy their fully tested blog to their own production web server using the latest versions of Ruby 3 and Ruby on Rails 7.
The biggest challenge with learning and becoming comfortable with test-driven development is that software engineers often cannot imagine what writing a failing test looks like in practice. They write their implementation code first, and only then think about writing tests around their implementation code. This leads to tests that pass by accident, or tests that do not actually test anything. This book will give you the confidence to write tests in the RSpec domain-specific language. You will see your tests fail "properly" before proceeding with writing any implementation code to get them to pass.
This book covers the latest techniques for writing RSpec tests, including "system" specs, and the often overlooked "view" specs, and how to integrate RSpec with other tools like Capybara, headless Chrome, and the new web driver gem. It also covers FactoryBot for mock test data and offers experienced advice on how to avoid creating tests that fail randomly.
What You Will Learn
- Build a blog application from start to finish using test driven development
- Install and explore popular tools used in professional Ruby software engineering
- Evaluate the benefits of effective testing in RSpec
- Explore Capistrano for advanced user interface testing
Who Is This Book For
Beginner to intermediate Ruby software engineers who are interested in learning to use TDD with RSpec to test and build web applications using Ruby on Rails. Readers should have some basic experience with Ruby and Ruby on Rails and have read the "Getting Started with Rails" guide, or something similar.
About the Author
Greg Donald has been a professional software engineer since 1996 and has worked with Ruby on Rails since 2006. Prior to that, he worked on many Perl and PHP projects, often finding the lack of tests made them hard to maintain and extend. After having seen the results of software written using different testing methods, he became a test driven development enthusiast and practitioner, determining no other method would ever be more successful in producing quality software than TDD. He decided to write this book to promote TDD and share his positive experiences using it.
In this Book
-
Introduction
-
What Is Test-Driven Development?
-
Getting Started with Ruby
-
Getting Started with Ruby on Rails
-
Setting Up RSpec and FactoryBot
-
Adding Initial Models
-
Creating Pages
-
Build Homepage Contents
-
Sidebar Contents
-
Page Tags
-
Images
-
User Authentication
-
Administration
-
Odds and Ends
-
Bonus: Deploy to Production