Permalink
Browse files

Added some specs. Not very thorough but at least it is something.

  • Loading branch information...
1 parent 35f7079 commit 6fd55396823e8c6678836608b1dd4d556e23e7f3 @jeremyboles committed Jan 26, 2011
View
@@ -1 +1,3 @@
-.DS_Store
+.DS_Store
+pkg
+rdoc
View
@@ -1,4 +1,2 @@
source :rubygems
-
-gem 'json', '1.4.6'
-gem 'rest-client', '1.6.1'
+gemspec
View
@@ -1,12 +1,32 @@
+PATH
+ remote: .
+ specs:
+ snapshot (0.1)
+ json (= 1.4.6)
+ rest-client (= 1.6.1)
+
GEM
remote: http://rubygems.org/
specs:
+ diff-lcs (1.1.2)
+ fakeweb (1.3.0)
+ json (1.4.6)
mime-types (1.16)
rest-client (1.6.1)
mime-types (>= 1.16)
+ rspec (2.4.0)
+ rspec-core (~> 2.4.0)
+ rspec-expectations (~> 2.4.0)
+ rspec-mocks (~> 2.4.0)
+ rspec-core (2.4.0)
+ rspec-expectations (2.4.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.4.0)
PLATFORMS
ruby
DEPENDENCIES
- rest-client (= 1.6.1)
+ fakeweb (= 1.3)
+ rspec (= 2.4.0)
+ snapshot!
View
@@ -9,7 +9,7 @@ The Snapshot gem provides an nice, ActiveRecord-ish interface to the
Installation
------------
- gem install snapshot-rb
+ gem install snapshot-ruby
Using the gem
-------------
View
@@ -0,0 +1,25 @@
+$:.unshift File.expand_path('../lib', __FILE__)
+
+begin
+
+ require 'rspec/core/rake_task'
+ desc 'Run specs'
+ RSpec::Core::RakeTask.new do |t|
+ t.rspec_opts = %w(-fs --color)
+ end
+
+rescue LoadError
+
+ task :spec do
+ abort 'Run `rake spec:deps` to be able to run the specs'
+ end
+ namespace :spec do
+ desc 'Ensure spec dependencies are installed'
+ task :deps do
+ sh "gem list rspec | (grep 'rspec (2.0' 1> /dev/null) || gem install rspec --no-ri --no-rdoc"
+ end
+ end
+
+end
+
+task :default => :spec
View
@@ -1,5 +1,7 @@
require 'snapshot/connection'
require 'snapshot/image'
+require 'snapshot/url'
+require 'snapshot/version'
module Snapshot
extend self
@@ -44,17 +46,10 @@ def configure(opts={})
# ==== Examples
#
# # Using a String:
- # Snapshot.configure('http://access_key:secret_ket@subdomain.snapshothq.com/')
+ # Snapshot.connect!('http://access_key:secret_ket@subdomain.snapshothq.com/')
#
# # Using a Hash:
- # Snapshot.configure(:access_key => 'access_key', :domain => 'subdomain.snapshothq.com', :secret_key => 'secret_key')
- #
- # # Using a block:
- # Snapshot.configure do |config|
- # config.access_key = 'access_key'
- # config.domain = 'subdomain.snapshothq.com'
- # config.secret_key = 'secret_key
- # end
+ # Snapshot.connect!(:access_key => 'access_key', :domain => 'subdomain.snapshothq.com', :secret_key => 'secret_key')
#
def connect!(opts=nil)
opts = ENV['SNAPSHOT_URL'] if opts.nil?
@@ -68,4 +63,9 @@ def connection
raise 'Not connected. Please connect! first.' unless @connection
@connection
end
+
+ # Terminates the connection to Snapshot
+ def disconnect!
+ @connection = nil
+ end
end
@@ -84,8 +84,8 @@ def destroy
# img = Snapshot::Image.find('a45af9b9e6ebab9c685faef4e72e7a14f3e24e1a')
# img.url # => http://subdomain.snapshothq.com/a45af9b9e6ebab9c685faef4e72e7a14f3e24e1a.jpg
#
- def url
- Snapshot.connection.url << id << extension
+ def url(&block)
+ Snapshot::URL.new(id, extension, &block)
end
private
View
@@ -0,0 +1,22 @@
+module Snapshot
+ class URL
+ attr_reader :extension, :id
+
+ def initialize(id, extension, &block)
+ @id = id
+ @extension = extension
+ @options = []
+ tap(&block) if block_given?
+ end
+
+ def method_missing(process, *options)
+ @options << [process.to_s, options]
+ end
+
+ def to_s
+ @options = @options.flatten
+ @options << '' unless @options.empty?
+ Snapshot.connection.url << @options.join('/') << id << '.' << extension
+ end
+ end
+end
View
@@ -12,10 +12,16 @@ Gem::Specification.new do |s|
s.homepage = 'https://github.com/jeremyboles/snapshot-ruby'
s.summary = 'Ruby wrapper for storing and manipulating images via Snapshot.'
s.description = 'Snap is a very simple image storage and processing services for developers.'
-
+
s.required_rubygems_version = '>= 1.3.7'
s.rubyforge_project = 'snapshot-ruby'
-
+
+ s.add_dependency 'json', '1.4.6'
+ s.add_dependency 'rest-client', '1.6.1'
+
+ s.add_development_dependency 'fakeweb', '1.3'
+ s.add_development_dependency 'rspec', '2.4.0'
+
s.files = Dir.glob("lib/**/*") + %w(README.md)
s.require_path = 'lib'
end
@@ -0,0 +1,12 @@
+require File.expand_path('../../spec_helper', __FILE__)
+require 'uri'
+
+describe Snapshot::Connection do
+ before(:each) do
+ @connect = Snapshot::Connection.new('http://access_key:secret_key@example.com/')
+ end
+
+ it 'should return a valid url for the domain' do
+ lambda { URI.parse(@connect.url) }.should_not raise_error(URI::InvalidURIError)
+ end
+end
@@ -0,0 +1,13 @@
+require File.expand_path('../../spec_helper', __FILE__)
+
+describe Snapshot::Image do
+ before do
+ Snapshot.configure('http://access_key:secret_key@example.com/')
+ end
+
+ after do
+ Snapshot.disconnect!
+ end
+
+
+end
@@ -0,0 +1,25 @@
+require File.expand_path('../../spec_helper', __FILE__)
+
+describe Snapshot::URL do
+ before(:all) do
+ Snapshot.configure('http://access_key:secret_key@example.com/')
+ end
+
+ before(:each) do
+ @url = Snapshot::URL.new('id', 'jpg')
+ end
+
+ after(:all) do
+ Snapshot.disconnect!
+ end
+
+ it 'should construct a valid url' do
+ @url.to_s.should eql('http://example.com/id.jpg')
+ end
+
+ it 'should build processing on the url' do
+ @url.size 200,150
+ @url.quality 75
+ @url.to_s.should eql('http://example.com/size/200/150/quality/75/id.jpg')
+ end
+end
View
@@ -0,0 +1,36 @@
+require File.expand_path('../spec_helper', __FILE__)
+
+describe Snapshot do
+ after(:each) do
+ Snapshot.disconnect!
+ end
+
+ it 'should raise an error if used without being connected' do
+ lambda { Snapshot.connection }.should raise_error
+ end
+
+ it 'should be able to be configured by a String' do
+ Snapshot.configure("http://access_key:secret_key@example.com/")
+ lambda { Snapshot.connection }.should_not raise_error
+ end
+
+ it 'should be able to be configured by a Hash' do
+ Snapshot.configure(:access_key => 'access_key', :secret_key => 'secret_key', :domain => 'example.com')
+ lambda { Snapshot.connection }.should_not raise_error
+ end
+
+ it 'should be able to be configured by a block' do
+ Snapshot.configure do |config|
+ config.access_key = 'access_key'
+ config.domain = 'example.com'
+ config.secret_key = 'secret_key'
+ end
+ lambda { Snapshot.connection }.should_not raise_error
+ end
+
+ it 'should be able to be disconnected' do
+ Snapshot.configure("http://access_key:secret_key@example.com/")
+ Snapshot.disconnect!
+ lambda { Snapshot.connection }.should raise_error
+ end
+end
View
@@ -0,0 +1 @@
+require File.join(File.dirname(__FILE__), '..','lib','snapshot')
View
Deleted file not rendered

0 comments on commit 6fd5539

Please sign in to comment.