|
9 | 9 | # default variables and API object for all tests |
10 | 10 | let(:url) { "http://server.com" } |
11 | 11 | let(:secret) { "1234567890abcdefghijkl" } |
12 | | - let(:debug) { false } |
13 | | - let(:api) { BigBlueButton::BigBlueButtonApi.new(url, secret, version, debug) } |
| 12 | + let(:logger) { Logger.new(STDOUT) } |
| 13 | + let(:api) { BigBlueButton::BigBlueButtonApi.new(url, secret, version, logger) } |
| 14 | + before { logger.level = Logger::INFO } |
14 | 15 |
|
15 | 16 | describe "#initialize" do |
16 | 17 | context "standard initialization" do |
17 | | - subject { BigBlueButton::BigBlueButtonApi.new(url, secret, version, debug) } |
| 18 | + subject { BigBlueButton::BigBlueButtonApi.new(url, secret, version, logger) } |
18 | 19 | it { subject.url.should == url } |
19 | 20 | it { subject.secret.should == secret } |
20 | 21 | it { subject.version.should == version } |
21 | | - it { subject.debug.should == debug } |
| 22 | + it { subject.logger.should == logger } |
22 | 23 | it { subject.timeout.should == 10 } |
23 | 24 | it { subject.supported_versions.should include("0.8") } |
24 | 25 | it { subject.supported_versions.should include("0.81") } |
|
350 | 351 | end |
351 | 352 |
|
352 | 353 | describe "#==" do |
353 | | - let(:api2) { BigBlueButton::BigBlueButtonApi.new(url, secret, version, debug) } |
| 354 | + let(:api2) { BigBlueButton::BigBlueButtonApi.new(url, secret, version, logger) } |
354 | 355 |
|
355 | 356 | context "compares attributes" do |
356 | 357 | it { api.should == api2 } |
357 | 358 | end |
358 | 359 |
|
359 | | - context "differs #debug" do |
360 | | - before { api2.debug = !api.debug } |
| 360 | + context "differs #logger" do |
| 361 | + before { api2.logger = !api.logger } |
361 | 362 | it { api.should_not == api2 } |
362 | 363 | end |
363 | 364 |
|
|
559 | 560 | describe "#send_request" do |
560 | 561 | let(:url) { "http://test-server:8080/res?param1=value1&checksum=12345" } |
561 | 562 | let(:url_parsed) { URI.parse(url) } |
| 563 | + let(:res) { Net::HTTPResponse.new(1.0, '200', 'OK') } |
562 | 564 |
|
563 | 565 | before do |
564 | 566 | @http_mock = mock(Net::HTTP) |
565 | 567 | @http_mock.should_receive(:"open_timeout=").with(api.timeout) |
566 | 568 | @http_mock.should_receive(:"read_timeout=").with(api.timeout) |
567 | 569 | Net::HTTP.should_receive(:new).with("test-server", 8080).and_return(@http_mock) |
| 570 | + res.stub(:body) { "ok" } |
568 | 571 | end |
569 | 572 |
|
570 | 573 | context "standard case" do |
571 | | - before { @http_mock.should_receive(:get).with("/res?param1=value1&checksum=12345", {}).and_return("ok") } |
572 | | - it { api.send(:send_request, url).should == "ok" } |
| 574 | + before { @http_mock.should_receive(:get).with("/res?param1=value1&checksum=12345", {}).and_return(res) } |
| 575 | + it { api.send(:send_request, url).should == res } |
573 | 576 | end |
574 | 577 |
|
575 | 578 | context "handles a TimeoutError" do |
|
586 | 589 | let(:data) { "any data" } |
587 | 590 | before { |
588 | 591 | path = "/res?param1=value1&checksum=12345" |
589 | | - opts = { 'Content-Type' => 'application/x-www-form-urlencoded' } |
590 | | - @http_mock.should_receive(:post).with(path, data, opts).and_return("ok") |
| 592 | + opts = { 'Content-Type' => 'application/xml' } |
| 593 | + @http_mock.should_receive(:post).with(path, data, opts).and_return(res) |
591 | 594 | } |
592 | 595 | it { |
593 | | - api.send(:send_request, url, data).should == "ok" |
| 596 | + api.send(:send_request, url, data).should == res |
594 | 597 | } |
595 | 598 | end |
596 | 599 |
|
597 | 600 | context "get with headers" do |
598 | 601 | let(:headers_hash) { { :anything => "anything" } } |
599 | | - before { @http_mock.should_receive(:get).with("/res?param1=value1&checksum=12345", headers_hash).and_return("ok") } |
| 602 | + before { @http_mock.should_receive(:get).with("/res?param1=value1&checksum=12345", headers_hash).and_return(res) } |
600 | 603 | it { |
601 | 604 | api.request_headers = headers_hash |
602 | | - api.send(:send_request, url).should == "ok" |
| 605 | + api.send(:send_request, url).should == res |
603 | 606 | } |
604 | 607 | end |
605 | 608 |
|
|
608 | 611 | let(:data) { "any data" } |
609 | 612 | before { |
610 | 613 | path = "/res?param1=value1&checksum=12345" |
611 | | - opts = { 'Content-Type' => 'application/x-www-form-urlencoded', :anything => "anything" } |
612 | | - @http_mock.should_receive(:post).with(path, data, opts).and_return("ok") |
| 614 | + opts = { 'Content-Type' => 'application/xml', :anything => "anything" } |
| 615 | + @http_mock.should_receive(:post).with(path, data, opts).and_return(res) |
613 | 616 | } |
614 | 617 | it { |
615 | 618 | api.request_headers = headers_hash |
616 | | - api.send(:send_request, url, data).should == "ok" |
| 619 | + api.send(:send_request, url, data).should == res |
617 | 620 | } |
618 | 621 | end |
619 | 622 | end |
|
0 commit comments