Skip to content

Commit

Permalink
Don't clash constants in specifications
Browse files Browse the repository at this point in the history
darcs-hash:20070228182546-4fc50-0a553ddbe739f05a097186c2be4030b457aef699.gz
  • Loading branch information
leahneukirchen committed Feb 28, 2007
1 parent f428736 commit 3b23539
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 36 deletions.
6 changes: 3 additions & 3 deletions test/spec_rack_commonlogger.rb
Expand Up @@ -6,14 +6,14 @@
require 'rack/mock'

context "Rack::CommonLogger" do
App = lambda { |env|
app = lambda { |env|
[200,
{"Content-Type" => "text/html"},
["foo"]]}

specify "should log to rack.errors by default" do
log = StringIO.new
res = Rack::MockRequest.new(Rack::CommonLogger.new(App)).get("/")
res = Rack::MockRequest.new(Rack::CommonLogger.new(app)).get("/")

res.errors.should.not.be.empty
res.errors.should =~ /GET /
Expand All @@ -23,7 +23,7 @@

specify "should log to anything with <<" do
log = ""
res = Rack::MockRequest.new(Rack::CommonLogger.new(App, log)).get("/")
res = Rack::MockRequest.new(Rack::CommonLogger.new(app, log)).get("/")

log.should =~ /GET /
log.should =~ / 200 / # status
Expand Down
66 changes: 33 additions & 33 deletions test/spec_rack_mock.rb
Expand Up @@ -3,23 +3,23 @@
require 'rack/request'
require 'rack/response'

context "Rack::MockRequest" do
App = lambda { |env|
req = Rack::Request.new(env)

env["mock.postdata"] = env["rack.input"].read
if req.GET["error"]
env["rack.errors"].puts req.GET["error"]
env["rack.errors"].flush
end

Rack::Response.new(env.to_yaml,
req.GET["status"] || 200,
"Content-Type" => "text/yaml").finish
}
app = lambda { |env|
req = Rack::Request.new(env)

env["mock.postdata"] = env["rack.input"].read
if req.GET["error"]
env["rack.errors"].puts req.GET["error"]
env["rack.errors"].flush
end

Rack::Response.new(env.to_yaml,
req.GET["status"] || 200,
"Content-Type" => "text/yaml").finish
}

context "Rack::MockRequest" do
specify "should return a MockResponse" do
res = Rack::MockRequest.new(App).get("")
res = Rack::MockRequest.new(app).get("")
res.should.be.kind_of Rack::MockResponse
end

Expand All @@ -30,7 +30,7 @@
end

specify "should provide sensible defaults" do
res = Rack::MockRequest.new(App).request
res = Rack::MockRequest.new(app).request

env = YAML.load(res.body)
env["REQUEST_METHOD"].should.equal "GET"
Expand All @@ -44,19 +44,19 @@
end

specify "should allow GET/POST/PUT/DELETE" do
res = Rack::MockRequest.new(App).get("", :input => "foo")
res = Rack::MockRequest.new(app).get("", :input => "foo")
env = YAML.load(res.body)
env["REQUEST_METHOD"].should.equal "GET"

res = Rack::MockRequest.new(App).post("", :input => "foo")
res = Rack::MockRequest.new(app).post("", :input => "foo")
env = YAML.load(res.body)
env["REQUEST_METHOD"].should.equal "POST"

res = Rack::MockRequest.new(App).put("", :input => "foo")
res = Rack::MockRequest.new(app).put("", :input => "foo")
env = YAML.load(res.body)
env["REQUEST_METHOD"].should.equal "PUT"

res = Rack::MockRequest.new(App).delete("", :input => "foo")
res = Rack::MockRequest.new(app).delete("", :input => "foo")
env = YAML.load(res.body)
env["REQUEST_METHOD"].should.equal "DELETE"

Expand All @@ -65,17 +65,17 @@
end

specify "should allow posting" do
res = Rack::MockRequest.new(App).get("", :input => "foo")
res = Rack::MockRequest.new(app).get("", :input => "foo")
env = YAML.load(res.body)
env["mock.postdata"].should.equal "foo"

res = Rack::MockRequest.new(App).post("", :input => StringIO.new("foo"))
res = Rack::MockRequest.new(app).post("", :input => StringIO.new("foo"))
env = YAML.load(res.body)
env["mock.postdata"].should.equal "foo"
end

specify "should use all parts of an URL" do
res = Rack::MockRequest.new(App).
res = Rack::MockRequest.new(app).
get("https://bla.example.org:9292/meh/foo?bar")
res.should.be.kind_of Rack::MockResponse

Expand All @@ -90,36 +90,36 @@

specify "should behave valid according to the Rack spec" do
lambda {
res = Rack::MockRequest.new(App).
res = Rack::MockRequest.new(app).
get("https://bla.example.org:9292/meh/foo?bar", :lint => true)
}.should.not.raise(Rack::Lint::LintError)
end
end

context "Rack::MockResponse" do
specify "should provide access to the HTTP status" do
res = Rack::MockRequest.new(App).get("")
res = Rack::MockRequest.new(app).get("")
res.should.be.successful
res.should.be.ok

res = Rack::MockRequest.new(App).get("/?status=404")
res = Rack::MockRequest.new(app).get("/?status=404")
res.should.not.be.successful
res.should.be.client_error
res.should.be.not_found

res = Rack::MockRequest.new(App).get("/?status=501")
res = Rack::MockRequest.new(app).get("/?status=501")
res.should.not.be.successful
res.should.be.server_error

res = Rack::MockRequest.new(App).get("/?status=307")
res = Rack::MockRequest.new(app).get("/?status=307")
res.should.be.redirect

res = Rack::MockRequest.new(App).get("/?status=201", :lint => true)
res = Rack::MockRequest.new(app).get("/?status=201", :lint => true)
res.should.be.empty
end

specify "should provide access to the HTTP headers" do
res = Rack::MockRequest.new(App).get("")
res = Rack::MockRequest.new(app).get("")
res.should.include "Content-Type"
res.headers["Content-Type"].should.equal "text/yaml"
res.original_headers["Content-Type"].should.equal "text/yaml"
Expand All @@ -129,22 +129,22 @@
end

specify "should provide access to the HTTP body" do
res = Rack::MockRequest.new(App).get("")
res = Rack::MockRequest.new(app).get("")
res.body.should =~ /rack/
res.should =~ /rack/
res.should.match /rack/
end

specify "should provide access to the Rack errors" do
res = Rack::MockRequest.new(App).get("/?error=foo", :lint => true)
res = Rack::MockRequest.new(app).get("/?error=foo", :lint => true)
res.should.be.ok
res.errors.should.not.be.empty
res.errors.should.include "foo"
end

specify "should optionally make Rack errors fatal" do
lambda {
Rack::MockRequest.new(App).get("/?error=foo", :fatal => true)
Rack::MockRequest.new(app).get("/?error=foo", :fatal => true)
}.should.raise(Rack::MockRequest::FatalWarning)
end
end

0 comments on commit 3b23539

Please sign in to comment.