<commit_before>require 'spec_helper'
require 'resolv'

describe Celluloid::Http::Proxy::HandlersProvider do
  it 'can raise exception on trying to get missing condition' do
    handlers_provider = Celluloid::Http::Proxy::HandlersProvider.register do
    end

    expect { handlers_provider.get_condition(:missing_condition) }.to raise_error
  end

  it 'can register custom condition' do
    handlers_provider = Celluloid::Http::Proxy::HandlersProvider.register do
      condition :custom_condition do 
        true
      end
    end

    handlers_provider.get_condition(:custom_condition).should be_a_kind_of Proc
  end

  it 'can register handler on custom condition' do
    request = Celluloid::Http::Proxy::Request.new( "http://localhost:8080/proxy/movies.json?movie_source_id=1" )

    handlers_provider = Celluloid::Http::Proxy::HandlersProvider.register do
      condition :custom_condition do |r|
        r.host == "localhost"
      end

      on :custom_condition do
        true
      end

      on :another_condition do
        true
      end
    end

    handlers = handlers_provider.get_handlers(:custom_condition, request)
    handlers.count.should eq 1 
    handlers.first[:condition].should eq :custom_condition
    handlers.first[:block].should be_a_kind_of Proc
  end
end
<commit_msg>Additional asserts added<commit_after>require 'spec_helper'
require 'resolv'

describe Celluloid::Http::Proxy::HandlersProvider do
  it 'can raise exception on trying to get missing condition' do
    handlers_provider = Celluloid::Http::Proxy::HandlersProvider.register do
    end

    expect { handlers_provider.get_condition(:missing_condition) }.to raise_error
  end

  it 'can register custom condition' do
    handlers_provider = Celluloid::Http::Proxy::HandlersProvider.register do
      condition :custom_condition do 
        true
      end
    end

    handlers_provider.get_condition(:custom_condition).should be_a_kind_of Proc
    handlers_provider.get_condition(:custom_condition).call.should eq true
  end

  it 'can register handler on custom condition' do
    request = Celluloid::Http::Proxy::Request.new( "http://localhost:8080/proxy/movies.json?movie_source_id=1" )

    handlers_provider = Celluloid::Http::Proxy::HandlersProvider.register do
      condition :custom_condition do |r|
        r.host == "localhost"
      end

      on :custom_condition do
        true
      end

      on :another_condition do
        true
      end
    end

    handlers = handlers_provider.get_handlers(:custom_condition, request)
    handlers.count.should eq 1 
    handlers.first[:condition].should eq :custom_condition
    handlers.first[:block].should be_a_kind_of Proc
    handlers.first[:block].call.should eq true
  end
end

{'fraction_non_alphanumeric': 0.08184143222506395, 'fraction_numerical': 0.004384362440628425, 'mean_word_length': 3.7617391304347825, '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': '6340153', 'n_tokens_mistral': 819, 'n_tokens_neox': 776, 'n_words': 192}