Sha256: 45f900c16527a0521b3723b6a72c1b1c8b1e959f24f48daf0eec6d02c10ff4b5

Contents?: true

Size: 1.75 KB

Versions: 1

Compression:

Stored size: 1.75 KB

Contents

require 'spec_helper'

describe Benches::Routine do
  describe 'initialize' do
    context 'no method arguments' do
      let(:bench) { Benches::Routine.new("test_string", 'split', 50000) }

      it 'assigns instance correctly' do
        expect(bench.instance_variable_get('@instance')).to eql 'test_string'
      end

      it 'assigns method correctly' do
        expect(bench.instance_variable_get('@method')).to eql 'split'
      end

      it 'assigns repetitions correctly' do
        expect(bench.instance_variable_get('@repetitions')).to eql 50000
      end

      it 'sets args to empty array' do
        expect(bench.instance_variable_get('@args')).to eql []
      end
    end

    context 'method has arguments' do
      let(:bench) { Benches::Routine.new("test_string", 'insert', 50000, 1, 'a') }

      it 'assigns instance correctly' do
        expect(bench.instance_variable_get('@instance')).to eql 'test_string'
      end

      it 'assigns method correctly' do
        expect(bench.instance_variable_get('@method')).to eql 'insert'
      end

      it 'assigns repetitions correctly' do
        expect(bench.instance_variable_get('@repetitions')).to eql 50000
      end

      it' assigns args correctly' do
        expect(bench.instance_variable_get('@args')).to eql [1, 'a']
      end
    end
  end

  describe 'call' do
    context 'no method arguments' do
      let(:bench) { Benches::Routine.new("test_string", 'split', 20) }

      it 'performs benchmark' do
        expect(bench.call.first).to be_a Benchmark::Tms
      end
    end

    context 'method has arguments' do
      let(:bench) { Benches::Routine.new("test_string", 'insert', 20, 1, 'a') }

      it 'performs benchmark' do
        expect(bench.call.first).to be_a Benchmark::Tms
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
benches-0.1.0 spec/routine_spec.rb