What We Just Learned

When testing a REST web service with Cucumber, it’s generally preferable to run Cucumber in-process—in the same process as your application. In this chapter, we covered the two main approaches—in-process and out-of-process. Although our example used the Sinatra web framework, the techniques used in this chapter can be applied to other web frameworks too.

  • Rack-based applications such as Ruby on Rails and Sinatra can be tested in-process using Rack-Test, completely bypassing HTTP, making them fast.

  • Non-Rack-based applications run in a separate process from Cucumber and have to be started before Cucumber runs.

  • You can use indented JSON documents in your scenarios, as long as you ignore whitespace when you compare them to documents produced by your API.

Try This

Our Fruit application is very simple. It doesn’t provide an API to store fruit, and the file-based database is very simplistic. Here are some new features you can try to express with Cucumber and then implement:

  • Add a scenario that starts with one fruit in the database, adds another one via an HTTP POST, and then verifies that you now have two fruit.

  • Refactor your code to use a proper database, like MySQL or MongoDB, to store fruit. Make sure all scenarios are still passing and that you can run each of them individually. Hint: use DatabaseCleaner to make sure each scenario starts with a blank slate.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.162.37