Test Driven Development with Clojure

We're going to build a Pig Latin translation library using Clojure.

Use your left and right arrow keys to move throught the steps for Clojure.

Use your up and down arrow keys to move through the different languages for any step.

Clojure: Installing Homebrew

We're going to start by installing Homebrew which will make installing everything else we need much easier.

Open a Terminal window and run the following commands:

1
2
xcode-select --install
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Clojure: Installing Clojure

Now we can easily install Clojure with Homebrew using the following:

1
brew install clojure

Clojure: Creating the Project

Now we'll use Leiningen to initialize a project for us.

1
2
3
brew intall leiningen
lein new default piglatin
cd piglatin

Clojure: Dependency Management

When building software you will frequently use libraries and tools from a third party. Since they have their own development lifecycles and versions we want to be able to define a specific version of that dependency to use in our software. We want to do that with a tool and a file.

For Clojure we'll use the tool Leiningen and our dependencies will be defined in the file project.clj.

1
# leiningen was already installed above

Clojure: Adding a Testing Library

We're going to use the testing library clojure.test to write our tests.

Edit the file project.clj and add clojure.test as a testing dependency:

1

Then we retrieve clojure.test by running lein deps.

Finally we initialize clojure.test by running .

Clojure: The First Test

Create the file test/piglatin/core_test.clj with the following contents:

1
2
3
4
5
6
7
(ns piglatin.core-test
  (:require [clojure.test :refer :all]
            [piglatin.core :refer :all]))

(deftest word-starting-with-a-vowel
  (testing "translate_word"
    (is (= "appleyay" (translate_word "apple")))))

Clojure: Run the Test

Then run the test with the command lein test to see the results:

1
Exception in thread "main" java.lang.RuntimeException: Unable to resolve symbol: translate_word in this context, compiling:(piglatin/core_test.clj:7:23)

Test Driven Development with Crystal

We're going to build a Pig Latin translation library using Crystal.

Use your left and right arrow keys to move throught the steps for Crystal.

Use your up and down arrow keys to move through the different languages for any step.

Crystal: Installing Homebrew

We're going to start by installing Homebrew which will make installing everything else we need much easier.

Open a Terminal window and run the following commands:

1
2
xcode-select --install
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Crystal: Installing Crystal

Now we can easily install Crystal with Homebrew using the following:

1
brew install crystal-lang

Crystal: Creating the Project

Now we'll use crystal to initialize a project for us.

1
2
3
# crystal is installed with the language
crystal init lib ystalcray
cd ystalcray

Crystal: Dependency Management

When building software you will frequently use libraries and tools from a third party. Since they have their own development lifecycles and versions we want to be able to define a specific version of that dependency to use in our software. We want to do that with a tool and a file.

For Crystal we'll use the tool crystal and our dependencies will be defined in the file shard.yml.

1
# crystal is installed with the language

Crystal: Adding a Testing Library

We're going to use the testing library Spec to write our tests.

Edit the file shard.yml and add Spec as a testing dependency:

1

Then we retrieve Spec by running crystal deps install.

Finally we initialize Spec by running .

Crystal: The First Test

Create the file spec/ystalcray.cr with the following contents:

1
2
3
4
5
6
7
8
9
require "./spec_helper"

describe Ystalcray do
  describe "translate_word" do
    it "translates words starting with a vowel" do
      Ystalcray.translate_word("apple").should eq "appleway"
    end
  end
end

Crystal: Run the Test

Then run the test with the command crystal spec to see the results:

1
2
3
4
5
6
Error in line 1: while requiring "./spec/ystalcray_spec.cr"

in spec/ystalcray_spec.cr:6: undefined method 'translate_word' for Ystalcray:Module

      Ystalcray.translate_word("apple").should eq "appleway"
                ^~~~~~~~~~~~~~

Test Driven Development with Elixir

We're going to build a Pig Latin translation library using Elixir.

Use your left and right arrow keys to move throught the steps for Elixir.

Use your up and down arrow keys to move through the different languages for any step.

Elixir: Installing Homebrew

We're going to start by installing Homebrew which will make installing everything else we need much easier.

Open a Terminal window and run the following commands:

1
2
xcode-select --install
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Elixir: Installing Elixir

Now we can easily install Elixir with Homebrew using the following:

1
brew install elixir

Elixir: Creating the Project

Now we'll use mix to initialize a project for us.

1
2
3
# mix is installed along with Elixir
mix new elixiray
cd elixiryay

Elixir: Dependency Management

When building software you will frequently use libraries and tools from a third party. Since they have their own development lifecycles and versions we want to be able to define a specific version of that dependency to use in our software. We want to do that with a tool and a file.

For Elixir we'll use the tool mix and our dependencies will be defined in the file mix.exs.

1
# mix is installed along with Elixir

Elixir: Adding a Testing Library

We're going to use the testing library ExUnit to write our tests.

Edit the file mix.exs and add ExUnit as a testing dependency:

1

Then we retrieve ExUnit by running mix deps.get.

Finally we initialize ExUnit by running .

Elixir: The First Test

Create the file text/elixiray_text.exs with the following contents:

1
2
3
4
5
6
7
8
defmodule ElixirayTest do
  use ExUnit.Case
  doctest Elixiray

  test "word starting with a vowel" do
    assert Elixiray.translate_word("apple") == "appleyay"
  end
end

Elixir: Run the Test

Then run the test with the command mix test to see the results:

1
2
3
4
5
6
7
1) test word starting with a vowel (ElixirayTest)
   test/elixiray_test.exs:5
   ** (UndefinedFunctionError) function Elixiray.translate_word/1 is undefined or private
   code: assert Elixiray.translate_word("apple") == "appleyay"
   stacktrace:
     (elixiray) Elixiray.translate_word("apple")
     test/elixiray_test.exs:6: (test)

Test Driven Development with Java

We're going to build a Pig Latin translation library using Java.

Use your left and right arrow keys to move throught the steps for Java.

Use your up and down arrow keys to move through the different languages for any step.

Java: Installing Homebrew

We're going to start by installing Homebrew which will make installing everything else we need much easier.

Open a Terminal window and run the following commands:

1
2
xcode-select --install
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Java: Installing Java

Now we can easily install Java with Homebrew using the following:

1
brew cask install java

Java: Creating the Project

Now we'll use Savant to initialize a project for us.

1
2
3
brew tap spilth/tap && brew install savant
savant init avajay -l java
cd avajay

Java: Dependency Management

When building software you will frequently use libraries and tools from a third party. Since they have their own development lifecycles and versions we want to be able to define a specific version of that dependency to use in our software. We want to do that with a tool and a file.

For Java we'll use the tool Maven and our dependencies will be defined in the file pom.xml.

1
brew install maven

Java: Adding a Testing Library

We're going to use the testing library JUnit to write our tests.

Edit the file pom.xml and add JUnit as a testing dependency:

1
2
3
4
5
6
7
8
<dependencies>
  <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
  </dependency>
</dependencies>

Then we retrieve JUnit by running mvn dependency:resolve.

Finally we initialize JUnit by running mkdir -p src/test/java/tdd.

Java: The First Test

Create the file src/test/java/tdd/PiglatinTest.java with the following contents:

1
2
3
4
5
6
7
8
9
10
package tdd;

import org.junit.Test;

public class PiglatinTest {
    @Test
    public void translateWord_startingWithVowel() {
        assertEquals("apple", Piglatin.translateWorld("appleyay"));
    }
}

Java: Run the Test

Then run the test with the command mvn test to see the results:

1
2
3
4
5
6
7
8
9
[INFO] Compiling 2 source files to /Users/bkelly/temp/piglatin-java/target/test-classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /Users/bkelly/temp/piglatin-java/src/test/java/tdd/PiglatinTest.java:[9,32] cannot find symbol
  symbol:   variable Piglatin
  location: class tdd.PiglatinTest
[INFO] 1 error
[INFO] -------------------------------------------------------------

Test Driven Development with Kotlin

We're going to build a Pig Latin translation library using Kotlin.

Use your left and right arrow keys to move throught the steps for Kotlin.

Use your up and down arrow keys to move through the different languages for any step.

Kotlin: Installing Homebrew

We're going to start by installing Homebrew which will make installing everything else we need much easier.

Open a Terminal window and run the following commands:

1
2
xcode-select --install
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Kotlin: Installing Kotlin

Now we can easily install Kotlin with Homebrew using the following:

1
brew install kotlin

Kotlin: Creating the Project

Now we'll use Savant to initialize a project for us.

1
2
3
brew tap spilth/tap && brew install savant
savant init otlinkay -l kotlin
cd otlinkay

Kotlin: Dependency Management

When building software you will frequently use libraries and tools from a third party. Since they have their own development lifecycles and versions we want to be able to define a specific version of that dependency to use in our software. We want to do that with a tool and a file.

For Kotlin we'll use the tool Maven and our dependencies will be defined in the file pom.xml.

1
brew install maven

Kotlin: Adding a Testing Library

We're going to use the testing library JUnit to write our tests.

Edit the file pom.xml and add JUnit as a testing dependency:

1
2
3
4
5
6
7
8
<dependencies>
  <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
  </dependency>
</dependencies>

Then we retrieve JUnit by running mvn dependency:resolve.

Finally we initialize JUnit by running mkdir -p src/test/kotlin/tdd.

Kotlin: The First Test

Create the file src/test/kotlin/tdd/OtlinkayTest.kt with the following contents:

1
TK

Kotlin: Run the Test

Then run the test with the command mvn test to see the results:

1
TK

Test Driven Development with NodeJS

We're going to build a Pig Latin translation library using NodeJS.

Use your left and right arrow keys to move throught the steps for NodeJS.

Use your up and down arrow keys to move through the different languages for any step.

NodeJS: Installing Homebrew

We're going to start by installing Homebrew which will make installing everything else we need much easier.

Open a Terminal window and run the following commands:

1
2
xcode-select --install
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

NodeJS: Installing NodeJS

Now we can easily install NodeJS with Homebrew using the following:

1
brew install nodejs

NodeJS: Creating the Project

Now we'll use npm to initialize a project for us.

1
2
3
# npm is installed along with NodeJS
mkdir odenay && cd odenay && npm init --yes
cd odenay

NodeJS: Dependency Management

When building software you will frequently use libraries and tools from a third party. Since they have their own development lifecycles and versions we want to be able to define a specific version of that dependency to use in our software. We want to do that with a tool and a file.

For NodeJS we'll use the tool npm and our dependencies will be defined in the file package.json.

1
# npm is installed along with NodeJS

NodeJS: Adding a Testing Library

We're going to use the testing library Jasmine to write our tests.

Edit the file package.json and add Jasmine as a testing dependency:

1

Then we retrieve Jasmine by running npm install.

Finally we initialize Jasmine by running .

NodeJS: The First Test

Create the file test/odenay_test.js with the following contents:

1
2
3
4
5
6
describe("translateWord", function () {
  it("should translate the word", function () {
    var result = piglatin.translateWord("apple");
    expect(result).toBe("appleyay");
  });
});

NodeJS: Run the Test

Then run the test with the command jasmine to see the results:

1
2
3
4
5
6
7
8
9
10
11
12
13
Started
F

Failures:
1) translateWorld should translate the word
  Message:
    ReferenceError: piglatin is not defined
  Stack:
    ReferenceError: piglatin is not defined
        at Object.<anonymous> (/Users/bkelly/temp/piglatin-nodejs/spec/piglatin_spec.js:3:18)

1 spec, 1 failure
Finished in 0.005 seconds

Test Driven Development with Python

We're going to build a Pig Latin translation library using Python.

Use your left and right arrow keys to move throught the steps for Python.

Use your up and down arrow keys to move through the different languages for any step.

Python: Installing Homebrew

We're going to start by installing Homebrew which will make installing everything else we need much easier.

Open a Terminal window and run the following commands:

1
2
xcode-select --install
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Python: Installing Python

Now we can easily install Python with Homebrew using the following:

1
brew install python

Python: Creating the Project

Now we'll use PyScaffold to initialize a project for us.

1
2
3
pip2 install pyscaffold
putup ythonpay
cd ythonpay

Python: Dependency Management

When building software you will frequently use libraries and tools from a third party. Since they have their own development lifecycles and versions we want to be able to define a specific version of that dependency to use in our software. We want to do that with a tool and a file.

For Python we'll use the tool pip and our dependencies will be defined in the file requirements.txt.

1
# pip is installed with Python

Python: Adding a Testing Library

We're going to use the testing library pytest to write our tests.

Edit the file requirements.txt and add pytest as a testing dependency:

1

Then we retrieve pytest by running pip2 install -r requirements.txt.

Finally we initialize pytest by running .

Python: The First Test

Create the file tests/test_skeleton.py with the following contents:

1
2
3
4
5
import pytest
from ythonpay.skeleton import translate_word

def test_translate_word():
    assert translate_word("apple") == "appleway"

Python: Run the Test

Then run the test with the command python setup.py test to see the results:

1
2
3
NameError: global name 'translate_word' is not defined

tests/test_skeleton.py:8: NameError

Test Driven Development with Ruby

We're going to build a Pig Latin translation library using Ruby.

Use your left and right arrow keys to move throught the steps for Ruby.

Use your up and down arrow keys to move through the different languages for any step.

Ruby: Installing Homebrew

We're going to start by installing Homebrew which will make installing everything else we need much easier.

Open a Terminal window and run the following commands:

1
2
xcode-select --install
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Ruby: Installing Ruby

Now we can easily install Ruby with Homebrew using the following:

1
brew install ruby

Ruby: Creating the Project

Now we'll use Bundler to initialize a project for us.

1
2
3
gem install bundler
bundle gem ubyray --no-coc --no-mit
cd ubyray

Ruby: Dependency Management

When building software you will frequently use libraries and tools from a third party. Since they have their own development lifecycles and versions we want to be able to define a specific version of that dependency to use in our software. We want to do that with a tool and a file.

For Ruby we'll use the tool Bundler and our dependencies will be defined in the file Gemfile.

1
# We already installed Bundler above

Ruby: Adding a Testing Library

We're going to use the testing library RSpec to write our tests.

Edit the file Gemfile and add RSpec as a testing dependency:

1
spec.add_development_dependency 'rspec'

Then we retrieve RSpec by running bundle.

Finally we initialize RSpec by running rspec --init.

Ruby: The First Test

Create the file spec/piglatin_spec.rb with the following contents:

1
2
3
4
5
6
7
describe Piglatin do
  context "word starting with a vowel" do
    it "translates the word" do
      expect(Piglatin.translate_word "apple").to eq "appleyay"
    end
  end
end

Ruby: Run the Test

Then run the test with the command rspec to see the results:

1
...spec/piglatin_spec.rb:1:in `<top (required)>': uninitialized constant Piglatin (NameError)

Test Driven Development with Rust

We're going to build a Pig Latin translation library using Rust.

Use your left and right arrow keys to move throught the steps for Rust.

Use your up and down arrow keys to move through the different languages for any step.

Rust: Installing Homebrew

We're going to start by installing Homebrew which will make installing everything else we need much easier.

Open a Terminal window and run the following commands:

1
2
xcode-select --install
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Rust: Installing Rust

Now we can easily install Rust with Homebrew using the following:

1
brew install rust

Rust: Creating the Project

Now we'll use Cargo to initialize a project for us.

1
2
3
# cargo is installed along with Rust
cargo new ustray --lib
cd urstray

Rust: Dependency Management

When building software you will frequently use libraries and tools from a third party. Since they have their own development lifecycles and versions we want to be able to define a specific version of that dependency to use in our software. We want to do that with a tool and a file.

For Rust we'll use the tool Cargo and our dependencies will be defined in the file Cargo.toml.

1
# cargo is installed along with Rust

Rust: Adding a Testing Library

We're going to use the testing library TK to write our tests.

Edit the file Cargo.toml and add TK as a testing dependency:

1
TK

Then we retrieve TK by running cargo update.

Finally we initialize TK by running TK.

Rust: The First Test

Create the file src/lib.rs with the following contents:

1
2
3
4
5
6
7
#[cfg(test)]
mod tests {
    #[test]
    fn it_works() {
        assert_eq!("appleway", translate_word("apple"));
    }
}

Rust: Run the Test

Then run the test with the command cargo test to see the results:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Compiling ustray v0.1.0 (file:///Users/brian/temp/ustray)
error[E0425]: cannot find function `translate_word` in this scope
  --> src/lib.rs:10:32
   |
10 |         assert_eq!("appleway", translate_word("apple"));
   |                                ^^^^^^^^^^^^^^ not found in this scope
   |
help: possible candidate is found in another module, you can import it into scope
   |
1  | use translate_word;
   |

error: aborting due to previous error

error: Could not compile `ustray`.

To learn more, run the command again with --verbose.