forked from jekyll/jekyll
/
jekyll_steps.rb
102 lines (83 loc) · 2.19 KB
/
jekyll_steps.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
Before do
FileUtils.mkdir(TEST_DIR)
Dir.chdir(TEST_DIR)
end
After do
Dir.chdir(TEST_DIR)
FileUtils.rm_rf(TEST_DIR)
end
Given /^I have an "(.*)" page(?: with layout "(.*)")? that contains "(.*)"$/ do |file, layout, text|
File.open(file, 'w') do |f|
f.write <<EOF
---
layout: #{layout || 'nil'}
---
EOF
f.write(text)
f.close
end
end
Given /^I have an "(.*)" file that contains "(.*)"$/ do |file, text|
File.open(file, 'w') do |f|
f.write(text)
f.close
end
end
Given /^I have a (.*) layout that contains "(.*)"$/ do |layout, text|
File.open(File.join('_layouts', layout + '.html'), 'w') do |f|
f.write(text)
f.close
end
end
Given /^I have a (.*) directory$/ do |dir|
FileUtils.mkdir(dir)
end
Given /^I have the following posts?(?: in "(.*)")?:$/ do |dir, table|
table.hashes.each do |post|
date = Date.parse(post['date']).strftime('%Y-%m-%d')
title = post['title'].downcase.gsub(/[^\w]/, " ").strip.gsub(/\s+/, '-')
path = File.join("_posts", "#{date}-#{title}.#{post['type'] || 'textile'}")
matter_hash = {}
%w(title layout tags).each do |key|
matter_hash[key] = post[key] if post[key]
end
matter = matter_hash.map { |k, v| "#{k}: #{v}\n" }.join.chomp
content = post['content']
if post['input'] && post['filter']
content = "{{ #{post['input']} | #{post['filter']} }}"
end
File.open(path, 'w') do |f|
f.write <<EOF
---
#{matter}
---
#{content}
EOF
f.close
end
end
end
Given /^I have a configuration file(?: in "(.*)")? with "(.*)" set to "(.*)"$/ do |dir, key, value|
pending
end
When /^I run jekyll$/ do
system File.join(ENV['PWD'], 'bin', 'jekyll') + " >> /dev/null"
end
When /^I change "(.*)" to contain "(.*)"$/ do |file, text|
pending
end
When /^I go to "(.*)"$/ do |address|
pending
end
Then /^the (.*) directory should exist$/ do |dir|
assert File.directory?(dir)
end
Then /^I should see "(.*)" in "(.*)"$/ do |text, file|
assert_match Regexp.new(text), File.open(file).readlines.join
end
Then /^the "(.*)" file should not exist$/ do |file|
pending
end
Then /^I should see today's date in "(.*)"$/ do |file|
assert_match Regexp.new(Date.today.to_s), File.open(file).readlines.join
end