From 09924678e8a233b2102ec73bf8dcad33e31947d1 Mon Sep 17 00:00:00 2001 From: Thomas Walpole Date: Fri, 27 Apr 2018 09:39:34 -0700 Subject: [PATCH] Fix issue with not defaulting locator --- lib/capybara/node/actions.rb | 2 +- lib/capybara/spec/session/check_spec.rb | 6 ++++++ lib/capybara/spec/session/choose_spec.rb | 6 ++++++ lib/capybara/spec/session/uncheck_spec.rb | 7 +++++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/capybara/node/actions.rb b/lib/capybara/node/actions.rb index 0b86cef2..51c19924 100644 --- a/lib/capybara/node/actions.rb +++ b/lib/capybara/node/actions.rb @@ -129,7 +129,7 @@ module Capybara # @macro waiting_behavior # # @return [Capybara::Node::Element] The element checked or the label clicked - def check(locator, **options) + def check(locator = nil, **options) _check_with_label(:checkbox, true, locator, **options) end diff --git a/lib/capybara/spec/session/check_spec.rb b/lib/capybara/spec/session/check_spec.rb index 9f0dd7b6..172dd368 100644 --- a/lib/capybara/spec/session/check_spec.rb +++ b/lib/capybara/spec/session/check_spec.rb @@ -62,6 +62,12 @@ Capybara::SpecHelper.spec "#check" do expect(extract_results(@session)['pets']).to include('dog', 'cat', 'hamster') end + it "should work without a locator string" do + @session.check(id: "form_pets_cat") + @session.click_button('awesome') + expect(extract_results(@session)['pets']).to include('dog', 'cat', 'hamster') + end + it "casts to string" do @session.check(:form_pets_cat) @session.click_button('awesome') diff --git a/lib/capybara/spec/session/choose_spec.rb b/lib/capybara/spec/session/choose_spec.rb index 8900e733..597871e6 100644 --- a/lib/capybara/spec/session/choose_spec.rb +++ b/lib/capybara/spec/session/choose_spec.rb @@ -17,6 +17,12 @@ Capybara::SpecHelper.spec "#choose" do expect(extract_results(@session)['gender']).to eq('both') end + it "should work without a locator string" do + @session.choose(id: "gender_male") + @session.click_button('awesome') + expect(extract_results(@session)['gender']).to eq('male') + end + it "casts to string" do @session.choose("Both") @session.click_button(:awesome) diff --git a/lib/capybara/spec/session/uncheck_spec.rb b/lib/capybara/spec/session/uncheck_spec.rb index 3c1efaff..9814990b 100644 --- a/lib/capybara/spec/session/uncheck_spec.rb +++ b/lib/capybara/spec/session/uncheck_spec.rb @@ -19,6 +19,13 @@ Capybara::SpecHelper.spec "#uncheck" do expect(extract_results(@session)['pets']).not_to include('hamster') end + it "should work without a locator string" do + @session.uncheck(id: "form_pets_hamster") + @session.click_button('awesome') + expect(extract_results(@session)['pets']).to include('dog') + expect(extract_results(@session)['pets']).not_to include('hamster') + end + it "casts to string" do @session.uncheck(:form_pets_hamster) @session.click_button('awesome')