From c52a9683df3309c967d166bc8b52881d889e0843 Mon Sep 17 00:00:00 2001 From: Tuomas Kareinen Date: Sat, 15 Dec 2012 16:05:41 +0200 Subject: [PATCH] Rename test dir helpers for better clarity --- test/integration/minibundle_test.rb | 20 ++++++++++---------- test/integration/ministamp_test.rb | 8 ++++---- test/support/test_case.rb | 21 +++++++++++---------- test/unit/asset_bundle_test.rb | 2 +- 4 files changed, 26 insertions(+), 25 deletions(-) diff --git a/test/integration/minibundle_test.rb b/test/integration/minibundle_test.rb index ac1ea5b..43c8357 100644 --- a/test/integration/minibundle_test.rb +++ b/test/integration/minibundle_test.rb @@ -27,49 +27,49 @@ def test_js_asset_bundle_has_stamp end def test_css_asset_bundle_is_copied_to_destination_dir - assert File.exists?(gensite_path(EXPECTED_CSS_ASSET_PATH)) + assert File.exists?(destination_path(EXPECTED_CSS_ASSET_PATH)) end def test_js_asset_bundle_is_copied_to_destination_dir - assert File.exists?(gensite_path(EXPECTED_JS_ASSET_PATH)) + assert File.exists?(destination_path(EXPECTED_JS_ASSET_PATH)) end def test_css_asset_bundle_is_concatenated_in_configured_order - bundle = File.read(gensite_path(EXPECTED_CSS_ASSET_PATH)) + bundle = File.read(destination_path(EXPECTED_CSS_ASSET_PATH)) assert bundle.index('html { margin: 0; }') < bundle.index('p { margin: 0; }') end def test_js_asset_bundle_is_concatenated_in_configured_order - bundle = File.read(gensite_path(EXPECTED_JS_ASSET_PATH)) + bundle = File.read(destination_path(EXPECTED_JS_ASSET_PATH)) assert bundle.index('root.dependency = {};') < bundle.index('root.app = {};') end def test_js_asset_bundle_has_inserted_semicolons_between_assets - bundle = File.read(gensite_path(EXPECTED_JS_ASSET_PATH)) + bundle = File.read(destination_path(EXPECTED_JS_ASSET_PATH)) assert_match(%r|}\)\(window\)\n;\n\(function|, bundle) end def test_css_asset_bundle_is_minified source_contents_size = source_assets_size('_assets/styles', %w{reset common}, 'css') - destination_contents_size = File.read(gensite_path(EXPECTED_CSS_ASSET_PATH)).size + destination_contents_size = File.read(destination_path(EXPECTED_CSS_ASSET_PATH)).size assert destination_contents_size < source_contents_size end def test_js_asset_bundle_is_minified source_contents_size = source_assets_size('_assets/scripts', %w{dependency app}, 'js') - destination_contents_size = File.read(gensite_path(EXPECTED_JS_ASSET_PATH)).size + destination_contents_size = File.read(destination_path(EXPECTED_JS_ASSET_PATH)).size assert destination_contents_size < source_contents_size end private def find_html_element_from_index(css) - find_html_element(read_from_gensite('index.html'), css) + find_html_element(read_from_destination('index.html'), css) end - def source_assets_size(fixture_subdir, assets, type) + def source_assets_size(source_subdir, assets, type) assets. - map { |f| File.read fixture_path(fixture_subdir, "#{f}.#{type}") }. + map { |f| File.read source_path(source_subdir, "#{f}.#{type}") }. join(''). size end diff --git a/test/integration/ministamp_test.rb b/test/integration/ministamp_test.rb index d99354a..9b73920 100644 --- a/test/integration/ministamp_test.rb +++ b/test/integration/ministamp_test.rb @@ -5,17 +5,17 @@ class MiniStampTest < TestCase EXPECTED_ASSET_PATH = 'assets/screen-390be921ee0eff063817bb5ef2954300.css' def test_asset_path_has_stamp - actual = find_html_element(read_from_gensite('index.html'), 'head link').first['href'] + actual = find_html_element(read_from_destination('index.html'), 'head link').first['href'] assert_equal EXPECTED_ASSET_PATH, actual end def test_asset_file_is_copied_to_destination_dir - assert File.exists?(gensite_path(EXPECTED_ASSET_PATH)) + assert File.exists?(destination_path(EXPECTED_ASSET_PATH)) end def test_asset_file_is_equal_to_source_file - source_contents = File.read fixture_path('_tmp/site.css') - destination_contents = File.read gensite_path(EXPECTED_ASSET_PATH) + source_contents = File.read source_path('_tmp/site.css') + destination_contents = File.read destination_path(EXPECTED_ASSET_PATH) assert_equal source_contents, destination_contents end end diff --git a/test/support/test_case.rb b/test/support/test_case.rb index c3cf473..e4f21e4 100644 --- a/test/support/test_case.rb +++ b/test/support/test_case.rb @@ -9,18 +9,19 @@ module Jekyll::Minibundle::Test class TestCase < ::MiniTest::Unit::TestCase include ::Jekyll::Minibundle - FIXTURE_DIR = File.expand_path(File.join(File.dirname(__FILE__), '../fixture/site')) + FIXTURE_DIR = File.expand_path(File.join(File.dirname(__FILE__), '../fixture')) + SOURCE_DIR = File.join(FIXTURE_DIR, 'site') - def fixture_path(*args) - File.join(FIXTURE_DIR, *args) + def source_path(*args) + File.join(SOURCE_DIR, *args) end - def gensite_path(*args) - File.join(_gensite_dir, *args) + def destination_path(*args) + File.join(_destination_dir, *args) end - def read_from_gensite(*args) - File.read gensite_path(*args) + def read_from_destination(*args) + File.read destination_path(*args) end def find_html_element(file, css) @@ -40,8 +41,8 @@ def with_env(env) private - def _gensite_dir(&block) - @@_gensite_dir ||= begin + def _destination_dir(&block) + @@_destination_dir ||= begin dir = Dir.mktmpdir('jekyll-minibundle-test-') at_exit do FileUtils.rm_rf dir @@ -55,7 +56,7 @@ def _gensite_dir(&block) def _generate_site(destination) options = { - 'source' => fixture_path, + 'source' => source_path, 'destination' => destination } capture_io { Jekyll::Site.new(Jekyll.configuration(options)).process } diff --git a/test/unit/asset_bundle_test.rb b/test/unit/asset_bundle_test.rb index 6fac297..c429c2f 100644 --- a/test/unit/asset_bundle_test.rb +++ b/test/unit/asset_bundle_test.rb @@ -28,7 +28,7 @@ def test_raise_exception_if_bundle_command_not_configured private def make_bundle - bundle = AssetBundle.new :js, [fixture_path('_assets/scripts/dependency.js')], fixture_path + bundle = AssetBundle.new :js, [source_path('_assets/scripts/dependency.js')], source_path bundle.make_bundle end end