Module: Imagery::Faking::ClassMethods

Defined in:
lib/imagery/faking.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#modeObject

Allows you to define the current mode. The only special value here is :fake. If the mode is :fake, then Imagery::Model#save and Imagery::Model#delete will not actually run.

Examples:


Photo = Class.new(Struct.new(:id))

i = Imagery.new(Photo.new(1001))
i.root = '/tmp'

Imagery::Model.faked {
  assert i.save(File.open('/path/to/image.png'))
}

See Also:



25
26
27
# File 'lib/imagery/faking.rb', line 25

def mode
  @mode
end

Instance Method Details

#fakedObject

Switches the current mode to :fake.

Examples:

Imagery::Model.mode == nil
# => true

Imagery::Model.faked {
  Imagery::Model.mode == :fake
  # => true
}

Imagery::Model.mode = nil
# => true


41
42
43
44
45
46
# File 'lib/imagery/faking.rb', line 41

def faked
  @omode, @mode = @mode, :fake
  yield
ensure
  @mode = @omode
end

#realObject

Switches the current mode to nil. Useful for forcing real saves in your test.

You should do this at least once in your project just to know that all your Imagery::Model#save and Imagery::Model#delete operations actually work.

Examples:

Imagery::Model.mode = :fake

Imagery::Model.faked {
  Imagery::Model.mode == nil
  # => true
}

Imagery::Model.mode = :fake
# => true


66
67
68
69
70
71
# File 'lib/imagery/faking.rb', line 66

def real
  @omode, @mode = @mode, nil
  yield
ensure
  @mode = @omode
end