require 'rack/test'
require 'rspec/its'
require 'webmock/rspec'
include Rack::Test::Methods

# This file was generated by the `rspec --init` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# Require this file using `require "spec_helper"` to ensure that it is only
# loaded once.
#
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration

def app
  Sinatra::Application
end

RSpec.configure do |config|
  config.run_all_when_everything_filtered = true
  config.filter_run :focus

  config.order = 'random'
end

WebMock.disable_net_connect!(:allow_localhost => true)

def payload
  JSON.parse(GITHUB_JSON)
end

SETTINGS_YAML = <<-eof
---
applications:
  - name: github
    path: /home/deployer/github
    git: git@github.com:defunkt/github
    chat_integration: SlackIntegration
    api_token: 182efbfc0aceda25182c8d982a2e1dfd
    url: http://%{branch}.staging.github.com
    git_provider: github
eof

GITHUB_JSON = <<-GITHUB_JSON
  {
    "before": "5aef35982fb2d34e9d9d4502f6ede1072793222d",
    "repository": {
      "url": "http://github.com/defunkt/github",
      "name": "github",
      "owner": {
        "email": "chris@ozmm.org",
        "name": "defunkt"
      }
    },
    "commits": {
      "41a212ee83ca127e3c8cf465891ab7216a705f59": {
        "url": "http://github.com/defunkt/github/commit/41a212ee83ca127e3c8cf465891ab7216a705f59",
        "author": {
          "email": "chris@ozmm.org",
          "name": "Chris Wanstrath"
        },
        "message": "okay i give in",
        "timestamp": "2008-02-15T14:57:17-08:00"
      },
      "de8251ff97ee194a289832576287d6f8ad74e3d0": {
        "url": "http://github.com/defunkt/github/commit/de8251ff97ee194a289832576287d6f8ad74e3d0",
        "author": {
          "email": "chris@ozmm.org",
          "name": "Chris Wanstrath"
        },
        "message": "update pricing a tad",
        "timestamp": "2008-02-15T14:36:34-08:00"
      }
    },
    "after": "de8251ff97ee194a289832576287d6f8ad74e3d0",
    "ref": "refs/heads/features/awesome-feature"
  }
GITHUB_JSON

BITBUCKET_JSON = <<-eof
{
  "canon_url": "https://bitbucket.org",
  "commits": [
    {
      "author": "marcus",
      "branch": null,
      "files": [
        {
          "file": "somefile.py",
          "type": "modified"
        }
      ],
      "message": "Added some more things to somefile.py",
      "node": "620ade18607a",
      "parents": [
        "702c70160afc"
      ],
      "raw_author": "Marcus Bertrand <marcus@somedomain.com>",
      "raw_node": "620ade18607ac42d872b568bb92acaa9a28620e9",
      "revision": null,
      "size": -1,
      "timestamp": "2012-05-30 05:58:56",
      "utctimestamp": "2012-05-30 03:58:56+00:00"
    },
    {
      "author": "marcus",
      "branch": "master",
      "files": [
        {
          "file": "somefile.py",
          "type": "modified"
        }
      ],
      "message": "Added some more things to somefile.py",
      "node": "620ade18607a",
      "parents": [
        "702c70160afc"
      ],
      "raw_author": "Marcus Bertrand <marcus@somedomain.com>",
      "raw_node": "620ade18607ac42d872b568bb92acaa9a28620e9",
      "revision": null,
      "size": -1,
      "timestamp": "2012-05-30 05:58:56",
      "utctimestamp": "2012-05-30 03:58:56+00:00"
    }
  ],
  "repository": {
    "absolute_url": "/marcus/project-x/",
    "fork": false,
    "is_private": true,
    "name": "Project X",
    "owner": "marcus",
    "scm": "git",
    "slug": "project-x",
    "website": "https://atlassian.com/"
  },
  "user": "marcus"
}
eof
