Displaying 20 results from an estimated 800 matches similar to: "mocking methods that receive blocks - back to mocking Thread again"
2007 Jan 21
1
A Thread / Mock question
Hi!
What I''m trying at the moment is to build specifications for some
background thread code. What I want is a class Task and a class
TaskRunner. The TaskRunner should run a task in a background thread. It
should also indicate the status of the running task when calling the
running? method.
That''s basically, what I came up with so far:
class TaskRunner
    def initialize
     
2012 May 05
1
rspec-mocks and rspec-rails-2.10.1 are released!
These are patch releases recommended for anybody who has already
upgraded to 2.10.
### rspec-mocks-2.10.1
full changelog: http://github.com/rspec/rspec-mocks/compare/v2.10.0...v2.10.1
Bug fixes
* fix [regression of edge case
behavior](https://github.com/rspec/rspec-mocks/issues/132)
    * fixed failure of
`object.should_receive(:message).at_least(0).times.and_return value`
    * fixed failure
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
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
2013 Jan 14
2
The three-dot question
Dear all,
Why does not the three-dot accept arguments from the parent environment?
I am just confused with this error, can someone give me a hint? 
> rm(list=ls())
> testFun <- function(a, ...)
+   {
+     if(a){
+         print(a)
+       }else
+       {
+         print(b)
+       }
+   }
> 
> myTask <- function(a)
+   {
+     b <- 3
+     testFun(a, b = b)
+   }
>
2013 Feb 18
2
[PATCH v2 2/4] xen/arm: do not use is_running to decide whether we can write directly to the LR registers
During context switch is_running is set for the next vcpu before the
gic state is actually saved.
This leads to possible nasty races when interrupts need to be injected
after is_running is set to the next vcpu but before the currently
running gic state has been saved from the previous vcpu.
Use current instead of is_running to check which one is the currently
running vcpu: set_current is called
2006 Dec 15
3
Partial mock when a complex return value is required
Hi
I''ve come up with a problem using RSpec on a model class in my rails  
app.  I wanted to test that some data was being cached for some  
calculations, so rather than do state-based testing I tried to  
specify that the method that fetches the data should NOT be called  
when I  call the calculate method.  However in doing so I have to  
simulate the return value, which is about 27
2007 Aug 06
1
Stubbing Enumerable#each
I have a mock of an instance of a class which descends from Array:
class ArrayDescendent < Array; end
#... in the specs...
@descendent = mock ArrayDescendent
How would I stub out ArrayDescendent#each, which is inherited from  
Array, to return multiple values successively?  I could use  
and_yield, but that is raising an arity error (the anonymous function/ 
block should expect only *one
2007 Feb 20
6
How to spec code with multiple (interacting) paths
Hi
Code with a large number of different paths is probably the biggest  
problem I have right now.  I''ve made a sample class that illustrates  
the simplest case of one parameter that takes two values:
     class DataStorer
       def initialize(logger, emailer, db_updater, do_update_db_step)
         @logger = logger; @emailer = emailer; @db_updater = db_updater
        
2007 Aug 23
7
TaskBarIcon gives Typerror
Hi,
I''m working with wxruby since 2 days but next to this Wiki: http://wxruby.rubyforge.org/wiki/wiki.pl and this Doc: http://wxruby.rubyforge.org/doc/ I couldn''t find something usefull for it. Also del.icio.us has no intresting links. Do you know any good website or book about wxruby?
My problem at the moment is, I wanna test the TaskBarIcon on Gnome and so I did:
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
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 Jun 04
2
help to understand is_running _on_xen ?
help to understand is_running _on_xen ?
   I don''t  understand why we check this condition is_running_on_xen  ?In all drivers(front & back) code we are checking this condition ?what is this function stands for ? what it does ?
DISCLAIMER:
-----------------------------------------------------------------------------------------------------------------------
The contents of this
2006 Jul 24
6
Mocking causes empty specification blocks
I''ve found myself mocking out a published api in my set-up method.
This has led to some contexts having a large set-up and empty
specifications.  As the mocks get auto-verified, the specification
blocks have nothing to do but serve as documentation.  Does this sound
bad?
Chris
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
 
2006 Oct 23
6
overriding mock expectations
There is one annoyance I''m encountering with the  Mock API in rSpec.   
Overall it works well, as far as dynamic mocks go ;)... but there''s  
this one thing... It doesn''t allow overriding of expectations.
example:
m = mock("blah")
m.should_receive(:one).any_number_of_times().and_return(1)
m.should_receive(:one).and_return(1)
The second call to should_receive
2007 Jun 29
3
[PATCH] Make xendomains ignore lost+found
As requested by Mark Williamson in BZ #681
Signed-off-by: Gawain Lynch <gawain.lynch@gmail.com>
--- xendomains.orig	2006-06-17 14:35:48.000000000 +1000
+++ xendomains	2006-06-17 14:45:29.000000000 +1000
@@ -207,10 +207,11 @@
     if [ "$XENDOMAINS_RESTORE" = "true" ] &&
        contains_something "$XENDOMAINS_SAVE"
     then
+	XENDOMAINS_SAVED=`/bin/ls
2007 Jul 26
5
Coding standards and whitespace
Recently as a result of using Git I''ve noticed a number of  
inconsistencies in the RSpec codebase with respect to whitespace  
(mixed line endings, mixed use of spaces and tabs for indentation,  
and trailing whitespace at the end of lines). I never would have  
noticed, but Git produces nice colorized diff output which highlights  
these kinds of inconsistencies.
I wanted to ask if the
2007 Oct 25
1
Mocking/Stubbing help with subdomain as account key
My app uses account_location to set up subdomains as account keys. In  
my controllers, all my model operations are scoped through the  
@current_person object.
The question is: How do I test this with RSpec''s mocking and  
stubbing? Basically, I need to test that @current_person.things is  
getting the find message and returning @thing. I''ve tried stubbing  
and mocking
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