Displaying 20 results from an estimated 600 matches similar to: "Stubbing Enumerable#each"
2007 Aug 12
5
stubbing a method that yeilds sequential results
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
2008 Jun 05
1
Using and_yield to pass multiple or no iterations
Hi, imagine there''s a class called Egg which has the following method
(which calls another method):
<CODE>
def do_thing
has_iterated = false
self.each_row do |row|
has_iterated = true unless has_iterated
end
has_iterated
end
</CODE>
Stupid code, I know.
I have two questions with it. The first is, would it be possible to set
it up to test the case when each_row
2007 Aug 08
5
and_yield + instance_eval(&block)
I have the following code, which yields instance eval''s the block given:
class Foo
def bar(&blk)
instance_eval &blk
end
def baz
yield
end
end
The effect of this is that self is reassigned:
Foo.new.bar do
# here, self is the instance of Foo
# created by new
end
But normally self is the object in which
Foo.new.bar {...} occurs.
Foo.new.baz do
2007 Apr 20
7
Stubbing Model.new w/ block?
Ok, I followed the advice of the list and moved more code into my
model from my controller. When developing tests for this new code, I
ran into a problem...
My model code creates a receipt object and sets some values on it:
@receipt = Receipt.new do |r|
r.x = 1
r.y = 2
# etc
end
I wanted to be able to stub out Receipt.new so that I could set
expectations on the methods called on the
2007 Nov 04
3
Specing raising error, handling, and then not raising error
Hey guys and gals,
I have a snippet of code:
Net::SMTP(@host, @port, @from_domain) do |smtp|
@emails.each do |email|
begin
smtp.send_message email.encoded, email.from, email.destinations
@emails_sent += 1
rescue Exception => e
# blah
end
end
end
What I want to do is:
Say there are 4 emails.
First email is sent OK
On the second email smtp raises a IOError
2007 Feb 28
12
Specifying that code is called in a block
Not sure if this is possible currently.
I have a section of code like this:
ActiveRecord::Base.transaction do
cow.save!
duck.save!
dog.save!
end
(Names changed to protect the innocent.)
I''d like to specify that the saves run in a transaction. I can do
ActiveRecord::Base.should_receive(:transaction).and_yield
But is there any way to specify that the code is
2007 Jan 25
0
mocking methods that receive blocks - back to mocking Thread again
Hi again,
my last example wasn''t good either. It really makes only sense in the
context of using Thread.
I finally came up with this code, that should now test all important
aspects of running a task in a background thread (to keep it simple, I
left out the exception handling).
see http://pastie.caboo.se/35559 or end of mail.
It seems, TaskRunner is now very well covered by the
2008 Dec 04
3
The RSpec way of doing this? Need help on validating block
Hello, I''m back again with more questions about mocks and how to do good
testing in general. Let''s say I''m writing this EmailSender class and I
want to make it totally awesomely tested with RSpec. Here''s how far I''ve
gotten so far:
require ''net/smtp''
class EmailSender
def send_email
2007 Jul 24
2
Mocking Resolv::DNS?
Hello Rspecers,
I have a rails project where I am calling Resolv::DNS.open and then
using the block to check a domain name.
The code snippet in question is:
domain = "mytest.com"
Resolv::DNS.open do |dns|
@mx = dns.getresources(domain, Resolv::DNS::Resource::IN::MX)
end
I obviously want to stub this out, especially for speed but can''t
quite work out how.
I
2007 Apr 17
8
Verifying that a block calls a method
I have something like the following:
def my_fun
my_fun2 do
raise Error
end
end
I know that I can verify that the method receives my_fun2. How can I
mock/stub out the example to verify that it calls raise Error?
Scott
2006 Dec 12
3
Stubs breaking other things
Hi All
I''m working on converting some existing controller specs to use mocks
and stubs rather than real ActiveRecord objects in a Rails project.
In one of my controller actions, I use a database transaction. So,
the obvious thing to do is have this in my setup block:
Project.stub!(:transaction)
Firstly, is there an easy way to have that stub yield to the block
passed to any
2007 Sep 20
3
Bug? in wxSugar enumerable_controls.rb
Hi,
I wanted to use wxSugar enumerable features to add a method for
returning checked items'' index to the CheckListBox class :
require ''wx_sugar/version''
require ''wx_sugar/wx_classes/control_with_items''
require ''wx_sugar/wx_classes/listctrl''
class Wx::CheckListBox
def checked_items
# use of find_all method from Enumerable
2006 Mar 27
3
Enumerable?
Hi,
Can anyone please point me to some docs on Enumerable. I can''t seem to find
anything on how to use it.
Thanx
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060327/0825d5e8/attachment-0001.html
2006 Jul 06
1
ActiveRecord::find or Enumerable::find
Does anyone know the difference in performance between an
ActiveRecord::find and Enumerable::find (or detect since ActiveRecord
redefines the find method) for a has_many association?
Here is an example:
I have a list that has 10 lines and I want to find the first blank line.
Which approach would be better?
list.lines.detect { |line| line.content == nil }
or
2005 Dec 09
5
Prototype Enumerable, Array and Hash Documentation
Hey guys,
I recently published an article documenting some of the more useful
and interesting parts of Prototype''s Enumerable, Hash and Array objects.
You can find it here: http://encytemedia.com/blog/articles/
2005/12/07/prototype-meets-ruby-a-look-at-enumerable-array-and-hash
If you have any feedback or suggestions, fire away.
Cheers,
-Justin Palmer
2007 Mar 07
0
Simulate an enumerable with a mock
I need to simulate an enumerable class (well, it has one method: each).
The code looks something like this OTTOMH:
class Processor
def initialize(input, output)
@input = input; @output = output
end
def run
@input.each do |row|
@output << ProcessorEngine.new(row).process
end
end
end
This is the best I could come up with:
@input
2008 Jan 26
0
"value must be enumerable" exception when using a sweeper?
Folks,
I''m going slightly crazy here - I implemented a Sweeper in an older app
and used nearly the same exact code in my new app, yet I keep getting
this ''value must be enumerable'' exception. Even after I cut most of the
code away, I still get the error. If anyone can help, I would be much
obliged.
Notes: I''m using Engines... wonder if that could cause a
2013 Jan 31
2
CollectionAssociation shadows Enumerable#count
Hi all,
I realize this behavior is by design, and in some respects the right thing
to do. It also pre-dates the addition of Enumerable#count. I''m wondering,
however, if it''s possible/desirable to allow the caller to access the
Enumerable versions under certain conditions. I originally wrote the up as
an issue, but was informed this would be the better venue. I''m
2008 Jun 11
3
help with test design
I''m having trouble figuring out how to drive the design of a class.
I''m hoping I can get a hint or two from the more experienced BDDers on
this list.
I''m writing an adapter class that sits between a 3rd party library and
my business logic. I would like to extract some information from
objects available from the 3rd party lib and covert them into ruby
objects.
2006 Jun 28
3
Add to enumerable
This might seem like a really daft question, but I couldn''t find an
answer anywhere. How do you add something to an enumerable object?
Something like
var first = $A(getElementsByTagName(''td''));
var second = $A(getElementsByTagName(''tr''));
first.PUSH(second);
where the PUSH is something unknown.
am i supposed to use inject here in some way?
Andreas