|
302 | 302 | before { |
303 | 303 | api.should_receive(:send_api_request).with(:getMeetings, {}). |
304 | 304 | and_return(flattened_response) |
305 | | - formatter_mock = mock(BigBlueButton::BigBlueButtonFormatter) |
306 | | - formatter_mock.should_receive(:flatten_objects).with(:meetings, :meeting) |
307 | | - BigBlueButton::BigBlueButtonFormatter.should_receive(:new).and_return(formatter_mock) |
| 305 | + formatter_double = double(BigBlueButton::BigBlueButtonFormatter) |
| 306 | + formatter_double.should_receive(:flatten_objects).with(:meetings, :meeting) |
| 307 | + BigBlueButton::BigBlueButtonFormatter.should_receive(:new).and_return(formatter_double) |
308 | 308 | BigBlueButton::BigBlueButtonFormatter.should_receive(:format_meeting).with(meeting_hash1) |
309 | 309 | BigBlueButton::BigBlueButtonFormatter.should_receive(:format_meeting).with(meeting_hash2) |
310 | 310 | } |
|
381 | 381 | describe "#last_http_response" do |
382 | 382 | # we test this through a #test_connection call |
383 | 383 |
|
384 | | - let(:request_mock) { mock } |
| 384 | + let(:request_double) { double } |
385 | 385 | before { |
386 | 386 | api.should_receive(:get_url) |
387 | 387 | # this return value will be stored in @http_response |
388 | | - api.should_receive(:send_request).and_return(request_mock) |
| 388 | + api.should_receive(:send_request).and_return(request_double) |
389 | 389 | # to return fast from #send_api_request |
390 | | - request_mock.should_receive(:body).and_return("") |
| 390 | + request_double.should_receive(:body).and_return("") |
391 | 391 | api.test_connection |
392 | 392 | } |
393 | | - it { api.last_http_response.should == request_mock } |
| 393 | + it { api.last_http_response.should == request_double } |
394 | 394 | end |
395 | 395 |
|
396 | 396 | describe "#last_xml_response" do |
397 | 397 | # we test this through a #test_connection call |
398 | 398 |
|
399 | | - let(:request_mock) { mock } |
| 399 | + let(:request_double) { double } |
400 | 400 | let(:expected_xml) { "<response><returncode>SUCCESS</returncode></response>" } |
401 | 401 | before { |
402 | 402 | api.should_receive(:get_url) |
403 | | - api.should_receive(:send_request).and_return(request_mock) |
404 | | - request_mock.should_receive(:body).at_least(1).and_return(expected_xml) |
| 403 | + api.should_receive(:send_request).and_return(request_double) |
| 404 | + request_double.should_receive(:body).at_least(1).and_return(expected_xml) |
405 | 405 | api.test_connection |
406 | 406 | } |
407 | 407 | it { api.last_xml_response.should == expected_xml } |
|
503 | 503 | let(:data) { "any data" } |
504 | 504 | let(:url) { "http://test-server:8080?param1=value1&checksum=12345" } |
505 | 505 | let(:make_request) { api.send_api_request(method, params, data) } |
506 | | - let(:response_mock) { mock() } # mock of what send_request() would return |
| 506 | + let(:response_double) { double() } # mock of what send_request() would return |
507 | 507 |
|
508 | 508 | before { api.should_receive(:get_url).with(method, params).and_return([url, nil]) } |
509 | 509 |
|
510 | 510 | context "returns an empty hash if the response body is empty" do |
511 | 511 | before do |
512 | | - api.should_receive(:send_request).with(url, data).and_return(response_mock) |
513 | | - response_mock.should_receive(:body).and_return("") |
| 512 | + api.should_receive(:send_request).with(url, data).and_return(response_double) |
| 513 | + response_double.should_receive(:body).and_return("") |
514 | 514 | end |
515 | 515 | it { make_request.should == { } } |
516 | 516 | end |
517 | 517 |
|
518 | 518 | context "hashfies and validates the response body" do |
519 | 519 | before do |
520 | | - api.should_receive(:send_request).with(url, data).and_return(response_mock) |
521 | | - response_mock.should_receive(:body).twice.and_return("response-body") |
| 520 | + api.should_receive(:send_request).with(url, data).and_return(response_double) |
| 521 | + response_double.should_receive(:body).twice.and_return("response-body") |
522 | 522 | end |
523 | 523 |
|
524 | 524 | context "checking if it has a :response key" do |
|
536 | 536 | let(:response) { { :returncode => "SUCCESS" } } |
537 | 537 | let(:formatted_response) { { :returncode => true, :messageKey => "", :message => "" } } |
538 | 538 | before do |
539 | | - api.should_receive(:send_request).with(url, data).and_return(response_mock) |
540 | | - response_mock.should_receive(:body).twice.and_return("response-body") |
| 539 | + api.should_receive(:send_request).with(url, data).and_return(response_double) |
| 540 | + response_double.should_receive(:body).twice.and_return("response-body") |
541 | 541 | BigBlueButton::BigBlueButtonHash.should_receive(:from_xml).with("response-body").and_return(response) |
542 | 542 |
|
543 | 543 | # here starts the validation |
544 | 544 | # doesn't test the resulting format, only that the formatter was called |
545 | | - formatter_mock = mock(BigBlueButton::BigBlueButtonFormatter) |
546 | | - BigBlueButton::BigBlueButtonFormatter.should_receive(:new).with(response).and_return(formatter_mock) |
547 | | - formatter_mock.should_receive(:default_formatting).and_return(formatted_response) |
| 545 | + formatter_double = double(BigBlueButton::BigBlueButtonFormatter) |
| 546 | + BigBlueButton::BigBlueButtonFormatter.should_receive(:new).with(response).and_return(formatter_double) |
| 547 | + formatter_double.should_receive(:default_formatting).and_return(formatted_response) |
548 | 548 | end |
549 | 549 | it { make_request } |
550 | 550 | end |
|
553 | 553 | let(:response) { { :returncode => true } } |
554 | 554 | let(:formatted_response) { { } } |
555 | 555 | before do |
556 | | - api.should_receive(:send_request).with(url, data).and_return(response_mock) |
557 | | - response_mock.should_receive(:body).twice.and_return("response-body") |
| 556 | + api.should_receive(:send_request).with(url, data).and_return(response_double) |
| 557 | + response_double.should_receive(:body).twice.and_return("response-body") |
558 | 558 | BigBlueButton::BigBlueButtonHash.should_receive(:from_xml).with("response-body").and_return(response) |
559 | 559 |
|
560 | | - formatter_mock = mock(BigBlueButton::BigBlueButtonFormatter) |
561 | | - BigBlueButton::BigBlueButtonFormatter.should_receive(:new).with(response).and_return(formatter_mock) |
562 | | - formatter_mock.should_receive(:default_formatting).and_return(formatted_response) |
| 560 | + formatter_double = double(BigBlueButton::BigBlueButtonFormatter) |
| 561 | + BigBlueButton::BigBlueButtonFormatter.should_receive(:new).with(response).and_return(formatter_double) |
| 562 | + formatter_double.should_receive(:default_formatting).and_return(formatted_response) |
563 | 563 | end |
564 | 564 | it { expect { make_request }.to raise_error(BigBlueButton::BigBlueButtonException) } |
565 | 565 | end |
|
571 | 571 | let(:res) { Net::HTTPResponse.new(1.0, '200', 'OK') } |
572 | 572 |
|
573 | 573 | before do |
574 | | - @http_mock = mock(Net::HTTP) |
575 | | - @http_mock.should_receive(:"open_timeout=").with(api.timeout) |
576 | | - @http_mock.should_receive(:"read_timeout=").with(api.timeout) |
577 | | - Net::HTTP.should_receive(:new).with("test-server", 8080).and_return(@http_mock) |
| 574 | + @http_double = double(Net::HTTP) |
| 575 | + @http_double.should_receive(:"open_timeout=").with(api.timeout) |
| 576 | + @http_double.should_receive(:"read_timeout=").with(api.timeout) |
| 577 | + Net::HTTP.should_receive(:new).with("test-server", 8080).and_return(@http_double) |
578 | 578 | res.stub(:body) { "ok" } |
579 | 579 | end |
580 | 580 |
|
581 | 581 | context "standard case" do |
582 | | - before { @http_mock.should_receive(:get).with("/res?param1=value1&checksum=12345", {}).and_return(res) } |
| 582 | + before { @http_double.should_receive(:get).with("/res?param1=value1&checksum=12345", {}).and_return(res) } |
583 | 583 | it { api.send(:send_request, url).should == res } |
584 | 584 | end |
585 | 585 |
|
586 | 586 | context "handles a TimeoutError" do |
587 | | - before { @http_mock.should_receive(:get) { raise TimeoutError } } |
| 587 | + before { @http_double.should_receive(:get) { raise TimeoutError } } |
588 | 588 | it { expect { api.send(:send_request, url) }.to raise_error(BigBlueButton::BigBlueButtonException) } |
589 | 589 | end |
590 | 590 |
|
591 | 591 | context "handles general Exceptions" do |
592 | | - before { @http_mock.should_receive(:get) { raise Exception } } |
| 592 | + before { @http_double.should_receive(:get) { raise Exception } } |
593 | 593 | it { expect { api.send(:send_request, url) }.to raise_error(BigBlueButton::BigBlueButtonException) } |
594 | 594 | end |
595 | 595 |
|
|
598 | 598 | before { |
599 | 599 | path = "/res?param1=value1&checksum=12345" |
600 | 600 | opts = { 'Content-Type' => 'application/xml' } |
601 | | - @http_mock.should_receive(:post).with(path, data, opts).and_return(res) |
| 601 | + @http_double.should_receive(:post).with(path, data, opts).and_return(res) |
602 | 602 | } |
603 | 603 | it { |
604 | 604 | api.send(:send_request, url, data).should == res |
|
607 | 607 |
|
608 | 608 | context "get with headers" do |
609 | 609 | let(:headers_hash) { { :anything => "anything" } } |
610 | | - before { @http_mock.should_receive(:get).with("/res?param1=value1&checksum=12345", headers_hash).and_return(res) } |
| 610 | + before { @http_double.should_receive(:get).with("/res?param1=value1&checksum=12345", headers_hash).and_return(res) } |
611 | 611 | it { |
612 | 612 | api.request_headers = headers_hash |
613 | 613 | api.send(:send_request, url).should == res |
|
620 | 620 | before { |
621 | 621 | path = "/res?param1=value1&checksum=12345" |
622 | 622 | opts = { 'Content-Type' => 'application/xml', :anything => "anything" } |
623 | | - @http_mock.should_receive(:post).with(path, data, opts).and_return(res) |
| 623 | + @http_double.should_receive(:post).with(path, data, opts).and_return(res) |
624 | 624 | } |
625 | 625 | it { |
626 | 626 | api.request_headers = headers_hash |
|
685 | 685 | context "formats the response" do |
686 | 686 | before { |
687 | 687 | api.should_receive(:send_api_request).with(:getRecordings, anything).and_return(flattened_response) |
688 | | - formatter_mock = mock(BigBlueButton::BigBlueButtonFormatter) |
689 | | - formatter_mock.should_receive(:flatten_objects).with(:recordings, :recording) |
| 688 | + formatter_double = double(BigBlueButton::BigBlueButtonFormatter) |
| 689 | + formatter_double.should_receive(:flatten_objects).with(:recordings, :recording) |
690 | 690 | BigBlueButton::BigBlueButtonFormatter.should_receive(:format_recording).with(recording1) |
691 | 691 | BigBlueButton::BigBlueButtonFormatter.should_receive(:format_recording).with(recording2) |
692 | | - BigBlueButton::BigBlueButtonFormatter.should_receive(:new).and_return(formatter_mock) |
| 692 | + BigBlueButton::BigBlueButtonFormatter.should_receive(:new).and_return(formatter_double) |
693 | 693 | } |
694 | 694 | it { api.get_recordings } |
695 | 695 | end |
|
0 commit comments