Skip to content
Browse files

Cleanup whitespace.

  • Loading branch information...
1 parent c085aa5 commit ab18d3f974ef5eac665585555319ea0f1c613827 @seancribbs seancribbs committed
View
19 Rakefile
@@ -32,6 +32,25 @@ task :release => :gem do
system "gem push pkg/#{gemspec.name}-#{gemspec.version}.gem"
end
+desc "Cleans up white space in source files"
+task :clean_whitespace do
+ no_file_cleaned = true
+
+ Dir["**/*.rb"].each do |file|
+ contents = File.read(file)
+ cleaned_contents = contents.gsub(/([ \t]+)$/, '')
+ unless cleaned_contents == contents
+ no_file_cleaned = false
+ puts " - Cleaned #{file}"
+ File.open(file, 'w') { |f| f.write(cleaned_contents) }
+ end
+ end
+
+ if no_file_cleaned
+ puts "No files with trailing whitespace found"
+ end
+end
+
require 'rspec/core'
require 'rspec/core/rake_task'
View
16 lib/webmachine/application.rb
@@ -4,19 +4,19 @@
module Webmachine
# How to get your Webmachine app running:
- #
+ #
# MyApp = Webmachine::Application.new do |app|
# app.routes do
# add ['*'], AssetResource
# end
- #
+ #
# app.configure do |config|
# config.port = 8888
# end
# end
- #
+ #
# MyApp.run
- #
+ #
class Application
extend Forwardable
@@ -32,10 +32,10 @@ class Application
#
# An instance of application contains Adapter configuration and
# a Dispatcher instance which can be configured with Routes.
- #
+ #
# @param [Webmachine::Configuration] configuration
# a Webmachine::Configuration
- #
+ #
# @yield [app]
# a block in which to configure this Application
# @yieldparam [Application]
@@ -66,10 +66,10 @@ def adapter_class
# Evaluates the passed block in the context of {Webmachine::Dispatcher}
# for use in adding a number of routes at once.
- #
+ #
# @return [Application, Array<Route>]
# self if configuring, or an Array of Routes otherwise
- #
+ #
# @see Webmachine::Dispatcher#add_route
def routes(&block)
if block_given?
View
2 lib/webmachine/decision/flow.rb
@@ -8,7 +8,7 @@ module Decision
# This module encapsulates all of the decisions in Webmachine's
# flow-chart. These invoke {Webmachine::Resource::Callbacks} methods to
# determine the appropriate response code, headers, and body for
- # the response.
+ # the response.
#
# This module is included into {FSM}, which drives the processing
# of the chart.
View
2 lib/webmachine/decision/fsm.rb
@@ -40,7 +40,7 @@ def run
rescue Exception => e # Handle all exceptions without crashing the server
response.end_state = state
code = resource.handle_exception(e)
- code = (100...600).include?(code) ? (code) : (500)
+ code = (100...600).include?(code) ? (code) : (500)
respond(code)
end
View
6 lib/webmachine/media_type.rb
@@ -62,7 +62,7 @@ def ==(other)
# Detects whether this {MediaType} matches the other {MediaType},
# taking into account wildcards. Sub-type parameters are treated
# strictly.
- # @param [MediaType, String, Array<String,Hash>] other the other type
+ # @param [MediaType, String, Array<String,Hash>] other the other type
# @return [true,false] whether it is an acceptable match
def exact_match?(other)
other = self.class.parse(other)
@@ -73,7 +73,7 @@ def exact_match?(other)
# other {MediaType}, taking into account wildcards and satisfying
# all requested parameters, but allowing this type to have extra
# specificity.
- # @param [MediaType, String, Array<String,Hash>] other the other type
+ # @param [MediaType, String, Array<String,Hash>] other the other type
# @return [true,false] whether it is an acceptable match
def match?(other)
other = self.class.parse(other)
@@ -88,7 +88,7 @@ def match?(other)
def params_match?(other)
other.all? {|k,v| params[k] == v }
end
-
+
# Reconstitutes the type into a String
# @return [String] the type as a String
def to_s
View
2 lib/webmachine/resource.rb
@@ -38,7 +38,7 @@ def self.new(request, response)
instance.send :initialize
instance
end
-
+
private
# When no specific charsets are provided, this acts as an identity
# on the response body. Probably deserves some refactoring.
View
2 lib/webmachine/resource/authentication.rb
@@ -11,7 +11,7 @@ module Authentication
# A simple implementation of HTTP Basic auth. Call this from the
# {Webmachine::Resource::Callbacks#is_authorized?} callback,
# giving it a block which will be yielded the username and
- # password and return true or false.
+ # password and return true or false.
# @param [String] header the value of the Authentication request
# header, passed to the {Callbacks#is_authorized?} callback.
# @param [String] realm the "realm", or description of the
View
2 lib/webmachine/resource/callbacks.rb
@@ -361,7 +361,7 @@ def generate_etag
def finish_request; end
#
- # This method is called when an exception is raised within a subclass of
+ # This method is called when an exception is raised within a subclass of
# {Webmachine::Resource}.
#
# @param [Exception] e
View
6 lib/webmachine/response.rb
@@ -15,7 +15,7 @@ class Response
# @return [Array] the list of states that were traversed
attr_reader :trace
-
+
# @return [Symbol] When an error has occurred, the last state the
# FSM was in
attr_accessor :end_state
@@ -23,13 +23,13 @@ class Response
# @return [String] The error message when responding with an error
# code
attr_accessor :error
-
+
# Creates a new Response object with the appropriate defaults.
def initialize
@headers = HeaderHash.new
@trace = []
self.code = 200
- self.redirect = false
+ self.redirect = false
end
# Indicate that the response should be a redirect. This is only
View
2 spec/webmachine/configuration_spec.rb
@@ -2,7 +2,7 @@
describe Webmachine::Configuration do
before { Webmachine.configuration = nil }
-
+
%w{ip port adapter adapter_options}.each do |field|
it { should respond_to(field) }
it { should respond_to("#{field}=") }
View
20 spec/webmachine/cookie_spec.rb
@@ -5,23 +5,23 @@
let(:name) { "monster" }
let(:value) { "mash" }
let(:attributes) { {} }
-
+
let(:cookie) { Webmachine::Cookie.new(name, value, attributes) }
-
+
subject { cookie }
-
+
its(:name) { should == name }
its(:value) { should == value }
-
+
its(:to_s) { should == "monster=mash" }
-
+
describe "a cookie with whitespace in name and value" do
let(:name) { "cookie name" }
let(:value) { "cookie value" }
-
+
its(:to_s) { should == "cookie+name=cookie+value" }
end
-
+
describe "a cookie with attributes set" do
let(:domain) { "www.server.com" }
let(:path) { "/" }
@@ -41,7 +41,7 @@
:expires => expires
}
}
-
+
its(:secure?) { should be true }
its(:http_only?) { should be true }
its(:comment) { should == comment }
@@ -50,7 +50,7 @@
its(:version) { should == version }
its(:maxage) { should == maxage }
its(:expires) { should == expires }
-
+
it "should include the attributes in its string version" do
str = subject.to_s
str.should include "Secure"
@@ -80,7 +80,7 @@
describe "parsing an encoded cookie" do
let(:str) { "cookie=yum+yum" }
-
+
it("should decode the cookie") { subject.should == { "cookie" => "yum yum" } }
end
View
4 spec/webmachine/decision/conneg_spec.rb
@@ -33,7 +33,7 @@ def to_html; "hello world!"; end
"text/html;charset=iso8859-1, application/xml").
should == "text/html;charset=iso8859-1"
end
-
+
it "should choose a type more specific than requested when an exact match is not present" do
subject.choose_media_type(["application/json;v=3;foo=bar", "application/json;v=2"],
"text/html, application/json").
@@ -75,7 +75,7 @@ def to_html; "hello world!"; end
end
it "should choose the first acceptable encoding" \
- ", even when no white space after comma" do
+ ", even when no white space after comma" do
subject.choose_encoding({"gzip" => :encode_gzip}, "identity,gzip")
subject.metadata['Content-Encoding'].should == 'gzip'
response.headers['Content-Encoding'].should == 'gzip'
View
8 spec/webmachine/decision/flow_spec.rb
@@ -922,7 +922,7 @@ def delete_completed?; @completed; end
# commented for now.
# describe "#n16 (POST?)" do it; end
# describe "#o16 (PUT?)" do it; end
-
+
describe "#o18 (Multiple representations?)" do
let(:resource) do
resource_with do
@@ -947,7 +947,7 @@ def accept_all
end
end
end
-
+
[["GET", true],["HEAD", true],["PUT", true],["PUT", false],["POST",true],["POST",false],
["DELETE", true]].each do |m, e|
context "when the method is #{m} and the resource #{e ? 'exists' : 'does not exist' }" do
@@ -970,7 +970,7 @@ def accept_all
end
end
end
-
+
describe "#o20 (Response has entity?)" do
let(:resource) do
resource_with do
@@ -1081,6 +1081,6 @@ def to_html
end
end
end
-
+
end
View
7 spec/webmachine/decision/helpers_spec.rb
@@ -1,13 +1,8 @@
require 'spec_helper'
describe Webmachine::Decision::Helpers do
+ include_context "default resource"
subject { Webmachine::Decision::FSM.new(resource, request, response) }
- let(:method) { 'GET' }
- let(:uri) { URI.parse('http://localhost/') }
- let(:headers) { Webmachine::Headers.new }
- let(:body) { '' }
- let(:request) { Webmachine::Request.new(method, uri, headers, body) }
- let(:response) { Webmachine::Response.new }
def resource_with(&block)
klass = Class.new(Webmachine::Resource) do
View
2 spec/webmachine/dispatcher_spec.rb
@@ -48,7 +48,7 @@ def to_html; "goodbye, cruel world"; end
it "should apply route to request before creating the resource" do
route = dispatcher.add_route ["*"], resource
applied = false
-
+
route.should_receive(:apply) { applied = true }
resource.should_receive(:new) do
applied.should be_true
View
2 spec/webmachine/headers_spec.rb
@@ -13,7 +13,7 @@
headers["content-length"].should == 14
end
end
-
+
context "filtering with #grep" do
subject { described_class["content-type" => "text/plain", "etag" => '"abcdef1234567890"'] }
it "should filter keys by the given pattern" do
View
2 spec/webmachine/media_type_spec.rb
@@ -62,7 +62,7 @@
it { should_not be_exact_match("text/xml") }
it { should_not be_exact_match("application/xml") }
it { should_not be_exact_match("application/xml;version=1") }
-
+
it { should be_type_matches("application/xml") }
it { should be_type_matches("application/*") }
it { should be_type_matches("*/*") }
View
6 spec/webmachine/resource/authentication_spec.rb
@@ -27,7 +27,7 @@ def is_authorized?(auth)
end
end
end
-
+
context "when no authorization is sent by the client" do
it "should reply with a 401 Unauthorized and a WWW-Authenticate header using Basic" do
subject.run
@@ -46,12 +46,12 @@ def is_authorized?(auth)
before do
headers['Authorization'] = "Basic " + ["invalid:auth"].pack('m*').chomp
end
-
+
it "should reply with a 401 Unauthorized and a WWW-Authenticate header using Basic" do
subject.run
response.code.should == 401
response.headers['WWW-Authenticate'].should == 'Basic realm="Webmachine"'
- end
+ end
end
context "when the client sends valid authorization" do
View
2 spec/webmachine/trace/trace_store_spec.rb
@@ -20,7 +20,7 @@
describe Webmachine::Trace::PStoreTraceStore do
subject { described_class.new("./wmtrace") }
after { FileUtils.rm_rf("./wmtrace") }
- it_behaves_like "trace storage"
+ it_behaves_like "trace storage"
end
describe "Webmachine::Trace :memory Trace Store (Hash)" do

0 comments on commit ab18d3f

Please sign in to comment.
Something went wrong with that request. Please try again.