spec/achecker/api_spec.rb in achecker-0.0.8 vs spec/achecker/api_spec.rb in achecker-0.0.9

- old
+ new

@@ -6,34 +6,50 @@ describe Api do describe "#check" do - it "should check url" do - id = "12345678" - url = CGI::escape("http://example.com/some-resource/") - xml = <<-eos + let(:id) { "12345678" } + let(:url) { CGI::escape("http://example.com/some-resource/") } + let(:xml) { <<-eos <?xml version="1.0" encoding="ISO-8859-1"?> <resultset> <summary> <NumOfErrors>30</NumOfErrors> </summary> </resultset> eos + } + + context "when achecker url is not provided" do + it "should check url" do + stub_request(:get, "https://achecker.ca/checkacc.php") + .with(:query => {"uri" => url, "id" => id, "output" => "rest"}) + .to_return(:body => xml) + api = Api.new(id) - stub_request(:get, "https://achecker.ca/checkacc.php") - .with(:query => {"uri" => url, "id" => id, "output" => "rest"}) - .to_return(:body => xml) + result = api.check(url) - api = Api.new(id) + expect(result.url).to eq(url) + expect(result.num_errors).to eq(30) + end + end - result = api.check(url) + context "when achecker url is provided" do + it "should check url" do + stub_request(:get, "https://some.url/checkacc.php") + .with(:query => {"uri" => url, "id" => id, "output" => "rest"}) + .to_return(:body => xml) - expect(result.url).to eq(url) - expect(result.num_errors).to eq(30) - end + api = Api.new(id, "https://some.url/checkacc.php") + result = api.check(url) + + expect(result.url).to eq(url) + expect(result.num_errors).to eq(30) + end + end end end end