Skip to content

Instantly share code, notes, and snippets.

@bronson
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bronson/aa505e247d93f095c20b to your computer and use it in GitHub Desktop.
Save bronson/aa505e247d93f095c20b to your computer and use it in GitHub Desktop.
trying to rspec a live site
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