Skip to content

Commit

Permalink
CR: Fix up un-needed splatters and slightly improve cop issues
Browse files Browse the repository at this point in the history
  • Loading branch information
luke-hill committed Jul 21, 2018
1 parent 399e54e commit 8cbe75f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ BlockLength:
- './spec/*_spec.rb'
- 'site_prism.gemspec'

# Offense count: 7
# Offense count: 4
Metrics/LineLength:
Max: 90
Max: 89

Style/TrailingCommaInHashLiteral:
EnforcedStyleForMultiline: comma
Expand Down
2 changes: 1 addition & 1 deletion features/explicit_waiting.feature
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Feature: Waiting for Elements

Scenario: Wait for Invisibility of element - Negative Test
When I navigate to the home page
Then I get a timeout error when I wait for an element that never disappears
Then I get a timeout error when I wait for an element that never vanishes

Scenario: Wait for Invisibility of element - Non-Existent Element
When I navigate to the home page
Expand Down
14 changes: 7 additions & 7 deletions features/step_definitions/wait_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
end

When('I wait for the section element that takes a while to appear') do
@test_site.section_experiments.parent_section.wait_for_slow_section_element
@test_site.section_experiments.parent_section.wait_for_slow_element
end

When('I wait for the section element that takes a while to disappear') do
Expand All @@ -82,7 +82,7 @@

Then('the slow section appears') do
expect(@test_site.section_experiments.parent_section)
.to have_slow_section_element
.to have_slow_element
end

Then('the removing section disappears') do
Expand All @@ -93,9 +93,9 @@
Then("an exception is raised when I wait for a section that won't appear") do
section = @test_site.section_experiments.parent_section

expect { section.wait_for_slow_section_element(0.25) }
expect { section.wait_for_slow_element(0.25) }
.to raise_error(SitePrism::TimeOutWaitingForExistenceError)
.with_message('Timed out after 0.25s waiting for Parent#slow_section_element')
.with_message('Timed out after 0.25s waiting for Parent#slow_element')
end

Then("an exception is raised when I wait for a section that won't disappear") do
Expand All @@ -116,11 +116,11 @@
end

When('I wait a variable time for elements to appear') do
@test_site.home.wait_for_lots_of_links(2.1)
@test_site.home.wait_for_lots_of_links(1.6)
end

When('I wait a variable time for elements to disappear') do
@test_site.home.wait_for_no_removing_links(2.1)
@test_site.home.wait_for_no_removing_links(1.6)
end

Then('I get a timeout error when I wait for an element that never appears') do
Expand Down Expand Up @@ -154,7 +154,7 @@
@test_site.home.wait_until_retiring_element_invisible(5)
end

Then('I get a timeout error when I wait for an element that never disappears') do
Then('I get a timeout error when I wait for an element that never vanishes') do
expect { @test_site.home.wait_until_welcome_header_invisible(1) }
.to raise_error(SitePrism::TimeOutWaitingForElementInvisibility)
end
Expand Down
24 changes: 12 additions & 12 deletions lib/site_prism/element_container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ def self.included(klass)

private

def waiter_wait_time
def wait_time
Capybara.default_max_wait_time
end

def checker_wait_time
if SitePrism.use_implicit_waits
waiter_wait_time
wait_time
else
0
end
Expand Down Expand Up @@ -178,7 +178,7 @@ def create_existence_checker(element_name, *find_args)
create_helper_method(method_name, *find_args) do
define_method(method_name) do |*runtime_args|
visibility_args = { wait: checker_wait_time }
args = merge_args(find_args, runtime_args, **visibility_args)
args = merge_args(find_args, runtime_args, visibility_args)
element_exists?(*args)
end
end
Expand All @@ -189,7 +189,7 @@ def create_nonexistence_checker(element_name, *find_args)
create_helper_method(method_name, *find_args) do
define_method(method_name) do |*runtime_args|
visibility_args = { wait: checker_wait_time }
args = merge_args(find_args, runtime_args, **visibility_args)
args = merge_args(find_args, runtime_args, visibility_args)
element_does_not_exist?(*args)
end
end
Expand All @@ -198,9 +198,9 @@ def create_nonexistence_checker(element_name, *find_args)
def create_waiter(element_name, *find_args)
method_name = "wait_for_#{element_name}"
create_helper_method(method_name, *find_args) do
define_method(method_name) do |timeout = waiter_wait_time, *runtime_args|
define_method(method_name) do |timeout = wait_time, *runtime_args|
visibility_args = { wait: timeout }
args = merge_args(find_args, runtime_args, **visibility_args)
args = merge_args(find_args, runtime_args, visibility_args)
result = element_exists?(*args)
raise_wait_for_if_failed(self, element_name, timeout, !result)
result
Expand All @@ -211,9 +211,9 @@ def create_waiter(element_name, *find_args)
def create_nonexistence_waiter(element_name, *find_args)
method_name = "wait_for_no_#{element_name}"
create_helper_method(method_name, *find_args) do
define_method(method_name) do |timeout = waiter_wait_time, *runtime_args|
define_method(method_name) do |timeout = wait_time, *runtime_args|
visibility_args = { wait: timeout }
args = merge_args(find_args, runtime_args, **visibility_args)
args = merge_args(find_args, runtime_args, visibility_args)
result = element_does_not_exist?(*args)
raise_wait_for_no_if_failed(self, element_name, timeout, !result)
result
Expand All @@ -224,9 +224,9 @@ def create_nonexistence_waiter(element_name, *find_args)
def create_visibility_waiter(element_name, *find_args)
method_name = "wait_until_#{element_name}_visible"
create_helper_method(method_name, *find_args) do
define_method(method_name) do |timeout = waiter_wait_time, *runtime_args|
define_method(method_name) do |timeout = wait_time, *runtime_args|
visibility_args = { visible: true, wait: timeout }
args = merge_args(find_args, runtime_args, **visibility_args)
args = merge_args(find_args, runtime_args, visibility_args)
return true if element_exists?(*args)
raise SitePrism::TimeOutWaitingForElementVisibility
end
Expand All @@ -236,9 +236,9 @@ def create_visibility_waiter(element_name, *find_args)
def create_invisibility_waiter(element_name, *find_args)
method_name = "wait_until_#{element_name}_invisible"
create_helper_method(method_name, *find_args) do
define_method(method_name) do |timeout = waiter_wait_time, *runtime_args|
define_method(method_name) do |timeout = wait_time, *runtime_args|
visibility_args = { visible: true, wait: timeout }
args = merge_args(find_args, runtime_args, **visibility_args)
args = merge_args(find_args, runtime_args, visibility_args)
return true if element_does_not_exist?(*args)
raise SitePrism::TimeOutWaitingForElementInvisibility
end
Expand Down
2 changes: 1 addition & 1 deletion test_site/sections/parent.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class Parent < SitePrism::Section
element :slow_section_element, 'a.slow'
element :slow_element, 'a.slow'
section :child_section, Child, '.child-div'
end

0 comments on commit 8cbe75f

Please sign in to comment.