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.
Thor is a wrapper
Example
Thor wrapper
bin/seedFor more details on command line Thor see this excellent walkthrough
Production code
lib/services/seed_budgets.rbUnit tests
test/services/seed_budgets_test.rbThat will allow you to decouple the command line interface from the actual code.
Then Thor becomes a very thin wrapper around your actual code.
Feel free to post more detailed code and I can help more. :)