<commit_before>Feature: hub gist
  Background:
    Given I am "octokitten" on github.com with OAuth token "<PASSWORD>"

  Scenario: Fetch a gist with a single file
    Given the GitHub API server:
      """
      get('/gists/myhash') {
        json({
          :files => {
            'hub_gist1.txt' => {
              'content' => "my content is here",
            }
          },
          :description => "my gist",
        })
      }
      """
    When I successfully run `hub gist show myhash`
    Then the output should contain exactly:
      """
      my content is here
      """
  
  Scenario: Fetch a gist with many files
    Given the GitHub API server:
      """
      get('/gists/myhash') {
        json({
          :files => {
            'hub_gist1.txt' => {
              'content' => "my content is here"
            },
            'hub_gist2.txt' => {
              'content' => "more content is here"
            }
          },
          :description => "my gist",
          :id => "myhash",
        })
      }
      """
    When I run `hub gist show myhash`
    Then the exit status should be 1
    Then the output should contain:
      """
      the gist contains multiple files, you must specify one:\n
      """
    And the output should contain "hub_gist1.txt"
    And the output should contain "hub_gist2.txt"

  Scenario: Fetch a single file from gist
    Given the GitHub API server:
      """
      get('/gists/myhash') {
        json({
          :files => {
            'hub_gist1.txt' => {
              'content' => "my content is here"
            },
            'hub_gist2.txt' => {
              'content' => "more content is here"
            }
          },
          :description => "my gist",
          :id => "myhash",
        })
      }
      """
    When I successfully run `hub gist show myhash hub_gist1.txt`
    Then the output should contain exactly:
      """
      my content is here
      """

  Scenario: Creates a gist
    Given the GitHub API server:
      """
      post('/gists') {
        status 201
        json({
          :html_url => 'http://gists.github.com/somehash',
        })
      }
      """
    Given a file named "testfile.txt" with:
      """
      this is a test file
      """
    When I successfully run `hub gist create testfile.txt`
    Then the output should contain exactly:
      """
      http://gists.github.com/somehash
      """

  Scenario: Open the new gist in a browser
    Given the GitHub API server:
      """
      post('/gists') {
        status 201
        json :html_url => 'http://gists.github.com/somehash'
      }
      """
    Given a file named "testfile.txt" with:
      """
      this is a test file
      """
    When I successfully run `hub gist create -o testfile.txt`
    Then the output should contain exactly ""
    And "open http://gists.github.com/somehash" should be run

  Scenario: Creates a gist with multiple files
    Given the GitHub API server:
      """
      post('/gists') {
        halt 400 unless params[:files]["testfile.txt"]["content"]
        halt 400 unless params[:files]["testfile2.txt"]["content"]
        status 201
        json({
          :html_url => 'http://gists.github.com/somehash',
        })
      }
      """
    Given a file named "testfile.txt" with:
      """
      this is a test file
      """
    Given a file named "testfile2.txt" with:
      """
      this is another test file
      """
    When I successfully run `hub gist create testfile.txt testfile2.txt`
    Then the output should contain exactly:
      """
      http://gists.github.com/somehash
      """

  Scenario: Insufficient OAuth scopes
    Given the GitHub API server:
      """
      post('/gists') {
        status 404
        response.headers['x-oauth-scopes'] = 'repos'
        json({})
      }
      """
    Given a file named "testfile.txt" with:<commit_msg>[gist] Add test for reading from stdin<commit_after>Feature: hub gist
  Background:
    Given I am "octokitten" on github.com with OAuth token "<PASSWORD>"

  Scenario: Fetch a gist with a single file
    Given the GitHub API server:
      """
      get('/gists/myhash') {
        json({
          :files => {
            'hub_gist1.txt' => {
              'content' => "my content is here",
            }
          },
          :description => "my gist",
        })
      }
      """
    When I successfully run `hub gist show myhash`
    Then the output should contain exactly:
      """
      my content is here
      """
  
  Scenario: Fetch a gist with many files
    Given the GitHub API server:
      """
      get('/gists/myhash') {
        json({
          :files => {
            'hub_gist1.txt' => {
              'content' => "my content is here"
            },
            'hub_gist2.txt' => {
              'content' => "more content is here"
            }
          },
          :description => "my gist",
          :id => "myhash",
        })
      }
      """
    When I run `hub gist show myhash`
    Then the exit status should be 1
    Then the output should contain:
      """
      the gist contains multiple files, you must specify one:\n
      """
    And the output should contain "hub_gist1.txt"
    And the output should contain "hub_gist2.txt"

  Scenario: Fetch a single file from gist
    Given the GitHub API server:
      """
      get('/gists/myhash') {
        json({
          :files => {
            'hub_gist1.txt' => {
              'content' => "my content is here"
            },
            'hub_gist2.txt' => {
              'content' => "more content is here"
            }
          },
          :description => "my gist",
          :id => "myhash",
        })
      }
      """
    When I successfully run `hub gist show myhash hub_gist1.txt`
    Then the output should contain exactly:
      """
      my content is here
      """

  Scenario: Create a gist from file
    Given the GitHub API server:
      """
      post('/gists') {
        status 201
        json :html_url => 'http://gists.github.com/somehash'
      }
      """
    Given a file named "testfile.txt" with:
      """
      this is a test file
      """
    When I successfully run `hub gist create testfile.txt`
    Then the output should contain exactly:
      """
      http://gists.github.com/somehash
      """

  Scenario: Open the new gist in a browser
    Given the GitHub API server:
      """
      post('/gists') {
        status 201
        json :html_url => 'http://gists.github.com/somehash'
      }
      """
    Given a file named "testfile.txt" with:
      """
      this is a test file
      """
    When I successfully run `hub gist create -o testfile.txt`
    Then the output should contain exactly ""
    And "open http://gists.github.com/somehash" should be run

  Scenario: Create a gist with multiple files
    Given the GitHub API server:
      """
      post('/gists') {
        halt 400 unless params[:files]["testfile.txt"]["content"]
        halt 400 unless params[:files]["testfile2.txt"]["content"]
        status 201
        json({
          :html_url => 'http://gists.github.com/somehash',
        })
      }
      """
    Given a file named "testfile.txt" with:
      """
      this is a test file
      """
    Given a file named "testfile2.txt" with:
      """
      this is another test file
      """
    When I successfully run `hub gist create testfile.txt testfile2.txt`
    Then the output should contain exactly:
      """
      http://gists.github.com/somehash
      """

  Scenario: Create a gist from stdin
    Given the GitHub API server:
      """
      post('/gists') {
        halt 400 unless params[:files]["gistfile1.txt"]["content"] == "hello\n"
        status 201
        json :html_url => 'http://gists.github.com/somehash'
      }
      """
    When I run `hub gist create` interactively
    And I pass in:
      """
      hello
      """
    Then the output should contain exactly:
      """
      http://gists.github.com/somehash
      """

  Scenario: Insufficient OAuth scopes
    Given the GitHub API server:
      """
      post('/gists') {
        status 404
        response.headers['x-oauth-scopes'] = 'repos'
        json({})
      }
      """
    Given a file named "testfile.txt" with:
{'fraction_non_alphanumeric': 0.11841785974278088, 'fraction_numerical': 0.008129094879883524, 'mean_word_length': 1.6893964110929853, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 48, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2319116', 'n_tokens_mistral': 2464, 'n_tokens_neox': 2395, 'n_words': 762}