add tests for json data
This commit is contained in:
parent
bf3a20b2d7
commit
5129a3ccc3
|
@ -33,6 +33,18 @@ Feature: Data
|
|||
And I should see "Jack" in "_site/index.html"
|
||||
And I should see "Leon" in "_site/index.html"
|
||||
|
||||
Scenario: autoload *.json files in _data directory
|
||||
Given I have a _data directory
|
||||
And I have a "_data/members.json" file with content:
|
||||
"""
|
||||
[{"name": "Jack", "age": 28},{"name": "Leon", "age": 34}]
|
||||
"""
|
||||
And I have an "index.html" page that contains "{% for member in site.data.members %}{{member.name}}{% endfor %}"
|
||||
When I run jekyll build
|
||||
Then the "_site/index.html" file should exist
|
||||
And I should see "Jack" in "_site/index.html"
|
||||
And I should see "Leon" in "_site/index.html"
|
||||
|
||||
Scenario: autoload *.yml files in _data directory with space in file name
|
||||
Given I have a _data directory
|
||||
And I have a "_data/team members.yml" file with content:
|
||||
|
@ -62,4 +74,3 @@ Feature: Data
|
|||
Then the "_site/index.html" file should exist
|
||||
And I should see "Jack" in "_site/index.html"
|
||||
And I should see "Leon" in "_site/index.html"
|
||||
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
[
|
||||
{
|
||||
"name": "Jack",
|
||||
"age": 27,
|
||||
"blog": "http://example.com/jack"
|
||||
},
|
||||
{
|
||||
"name": "John",
|
||||
"age": 32,
|
||||
"blog": "http://example.com/john"
|
||||
}
|
||||
]
|
|
@ -378,6 +378,16 @@ class TestSite < Test::Unit::TestCase
|
|||
assert_equal site.site_payload['site']['data']['languages'], file_content
|
||||
end
|
||||
|
||||
should 'auto load json files' do
|
||||
site = Site.new(Jekyll.configuration)
|
||||
site.process
|
||||
|
||||
file_content = SafeYAML.load_file(File.join(source_dir, '_data', 'members.json'))
|
||||
|
||||
assert_equal site.data['members'], file_content
|
||||
assert_equal site.site_payload['site']['data']['members'], file_content
|
||||
end
|
||||
|
||||
should "load symlink files in unsafe mode" do
|
||||
site = Site.new(Jekyll.configuration.merge({'safe' => false}))
|
||||
site.process
|
||||
|
|
Loading…
Reference in New Issue