lib/roar/rails/test_case.rb in roar-0.9.0 vs lib/roar/rails/test_case.rb in roar-0.9.1

- old
+ new

@@ -1,43 +1,69 @@ -require 'test_xml/test_unit' +#require 'test_xml/test_unit' +require 'action_controller/test_case' -ActionController::TestCase.class_eval do +module Roar::Rails + module TestCase + def process(action, *args) + raise + if args.first.is_a?(String) + puts "YO" + request.env['RAW_POST_DATA'] = args.shift + method = args.pop + args << nil + args << method + end + + super + end + + def assert_response(status, headers={}) # FIXME: allow message. + super + + if headers.is_a?(Hash) + assert_headers(headers) + else + assert_body(headers) + end + end + + def assert_headers(headers) + headers.each_pair do |k,v| + assert_equal v, @response.headers[k] + end + end + + def assert_body(body, options={}) + return assert_xml_equal body, @response.body if options[:format] == :xml # FIXME: how do we know whether assert_xml is appropriate? + assert_equal body, @response.body + end + end +end + + +ActionController::TestCase::Behavior.class_eval do # FIXME: ugly monkey-patching. # TODO: test: # put :create # put :create, :format => :xml # put :create, "<order/>", :format => :xml # put :create, "<order/>" + + + include Roar::Rails::TestCase +end + +RSpec::Rails::ControllerExampleGroup.class_eval do + #include Roar::Rails::TestCase + # FIXME: include module! + def process(action, *args) if args.first.is_a?(String) request.env['RAW_POST_DATA'] = args.shift method = args.pop args << nil args << method end - - super - end - def assert_response(status, headers={}) # FIXME: allow message. super - - if headers.is_a?(Hash) - assert_headers(headers) - else - assert_body(headers) - end end - - def assert_headers(headers) - headers.each_pair do |k,v| - assert_equal v, @response.headers[k] - end - end - - def assert_body(body, options={}) - return assert_xml_equal body, @response.body if options[:format] == :xml # FIXME: how do we know whether assert_xml is appropriate? - assert_equal body, @response.body - end - - end