Re: [rspec-users] how to mock active record relationships

2009-10-21 Thread Christoph ----
Thanks guys, you really helped me a lot where to put my focus on. I will refactor my code to have it more easily being mocked, I thought about this at one point, but kept it for readability. Hope to get my specs up running soon. -- Posted via http://www.ruby-forum.com/.

Re: [rspec-users] Stub that returns hash values

2009-10-21 Thread Stephen Eley
On Wed, Oct 21, 2009 at 1:12 PM, Carl Graff wrote: > > In truth, due to my inexperience and confusion, mocks seem to slow my > development more than just creating real objects. But since there has been > so much effort to put these into testing frameworks, I think it must be > important to try and

Re: [rspec-users] Can't get running a simple rspec test: assigns is always nil

2009-10-21 Thread Stephen Eley
On Wed, Oct 21, 2009 at 1:07 PM, Alexander Seidl wrote: > > But why does this filter prevents the index action from being executed? Because returning 'false' from a filter does exactly that: it prevents the execution of the controller action. I'll bet I know what you're thinking -- you're thinki

Re: [rspec-users] Stub that returns hash values

2009-10-21 Thread Matt Wynne
Hi Carl, Some thoughts below... On 21 Oct 2009, at 18:12, Carl Graff wrote: Well i just started using RSpec about a week ago and mostly I was just trying to learn how to use mocks as I could have easily just created the real object in this case. Anyway, I had a real object, that needed to

Re: [rspec-users] How can I spec protect method

2009-10-21 Thread Matt Wynne
On 21 Oct 2009, at 17:31, Elza wrote: How can I spec the 3rd line of my controller? What does that method do to the other objects in your domain? Can you describe that behaviour easily using mocks and stubs? If not, you would be best to move the method out of the controller and onto an

Re: [rspec-users] Can't get running a simple rspec test: assigns is always nil

2009-10-21 Thread Alexander Seidl
Pat Maddox wrote: > On Wed, Oct 21, 2009 at 3:58 AM, Alexander Seidl > wrote: >> hi pat, >> thats all of the code that will be executed in >> categories_controller_spec.rb. the rest is commented out. > > Looks like this may be the same issue as the other thread. You didn't > show all the code,

Re: [rspec-users] Stub that returns hash values

2009-10-21 Thread Carl Graff
Well i just started using RSpec about a week ago and mostly I was just trying to learn how to use mocks as I could have easily just created the real object in this case. Anyway, I had a real object, that needed to contain a hash of a yet to be created object, which itself contained a hash of a

[rspec-users] How can I spec protect method

2009-10-21 Thread Elza
How can I spec the 3rd line of my controller? update_successful, error_msg = update_channels_association def create @user = User.new(get_param(:user, :hash)) if @user.save update_successful, error_msg = update_channels_association set_flash_if update_successful, :resource_s

Re: [rspec-users] Can't get running a simple rspec test: assigns is always nil

2009-10-21 Thread Alexander Seidl
im repeating this message here in the mailing list with an email. i already answered the message at http://www.ruby-forum.com, but it seems that delivering messages via http://www.ruby-forum.com lasts way too long, so i write an email to the mailing list. hi pat, thats all of the code that wil

Re: [rspec-users] be_none and be_any don't seem to work properly

2009-10-21 Thread David Chelimsky
On Oct 19, 2009, at 2:12 PM, iain wrote: Hi all! I'm testing some named scopes. I use be_all(&:some_predicate) to test if all the elements in the collection are valid, which works, but when I try to test the inverse, it fails. You can see the complete code at: http://gist.github.com/213636 B

Re: [rspec-users] How can I test the values of css style attributes assigned to a div

2009-10-21 Thread David Chelimsky
On Oct 21, 2009, at 8:08 AM, Tom Hoen wrote: My site allows users to change the backround color (among other things) for their page. These values are stored in database. Their choices (or the default) are placed on the page using a block at the end of the block in the layout. Here

Re: [rspec-users] Can't get running a simple rspec test: assigns is always nil

2009-10-21 Thread Pat Maddox
On Wed, Oct 21, 2009 at 3:58 AM, Alexander Seidl wrote: > hi pat, > thats all of the code that will be executed in > categories_controller_spec.rb. the rest is commented out. Looks like this may be the same issue as the other thread. You didn't show all the code, because there's an unknown UserC

Re: [rspec-users] controller code doesn't seem to be called within rspec test

2009-10-21 Thread Pat Maddox
On Wed, Oct 21, 2009 at 6:56 AM, Alexander Seidl wrote: > I started a new test: Have a look at my new code: > http://pastie.org/663455 > > 1) The categories_controller is NOT called from the test! > > 2) I created another example with a message_controller and associated > tests. There, the control

[rspec-users] How can I test the values of css style attributes assigned to a div

2009-10-21 Thread Tom Hoen
My site allows users to change the backround color (among other things) for their page. These values are stored in database. Their choices (or the default) are placed on the page using a block at the end of the block in the layout. Here is what the style block looks like. <% if !!

Re: [rspec-users] controller code doesn't seem to be called within rspec test

2009-10-21 Thread Alexander Seidl
Its definitly that line that causes trouble: class User::CategoriesController < UserController ^ ... end If i change it to: class User::CategoriesController < ActionController::Base ^^^ ... en

Re: [rspec-users] controller code doesn't seem to be called within rspec test

2009-10-21 Thread Alexander Seidl
David Chelimsky wrote: > On Wed, Oct 21, 2009 at 7:19 AM, Alexander Seidl > wrote: > >> http://pastie.org/663143. The test still failes. But it shouldn't! >> > Rails version? > Ruby version? > OS? > etc BTW :) The second example with the message_controller is copied from your Book^^ Cheers, Al

Re: [rspec-users] controller code doesn't seem to be called within rspec test

2009-10-21 Thread Alexander Seidl
David Chelimsky wrote: > On Wed, Oct 21, 2009 at 7:19 AM, Alexander Seidl > wrote: > >> http://pastie.org/663143. The test still failes. But it shouldn't! >> > Rails version? > Ruby version? > OS? > etc :( Really sorry for triple answer. But my mind is weakened by all this RAILS_GEM_VERSION = '2

Re: [rspec-users] controller code doesn't seem to be called within rspec test

2009-10-21 Thread Alexander Seidl
David Chelimsky wrote: > On Wed, Oct 21, 2009 at 7:19 AM, Alexander Seidl > wrote: > >> http://pastie.org/663143. The test still failes. But it shouldn't! >> > Rails version? > Ruby version? > OS? > etc Sorry, forgot OS: alexand...@alexanders-desktop:$ lsb_release -a No LSB modules are available

Re: [rspec-users] controller code doesn't seem to be called within rspec test

2009-10-21 Thread Alexander Seidl
David Chelimsky wrote: > On Wed, Oct 21, 2009 at 7:19 AM, Alexander Seidl > wrote: > >> http://pastie.org/663143. The test still failes. But it shouldn't! >> > Rails version? > Ruby version? > OS? > etc Hi David, alexand...@alexanders-desktop:$ gem list -l rspec *** LOCAL GEMS *** rspec (1.2.9

Re: [rspec-users] controller code doesn't seem to be called within rspec test

2009-10-21 Thread Alexander Seidl
I started a new test: Have a look at my new code: http://pastie.org/663455 1) The categories_controller is NOT called from the test! 2) I created another example with a message_controller and associated tests. There, the controller IS called! You can see that, because the puts statement produce

Re: [rspec-users] Slides from "Uses & Abuses of Mocks & Stubs" at NWRUG

2009-10-21 Thread Ashley Moran
On 21 Oct 2009, at 09:46, Pat Maddox wrote: Response written as I go through the slides, and late at night under sleep deprivation ;) Seems fitting, I wrote them under the exact same conditions =) * 57 juicy slides in half an hour? Damn dude. Well, might have had about 45-50 mins, but the

Re: [rspec-users] controller code doesn't seem to be called within rspec test

2009-10-21 Thread David Chelimsky
On Wed, Oct 21, 2009 at 7:19 AM, Alexander Seidl wrote: > David Chelimsky wrote: > > [...] > > Please quote at least the relevant part of the previous email when you > > respond > > [...] > yes ok, i'll keep that in mind. > > > If you reverse lines 6 and 7 on http://pastie.org/663143, the example

Re: [rspec-users] controller code doesn't seem to be called within rspec test

2009-10-21 Thread Alexander Seidl
David Chelimsky wrote: > [...] > Please quote at least the relevant part of the previous email when you > respond > [...] yes ok, i'll keep that in mind. > If you reverse lines 6 and 7 on http://pastie.org/663143, the example > _should_ pass, so I'm a bit mystified. I changed this two lines. Pleas

Re: [rspec-users] controller code doesn't seem to be called within rspec test

2009-10-21 Thread David Chelimsky
On Wed, Oct 21, 2009 at 6:12 AM, Alexander Seidl wrote: > hi ben, > no impact, same result. > > cheers, > Alexander Please quote at least the relevant part of the previous email when you respond. I can get the context if I'm looking at mail in a web browser. Not so much on my phone. If you reve

Re: [rspec-users] controller code doesn't seem to be called within rspec test

2009-10-21 Thread Alexander Seidl
hi ben, no impact, same result. cheers, Alexander -- Posted via http://www.ruby-forum.com/. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users

Re: [rspec-users] Can't get running a simple rspec test: assigns is always nil

2009-10-21 Thread Alexander Seidl
hi pat, thats all of the code that will be executed in categories_controller_spec.rb. the rest is commented out. i use the newest version of both gems? could that be a bug. which versions of rpsec and rspec-rails do you use? alexand...@alexanders-desktop:$ gem list -l rspec *** LOCAL GEMS ***

Re: [rspec-users] controller code doesn't seem to be called within rspec test

2009-10-21 Thread Ben Lovell
2009/10/21 Alexander Seidl > Alexander Seidl wrote: > > i call current_user in the index-method, but the test fails and says: > > "# expected :current_user with > > (any args) once, but received it 0 times" > > > > Why? > > Try putting line 7 before line 6. Cheers, Ben __

Re: [rspec-users] controller code doesn't seem to be called within rspec test

2009-10-21 Thread Alexander Seidl
Alexander Seidl wrote: > i call current_user in the index-method, but the test fails and says: > "# expected :current_user with > (any args) once, but received it 0 times" > > Why? i forgot "get :index" in test. but anyways, no impact. same result. http://pastie.org/663143 -- Posted via http://

[rspec-users] controller code doesn't seem to be called within rspec test

2009-10-21 Thread Alexander Seidl
i call current_user in the index-method, but the test fails and says: "# expected :current_user with (any args) once, but received it 0 times" Why? Attachments: http://www.ruby-forum.com/attachment/4166/pastie-663143.rb -- Posted via http://www.ruby-forum.com/. _

Re: [rspec-users] stub! and stubs

2009-10-21 Thread Pat Maddox
On Mon, Oct 12, 2009 at 6:26 PM, Scott Taylor wrote: > > On Oct 12, 2009, at 9:14 PM, David Chelimsky wrote: > >> On Oct 12, 2009, at 9:37 PM, Sam Woodard wrote: >> >>> I have an interesting setup:  I am using rspec for mocking but I have >>> mocha installed which give me access to any_instance, e

Re: [rspec-users] Factory_girl Need help

2009-10-21 Thread Pat Maddox
or check out fixjour (http://github.com/nakajima/fixjour/) which is better imo because it has a better API and fewer surprises (associations in factory girl always confuse me) Pat On Mon, Oct 5, 2009 at 3:32 AM, Mithun Perera wrote: > Hi > please any body can help me to learn the basics of Facto

Re: [rspec-users] Slides from "Uses & Abuses of Mocks & Stubs" at NWRUG

2009-10-21 Thread Pat Maddox
Response written as I go through the slides, and late at night under sleep deprivation ;) * 57 juicy slides in half an hour? Damn dude. * Not a fan of the "defining an interface" service example. A single method named #query that accepts a string that appears to have the real command is not much

Re: [rspec-users] Can't get running a simple rspec test: assigns is always nil

2009-10-21 Thread Pat Maddox
Is this all of the code, or did you remove some stuff? I copied the code in a new rails app and the test passed. What versions of rspec & rspec-rails are you running? Pat On Tue, Oct 20, 2009 at 5:23 AM, Alexander Seidl wrote: > http://pastie.org/pastes/661816 > > hi, > please have a look at m

Re: [rspec-users] how to mock active record relationships

2009-10-21 Thread Pat Maddox
user = mock('user') controller.stub(:current_user).and_return user friendships_proxy = mock('friendships proxy') user.stub(:friendships).and_return friendships_proxy friendship = mock('friendship') friendhips_proxy.stub(:build).and_return friendship Try to avoid chains like this. Makes the test s

Re: [rspec-users] Stub that returns hash values

2009-10-21 Thread Ashley Moran
On 21 Oct 2009, at 08:41, Pat Maddox wrote: wait why do you want to do this?? Just use a regular hash and do state-based assertions on it. Or determine the role that this hash-like thing is doing, and use a mock to define a proper interface. Ashley's solution works but I am very skeptical tha

Re: [rspec-users] Stub that returns hash values

2009-10-21 Thread Pat Maddox
wait why do you want to do this?? Just use a regular hash and do state-based assertions on it. Or determine the role that this hash-like thing is doing, and use a mock to define a proper interface. Ashley's solution works but I am very skeptical that the approach is a good one. Can you post som

Re: [rspec-users] how to mock active record relationships

2009-10-21 Thread Ashley Moran
On 21 Oct 2009, at 06:40, Christoph wrote: Hi I am new to Rspec and try to mock my controller that looks like def create @friendship = current_user.friendships.build(:friend_id => params[:friend_id]) if @friendship.save flash[:notice] = "Added friend." render :text => flash[

Re: [rspec-users] spec-ing private methods?

2009-10-21 Thread Pat Maddox
Break your object up. It's too big. On Wed, Oct 14, 2009 at 12:36 PM, Joaquin Rivera Padron wrote: > hello there, > how do you tipically spec private methods? The thing is Ï have something > like this: > > def some_method >    complex_method + other_complex_methods > end > > private > def comple