Developing on Staxmanade

Approval Tests - Command Line Tool (CLI)

(Comments)

In my previous post I introduced Approval Tests using the Approvals.NodeJS variant of the tool.

In this post I'd like to go over how you can use the command line version of Approvals.NodeJS for several different scenarios.

First thing first (How to Install)

Globally install approvals via npm.

npm install -g approvals

Now that you have it installed, let's go over some scenarios that you can use the approvals tool.

Scenario 1: Compare JSON files downloaded from a web server.

Let's say you want to see a quick file diff between two api requests.

You can use curl to download the file and pipe (|) it to the approvals CLI tool. We give it a name parameter which is used to generate the file name used to save to.

So if you were to run:

curl https://api.github.com/orgs/approvals | approvals githubOrg

This would generate two files:

githubOrg.received.txt which at the time of this writing would look like:

{
  "login": "approvals",
  "id": 36907,
  "url": "https://api.github.com/orgs/approvals",
  "repos_url": "https://api.github.com/orgs/approvals/repos",
  "events_url": "https://api.github.com/orgs/approvals/events",
  "members_url": "https://api.github.com/orgs/approvals/members{/member}",
  "public_members_url": "https://api.github.com/orgs/approvals/public_members{/member}",
  "avatar_url": "https://avatars.githubusercontent.com/u/36907?v=3",
  "description": null,
  "name": null,
  "company": null,
  "blog": "http://approvaltests.com",
  "location": null,
  "email": null,
  "public_repos": 13,
  "public_gists": 0,
  "followers": 0,
  "following": 0,
  "html_url": "https://github.com/approvals",
  "created_at": "2008-11-27T06:03:58Z",
  "updated_at": "2014-12-28T03:02:33Z",
  "type": "Organization"
}

and an empty githubOrg.approved.txt file.

Note when you first run this command you are prompted with the received file compared to the empty approved files; however, on an initial run, you can use the --forceapproveall argument to avoid the diff step and force all the contents of the received file into the approved file.

Now if the remote file were to change on you and you run the below command again:

curl https://api.github.com/orgs/approvals | approvals githubOrg

You would get a diff between the the originally approved file and the newly downloaded file.

Scenario 2:

Ok, well I actually have another great scenario for using the approvals CLI, but I believe it deserves it's own post as I'm going to introduce some nifty configuration on a Mac that I've used to setup my own development servers automatically.

Until next time...

Comments