Skip to content

Instantly share code, notes, and snippets.

@mexelout
Created May 20, 2019 17:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mexelout/cc9b8a774b6173267d071ee1242f0ec8 to your computer and use it in GitHub Desktop.
Save mexelout/cc9b8a774b6173267d071ee1242f0ec8 to your computer and use it in GitHub Desktop.
wait_for関係
# デフォでコメントアウトされてるの外すだけ
Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each { |f| require f }
RSpec.configure do |config|
config.include WaitFor
end
# spec/features/top_spec.rb
require 'rails_helper'
feature 'top page' do
describe 'visit top page' do
context '100 users' do
background { create_list(:user, 100) }
given!(:user) { create(:user) }
scenario 'collapse test' do
visit root_path
# こんな感じで括る
wait_for_html { click_on 'トグルボタン' }
click_on user.name
expect(page.current_path).to eq "/users/#{user.id}"
end
end
end
end
# spec/support/wait_for.rb
module WaitFor
def wait_for_html(wait_time: Capybara.default_max_wait_time)
prev_html = page.html
yield if block_given?
Timeout.timeout(wait_time) { loop until prev_html != page.html }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment