Skip to content

Commit

Permalink
resurrecting old tests where applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
automatthew committed Jan 1, 2009
1 parent bdd2ab5 commit 662b85d
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/runtime/configurations.rb
@@ -0,0 +1,19 @@
require "#{File.dirname(__FILE__)}/../helpers.rb"

describe "Configuration attributes" do

class Basic < Waves::Configurations::Base; end

it "can be declared by developers" do
Basic.attribute :smurf
Basic.smurf("smurfy")
Basic.smurf.should == "smurfy"
end


it "must be declared before use" do
Basic.should.not.respond_to :gnome
end

end

63 changes: 63 additions & 0 deletions test/runtime/request.rb
@@ -0,0 +1,63 @@
require "#{File.dirname(__FILE__)}/../helpers.rb"

describe "A Waves request instance" do

before do
@request = Waves::Request.new(env( '/', :method => 'GET' ))
end

it "has session, response, and blackboard objects" do
@request.session.class.should == Waves::Session
@request.response.class.should == Waves::Response
end

it "provides an accessor to the Rack request" do
@request.rack_request.class.should == Rack::Request
end

it "wraps some useful Rack data in more elegant methods" do
@request.path.should == "/"

@request.domain.should == "example.org"

# @request.content_type.should == "text/html"
end

# it "delegates unknown methods to the Rack request" do
# @request.chitty_bang_bang
# end

end

describe "The HTTP request method" do


it "is determined in a straightforward manner for straightforward requests" do
@get = Waves::Request.new(env("/", :method => 'GET'))
@post = Waves::Request.new(env("/", :method => 'POST'))
@put = Waves::Request.new(env("/", :method => 'PUT'))
@delete = Waves::Request.new(env("/", :method => 'DELETE'))

@get.method.should == :get
@post.method.should == :post
@put.method.should == :put
@delete.method.should == :delete
end

it "can be set with the '_method' query param on a POST" do
@url_put = Waves::Request.new(env("/?_method=put", :method => 'POST'))
@url_delete = Waves::Request.new(env("/?_method=delete", :method => 'POST'))

@url_put.method.should == :put; @url_put.put.should.be.true
@url_delete.method.should == :delete; @url_delete.delete.should.be.true
end

it "can be set with the '_method' body param on a POST" do
@body_put = Waves::Request.new(env("/", :method => 'POST', :input => '_method=put'))
@body_delete = Waves::Request.new(env("/", :method => 'POST', :input => '_method=delete'))

@body_put.method.should == :put; @body_put.put.should.be.true
@body_delete.method.should == :delete
end

end
55 changes: 55 additions & 0 deletions test/runtime/response.rb
@@ -0,0 +1,55 @@
require "#{File.dirname(__FILE__)}/../helpers.rb"

describe "An instance of Waves::Response" do

before do
@request = Waves::Request.new(env( '/', :method => 'GET' ))
@response = Waves::Response.new(@request)
end

it "has a Rack::Response" do
@response.rack_response.class.should == Rack::Response
end

it "has a Waves::Request" do
@response.request.class.should == Waves::Request
end

it "can access the session for the current request" do
@response.session.class.should == Waves::Session
end

it "provides setter methods for commonly used headers" do
@response.rack_response.should.receive(:[]=).with('Content-Type', 'text/javascript')
@response.content_type = 'text/javascript'

@response.rack_response.should.receive(:[]=).with('Content-Length', '42')
@response.content_length = '42'

@response.rack_response.should.receive(:[]=).with('Location', '/here/')
@response.location = '/here/'

@response.rack_response.should.receive(:[]=).with('Expires', 'Thu, 09 Aug 2007 05:22:55 GMT')
@response.expires = 'Thu, 09 Aug 2007 05:22:55 GMT'
end

it "delegates unknown methods to the Rack response" do
@response.rack_response.should.receive(:mclintock!)
@response.mclintock!
end

end

describe "Waves::Response#finish" do

before do
@request = Waves::Request.new(env( '/', :method => 'GET' ))
@response = Waves::Response.new(@request)
end

it "saves the request session and calls Rack::Response#finish" do
@response.rack_response.should.receive(:finish)
@response.finish
end

end

0 comments on commit 662b85d

Please sign in to comment.