Sha256: dc93319ebd6f25a4c60cec9c9737afffdb69692109b94a28ded7f68dc0485ed6

Contents?: true

Size: 1.71 KB

Versions: 3

Compression:

Stored size: 1.71 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

require_relative '../../lib/geet/git/repository'
require_relative '../../lib/geet/services/create_label'

describe Geet::Services::CreateLabel do
  let(:repository) { Geet::Git::Repository.new }

  context 'with user-specified color' do
    it 'should create a label' do
      allow(repository).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/testrepo')

      expected_output = <<~STR
        Creating label...
        Created with color #c64c64
      STR

      actual_output = StringIO.new

      actual_created_label = VCR.use_cassette('create_label') do
        described_class.new.execute(repository, 'my_label', color: 'c64c64', output: actual_output)
      end

      expect(actual_output.string).to eql(expected_output)

      expect(actual_created_label.name).to eql('my_label')
      expect(actual_created_label.color).to eql('c64c64')
    end
  end

  context 'with auto-generated color' do
    it 'should create a label' do
      allow(repository).to receive(:remote).with('origin').and_return('git@github.com:donaldduck/testrepo')

      expected_output_template = <<~STR
        Creating label...
        Created with color #%<color>s
      STR

      actual_output = StringIO.new

      actual_created_label = VCR.use_cassette('create_label_with_random_color') do
        described_class.new.execute(repository, 'my_label', output: actual_output)
      end

      expected_output = format(expected_output_template, color: actual_created_label.color)

      expect(actual_output.string).to eql(expected_output)

      expect(actual_created_label.name).to eql('my_label')
      expect(actual_created_label.color).to match(/\A[0-9a-f]{6}\z/)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
geet-0.3.0 spec/integration/create_label_spec.rb
geet-0.2.1 spec/integration/create_label_spec.rb
geet-0.2.0 spec/integration/create_label_spec.rb