<commit_before>require 'fileutils'
require 'tmpdir'

def execute_command_with_success(cmd)
	system(cmd)
	if ! $?.success?
		puts "Failed with #{$?}"
		raise "failed! #{cmd}"
	end
end

describe 'Templating' do
	let(:templating) { FruitToLime::Templating.new(File.expand_path("../templates", File.dirname(__FILE__))) }
	
	describe 'list' do
		it 'can find some templates' do
			templating.list().length.should > 0
		end
	end

	describe 'unpack' do
		unpack_path = File.expand_path("unpacked", Dir.tmpdir)
		before {
			FileUtils.remove_dir(unpack_path, true)
			FileUtils.mkdir(unpack_path)
		}

		it 'can unpack all templates and run the template tests' do
			templating.list().each {|t|
				templating.unpack t, unpack_path
				Dir.chdir(File.expand_path(t, unpack_path)) do
					execute_command_with_success('rake spec')
				end
			}
		end

		after {
			FileUtils.remove_dir(unpack_path, true)
		}
	end
end<commit_msg>Should be a bit clearer<commit_after>require 'fileutils'
require 'tmpdir'

def execute_command_with_success_for_template(cmd, template)
	system(cmd)
	if ! $?.success?
		puts "Failed with #{$?}"
		raise "failed! #{cmd} for template #{template}"
	end
end

describe 'Templating' do
	let(:templating) { FruitToLime::Templating.new(File.expand_path("../templates", File.dirname(__FILE__))) }
	
	describe 'list' do
		it 'can find some templates' do
			templating.list().length.should > 0
		end
	end

	describe 'unpack' do
		unpack_path = File.expand_path("unpacked", Dir.tmpdir)
		before {
			FileUtils.remove_dir(unpack_path, true)
			FileUtils.mkdir(unpack_path)
		}

		it 'can unpack all templates and run the template tests' do
			templating.list().each {|t|
				templating.unpack t, unpack_path
				Dir.chdir(File.expand_path(t, unpack_path)) do
					execute_command_with_success_for_template('rake spec', t)
				end
			}
		end

		after {
			FileUtils.remove_dir(unpack_path, true)
		}
	end
end
{'fraction_non_alphanumeric': 0.11872384937238493, 'fraction_numerical': 0.0010460251046025104, 'mean_word_length': 4.2845303867403315, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2814842', 'n_tokens_mistral': 779, 'n_tokens_neox': 677, 'n_words': 156}