Navigation Menu

Skip to content

Commit

Permalink
Rename test dir helpers for better clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
tkareine committed Dec 15, 2012
1 parent 2325ec7 commit c52a968
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 25 deletions.
20 changes: 10 additions & 10 deletions test/integration/minibundle_test.rb
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions test/integration/ministamp_test.rb
Expand Up @@ -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
Expand Down
21 changes: 11 additions & 10 deletions test/support/test_case.rb
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion test/unit/asset_bundle_test.rb
Expand Up @@ -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
Expand Down

0 comments on commit c52a968

Please sign in to comment.