Skip to content

Commit

Permalink
Made gem working out of the box (with a little help from alto) and fi…
Browse files Browse the repository at this point in the history
…xing the tests
  • Loading branch information
mortro committed Nov 18, 2011
1 parent ddeeff7 commit 3b5cbf1
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 27 deletions.
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source :rubygems

gemspec
30 changes: 30 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
PATH
remote: .
specs:
mobilove (0.0.4)
rest-client

GEM
remote: http://rubygems.org/
specs:
diff-lcs (1.1.3)
mime-types (1.17.2)
rake (0.9.2.2)
rest-client (1.6.7)
mime-types (>= 1.16)
rspec (2.7.0)
rspec-core (~> 2.7.0)
rspec-expectations (~> 2.7.0)
rspec-mocks (~> 2.7.0)
rspec-core (2.7.1)
rspec-expectations (2.7.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.7.0)

PLATFORMS
ruby

DEPENDENCIES
mobilove!
rake
rspec
13 changes: 5 additions & 8 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
require 'rake'
require 'rake/testtask'
require 'bundler/gem_tasks'

Rake::TestTask.new do |t|
t.libs << 'lib'
t.pattern = 'test/**/*_test.rb'
t.verbose = false
require 'rspec/core'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) do |spec|
spec.pattern = FileList['spec/**/*_spec.rb']
end

task :spec => :check_dependencies

task :default => :spec
3 changes: 2 additions & 1 deletion lib/mobilove/text.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# coding: utf-8
require 'uri'
require 'iconv'

module Mobilove

Expand All @@ -9,7 +10,7 @@ def initialize(key, route, from)
end

# concat: if true multiple messages will be concatenated if the text has more than 160 chars (70 unicode)
def send(to, message, debug_mode = false, concat = false)
def send_message(to, message, debug_mode = false, concat = false)
url = send_url(to, message, debug_mode, concat)
response = RestClient.get(url)
respond(response)
Expand Down
4 changes: 4 additions & 0 deletions mobilove.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ Gem::Specification.new do |s|
s.summary = "Small wrapper for sending text messages with mobilant.de"
s.description = "Use mobilove to send text messages with Ruby. Account on mobilant.de required."

s.add_dependency 'rest-client'
s.add_development_dependency 'rake'
s.add_development_dependency 'rspec'

s.files = `git ls-files app lib`.split("\n")
s.platform = Gem::Platform::RUBY
s.require_path = 'lib'
Expand Down
12 changes: 12 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__)))
$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')))
require 'mobilove'

require 'rspec'
require 'rspec/autorun'

# require 'ruby-debug'; Debugger.settings[:autoeval] = true; debugger; rubys_debugger = 'annoying'
# require 'ruby-debug/completion'

# Requiring custom spec helpers
Dir[File.dirname(__FILE__) + "/spec_helpers/**/*.rb"].sort.each { |f| require File.expand_path(f) }
43 changes: 25 additions & 18 deletions test/mobilove_test.rb → spec/unit/mobilove_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'rubygems'
require 'mobilove'
require 'rspec'
require 'iconv'

describe "Mobilove" do

Expand All @@ -13,15 +14,15 @@

it "should send text" do
RestClient.should_receive(:get)
@a.send(49123, 'sometext')
@a.send_message(49123, 'sometext')
end

it "should return true" do
@a.send(49123, 'yer').should be_true
@a.send_message(49123, 'yer').should be_true
end

it "should return true for unicode text" do
@a.send(49123, 'some turkish text with an ı').should be_true
@a.send_message(49123, 'some turkish text with an ı').should be_true
end
end

Expand All @@ -32,16 +33,22 @@

it "should detect non gsm chars" do
gsm_text = "@£$¥èéùìòÇ\fØø\nÅåΔ_ΦΓΛΩΠΨΣΘΞÆæßÉ !\"#¤%&'()*+,-./0123456789:;<=>\?¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑܧ¿abcdefghijklmnopqrstuvwxyzäöñüà\^\{\}\[~\]\|€"
@a.is_gsm0338_encoded?(gsm_text).should be_true
@a.is_gsm0338_encoded?("Tım").should be_false
@a.send(:is_gsm0338_encoded?, gsm_text).should be_true
@a.send(:is_gsm0338_encoded?, "Tım").should be_false
end

it "should transform utf8 to hexadecimal code points" do
@a.string_to_hexadecimal_code_points("arasında").should eql("00610072006100730131006e00640061")
@a.send(:string_to_hexadecimal_code_points, "arasında").should eql("00610072006100730131006e00640061")
end

it "should raise Error for trying convert non utf-8 string" do
@a.string_to_hexadecimal_code_points(42).should raise_error(Mobilove::MessageIsNoUtf8String)
lambda do
@a.send(:string_to_hexadecimal_code_points, 42)
end.should raise_error(Mobilove::MessageIsNoUtf8String)

lambda do
@a.send(:string_to_hexadecimal_code_points, Iconv.iconv("UCS-2", "utf-8", "utf-8 text").first)
end.should raise_error(Mobilove::MessageIsNoUtf8String)
end
end

Expand All @@ -55,7 +62,7 @@

it "should raise an InvalidNumber exception" do
lambda do
@a.send(49123, 'test')
@a.send_message(49123, 'test')
end.should raise_error(Mobilove::InvalidNumber)
end
end
Expand All @@ -68,7 +75,7 @@

it "should raise an InvalidSender exception" do
lambda do
@a.send(49123, 'test')
@a.send_message(49123, 'test')
end.should raise_error(Mobilove::InvalidSender)
end
end
Expand All @@ -81,7 +88,7 @@

it "should raise an MessageTooLong exception" do
lambda do
@a.send(49123, 'test')
@a.send_message(49123, 'test')
end.should raise_error(Mobilove::MessageTooLong)
end
end
Expand All @@ -94,7 +101,7 @@

it "should raise an InvalidMessageType exception" do
lambda do
@a.send(49123, 'test')
@a.send_message(49123, 'test')
end.should raise_error(Mobilove::InvalidMessageType)
end
end
Expand All @@ -107,7 +114,7 @@

it "should raise an InvalidRoute exception" do
lambda do
@a.send(49123, 'test')
@a.send_message(49123, 'test')
end.should raise_error(Mobilove::InvalidRoute)
end
end
Expand All @@ -120,7 +127,7 @@

it "should raise an AuthenticationFailed exception" do
lambda do
@a.send(49123, 'test')
@a.send_message(49123, 'test')
end.should raise_error(Mobilove::AuthenticationFailed)
end
end
Expand All @@ -133,7 +140,7 @@

it "should raise an NoCreditLeft exception" do
lambda do
@a.send(49123, 'test')
@a.send_message(49123, 'test')
end.should raise_error(Mobilove::NoCreditLeft)
end
end
Expand All @@ -146,7 +153,7 @@

it "should raise an RouteCannotHandleProvider exception" do
lambda do
@a.send(49123, 'test')
@a.send_message(49123, 'test')
end.should raise_error(Mobilove::RouteCannotHandleProvider)
end
end
Expand All @@ -159,7 +166,7 @@

it "should raise an FeatureNotSupportedByRoute exception" do
lambda do
@a.send(49123, 'test')
@a.send_message(49123, 'test')
end.should raise_error(Mobilove::FeatureNotSupportedByRoute)
end
end
Expand All @@ -172,7 +179,7 @@

it "should raise an SMSCTransferFailed exception" do
lambda do
@a.send(49123, 'test')
@a.send_message(49123, 'test')
end.should raise_error(Mobilove::SMSCTransferFailed)
end
end
Expand All @@ -185,7 +192,7 @@

it "should raise an UnknownError exception" do
lambda do
@a.send(49123, 'test')
@a.send_message(49123, 'test')
end.should raise_error(Mobilove::UnknownError)
end
end
Expand Down

0 comments on commit 3b5cbf1

Please sign in to comment.