[rspec-users] stubbing a method that yeilds sequential results

2007-08-12 Thread rupert
I've just found myself stuck trying to rspec something so am hoping  
someone more knowledgable can help.

I have a Connector class which has a class method 'results' that  
yields results it get from a network service based on a set of  
attributes that I pass to it.  I am wanting to yield these results  
from my Intermediate class up to the next 'level' so the basic no  
frills set up would be this:

class Intermediate
   def self.results(attributes)
 Connector.each_result(attributes) do |result|
   yield result
 end
   end
end

I've worked out how to stub things for the case where the Connector.  
each_result method yields a result once

#setup
@result = mock(result)
Connector.stub!(:each_result).and_yield(@result)

@attributes = {}
@results = []
@block = Proc.new { |r| @results  r }

#action
Intermediate.search_results(@attributes, @block)

# expectation
@results.should == [EMAIL PROTECTED]


However, what I actually need to do is check each result that is  
yielded by the Connector.each_result method and compare it to the  
previous one.  If they are sufficiently similar I need to merge them  
(and same again if the next result is sufficiently similar). I only  
want to yeild merged results and results that are not similar to  
their preceeding result(s) - I'd imagined he code to do this would be  
something along the lines of:

class Intermediate
   def self.results(attributes)
 @saved_result = nil

 Connector.each_result(attributes) do |result|
   if results_match(result, @saved_result)
 @saved_result.merge!(result)
   else
 yield @saved_result unless @saved_result.nil?
 @saved_result = result
   end
 end
 yield @saved_result unless @saved_result.nil?
   end

   def results_match(this, last)
 return false if last.nil?
 
   end
end

I can't for the life of me see how I should spec this though, as trying:

Connector.stub!(:results).and_yield(@result1, @result2)

is expecting the two results to be yielded at the same time and not  
sequentially. I can't see how to stub a method to yield sequential  
results so I can spec the behavior for different scenarios of  
similarities between subsequent results.  Is it possible to do this?

Any help would be much appreciated

Cheers

Rupert

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


Re: [rspec-users] stubbing a method that yeilds sequential results

2007-08-12 Thread David Chelimsky
On 8/12/07, rupert [EMAIL PROTECTED] wrote:
 I've just found myself stuck trying to rspec something so am hoping
 someone more knowledgable can help.

 I have a Connector class which has a class method 'results' that
 yields results it get from a network service based on a set of
 attributes that I pass to it.  I am wanting to yield these results
 from my Intermediate class up to the next 'level' so the basic no
 frills set up would be this:

 class Intermediate
def self.results(attributes)
  Connector.each_result(attributes) do |result|
yield result
  end
end
 end

 I've worked out how to stub things for the case where the Connector.
 each_result method yields a result once

 #setup
 @result = mock(result)
 Connector.stub!(:each_result).and_yield(@result)

 @attributes = {}
 @results = []
 @block = Proc.new { |r| @results  r }

 #action
 Intermediate.search_results(@attributes, @block)

 # expectation
 @results.should == [EMAIL PROTECTED]


 However, what I actually need to do is check each result that is
 yielded by the Connector.each_result method and compare it to the
 previous one.  If they are sufficiently similar I need to merge them
 (and same again if the next result is sufficiently similar). I only
 want to yeild merged results and results that are not similar to
 their preceeding result(s) - I'd imagined he code to do this would be
 something along the lines of:

 class Intermediate
def self.results(attributes)
  @saved_result = nil

  Connector.each_result(attributes) do |result|
if results_match(result, @saved_result)
  @saved_result.merge!(result)
else
  yield @saved_result unless @saved_result.nil?
  @saved_result = result
end
  end
  yield @saved_result unless @saved_result.nil?
end

def results_match(this, last)
  return false if last.nil?
  
end
 end

 I can't for the life of me see how I should spec this though, as trying:

 Connector.stub!(:results).and_yield(@result1, @result2)

 is expecting the two results to be yielded at the same time and not
 sequentially.

I'm pretty sure you can get what you want by using should_receive
instead of stub and doing this:

Connector.should_receive(:results).and_yield(@result1)
Connector.should_receive(:results).and_yield(@result2)

 I can't see how to stub a method to yield sequential
 results so I can spec the behavior for different scenarios of
 similarities between subsequent results.  Is it possible to do this?

 Any help would be much appreciated

 Cheers

 Rupert

 ___
 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] 1.0.6 gotcha

2007-08-12 Thread David Chelimsky
Hi All - I released 1.0.6 this morning, but there is apparently a bug
related to rspec and autotest. I'll be fixing this today (but not
until tonight) so you have two options:

Wait until 1.0.7 (tonight)

Upgrade now to 1.0.6 but make sure you install the rspec gem.

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


Re: [rspec-users] 1.0.6 gotcha

2007-08-12 Thread Ian Leitch
Cheers David, I've been waiting patiently for this release :)

I think I might wait for a rainy day until I upgrade though (I'm not using
autotest btw)..

1469 examples, 62 failures

It's good to see you (and the rest of the team) give credit where credit is
due. I was half expecting the contributors list to stay the same with this
release. I'm glad to see that it didn't, I only wish more projects accepted
contributions so graciously.

Cheers
Ian

On 12/08/07, David Chelimsky [EMAIL PROTECTED] wrote:

 Hi All - I released 1.0.6 this morning, but there is apparently a bug
 related to rspec and autotest. I'll be fixing this today (but not
 until tonight) so you have two options:

 Wait until 1.0.7 (tonight)

 Upgrade now to 1.0.6 but make sure you install the rspec gem.

 Thanks,
 David
 ___
 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] Problems with RESTfully generated helpers

2007-08-12 Thread Jay Levitt
David Chelimsky wrote:
 On 8/10/07, Lance Carlson [EMAIL PROTECTED] wrote:
 Thanks for your patience trying to resolve this issue. I posted a bug
 report here:

 http://rubyforge.org/tracker/index.php?func=detailaid=12963group_id=797atid=3149
 
 I see it - thanks. If you have time now, Lance, pls join the #rspec IRC chat.

How did this chat go, if it went?  I'm about to dive into this problem 
but don't want to duplicate efforts.

Jay

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


Re: [rspec-users] Problems with RESTfully generated helpers

2007-08-12 Thread Lance Carlson
It was never resolved.. the only resolution was to mock out the
methods at this point or provide the views with the instance
variables.

On 8/12/07, Jay Levitt [EMAIL PROTECTED] wrote:
 David Chelimsky wrote:
  On 8/10/07, Lance Carlson [EMAIL PROTECTED] wrote:
  Thanks for your patience trying to resolve this issue. I posted a bug
  report here:
 
  http://rubyforge.org/tracker/index.php?func=detailaid=12963group_id=797atid=3149
 
  I see it - thanks. If you have time now, Lance, pls join the #rspec IRC 
  chat.

 How did this chat go, if it went?  I'm about to dive into this problem
 but don't want to duplicate efforts.

 Jay

 ___
 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] Problems with RESTfully generated helpers

2007-08-12 Thread Jay Levitt
Lance Carlson wrote:
 It was never resolved.. the only resolution was to mock out the
 methods at this point or provide the views with the instance
 variables.

Well, I didn't get anywhere tonight - but I did discover that 
script/console has the same problem.  Given routes.rb:

map.resources :users, :member =
 {:edit_business_card = :get,
  :update_business_card = :put }

and:

  app.update_business_card_user_url

I get:

ActionController::RoutingError: update_business_card_user_url failed to 
generate from {:controller=users, :action=update_business_card} - 
you may have ambiguous routes, or you may need to supply additional 
parameters for this route.  content_url has the following required 
parameters: [users, :id, update_business_card] - are they all satisfied?

Yet using update_business_card_user_url from a view works fine.

Since I can duplicate it without rspec, I'll post a message to 
rubyonrails-talk and see if anyone has some ideas.

Jay

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