Class: Booth::Testing::Support::AssertLoggedIn

Inherits:
Object
  • Object
show all
Includes:
Logging, Calls, Capybara::DSL
Defined in:
lib/booth/testing/support/assert_logged_in.rb

Defined Under Namespace

Classes: AssertionFailedError

Instance Method Summary collapse

Instance Method Details

#callObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/booth/testing/support/assert_logged_in.rb', line 16

def call
  browser_session_id = nil

  begin
    ::Timeout.timeout(Capybara.default_max_wait_time) do
      loop do
        log { "Polling to see if #{credential.username} logged in in scope #{scope}..." }
        browser_session_id = ::Booth::Testing::Support::CookieDataFromBrowser.call[key]
        active_sessions.each do |session|
          return true if session.id.to_s == browser_session_id
        end
        sleep 0.1
      end
    end
  rescue ::Timeout::Error
    # Timed out
  end

  raise AssertionFailedError, "Expected to be logged in as #{credential.username} " \
                              "(Credential #{credential.id}) " \
                              "with some Session ID #{active_sessions.map(&:id)} " \
                              "but the Browser Cookie has #{browser_session_id} "
end