|
1 | 1 | require 'spec_helper'
|
2 | 2 |
|
3 | 3 | describe(Jekyll::Gist::GistTag) do
|
| 4 | + let(:http_output) { "<test>true</test>" } |
4 | 5 | let(:doc) { doc_with_content(content) }
|
5 | 6 | let(:content) { "{% gist #{gist} %}" }
|
6 | 7 | let(:output) do
|
|
11 | 12 |
|
12 | 13 | context "valid gist" do
|
13 | 14 | context "with user prefix" do
|
| 15 | + before { stub_request(:get, "https://gist.githubusercontent.com/#{gist}/raw").to_return(body: http_output) } |
14 | 16 | let(:gist) { "mattr-/24081a1d93d2898ecf0f" }
|
15 | 17 |
|
16 | 18 | it "produces the correct script tag" do
|
17 | 19 | expect(output).to match(/<script src="https:\/\/gist.github.com\/#{gist}.js">\s<\/script>/)
|
18 | 20 | end
|
| 21 | + it "produces the correct noscript tag" do |
| 22 | + expect(output).to match(/<noscript><pre><test>true<\/test><\/pre><\/noscript>\n/) |
| 23 | + end |
19 | 24 | end
|
20 | 25 |
|
21 | 26 | context "without user prefix" do
|
| 27 | + before { stub_request(:get, "https://gist.githubusercontent.com/#{gist}/raw").to_return(body: http_output) } |
22 | 28 | let(:gist) { "28949e1d5ee2273f9fd3" }
|
23 | 29 |
|
24 | 30 | it "produces the correct script tag" do
|
25 | 31 | expect(output).to match(/<script src="https:\/\/gist.github.com\/#{gist}.js">\s<\/script>/)
|
26 | 32 | end
|
| 33 | + it "produces the correct noscript tag" do |
| 34 | + expect(output).to match(/<noscript><pre><test>true<\/test><\/pre><\/noscript>\n/) |
| 35 | + end |
27 | 36 | end
|
28 | 37 |
|
29 | 38 | context "classic Gist id style" do
|
| 39 | + before { stub_request(:get, "https://gist.githubusercontent.com/#{gist}/raw").to_return(body: http_output) } |
30 | 40 | let(:gist) { "1234321" }
|
31 | 41 |
|
32 | 42 | it "produces the correct script tag" do
|
33 | 43 | expect(output).to match(/<script src="https:\/\/gist.github.com\/#{gist}.js">\s<\/script>/)
|
34 | 44 | end
|
| 45 | + it "produces the correct noscript tag" do |
| 46 | + expect(output).to match(/<noscript><pre><test>true<\/test><\/pre><\/noscript>\n/) |
| 47 | + end |
35 | 48 | end
|
36 | 49 |
|
37 | 50 | context "with file specified" do
|
| 51 | + before { stub_request(:get, "https://gist.githubusercontent.com/#{gist}/raw/#{filename}").to_return(body: http_output) } |
38 | 52 | let(:gist) { "mattr-/24081a1d93d2898ecf0f" }
|
39 | 53 | let(:filename) { "myfile.ext" }
|
40 | 54 | let(:content) { "{% gist #{gist} #{filename} %}" }
|
41 | 55 |
|
42 | 56 | it "produces the correct script tag" do
|
43 | 57 | expect(output).to match(/<script src="https:\/\/gist.github.com\/#{gist}.js\?file=#{filename}">\s<\/script>/)
|
44 | 58 | end
|
| 59 | + it "produces the correct noscript tag" do |
| 60 | + expect(output).to match(/<noscript><pre><test>true<\/test><\/pre><\/noscript>\n/) |
| 61 | + end |
45 | 62 | end
|
46 | 63 |
|
47 | 64 | context "with variable gist id" do
|
| 65 | + before { stub_request(:get, "https://gist.githubusercontent.com/#{gist_id}/raw").to_return(body: http_output) } |
| 66 | + let(:gist_id) { "1342013" } |
48 | 67 | let(:gist) { "page.gist_id" }
|
49 | 68 | let(:output) do
|
50 |
| - doc.data['gist_id'] = "1342013" |
| 69 | + doc.data['gist_id'] = gist_id |
51 | 70 | doc.content = content
|
52 | 71 | doc.output = Jekyll::Renderer.new(doc.site, doc).run
|
53 | 72 | end
|
54 | 73 |
|
55 | 74 | it "produces the correct script tag" do
|
56 | 75 | expect(output).to match(/<script src="https:\/\/gist.github.com\/#{doc.data['gist_id']}.js">\s<\/script>/)
|
57 | 76 | end
|
| 77 | + it "produces the correct noscript tag" do |
| 78 | + expect(output).to match(/<noscript><pre><test>true<\/test><\/pre><\/noscript>\n/) |
| 79 | + end |
58 | 80 | end
|
59 | 81 |
|
60 | 82 | context "with variable gist id and filename" do
|
61 |
| - let(:gist) { "page.gist_id" } |
62 |
| - let(:filename) { "page.gist_filename" } |
63 |
| - let(:content) { "{% gist #{gist} #{filename} %}" } |
| 83 | + before { stub_request(:get, "https://gist.githubusercontent.com/#{gist_id}/raw/#{gist_filename}").to_return(body: http_output) } |
| 84 | + let(:gist_id) { "1342013" } |
| 85 | + let(:gist_filename) { "atom.xml" } |
| 86 | + let(:gist) { "page.gist_id" } |
| 87 | + let(:filename) { "page.gist_filename" } |
| 88 | + let(:content) { "{% gist #{gist} #{filename} %}" } |
64 | 89 | let(:output) do
|
65 | 90 | doc.data['gist_id'] = "1342013"
|
66 | 91 | doc.data['gist_filename'] = "atom.xml"
|
|
71 | 96 | it "produces the correct script tag" do
|
72 | 97 | expect(output).to match(/<script src="https:\/\/gist.github.com\/#{doc.data['gist_id']}.js\?file=#{doc.data['gist_filename']}">\s<\/script>/)
|
73 | 98 | end
|
| 99 | + |
| 100 | + it "produces the correct noscript tag" do |
| 101 | + expect(output).to match(/<noscript><pre><test>true<\/test><\/pre><\/noscript>\n/) |
| 102 | + end |
74 | 103 | end
|
| 104 | + |
| 105 | + context "with valid gist id and invalid filename" do |
| 106 | + before { stub_request(:get, "https://gist.githubusercontent.com/#{gist_id}/raw/#{gist_filename}").to_return(status: 404) } |
| 107 | + let(:gist_id) { "mattr-/24081a1d93d2898ecf0f" } |
| 108 | + let(:gist_filename) { "myfile.ext" } |
| 109 | + let(:content) { "{% gist #{gist_id} #{gist_filename} %}" } |
| 110 | + |
| 111 | + it "produces the correct script tag" do |
| 112 | + expect(output).to match(/<script src="https:\/\/gist.github.com\/#{gist_id}.js\?file=#{gist_filename}">\s<\/script>/) |
| 113 | + end |
| 114 | + |
| 115 | + it "does not produce the noscript tag" do |
| 116 | + expect(output).to_not match(/<noscript><pre><test>true<\/test><\/pre><\/noscript>\n/) |
| 117 | + end |
| 118 | + |
| 119 | + end |
| 120 | + |
75 | 121 | end
|
76 | 122 |
|
77 | 123 |
|
|
0 commit comments