diff options
author | Z.J. van de Weg <git@zjvandeweg.nl> | 2016-11-17 14:06:45 +0300 |
---|---|---|
committer | Z.J. van de Weg <git@zjvandeweg.nl> | 2016-11-17 23:34:24 +0300 |
commit | d4def9cbcd664b7067e7f9f4ea8be54463bd1d50 (patch) | |
tree | 10c5fe56054be36687146877b4000286334e76e7 /spec/lib/gitlab/chat_commands | |
parent | 1b4fdb9893af28606b7594ee656438c7ef21e9d8 (diff) |
Incorporate feedback, improve presenter class
[ci skip]
Diffstat (limited to 'spec/lib/gitlab/chat_commands')
-rw-r--r-- | spec/lib/gitlab/chat_commands/issue_create_spec.rb | 32 | ||||
-rw-r--r-- | spec/lib/gitlab/chat_commands/issue_show_spec.rb | 30 | ||||
-rw-r--r-- | spec/lib/gitlab/chat_commands/merge_request_search_spec.rb | 16 |
3 files changed, 58 insertions, 20 deletions
diff --git a/spec/lib/gitlab/chat_commands/issue_create_spec.rb b/spec/lib/gitlab/chat_commands/issue_create_spec.rb index 184c09708a4..5f5cc706c96 100644 --- a/spec/lib/gitlab/chat_commands/issue_create_spec.rb +++ b/spec/lib/gitlab/chat_commands/issue_create_spec.rb @@ -6,9 +6,13 @@ describe Gitlab::ChatCommands::IssueCreate, service: true do let(:user) { create(:user) } let(:regex_match) { described_class.match("issue create bird is the word") } - before { project.team << [user, :master] } + before do + project.team << [user, :master] + end - subject { described_class.new(project, user).execute(regex_match) } + subject do + described_class.new(project, user).execute(regex_match) + end context 'without description' do it 'creates the issue' do @@ -17,7 +21,7 @@ describe Gitlab::ChatCommands::IssueCreate, service: true do end.to change { project.issues.count }.by(1) expect(subject[:response_type]).to be :in_channel - expect(subject[:text]).to match 'bird is the word' + expect(subject[:text]).to match('bird is the word') end end @@ -25,11 +29,29 @@ describe Gitlab::ChatCommands::IssueCreate, service: true do let(:description) { "Surfin bird" } let(:regex_match) { described_class.match("issue create bird is the word\n#{description}") } - before { subject } + before do + subject + end it 'creates the issue with description' do - expect(Issue.last.description).to eq description + expect(Issue.last.description).to eq(description) end end end + + describe 'self.match' do + it 'matches the title without description' do + match = described_class.match("issue create my title") + + expect(match[:title]).to eq('my title') + expect(match[:description]).to eq("") + end + + it 'matches the title with description' do + match = described_class.match("issue create my title\n\ndescription") + + expect(match[:title]).to eq('my title') + expect(match[:description]).to eq('description') + end + end end diff --git a/spec/lib/gitlab/chat_commands/issue_show_spec.rb b/spec/lib/gitlab/chat_commands/issue_show_spec.rb index ddf7fc87c36..d7824dd6bf5 100644 --- a/spec/lib/gitlab/chat_commands/issue_show_spec.rb +++ b/spec/lib/gitlab/chat_commands/issue_show_spec.rb @@ -2,19 +2,23 @@ require 'spec_helper' describe Gitlab::ChatCommands::IssueShow, service: true do describe '#execute' do - let(:issue) { create(:issue) } - let(:project) { issue.project } - let(:user) { issue.author } + let(:issue) { create(:issue) } + let(:project) { issue.project } + let(:user) { issue.author } let(:regex_match) { described_class.match("issue show #{issue.iid}") } - before { project.team << [user, :master] } + before do + project.team << [user, :master] + end - subject { described_class.new(project, user).execute(regex_match) } + subject do + described_class.new(project, user).execute(regex_match) + end context 'the issue exists' do it 'returns the issue' do - expect(subject[:response_type]).to be :in_channel - expect(subject[:text]).to match issue.title + expect(subject[:response_type]).to be(:in_channel) + expect(subject[:text]).to match(issue.title) end end @@ -22,9 +26,17 @@ describe Gitlab::ChatCommands::IssueShow, service: true do let(:regex_match) { described_class.match("issue show 1234") } it "returns nil" do - expect(subject[:response_type]).to be :ephemeral - expect(subject[:text]).to start_with '404 not found!' + expect(subject[:response_type]).to be(:ephemeral) + expect(subject[:text]).to start_with('404 not found!') end end end + + describe 'self.match' do + it 'matches the iid' do + match = described_class.match("issue show 123") + + expect(match[:iid]).to eq("123") + end + end end diff --git a/spec/lib/gitlab/chat_commands/merge_request_search_spec.rb b/spec/lib/gitlab/chat_commands/merge_request_search_spec.rb index 4cb4563e589..4033358ab2e 100644 --- a/spec/lib/gitlab/chat_commands/merge_request_search_spec.rb +++ b/spec/lib/gitlab/chat_commands/merge_request_search_spec.rb @@ -7,14 +7,18 @@ describe Gitlab::ChatCommands::MergeRequestSearch, service: true do let(:user) { merge_request.author } let(:regex_match) { described_class.match("mergerequest search #{merge_request.title}") } - before { project.team << [user, :master] } + before do + project.team << [user, :master] + end - subject { described_class.new(project, user, {}).execute(regex_match) } + subject do + described_class.new(project, user).execute(regex_match) + end context 'the merge request exists' do it 'returns the merge request' do - expect(subject[:response_type]).to be :in_channel - expect(subject[:text]).to match merge_request.title + expect(subject[:response_type]).to be(:in_channel) + expect(subject[:text]).to match(merge_request.title) end end @@ -22,8 +26,8 @@ describe Gitlab::ChatCommands::MergeRequestSearch, service: true do let(:regex_match) { described_class.match("mergerequest search 12334") } it "returns a 404 message" do - expect(subject[:response_type]).to be :ephemeral - expect(subject[:text]).to start_with '404 not found!' + expect(subject[:response_type]).to be(:ephemeral) + expect(subject[:text]).to start_with('404 not found!') end end end |