~siegfriedehret/crystal-tuto

d3aa1a67905e1b57f545f6bb9f6ffca0861ea29a — Siegfried Ehret 2 years ago 07d47e5 partie-03
🎁 on bidouille pour la troisième partie

tagzytout: partie-03
A shard.lock => shard.lock +6 -0
@@ 0,0 1,6 @@
version: 2.0
shards:
  emoji:
    git: https://github.com/veelenga/emoji.cr.git
    version: 0.4.0+git.commit.94c9047f6e8adc8db07494644be0cc104336de3c


M shard.yml => shard.yml +5 -0
@@ 8,6 8,11 @@ targets:
  myapp:
    main: src/myapp.cr

dependencies:
  emoji:
    github: veelenga/emoji.cr
    branch: master

crystal: 1.3.2

license: MIT

A spec/lib/config_spec.cr => spec/lib/config_spec.cr +17 -0
@@ 0,0 1,17 @@
require "../spec_helper"
require "../../src/lib/config"

describe Myapp::Config do
  config = Myapp::Config.new

  describe "#add_contact" do
    it "should work" do
      config.contacts.size.should eq 0

      contact = Myapp::Contact.new("Jane doe", ["janedoe@example.com"])
      config.add_contact(contact)

      config.contacts.size.should eq 1
    end
  end
end

M spec/myapp_spec.cr => spec/myapp_spec.cr +11 -7
@@ 1,9 1,13 @@
require "./spec_helper"
# require "./spec_helper"

describe Myapp do
  # TODO: Write tests
# describe Myapp do
#   # TODO: Write tests

  it "works" do
    false.should eq(true)
  end
end
#   it "works" do
#     false.should eq(true)
#   end
# end

# require "file_utils"

# SPEC_TEMPFILE_PATH    = File.join(Dir.tempdir, "cr-spec-#{Random.new.hex(4)}")

M spec/spec_helper.cr => spec/spec_helper.cr +8 -1
@@ 1,2 1,9 @@
require "file_utils"
require "spec"
require "../src/myapp"

ENV["MYAPP_PATH"] = File.join(Dir.tempdir, "myapp-spec-#{Random.new.hex(4)}")
FileUtils.mkdir_p(ENV["MYAPP_PATH"])

Spec.after_suite do
  FileUtils.rm_rf ENV["MYAPP_PATH"]
end

M src/commands/add.cr => src/commands/add.cr +2 -1
@@ 1,3 1,4 @@
require "emoji"
require "../lib/config"
require "../structs/*"



@@ 16,7 17,7 @@ module Myapp

      def add(name : String | Nil, emails : Array(String))
        if name.nil?
          puts "We need a name!"
          puts Emoji.emojize(":warning: We need a name!")
        else
          @config.add_contact Contact.new(name.split("=")[1], emails)
        end

M src/lib/config.cr => src/lib/config.cr +1 -1
@@ 3,7 3,7 @@ require "../structs/list"

module Myapp
  class Config
    @@config_path : Path = Path.home / "myapp.yaml"
    @@config_path : Path = Path[ENV.fetch("MYAPP_PATH", Path.home.to_s)] / "myapp.yaml"
    property list : List

    def initialize