Skip to content

Commit

Permalink
Delegate #present? to Element. Closes #216
Browse files Browse the repository at this point in the history
  • Loading branch information
p0deje committed Sep 12, 2013
1 parent 1fc91c9 commit 231002d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/watir-webdriver/wait.rb
@@ -1,4 +1,6 @@
# encoding: utf-8
require 'forwardable'

module Watir
module Wait

Expand Down Expand Up @@ -80,6 +82,10 @@ def wait_while(*args, &blk)
#

class WhenPresentDecorator
extend Forwardable

def_delegator :@element, :present?

def initialize(element, timeout, message = nil)
@element = element
@timeout = timeout
Expand Down
10 changes: 10 additions & 0 deletions spec/wait_spec.rb
Expand Up @@ -83,6 +83,16 @@
decorator.should respond_to(:present?)
decorator.should respond_to(:click)
end

it "delegates present? to element" do
Object.class_eval do
def present?
false
end
end
element = browser.a(:id, "show_bar").when_present(1)
element.should be_present

This comment has been minimized.

Copy link
@jarmo

jarmo Sep 12, 2013

Member

Maybe here should be also some line like this to make it more clear:

Object.any_instance.should_not_receive(:present?)

Not sure if it works though, but you can try it by removing the delegate.

This comment has been minimized.

Copy link
@p0deje

p0deje Sep 13, 2013

Author Member

I've tried to do this first, but was getting exception:

RuntimeError:
       can't modify frozen String
     # ./lib/watir-webdriver/browser.rb:367:in `assert_exists'
     # ./lib/watir-webdriver/elements/element.rb:508:in `locate'
     # ./lib/watir-webdriver/elements/element.rb:487:in `assert_exists'
     # ./lib/watir-webdriver/elements/element.rb:43:in `exists?'
     # ./lib/watir-webdriver/elements/element.rb:398:in `present?'
     # ./spec/wait_spec.rb:95:in `block (4 levels) in <top (required)>'

So, since the spec is valid (i.e. failing when delegating is removed), I think that's ok.

end
end

describe "#wait_until_present" do
Expand Down

0 comments on commit 231002d

Please sign in to comment.