|
1 |
| -require 'spec_helper' |
| 1 | +require "spec_helper" |
2 | 2 |
|
3 | 3 | describe(Jekyll::Gist::GistTag) do
|
4 | 4 | let(:http_output) { "<test>true</test>" }
|
5 | 5 | let(:doc) { doc_with_content(content) }
|
6 |
| - let(:content) { "{% gist #{gist} %}" } |
| 6 | + let(:content) { "{% gist #{gist} %}" } |
7 | 7 | let(:output) do
|
8 | 8 | doc.content = content
|
9 | 9 | doc.output = Jekyll::Renderer.new(doc.site, doc).run
|
|
13 | 13 |
|
14 | 14 | context "valid gist" do
|
15 | 15 | context "with user prefix" do
|
16 |
| - before { stub_request(:get, "https://gist.githubusercontent.com/#{gist}/raw").to_return(body: http_output) } |
| 16 | + before { stub_request(:get, "https://gist.githubusercontent.com/#{gist}/raw").to_return(:body => http_output) } |
17 | 17 | let(:gist) { "mattr-/24081a1d93d2898ecf0f" }
|
18 | 18 |
|
19 | 19 | it "produces the correct script tag" do
|
20 |
| - expect(output).to match(/<script src="https:\/\/gist.github.com\/#{gist}.js">\s<\/script>/) |
| 20 | + expect(output).to match(%r!<script src="https:\/\/gist.github.com\/#{gist}.js">\s<\/script>!) |
21 | 21 | end
|
22 | 22 | it "produces the correct noscript tag" do
|
23 |
| - expect(output).to match(/<noscript><pre><test>true<\/test><\/pre><\/noscript>\n/) |
| 23 | + expect(output).to match(%r!<noscript><pre><test>true<\/test><\/pre><\/noscript>\n!) |
24 | 24 | end
|
25 | 25 | end
|
26 | 26 |
|
27 | 27 | context "without user prefix" do
|
28 |
| - before { stub_request(:get, "https://gist.githubusercontent.com/#{gist}/raw").to_return(body: http_output) } |
| 28 | + before { stub_request(:get, "https://gist.githubusercontent.com/#{gist}/raw").to_return(:body => http_output) } |
29 | 29 | let(:gist) { "28949e1d5ee2273f9fd3" }
|
30 | 30 |
|
31 | 31 | it "produces the correct script tag" do
|
32 |
| - expect(output).to match(/<script src="https:\/\/gist.github.com\/#{gist}.js">\s<\/script>/) |
| 32 | + expect(output).to match(%r!<script src="https:\/\/gist.github.com\/#{gist}.js">\s<\/script>!) |
33 | 33 | end
|
34 | 34 | it "produces the correct noscript tag" do
|
35 |
| - expect(output).to match(/<noscript><pre><test>true<\/test><\/pre><\/noscript>\n/) |
| 35 | + expect(output).to match(%r!<noscript><pre><test>true<\/test><\/pre><\/noscript>\n!) |
36 | 36 | end
|
37 | 37 | end
|
38 | 38 |
|
39 | 39 | context "classic Gist id style" do
|
40 |
| - before { stub_request(:get, "https://gist.githubusercontent.com/#{gist}/raw").to_return(body: http_output) } |
| 40 | + before { stub_request(:get, "https://gist.githubusercontent.com/#{gist}/raw").to_return(:body => http_output) } |
41 | 41 | let(:gist) { "1234321" }
|
42 | 42 |
|
43 | 43 | it "produces the correct script tag" do
|
44 |
| - expect(output).to match(/<script src="https:\/\/gist.github.com\/#{gist}.js">\s<\/script>/) |
| 44 | + expect(output).to match(%r!<script src="https:\/\/gist.github.com\/#{gist}.js">\s<\/script>!) |
45 | 45 | end
|
46 | 46 | it "produces the correct noscript tag" do
|
47 |
| - expect(output).to match(/<noscript><pre><test>true<\/test><\/pre><\/noscript>\n/) |
| 47 | + expect(output).to match(%r!<noscript><pre><test>true<\/test><\/pre><\/noscript>\n!) |
48 | 48 | end
|
49 | 49 | end
|
50 | 50 |
|
51 | 51 | context "with file specified" do
|
52 |
| - before { stub_request(:get, "https://gist.githubusercontent.com/#{gist}/raw/#{filename}").to_return(body: http_output) } |
| 52 | + before { stub_request(:get, "https://gist.githubusercontent.com/#{gist}/raw/#{filename}").to_return(:body => http_output) } |
53 | 53 | let(:gist) { "mattr-/24081a1d93d2898ecf0f" }
|
54 | 54 | let(:filename) { "myfile.ext" }
|
55 | 55 | let(:content) { "{% gist #{gist} #{filename} %}" }
|
56 | 56 |
|
57 | 57 | it "produces the correct script tag" do
|
58 |
| - expect(output).to match(/<script src="https:\/\/gist.github.com\/#{gist}.js\?file=#{filename}">\s<\/script>/) |
| 58 | + expect(output).to match(%r!<script src="https:\/\/gist.github.com\/#{gist}.js\?file=#{filename}">\s<\/script>!) |
59 | 59 | end
|
60 | 60 | it "produces the correct noscript tag" do
|
61 |
| - expect(output).to match(/<noscript><pre><test>true<\/test><\/pre><\/noscript>\n/) |
| 61 | + expect(output).to match(%r!<noscript><pre><test>true<\/test><\/pre><\/noscript>\n!) |
62 | 62 | end
|
63 | 63 | end
|
64 | 64 |
|
65 | 65 | context "with variable gist id" do
|
66 |
| - before { stub_request(:get, "https://gist.githubusercontent.com/#{gist_id}/raw").to_return(body: http_output) } |
| 66 | + before { stub_request(:get, "https://gist.githubusercontent.com/#{gist_id}/raw").to_return(:body => http_output) } |
67 | 67 | let(:gist_id) { "1342013" }
|
68 | 68 | let(:gist) { "page.gist_id" }
|
69 | 69 | let(:output) do
|
70 |
| - doc.data['gist_id'] = gist_id |
| 70 | + doc.data["gist_id"] = gist_id |
71 | 71 | doc.content = content
|
72 | 72 | doc.output = Jekyll::Renderer.new(doc.site, doc).run
|
73 | 73 | end
|
74 | 74 |
|
75 | 75 | it "produces the correct script tag" do
|
76 |
| - expect(output).to match(/<script src="https:\/\/gist.github.com\/#{doc.data['gist_id']}.js">\s<\/script>/) |
| 76 | + expect(output).to match(%r!<script src="https:\/\/gist.github.com\/#{doc.data['gist_id']}.js">\s<\/script>!) |
77 | 77 | end
|
78 | 78 | it "produces the correct noscript tag" do
|
79 |
| - expect(output).to match(/<noscript><pre><test>true<\/test><\/pre><\/noscript>\n/) |
| 79 | + expect(output).to match(%r!<noscript><pre><test>true<\/test><\/pre><\/noscript>\n!) |
80 | 80 | end
|
81 | 81 | end
|
82 | 82 |
|
83 | 83 | context "with variable gist id and filename" do
|
84 |
| - before { stub_request(:get, "https://gist.githubusercontent.com/#{gist_id}/raw/#{gist_filename}").to_return(body: http_output) } |
| 84 | + before { stub_request(:get, "https://gist.githubusercontent.com/#{gist_id}/raw/#{gist_filename}").to_return(:body => http_output) } |
85 | 85 | let(:gist_id) { "1342013" }
|
86 | 86 | let(:gist_filename) { "atom.xml" }
|
87 | 87 | let(:gist) { "page.gist_id" }
|
88 | 88 | let(:filename) { "page.gist_filename" }
|
89 | 89 | let(:content) { "{% gist #{gist} #{filename} %}" }
|
90 | 90 | let(:output) do
|
91 |
| - doc.data['gist_id'] = "1342013" |
92 |
| - doc.data['gist_filename'] = "atom.xml" |
| 91 | + doc.data["gist_id"] = "1342013" |
| 92 | + doc.data["gist_filename"] = "atom.xml" |
93 | 93 | doc.content = content
|
94 | 94 | doc.output = Jekyll::Renderer.new(doc.site, doc).run
|
95 | 95 | end
|
96 | 96 |
|
97 | 97 | it "produces the correct script tag" do
|
98 |
| - expect(output).to match(/<script src="https:\/\/gist.github.com\/#{doc.data['gist_id']}.js\?file=#{doc.data['gist_filename']}">\s<\/script>/) |
| 98 | + expect(output).to match(%r!<script src="https:\/\/gist.github.com\/#{doc.data['gist_id']}.js\?file=#{doc.data['gist_filename']}">\s<\/script>!) |
99 | 99 | end
|
100 | 100 |
|
101 | 101 | it "produces the correct noscript tag" do
|
102 |
| - expect(output).to match(/<noscript><pre><test>true<\/test><\/pre><\/noscript>\n/) |
| 102 | + expect(output).to match(%r!<noscript><pre><test>true<\/test><\/pre><\/noscript>\n!) |
103 | 103 | end
|
104 | 104 | end
|
105 | 105 |
|
106 | 106 | context "with valid gist id and invalid filename" do
|
107 |
| - before { stub_request(:get, "https://gist.githubusercontent.com/#{gist_id}/raw/#{gist_filename}").to_return(status: 404) } |
108 |
| - let(:gist_id) { "mattr-/24081a1d93d2898ecf0f" } |
| 107 | + before { stub_request(:get, "https://gist.githubusercontent.com/#{gist_id}/raw/#{gist_filename}").to_return(:status => 404) } |
| 108 | + let(:gist_id) { "mattr-/24081a1d93d2898ecf0f" } |
109 | 109 | let(:gist_filename) { "myfile.ext" }
|
110 |
| - let(:content) { "{% gist #{gist_id} #{gist_filename} %}" } |
| 110 | + let(:content) { "{% gist #{gist_id} #{gist_filename} %}" } |
111 | 111 |
|
112 | 112 | it "produces the correct script tag" do
|
113 |
| - expect(output).to match(/<script src="https:\/\/gist.github.com\/#{gist_id}.js\?file=#{gist_filename}">\s<\/script>/) |
| 113 | + expect(output).to match(%r!<script src="https:\/\/gist.github.com\/#{gist_id}.js\?file=#{gist_filename}">\s<\/script>!) |
114 | 114 | end
|
115 | 115 |
|
116 | 116 | it "does not produce the noscript tag" do
|
117 |
| - expect(output).to_not match(/<noscript><pre><test>true<\/test><\/pre><\/noscript>\n/) |
| 117 | + expect(output).to_not match(%r!<noscript><pre><test>true<\/test><\/pre><\/noscript>\n!) |
118 | 118 | end
|
119 |
| - |
120 | 119 | end
|
121 | 120 |
|
122 | 121 | context "with token" do
|
123 | 122 | before { ENV["JEKYLL_GITHUB_TOKEN"] = "1234" }
|
124 |
| - before { |
125 |
| - stub_request(:get, "https://api.github.com/gists/1342013"). |
126 |
| - to_return(:status => 200, :body => fixture("single-file"), :headers => {"Content-Type" => "application/json"}) |
127 |
| - } |
| 123 | + before do |
| 124 | + stub_request(:get, "https://api.github.com/gists/1342013") |
| 125 | + .to_return(:status => 200, :body => fixture("single-file"), :headers => { "Content-Type" => "application/json" }) |
| 126 | + end |
128 | 127 | let(:gist_id) { "1342013" }
|
129 | 128 | let(:gist) { "page.gist_id" }
|
130 | 129 | let(:output) do
|
131 |
| - doc.data['gist_id'] = gist_id |
| 130 | + doc.data["gist_id"] = gist_id |
132 | 131 | doc.content = content
|
133 | 132 | doc.output = Jekyll::Renderer.new(doc.site, doc).run
|
134 | 133 | end
|
135 | 134 |
|
136 | 135 | it "produces the noscript tag" do
|
137 |
| - expect(output).to match(/<noscript><pre>contents of gist<\/pre><\/noscript>/) |
| 136 | + expect(output).to match(%r!<noscript><pre>contents of gist<\/pre><\/noscript>!) |
138 | 137 | end
|
139 | 138 |
|
140 | 139 | context "with a filename" do
|
141 |
| - before { |
142 |
| - stub_request(:get, "https://api.github.com/gists/1342013"). |
143 |
| - to_return(:status => 200, :body => fixture("multiple-files"), :headers => {"Content-Type" => "application/json"}) |
144 |
| - } |
145 |
| - let(:content) { "{% gist 1342013 hello-world.rb %}" } |
| 140 | + before do |
| 141 | + stub_request(:get, "https://api.github.com/gists/1342013") |
| 142 | + .to_return(:status => 200, :body => fixture("multiple-files"), :headers => { "Content-Type" => "application/json" }) |
| 143 | + end |
| 144 | + let(:content) { "{% gist 1342013 hello-world.rb %}" } |
146 | 145 |
|
147 | 146 | it "produces the noscript tag" do
|
148 |
| - expect(output).to match(/<noscript><pre>puts 'hello world'<\/pre><\/noscript>/) |
| 147 | + expect(output).to match(%r!<noscript><pre>puts 'hello world'<\/pre><\/noscript>!) |
149 | 148 | end
|
150 | 149 | end
|
151 | 150 | end
|
|
159 | 158 | let(:gist) { "mattr-/24081a1d93d2898ecf0f" }
|
160 | 159 |
|
161 | 160 | it "does not produce the noscript tag" do
|
162 |
| - expect(output).to_not match(/<noscript>/) |
| 161 | + expect(output).to_not match(%r!<noscript>!) |
163 | 162 | end
|
164 | 163 | end
|
165 |
| - |
166 | 164 | end
|
167 | 165 |
|
168 | 166 | context "invalid gist" do
|
169 |
| - |
170 | 167 | context "no gist id present" do
|
171 | 168 | let(:gist) { "" }
|
172 | 169 |
|
173 | 170 | it "raises an error" do
|
174 |
| - expect(->{ output }).to raise_error |
| 171 | + expect(-> { output }).to raise_error |
175 | 172 | end
|
176 | 173 | end
|
177 |
| - |
178 | 174 | end
|
179 |
| - |
180 | 175 | end
|
0 commit comments