Skip to content

Commit 0655f7b

Browse files
committed
Renew the test suite
- Bye bye faraday - $TARGET_HOST to test against an alternate host i.e. staging
1 parent e64b735 commit 0655f7b

File tree

3 files changed

+65
-56
lines changed

3 files changed

+65
-56
lines changed

Gemfile

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
source "https://rubygems.org"
22

33
gem "rspec"
4-
gem "faraday"
54
gem "rake"
65

spec/rubykaigi_org_spec.rb

+52-52
Original file line numberDiff line numberDiff line change
@@ -4,161 +4,161 @@
44
let(:latest_year) { "2018" }
55

66
describe "/" do
7-
let(:res) { connection.get("http://rubykaigi.org/") }
7+
let(:res) { http_get("http://rubykaigi.org/") }
88
it "redirects to /?locale=en" do
9-
expect(res.status).to eq(302)
10-
expect(res.headers["location"]).to eq("http://rubykaigi.org/#{latest_year}")
9+
expect(res.code).to eq("302")
10+
expect(res["location"]).to eq("http://rubykaigi.org/#{latest_year}")
1111
end
1212
end
1313

1414
describe "/?locale=en" do
15-
let(:res) { connection.get("http://rubykaigi.org/?locale=en") }
15+
let(:res) { http_get("http://rubykaigi.org/?locale=en") }
1616
it "redirects to the latest" do
17-
expect(res.status).to eq(302)
18-
expect(res.headers["location"]).to eq("http://rubykaigi.org/#{latest_year}")
17+
expect(res.code).to eq("302")
18+
expect(res["location"]).to eq("http://rubykaigi.org/#{latest_year}")
1919
end
2020
end
2121

2222
describe "/?locale=ja" do
23-
let(:res) { connection.get("http://rubykaigi.org/?locale=ja") }
23+
let(:res) { http_get("http://rubykaigi.org/?locale=ja") }
2424
it "redirects to the latest" do
25-
expect(res.status).to eq(302)
26-
expect(res.headers["location"]).to eq("http://rubykaigi.org/#{latest_year}")
25+
expect(res.code).to eq("302")
26+
expect(res["location"]).to eq("http://rubykaigi.org/#{latest_year}")
2727
end
2828
end
2929

3030
(2014..2017).each do |year|
3131
describe "/#{year}" do
32-
let(:res) { connection.get("http://rubykaigi.org/#{year}") }
32+
let(:res) { http_get("http://rubykaigi.org/#{year}") }
3333
it "should be available" do
34-
expect(res.status).to eq(200)
34+
expect(res.code).to eq("200")
3535
end
3636
end
3737
end
3838

3939
describe "/2013" do
40-
let(:res) { connection.get("http://rubykaigi.org/2013") }
40+
let(:res) { http_get("http://rubykaigi.org/2013") }
4141
it "should render the top page" do
42-
expect(res.status).to eq(200)
42+
expect(res.code).to eq("200")
4343
expect(res.body).to include("<title>RubyKaigi 2013, May 30 - Jun 1</title>")
4444
end
4545
end
4646

4747
describe "/2012" do
48-
let(:res) { connection.get("http://rubykaigi.org/2012/") }
48+
let(:res) { http_get("http://rubykaigi.org/2012/") }
4949
it "should render the special 200 (not 404) page" do
50-
expect(res.status).to eq(200)
50+
expect(res.code).to eq("200")
5151
expect(res.body).to include("<title>RubyKaigi 2012: 404 Kaigi Not Found</title>")
5252
end
5353
end
5454

5555
describe "/2011" do
56-
let(:res) { connection.get("http://rubykaigi.org/2011") }
56+
let(:res) { http_get("http://rubykaigi.org/2011") }
5757
it "redirects to /2011/" do
58-
expect(res.status).to eq(301)
59-
expect(res.headers["location"]).to eq("http://rubykaigi.org/2011/")
58+
expect(res.code).to eq("301")
59+
expect(res["location"]).to eq("http://rubykaigi.org/2011/")
6060
end
6161
end
6262

6363
describe "/2011/" do
64-
let(:res) { connection.get("http://rubykaigi.org/2011/") }
64+
let(:res) { http_get("http://rubykaigi.org/2011/") }
6565
it "should render the top page" do
66-
expect(res.status).to eq(200)
66+
expect(res.code).to eq("200")
6767
expect(res.body).to include("<title>RubyKaigi 2011(July 16 - 18)</title>")
6868
end
6969
end
7070

7171
describe "/2010" do
72-
let(:res) { connection.get("http://rubykaigi.org/2010") }
72+
let(:res) { http_get("http://rubykaigi.org/2010") }
7373
it "redirects to /2010/" do
74-
expect(res.status).to eq(301)
75-
expect(res.headers["location"]).to eq("http://rubykaigi.org/2010/")
74+
expect(res.code).to eq("301")
75+
expect(res["location"]).to eq("http://rubykaigi.org/2010/")
7676
end
7777
end
7878

7979
describe "/2010/en/" do
80-
let(:res) { connection.get("http://rubykaigi.org/2010/en/") }
80+
let(:res) { http_get("http://rubykaigi.org/2010/en/") }
8181
it "should render the top page" do
82-
expect(res.status).to eq(200)
82+
expect(res.code).to eq("200")
8383
expect(res.body).to include("<title>RubyKaigi 2010, August 27-29</title>")
8484
end
8585
end
8686

8787
describe "/2009" do
88-
let(:res) { connection.get("http://rubykaigi.org/2009") }
88+
let(:res) { http_get("http://rubykaigi.org/2009") }
8989
it "redirects to /2009/" do
90-
expect(res.status).to eq(301)
91-
expect(res.headers["location"]).to eq("http://rubykaigi.org/2009/")
90+
expect(res.code).to eq("301")
91+
expect(res["location"]).to eq("http://rubykaigi.org/2009/")
9292
end
9393
end
9494

9595
describe "/2009/en/" do
96-
let(:res) { connection.get("http://rubykaigi.org/2009/en/") }
96+
let(:res) { http_get("http://rubykaigi.org/2009/en/") }
9797
it "should render the top page" do
98-
expect(res.status).to eq(200)
98+
expect(res.code).to eq("200")
9999
expect(res.body).to include("<title>RubyKaigi2009</title>")
100100
end
101101
end
102102

103103
describe "/2008" do
104-
let(:res) { connection.get("http://rubykaigi.org/2008") }
104+
let(:res) { http_get("http://rubykaigi.org/2008") }
105105
it "redirects to http://jp.rubyist.net/RubyKaigi2008" do
106-
expect(res.status).to eq(301)
107-
expect(res.headers["location"]).to eq("http://jp.rubyist.net/RubyKaigi2008")
106+
expect(res.code).to eq("301")
107+
expect(res["location"]).to eq("http://jp.rubyist.net/RubyKaigi2008")
108108
end
109109
end
110110

111111
describe "/2008/en" do
112-
let(:res) { connection.get("http://rubykaigi.org/2008/en") }
112+
let(:res) { http_get("http://rubykaigi.org/2008/en") }
113113
it "should redirect to http://jp.rubyist.net/RubyKaigi2008" do
114-
expect(res.status).to eq(301)
115-
expect(res.headers["location"]).to eq("http://jp.rubyist.net/RubyKaigi2008")
114+
expect(res.code).to eq("301")
115+
expect(res["location"]).to eq("http://jp.rubyist.net/RubyKaigi2008")
116116
end
117117
end
118118

119119
describe "/2007" do
120-
let(:res) { connection.get("http://rubykaigi.org/2007") }
120+
let(:res) { http_get("http://rubykaigi.org/2007") }
121121
it "redirects to http://jp.rubyist.net/RubyKaigi2007" do
122-
expect(res.status).to eq(301)
123-
expect(res.headers["location"]).to eq("http://jp.rubyist.net/RubyKaigi2007")
122+
expect(res.code).to eq("301")
123+
expect(res["location"]).to eq("http://jp.rubyist.net/RubyKaigi2007")
124124
end
125125
end
126126

127127
describe "/2007/en" do
128-
let(:res) { connection.get("http://rubykaigi.org/2007/en") }
128+
let(:res) { http_get("http://rubykaigi.org/2007/en") }
129129
it "should redirect to http://jp.rubyist.net/RubyKaigi2007" do
130-
expect(res.status).to eq(301)
131-
expect(res.headers["location"]).to eq("http://jp.rubyist.net/RubyKaigi2007")
130+
expect(res.code).to eq("301")
131+
expect(res["location"]).to eq("http://jp.rubyist.net/RubyKaigi2007")
132132
end
133133
end
134134

135135
describe "/2006" do
136-
let(:res) { connection.get("http://rubykaigi.org/2006") }
136+
let(:res) { http_get("http://rubykaigi.org/2006") }
137137
it "redirects to http://jp.rubyist.net/RubyKaigi2006" do
138-
expect(res.status).to eq(301)
139-
expect(res.headers["location"]).to eq("http://jp.rubyist.net/RubyKaigi2006")
138+
expect(res.code).to eq("301")
139+
expect(res["location"]).to eq("http://jp.rubyist.net/RubyKaigi2006")
140140
end
141141
end
142142

143143
describe "/2006/en" do
144-
let(:res) { connection.get("http://rubykaigi.org/2006/en") }
144+
let(:res) { http_get("http://rubykaigi.org/2006/en") }
145145
it "should redirect to http://jp.rubyist.net/RubyKaigi2006" do
146-
expect(res.status).to eq(301)
147-
expect(res.headers["location"]).to eq("http://jp.rubyist.net/RubyKaigi2006")
146+
expect(res.code).to eq("301")
147+
expect(res["location"]).to eq("http://jp.rubyist.net/RubyKaigi2006")
148148
end
149149
end
150150

151151
describe "/2005" do
152-
let(:res) { connection.get("http://rubykaigi.org/2005") }
152+
let(:res) { http_get("http://rubykaigi.org/2005") }
153153
it "should be 404" do
154-
expect(res.status).to eq(404)
154+
expect(res.code).to eq("404")
155155
end
156156
end
157157

158158
describe "/2005/en" do
159-
let(:res) { connection.get("http://rubykaigi.org/2005/en") }
159+
let(:res) { http_get("http://rubykaigi.org/2005/en") }
160160
it "should be 404" do
161-
expect(res.status).to eq(404)
161+
expect(res.code).to eq("404")
162162
end
163163
end
164164

spec/support/http_client.rb

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1-
require "faraday"
1+
require 'net/http'
2+
require 'net/https'
3+
require 'uri'
24

35
module Helpers
4-
def connection
5-
Faraday::Connection.new
6+
def http_get(url)
7+
uri = URI.parse(url)
8+
target = URI.parse(ENV.fetch('TARGET_HOST', url))
9+
10+
http = Net::HTTP.new(target.host, target.port)
11+
http.use_ssl = true if target.scheme == 'https'
12+
13+
http.start do
14+
http.get(uri.path, {'x-rko-host' => uri.host, 'Host' => target.host})
15+
end
616
end
717
end

0 commit comments

Comments
 (0)