Re: [rspec-users] silly partial qu

2008-05-04 Thread steven shingler
Hi Rick,
Thanks for your reply.
You are right that this step is basically testing the basic actions of
a controller, and is being run as part of a story_with_steps stack.
The step itself is definitely being hit, because I have a:
response.should have_tag('li', @title)
...in the same step, and that is working nicely.

This step is called right after clicking an Update button, which is a
standard rails scaffold and does a: redirect_to(@task) - this causes a
partial to be rendered to the screen as part of my default layout, and
I was hoping to be able to verify that the partial loaded.

What would fit my brain better, would be:
response.should render_partial("tasks/list")
...but that isn't available :)

I hope that is clearer - I am quite new to the world of rspec.
If you can shed any more light that would be really great.
Thanks,
Steven


On Sat, May 3, 2008 at 11:17 PM, Rick DeNatale <[EMAIL PROTECTED]> wrote:
>
> On Sat, May 3, 2008 at 4:08 PM, steven shingler <[EMAIL PROTECTED]> wrote:
>  > hi all,
>  >
>  >  i'm just trying to check a partial has been rendered, by using:
>  >  response.template.should_receive(:render).with(:partial => "tasks/list")
>  >
>  >  this passes, even if I put something bogus in the partial name, such as:
>  >  response.template.should_receive(:render).with(:partial =>
>  >  "___tassdfsdfks/list")
>  >
>  >  does anyone know why this doesn't fail?
>  >  is this the wrong way to simply check a partial is being rendered?
>  >  am running this as a story step.
>
>  I'm not sure how this is working to begin with.
>
>  Where is this expectation in the flow of the code?  It would seem to
>  need to be before the request since it's a should_receive
>  But then what's response at this point?
>  And what's response.template?
>
>  It's the controller, not the template which receives the render call.
>
>  You say that this is in a story step? I've got a hunch that the step
>  is'nt actually matching and therfore not getting run, which would
>  explain why the assertion never fails.
>
>  If you're doing this as a full stack rails integration story, I don't
>  believe that you've got access to the controller, and this level of
>  specification doesn't belong here but rather in a controller spec,
>  where you might want to use expect_render instead of
>  should_receive(:render) as well.
>
>  --
>  Rick DeNatale
>
>  My blog on Ruby
>  http://talklikeaduck.denhaven2.com/
>  ___
>  rspec-users mailing list
>  rspec-users@rubyforge.org
>  http://rubyforge.org/mailman/listinfo/rspec-users
>
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] silly partial qu

2008-05-04 Thread Rick DeNatale
On Sun, May 4, 2008 at 10:16 AM, steven shingler <[EMAIL PROTECTED]> wrote:
> Hi Rick,
>  Thanks for your reply.
>  You are right that this step is basically testing the basic actions of
>  a controller, and is being run as part of a story_with_steps stack.
>  The step itself is definitely being hit, because I have a:
>  response.should have_tag('li', @title)
>  ...in the same step, and that is working nicely.
>
>  This step is called right after clicking an Update button, which is a
>  standard rails scaffold and does a: redirect_to(@task) - this causes a
>  partial to be rendered to the screen as part of my default layout, and
>  I was hoping to be able to verify that the partial loaded.
>
>  What would fit my brain better, would be:
>  response.should render_partial("tasks/list")

Except that responses don't render anything, controllers do which
result in the body of the response.

Also even if this were

controller.should render_partial...

I can't see how this would work, since it seems to involve backwards
time travel. In a controller spec you use

   controller.expect_render(:partial => ...)

BEFORE doing a get/post etc.  It works like x.should_receive(:foo)
it's something which needs to be set up before something happens.

>  ...but that isn't available :)
>
>  I hope that is clearer - I am quite new to the world of rspec.
>  If you can shed any more light that would be really great.

Rails integration testing happens in the context of a simulated
browser.  It's awkward, if indeed it's possible at all, to instrument
the mechanisms of controllers and templates here. This is normally
done in controller and/or view specs.

At the story/integration level, I think you really want to be looking
at the result of the http requests, which means you should be setting
expectations about what's in the response rather than how the response
is going to be constructed.

So instead of trying to determine if the tasks_list partial is being
rendered, why not do something like having the partial generate
evidence that it was invoked in the output, for example it might
generate a div or ol or whatever which contains the tasks list which
has a particular dom id, and then use response.should have_tag to
verify that the task list is in the response?

-- 
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] silly partial qu

2008-05-04 Thread steven shingler
Hi Rick - Thanks again.
Cool - I see what you mean about what the story steps should get
involved with, and what should be left to the specs.
In that case, my response.should have_tag('li', @title) is a
reasonable test, and I'll leave it at that!
All the best,
Steven

On Sun, May 4, 2008 at 3:36 PM, Rick DeNatale <[EMAIL PROTECTED]> wrote:
> On Sun, May 4, 2008 at 10:16 AM, steven shingler <[EMAIL PROTECTED]> wrote:
>  > Hi Rick,
>  >  Thanks for your reply.
>  >  You are right that this step is basically testing the basic actions of
>  >  a controller, and is being run as part of a story_with_steps stack.
>  >  The step itself is definitely being hit, because I have a:
>  >  response.should have_tag('li', @title)
>  >  ...in the same step, and that is working nicely.
>  >
>  >  This step is called right after clicking an Update button, which is a
>  >  standard rails scaffold and does a: redirect_to(@task) - this causes a
>  >  partial to be rendered to the screen as part of my default layout, and
>  >  I was hoping to be able to verify that the partial loaded.
>  >
>  >  What would fit my brain better, would be:
>  >  response.should render_partial("tasks/list")
>
>  Except that responses don't render anything, controllers do which
>  result in the body of the response.
>
>  Also even if this were
>
> controller.should render_partial...
>
>  I can't see how this would work, since it seems to involve backwards
>  time travel. In a controller spec you use
>
>controller.expect_render(:partial => ...)
>
>  BEFORE doing a get/post etc.  It works like x.should_receive(:foo)
>  it's something which needs to be set up before something happens.
>
>
>  >  ...but that isn't available :)
>  >
>  >  I hope that is clearer - I am quite new to the world of rspec.
>  >  If you can shed any more light that would be really great.
>
>  Rails integration testing happens in the context of a simulated
>  browser.  It's awkward, if indeed it's possible at all, to instrument
>  the mechanisms of controllers and templates here. This is normally
>  done in controller and/or view specs.
>
>  At the story/integration level, I think you really want to be looking
>  at the result of the http requests, which means you should be setting
>  expectations about what's in the response rather than how the response
>  is going to be constructed.
>
>  So instead of trying to determine if the tasks_list partial is being
>  rendered, why not do something like having the partial generate
>  evidence that it was invoked in the output, for example it might
>  generate a div or ol or whatever which contains the tasks list which
>  has a particular dom id, and then use response.should have_tag to
>  verify that the task list is in the response?
>
>  --
>
>
> Rick DeNatale
>
>  My blog on Ruby
>  http://talklikeaduck.denhaven2.com/
>  ___
>  rspec-users mailing list
>  rspec-users@rubyforge.org
>  http://rubyforge.org/mailman/listinfo/rspec-users
>
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Everyone Using Rspec Autotest?

2008-05-04 Thread Matt Berther

Hi Andrew,

I've been using rspactor (the command line version) and really prefer  
it to autotest. If you're using a Mac, you may want to look at this.


--
Matt Berther
http://www.mattberther.com




On May 3, 2008, at 1:36 PM, Andrew Brown wrote:


I will, once I resolve the error.


On 3-May-08, at 3:21 PM, Jarkko Laine wrote:



On 3.5.2008, at 22.18, Andrew Brown wrote:

I haven't been spec'ing lately, but been hopping back on and  
adding autotest.

However I get an error:

http://pastie.caboo.se/177538/wrap

I also noticed a post by Scott and there was mention of  
rspec_autotest.

Is this is what everyone is using?


I'm just using the one that comes with ZenTest. No need for  
anything else, just run 'autotest' in the root of your Rails app.


//jarkko

--
Jarkko Laine
http://jlaine.net
http://dotherightthing.com
http://www.railsecommerce.com
http://odesign.fi


___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Everyone Using Rspec Autotest?

2008-05-04 Thread Andrew Brown

I am and I will

On 4-May-08, at 12:30 PM, Matt Berther wrote:


rspactor


___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


[rspec-users] Do message expectations work in story steps?

2008-05-04 Thread Rick DeNatale
I've never tried to use them myself, but another list member brought
this up in another thread.

He was using a message expectation in a story step, and couldn't get it to fail.

Looking at what he was doing, it didn't look to me that it would ever
succeed, which got me thinking.

Message expectations are implemented in rspec by asking the mock
framework to verify them after each example by calling
verify_mocks_for_rspec.

This seems to be the only place where this is called, so I've got my
doubts that message expectations ever get verified when a story is
run.

Now, it's not clear just when in a story a message expectation should
be tested, and it's probably the case that they shouldn't be
used/supported in stories.

If so should this be documented somewhere, or is it already?

-- 
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Date comparisons

2008-05-04 Thread s.ross

Hi--

On May 3, 2008, at 9:17 AM, Joe Van Dyk wrote:


I occasionally get this error:

1)
'A puzzle once featured, should no longer be nominated' FAILED
expected: Sun May 04 09:10:26 -0700 2008,
got: Sun May 04 09:10:26 -0700 2008 (using ==)
./spec/models/puzzle_spec.rb:180:



So, the dates looks the same to me.  Any ideas for how to debug?

Joe


I monkeypatched DateTime (aiee!) to get this effect. A custom  
matcher is probably a better solution. Here's the monkeypatch:


require File.dirname(__FILE__) + '/../spec_helper'

class DateTime
def close?(other_date, difference)
(other_date.to_time.to_i - DateTime.now.to_time.to_i).abs <  
difference

end
end

#Delete this context and add some real ones
context "should be able to create a project viewer" do
  fixtures :project_viewers

  specify "fixtures should load two ProjectViewers" do
pb = ProjectViewer.create(:comments => 'a  
comment', :last_viewed_at => DateTime.now)

pb.last_viewed_at.should_be_close(DateTime.now, 100)
  end
end


___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Date comparisons

2008-05-04 Thread Aslak Hellesøy
If your code uses Date#now, always make sure you stub it in your  
specs. Always.


On 5. mai. 2008, at 05.42, "s.ross" <[EMAIL PROTECTED]> wrote:


Hi--

On May 3, 2008, at 9:17 AM, Joe Van Dyk wrote:


I occasionally get this error:

1)
'A puzzle once featured, should no longer be nominated' FAILED
expected: Sun May 04 09:10:26 -0700 2008,
   got: Sun May 04 09:10:26 -0700 2008 (using ==)
./spec/models/puzzle_spec.rb:180:



So, the dates looks the same to me.  Any ideas for how to debug?

Joe


I monkeypatched DateTime (aiee!) to get this effect. A custom  
matcher is probably a better solution. Here's the monkeypatch:


require File.dirname(__FILE__) + '/../spec_helper'

class DateTime
   def close?(other_date, difference)
   (other_date.to_time.to_i - DateTime.now.to_time.to_i).abs <  
difference

   end
end

#Delete this context and add some real ones
context "should be able to create a project viewer" do
 fixtures :project_viewers

 specify "fixtures should load two ProjectViewers" do
   pb = ProjectViewer.create(:comments => 'a  
comment', :last_viewed_at => DateTime.now)

   pb.last_viewed_at.should_be_close(DateTime.now, 100)
 end
end


___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users