jekyll_steps.rb 1.37 KB
Newer Older
Sylvester Keil's avatar
Sylvester Keil committed
1 2

# Like "I have a foo file" but gives a yaml front matter so jekyll actually processes it
Sylvester Keil's avatar
Sylvester Keil committed
3
Given(/^I have an? "(.*)" page(?: with (.*) "(.*)")? that contains "(.*)"$/) do |file, key, value, text|
Sylvester Keil's avatar
Sylvester Keil committed
4 5 6 7 8 9 10 11 12 13 14
  File.open(file, 'w') do |f|
    f.write <<EOF
---
#{key || 'layout'}: #{value || 'nil'}
---
#{text}
EOF
    f.close
  end
end

Sylvester Keil's avatar
Sylvester Keil committed
15
Given(/^I have an? "(.*)" file that contains "(.*)"$/) do |file, text|
Sylvester Keil's avatar
Sylvester Keil committed
16 17 18 19 20 21
  File.open(file, 'w') do |f|
    f.write(text)
    f.close
  end
end

Sylvester Keil's avatar
Sylvester Keil committed
22
Given(/^I have a configuration file with "(.*)" set to "(.*)"$/) do |key, value|
Sylvester Keil's avatar
Sylvester Keil committed
23
  File.open('_config.yml', 'a') do |f|
Sylvester Keil's avatar
Sylvester Keil committed
24 25 26 27 28
    f.write("#{key}: #{value}\n")
    f.close
  end
end

Sylvester Keil's avatar
Sylvester Keil committed
29
Given(/^I have a configuration file with:$/) do |table|
Sylvester Keil's avatar
Sylvester Keil committed
30
  File.open('_config.yml', 'a') do |f|
Sylvester Keil's avatar
Sylvester Keil committed
31 32 33 34 35 36 37
    table.hashes.each do |row|
      f.write("#{row["key"]}: #{row["value"]}\n")
    end
    f.close
  end
end

Sylvester Keil's avatar
Sylvester Keil committed
38
When(/^I run jekyll$/) do
Sylvester Keil's avatar
Sylvester Keil committed
39 40 41
  run_jekyll
end

Sylvester Keil's avatar
Sylvester Keil committed
42
Then(/^the (.*) directory should exist$/) do |dir|
Sylvester Keil's avatar
Sylvester Keil committed
43 44 45
  assert File.directory?(dir)
end

Sylvester Keil's avatar
Sylvester Keil committed
46
Then(/^I should see "(.*)" in "(.*)"$/) do |text, file|
Sylvester Keil's avatar
Sylvester Keil committed
47 48 49
  assert_match Regexp.new(text), File.open(file).readlines.join
end

Sylvester Keil's avatar
Sylvester Keil committed
50
Then(/^I should not see "(.*)" in "(.*)"$/) do |text, file|
Sylvester Keil's avatar
Sylvester Keil committed
51 52 53 54
  assert !File.open(file).readlines.join.match(Regexp.new(text))
end


Sylvester Keil's avatar
Sylvester Keil committed
55
Then(/^the "(.*)" file should exist$/) do |file|
Sylvester Keil's avatar
Sylvester Keil committed
56 57 58
  assert File.file?(file)
end

Sylvester Keil's avatar
Sylvester Keil committed
59
Then(/^the "(.*)" file should not exist$/) do |file|
Sylvester Keil's avatar
Sylvester Keil committed
60 61
  assert !File.exists?(file)
end