Feature: Incremental rebuild
  As an impatient hacker who likes to blog
  I want to be able to make a static site
  Without waiting too long for it to build
  Scenario: Produce correct output site
    Given I have a _layouts directory
    And I have a _posts directory
    And I have the following posts:
      | title    | date       | layout  | content                               |
      | Wargames | 2009-03-27 | default | The only winning move is not to play. |
    And I have a default layout that contains "Post Layout: {{ content }}"
    When I run jekyll build -I
    Then I should get a zero exit status
    And the _site directory should exist
    And I should see "Post Layout: 
The only winning move is not to play.
" in "_site/2009/03/27/wargames.html"
    When I run jekyll build -I
    Then I should get a zero exit status
    And the _site directory should exist
    And I should see "Post Layout: The only winning move is not to play.
" in "_site/2009/03/27/wargames.html"
  Scenario: Generate a metadata file
    Given I have an "index.html" file that contains "Basic Site"
    When I run jekyll build -I
    Then the ".jekyll-metadata" file should exist
  Scenario: Rebuild when content is changed
    Given I have an "index.html" file that contains "Basic Site"
    When I run jekyll build -I
    Then I should get a zero exit status
    And the _site directory should exist
    And I should see "Basic Site" in "_site/index.html"
    When I wait 1 second
    Then I have an "index.html" file that contains "Bacon Site"
    When I run jekyll build -I
    Then I should get a zero exit status
    And the _site directory should exist
    And I should see "Bacon Site" in "_site/index.html"
  Scenario: Rebuild when layout is changed
    Given I have a _layouts directory
    And I have an "index.html" page with layout "default" that contains "Basic Site with Layout"
    And I have a default layout that contains "Page Layout: {{ content }}"
    When I run jekyll build -I
    Then I should get a zero exit status
    And the _site directory should exist
    And I should see "Page Layout: Basic Site with Layout" in "_site/index.html"
    When I wait 1 second
    Then I have a default layout that contains "Page Layout Changed: {{ content }}"
    When I run jekyll build
    Then I should get a zero exit status
    And the _site directory should exist
    And I should see "Page Layout Changed: Basic Site with Layout" in "_site/index.html"
  Scenario: Rebuild when an include is changed
    Given I have a _includes directory
    And I have an "index.html" page that contains "Basic Site with include tag: {% include about.textile %}"
    And I have an "_includes/about.textile" file that contains "Generated by Jekyll"
    When I run jekyll build -I
    Then I should get a zero exit status
    And the _site directory should exist
    And I should see "Basic Site with include tag: Generated by Jekyll" in "_site/index.html"
    When I wait 1 second
    Then I have an "_includes/about.textile" file that contains "Regenerated by Jekyll"
    When I run jekyll build -I
    Then I should get a zero exit status
    And the _site directory should exist
    And I should see "Basic Site with include tag: Regenerated by Jekyll" in "_site/index.html"
  Scenario: Rebuild when a data file is changed
    Given I have a _data directory
    And I have a "_data/colors.yml" file that contains "[red, green, blue]"
    And I have a _data/members/core directory
    And I have a "_data/members/core/emeritus.yml" file with content:
      """
      - name: John Doe
        role: Admin
      """
    And I have an _includes directory
    And I have an "_includes/about.html" file with content:
      """
      
      {% for entry in site.data.members.core.emeritus %}
        - {{ entry.name }}
 
      {% endfor %}
      
      """
    And I have a _layouts directory
    And I have a page layout that contains "{{ content }}\n\n{% include about.html %}"
    And I have a home layout that contains "{{ content }}\n\nGenerated by Jekyll"
    And I have a "_layouts/post.html" page with layout "page" that contains "{{ content }}"
    And I have a "_layouts/static.html" page with layout "home" that contains "{{ content }}"
    And I have an "index.html" page with layout "home" that contains "{{ site.data.colors | join: '_' }}"
    And I have an "about.html" page with layout "page" that contains "About Us"
    And I have a configuration file with "collections_dir" set to "collections"
    And I have a collections/_posts directory
    And I have the following post within the "collections" directory:
      | title    | date       | layout  | content                      |
      | Table    | 2009-03-26 | post    | Post with data dependency    |
      | Wargames | 2009-03-27 | static  | Post without data dependency |
    When I run jekyll build -IV
    Then I should get a zero exit status
    And the _site directory should exist
    And I should see "red_green_blue" in "_site/index.html"
    And I should see "John Doe -- Admin" in "_site/about.html"
    And I should see "Rendering: index.html" in the build output
    And I should see "Rendering: _posts/2009-03-27-wargames.markdown" in the build output
    When I wait 1 second
    Then I have a "_data/members/core/emeritus.yml" file with content:
      """
      - name: Jane Doe
        role: Admin
      """
    When I run jekyll build -IV
    Then I should get a zero exit status
    And the _site directory should exist
    And I should see "red_green_blue" in "_site/index.html"
    And I should see "Jane Doe -- Admin" in "_site/about.html"
    And I should see "Rendering: _posts/2009-03-26-table.markdown" in the build output
    But I should not see "Rendering: index.html" in the build output
    And I should not see "Rendering: _posts/2009-03-27-wargames.markdown" in the build output
  Scenario: Rebuild when a dependency of document in custom collection_dir is changed
    Given I have a _includes directory
    And I have a configuration file with "collections_dir" set to "collections"
    And I have a collections/_posts directory
    And I have the following post within the "collections" directory:
      | title    | date       | layout  | content                                               |
      | Wargames | 2009-03-27 | default | Basic Site with include tag: {% include about.html %} |
    And I have an "_includes/about.html" file that contains "Generated by Jekyll"
    When I run jekyll build -I
    Then I should get a zero exit status
    And the _site directory should exist
    And I should see "Basic Site with include tag: Generated by Jekyll" in "_site/2009/03/27/wargames.html"
    When I wait 1 second
    Then I have an "_includes/about.html" file that contains "Regenerated by Jekyll"
    When I run jekyll build -I
    Then I should get a zero exit status
    And the _site directory should exist
    And I should see "Basic Site with include tag: Regenerated by Jekyll" in "_site/2009/03/27/wargames.html"
  Scenario: A themed-site and incremental regeneration
    Given I have a configuration file with "theme" set to "test-theme"
    And I have an "index.md" page that contains "Themed site"
    When I run jekyll build --incremental --verbose
    Then I should get a zero exit status
    And the _site directory should exist
    And I should see "Rendering: index.md" in the build output
    And I should see "Themed site" in "_site/index.html"
    When I wait 1 second
    And I have an "about.md" page that contains "About Themed site"
    When I run jekyll build --incremental --verbose
    Then I should get a zero exit status
    And the _site directory should exist
    And I should not see "Rendering: index.md" in the build output
    But I should see "Themed site" in "_site/index.html"
    And I should see "About Themed site" in "_site/about.html"