Sha256: 41a7faa78aab013717b22a4b8db69c8740e45575a837d74943ae34ca9049e9fe

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
      @input.arguments.push "query"
      @command.should_receive(:mutt_search).and_return([])
      @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) do |line|
        line.should include "Searching address book... 1 entries... 1 matching:"
        line.should include "test@example.org\tTest User"
      end
      @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) do |line|
        line.should include "Searching address book... 1 entries... 1 matching:"
        line.should include "test@example.org\tTest User"
      end
      @command.execute(@input, @output).should eq true
    end


  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ppl-1.8.0 spec/ppl/command/mutt_spec.rb
ppl-1.7.0 spec/ppl/command/mutt_spec.rb
ppl-1.6.0 spec/ppl/command/mutt_spec.rb
ppl-1.5.3 spec/ppl/command/mutt_spec.rb