Competenze Digitali per le Professioni del Futuro

Il concetto di competenza digitale è emerso contemporaneamente allo sviluppo tecnologico

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Testing with Rspec

A very important learning about the project that I’m doing at Pernix, is the knowledge that I’ve acquired about testing. At the beginning, I didn’t understand why we had to test everything in the project, I just keep telling to myself to just do it because the customer required it. Also, starting to do the testing, it was a little bit hard to me because the project it was in Ruby on Rails, a programming language that I have no experience before and the gem selected to do the testing it was Rspec.

After a couple of test, I understand that doing this testing is helpful to you as a programmer, that is how you actually can verify if your code is useful or not. Also, in this way you really get to know what you’ve coded, if your code is doing what it suppose to do, because you can set different scenarios where you have to know what it going to happen in each of them. You can set one scenario that is going to pass the test and other that is going to fail if you want it to fail.

A very simple test, is doing it to a model, as an example let create an user with two fields, an email and a name. Also let set the email as required and the name with a limit of 35 letters, these are going to be our validations in the model, it should look as follow:

As you have notice, the describe is the title or the description of what you are doing, in this case we are validating the fields, email and name. And both “it” are validating what we did in the model before.

That means your testing are passing, so you can keep going with the your coding. Also you can verify if your spec is actually doing what it suppose to, by making it to failed to the test. For example, we know that the limit of the name is set to 35, so if we set the spec to be expecting 30 as limit, it going to failed for sure. Let changed it to 30, just to show you what is going to happen, change it as follow:

Save the project and run the command of rspec, the result it should be the follow:

Now, we know for sure that our specs are doing what it suppose to do, first, we have to understand our code, then we know what we are testing and set the scenarios we want to.

Add a comment

Related posts:

Medium Bonus!

As I woke up on the 7th of May and was getting ready for my presentation at university, a random thought popped in my head to check my e-mails. When I opened the app, all the emails seem ordinary…

The Cliffs of Moher

The Cliffs of Moher are a must-add stop to any Ireland itinerary! In fact, it’s the #1 visited natural attraction in the country. If you don’t recognize the cliffs by name, you’d surely recognize…

I am the WORST parent ever!

I remember looking down at my infant son, entrusted to my care. My wife just left for her first weekend away as a mom. Panic started setting in. I stared at him and thought, “Am I really the best man…