Module: Gamera::Visitable
Instance Method Summary collapse
-
#displayed?(wait_time_seconds = Capybara.default_wait_time) ⇒ Boolean
Check to see if we eventually land on the right page.
-
#url ⇒ Object
A reminder to implement a url method when using this module.
-
#visit(fail_on_redirect = true) ⇒ Object
Open the page url in the browser specified in your Capybara configuration.
-
#with_refreshes(retries, allowed_errors = [RSpec::Expectations::ExpectationNotMetError], &block) ⇒ Object
A method to wait for slow loading data on a page.
Instance Method Details
#displayed?(wait_time_seconds = Capybara.default_wait_time) ⇒ Boolean
Check to see if we eventually land on the right page
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/gamera/modules/visitable.rb', line 23 def displayed?(wait_time_seconds = Capybara.default_wait_time) fail Gamera::NoUrlMatcherForPage if url_matcher.nil? start_time = Time.now loop do return true if page.current_url.chomp('/') =~ url_matcher break unless Time.now - start_time <= wait_time_seconds sleep(0.05) end false end |
#url ⇒ Object
A reminder to implement a url method when using this module.
52 53 54 |
# File 'lib/gamera/modules/visitable.rb', line 52 def url fail NotImplementedError, 'To use the Visitable module, you must implement a url method' end |
#visit(fail_on_redirect = true) ⇒ Object
Open the page url in the browser specified in your Capybara configuration
11 12 13 14 15 16 |
# File 'lib/gamera/modules/visitable.rb', line 11 def visit(fail_on_redirect = true) super(url) if fail_on_redirect fail Gamera::WrongPageVisited, "Expected URL '#{url}', got '#{page.current_url}'" unless displayed? end end |
#with_refreshes(retries, allowed_errors = [RSpec::Expectations::ExpectationNotMetError], &block) ⇒ Object
A method to wait for slow loading data on a page. Useful, for example, when waiting on a page that shows the count of records loaded via a slow web or import.
41 42 43 44 45 46 47 48 49 |
# File 'lib/gamera/modules/visitable.rb', line 41 def with_refreshes(retries, allowed_errors = [RSpec::Expectations::ExpectationNotMetError], &block) retries_left ||= retries visit block.call(retries_left) rescue *allowed_errors => e retries_left -= 1 retry if retries_left >= 0 raise e end |