I built a Thor script that connects to an HTTP API to perform some very simple actions. I've coded tests for the backend but the Thor script is basically untested, which is quite suboptimal.
My first approach was to capture the output of the commands itself and write test against such output, the resulting tests are unsurprisingly slow.
expect(`bin/script foo`).to eq('bar')
I then tried to use both webmock
and vcr
but using this approach none of these frameworks are invoked, even if I mock the exact request the mock is unused, most probably because both webmock
and vcr
are unable to hook into the thor script.
Has anybody found a nice solution for this? Invoking the Thor script directly (Thorclass.action('bar')
) would be enough for my taste, but I haven't found a way to do it.
Any suggestion? Thanks in advance.