Last active
August 29, 2015 14:17
-
-
Save bronson/aa505e247d93f095c20b to your computer and use it in GitHub Desktop.
trying to rspec a live site
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/http' | |
require 'nokogiri' | |
describe "build site", build_site: true, network: true do | |
let(:host) { 'property-build.prologisweb.com' } | |
def get path | |
# it appears path must be absolute | |
Net::HTTP.get_response(host, path) | |
end | |
def document body | |
Nokogiri::HTML(body) | |
end | |
def ensure_styles_exist body | |
href = document(body).css('link[rel=stylesheet]').attr('href').value | |
expect(href).to start_with('/') | |
styles = get(href) | |
expect(styles.body).to match(".footer-bucket") # a random style in the stylesheet | |
end | |
# ensure the 404 page was generated correctly | |
it "has a 404 page" do | |
response = get '/does-not-exist' | |
expect(response.code).to eq '404' | |
# ensure it's our 404 and not some generic nginx 404 | |
expect(response.body).to match("Property Availability Search") | |
expect(response.body).to match("The page you were looking for doesn't exist.") | |
ensure_styles_exist(response.body) | |
end | |
# ensure the 500 page was generated correctly | |
it "has a 500 page" do | |
response = get('/http500') | |
expect(response.code).to eq '500' | |
# ensure that it's our 500 and not some generic nginx 500 | |
expect(response.body).to match("We're sorry, but something went wrong.") | |
ensure_styles_exist(response.body) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment