Permalink
Browse files

Added asserts_response context macro

  • Loading branch information...
1 parent 314e702 commit 3ad27818027cb2cbb53afa733b137a3d7e40371e @gus gus committed May 18, 2010
View
@@ -1,5 +1,23 @@
*0.0.10.pre.3*
+* Added asserts_response context macro. You can also provide method names to be called against the response. [jaknowlden]
+
+ context FoosController do
+ setup { get "/foos" }
+
+ asserts_response.exists
+ asserts_response(:status).equals(200)
+ asserts_response(:body).matches(/Bar baz/)
+ end # FoosController
+
+* Added GET support for ActionController testing, a la Rack testing methods. [jaknowlden]
+
+ context MyController do
+ setup { get "/my/dashboard", "foo" => "bar" }
+ end # MyController
+
+* Redoing support for ActionController. Dropped everything started from scratch. Also, moved the context-helper stuff into Riot and called it ContextMiddleware. Reimplemented helpers as middleware here. [jaknowlden]
+
*0.0.9.pre*
* To accommodate the last change, added concept of context helpers. It's so simple you can define your own. [jaknowlden]
@@ -1,3 +1,4 @@
require 'riot/rails'
require 'riot/action_controller/context_middleware'
+require 'riot/action_controller/context_macros/asserts_response'
require 'riot/action_controller/http_methods'
@@ -0,0 +1,11 @@
+module RiotRails
+ module ActionController
+ module AssertsResponse
+
+ def asserts_response
+ asserts("response") { response }
+ end
+
+ end # AssertsResponse
+ end # ActionController
+end # RiotRails
@@ -8,6 +8,17 @@ def handle?(context)
end # handle?
def call(context)
+ setup_context_macros(context)
+ setup_situation(context)
+ end
+ private
+ def setup_context_macros(context)
+ context.class_eval do
+ include RiotRails::ActionController::AssertsResponse
+ end
+ end
+
+ def setup_situation(context)
context.helper(:app) { @app }
context.helper(:env) { @env }
context.helper(:controller) { @controller }
@@ -0,0 +1,18 @@
+require 'teststrap'
+
+context "An asserts_response context macro" do
+ context "for context not representing an ActionController" do
+ setup { Riot::Context.new("Hello") {} }
+ asserts("asserts_response returns") { topic.asserts_response }.raises(NoMethodError)
+ end # for context not representing an ActionController
+
+ setup { Riot::Context.new(RoomsController) {} }
+
+ asserts("asserts_response returns") { topic.asserts_response }.kind_of(Riot::Assertion)
+
+ asserts("the result of assertion responds to :status") do
+ situation = Riot::Situation.new
+ situation.helper(:response) { OpenStruct.new(:status => 200) }
+ topic.asserts_response.responds_to(:status).run(situation).first
+ end.equals(:pass)
+end # An asserts_response context macro
@@ -26,7 +26,7 @@
asserts("helper request") { topic.request }.equals { assigned(:@request) }
asserts("@response") { assigned(:@response) }.kind_of(Rack::Response)
- asserts("helper response") { topic.response }.equals { assigned(:@response) }
+ asserts("helper response when no request made") { topic.response }.raises(Rack::Test::Error)
asserts_topic.responds_to(:get)
asserts_topic.responds_to(:post)
View
@@ -1,5 +1,6 @@
require 'rubygems'
require 'pathname'
+require 'ostruct'
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")

0 comments on commit 3ad2781

Please sign in to comment.