Because of the difficulties (opacity) of trying to develop unit tests with Rack on a Sinatra application, I decided to try get something working with curl: we have much better control of the post process and is something we can actually troubleshoot.
Of all the posts I have seen regarding to Rack applications, the one that sticks with me is http://lightyearsoftware.com/2013/02/sending-json-post-data-in-an-integration-test http://lightyearsoftware.com/2013/02/sending-json-post-data-in-an-integration-test/, simply because the author says that it is not straightforward and doesn’t expect it to continue working with future versions of Ruby or Rails.
I’ll put together another post shortly describing in a bit more detail, not just the POSTing, but the receiving end as well. It’s been painful.
I have been mucking around a bit more with my Sinatra application, running it via Rack with a config.ru file and some code improvements (though everything I write still looks like it was done by a ten-year-old) and I decided it ought to be fairly straightforward to prepare some test cases since I’m only handling two routes.
Not so. This is Ruby after all.
There’s quite a long testing page, http://www.sinatrarb.com/testing.html, but at no point does it give a command that will actually run the tests listed on the page! And none of the tests include POST data.
Every time I’ve tried to spend time figuring out how to run simple application tests with Rails, and now Sinatra, I just want to tear my hair out and just give up.
I know I’m a numpty coder, but it’s so difficult trying to do the right thing.
Have just embarked on trying to write a simple microservice to record lists of installed packages from clients and then be able to serve them back to a different client that uses the records to populate database.
The initial code is very ropy but good fun to write and I’m just discovering the wonders of Sinatra for providing this kind of service.
If I make any kind of progress here, and I want to try out some mock testing without requiring an actual database, there are a few other applications I can think of that would benefit from a lightweight touch such as this.