Sha256: f4e20bea8ba3e2cd5eb98e8161b32b7b78e04c4071fe26e1e5e693d455818d9c

Contents?: true

Size: 1.7 KB

Versions: 52

Compression:

Stored size: 1.7 KB

Contents

describe Ppl::Command::Mv do

  before(:each) do
    @command = Ppl::Command::Mv.new
    @input   = Ppl::Application::Input.new
    @output  = double(Ppl::Application::Output)
    @contact = Ppl::Entity::Contact.new
    @storage = double(Ppl::Adapter::Storage)

    @command.storage = @storage
    @contact.id = "old"
  end

  describe "#name" do
    it "should be 'mv'" do
      @command.name.should eq "mv"
    end
  end

  describe "#execute" do

    it "should raise an error if no contact is specified" do
      @input.arguments = []
      expect{@command.execute(@input, @output)}.to raise_error(Ppl::Error::IncorrectUsage)
    end

    it "should raise an error if no new ID is specified" do
      @input.arguments = ["test", nil]
      expect{@command.execute(@input, @output)}.to raise_error(Ppl::Error::IncorrectUsage)
    end

    it "should return false if the new id is taken" do
      @storage.should_receive(:require_contact).with("old").and_return(@contact)
      @storage.should_receive(:load_contact).with("new").and_return(@contact)
      @output.should_receive(:error)
      @input.arguments = ["old", "new"]

      @command.execute(@input, @output).should eq false
    end

    it "should rename the given contact" do
      @storage.should_receive(:require_contact).with("old").and_return(@contact)
      @storage.should_receive(:load_contact).with("new").and_return(nil)

      @storage.should_receive(:delete_contact).with(@contact) do |contact|
        contact.id.should eq "old"
      end

      @storage.should_receive(:save_contact).with(@contact) do |contact|
        contact.id.should eq "new"
      end

      @input.arguments = ["old", "new"]

      @command.execute(@input, @output)
    end

  end

end

Version data entries

52 entries across 52 versions & 1 rubygems

Version Path
ppl-1.18.0 spec/ppl/command/mv_spec.rb
ppl-1.17.2 spec/ppl/command/mv_spec.rb
ppl-1.17.1 spec/ppl/command/mv_spec.rb
ppl-1.17.0 spec/ppl/command/mv_spec.rb
ppl-1.16.0 spec/ppl/command/mv_spec.rb
ppl-1.15.1 spec/ppl/command/mv_spec.rb
ppl-1.15.0 spec/ppl/command/mv_spec.rb
ppl-1.14.1 spec/ppl/command/mv_spec.rb
ppl-1.14.0 spec/ppl/command/mv_spec.rb
ppl-1.13.0 spec/ppl/command/mv_spec.rb
ppl-1.12.0 spec/ppl/command/mv_spec.rb
ppl-1.11.0 spec/ppl/command/mv_spec.rb
ppl-1.10.0 spec/ppl/command/mv_spec.rb
ppl-1.9.0 spec/ppl/command/mv_spec.rb
ppl-1.8.0 spec/ppl/command/mv_spec.rb
ppl-1.7.0 spec/ppl/command/mv_spec.rb
ppl-1.6.0 spec/ppl/command/mv_spec.rb
ppl-1.5.3 spec/ppl/command/mv_spec.rb
ppl-1.5.2 spec/ppl/command/mv_spec.rb
ppl-1.5.1 spec/ppl/command/mv_spec.rb