Sha256: 88eadf126aed3495f303ab77360fccda11186fff1d79cae2ad2b245e460afa0d

Contents?: true

Size: 1.46 KB

Versions: 2

Compression:

Stored size: 1.46 KB

Contents

require 'test/unit'
require 'solusvm'
require 'mocha/setup'
require 'sham_rack'
require 'set'
require 'json'

class Test::Unit::TestCase
  # Public: Stubs a JSON reponse using ShamRack.
  #
  # name - The name of a JSON file in `test/sham_rack_stubs/`
  #
  # Returns Sinatra::Wrapper.
  def stub_response(name)
    setup_sham_rack do
      path = File.expand_path("../sham_rack_stubs/#{name}.json", __FILE__)
      File.read(path)
    end
  end

  # Public: Setup a ShamRack response using Sinatra.
  #
  # block - Required block, passed to Sinatra's `get` method when setting up a
  #         the `/api` route
  #
  # Returns Sinatra::Wrapper.
  def setup_sham_rack(&block)
    ShamRack.at(URI.parse(solusvm_params[:url]).host).sinatra do
      get("/api", &block)
    end
  end

  # Public: API login credentials.
  #
  # Returns a Hash.
  def api_login
    {
      id:  'api_id',
      key: 'api_key'
    }
  end

  # Public: Parameters used when sending a request to the SolusVM API.
  #
  # Returns a Hash.
  def solusvm_params
    {
      api_id:  api_login[:id],
      api_key: api_login[:key],
      url:     'http://www.example.com/api'
    }
  end

  # Public: Arguments used for testing CLI.
  #
  # options - Extra arguments to use
  #
  # Returns an Array.
  def cli_expand_base_arguments(options)
    options + [
      "--api-login", "#{solusvm_params[:api_id]}",
      "--api-key", "#{solusvm_params[:api_key]}",
      "--api-url", "#{solusvm_params[:url]}"
    ]
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
solusvm-2.0.0.beta2 test/test_helper.rb
solusvm-2.0.0.beta1 test/test_helper.rb