Sha256: 28852a724a2866266ad9e97deca259f9b159e79bda8e1d536c722f6c15eeb9e6

Contents?: true

Size: 1.73 KB

Versions: 32

Compression:

Stored size: 1.73 KB

Contents

require 'spec_helper'

describe '#hincrbyfloat(key, field, increment)' do
  before do
    @key = 'mock-redis-test:hincrbyfloat'
    @field = 'count'
  end

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

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

  it 'creates a hash if nothing is present' do
    @redises.hincrbyfloat(@key, @field, 1.0)
    @redises.hget(@key, @field).should == '1'
  end

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

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

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

  it 'treats the field as a string' do
    field = 11
    @redises.hset(@key, field, 2)
    @redises.hincrbyfloat(@key, field, 2).should == 4.0
  end

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

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

  it_should_behave_like 'a hash-only command'
end

Version data entries

32 entries across 32 versions & 1 rubygems

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