@@ -52,17 +52,6 @@ module Code
5252 end
5353 end
5454
55- describe "self.coerce_patterns" do
56- it "returns an array consisting of provided patterns" do
57- patterns = Branch . coerce_patterns 'abc' , 'def' , '123'
58-
59- expect ( patterns . length ) . to eq 3
60- expect ( patterns [ 0 ] ) . to eq 'abc'
61- expect ( patterns [ 1 ] ) . to eq 'def'
62- expect ( patterns [ 2 ] ) . to eq '123'
63- end
64- end
65-
6655 describe "self.matching" do
6756
6857 before do
@@ -180,7 +169,7 @@ module Code
180169
181170 describe "self.find" do
182171 it "creates a new Branch instance with specified name, but makes no System.call" do
183- expect ( System ) . not_to receive ( :call )
172+ expect ( System ) . not_to receive ( :call ) . with ( "branch test_branch" )
184173
185174 branch = Branch . find "test_branch"
186175
@@ -189,7 +178,7 @@ module Code
189178 end
190179 end
191180
192- describe "#== " do
181+ describe "equality comparer " do
193182 it "compares by branch name" do
194183 branch_a = Branch . new "branch-a"
195184 branch_b = Branch . new "branch-b"
@@ -362,15 +351,6 @@ module Code
362351 end
363352
364353 describe "#push" do
365- it "checks if the branch is public before pushing it" do
366- random_branch = Branch . new "random"
367-
368- expect ( random_branch ) . to receive ( :ensure_public! ) . and_return ( true )
369- allow ( System ) . to receive ( :call )
370-
371- random_branch . push
372- end
373-
374354 it "makes a system call for 'push origin branch-name:branch-name'" do
375355 random_branch = Branch . new "random"
376356 allow ( random_branch ) . to receive ( :ensure_public! ) . and_return ( true )
@@ -381,7 +361,7 @@ module Code
381361
382362 it "allows pushing of a public branch" do
383363 random_branch = Branch . new "random"
384- allow ( System ) . to receive ( :call )
364+ allow ( System ) . to receive ( :call ) . with ( "push origin random:random" )
385365 expect { random_branch . push } . not_to raise_error
386366 end
387367
@@ -413,22 +393,6 @@ module Code
413393 end
414394 end
415395
416- describe "#authorize_delete!" do
417- it "raises a ProtectedBranchError for protected branches" do
418- random_branch = Branch . new "random"
419-
420- expect ( random_branch ) . to receive ( :protected? ) . and_return ( true )
421- expect { random_branch . authorize_delete! } . to raise_error Branch ::ProtectedBranchError
422- end
423-
424- it "doesn't raise an error for unprotected branches" do
425- random_branch = Branch . new "random"
426-
427- expect ( random_branch ) . to receive ( :protected? ) . and_return ( false )
428- expect { random_branch . authorize_delete! } . not_to raise_error
429- end
430- end
431-
432396 describe "#message" do
433397 it "returns the capitalized branch name, where dashes are replaced with spaces" do
434398 random_branch = Branch . new "random"
@@ -457,12 +421,17 @@ module Code
457421 end
458422
459423 describe "#has_pull_request?" do
460- it "returns true if #pull_request is not nil, false otherwise" do
461- random_branch = Branch . new "random"
462- expect ( random_branch ) . to receive ( :pull_request ) . and_return ( "something" )
463- expect ( random_branch . has_pull_request? ) . to eq true
464- expect ( random_branch ) . to receive ( :pull_request ) . and_return ( nil )
465- expect ( random_branch . has_pull_request? ) . to eq false
424+ it "returns true if the branch has any pull requests, false otherwise" do
425+ random_branch_1 = Branch . new "random_1"
426+ pull_request_1 = PullRequest . new ( pull_request_info : { html_url : "example.com" } )
427+ pull_request_2 = PullRequest . new ( pull_request_info : { html_url : "example2.com" } )
428+
429+ expect ( PullRequest ) . to receive ( :for_branch ) . with ( random_branch_1 ) . and_return ( [ pull_request_1 , pull_request_2 ] )
430+ expect ( random_branch_1 . has_pull_request? ) . to eq true
431+
432+ random_branch_2 = Branch . new "random_2"
433+ expect ( PullRequest ) . to receive ( :for_branch ) . with ( random_branch_2 ) . and_return ( [ ] )
434+ expect ( random_branch_2 . has_pull_request? ) . to eq false
466435 end
467436 end
468437
@@ -494,76 +463,15 @@ module Code
494463 end
495464 end
496465
497- describe "#pull_request" do
498- it "returns the first item in #pull_requests" do
499- random_branch = Branch . new "random"
500-
501- expect ( random_branch ) . to receive ( :pull_requests ) . and_return ( [ "first" , "second" ] )
502- expect ( random_branch . pull_request ) . to eq "first"
503- end
504-
505- it "returns nil if #pull_requests is empty" do
506- random_branch = Branch . new "random"
507-
508- expect ( random_branch ) . to receive ( :pull_requests ) . and_return ( [ ] )
509- expect ( random_branch . pull_request ) . to eq nil
510- end
511- end
512-
513- describe "#pull_requests" do
514- it "calls 'PullRequest.for_branch'" do
515- random_branch = Branch . new "random"
516- pull_requests = [ Code ::PullRequest . new ( pull_request_info : { } ) ]
517-
518- expect ( PullRequest ) . to receive ( :for_branch ) . with ( random_branch ) . and_return ( pull_requests )
519- expect ( random_branch . pull_requests ) . to eq pull_requests
520- end
521- end
522-
523466 describe "#pull_request_url" do
524- it "returns #pull_request.url " do
467+ it "returns the URL of the first pull request " do
525468 random_branch = Branch . new "random"
526- pull_request = Code ::PullRequest . new ( pull_request_info : { html_url : "example.com" } )
469+ pull_request_1 = PullRequest . new ( pull_request_info : { html_url : "example.com" } )
470+ pull_request_2 = PullRequest . new ( pull_request_info : { html_url : "example2.com" } )
527471
528- expect ( random_branch ) . to receive ( :pull_request ) . and_return ( pull_request )
529- expect ( random_branch . pull_request_url ) . to eq "example.com"
530- end
531- end
532-
533- describe "#ensure_public!" do
534- it "raises error if branch is private" do
535- random_branch = Branch . new "random-local"
536-
537- expect { random_branch . ensure_public! } . to raise_error Branch ::PrivateBranchError
538- end
472+ expect ( PullRequest ) . to receive ( :for_branch ) . and_return ( [ pull_request_1 , pull_request_2 ] )
539473
540- it "raises no error if branch is public" do
541- random_branch = Branch . new "random"
542-
543- expect { random_branch . ensure_public! } . not_to raise_error
544- end
545- end
546-
547- describe "#label_prs" do
548- it "rases a NoPRError if there are no PRs" do
549- random_branch = Branch . new "random"
550-
551- expect ( random_branch ) . to receive ( :has_pull_request? ) . and_return ( false )
552- expect { random_branch . send ( :label_prs , "label" ) } . to raise_error Branch ::NoPRError
553- end
554-
555- it "calls PullRequest#add_label for each pull_request" do
556- random_branch = Branch . new "random"
557-
558- pull_request_a = Code ::PullRequest . new ( pull_request_info : { } )
559- pull_request_b = Code ::PullRequest . new ( pull_request_info : { } )
560-
561- expect ( random_branch ) . to receive ( :pull_requests ) . and_return ( [ pull_request_a , pull_request_b ] ) . twice
562-
563- expect ( pull_request_a ) . to receive ( :add_label ) . with ( "label" )
564- expect ( pull_request_b ) . to receive ( :add_label ) . with ( "label" )
565-
566- expect { random_branch . send ( :label_prs , "label" ) } . not_to raise_error
474+ expect ( random_branch . pull_request_url ) . to eq "example.com"
567475 end
568476 end
569477 end
0 commit comments