Skip to content

Commit

Permalink
ensure options are correct. no misspellings!
Browse files Browse the repository at this point in the history
  • Loading branch information
bronson committed Mar 26, 2011
1 parent 3afdfa5 commit b5e4254
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/retryable.rb
@@ -1,5 +1,12 @@
module Retryable
class NestingError < Exception; end
class InvalidOptions < RuntimeError; end

def retryable_merge dst, src
typos = src.keys - dst.keys
raise InvalidOptions.new("Invalid options: #{typos.join(", ")}") unless typos.empty?
dst.merge! src
end

def retryable_options options=nil
@retryable_options = options = nil if options == :reset # for testing
Expand All @@ -11,12 +18,13 @@ def retryable_options options=nil
:detect_nesting => false,
}

@retryable_options.merge!(options) if options
retryable_merge @retryable_options, options if options
@retryable_options
end

def retryable options = {}, &block
opts = retryable_options.merge options
opts = retryable_options
retryable_merge opts, options
return nil if opts[:tries] < 1

raise NestingError.new("Nested retryable: #{@retryable_nest}") if @retryable_nest
Expand Down
13 changes: 13 additions & 0 deletions spec/retryable_spec.rb
Expand Up @@ -178,4 +178,17 @@ def count_retryable *opts
}
}
end

it "doesn't allow invalid options" do
should_raise(InvalidOptions) {
retryable(:bad_option => 2) { raise "this is bad" }
}
end

it "doesn't allow invalid global options" do
should_raise(InvalidOptions) {
retryable_options :bad_option => 'bogus'
raise "not reached"
}
end
end

0 comments on commit b5e4254

Please sign in to comment.