diff --git a/README.rdoc b/README.rdoc
index 7e496844..bd62965d 100644
--- a/README.rdoc
+++ b/README.rdoc
@@ -81,6 +81,10 @@ This is more ideal for rendering templates as partials from within templates
This works like Haml except you use erb instead of haml
+=== Builder
+
+See Sinatra::Builder
+
= Helpers
It is ill-advised to create helpers on (main). Use the handy helpers to install helper methods on Sinatra::EventContext for use inside events and templates.
diff --git a/lib/sinatra.rb b/lib/sinatra.rb
index c0685012..d6ac87f5 100644
--- a/lib/sinatra.rb
+++ b/lib/sinatra.rb
@@ -205,8 +205,8 @@ module Sinatra
@path, @options = path, options
end
- def to_result(cx)
- cx.body = self
+ def to_result(cx, *args)
+ self
end
def each
@@ -545,8 +545,8 @@ module Sinatra
@params ||= @route_params.merge(@request.params).symbolize_keys
end
- def stop(content)
- throw :halt, content
+ def stop(*args)
+ throw :halt, args
end
def complete(returned)
@@ -934,12 +934,14 @@ end
class Proc
def to_result(cx, *args)
cx.instance_eval(&self)
+ args.shift.to_result(cx, *args)
end
end
class String
def to_result(cx, *args)
- cx.body = self
+ args.shift.to_result(cx, *args)
+ self
end
end
@@ -958,14 +960,13 @@ end
class Fixnum
def to_result(cx, *args)
cx.status self
- cx.body args.first
+ args.shift.to_result(cx, *args)
end
end
class NilClass
def to_result(cx, *args)
- cx.body = ''
- # log warning here
+ ''
end
end
diff --git a/test/app_test.rb b/test/app_test.rb
index cfac09be..972e7c40 100644
--- a/test/app_test.rb
+++ b/test/app_test.rb
@@ -72,6 +72,20 @@ context "Sinatra" do
body.should.equal 'Hello!'
end
+
+ specify "should set status then call helper with a var" do
+ Sinatra::EventContext.any_instance.expects(:foo).once.with(1).returns('bah!')
+
+ get '/set_body' do
+ stop [404, [:foo, 1]]
+ end
+
+ get_it '/set_body'
+
+ should.be.not_found
+ body.should.equal 'bah!'
+
+ end
specify "delegates HEAD requests to GET handlers" do
get '/invisible' do