About This Title

Pages: 404
Published: February 2018
ISBN: 9781680502503
In Print

Skill Level Meter

Rails 5 Test Prescriptions

Build a Healthy Codebase

by Noel Rappin

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.2, Minitest 5, and RSpec 3.7, as well as popular testing libraries such as factory_bot and Cucumber. Updates include Rails 5.2 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.

STOP!

  • This edition uses Rails 5.2

eBook Formats:

  • PDF for desktop/tablets

  • epub for Apple Books, e-readers

  • mobi for Kindle readers

Get all eBook formats here for $27.95 (USD)

Add to Cart we accept visa, mastercard, amex, discover, paypal


Paperback Formats:

Please support indie bookstores!
Find indie bookstores in the U.S. Find indie bookstores around the world.


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_bot. 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.2 and RSpec 3.7 and contains full coverage of new Rails features, including system tests and the Webpack-based JavaScript setup.

What You Need

Ruby 2.5, Rails 5.2

Resources

Releases:

  • P1.0 2018/02/14
  • B3.0 2018/02/08
  • B2.0 2017/11/30
  • B1.0 2017/11/13

Contents & Extracts

  • Acknowledgments
  • Preface
    • Who You Are
    • What’s in This Book
    • What You’ll Need
    • A Word About Tools, Best Practices, and Teaching TDD
    • Changes in This Edition
    • Online Resources
  • A Test-Driven Fable
    • Testing First Drives Design
    • What Is TDD Good For?
    • When TDD Needs Some Help
    • What You’ve Done
  • Test-Driven Development Basics
    • Infrastructure
    • The Requirements
    • Installing RSpec
    • Where to Start? excerpt
    • Running the Test
    • Making the Test Pass
    • The Second Test
    • Back on Task
    • Adding Some Math
    • The First Date
    • Using the Time Data
    • What You’ve Done
  • Test-Driven Rails
    • Let’s Write Some Rails
    • The Days Are Action-Packed
    • Who Controls the Controller?
    • A Test with a View
    • Testing for Failure
    • What You’ve Done
  • What Makes Great Tests
    • The Big One
    • Cost and Value
    • SWIFT: The Five Qualities of Valuable Tests
    • What You’ve Done
  • Testing Models excerpt
    • 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
  • Adding Data to Tests
    • What’s the Problem?
    • Fixtures
    • Factories
    • Dates and Times
    • What You’ve Done
  • Using Test Doubles as Mocks and Stubs
    • Test Doubles Defined
    • Creating Stubs
    • Mock Expectations
    • Using Mocks to Simulate Database Failure
    • Using Mocks to Specify Behavior
    • More Expectation Annotations
    • Mock Tips
    • What You’ve Done
  • 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
  • Testing JavaScript: Integration Testing
    • Integration-Testing JavaScript with Capybara
    • Let’s Talk About Drivers
    • Making the Test Pass
    • Webpack in Developer Mode
    • What You’ve Done
  • Unit-Testing JavaScript
    • Setting Up JavaScript Unit Tests
    • Writing a Sample Test
    • TDD in JavaScript
    • Jasmine Matchers
    • Testing Ajax Calls
    • Using testdouble.js
    • Connecting the JavaScript to the Server Code
    • What You’ve Done
  • Testing Rails Display Elements
    • Testing Routes
    • Testing Helper Methods excerpt
    • Testing Controllers and Requests
    • Simulating Requests
    • What to Expect in a Request Spec
    • Older Rails Controller Tests
    • Testing Mailers
    • Testing Views and View Markup
    • Using Presenters
    • Testing Jobs and Cables
    • What You’ve Done
  • Minitest
    • Getting Started with Minitest
    • Minitest Basics
    • Running Minitest
    • Minitest Setup
    • Mocha
    • System Tests and Others
    • Minitest Helper Tests
    • Minitest and Routing
    • What You’ve Done
  • Testing for Security
    • User Authentication and Authorization
    • Adding Users and Roles
    • Restricting Access
    • More Access-Control Testing
    • Using Roles
    • Protection Against Form Modification
    • Mass Assignment Testing
    • Other Security Resources
    • What You’ve Done
  • Testing External Services
    • External Testing Strategy
    • The Service Integration Test
    • Introducing VCR
    • Client Unit Tests
    • Why an Adapter?
    • Adapter Tests
    • Testing for Error Cases
    • Smoke Tests and VCR Options
    • The World Is a Service
    • What You’ve Done
  • Troubleshooting and Debugging
    • General Principles
    • The Humble Print Statement
    • Git Bisect
    • RSpec or Minitest Bisect
    • Pry
    • Common Rails Gotchas
    • What You’ve Done
  • Running Tests Faster and Running Faster Tests
    • Running Smaller Groups of Tests
    • Running Rails in the Background
    • Running Tests Automatically with Guard
    • Writing Faster Tests by Bypassing Rails
    • Recommendations for Faster Tests
    • What You’ve Done
  • Testing Legacy Code
    • What’s a Legacy?
    • Set Expectations
    • Getting Started with Legacy Code
    • Test-Driven Exploration
    • Dependency Removal
    • Find the Seam
    • Don’t Look Back
    • What You’ve Done

Author

Noel Rappin is a Principal Software Engineer at Table XI, and is the author of multiple technical books. Before joining Table XI, Noel ran internal training at Groupon, and has a Ph.D. in educational technology and user-centered design from the GVU Lab at the Georgia Institute of Technology. Find Noel online at noelrappin.com.

eBook Formats:

  • PDF for desktop/tablets

  • epub for Apple Books, e-readers

  • mobi for Kindle readers

Get all eBook formats here for $27.95 (USD)

Add to Cart we accept visa, mastercard, amex, discover, paypal


Paperback Formats:

Please support indie bookstores!
Find indie bookstores in the U.S. Find indie bookstores around the world.

Related Titles:

Skill Level Meter

About This Title

Pages: 404
Published: February 2018
ISBN: 9781680502503
Edition: 1
In Print