Book description
Does your Rails code suffer from bloat, brittleness, or inaccuracy? Cure these problems with the regular application of test-driven development. You'll use Rails 5.1, Minitest 5, and RSpec 3.6, as well as popular testing libraries such as factory_girl and Cucumber. Updates include Rails 5.1 system tests and Webpack integration. Do what the doctor ordered to make your applications feel all better. Side effects may include better code, fewer bugs, and happier developers.
Your Ruby on Rails application is sick. Deadlines are looming, but every time you make the slightest change to the code, something else breaks. Nobody remembers what that tricky piece of code was supposed to do, and nobody can tell what it actually does. Plus, it has bugs. You need test-driven development: a process for improving the design, maintainability, and long-term viability of software.
With both practical code examples and discussion of why testing works, this book starts with the most basic features delivered as part of core Ruby on Rails. Once you've integrated those features into your coding practice, work with popular third-party testing tools such as RSpec, Jasmine, Cucumber, and factory_girl. Test the component parts of a Rails application, including the back-end model logic and the front-end display logic. With Rails examples, use testing to enable your code to respond better to future change. Plus, see how to handle real-world testing situations.
This new edition has been updated to Rails 5.1 and RSpec 3.6 and contains full coverage of new Rails features, including system tests and the Webpack-based JavaScript setup.
What You Need:
Ruby 2.4, Rails 5.1
Publisher resources
Table of contents
- Acknowledgments
- Preface
- 1. A Test-Driven Fable
- 2. Test-Driven Development Basics
- 3. Test-Driven Rails
- 4. What Makes Great Tests
-
5. Testing Models
- What Can You Do in a Model Test?
- What Should You Test in a Model Test?
- Okay, Funny Man, What Makes a Good Set of Model Tests?
- Refactoring Models
- A Note on Assertions per Test
- Testing What Rails Gives You
- Testing ActiveRecord Finders
- Testing Shared Modules and ActiveSupport Concerns
- Writing Your Own RSpec Matchers
- What You’ve Done
- 6. Adding Data to Tests
- 7. Using Test Doubles as Mocks and Stubs
-
8. Integration Testing with Capybara and Cucumber
- A Field Guide to Integration and System Tests
- Setting Up Capybara
- Using Feature Tests to Build a Feature
- What to Test in an RSpec System Test
- Outside-in Testing
- Making the Capybara Test Pass
- Retrospective
- Setting Up Cucumber
- Writing Cucumber Features
- Writing Cucumber Steps
- Advanced Cucumber
- Is Cucumber Worth It?
- What You’ve Done
- 9. Testing JavaScript: Integration Testing
- 10. Unit-Testing JavaScript
- 11. Testing Rails Display Elements
- 12. Minitest
- 13. Testing for Security
- 14. Testing External Services
- 15. Troubleshooting and Debugging
- 16. Running Tests Faster and Running Faster Tests
- 17. Testing Legacy Code
- Bibliography
Product information
- Title: Rails 5 Test Prescriptions
- Author(s):
- Release date: February 2018
- Publisher(s): Pragmatic Bookshelf
- ISBN: 9781680502503
You might also like
book
Rails 4 Test Prescriptions
Does your Rails code suffer from bloat, brittleness, or inaccuracy? Cure these problems with a regular …
book
Beginning Rails 6: From Novice to Professional
Springboard your journey into web application development and discover how much fun building web applications with …
article
Reinventing the Organization for GenAI and LLMs
Previous technology breakthroughs did not upend organizational structure, but generative AI and LLMs will. We now …
book
Crafting Rails 4 Applications, 2nd Edition
Get ready to see Rails as you've never seen it before. Learn how to extend the …