lib/watirsplash/rspec_patches.rb in watirsplash-2.0.0.rc2 vs lib/watirsplash/rspec_patches.rb in watirsplash-2.0.0

- old
+ new

@@ -27,14 +27,10 @@ end end RSpec.configure do |config| #:nodoc: config.include(WatirSplash::SpecHelper) - - config.after(:all) do - WatirSplash::Util.formatter.browser.close if WatirSplash::Util.formatter.browser - end end module RSpec #:nodoc:all module Core class ExampleGroup @@ -72,18 +68,18 @@ # patch for #in(timeout) method module RSpec::Matchers class Change def matches?(event_proc) raise_block_syntax_error if block_given? - + # to make #change work with #in(timeout) method unless defined? @actual_before @actual_before = evaluate_value_proc event_proc.call end @actual_after = evaluate_value_proc - + (!change_expected? || changed?) && matches_before? && matches_after? && matches_expected_delta? && matches_min? && matches_max? end end alias_method :make, :change @@ -112,19 +108,19 @@ RSpec::Matchers.const_get(const).class_eval do inst_methods = instance_methods.map {|m| m.to_sym} if !(inst_methods.include?(:__matches?) || inst_methods.include?(:__does_not_match?)) && - (inst_methods.include?(:matches?) || inst_methods.include?(:does_not_match?)) + (inst_methods.include?(:matches?) || inst_methods.include?(:does_not_match?)) - def in(timeout) - Kernel.warn "DEPRECATION NOTICE: #in(timeout) is DEPRECATED, please use #within(timeout) method instead!" - within(timeout) + def within(timeout) + @within_timeout = timeout + self end - def within(timeout) - @timeout = timeout + def during(timeout) + @during_timeout = timeout self end def soon within(30) @@ -136,34 +132,52 @@ end alias_method :second, :seconds def minutes - return unless @timeout - @timeout *= 60 + @within_timeout *= 60 if @within_timeout + @during_timeout *= 60 if @during_timeout self end alias_method :minute, :minutes end if inst_methods.include? :matches? alias_method :__matches?, :matches? def matches?(actual) - @timeout ? (Watir::Wait.until(@timeout) {__matches?(actual)} rescue false) : __matches?(actual) + if @within_timeout + Watir::Wait.until(@within_timeout) {__matches?(actual)} rescue false + elsif @during_timeout + Watir::Wait.while(@during_timeout) {__matches?(actual)} rescue true + else + __matches?(actual) + end end end if inst_methods.include? :does_not_match? alias_method :__does_not_match?, :does_not_match? def does_not_match?(actual) - @timeout ? (Watir::Wait.until(@timeout) {__does_not_match?(actual)} rescue false) : __does_not_match?(actual) + if @within_timeout + Watir::Wait.until(@within_timeout) {__does_not_match?(actual)} rescue false + elsif @during_timeout + Watir::Wait.while(@during_timeout) {__does_not_match?(actual)} rescue true + else + __does_not_match?(actual) + end end elsif inst_methods.include? :matches? def does_not_match?(actual) - @timeout ? !(Watir::Wait.while(@timeout) {__matches?(actual)} rescue true) : !__matches?(actual) + if @within_timeout + Watir::Wait.until(@within_timeout) {!__matches?(actual)} rescue false + elsif @during_timeout + Watir::Wait.while(@during_timeout) {!__matches?(actual)} rescue true + else + !__matches?(actual) + end end end end end