debian-mirror-gitlab/spec/services/packages/composer/composer_json_service_spec.rb

40 lines
1.1 KiB
Ruby
Raw Normal View History

2020-07-28 23:09:34 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Packages::Composer::ComposerJsonService do
describe '#execute' do
let(:branch) { project.repository.find_branch('master') }
let(:target) { branch.target }
subject { described_class.new(project, target).execute }
context 'with an existing file' do
let(:project) { create(:project, :custom_repo, files: { 'composer.json' => json } ) }
context 'with a valid file' do
let(:json) { '{ "name": "package-name"}' }
it 'returns the parsed json' do
expect(subject).to eq({ 'name' => 'package-name' })
end
end
context 'with an invalid file' do
let(:json) { '{ name": "package-name"}' }
it 'raises an error' do
2021-01-03 14:25:43 +05:30
expect { subject }.to raise_error(described_class::InvalidJson, /Invalid/)
2020-07-28 23:09:34 +05:30
end
end
end
context 'without the composer.json file' do
let(:project) { create(:project, :repository) }
it 'raises an error' do
2021-01-03 14:25:43 +05:30
expect { subject }.to raise_error(described_class::InvalidJson, /not found/)
2020-07-28 23:09:34 +05:30
end
end
end
end