Confused with Cucumber and Capybara

These last few days have been quite tough. Not only have I struggled to get to grips with the material, I’ve also been feeling rather poorly, with a headache that refuses to budge. Not a great combination in the fast-paced, intensive world of Makers Academy.

This week we have been introduced to a new type of testing, which focuses on behaviour from the front-end of the app, rather than the back-end, as well as databases, and the different tools we can use to store the information that our app needs. Capybara is tool that stimulates how a user would interact with a website, and we’re combining that with Cucumber, which allows us write the tests in simple English. Here is an example of such a test:

Feature: Division
In order to avoid silly mistakes
As a maths beginner
I want to be told the division of one number by another

Scenario: Dividing one number by another
I have entered 50 into the calculator
And I have entered 10 into the calculator
When I press divide
The result should be 5 on the screen

As you can see, you don’t need to know any code to understand what is going on above. This is why Cucumber tests are very useful not only for communication within a team, but for business clients who are not familiar with technical language but need some evidence that their website or app does what they’ve paid for it to do. When Enrique first demonstrated it to us he made it seem rather straightforward, as he has a knack of doing, but when I attempted to write my first feature test for my bookmark manager application (this week’s project), I was lost. I didn’t know where to begin or how to apply the syntax. A fellow Maker, Darrell, suggested that we work together on a simple phonebook application to help break down some of the barriers we were facing in terms of getting to grips with this new language. This helped somewhat, but I still didn’t feel comfortable approaching the tests without further guidance.

After a confusing Monday, I looked forward to a Ruby Hack Night at Yammer, an enterprise social network company, conveniently located around the corner from Makers. When asked what I would like to work on, to my dismay, I discovered that only one of the five Yammer engineers present knew how to use Cucumber or Capybara, and the one that did know something wasn’t particularly keen on discussing it. After chatting to others about the prevalence of such Behaviour Driven Development practices in the industry today, it appears that they are not so widely used as TDD is, particularly if clients do not express any interest in seeing such tests.

In general, the hack night was excellent. Though forty people had signed up, the six representatives from Makers Academy formed the majority of the attendees, which not only meant lots more pizza for us, but also more focused time with the Yammer employees, who were interesting to talk to, and very attentive to our coding problems. It was a useful experience to discuss code with people outside of Makers Academy being that we had to incorporate different perspectives on how to solve problems with code and when you’re working as a dev, you need to be able to adapt to a range of working styles.

Today, Enrique held a session where he walked through how to build up the bookmark manager app step-by-step. This was very valuable. Once again it highlighted how essential it is to use both rspec and Cucumber to guide the coding process: read the error message. What does it tell you is wrong? Okay – fix that one thing, and nothing more. So often it can be tempting to write the code for where you know your programme is going, but eventually you will run into problems and not know where exactly it is that you went wrong.

Unfortunately, I couldn’t get the most out of this session because I was feeling quite unwell, so I had to return home early and catch up on some rest. Need to be fresh tomorrow for the introduction of user data and security considerations!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s