Hi :) Does anyone know of a way to set the value of $? ? I have a test which stubs ` ; the call works fine, but then the library I am testing checks the value of $? to see if the process terminated correctly. It seems not to be possible to assign $? directly... For now I do this before my test : `ls > /dev/null` Which ensure that $? is zero ; but this is not a very nice way of doing it ! If anyone here has a good trick for this, it will be very welcome :) Thanks, Anselm -- ------------------------------ Netuxo Ltd a workers'' co-operative providing low-cost IT solutions for peace, environmental and social justice groups and the radical NGO sector Registered as a company in England and Wales. No 4798478 Registered office: 5 Caledonian Road, London N1 9DY, Britain ------------------------------ email office at netuxo.co.uk http://www.netuxo.co.uk ------------------------------
The only thing I can suggest is to wrap the $? execution environment variable in a method e.g. exit_status(). Then you could then stub the exit_status() method to return your desired result. -- James. http://blog.floehopper.org
This is working for me, right now: $?.stubs(:exitstatus).returns(0) also (though I know the proc version is deprecated) : Job.any_instance.expects(:`).with() {|call| call =~ /ssh/ }.returns(lambda { $?.expects(:exitstatus).returns(-1) ''11807'' }) On 6/19/07, James Mead <jamesmead44 at gmail.com> wrote:> The only thing I can suggest is to wrap the $? execution environment > variable in a method e.g. exit_status(). Then you could then stub the > exit_status() method to return your desired result. > -- > James. > http://blog.floehopper.org > _______________________________________________ > mocha-developer mailing list > mocha-developer at rubyforge.org > http://rubyforge.org/mailman/listinfo/mocha-developer >-- Kevin Clark http://glu.ttono.us
On 20/06/07, Kevin Clark <kevin.clark at gmail.com> wrote:> > $?.stubs(:exitstatus).returns(0) >That''s interesting - I didn''t think that would work, because $? is normally nil, but of course it does, because nil is an object in Ruby :-) -- James. http://blog.floehopper.org
On 20/06/07, Kevin Clark <kevin.clark at gmail.com> wrote:> > $?.stubs(:exitstatus).returns(0) > >Thanks for that one :) Anselm -- ------------------------------ Netuxo Ltd a workers'' co-operative providing low-cost IT solutions for peace, environmental and social justice groups and the radical NGO sector Registered as a company in England and Wales. No 4798478 Registered office: 5 Caledonian Road, London N1 9DY, Britain ------------------------------ email office at netuxo.co.uk http://www.netuxo.co.uk ------------------------------