rspec and testing various return types

I’ve just started a new project so I’m starting with 1.2RC and the experimenting with BDD with rspec.

I won’t delve into either as folks with more FU than myself have explored both topics.

Specifically though I have run into problems with rspec and the new simply_helpful - thankfully Lourens of methodmissing has nailed down a monkey patch.

Laurens also supplies a monkey patch to permit testing of various return types - but, alas, since rspec is maturing at the speed of light it doesn’t work with rspec 0.7.4.

Following is a mod of Lauren’s patch that’ll get your specifies testing RSS, XML, et al.

1
2
3
4
5
6
7
8
9

class Test::Unit::TestCase
  %w(get put post head delete).each{|m| define_method(m.to_sym) do |*args|
      @request.env['REQUEST_METHOD'] = m.upcase
      @request.env['CONTENT_TYPE'] = Mime::EXTENSION_LOOKUP[(args[2].nil? ? 'html' : args[2].to_s )]
      process( args[0], args[1] || {} )  
    end
  }   
end

put this in your spechelper.rb, after require ‘rspecon_rails’ and before your Test::Rails::Testcase definition.

Gotta a comment?

1 Response to “rspec and testing various return types”

  1. Joesph Bass Says:

    x0hu22dy56awftst

Leave a comment