Sha256: 23658946d4dcbb2464265be4f34067450e885df38ae63819c7a75e1fe18af0d2

Contents?: true

Size: 1.72 KB

Versions: 6

Compression:

Stored size: 1.72 KB

Contents

require File.expand_path('spec_helper', File.dirname(__FILE__))

module Ftpd
  describe CommandSequenceChecker do

    let(:sequence_error_verification) do
      lambda {|e| e.code == 503 && e.message == "Bad sequence of commands"}
    end
    subject(:checker) {CommandSequenceChecker.new}

    context 'initial' do

      it 'accepts any command' do
        checker.check 'NOOP'
      end

    end

    context 'when a specific command is expected' do
      
      before(:each) {checker.expect 'PASS'}

      it 'accepts that command' do
        checker.check 'PASS'
      end

      it 'rejects any other command' do
        expect {
          checker.check 'NOOP'
        }.to raise_error(FtpServerError, &sequence_error_verification)
      end

    end

    context 'after the expected command has arrived' do

      before(:each) do
        checker.expect 'PASS'
        checker.check 'PASS'
      end

      it 'accepts any other command' do
        checker.check 'NOOP'
      end

    end

    context 'after a command is rejected' do

      before(:each) do
        checker.expect 'PASS'
        expect {
          checker.check 'NOOP'
        }.to raise_error(FtpServerError, &sequence_error_verification)
      end

      it 'accepts any other command' do
        checker.check 'NOOP'
      end

    end

    context 'when a command must be expected' do

      before(:each) do
        checker.must_expect 'PASS'
      end

      it 'rejects that command if not expected' do
        expect {
          checker.check 'PASS'
        }.to raise_error(FtpServerError, &sequence_error_verification)
      end

      it 'accepts that command when it is accepted' do
        checker.expect 'PASS'
        checker.check 'PASS'
      end

    end

  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
ftpd-1.1.1 spec/command_sequence_checker_spec.rb
ftpd-1.1.0 spec/command_sequence_checker_spec.rb
investtools-ftpd-1.0.1 spec/command_sequence_checker_spec.rb
ftpd-1.0.1 spec/command_sequence_checker_spec.rb
ftpd-1.0.0 spec/command_sequence_checker_spec.rb
ftpd-0.17.0 spec/command_sequence_checker_spec.rb