Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactor test apps.

  • Loading branch information...
commit 74e8caab3519a3e6bf3902f4e2c2f3b64e3b9144 1 parent 12d3cd4
@mdub authored
Showing with 50 additions and 52 deletions.
  1. +35 −35 spec/sham_rack_spec.rb
  2. +15 −17 spec/test_apps.rb
View
70 spec/sham_rack_spec.rb
@@ -16,7 +16,7 @@
describe "mounted Rack application" do
before(:each) do
- ShamRack.mount(SimpleMessageApp.new("Hello, world"), "www.test.xyz")
+ ShamRack.mount(GreetingApp.new, "www.test.xyz")
end
it "can be accessed using Net::HTTP" do
@@ -56,37 +56,6 @@
end
- describe "response" do
-
- before(:each) do
- ShamRack.at("www.test.xyz") do
- [
- "201 Created",
- { "Content-Type" => "text/plain", "X-Foo" => "bar" },
- ["BODY"]
- ]
- end
- @response = Net::HTTP.get_response(URI.parse("http://www.test.xyz/"))
- end
-
- it "has status returned by app" do
- @response.code.should == "201"
- end
-
- it "has body returned by app" do
- @response.body.should == "BODY"
- end
-
- it "has Content-Type returned by app" do
- @response.content_type.should == "text/plain"
- end
-
- it "has other headers returned by app" do
- @response["x-foo"].should =="bar"
- end
-
- end
-
describe ".at" do
describe "with a block" do
@@ -108,12 +77,12 @@
before do
@return_value = ShamRack.at("rackup.xyz").rackup do
use UpcaseBody
- run SimpleMessageApp.new("Racked!")
+ run GreetingApp.new
end
end
it "mounts an app created using Rack::Builder" do
- open("http://rackup.xyz").read.should == "RACKED!"
+ open("http://rackup.xyz").read.should == "HELLO, WORLD"
end
it "returns the app" do
@@ -160,10 +129,41 @@
end
+ describe "response" do
+
+ before(:each) do
+ ShamRack.at("www.test.xyz") do
+ [
+ "201 Created",
+ { "Content-Type" => "text/plain", "X-Foo" => "bar" },
+ ["BODY"]
+ ]
+ end
+ @response = Net::HTTP.get_response(URI.parse("http://www.test.xyz/"))
+ end
+
+ it "has status returned by app" do
+ @response.code.should == "201"
+ end
+
+ it "has body returned by app" do
+ @response.body.should == "BODY"
+ end
+
+ it "has Content-Type returned by app" do
+ @response.content_type.should == "text/plain"
+ end
+
+ it "has other headers returned by app" do
+ @response["x-foo"].should =="bar"
+ end
+
+ end
+
describe "Rack environment" do
before(:each) do
- @env_recorder = recorder = EnvRecordingApp.new
+ @env_recorder = recorder = EnvRecorder.new(GreetingApp.new)
ShamRack.at("env.xyz").rackup do
use Rack::Lint
run recorder
View
32 spec/test_apps.rb
@@ -1,38 +1,36 @@
-class PlainTextApp
+require "rack"
+class GreetingApp
+
+ include Rack::Utils
+
def call(env)
+ params = parse_nested_query(env["QUERY_STRING"])
+ salutation = params[:salutation] || "Hello"
+ subject = params[:subject] || "world"
+ message = "#{salutation}, #{subject}"
[
"200 OK",
{ "Content-Type" => "text/plain", "Content-Length" => message.length.to_s },
[message]
]
end
-
+
end
-class SimpleMessageApp < PlainTextApp
+class EnvRecorder
- def initialize(message)
- @message = message
+ def initialize(app)
+ @app = app
end
-
- attr_reader :message
-
-end
-
-class EnvRecordingApp < PlainTextApp
-
+
def call(env)
@last_env = env
- super
+ @app.call(env)
end
attr_reader :last_env
- def message
- "env stored for later perusal"
- end
-
end
class UpcaseBody
Please sign in to comment.
Something went wrong with that request. Please try again.