Re: [rspec-users] Problems with array mock

2007-08-07 Thread Don Petersen
Have a look at this:
http://pastie.textmate.org/85317

That should work out.

Don

On Aug 6, 2007, at 2:04 PM, Gaston Ramos wrote:

 El lun, 06 de ago de 2007, a las 11:52:28 -0500, David Chelimsky dijo:
 On 8/6/07, Gaston Ramos [EMAIL PROTECTED] wrote:

 Hi everyone,

 I'm trying this in my helper spec and it didn't work:

 @curr_odontogram.should_receive('photos[1]').and_return(@photo)

 and the error is:

 SyntaxError in 'PersonHelper Deberia devolverme un link para  
 eliminar una foto'
 compile error
 /home/gramos/src/rails/r-dental/config/../vendor/plugins/rspec/ 
 lib/spec/mocks/proxy.rb:99:
 syntax error, unexpected '[', expecting '\n' or ';'
   def photos[1](*args, block)

 does anyone have a good solution for this?

 the complete code of the helper:

 http://pastie.caboo.se/85287

 the complete code of the spec helper:

 http://pastie.caboo.se/85289

 This is ruby magic causing confusion. When you call foo.photos[1],
 you're actually calling foo.photos[](1) (though that won't work) - so
 I *think* the expectation should read:

 @curr_odontogram.should_receive(:photos[]).with(1).and_return(@photo)

 Give that a try.

 I tried this:
 @curr_odontogram.should_receive(:photos[]).with(1).and_return(@photo)

 and I have this error:

 NoMethodError in 'PersonHelper Deberia devolverme un link para  
 eliminar una
 foto'
 undefined method `[]' for :photos:Symbol




 See you.
 --
 Gastón Ramos

 GNU/Linux Counter user #450312
 http://gastonramos.wordpress.com/

 No a la Matricula Obligatoria
 http://noalamatricula.wordpress.com/about/
 ___
 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


 -- 
 Gastón Ramos

 GNU/Linux Counter user #450312
 http://gastonramos.wordpress.com/

 No a la Matricula Obligatoria
 http://noalamatricula.wordpress.com/about/
 ___
 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] Rspec controller test

2007-08-07 Thread Shaker

Great Hi to everybody!
I am currently working on a project which tests the controllers using rspec.
I came across some methods in the controller which do not generate any
actions at all. However, they still need testing! Some of these methods do
require parameters. I am wondering how I can pass the test cases as the
parameters to these targeted methods in the controller spec?? Below is a
simple example for illustration:
in the controller:
def method_for_test(parameter_1, parameter_2)
#do some coding
#no action
end

in the controller_spec:
it should test the method_for_test do
parameter_1
parameter_2
??how to pass them to method_for_test
end

Thank you all in advance.
-- 
View this message in context: 
http://www.nabble.com/Rspec-controller-test-tf4229016.html#a12030820
Sent from the rspec-users mailing list archive at Nabble.com.

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


Re: [rspec-users] Rspec controller test

2007-08-07 Thread David Chelimsky
On 8/7/07, Shaker [EMAIL PROTECTED] wrote:

 Great Hi to everybody!
 I am currently working on a project which tests the controllers using rspec.
 I came across some methods in the controller which do not generate any
 actions at all. However, they still need testing! Some of these methods do
 require parameters. I am wondering how I can pass the test cases as the
 parameters to these targeted methods in the controller spec?? Below is a
 simple example for illustration:
 in the controller:
 def method_for_test(parameter_1, parameter_2)
 #do some coding
 #no action
 end

 in the controller_spec:
 it should test the method_for_test do
 parameter_1
 parameter_2
 ??how to pass them to method_for_test
 end

controller.method_for_test(arg1, arg2)


 Thank you all in advance.
 --
 View this message in context: 
 http://www.nabble.com/Rspec-controller-test-tf4229016.html#a12030820
 Sent from the rspec-users mailing list archive at Nabble.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


[rspec-users] stubs which yield and return

2007-08-07 Thread Scott Taylor

Is there any reason why a stub couldn't both yield and return?  I'm  
looking for a way to mock out a class I've made named AnonymousClass:

class AnonymousClass

   def initialize(blk)
 @klass = Class.new
 @klass.instance_eval(blk) if block_given?
   end

   def new
 @klass.new
   end

   def evaluate(blk)
 @klass.instance_eval(blk)
   end

   attr_reader :klass
   alias_method :class, :klass
end

One of the behaviours of the AnonymousClass is that new can take a  
block, and eval the block in the anonymous class, represented by the  
@klass instance_variable:

ac = AnonymousClass.new do
   include Enumerable
end

So is there a way to stub AnonymousClass.new such that it yield an  
AnonymousClass mock, as well as yielding to the block given?  What  
are the technical challenges involved in implementing this in the  
mocking framework?  Or is it a matter of clean syntax?

Regards,

Scott


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


Re: [rspec-users] stubs which yield and return

2007-08-07 Thread Scott Taylor

On Aug 7, 2007, at 12:54 PM, David Chelimsky wrote:

 On 8/7/07, Scott Taylor [EMAIL PROTECTED] wrote:

 Is there any reason why a stub couldn't both yield and return?

 Yes. Nobody ever asked for it :)

 Again - this simply hasn't come up. Please add an RFE and feel free to
 submit a patch.


Will do.  I think for now I'm going to override the stub in the  
individual
spec to yield.

More importantly, I'm going to get autotest to work w/ rspec's native
development before I do anymore rspec work.  The time to run the
full test suite is absolutely unbearable on my Mac G4.

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


[rspec-users] Problems with raising errors on a mocked object

2007-08-07 Thread Eivind Uggedal
I'm trying to mock a object to raise a certain error. By doing so I
get a ArgumentError on ActiveRecord's save! method:

http://pastie.caboo.se/85628

I've tried to debug it but just can't seem to find what I'm doing
wrong. Any help is greatly appreciated.

Cheers,
Eivind Uggedal
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


[rspec-users] and_yield + instance_eval(block)

2007-08-07 Thread Scott Taylor

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

   # self is the execution context
   # in which Foo.new was called,
   # since a block is a closure

end


The second case is easy; it is covered by and_yield (with no arguments).

Is there some way to spec the first case?  Do I smell the need for a  
patch?

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


Re: [rspec-users] and_yield + instance_eval(block)

2007-08-07 Thread Scott Taylor
Duh.  I should be using and_return(), not and_yield(), since I am  
actually returning the value
of the instance eval.  The method in question takes one parameter, a  
proc obj (as block).  But
how can I get a handle on that object (since it is anonymous)?

Scott

On Aug 7, 2007, at 9:14 PM, Scott Taylor wrote:


 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

# self is the execution context
# in which Foo.new was called,
# since a block is a closure

 end


 The second case is easy; it is covered by and_yield (with no  
 arguments).

 Is there some way to spec the first case?  Do I smell the need for a
 patch?

 Scott
 ___
 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 raising errors on a mocked object

2007-08-07 Thread David Chelimsky
On 8/7/07, Eivind Uggedal [EMAIL PROTECTED] wrote:
 I'm trying to mock a object to raise a certain error. By doing so I
 get a ArgumentError on ActiveRecord's save! method:

 http://pastie.caboo.se/85628

 I've tried to debug it but just can't seem to find what I'm doing
 wrong. Any help is greatly appreciated.

Please run this:

ruby script/spec ./spec/controllers/users_controller_spec.rb -b

That will give the complete backtrace for the failure, which I'd ask
you to pastie as well.


 Cheers,
 Eivind Uggedal
 ___
 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] Failed to pass arguments to controller method

2007-08-07 Thread Shaker

Good morning to everyone:
So weird!!
I got a method called apply_settings(arg1, arg2) in the controller to be
tested. In the controller spec, I of course called the method. 
In the controller:
def apply_settings(arg1, arg2) #where arg1 is a hash, and arg2 is an
array of object
  #do some coding
end
In the controller spec:
before(:each) do
  @controller = Controller.new
end

it should test the apply_settings do
  @controller.apply_settings(Hash.new, array_of_object) #where the
arguments are exactly some format

#as required
end

However, it yielded wrong number of arguments(0 for 1) error after I ran
the spec. It there anything wrong in my spec?

Cheers!

-- 
View this message in context: 
http://www.nabble.com/Failed-to-pass-arguments-to-controller-method-tf4233633.html#a12045114
Sent from the rspec-users mailing list archive at Nabble.com.

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


Re: [rspec-users] Failed to pass arguments to controller method

2007-08-07 Thread David Chelimsky
On 8/7/07, Shaker [EMAIL PROTECTED] wrote:

 Good morning to everyone:
 So weird!!
 I got a method called apply_settings(arg1, arg2) in the controller to be
 tested. In the controller spec, I of course called the method.
 In the controller:
 def apply_settings(arg1, arg2) #where arg1 is a hash, and arg2 is an
 array of object
   #do some coding
 end
 In the controller spec:
 before(:each) do
   @controller = Controller.new
 end

 it should test the apply_settings do
   @controller.apply_settings(Hash.new, array_of_object) #where the
 arguments are exactly some format

 #as required
 end

 However, it yielded wrong number of arguments(0 for 1) error after I ran
 the spec. It there anything wrong in my spec?

Difficult to say with the little bit of code you're posting. It would
be a lot easier to help if you posted the full code of the spec'd
method, the spec, and the resulting backtrace.
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Problems with raising errors on a mocked object

2007-08-07 Thread Eivind Uggedal
Here you go: http://pastie.caboo.se/85876

Eivind

On 8/8/07, David Chelimsky [EMAIL PROTECTED] wrote:
 On 8/7/07, Eivind Uggedal [EMAIL PROTECTED] wrote:
  I'm trying to mock a object to raise a certain error. By doing so I
  get a ArgumentError on ActiveRecord's save! method:
 
  http://pastie.caboo.se/85628
 
  I've tried to debug it but just can't seem to find what I'm doing
  wrong. Any help is greatly appreciated.

 Please run this:

 ruby script/spec ./spec/controllers/users_controller_spec.rb -b

 That will give the complete backtrace for the failure, which I'd ask
 you to pastie as well.

 
  Cheers,
  Eivind Uggedal
  ___
  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