Skip to content
Browse files

Switch to full stack, rack-test based specs

  • Loading branch information...
1 parent 8b6d2c2 commit 2ae3a6f32a634ed81863e4211859217ea08707ad Andy Delcambre committed Apr 2, 2010
Showing with 38 additions and 22 deletions.
  1. +3 −1 Gemfile
  2. +11 −4 spec/controllers/action_args_controller.rb
  3. +23 −17 spec/rails_action_args_spec.rb
  4. +1 −0 spec/spec_helper.rb
View
4 Gemfile
@@ -3,6 +3,8 @@ source :gemcutter
gem "rspec"
gem "rack"
gem "actionpack", "3.0.0.beta2", :require => "action_controller"
+gem "railties", "3.0.0.beta2", :require => "rails"
gem "ParseTree"
gem "ruby2ruby"
-gem "rake"
+gem "rake"
+gem "rack-test", :require => "rack/test"
View
15 spec/controllers/action_args_controller.rb
@@ -3,10 +3,6 @@ class ApplicationController < ActionController::Base
end
module ExtraActions
- # def self.included(base)
- # base.show_action(:funky_inherited_method)
- # end
-
def funky_inherited_method(foo, bar)
render :text => "#{foo} #{bar}"
end
@@ -57,3 +53,14 @@ def with_default_array(foo, bar = [])
end
+class MyApp < Rails::Application
+ config.session_store :disabled
+
+ routes.draw do
+ match "/awesome/index" => "Awesome::ActionArgs#index"
+
+ controller :action_args do
+ match "/action_args/:action"
+ end
+ end
+end
View
40 spec/rails_action_args_spec.rb
@@ -1,57 +1,63 @@
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
describe "RailsActionArgs" do
+ def app
+ MyApp
+ end
+
it "should be able to handle a nested class" do
- Awesome::ActionArgsController.action(:index).call(Rack::MockRequest.env_for("/?foo=bar"))[2].body.should == "bar"
+ request("/awesome/index?foo=bar").body.should == "bar"
end
it "should be able to handle no arguments" do
- ActionArgsController.action(:nada).call(Rack::MockRequest.env_for("/"))[2].body.should == "NADA"
+ request("/action_args/nada").body.should == "NADA"
end
it "should be able to accept Action Arguments" do
- ActionArgsController.action(:index).call(Rack::MockRequest.env_for("/?foo=bar"))[2].body.should == "bar"
+ request("/action_args/index?foo=bar").body.should == "bar"
end
it "should be able to accept multiple Action Arguments" do
- ActionArgsController.action(:multi).call(Rack::MockRequest.env_for("/?foo=bar&bar=baz"))[2].body.should == "bar baz"
+ request("/action_args/multi?foo=bar&bar=baz").body.should == "bar baz"
end
it "should be able to handle defaults in Action Arguments" do
- ActionArgsController.action(:defaults).call(Rack::MockRequest.env_for("/?foo=bar"))[2].body.should == "bar bar"
+ request("/action_args/defaults?foo=bar").body.should == "bar bar"
end
it "should be able to handle out of order defaults" do
- ActionArgsController.action(:defaults_mixed).call(Rack::MockRequest.env_for("/?foo=bar&baz=bar"))[2].body.should == "bar bar bar"
+ request("/action_args/defaults_mixed?foo=bar&baz=bar").body.should == "bar bar bar"
end
- it "should throw a BadRequest if the arguments are not provided" do
- lambda { ActionArgsController.action(:index).call(Rack::MockRequest.env_for("/")) }.should raise_error(AbstractController::BadRequest)
+ it "should throw a 400 Bad Request if the arguments are not provided" do
+ request("/action_args/index").status.should == 400
end
it "should treat define_method actions as equal" do
- ActionArgsController.action(:dynamic_define_method).call(Rack::MockRequest.env_for("/"))[2].body.should == "mos def"
+ request("/action_args/dynamic_define_method").body.should == "mos def"
end
it "should be able to inherit actions for use with Action Arguments" do
- ActionArgsController.action(:funky_inherited_method).call(Rack::MockRequest.env_for("/?foo=bar&bar=baz"))[2].body.should == "bar baz"
+ request("/action_args/funky_inherited_method?foo=bar&bar=baz").body.should == "bar baz"
end
it "should be able to handle nil defaults" do
- ActionArgsController.action(:with_default_nil).call(Rack::MockRequest.env_for("/?foo=bar"))[2].body.should == "bar "
+ request("/action_args/with_default_nil?foo=bar").body.should == "bar "
end
it "should be able to handle [] defaults" do
- ActionArgsController.action(:with_default_array).call(Rack::MockRequest.env_for("/?foo=bar"))[2].body.should == "bar []"
+ request("/action_args/with_default_array?foo=bar").body.should == "bar []"
end
it "should print out the missing parameters if all are required" do
- lambda { ActionArgsController.action(:multi).call(Rack::MockRequest.env_for("/")) }.should raise_error(
- AbstractController::BadRequest, /were missing foo, bar/)
+ response = request("/action_args/multi")
+ response.status.should == 400
+ response.body.should include("were missing foo, bar")
end
-
+
it "should only print out missing parameters" do
- lambda { ActionArgsController.action(:multi).call(Rack::MockRequest.env_for("/?foo=Hello")) }.should raise_error(
- AbstractController::BadRequest, /were missing bar/)
+ response = request("/action_args/multi?foo=Hello")
+ response.status.should == 400
+ response.body.should include("were missing bar")
end
end
View
1 spec/spec_helper.rb
@@ -8,4 +8,5 @@
require File.expand_path(File.join(File.dirname(__FILE__), "controllers", "action_args_controller"))
Spec::Runner.configure do |config|
+ config.include(Rack::Test::Methods)
end

0 comments on commit 2ae3a6f

Please sign in to comment.
Something went wrong with that request. Please try again.