Skip to content

Commit

Permalink
Update the code to use the bundler and make it clean
Browse files Browse the repository at this point in the history
  • Loading branch information
halorgium committed Oct 28, 2009
1 parent 42d5737 commit 036c4e9
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 32 deletions.
9 changes: 3 additions & 6 deletions .gitignore
@@ -1,6 +1,3 @@
.DS_Store
*~
.#*
*.jar
sinatra.log
pkg
pkg
bin
vendor/gems
13 changes: 13 additions & 0 deletions Gemfile
@@ -0,0 +1,13 @@
gem 'rack'
gem 'rack-test'

only :test do
gem 'rake'
gem 'sinatra', :require_as => 'sinatra/base'
gem 'rspec', :require_as => 'spec'
gem 'rack-contrib', :require_as => 'rack/contrib'
gem 'ruby-debug'
gem 'bundler'
end

disable_system_gems
4 changes: 2 additions & 2 deletions History.txt
@@ -1,5 +1,5 @@
== 0.1.0 / 2009-06-14

* 1 major enhancement

* Birthday!
4 changes: 2 additions & 2 deletions README.textile
Expand Up @@ -14,8 +14,8 @@ h2. Rack responses

Rack::Client can be used to make HTTP requests to any type of server, not
just ones using Rack. However, when a request is made then a proper
Rack response (specifically a Rack::MockResponse) object is returned.
For Rubyists, this means you don't need to learn yet another interface
Rack response (specifically a Rack::MockResponse) object is returned.
For Rubyists, this means you don't need to learn yet another interface
and can just stick with Rack both on the server, test, and client side of
things.

Expand Down
10 changes: 7 additions & 3 deletions Rakefile
Expand Up @@ -13,7 +13,7 @@ task :default => :spec

spec = Gem::Specification.new do |s|
s.name = "rack-client"
s.rubyforge_project = s.name
s.rubyforge_project = s.name
s.version = Rack::Client::VERSION
s.author = "Tim Carey-Smith"
s.email = "tim" + "@" + "spork.in"
Expand All @@ -23,8 +23,12 @@ spec = Gem::Specification.new do |s|
s.files = %w[History.txt LICENSE README.textile Rakefile] + Dir["lib/**/*"] + Dir["demo/**/*"]
s.test_files = Dir["spec/**/*"]

s.add_dependency 'rack', '~> 1' # 1.X.X
s.add_dependency 'rack-test', '~> 0' # 0.X.X
require 'bundler'
manifest = Bundler::Environment.load(File.dirname(__FILE__) + '/Gemfile')
manifest.dependencies.each do |d|
next if d.only && d.only.include?('test')
s.add_dependency(d.name, d.version)
end
end

Rake::GemPackageTask.new(spec) do |package|
Expand Down
6 changes: 3 additions & 3 deletions demo/demo_spec.rb
Expand Up @@ -12,7 +12,7 @@ def app
Rack::Client.new
# Demo::App.new
end
before(:all) { delete "http://localhost:9292/store" }
before(:all) { delete "http://localhost:9292/store" }
after { delete "http://localhost:9292/store" }

it "should return a 404 if a resource does not exist" do
Expand All @@ -28,8 +28,8 @@ def app
last_response.status.should == 200
last_response.body.should == "strawberry"
get "http://localhost:9292/store/car"
last_response.status.should == 200
last_response.body.should == "lotus"
last_response.status.should == 200
last_response.body.should == "lotus"
end

it "should be able to clear the store of all items" do
Expand Down
2 changes: 1 addition & 1 deletion lib/rack/client.rb
Expand Up @@ -11,7 +11,7 @@ class Client < Rack::Builder
VERSION = "0.1.1"
include Rack::Test::Methods
HTTP_METHODS = [:head, :get, :put, :post, :delete]

class << self
extend Forwardable
def_delegators :new, *HTTP_METHODS
Expand Down
4 changes: 2 additions & 2 deletions lib/rack/client/http.rb
Expand Up @@ -15,7 +15,7 @@ def run
head = Net::HTTP::Head.new(request.path, request_headers)
http.request(head) do |response|
return parse(response)
end
end
when "GET"
get = Net::HTTP::Get.new(request.path, request_headers)
http.request(get) do |response|
Expand All @@ -37,7 +37,7 @@ def run
delete = Net::HTTP::Delete.new(request.path, request_headers)
http.request(delete) do |response|
return parse(response)
end
end
else
raise "Unsupported method: #{request.request_method.inspect}"
end
Expand Down
2 changes: 1 addition & 1 deletion spec/auth_spec.rb
Expand Up @@ -5,7 +5,7 @@
client = Rack::Client.new do
use Rack::Client::Auth::Basic, "username", "password"
end
response = client.get("http://localhost:9292/auth/ping")
response = client.get("http://localhost:9292/auth/ping") #, :username => "username")
response.status.should == 200
response.headers["Content-Type"].should == "text/html"
response.body.should == "pong"
Expand Down
14 changes: 7 additions & 7 deletions spec/core_spec.rb
Expand Up @@ -13,7 +13,7 @@
it "returns a 302" do
response = Rack::Client.new.get("http://localhost:9292/redirect")
response.status.should == 302
response["Location"].should == "/after-redirect"
response["Location"].should == "http://localhost:9292/after-redirect"
end

it "heads data" do
Expand All @@ -25,7 +25,7 @@
it "puts data" do
response = Rack::Client.new.put "http://localhost:9292/shelf/ctm", "some data"
response.status.should == 200
response["Location"].should == "/shelf/ctm"
response["Location"].should == "http://localhost:9292/shelf/ctm"
end

it "deletes data" do
Expand All @@ -52,7 +52,7 @@
it "returns a 302" do
response = Rack::Client.get("http://localhost:9292/redirect")
response.status.should == 302
response["Location"].should == "/after-redirect"
response["Location"].should == "http://localhost:9292/after-redirect"
end

it "heads data" do
Expand All @@ -64,7 +64,7 @@
it "puts data" do
response = Rack::Client.put "http://localhost:9292/shelf/ctm", "some data"
response.status.should == 200
response["Location"].should == "/shelf/ctm"
response["Location"].should == "http://localhost:9292/shelf/ctm"
end

it "deletes data" do
Expand All @@ -82,7 +82,7 @@
context "at the rack-test level" do
include Rack::Test::Methods
def app() Rack::Client.new end

it "returns an empty body" do
get "http://localhost:9292/empty"
last_response.status.should == 200
Expand All @@ -94,7 +94,7 @@ def app() Rack::Client.new end
it "returns a 302" do
get "http://localhost:9292/redirect"
last_response.status.should == 302
last_response["Location"].should == "/after-redirect"
last_response["Location"].should == "http://localhost:9292/after-redirect"
end

it "heads data" do
Expand All @@ -106,7 +106,7 @@ def app() Rack::Client.new end
it "puts data" do
put "http://localhost:9292/shelf/ctm", "some data"
last_response.status.should == 200
last_response["Location"].should == "/shelf/ctm"
last_response["Location"].should == "http://localhost:9292/shelf/ctm"
end

it "deletes data" do
Expand Down
2 changes: 1 addition & 1 deletion spec/endpoint_spec.rb
Expand Up @@ -30,7 +30,7 @@ class MyApp < Sinatra::Base

it "only functions for that domain" do
client = Rack::Client.new do
run Rack::URLMap.new("http://google.com/" => MyApp)
run Rack::URLMap.new("http://google.com/" => MyApp)
end
response = client.get("http://example.org/")
response.status.should == 404
Expand Down
46 changes: 46 additions & 0 deletions spec/quality_spec.rb
@@ -0,0 +1,46 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe "The library itself" do

def check_for_tab_characters(filename)
failing_lines = []
File.readlines(filename).each_with_index do |line,number|
failing_lines << number + 1 if line =~ /\t/
end

unless failing_lines.empty?
"#{filename} has tab characters on lines #{failing_lines.join(', ')}"
end
end

def check_for_extra_spaces(filename)
failing_lines = []
File.readlines(filename).each_with_index do |line,number|
next if line =~ /^\s+#.*\s+\n$/
failing_lines << number + 1 if line =~ /\s+\n$/
end

unless failing_lines.empty?
"#{filename} has spaces on the EOL on lines #{failing_lines.join(', ')}"
end
end

def be_well_formed
simple_matcher("be well formed") do |given, matcher|
matcher.failure_message = given.join("\n")
given.empty?
end
end

it "has no malformed whitespace" do
error_messages = []
Dir.chdir(File.dirname(__FILE__) + '/..') do
`git ls-files`.split("\n").each do |filename|
next if filename =~ /\.gitmodules|fixtures/
error_messages << check_for_tab_characters(filename)
error_messages << check_for_extra_spaces(filename)
end
end
error_messages.compact.should be_well_formed
end
end
5 changes: 1 addition & 4 deletions spec/spec_helper.rb
@@ -1,6 +1,3 @@
require 'rubygems'
require 'spec'
require 'rack/contrib'
gem 'rack-test'
Bundler.require_env(:test)

require File.expand_path(File.dirname(__FILE__) + "/../lib/rack/client")

0 comments on commit 036c4e9

Please sign in to comment.