I figure out. The thread does not go to the "expect" statement because of the Ruby script terminates with the "exit" statement.
So, I reverted PR, and now in the “master” branch is the implementation of my loop, and in the “dev” branch is the implementation with the “exit” operator.
My loop implementation works well, but “expect (current_subject) .to receive (: create)” runs the “create” method in addition to the loop and it hangs up the test.
If you comment out the “expect” statement, the test completes correctly.
I mean going through all the expected methods that I checked by their messages and state values, that is, I see changes of all expected states:
:greeting -> :choose_base_option -> :create -> :exit
And if you change the name of the called method from "
create" to "
load" (which will not be called), the test will
fail,
as expected.
If you add "once / twice" to the “expect” expression, for example, “expect(current_subject).to receive(:create).once / twice ”, this will raise an expectation error:
(#<Console:0x0000563bfc2f7f90 @state=:create>).create(no args)
expected: 1 time with any arguments
received: 2 times
and
(#<Console:0x00005570a26aedf8 @state=:create>).create(no args)
expected: 2 times with any arguments
received: 3 times
respectively
branch master
Thus, the issue is how to test the method being called without calling it from the expression "expect".