Alex Satrapa
2008-Feb-24 23:54 UTC
[rspec-users] How to dump contents produced during spec evaluation?
In a story, I have the following happening: post("/resources/", ''resource'' => request_attrs) response.should render_template(''resource/new'') response.should have_tag(''*'', /must have one or more X defined/) In the ResourceController spec, I have the following happening: post( :create, :resource => request_attrs ) response.should render_template(''resource/new'') response.should have_tag(''*'', /must have one or more X defined/) The problem I''m having is that the story works just fine, but the spec claims that there are no tags matching ''*'' in the response. Is there any way I can dump the contents of the response, in the hope that they might tip me off as to the cause of this error? I''ve checked the stories, and I do not have any steps with the same description as the one that passes in the story but fails in the spec. I''ve stumbled across this before, especially where a step is "when the user creates a new resource" - often the first one the story runner sees will become the definition of "when the user creates a new resource", and later versions have to be renamed eg: "when the user creates a new resource with special feature X". That''s not happening here as far as I can tell. Any clues on where to start looking? Thanks Alex
David Chelimsky
2008-Feb-24 23:58 UTC
[rspec-users] How to dump contents produced during spec evaluation?
On Sun, Feb 24, 2008 at 5:54 PM, Alex Satrapa <grail at goldweb.com.au> wrote:> In a story, I have the following happening: > post("/resources/", ''resource'' => request_attrs) > response.should render_template(''resource/new'') > response.should have_tag(''*'', /must have one or more X defined/) > > In the ResourceController spec, I have the following happening: > post( :create, :resource => request_attrs ) > response.should render_template(''resource/new'') > response.should have_tag(''*'', /must have one or more X defined/) > > The problem I''m having is that the story works just fine, but the > spec claims that there are no tags matching ''*'' in the response. > > Is there any way I can dump the contents of the response, in the hope > that they might tip me off as to the cause of this error?puts response.body> > I''ve checked the stories, and I do not have any steps with the same > description as the one that passes in the story but fails in the > spec. I''ve stumbled across this before, especially where a step is > "when the user creates a new resource" - often the first one the > story runner sees will become the definition of "when the user > creates a new resource", and later versions have to be renamed eg: > "when the user creates a new resource with special feature X". > That''s not happening here as far as I can tell. > > Any clues on where to start looking? > > Thanks > Alex > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Alex Satrapa
2008-Feb-25 00:29 UTC
[rspec-users] How to dump contents produced during spec evaluation?
On 25/02/2008, at 10:58 , David Chelimsky wrote:> On Sun, Feb 24, 2008 at 5:54 PM, Alex Satrapa > <grail at goldweb.com.au> wrote: >> In the ResourceController spec, I have the following happening: >> post( :create, :resource => request_attrs ) >> response.should render_template(''resource/new'') >> response.should have_tag(''*'', /must have one or more X defined/)>> Is there any way I can dump the contents of the response, in the >> hope >> that they might tip me off as to the cause of this error? > > puts response.bodyOkay, this is weird. The result seems to indicate that the body of the response is the literal text, "resource/new": My autotest results show (I''ve changed the name of the resource to ''resource''):> ..........resources/new > F.............. > > 1) > ''ResourcesController on ''POST /resources/'', with an invalid request > should generate an error message indicating that magic parts are > missing'' FAILED > Expected at least 1 element matching "*", found 0. > <false> is not true. > ./spec/controllers/resources_controller_spec.rb:138: > script/spec:4: > > Finished in 0.753821 seconds > > 25 examples, 1 failureTime to go through all my other specs and check that they''re working (or breaking) the same way, to see if I can figure out what I''ve done wrong. Alex
David Chelimsky
2008-Feb-25 00:33 UTC
[rspec-users] How to dump contents produced during spec evaluation?
On Sun, Feb 24, 2008 at 6:29 PM, Alex Satrapa <grail at goldweb.com.au> wrote:> On 25/02/2008, at 10:58 , David Chelimsky wrote: > > > On Sun, Feb 24, 2008 at 5:54 PM, Alex Satrapa > > <grail at goldweb.com.au> wrote: > > >> In the ResourceController spec, I have the following happening: > >> post( :create, :resource => request_attrs ) > >> response.should render_template(''resource/new'') > >> response.should have_tag(''*'', /must have one or more X defined/) > > > >> Is there any way I can dump the contents of the response, in the > >> hope > >> that they might tip me off as to the cause of this error? > > > > puts response.body > > Okay, this is weird. The result seems to indicate that the body of > the response is the literal text, "resource/new":Ah yes - of course. Give this a read and see if it answers your question: http://rspec.info/documentation/rails/writing/controllers.html> > My autotest results show (I''ve changed the name of the resource to > ''resource''): > > ..........resources/new > > F.............. > > > > 1) > > ''ResourcesController on ''POST /resources/'', with an invalid request > > should generate an error message indicating that magic parts are > > missing'' FAILED > > Expected at least 1 element matching "*", found 0. > > <false> is not true. > > ./spec/controllers/resources_controller_spec.rb:138: > > script/spec:4: > > > > Finished in 0.753821 seconds > > > > 25 examples, 1 failure > > > Time to go through all my other specs and check that they''re working > (or breaking) the same way, to see if I can figure out what I''ve done > wrong. > > > > Alex > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
s.ross
2008-Feb-25 00:35 UTC
[rspec-users] How to dump contents produced during spec evaluation?
On Feb 24, 2008, at 4:29 PM, Alex Satrapa wrote:> Okay, this is weird. The result seems to indicate that the body of > the response is the literal text, "resource/new": > > My autotest results show (I''ve changed the name of the resource to > ''resource''): >>Try puts response.class puts response.inspect to see whether you have what you think you do.
David Chelimsky
2008-Feb-25 00:42 UTC
[rspec-users] How to dump contents produced during spec evaluation?
On Sun, Feb 24, 2008 at 6:35 PM, s.ross <cwdinfo at gmail.com> wrote:> On Feb 24, 2008, at 4:29 PM, Alex Satrapa wrote: > > > Okay, this is weird. The result seems to indicate that the body of > > the response is the literal text, "resource/new": > > > > My autotest results show (I''ve changed the name of the resource to > > ''resource''): > >> > > Try > > puts response.class > puts response.inspectSteve - it''s because of isolation - I pointed Alex to the docs.> > to see whether you have what you think you do. > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Alex Satrapa
2008-Feb-25 01:10 UTC
[rspec-users] How to dump contents produced during spec evaluation?
On 25/02/2008, at 11:42 , David Chelimsky wrote:> Steve - it''s because of isolation - I pointed Alex to the docs.Yup, I''m having a low-caffeine day apparently. I''m going to great pains to isolate just the portions of the controller that need to be designed (using mocks and stubs), then slapping a test in there that looks for an output that the mock will never generate. The error message is already specced in the model spec and the view spec, and it''s already checked for in the story - do I need more testing for that failure path? Alex