git_helper 3.2.2 → 3.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/Gemfile.lock +134 -0
- data/Guardfile +3 -1
- data/README.md +10 -5
- data/Rakefile +2 -0
- data/bin/git-helper +24 -12
- data/lib/git_helper.rb +6 -2
- data/lib/git_helper/change_remote.rb +15 -6
- data/lib/git_helper/checkout_default.rb +2 -0
- data/lib/git_helper/clean_branches.rb +2 -0
- data/lib/git_helper/code_request.rb +33 -19
- data/lib/git_helper/empty_commit.rb +2 -0
- data/lib/git_helper/forget_local_commits.rb +2 -0
- data/lib/git_helper/git_config_reader.rb +12 -6
- data/lib/git_helper/gitlab_client.rb +2 -0
- data/lib/git_helper/local_code.rb +18 -8
- data/lib/git_helper/merge_request.rb +90 -70
- data/lib/git_helper/new_branch.rb +4 -2
- data/lib/git_helper/octokit_client.rb +2 -0
- data/lib/git_helper/pull_request.rb +97 -66
- data/lib/git_helper/setup.rb +116 -0
- data/lib/git_helper/version.rb +3 -1
- data/spec/git_helper/change_remote_spec.rb +24 -24
- data/spec/git_helper/checkout_default_spec.rb +2 -0
- data/spec/git_helper/clean_branches_spec.rb +2 -0
- data/spec/git_helper/code_request_spec.rb +31 -28
- data/spec/git_helper/empty_commit_spec.rb +2 -0
- data/spec/git_helper/forget_local_commits_spec.rb +2 -0
- data/spec/git_helper/git_config_reader_spec.rb +32 -4
- data/spec/git_helper/gitlab_client_spec.rb +2 -0
- data/spec/git_helper/local_code_spec.rb +2 -0
- data/spec/git_helper/merge_request_spec.rb +24 -23
- data/spec/git_helper/new_branch_spec.rb +10 -8
- data/spec/git_helper/octokit_client_spec.rb +2 -0
- data/spec/git_helper/pull_request_spec.rb +20 -18
- data/spec/git_helper/setup_spec.rb +183 -0
- data/spec/spec_helper.rb +4 -1
- metadata +38 -9
- data/lib/git_helper/highline_cli.rb +0 -33
- data/spec/git_helper/highline_cli_spec.rb +0 -51
| @@ -1,19 +1,20 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 1 3 | 
             
            require 'spec_helper'
         | 
| 2 4 | 
             
            require 'git_helper'
         | 
| 3 5 |  | 
| 4 6 | 
             
            describe GitHelper::GitLabMergeRequest do
         | 
| 5 7 | 
             
              let(:local_code) { double(:local_code, read_template: Faker::Lorem.word) }
         | 
| 6 | 
            -
              let(: | 
| 8 | 
            +
              let(:highline_wrapper) { double(:highline_wrapper) }
         | 
| 7 9 | 
             
              let(:gitlab_client_client) { double(:gitlab_client_client, project: :project, merge_request: :merge_request, create_merge_request: :created) }
         | 
| 8 10 | 
             
              let(:gitlab_client) { double(:gitlab_client, client: gitlab_client_client) }
         | 
| 9 11 | 
             
              let(:diff_refs) { double(:diff_refs, base_sha: :base, head_sha: :head) }
         | 
| 10 12 |  | 
| 11 13 | 
             
              let(:merge_request) do
         | 
| 12 14 | 
             
                double(:merge_request,
         | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 16 | 
            -
                )
         | 
| 15 | 
            +
                       diff_refs: diff_refs,
         | 
| 16 | 
            +
                       web_url: Faker::Internet.url,
         | 
| 17 | 
            +
                       merge_commit_sha: Faker::Internet.password)
         | 
| 17 18 | 
             
              end
         | 
| 18 19 |  | 
| 19 20 | 
             
              let(:options) do
         | 
| @@ -21,7 +22,7 @@ describe GitHelper::GitLabMergeRequest do | |
| 21 22 | 
             
                  local_project: Faker::Lorem.word,
         | 
| 22 23 | 
             
                  local_branch: Faker::Lorem.word,
         | 
| 23 24 | 
             
                  local_code: local_code,
         | 
| 24 | 
            -
                   | 
| 25 | 
            +
                  highline: highline_wrapper
         | 
| 25 26 | 
             
                }
         | 
| 26 27 | 
             
              end
         | 
| 27 28 |  | 
| @@ -38,7 +39,7 @@ describe GitHelper::GitLabMergeRequest do | |
| 38 39 | 
             
                  allow(subject).to receive(:remove_source_branch).and_return(false)
         | 
| 39 40 | 
             
                  allow(subject).to receive(:new_mr_body).and_return('')
         | 
| 40 41 | 
             
                  expect(gitlab_client_client).to receive(:create_merge_request).and_return(merge_request)
         | 
| 41 | 
            -
                  subject.create({base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word})
         | 
| 42 | 
            +
                  subject.create({ base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word })
         | 
| 42 43 | 
             
                end
         | 
| 43 44 |  | 
| 44 45 | 
             
                it 'should call various other methods' do
         | 
| @@ -46,7 +47,7 @@ describe GitHelper::GitLabMergeRequest do | |
| 46 47 | 
             
                  expect(subject).to receive(:remove_source_branch).and_return(false)
         | 
| 47 48 | 
             
                  expect(subject).to receive(:new_mr_body).and_return('')
         | 
| 48 49 | 
             
                  allow(gitlab_client_client).to receive(:create_merge_request).and_return(merge_request)
         | 
| 49 | 
            -
                  subject.create({base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word})
         | 
| 50 | 
            +
                  subject.create({ base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word })
         | 
| 50 51 | 
             
                end
         | 
| 51 52 |  | 
| 52 53 | 
             
                it 'should catch the raised error if the creation does not work' do
         | 
| @@ -54,7 +55,7 @@ describe GitHelper::GitLabMergeRequest do | |
| 54 55 | 
             
                  allow(subject).to receive(:remove_source_branch).and_return(false)
         | 
| 55 56 | 
             
                  allow(subject).to receive(:new_mr_body).and_return('')
         | 
| 56 57 | 
             
                  allow(gitlab_client_client).to receive(:create_merge_request).and_raise(StandardError)
         | 
| 57 | 
            -
                  expect(subject.create({base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word})).to eq(nil)
         | 
| 58 | 
            +
                  expect(subject.create({ base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word })).to eq(nil)
         | 
| 58 59 | 
             
                end
         | 
| 59 60 | 
             
              end
         | 
| 60 61 |  | 
| @@ -120,19 +121,19 @@ describe GitHelper::GitLabMergeRequest do | |
| 120 121 |  | 
| 121 122 | 
             
                  it 'should call the CLI to ask about a single template' do
         | 
| 122 123 | 
             
                    allow(subject).to receive(:mr_template_options).and_return([template])
         | 
| 123 | 
            -
                    expect( | 
| 124 | 
            +
                    expect(highline_wrapper).to receive(:ask_yes_no).and_return(true)
         | 
| 124 125 | 
             
                    subject.send(:template_name_to_apply)
         | 
| 125 126 | 
             
                  end
         | 
| 126 127 |  | 
| 127 128 | 
             
                  it 'should return the single template if the user says yes' do
         | 
| 128 129 | 
             
                    allow(subject).to receive(:mr_template_options).and_return([template])
         | 
| 129 | 
            -
                    allow( | 
| 130 | 
            +
                    allow(highline_wrapper).to receive(:ask_yes_no).and_return(true)
         | 
| 130 131 | 
             
                    expect(subject.send(:template_name_to_apply)).to eq(template)
         | 
| 131 132 | 
             
                  end
         | 
| 132 133 |  | 
| 133 134 | 
             
                  it 'should return nil if the user says no' do
         | 
| 134 135 | 
             
                    allow(subject).to receive(:mr_template_options).and_return([template])
         | 
| 135 | 
            -
                    allow( | 
| 136 | 
            +
                    allow(highline_wrapper).to receive(:ask_yes_no).and_return(false)
         | 
| 136 137 | 
             
                    expect(subject.send(:template_name_to_apply)).to eq(nil)
         | 
| 137 138 | 
             
                  end
         | 
| 138 139 | 
             
                end
         | 
| @@ -143,19 +144,19 @@ describe GitHelper::GitLabMergeRequest do | |
| 143 144 |  | 
| 144 145 | 
             
                  it 'should call the CLI to ask which of multiple templates to apply' do
         | 
| 145 146 | 
             
                    allow(subject).to receive(:mr_template_options).and_return([template1, template2])
         | 
| 146 | 
            -
                    expect( | 
| 147 | 
            +
                    expect(highline_wrapper).to receive(:ask_options).and_return(template1)
         | 
| 147 148 | 
             
                    subject.send(:template_name_to_apply)
         | 
| 148 149 | 
             
                  end
         | 
| 149 150 |  | 
| 150 151 | 
             
                  it 'should return the answer template if the user says yes' do
         | 
| 151 152 | 
             
                    allow(subject).to receive(:mr_template_options).and_return([template1, template2])
         | 
| 152 | 
            -
                    allow( | 
| 153 | 
            +
                    allow(highline_wrapper).to receive(:ask_options).and_return(template1)
         | 
| 153 154 | 
             
                    expect(subject.send(:template_name_to_apply)).to eq(template1)
         | 
| 154 155 | 
             
                  end
         | 
| 155 156 |  | 
| 156 157 | 
             
                  it 'should return nil if the user says no' do
         | 
| 157 158 | 
             
                    allow(subject).to receive(:mr_template_options).and_return([template1, template2])
         | 
| 158 | 
            -
                    allow( | 
| 159 | 
            +
                    allow(highline_wrapper).to receive(:ask_options).and_return('None')
         | 
| 159 160 | 
             
                    expect(subject.send(:template_name_to_apply)).to eq(nil)
         | 
| 160 161 | 
             
                  end
         | 
| 161 162 | 
             
                end
         | 
| @@ -170,25 +171,25 @@ describe GitHelper::GitLabMergeRequest do | |
| 170 171 |  | 
| 171 172 | 
             
              describe '#mr_id' do
         | 
| 172 173 | 
             
                it 'should ask the CLI for the code request ID' do
         | 
| 173 | 
            -
                  expect( | 
| 174 | 
            +
                  expect(highline_wrapper).to receive(:ask).and_return(Faker::Number.number)
         | 
| 174 175 | 
             
                  subject.send(:mr_id)
         | 
| 175 176 | 
             
                end
         | 
| 176 177 |  | 
| 177 178 | 
             
                it 'should equal an integer' do
         | 
| 178 179 | 
             
                  pr_id = Faker::Number.number
         | 
| 179 | 
            -
                  expect( | 
| 180 | 
            +
                  expect(highline_wrapper).to receive(:ask).and_return(pr_id)
         | 
| 180 181 | 
             
                  expect(subject.send(:mr_id)).to eq(pr_id)
         | 
| 181 182 | 
             
                end
         | 
| 182 183 | 
             
              end
         | 
| 183 184 |  | 
| 184 185 | 
             
              describe '#squash_merge_request' do
         | 
| 185 186 | 
             
                it 'should ask the CLI for the code request ID' do
         | 
| 186 | 
            -
                  expect( | 
| 187 | 
            +
                  expect(highline_wrapper).to receive(:ask_yes_no).and_return(true)
         | 
| 187 188 | 
             
                  subject.send(:squash_merge_request)
         | 
| 188 189 | 
             
                end
         | 
| 189 190 |  | 
| 190 191 | 
             
                it 'should be a boolean' do
         | 
| 191 | 
            -
                  expect( | 
| 192 | 
            +
                  expect(highline_wrapper).to receive(:ask_yes_no).and_return(false)
         | 
| 192 193 | 
             
                  expect([true, false]).to include(subject.send(:squash_merge_request))
         | 
| 193 194 | 
             
                end
         | 
| 194 195 | 
             
              end
         | 
| @@ -200,12 +201,12 @@ describe GitHelper::GitLabMergeRequest do | |
| 200 201 |  | 
| 201 202 | 
             
                context 'when the existing project has no setting' do
         | 
| 202 203 | 
             
                  it 'should ask the CLI for the code request ID' do
         | 
| 203 | 
            -
                    expect( | 
| 204 | 
            +
                    expect(highline_wrapper).to receive(:ask_yes_no).and_return(true)
         | 
| 204 205 | 
             
                    subject.send(:remove_source_branch)
         | 
| 205 206 | 
             
                  end
         | 
| 206 207 |  | 
| 207 208 | 
             
                  it 'should be a boolean' do
         | 
| 208 | 
            -
                    allow( | 
| 209 | 
            +
                    allow(highline_wrapper).to receive(:ask_yes_no).and_return(false)
         | 
| 209 210 | 
             
                    expect([true, false]).to include(subject.send(:remove_source_branch))
         | 
| 210 211 | 
             
                  end
         | 
| 211 212 | 
             
                end
         | 
| @@ -222,7 +223,7 @@ describe GitHelper::GitLabMergeRequest do | |
| 222 223 |  | 
| 223 224 | 
             
                it 'should return the existing projects setting if it exists' do
         | 
| 224 225 | 
             
                  allow(subject).to receive(:existing_project).and_return(double(remove_source_branch_after_merge: false))
         | 
| 225 | 
            -
                  allow( | 
| 226 | 
            +
                  allow(highline_wrapper).to receive(:ask_yes_no).and_return(true)
         | 
| 226 227 | 
             
                  expect(subject.send(:remove_source_branch)).to eq(true)
         | 
| 227 228 | 
             
                end
         | 
| 228 229 | 
             
              end
         | 
| @@ -236,7 +237,7 @@ describe GitHelper::GitLabMergeRequest do | |
| 236 237 |  | 
| 237 238 | 
             
              describe '#existing_mr' do
         | 
| 238 239 | 
             
                it 'should call the gitlab client' do
         | 
| 239 | 
            -
                  allow( | 
| 240 | 
            +
                  allow(highline_wrapper).to receive(:ask).and_return(Faker::Number.number)
         | 
| 240 241 | 
             
                  expect(gitlab_client_client).to receive(:merge_request).and_return(:merge_request)
         | 
| 241 242 | 
             
                  subject.send(:existing_mr)
         | 
| 242 243 | 
             
                end
         | 
| @@ -1,16 +1,18 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 1 3 | 
             
            require 'spec_helper'
         | 
| 2 4 | 
             
            require 'git_helper'
         | 
| 3 5 |  | 
| 4 6 | 
             
            describe GitHelper::NewBranch do
         | 
| 5 7 | 
             
              let(:new_branch_name) { 'new-branch-name' }
         | 
| 6 8 | 
             
              let(:local_code) { double(:local_code, new_branch: :commit) }
         | 
| 7 | 
            -
              let(: | 
| 9 | 
            +
              let(:highline) { double(:highline_wrapper, ask: new_branch_name) }
         | 
| 8 10 |  | 
| 9 11 | 
             
              subject { GitHelper::NewBranch.new }
         | 
| 10 12 |  | 
| 11 13 | 
             
              before do
         | 
| 12 14 | 
             
                allow(GitHelper::LocalCode).to receive(:new).and_return(local_code)
         | 
| 13 | 
            -
                allow( | 
| 15 | 
            +
                allow(HighlineWrapper).to receive(:new).and_return(highline)
         | 
| 14 16 | 
             
                allow(subject).to receive(:puts)
         | 
| 15 17 | 
             
              end
         | 
| 16 18 |  | 
| @@ -25,20 +27,20 @@ describe GitHelper::NewBranch do | |
| 25 27 | 
             
              end
         | 
| 26 28 |  | 
| 27 29 | 
             
              context 'when no branch name is passed in' do
         | 
| 28 | 
            -
                it 'should call the highline  | 
| 29 | 
            -
                  expect( | 
| 30 | 
            +
                it 'should call the highline client' do
         | 
| 31 | 
            +
                  expect(HighlineWrapper).to receive(:new).and_return(highline)
         | 
| 30 32 | 
             
                  subject.execute
         | 
| 31 33 | 
             
                end
         | 
| 32 34 |  | 
| 33 | 
            -
                it 'should ask the highline  | 
| 34 | 
            -
                  expect( | 
| 35 | 
            +
                it 'should ask the highline client what the new branch name should be' do
         | 
| 36 | 
            +
                  expect(highline).to receive(:ask)
         | 
| 35 37 | 
             
                  subject.execute
         | 
| 36 38 | 
             
                end
         | 
| 37 39 | 
             
              end
         | 
| 38 40 |  | 
| 39 41 | 
             
              context 'when there is a branch name passed in' do
         | 
| 40 | 
            -
                it 'should not create a  | 
| 41 | 
            -
                  expect( | 
| 42 | 
            +
                it 'should not create a highline_wrapper client' do
         | 
| 43 | 
            +
                  expect(HighlineWrapper).not_to receive(:new)
         | 
| 42 44 | 
             
                  subject.execute(new_branch_name)
         | 
| 43 45 | 
             
                end
         | 
| 44 46 | 
             
              end
         | 
| @@ -1,9 +1,11 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 1 3 | 
             
            require 'spec_helper'
         | 
| 2 4 | 
             
            require 'git_helper'
         | 
| 3 5 |  | 
| 4 6 | 
             
            describe GitHelper::GitHubPullRequest do
         | 
| 5 7 | 
             
              let(:local_code) { double(:local_code, read_template: Faker::Lorem.word) }
         | 
| 6 | 
            -
              let(: | 
| 8 | 
            +
              let(:highline_wrapper) { double(:highline_wrapper) }
         | 
| 7 9 | 
             
              let(:octokit_client_client) { double(:octokit_client_client, project: :project, merge_request: :merge_request, create_merge_request: :created) }
         | 
| 8 10 | 
             
              let(:octokit_client) { double(:octokit_client, client: octokit_client_client) }
         | 
| 9 11 |  | 
| @@ -12,7 +14,7 @@ describe GitHelper::GitHubPullRequest do | |
| 12 14 | 
             
                  local_project: Faker::Lorem.word,
         | 
| 13 15 | 
             
                  local_branch: Faker::Lorem.word,
         | 
| 14 16 | 
             
                  local_code: local_code,
         | 
| 15 | 
            -
                   | 
| 17 | 
            +
                  highline: highline_wrapper
         | 
| 16 18 | 
             
                }
         | 
| 17 19 | 
             
              end
         | 
| 18 20 |  | 
| @@ -27,19 +29,19 @@ describe GitHelper::GitHubPullRequest do | |
| 27 29 | 
             
                it 'should call the octokit client to create' do
         | 
| 28 30 | 
             
                  allow(subject).to receive(:new_pr_body).and_return('')
         | 
| 29 31 | 
             
                  expect(octokit_client_client).to receive(:create_pull_request).and_return(double(html_url: Faker::Internet.url))
         | 
| 30 | 
            -
                  subject.create({base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word})
         | 
| 32 | 
            +
                  subject.create({ base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word })
         | 
| 31 33 | 
             
                end
         | 
| 32 34 |  | 
| 33 35 | 
             
                it 'should call various other methods' do
         | 
| 34 36 | 
             
                  expect(subject).to receive(:new_pr_body).and_return('').at_least(:once)
         | 
| 35 37 | 
             
                  allow(octokit_client_client).to receive(:create_pull_request).and_return(double(html_url: Faker::Internet.url))
         | 
| 36 | 
            -
                  subject.create({base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word})
         | 
| 38 | 
            +
                  subject.create({ base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word })
         | 
| 37 39 | 
             
                end
         | 
| 38 40 |  | 
| 39 41 | 
             
                it 'should catch the raised error if the creation does not work' do
         | 
| 40 42 | 
             
                  allow(subject).to receive(:new_pr_body).and_return('')
         | 
| 41 43 | 
             
                  allow(octokit_client_client).to receive(:create_pull_request).and_raise(StandardError)
         | 
| 42 | 
            -
                  expect(subject.create({base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word})).to eq(nil)
         | 
| 44 | 
            +
                  expect(subject.create({ base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word })).to eq(nil)
         | 
| 43 45 | 
             
                end
         | 
| 44 46 | 
             
              end
         | 
| 45 47 |  | 
| @@ -101,19 +103,19 @@ describe GitHelper::GitHubPullRequest do | |
| 101 103 |  | 
| 102 104 | 
             
                  it 'should call the CLI to ask about a single template' do
         | 
| 103 105 | 
             
                    allow(subject).to receive(:pr_template_options).and_return([template])
         | 
| 104 | 
            -
                    expect( | 
| 106 | 
            +
                    expect(highline_wrapper).to receive(:ask_yes_no).and_return(true)
         | 
| 105 107 | 
             
                    subject.send(:template_name_to_apply)
         | 
| 106 108 | 
             
                  end
         | 
| 107 109 |  | 
| 108 110 | 
             
                  it 'should return the single template if the user says yes' do
         | 
| 109 111 | 
             
                    allow(subject).to receive(:pr_template_options).and_return([template])
         | 
| 110 | 
            -
                    allow( | 
| 112 | 
            +
                    allow(highline_wrapper).to receive(:ask_yes_no).and_return(true)
         | 
| 111 113 | 
             
                    expect(subject.send(:template_name_to_apply)).to eq(template)
         | 
| 112 114 | 
             
                  end
         | 
| 113 115 |  | 
| 114 116 | 
             
                  it 'should return nil if the user says no' do
         | 
| 115 117 | 
             
                    allow(subject).to receive(:pr_template_options).and_return([template])
         | 
| 116 | 
            -
                    allow( | 
| 118 | 
            +
                    allow(highline_wrapper).to receive(:ask_yes_no).and_return(false)
         | 
| 117 119 | 
             
                    expect(subject.send(:template_name_to_apply)).to eq(nil)
         | 
| 118 120 | 
             
                  end
         | 
| 119 121 | 
             
                end
         | 
| @@ -124,19 +126,19 @@ describe GitHelper::GitHubPullRequest do | |
| 124 126 |  | 
| 125 127 | 
             
                  it 'should call the CLI to ask which of multiple templates to apply' do
         | 
| 126 128 | 
             
                    allow(subject).to receive(:pr_template_options).and_return([template1, template2])
         | 
| 127 | 
            -
                    expect( | 
| 129 | 
            +
                    expect(highline_wrapper).to receive(:ask_options).and_return(template1)
         | 
| 128 130 | 
             
                    subject.send(:template_name_to_apply)
         | 
| 129 131 | 
             
                  end
         | 
| 130 132 |  | 
| 131 133 | 
             
                  it 'should return the answer template if the user says yes' do
         | 
| 132 134 | 
             
                    allow(subject).to receive(:pr_template_options).and_return([template1, template2])
         | 
| 133 | 
            -
                    allow( | 
| 135 | 
            +
                    allow(highline_wrapper).to receive(:ask_options).and_return(template1)
         | 
| 134 136 | 
             
                    expect(subject.send(:template_name_to_apply)).to eq(template1)
         | 
| 135 137 | 
             
                  end
         | 
| 136 138 |  | 
| 137 139 | 
             
                  it 'should return nil if the user says no' do
         | 
| 138 140 | 
             
                    allow(subject).to receive(:pr_template_options).and_return([template1, template2])
         | 
| 139 | 
            -
                    allow( | 
| 141 | 
            +
                    allow(highline_wrapper).to receive(:ask_options).and_return('None')
         | 
| 140 142 | 
             
                    expect(subject.send(:template_name_to_apply)).to eq(nil)
         | 
| 141 143 | 
             
                  end
         | 
| 142 144 | 
             
                end
         | 
| @@ -151,13 +153,13 @@ describe GitHelper::GitHubPullRequest do | |
| 151 153 |  | 
| 152 154 | 
             
              describe '#pr_id' do
         | 
| 153 155 | 
             
                it 'should ask the CLI for the code request ID' do
         | 
| 154 | 
            -
                  expect( | 
| 156 | 
            +
                  expect(highline_wrapper).to receive(:ask).and_return(Faker::Number.number)
         | 
| 155 157 | 
             
                  subject.send(:pr_id)
         | 
| 156 158 | 
             
                end
         | 
| 157 159 |  | 
| 158 160 | 
             
                it 'should equal an integer' do
         | 
| 159 161 | 
             
                  pr_id = Faker::Number.number
         | 
| 160 | 
            -
                  expect( | 
| 162 | 
            +
                  expect(highline_wrapper).to receive(:ask).and_return(pr_id)
         | 
| 161 163 | 
             
                  expect(subject.send(:pr_id)).to eq(pr_id)
         | 
| 162 164 | 
             
                end
         | 
| 163 165 | 
             
              end
         | 
| @@ -167,16 +169,16 @@ describe GitHelper::GitHubPullRequest do | |
| 167 169 |  | 
| 168 170 | 
             
                before do
         | 
| 169 171 | 
             
                  allow(subject).to receive(:existing_project).and_return(project)
         | 
| 170 | 
            -
                  allow( | 
| 172 | 
            +
                  allow(highline_wrapper).to receive(:ask_options)
         | 
| 171 173 | 
             
                end
         | 
| 172 174 |  | 
| 173 175 | 
             
                it 'should ask the CLI for the merge_method' do
         | 
| 174 | 
            -
                  expect( | 
| 176 | 
            +
                  expect(highline_wrapper).to receive(:ask_options).and_return('merge')
         | 
| 175 177 | 
             
                  subject.send(:merge_method)
         | 
| 176 178 | 
             
                end
         | 
| 177 179 |  | 
| 178 180 | 
             
                it 'should be a string' do
         | 
| 179 | 
            -
                  allow( | 
| 181 | 
            +
                  allow(highline_wrapper).to receive(:ask_options).and_return('merge')
         | 
| 180 182 | 
             
                  expect(subject.send(:merge_method)).to be_a(String)
         | 
| 181 183 | 
             
                end
         | 
| 182 184 |  | 
| @@ -184,7 +186,7 @@ describe GitHelper::GitHubPullRequest do | |
| 184 186 | 
             
                  let(:project) { double(:project, allow_merge_commit: true, allow_squash_merge: false, allow_rebase_merge: false) }
         | 
| 185 187 |  | 
| 186 188 | 
             
                  it 'should not ask the CLI anything' do
         | 
| 187 | 
            -
                    expect( | 
| 189 | 
            +
                    expect(highline_wrapper).not_to receive(:merge_method)
         | 
| 188 190 | 
             
                    subject.send(:merge_method)
         | 
| 189 191 | 
             
                  end
         | 
| 190 192 | 
             
                end
         | 
| @@ -239,7 +241,7 @@ describe GitHelper::GitHubPullRequest do | |
| 239 241 |  | 
| 240 242 | 
             
              describe '#existing_pr' do
         | 
| 241 243 | 
             
                it 'should call the octokit client' do
         | 
| 242 | 
            -
                  allow( | 
| 244 | 
            +
                  allow(highline_wrapper).to receive(:ask).and_return(Faker::Number.number)
         | 
| 243 245 | 
             
                  expect(octokit_client_client).to receive(:pull_request).and_return(:pull_request)
         | 
| 244 246 | 
             
                  subject.send(:existing_pr)
         | 
| 245 247 | 
             
                end
         | 
| @@ -0,0 +1,183 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'spec_helper'
         | 
| 4 | 
            +
            require 'git_helper'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            describe GitHelper::Setup do
         | 
| 7 | 
            +
              let(:highline_wrapper) { double(:highline_wrapper, ask: Faker::Lorem.word, ask_yes_no: true) }
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              before do
         | 
| 10 | 
            +
                allow(HighlineWrapper).to receive(:new).and_return(highline_wrapper)
         | 
| 11 | 
            +
                allow(subject).to receive(:puts)
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
              after do
         | 
| 15 | 
            +
                GitHelper::Setup.instance_variable_set('@highline', nil)
         | 
| 16 | 
            +
              end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
              describe '#execute' do
         | 
| 19 | 
            +
                it 'only asks the user one question if the config file does not exist' do
         | 
| 20 | 
            +
                  allow(subject).to receive(:config_file_exists?).and_return(false)
         | 
| 21 | 
            +
                  allow(File).to receive(:exists?).and_return(true)
         | 
| 22 | 
            +
                  expect(highline_wrapper).to receive(:ask_yes_no).and_return(true).exactly(:once)
         | 
| 23 | 
            +
                  allow(subject).to receive(:create_or_update_config_file).and_return(true)
         | 
| 24 | 
            +
                  allow(subject).to receive(:create_or_update_plugin_files)
         | 
| 25 | 
            +
                  subject.execute
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                it 'should ask two questions if the config file exists' do
         | 
| 29 | 
            +
                  allow(subject).to receive(:config_file_exists?).and_return(true)
         | 
| 30 | 
            +
                  allow(File).to receive(:exists?).and_return(true)
         | 
| 31 | 
            +
                  expect(highline_wrapper).to receive(:ask_yes_no).and_return(true).at_least(:twice)
         | 
| 32 | 
            +
                  allow(subject).to receive(:create_or_update_config_file).and_return(true)
         | 
| 33 | 
            +
                  allow(subject).to receive(:create_or_update_plugin_files)
         | 
| 34 | 
            +
                  subject.execute
         | 
| 35 | 
            +
                end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                it 'should call to create or update the config file' do
         | 
| 38 | 
            +
                  allow(File).to receive(:exists?).and_return(true)
         | 
| 39 | 
            +
                  allow(highline_wrapper).to receive(:ask_yes_no).and_return(true)
         | 
| 40 | 
            +
                  expect(subject).to receive(:create_or_update_config_file).and_return(true)
         | 
| 41 | 
            +
                  allow(subject).to receive(:create_or_update_plugin_files)
         | 
| 42 | 
            +
                  subject.execute
         | 
| 43 | 
            +
                end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                it 'should skip if the user opts not to continue' do
         | 
| 46 | 
            +
                  allow(File).to receive(:exists?).and_return(true)
         | 
| 47 | 
            +
                  allow(subject).to receive(:config_file_exists?).and_return(true)
         | 
| 48 | 
            +
                  allow(highline_wrapper).to receive(:ask_yes_no).and_return(false)
         | 
| 49 | 
            +
                  expect(subject).not_to receive(:create_or_update_config_file)
         | 
| 50 | 
            +
                  expect(subject).not_to receive(:create_or_update_plugin_files)
         | 
| 51 | 
            +
                  subject.execute
         | 
| 52 | 
            +
                end
         | 
| 53 | 
            +
              end
         | 
| 54 | 
            +
             | 
| 55 | 
            +
              describe '#create_or_update_config_file' do
         | 
| 56 | 
            +
                it 'should generate the file based on the answers to the questions' do
         | 
| 57 | 
            +
                  expect(subject).to receive(:generate_file_contents)
         | 
| 58 | 
            +
                  allow(File).to receive(:open).and_return(nil)
         | 
| 59 | 
            +
                  subject.send(:create_or_update_config_file)
         | 
| 60 | 
            +
                end
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                it 'should open the file for writing' do
         | 
| 63 | 
            +
                  allow(subject).to receive(:generate_file_contents)
         | 
| 64 | 
            +
                  expect(File).to receive(:open).and_return(nil)
         | 
| 65 | 
            +
                  subject.send(:create_or_update_config_file)
         | 
| 66 | 
            +
                end
         | 
| 67 | 
            +
              end
         | 
| 68 | 
            +
             | 
| 69 | 
            +
              describe '#config_file_exists?' do
         | 
| 70 | 
            +
                it 'should return true if the file exists' do
         | 
| 71 | 
            +
                  allow(File).to receive(:exist?).and_return(true)
         | 
| 72 | 
            +
                  expect(subject.send(:config_file_exists?)).to eq(true)
         | 
| 73 | 
            +
                end
         | 
| 74 | 
            +
             | 
| 75 | 
            +
                it 'should return false if the file does not exist' do
         | 
| 76 | 
            +
                  allow(File).to receive(:exist?).and_return(false)
         | 
| 77 | 
            +
                  expect(subject.send(:config_file_exists?)).to eq(false)
         | 
| 78 | 
            +
                end
         | 
| 79 | 
            +
              end
         | 
| 80 | 
            +
             | 
| 81 | 
            +
              describe '#ask_question' do
         | 
| 82 | 
            +
                it 'should use highline to ask a question' do
         | 
| 83 | 
            +
                  expect(highline_wrapper).to receive(:ask).and_return(Faker::Lorem.word)
         | 
| 84 | 
            +
                  subject.send(:ask_question, Faker::Lorem.sentence)
         | 
| 85 | 
            +
                end
         | 
| 86 | 
            +
             | 
| 87 | 
            +
                it 'should return the answer if it is given' do
         | 
| 88 | 
            +
                  answer = Faker::Lorem.sentence
         | 
| 89 | 
            +
                  allow(highline_wrapper).to receive(:ask).and_return(answer)
         | 
| 90 | 
            +
                  expect(subject.send(:ask_question, Faker::Lorem.sentence)).to be(answer)
         | 
| 91 | 
            +
                end
         | 
| 92 | 
            +
              end
         | 
| 93 | 
            +
             | 
| 94 | 
            +
              describe '#generate_file_contents' do
         | 
| 95 | 
            +
                it 'should ask two yes/no questions' do
         | 
| 96 | 
            +
                  expect(highline_wrapper).to receive(:ask_yes_no).exactly(2).times.and_return(false)
         | 
| 97 | 
            +
                  subject.send(:generate_file_contents)
         | 
| 98 | 
            +
                end
         | 
| 99 | 
            +
             | 
| 100 | 
            +
                it 'should ask two additional questions for each time the user says yes' do
         | 
| 101 | 
            +
                  allow(highline_wrapper).to receive(:ask_yes_no).exactly(2).times.and_return(true, false)
         | 
| 102 | 
            +
                  expect(subject).to receive(:ask_question).exactly(2).times.and_return(Faker::Lorem.word)
         | 
| 103 | 
            +
                  subject.send(:generate_file_contents)
         | 
| 104 | 
            +
                end
         | 
| 105 | 
            +
             | 
| 106 | 
            +
                it 'should ask four additional questions for each time the user says yes' do
         | 
| 107 | 
            +
                  allow(highline_wrapper).to receive(:ask_yes_no).exactly(2).times.and_return(true)
         | 
| 108 | 
            +
                  expect(subject).to receive(:ask_question).exactly(4).times.and_return(Faker::Lorem.word)
         | 
| 109 | 
            +
                  subject.send(:generate_file_contents)
         | 
| 110 | 
            +
                end
         | 
| 111 | 
            +
             | 
| 112 | 
            +
                it 'should return a string no matter what' do
         | 
| 113 | 
            +
                  allow(highline_wrapper).to receive(:ask_yes_no).exactly(2).times.and_return(true)
         | 
| 114 | 
            +
                  allow(subject).to receive(:ask_question).exactly(4).times.and_return(Faker::Lorem.word)
         | 
| 115 | 
            +
                  expect(subject.send(:generate_file_contents)).to be_a(String)
         | 
| 116 | 
            +
                end
         | 
| 117 | 
            +
              end
         | 
| 118 | 
            +
             | 
| 119 | 
            +
              describe '#create_or_update_plugin_files' do
         | 
| 120 | 
            +
                let(:plugins) do
         | 
| 121 | 
            +
                  [
         | 
| 122 | 
            +
                    {
         | 
| 123 | 
            +
                      name: 'plugin-file-one'
         | 
| 124 | 
            +
                    },
         | 
| 125 | 
            +
                    {
         | 
| 126 | 
            +
                      name: 'plugin-file-two'
         | 
| 127 | 
            +
                    }
         | 
| 128 | 
            +
                  ]
         | 
| 129 | 
            +
                end
         | 
| 130 | 
            +
             | 
| 131 | 
            +
                let(:plugins_json) do
         | 
| 132 | 
            +
                  "[
         | 
| 133 | 
            +
                    {
         | 
| 134 | 
            +
                      \"name\": \"plugin-file-one\"
         | 
| 135 | 
            +
                    },
         | 
| 136 | 
            +
                    {
         | 
| 137 | 
            +
                      \"name\": \"plugin-file-two\"
         | 
| 138 | 
            +
                    }
         | 
| 139 | 
            +
                  ]"
         | 
| 140 | 
            +
                end
         | 
| 141 | 
            +
             | 
| 142 | 
            +
                before do
         | 
| 143 | 
            +
                  allow_any_instance_of(GitHelper::GitConfigReader).to receive(:github_token).and_return(Faker::Internet.password)
         | 
| 144 | 
            +
                  allow_any_instance_of(GitHelper::GitConfigReader).to receive(:github_user).and_return(Faker::Internet.username)
         | 
| 145 | 
            +
                end
         | 
| 146 | 
            +
             | 
| 147 | 
            +
                it 'should create the directory if it does not exist' do
         | 
| 148 | 
            +
                  allow(File).to receive(:exist?).and_return(false)
         | 
| 149 | 
            +
                  allow(File).to receive(:open).and_return(nil)
         | 
| 150 | 
            +
                  expect(Dir).to receive(:mkdir)
         | 
| 151 | 
            +
                  allow(subject).to receive(:`).and_return(plugins_json)
         | 
| 152 | 
            +
                  allow(JSON).to receive(:parse).and_return(plugins)
         | 
| 153 | 
            +
                  subject.send(:create_or_update_plugin_files)
         | 
| 154 | 
            +
                end
         | 
| 155 | 
            +
             | 
| 156 | 
            +
                it 'should not create the directory if it already exists' do
         | 
| 157 | 
            +
                  allow(File).to receive(:exist?).and_return(true)
         | 
| 158 | 
            +
                  allow(File).to receive(:open).and_return(nil)
         | 
| 159 | 
            +
                  expect(Dir).not_to receive(:mkdir)
         | 
| 160 | 
            +
                  allow(subject).to receive(:`).and_return(plugins_json)
         | 
| 161 | 
            +
                  allow(JSON).to receive(:parse).and_return(plugins)
         | 
| 162 | 
            +
                  subject.send(:create_or_update_plugin_files)
         | 
| 163 | 
            +
                end
         | 
| 164 | 
            +
             | 
| 165 | 
            +
                it 'should curl the GitHub API' do
         | 
| 166 | 
            +
                  allow(Dir).to receive(:mkdir).and_return(true)
         | 
| 167 | 
            +
                  allow(File).to receive(:exists?).and_return(true)
         | 
| 168 | 
            +
                  allow(File).to receive(:open).and_return(nil)
         | 
| 169 | 
            +
                  allow(subject).to receive(:`).and_return(plugins_json)
         | 
| 170 | 
            +
                  expect(JSON).to receive(:parse).with(plugins_json).and_return(plugins)
         | 
| 171 | 
            +
                  subject.send(:create_or_update_plugin_files)
         | 
| 172 | 
            +
                end
         | 
| 173 | 
            +
             | 
| 174 | 
            +
                it 'should go through the loop for each plugin' do
         | 
| 175 | 
            +
                  allow(Dir).to receive(:mkdir).and_return(true)
         | 
| 176 | 
            +
                  allow(File).to receive(:exists?).and_return(true)
         | 
| 177 | 
            +
                  allow(File).to receive(:open).and_return(nil)
         | 
| 178 | 
            +
                  expect(subject).to receive(:`).exactly(3).times
         | 
| 179 | 
            +
                  allow(JSON).to receive(:parse).and_return(plugins)
         | 
| 180 | 
            +
                  subject.send(:create_or_update_plugin_files)
         | 
| 181 | 
            +
                end
         | 
| 182 | 
            +
              end
         | 
| 183 | 
            +
            end
         |