Browse files

add tests

  • Loading branch information...
1 parent f6470d7 commit 023fe3ed2906a90309d36ea6b3bb408b40f2c118 @maccman committed Oct 13, 2010
Showing with 74 additions and 2 deletions.
  1. +16 −2 Rakefile
  2. +10 −0 test/helper.rb
  3. +48 −0 test/test_roauth.rb
View
18 Rakefile
@@ -1,3 +1,6 @@
+require 'rubygems'
+require 'rake'
+
begin
require 'jeweler'
Jeweler::Tasks.new do |gemspec|
@@ -9,5 +12,16 @@ begin
gemspec.authors = ["Alex MacCaw"]
end
rescue LoadError
- puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
-end
+ puts "Jeweler not available. Install it with: sudo gem install jeweler"
+end
+
+
+require 'rake/testtask'
+Rake::TestTask.new(:test) do |test|
+ test.libs << 'lib' << 'test'
+ test.pattern = 'test/**/test_*.rb'
+ test.verbose = true
+end
+
+task :test => :check_dependencies
+task :default => :test
View
10 test/helper.rb
@@ -0,0 +1,10 @@
+require 'rubygems'
+require 'test/unit'
+require 'shoulda'
+
+$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
+$LOAD_PATH.unshift(File.dirname(__FILE__))
+require 'roauth'
+
+class Test::Unit::TestCase
+end
View
48 test/test_roauth.rb
@@ -0,0 +1,48 @@
+require 'helper'
+
+class TestRoauth < Test::Unit::TestCase
+ should "correctly sign params" do
+ url = "https://twitter.com/direct_messages.json"
+
+ oauth = {
+ :consumer_key => "consumer_key",
+ :consumer_secret => "consumer_secret",
+ :access_key => "access_key",
+ :access_secret => "access_secret",
+ :nonce => "foo",
+ :timestamp => 1286967499
+ }
+
+ params = {
+ :count => "11",
+ :since_id => "5000"
+ }
+
+ oauth_header = ROAuth.header(oauth, url, params)
+ signature = ROAuth.parse(oauth_header)[:signature]
+
+ assert_equal "7/y7qmvtcOGo7sI0z1IY4WILZso=", signature
+ end
+
+ should "verify correctly signed params" do
+ url = "https://twitter.com/direct_messages.json"
+
+ oauth = {
+ :consumer_key => "consumer_key",
+ :consumer_secret => "consumer_secret",
+ :access_key => "access_key",
+ :access_secret => "access_secret",
+ :nonce => "foo",
+ :timestamp => 1286967499
+ }
+
+ params = {
+ :count => "11",
+ :since_id => "5000"
+ }
+
+ header = %{OAuth oauth_consumer_key="consumer_key", oauth_nonce="foo", oauth_signature="7%2Fy7qmvtcOGo7sI0z1IY4WILZso%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1286967499", oauth_token="access_key", oauth_version="1.0"}
+
+ assert ROAuth.verify(oauth, header, url, params), "verify failed"
+ end
+end

0 comments on commit 023fe3e

Please sign in to comment.