spec/unit/rack/validation/request_method_spec.rb in goliath-0.9.1 vs spec/unit/rack/validation/request_method_spec.rb in goliath-0.9.2

- old
+ new

@@ -1,11 +1,15 @@ require 'spec_helper' require 'goliath/rack/validation/request_method' describe Goliath::Rack::Validation::RequestMethod do before(:each) do + @app_headers = {'Content-Type' => 'asdf'} + @app_body = {'a' => 'b'} + @app = mock('app').as_null_object + @app.stub!(:call).and_return([200, @app_headers, @app_body]) end it 'accepts an app' do lambda { Goliath::Rack::Validation::RequestMethod.new('my app') }.should_not raise_error end @@ -16,28 +20,24 @@ @rm = Goliath::Rack::Validation::RequestMethod.new(@app, ['GET', 'POST']) end it 'raises error if method is invalid' do @env['REQUEST_METHOD'] = 'fubar' - lambda { @rm.call(@env) }.should raise_error(Goliath::Validation::Error) + @rm.call(@env).should == [405, {'Allow' => 'GET, POST'}, {:error => "Invalid request method"}] end it 'allows valid methods through' do @env['REQUEST_METHOD'] = 'GET' - lambda { @rm.call(@env) }.should_not raise_error + @rm.call(@env).should == [200, @app_headers, @app_body] end it 'returns app status, headers and body' do - app_headers = {'Content-Type' => 'asdf'} - app_body = {'a' => 'b'} - @app.should_receive(:call).and_return([200, app_headers, app_body]) - @env['REQUEST_METHOD'] = 'POST' status, headers, body = @rm.call(@env) status.should == 200 - headers.should == app_headers - body.should == app_body + headers.should == @app_headers + body.should == @app_body end end it 'accepts methods on initialize' do rm = Goliath::Rack::Validation::RequestMethod.new('my app', ['GET', 'DELETE', 'HEAD']) \ No newline at end of file