Module: Bacon_Rack
- Included in:
- Bacon::Context
- Defined in:
- lib/Bacon_Rack/module.rb
Instance Method Summary collapse
- #redirects_to(status, path = nil) ⇒ Object
- #renders(status, body = nil) ⇒ Object
- #renders_assets ⇒ Object
Instance Method Details
#redirects_to(status, path = nil) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/Bacon_Rack/module.rb', line 3 def redirects_to status, path = nil if status.is_a?(Integer) # do nothing else path, status = status, path end status ||= [ 301, 302, 303, 307 ] status = [ status ].compact.flatten status.should.include last_response.status last_response['Location'].sub(%r!http://(www.)?example\.com!, '') .should == path end |
#renders(status, body = nil) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/Bacon_Rack/module.rb', line 19 def renders status, body = nil case status when Regexp, String body, status = status, body else # do nothing end status ||= 200 l = last_response l.status.should == status case body when Regexp l.body.should.match body else l.body.should == body end [ nil, l.body.bytesize.to_s ] .should.include l['Content-Length'] end |
#renders_assets ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/Bacon_Rack/module.rb', line 42 def renders_assets files = last_response.body \ .scan( %r!"(/[^"]+.(js|css|png|gif|ico|jpg|jpeg)[^"]*)"!i ) \ .map(&:first) files.each { |f| get f (200..310).should.include last_response.status } end |