Sha256: 9799d9cd9fdcf69ae8cf2651b9fa98be2f5f4ab48d537ce500bad626f0c24264

Contents?: true

Size: 1.34 KB

Versions: 3

Compression:

Stored size: 1.34 KB

Contents

require 'rspec'
require 'spec_helper'

module Berkshelf
  describe Visualizer, :not_supported_on_windows do
    describe '#to_png' do
      context 'when graphviz is not installed' do
        before do
          allow(Berkshelf).to receive(:which)
            .with('dot')
            .and_return(nil)
          allow(Berkshelf).to receive(:which)
            .with('dot.exe')
            .and_return(nil)
        end

        it 'raises a GraphvizNotInstalled exception' do
          expect { subject.to_png }.to raise_error(GraphvizNotInstalled)
        end
      end

      context 'when the graphviz command fails', :graphviz do
        before do
          response = double(success?: false, stderr: 'Something happened!')
          allow(subject).to receive(:shell_out).and_return(response)
        end

        it 'raises a GraphvizCommandFailed exception' do
          expect { subject.to_png }.to raise_error(GraphvizCommandFailed)
        end
      end

      context 'when the graphviz command succeeds', :graphviz do
        it 'builds a png from a Lockfile' do
          outfile = tmp_path.join('test-graph.png').to_s
          lockfile = Lockfile.from_file(fixtures_path.join('lockfiles/default.lock').to_s)

          Visualizer.from_lockfile(lockfile).to_png(outfile)

          expect(File.exists?(outfile)).to be true
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
berkshelf-5.3.0 spec/unit/berkshelf/visualizer_spec.rb
berkshelf-5.2.0 spec/unit/berkshelf/visualizer_spec.rb
berkshelf-5.1.0 spec/unit/berkshelf/visualizer_spec.rb