Sha256: 1b28441c3d118684cb7d3859d10297051ca85c39544ba2e0c6ee3a9a7c2abc2b

Contents?: true

Size: 1.2 KB

Versions: 5

Compression:

Stored size: 1.2 KB

Contents

require File.expand_path("helper", File.dirname(__FILE__))
require "stringio"

# Imagery::Test hooks
scope do
  setup do
    Object.send :include, Imagery::Test
  end

  test "auto-includes Imagery::Faking upon inclusion" do
    assert Imagery.ancestors.include?(Imagery::Faking)
  end

  test "auto-sets mode to :fake" do
    assert_equal :fake, Imagery.mode
  end
end


class Imagery
  include Faking
end

test "skips saving when faked" do
  Imagery.mode = :fake

  i = Imagery.new(:avatar, "1001")
  i.save(StringIO.new)

  assert ! File.exist?(Imagery.root("avatar", "1001"))
end

test "skips deleting when faked" do
  Imagery.mode = :fake
  
  FileUtils.mkdir_p(Imagery.root("avatar", "1001"))

  i = Imagery.new(:avatar, "1001")
  i.delete

  assert File.exist?(Imagery.root("avatar", "1001"))
end

# Imagery::Test
scope do
  extend Imagery::Test

  test "yields true when REAL_IMAGERY is set" do
    ENV["REAL_IMAGERY"] = "true"
  
    enabled = nil

    imagery do |e|
      enabled = e  
    end

    assert enabled
  end

  test "yields false when REAL_IMAGERY is not set" do
    ENV["REAL_IMAGERY"] = nil
  
    enabled = nil

    imagery do |e|
      enabled = e  
    end

    assert_equal false, enabled
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
imagery-1.0.0.rc2 tests/faking.rb
imagery-1.0.0.rc1 tests/faking.rb
imagery-0.2.2 test/faking.rb
imagery-0.2.1 test/faking.rb
imagery-0.2.0 test/faking.rb