<commit_before>require 'spec_helper'

describe Beaker::Session do
  before { Beaker.base_url = beaker_base_url }

  describe '#participate' do
    let(:user_id) { 123 }
    let(:ab_test) { :sign_up }

    subject { Beaker::Session.new user_id }

    context 'When beaker server successfully respond' do
      before do
        stub_request(:get, experiment_url(ab_test, user_id))
          .to_return body: response
      end

      let(:response) { { alternative: 'green' }.to_json }

      it { expect(subject.participate(ab_test)).to eq 'green' }

      it {
        expect { |b| subject.participate(ab_test, &b) }
          .to yield_with_args 'green'
      }
    end

    context 'When beaker server respond invalid payload' do
      before do
        stub_request(:get, experiment_url(ab_test, user_id))
          .to_return body: response
      end

      let(:response) { { bad_body: 'green' }.to_json }

      it { expect(subject.participate(ab_test)).to be_nil }

      it {
        expect { |b| subject.participate(ab_test, &b) }
          .to yield_with_args nil
      }
    end

    context 'When beaker server not responding 200' do
      before do
        stub_request(:get, experiment_url(ab_test, user_id))
          .to_return status: [500, 'Internal Server Error']
      end<commit_msg>Fix some grammar issue<commit_after>require 'spec_helper'

describe Beaker::Session do
  before { Beaker.base_url = beaker_base_url }

  describe '#participate' do
    let(:user_id) { 123 }
    let(:ab_test) { :sign_up }

    subject { Beaker::Session.new user_id }

    context 'When beaker server successfully responds' do
      before do
        stub_request(:get, experiment_url(ab_test, user_id))
          .to_return body: response
      end

      let(:response) { { alternative: 'green' }.to_json }

      it { expect(subject.participate(ab_test)).to eq 'green' }

      it {
        expect { |b| subject.participate(ab_test, &b) }
          .to yield_with_args 'green'
      }
    end

    context 'When beaker server responds invalid payload' do
      before do
        stub_request(:get, experiment_url(ab_test, user_id))
          .to_return body: response
      end

      let(:response) { { bad_body: 'green' }.to_json }

      it { expect(subject.participate(ab_test)).to be_nil }

      it {
        expect { |b| subject.participate(ab_test, &b) }
          .to yield_with_args nil
      }
    end

    context 'When beaker server responds error status' do
      before do
        stub_request(:get, experiment_url(ab_test, user_id))
          .to_return status: [500, 'Internal Server Error']
      end
{'fraction_non_alphanumeric': 0.10213414634146341, 'fraction_numerical': 0.005716463414634146, 'mean_word_length': 2.5569105691056913, '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': '191372', 'n_tokens_mistral': 861, 'n_tokens_neox': 815, 'n_words': 210}