alphagov/vcloud-edge_gateway — pull request #70 by dcarley (2014-05-28 08:34:27+00:00)
Title: [#65370914] Replace methadone with optparse and tests

The primary purpose of this is to move the untested logic that's in the
executable file into a normal class and give it test coverage.

This happens to be a good reason to remove methadone, which collectively
we've not grown very fond of. Whilst it definitely results in less
boilerplate code than using OptionParser directly, it's a lot harder to
understand what's going on, e.g.

- Where does that options hash come from?
- Why don't `arg()` names match the block arguments on `main()`?

Whereas OptionParser makes it clear where we've defined those and that usage
strings don't necessarily match variable assignments for remaining
arguments.

The tipping point was figuring out how we'd test what it is or isn't doing. Not
the basic CLI interface, using cucumber - but what methods it will call
underneath.

I've stolen this pattern from rodjek/puppet-lint which was the best/simplest
example I could find. The binary just passes over `ARGV` which is an array
of CLI argument strings. We can then interface this with rspec and stub out
the parts underneath for testing.

There are some significant changes from the previous implementation:

- `--version` no longer prints help. Just the version string.
- Usage message goes to STDOUT instead of STDERR. Though I may fix that in a
following commit.
- Exceptions from the underlying Vcloud::EdgeGateway classes are no longer
wrapped so we'll get the full stacktrace. I think that is OK though, since
some of the error messages we get further down from Vcloud::Core aren't
very useful at the moment, e.g.

➜ vcloud-edge_gateway git:(65370914-test_executable_file) ✗ b bin/vcloud-configure-edge README.md
/Users/dcarley/vendor/bundle/gems/json-1.8.1/lib/json/common.rb:223:in `generate': only generation of JSON objects or arrays allowed (JSON::GeneratorError)
from /Users/dcarley/vendor/bundle/gems/json-1.8.1/lib/json/common.rb:223:in `generate'
from /Users/dcarley/vendor/bundle/gems/vcloud-core-0.2.0/lib/vcloud/core/config_loader.rb:19:in `load_config'
from /Users/dcarley/projects/govuk/vcloud-edge_gateway/lib/vcloud/edge_gateway/configure.rb:9:in `initialize'
from /Users/dcarley/projects/govuk/vcloud-edge_gateway/lib/vcloud/edge_gateway/bin.rb:22:in `new'
from /Users/dcarley/projects/govuk/vcloud-edge_gateway/lib/vcloud/edge_gateway/bin.rb:22:in `run'
from bin/vcloud-configure-edge:5:in `

'

---

Help is moved to STDERR in a separate commit.