<commit_before>require_relative 'spec_helper'

module RUPNP

  describe Event do
    include EM::SpecHelper

    let(:host) { '192.168.3.11:45678' }
    let(:location) { "#{host}/event_subscription" }
    let(:ev_suburl) { "http://#{location}" }
    let(:sid) { "uuid:#{UUID.generate}" }
    let(:options) { { :auto_renew => true, :before_timeout => 1 } }
    let(:ev) { Event.new(ev_suburl, '', sid, 2, options)}

    it 'should send timeout message' do
      em do
        ev = Event.new('', '', '', 1, :auto_renew => false,
                       :before_timeout => 0)
        ev.subscribe do |msg|
          expect(msg).to eq(:timeout)
          done
        end
      end
    end

    it 'should renew subscription on demand' do
      em do
        stub_request(:subscribe, location).
          with(:headers => { 'HOST' => host, 'SID' => sid,
               'TIMEOUT' => "Second-#{ev.timeout}"}).
          to_return(:status => 200,
                    :headers => {
                      'SERVER' => 'OS/1.0 UPnP/1.1 TEST/1.0',
                      'SID' => sid,
                      'TIMEOUT' => 'Second-1800'
                    })
        ev.renew_subscription
        ev.subscribe do |msg|
          expect(msg).to eq(:renewed)
          expect(ev.timeout).to eq(1800)
          done
        end
      end
    end

    it 'should automatically renew subscription' do
      em do
        stub_request(:subscribe, location).
          with(:headers => { 'HOST' => host, 'SID' => sid,
               'TIMEOUT' => "Second-#{ev.timeout}"}).
          to_return(:status => 200,
                    :headers => {
                      'SERVER' => 'OS/1.0 UPnP/1.1 TEST/1.0',
                      'SID' => sid,
                      'TIMEOUT' => 'Second-1800'
                    })

        ev.subscribe do |msg|
          expect(msg).to eq(:renewed)
          expect(ev.timeout).to eq(1800)
          done
        end
      end
    end

    it 'should cancel subscription'
  end

end
<commit_msg>Write 'Event should cancel subscription' spec.<commit_after>require_relative 'spec_helper'

module RUPNP

  describe Event do
    include EM::SpecHelper

    let(:host) { '192.168.3.11:45678' }
    let(:location) { "#{host}/event_subscription" }
    let(:ev_suburl) { "http://#{location}" }
    let(:sid) { "uuid:#{UUID.generate}" }
    let(:options) { { :auto_renew => true, :before_timeout => 1 } }
    let(:ev) { Event.new(ev_suburl, '', sid, 2, options)}

    it 'should send timeout message' do
      em do
        ev = Event.new('', '', '', 1, :auto_renew => false,
                       :before_timeout => 0)
        ev.subscribe do |msg|
          expect(msg).to eq(:timeout)
          done
        end
      end
    end

    it 'should renew subscription on demand' do
      em do
        stub_request(:subscribe, location).
          with(:headers => { 'HOST' => host, 'SID' => sid,
               'TIMEOUT' => "Second-#{ev.timeout}"}).
          to_return(:status => 200,
                    :headers => {
                      'SERVER' => 'OS/1.0 UPnP/1.1 TEST/1.0',
                      'SID' => sid,
                      'TIMEOUT' => 'Second-1800'
                    })
        ev.renew_subscription
        ev.subscribe do |msg|
          expect(msg).to eq(:renewed)
          expect(ev.timeout).to eq(1800)
          done
        end
      end
    end

    it 'should automatically renew subscription' do
      em do
        stub_request(:subscribe, location).
          with(:headers => { 'HOST' => host, 'SID' => sid,
               'TIMEOUT' => "Second-#{ev.timeout}"}).
          to_return(:status => 200,
                    :headers => {
                      'SERVER' => 'OS/1.0 UPnP/1.1 TEST/1.0',
                      'SID' => sid,
                      'TIMEOUT' => 'Second-1800'
                    })

        ev.subscribe do |msg|
          expect(msg).to eq(:renewed)
          expect(ev.timeout).to eq(1800)
          done
        end
      end
    end

    it 'should cancel subscription' do
      em do
        stub_request(:unsubscribe, location).
          with(:headers => { 'HOST' => host, 'SID' => sid }).
          to_return(:status => 200)
        ev.cancel_subscription
        ev.subscribe do |msg|
          expect(msg).to eq(:cancelled)
          done
        end
      end
    end
  end

end

{'fraction_non_alphanumeric': 0.14312011044638748, 'fraction_numerical': 0.02462034054302807, 'mean_word_length': 1.5332167832167831, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '3054177', 'n_tokens_mistral': 1374, 'n_tokens_neox': 1279, 'n_words': 301}