From 69b68f3a447a14aec64feb78eaca7274cb6cbc1d Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Mon, 26 Jan 2015 16:22:55 -0600 Subject: [PATCH] Extracting common methods into helper. --- test/helper.rb | 18 ++++++++++++++++++ test/test_blob.rb | 18 ------------------ test/test_classifier.rb | 4 ---- test/test_generated.rb | 4 ---- test/test_heuristics.rb | 4 ---- test/test_modelines.rb | 9 --------- test/test_tokenizer.rb | 4 ---- 7 files changed, 18 insertions(+), 43 deletions(-) diff --git a/test/helper.rb b/test/helper.rb index ebfeefc7..a6a03672 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -2,3 +2,21 @@ require "bundler/setup" require "minitest/autorun" require "mocha/setup" require "linguist" + +def fixtures_path + File.expand_path("../fixtures", __FILE__) +end + +def fixture_blob(name) + name = File.join(fixtures_path, name) unless name =~ /^\// + Linguist::FileBlob.new(name, fixtures_path) +end + +def samples_path + File.expand_path("../../samples", __FILE__) +end + +def sample_blob(name) + name = File.join(samples_path, name) unless name =~ /^\// + Linguist::FileBlob.new(name, samples_path) +end diff --git a/test/test_blob.rb b/test/test_blob.rb index 372ff13f..ceb54bb3 100644 --- a/test/test_blob.rb +++ b/test/test_blob.rb @@ -14,24 +14,6 @@ class TestBlob < Minitest::Test Encoding.default_external = @original_external end - def samples_path - File.expand_path("../../samples", __FILE__) - end - - def fixtures_path - File.expand_path("../fixtures", __FILE__) - end - - def sample_blob(name) - name = File.join(samples_path, name) unless name =~ /^\// - FileBlob.new(name, samples_path) - end - - def fixture_blob(name) - name = File.join(fixtures_path, name) unless name =~ /^\// - FileBlob.new(name, fixtures_path) - end - def script_blob(name) blob = sample_blob(name) blob.instance_variable_set(:@name, 'script') diff --git a/test/test_classifier.rb b/test/test_classifier.rb index 1d10d512..2ae2f45e 100644 --- a/test/test_classifier.rb +++ b/test/test_classifier.rb @@ -3,10 +3,6 @@ require_relative "./helper" class TestClassifier < Minitest::Test include Linguist - def samples_path - File.expand_path("../../samples", __FILE__) - end - def fixture(name) File.read(File.join(samples_path, name)) end diff --git a/test/test_generated.rb b/test/test_generated.rb index 1c3f8d90..b714e19e 100644 --- a/test/test_generated.rb +++ b/test/test_generated.rb @@ -3,10 +3,6 @@ require_relative "./helper" class TestGenerated < Minitest::Test include Linguist - def samples_path - File.expand_path("../../samples", __FILE__) - end - class DataLoadedError < StandardError; end def generated_without_loading_data(name) diff --git a/test/test_heuristics.rb b/test/test_heuristics.rb index b88d0fda..3ea4af78 100644 --- a/test/test_heuristics.rb +++ b/test/test_heuristics.rb @@ -3,10 +3,6 @@ require_relative "./helper" class TestHeuristcs < Minitest::Test include Linguist - def samples_path - File.expand_path("../../samples", __FILE__) - end - def fixture(name) File.read(File.join(samples_path, name)) end diff --git a/test/test_modelines.rb b/test/test_modelines.rb index 717dadf9..6c68cc87 100644 --- a/test/test_modelines.rb +++ b/test/test_modelines.rb @@ -3,15 +3,6 @@ require_relative "./helper" class TestModelines < Minitest::Test include Linguist - def fixtures_path - File.expand_path("../fixtures", __FILE__) - end - - def fixture_blob(name) - name = File.join(fixtures_path, name) unless name =~ /^\// - FileBlob.new(name, fixtures_path) - end - def assert_modeline(language, blob) assert_equal language, Linguist::Strategy::Modeline.call(blob).first end diff --git a/test/test_tokenizer.rb b/test/test_tokenizer.rb index 339d5485..780db019 100644 --- a/test/test_tokenizer.rb +++ b/test/test_tokenizer.rb @@ -3,10 +3,6 @@ require_relative "./helper" class TestTokenizer < Minitest::Test include Linguist - def samples_path - File.expand_path("../../samples", __FILE__) - end - def tokenize(data) data = File.read(File.join(samples_path, data.to_s)) if data.is_a?(Symbol) Tokenizer.tokenize(data)