Sha256: d652e65894d5b23e7d0639c2b82b4b1f18e133b7dc29ce515a5eb8ca94cafdd2

Contents?: true

Size: 1.93 KB

Versions: 6

Compression:

Stored size: 1.93 KB

Contents

require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'../resource')

class TestResourceUnit < Test::Unit::TestCase
  module TestResource
    extend Resource

    self.subdir = Path.setup('tmp/test-resource')

    claim self.tmp.test.google, :url, "http://google.com"
    claim self.tmp.test.string, :string, "TEST"
    claim self.tmp.test.proc, :proc do
      "PROC TEST"
    end

    claim self.tmp.test.rakefiles.Rakefile , :string , <<-EOF
file('foo') do |t|
  Open.write(t.name, "FOO")
end

rule(/.*/) do |t|
  Open.write(t.name, "OTHER")
end
    EOF

    claim self.tmp.test.work.footest, :rake, TestResource.tmp.test.rakefiles.Rakefile

    claim self.tmp.test.work.file_proc, :file_proc do |file,filename|
      Open.write(filename, file)
      nil
    end
  end

  def teardown
    FileUtils.rm_rf TestResource.root.find
  end

  def test_proc
    TestResource.produce TestResource.tmp.test.proc
    assert_include File.open(TestResource.tmp.test.proc.find).read, "PROC TEST"
  end

  def test_string
    TestResource.produce TestResource.tmp.test.string
    assert_include File.open(TestResource.tmp.test.string.find).read, "TEST"
  end

  def test_url
    TestResource.produce TestResource.tmp.test.google
    assert_include File.open(TestResource.tmp.test.google.find).read, "html"
  end

  def test_rake
    TestResource.produce TestResource.tmp.test.work.footest.foo
    TestResource.produce TestResource.tmp.test.work.footest.bar
    TestResource.produce TestResource.tmp.test.work.footest.foo_bar
    assert_include File.open(TestResource.tmp.test.work.footest.foo.find).read, "FOO"
    assert_include File.open(TestResource.tmp.test.work.footest.bar.find).read, "OTHER"
    assert_include File.open(TestResource.tmp.test.work.footest.foo_bar.find).read, "OTHER"
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
scout-gear-7.3.0 test/scout/resource/test_produce.rb
scout-gear-7.2.0 test/scout/resource/test_produce.rb
scout-gear-7.1.0 test/scout/resource/test_produce.rb
scout-gear-6.0.0 test/scout/resource/test_produce.rb
scout-gear-5.2.0 test/scout/resource/test_produce.rb
scout-gear-5.1.1 test/scout/resource/test_produce.rb