Giter VIP home page Giter VIP logo

Comments (2)

alexandredosim avatar alexandredosim commented on May 28, 2024 1

Hello JConan!
Thanks for your reply. After some study I came to a passing answer of the same type of yours. Pasting the full test here:

# Constants accessed from functions
% DATE_STR: dom 26 mar 2023 22:38:45
% LOG_DIR: .
% LOG_PATH: "$LOG_DIR/$DATE_STR test_env_builder.log"
#######################################

Mock date
    if [ ! -e "$date_lock" ]; then
        echo $DATE_STR
        touch "$date_lock"
    else
        echo dom 26 mar 2023 22:38:46
    fi
End
export "DATE_STR"

Context 'log'
    Include $script_file

    Context 'usage: caller'

        It 'should redirect the stdout to the file setted by log'

            usage() {
                log
                echo 'test message' &>> "$LOG_FILE"
            }

            When call usage

            The file "$LOG_PATH" should be a file
            The file "$LOG_PATH" should not be a empty file
            The file "$LOG_PATH" should be readable

            The output should equal "" 
        End
    End

    It 'should set the log file with the right format'
        When call log

        The variable "LOG_FILE" should equal "$LOG_PATH"
    End

    It 'should set the log file path one time only'
        log_twice() {
            log
            log
        }

        When call log_twice

        The variable "LOG_FILE" should equal "$LOG_PATH"
    End
End

from shellspec.

JConan avatar JConan commented on May 28, 2024

I don't think evaluation line "When" can resolve redirection.
You can otherwise encapsuled this in a function and then call it.

LOG_FILE="$SHELLSPEC_TMPDIR/test"

remove_logs() {
    rm "$LOG_FILE"
}

Context 'log'
    AfterEach 'remove_logs'
    File log_file="$LOG_FILE"
    log_to_file(){
      echo 'test message' >> "$LOG_FILE"
    }


    It 'should log a message to file'
        When call echo 'toto' >> "$LOG_FILE"

        The file log_file should be a file
        The file log_file should not be a empty file
        The file log_file should be readable
        The length of output should equal 0
    End
End

from shellspec.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.