require "bugsnag/api" require "webmock/rspec" require "faker" require "vcr" require "uri" require "json" require "sawyer" # 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 RSpec.configure do |config| config.expect_with :rspec do |c| c.syntax = :expect end end # VCR VCR.configure do |c| c.cassette_library_dir = "spec/cassettes" c.hook_into :webmock c.configure_rspec_metadata! USER_AGENT_REGEX = /\ABugsnag API Ruby Gem \d+\.\d+\.\d+\z/ HEADERS_SET_BY_BUGSNAG = ["Content-Type", "X-Version", "X-Bugsnag-Api", "Authorization"] user_agent_valid = lambda do |values| return false if values.length != 1 values.first.match(USER_AGENT_REGEX) end header_matcher = lambda do |request_a, request_b| return false unless user_agent_valid.(request_a.headers["User-Agent"]) return false unless user_agent_valid.(request_b.headers["User-Agent"]) HEADERS_SET_BY_BUGSNAG.all? do |header| request_a.headers[header] == request_b.headers[header] end end c.default_cassette_options = { :record => ENV['CI'] ? :none : :once, :match_requests_on => [:method, :path, header_matcher] } c.filter_sensitive_data("https://api.bugsnag.com") { test_bugsnag_endpoint } c.filter_sensitive_data("api.bugsnag.com") { URI.parse(Bugsnag::Api.configuration.endpoint).host } c.filter_sensitive_data("BUGSNAG_AUTH_TOKEN") { test_bugsnag_auth_token } c.filter_sensitive_data("BUGSNAG_LOGIN") { CGI::escape(test_bugsnag_email) } c.filter_sensitive_data("BUGSNAG_USER_EMAIL") { test_bugsnag_email } c.filter_sensitive_data("BUGSNAG_PASSWORD") { test_bugsnag_password } c.filter_sensitive_data("BUGSNAG_ORG_ID") { test_bugsnag_org_id } c.filter_sensitive_data("BUGSNAG_PROJECT_ID") { test_bugsnag_project_id } c.filter_sensitive_data("BUGSNAG_COLLABORATOR_EMAIL") { test_bugsnag_collaborator } c.filter_sensitive_data("BUGSNAG_ERROR_ID") { test_bugsnag_error_id } c.filter_sensitive_data("BUGSNAG_EVENT_ID") { test_bugsnag_event_id } c.filter_sensitive_data("BUGSNAG_RELEASE_ID") { test_bugsnag_release_id } c.filter_sensitive_data("BUGSNAG_RELEASE_GROUP_ID") { test_bugsnag_release_group_id } end def auth_token_client Bugsnag::Api.configure do |config| config.endpoint = test_bugsnag_endpoint end Bugsnag::Api::Client.new do |config| config.endpoint = test_bugsnag_endpoint config.auth_token = test_bugsnag_auth_token end end def basic_auth_client Bugsnag::Api.configure do |config| config.endpoint = test_bugsnag_endpoint end Bugsnag::Api::Client.new do |config| config.endpoint = test_bugsnag_endpoint config.email = test_bugsnag_email config.password = test_bugsnag_password end end def bugsnag_url(path) URI.join(test_bugsnag_endpoint, path).to_s end def basic_bugsnag_url(path, options = {}) url = File.join(test_bugsnag_endpoint, path) uri = Addressable::URI.parse(url) uri.user = options.fetch(:login, test_bugsnag_email) uri.password = options.fetch(:password, test_bugsnag_password) uri.to_s end def stub_get(url) stub_request(:get, bugsnag_url(url)) end def test_bugsnag_endpoint ENV["BUGSNAG_TEST_ENDPOINT"] || Bugsnag::Api::Configuration::DEFAULT_ENDPOINT end def test_bugsnag_auth_token ENV["BUGSNAG_TEST_AUTH_TOKEN"] || "BUGSNAG_AUTH_TOKEN" end def test_bugsnag_email ENV["BUGSNAG_TEST_EMAIL"] || "BUGSNAG_USER_EMAIL" end def test_bugsnag_password ENV["BUGSNAG_TEST_PASSWORD"] || "BUGSNAG_PASSWORD" end def test_bugsnag_org_id ENV["BUGSNAG_TEST_ORG_ID"] || "BUGSNAG_ORG_ID" end def test_bugsnag_project_id ENV["BUGSNAG_PROJECT_ID"] || "BUGSNAG_PROJECT_ID" end def test_bugsnag_error_id ENV["BUGSNAG_TEST_ERROR"] || "BUGSNAG_ERROR_ID" end def test_bugsnag_eventfield_id ENV["BUGSNAG_TEST_EVENTFIELD"] || "BUGSNAG_EVENTFIELD_ID" end def test_bugsnag_event_id ENV["BUGSNAG_TEST_EVENT"] || "BUGSNAG_EVENT_ID" end def test_bugsnag_collaborator ENV["BUGSNAG_TEST_COLLABORATOR_EMAIL"] || "BUGSNAG_COLLABORATOR_EMAIL" end def test_bugsnag_release_id ENV["BUGSNAG_TEST_RELEASE_ID"] || "BUGSNAG_RELEASE_ID" end def test_bugsnag_release_group_id ENV["BUGSNAG_TEST_RELEASE_GROUP_ID"] || "BUGSNAG_RELEASE_GROUP_ID" end