Testing
Yesterday we tested. We tested Rails for the first time, and it was not that hard. Many things are built-in, and the presence of gems like : shoulda-matchers ended up making that day even easier than expected.
The idea behind testing your code is that you don’t want it to break later. Now that you are working on that 100 lines project, you don’t feel the need to do so, but what about when it hits 10000 lines and the 10001 actually breaks something in the middle? And what if solving that bug actually creates new ones?
So, to prevent that… We test. We test that an user can create an account, that it is correctly saved. We test that an user can login, that our password verification does not send unencrypted passwords, that the posts we make are not duplicates, etc…
All that, in 3 big groups :
- Integration tests : Complicated to do (Use Capybara for Ruby web frameworks like Sinatra or Rails), and very long to execute. The idea is that you make a program do exactly what an user would do, to make sure every step works
- Controller tests : This is a bit … fuzzy. These are considered as integration tests, or unit tests, depending on the piece of code you’re testing, but of specific actions of the “controller” in your app. For example, when a user sends data to /users/new it should create a new user. They are faster than integration test, but still not the fastest
- Model (Unit) tests : The idea here is to test the basic data you have. You have one single piece of data, a User, a Post, a Category, and you want to test that its data is the one you want. You want to test that a User can’t have an email without an @ for example.
This, we did it in Ruby, with Rspec, Capybara, shoulda-matchers, and some others. I then did that in Javascript with Jasmine and Sinon, for a small part of the evening. All in all, it was a nice day, and now nothing breaks anymore ;)
A video
A tradition here in Dev Bootcamp says that people who are graduating from phase 2 need to prepare a video for the newcomers of the next monday. The video shows a bit about the bootcamp, the spirit, and the people that you can meet there… So without further introduction, ours :
Naps
Nowadays, I am a bit tired. I had no idea that we had to change the clocks on sunday, and discovered that after a very short night… Unfortunately, I was busy so I ended up doing a lot of things and not sleeping enough.
I am working on that, but since Monday, I am napping every afternoon now!
I hope I can make that be less of a habit soon… So I’ll go to sleep now ;)