Testing with RSpec - Output activity messages to STDOUT in Ruby -
I'm looking for some help in output the activity messages in the command line window. I know this may look backwards but this is the work given to me. I have already written the tests so that they are all but I need to change the activity below to the command line window. This is a game similar to the impossible machine game.
First of all, I need to make a process that starts the impossible machine, then simulate every move started in succession before the end.
> All the messages I see should be sent to the STDOUT channel. These are some of the tests that have been written: Module Impossamine # Input and Output Constants Processed by Sub Processes DOWN_ARROW = 1 UP_ARROW = 2 RIGHT_ARROW = 3 REPEAT_ARROW = 4 END_PROCESS = 5 START_CURRENT = 6 # Description of the RSpec test game describes what "impossible machine game # start" first (what is: each). Such as @process = [] @output = double ('output') as_null_object @game = Game.new (@output) it ends in "Welcome Message" do @ output.should_receive (: puts) .with ('In Impossible Machine Your Welcome! ') @ Sends. Starts to End "A method has been created by which the name of the student gives" myname = @game. ", Activity # {UP_ARROW}: created_by myname.should ==" My name "is the finished" lifts_lever_turns_wheel activity that is REPEAT_ARROW Returns should be performed "@ output.should_receive ((puts)) .with (" Input Heave_ho_sque ek_squeek ") @process [1] = @ game.lifts_lever_turns_wheel (UP_ARROW) @process [1] .should == REPEAT_ARROW Finally On this, "a refinement message" such as @ output.should_receive (sends: puts) .with ('... game has ended.') @ Game.Finish end and D &
My only knowledge is that I need to start the module like this and then add the code below so that it can output the activity message on the command line:
Module impossible Mitchin @process = [] g = Game.new (STDOUT)
Hope that makes sense.
STDOUT STDOUT
If this is the case, then let me tell you why you post in your code, it does not happen:
When you use the new game @game
You make it from Game.new (@output).
@output
is a double
, which means that it is not actually a output object, but rather a duplicate object instead.
It's completely okay, the only problem with it from the path is that it does not print anything for actually the console.
If you want to test, while actually printing on the console, you should pass before the actual STDOUT
object:
(: Each) @process = [] @output = STDOUT @game = Game.new (@output) end
. To make them work, you should add in each expectation:this will work around because it All your tests @ output.should_receive ...)
@ output.should_receive (puts) .with ('Welcome to the Impossible Machine!'). And_color_original
Comments
Post a Comment