Sha256: 20bc6fa259e26ac206ebb6d05fbc37bd4252cf397e24d91f08948fd733541273

Contents?: true

Size: 1.89 KB

Versions: 5

Compression:

Stored size: 1.89 KB

Contents

require 'webmock/rspec'
require 'rspec/expectations'
require 'rspec/mocks'

require 'webrick'

describe "bugsnag capistrano", :always do

  server = nil
  queue = Queue.new
  cap_2 = ENV['CAP_2_TEST'] == 'true'
  fixture_path = cap_2 ? '../examples/capistrano2' : '../examples/capistrano3'
  exec_string = cap_2 ? 'bundle exec cap deploy' : 'bundle exec cap test deploy'
  example_path = File.join(File.dirname(__FILE__), fixture_path)

  before do
    server = WEBrick::HTTPServer.new :Port => 0, :Logger => WEBrick::Log.new(STDOUT), :AccessLog => []
    server.mount_proc '/deploy' do |req, res|
      queue.push req.body
      res.status = 200
      res.body = "OK\n"
    end
    Thread.new{ server.start }
  end

  after do
    server.stop
    queue.clear
  end

  let(:request) { JSON.parse(queue.pop) }
  
  it "sends a deploy notification to the set endpoint" do
    ENV['BUGSNAG_ENDPOINT'] = "http://localhost:" + server.config[:Port].to_s + "/deploy"
    
    Dir.chdir(example_path) do
      system(exec_string)
    end

    payload = request()
    expect(payload["apiKey"]).to eq('YOUR_API_KEY')
    expect(payload["releaseStage"]).to eq('production')
  end

  it "allows modifications of deployment characteristics" do
    ENV['BUGSNAG_ENDPOINT'] = "http://localhost:" + server.config[:Port].to_s + "/deploy"
    ENV['BUGSNAG_API_KEY'] = "this is a test key"
    ENV['BUGSNAG_RELEASE_STAGE'] = "test"
    ENV['BUGSNAG_REVISION'] = "test"
    ENV['BUGSNAG_APP_VERSION'] = "1"
    ENV['BUGSNAG_REPOSITORY'] = "test@repo.com:test/test_repo.git"

    Dir.chdir(example_path) do
      system(exec_string)
    end

    payload = request()
    expect(payload["apiKey"]).to eq('this is a test key')
    expect(payload["releaseStage"]).to eq('test')
    expect(payload["repository"]).to eq("test@repo.com:test/test_repo.git")
    expect(payload["appVersion"]).to eq("1")
    expect(payload["revision"]).to eq("test")
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
bugsnag-capistrano-1.1.2 spec/capistrano_spec.rb
bugsnag-capistrano-1.1.1 spec/capistrano_spec.rb
bugsnag-capistrano-1.1.0 spec/capistrano_spec.rb
bugsnag-capistrano-1.0.1 spec/capistrano_spec.rb
bugsnag-capistrano-1.0.0 spec/capistrano_spec.rb