Sha256: be30255dd55cea696ad1bb5d7e1d187a3c60ae436ee5f2ca3a7308df8c09800a
Contents?: true
Size: 1.76 KB
Versions: 1
Compression:
Stored size: 1.76 KB
Contents
module ShouldBeRestful module Macros # Generates a full suite of tests for a restful controller. # # The following definition will generate tests for the +index+, +show+, +new+, # +edit+, +create+, +update+ and +destroy+ actions, in both +html+ and +xml+ formats: # # should_be_restful do |resource| # resource.parent = :user # # resource.create.params = { :title => "first post", :body => 'blah blah blah'} # resource.update.params = { :title => "changed" } # end # # This generates about 40 tests, all of the format: # "on GET to :show should assign @user." # "on GET to :show should not set the flash." # "on GET to :show should render 'show' template." # "on GET to :show should respond with success." # "on GET to :show as xml should assign @user." # "on GET to :show as xml should have ContentType set to 'application/xml'." # "on GET to :show as xml should respond with success." # "on GET to :show as xml should return <user/> as the root element." # The +resource+ parameter passed into the block is a ResourceOptions object, and # is used to configure the tests for the details of your resources. # def should_be_restful(&blk) # :yields: resource resource = ResourceOptions.new blk.call(resource) resource.normalize!(self) resource.formats.each do |format| resource.actions.each do |action| if self.respond_to? :"make_#{action}_#{format}_tests" self.send(:"make_#{action}_#{format}_tests", resource) else should "test #{action} #{format}" do flunk "Test for #{action} as #{format} not implemented" end end end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
khalsah-should_be_restful-1.0.0 | lib/should_be_restful/macros.rb |