Module: Bacon_Rack
- Included in:
- Bacon::Context
- Defined in:
- lib/Bacon_Rack/module.rb
Instance Method Summary collapse
- #it_redirects(*args) ⇒ Object
- #redirects_to(status, path = nil) ⇒ Object
- #renders(status, body = nil) ⇒ Object
- #renders_assets ⇒ Object
Instance Method Details
#it_redirects(*args) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/Bacon_Rack/module.rb', line 3 def it_redirects *args case args.size when 2 req, resp, stat = args when 3 stat, req, resp = args else raise ArgumentError, "Incorrect number of arguments: #{args.inspect}" end suffix = stat ? "using #{stat}" : '' it "redirects #{req} to #{resp} #{suffix}" do get req redirects_to( *([stat, resp].compact)) yield(stat, req, resp) if block_given? end end |
#redirects_to(status, path = nil) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/Bacon_Rack/module.rb', line 20 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
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/Bacon_Rack/module.rb', line 36 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
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/Bacon_Rack/module.rb', line 59 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 |