class Watir::RSpec::Matchers::BaseMatcher

@private

Public Class Methods

new(predicate) click to toggle source
# File lib/watir/rspec/matchers/base_matcher.rb, line 8
def initialize(predicate)
  @predicate = predicate
end

Public Instance Methods

does_not_match?(target) click to toggle source
# File lib/watir/rspec/matchers/base_matcher.rb, line 24
def does_not_match?(target)
  @target = target

  if @within_seconds
    match_with_timeout(@within_seconds, true) { !target.send @predicate }
  elsif @during_seconds
    match_with_timeout(@during_seconds, false) { target.send @predicate }
  else
    !target.send(@predicate)
  end
end
during(seconds) click to toggle source
# File lib/watir/rspec/matchers/base_matcher.rb, line 49
def during(seconds)
  @during_seconds = seconds
  self
end
failure_message_for_should() click to toggle source
# File lib/watir/rspec/matchers/base_matcher.rb, line 36
def failure_message_for_should
  "expected #{@target.inspect} to #{be_prefix}#{@predicate.to_s[0..-2]}#{timeout_to_s}"
end
failure_message_for_should_not() click to toggle source
# File lib/watir/rspec/matchers/base_matcher.rb, line 40
def failure_message_for_should_not
  "expected #{@target.inspect} not to #{be_prefix}#{@predicate.to_s[0..-2]}#{timeout_to_s}"
end
matches?(target) click to toggle source
# File lib/watir/rspec/matchers/base_matcher.rb, line 12
def matches?(target)
  @target = target

  if @within_seconds
    match_with_timeout(@within_seconds, true) { target.send @predicate }
  elsif @during_seconds
    match_with_timeout(@during_seconds, false) { !target.send @predicate }
  else
    target.send(@predicate)
  end
end
within(seconds) click to toggle source
# File lib/watir/rspec/matchers/base_matcher.rb, line 44
def within(seconds)
  @within_seconds = seconds
  self
end

Private Instance Methods

be_prefix() click to toggle source
# File lib/watir/rspec/matchers/base_matcher.rb, line 60
def be_prefix
  @predicate.to_s[0..-2] == "exist" ? "" : "be "
end
match_with_timeout(seconds, expected_result) { |rescue false); expected_result| ... } click to toggle source
# File lib/watir/rspec/matchers/base_matcher.rb, line 56
def match_with_timeout(seconds, expected_result)
  Timeout.timeout(seconds) { sleep 0.1 until (yield rescue false); expected_result } rescue !expected_result
end
timeout_to_s() click to toggle source
# File lib/watir/rspec/matchers/base_matcher.rb, line 64
def timeout_to_s
  if @within_seconds 
    " within #{@within_seconds} second(s) "
  elsif @during_seconds
    " during #{@during_seconds} second(s) "
  else
    " "
  end
end