Add cukes

This commit is contained in:
Joseph Wynn 2014-12-05 23:55:10 +00:00
parent a09d47b60a
commit fb6ef53a97
6 changed files with 52 additions and 9 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

View File

@ -10,7 +10,38 @@ Feature: Jekyll responsive-image tag
"""
And I have a file "index.html" with:
"""
{% responsive_image path: assets/test.jpg %}
{% responsive_image path: assets/test.png alt: Foobar %}
"""
When I run Jekyll
Then I should see "<img src=\"/assets/test.jpg\" alt=\"\">" in "_site/index.html"
Then I should see "<img alt=\"Foobar\" src=\"/assets/test.png\">" in "_site/index.html"
Scenario: UTF-8 alt attribute
Given I have a responsive_image configuration with:
"""
template: _includes/responsive-image.html
"""
And I have a file "index.html" with:
"""
{% responsive_image path: assets/test.png alt: " " %}
"""
When I run Jekyll
Then I should see "<img alt=\"かっこいい! ジェケルが好きです!\" src=\"/assets/test.png\">" in "_site/index.html"
Scenario: Image with multiple sizes
Given I have a responsive_image configuration with:
"""
template: _includes/responsive-image.html
sizes:
- width: 100
- width: 200
"""
And I have a file "index.html" with:
"""
{% responsive_image path: assets/test.png %}
"""
When I run Jekyll
Then I should see "<img alt=\"\" src=\"/assets/test.png\"" in "_site/index.html"
And I should see "/assets/resized/test-100x50.png 100w" in "_site/index.html"
And I should see "/assets/resized/test-200x100.png 200w" in "_site/index.html"
And the file "assets/resized/test-100x50.png" should exist
And the file "assets/resized/test-200x100.png" should exist

View File

@ -6,14 +6,18 @@ Given /^I have a responsive_image configuration with:$/ do |config|
write_file('_config.yml', "responsive_image:\n#{config}")
end
Given /^I have a file "([^\"]+)" with:$/ do |path, contents|
write_file(path, contents)
Given /^I have a file "(.+)" with:$/ do |path, contents|
write_file(path, "---\n---\n#{contents}")
end
Then /^I should see "(.*)" in "(.*)"$/ do |text, file|
Then /^I should see "(.+)" in "(.*)"$/ do |text, file|
assert_match(Regexp.new(text), File.open(file).readlines.join)
end
Then /^the file "(.+)" should exist$/ do |path|
assert File.exists?(path)
end
def write_file(path, contents)
File.open(path, 'w') do |f|
f.write(contents)

View File

@ -1,9 +1,13 @@
Before do
FileUtils.rm_rf(TEST_DIR) if File.exist?(TEST_DIR)
FileUtils.mkdir_p(TEST_DIR)
fixtures = File.expand_path('../../fixtures', __FILE__)
FileUtils.cp_r(Dir.glob("#{fixtures}/*"), TEST_DIR)
Dir.chdir(TEST_DIR)
end
After do
at_exit do
FileUtils.rm_rf(TEST_DIR) if File.exist?(TEST_DIR)
end

View File

@ -19,13 +19,17 @@ module Jekyll
end
def resize_image(path, config)
sizes = config['sizes']
return if sizes.empty?
output_dir = config['output_dir']
ensure_output_dir_exists!(output_dir)
resized = []
img = Magick::Image::read(path).first
config['sizes'].each do |size|
sizes.each do |size|
width = size['width']
ratio = width.to_f / img.columns.to_f
height = (img.rows.to_f * ratio).round