spec/unit/lita/handlers/github_pr_spec.rb in lita-github-0.1.2 vs spec/unit/lita/handlers/github_pr_spec.rb in lita-github-0.2.0

- old
+ new

@@ -50,11 +50,11 @@ end describe '.merge_pr' do before do @octo_obj = double('Octokit::Client', merge_pull_request: :ohai) - allow(github_pr).to receive(:octo).and_return(@octo_obj) + allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:octo).and_return(@octo_obj) end let(:pr_num) { 42 } let(:ref) { '1234567890' } @@ -165,11 +165,11 @@ describe '.build_pr_status!' do before do @user_obj = { name: 'Tim Heckman' } @cs_obj = { state: 'success' } @octo_obj = double('Octokit::Client', user: @user_obj, combined_status: @cs_obj) - allow(github_pr).to receive(:octo).and_return(@octo_obj) + allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:octo).and_return(@octo_obj) end let(:pr_obj) do { user: { login: 'theckman' }, state: 'closed', merged: true, pr_sha: '1234567890' @@ -215,11 +215,11 @@ end context 'when user has no name set' do before do @octo_obj = double('Octokit::Client', user: {}, combined_status: @cs_obj) - allow(github_pr).to receive(:octo).and_return(@octo_obj) + allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:octo).and_return(@octo_obj) end it 'should not include the real name parenthesis' do github_pr.send(:build_pr_status!, info, pr_obj, full_name) expect(info[:user]).to eql 'theckman' @@ -267,11 +267,11 @@ describe '.build_pr_merge!' do before do @user_obj = { name: 'Tim Heckman' } @octo_obj = double('Octokit::Client', user: @user_obj) - allow(github_pr).to receive(:octo).and_return(@octo_obj) + allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:octo).and_return(@octo_obj) end let(:pr_obj) do { state: :open, mergeable: true @@ -318,11 +318,11 @@ context 'when the user has no name field' do before do @user_obj = {} @octo_obj = double('Octokit::Client', user: @user_obj) - allow(github_pr).to receive(:octo).and_return(@octo_obj) + allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:octo).and_return(@octo_obj) end it 'should set the :merged_by key without parenthesis' do github_pr.send(:build_pr_merge!, info, pr_obj) expect(info[:merged_by]).to eql 'theckman' @@ -350,45 +350,45 @@ end end describe '.build_pr_info' do before do - allow(github_pr).to receive(:build_pr_header!).and_return(nil) - allow(github_pr).to receive(:build_pr_commitinfo!).and_return(nil) - allow(github_pr).to receive(:build_pr_status!).and_return(nil) - allow(github_pr).to receive(:build_pr_merge!).and_return(nil) - allow(github_pr).to receive(:build_pr_comments!).and_return(nil) + allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:build_pr_header!).and_return(nil) + allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:build_pr_commitinfo!).and_return(nil) + allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:build_pr_status!).and_return(nil) + allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:build_pr_merge!).and_return(nil) + allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:build_pr_comments!).and_return(nil) end let(:pr_obj) { :ohai } it 'should return an instance of Hash' do expect(github_pr.send(:build_pr_info, pr_obj, full_name)).to be_an_instance_of Hash end it 'should call .build_pr_header!' do - expect(github_pr).to receive(:build_pr_header!).with({}, pr_obj).and_return(nil) + expect_any_instance_of(Lita::Handlers::GithubPR).to receive(:build_pr_header!).with({}, pr_obj).and_return(nil) github_pr.send(:build_pr_info, pr_obj, full_name) end it 'should call .build_pr_commitinfo!' do - expect(github_pr).to receive(:build_pr_commitinfo!).with({}, pr_obj).and_return(nil) + expect_any_instance_of(Lita::Handlers::GithubPR).to receive(:build_pr_commitinfo!).with({}, pr_obj).and_return(nil) github_pr.send(:build_pr_info, pr_obj, full_name) end it 'should call .build_pr_status!' do - expect(github_pr).to receive(:build_pr_status!).with({}, pr_obj, full_name).and_return(nil) + expect_any_instance_of(Lita::Handlers::GithubPR).to receive(:build_pr_status!).with({}, pr_obj, full_name).and_return(nil) github_pr.send(:build_pr_info, pr_obj, full_name) end it 'should call .build_pr_merge!' do - expect(github_pr).to receive(:build_pr_merge!).with({}, pr_obj).and_return(nil) + expect_any_instance_of(Lita::Handlers::GithubPR).to receive(:build_pr_merge!).with({}, pr_obj).and_return(nil) github_pr.send(:build_pr_info, pr_obj, full_name) end it 'should call .build_pr_comments!' do - expect(github_pr).to receive(:build_pr_comments!).with({}, pr_obj).and_return(nil) + expect_any_instance_of(Lita::Handlers::GithubPR).to receive(:build_pr_comments!).with({}, pr_obj).and_return(nil) github_pr.send(:build_pr_info, pr_obj, full_name) end end describe '.list_line' do @@ -406,11 +406,11 @@ #### describe '.merge_pr' do before do @merge_status = { sha: 'abc456', merged: true, message: 'Pull Request successfully merged' } @octo_obj = double('Octokit::Client', merge_pull_request: @merge_status) - allow(github_pr).to receive(:octo).and_return(@octo_obj) + allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:octo).and_return(@octo_obj) end context 'when all goes well' do it 'should return the response from trying to merge' do expect(github_pr.send(:merge_pr, github_org, github_repo, '42', 'test commit')) @@ -421,11 +421,11 @@ context 'when we hit an exception' do before do @merge_status = { sha: 'abc456', merged: false, message: '*BOOM*' } @octo_obj = double('Octokit::Client') allow(@octo_obj).to receive(:merge_pull_request).and_raise(StandardError.new) - allow(github_pr).to receive(:octo).and_return(@octo_obj) + allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:octo).and_return(@octo_obj) end it 'should return nil' do expect(github_pr.send(:merge_pr, github_org, github_repo, 42, 'test commit')) .to be_nil @@ -443,12 +443,12 @@ base_sha: '0987654321', pr_sha_short: '1234567', user: 'theckman (Tim Heckman)', state: :open, state_str: 'Open', build_status: 'success', mergeable: true, review_comments: 2, comments: 1 } @pr_resp = { fail: false, not_found: false, pr: @pr_info } - allow(github_pr).to receive(:pull_request).and_return(@pr_resp) - allow(github_pr).to receive(:build_pr_info).and_return(@pr_info) + allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:pull_request).and_return(@pr_resp) + allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:build_pr_info).and_return(@pr_info) end it 'should reply with the expeced output' do r = "GrapeDuty/lita-test #42: 'Test Pull Request (Not Real)' :: " \ "https://github.com/GrapeDuty/lita-test/pulls/42\n" \ @@ -470,12 +470,12 @@ base_sha: '0987654321', pr_sha_short: '1234567', user: 'theckman (Tim Heckman)', state: :merged, state_str: 'Merged', build_status: 'success', mergeable: true, merged_by: 'theckman (Tim Heckman)', review_comments: 2, comments: 1 } @pr_resp = { fail: false, not_found: false, pr: @pr_info } - allow(github_pr).to receive(:pull_request).and_return(@pr_resp) - allow(github_pr).to receive(:build_pr_info).and_return(@pr_info) + allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:pull_request).and_return(@pr_resp) + allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:build_pr_info).and_return(@pr_info) end it 'should reply with the expeced output' do r = "GrapeDuty/lita-test #42: 'Test Pull Request (Not Real)' :: " \ "https://github.com/GrapeDuty/lita-test/pulls/42\n" \ @@ -490,11 +490,11 @@ end context 'when the PR was not found' do before do @pr_resp = { fail: true, not_found: true, pr: @pr_info } - allow(github_pr).to receive(:pull_request).and_return(@pr_resp) + allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:pull_request).and_return(@pr_resp) end it 'should reply with the not found error' do send_command("gh pr info #{github_org}/#{github_repo} #42") expect(replies.last).to eql 'Pull request #42 on GrapeDuty/lita-test not found' @@ -506,19 +506,19 @@ before do @cfg_obj = double('Lita::Configuration', pr_merge_enabled: true) @pr_obj = { head: { ref: 'fix-some-bugs' }, title: 'fix bug' } @merge_status = { sha: 'abc456', merged: true, message: 'Pull Request successfully merged' } @octo_obj = double('Octokit::Client', pull_request: @pr_obj) - allow(github_pr).to receive(:octo).and_return(@octo_obj) - allow(github_pr).to receive(:func_disabled?).and_return(false) - allow(github_pr).to receive(:config).and_return(@cfg_obj) - allow(github_pr).to receive(:merge_pr).and_return(@merge_status) + allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:octo).and_return(@octo_obj) + allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:func_disabled?).and_return(false) + allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:config).and_return(@cfg_obj) + allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:merge_pr).and_return(@merge_status) end context 'when command disabled' do before do - allow(github_pr).to receive(:func_disabled?).and_return(true) + allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:func_disabled?).and_return(true) end it 'should no-op and say such' do send_command("shipit #{github_org}/#{github_repo} #42") expect(replies.last).to eql disabled_reply @@ -536,11 +536,11 @@ end end context 'when merging should succeed' do it 'should set the right commit message' do - expect(github_pr).to receive(:merge_pr).with( + expect_any_instance_of(Lita::Handlers::GithubPR).to receive(:merge_pr).with( 'GrapeDuty', 'lita-test', '42', "Merge pull request #42 from GrapeDuty/fix-some-bugs\n\nfix bug" ) send_command('shipit GrapeDuty/lita-test #42') end @@ -552,11 +552,11 @@ end context 'when merging bombs' do before do @merge_status = { sha: 'abc456', merged: false, message: '*BOOM*' } - allow(github_pr).to receive(:merge_pr).and_return(@merge_status) + allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:merge_pr).and_return(@merge_status) end it 'should confirm the failure' do send_command("shipit #{github_org}/#{github_repo} #42") expect(replies.last) @@ -569,11 +569,11 @@ context 'when the API request explodes' do before do @merge_status = { sha: 'abc456', merged: false, message: '*BOOM*' } @octo_obj = double('Octokit::Client', pull_request: @pr_obj) - allow(github_pr).to receive(:merge_pr).and_return(nil) + allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:merge_pr).and_return(nil) end it 'should confirm the failure' do send_command("shipit #{github_org}/#{github_repo} #42") expect(replies.last) @@ -587,12 +587,12 @@ describe '.pr_list' do before do cfg_obj = double('Lita::Configuration') octo_obj = double('Octokit::Client', pull_requests: []) - allow(github_pr).to receive(:octo).and_return(octo_obj) - allow(github_pr).to receive(:config).and_return(cfg_obj) + allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:octo).and_return(octo_obj) + allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:config).and_return(cfg_obj) end context 'when there are no pull requests' do it 'should state that there are no pull requests' do send_command("gh pr list #{github_org}/#{github_repo}") @@ -605,11 +605,11 @@ pr = [ { title: 'Test2', number: 84, html_url: 'nohtmlurl', user: { login: 'theckman' } }, { title: 'Test1', number: 42, html_url: 'htmlurl', user: { login: 'theckman' } } ] octo_obj = double('Octokit::Client', pull_requests: pr) - allow(github_pr).to receive(:octo).and_return(octo_obj) + allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:octo).and_return(octo_obj) end it 'should reply with the PRs' do send_command("gh pr list #{github_org}/#{github_repo}") expect(replies.last).to eql "GrapeDuty/lita-test #84: 'Test2' opened by theckman :: nohtmlurl\n" \ @@ -641,10 +641,10 @@ { title: 'Test3', number: 44, html_url: 'xxx', user: { login: 'theckman' } }, { title: 'Test2', number: 43, html_url: 'xxx', user: { login: 'theckman' } }, { title: 'Test1', number: 42, html_url: 'xxx', user: { login: 'theckman' } } ] octo_obj = double('Octokit::Client', pull_requests: pr) - allow(github_pr).to receive(:octo).and_return(octo_obj) + allow_any_instance_of(Lita::Handlers::GithubPR).to receive(:octo).and_return(octo_obj) end it 'should return the list of ten oldest & ten newest' do send_command("gh pr list #{github_org}/#{github_repo}") expect(replies.last)