1
Finished in 0.0137 seconds (files took 0.0769 seconds to load)
5 examples, 1 failure

Failed examples:

rspec ./spec/basic_math_spec.rb:10 # Basic-Math Subtract numbers

Error: Process completed with exit code 1.

GitHub Actions marks the testing-step correctly as erroneous.

But how does GitHub Actions know that the tests have failed?

RSpec is just some command-line software, which is executed. How is it reported upwards and then reported, that something didn't work as expected?

3
  • 4
    "Process completed with exit code 1" Commented Jun 19 at 9:49
  • But that's just some string, printed to the console. How does the actual mechanism work? Commented Jun 19 at 9:50
  • 4
    It's all just some software that's executed. The string is telling you about the actual exit code from the process, which was non-zero and therefore unhappy (stackoverflow.com/q/74259632/3001761). Commented Jun 19 at 9:59

1 Answer 1

2

But that's just some string, printed to the console. How does the actual mechanism work?

Well, what you see is not just tests being run, but an output of another program that runs the tests. A runner, or wrapper if you will. We can write one in bash ourselves

ls "foo" # we can another command instead of running tests
if [ $? -ne 0 ]; then
  echo "Directory 'foo' does not exist."
else
  echo "Directory 'foo' exists."
fi

And if you run it:

$ ./runner.sh
ls: cannot access 'foo': No such file or directory
Directory 'foo' does not exist.

We essentially have a program that runs another program, and inspects it's return code (bash holds the last run program's return code in $? var)

This is a standard across operating systems for program to return a status upon it's execution. The successful runs usually return 0 (I'm not sure if it's universal rule, though).

In Ruby (since you're asking about rspec, I'll asume this is what you're familiar with) you have https://ruby-doc.org/core-2.6/Process.html#method-c-exit to control (to an extent) what your program returns.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.