Sha256: 258259178a2e323561dc799d67a2e8eb78f3ebba1779bcfa26670459a51b2f1b

Contents?: true

Size: 1.98 KB

Versions: 4

Compression:

Stored size: 1.98 KB

Contents

describe Ppl::Command::Mutt do

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

    @address_book = Ppl::Entity::AddressBook.new
    @contact      = Ppl::Entity::Contact.new

    @command.storage = @storage
  end

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

  describe "#execute" do

    it "should raise an error if no query is given" do
      expect{@command.execute(@input, @output)}.to raise_error(Ppl::Error::IncorrectUsage)
    end

    it "should search the address book for the query" do
      @storage.should_receive(:load_address_book).and_return(@address_book)
      @input.arguments.push "query"
      @command.stub(:mutt_search) { |ab| [] }
      @output.should_receive(:line).with("No matches")
      @command.execute(@input, @output).should eq false
    end

    it "should return email address matches" do

      @contact.name = "Test User"
      @contact.email_addresses.push "test@example.org"
      @address_book.add_contact(@contact)

      @input.arguments.push "example"

      @storage.should_receive(:load_address_book).and_return(@address_book)
      @output.should_receive(:line).with("Searching database... 1 entries... 1 matching:")
      @output.should_receive(:line).with("test@example.org\tTest User")
      @command.execute(@input, @output).should eq true
    end

    it "should return name matches" do

      @contact.name = "Test User"
      @contact.email_addresses.push "test@example.org"
      @address_book.add_contact(@contact)

      @input.arguments.push "User"

      @storage.should_receive(:load_address_book).and_return(@address_book)
      @output.should_receive(:line).with("Searching database... 1 entries... 1 matching:")
      @output.should_receive(:line).with("test@example.org\tTest User")
      @command.execute(@input, @output).should eq true
    end


  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ppl-1.5.2 spec/ppl/command/mutt_spec.rb
ppl-1.5.1 spec/ppl/command/mutt_spec.rb
ppl-1.5.0 spec/ppl/command/mutt_spec.rb
ppl-1.4.1 spec/ppl/command/mutt_spec.rb