When to use cucumber and when to use RSpec?

I am new to cucumber testing and I am trying to figure out when to use the cucumber and when to use RSpec. For my models, I know that I need to test them with RSpec, and I know that I do not need to write RSpec specification specifications if I write cucumber stories. That I do not know when to use what is with representations and controllers. Should I use RSpec to test my views and controllers, or can I just skip them because I use Cucumber to test higher level? Any advice would be greatly appreciated! Thanks!

+7
source share
4 answers

I use RSpec to manage the development and testing of my models, and to some extent my controllers, and Cucumber to develop and test my views (and then integrate them with the controllers).

I don’t feel that writing tests for cucumbers allows me to “skip” the RSpec test recording because most of the development takes place at the model level before any representations are created.

+5
source

If you continue to write Cucumber scripts instead of unit tests, you will probably find that your tests become very slow to run. If the tests are slow, you probably won't run them very often, so the pace of development will slow down.

You can use RSpec for integration tests that run at the same level as Cucumber. If you need to share and discuss features with non-developers, then Cucumber is a huge help. But even if you're a solo developer, Cucumber helps by acting as a “mental guard” between the behavior you need and the underlying implementation.

Most people's standard practice is to write extensive unit tests for a model, minimum tests for a controller, and very rarely any unit tests for presentation. Then you should use Cucumber to verify that everything interacts correctly (make sure the scripts cover any loops / conditions in the controllers and views).

+1
source

I'm not sure whether to recommend the book here, but the RSpec book does provide a good practical example of how cucumbers and RSpec can alternate with behavior to develop a small command line in Ruby.

In a nutshell : recording your Cucumber functions from the perspective of your end user, and your RSpec specs using your own point of view as a developer - a good balance between the speed of execution, a set of tests, test granularity (how accurate error messages are when tests fail) and documentation coverage (Cucumber functions can be considered as always up-to-date documentation is a great example of that ).

+1
source

Just a small addition that may be useful to you. Many people think (I also do) that a cucumber is more of a hassle than a practical test basis for a programmer. While you do not need to collaborate when discussing scenarios with clients who know little about programming, I strongly recommend that you do not use cucumber. I'm with DHH on this. But RSpec, use and even abuse :)

0
source

All Articles