File: processing_skip_analyzer_spec.rb

package info (click to toggle)
ruby-rack-livereload 0.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 244 kB
  • sloc: javascript: 974; ruby: 477; makefile: 4
file content (143 lines) | stat: -rw-r--r-- 3,196 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
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_truthy
    end
  end

  describe '#ignored?' do
    let(:options) { { :ignore => [ %r{file} ] } }

    context 'path contains ignore pattern' do
      let(:env) { { 'PATH_INFO' => '/this/file', 'QUERY_STRING' => '' } }

      it { should be_ignored }
    end

    context 'root path' do
      let(:env) { { 'PATH_INFO' => '/', 'QUERY_STRING' => '' } }

      it { should_not be_ignored }
    end
  end

  describe '#chunked?' do
    context 'regular response' do
      it { should_not be_chunked }
    end

    context 'chunked response' do
      let(:headers) { { 'transfer-encoding' => 'chunked' } }

      it { should be_chunked }
    end
  end

  describe '#inline?' do
    context 'inline disposition' do
      let(:headers) { { 'content-disposition' => 'inline; filename=my_inlined_file' } }

      it { should be_inline }
    end
  end

  describe '#ignored?' do
    let(:path_info) { 'path info' }
    let(:query_string) { 'query_string' }
    let(:env) { { 'PATH_INFO' => path_info, 'QUERY_STRING' => query_string } }

    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

    context 'ignore set including query_string' do
      let(:options) { { :ignore => [ %r{#{path_info}\?#{query_string}} ] } }

      it { should be_ignored }
    end
  end

  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 'XHTML content' do
      let(:headers) { { 'content-type' => 'application/xhtml+xml' } }

      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
end