Sha256: 47cbac0cf81870c2d31364bae104a593beba8b33da39fdcb09f88843871c3a5e

Contents?: true

Size: 1.48 KB

Versions: 17

Compression:

Stored size: 1.48 KB

Contents

# encoding: utf-8

class Nanoc::Tasks::CleanTest < MiniTest::Unit::TestCase

  include Nanoc::TestHelpers

  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

17 entries across 17 versions & 1 rubygems

Version Path
nanoc-3.6.1 test/tasks/test_clean.rb
nanoc-3.6.0 test/tasks/test_clean.rb
nanoc-3.5.0 test/tasks/test_clean.rb
nanoc-3.5.0b2 test/tasks/test_clean.rb
nanoc-3.5.0b1 test/tasks/test_clean.rb
nanoc-3.4.3 test/tasks/test_clean.rb
nanoc-3.4.2 test/tasks/test_clean.rb
nanoc-3.4.1 test/tasks/test_clean.rb
nanoc-3.4.0 test/tasks/test_clean.rb
nanoc-3.3.7 test/tasks/test_clean.rb
nanoc-3.3.6 test/tasks/test_clean.rb
nanoc-3.3.5 test/tasks/test_clean.rb
nanoc-3.3.4 test/tasks/test_clean.rb
nanoc-3.3.3 test/tasks/test_clean.rb
nanoc-3.3.2 test/tasks/test_clean.rb
nanoc-3.3.1 test/tasks/test_clean.rb
nanoc-3.3.0 test/tasks/test_clean.rb