Module: ApiMaker::SpecHelper::WaitForFlashMessage

Included in:
ApiMaker::SpecHelper
Defined in:
lib/api_maker/spec_helper/wait_for_flash_message.rb

Instance Method Summary collapse

Instance Method Details

#wait_for_flash_message(expected_message, delay_sec: 0.2, timeout_sec: 6) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/api_maker/spec_helper/wait_for_flash_message.rb', line 2

def wait_for_flash_message(expected_message, delay_sec: 0.2, timeout_sec: 6)
  received_messages = []

  WaitUtil.wait_for_condition("wait for flash message", timeout_sec: timeout_sec, delay_sec: delay_sec) do
    expect_no_browser_errors
    current_message = flash_message_text
    received_messages << current_message

    if current_message.is_a?(Array)
      current_message.include?(expected_message)
    else
      current_message == expected_message
    end
  end

  expect_no_browser_errors
rescue WaitUtil::TimeoutError
  expect(received_messages.uniq.reject(&:blank?)).to eq include expected_message
end