Sha256: f862c7510a0b0550246fc1be2e9638366f41c3be44e327e0bc695966136d31d2

Contents?: true

Size: 1.83 KB

Versions: 1

Compression:

Stored size: 1.83 KB

Contents

require "spec_helper"

describe Moped::Protocol::Command do

  describe "#failure?" do

    let(:command) do
      described_class.new(:moped, ismaster: 1)
    end

    let(:reply) do
      Moped::Protocol::Reply.new
    end

    context "when the reply is a command failure" do

      before do
        reply.documents = [{ "ok" => 0.0 }]
      end

      it "returns true" do
        expect(command).to be_failure(reply)
      end
    end

    context "when the reply is not a command failure" do

      before do
        reply.documents = [{ "ok" => 1.0 }]
      end

      it "returns true" do
        expect(command).to_not be_failure(reply)
      end
    end
  end

  describe "#failure_exception" do

    let(:command) do
      described_class.new(:moped, ismaster: 1)
    end

    let(:reply) do
      Moped::Protocol::Reply.new.tap do |message|
        message.documents = [{}]
      end
    end

    let(:exception) do
      command.failure_exception(reply)
    end

    it "returns a query failure" do
      expect(exception).to be_a(Moped::Errors::OperationFailure)
    end
  end

  describe "#initialize" do

    let(:command) do
      described_class.new(:moped, ismaster: 1)
    end

    it "sets the query's full collection name" do
      expect(command.full_collection_name).to eq("moped.$cmd")
    end

    it "sets the query's selector to the command provided" do
      expect(command.selector).to eq(ismaster: 1)
    end

    it "sets the query's limit to -1" do
      expect(command.limit).to eq(-1)
    end
  end

  describe "#results" do

    let(:command) do
      described_class.new(:moped, ismaster: 1)
    end

    let(:reply) do
      Moped::Protocol::Reply.new.tap do |message|
        message.documents = [{}]
      end
    end

    it "returns the first document in the reply" do
      expect(command.results(reply)).to be_empty
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/bundler/gems/moped-cf817ca58a85/spec/moped/protocol/command_spec.rb