Commit 2f3f6828 authored by Vasilii Iakliushin's avatar Vasilii Iakliushin

Use `let_it_be` for create_service_spec

parent b276cc04
......@@ -3,30 +3,27 @@
require 'spec_helper'
describe Branches::CreateService do
let(:user) { create(:user) }
subject(:service) { described_class.new(project, user) }
let_it_be(:project) { create(:project_empty_repo) }
let_it_be(:user) { create(:user) }
describe '#execute' do
context 'when repository is empty' do
let(:project) { create(:project_empty_repo) }
it 'creates master branch' do
service.execute('my-feature', 'master')
expect(project.repository.branch_exists?('master')).to be_truthy
end
it 'creates my-feature branch' do
service.execute('my-feature', 'master')
it 'creates another-feature branch' do
service.execute('another-feature', 'master')
expect(project.repository.branch_exists?('my-feature')).to be_truthy
expect(project.repository.branch_exists?('another-feature')).to be_truthy
end
end
context 'when branch already exists' do
let(:project) { create(:project_empty_repo) }
it 'returns an error' do
result = service.execute('master', 'master')
......@@ -36,14 +33,12 @@ describe Branches::CreateService do
end
context 'when incorrect reference is provided' do
let(:project) { create(:project_empty_repo) }
before do
allow(project.repository).to receive(:add_branch).and_return(false)
end
it 'returns an error with reference name' do
result = service.execute('my-feature', 'unknown')
it 'returns an error with a reference name' do
result = service.execute('new-feature', 'unknown')
expect(result[:status]).to eq(:error)
expect(result[:message]).to eq('Invalid reference name: unknown')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment