<commit_before>require 'spec_helper'
require 'fileutils'

describe "extension loading and operation" do
  describe ".agent_config" do
    subject { Appsignal::Extension.agent_config }

    it { should have_key('version') }
    it { should have_key('triples') }
  end

  describe ".agent_version" do
    subject { Appsignal::Extension.agent_version }

    it { should_not be_nil }
  end

  context "when the extension library can be loaded" do
    subject { Appsignal::Extension }

    it "should indicate that the extension is loaded" do
      Appsignal.extension_loaded?.should be_true
    end

    it "should have a start and stop method" do
      subject.start
      subject.stop
    end

    context "with a valid config" do
      before do
        project_fixture_config.write_to_environment
      end

      it "should have a start and stop method" do
        subject.start
        subject.stop
      end

      it "should have a start_transaction method" do
        subject.start_transaction('request_id', 'http_request')
      end

      it "should have a start_event method" do
        subject.start_event(1)
      end

      it "should have a finish_event method" do
        subject.finish_event(1, 'name', 'title', 'body', 0)
      end

      it "should have a set_transaction_error method" do
        subject.set_transaction_error(1, 'name', 'message', '[backtrace]')
      end

      it "should have a set_transaction_sample_data method" do
        subject.set_transaction_sample_data(1, 'params', '{}')
      end

      it "should have a set_transaction_action method" do
        subject.set_transaction_action(1, 'value')
      end

      it "should have a set_transaction_queue_start method" do
        subject.set_transaction_queue_start(1, 10)
      end

      it "should have a set_transaction_metadata method" do
        subject.set_transaction_metadata(1, 'key', 'value')
      end

      it "should have a finish_transaction method" do
        subject.finish_transaction(1)
      end

      it "should have a set_gauge method" do
        subject.set_gauge('key', 1.0)
      end

      it "should have a increment_counter method" do
        subject.increment_counter('key', 1)
      end

      it "should have a add_distribution_value method" do
        subject.add_distribution_value('key', 1.0)
      end
    end
  end

  context "when the extension library cannot be loaded" do
    subject { Appsignal::Extension }

    before :all do
      Appsignal.extension_loaded = false<commit_msg>Make extension spec test new style api<commit_after>require 'spec_helper'
require 'fileutils'

describe "extension loading and operation" do
  describe ".agent_config" do
    subject { Appsignal::Extension.agent_config }

    it { should have_key('version') }
    it { should have_key('triples') }
  end

  describe ".agent_version" do
    subject { Appsignal::Extension.agent_version }

    it { should_not be_nil }
  end

  context "when the extension library can be loaded" do
    subject { Appsignal::Extension }

    it "should indicate that the extension is loaded" do
      Appsignal.extension_loaded?.should be_true
    end

    it "should have a start and stop method" do
      subject.start
      subject.stop
    end

    context "with a valid config" do
      before do
        project_fixture_config.write_to_environment
      end

      it "should have a start and stop method" do
        subject.start
        subject.stop
      end

      context "with a transaction" do
        subject { Appsignal::Extension.start_transaction('request_id', 'http_request') }

        it "should have a start_event method" do
          subject.start_event
        end

        it "should have a finish_event method" do
          subject.finish_event('name', 'title', 'body', 0)
        end

        it "should have a set_error method" do
          subject.set_error('name', 'message', '[backtrace]')
        end

        it "should have a set_sample_data method" do
          subject.set_sample_data('params', '{}')
        end

        it "should have a set_action method" do
          subject.set_action('value')
        end

        it "should have a set_queue_start method" do
          subject.set_queue_start(10)
        end

        it "should have a set_metadata method" do
          subject.set_metadata('key', 'value')
        end

        it "should have a finish method" do
          subject.finish
        end

        it "should have a complete method" do
          subject.complete
        end
      end

      it "should have a set_gauge method" do
        subject.set_gauge('key', 1.0)
      end

      it "should have a increment_counter method" do
        subject.increment_counter('key', 1)
      end

      it "should have a add_distribution_value method" do
        subject.add_distribution_value('key', 1.0)
      end
    end
  end

  context "when the extension library cannot be loaded" do
    subject { Appsignal::Extension }

    before :all do
      Appsignal.extension_loaded = false
{'fraction_non_alphanumeric': 0.07306390603225164, 'fraction_numerical': 0.004778021102926538, 'mean_word_length': 2.4913134120917304, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4875207', 'n_tokens_mistral': 1437, 'n_tokens_neox': 1370, 'n_words': 469}