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

Use `let_it_be` for create_service_spec

parent b276cc04
...@@ -3,30 +3,27 @@ ...@@ -3,30 +3,27 @@
require 'spec_helper' require 'spec_helper'
describe Branches::CreateService do describe Branches::CreateService do
let(:user) { create(:user) }
subject(:service) { described_class.new(project, 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 describe '#execute' do
context 'when repository is empty' do context 'when repository is empty' do
let(:project) { create(:project_empty_repo) }
it 'creates master branch' do it 'creates master branch' do
service.execute('my-feature', 'master') service.execute('my-feature', 'master')
expect(project.repository.branch_exists?('master')).to be_truthy expect(project.repository.branch_exists?('master')).to be_truthy
end end
it 'creates my-feature branch' do it 'creates another-feature branch' do
service.execute('my-feature', 'master') 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
end end
context 'when branch already exists' do context 'when branch already exists' do
let(:project) { create(:project_empty_repo) }
it 'returns an error' do it 'returns an error' do
result = service.execute('master', 'master') result = service.execute('master', 'master')
...@@ -36,14 +33,12 @@ describe Branches::CreateService do ...@@ -36,14 +33,12 @@ describe Branches::CreateService do
end end
context 'when incorrect reference is provided' do context 'when incorrect reference is provided' do
let(:project) { create(:project_empty_repo) }
before do before do
allow(project.repository).to receive(:add_branch).and_return(false) allow(project.repository).to receive(:add_branch).and_return(false)
end end
it 'returns an error with reference name' do it 'returns an error with a reference name' do
result = service.execute('my-feature', 'unknown') result = service.execute('new-feature', 'unknown')
expect(result[:status]).to eq(:error) expect(result[:status]).to eq(:error)
expect(result[:message]).to eq('Invalid reference name: unknown') 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