Created
June 28, 2016 10:48
-
-
Save rhargreaves/400265fdfd35a973e143e26684d046b8 to your computer and use it in GitHub Desktop.
SPA 2016: Acceptance Test: Has Up To Date Counter
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
# 1) Place following in 'context' block | |
# START --- | |
it 'has up-to-date counter' do | |
api_counter_value = get_counter_value_from_api | |
page_counter_value = get_counter_value_from_page | |
puts "API counter is #{api_counter_value}, Page is #{page_counter_value}" | |
expect(page_counter_value).to be >= api_counter_value | |
end | |
# END --- | |
# 2) Place below in 'describe' block | |
# START --- | |
def get_counter_value_from_api | |
api_url = 'http://robh-spa-2016-demo-site.eu-west-1.elasticbeanstalk.com/' | |
uri = URI(api_url + 'counter') | |
response = Net::HTTP.get(uri) | |
data = JSON.parse(response) | |
val = data["value"] | |
val | |
end | |
def get_counter_value_from_page | |
visit @site_url | |
page_counter_value = find('#counter').text | |
page_counter_value = page_counter_value.scan(/\d+/).join().to_i | |
page_counter_value | |
end | |
# END --- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment