Sha256: 9b2aad240cfa867b6bc044584fba5b2fd46aa10acb02f8cd2f957e2409096849

Contents?: true

Size: 1.29 KB

Versions: 4

Compression:

Stored size: 1.29 KB

Contents

require 'spec_helper'
require "vagrant-rackspace/action/list_images"

describe VagrantPlugins::Rackspace::Action::ListImages do
  let(:app) { lambda { |env| } }
  let(:ui) { Vagrant::UI::Silent.new }
  let(:images) {
    Fog.mock!
    Fog::Compute.new({
      :provider => :rackspace,
      :rackspace_region => :dfw,
      :rackspace_api_key => 'anything',
      :rackspace_username => 'anything',
    }).images
  }
  let(:compute_connection) { double('fog connection') }
  let(:env) do
    {
      :rackspace_compute => compute_connection,
      :ui => ui
    }
  end

  subject(:action) { described_class.new(app, env) }

  before do
    allow(compute_connection).to receive(:images).and_return images
  end

  it 'get images from Fog' do
    expect(compute_connection).to receive(:images).and_return images
    action.call(env)
  end

  it 'writes a sorted, formatted image table to Vagrant::UI' do
    header_line = '%-36s %s' % ['Image ID', 'Image Name']
    expect(ui).to receive(:info).with(header_line)
    images.sort_by(&:name).each do |image|
      formatted_line = '%-36s %s' % [image.id.to_s, image.name]
      expect(ui).to receive(:info).with formatted_line
    end
    action.call(env)
  end

  it 'continues the middleware chain' do
    expect(app).to receive(:call).with(env)
    action.call(env)
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
vagrant-rackspace-0.1.10 spec/vagrant-rackspace/actions/list_images_spec.rb
vagrant-rackspace-0.1.9 spec/vagrant-rackspace/actions/list_images_spec.rb
vagrant-rackspace-0.1.8 spec/vagrant-rackspace/actions/list_images_spec.rb
vagrant-rackspace-0.1.7 spec/vagrant-rackspace/actions/list_images_spec.rb