You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: voting_spec.rb
    path of file: ./repos/osem/spec/features
    
    the code of the file until where you have to start completion: # frozen_string_literal: true

require 'spec_helper'

def have_rating(rating, max)
  have_selector('.rating.bright', count: rating)
    .and have_selector('.rating:not(.bright)', count: max - rating)
end

def cast_vote(rating, before:, after:)
  # Index shows existing rating but not user’s vote
  visit admin_conference_program_events_path(conference.short_title)
  within("#event-#{event.id}") do
    expect(page).to have_rating(before, 5)
    expect(page).to have_text('Not rated')
  end

  # Event page shows existing rating but not user’s vote
  click_on event.title
  within('tr', text: 'Rating') { expect(page).to have_rating(before, 5
    
def cast_vote(rating, before:, after:)
  # Index shows existing rating but not user’s vote
  visit admin_conference_program_events_path(conference.short_title)
  within("#event-#{event.id}") do
    expect(page).to have_rating(before, 5)
    expect(page).to have_text('Not rated')
  end

  # Event page shows existing rating but not user’s vote
  click_on event.title
  within('tr', text: 'Rating') { expect(page).to have_rating(before, 5) }
  within('tr', text: 'Your vote') { expect(page).to have_rating(0, 5) }

  # Voting dynamically updates the page
  within('tr', text: 'Your vote') { page.find(".rating:nth-of-type(#{rating})").click }
  within('tr', text: 'Rating') { expect(page).to have_rating(after, 5) }
  within('tr', text: 'Your vote') { expect(page).to have_rating(rating, 5) }

  # Index shows updated rating and vote
  visit admin_conference_program_events_path(conference.short_title)
  within("#event-#{event.id}") do
    expect(page).to have_rating(after, 5)
    expect(page).to have_text("You voted: #{rating}/5")
  end

  # Re-rendered event page shows updated rating and vote
  click_on event.title
  within('tr', text: 'Rating') { expect(page).to have_rating(after, 5) }
  within('tr', text: 'Your vote') { expect(page).to have_rating(rating, 5) }
end