Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[ADD] written test cases.

  • Loading branch information...
commit a7ca3e4be9e13b5b3150a486d24a2288e9758d8a 1 parent 0390ad5
Bagwan Pankaj authored

Showing 2 changed files with 98 additions and 3 deletions. Show diff stats Hide diff stats

  1. +3 1 .rspec
  2. +95 2 spec/shortly_spec.rb
4 .rspec
... ... @@ -1 +1,3 @@
1   ---color
  1 +--colour
  2 +--format doc
  3 +--backtrace
97 spec/shortly_spec.rb
... ... @@ -1,7 +1,100 @@
1 1 require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2 2
3 3 describe "Shortly" do
4   - it "fails" do
5   - fail "hey buddy, you should probably rename this file and start specing for real"
  4 +
  5 + #tests for client googl
  6 + describe "Googl" do
  7 + before(:all) do
  8 + @long_url = "http://bagwanpankaj.com"
  9 + @invalid_url = "bagwanpankaj.com"
  10 + end
  11 +
  12 + it "should get a short url from googl(provided valid url)" do
  13 + res = Shortly::Clients::Googl.shorten(@long_url)
  14 + res.short_url.should_not be_empty
  15 + res.short_url.should == "http://goo.gl/17pbM"
  16 + end
  17 +
  18 + it "result should be an instance of OpenStruct" do
  19 + res = Shortly::Clients::Googl.shorten(@long_url)
  20 + res.should be_an_instance_of(OpenStruct)
  21 + end
  22 +
  23 + it "should not be added to history(by default)" do
  24 + res = Shortly::Clients::Googl.shorten(@long_url)
  25 + res.added_to_history.should be_an_instance_of(FalseClass)
  26 + end
  27 +
  28 + it "should throw an error on wrong uri format" do
  29 + lambda do
  30 + Shortly::Clients::Googl.shorten(@invalid_url)
  31 + end.should raise_error(Shortly::Errors::InvalidURIError)
  32 + end
  33 +
  34 + it "should raise MethodNotAvailableError if method is not implemented for" do
  35 + lambda do
  36 + Shortly::Clients::Googl.expand(@long_url)
  37 + end.should raise_error(Shortly::Errors::MethodNotAvailableError)
  38 + end
6 39 end
  40 +
  41 + #tests for client isgd
  42 + describe "Isgd" do
  43 + before(:all) do
  44 + @long_url = "http://bagwanpankaj.com"
  45 + @invalid_url = "bagwanpankaj.com"
  46 + end
  47 +
  48 + it "should get a short url from googl(provided valid url)" do
  49 + res = Shortly::Clients::Isgd.shorten(@long_url)
  50 + res.shorturl.should_not be_empty
  51 + res.shorturl.should == "http://is.gd/5V9Unz"
  52 + end
  53 +
  54 + it "result should be an instance of OpenStruct" do
  55 + res = Shortly::Clients::Isgd.shorten(@long_url)
  56 + res.should be_an_instance_of(OpenStruct)
  57 + end
  58 +
  59 + it "should throw an error on wrong uri format" do
  60 + lambda do
  61 + Shortly::Clients::Isgd.shorten(@invalid_url)
  62 + end.should raise_error(Shortly::Errors::InvalidURIError)
  63 + end
  64 +
  65 + it "should raise MethodNotAvailableError if method is not implemented for" do
  66 + lambda do
  67 + Shortly::Clients::Isgd.expand(@long_url)
  68 + end.should raise_error(Shortly::Errors::MethodNotAvailableError)
  69 + end
  70 + end
  71 +
  72 + #tests for client bitly
  73 + describe "Bitly" do
  74 + before(:all) do
  75 + Shortly::Clients::Bitly.login = "modulo9"
  76 + Shortly::Clients::Bitly.apiKey = "R_0f17f32f11de7e3e953de49c6f255104"
  77 + @long_url = "http://bagwanpankaj.com"
  78 + @invalid_url = "bagwanpankaj.com"
  79 + end
  80 +
  81 + it "should get a short url from googl(provided valid url)" do
  82 + res = Shortly::Clients::Bitly.shorten(@long_url)
  83 + res.url.should_not be_empty
  84 + res.url.should == "http://bit.ly/dUdiIJ"
  85 + end
  86 +
  87 + it "result should be an instance of OpenStruct" do
  88 + res = Shortly::Clients::Bitly.shorten(@long_url)
  89 + res.should be_an_instance_of(OpenStruct)
  90 + end
  91 +
  92 + it "should throw an error on wrong uri format" do
  93 + lambda do
  94 + Shortly::Clients::Bitly.shorten(@invalid_url)
  95 + end.should raise_error(Shortly::Errors::InvalidURIError)
  96 + end
  97 +
  98 + end
  99 +
7 100 end

0 comments on commit a7ca3e4

Please sign in to comment.
Something went wrong with that request. Please try again.