Hi, I keep facing problems with autotest, and I don''t know what''s happening in the background, is there anyway to know what''s happening while testing? Example: @user = User.new @user.email = "testcom" @user.errors.on(:email).should_not be_empty ...throws error failure - You have a nil object when you didn''t expect it! - You might have expected an instance of Array. - The error occurred while evaluating nil.empty? ...but when I type this in ./script/console>> @user = User.new=> #<User id: nil, email: nil, nickname: nil, password: nil, logged_at: nil, created_at: nil>>> @user.valid?=> false>> @user.email = "asd@" >> @user.errors.on ''email''=> "is invalid" So how do you guys test things out and see what''s happening behind? I''m lost :( Thanks in advance :) -- Posted via http://www.ruby-forum.com/.
On Nov 1, 2007, at 6:18 AM, Jamal Soueidan wrote:> Hi, > > I keep facing problems with autotest, and I don''t know what''s > happening > in the background, is there anyway to know what''s happening while > testing? > > Example: > @user = User.new > @user.email = "testcom" > @user.errors.on(:email).should_not be_empty > > ...throws error failure >This is not an autotest problem, this is a test problem. Usually I start adding extra tests: it "should not raise an error with a new user (exploratory test)" do lambda { User.new }.should_not raise_error end If that one fails...then it''s a problem with my setup (before (:each))...and so on. If I really have no idea what''s going on, I''ll insert the following snippet to the top of the spec: require ''rubygems''; require ''ruby-debug''; debugger; (I use textmate, and have a snippet setup so that I can type "debug" tab, and the full line gets inserted) The next time autotest runs, it will drop me into the debugger (make sure you have the ruby-debug gem installed). Hope that helps, Scott> - You have a nil object when you didn''t expect it! > - You might have expected an instance of Array. > - The error occurred while evaluating nil.empty? > > ...but when I type this in ./script/console > >>> @user = User.new > => #<User id: nil, email: nil, nickname: nil, password: nil, > logged_at: > nil, created_at: nil> >>> @user.valid? > => false >>> @user.email = "asd@" >>> @user.errors.on ''email'' > => "is invalid" > > So how do you guys test things out and see what''s happening behind? > I''m > lost :( > > Thanks in advance :) > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
Scott Taylor wrote:> On Nov 1, 2007, at 6:18 AM, Jamal Soueidan wrote: > >> @user.errors.on(:email).should_not be_empty >> >> ...throws error failure >> > > This is not an autotest problem, this is a test problem. > > Usually I start adding extra tests: > > it "should not raise an error with a new user (exploratory test)" do > lambda { > User.new > }.should_not raise_error > end > > If that one fails...then it''s a problem with my setup (before > (:each))...and so on. > > If I really have no idea what''s going on, I''ll insert the following > snippet to the top of the spec: > > require ''rubygems''; require ''ruby-debug''; debugger; > > (I use textmate, and have a snippet setup so that I can type "debug" > tab, and the full line gets inserted) > > The next time autotest runs, it will drop me into the debugger (make > sure you have the ruby-debug gem installed). > > Hope that helps, > > ScottI tried to insert the requiring files etc. and went into the debugger, but how do I use it ? $ autotest loading autotest/rails_rspec /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -S script/spec -O spec/spec.opts spec/controllers/user_controller_spec.rb spec/models/user_spec.rb spec/helpers/user_helper_spec.rb spec/controllers/video_controller_spec.rb spec/helpers/video_helper_spec.rb ./spec/controllers/user_controller_spec.rb:5 require File.dirname(__FILE__) + ''/../spec_helper'' (rdb:1) user = User.new Adjusting would put us beyond the oldest (initial) frame. (rdb:1) user.email = "test" Adjusting would put us beyond the oldest (initial) frame. (rdb:1) user.should_not be_valid Adjusting would put us beyond the oldest (initial) frame. (rdb:1) -- Posted via http://www.ruby-forum.com/.
On Nov 2, 2007, at 4:48 AM, Jamal Soueidan wrote:> Scott Taylor wrote: >> On Nov 1, 2007, at 6:18 AM, Jamal Soueidan wrote: >> >>> @user.errors.on(:email).should_not be_empty >>> >>> ...throws error failure >>> >> >> This is not an autotest problem, this is a test problem. >> >> Usually I start adding extra tests: >> >> it "should not raise an error with a new user (exploratory test)" do >> lambda { >> User.new >> }.should_not raise_error >> end >> >> If that one fails...then it''s a problem with my setup (before >> (:each))...and so on. >> >> If I really have no idea what''s going on, I''ll insert the following >> snippet to the top of the spec: >> >> require ''rubygems''; require ''ruby-debug''; debugger; >> >> (I use textmate, and have a snippet setup so that I can type "debug" >> tab, and the full line gets inserted) >> >> The next time autotest runs, it will drop me into the debugger (make >> sure you have the ruby-debug gem installed). >> >> Hope that helps, >> >> Scott > > I tried to insert the requiring files etc. and went into the debugger, > but how do I use it ? > > $ autotest > loading autotest/rails_rspec > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -S > script/spec -O spec/spec.opts spec/controllers/ > user_controller_spec.rb > spec/models/user_spec.rb spec/helpers/user_helper_spec.rb > spec/controllers/video_controller_spec.rb > spec/helpers/video_helper_spec.rb > ./spec/controllers/user_controller_spec.rb:5 require > File.dirname(__FILE__) + ''/../spec_helper'' > (rdb:1) user = User.new > Adjusting would put us beyond the oldest (initial) frame. > (rdb:1) user.email = "test" > Adjusting would put us beyond the oldest (initial) frame. > (rdb:1) user.should_not be_valid > Adjusting would put us beyond the oldest (initial) frame. > (rdb:1) > -- > Posted via http://www.ruby-forum.com/.Google for the ruby-debugger. The most common commands are: h - help c - continue p - print (so p user = User.new) irb - drops you into irb b - breakpoint l - list where you are in the code And so on. I would advise looking up the tutorial, though. Scott