In the past weeks I bumped into LotusRB from my RubyWeekly.com newsletter published by @PeterC, signup if you haven't (pun intended). After a few glances I fell in love. So i immediately setout to get my next project at work going. Lotus is very testable. And as usual in the Ruby world, there is enough rope to kill 10 newbies in one go. After a bit of enthusiasm came the realization that i'd better do things the right way and make my life easy.
There are things to test. Depending on how you like your flow. Lotus supports both MiniTest by default and RSpec as an option. Just follow the 'get started' docs and get your app going.
BDD can easily be done without hitting the DB. Capybara is included and a spec/web/features
directory is a start for you. So, assuming you are a Lotus newbie. You might want to know what you need to test.
Template, View, Controller in that order or Controller, View, Template in the other order. I like that.
TDD/Unit tests are also nicely tucked away from the world until you get there. Basically in the lib/
directory you find app_name/entities/
and app_name/repositories
directories. Here is where all your busness logic should live as recommended.
Lotus app should look like a gem where you can share and refine your libraries.
My problem was understanding what to test. What is available at certain levels of the flow. Sometimes I'd get errors like params is not defined
or params is empty
.
It makes it easier to start if the docs had some guidance but Lotus is young and has a lot of ground to cover. So if we can all chip in and guide this kid, he can get better sooner.
For your tests to make sense and have a smooth flow, you need to understand what you are testing and what reponses you get or what a response looks like at different levels.
At controller level the request/response
are different. thats what you need to know and write correct tests.
You need to know the best way to write tests for controllers ... Controllers in Lotus are different from Rails. In Rails controllers are classes and have inheritance. Their actions are methods instances. In Lotus you dont have Controllers are namespaces/encapsulation if thats the right word, and all actions are classes. they are easier to test. They are rack.
A controller will give you ... and replies with a RACK response i.e. [status, { headers }, [body]]
etc.
You test it this way...
...
...
...
There are some things you cannot test in controllers. For example:
abcd
...
...
...
...