Sha256: fc4433892cfc3e199c60d36974b7f4b6d902724d05895fcde4ea5f360b6ab5bd

Contents?: true

Size: 1.88 KB

Versions: 2

Compression:

Stored size: 1.88 KB

Contents

require 'triglav/client'
require 'triglav/model'

require 'rspec'

unless ENV['LIVE_TEST']
  require 'webmock/rspec'
end

RSpec.configure do |config|
end

shared_context 'initialize client' do
  let(:client) {
    Triglav::Client.new(
      base_url:  ENV['TRIGLAV_BASE_URL'] ||'http://127.0.0.1:3000',
      api_token: ENV['TRIGLAV_API_KEY']  || 'xxxxxxxxxxxxxxxxxxx',
    )
  }
  subject { client }
end

shared_context 'setup request' do
  before {
    if !ENV['LIVE_TEST']
      stub_request(
        endpoint[:method],
        "#{client.base_url}#{endpoint[:path]}?api_token=#{client.api_token}").to_return(
        status: res_code,
        body:   res_body,
      )
    end
  }
end

shared_context 'initialize client with fixtures' do
  include_context 'initialize client'
  include_context 'setup request'

  let(:services) {
    [
      { 'id' => 1 },
      { 'id' => 2 },
    ]
  }

  let(:roles) {
    [
      { 'id' => 1 },
      { 'id' => 2 },
    ]
  }

  let(:hosts) {
    [
      { 'id' => 1, 'active' => true  },
      { 'id' => 2, 'active' => false },
      { 'id' => 2, 'active' => true  },
    ]
  }
end

shared_context 'initialize client with model fixtures' do
  include_context 'initialize client'
  include_context 'setup request'

  let(:model) {
    info = fixture_for(model_name)

    klass_name.new(
      client: client,
      info:   info
    )
  }

  let(:service_model) {
    info = fixture_for(:service)['service']

    klass_name.new(
      client: client,
      info:   info
    )
  }

  let(:role_model) {
    info = fixture_for(:role)['role']

    klass_name.new(
      client: client,
      info:   info
    )
  }

  def fixture_for(model_name)
    __send__(model_name)
  end

  let(:service) {
    { 'id' => 1, 'name' => 'test service' }
  }

  let(:role) {
    { 'id' => 1, 'name' => 'test role' }
  }

  let(:host) {
    { 'id' => 1, 'name' => 'test host', 'active' => true }
  }
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
triglav-client-0.0.7 spec/spec_helper.rb
triglav-client-0.0.6 spec/spec_helper.rb