Permalink
Browse files

small fixes and setup rspec

  • Loading branch information...
1 parent 9162f3c commit 27e69b809382a390d03431dd0e597d8e097b01e8 @nov committed Jun 24, 2009
View
2 README
@@ -12,7 +12,7 @@
== Installation
- git clone http://github.com/nov/smartfm.git
+ git clone git://github.com/nov/smartfm.git
cd smartfm
rake install
View
172 Rakefile
@@ -1,7 +1,6 @@
require 'rubygems'
require 'rake'
require 'rake/clean'
-require 'rake/testtask'
require 'rake/packagetask'
require 'rake/gempackagetask'
require 'rake/rdoctask'
@@ -24,129 +23,130 @@ VERS = Smartfm::Version.to_version
REV = File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
CLEAN.include ['**/.*.sw?', '*.gem', '.config']
RDOC_OPTS = [
- '--title', "#{NAME} documentation",
- "--charset", "utf-8",
- "--opname", "index.html",
- "--line-numbers",
- "--main", "README",
- "--inline-source",
+ '--title', "#{NAME} documentation",
+ "--charset", "utf-8",
+ "--opname", "index.html",
+ "--line-numbers",
+ "--main", "README",
+ "--inline-source",
]
-task :default => [:test]
+task :default => [:spec]
task :package => [:clean]
-Rake::TestTask.new("test") do |t|
- t.libs << "test"
- t.pattern = "test/**/*_test.rb"
- t.verbose = true
-end
-
-Rake::TestTask.new("spec") do |t|
- t.libs << "spec"
- t.pattern = "spec/**/*_spec.rb"
- t.verbose = true
+begin
+ require 'spec/rake/spectask'
+ Spec::Rake::SpecTask.new('spec') do |t|
+ t.spec_opts = ["-f specdoc", "-c"]
+ t.spec_files = FileList['spec/*_spec.rb', 'spec/**/*_spec.rb']
+ end
+rescue LoadError
+ desc 'Spec rake task not available'
+ task :spec do
+ abort 'Spec rake task is not available. Be sure to install rspec as a gem or plugin'
+ end
end
spec = Gem::Specification.new do |s|
- s.name = NAME
- s.version = VERS
- s.platform = Gem::Platform::RUBY
- s.has_rdoc = true
- s.extra_rdoc_files = ["README", "ChangeLog"]
- s.rdoc_options += RDOC_OPTS + ['--exclude', '^(examples|extras)/']
- s.summary = DESCRIPTION
- s.description = DESCRIPTION
- s.author = AUTHOR
- s.email = EMAIL
- s.homepage = HOMEPATH
- s.executables = BIN_FILES
- s.rubyforge_project = RUBYFORGE_PROJECT
- s.bindir = "bin"
- s.require_path = "lib"
- #s.autorequire = ""
- s.test_files = Dir["test/*_test.rb"]
-
- s.add_dependency('json')
- s.add_dependency('oauth')
+ s.name = NAME
+ s.version = VERS
+ s.platform = Gem::Platform::RUBY
+ s.has_rdoc = true
+ s.extra_rdoc_files = ["README", "ChangeLog"]
+ s.rdoc_options += RDOC_OPTS + ['--exclude', '^(examples|extras)/']
+ s.summary = DESCRIPTION
+ s.description = DESCRIPTION
+ s.author = AUTHOR
+ s.email = EMAIL
+ s.homepage = HOMEPATH
+ s.executables = BIN_FILES
+ s.rubyforge_project = RUBYFORGE_PROJECT
+ s.bindir = "bin"
+ s.require_path = "lib"
+ #s.autorequire = ""
+ s.test_files = Dir["spec/*_spec.rb"]
+
+ s.add_dependency('json')
+ s.add_dependency('oauth')
# s.required_ruby_version = '>= 1.8.6'
- s.files = %w(README ChangeLog Rakefile) +
- Dir.glob("{bin,doc,test,spec,lib,templates,extras,website,script}/**/*") +
- Dir.glob("ext/**/*.{h,c,rb}") +
- Dir.glob("examples/**/*.rb") +
- Dir.glob("tools/*.rb") +
- Dir.glob("rails/*.rb")
+ s.files = %w(README ChangeLog Rakefile) +
+ Dir.glob("{bin,doc,spec,lib,templates,extras,website,script}/**/*") +
+ Dir.glob("ext/**/*.{h,c,rb}") +
+ Dir.glob("examples/**/*.rb") +
+ Dir.glob("tools/*.rb") +
+ Dir.glob("rails/*.rb")
- s.extensions = FileList["ext/**/extconf.rb"].to_a
+ s.extensions = FileList["ext/**/extconf.rb"].to_a
end
Rake::GemPackageTask.new(spec) do |p|
- p.need_tar = true
- p.gem_spec = spec
+ p.need_tar = true
+ p.gem_spec = spec
end
desc "Install"
task :install do
- name = "#{NAME}-#{VERS}.gem"
- sh %{rake package}
- sh %{sudo gem install pkg/#{name}}
+ name = "#{NAME}-#{VERS}.gem"
+ sh %{rake package}
+ sh %{sudo gem install pkg/#{name}}
end
desc "Uninstall"
task :uninstall => [:clean] do
- sh %{sudo gem uninstall #{NAME}}
+ sh %{sudo gem uninstall #{NAME}}
end
Rake::RDocTask.new do |rdoc|
- rdoc.rdoc_dir = 'html'
- rdoc.options += RDOC_OPTS
- rdoc.template = "resh"
- #rdoc.template = "#{ENV['template']}.rb" if ENV['template']
- if ENV['DOC_FILES']
- rdoc.rdoc_files.include(ENV['DOC_FILES'].split(/,\s*/))
- else
- rdoc.rdoc_files.include('README', 'ChangeLog')
- rdoc.rdoc_files.include('lib/**/*.rb')
- rdoc.rdoc_files.include('ext/**/*.c')
- end
+ rdoc.rdoc_dir = 'html'
+ rdoc.options += RDOC_OPTS
+ rdoc.template = "resh"
+ #rdoc.template = "#{ENV['template']}.rb" if ENV['template']
+ if ENV['DOC_FILES']
+ rdoc.rdoc_files.include(ENV['DOC_FILES'].split(/,\s*/))
+ else
+ rdoc.rdoc_files.include('README', 'ChangeLog')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+ rdoc.rdoc_files.include('ext/**/*.c')
+ end
end
desc "Publish to RubyForge"
task :rubyforge => [:rdoc, :package] do
- require 'rubyforge'
- Rake::RubyForgePublisher.new(RUBYFORGE_PROJECT, 'nov').upload
+ require 'rubyforge'
+ Rake::RubyForgePublisher.new(RUBYFORGE_PROJECT, 'nov').upload
end
# rake release VERSION=x.y.z
desc 'Package and upload the release to rubyforge.'
task :release => [:clean, :package] do |t|
- v = ENV["VERSION"] or abort "Must supply VERSION=x.y.z"
- abort "Versions don't match #{v} vs #{VERS}" unless v == VERS
- pkg = "pkg/#{NAME}-#{VERS}"
-
- require 'rubyforge'
- rf = RubyForge.new.configure
- puts "Logging in"
- rf.login
-
- c = rf.userconfig
-# c["release_notes"] = description if description
-# c["release_changes"] = changes if changes
- c["preformatted"] = true
-
- files = [
- "#{pkg}.tgz",
- "#{pkg}.gem"
- ].compact
-
- puts "Releasing #{NAME} v. #{VERS}"
- rf.add_release RUBYFORGE_PROJECT, NAME, VERS, *files
+ v = ENV["VERSION"] or abort "Must supply VERSION=x.y.z"
+ abort "Versions don't match #{v} vs #{VERS}" unless v == VERS
+ pkg = "pkg/#{NAME}-#{VERS}"
+
+ require 'rubyforge'
+ rf = RubyForge.new.configure
+ puts "Logging in"
+ rf.login
+
+ c = rf.userconfig
+# c["release_notes"] = description if description
+# c["release_changes"] = changes if changes
+ c["preformatted"] = true
+
+ files = [
+ "#{pkg}.tgz",
+ "#{pkg}.gem"
+ ].compact
+
+ puts "Releasing #{NAME} v. #{VERS}"
+ rf.add_release RUBYFORGE_PROJECT, NAME, VERS, *files
end
desc 'Show information about the gem.'
task :debug_gem do
- puts spec.to_ruby
+ puts spec.to_ruby
end
desc 'Update gem spec'
View
4 lib/smartfm/models/item.rb
@@ -42,8 +42,8 @@ def initialize(params = {})
end
def initialize(params = {})
- params[:responses] = [params[:response]] if params[:response]
- @id = params[:id].to_i
+ params[:responses] = Array(params[:response]) if params[:response]
+ @id = params[:id].to_i if params[:id]
@list = params[:list]
@cue = self.deserialize(params[:cue], :as => Smartfm::Item::Cue)
@responses = self.deserialize(params[:responses], :as => Smartfm::Item::Response)
View
2 lib/smartfm/models/like.rb
@@ -8,7 +8,7 @@ def self.rest_client; Smartfm::RestClient::Like; end
def rest_client; self.class.rest_client; end
def initialize(params)
- @id = params[:id]
+ @id = params[:id].to_i
@type = params[:user]
@title = params[:title]
@description = params[:description]
View
27 lib/smartfm/models/list.rb
@@ -1,8 +1,8 @@
class Smartfm::List < Smartfm::Base
- ATTRIBUTES = [:id, :title, :description, :icon, :square_icon, :item_count, :user_count, :iknow, :dictation, :brainspeed,
- :language, :translation_language, :item_type, :transcript, :embed, :tags, :media_entry,
- :attribution_license_id, :items, :sentences, :user]
- READONLY_ATTRIBUTES = [:id, :icon, :item_count, :user_count, :iknow, :dictation, :brainspeed, :user]
+ ATTRIBUTES = [:id, :title, :description, :icon, :square_icon, :items_count, :users_count, :likes_count,
+ :iknow, :dictation, :brainspeed, :language, :translation_language, :item_type, :transcript,
+ :embed, :tags, :media_entry, :attribution_license_id, :items, :sentences, :user]
+ READONLY_ATTRIBUTES = [:id, :icon, :items_count, :users_count, :likes_count, :iknow, :dictation, :brainspeed, :user]
attr_accessor *(ATTRIBUTES - READONLY_ATTRIBUTES)
attr_reader *READONLY_ATTRIBUTES
@@ -35,13 +35,14 @@ def available?
end
def initialize(params = {})
- @id = (params[:id].to_i rescue nil)
+ @id = params[:id].to_i if params[:id]
@title = params[:title]
@description = params[:description]
@icon = params[:icon]
@square_icon = params[:square_icon]
- @item_count = (params[:item_count].to_i rescue nil)
- @user_count = (params[:user_count].to_i rescue nil)
+ @items_count = params[:items_count].to_i if params[:items_count]
+ @users_count = params[:users_count].to_i if params[:users_count]
+ @likes_count = params[:likes_count].to_i if params[:likes_count]
@language = params[:language]
@translation_language = params[:translation_language]
if @id and @translation_language
@@ -50,12 +51,12 @@ def initialize(params = {})
@dictation = Application.new(common_settings.merge(:dictation => params[:dictation]))
@brainspeed = Application.new(common_settings.merge(:brainspeed => params[:brainspeed]))
end
- @item_type = params[:item_type] # for list creation
- @transcript = params[:transcript] # for list creation
- @embed = params[:embed] # for list creation
- @tags = params[:tags] # for list creation
- @media_entry = params[:media_entry] # for list creation
- @attribution_license_id = params[:attribution_license_id] # for list creation
+ @item_type = params[:item_type]
+ @transcript = params[:transcript]
+ @embed = params[:embed]
+ @tags = params[:tags]
+ @media_entry = params[:media_entry]
+ @attribution_license_id = params[:attribution_license_id].to_i if params[:attribution_license_id]
@items = self.deserialize(params[:items], :as => Smartfm::Item)
@sentences = self.deserialize(params[:sentences], :as => Smartfm::Sentence)
@user = self.deserialize(params[:user], :as => Smartfm::User)
View
10 lib/smartfm/models/sentence.rb
@@ -12,9 +12,9 @@ def self.rest_client; Smartfm::RestClient::Sentence; end
def rest_client; self.class.rest_client; end
def initialize(params = {})
- params[:translations] = [params[:translation]] if params[:translation]
- params[:transliterations] = [params[:transliteration]] if params[:transliteration]
- @id = params[:id]
+ params[:translations] = Array(params[:translation]) if params[:translation]
+ params[:transliterations] = Array(params[:transliteration]) if params[:transliteration]
+ @id = params[:id].to_i if params[:id]
@item = params[:item]
@list = params[:list]
@sound = params[:sound]
@@ -60,11 +60,11 @@ def validate
end
def translation
- self.translations.first rescue nil
+ self.translations.first if self.translations
end
def transliteration
- self.transliterations.first rescue nil
+ self.transliterations.first if self.transliterations
end
end
View
30 lib/smartfm/models/user.rb
@@ -12,7 +12,7 @@ class Profile < Smartfm::Base
def initialize(params = {})
@name = params[:name]
@gender = params[:gender]
- @birthday = (Date.parse(params[:birthday]) rescue nil)
+ @birthday = Date.parse(params[:birthday]) if params[:birthday]
@description = params[:description]
@blog_url = params[:blog_url]
@profile_url = params[:profile_url]
@@ -30,16 +30,16 @@ class Result < Smartfm::Base
attr_reader *ATTRIBUTES
def initialize(params = {})
- @timestamp = (params[:timestamp].to_i rescue nil)
- @seconds = (params[:seconds].to_i rescue nil)
+ @timestamp = params[:timestamp].to_i if params[:timestamp]
+ @seconds = params[:seconds].to_i if params[:seconds]
@totals = {
- :seconds => (params[:totals][:seconds].to_i rescue nil),
- :seen => (params[:totals][:seen].to_i rescue nil),
- :completed => (params[:totals][:completed].to_i rescue nil)
+ :seconds => params[:totals][:seconds] ? params[:totals][:seconds].to_i : nil,
+ :seen => params[:totals][:seen] ? params[:totals][:seen].to_i : nil,
+ :completed => params[:totals][:completed] ? params[:totals][:completed].to_i : nil
}
- @seen = (params[:seen].to_i rescue nil)
- @completed = (params[:completed].to_i rescue nil)
- @date = (Date.parse(params[:date]) rescue nil)
+ @seen = params[:seen].to_i if params[:seen]
+ @completed = params[:completed].to_i if params[:completed]
+ @date = Date.parse(params[:date]) if params[:date]
end
end
@@ -48,16 +48,16 @@ class TotalSummary < Smartfm::Base
attr_reader *ATTRIBUTES
def initialize(params = {})
- @studied = params[:studied]
- @completed = params[:completed]
- @performance = params[:performance]
- @best_speed = params[:best_speed]
- @best_score = params[:best_score]
+ @studied = params[:studied].to_i if params[:studied]
+ @completed = params[:completed].to_i if params[:completed]
+ @performance = params[:performance].to_i if params[:performance]
+ @best_speed = params[:best_speed].to_i if params[:best_speed]
+ @best_score = params[:best_score].to_i if params[:best_score]
end
end
def initialize(params = {})
- @today = (Date.parse(params[:today]) rescue nil)
+ @today = Date.new(params[:today]) if params[:today]
@results = self.deserialize(params[:study_results], :as => Smartfm::User::Study::Result)
@total_summary = self.deserialize(params[:total_summary], :as => Smartfm::User::Study::TotalSummary)
end
View
12 lib/smartfm/rest_clients/base.rb
@@ -73,7 +73,7 @@ def self.handle_rest_response(response, format)
rescue Exception => e
e.is_a?(RESTError) ? raise(e) : :success
end
- else
+ else
begin
handle_json_response(response.body)
rescue Exception => e
@@ -83,15 +83,15 @@ def self.handle_rest_response(response, format)
end
def self.handle_json_response(json_response)
- hash = JSON.parse(json_response)
- unless (hash['error'].nil? rescue :success) # success response may be Array, not Hash.
- if hash['error']['code'] == 404
+ result = JSON.parse(json_response)
+ unless result.is_a?(Array) || result['error'].nil?
+ if result['error']['code'] == 404
return nil
else
- raise RESTError.new(:code => hash['error']['code'], :message => hash['error']['message'])
+ raise RESTError.new(:code => result['error']['code'], :message => result['error']['message'])
end
end
- hash
+ result
end
def self.http_header
View
8 test/smartfm_test.rb
@@ -1,8 +0,0 @@
-require File.dirname(__FILE__) + '/test_helper.rb'
-
-require "test/unit"
-class SmartfmTest < Test::Unit::TestCase
- def test_truth
- true
- end
-end
View
3 test/test_helper.rb
@@ -1,3 +0,0 @@
-require 'test/unit'
-require File.dirname(__FILE__) + '/../lib/smartfm'
-

0 comments on commit 27e69b8

Please sign in to comment.