Wednesday, January 29, 2014

Scripts are code!

Scripts (powershell, bash, ruby, etc) should be held to the same rigor and standards as your application's code.

I just wrote a bunch of tests around our powershell scripts that help us perform certain Continuous Delivery steps.  I ended up using Pester because of it's simplicity and likeness to RSpec.  We use RSpec to test our Ruby applications and scripts.

It has nice mocking abilities, and all the assertion logic you need - including exceptions.

Pester is available as a Chocolatey install (cinst pester), and it has a ISE plugin (cinst IsePester).

It had one weird quirk - It is unable to validate the exception type using the built-in asserts. I didn't spend any time digging into why, I just wanted to move on to my next task.

Context "Bad data" {
        try {
            $result = Method(@("asfd", "asdd"))
        catch { $msg = $_.Exception.Message }

        It "Throws exception" {
            $msg | Should Be "Reboot cycle exceeded"

I also like the simplicity and functionality of  the Ruby Gem JSLint.  Very easy to use to validate your json files are correct before you read them.

No comments:

Post a Comment