rack-livereload/spec/rack/livereload/processing_skip_analyzer_sp...

131 lines
2.7 KiB
Ruby
Raw Normal View History

2013-04-23 20:28:23 +00:00
require 'spec_helper'
describe Rack::LiveReload::ProcessingSkipAnalyzer do
subject { described_class.new(result, env, options) }
let(:result) { [ status, headers, body ] }
let(:env) { { 'HTTP_USER_AGENT' => user_agent } }
let(:options) { {} }
let(:user_agent) { 'Firefox' }
let(:status) { 200 }
let(:headers) { {} }
let(:body) { [] }
describe '#skip_processing?' do
it "should skip processing" do
subject.skip_processing?.should be_true
end
end
2013-08-20 20:55:47 +00:00
describe '#ignored?' do
2013-04-23 20:28:23 +00:00
let(:options) { { :ignore => [ %r{file} ] } }
2013-08-20 20:55:47 +00:00
context 'path contains ignore pattern' do
2013-04-23 20:28:23 +00:00
let(:env) { { 'PATH_INFO' => '/this/file' } }
it { should be_ignored }
end
2013-08-20 20:55:47 +00:00
context 'root path' do
2013-04-23 20:28:23 +00:00
let(:env) { { 'PATH_INFO' => '/' } }
it { should_not be_ignored }
end
end
2013-08-20 20:55:47 +00:00
describe '#chunked?' do
context 'regular response' do
it { should_not be_chunked }
end
2013-04-23 20:28:23 +00:00
2013-08-20 20:55:47 +00:00
context 'chunked response' do
let(:headers) { { 'Transfer-Encoding' => 'chunked' } }
2013-04-23 20:28:23 +00:00
2013-08-20 20:55:47 +00:00
it { should be_chunked }
end
2013-04-23 20:28:23 +00:00
end
2013-08-20 20:55:47 +00:00
describe '#inline?' do
context 'inline disposition' do
let(:headers) { { 'Content-Disposition' => 'inline; filename=my_inlined_file' } }
2013-04-23 20:28:23 +00:00
2013-08-20 20:55:47 +00:00
it { should be_inline }
end
2013-04-23 20:28:23 +00:00
end
describe '#ignored?' do
let(:path_info) { 'path info' }
let(:env) { { 'PATH_INFO' => path_info } }
context 'no ignore set' do
it { should_not be_ignored }
end
context 'ignore set' do
let(:options) { { :ignore => [ %r{#{path_info}} ] } }
it { should be_ignored }
end
end
2013-08-20 20:55:47 +00:00
describe '#bad_browser?' do
context 'Firefox' do
it { should_not be_bad_browser }
end
context 'BAD browser' do
let(:user_agent) { described_class::BAD_USER_AGENTS.first.source }
it { should be_bad_browser }
end
end
describe '#html?' do
context 'HTML content' do
let(:headers) { { 'Content-Type' => 'text/html' } }
it { should be_html }
end
context 'PDF content' do
let(:headers) { { 'Content-Type' => 'application/pdf' } }
it { should_not be_html }
end
end
describe '#get?' do
context 'GET request' do
let(:env) { { 'REQUEST_METHOD' => 'GET' } }
it { should be_get }
end
context 'PUT request' do
let(:env) { { 'REQUEST_METHOD' => 'PUT' } }
it { should_not be_get }
end
context 'POST request' do
let(:env) { { 'REQUEST_METHOD' => 'POST' } }
it { should_not be_get }
end
context 'DELETE request' do
let(:env) { { 'REQUEST_METHOD' => 'DELETE' } }
it { should_not be_get }
end
context 'PATCH request' do
let(:env) { { 'REQUEST_METHOD' => 'PATCH' } }
it { should_not be_get }
end
end
2013-04-23 20:28:23 +00:00
end