public
Created

  • Download Gist
helpers.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
module Helpers
def sign_in(user)
@user_session = UserSession.create user
end
def fill_in_autocomplete(selector, value)
page.execute_script %Q{$('#{selector}').val('#{value}').keydown()}
end
 
def choose_autocomplete(text)
find('ul.ui-autocomplete').should have_content(text)
page.execute_script("$('.ui-menu-item:contains(\"#{text}\")').find('a').trigger('mouseenter').click()")
end
def wait_for_animation
wait_until do
page.evaluate_script('$(":animated").length') == 0
end
end
end
register_spec.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
# Here's how to use the autocomplete, and how to avoid triggering the autocomplete.
 
context "User chooses new company" do
before(:each) do
visit new_user_path
fill_in_autocomplete "#user_dealership_attributes_company_attributes_name", "New company"
choose_autocomplete "New Company"
wait_for_animation
end
it "should expose new company and dealership fields" do
page.find(".company_info_fields").should be_visible
page.find("#new_dealership_fields").should be_visible
end
end
context "User does not use autocomplete" do
it "should expose new company and dealership fields" do
visit new_user_path
page.execute_script %Q{$("#user_dealership_attributes_company_attributes_name").val("New company").change()}
wait_for_animation
page.find(".company_info_fields").should be_visible
page.find("#new_dealership_fields").should be_visible
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.