Project

communist

0.01
No commit activity in last 3 years
No release in over 3 years
Library for mocking CLI calls to external APIs
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0

Runtime

>= 0
>= 0
 Project Readme

Communist

Gem Version Build Status Dependency Status Inline docs

The Manifesto:

It is Communist prime role to serve community by providing Cucumber steps for testing external API calls from command line applications. To meet this aim the Communist employees Sinatra DSL for mocking server responses. The Communist server receives requests from CLI and provides an API to respond to those requests. Canned answers/expectations have to be provided upfront.

Installation

Add this line to your application's Gemfile:

gem 'communist'

And then execute:

$ bundle

Or install it yourself as:

$ gem install communist

Usage

To get started include the following in your cucumber environment file:

# features/support/env.rb
require 'communist/cucumber'

The gem uses ENV['TEST_HOST'] variable to instrument requests. In your command line application add the following logic to switch between live and test requests:

if ENV['TEST_HOST']
  @@api.endpoint = 'http://' + ENV['TEST_HOST']
end

Finally, communist has few cucumber steps such as Given ... server: that help setting expectations such as:

Scenario: Get blob
  Given the GitHub API server:
  """
  get('/repos/wycats/thor/git/blobs/59b23de9b91d') { status 200 }
  """
  When I run `ghub blob get wycats thor 59b23de9b91d`
  Then the exit status should be 0

Further, by including aruba cucumber steps and using sinatra dsl you can easily describe canned responses:

Scenario: List watchers
  Given the GitHub API server:
  """
  get('/repos/wycats/thor/subscribers') {
    body :login => 'octokit', :id => 1,
          :url => 'https://api.github.com/users/piotrmurach'
    status 200
  }
  """
  When I successfully run `gcli watch ls wycats thor`
  Then the stdout should contain "octokit"

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

License

The gem is available as open source under the terms of the MIT License.

Copyright

Copyright (c) 2012-2016 Piotr Murach. See LICENSE for further details.