<commit_before>#!/usr/bin/env bats

# Copyright 2016 tsuru authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

setup() {
    rm -rf /home/application/current && mkdir /home/application/current
    chown ubuntu /home/application/current
    export CURRENT_DIR=/home/application/current
}

@test "installs ruby" {
    dpkg -s ruby | grep "install ok installed"
}

@test "installs build-essential" {
    dpkg -s build-essential | grep "install ok installed"
}

@test "install ruby version 2.3.1 as default" {
    run /home/application/ruby/bin/ruby --version
    [ "$status" -eq 0 ]
    [[ "$output" == *"2.3.1"* ]]
}

@test "install specific ruby version" {
    export RUBY_VERSION="2.2.2"
    run /var/lib/tsuru/deploy
    run /home/application/ruby/bin/ruby --version
    [ "$status" -eq 0 ]
    [[ "$output" == *"2.2.2"* ]]
}

@test "deploy fails on invalid ruby version" {
    export RUBY_VERSION="ABC"
    run /var/lib/tsuru/deploy
    [ "$status" -eq 1 ]
    [[ "$output" == *"ERROR: ruby version ABC is not supported."* ]]
}

@test "display supported versions if set" {
    export RUBY_VERSION="ABC"
    export SUPPORTED_VERSIONS="1.1.1, 1.2, 1.3"
    run /var/lib/tsuru/deploy
    [ "$status" -eq 1 ]
    [[ "$output" == *"Supported versions are: 1.1.1, 1.2, 1.3"* ]]
}

@test "parse ruby version from .ruby-version" {
    echo "ruby-2.1.2" > ${CURRENT_DIR}/.ruby-version
    run /var/lib/tsuru/deploy
    run /home/application/ruby/bin/ruby --version
    [ "$status" -eq 0 ]
    [[ "$output" == *"2.1.2"* ]]
    rm ${CURRENT_DIR}/.ruby-version
}

@test "bundle install when provide Gemfile and reuse already installed gem" {<commit_msg>Add tests for bundler version<commit_after>#!/usr/bin/env bats

# Copyright 2016 tsuru authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

setup() {
    rm -rf /home/application/current && mkdir /home/application/current
    chown ubuntu /home/application/current
    export CURRENT_DIR=/home/application/current
    export PATH=/home/application/ruby/bin:${PATH}
}

@test "installs ruby" {
    dpkg -s ruby | grep "install ok installed"
}

@test "installs build-essential" {
    dpkg -s build-essential | grep "install ok installed"
}

@test "install ruby version 2.3.1 as default" {
    run /home/application/ruby/bin/ruby --version
    [ "$status" -eq 0 ]
    [[ "$output" == *"2.3.1"* ]]
}

@test "install specific ruby version" {
    export RUBY_VERSION="2.2.2"
    run /var/lib/tsuru/deploy
    run /home/application/ruby/bin/ruby --version
    [ "$status" -eq 0 ]
    [[ "$output" == *"2.2.2"* ]]
}

@test "deploy fails on invalid ruby version" {
    export RUBY_VERSION="ABC"
    run /var/lib/tsuru/deploy
    [ "$status" -eq 1 ]
    [[ "$output" == *"ERROR: ruby version ABC is not supported."* ]]
}

@test "display supported versions if set" {
    export RUBY_VERSION="ABC"
    export SUPPORTED_VERSIONS="1.1.1, 1.2, 1.3"
    run /var/lib/tsuru/deploy
    [ "$status" -eq 1 ]
    [[ "$output" == *"Supported versions are: 1.1.1, 1.2, 1.3"* ]]
}

@test "parse ruby version from .ruby-version" {
    echo "ruby-2.1.2" > ${CURRENT_DIR}/.ruby-version
    run /var/lib/tsuru/deploy
    run /home/application/ruby/bin/ruby --version
    [ "$status" -eq 0 ]
    [[ "$output" == *"2.1.2"* ]]
    rm ${CURRENT_DIR}/.ruby-version
}

@test "install bundler version <2 when ruby version < 2.3.0" {
    export RUBY_VERSION="2.2.2"
    run /var/lib/tsuru/deploy
    run /home/application/ruby/bin/bundler --version
    [ "$status" -eq 0 ]
    [[ "$output" == "Bundler version 1."* ]]
}

@test "install bundler version >=2 when ruby version >= 2.3.0" {
    export RUBY_VERSION="2.3.0"
    run /var/lib/tsuru/deploy
    run /home/application/ruby/bin/bundler --version
    [ "$status" -eq 0 ]
    [[ "$output" == "Bundler version 2."* ]]
}

@test "bundle install when provide Gemfile and reuse already installed gem" {
{'fraction_non_alphanumeric': 0.16056758775205376, 'fraction_numerical': 0.024894199651481205, 'mean_word_length': 2.927663734115347, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1267920', 'n_tokens_mistral': 1521, 'n_tokens_neox': 1395, 'n_words': 390}