Navigation Menu

Skip to content

Commit

Permalink
Add "subscribe-until" directive
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Apr 14, 2015
1 parent f72b477 commit 199c1c0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/drntest/directive.rb
Expand Up @@ -67,4 +67,25 @@ class EnableValidationDirective < Directive

class DisableValidationDirective < Directive
end

class SubscribeUntil < Directive
attr_reader :timeout_seconds

DEFAULT_TIMEOUT_SECONDS = 1

ONE_MINUTE_IN_SECONDS = 60
ONE_HOUR_IN_SECONDS = ONE_MINUTE_IN_SECONDS * 60

def initialize(timeout)
if timeout =~ /\A(\d+\.?|\.\d+|\d+\.\d+)s(?:ec(?:onds?)?)?\z/
@timeout_seconds = $1.to_f
elsif timeout =~ /\A(\d+\.?|\.\d+|\d+\.\d+)m(?:inutes?)?\z/
@timeout_seconds = $1.to_f * ONE_MINUTE_IN_SECONDS
elsif timeout =~ /\A(\d+\.?|\.\d+|\d+\.\d+)h(?:ours?)?\z/
@timeout_seconds = $1.to_f * ONE_HOUR_IN_SECONDS
else
@timeout_seconds = DEFAULT_TIMEOUT_SECONDS
end
end
end
end
2 changes: 2 additions & 0 deletions lib/drntest/test-loader.rb
Expand Up @@ -99,6 +99,8 @@ def parse_directive(type, options)
EnableValidationDirective.new
when :disable_validation
DisableValidationDirective.new
when :subscribe_until
SubscribeUntil.new(options.first)
else
UnknownDirective.new(type, options)
end
Expand Down

0 comments on commit 199c1c0

Please sign in to comment.