BVB Source Codes

guard-livereload Show dispatcher_spec.rb Source code

Return Download guard-livereload: download dispatcher_spec.rb Source code - Download guard-livereload Source code - Type:.rb
  1. RSpec.describe Guard::LiveReload::WebSocket::Dispatcher do
  2.   let(:options) { { livereload_js_path: '/tmp/foo.js.123' } }
  3.   subject { described_class.new(options) }
  4.  
  5.   def http_request(type, path)
  6.     [
  7.       "#{type} #{path} HTTP/1.1",
  8.       'Host: 127.0.0.1:35729',
  9.       'Connection: keep-alive',
  10.       'Accept: */*',
  11.       'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36',
  12.       'Referer: http://localhost:4000/foo.html',
  13.       'Accept-Encoding: gzip, deflate, sdch',
  14.       'Accept-Language: en-US,en;q=0.8,pl;q=0.6',
  15.       '',
  16.       ''
  17.     ].join("\r\n")
  18.   end
  19.  
  20.   describe '#dispatch' do
  21.     context 'with a request for livereload.js' do
  22.       let(:data) { http_request('GET', '/livereload.js?ext=Chrome&extver=2.1.0') }
  23.  
  24.       before do
  25.         allow(File).to receive(:size).with('/tmp/foo.js.123').and_return(123)
  26.       end
  27.  
  28.       it 'sends livereload files' do
  29.         expected = "HTTP/1.1 200 OK\r\nContent-Type: application/ecmascript\r\nContent-Length: 123\r\n\r\n"
  30.         expect(subject.dispatch(data)).to eq([[:data, expected], [:file, '/tmp/foo.js.123']])
  31.       end
  32.     end
  33.  
  34.     context 'with a non-GET request' do
  35.       let(:data) { http_request('DELETE', '/livereload.js?ext=Chrome&extver=2.1.0') }
  36.  
  37.       it 'lets the socket process the request' do
  38.         expect(subject.dispatch(data)).to eq([[:default, nil]])
  39.       end
  40.     end
  41.  
  42.     context 'with a request for a non-existing file' do
  43.       let(:data) { http_request('GET', '/nosuchfile.js?ext=Chrome&extver=2.1.0') }
  44.  
  45.       it 'responds with a 404' do
  46.         expected = "HTTP/1.1 404 Not Found\r\nContent-Type: text/plain\r\nContent-Length: 13\r\n\r\n404 Not Found"
  47.         expect(subject.dispatch(data)).to eq([[:data, expected], [:close_write, nil]])
  48.       end
  49.     end
  50.  
  51.     context 'with a request for file outside the project' do
  52.       let(:data) { http_request('GET', '/./../Rakefile?ext=Chrome&extver=2.1.0') }
  53.  
  54.       before do
  55.         allow(File).to receive(:readable?).with('././../Rakefile').and_return(true)
  56.       end
  57.  
  58.       it 'responds with a 403' do
  59.         expected = "HTTP/1.1 403 Forbidden\r\nContent-Type: text/plain\r\nContent-Length: 13\r\n\r\n403 Forbidden"
  60.         expect(subject.dispatch(data)).to eq([[:data, expected], [:close_write, nil]])
  61.       end
  62.     end
  63.   end
  64. end
  65.  
downloaddispatcher_spec.rb Source code - Download guard-livereload Source code
Related Source Codes/Software:
Begin-Latex-in-minutes - Brief Intro to LaTeX for beginners that helps you ... 2017-04-22
wicked - Use wicked to turn your controller into a wizard ... 2017-04-22
flexboxfroggy - A game for learning CSS flexbox ... 2017-04-22
phpDocumentor2 - Documentation Generator for PHP ... 2017-04-22
cmus - Small, fast and powerful console music player for ... 2017-04-22
grit - **Grit is no longer maintained. Check out libgit2/... 2017-04-22
grr - GRR Rapid Response: remote live forensics for inci... 2017-04-22
libsvm - 2017-04-22
breakpoint - Really simple media queries in Sa 2017-04-23
CoffeeScriptRedux - 2017-04-23
PreloadJS - PreloadJS makes preloading assets & getting ag... 2017-04-29
gotraining - Go Training Class Material : ... 2017-04-29
eigen - The Art World in Your Pocket or Your Trendy Tech C... 2017-04-29
rack-cors - Rack Middleware for handling Cross-Origin Resource... 2017-04-29
react-redux-tutorial - react-redux-tutorial in Chinese, catalog &&... 2017-04-29
swifter - Tiny http server engine written in Swift programmi... 2017-04-29
Chartbuilder - A front-end charting application that facilitates ... 2017-04-29
offline-first - 2017-04-29
plotly.py - An interactive, browser-based graphing library for... 2017-04-29
statsmodels - Statsmodels: statistical modeling and econometrics... 2017-04-29

 Back to top