Created
February 1, 2012 02:26
-
-
Save jxson/1714672 to your computer and use it in GitHub Desktop.
Using cucumber, capybara, and net/http to check dynamically injected content
This file contains hidden or 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
| Then /^I should see the API documentation$/ do | |
| uri = URI.parse('http://api.spire.io') | |
| request = Net::HTTP::Get.new(uri.request_uri) | |
| request['Accept'] = 'text/html' | |
| response = Net::HTTP.start(uri.host, uri.port) {|http| | |
| http.request(request) | |
| } | |
| page.should have_css('.api-reference') | |
| # ugh. | |
| script = 'document.getElementsByClassName("api-reference")[0].innerHTML' | |
| actual = page.evaluate_script(script) | |
| script = <<-SCRIPT | |
| var div = document.createElement('div') | |
| div.innerHTML = #{ response.body.inspect }; | |
| return div.innerHTML; | |
| SCRIPT | |
| expected = page.execute_script(script) | |
| actual.should_not be_nil | |
| actual.should == expected | |
| end |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
actualis the content that was injected by the application's javascriptThe reason for the crazy
expected = page.execute_script(script)on line 24 for ensuring that any transformations on theactualinjected content caused by sticking it into the DOM are applied the same to theexpectedhtml content. Without this step problems with whitespace and escaped html will cause some serious head scratching...