Hello everyone, I''m trying to write a failure test for updating a model, but the flash[:error] seems to be causing a problem. All code can be found here: http://pastie.org/private/zcu0fpzbfbjbleocmf1bqw I''ve also tried using regular expressions, instead of: flash[:error].should == "Name can''t be blank" I''ve tried: flash[:error].should =~ /Name can''t be blank/i Thank you in advance!! Andrew Davis -- Posted via http://www.ruby-forum.com/.
Hi Andrew I suspect that flash[:error] is not a valid identifier, and therefore is returning a nil value. Hope this is of use to you. Paul On Mon, Nov 22, 2010 at 2:00 PM, Andrew Davis <lists at ruby-forum.com> wrote:> Hello everyone, > > I''m trying to write a failure test for updating a model, but the > flash[:error] seems to be causing a problem. > > All code can be found here: > http://pastie.org/private/zcu0fpzbfbjbleocmf1bqw > > I''ve also tried using regular expressions, instead of: > > flash[:error].should == "Name can''t be blank" > > I''ve tried: > > flash[:error].should =~ /Name can''t be blank/i > > Thank you in advance!! > Andrew Davis > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20101122/82f171a3/attachment.html>
On Mon, Nov 22, 2010 at 4:04 PM, Paul Nelligan <nellboy at gmail.com> wrote:> Hi Andrew > I suspect that flash[:error] is not a valid identifier, ?and therefore is > returning a nil value. > Hope this is of use to you. > Paul > > On Mon, Nov 22, 2010 at 2:00 PM, Andrew Davis <lists at ruby-forum.com> wrote: >> >> Hello everyone, >> >> I''m trying to write a failure test for updating a model, but the >> flash[:error] seems to be causing a problem. >> >> All code can be found here: >> http://pastie.org/private/zcu0fpzbfbjbleocmf1bqw >> >> I''ve also tried using regular expressions, instead of: >> >> flash[:error].should == "Name can''t be blank" >> >> I''ve tried: >> >> flash[:error].should =~ /Name can''t be blank/iAs Paul pointed out correctly flash[:error] == nil, thus your spec works quite correctly. All you have to do now is to set flash[:error] appropriately, in your case I guess that this should be done by means of ActiveRecord/ActiveModel validations. Are you sure that you have the necessary validation in your Task model? HTH Robert -- The 1,000,000th fibonacci number contains ''42'' 2039 times; that is almost 30 occurrences more than expected (208988 digits). N.B. The 42nd fibonacci number does not contain ''1000000'' that is almost the expected 3.0e-06 times.
the question you need to ask is: is flash[:error] a variable within the scope that you''re working ? ... I suspect that it''s not, although I could be wrong. with that in mind, does anyone know of a way of determining which variables are accessible via rspec on each (MVC) layer ?, Is it a simple case of ''what''s accessible in the controller is accessible in the controller spec'' (for example) ?, or is it more complicated ? cheers On Mon, Nov 22, 2010 at 9:55 PM, Robert Dober <robert.dober at gmail.com>wrote:> On Mon, Nov 22, 2010 at 4:04 PM, Paul Nelligan <nellboy at gmail.com> wrote: > > Hi Andrew > > I suspect that flash[:error] is not a valid identifier, and therefore is > > returning a nil value. > > Hope this is of use to you. > > Paul > > > > On Mon, Nov 22, 2010 at 2:00 PM, Andrew Davis <lists at ruby-forum.com> > wrote: > >> > >> Hello everyone, > >> > >> I''m trying to write a failure test for updating a model, but the > >> flash[:error] seems to be causing a problem. > >> > >> All code can be found here: > >> http://pastie.org/private/zcu0fpzbfbjbleocmf1bqw > >> > >> I''ve also tried using regular expressions, instead of: > >> > >> flash[:error].should == "Name can''t be blank" > >> > >> I''ve tried: > >> > >> flash[:error].should =~ /Name can''t be blank/i > > As Paul pointed out correctly flash[:error] == nil, thus your spec > works quite correctly. All you have to do now is to set flash[:error] > appropriately, in your case I guess that this should be done by means > of ActiveRecord/ActiveModel validations. > Are you sure that you have the necessary validation in your Task model? > > HTH > Robert > > -- > The 1,000,000th fibonacci number contains ''42'' 2039 times; that is > almost 30 occurrences more than expected (208988 digits). > N.B. The 42nd fibonacci number does not contain ''1000000'' that is > almost the expected 3.0e-06 times. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20101122/e82bc955/attachment.html>
On Mon, Nov 22, 2010 at 11:26 PM, Paul Nelligan <nellboy at gmail.com> wrote:> the question you need to ask is: is flash[:error] a variable within the > scope that you''re working ? ... I suspect that it''s not, although I could be > wrong. > with that in mind, ?does anyone know of a way of determining which variables > are accessible via rspec on each (MVC) layer ?, ?Is it a simple case of > ''what''s accessible in the controller is accessible in the controller spec'' > (for example) ?, ?or is it more complicated ? > cheers > On Mon, Nov 22, 2010 at 9:55 PM, Robert Dober <robert.dober at gmail.com> > wrote:Paul, it was a little bit tricky to answer this because of the top post, most of us are not used to that. So please if you can, do rather bottom post or inline post. That said, I am not sure what you mean by flash[:error] being a variable? As the trace shows flash[:error] is nil, from this alone, we can follow that flash points to an object which responds to the #[] message. In our case it replies to [:error] with nil. However in the given context we *know* that flash is a Hash representing well, the flash. I am not an expert to tell you where in the rspec setup this is mocked, but this should not be the problem in our case. That said I would be happy to learn more about that mechanism. Cheers R.