Sha256: 83c31b929c223356cbe9f54d41b6d729892ff7b21ae5816f7df66689a4e072ac

Contents?: true

Size: 1.5 KB

Versions: 1

Compression:

Stored size: 1.5 KB

Contents

require 'spec_helper'
require 'markdo/commands/add_command'

module Markdo
  describe AddCommand do
    before do
      skip 'Could not access fixtures' unless File.exists?('spec/fixtures/')
    end

    it 'appends to the inbox' do
      clear_inbox
      markdo_add 'Example task'
      expect(read_inbox).to eq([
        '- [ ] Example task',
      ])
      markdo_add 'Another example task'
      expect(read_inbox).to eq([
        '- [ ] Example task',
        '- [ ] Another example task',
      ])
    end

    describe 'given a nil' do
      it 'appends to the inbox' do
        clear_inbox
        markdo_add nil
        assert_inbox_empty
      end
    end

    describe 'given an empty string' do
      it 'appends to the inbox' do
        clear_inbox
        markdo_add ''
        assert_inbox_empty
      end
    end

    describe 'given a blank string' do
      it 'appends to the inbox' do
        clear_inbox
        markdo_add ' '
        assert_inbox_empty
      end
    end

    def clear_inbox
      File.write('spec/fixtures/add_command/Inbox.md', '')
    end

    def read_inbox
      File.
        readlines('spec/fixtures/add_command/Inbox.md').
        map { |line| line.chomp }
    end

    def markdo_add(task_body)
      command_support = build_command_support({
        'MARKDO_ROOT' => 'spec/fixtures/add_command',
        'MARKDO_INBOX' => 'Inbox.md',
      })

      AddCommand.new(command_support).run(task_body)
    end

    def assert_inbox_empty
      expect(read_inbox).to be_empty
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
markdo-0.2.0 spec/lib/commands/add_command_spec.rb