<commit_before>require 'spec_helper'
require './generate_flatfile'

describe "Flatfiles backend", :js => true do

        type = "Flatfile"
	name = "Metric"
	metric = "#{type}~#{name}"
	
	before :each do
		add_config "backends: [{ type: '#{type}', settings: { file_name: 'public/flatfile_15s.csv', metric: '#{name}'}}]"
		test_config type
	end

	context "refresh metrics" do
		include_examples "refresh metrics", type
	end
	
	context "graphs" do
		it_behaves_like "a graph", metric
	end

end

describe "Broken Filefiles Backend", :js => true do	
	
	
	it "test fallback functionality" do

		bad_backend = "Flatfile~Potato"
		file = 'this_does_not_exist/nope.csv'
		add_config "backends: [{ type: 'flatfile', settings: { file_name: #{file}, metric: 'potato'}}]"
		visit "/metric/?metric=#{bad_backend}"
		json = JSON.parse(page.text)
		expect(json).to include "error"
		expect(json["error"]).to eq "File #{file} does not exist"

		visit "/refresh"
		expect(page).to have_css "div.alert-danger"

		visit "/source/"
		json = JSON.parse(page.text)
		expect(json).to include "error"
		expect(json["error"]).to eq "File #{file} does not exist"
	end
end<commit_msg>remove /source/ check for now, pending expected behaviour checks.<commit_after>require 'spec_helper'
require './generate_flatfile'

describe "Flatfiles backend", :js => true do

        type = "Flatfile"
	name = "Metric"
	metric = "#{type}~#{name}"
	
	before :each do
		add_config "backends: [{ type: '#{type}', settings: { file_name: 'public/flatfile_15s.csv', metric: '#{name}'}}]"
		test_config type
	end

	context "refresh metrics" do
		include_examples "refresh metrics", type
	end
	
	context "graphs" do
		it_behaves_like "a graph", metric
	end

end

describe "Broken Filefiles Backend", :js => true do	
	
	
	it "test fallback functionality" do

		bad_backend = "Flatfile~Potato"
		file = 'this_does_not_exist/nope.csv'
		add_config "backends: [{ type: 'flatfile', settings: { file_name: #{file}, metric: 'potato'}}]"
		visit "/metric/?metric=#{bad_backend}"
		json = JSON.parse(page.text)
		expect(json).to include "error"
		expect(json["error"]).to eq "File #{file} does not exist"

		visit "/refresh"
		expect(page).to have_css "div.alert-danger"
	end
end
{'fraction_non_alphanumeric': 0.1494822152183701, 'fraction_numerical': 0.0018009905447996398, 'mean_word_length': 4.472906403940887, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '5769374', 'n_tokens_mistral': 828, 'n_tokens_neox': 754, 'n_words': 211}