[rspec-users] Mocking and stubbing Rails' association extensions

2008-01-10 Thread Chris Kampmeier
I'm having a lot of trouble stubbing out an association extension for some view tests. Example rails code modeling a music album: class Album < ActiveRecord::Base has_many :songs do def streamable find(:all, :conditions => 'streamable = 1') end end end So for a given Album in

Re: [rspec-users] Mocking and stubbing Rails' association extensions

2008-01-10 Thread David Chelimsky
On Jan 10, 2008 12:35 PM, Chris Kampmeier <[EMAIL PROTECTED]> wrote: > I'm having a lot of trouble stubbing out an association extension for > some view tests. Example rails code modeling a music album: > > class Album < ActiveRecord::Base >has_many :songs do > def streamable >find

Re: [rspec-users] Mocking and stubbing Rails' association extensions

2008-01-10 Thread Rick DeNatale
On 1/10/08, Chris Kampmeier <[EMAIL PROTECTED]> wrote: > On 1/10/08, David Chelimsky <[EMAIL PROTECTED]> wrote: > > > album = mock("album") > > songs = mock("songs") > > album.stub!(:songs).and_return(songs) > > songs.stub!(:streamable).and_return(true) > > > > That's the general idea. Specifics wi

Re: [rspec-users] Mocking and stubbing Rails' association extensions

2008-01-10 Thread Chris Kampmeier
On 1/10/08, David Chelimsky <[EMAIL PROTECTED]> wrote: > album = mock("album") > songs = mock("songs") > album.stub!(:songs).and_return(songs) > songs.stub!(:streamable).and_return(true) > > That's the general idea. Specifics will vary for each example. If I do this, I end up with a mock object

Re: [rspec-users] Mocking and stubbing Rails' association extensions

2008-01-10 Thread Chris Kampmeier
On 1/10/08, Rick DeNatale <[EMAIL PROTECTED]> wrote: > > So why not > > songs = [song1, song2, song3] > album.stub!(:songs).and_return(songs) > songs.stub!(:streamable).and_return([song1, song2]) Oh, of course. Thank you. I think my mind was in a rut of "must use mock or mock_model" and I didn't

[rspec-users] specs on private methods

2008-01-10 Thread barsalou
It's interesting that this thread has started because I just ran into this problem. The error I got was: NoMethodError in 'Signup she be a valid mac address' protected method `normalize_mac' called for # ./spec/models/signup_spec.rb:10: Here's the spec: describe Signup do before(:each) do

Re: [rspec-users] specs on private methods

2008-01-10 Thread Francois Wurmus
Apart from private or public methods I see a problem in your test case. You don't make sure that your mac_address is returned in exactly the way you want - you are merely saying it should look like the return value of some (protected) method you call (normalize_mac). Let's assume this method was

Re: [rspec-users] specs on private methods

2008-01-10 Thread Jarkko Laine
On 10.1.2008, at 22.21, Francois Wurmus wrote: > Apart from private or public methods I see a problem in your test > case. > You don't make sure that your mac_address is returned in exactly the > way > you want - you are merely saying it should look like the return > value of > some (protec

Re: [rspec-users] specs on private methods

2008-01-10 Thread Francois Wurmus
Even my suggestion wouldn't be a sufficient spec. What about completely wrong mac addresses? Empty addresses, too many characters, invalid characters? It is not for nothing that the rspec test cases are called examples - you may define any number of example inputs and expected outputs that are

Re: [rspec-users] specs on private methods

2008-01-10 Thread Pat Maddox
On Jan 10, 2008 12:34 PM, Francois Wurmus <[EMAIL PROTECTED]> wrote: > Even my suggestion wouldn't be a sufficient spec. What about completely > wrong mac addresses? Empty addresses, too many characters, invalid > characters? I just sent a reply that crossed wires with yours...anyway, introducing

Re: [rspec-users] specs on private methods

2008-01-10 Thread Francois Wurmus
Yes, you're absolutely right. I somehow ignored the class name in my previous answers, but that would have been the next point of attack. ;-) Pat Maddox schrieb: > On Jan 10, 2008 12:34 PM, Francois Wurmus <[EMAIL PROTECTED]> wrote: >> Even my suggestion wouldn't be a sufficient spec. What abou

Re: [rspec-users] specs on private methods

2008-01-10 Thread Pat Maddox
On Jan 10, 2008 12:25 PM, Jarkko Laine <[EMAIL PROTECTED]> wrote: > Also, this line of code is a bit smelly: > > >> normalized = @signup.normalize_mac(@signup.mac_address) > > Since normalize_mac is an instance method in the Signup class, there's > no point passing the mac_address as a paramet

[rspec-users] Shoulda

2008-01-10 Thread Nathan Sutton
Hey, we're currently using shoulda (http://dev.thoughtbot.com/ shoulda/) on a project and I saw some things that would be really nice to see in rspec, namely the should_ methods, and especially the should_be_restful method. Do these go against the rspec goals at all? Or could an ambitious

Re: [rspec-users] Shoulda

2008-01-10 Thread Josh Knowles
On 1/10/08, Nathan Sutton <[EMAIL PROTECTED]> wrote: > Hey, we're currently using shoulda (http://dev.thoughtbot.com/ > shoulda/) on a project and I saw some things that would be really nice > to see in rspec, namely the should_ methods, and especially the > should_be_restful method. Do these go a

Re: [rspec-users] Shoulda

2008-01-10 Thread Nathan Sutton
Hmm, that includes a good number of them, but there's still the restful resource to think about, which is in my opinion the most valuable one. Would you consider the addition of a restful resource matcher similar to shoulda's? Nathan Sutton [EMAIL PROTECTED] rspec 1.1 rspec_on_rails 1.1 rai

Re: [rspec-users] Shoulda

2008-01-10 Thread Josh Knowles
On 1/10/08, Nathan Sutton <[EMAIL PROTECTED]> wrote: > Hmm, that includes a good number of them, but there's still the > restful resource to think about, which is in my opinion the most > valuable one. Would you consider the addition of a restful resource > matcher similar to shoulda's? Yes. If

Re: [rspec-users] Shoulda

2008-01-10 Thread Nathan Sutton
We'll see if I get around to it. It would be a lot of work, I think, and I know a couple people who have started similar efforts. Nathan Sutton [EMAIL PROTECTED] rspec 1.1 rspec_on_rails 1.1 rails 2.0.2 On Jan 10, 2008, at 5:47 PM, Josh Knowles wrote: > On 1/10/08, Nathan Sutton <[EMAIL PROTE

Re: [rspec-users] Shoulda

2008-01-10 Thread Nathan Sutton
Also, that strikes me as strange that the current philosophy is that for the rspec_on_rails plugin. I would think rails-specific matchers would be endorsed at some point, since rails is so big on convention. Nathan Sutton [EMAIL PROTECTED] rspec 1.1 rspec_on_rails 1.1 rails 2.0.2 On Jan 10,

Re: [rspec-users] Shoulda

2008-01-10 Thread David Chelimsky
On Jan 10, 2008 5:50 PM, Nathan Sutton <[EMAIL PROTECTED]> wrote: > Also, that strikes me as strange that the current philosophy is that > for the rspec_on_rails plugin. I would think rails-specific matchers > would be endorsed at some point, since rails is so big on convention. It's actually qui

Re: [rspec-users] Shoulda

2008-01-10 Thread Nathan Sutton
There David goes, making sense again. Nathan Sutton [EMAIL PROTECTED] rspec 1.1 rspec_on_rails 1.1 rails 2.0.2 On Jan 10, 2008, at 5:59 PM, David Chelimsky wrote: > On Jan 10, 2008 5:50 PM, Nathan Sutton <[EMAIL PROTECTED]> > wrote: >> Also, that strikes me as strange that the current philosop

Re: [rspec-users] Shoulda

2008-01-10 Thread David Chelimsky
On Jan 10, 2008 6:02 PM, Nathan Sutton <[EMAIL PROTECTED]> wrote: > Nathan Sutton > [EMAIL PROTECTED] > rspec 1.1 > rspec_on_rails 1.1 > rails 2.0.2 I love that your sig has your rspec and rails versions. That cracks me up. ___ rspec-users mailing list r

Re: [rspec-users] Shoulda

2008-01-10 Thread Jonathan Leighton
On Thu, 2008-01-10 at 17:59 -0600, David Chelimsky wrote: > Another issue is BDD philosophy. BDD is about behaviour. should > have_many(:posts) is not behaviour. It is structure. I understand that > there are people who view this differently, and I would not want to > get in the way of anyone using

Re: [rspec-users] Shoulda

2008-01-10 Thread James Deville
Speaking for myself, since I support the same philosophy, I wouldn't test the association. I don't care that it has_many posts. I might care that I can add multiple posts, or that I can find posts by criteria, so I would test that. JD On Jan 10, 2008, at 4:04 PM, Jonathan Leighton wrote: >

Re: [rspec-users] Shoulda

2008-01-10 Thread Nathan Sutton
Hey now! Really though, have you ever been digging through old mailing lists and wondered which version they were using when they had that issue? Or when someone posts and issue, you need to ask them what versions of everything they're using? It can be a pain and it usually wastes time/e

[rspec-users] Peepcode RSpec User Stories

2008-01-10 Thread Shane Mingins
http://peepcode.com/products/rspec-user-stories Shane Mingins ELC Technologies (TM) 1921 State Street Santa Barbara, CA 93101 Phone: +64 4 568 6684 Mobile: +64 21 435 586 Email: [EMAIL PROTECTED] AIM: ShaneMingins Skype: shane.mingins (866) 863-7365 Tel - Santa Barbara Office (866) 893-19

Re: [rspec-users] Shoulda

2008-01-10 Thread David Chelimsky
On Jan 10, 2008 6:04 PM, Jonathan Leighton <[EMAIL PROTECTED]> wrote: > On Thu, 2008-01-10 at 17:59 -0600, David Chelimsky wrote: > > Another issue is BDD philosophy. BDD is about behaviour. should > > have_many(:posts) is not behaviour. It is structure. I understand that > > there are people who v

Re: [rspec-users] Shoulda

2008-01-10 Thread David Chelimsky
On Jan 10, 2008 6:07 PM, Nathan Sutton <[EMAIL PROTECTED]> wrote: > Hey now! Really though, have you ever been digging through old > mailing lists and wondered which version they were using when they had > that issue? Or when someone posts and issue, you need to ask them > what versions of everyt

Re: [rspec-users] Shoulda

2008-01-10 Thread Nathan Sutton
Well then, hop to! ;) Nathan Sutton [EMAIL PROTECTED] rspec 1.1 rspec_on_rails 1.1 rails 2.0.2 On Jan 10, 2008, at 6:10 PM, David Chelimsky wrote: > On Jan 10, 2008 6:07 PM, Nathan Sutton <[EMAIL PROTECTED]> > wrote: >> Hey now! Really though, have you ever been digging through old >> mailing

Re: [rspec-users] Shoulda

2008-01-10 Thread James Deville
On Jan 10, 2008, at 4:11 PM, Nathan Sutton wrote: > Well then, hop to! ;) > Nathan Sutton > [EMAIL PROTECTED] > rspec 1.1 > rspec_on_rails 1.1 > rails 2.0.2 > > On Jan 10, 2008, at 6:10 PM, David Chelimsky wrote: > >> On Jan 10, 2008 6:07 PM, Nathan Sutton <[EMAIL PROTECTED]> >> wrote: >>> Hey no

Re: [rspec-users] Shoulda

2008-01-10 Thread Jonathan Leighton
On Thu, 2008-01-10 at 18:09 -0600, David Chelimsky wrote: > It has more to do with what I'm looking at in my specs than what lies > under the hood. Why do I care if a visitor has_many(:posts)? Maybe > there is something different about a blogger with no posts vs one with > 50. So I'd have an exampl

Re: [rspec-users] Shoulda

2008-01-10 Thread Jonathan Leighton
On Thu, 2008-01-10 at 18:47 -0500, Josh Knowles wrote: > On 1/10/08, Nathan Sutton <[EMAIL PROTECTED]> wrote: > > Hmm, that includes a good number of them, but there's still the > > restful resource to think about, which is in my opinion the most > > valuable one. Would you consider the addition o

Re: [rspec-users] Shoulda

2008-01-10 Thread Pat Maddox
On Jan 10, 2008 4:17 PM, Jonathan Leighton <[EMAIL PROTECTED]> wrote: > In principle, yes. But what if your association isn't that interesting. > What if it is literally has_many :posts and that's it. You still want to > make sure it will work (for instance that the posts.blogger_id column > actual

Re: [rspec-users] Shoulda

2008-01-10 Thread Nathan Sutton
You should browse over how shoulda does it here: http://thoughtbot.com/projects/shoulda/tutorial/controllers and here: http://dev.thoughtbot.com/shoulda/classes/ThoughtBot/Shoulda/Controller/ClassMethods.html Nathan Sutton [EMAIL PROTECTED] rspec 1.1 rspec_on_rails 1.1 rails 2.0.2 On Jan 10, 200

Re: [rspec-users] Shoulda

2008-01-10 Thread David Chelimsky
On Jan 10, 2008 6:48 PM, Nathan Sutton <[EMAIL PROTECTED]> wrote: > You should browse over how shoulda does it here: > http://thoughtbot.com/projects/shoulda/tutorial/controllers Or how others are supplying plugins for rspec: http://weblog.techno-weenie.net/2007/12/26/controller-specs-are-a-drag

Re: [rspec-users] Shoulda

2008-01-10 Thread Nathan Sutton
That too :) Nathan Sutton [EMAIL PROTECTED] rspec 1.1 rspec_on_rails 1.1 rails 2.0.2 On Jan 10, 2008, at 6:59 PM, David Chelimsky wrote: > On Jan 10, 2008 6:48 PM, Nathan Sutton <[EMAIL PROTECTED]> > wrote: >> You should browse over how shoulda does it here: >> http://thoughtbot.com/projects/s

[rspec-users] guide to good mocking?

2008-01-10 Thread Giles Bowkett
Hi all - does anyone know of a good blog post or wiki or something with a good guide to mocking? I've got some degree of responsibility for people who are creating mocks. I'm supposed to actually be telling them the best way to do it. In some cases we have code with like a bazillion mock(:x) state

Re: [rspec-users] guide to good mocking?

2008-01-10 Thread David Chelimsky
On Jan 10, 2008 7:24 PM, Giles Bowkett <[EMAIL PROTECTED]> wrote: > Hi all - does anyone know of a good blog post or wiki or something > with a good guide to mocking? http://www.jmock.org/oopsla2004.pdf Cheers, David >I've got some degree of responsibility > for people who are creating mocks. I'

[rspec-users] Missing methods

2008-01-10 Thread James Deville
We have a custom implementation of the Mother Object idea. It's inside of a module, basically like this: module Factory %w(account friendship person invitation message asset email_address birth).each do |klass| eval <<-EOF def self.create_#{klass}(attrib

[rspec-users] changes in rspec's trunk and autotest

2008-01-10 Thread David Chelimsky
This applies to anyone using rspec's trunk from >= 3220 with ZenTest <= 3.7.2. Anyone else, feel free to move on The next release of ZenTest, coming soon, includes some changes that improve the relationship between Autotest, it's subclasses (like those in rspec) and .autotest, the file that y

Re: [rspec-users] guide to good mocking?

2008-01-10 Thread Steven Baker
> Hi all - does anyone know of a good blog post or wiki or something > with a good guide to mocking? I've got some degree of responsibility > for people who are creating mocks. I'm supposed to actually be telling > them the best way to do it. There's ots of good stuff in here: http://martinfowler

Re: [rspec-users] Missing methods

2008-01-10 Thread John D. Hume
Your implementation looks so much like a ModelFactory my team implemented last week that it's scary. Anyway ... Is it a typo that you show the "create_..." methods being def'd as module methods (i.e., "def self.create...") while the "valid_..._attribute" methods are instance methods? That would

Re: [rspec-users] Missing methods

2008-01-10 Thread James Deville
It's not a typo. However, since I'm not the only one to think this, I might make a set of module methods, which can be called by the non- module methods to avoid breaking the current specs. Any idea why one works (specs) and the other doesn't (stories)? James Deville http://devillecompanies.

Re: [rspec-users] Missing methods

2008-01-10 Thread Scott Taylor
On Jan 10, 2008, at 8:27 PM, James Deville wrote: > We have a custom implementation of the Mother Object idea. It's inside > of a module, basically like this: > > module Factory > %w(account friendship person invitation message asset email_address > birth).each do |klass| > e