Sha256: 1e6aa05704e9757a0943e624e6fecf7de8a2717fad13123ef2ba4f6072e044f7

Contents?: true

Size: 1.45 KB

Versions: 14

Compression:

Stored size: 1.45 KB

Contents

# encoding: utf-8

class Nanoc::Tasks::CleanTest < Nanoc::TestCase

  def test_simple
    if_have 'w3c_validators' do
      # Stub items
      items = [ mock, mock ]
      reps  = [ [ mock, mock ], [ mock, mock ] ]
      items[0].expects(:reps).returns(reps[0])
      items[1].expects(:reps).returns(reps[1])

      # Create sample files
      [ 0, 1 ].each do |item_id|
        [ 0, 1 ].each do |rep_id|
          filename = "item-#{item_id}-rep-#{rep_id}.txt"
          reps[item_id][rep_id].expects(:raw_path).returns(filename)
          File.open(filename, 'w') { |io| io.write('hello') }
          assert File.file?(filename)
        end
      end

      # Stub site
      site = mock
      site.expects(:items).returns(items)

      # Create clean task
      clean = ::Nanoc::Tasks::Clean.new(site)

      # Run
      clean.run

      # Check
      [ 0, 1 ].each do |item_id|
        [ 0, 1 ].each do |rep_id|
          filename = "item-#{item_id}-rep-#{rep_id}.txt"
          assert !File.file?(filename)
        end
      end
    end
  end

  def test_with_nil_raw_path
    if_have 'w3c_validators' do
      # Stub items
      item = mock
      rep = mock
      item.expects(:reps).returns([ rep ])

      # Create sample file
      rep.expects(:raw_path).returns(nil)

      # Stub site
      site = mock
      site.expects(:items).returns([ item ])

      # Create clean task
      clean = ::Nanoc::Tasks::Clean.new(site)

      # Run
      clean.run
    end
  end

end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
nanoc-3.7.3 test/tasks/test_clean.rb
nanoc-3.7.2 test/tasks/test_clean.rb
nanoc-3.7.1 test/tasks/test_clean.rb
nanoc-3.7.0 test/tasks/test_clean.rb
nanoc-3.6.11 test/tasks/test_clean.rb
nanoc-3.6.10 test/tasks/test_clean.rb
nanoc-3.6.9 test/tasks/test_clean.rb
nanoc-3.6.8 test/tasks/test_clean.rb
nanoc-3.6.7 test/tasks/test_clean.rb
nanoc-3.6.6 test/tasks/test_clean.rb
nanoc-3.6.5 test/tasks/test_clean.rb
nanoc-3.6.4 test/tasks/test_clean.rb
nanoc-3.6.3 test/tasks/test_clean.rb
nanoc-3.6.2 test/tasks/test_clean.rb