Permalink
Browse files

Made gem working out of the box (with a little help from alto) and fi…

…xing the tests
  • Loading branch information...
1 parent ddeeff7 commit 3b5cbf1026663688fd723e0f5e3b56d4f83de7df @mortro mortro committed Nov 18, 2011
Showing with 81 additions and 27 deletions.
  1. +3 −0 Gemfile
  2. +30 −0 Gemfile.lock
  3. +5 −8 Rakefile
  4. +2 −1 lib/mobilove/text.rb
  5. +4 −0 mobilove.gemspec
  6. +12 −0 spec/spec_helper.rb
  7. +25 −18 test/mobilove_test.rb → spec/unit/mobilove_spec.rb
View
3 Gemfile
@@ -0,0 +1,3 @@
+source :rubygems
+
+gemspec
View
30 Gemfile.lock
@@ -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
View
13 Rakefile
@@ -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
View
3 lib/mobilove/text.rb
@@ -1,5 +1,6 @@
# coding: utf-8
require 'uri'
+require 'iconv'
module Mobilove
@@ -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)
View
4 mobilove.gemspec
@@ -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'
View
12 spec/spec_helper.rb
@@ -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) }
View
43 test/mobilove_test.rb → spec/unit/mobilove_spec.rb
@@ -2,6 +2,7 @@
require 'rubygems'
require 'mobilove'
require 'rspec'
+require 'iconv'
describe "Mobilove" do
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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

0 comments on commit 3b5cbf1

Please sign in to comment.