Skip to content

Commit

Permalink
minitest
Browse files Browse the repository at this point in the history
  • Loading branch information
grosser committed Sep 13, 2013
1 parent becdffb commit 0eaf390
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 65 deletions.
3 changes: 2 additions & 1 deletion Gemfile
Expand Up @@ -4,7 +4,8 @@ gem "httparty", ">= 0.6.1"

group :development do
gem "mocha"
gem "shoulda"
gem "minitest"
gem "minitest-colorize"
gem "jeweler"
gem "rcov", :platform => :ruby_18
end
22 changes: 4 additions & 18 deletions Gemfile.lock
@@ -1,14 +1,7 @@
GEM
remote: https://rubygems.org/
specs:
activesupport (4.0.0)
i18n (~> 0.6, >= 0.6.4)
minitest (~> 4.2)
multi_json (~> 1.3)
thread_safe (~> 0.1)
tzinfo (~> 0.3.37)
addressable (2.3.5)
atomic (1.1.14)
builder (3.2.2)
faraday (0.8.8)
multipart-post (~> 1.2.0)
Expand All @@ -26,7 +19,6 @@ GEM
multi_json (~> 1.0)
multi_xml (>= 0.5.2)
httpauth (0.2.0)
i18n (0.6.5)
jeweler (1.8.7)
builder
bundler (~> 1.0)
Expand All @@ -41,6 +33,8 @@ GEM
multi_json (>= 1.5)
metaclass (0.0.1)
minitest (4.7.5)
minitest-colorize (0.0.5)
minitest (>= 2.0)
mocha (0.14.0)
metaclass (~> 0.0.1)
multi_json (1.8.0)
Expand All @@ -59,22 +53,14 @@ GEM
rcov (1.0.0)
rdoc (4.0.1)
json (~> 1.4)
shoulda (3.5.0)
shoulda-context (~> 1.0, >= 1.0.1)
shoulda-matchers (>= 1.4.1, < 3.0)
shoulda-context (1.1.5)
shoulda-matchers (2.3.0)
activesupport (>= 3.0.0)
thread_safe (0.1.3)
atomic
tzinfo (0.3.37)

PLATFORMS
ruby

DEPENDENCIES
httparty (>= 0.6.1)
jeweler
minitest
minitest-colorize
mocha
rcov
shoulda
Empty file modified bin/bitly 100644 → 100755
Empty file.
Empty file modified bin/isgd 100644 → 100755
Empty file.
Empty file modified bin/mush 100644 → 100755
Empty file.
Empty file modified bin/owly 100644 → 100755
Empty file.
Empty file modified bin/shorten 100644 → 100755
Empty file.
12 changes: 4 additions & 8 deletions test/helper.rb
@@ -1,11 +1,7 @@
require 'rubygems'
require 'test/unit'
require 'mocha'
require 'shoulda'
require 'bundler/setup'
require 'minitest/autorun'
require 'minitest/colorize'
require 'mocha/setup'

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'mush'

class Test::Unit::TestCase
end
68 changes: 30 additions & 38 deletions test/test_mush.rb
@@ -1,66 +1,63 @@
require File.expand_path('../helper', __FILE__)

class TestMush < Test::Unit::TestCase

context "Mush::Service class" do
should "include HTTParty module" do
describe Mush do
describe "Mush::Service class" do
it "include HTTParty module" do
assert Mush::Service.include? HTTParty
end

should "define a #shorten method" do
it "define a #shorten method" do
assert Mush::Service.new.respond_to? :shorten
end

should "raise and exception if use tries to use #shorten method" do
assert_raise Mush::InterfaceMethodNotImplementedError do
it "raise and exception if use tries to use #shorten method" do
assert_raises Mush::InterfaceMethodNotImplementedError do
Mush::Service.new.shorten
end
end

should "add an instance method called 'get' that wrappes the HTTParty#get method" do
it "add an instance method called 'get' that wrappes the HTTParty#get method" do
assert Mush::Service.new.respond_to? :get
end
end

context "All Services" do
setup do
describe "All Services" do
before do
s = Mush::Services
@services = [s::IsGd, s::Bitly]
end

should "be subclasses of Mush::Service" do
it "be subclasses of Mush::Service" do
@services.each do |service|
assert service < Mush::Service, "#{service} extends Mush::Service"
end
end

should "raise an exception if shorten is called with an empty url" do
it "raise an exception if shorten is called with an empty url" do
@services.each do |service|
assert_raise Mush::InvalidURI do
assert_raises Mush::InvalidURI do
service.new.shorten('')
end
end
end

end

context "Service" do
setup do
describe "Service" do
before do
@long_url = "http://www.a_very_long_url.com"
@shortened_url = "http://is.gd/test"
@httparty_response = stub('HTTParty::Response', :body => @shortened_url)
end

context "not authorizable" do

setup do
describe "not authorizable" do
before do
@httparty_response = stub('HTTParty::Response', :body => @shortened_url)
@custom_shortener = 'http://is.gd/api.php?longurl={{url}}'
end

context "IsGd" do
describe "IsGd" do

should "return a shortened url" do
it "return a shortened url" do
Mush::Services::IsGd.any_instance.stubs(:get).with(instance_of(String), instance_of(Hash)).returns(@httparty_response)

isgd = Mush::Services::IsGd.new
Expand All @@ -70,8 +67,8 @@ class TestMush < Test::Unit::TestCase
end
end

context "Custom" do
should "return a shortened url" do
describe "Custom" do
it "return a shortened url" do
Mush::Services::Custom.any_instance.stubs(:get).with(instance_of(String), instance_of(Hash)).returns(@httparty_response)

custom = Mush::Services::Custom.new
Expand All @@ -83,48 +80,43 @@ class TestMush < Test::Unit::TestCase
end
end

context "authorizable" do
setup do
describe "authorizable" do
before do
@response = @shortened_url
end

context "Bitly" do
should "has authentication credentials to return a shortened url" do
describe "Bitly" do
it "has authentication credentials to return a shortened url" do

httparty_response = stub('HTTParty::Response', :[] => @shortened_url)
bitly = Mush::Services::Bitly.new

assert_raise Mush::InvalidAuthorizationData do
assert_raises Mush::InvalidAuthorizationData do
bitly.shorten(@long_url)
end

bitly.login = "login"
bitly.apikey = "apikey"

assert_nothing_raised do
bitly.shorten(@long_url)
end
bitly.shorten(@long_url)

Mush::Services::Bitly.any_instance.stubs(:get).with(instance_of(String), instance_of(Hash)).returns(httparty_response)
assert_equal @shortened_url, bitly.shorten(@long_url)
end
end

context "Owly" do
should "has authentication credentials to return a shortened url" do
describe "Owly" do
it "has authentication credentials to return a shortened url" do

httparty_response = stub('HTTParty::Response', :[] => @shortened_url)
owly = Mush::Services::Owly.new

assert_raise Mush::InvalidAuthorizationData do
assert_raises Mush::InvalidAuthorizationData do
owly.shorten(@long_url)
end

owly.apikey = "apikey"

assert_nothing_raised do
owly.shorten(@long_url)
end
owly.shorten(@long_url)

Mush::Services::Owly.any_instance.stubs(:get).with(instance_of(String), instance_of(Hash)).returns(httparty_response)
end
Expand Down

0 comments on commit 0eaf390

Please sign in to comment.