Skip to content

Commit

Permalink
refs #4035: Use railtie for loading app keys automatically and tested…
Browse files Browse the repository at this point in the history
… with cucumber
  • Loading branch information
Gary Or committed Aug 15, 2011
1 parent 574c75d commit e23510e
Show file tree
Hide file tree
Showing 13 changed files with 269 additions and 36 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ rdoc
pkg

## PROJECT::SPECIFIC
tmp
12 changes: 11 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@ source "http://rubygems.org"
gem "oauth"
gem "hashie"
gem "httparty"

# For Development
gem "rake"
gem "rspec", "~> 2.0"
gem "cucumber"
gem "aruba"
gem "rails", "3.0.9"

# For Gem release
gem "jeweler"

# For Guard
gem "rb-fsevent"
gem "guard-rspec"
gem "growl_notify"
gem "guard-rspec"
gem "guard-cucumber"
94 changes: 93 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,26 +1,109 @@
GEM
remote: http://rubygems.org/
specs:
abstract (1.0.0)
actionmailer (3.0.9)
actionpack (= 3.0.9)
mail (~> 2.2.19)
actionpack (3.0.9)
activemodel (= 3.0.9)
activesupport (= 3.0.9)
builder (~> 2.1.2)
erubis (~> 2.6.6)
i18n (~> 0.5.0)
rack (~> 1.2.1)
rack-mount (~> 0.6.14)
rack-test (~> 0.5.7)
tzinfo (~> 0.3.23)
activemodel (3.0.9)
activesupport (= 3.0.9)
builder (~> 2.1.2)
i18n (~> 0.5.0)
activerecord (3.0.9)
activemodel (= 3.0.9)
activesupport (= 3.0.9)
arel (~> 2.0.10)
tzinfo (~> 0.3.23)
activeresource (3.0.9)
activemodel (= 3.0.9)
activesupport (= 3.0.9)
activesupport (3.0.9)
arel (2.0.10)
aruba (0.4.6)
bcat (>= 0.6.1)
childprocess (>= 0.2.0)
cucumber (>= 1.0.2)
rdiscount (>= 1.6.8)
rspec (>= 2.6.0)
bcat (0.6.1)
rack (~> 1.0)
builder (2.1.2)
childprocess (0.2.1)
ffi (~> 1.0.6)
crack (0.1.8)
cucumber (1.0.2)
builder (>= 2.1.2)
diff-lcs (>= 1.1.2)
gherkin (~> 2.4.5)
json (>= 1.4.6)
term-ansicolor (>= 1.0.5)
diff-lcs (1.1.2)
erubis (2.6.6)
abstract (>= 1.0.0)
ffi (1.0.9)
gherkin (2.4.6)
json (>= 1.4.6)
git (1.2.5)
growl_notify (0.0.1)
rb-appscript
guard (0.6.0)
thor (~> 0.14.6)
guard-rspec (0.4.1)
guard-cucumber (0.6.0)
cucumber (>= 0.10)
guard (>= 0.4.0)
guard-rspec (0.4.2)
guard (>= 0.4.0)
hashie (1.1.0)
httparty (0.7.8)
crack (= 0.1.8)
i18n (0.5.0)
jeweler (1.6.4)
bundler (~> 1.0)
git (>= 1.2.5)
rake
json (1.5.3)
mail (2.2.19)
activesupport (>= 2.3.6)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.16)
oauth (0.4.5)
polyglot (0.3.2)
rack (1.2.3)
rack-mount (0.6.14)
rack (>= 1.0.0)
rack-test (0.5.7)
rack (>= 1.0)
rails (3.0.9)
actionmailer (= 3.0.9)
actionpack (= 3.0.9)
activerecord (= 3.0.9)
activeresource (= 3.0.9)
activesupport (= 3.0.9)
bundler (~> 1.0)
railties (= 3.0.9)
railties (3.0.9)
actionpack (= 3.0.9)
activesupport (= 3.0.9)
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (~> 0.14.4)
rake (0.9.2)
rb-appscript (0.6.1)
rb-fsevent (0.4.3)
rdiscount (1.6.8)
rdoc (3.9.2)
rspec (2.6.0)
rspec-core (~> 2.6.0)
rspec-expectations (~> 2.6.0)
Expand All @@ -29,18 +112,27 @@ GEM
rspec-expectations (2.6.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.6.0)
term-ansicolor (1.0.6)
thor (0.14.6)
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.29)

PLATFORMS
ruby

DEPENDENCIES
aruba
cucumber
growl_notify
guard-cucumber
guard-rspec
hashie
httparty
jeweler
oauth
rails (= 3.0.9)
rake
rb-fsevent
rspec (~> 2.0)
5 changes: 5 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ guard 'rspec', :version => 2 do
watch('spec/spec_helper.rb') { "spec/" }
end

guard 'cucumber' do
watch(%r{^features/.+\.feature$})
watch(%r{^features/support/.+$}) { 'features' }
watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
end
16 changes: 14 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ require 'rubygems'
require 'bundler/setup'
require 'rake'
require 'rspec/core/rake_task'
require 'cucumber/rake/task'

desc 'Default: Run the specs'
task :default => 'spec:unit'
task :default => ['spec:unit', 'cucumber']

namespace :spec do
desc 'Run unit specs'
Expand All @@ -14,6 +15,11 @@ namespace :spec do
end
task :spec => 'spec:unit'

desc 'Cucumber'
Cucumber::Rake::Task.new(:cucumber) do |t|
t.fork = true
end

begin
require 'jeweler'
Jeweler::Tasks.new do |gem|
Expand All @@ -23,10 +29,16 @@ begin
gem.email = "[email protected]"
gem.homepage = "http://github.com/ballantyne/weibo"
gem.authors = ["Scott Ballantyne"]
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
gem.add_dependency "oauth", "~> 0.4.1"
gem.add_dependency "hashie"
gem.add_dependency "httparty", ">= 0.5.2"
gem.add_dependency "railties"
gem.add_development_dependency "rake"
gem.add_development_dependency "rspec"
gem.add_development_dependency "cucumber"
gem.add_development_dependency "jeweler"
gem.add_development_dependency "aruba"
gem.add_development_dependency "rails", "3.0.9"
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
end
Jeweler::GemcutterTasks.new
Expand Down
31 changes: 31 additions & 0 deletions features/load_configurations.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Feature: Load Configurations
In order to simplify the configurations
As a Rails app
I should load config/weibo.yml automatically

@disable-bundler
Scenario: generate a rails 3 application and load weibo configurations
When I successfully run `bundle exec rails new testapp`
And I cd to "testapp"
And I add weibo from this project as a dependency
When I successfully run `bundle install`
And I write to "config/weibo.yml" with:
"""
development:
api_key: dev_key
api_secret: dev_secret
production:
api_key: prod_key
api_secret: prod_secret
test:
api_key: test_key
api_secret: test_secret
"""
When I successfully run `bundle exec rake -T`
Then the output should contain "rake weibo"
When I successfully run `bundle exec rake weibo RAILS_ENV=development`
Then the output should contain "Weibo API Key: dev_key"
And the output should contain "Weibo API Secret: dev_secret"
When I successfully run `bundle exec rake weibo RAILS_ENV=production`
Then the output should contain "Weibo API Key: prod_key"
And the output should contain "Weibo API Secret: prod_secret"
3 changes: 3 additions & 0 deletions features/step_definitions/rails_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
When /^I add weibo from this project as a dependency$/ do
append_to_file('Gemfile', %{gem "weibo", :path => "#{PROJECT_ROOT}"})
end
8 changes: 8 additions & 0 deletions features/support/env.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'aruba/cucumber'

PROJECT_ROOT = File.expand_path("../../..", __FILE__).freeze
puts PROJECT_ROOT

Before do
@aruba_timeout_seconds = 3600
end
33 changes: 15 additions & 18 deletions lib/weibo.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
# code is an adaptation of the twitter gem by John Nunemaker
# http://github.com/jnunemaker/twitter
# Copyright (c) 2009 John Nunemaker
#
# made to work with china's leading twitter service, 新浪微博

require 'forwardable'
require 'rubygems'
require 'oauth'
require 'hashie'
require 'httparty'
require 'rails'

require 'weibo/oauth'
require 'weibo/oauth_hack'
require 'weibo/httpauth'
require 'weibo/request'
require 'weibo/config'
require 'weibo/base'
require 'weibo/railtie'

module Weibo
class WeiboError < StandardError
attr_reader :data

def initialize(data)
@data = data

super
end
end
Expand All @@ -26,7 +40,6 @@ class NotFound < StandardError; end

module Hashie
class Mash

# Converts all of the keys to strings, optionally formatting key name
def rubyify_keys!
keys.each{|k|
Expand All @@ -38,21 +51,5 @@ def rubyify_keys!
}
self
end

end
end

directory = File.expand_path(File.dirname(__FILE__))

require File.join(directory, 'weibo', 'oauth')
require File.join(directory, 'weibo', 'oauth_hack')
require File.join(directory, 'weibo', 'httpauth')
require File.join(directory, 'weibo', 'request')
require File.join(directory, 'weibo', 'config')
require File.join(directory, 'weibo', 'base')

# code is an adaptation of the twitter gem by John Nunemaker
# http://github.com/jnunemaker/twitter
# Copyright (c) 2009 John Nunemaker
#
# made to work with china's leading twitter service, 新浪微博
12 changes: 12 additions & 0 deletions lib/weibo/railtie.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Weibo
class Railtie < Rails::Railtie
config.after_initialize do
weibo_oauth = YAML.load_file(File.join(Rails.root.to_s, 'config', 'weibo.yml'))[Rails.env || "development"]
Weibo::Config.api_key = weibo_oauth["api_key"]
Weibo::Config.api_secret = weibo_oauth["api_secret"]
end
rake_tasks do
load "weibo/tasks/weibo.rake"
end
end
end
5 changes: 5 additions & 0 deletions lib/weibo/tasks/weibo.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
desc 'Show Weibo Configurations'
task :weibo => :environment do
puts "Weibo API Key: #{Weibo::Config.api_key}"
puts "Weibo API Secret: #{Weibo::Config.api_secret}"
end
3 changes: 3 additions & 0 deletions spec/weibo_spec.rb
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
require 'spec_helper'

describe Weibo do
end
Loading

0 comments on commit e23510e

Please sign in to comment.