Sha256: d376ec220343d1c7252da30ade301116468fe78ff9e7e4a6997b779812a5867a

Contents?: true

Size: 1.29 KB

Versions: 32

Compression:

Stored size: 1.29 KB

Contents

require 'spec_helper'

describe '#incrbyfloat(key, increment)' do
  before { @key = 'mock-redis-test:65374' }

  it 'returns the value after the increment' do
    @redises.set(@key, 2.0)
    @redises.incrbyfloat(@key, 2.1).should be_within(0.0001).of(4.1)
  end

  it 'treats a missing key like 0' do
    @redises.incrbyfloat(@key, 1.2).should be_within(0.0001).of(1.2)
  end

  it 'increments negative numbers' do
    @redises.set(@key, -10.4)
    @redises.incrbyfloat(@key, 2.3).should be_within(0.0001).of(-8.1)
  end

  it 'works multiple times' do
    @redises.incrbyfloat(@key, 2.1).should be_within(0.0001).of(2.1)
    @redises.incrbyfloat(@key, 2.2).should be_within(0.0001).of(4.3)
    @redises.incrbyfloat(@key, 2.3).should be_within(0.0001).of(6.6)
  end

  it 'accepts an float-ish string' do
    @redises.incrbyfloat(@key, '2.2').should be_within(0.0001).of(2.2)
  end

  it 'raises an error if the value does not look like an float' do
    @redises.set(@key, 'one.two')
    lambda do
      @redises.incrbyfloat(@key, 1)
    end.should raise_error(Redis::CommandError)
  end

  it 'raises an error if the delta does not look like an float' do
    lambda do
      @redises.incrbyfloat(@key, 'foobar.baz')
    end.should raise_error(Redis::CommandError)
  end

  it_should_behave_like 'a string-only command'
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
mock_redis-0.36.0 spec/commands/incrbyfloat_spec.rb
mock_redis-0.35.0 spec/commands/incrbyfloat_spec.rb
mock_redis-0.34.0 spec/commands/incrbyfloat_spec.rb
mock_redis-0.33.0 spec/commands/incrbyfloat_spec.rb
mock_redis-0.32.0 spec/commands/incrbyfloat_spec.rb
mock_redis-0.31.0 spec/commands/incrbyfloat_spec.rb
mock_redis-0.30.0 spec/commands/incrbyfloat_spec.rb
mock_redis-0.29.0 spec/commands/incrbyfloat_spec.rb
mock_redis-0.28.0 spec/commands/incrbyfloat_spec.rb
mock_redis-0.27.3 spec/commands/incrbyfloat_spec.rb
mock_redis-0.27.2 spec/commands/incrbyfloat_spec.rb
mock_redis-0.27.1 spec/commands/incrbyfloat_spec.rb
mock_redis-0.27.0 spec/commands/incrbyfloat_spec.rb
mock_redis-0.26.0 spec/commands/incrbyfloat_spec.rb
mock_redis-0.25.0 spec/commands/incrbyfloat_spec.rb
mock_redis-0.24.0 spec/commands/incrbyfloat_spec.rb
mock_redis-0.23.0 spec/commands/incrbyfloat_spec.rb
mock_redis-0.22.0 spec/commands/incrbyfloat_spec.rb
mock_redis-0.21.0 spec/commands/incrbyfloat_spec.rb
mock_redis-0.20.0 spec/commands/incrbyfloat_spec.rb