Sha256: c79eb8556a3bdb20faa9daf6a0b7ef07371afa36a33c0f9ce18979d3c2cdbfa0

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

require 'assert'
require 'hella-redis/connection_spy'

class HellaRedis::ConnectionSpy

  class UnitTests < Assert::Context
    desc "HellaRedis::ConnectionSpy"
    setup do
      @connection_spy = HellaRedis::ConnectionSpy.new(Factory.config)
    end
    subject{ @connection_spy }

    should have_accessors :calls
    should have_imeths :pipelined, :multi

    should "default its calls" do
      assert_equal [], subject.calls
    end

    should "track redis calls made to it" do
      assert_true subject.respond_to?(:set)

      key, value = [Factory.string, Factory.string]
      subject.set(key, value)

      call = subject.calls.first
      assert_equal :set, call.command
      assert_equal [key, value], call.args
    end

    should "track the call and yield itself using `pipelined`" do
      subject.pipelined{ |c| c.set(Factory.string, Factory.string) }
      assert_equal [:pipelined, :set], subject.calls.map(&:command)
    end

    should "track the call and yield itself using `multi`" do
      subject.multi{ |c| c.set(Factory.string, Factory.string) }
      assert_equal [:multi, :set], subject.calls.map(&:command)
    end

    should "raise no method errors for non-redis methods" do
      assert_false subject.respond_to?(:super_awesome_set)
      assert_raises(NoMethodError) do
        subject.super_awesome_set(Factory.string, Factory.string)
      end
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hella-redis-0.4.0 test/unit/connection_spy_tests.rb