lib/sham.rb in notahat-machinist-1.0.0 vs lib/sham.rb in notahat-machinist-1.0.3
- old
+ new
@@ -22,12 +22,12 @@
def self.clear
@@shams = {}
end
- def self.reset
- @@shams.values.each(&:reset)
+ def self.reset(scope = :before_all)
+ @@shams.values.each { |sham| sham.reset(scope) }
end
def self.define(&block)
Sham.instance_eval(&block)
end
@@ -38,11 +38,17 @@
@offset = 0
@unique = options.has_key?(:unique) ? options[:unique] : true
generate_values(12)
end
- def reset
- @offset = 0
+ def reset(scope)
+ if scope == :before_all
+ @offset, @before_offset = 0, nil
+ elsif @before_offset
+ @offset = @before_offset
+ else
+ @before_offset = @offset
+ end
end
def fetch_value
# Generate more values if we need them.
if @offset >= @values.length