From armin.joellenbeck at googlemail.com Tue Jan 1 07:33:05 2008 From: armin.joellenbeck at googlemail.com (Armin Joellenbeck) Date: Tue, 1 Jan 2008 13:33:05 +0100 Subject: [rspec-users] executing code after each step of a story In-Reply-To: <20071231175359.GB24657@chello.nl> References: <4a117bfc0712261338y789f13a4p35f6b9546d3a7905@mail.gmail.com> <57c63afe0712261348l31537bd2m96eb343b9ed1a14f@mail.gmail.com> <20071231175359.GB24657@chello.nl> Message-ID: <4a117bfc0801010433u35bfedf7o9f4508184c018777@mail.gmail.com> Hello and happy new year, David's answer and some digging in RDoc of RSpec has lead to the following code sceleton: class Listener def run_started(number_of_scenarios) end def run_ended end def story_started(title, description) end def story_ended(title, description) end def scenario_started(story_title, scenario_title) end def scenario_succeeded(story_title, scenario_title) end def scenario_failed(story_title, scenario_title, exception) end def scenario_pending(story_title, scenario_title, message) end def step_succeeded(kind_of_step, step_line, *args) end def step_failed(kind_of_step, step_line, *args) end def step_pending(kind_of_step, step_line, *args) end def collected_steps(*args) end end Spec::Story::Runner.register_listener(Listener.new) The above instance methods of Listener has to be implemented. The seem to me self-explaining. Only the last one, Listener# collected_steps, needs further investigation. But I have not needed it yet. Hope this helps, Armin From bryan at osesm.com Tue Jan 1 10:34:18 2008 From: bryan at osesm.com (Bryan Liles) Date: Tue, 1 Jan 2008 10:34:18 -0500 Subject: [rspec-users] How to run stories with `spec' command? In-Reply-To: References: <00360231-66F2-4DB7-A944-EF7612AA0A87@osesm.com> Message-ID: <267568A1-90C9-453E-A4A8-A9FCD82A42CE@osesm.com> On Dec 31, 2007, at 9:22 PM, Chiyuan Zhang wrote: > Hmm, Thanks for your suggestion. I suppose the document of stories > for rspec is not complete yet? Maybe the file layout suggestion could > be included in the document. > > ps: Happy New Year to all! Stories are still a moving target. I was suggesting one possibility, but I do believe that Bryan H's idea has merit as well, and I may include parts of his in my ultimate solution (while the jury is still out on official rspec endorsed method) From sera at fhwang.net Tue Jan 1 13:48:04 2008 From: sera at fhwang.net (Francis Hwang) Date: Tue, 1 Jan 2008 13:48:04 -0500 Subject: [rspec-users] Mocks? Really? In-Reply-To: <85d99afe0712311010h5f95a862oa82789b4df59ae5c@mail.gmail.com> References: <139c56460712060856i6bb410fcl23def3b16c0388b4@mail.gmail.com> <810a540e0712261223u4a0f375bqa3f63f6a4711cb60@mail.gmail.com> <85d99afe0712270613i2d221e35m6f9a34b8c7de4f04@mail.gmail.com> <57c63afe0712291407h5eec4eajabb50f7b3c763e09@mail.gmail.com> <8DD055F8-AFDD-4AC5-8258-C21F452C861D@fhwang.net> <4777E8D5.4030907@shopwatch.org> <66AFA127-0223-444F-A4CA-7E31253182CC@fhwang.net> <4778561C.7030608@shopwatch.org> <02ED17FC-3B18-4DBF-A9E9-A063AC49024C@fhwang.net> <85d99afe0712311010h5f95a862oa82789b4df59ae5c@mail.gmail.com> Message-ID: On Dec 31, 2007, at 1:10 PM, Zach Dennis wrote: > I don't think it is "designing less" either. It's designing better > and doing it smarter, knowing that you'll never fully comprehend > the domain of your problem upfront, so you discover it, > iteratively. As you discover more about the domain the design of > your program changes (during refactoring) to support a domain model > to which it is representing. > > This is a concept from Domain Driven Design. > > It Francis is referring to doing less upfront design to try to > master it all from the outset, then I agree that less of that is > better. But that is entirely different then just doing less design. I'm not certain how much we're genuinely disagreeing here and how much we're talking past each other -- I'm certainly feeling like I'm not communicating my amorphous ideas very well. One thing that seems fuzzy to me is the implied time frames here. Let me ask you this, Zach: Is it your aim that your released code always contains a set of classes whose interactions with other classes is well-structured and defined, through mocks, and other tools? And is it your belief that you can always seek to release code which embodies a precise understanding of the domain in question? I suppose part of what I'm saying is that sometimes, for non- programmer reasons, the domain itself is too fuzzy or too quickly shifting to try to nail down with a well-structured design. Sometimes you just release code that amorphously hints at a future design -- and in those cases, a strong test suite is what prevents you from shooting yourself in the foot. Francis Hwang http://fhwang.net/ From zach.dennis at gmail.com Tue Jan 1 17:40:35 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Tue, 1 Jan 2008 17:40:35 -0500 Subject: [rspec-users] Mocks? Really? In-Reply-To: References: <139c56460712060856i6bb410fcl23def3b16c0388b4@mail.gmail.com> <57c63afe0712291407h5eec4eajabb50f7b3c763e09@mail.gmail.com> <8DD055F8-AFDD-4AC5-8258-C21F452C861D@fhwang.net> <4777E8D5.4030907@shopwatch.org> <66AFA127-0223-444F-A4CA-7E31253182CC@fhwang.net> <4778561C.7030608@shopwatch.org> <02ED17FC-3B18-4DBF-A9E9-A063AC49024C@fhwang.net> <85d99afe0712311010h5f95a862oa82789b4df59ae5c@mail.gmail.com> Message-ID: <85d99afe0801011440w31436ba4ia90e97415262defd@mail.gmail.com> On Jan 1, 2008 1:48 PM, Francis Hwang wrote: > > On Dec 31, 2007, at 1:10 PM, Zach Dennis wrote: > > I don't think it is "designing less" either. It's designing better > > and doing it smarter, knowing that you'll never fully comprehend > > the domain of your problem upfront, so you discover it, > > iteratively. As you discover more about the domain the design of > > your program changes (during refactoring) to support a domain model > > to which it is representing. > > > > This is a concept from Domain Driven Design. > > > > It Francis is referring to doing less upfront design to try to > > master it all from the outset, then I agree that less of that is > > better. But that is entirely different then just doing less design. > > I'm not certain how much we're genuinely disagreeing here and how > much we're talking past each other -- I'm certainly feeling like I'm > not communicating my amorphous ideas very well. I think I understand what you are trying to get across. That is why I've communicated back what I think you have said (or at least what I think you mean) in each of my responses, hopefully clarifying my position (in both agreement and disagreement) to something more specific, since phrases like "designing less" can be taken in several ways and carry several different meanings. I'd much rather discuss a particular aspect of "designing less" where it is advantageous or not. > One thing that seems fuzzy to me is the implied time frames here. Let > me ask you this, Zach: Is it your aim that your released code always > contains a set of classes whose interactions with other classes is > well-structured and defined, through mocks, and other tools? It is my aim that objects, their responsibilities and their interactions are purposefully structured and defined. For me, this is through the iterative process of adding features to the system in a TDD/BDD manner. Since I test drive feature implementation I have explicitly made a decision to create a new object, add a new responsibility to an existing object, or move responsibilities from one object to another. Mocks are simply a tool that I use to help me discover interfaces and objects. They also help me express the coordination and interaction between objects which fulfill an application requirement, and they provide the added benefit of testing objects in isolation without the unnecessary complexity of testing objects throughout the test suite (which I believe strict state based testing of everything does). I do not use any tool primarily for the sake of designing a well-structured class taxonomy or detailed system design. No all encompassing UML diagrams or oodles of documentation. I strive for the domain driven design principle of having the domain model in the code accurately reflect the domain you are solving a problem for. > And is > it your belief that you can always seek to release code which > embodies a precise understanding of the domain in question? I believe you can always seek to release code which is an accurate reflection of the domain you are solving a problem for. I do not believe that the code itself will be a precise understanding of the domain in question. The features you implement will be solving a specific problem in a given domain. What is required to implement those features are only part of the domain. Ideally, what is implemented is only "precise" enough to satisfy the feature requirement. A lot of parts of the domain will be missing. Initially, the understanding of the domain may be fuzzy at best. But you start with a single feature to implement and you begin modeling the domain within your codebase for only what is required to implement that feature. You may only end up with a couple of objects; hardly a "precise" or perfect understanding of the domain at large, but as more features are added and time passes you get a better grasp of the domain. As you implement more features you will most likely discover new objects and responsibilities. This may entail extracting behavior from existing objects onto a new object because it better reflects what is required in the domain or it may promote single responsibility or separation of concerns and the concept of simple objects. The whole process though is something that is learned, continually and incrementally. I don't stop development of a feature because I am not an expert of the domain I am working in. I have to understand what is required to implement a particular feature or solve a particular problem anyways -- so I try to understand how the business expert or customer understands it and I try to keep that understanding consistent within the codebase. Specifically the domain objects in the application. I agree with a lot of the concepts behind domain driven design and how it works with agile (specifically XP in my case) development. It has created simpler code, easier to understand and maintain code and better test suites for apps that I've worked on. > I suppose part of what I'm saying is that sometimes, for non- > programmer reasons, the domain itself is too fuzzy or too quickly > shifting to try to nail down with a well-structured design. Sometimes > you just release code that amorphously hints at a future design -- > and in those cases, a strong test suite is what prevents you from > shooting yourself in the foot. > I agree that the domains in which we are implementing features and solving problems for are largely fuzzy. This is why it is so important to have business experts and real users apart of the development process. Sometimes it's not always possible to have direct access when you need it or your customer is venturing into new territory and they are trying to figure things out as they go as well. This is why it's so important to have a clean code base which reflects the domain because when that shifts we know what has to shift in our code. For me well-structured is a relative term. It shifts with each feature I add, remove or change in the system. After I complete a feature I want the codebase to be a coherent reflection of the features it includes. Over time the system is going to change and evolve, and parts and pieces are going to be added or thrown away. My implementation may not always be the best possible but it will be the best I could do at a given time. And it will always strive for simplicity over complexity and it will have a strong test suite. This is probably a longer reply then you were looking for.. hopefully thats alright. ;) -- Zach Dennis http://www.continuousthinking.com From shot at hot.pl Wed Jan 2 03:06:55 2008 From: shot at hot.pl (Shot (Piotr Szotkowski)) Date: Wed, 2 Jan 2008 09:06:55 +0100 Subject: [rspec-users] RSpec on Ruby 1.9: before(:all) (Not Yet Implemented) pending messages instead of tests In-Reply-To: <57c63afe0712290244p13fb9febp8e2e3fb1015edc9b@mail.gmail.com> References: <20071227181607.GI1277@durance.shot.pl> <57c63afe0712290244p13fb9febp8e2e3fb1015edc9b@mail.gmail.com> Message-ID: <20080102080655.GB10401@durance.shot.pl> David Chelimsky: > On Dec 27, 2007 4:28 PM, Shot (Piotr Szotkowski) wrote: >> I happily hand-compiled Ruby 1.9.0-0 into /home/shot/opt/ruby today >> and I'm running into a strange error with RSpec ? all my examples work >> perfectly with Ruby 1.8 but are considered pending on Ruby 1.9. >> How can I bugtrack/fix this? > RSpec's tracker can be found at http://rspec.lighthouseapp.com. Right; I?m not too fluent in RSpec yet (in particular, I didn?t use any pending specs yet), so I just wanted to ask around before filing a ticket. > The "Not Yet Implemented" issue you had is fixed in trunk now. Most appreciated! I?ll wait for RSpec 1.1.2 before switching to Ruby 1.9 in full then. BTW: The tracker says 1.1.2 ?is 11 months late? and ?Expected: Jan 17th, 2007?. Is 1.1.2 expected in two weeks? time and it should be 2008 there? >> I had to patch RSpec in the below manner to get it running >> on Ruby 1.9, but I doubt these fixes can be the culprit. >> --- lib/spec/runner/options.rb.orig 2007-12-27 16:36:03.000000000 +0100 >> +++ lib/spec/runner/options.rb 2007-12-27 16:36:28.000000000 +0100 >> @@ -102,7 +102,7 @@ >> def colour=(colour) >> @colour = colour >> begin; \ >> - require 'Win32/Console/ANSI' if @colour && PLATFORM =~ /win32/; \ >> +# require 'Win32/Console/ANSI' if @colour && PLATFORM =~ /win32/; \ >> rescue LoadError ; \ >> raise "You must gem install win32console to use colour on Windows" ; \ >> end > The change to be.rb has already been applied, but not the change > to options.rb. I'm not sure I see any relationship between that and > problems you might be experiencing with 1.9 (unless win32console does > not yet support 1.9). Sorry for not explaining this one. This is with using `spec -c -D u` on Ubuntu (with diff-lcs installed) ? I keep running into an ?uninitialized constant Spec::Runner::Options::PLATFORM? error, hence the simplest above workaround. Might be a bug in Ruby 1.9 not scoping the class constants properly, though. > Feel free to submit a ticket to the tracker on this one. #215 filed: http://rspec.lighthouseapp.com/projects/5645-rspec/tickets/215 -- Shot -- > So, this guy gets into Guinness by riding a 70-foot wave, > toppling the previous record-holder's 68-footer. How do they > measure the height of the waves to that degree of accuracy? With a barometer, silly. -- John Hatpin and Stan, afca -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 191 bytes Desc: not available Url : http://rubyforge.org/pipermail/rspec-users/attachments/20080102/1efb7789/attachment.bin From lists at ruby-forum.com Wed Jan 2 09:05:17 2008 From: lists at ruby-forum.com (Oscar Del ben) Date: Wed, 2 Jan 2008 15:05:17 +0100 Subject: [rspec-users] RSpec Book(s) on the radar In-Reply-To: <1299.216.167.174.73.1191590398.squirrel@webmail.skidmore.us> References: <1299.216.167.174.73.1191590398.squirrel@webmail.skidmore.us> Message-ID: <8244a5ee7150b6f670511260a69eed98@ruby-forum.com> Cody P. Skidmore wrote: > I just found this one: http://tinyurl.com/3c3mfa > > David, are there any other RSpec books in the works? > > With Regards, > > Cody Skidmore That book is not longer available, and i don't know the matter, what about the book of prag prog? -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Wed Jan 2 09:52:14 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 2 Jan 2008 12:52:14 -0200 Subject: [rspec-users] RSpec Book(s) on the radar In-Reply-To: <8244a5ee7150b6f670511260a69eed98@ruby-forum.com> References: <1299.216.167.174.73.1191590398.squirrel@webmail.skidmore.us> <8244a5ee7150b6f670511260a69eed98@ruby-forum.com> Message-ID: <57c63afe0801020652w32871bebsc6876eb3c4ab9566@mail.gmail.com> On Jan 2, 2008 12:05 PM, Oscar Del ben wrote: > Cody P. Skidmore wrote: > > I just found this one: http://tinyurl.com/3c3mfa > > > > David, are there any other RSpec books in the works? > > > > With Regards, > > > > Cody Skidmore > > > That book is not longer available, and i don't know the matter, what > about the book of prag prog? We don't have an official date yet, but you can trust that the second we do there will be an announcement. I will say that we are getting very close to beta, but there are a few hoops before we get there. Cheers, David From zach.dennis at gmail.com Wed Jan 2 14:20:30 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Wed, 2 Jan 2008 14:20:30 -0500 Subject: [rspec-users] Do you think it would look cleaner? In-Reply-To: <20071230094725.GA24657@chello.nl> References: <20071230094725.GA24657@chello.nl> Message-ID: <85d99afe0801021120i4648938apcaf5e76c955fa624@mail.gmail.com> On Dec 30, 2007 4:47 AM, Kero van Gelder wrote: > > > I was looking over some of my specs. > > I was thinking that the following: > > > > @game.should_receive(:name).and_return('The Battle for Blaze') > > @game.should_receive(:people).and_return(5000000) > > @game.should_receive(:activated).and_return(true) > > > > Would it look cleaner if I could do this instead? > > > > @game.should_recieve_and_return( > > :name => 'The Battle for Blaze' > > :people => 5000000 > > :activated => true) > > > > Opinions? > > A Hash is not ordered. > (but the 1st set of statements is) I don't know if this matters in this case. RSpec doesn't enforce strict-order mocking. Nor does Mocha. Hardmock is the only mocking library in ruby that I know of that can do this, -- Zach Dennis http://www.continuousthinking.com From loop at superinfinite.com Wed Jan 2 17:05:04 2008 From: loop at superinfinite.com (Bart Zonneveld) Date: Wed, 2 Jan 2008 23:05:04 +0100 Subject: [rspec-users] RSpec Book(s) on the radar In-Reply-To: <57c63afe0801020652w32871bebsc6876eb3c4ab9566@mail.gmail.com> References: <1299.216.167.174.73.1191590398.squirrel@webmail.skidmore.us> <8244a5ee7150b6f670511260a69eed98@ruby-forum.com> <57c63afe0801020652w32871bebsc6876eb3c4ab9566@mail.gmail.com> Message-ID: <604BD6AC-D087-4810-B970-87A61BBA7A83@superinfinite.com> On 2 jan 2008, at 15:52, David Chelimsky wrote: > On Jan 2, 2008 12:05 PM, Oscar Del ben wrote: >> Cody P. Skidmore wrote: >>> I just found this one: http://tinyurl.com/3c3mfa >>> >>> David, are there any other RSpec books in the works? >>> >>> With Regards, >>> >>> Cody Skidmore >> >> >> That book is not longer available, and i don't know the matter, what >> about the book of prag prog? > > We don't have an official date yet, but you can trust that the second > we do there will be an announcement. I will say that we are getting > very close to beta, but there are a few hoops before we get there. Curious, are the Stories going to be part of the rspec book? Eagerly waiting on that one... cheers, bartz From dchelimsky at gmail.com Wed Jan 2 17:09:43 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 2 Jan 2008 20:09:43 -0200 Subject: [rspec-users] Do you think it would look cleaner? In-Reply-To: <85d99afe0801021120i4648938apcaf5e76c955fa624@mail.gmail.com> References: <20071230094725.GA24657@chello.nl> <85d99afe0801021120i4648938apcaf5e76c955fa624@mail.gmail.com> Message-ID: <57c63afe0801021409x48507bb3ye9cd07e82bfdfa0@mail.gmail.com> On Jan 2, 2008 5:20 PM, Zach Dennis wrote: > RSpec doesn't enforce strict-order mocking. Sure it does, if you ask it to: http://rspec.info/documentation/mocks/message_expectations.html From dchelimsky at gmail.com Wed Jan 2 17:12:41 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 2 Jan 2008 20:12:41 -0200 Subject: [rspec-users] RSpec Book(s) on the radar In-Reply-To: <604BD6AC-D087-4810-B970-87A61BBA7A83@superinfinite.com> References: <1299.216.167.174.73.1191590398.squirrel@webmail.skidmore.us> <8244a5ee7150b6f670511260a69eed98@ruby-forum.com> <57c63afe0801020652w32871bebsc6876eb3c4ab9566@mail.gmail.com> <604BD6AC-D087-4810-B970-87A61BBA7A83@superinfinite.com> Message-ID: <57c63afe0801021412n2c22df17n7bdb84c245331693@mail.gmail.com> On Jan 2, 2008 8:05 PM, Bart Zonneveld wrote: > Curious, are the Stories going to be part of the rspec book? Yep. > Eagerly waiting on that one... Us too! Cheers, David From zach.dennis at gmail.com Wed Jan 2 18:26:00 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Wed, 2 Jan 2008 18:26:00 -0500 Subject: [rspec-users] Do you think it would look cleaner? In-Reply-To: <57c63afe0801021409x48507bb3ye9cd07e82bfdfa0@mail.gmail.com> References: <20071230094725.GA24657@chello.nl> <85d99afe0801021120i4648938apcaf5e76c955fa624@mail.gmail.com> <57c63afe0801021409x48507bb3ye9cd07e82bfdfa0@mail.gmail.com> Message-ID: <85d99afe0801021526r606e3121rc77b2435483cb617@mail.gmail.com> I learn something everyday. Thanks On Jan 2, 2008 5:09 PM, David Chelimsky wrote: > On Jan 2, 2008 5:20 PM, Zach Dennis wrote: > > > RSpec doesn't enforce strict-order mocking. > > Sure it does, if you ask it to: > http://rspec.info/documentation/mocks/message_expectations.html > -- Zach Dennis http://www.continuousthinking.com From glenn at aldenta.com Wed Jan 2 23:19:39 2008 From: glenn at aldenta.com (Glenn Ford) Date: Wed, 2 Jan 2008 23:19:39 -0500 Subject: [rspec-users] Cookie Session Store Not Working in Safari In-Reply-To: References: Message-ID: <5AE0BDB9-90C1-4C4A-B301-651673C14149@aldenta.com> Here's the steps I followed: Generated the test code rails test mate test cd test script/generate scaffold thing rake db:create script/server Modified things_controller.rb index and new: def index end def new session[:user] = 5 redirect_to(things_path) end Set index.html.erb to: Hello! <%= session[:user] %> <%= link_to 'New thing', new_thing_path %> ------- Now when I go to the page in FireFox, I see "Hello" on the screen. Clicking the link gives me "Hello 5" on my screen. This is expected. However, when I go to Safari, I only ever see "Hello" and never "Hello 5". I have, in the Safari preferences, accept cookies set to "Accept All". I've checked everything I can think of to make sure nothing is blocking it. I've inspected the session and the only thing I can find is that the Session ID for the Safari requests is a new 32 character string for every request, and for FireFox requests it's the same 128 character string for every request. I'm using Ruby on Rails 2.0.2. I hope I'm not forgetting some other useful piece of info. How do I get this to work for me in Safari? Thanks, Glenn -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080102/024f1d74/attachment.html From gilesb at gmail.com Wed Jan 2 23:36:43 2008 From: gilesb at gmail.com (Giles Bowkett) Date: Wed, 2 Jan 2008 20:36:43 -0800 Subject: [rspec-users] Cookie Session Store Not Working in Safari In-Reply-To: <5AE0BDB9-90C1-4C4A-B301-651673C14149@aldenta.com> References: <5AE0BDB9-90C1-4C4A-B301-651673C14149@aldenta.com> Message-ID: <2d81dedb0801022036l7db5334ag113877d45fa4a896@mail.gmail.com> Sorry, I'm new here, but isn't this totally irrelevant to RSpec in every way? On 1/2/08, Glenn Ford wrote: > > Here's the steps I followed: > > Generated the test code > rails test > mate test > cd test > script/generate scaffold thing > rake db:create > script/server > > > Modified things_controller.rb index and new: > def index > end > def new > session[:user] = 5 > redirect_to(things_path) > end > > Set index.html.erb to: > Hello! <%= session[:user] %> > <%= link_to 'New thing', new_thing_path %> > > ------- > > Now when I go to the page in FireFox, I see "Hello" on the screen. Clicking > the link gives me "Hello 5" on my screen. This is expected. > > However, when I go to Safari, I only ever see "Hello" and never "Hello 5". > I have, in the Safari preferences, accept cookies set to "Accept All". I've > checked everything I can think of to make sure nothing is blocking it. > > I've inspected the session and the only thing I can find is that the Session > ID for the Safari requests is a new 32 character string for every request, > and for FireFox requests it's the same 128 character string for every > request. > > I'm using Ruby on Rails 2.0.2. I hope I'm not forgetting some other useful > piece of info. > > How do I get this to work for me in Safari? > > Thanks, > Glenn > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Giles Bowkett Podcast: http://hollywoodgrit.blogspot.com Blog: http://gilesbowkett.blogspot.com Portfolio: http://www.gilesgoatboy.org Tumblelog: http://giles.tumblr.com From glenn at aldenta.com Thu Jan 3 00:35:09 2008 From: glenn at aldenta.com (Glenn Ford) Date: Thu, 3 Jan 2008 00:35:09 -0500 Subject: [rspec-users] Cookie Session Store Not Working in Safari In-Reply-To: <2d81dedb0801022036l7db5334ag113877d45fa4a896@mail.gmail.com> References: <5AE0BDB9-90C1-4C4A-B301-651673C14149@aldenta.com> <2d81dedb0801022036l7db5334ag113877d45fa4a896@mail.gmail.com> Message-ID: Whoops, you're very right, this isn't the RoR list! Oh well it's the only one I ever use. My bad! Let's look at it this way... my spec's are failing because I can't use session! What do I do? :) On Jan 2, 2008, at 11:36 PM, Giles Bowkett wrote: > Sorry, I'm new here, but isn't this totally irrelevant to RSpec in > every way? > > On 1/2/08, Glenn Ford wrote: >> >> Here's the steps I followed: >> >> Generated the test code >> rails test >> mate test >> cd test >> script/generate scaffold thing >> rake db:create >> script/server >> >> >> Modified things_controller.rb index and new: >> def index >> end >> def new >> session[:user] = 5 >> redirect_to(things_path) >> end >> >> Set index.html.erb to: >> Hello! <%= session[:user] %> >> <%= link_to 'New thing', new_thing_path %> >> >> ------- >> >> Now when I go to the page in FireFox, I see "Hello" on the screen. >> Clicking >> the link gives me "Hello 5" on my screen. This is expected. >> >> However, when I go to Safari, I only ever see "Hello" and never >> "Hello 5". >> I have, in the Safari preferences, accept cookies set to "Accept >> All". I've >> checked everything I can think of to make sure nothing is blocking >> it. >> >> I've inspected the session and the only thing I can find is that >> the Session >> ID for the Safari requests is a new 32 character string for every >> request, >> and for FireFox requests it's the same 128 character string for every >> request. >> >> I'm using Ruby on Rails 2.0.2. I hope I'm not forgetting some >> other useful >> piece of info. >> >> How do I get this to work for me in Safari? >> >> Thanks, >> Glenn >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > -- > Giles Bowkett > > Podcast: http://hollywoodgrit.blogspot.com > Blog: http://gilesbowkett.blogspot.com > Portfolio: http://www.gilesgoatboy.org > Tumblelog: http://giles.tumblr.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From gilesb at gmail.com Thu Jan 3 00:54:00 2008 From: gilesb at gmail.com (Giles Bowkett) Date: Wed, 2 Jan 2008 21:54:00 -0800 Subject: [rspec-users] Cookie Session Store Not Working in Safari In-Reply-To: References: <5AE0BDB9-90C1-4C4A-B301-651673C14149@aldenta.com> <2d81dedb0801022036l7db5334ag113877d45fa4a896@mail.gmail.com> Message-ID: <2d81dedb0801022154k7ef6b6dfha3d2e7b1fb559cc5@mail.gmail.com> > Whoops, you're very right, this isn't the RoR list! Oh well it's the > only one I ever use. My bad! Let's look at it this way... my spec's > are failing because I can't use session! What do I do? :) Stub like there's no tomorrow? -- Giles Bowkett Podcast: http://hollywoodgrit.blogspot.com Blog: http://gilesbowkett.blogspot.com Portfolio: http://www.gilesgoatboy.org Tumblelog: http://giles.tumblr.com From glenn at aldenta.com Thu Jan 3 08:58:44 2008 From: glenn at aldenta.com (Glenn Ford) Date: Thu, 3 Jan 2008 08:58:44 -0500 Subject: [rspec-users] Cookie Session Store Not Working in Safari In-Reply-To: <2d81dedb0801022154k7ef6b6dfha3d2e7b1fb559cc5@mail.gmail.com> References: <5AE0BDB9-90C1-4C4A-B301-651673C14149@aldenta.com> <2d81dedb0801022036l7db5334ag113877d45fa4a896@mail.gmail.com> <2d81dedb0801022154k7ef6b6dfha3d2e7b1fb559cc5@mail.gmail.com> Message-ID: <3BC95201-DA68-414C-B489-9F1D0A5DD6C7@aldenta.com> I figured it out. My host, or rather my /etc/hosts mapped localhost url, had an underscore in it. That was causing the problem. I never new that was bad. Crazy! On Jan 3, 2008, at 12:54 AM, Giles Bowkett wrote: >> Whoops, you're very right, this isn't the RoR list! Oh well it's the >> only one I ever use. My bad! Let's look at it this way... my spec's >> are failing because I can't use session! What do I do? :) > > Stub like there's no tomorrow? > > -- > Giles Bowkett > > Podcast: http://hollywoodgrit.blogspot.com > Blog: http://gilesbowkett.blogspot.com > Portfolio: http://www.gilesgoatboy.org > Tumblelog: http://giles.tumblr.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080103/cbe0a4c9/attachment.html From kerry at kerrybuckley.com Thu Jan 3 12:20:45 2008 From: kerry at kerrybuckley.com (Kerry Buckley) Date: Thu, 3 Jan 2008 17:20:45 +0000 Subject: [rspec-users] Do you think it would look cleaner? In-Reply-To: <57c63afe0801021409x48507bb3ye9cd07e82bfdfa0@mail.gmail.com> References: <20071230094725.GA24657@chello.nl> <85d99afe0801021120i4648938apcaf5e76c955fa624@mail.gmail.com> <57c63afe0801021409x48507bb3ye9cd07e82bfdfa0@mail.gmail.com> Message-ID: <78CDA16D-51B4-4EFC-A62E-77E243009497@kerrybuckley.com> On 2 Jan 2008, at 22:09, David Chelimsky wrote: > On Jan 2, 2008 5:20 PM, Zach Dennis wrote: > >> RSpec doesn't enforce strict-order mocking. > > Sure it does, if you ask it to: > http://rspec.info/documentation/mocks/message_expectations.html Am I right, though, in thinking that you can't enforce order between two mocks? It would occasionally be nice to be able to say something like: master.should_receive(:start).and_then(slave).should_receive(:start) From zach.dennis at gmail.com Thu Jan 3 12:39:19 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Thu, 3 Jan 2008 12:39:19 -0500 Subject: [rspec-users] Do you think it would look cleaner? In-Reply-To: <78CDA16D-51B4-4EFC-A62E-77E243009497@kerrybuckley.com> References: <20071230094725.GA24657@chello.nl> <85d99afe0801021120i4648938apcaf5e76c955fa624@mail.gmail.com> <57c63afe0801021409x48507bb3ye9cd07e82bfdfa0@mail.gmail.com> <78CDA16D-51B4-4EFC-A62E-77E243009497@kerrybuckley.com> Message-ID: <85d99afe0801030939w5cd55fd9j2ec9fc9123388e42@mail.gmail.com> On Jan 3, 2008 12:20 PM, Kerry Buckley wrote: > > On 2 Jan 2008, at 22:09, David Chelimsky wrote: > > > On Jan 2, 2008 5:20 PM, Zach Dennis wrote: > > > >> RSpec doesn't enforce strict-order mocking. > > > > Sure it does, if you ask it to: > > http://rspec.info/documentation/mocks/message_expectations.html > > Am I right, though, in thinking that you can't enforce order between > two mocks? It would occasionally be nice to be able to say something > like: > > master.should_receive(:start).and_then(slave).should_receive(:start) > I'd like to be proven wrong again, but I don't think you can do this with rspec. From running some examples in irb it looks like each mock only verifies its own order. Hardmock does support this. Flexmock does not that I am aware of, and Mocha most certainly does not. Hardmock considers all expectations ordered across all mocks. Hardmock does work with rspec too: http://hardmock.rubyforge.org/doc/index.html -- Zach Dennis http://www.continuousthinking.com From dchelimsky at gmail.com Thu Jan 3 12:45:16 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 3 Jan 2008 15:45:16 -0200 Subject: [rspec-users] Do you think it would look cleaner? In-Reply-To: <78CDA16D-51B4-4EFC-A62E-77E243009497@kerrybuckley.com> References: <20071230094725.GA24657@chello.nl> <85d99afe0801021120i4648938apcaf5e76c955fa624@mail.gmail.com> <57c63afe0801021409x48507bb3ye9cd07e82bfdfa0@mail.gmail.com> <78CDA16D-51B4-4EFC-A62E-77E243009497@kerrybuckley.com> Message-ID: <57c63afe0801030945u4bb269belb4fd708c0bceef@mail.gmail.com> On Jan 3, 2008 3:20 PM, Kerry Buckley wrote: > > On 2 Jan 2008, at 22:09, David Chelimsky wrote: > > > On Jan 2, 2008 5:20 PM, Zach Dennis wrote: > > > >> RSpec doesn't enforce strict-order mocking. > > > > Sure it does, if you ask it to: > > http://rspec.info/documentation/mocks/message_expectations.html > > Am I right, though, in thinking that you can't enforce order between > two mocks? It would occasionally be nice to be able to say something > like: > > master.should_receive(:start).and_then(slave).should_receive(:start) Yes, you are correct. RSpec does not support this functionality. From timcharper at gmail.com Fri Jan 4 01:15:48 2008 From: timcharper at gmail.com (Tim Harper) Date: Thu, 3 Jan 2008 23:15:48 -0700 Subject: [rspec-users] patch for html display Message-ID: All, I've found that the html view for the rspec formatter falls to pieces with Rails 2.02 and rspec 1.10. Has anyone else run into this trouble? Here's a monkey patch that fixes the problem. A more elegant fix would be in order, but this gets the job done: Index: /Users/timcharper/www/exchange/vendor/plugins/rspec/lib/spec/runner/formatter/text_mate_formatter.rb =================================================================== --- /Users/timcharper/www/exchange/vendor/plugins/rspec/lib/spec/runner/formatter/text_mate_formatter.rb (revision 906) +++ /Users/timcharper/www/exchange/vendor/plugins/rspec/lib/spec/runner/formatter/text_mate_formatter.rb (working copy) @@ -6,8 +6,9 @@ # Formats backtraces so they're clickable by TextMate class TextMateFormatter < HtmlFormatter def backtrace_line(line) - line.gsub(/([^:]*\.rb):(\d*)/) do - "#{$1}:#{$2} " + line.gsub!(/^(On line #([0-9]+) of )(.+)$/) { "app/views/#{$3}:#{$2}"} + line.gsub(/([^:]*\.(rb|rhtml|erb)):(\d*)/) do + "#{$1}:#{$3} " end end end Index: /Users/timcharper/www/exchange/vendor/plugins/rspec/lib/spec/runner/formatter/base_text_formatter.rb =================================================================== --- /Users/timcharper/www/exchange/vendor/plugins/rspec/lib/spec/runner/formatter/base_text_formatter.rb (revision 906) +++ /Users/timcharper/www/exchange/vendor/plugins/rspec/lib/spec/runner/formatter/base_text_formatter.rb (working copy) @@ -88,6 +88,7 @@ def format_backtrace(backtrace) return "" if backtrace.nil? + backtrace = backtrace.first.split("\n").map { |l| h(l).strip } backtrace.map { |line| backtrace_line(line) }.join("\n") end Tim -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080103/8c03be19/attachment.html From aslak.hellesoy at gmail.com Fri Jan 4 04:27:56 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Fri, 4 Jan 2008 10:27:56 +0100 Subject: [rspec-users] patch for html display In-Reply-To: References: Message-ID: <8d961d900801040127w36618d97i84d0036b29b3be1e@mail.gmail.com> Please register this on http://rspec.lighthouseapp.com/ We *will* forget to apply this patch if you don't ;-) Thanks, Aslak On Jan 4, 2008 7:15 AM, Tim Harper wrote: > All, > > I've found that the html view for the rspec formatter falls to pieces with > Rails 2.02 and rspec 1.10. Has anyone else run into this trouble? > > Here's a monkey patch that fixes the problem. A more elegant fix would be > in order, but this gets the job done: > > Index: > /Users/timcharper/www/exchange/vendor/plugins/rspec/lib/spec/runner/formatter/text_mate_formatter.rb > =================================================================== > --- > /Users/timcharper/www/exchange/vendor/plugins/rspec/lib/spec/runner/formatter/text_mate_formatter.rb > (revision 906) > +++ > /Users/timcharper/www/exchange/vendor/plugins/rspec/lib/spec/runner/formatter/text_mate_formatter.rb > (working copy) > @@ -6,8 +6,9 @@ > # Formats backtraces so they're clickable by TextMate > class TextMateFormatter < HtmlFormatter > def backtrace_line(line) > - line.gsub(/([^:]*\.rb):(\d*)/) do > - " href=\"txmt://open?url=file://#{File.expand_path($1)}&line=#{$2}\">#{$1}:#{$2} > " > + line.gsub!(/^(On line #([0-9]+) of )(.+)$/) { > "app/views/#{$3}:#{$2}"} > + line.gsub(/([^:]*\.(rb|rhtml|erb)):(\d*)/) do > + " File.expand_path($1)}&line=#{$3}\">#{$1}:#{$3} " > end > end > end > Index: > /Users/timcharper/www/exchange/vendor/plugins/rspec/lib/spec/runner/formatter/base_text_formatter.rb > =================================================================== > --- > /Users/timcharper/www/exchange/vendor/plugins/rspec/lib/spec/runner/formatter/base_text_formatter.rb > (revision 906) > +++ > /Users/timcharper/www/exchange/vendor/plugins/rspec/lib/spec/runner/formatter/base_text_formatter.rb > (working copy) > @@ -88,6 +88,7 @@ > > def format_backtrace(backtrace) > return "" if backtrace.nil? > + backtrace = backtrace.first.split("\n").map { |l| h(l).strip } > backtrace.map { |line| backtrace_line(line) }.join("\n") > end > > > > Tim > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From gilesb at gmail.com Fri Jan 4 10:55:37 2008 From: gilesb at gmail.com (Giles Bowkett) Date: Fri, 4 Jan 2008 07:55:37 -0800 Subject: [rspec-users] best way to modify spec (the command-line tool)? Message-ID: <2d81dedb0801040755y41d4e4e2l9114aae95d47508b@mail.gmail.com> Hi all, where I work we've cooked up a kind of ghetto profiler for our specs. It basically just does this: time = Time.now # run the spec puts "woah! dude. long spec." if time > 1.second I'm simplifying here. I think the threshold is actually 0.1 seconds, and we use more precise language, and highlight the spec in red via terminal colors, etc. But the way it works is a bit ghetto. We just manually hacked it onto the Rails example groups (it's a Rails project) and then added a shell env var to turn it on and off. What's the cleanest way to implement this? Add a -profiling command-line flag to spec itself? Is there a single point of entry and exit for running individual specs that I can put the code around? It's currently manually hacked onto each example group individually and it seems a bit untidy. -- Giles Bowkett Podcast: http://hollywoodgrit.blogspot.com Blog: http://gilesbowkett.blogspot.com Portfolio: http://www.gilesgoatboy.org Tumblelog: http://giles.tumblr.com From dchelimsky at gmail.com Fri Jan 4 11:08:27 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 4 Jan 2008 10:08:27 -0600 Subject: [rspec-users] best way to modify spec (the command-line tool)? In-Reply-To: <2d81dedb0801040755y41d4e4e2l9114aae95d47508b@mail.gmail.com> References: <2d81dedb0801040755y41d4e4e2l9114aae95d47508b@mail.gmail.com> Message-ID: <57c63afe0801040808n2807ce85nd65c1b567f8bffaa@mail.gmail.com> On Jan 4, 2008 9:55 AM, Giles Bowkett wrote: > Hi all, where I work we've cooked up a kind of ghetto profiler for our > specs. It basically just does this: > > time = Time.now > # run the spec > puts "woah! dude. long spec." if time > 1.second > > I'm simplifying here. I think the threshold is actually 0.1 seconds, > and we use more precise language, and highlight the spec in red via > terminal colors, etc. > > But the way it works is a bit ghetto. We just manually hacked it onto > the Rails example groups (it's a Rails project) and then added a shell > env var to turn it on and off. > > What's the cleanest way to implement this? Hey Giles, we've already done this for you! spec some_directory --format profile This will print out the 10 slowest examples (regardless of threshold). Cheers, and welcome to the RSpec community! David > Add a -profiling > command-line flag to spec itself? Is there a single point of entry and > exit for running individual specs that I can put the code around? It's > currently manually hacked onto each example group individually and it > seems a bit untidy. > > -- > Giles Bowkett > > Podcast: http://hollywoodgrit.blogspot.com > Blog: http://gilesbowkett.blogspot.com > Portfolio: http://www.gilesgoatboy.org > Tumblelog: http://giles.tumblr.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ben at benmabey.com Fri Jan 4 11:14:58 2008 From: ben at benmabey.com (Ben Mabey) Date: Fri, 04 Jan 2008 09:14:58 -0700 Subject: [rspec-users] best way to modify spec (the command-line tool)? In-Reply-To: <2d81dedb0801040755y41d4e4e2l9114aae95d47508b@mail.gmail.com> References: <2d81dedb0801040755y41d4e4e2l9114aae95d47508b@mail.gmail.com> Message-ID: <477E5B82.4070204@benmabey.com> On rspec's specs I have noticed they have a profiling flag that they pass into the spec command. What is does is print out the longest specs with there times. So you may not have to rewrite this.. I have tried using the flag on my own projects but it didn't work. Maybe someone from the dev team could enlighten us on how to use that nifty trick? -Ben Giles Bowkett wrote: > Hi all, where I work we've cooked up a kind of ghetto profiler for our > specs. It basically just does this: > > time = Time.now > # run the spec > puts "woah! dude. long spec." if time > 1.second > > I'm simplifying here. I think the threshold is actually 0.1 seconds, > and we use more precise language, and highlight the spec in red via > terminal colors, etc. > > But the way it works is a bit ghetto. We just manually hacked it onto > the Rails example groups (it's a Rails project) and then added a shell > env var to turn it on and off. > > What's the cleanest way to implement this? Add a -profiling > command-line flag to spec itself? Is there a single point of entry and > exit for running individual specs that I can put the code around? It's > currently manually hacked onto each example group individually and it > seems a bit untidy. > > From dchelimsky at gmail.com Fri Jan 4 11:37:23 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 4 Jan 2008 10:37:23 -0600 Subject: [rspec-users] best way to modify spec (the command-line tool)? In-Reply-To: <477E5B82.4070204@benmabey.com> References: <2d81dedb0801040755y41d4e4e2l9114aae95d47508b@mail.gmail.com> <477E5B82.4070204@benmabey.com> Message-ID: <57c63afe0801040837i685399cw9ef31369c19a09df@mail.gmail.com> On Jan 4, 2008 10:14 AM, Ben Mabey wrote: > On rspec's specs I have noticed they have a profiling flag that they > pass into the spec command. What is does is print out the longest specs > with there times. So you may not have to rewrite this.. I have tried > using the flag on my own projects but it didn't work. Maybe someone > from the dev team could enlighten us on how to use that nifty trick? It should just work with --format profile. What are you experiencing when you do that? > > -Ben > > > Giles Bowkett wrote: > > Hi all, where I work we've cooked up a kind of ghetto profiler for our > > specs. It basically just does this: > > > > time = Time.now > > # run the spec > > puts "woah! dude. long spec." if time > 1.second > > > > I'm simplifying here. I think the threshold is actually 0.1 seconds, > > and we use more precise language, and highlight the spec in red via > > terminal colors, etc. > > > > But the way it works is a bit ghetto. We just manually hacked it onto > > the Rails example groups (it's a Rails project) and then added a shell > > env var to turn it on and off. > > > > What's the cleanest way to implement this? Add a -profiling > > command-line flag to spec itself? Is there a single point of entry and > > exit for running individual specs that I can put the code around? It's > > currently manually hacked onto each example group individually and it > > seems a bit untidy. > > > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From george at benevolentcode.com Fri Jan 4 11:31:07 2008 From: george at benevolentcode.com (George Anderson) Date: Fri, 4 Jan 2008 11:31:07 -0500 Subject: [rspec-users] best way to modify spec (the command-line tool)? In-Reply-To: <2d81dedb0801040755y41d4e4e2l9114aae95d47508b@mail.gmail.com> References: <2d81dedb0801040755y41d4e4e2l9114aae95d47508b@mail.gmail.com> Message-ID: <782d66f30801040831u5a869e97y9d6c5694b1daf418@mail.gmail.com> "ghetto profiler": how appropriate for rails work these days. You might ask on the rspec-devel list if you haven't already. http://rubyforge.org/mail/?group_id=797 While you're waiting for a response, consider watching Zed's interpretive piece in which he channels the King: http://www.youtube.com/watch?v=zmVFnhO3A98 /g On 1/4/08, Giles Bowkett wrote: > Hi all, where I work we've cooked up a kind of ghetto profiler for our > specs. It basically just does this: > > time = Time.now > # run the spec > puts "woah! dude. long spec." if time > 1.second > > I'm simplifying here. I think the threshold is actually 0.1 seconds, > and we use more precise language, and highlight the spec in red via > terminal colors, etc. > > But the way it works is a bit ghetto. We just manually hacked it onto > the Rails example groups (it's a Rails project) and then added a shell > env var to turn it on and off. > > What's the cleanest way to implement this? Add a -profiling > command-line flag to spec itself? Is there a single point of entry and > exit for running individual specs that I can put the code around? It's > currently manually hacked onto each example group individually and it > seems a bit untidy. > > -- > Giles Bowkett > > Podcast: http://hollywoodgrit.blogspot.com > Blog: http://gilesbowkett.blogspot.com > Portfolio: http://www.gilesgoatboy.org > Tumblelog: http://giles.tumblr.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- George Anderson BenevolentCode LLC O: (410) 461-7553 C: (410) 218-5185 george at benevolentcode.com From ben at benmabey.com Fri Jan 4 11:55:57 2008 From: ben at benmabey.com (Ben Mabey) Date: Fri, 04 Jan 2008 09:55:57 -0700 Subject: [rspec-users] best way to modify spec (the command-line tool)? In-Reply-To: <57c63afe0801040837i685399cw9ef31369c19a09df@mail.gmail.com> References: <2d81dedb0801040755y41d4e4e2l9114aae95d47508b@mail.gmail.com> <477E5B82.4070204@benmabey.com> <57c63afe0801040837i685399cw9ef31369c19a09df@mail.gmail.com> Message-ID: <477E651D.4010802@benmabey.com> David Chelimsky wrote: > On Jan 4, 2008 10:14 AM, Ben Mabey wrote: > >> On rspec's specs I have noticed they have a profiling flag that they >> pass into the spec command. What is does is print out the longest specs >> with there times. So you may not have to rewrite this.. I have tried >> using the flag on my own projects but it didn't work. Maybe someone >> from the dev team could enlighten us on how to use that nifty trick? >> > > It should just work with --format profile. What are you experiencing > when you do that? > > I just tried that and it worked great, thanks. Before, I didn't realize it was a formatter and thought it was its own flag. Thanks! -Ben >> -Ben >> >> >> Giles Bowkett wrote: >> >>> Hi all, where I work we've cooked up a kind of ghetto profiler for our >>> specs. It basically just does this: >>> >>> time = Time.now >>> # run the spec >>> puts "woah! dude. long spec." if time > 1.second >>> >>> I'm simplifying here. I think the threshold is actually 0.1 seconds, >>> and we use more precise language, and highlight the spec in red via >>> terminal colors, etc. >>> >>> But the way it works is a bit ghetto. We just manually hacked it onto >>> the Rails example groups (it's a Rails project) and then added a shell >>> env var to turn it on and off. >>> >>> What's the cleanest way to implement this? Add a -profiling >>> command-line flag to spec itself? Is there a single point of entry and >>> exit for running individual specs that I can put the code around? It's >>> currently manually hacked onto each example group individually and it >>> seems a bit untidy. >>> >>> >>> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Fri Jan 4 12:06:31 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 4 Jan 2008 11:06:31 -0600 Subject: [rspec-users] best way to modify spec (the command-line tool)? In-Reply-To: <477E651D.4010802@benmabey.com> References: <2d81dedb0801040755y41d4e4e2l9114aae95d47508b@mail.gmail.com> <477E5B82.4070204@benmabey.com> <57c63afe0801040837i685399cw9ef31369c19a09df@mail.gmail.com> <477E651D.4010802@benmabey.com> Message-ID: <57c63afe0801040906l57b3f726gbad26c1a79789747@mail.gmail.com> On Jan 4, 2008 10:55 AM, Ben Mabey wrote: > David Chelimsky wrote: > > On Jan 4, 2008 10:14 AM, Ben Mabey wrote: > > > >> On rspec's specs I have noticed they have a profiling flag that they > >> pass into the spec command. What is does is print out the longest specs > >> with there times. So you may not have to rewrite this.. I have tried > >> using the flag on my own projects but it didn't work. Maybe someone > >> from the dev team could enlighten us on how to use that nifty trick? > >> > > > > It should just work with --format profile. What are you experiencing > > when you do that? > > > > > > I just tried that and it worked great, thanks. Before, I didn't realize > it was a formatter and thought it was its own flag. Thanks! n/p Glad you got it working. Cheers, David From gilesb at gmail.com Fri Jan 4 14:41:38 2008 From: gilesb at gmail.com (Giles Bowkett) Date: Fri, 4 Jan 2008 11:41:38 -0800 Subject: [rspec-users] best way to modify spec (the command-line tool)? In-Reply-To: <57c63afe0801040808n2807ce85nd65c1b567f8bffaa@mail.gmail.com> References: <2d81dedb0801040755y41d4e4e2l9114aae95d47508b@mail.gmail.com> <57c63afe0801040808n2807ce85nd65c1b567f8bffaa@mail.gmail.com> Message-ID: <2d81dedb0801041141yb92b3d0h7b806074ab85029c@mail.gmail.com> > Hey Giles, we've already done this for you! > > spec some_directory --format profile > > This will print out the 10 slowest examples (regardless of threshold). > > Cheers, and welcome to the RSpec community! Doh! Gracias. :-) -- Giles Bowkett Podcast: http://hollywoodgrit.blogspot.com Blog: http://gilesbowkett.blogspot.com Portfolio: http://www.gilesgoatboy.org Tumblelog: http://giles.tumblr.com From ben at benmabey.com Fri Jan 4 20:39:37 2008 From: ben at benmabey.com (Ben Mabey) Date: Fri, 04 Jan 2008 18:39:37 -0700 Subject: [rspec-users] status/exit code for story runner Message-ID: <477EDFD9.5000004@benmabey.com> Hi All, I'm trying to incorporate our stories into our build for our cruisecrontrol.rb projects and it looks like the Story Runner always returns a 0 (zero) no matter if the tests pass or fail. This is in contrast to the actual and expected behavior of the spec command which will return a 0 or a 1 depending on whether specs pass or fail. Am I doing something wrong with the story runner or would this need to be patched to get it to work correctly? Thanks, Ben From aslak.hellesoy at gmail.com Sat Jan 5 04:15:10 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Sat, 5 Jan 2008 10:15:10 +0100 Subject: [rspec-users] status/exit code for story runner In-Reply-To: <477EDFD9.5000004@benmabey.com> References: <477EDFD9.5000004@benmabey.com> Message-ID: <8d961d900801050115n2354e28br6948461a8ef3588e@mail.gmail.com> On Jan 5, 2008 2:39 AM, Ben Mabey wrote: > Hi All, > I'm trying to incorporate our stories into our build for our > cruisecrontrol.rb projects and it looks like the Story Runner always > returns a 0 (zero) no matter if the tests pass or fail. > This is in contrast to the actual and expected behavior of the spec > command which will return a 0 or a 1 depending on whether specs pass or > fail. > > Am I doing something wrong with the story runner or would this need to > be patched to get it to work correctly? > It's something we haven't implemented, so a patch at http://rspec.lighthouseapp.com/ would be great. Aslak > Thanks, > > Ben > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From matt-lists at reprocessed.org Tue Jan 8 10:55:17 2008 From: matt-lists at reprocessed.org (Matt Patterson) Date: Tue, 8 Jan 2008 15:55:17 +0000 Subject: [rspec-users] Problems with rspec 1.1 required inside rake tasks Message-ID: This is interesting. The default rspec rake tasks generated by Hoe give you an rspec.rake file that looks like: > begin > require 'spec' > rescue LoadError > require 'rubygems' > require 'spec' > end > So far so good. When you invoke rake to do something, say check_manifest > rake check_manifest > You wind up with a Runtime error, as follows: > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.1/lib/spec/runner/ > options.rb:216:in `files_to_load': File or directory not found: > check_manifest (RuntimeError) > from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.1/lib/spec/ > runner/options.rb:210:in `each' > from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.1/lib/spec/ > runner/options.rb:210:in `files_to_load' > from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.1/lib/spec/ > runner/options.rb:83:in `run_examples' > from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.1/lib/ > spec.rb:20:in `run' > from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.1/lib/ > spec.rb:34 > from /usr/local/bin/rdebug:19 > Note that the spec runner is trying to load 'check_manifest', the argument to rake... The reason is that rspec-1.1.1/lib/spec.rb's at_exit hook is being invoked by, I presume, require 'spec' Is there a better way to require rspec (this worked fine in 1.0.8 and recent trunks), or should I be filing a bug? Thanks, Matt -- Matt Patterson | Design & Code | http://www.reprocessed.org/ From bryan at osesm.com Tue Jan 8 12:01:25 2008 From: bryan at osesm.com (Bryan Liles) Date: Tue, 8 Jan 2008 12:01:25 -0500 Subject: [rspec-users] Problems with rspec 1.1 required inside rake tasks In-Reply-To: References: Message-ID: <8804BB78-A61C-4E67-977F-38306E158D97@osesm.com> On Jan 8, 2008, at 10:55 AM, Matt Patterson wrote: > > > When you invoke rake to do something, say check_manifest > > >> rake check_manifest >> > > You wind up with a Runtime error, as follows: > > >> /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.1/lib/spec/runner/ >> options.rb:216:in `files_to_load': File or directory not found: >> check_manifest (RuntimeError) >> from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.1/lib/spec/ >> runner/options.rb:210:in `each' >> from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.1/lib/spec/ >> runner/options.rb:210:in `files_to_load' >> from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.1/lib/spec/ >> runner/options.rb:83:in `run_examples' >> from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.1/lib/ >> spec.rb:20:in `run' >> from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.1/lib/ >> spec.rb:34 >> from /usr/local/bin/rdebug:19 >> > > Note that the spec runner is trying to load 'check_manifest', the > argument to rake... > > The reason is that rspec-1.1.1/lib/spec.rb's at_exit hook is being > invoked by, I presume, require 'spec' > > Is there a better way to require rspec (this worked fine in 1.0.8 and > recent trunks), or should I be filing a bug? > I think it is some weird bug, and the solution that I am using until it is resolved is to do this add this to my rake task. module Spec class << self; def run; false; end; end end From lists at ruby-forum.com Tue Jan 8 13:39:53 2008 From: lists at ruby-forum.com (Chris Olsen) Date: Tue, 8 Jan 2008 19:39:53 +0100 Subject: [rspec-users] specs on private methods Message-ID: <840215067e9a8ce8de426499acb0d2a5@ruby-forum.com> How does a person test private methods? Is there a way to declare them as private, but retain any tests that were written during the initial development? Thanks. -- Posted via http://www.ruby-forum.com/. From matt-lists at reprocessed.org Tue Jan 8 14:02:31 2008 From: matt-lists at reprocessed.org (Matt Patterson) Date: Tue, 8 Jan 2008 19:02:31 +0000 Subject: [rspec-users] Problems with rspec 1.1 required inside rake tasks In-Reply-To: <8804BB78-A61C-4E67-977F-38306E158D97@osesm.com> References: <8804BB78-A61C-4E67-977F-38306E158D97@osesm.com> Message-ID: <7DB1F1B6-04D4-440F-A5F1-FD0615B2397E@reprocessed.org> On 8 Jan 2008, at 17:01, Bryan Liles wrote: >> Is there a better way to require rspec (this worked fine in 1.0.8 and >> recent trunks), or should I be filing a bug? >> > I think it is some weird bug, and the solution that I am using until > it is resolved is to do this add this to my rake task. > > module Spec > class << self; def run; false; end; end > end I solved it by changing the require stanza: > begin > require 'spec' > rescue LoadError > require 'rubygems' > require 'spec' > end > begin > require 'spec/rake/spectask' > rescue LoadError > ... to: begin require 'spec/rake/spectask' rescue LoadError require 'rubygems' gem 'rspec' end begin require 'spec/rake/spectask' rescue LoadError ... (Based on the rspec.rake Hoe / newgem threw in) That does the trick, rake spec still works, and I can run other rake tasks without explosions. I'd still like to know whether this is a bug or if there's a change in require best practice... I'll file a bug if it is... Matt -- Matt Patterson | Design & Code | http://www.reprocessed.org/ From matt-lists at reprocessed.org Tue Jan 8 14:06:00 2008 From: matt-lists at reprocessed.org (Matt Patterson) Date: Tue, 8 Jan 2008 19:06:00 +0000 Subject: [rspec-users] specs on private methods In-Reply-To: <840215067e9a8ce8de426499acb0d2a5@ruby-forum.com> References: <840215067e9a8ce8de426499acb0d2a5@ruby-forum.com> Message-ID: On 8 Jan 2008, at 18:39, Chris Olsen wrote: > How does a person test private methods? > > Is there a way to declare them as private, but retain any tests that > were written during the initial development? I'm rather liking Jay Field's approach (described at http:// blog.jayfields.com/2007/11/ruby-testing-private-methods.html) In which he basically redeclares the private methods public for the duration of the test only, with a bit of block-scoped evaling goodness. Matt -- Matt Patterson | Design & Code | http://www.reprocessed.org/ From daniel.ruby at tenner.org Tue Jan 8 14:14:30 2008 From: daniel.ruby at tenner.org (Daniel Tenner) Date: Tue, 8 Jan 2008 19:14:30 +0000 Subject: [rspec-users] specs on private methods In-Reply-To: References: <840215067e9a8ce8de426499acb0d2a5@ruby-forum.com> Message-ID: <071A280E-9D43-497B-ABAE-01FD15716D75@tenner.org> Might be a personal thing, but my approach is that I try to test the public behaviour of the object. Testing private methods is, imho, getting dangerously close to specifying how the object does its business, rather than what it does. I would just spec the externally visible behaviour, where it occurs, and let the object implement it as it wants (using private methods or any other mechanism). Daniel On 8 Jan 2008, at 19:06 8 Jan 2008, Matt Patterson wrote: > On 8 Jan 2008, at 18:39, Chris Olsen wrote: > >> How does a person test private methods? >> >> Is there a way to declare them as private, but retain any tests that >> were written during the initial development? > > I'm rather liking Jay Field's approach (described at http:// > blog.jayfields.com/2007/11/ruby-testing-private-methods.html) > > In which he basically redeclares the private methods public for the > duration of the test only, with a bit of block-scoped evaling > goodness. > > Matt > > -- > Matt Patterson | Design & Code > | http://www.reprocessed.org/ > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From ben at benmabey.com Tue Jan 8 14:20:58 2008 From: ben at benmabey.com (Ben Mabey) Date: Tue, 08 Jan 2008 12:20:58 -0700 Subject: [rspec-users] specs on private methods In-Reply-To: <840215067e9a8ce8de426499acb0d2a5@ruby-forum.com> References: <840215067e9a8ce8de426499acb0d2a5@ruby-forum.com> Message-ID: <4783CD1A.4000506@benmabey.com> Chris Olsen wrote: > How does a person test private methods? > > Is there a way to declare them as private, but retain any tests that > were written during the initial development? > > Thanks. > When I need to do this I just use the send method. -Ben From matt-lists at reprocessed.org Tue Jan 8 14:25:56 2008 From: matt-lists at reprocessed.org (Matt Patterson) Date: Tue, 8 Jan 2008 19:25:56 +0000 Subject: [rspec-users] specs on private methods In-Reply-To: <071A280E-9D43-497B-ABAE-01FD15716D75@tenner.org> References: <840215067e9a8ce8de426499acb0d2a5@ruby-forum.com> <071A280E-9D43-497B-ABAE-01FD15716D75@tenner.org> Message-ID: <2814261D-8B77-49E7-854C-4D4FE30926C6@reprocessed.org> On 8 Jan 2008, at 19:14, Daniel Tenner wrote: > Might be a personal thing, but my approach is that I try to test the > public behaviour of the object. Testing private methods is, imho, > getting dangerously close to specifying how the object does its > business, rather than what it does. > If you're a proponent of many-skinny-methods then you wind up with a lot of public methods which should never need to be called by another object, so making them private can be a good thing for general users of the object. > I would just spec the externally visible behaviour, where it occurs, > and let the object implement it as it wants (using private methods or > any other mechanism). > If the object were to implement it itself, that would be great ;-) Unfortunately, I have to implement the innards, and I'm rubbish so I like to test things... Matt -- Matt Patterson | Design & Code | http://www.reprocessed.org/ From mailing_lists at railsnewbie.com Tue Jan 8 14:27:21 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Tue, 8 Jan 2008 14:27:21 -0500 Subject: [rspec-users] specs on private methods In-Reply-To: <4783CD1A.4000506@benmabey.com> References: <840215067e9a8ce8de426499acb0d2a5@ruby-forum.com> <4783CD1A.4000506@benmabey.com> Message-ID: <29941B44-81FC-40CC-A5E4-2D892A65E7E6@railsnewbie.com> On Jan 8, 2008, at 2:20 PM, Ben Mabey wrote: > Chris Olsen wrote: >> How does a person test private methods? >> >> Is there a way to declare them as private, but retain any tests that >> were written during the initial development? >> >> Thanks. >> > When I need to do this I just use the send method. But it will break in 1.9 and on! (That's why Jay Fields didn't do it in his post). Scott From timcharper at gmail.com Tue Jan 8 14:32:36 2008 From: timcharper at gmail.com (Tim Harper) Date: Tue, 8 Jan 2008 12:32:36 -0700 Subject: [rspec-users] specs on private methods In-Reply-To: <29941B44-81FC-40CC-A5E4-2D892A65E7E6@railsnewbie.com> References: <840215067e9a8ce8de426499acb0d2a5@ruby-forum.com> <4783CD1A.4000506@benmabey.com> <29941B44-81FC-40CC-A5E4-2D892A65E7E6@railsnewbie.com> Message-ID: Doesn't 1.9 allow you to call obj.send!, which will allow you to access private methods? Tim On Jan 8, 2008, at 12:27 PM, Scott Taylor wrote: > > On Jan 8, 2008, at 2:20 PM, Ben Mabey wrote: > >> Chris Olsen wrote: >>> How does a person test private methods? >>> >>> Is there a way to declare them as private, but retain any tests that >>> were written during the initial development? >>> >>> Thanks. >>> >> When I need to do this I just use the send method. > > But it will break in 1.9 and on! (That's why Jay Fields didn't do it > in his post). > > Scott > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From ben at benmabey.com Tue Jan 8 14:36:52 2008 From: ben at benmabey.com (Ben Mabey) Date: Tue, 08 Jan 2008 12:36:52 -0700 Subject: [rspec-users] specs on private methods In-Reply-To: References: <840215067e9a8ce8de426499acb0d2a5@ruby-forum.com> <4783CD1A.4000506@benmabey.com> <29941B44-81FC-40CC-A5E4-2D892A65E7E6@railsnewbie.com> Message-ID: <4783D0D4.9080501@benmabey.com> Yes. http://eigenclass.org/hiki/Changes+in+Ruby+1.9#l24 Tim Harper wrote: > Doesn't 1.9 allow you to call obj.send!, which will allow you to > access private methods? > > Tim > > On Jan 8, 2008, at 12:27 PM, Scott Taylor wrote: > > >> On Jan 8, 2008, at 2:20 PM, Ben Mabey wrote: >> >> >>> Chris Olsen wrote: >>> >>>> How does a person test private methods? >>>> >>>> Is there a way to declare them as private, but retain any tests that >>>> were written during the initial development? >>>> >>>> Thanks. >>>> >>>> >>> When I need to do this I just use the send method. >>> >> But it will break in 1.9 and on! (That's why Jay Fields didn't do it >> in his post). >> >> Scott >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From timcharper at gmail.com Tue Jan 8 14:44:21 2008 From: timcharper at gmail.com (Tim Harper) Date: Tue, 8 Jan 2008 12:44:21 -0700 Subject: [rspec-users] specs on private methods In-Reply-To: <4783D0D4.9080501@benmabey.com> References: <840215067e9a8ce8de426499acb0d2a5@ruby-forum.com> <4783CD1A.4000506@benmabey.com> <29941B44-81FC-40CC-A5E4-2D892A65E7E6@railsnewbie.com> <4783D0D4.9080501@benmabey.com> Message-ID: <82F3D2B9-BA68-4EE2-8D00-A4F9927ABF86@gmail.com> Well there we go, Ben's method still stands :) Tim On Jan 8, 2008, at 12:36 PM, Ben Mabey wrote: > Yes. http://eigenclass.org/hiki/Changes+in+Ruby+1.9#l24 > > Tim Harper wrote: >> Doesn't 1.9 allow you to call obj.send!, which will allow you to >> access private methods? >> >> Tim >> >> On Jan 8, 2008, at 12:27 PM, Scott Taylor wrote: >> >> >>> On Jan 8, 2008, at 2:20 PM, Ben Mabey wrote: >>> >>> >>>> Chris Olsen wrote: >>>> >>>>> How does a person test private methods? >>>>> >>>>> Is there a way to declare them as private, but retain any tests >>>>> that >>>>> were written during the initial development? >>>>> >>>>> Thanks. >>>>> >>>>> >>>> When I need to do this I just use the send method. >>>> >>> But it will break in 1.9 and on! (That's why Jay Fields didn't do >>> it >>> in his post). >>> >>> Scott >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Tue Jan 8 15:47:21 2008 From: lists at ruby-forum.com (Chris Olsen) Date: Tue, 8 Jan 2008 21:47:21 +0100 Subject: [rspec-users] specs on private methods In-Reply-To: <82F3D2B9-BA68-4EE2-8D00-A4F9927ABF86@gmail.com> References: <840215067e9a8ce8de426499acb0d2a5@ruby-forum.com> <4783CD1A.4000506@benmabey.com> <29941B44-81FC-40CC-A5E4-2D892A65E7E6@railsnewbie.com> <4783D0D4.9080501@benmabey.com> <82F3D2B9-BA68-4EE2-8D00-A4F9927ABF86@gmail.com> Message-ID: <7780c17e13c824b3343b5dc9253ea52f@ruby-forum.com> Will obj.send(:method) work in 1.9 or is it saying that the send call requires 2 params, the method and the object reference? -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Tue Jan 8 19:31:50 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 8 Jan 2008 18:31:50 -0600 Subject: [rspec-users] specs on private methods In-Reply-To: <7780c17e13c824b3343b5dc9253ea52f@ruby-forum.com> References: <840215067e9a8ce8de426499acb0d2a5@ruby-forum.com> <4783CD1A.4000506@benmabey.com> <29941B44-81FC-40CC-A5E4-2D892A65E7E6@railsnewbie.com> <4783D0D4.9080501@benmabey.com> <82F3D2B9-BA68-4EE2-8D00-A4F9927ABF86@gmail.com> <7780c17e13c824b3343b5dc9253ea52f@ruby-forum.com> Message-ID: <57c63afe0801081631s32b983cegd76fad7f0bf97672@mail.gmail.com> On Jan 8, 2008 2:47 PM, Chris Olsen wrote: > Will obj.send(:method) work in 1.9 or is it saying that the send call > requires 2 params, the method and the object reference? In 1.9 you can say obj.send!(:method) even if :method is private. obj.send(:method) will not work for private methods. From francois.wurmus at infopark.de Tue Jan 8 16:09:40 2008 From: francois.wurmus at infopark.de (Francois Wurmus) Date: Tue, 08 Jan 2008 22:09:40 +0100 Subject: [rspec-users] specs on private methods In-Reply-To: <7780c17e13c824b3343b5dc9253ea52f@ruby-forum.com> References: <840215067e9a8ce8de426499acb0d2a5@ruby-forum.com> <4783CD1A.4000506@benmabey.com> <29941B44-81FC-40CC-A5E4-2D892A65E7E6@railsnewbie.com> <4783D0D4.9080501@benmabey.com> <82F3D2B9-BA68-4EE2-8D00-A4F9927ABF86@gmail.com> <7780c17e13c824b3343b5dc9253ea52f@ruby-forum.com> Message-ID: <4783E694.20908@infopark.de> The send call never expects an object reference as a parameter. Either it is called on an object or without an object context (i.e. kernel). In the first case the parameter should contain one of the receiving object's methods. In the second case the parameter is a kernel method. But... that's not really an RSpec topic anymore. Chris Olsen schrieb: > Will obj.send(:method) work in 1.9 or is it saying that the send call > requires 2 params, the method and the object reference? > > From dchelimsky at gmail.com Tue Jan 8 20:41:29 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 8 Jan 2008 19:41:29 -0600 Subject: [rspec-users] specs on private methods In-Reply-To: <2814261D-8B77-49E7-854C-4D4FE30926C6@reprocessed.org> References: <840215067e9a8ce8de426499acb0d2a5@ruby-forum.com> <071A280E-9D43-497B-ABAE-01FD15716D75@tenner.org> <2814261D-8B77-49E7-854C-4D4FE30926C6@reprocessed.org> Message-ID: <57c63afe0801081741v568183ednf322254c1e7ba9a8@mail.gmail.com> On Jan 8, 2008 1:25 PM, Matt Patterson wrote: > On 8 Jan 2008, at 19:14, Daniel Tenner wrote: > > > > Might be a personal thing, but my approach is that I try to test the > > public behaviour of the object. Testing private methods is, imho, > > getting dangerously close to specifying how the object does its > > business, rather than what it does. > > > > If you're a proponent of many-skinny-methods then you wind up with a > lot of public methods which should never need to be called by another > object, so making them private can be a good thing for general users > of the object. Keep in mind that if you're specifying object behaviour with the prescribed granular red/green/refactor cycle, then the examples are all against public methods. Private methods should only ever appear as a result of refactoring. Those are the many-skinny that you are talking about. > > > I would just spec the externally visible behaviour, where it occurs, > > and let the object implement it as it wants (using private methods or > > any other mechanism). > > > > If the object were to implement it itself, that would be great ;-) > Unfortunately, I have to implement the innards, and I'm rubbish so I > like to test things... You should check out the bowling kata (http://butunclebob.com/ArticleS.UncleBob.TheBowlingGameKata) if you haven't. At the end there are just a few tests and they all touch only 2 public methods, but there are many, many smaller methods that appear through refactoring. They are all thoroughly tested, though not directly. Cheers, David From francois.wurmus at infopark.de Tue Jan 8 15:56:40 2008 From: francois.wurmus at infopark.de (Francois Wurmus) Date: Tue, 08 Jan 2008 21:56:40 +0100 Subject: [rspec-users] specs on private methods In-Reply-To: <7780c17e13c824b3343b5dc9253ea52f@ruby-forum.com> References: <840215067e9a8ce8de426499acb0d2a5@ruby-forum.com> <4783CD1A.4000506@benmabey.com> <29941B44-81FC-40CC-A5E4-2D892A65E7E6@railsnewbie.com> <4783D0D4.9080501@benmabey.com> <82F3D2B9-BA68-4EE2-8D00-A4F9927ABF86@gmail.com> <7780c17e13c824b3343b5dc9253ea52f@ruby-forum.com> Message-ID: <4783E388.5070708@infopark.de> obj.send(:method) will work for non-private methods and send! works for private methods. additionally there is send() without a receiving object. that is the only of those methods requiring two parameters. Chris Olsen schrieb: > Will obj.send(:method) work in 1.9 or is it saying that the send call > requires 2 params, the method and the object reference? > > From stefan.landro at gmail.com Wed Jan 9 05:01:15 2008 From: stefan.landro at gmail.com (=?ISO-8859-1?Q?Stefan_Magnus_Landr=F8?=) Date: Wed, 9 Jan 2008 11:01:15 +0100 Subject: [rspec-users] specs on private methods In-Reply-To: <57c63afe0801081741v568183ednf322254c1e7ba9a8@mail.gmail.com> References: <840215067e9a8ce8de426499acb0d2a5@ruby-forum.com> <071A280E-9D43-497B-ABAE-01FD15716D75@tenner.org> <2814261D-8B77-49E7-854C-4D4FE30926C6@reprocessed.org> <57c63afe0801081741v568183ednf322254c1e7ba9a8@mail.gmail.com> Message-ID: <921ca2f80801090201i73c2414dk9785522f82880def@mail.gmail.com> I totally agree with you, David! For quite a while I was testing all my methods (even had to declare them protected/package scope in java!), but I realized that I was getting into a lot of trouble. Now I've shifted to testing functionality in stead of methods. Now, sometimes you might end up having small methods (typically a result of refactoring) that are being used by several clients. In that case you should start testing those methods, since they actually represent real business logic. I talked to uncle Bob about this issue just a few months ago, and as far as I understood, he uses a similar approach. I think it might make sense to think of the facade pattern when you do your testing - do you really care what happens behind the facade? Stefan 2008/1/9, David Chelimsky : > > On Jan 8, 2008 1:25 PM, Matt Patterson wrote: > > You should check out the bowling kata > (http://butunclebob.com/ArticleS.UncleBob.TheBowlingGameKata) if you > haven't. At the end there are just a few tests and they all touch only > 2 public methods, but there are many, many smaller methods that appear > through refactoring. They are all thoroughly tested, though not > directly. > > Cheers, > David > ______________ -- Bekk Open Source http://boss.bekk.no -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080109/786c9b45/attachment.html From daniel.ruby at tenner.org Wed Jan 9 05:11:18 2008 From: daniel.ruby at tenner.org (Daniel Tenner) Date: Wed, 9 Jan 2008 10:11:18 +0000 Subject: [rspec-users] specs on private methods In-Reply-To: <921ca2f80801090201i73c2414dk9785522f82880def@mail.gmail.com> References: <840215067e9a8ce8de426499acb0d2a5@ruby-forum.com> <071A280E-9D43-497B-ABAE-01FD15716D75@tenner.org> <2814261D-8B77-49E7-854C-4D4FE30926C6@reprocessed.org> <57c63afe0801081741v568183ednf322254c1e7ba9a8@mail.gmail.com> <921ca2f80801090201i73c2414dk9785522f82880def@mail.gmail.com> Message-ID: Just to clarify, this is what I meant in my original email :-) Most of my methods are very small - in Ruby any method longer than 5 lines is, imho, a code smell that's waiting to be fixed. However, no matter how many methods are used to implement the functionality, I test the public behaviour of the object rather than the methods themselves. Sometimes, this maps directly to a public method. Sometimes, a spec will actually use several public methods in concert. With this approach, I never spec private methods. Daniel On 9 Jan 2008, at 10:01 9 Jan 2008, Stefan Magnus Landr? wrote: > I totally agree with you, David! > > For quite a while I was testing all my methods (even had to declare > them protected/package scope in java!), but I realized that I was > getting into a lot of trouble. Now I've shifted to testing > functionality in stead of methods. > > Now, sometimes you might end up having small methods (typically a > result of refactoring) that are being used by several clients. In > that case you should start testing those methods, since they > actually represent real business logic. > I talked to uncle Bob about this issue just a few months ago, and > as far as I understood, he uses a similar approach. > > I think it might make sense to think of the facade pattern when you > do your testing - do you really care what happens behind the facade? > > Stefan > > 2008/1/9, David Chelimsky : > On Jan 8, 2008 1:25 PM, Matt Patterson > wrote: > > You should check out the bowling kata > ( http://butunclebob.com/ArticleS.UncleBob.TheBowlingGameKata) if you > haven't. At the end there are just a few tests and they all touch only > 2 public methods, but there are many, many smaller methods that appear > through refactoring. They are all thoroughly tested, though not > directly. > > Cheers, > David > ______________ > > -- > Bekk Open Source > http://boss.bekk.no > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080109/eb7c2f0a/attachment.html From kerry at kerrybuckley.com Wed Jan 9 07:09:39 2008 From: kerry at kerrybuckley.com (Kerry Buckley) Date: Wed, 9 Jan 2008 12:09:39 +0000 Subject: [rspec-users] specs on private methods In-Reply-To: <921ca2f80801090201i73c2414dk9785522f82880def@mail.gmail.com> References: <840215067e9a8ce8de426499acb0d2a5@ruby-forum.com> <071A280E-9D43-497B-ABAE-01FD15716D75@tenner.org> <2814261D-8B77-49E7-854C-4D4FE30926C6@reprocessed.org> <57c63afe0801081741v568183ednf322254c1e7ba9a8@mail.gmail.com> <921ca2f80801090201i73c2414dk9785522f82880def@mail.gmail.com> Message-ID: <808f9ec90801090409t19e7c655k934660ff76cd1d8@mail.gmail.com> On Jan 9, 2008 10:01 AM, Stefan Magnus Landr? wrote: > I totally agree with you, David! > > For quite a while I was testing all my methods (even had to declare them > protected/package scope in java!), but I realized that I was getting into a > lot of trouble. Now I've shifted to testing functionality in stead of > methods. > > Now, sometimes you might end up having small methods (typically a result of > refactoring) that are being used by several clients. In that case you should > start testing those methods, since they actually represent real business > logic. I wonder whether that is a smell indicating that the functionality in those methods really belongs in its own class? Kerry -- http://www.kerrybuckley.com/ From stefan.landro at gmail.com Wed Jan 9 08:12:17 2008 From: stefan.landro at gmail.com (=?ISO-8859-1?Q?Stefan_Magnus_Landr=F8?=) Date: Wed, 9 Jan 2008 14:12:17 +0100 Subject: [rspec-users] specs on private methods In-Reply-To: <808f9ec90801090409t19e7c655k934660ff76cd1d8@mail.gmail.com> References: <840215067e9a8ce8de426499acb0d2a5@ruby-forum.com> <071A280E-9D43-497B-ABAE-01FD15716D75@tenner.org> <2814261D-8B77-49E7-854C-4D4FE30926C6@reprocessed.org> <57c63afe0801081741v568183ednf322254c1e7ba9a8@mail.gmail.com> <921ca2f80801090201i73c2414dk9785522f82880def@mail.gmail.com> <808f9ec90801090409t19e7c655k934660ff76cd1d8@mail.gmail.com> Message-ID: <921ca2f80801090512k71a9e69exb1c08f38cc1a446b@mail.gmail.com> Well, I think it all depends on the scenario - but in a lot of cases it should absolutely be considered a code-smell. Stefan 2008/1/9, Kerry Buckley : > > On Jan 9, 2008 10:01 AM, Stefan Magnus Landr? > wrote: > > I totally agree with you, David! > > > > For quite a while I was testing all my methods (even had to declare them > > protected/package scope in java!), but I realized that I was getting > into a > > lot of trouble. Now I've shifted to testing functionality in stead of > > methods. > > > > Now, sometimes you might end up having small methods (typically a result > of > > refactoring) that are being used by several clients. In that case you > should > > start testing those methods, since they actually represent real business > > logic. > > I wonder whether that is a smell indicating that the functionality in > those methods really belongs in its own class? > > Kerry > -- > http://www.kerrybuckley.com/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Bekk Open Source http://boss.bekk.no -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080109/c03ae384/attachment.html From dchelimsky at gmail.com Wed Jan 9 08:15:07 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 9 Jan 2008 07:15:07 -0600 Subject: [rspec-users] specs on private methods In-Reply-To: <808f9ec90801090409t19e7c655k934660ff76cd1d8@mail.gmail.com> References: <840215067e9a8ce8de426499acb0d2a5@ruby-forum.com> <071A280E-9D43-497B-ABAE-01FD15716D75@tenner.org> <2814261D-8B77-49E7-854C-4D4FE30926C6@reprocessed.org> <57c63afe0801081741v568183ednf322254c1e7ba9a8@mail.gmail.com> <921ca2f80801090201i73c2414dk9785522f82880def@mail.gmail.com> <808f9ec90801090409t19e7c655k934660ff76cd1d8@mail.gmail.com> Message-ID: <57c63afe0801090515q4ebea87xc13b02ec7cf4b671@mail.gmail.com> On Jan 9, 2008 6:09 AM, Kerry Buckley wrote: > On Jan 9, 2008 10:01 AM, Stefan Magnus Landr? wrote: > > I totally agree with you, David! Then you agree with the majority of the TDD community. > > > > For quite a while I was testing all my methods (even had to declare them > > protected/package scope in java!), but I realized that I was getting into a > > lot of trouble. Now I've shifted to testing functionality in stead of > > methods. > > > > Now, sometimes you might end up having small methods (typically a result of > > refactoring) that are being used by several clients. In that case you should > > start testing those methods, since they actually represent real business > > logic. Again, if they appear through refactoring, then they ARE tested through the public methods. The only time I would test them directly would be in the process of trying to locate the source of a bug, or if I wanted to move the method to another class because it represented a fundamentally different concept from the one represented by its current class. This is all TDD 101 stuff. Maybe we should have required reading on this list ;) Here are a few suggestions: http://www.amazon.com/Software-Development-Principles-Patterns-Practices/dp/0135974445/ http://www.amazon.com/Refactoring-Improving-Existing-Addison-Wesley-Technology/dp/0201485672 http://www.amazon.com/Test-Driven-Development-Practical-Guide-Coad/dp/0131016490/ http://www.amazon.com/Test-Driven-Development-Addison-Wesley-Signature/dp/0321146530/ These sorts of questions are explored in great detail in these books. Cheers, David > > I wonder whether that is a smell indicating that the functionality in > those methods really belongs in its own class? > > Kerry > -- > http://www.kerrybuckley.com/ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Wed Jan 9 08:18:44 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 9 Jan 2008 07:18:44 -0600 Subject: [rspec-users] specs on private methods In-Reply-To: <921ca2f80801090512k71a9e69exb1c08f38cc1a446b@mail.gmail.com> References: <840215067e9a8ce8de426499acb0d2a5@ruby-forum.com> <071A280E-9D43-497B-ABAE-01FD15716D75@tenner.org> <2814261D-8B77-49E7-854C-4D4FE30926C6@reprocessed.org> <57c63afe0801081741v568183ednf322254c1e7ba9a8@mail.gmail.com> <921ca2f80801090201i73c2414dk9785522f82880def@mail.gmail.com> <808f9ec90801090409t19e7c655k934660ff76cd1d8@mail.gmail.com> <921ca2f80801090512k71a9e69exb1c08f38cc1a446b@mail.gmail.com> Message-ID: <57c63afe0801090518q633311ddmdbca42bdd9f9ba12@mail.gmail.com> On Jan 9, 2008 7:12 AM, Stefan Magnus Landr? wrote: > > 2008/1/9, Kerry Buckley < kerry at kerrybuckley.com>: > > > On Jan 9, 2008 10:01 AM, Stefan Magnus Landr? < stefan.landro at gmail.com> > wrote: > > > I totally agree with you, David! > > > > > > For quite a while I was testing all my methods (even had to declare them > > > protected/package scope in java!), but I realized that I was getting > into a > > > lot of trouble. Now I've shifted to testing functionality in stead of > > > methods. > > > > > > Now, sometimes you might end up having small methods (typically a result > of > > > refactoring) that are being used by several clients. In that case you > should > > > start testing those methods, since they actually represent real business > > > logic. > > > > I wonder whether that is a smell indicating that the functionality in > > those methods really belongs in its own class? > Well, I think it all depends on the scenario - but in a lot of cases it > should absolutely be considered a code-smell. Keep in mind that a code smell is an indicator, but not a dictator. It is supposed to draw your attention but you still have to consider the pros and cons and make a reasoned decision. Cheers, David From richard.conroy at gmail.com Wed Jan 9 08:26:50 2008 From: richard.conroy at gmail.com (Richard Conroy) Date: Wed, 9 Jan 2008 13:26:50 +0000 Subject: [rspec-users] specs on private methods In-Reply-To: <071A280E-9D43-497B-ABAE-01FD15716D75@tenner.org> References: <840215067e9a8ce8de426499acb0d2a5@ruby-forum.com> <071A280E-9D43-497B-ABAE-01FD15716D75@tenner.org> Message-ID: <511fa3a20801090526k5f1163f9ybec1ec8bbafd14ac@mail.gmail.com> On Jan 8, 2008 7:14 PM, Daniel Tenner wrote: > Might be a personal thing, but my approach is that I try to test the > public behaviour of the object. Testing private methods is, imho, > getting dangerously close to specifying how the object does its > business, rather than what it does. > > I would just spec the externally visible behaviour, where it occurs, > and let the object implement it as it wants (using private methods or > any other mechanism). The trouble is that this makes it very difficult to get effective coverage. There is usually a lot more setup involved. If your tests are more expensive to write, because you are unit testing indirectly through public methods, less testing will get done, and worse tests can end up getting very brittle. I do like the idea though of during the unit test itself, you unseal the method. You get the best of both worlds. From dchelimsky at gmail.com Wed Jan 9 08:43:18 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 9 Jan 2008 07:43:18 -0600 Subject: [rspec-users] specs on private methods In-Reply-To: <511fa3a20801090526k5f1163f9ybec1ec8bbafd14ac@mail.gmail.com> References: <840215067e9a8ce8de426499acb0d2a5@ruby-forum.com> <071A280E-9D43-497B-ABAE-01FD15716D75@tenner.org> <511fa3a20801090526k5f1163f9ybec1ec8bbafd14ac@mail.gmail.com> Message-ID: <57c63afe0801090543p11f11f7chc9cb77b929637696@mail.gmail.com> On Jan 9, 2008 7:26 AM, Richard Conroy wrote: > On Jan 8, 2008 7:14 PM, Daniel Tenner wrote: > > Might be a personal thing, but my approach is that I try to test the > > public behaviour of the object. Testing private methods is, imho, > > getting dangerously close to specifying how the object does its > > business, rather than what it does. > > > > I would just spec the externally visible behaviour, where it occurs, > > and let the object implement it as it wants (using private methods or > > any other mechanism). > > The trouble is that this makes it very difficult to get effective coverage. > There is usually a lot more setup involved. If your tests are more expensive > to write, because you are unit testing indirectly through public methods, > less testing will get done, If you live by the rule of "never write a line of code except to get a failing example to pass," then you should always have 100% coverage implicitly. If you're back-filling that's a different story, but then we're not talking about BDD anymore. I'm not saying that I will never test private methods, but it's something that should be rare and avoided. FWIW, David > and worse tests can end up getting very brittle. > > I do like the idea though of during the unit test itself, you unseal the method. > You get the best of both worlds. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From stefan.landro at gmail.com Wed Jan 9 08:55:04 2008 From: stefan.landro at gmail.com (=?ISO-8859-1?Q?Stefan_Magnus_Landr=F8?=) Date: Wed, 9 Jan 2008 14:55:04 +0100 Subject: [rspec-users] specs on private methods In-Reply-To: <57c63afe0801090515q4ebea87xc13b02ec7cf4b671@mail.gmail.com> References: <840215067e9a8ce8de426499acb0d2a5@ruby-forum.com> <071A280E-9D43-497B-ABAE-01FD15716D75@tenner.org> <2814261D-8B77-49E7-854C-4D4FE30926C6@reprocessed.org> <57c63afe0801081741v568183ednf322254c1e7ba9a8@mail.gmail.com> <921ca2f80801090201i73c2414dk9785522f82880def@mail.gmail.com> <808f9ec90801090409t19e7c655k934660ff76cd1d8@mail.gmail.com> <57c63afe0801090515q4ebea87xc13b02ec7cf4b671@mail.gmail.com> Message-ID: <921ca2f80801090555h46461d74x123b9b2c66e55a7c@mail.gmail.com> This is also worth checking out: http://xunitpatterns.com/ -- Bekk Open Source http://boss.bekk.no -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080109/a02523a1/attachment.html From rick.denatale at gmail.com Wed Jan 9 12:01:54 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Wed, 9 Jan 2008 12:01:54 -0500 Subject: [rspec-users] specs on private methods In-Reply-To: <4783E388.5070708@infopark.de> References: <840215067e9a8ce8de426499acb0d2a5@ruby-forum.com> <4783CD1A.4000506@benmabey.com> <29941B44-81FC-40CC-A5E4-2D892A65E7E6@railsnewbie.com> <4783D0D4.9080501@benmabey.com> <82F3D2B9-BA68-4EE2-8D00-A4F9927ABF86@gmail.com> <7780c17e13c824b3343b5dc9253ea52f@ruby-forum.com> <4783E388.5070708@infopark.de> Message-ID: On Jan 8, 2008 3:56 PM, Francois Wurmus wrote: > Chris Olsen schrieb: > > Will obj.send(:method) work in 1.9 or is it saying that the send call > > requires 2 params, the method and the object reference? > > > obj.send(:method) will work for non-private methods and send! works for > private methods. I'm pretty sure that Matz backed this difference out between 1.8 and 1.9, he took out some of these things before the Christmas release of 1.9.0 Object#send will work for private methods as it always did, and Object#send! is no longer there. > additionally there is send() without a receiving object. that is the > only of those methods requiring two parameters. There's no such thing as a method call without a receiving object in Ruby send(:foo) is the same as self.send(:foo) Object#send takes an arbitrary number of arguments, the first argument is the method selector, the rest are used as arguments to the method being called. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From pergesu at gmail.com Thu Jan 10 01:44:46 2008 From: pergesu at gmail.com (Pat Maddox) Date: Wed, 9 Jan 2008 22:44:46 -0800 Subject: [rspec-users] specs on private methods In-Reply-To: <2814261D-8B77-49E7-854C-4D4FE30926C6@reprocessed.org> References: <840215067e9a8ce8de426499acb0d2a5@ruby-forum.com> <071A280E-9D43-497B-ABAE-01FD15716D75@tenner.org> <2814261D-8B77-49E7-854C-4D4FE30926C6@reprocessed.org> Message-ID: <810a540e0801092244s7c28ed55lbe1a6797c889037a@mail.gmail.com> On Jan 8, 2008 11:25 AM, Matt Patterson wrote: > On 8 Jan 2008, at 19:14, Daniel Tenner wrote: > > > > Might be a personal thing, but my approach is that I try to test the > > public behaviour of the object. Testing private methods is, imho, > > getting dangerously close to specifying how the object does its > > business, rather than what it does. > > > > If you're a proponent of many-skinny-methods then you wind up with a > lot of public methods which should never need to be called by another > object, so making them private can be a good thing for general users > of the object. There are several problems with this thinking: 1. It separates refactoring from BDD. Having several private helper methods is a result of refactoring. Refactoring is not only a design tool, but a central part of BDD. 2. It couples your specs too tightly to the implementation. If you rename/delete/add a private method, you need to update the spec, even though the object's public behavior didn't change. 3. It eliminates the effectiveness of specs as documentation. Reading the specs is one of the first things I do when examining some code. If I see examples of how to use it, except not really, because they're private methods, I'm going to be seriously confused or seriously pissed off. 4. It leads to violations of the "one defect, one broken test" guideline. Some spec that exercises public behavior covers this private method, as does its individual spec, so if it breaks, then you have two broken specs. Whether that's important is a matter of personal preference. There is no 1:1 mapping of specification example to method. You don't specify a method. You specify a behavior. There are no rules dictating the specification's granularity, as long as it helps you design your code in the beginning, and localize defects as your code base persists. Specifying private methods is, in my opinion, slightly less pleasant than week-old trout in my pillow. It means one of two things. At a code level, your method's visibility could just be off. At a conceptual level, you may be missing the point of BDD entirely. Pat From pergesu at gmail.com Thu Jan 10 01:56:19 2008 From: pergesu at gmail.com (Pat Maddox) Date: Wed, 9 Jan 2008 22:56:19 -0800 Subject: [rspec-users] specs on private methods In-Reply-To: <511fa3a20801090526k5f1163f9ybec1ec8bbafd14ac@mail.gmail.com> References: <840215067e9a8ce8de426499acb0d2a5@ruby-forum.com> <071A280E-9D43-497B-ABAE-01FD15716D75@tenner.org> <511fa3a20801090526k5f1163f9ybec1ec8bbafd14ac@mail.gmail.com> Message-ID: <810a540e0801092256i7cab9ec9t61abcb9a925e12df@mail.gmail.com> On Jan 9, 2008 5:26 AM, Richard Conroy wrote: > On Jan 8, 2008 7:14 PM, Daniel Tenner wrote: > > Might be a personal thing, but my approach is that I try to test the > > public behaviour of the object. Testing private methods is, imho, > > getting dangerously close to specifying how the object does its > > business, rather than what it does. > > > > I would just spec the externally visible behaviour, where it occurs, > > and let the object implement it as it wants (using private methods or > > any other mechanism). > > The trouble is that this makes it very difficult to get effective coverage. > There is usually a lot more setup involved. If your tests are more expensive > to write, because you are unit testing indirectly through public methods, > less testing will get done, and worse tests can end up getting very brittle. I've found that this is symptomatic of a bad design. Specifically, it smells of an SRP violation or tight coupling. One thing I think people don't realize is that a bit of code should be easiest to use in a test. We test objects in isolation, they don't depend on expensive external resources, etc. If you can't use the code within a test harness - that is, write a test for it - then how can you possibly expect to use it in production? In practice, of course, this can all be very difficult. I recommend reading "Working Effectively with Legacy Code" by Michael Feathers for some excellent strategies on how to make existing gnarly code easier to test. > I do like the idea though of during the unit test itself, you unseal the method. > You get the best of both worlds. Not really. You get test coverage, which is good, but at the expense of carefully thinking why your design might be wrong. Pat From chris at kampers.net Thu Jan 10 13:35:36 2008 From: chris at kampers.net (Chris Kampmeier) Date: Thu, 10 Jan 2008 10:35:36 -0800 Subject: [rspec-users] Mocking and stubbing Rails' association extensions Message-ID: <9E8FE35E-CA80-4839-8E91-1BCC9F7A38B1@kampers.net> 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 instance (say @album), I need to be able to stub both @album.songs and @album.songs.streamable in the same before block. Is there a way for a stub to return one thing when called alone (@album.songs) and another stub when the call is chained? (@album.songs.streamable) Before adding the extension, I just had @album.songs returning an array of Song instances. The only thing I've thought of that would work is temporarily extending Array itself to respond to #streamable, but that feels ugly. Thanks for any ideas, Chris Kampmeier http://www.shiftcommathree.com -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 2417 bytes Desc: not available Url : http://rubyforge.org/pipermail/rspec-users/attachments/20080110/57baee23/attachment.bin From dchelimsky at gmail.com Thu Jan 10 13:40:40 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 10 Jan 2008 12:40:40 -0600 Subject: [rspec-users] Mocking and stubbing Rails' association extensions In-Reply-To: <9E8FE35E-CA80-4839-8E91-1BCC9F7A38B1@kampers.net> References: <9E8FE35E-CA80-4839-8E91-1BCC9F7A38B1@kampers.net> Message-ID: <57c63afe0801101040p5c20905v2467d03ca24edd3f@mail.gmail.com> On Jan 10, 2008 12:35 PM, Chris Kampmeier 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(:all, :conditions => 'streamable = 1') > end > end > end > > So for a given Album instance (say @album), I need to be able to stub > both @album.songs and @album.songs.streamable in the same before block. > > Is there a way for a stub to return one thing when called alone > (@album.songs) and another stub when the call is chained? > (@album.songs.streamable) > > Before adding the extension, I just had @album.songs returning an > array of Song instances. The only thing I've thought of that would > work is temporarily extending Array itself to respond to #streamable, > but that feels ugly. 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. Cool? > > Thanks for any ideas, > > Chris Kampmeier > http://www.shiftcommathree.com > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From chris at kampers.net Thu Jan 10 14:07:44 2008 From: chris at kampers.net (Chris Kampmeier) Date: Thu, 10 Jan 2008 11:07:44 -0800 Subject: [rspec-users] Mocking and stubbing Rails' association extensions In-Reply-To: <57c63afe0801101040p5c20905v2467d03ca24edd3f@mail.gmail.com> References: <9E8FE35E-CA80-4839-8E91-1BCC9F7A38B1@kampers.net> <57c63afe0801101040p5c20905v2467d03ca24edd3f@mail.gmail.com> Message-ID: <94bfb5530801101107n1ebab8dfxee8e6c757933efe2@mail.gmail.com> On 1/10/08, David Chelimsky 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 when I call @album.songs. I need that object to act like a Rails association -- so it should respond to #each, #first, and all our other Enumerable friends, since my view iterates over it, as well as the stubbed call to #streamable, which returns a "filtered" version of the assocation (see Rails code in OP). But I certainly don't want to start stubbing Enumerable methods. # Let's say song1, song2, and song3 are instances of Song. # Song has a boolean attribute, streamable. # song1.streamable? => true # song2.streamable? => true # song3.streamable? => false album = mock("album") songs = mock("songs") album.stub!(:songs).and_return(songs) songs.stub!(:streamable).and_return([song1, song2]) So now album.songs.streamable returns [song1, song2] -- perfect. But I need album.songs to return [song1, song2, song3] as well. That's the problem. I hope that's a little clearer. Thanks for the help. Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080110/b151afac/attachment.html From rick.denatale at gmail.com Thu Jan 10 14:19:05 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Thu, 10 Jan 2008 14:19:05 -0500 Subject: [rspec-users] Mocking and stubbing Rails' association extensions In-Reply-To: <94bfb5530801101107n1ebab8dfxee8e6c757933efe2@mail.gmail.com> References: <9E8FE35E-CA80-4839-8E91-1BCC9F7A38B1@kampers.net> <57c63afe0801101040p5c20905v2467d03ca24edd3f@mail.gmail.com> <94bfb5530801101107n1ebab8dfxee8e6c757933efe2@mail.gmail.com> Message-ID: On 1/10/08, Chris Kampmeier wrote: > On 1/10/08, David Chelimsky 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 when I call @album.songs. I need > that object to act like a Rails association -- so it should respond to > #each, #first, and all our other Enumerable friends, since my view iterates > over it, as well as the stubbed call to #streamable, which returns a > "filtered" version of the assocation (see Rails code in OP). But I certainly > don't want to start stubbing Enumerable methods. > > # Let's say song1, song2, and song3 are instances of Song. > # Song has a boolean attribute, streamable. > # song1.streamable? => true > # song2.streamable? => true > # song3.streamable? => false > album = mock("album") > songs = mock("songs") > album.stub!(:songs).and_return(songs) > songs.stub!(:streamable).and_return([song1, song2]) > > So now album.songs.streamable returns [song1, song2] -- perfect. But I need > album.songs to return [song1, song2, song3] as well. That's the problem. So why not songs = [song1, song2, song3] album.stub!(:songs).and_return(songs) songs.stub!(:streamable).and_return([song1, song2]) -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From chris at kampers.net Thu Jan 10 14:38:55 2008 From: chris at kampers.net (Chris Kampmeier) Date: Thu, 10 Jan 2008 11:38:55 -0800 Subject: [rspec-users] Mocking and stubbing Rails' association extensions In-Reply-To: References: <9E8FE35E-CA80-4839-8E91-1BCC9F7A38B1@kampers.net> <57c63afe0801101040p5c20905v2467d03ca24edd3f@mail.gmail.com> <94bfb5530801101107n1ebab8dfxee8e6c757933efe2@mail.gmail.com> Message-ID: <94bfb5530801101138r6cc054ffvfca05b9188ebb3e2@mail.gmail.com> On 1/10/08, Rick DeNatale 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 think to just stub a method call on an existing array. Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080110/db2d6c94/attachment.html From barjunk at attglobal.net Thu Jan 10 14:50:49 2008 From: barjunk at attglobal.net (barsalou) Date: Thu, 10 Jan 2008 10:50:49 -0900 Subject: [rspec-users] specs on private methods Message-ID: <20080110105049.z4gu8q49gko8wo4o@lcgalaska.com> 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 @signup = Signup.new end it "she be a valid mac address" do @signup.mac_address = "00-11-22-33-44-55-66" normalized = @signup.normalize_mac(@signup.mac_address) @signup.mac_address.should == normalized end end I have a model that has mac_address attribute. In the before validation, I wanted to make the mac address have colons(:) instead of whatever the user typed in which could have spaces between, dashes, nothing at all. My thought was to just remove all of those special characters validate it against a regex then if it passed the regex check produce the mac address with the colons included. And, if I understand it properly, Pat's statement is saying that I really shouldn't be protecting that method...which would fix my problem. So my question is then, how do you know when to use protected and private or do I just do what Rick suggested and use send? I just realized this isn't really an rspec question...so I'll just move along. Mike B. ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From francois.wurmus at infopark.de Thu Jan 10 15:21:17 2008 From: francois.wurmus at infopark.de (Francois Wurmus) Date: Thu, 10 Jan 2008 21:21:17 +0100 Subject: [rspec-users] specs on private methods In-Reply-To: <20080110105049.z4gu8q49gko8wo4o@lcgalaska.com> References: <20080110105049.z4gu8q49gko8wo4o@lcgalaska.com> Message-ID: <47867E3D.1030003@infopark.de> 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 implemented wrong and just returns nil. Let's further assume that @signup.mac_address calls a reader method returning nil, too. Such an implementation, though wrong, would satisfy your spec! A second problem is, that the parameter you are passing to the normalize-method will already have been transformed before your method gets its hands on it. You are not passing the init value but the value that is returned be a read operation on the mac_address field. What you really should specify is your concrete mac address format: it "should return a valid mac address" do @signup.mac_address = "00-11-22-33-44-55" @signup.mac_address.should == "00:11:22:33:44:55" end Now you are not only implementation independent but your spec is also saying more. Fran?ois barsalou schrieb: > 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 > @signup = Signup.new > end > > it "she be a valid mac address" do > @signup.mac_address = "00-11-22-33-44-55-66" > normalized = @signup.normalize_mac(@signup.mac_address) > @signup.mac_address.should == normalized > end > end > > > I have a model that has mac_address attribute. In the before > validation, I wanted to make the mac address have colons(:) instead of > whatever the user typed in which could have spaces between, dashes, > nothing at all. > > My thought was to just remove all of those special characters validate > it against a regex then if it passed the regex check produce the mac > address with the colons included. > > And, if I understand it properly, Pat's statement is saying that I > really shouldn't be protecting that method...which would fix my problem. > > So my question is then, how do you know when to use protected and > private or do I just do what Rick suggested and use send? > > I just realized this isn't really an rspec question...so I'll just move along. > > Mike B. > > ---------------------------------------------------------------- > This message was sent using IMP, the Internet Messaging Program. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > From jarkko at jlaine.net Thu Jan 10 15:25:31 2008 From: jarkko at jlaine.net (Jarkko Laine) Date: Thu, 10 Jan 2008 22:25:31 +0200 Subject: [rspec-users] specs on private methods In-Reply-To: <47867E3D.1030003@infopark.de> References: <20080110105049.z4gu8q49gko8wo4o@lcgalaska.com> <47867E3D.1030003@infopark.de> Message-ID: <86A57DC8-F453-4C3A-A9B3-5336A05BC5DF@jlaine.net> 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 (protected) method you call (normalize_mac). > > Let's assume this method was implemented wrong and just returns nil. > Let's further assume that @signup.mac_address calls a reader method > returning nil, too. Such an implementation, though wrong, would > satisfy > your spec! > > A second problem is, that the parameter you are passing to the > normalize-method will already have been transformed before your method > gets its hands on it. You are not passing the init value but the value > that is returned be a read operation on the mac_address field. > > What you really should specify is your concrete mac address format: > > it "should return a valid mac address" do > @signup.mac_address = "00-11-22-33-44-55" > @signup.mac_address.should == "00:11:22:33:44:55" > end > > Now you are not only implementation independent but your spec is also > saying more. 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 parameter; the method can simply call the mac_address method directly. If you want to make it more general-purpose, it doesn't sound like it should be an instance method anymore. //jarkko -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http://odesign.fi From francois.wurmus at infopark.de Thu Jan 10 15:34:52 2008 From: francois.wurmus at infopark.de (Francois Wurmus) Date: Thu, 10 Jan 2008 21:34:52 +0100 Subject: [rspec-users] specs on private methods In-Reply-To: <20080110105049.z4gu8q49gko8wo4o@lcgalaska.com> References: <20080110105049.z4gu8q49gko8wo4o@lcgalaska.com> Message-ID: <4786816C.8070207@infopark.de> 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 required to describe the behavior of the object to be specified. barsalou schrieb: > 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 > @signup = Signup.new > end > > it "she be a valid mac address" do > @signup.mac_address = "00-11-22-33-44-55-66" > normalized = @signup.normalize_mac(@signup.mac_address) > @signup.mac_address.should == normalized > end > end > > > I have a model that has mac_address attribute. In the before > validation, I wanted to make the mac address have colons(:) instead of > whatever the user typed in which could have spaces between, dashes, > nothing at all. > > My thought was to just remove all of those special characters validate > it against a regex then if it passed the regex check produce the mac > address with the colons included. > > And, if I understand it properly, Pat's statement is saying that I > really shouldn't be protecting that method...which would fix my problem. > > So my question is then, how do you know when to use protected and > private or do I just do what Rick suggested and use send? > > I just realized this isn't really an rspec question...so I'll just move along. > > Mike B. > > ---------------------------------------------------------------- > This message was sent using IMP, the Internet Messaging Program. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > From pergesu at gmail.com Thu Jan 10 15:36:16 2008 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 10 Jan 2008 12:36:16 -0800 Subject: [rspec-users] specs on private methods In-Reply-To: <86A57DC8-F453-4C3A-A9B3-5336A05BC5DF@jlaine.net> References: <20080110105049.z4gu8q49gko8wo4o@lcgalaska.com> <47867E3D.1030003@infopark.de> <86A57DC8-F453-4C3A-A9B3-5336A05BC5DF@jlaine.net> Message-ID: <810a540e0801101236u79d8379arafdc8041802c1c99@mail.gmail.com> On Jan 10, 2008 12:25 PM, Jarkko Laine 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 parameter; the method can simply > call the mac_address method directly. If you want to make it more > general-purpose, it doesn't sound like it should be an instance method > anymore. Right, you could pull this into a MacAddress class, and use that: describe MacAddress, " for 00-11-22-33-44-55" do it "should normalize to 00:11:22:33:44:55" do MacAddress.new("00-11-22-33-44-55").to_s.should == "00:11:22:33:44:55" end end Then you can just do @signup.mac_address = MacAddress.new "00-11-22-33-44-55" and you don't really need to test that, of course, since it's just a setter. Pat From pergesu at gmail.com Thu Jan 10 15:38:33 2008 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 10 Jan 2008 12:38:33 -0800 Subject: [rspec-users] specs on private methods In-Reply-To: <4786816C.8070207@infopark.de> References: <20080110105049.z4gu8q49gko8wo4o@lcgalaska.com> <4786816C.8070207@infopark.de> Message-ID: <810a540e0801101238q2367443ej4a825c911cee3a15@mail.gmail.com> On Jan 10, 2008 12:34 PM, Francois Wurmus 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 a MacAddress class here would be great for solving these sorts of problems. Mac address validation is something that the @signup object should not be concerned with. Pat From francois.wurmus at infopark.de Thu Jan 10 15:41:37 2008 From: francois.wurmus at infopark.de (Francois Wurmus) Date: Thu, 10 Jan 2008 21:41:37 +0100 Subject: [rspec-users] specs on private methods In-Reply-To: <810a540e0801101238q2367443ej4a825c911cee3a15@mail.gmail.com> References: <20080110105049.z4gu8q49gko8wo4o@lcgalaska.com> <4786816C.8070207@infopark.de> <810a540e0801101238q2367443ej4a825c911cee3a15@mail.gmail.com> Message-ID: <47868301.10707@infopark.de> 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 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 a MacAddress class here would be great for solving these > sorts of problems. Mac address validation is something that the > @signup object should not be concerned with. > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > From nathan.sutton at gmail.com Thu Jan 10 17:15:26 2008 From: nathan.sutton at gmail.com (Nathan Sutton) Date: Thu, 10 Jan 2008 16:15:26 -0600 Subject: [rspec-users] Shoulda Message-ID: 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 programmer go to town implementing these for rspec_on_rails? Nathan Sutton fowlduck at gmail.com rspec 1.1 rspec_on_rails 1.1 rails 2.0.2 From joshknowles at gmail.com Thu Jan 10 18:40:41 2008 From: joshknowles at gmail.com (Josh Knowles) Date: Thu, 10 Jan 2008 18:40:41 -0500 Subject: [rspec-users] Shoulda In-Reply-To: References: Message-ID: On 1/10/08, Nathan Sutton 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 against the rspec goals at > all? Or could an ambitious programmer go to town implementing these > for rspec_on_rails? The current philosophy is to keep these kinds of things as plugins. A few of us have started to extract common matchers into a plugin which can be found at http://code.google.com/p/rspec-on-rails-matchers/. Feel free to submit a patch if we're missing something that you'd like. -- Josh Knowles phone: 509-979-1593 email: joshknowles at gmail.com web: http://joshknowles.com From nathan.sutton at gmail.com Thu Jan 10 18:43:42 2008 From: nathan.sutton at gmail.com (Nathan Sutton) Date: Thu, 10 Jan 2008 17:43:42 -0600 Subject: [rspec-users] Shoulda In-Reply-To: References: Message-ID: <174D0167-2A72-482D-9787-FC540BB4070E@gmail.com> 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 fowlduck at gmail.com rspec 1.1 rspec_on_rails 1.1 rails 2.0.2 On Jan 10, 2008, at 5:40 PM, Josh Knowles wrote: > On 1/10/08, Nathan Sutton 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 against the rspec goals at >> all? Or could an ambitious programmer go to town implementing these >> for rspec_on_rails? > > The current philosophy is to keep these kinds of things as plugins. A > few of us have started to extract common matchers into a plugin which > can be found at http://code.google.com/p/rspec-on-rails-matchers/. > Feel free to submit a patch if we're missing something that you'd > like. > > > -- > Josh Knowles > phone: 509-979-1593 > email: joshknowles at gmail.com > web: http://joshknowles.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From joshknowles at gmail.com Thu Jan 10 18:47:46 2008 From: joshknowles at gmail.com (Josh Knowles) Date: Thu, 10 Jan 2008 18:47:46 -0500 Subject: [rspec-users] Shoulda In-Reply-To: <174D0167-2A72-482D-9787-FC540BB4070E@gmail.com> References: <174D0167-2A72-482D-9787-FC540BB4070E@gmail.com> Message-ID: On 1/10/08, Nathan Sutton 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 you work something up I'd happily add it. Unfortunately I don't have the need/time/desire to do it myself right now though. -- Josh Knowles phone: 509-979-1593 email: joshknowles at gmail.com web: http://joshknowles.com From nathan.sutton at gmail.com Thu Jan 10 18:49:00 2008 From: nathan.sutton at gmail.com (Nathan Sutton) Date: Thu, 10 Jan 2008 17:49:00 -0600 Subject: [rspec-users] Shoulda In-Reply-To: References: <174D0167-2A72-482D-9787-FC540BB4070E@gmail.com> Message-ID: <95B79D43-4ADC-4BAF-B4BD-4FFCA639C701@gmail.com> 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 fowlduck at gmail.com 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 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 you work something up I'd happily add it. Unfortunately I > don't have the need/time/desire to do it myself right now though. > > -- > Josh Knowles > phone: 509-979-1593 > email: joshknowles at gmail.com > web: http://joshknowles.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From nathan.sutton at gmail.com Thu Jan 10 18:50:34 2008 From: nathan.sutton at gmail.com (Nathan Sutton) Date: Thu, 10 Jan 2008 17:50:34 -0600 Subject: [rspec-users] Shoulda In-Reply-To: References: Message-ID: <6FEBA8A3-1DCA-4365-BD53-597DEA2D8506@gmail.com> 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 fowlduck at gmail.com rspec 1.1 rspec_on_rails 1.1 rails 2.0.2 On Jan 10, 2008, at 5:40 PM, Josh Knowles wrote: > On 1/10/08, Nathan Sutton 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 against the rspec goals at >> all? Or could an ambitious programmer go to town implementing these >> for rspec_on_rails? > > The current philosophy is to keep these kinds of things as plugins. A > few of us have started to extract common matchers into a plugin which > can be found at http://code.google.com/p/rspec-on-rails-matchers/. > Feel free to submit a patch if we're missing something that you'd > like. > > > -- > Josh Knowles > phone: 509-979-1593 > email: joshknowles at gmail.com > web: http://joshknowles.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Thu Jan 10 18:59:21 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 10 Jan 2008 17:59:21 -0600 Subject: [rspec-users] Shoulda In-Reply-To: <6FEBA8A3-1DCA-4365-BD53-597DEA2D8506@gmail.com> References: <6FEBA8A3-1DCA-4365-BD53-597DEA2D8506@gmail.com> Message-ID: <57c63afe0801101559y3abdd46fg3220d30494b83cf9@mail.gmail.com> On Jan 10, 2008 5:50 PM, Nathan Sutton 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 quite sane. I'll give you an example: have_tag. That was initially implemented completely within RSpec. Rails was a moving target so it kept breaking. So we changed it to rely on assert_select, which ships w/ rails. It's been very stable since, but assert_select has not been updated with the new features - especially in terms of rjs, so it is no longer complete. What I'd really like to see now is that have_tag gets implemented w/ hpricot, but doing so would risk breaking a lot of existing specs. With a plugin approach, there is no problem. The community can offer different solutions to different problem sets. 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 that approach, but RSpec should not be sporting conveniences, even very pragmatic ones, that fundamentally go against the grain of BDD. FWIW, David > > Nathan Sutton > fowlduck at gmail.com > rspec 1.1 > rspec_on_rails 1.1 > rails 2.0.2 > > On Jan 10, 2008, at 5:40 PM, Josh Knowles wrote: > > > > On 1/10/08, Nathan Sutton 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 against the rspec goals at > >> all? Or could an ambitious programmer go to town implementing these > >> for rspec_on_rails? > > > > The current philosophy is to keep these kinds of things as plugins. A > > few of us have started to extract common matchers into a plugin which > > can be found at http://code.google.com/p/rspec-on-rails-matchers/. > > Feel free to submit a patch if we're missing something that you'd > > like. > > > > > > -- > > Josh Knowles > > phone: 509-979-1593 > > email: joshknowles at gmail.com > > web: http://joshknowles.com > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From nathan.sutton at gmail.com Thu Jan 10 19:02:01 2008 From: nathan.sutton at gmail.com (Nathan Sutton) Date: Thu, 10 Jan 2008 18:02:01 -0600 Subject: [rspec-users] Shoulda In-Reply-To: <57c63afe0801101559y3abdd46fg3220d30494b83cf9@mail.gmail.com> References: <6FEBA8A3-1DCA-4365-BD53-597DEA2D8506@gmail.com> <57c63afe0801101559y3abdd46fg3220d30494b83cf9@mail.gmail.com> Message-ID: There David goes, making sense again. Nathan Sutton fowlduck at gmail.com 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 > 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 quite sane. I'll give you an example: have_tag. That was > initially implemented completely within RSpec. Rails was a moving > target so it kept breaking. So we changed it to rely on assert_select, > which ships w/ rails. It's been very stable since, but assert_select > has not been updated with the new features - especially in terms of > rjs, so it is no longer complete. > > What I'd really like to see now is that have_tag gets implemented w/ > hpricot, but doing so would risk breaking a lot of existing specs. > > With a plugin approach, there is no problem. The community can offer > different solutions to different problem sets. > > 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 that approach, but RSpec should not be > sporting conveniences, even very pragmatic ones, that fundamentally go > against the grain of BDD. > > FWIW, > David > >> >> Nathan Sutton >> fowlduck at gmail.com >> rspec 1.1 >> rspec_on_rails 1.1 >> rails 2.0.2 >> >> On Jan 10, 2008, at 5:40 PM, Josh Knowles wrote: >> >> >>> On 1/10/08, Nathan Sutton 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 against the rspec goals at >>>> all? Or could an ambitious programmer go to town implementing >>>> these >>>> for rspec_on_rails? >>> >>> The current philosophy is to keep these kinds of things as >>> plugins. A >>> few of us have started to extract common matchers into a plugin >>> which >>> can be found at http://code.google.com/p/rspec-on-rails-matchers/. >>> Feel free to submit a patch if we're missing something that you'd >>> like. >>> >>> >>> -- >>> Josh Knowles >>> phone: 509-979-1593 >>> email: joshknowles at gmail.com >>> web: http://joshknowles.com >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Thu Jan 10 19:04:39 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 10 Jan 2008 18:04:39 -0600 Subject: [rspec-users] Shoulda In-Reply-To: References: <6FEBA8A3-1DCA-4365-BD53-597DEA2D8506@gmail.com> <57c63afe0801101559y3abdd46fg3220d30494b83cf9@mail.gmail.com> Message-ID: <57c63afe0801101604q56da98fcw1ffc065ed8e545a4@mail.gmail.com> On Jan 10, 2008 6:02 PM, Nathan Sutton wrote: > Nathan Sutton > fowlduck at gmail.com > 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. From j at jonathanleighton.com Thu Jan 10 19:04:53 2008 From: j at jonathanleighton.com (Jonathan Leighton) Date: Fri, 11 Jan 2008 00:04:53 +0000 Subject: [rspec-users] Shoulda In-Reply-To: <57c63afe0801101559y3abdd46fg3220d30494b83cf9@mail.gmail.com> References: <6FEBA8A3-1DCA-4365-BD53-597DEA2D8506@gmail.com> <57c63afe0801101559y3abdd46fg3220d30494b83cf9@mail.gmail.com> Message-ID: <1200009893.7582.4.camel@tybalt> 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 that approach, but RSpec should not be > sporting conveniences, even very pragmatic ones, that fundamentally go > against the grain of BDD. Out of interest, how would/do you test associations David? What if should have_many(:posts) tested the behaviour of the association rather than whether it's defined? -- Jonathan Leighton http://jonathanleighton.com/ From james.deville at gmail.com Thu Jan 10 19:06:56 2008 From: james.deville at gmail.com (James Deville) Date: Thu, 10 Jan 2008 16:06:56 -0800 Subject: [rspec-users] Shoulda In-Reply-To: <1200009893.7582.4.camel@tybalt> References: <6FEBA8A3-1DCA-4365-BD53-597DEA2D8506@gmail.com> <57c63afe0801101559y3abdd46fg3220d30494b83cf9@mail.gmail.com> <1200009893.7582.4.camel@tybalt> Message-ID: <3987CD4F-9395-4A0B-8777-90BD8D3CB34F@gmail.com> 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: > 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 that approach, but RSpec should not be >> sporting conveniences, even very pragmatic ones, that fundamentally >> go >> against the grain of BDD. > > Out of interest, how would/do you test associations David? What if > should have_many(:posts) tested the behaviour of the association > rather > than whether it's defined? > > -- > Jonathan Leighton > http://jonathanleighton.com/ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From nathan.sutton at gmail.com Thu Jan 10 19:07:39 2008 From: nathan.sutton at gmail.com (Nathan Sutton) Date: Thu, 10 Jan 2008 18:07:39 -0600 Subject: [rspec-users] Shoulda In-Reply-To: <57c63afe0801101604q56da98fcw1ffc065ed8e545a4@mail.gmail.com> References: <6FEBA8A3-1DCA-4365-BD53-597DEA2D8506@gmail.com> <57c63afe0801101559y3abdd46fg3220d30494b83cf9@mail.gmail.com> <57c63afe0801101604q56da98fcw1ffc065ed8e545a4@mail.gmail.com> Message-ID: <7480AF2B-6319-4E34-BAA5-8FDB7C084B1D@gmail.com> 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/energy, so this is a simple solution. :) Nathan Sutton fowlduck at gmail.com rspec 1.1 rspec_on_rails 1.1 rails 2.0.2 On Jan 10, 2008, at 6:04 PM, David Chelimsky wrote: > On Jan 10, 2008 6:02 PM, Nathan Sutton > wrote: >> Nathan Sutton >> fowlduck at gmail.com >> 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 > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From smingins at elctech.com Thu Jan 10 19:05:11 2008 From: smingins at elctech.com (Shane Mingins) Date: Fri, 11 Jan 2008 13:05:11 +1300 Subject: [rspec-users] Peepcode RSpec User Stories Message-ID: <23264334-9278-465C-A0E0-E96900ED24AB@elctech.com> 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: smingins at elctech.com AIM: ShaneMingins Skype: shane.mingins (866) 863-7365 Tel - Santa Barbara Office (866) 893-1902 Fax - Santa Barbara Office +44 020 7504 1346 Tel - London Office +44 020 7504 1347 Fax - London Office http://www.elctech.com -------------------------------------------------------------------- Privacy and Confidentiality Notice: The information contained in this electronic mail message is intended for the named recipient(s) only. It may contain privileged and confidential information. If you are not an intended recipient, you must not copy, forward, distribute or take any action in reliance on it. If you have received this electronic mail message in error, please notify the sender immediately. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080111/59c080f1/attachment.html From dchelimsky at gmail.com Thu Jan 10 19:09:35 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 10 Jan 2008 18:09:35 -0600 Subject: [rspec-users] Shoulda In-Reply-To: <1200009893.7582.4.camel@tybalt> References: <6FEBA8A3-1DCA-4365-BD53-597DEA2D8506@gmail.com> <57c63afe0801101559y3abdd46fg3220d30494b83cf9@mail.gmail.com> <1200009893.7582.4.camel@tybalt> Message-ID: <57c63afe0801101609w6c6748a9t728c0e4e0fa609b6@mail.gmail.com> On Jan 10, 2008 6:04 PM, Jonathan Leighton 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 view this differently, and I would not want to > > get in the way of anyone using that approach, but RSpec should not be > > sporting conveniences, even very pragmatic ones, that fundamentally go > > against the grain of BDD. > > Out of interest, how would/do you test associations David? What if > should have_many(:posts) tested the behaviour of the association rather > than whether it's defined? 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 example: describe Blogger, "with no posts" do it "should be completely lame and banned for eternity" do @blogger.should be_completely_lame_and_banned_for_eternity end end describe Blogger, "with 1000 posts" do it "should be revered by the community" do (1..1000).each { @blogger.post(:title => "today's thoughts") } @blogger.should be_revered_by_the_community end end Now we're talking about behaviour. has_many is implied. No need to spec it directly - serves no purpose by itself. That all make sense? From dchelimsky at gmail.com Thu Jan 10 19:10:41 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 10 Jan 2008 18:10:41 -0600 Subject: [rspec-users] Shoulda In-Reply-To: <7480AF2B-6319-4E34-BAA5-8FDB7C084B1D@gmail.com> References: <6FEBA8A3-1DCA-4365-BD53-597DEA2D8506@gmail.com> <57c63afe0801101559y3abdd46fg3220d30494b83cf9@mail.gmail.com> <57c63afe0801101604q56da98fcw1ffc065ed8e545a4@mail.gmail.com> <7480AF2B-6319-4E34-BAA5-8FDB7C084B1D@gmail.com> Message-ID: <57c63afe0801101610y21f325e5p33226e3d5d288ed9@mail.gmail.com> On Jan 10, 2008 6:07 PM, Nathan Sutton 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 everything they're using? It can be a pain and it > usually wastes time/energy, so this is a simple solution. :) I wasn't criticizing. It cracks me up in the sort of "that's so obvious, I should do it myself' sort of way. > > Nathan Sutton > fowlduck at gmail.com > rspec 1.1 > rspec_on_rails 1.1 > rails 2.0.2 > > > On Jan 10, 2008, at 6:04 PM, David Chelimsky wrote: > > > On Jan 10, 2008 6:02 PM, Nathan Sutton > > wrote: > >> Nathan Sutton > >> fowlduck at gmail.com > >> 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 > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From nathan.sutton at gmail.com Thu Jan 10 19:11:42 2008 From: nathan.sutton at gmail.com (Nathan Sutton) Date: Thu, 10 Jan 2008 18:11:42 -0600 Subject: [rspec-users] Shoulda In-Reply-To: <57c63afe0801101610y21f325e5p33226e3d5d288ed9@mail.gmail.com> References: <6FEBA8A3-1DCA-4365-BD53-597DEA2D8506@gmail.com> <57c63afe0801101559y3abdd46fg3220d30494b83cf9@mail.gmail.com> <57c63afe0801101604q56da98fcw1ffc065ed8e545a4@mail.gmail.com> <7480AF2B-6319-4E34-BAA5-8FDB7C084B1D@gmail.com> <57c63afe0801101610y21f325e5p33226e3d5d288ed9@mail.gmail.com> Message-ID: <8F5EB74D-0261-482D-8AE5-5B6CAB1E59C0@gmail.com> Well then, hop to! ;) Nathan Sutton fowlduck at gmail.com 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 > 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 everything they're using? It can be a pain and it >> usually wastes time/energy, so this is a simple solution. :) > > I wasn't criticizing. It cracks me up in the sort of "that's so > obvious, I should do it myself' sort of way. > >> >> Nathan Sutton >> fowlduck at gmail.com >> rspec 1.1 >> rspec_on_rails 1.1 >> rails 2.0.2 >> >> >> On Jan 10, 2008, at 6:04 PM, David Chelimsky wrote: >> >>> On Jan 10, 2008 6:02 PM, Nathan Sutton >>> wrote: >>>> Nathan Sutton >>>> fowlduck at gmail.com >>>> 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 >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From james.deville at gmail.com Thu Jan 10 19:16:50 2008 From: james.deville at gmail.com (James Deville) Date: Thu, 10 Jan 2008 16:16:50 -0800 Subject: [rspec-users] Shoulda In-Reply-To: <8F5EB74D-0261-482D-8AE5-5B6CAB1E59C0@gmail.com> References: <6FEBA8A3-1DCA-4365-BD53-597DEA2D8506@gmail.com> <57c63afe0801101559y3abdd46fg3220d30494b83cf9@mail.gmail.com> <57c63afe0801101604q56da98fcw1ffc065ed8e545a4@mail.gmail.com> <7480AF2B-6319-4E34-BAA5-8FDB7C084B1D@gmail.com> <57c63afe0801101610y21f325e5p33226e3d5d288ed9@mail.gmail.com> <8F5EB74D-0261-482D-8AE5-5B6CAB1E59C0@gmail.com> Message-ID: On Jan 10, 2008, at 4:11 PM, Nathan Sutton wrote: > Well then, hop to! ;) > Nathan Sutton > fowlduck at gmail.com > 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 >> 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 everything they're using? It can be a pain and it >>> usually wastes time/energy, so this is a simple solution. :) >> >> I wasn't criticizing. It cracks me up in the sort of "that's so >> obvious, I should do it myself' sort of way. >> >>> >>> Nathan Sutton >>> fowlduck at gmail.com >>> rspec 1.1 >>> rspec_on_rails 1.1 >>> rails 2.0.2 >>> >>> >>> On Jan 10, 2008, at 6:04 PM, David Chelimsky wrote: >>> >>>> On Jan 10, 2008 6:02 PM, Nathan Sutton >>>> wrote: >>>>> Nathan Sutton >>>>> fowlduck at gmail.com >>>>> 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 >>>> rspec-users at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Hop! James Deville http://devillecompanies.org james.deville at gmail.com rspec r3172 rspec_on_rails r3172 rails r8331 From j at jonathanleighton.com Thu Jan 10 19:17:57 2008 From: j at jonathanleighton.com (Jonathan Leighton) Date: Fri, 11 Jan 2008 00:17:57 +0000 Subject: [rspec-users] Shoulda In-Reply-To: <57c63afe0801101609w6c6748a9t728c0e4e0fa609b6@mail.gmail.com> References: <6FEBA8A3-1DCA-4365-BD53-597DEA2D8506@gmail.com> <57c63afe0801101559y3abdd46fg3220d30494b83cf9@mail.gmail.com> <1200009893.7582.4.camel@tybalt> <57c63afe0801101609w6c6748a9t728c0e4e0fa609b6@mail.gmail.com> Message-ID: <1200010677.7582.16.camel@tybalt> 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 example: > > describe Blogger, "with no posts" do > it "should be completely lame and banned for eternity" do > @blogger.should be_completely_lame_and_banned_for_eternity > end > end > > describe Blogger, "with 1000 posts" do > it "should be revered by the community" do > (1..1000).each { @blogger.post(:title => "today's thoughts") } > @blogger.should be_revered_by_the_community > end > end > > Now we're talking about behaviour. has_many is implied. No need to > spec it directly - serves no purpose by itself. > > That all make sense? 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 actually exists), but you've got nothing interesting to poke it with... On the other hand maybe it's stupid testing that as you are really testing the database, which is a different layer entirely. But in practise I know it's quite usual to make a database change and inadvertently break an association you had forgotten about... Jon -- Jonathan Leighton http://jonathanleighton.com/ From j at jonathanleighton.com Thu Jan 10 19:29:38 2008 From: j at jonathanleighton.com (Jonathan Leighton) Date: Fri, 11 Jan 2008 00:29:38 +0000 Subject: [rspec-users] Shoulda In-Reply-To: References: <174D0167-2A72-482D-9787-FC540BB4070E@gmail.com> Message-ID: <1200011378.7582.29.camel@tybalt> On Thu, 2008-01-10 at 18:47 -0500, Josh Knowles wrote: > On 1/10/08, Nathan Sutton 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 you work something up I'd happily add it. Unfortunately I > don't have the need/time/desire to do it myself right now though. My reservation with the idea of "should be restful" is that you have to assume an awful lot about how the controller is implemented. That's fine if you use scaffolding excessively but if you actually write your own code (!!) things quickly start to deviate from the trodden path. Recently I have been writing my controller specs a bit like this (I have some support code to enable it): describe PostsController do controller_name :posts stub_resource describe "when a post is viewed and the current user is an admin" do log_in :as => :admin get :show, :id => 42 it_should_find it_should_load_awesome_admin_stuff end describe "when a post is edited by a normal user" do log_in :as => :prole get :edit, :id => 23 it_should_find it_should_warn it_should_redirect_to "the post's page", :at => "post_path(@post)" end end Some of the above is me using my creative license but you get the idea. Just thought it might spark some ideas/opinions... it's certainly not a perfect implementation/API but I've found the general idea quite useful. I personally think this is the right level at which to make the abstraction - you are still specifying the behaviour explicitly, just writing less code when doing it. Jon -- Jonathan Leighton http://jonathanleighton.com/ From pergesu at gmail.com Thu Jan 10 19:45:15 2008 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 10 Jan 2008 16:45:15 -0800 Subject: [rspec-users] Shoulda In-Reply-To: <1200010677.7582.16.camel@tybalt> References: <6FEBA8A3-1DCA-4365-BD53-597DEA2D8506@gmail.com> <57c63afe0801101559y3abdd46fg3220d30494b83cf9@mail.gmail.com> <1200009893.7582.4.camel@tybalt> <57c63afe0801101609w6c6748a9t728c0e4e0fa609b6@mail.gmail.com> <1200010677.7582.16.camel@tybalt> Message-ID: <810a540e0801101645k18868988j4772a09f6f46dfaa@mail.gmail.com> On Jan 10, 2008 4:17 PM, Jonathan Leighton 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 > actually exists), but you've got nothing interesting to poke it with... I don't know. I'm starting to think that this falls under the category of so simple it's maybe not worth testing. Using Rails associations in the simplest way, i.e. no special conditions, is so declarative that I might consider it to be specification enough. I'm not sure though. I'm not totally cool with the idea of trashing the specs because the code is so expressive that it doesn't need them. There's always *something* interesting. If there weren't, it wouldn't be in the code to begin with, right? Your example can be something as simple as describe Blogger, " who just set up his site" do it "should have no posts" do Blogger.new.should have(0).posts end end That at least tells you that there's a method named #posts, which responds to length, and has a length of 0 when the blogger is first instantiated. That's more behavior-y than specifying the exact structure of it. I admit it's not interesting in the "call the sheriff, pa, there's somethin in the barn" sense, but it is interesting in that it's a facet of behavior that's worth knowing. Pat From nathan.sutton at gmail.com Thu Jan 10 19:48:09 2008 From: nathan.sutton at gmail.com (Nathan Sutton) Date: Thu, 10 Jan 2008 18:48:09 -0600 Subject: [rspec-users] Shoulda In-Reply-To: <1200011378.7582.29.camel@tybalt> References: <174D0167-2A72-482D-9787-FC540BB4070E@gmail.com> <1200011378.7582.29.camel@tybalt> Message-ID: 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 fowlduck at gmail.com rspec 1.1 rspec_on_rails 1.1 rails 2.0.2 On Jan 10, 2008, at 6:29 PM, Jonathan Leighton wrote: > On Thu, 2008-01-10 at 18:47 -0500, Josh Knowles wrote: >> On 1/10/08, Nathan Sutton 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 you work something up I'd happily add it. Unfortunately I >> don't have the need/time/desire to do it myself right now though. > > My reservation with the idea of "should be restful" is that you have > to > assume an awful lot about how the controller is implemented. That's > fine > if you use scaffolding excessively but if you actually write your own > code (!!) things quickly start to deviate from the trodden path. > > Recently I have been writing my controller specs a bit like this (I > have > some support code to enable it): > > describe PostsController do > controller_name :posts > stub_resource > > describe "when a post is viewed and the current user is an admin" do > log_in :as => :admin > get :show, :id => 42 > > it_should_find > it_should_load_awesome_admin_stuff > end > > describe "when a post is edited by a normal user" do > log_in :as => :prole > get :edit, :id => 23 > > it_should_find > it_should_warn > it_should_redirect_to "the post's page", :at => "post_path(@post)" > end > end > > Some of the above is me using my creative license but you get the > idea. > Just thought it might spark some ideas/opinions... it's certainly > not a > perfect implementation/API but I've found the general idea quite > useful. > I personally think this is the right level at which to make the > abstraction - you are still specifying the behaviour explicitly, just > writing less code when doing it. > > Jon > > -- > Jonathan Leighton > http://jonathanleighton.com/ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Thu Jan 10 19:59:42 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 10 Jan 2008 18:59:42 -0600 Subject: [rspec-users] Shoulda In-Reply-To: References: <174D0167-2A72-482D-9787-FC540BB4070E@gmail.com> <1200011378.7582.29.camel@tybalt> Message-ID: <57c63afe0801101659x2edc5258w314e157da6b18af@mail.gmail.com> On Jan 10, 2008 6:48 PM, Nathan Sutton 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 http://git.caboo.se/?p=altered_beast.git;a=tree;f=vendor/plugins/rspec_on_rails_on_crack/lib;h=62b5fe1ccad8186a989f5d72dd218f3678fae518;hb=HEAD > > and here: > http://dev.thoughtbot.com/shoulda/classes/ThoughtBot/Shoulda/Controller/ClassMethods.html > > Nathan Sutton > fowlduck at gmail.com > rspec 1.1 > rspec_on_rails 1.1 > rails 2.0.2 > > > On Jan 10, 2008, at 6:29 PM, Jonathan Leighton wrote: > > > On Thu, 2008-01-10 at 18:47 -0500, Josh Knowles wrote: > >> On 1/10/08, Nathan Sutton 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 you work something up I'd happily add it. Unfortunately I > >> don't have the need/time/desire to do it myself right now though. > > > > My reservation with the idea of "should be restful" is that you have > > to > > assume an awful lot about how the controller is implemented. That's > > fine > > if you use scaffolding excessively but if you actually write your own > > code (!!) things quickly start to deviate from the trodden path. > > > > Recently I have been writing my controller specs a bit like this (I > > have > > some support code to enable it): > > > > describe PostsController do > > controller_name :posts > > stub_resource > > > > describe "when a post is viewed and the current user is an admin" do > > log_in :as => :admin > > get :show, :id => 42 > > > > it_should_find > > it_should_load_awesome_admin_stuff > > end > > > > describe "when a post is edited by a normal user" do > > log_in :as => :prole > > get :edit, :id => 23 > > > > it_should_find > > it_should_warn > > it_should_redirect_to "the post's page", :at => "post_path(@post)" > > end > > end > > > > Some of the above is me using my creative license but you get the > > idea. > > Just thought it might spark some ideas/opinions... it's certainly > > not a > > perfect implementation/API but I've found the general idea quite > > useful. > > I personally think this is the right level at which to make the > > abstraction - you are still specifying the behaviour explicitly, just > > writing less code when doing it. > > > > Jon > > > > -- > > Jonathan Leighton > > http://jonathanleighton.com/ > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From nathan.sutton at gmail.com Thu Jan 10 20:19:51 2008 From: nathan.sutton at gmail.com (Nathan Sutton) Date: Thu, 10 Jan 2008 19:19:51 -0600 Subject: [rspec-users] Shoulda In-Reply-To: <57c63afe0801101659x2edc5258w314e157da6b18af@mail.gmail.com> References: <174D0167-2A72-482D-9787-FC540BB4070E@gmail.com> <1200011378.7582.29.camel@tybalt> <57c63afe0801101659x2edc5258w314e157da6b18af@mail.gmail.com> Message-ID: That too :) Nathan Sutton fowlduck at gmail.com 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 > 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 > http://git.caboo.se/?p=altered_beast.git;a=tree;f=vendor/plugins/rspec_on_rails_on_crack/lib;h=62b5fe1ccad8186a989f5d72dd218f3678fae518;hb=HEAD > >> >> and here: >> http://dev.thoughtbot.com/shoulda/classes/ThoughtBot/Shoulda/Controller/ClassMethods.html >> >> Nathan Sutton >> fowlduck at gmail.com >> rspec 1.1 >> rspec_on_rails 1.1 >> rails 2.0.2 >> >> >> On Jan 10, 2008, at 6:29 PM, Jonathan Leighton wrote: >> >>> On Thu, 2008-01-10 at 18:47 -0500, Josh Knowles wrote: >>>> On 1/10/08, Nathan Sutton 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 you work something up I'd happily add it. Unfortunately I >>>> don't have the need/time/desire to do it myself right now though. >>> >>> My reservation with the idea of "should be restful" is that you have >>> to >>> assume an awful lot about how the controller is implemented. That's >>> fine >>> if you use scaffolding excessively but if you actually write your >>> own >>> code (!!) things quickly start to deviate from the trodden path. >>> >>> Recently I have been writing my controller specs a bit like this (I >>> have >>> some support code to enable it): >>> >>> describe PostsController do >>> controller_name :posts >>> stub_resource >>> >>> describe "when a post is viewed and the current user is an admin" do >>> log_in :as => :admin >>> get :show, :id => 42 >>> >>> it_should_find >>> it_should_load_awesome_admin_stuff >>> end >>> >>> describe "when a post is edited by a normal user" do >>> log_in :as => :prole >>> get :edit, :id => 23 >>> >>> it_should_find >>> it_should_warn >>> it_should_redirect_to "the post's page", :at => "post_path(@post)" >>> end >>> end >>> >>> Some of the above is me using my creative license but you get the >>> idea. >>> Just thought it might spark some ideas/opinions... it's certainly >>> not a >>> perfect implementation/API but I've found the general idea quite >>> useful. >>> I personally think this is the right level at which to make the >>> abstraction - you are still specifying the behaviour explicitly, >>> just >>> writing less code when doing it. >>> >>> Jon >>> >>> -- >>> Jonathan Leighton >>> http://jonathanleighton.com/ >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From gilesb at gmail.com Thu Jan 10 20:24:58 2008 From: gilesb at gmail.com (Giles Bowkett) Date: Thu, 10 Jan 2008 17:24:58 -0800 Subject: [rspec-users] guide to good mocking? Message-ID: <2d81dedb0801101724h6face1tab1c61a3f642771e@mail.gmail.com> 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) statements and it's kind of out of control. I have an idea how the specs should look but I don't have it clearly articulated. I need a way to translate that vague sense for other people without guiding them through the code line by line. Earlier today I caught a spec that took 50 seconds to run, which was just nuts. -- Giles Bowkett Podcast: http://hollywoodgrit.blogspot.com Blog: http://gilesbowkett.blogspot.com Portfolio: http://www.gilesgoatboy.org Tumblelog: http://giles.tumblr.com From dchelimsky at gmail.com Thu Jan 10 20:27:24 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 10 Jan 2008 19:27:24 -0600 Subject: [rspec-users] guide to good mocking? In-Reply-To: <2d81dedb0801101724h6face1tab1c61a3f642771e@mail.gmail.com> References: <2d81dedb0801101724h6face1tab1c61a3f642771e@mail.gmail.com> Message-ID: <57c63afe0801101727t22935876pda75a0cefcc064df@mail.gmail.com> On Jan 10, 2008 7:24 PM, Giles Bowkett 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'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) statements > and it's kind of out of control. I have an idea how the specs should > look but I don't have it clearly articulated. I need a way to > translate that vague sense for other people without guiding them > through the code line by line. Earlier today I caught a spec that took > 50 seconds to run, which was just nuts. > > -- > Giles Bowkett > > Podcast: http://hollywoodgrit.blogspot.com > Blog: http://gilesbowkett.blogspot.com > Portfolio: http://www.gilesgoatboy.org > Tumblelog: http://giles.tumblr.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From james.deville at gmail.com Thu Jan 10 20:27:41 2008 From: james.deville at gmail.com (James Deville) Date: Thu, 10 Jan 2008 17:27:41 -0800 Subject: [rspec-users] Missing methods Message-ID: 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}(attributes = {}) default_attributes = valid_#{klass}_attributes #{klass.camelize}.create! default_attributes.merge(attributes) end EOF end def valid_message_attributes(options = {}) { #some message options } end #more valid_x_attributes methods end When I require this file in a spec file, Factory.create_person works fine. When I try to do it in a step file, Factory.create_person is defined, but it fails because valid_person_attributes is missing. If I'm in a debugger, and I do require 'model_factory' followed by Factory.create_person, same deal. Do we have a blank slate being loaded somewhere, and why is it wiping out require files? Thanks James Deville http://devillecompanies.org james.deville at gmail.com rspec r3172 rspec_on_rails r3172 rails r8331 From dchelimsky at gmail.com Thu Jan 10 22:29:22 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 10 Jan 2008 21:29:22 -0600 Subject: [rspec-users] changes in rspec's trunk and autotest Message-ID: <57c63afe0801101929q7be1d50ev5440cc78153d8a08@mail.gmail.com> 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 you can use to plug into autotest's hooks to extend/modify it's behaviour. Previously, subclasses got loaded after .autotest, causing changes to test_mappings and exceptions to be overridden. With the next release, the load order is corrected so anything in .autotest will be processed after Autotest::Rspec or Autotest::RailsRspec is loaded. I committed changes to RSpec's trunk r3220 that will break your current autotest configuration. If it does, you can apply this patch (http://pastie.caboo.se/138024) to your local copy of ZenTest (assuming you're up to 3.7.2) and all should be right with the world. Again - this is ONLY for people who are following RSpec's trunk and using autotest. Cheers, David From steven at stevenrbaker.com Thu Jan 10 20:30:03 2008 From: steven at stevenrbaker.com (Steven Baker) Date: Thu, 10 Jan 2008 20:30:03 -0500 Subject: [rspec-users] guide to good mocking? In-Reply-To: <2d81dedb0801101724h6face1tab1c61a3f642771e@mail.gmail.com> References: <2d81dedb0801101724h6face1tab1c61a3f642771e@mail.gmail.com> Message-ID: <825B11F8-B815-4AD0-929A-DDAC679E5573@pobox.com> > 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.com/articles/mocksArentStubs.html -Steven From duelin.markers at gmail.com Thu Jan 10 22:42:51 2008 From: duelin.markers at gmail.com (John D. Hume) Date: Thu, 10 Jan 2008 22:42:51 -0500 Subject: [rspec-users] Missing methods In-Reply-To: References: Message-ID: 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 certainly cause NoMethodErrors (though it would affect specs as well as other contexts). -hume. On Jan 10, 2008 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| > eval <<-EOF > def self.create_#{klass}(attributes = {}) > default_attributes = valid_#{klass}_attributes > #{klass.camelize}.create! default_attributes.merge(attributes) > end > EOF > end > > def valid_message_attributes(options = {}) > { > #some message options > } > end > > #more valid_x_attributes methods > end > > When I require this file in a spec file, Factory.create_person works > fine. When I try to do it in a step file, Factory.create_person is > defined, but it fails because valid_person_attributes is missing. If > I'm in a debugger, and I do require 'model_factory' followed by > Factory.create_person, same deal. > > Do we have a blank slate being loaded somewhere, and why is it wiping > out require files? > > Thanks > > James Deville > http://devillecompanies.org > james.deville at gmail.com > rspec r3172 > rspec_on_rails r3172 > rails r8331 > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From james.deville at gmail.com Thu Jan 10 23:00:20 2008 From: james.deville at gmail.com (James Deville) Date: Thu, 10 Jan 2008 20:00:20 -0800 Subject: [rspec-users] Missing methods In-Reply-To: References: Message-ID: <8BEF37E2-5FB8-4ED9-8E81-C83360C527F6@gmail.com> 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.org james.deville at gmail.com rspec r3172 rspec_on_rails r3172 rails r8331 On Jan 10, 2008, at 7:42 PM, John D. Hume wrote: > 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 > certainly cause NoMethodErrors (though it would affect specs as well > as other contexts). > > -hume. > > > On Jan 10, 2008 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| >> eval <<-EOF >> def self.create_#{klass}(attributes = {}) >> default_attributes = valid_#{klass}_attributes >> #{klass.camelize}.create! >> default_attributes.merge(attributes) >> end >> EOF >> end >> >> def valid_message_attributes(options = {}) >> { >> #some message options >> } >> end >> >> #more valid_x_attributes methods >> end >> >> When I require this file in a spec file, Factory.create_person works >> fine. When I try to do it in a step file, Factory.create_person is >> defined, but it fails because valid_person_attributes is missing. If >> I'm in a debugger, and I do require 'model_factory' followed by >> Factory.create_person, same deal. >> >> Do we have a blank slate being loaded somewhere, and why is it wiping >> out require files? >> >> Thanks >> >> James Deville >> http://devillecompanies.org >> james.deville at gmail.com >> rspec r3172 >> rspec_on_rails r3172 >> rails r8331 >> >> >> >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From mailing_lists at railsnewbie.com Fri Jan 11 01:24:33 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Fri, 11 Jan 2008 01:24:33 -0500 Subject: [rspec-users] Missing methods In-Reply-To: References: Message-ID: <9C3E1363-ADCE-4108-9A54-FE9787D76971@railsnewbie.com> 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| > eval <<-EOF > def self.create_#{klass}(attributes = {}) > default_attributes = valid_#{klass}_attributes > #{klass.camelize}.create! default_attributes.merge(attributes) > end > EOF > end > > def valid_message_attributes(options = {}) > { > #some message options > } > end > > #more valid_x_attributes methods > end > > When I require this file in a spec file, Factory.create_person works > fine. When I try to do it in a step file, Factory.create_person is > defined, but it fails because valid_person_attributes is missing. If > I'm in a debugger, and I do require 'model_factory' followed by > Factory.create_person, same deal. > > Do we have a blank slate being loaded somewhere, and why is it wiping > out require files? > Yep - this pretty much looks like version 0.1 of FixutreReplacement: http://pastie.caboo.se/138084 Scott From shot at hot.pl Fri Jan 11 04:49:14 2008 From: shot at hot.pl (Shot (Piotr Szotkowski)) Date: Fri, 11 Jan 2008 10:49:14 +0100 Subject: [rspec-users] specs on private methods In-Reply-To: <071A280E-9D43-497B-ABAE-01FD15716D75@tenner.org> References: <840215067e9a8ce8de426499acb0d2a5@ruby-forum.com> <071A280E-9D43-497B-ABAE-01FD15716D75@tenner.org> Message-ID: <20080111094914.GF10401@durance.shot.pl> Daniel Tenner: > Might be a personal thing, but my approach is that I try to test the > public behaviour of the object. Testing private methods is, imho, > getting dangerously close to specifying how the object does its > business, rather than what it does. I agree on principle, but I ran into the following case in my PhD: There?s a Decomposition class that decomposes an FSM to a given architecture. Its public methods should be new() and decompose!(). Now, decompose!() works by running a private method by_input_sets!() many times with different parameters. One run of by_input_sets!() takes a couple of seconds, so can be tested; one run of decompose!() takes much longer, so to test decompose!() I should stub by_input_sets!() so it returns canned data (right?). In this situation, I think I do need to test/spec the by_input_sets!() private method ? otherwise there would be no code that would check on the way it works. -- Shot -- A school in the UK is using RFID chips in school uniforms to track attendance. So now it's easy to cut class; just ask someone to carry your shirt around the building while you're elsewhere. -- Bruce Schneier -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 191 bytes Desc: not available Url : http://rubyforge.org/pipermail/rspec-users/attachments/20080111/66c1481b/attachment.bin From Andreas.Axelsson at combination.se Fri Jan 11 04:53:13 2008 From: Andreas.Axelsson at combination.se (Andreas Axelsson) Date: Fri, 11 Jan 2008 10:53:13 +0100 Subject: [rspec-users] Story teardowns? Message-ID: Does the plain text story framework support teardowns? There doesn't seem to be anywhere to put an "after" method. My stories test an application which parses and modifies a directory tree, which is currently generated in a Given-clause, and I want it to be deleted after each story. (I don't mind if the stories take a few seconds to run, the specs are still fast) Cheers , Andreas Axelsson Combination AB -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080111/6e061ae0/attachment-0001.html From aslak.hellesoy at gmail.com Fri Jan 11 05:10:46 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Fri, 11 Jan 2008 11:10:46 +0100 Subject: [rspec-users] Story teardowns? In-Reply-To: References: Message-ID: <8d961d900801110210j20dafd84kfd054839595afbfa@mail.gmail.com> On Jan 11, 2008 10:53 AM, Andreas Axelsson wrote: > > > > > Does the plain text story framework support teardowns? There doesn't seem to > be anywhere to put an "after" method. My stories test an application which > parses and modifies a directory tree, which is currently generated in a > Given-clause, and I want it to be deleted after each story. (I don't mind if > the stories take a few seconds to run, the specs are still fast) > There is no such feature (yet). For now I'd stick this in a Given that you use at the beginning of each scenario, for example: Given "the stash is in a clean state" do # yank any old residual gunk here end Aslak > > > Cheers , > > Andreas Axelsson > > Combination AB > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From Andreas.Axelsson at combination.se Fri Jan 11 05:20:15 2008 From: Andreas.Axelsson at combination.se (Andreas Axelsson) Date: Fri, 11 Jan 2008 11:20:15 +0100 Subject: [rspec-users] Story teardowns? In-Reply-To: <8d961d900801110210j20dafd84kfd054839595afbfa@mail.gmail.com> References: <8d961d900801110210j20dafd84kfd054839595afbfa@mail.gmail.com> Message-ID: > > Does the plain text story framework support teardowns? There doesn't > seem to > > be anywhere to put an "after" method. My stories test an application > which > > parses and modifies a directory tree, which is currently generated in > a > > Given-clause, and I want it to be deleted after each story. (I don't > mind if > > the stories take a few seconds to run, the specs are still fast) > > > > There is no such feature (yet). For now I'd stick this in a Given that > you use at the beginning of each scenario, for example: > > Given "the stash is in a clean state" do > # yank any old residual gunk here > end Thanks, that's how I solved it for now. /Andreas From dchelimsky at gmail.com Fri Jan 11 05:23:17 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 11 Jan 2008 04:23:17 -0600 Subject: [rspec-users] specs on private methods In-Reply-To: <20080111094914.GF10401@durance.shot.pl> References: <840215067e9a8ce8de426499acb0d2a5@ruby-forum.com> <071A280E-9D43-497B-ABAE-01FD15716D75@tenner.org> <20080111094914.GF10401@durance.shot.pl> Message-ID: <57c63afe0801110223o12ab6746w488584d3576454d8@mail.gmail.com> On Jan 11, 2008 3:49 AM, Shot (Piotr Szotkowski) wrote: > Daniel Tenner: > > > Might be a personal thing, but my approach is that I try to test the > > public behaviour of the object. Testing private methods is, imho, > > getting dangerously close to specifying how the object does its > > business, rather than what it does. > > I agree on principle, but I ran into the following case in my PhD: > > There's a Decomposition class that decomposes an FSM to a given > architecture. Its public methods should be new() and decompose!(). > Now, decompose!() works by running a private method by_input_sets!() > many times with different parameters. > > One run of by_input_sets!() takes a couple of seconds, so can be tested; > one run of decompose!() takes much longer, so to test decompose!() > I should stub by_input_sets!() so it returns canned data (right?). > > In this situation, I think I do need to test/spec the by_input_sets!() > private method ? otherwise there would be no code that would check on > the way it works. In TDD there is a rule of thumb that says don't stub a method in the same class as the method you're testing. The risk is that as the real implementation of by_input_sets!() changes over time, it has access to internal state that could impact the behaviour of decompose!(). It also sounds like by_input_sets!() has enough independent responsibility that it should actually be public. The standard approach here, which is as much a result of OO principles as TDD, is to extract a class with the by_input_sets!() exposed as a public method. You mock that object in your Decomposition examples and then you have public access to by_input_sets!() on the new class. Cheers, David > > -- Shot > -- > A school in the UK is using RFID chips in school uniforms to track > attendance. So now it's easy to cut class; just ask someone to carry > your shirt around the building while you're elsewhere. -- Bruce Schneier > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From kerry at kerrybuckley.com Fri Jan 11 05:33:29 2008 From: kerry at kerrybuckley.com (Kerry Buckley) Date: Fri, 11 Jan 2008 10:33:29 +0000 Subject: [rspec-users] Varying test data Message-ID: <02AB82F9-5F25-4C7F-B0B1-38D40B092D62@kerrybuckley.com> This isn't specific to RSpec, but is hopefully on-topic for this list. I like (especially when "ping pong pairing") to write a spec, then write the smallest amount of code I can to pass it (especially when "ping pong pairing"). Sometimes this means hard-coding a return value, which means another spec is needed to prove that the code is really behaving as it should. Trivial example: ---------- describe Adder do it "should add two numbers" do Adder.add(2, 2).should == 4 end end class Adder def add a, b 4 end end ---------- describe Adder do it "should add 2 and 2" do Adder.add(2, 2).should == 4 end it "should add 3 and 4" do Adder.add(3, 4).should == 7 end end class Adder def add a, b a + b end end ---------- It doesn't seem right though to have all those duplicate specs. An alternative is to generate random test data, but I'm not really comfortable doing that because it means the tests aren't strictly repeatable. I guess this is more of a problem with classic state-based testing, but even using BDD you still have to test state at the leaf nodes. Does anyone have an opinion about whether this is a problem, and whether there's a clean way of dealing with it? Thanks, Kerry From pergesu at gmail.com Fri Jan 11 05:48:15 2008 From: pergesu at gmail.com (Pat Maddox) Date: Fri, 11 Jan 2008 02:48:15 -0800 Subject: [rspec-users] Varying test data In-Reply-To: <02AB82F9-5F25-4C7F-B0B1-38D40B092D62@kerrybuckley.com> References: <02AB82F9-5F25-4C7F-B0B1-38D40B092D62@kerrybuckley.com> Message-ID: <810a540e0801110248s2d252035u924bd59fd3caf94@mail.gmail.com> On Jan 11, 2008 2:33 AM, Kerry Buckley wrote: > This isn't specific to RSpec, but is hopefully on-topic for this list. > > I like (especially when "ping pong pairing") to write a spec, then > write the smallest amount of code I can to pass it (especially when > "ping pong pairing"). Sometimes this means hard-coding a return value, > which means another spec is needed to prove that the code is really > behaving as it should. Trivial example: > > ---------- > describe Adder do > it "should add two numbers" do > Adder.add(2, 2).should == 4 > end > end > > class Adder > def add a, b > 4 > end > end > ---------- > describe Adder do > it "should add 2 and 2" do > Adder.add(2, 2).should == 4 > end > it "should add 3 and 4" do > Adder.add(3, 4).should == 7 > end > end > > class Adder > def add a, b > a + b > end > end > ---------- > > It doesn't seem right though to have all those duplicate specs. An > alternative is to generate random test data, but I'm not really > comfortable doing that because it means the tests aren't strictly > repeatable. I guess this is more of a problem with classic state-based > testing, but even using BDD you still have to test state at the leaf > nodes. > > Does anyone have an opinion about whether this is a problem, and > whether there's a clean way of dealing with it? If I were your pair, I would smack you if you hard-coded 4 and moved on to the next test :) You forgot the third step in BDD - refactoring! At the simplest level, that means removing duplication. The duplication in this case is between the test and production code. In your adder example, the red/green/refactor cycle ought to go like: red - write the spec green - make it pass by returning 4 refactor - generalize the method by returning the sum of the two variables Okay, I wouldn't smack you necessarily. What you're describing here is a TDD technique called Triangulation. Basically you keep writing tests until you have enough info to drive a useful generalization. With such a simple example, Triangulation probably isn't necessary. You can use Obvious Implementation (where you would just type out a + b to begin with - after being red first, of course), or you Fake It (by first returning 4 to get to green, then generalizing). Specs should give you confidence that the code works as expected. If it takes you two specs to Triangulate on a solution, and the two specs are redundant, feel free to delete one of them. Delete a spec if it doesn't add value, and keep it around if deleting it would reduce your confidence. I recommend reading Kent Beck's "TDD By Example" for a more in-depth discussion of these (and plenty other) techniques. Pat From dchelimsky at gmail.com Fri Jan 11 05:48:57 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 11 Jan 2008 04:48:57 -0600 Subject: [rspec-users] Varying test data In-Reply-To: <02AB82F9-5F25-4C7F-B0B1-38D40B092D62@kerrybuckley.com> References: <02AB82F9-5F25-4C7F-B0B1-38D40B092D62@kerrybuckley.com> Message-ID: <57c63afe0801110248i7d86c5qb416b97053c9e327@mail.gmail.com> On Jan 11, 2008 4:33 AM, Kerry Buckley wrote: > This isn't specific to RSpec, but is hopefully on-topic for this list. > > I like (especially when "ping pong pairing") to write a spec, then > write the smallest amount of code I can to pass it (especially when > "ping pong pairing"). Sometimes this means hard-coding a return value, > which means another spec is needed to prove that the code is really > behaving as it should. Trivial example: > > ---------- > describe Adder do > it "should add two numbers" do > Adder.add(2, 2).should == 4 > end > end > > class Adder > def add a, b > 4 > end > end > ---------- > describe Adder do > it "should add 2 and 2" do > Adder.add(2, 2).should == 4 > end > it "should add 3 and 4" do > Adder.add(3, 4).should == 7 > end > end > > class Adder > def add a, b > a + b > end > end > ---------- > > It doesn't seem right though to have all those duplicate specs. An > alternative is to generate random test data, but I'm not really > comfortable doing that because it means the tests aren't strictly > repeatable. I guess this is more of a problem with classic state-based > testing, but even using BDD you still have to test state at the leaf > nodes. > > Does anyone have an opinion about whether this is a problem, and > whether there's a clean way of dealing with it? The approach you are taking (writing the second example) is called triangulation. An other approach is to recognize in the first example that there is duplication between the example and the code being described. In this case, the number 4. From a duplication-removing perspective, that is sufficient motivation to make the change during the refactoring phase in THIS particular example. If you were describing an object that behaved fundamentally differently depending on input values, then you'd want the different examples. In this case, returning the sum is not fundamentally different in my view. That said, if you were REALLY building a calculator and not relying on the addition facilities of the language you were using, you would naturally have additional examples to cover edge cases. Double digits, for example. You might also want to run this by the testdrivendevelopment list (http://tech.groups.yahoo.com/group/testdrivendevelopment/). Cheers, David > > Thanks, > > Kerry > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Fri Jan 11 05:50:21 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 11 Jan 2008 04:50:21 -0600 Subject: [rspec-users] Varying test data In-Reply-To: <810a540e0801110248s2d252035u924bd59fd3caf94@mail.gmail.com> References: <02AB82F9-5F25-4C7F-B0B1-38D40B092D62@kerrybuckley.com> <810a540e0801110248s2d252035u924bd59fd3caf94@mail.gmail.com> Message-ID: <57c63afe0801110250u5aed4e9eh2e383658ca276ec7@mail.gmail.com> On Jan 11, 2008 4:48 AM, Pat Maddox wrote: > > On Jan 11, 2008 2:33 AM, Kerry Buckley wrote: > > This isn't specific to RSpec, but is hopefully on-topic for this list. > > > > I like (especially when "ping pong pairing") to write a spec, then > > write the smallest amount of code I can to pass it (especially when > > "ping pong pairing"). Sometimes this means hard-coding a return value, > > which means another spec is needed to prove that the code is really > > behaving as it should. Trivial example: > > > > ---------- > > describe Adder do > > it "should add two numbers" do > > Adder.add(2, 2).should == 4 > > end > > end > > > > class Adder > > def add a, b > > 4 > > end > > end > > ---------- > > describe Adder do > > it "should add 2 and 2" do > > Adder.add(2, 2).should == 4 > > end > > it "should add 3 and 4" do > > Adder.add(3, 4).should == 7 > > end > > end > > > > class Adder > > def add a, b > > a + b > > end > > end > > ---------- > > > > It doesn't seem right though to have all those duplicate specs. An > > alternative is to generate random test data, but I'm not really > > comfortable doing that because it means the tests aren't strictly > > repeatable. I guess this is more of a problem with classic state-based > > testing, but even using BDD you still have to test state at the leaf > > nodes. > > > > Does anyone have an opinion about whether this is a problem, and > > whether there's a clean way of dealing with it? > > If I were your pair, I would smack you if you hard-coded 4 and moved > on to the next test :) You forgot the third step in BDD - > refactoring! At the simplest level, that means removing duplication. > The duplication in this case is between the test and production code. > In your adder example, the red/green/refactor cycle ought to go like: > > red - write the spec > green - make it pass by returning 4 > refactor - generalize the method by returning the sum of the two variables > > Okay, I wouldn't smack you necessarily. What you're describing here > is a TDD technique called Triangulation. Basically you keep writing > tests until you have enough info to drive a useful generalization. > > With such a simple example, Triangulation probably isn't necessary. > You can use Obvious Implementation (where you would just type out a + > b to begin with - after being red first, of course), or you Fake It > (by first returning 4 to get to green, then generalizing). > > Specs should give you confidence that the code works as expected. If > it takes you two specs to Triangulate on a solution, and the two specs > are redundant, feel free to delete one of them. Delete a spec if it > doesn't add value, and keep it around if deleting it would reduce your > confidence. > > I recommend reading Kent Beck's "TDD By Example" for a more in-depth > discussion of these (and plenty other) techniques. Apparently, Pat and I are twins separated at birth. > > Pat > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From pergesu at gmail.com Fri Jan 11 05:58:21 2008 From: pergesu at gmail.com (Pat Maddox) Date: Fri, 11 Jan 2008 02:58:21 -0800 Subject: [rspec-users] Varying test data In-Reply-To: <57c63afe0801110250u5aed4e9eh2e383658ca276ec7@mail.gmail.com> References: <02AB82F9-5F25-4C7F-B0B1-38D40B092D62@kerrybuckley.com> <810a540e0801110248s2d252035u924bd59fd3caf94@mail.gmail.com> <57c63afe0801110250u5aed4e9eh2e383658ca276ec7@mail.gmail.com> Message-ID: <810a540e0801110258r66146546j690578ee75d35962@mail.gmail.com> On Jan 11, 2008 2:50 AM, David Chelimsky wrote: > > On Jan 11, 2008 4:48 AM, Pat Maddox wrote: > > > > On Jan 11, 2008 2:33 AM, Kerry Buckley wrote: > > > This isn't specific to RSpec, but is hopefully on-topic for this list. > > > > > > I like (especially when "ping pong pairing") to write a spec, then > > > write the smallest amount of code I can to pass it (especially when > > > "ping pong pairing"). Sometimes this means hard-coding a return value, > > > which means another spec is needed to prove that the code is really > > > behaving as it should. Trivial example: > > > > > > ---------- > > > describe Adder do > > > it "should add two numbers" do > > > Adder.add(2, 2).should == 4 > > > end > > > end > > > > > > class Adder > > > def add a, b > > > 4 > > > end > > > end > > > ---------- > > > describe Adder do > > > it "should add 2 and 2" do > > > Adder.add(2, 2).should == 4 > > > end > > > it "should add 3 and 4" do > > > Adder.add(3, 4).should == 7 > > > end > > > end > > > > > > class Adder > > > def add a, b > > > a + b > > > end > > > end > > > ---------- > > > > > > It doesn't seem right though to have all those duplicate specs. An > > > alternative is to generate random test data, but I'm not really > > > comfortable doing that because it means the tests aren't strictly > > > repeatable. I guess this is more of a problem with classic state-based > > > testing, but even using BDD you still have to test state at the leaf > > > nodes. > > > > > > Does anyone have an opinion about whether this is a problem, and > > > whether there's a clean way of dealing with it? > > > > If I were your pair, I would smack you if you hard-coded 4 and moved > > on to the next test :) You forgot the third step in BDD - > > refactoring! At the simplest level, that means removing duplication. > > The duplication in this case is between the test and production code. > > In your adder example, the red/green/refactor cycle ought to go like: > > > > red - write the spec > > green - make it pass by returning 4 > > refactor - generalize the method by returning the sum of the two variables > > > > Okay, I wouldn't smack you necessarily. What you're describing here > > is a TDD technique called Triangulation. Basically you keep writing > > tests until you have enough info to drive a useful generalization. > > > > With such a simple example, Triangulation probably isn't necessary. > > You can use Obvious Implementation (where you would just type out a + > > b to begin with - after being red first, of course), or you Fake It > > (by first returning 4 to get to green, then generalizing). > > > > Specs should give you confidence that the code works as expected. If > > it takes you two specs to Triangulate on a solution, and the two specs > > are redundant, feel free to delete one of them. Delete a spec if it > > doesn't add value, and keep it around if deleting it would reduce your > > confidence. > > > > I recommend reading Kent Beck's "TDD By Example" for a more in-depth > > discussion of these (and plenty other) techniques. > > Apparently, Pat and I are twins separated at birth. Have I ever told you what a smart guy you are? :) From kerry at kerrybuckley.com Fri Jan 11 06:13:46 2008 From: kerry at kerrybuckley.com (Kerry Buckley) Date: Fri, 11 Jan 2008 11:13:46 +0000 Subject: [rspec-users] Varying test data In-Reply-To: <57c63afe0801110250u5aed4e9eh2e383658ca276ec7@mail.gmail.com> References: <02AB82F9-5F25-4C7F-B0B1-38D40B092D62@kerrybuckley.com> <810a540e0801110248s2d252035u924bd59fd3caf94@mail.gmail.com> <57c63afe0801110250u5aed4e9eh2e383658ca276ec7@mail.gmail.com> Message-ID: <661FEE4B-9D11-4C81-9A9E-60B1CD9DE5F8@kerrybuckley.com> On 11 Jan 2008, at 10:50, David Chelimsky wrote: > On Jan 11, 2008 4:48 AM, Pat Maddox wrote: >> >> > > Apparently, Pat and I are twins separated at birth. Thanks both! Kerry From shot at hot.pl Fri Jan 11 09:04:09 2008 From: shot at hot.pl (Shot (Piotr Szotkowski)) Date: Fri, 11 Jan 2008 15:04:09 +0100 Subject: [rspec-users] specs on private methods In-Reply-To: <57c63afe0801110223o12ab6746w488584d3576454d8@mail.gmail.com> References: <840215067e9a8ce8de426499acb0d2a5@ruby-forum.com> <071A280E-9D43-497B-ABAE-01FD15716D75@tenner.org> <20080111094914.GF10401@durance.shot.pl> <57c63afe0801110223o12ab6746w488584d3576454d8@mail.gmail.com> Message-ID: <20080111140409.GG10401@durance.shot.pl> David Chelimsky: > On Jan 11, 2008 3:49 AM, Shot (Piotr Szotkowski) wrote: >> One run of by_input_sets!() takes a couple of seconds, so can >> be tested; one run of decompose!() takes much longer, so to test >> decompose!() I should stub by_input_sets!() so it returns canned >> data (right?). > In TDD there is a rule of thumb that says don't stub a method in the > same class as the method you're testing. The risk is that as the real > implementation of by_input_sets!() changes over time, it has access to > internal state that could impact the behaviour of decompose!(). Ah, well pointed. > It also sounds like by_input_sets!() has enough independent > responsibility that it should actually be public. It actually started out as a public method and only this very thread made me consider switching it to private. :) > The standard approach here, which is as much a result of OO principles > as TDD, is to extract a class with the by_input_sets!() exposed as > a public method. You mock that object in your Decomposition examples > and then you have public access to by_input_sets!() on the new class. Ok, makes sense, thanks ? this definitely made me think about the design. What about the general issue of a slow method that is fast enough to be testable in isolation, but some other method from the same class calls it so many times that it needs to be stubbed for that method to be spec?d in a sane manner? -- Shot -- Fail hard. Fail with motherfucking gusto. Succeeding, like flying, is throwing yourself to the ground and missing. -- Jeff Hodges -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 191 bytes Desc: not available Url : http://rubyforge.org/pipermail/rspec-users/attachments/20080111/f1b42214/attachment.bin From dchelimsky at gmail.com Fri Jan 11 10:18:27 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 11 Jan 2008 09:18:27 -0600 Subject: [rspec-users] specs on private methods In-Reply-To: <20080111140409.GG10401@durance.shot.pl> References: <840215067e9a8ce8de426499acb0d2a5@ruby-forum.com> <071A280E-9D43-497B-ABAE-01FD15716D75@tenner.org> <20080111094914.GF10401@durance.shot.pl> <57c63afe0801110223o12ab6746w488584d3576454d8@mail.gmail.com> <20080111140409.GG10401@durance.shot.pl> Message-ID: <57c63afe0801110718o8453bacv44b882601e14efbf@mail.gmail.com> On Jan 11, 2008 8:04 AM, Shot (Piotr Szotkowski) wrote: > David Chelimsky: > > > On Jan 11, 2008 3:49 AM, Shot (Piotr Szotkowski) wrote: > > >> One run of by_input_sets!() takes a couple of seconds, so can > >> be tested; one run of decompose!() takes much longer, so to test > >> decompose!() I should stub by_input_sets!() so it returns canned > >> data (right?). > > > In TDD there is a rule of thumb that says don't stub a method in the > > same class as the method you're testing. The risk is that as the real > > implementation of by_input_sets!() changes over time, it has access to > > internal state that could impact the behaviour of decompose!(). > > Ah, well pointed. > > > It also sounds like by_input_sets!() has enough independent > > responsibility that it should actually be public. > > It actually started out as a public method and only this > very thread made me consider switching it to private. :) > > > The standard approach here, which is as much a result of OO principles > > as TDD, is to extract a class with the by_input_sets!() exposed as > > a public method. You mock that object in your Decomposition examples > > and then you have public access to by_input_sets!() on the new class. > > Ok, makes sense, thanks ? this definitely > made me think about the design. > > What about the general issue of a slow method that is fast enough to be > testable in isolation, but some other method from the same class calls > it so many times that it needs to be stubbed for that method to be > spec'd in a sane manner? Every case is different. In this case, the method is slow because it calls one other method repeatedly, so the solution we've discussed may make sense. Without seeing the actual code, it's difficult to assess. In other cases there might be other design changes that could be made to not only improve the speed, but clarify intent. HTH, David > > -- Shot > -- > Fail hard. Fail with motherfucking gusto. Succeeding, like flying, > is throwing yourself to the ground and missing. -- Jeff Hodges > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Fri Jan 11 10:31:41 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Fri, 11 Jan 2008 10:31:41 -0500 Subject: [rspec-users] Missing methods In-Reply-To: References: Message-ID: <4167A6B3-624E-4665-B6FC-26EC8ED547FF@railsnewbie.com> 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| > eval <<-EOF > def self.create_#{klass}(attributes = {}) > default_attributes = valid_#{klass}_attributes > #{klass.camelize}.create! default_attributes.merge(attributes) > end > EOF > end > > def valid_message_attributes(options = {}) > { > #some message options > } > end > > #more valid_x_attributes methods > end > > When I require this file in a spec file, Factory.create_person works > fine. When I try to do it in a step file, Factory.create_person is > defined, but it fails because valid_person_attributes is missing. If > I'm in a debugger, and I do require 'model_factory' followed by > Factory.create_person, same deal. > > Do we have a blank slate being loaded somewhere, and why is it wiping > out require files? Actually, though, I think John D. Hume is right (and this is a current bug with FixtureReplacement, as well): your valid_* methods are not class methods, but instance methods. I bet the reason that it has worked in the past is because rspec does funny things with Module#include, and without having the time to look at the source, I'd bet that rspec ends up delegating to the class level (but story runner doesn't) - giving you the appearance that your software works, but in fact is just taking advantage of rspec's implementation. Prove me wrong, if you can. Best, Scott From zach.dennis at gmail.com Fri Jan 11 10:35:47 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Fri, 11 Jan 2008 10:35:47 -0500 Subject: [rspec-users] specs on private methods In-Reply-To: <57c63afe0801110223o12ab6746w488584d3576454d8@mail.gmail.com> References: <840215067e9a8ce8de426499acb0d2a5@ruby-forum.com> <071A280E-9D43-497B-ABAE-01FD15716D75@tenner.org> <20080111094914.GF10401@durance.shot.pl> <57c63afe0801110223o12ab6746w488584d3576454d8@mail.gmail.com> Message-ID: <85d99afe0801110735p86d5bf6g484e321f29f6058b@mail.gmail.com> On Jan 11, 2008 5:23 AM, David Chelimsky wrote: > On Jan 11, 2008 3:49 AM, Shot (Piotr Szotkowski) wrote: > > Daniel Tenner: > > > > > Might be a personal thing, but my approach is that I try to test the > > > public behaviour of the object. Testing private methods is, imho, > > > getting dangerously close to specifying how the object does its > > > business, rather than what it does. > > > > I agree on principle, but I ran into the following case in my PhD: > > > > There's a Decomposition class that decomposes an FSM to a given > > architecture. Its public methods should be new() and decompose!(). > > Now, decompose!() works by running a private method by_input_sets!() > > many times with different parameters. > > > > One run of by_input_sets!() takes a couple of seconds, so can be tested; > > one run of decompose!() takes much longer, so to test decompose!() > > I should stub by_input_sets!() so it returns canned data (right?). > > > > In this situation, I think I do need to test/spec the by_input_sets!() > > private method ? otherwise there would be no code that would check on > > the way it works. > > In TDD there is a rule of thumb that says don't stub a method in the > same class as the method you're testing. A simple rule I follow: Don't stub or mock the object under test. On Jan 11, 2008 9:04 AM, Shot (Piotr Szotkowski) wrote: > > What about the general issue of a slow method that is fast enough to be > testable in isolation, but some other method from the same class calls > it so many times that it needs to be stubbed for that method to be > spec'd in a sane manner? In addition to David's response to this, have you evaluated moving this method and its responsibility to its own object that could be tested in isolation, allowing you to not break the "don't stub or mock the object under test" guideline? -- Zach Dennis http://www.continuousthinking.com From tim at pivotib.com Fri Jan 11 10:45:11 2008 From: tim at pivotib.com (Tim Glen) Date: Fri, 11 Jan 2008 10:45:11 -0500 Subject: [rspec-users] changes in rspec's trunk and autotest In-Reply-To: <57c63afe0801101929q7be1d50ev5440cc78153d8a08@mail.gmail.com> References: <57c63afe0801101929q7be1d50ev5440cc78153d8a08@mail.gmail.com> Message-ID: since i'm on rspec trunk, I applied your patch and ran into a little issue. All my specs still run but it seems to be looking at and "attempting" all of my hidden files and directories (and some other stuff too?): Dunno! Capfile Dunno! app/helpers/.svn/format Dunno! app/views/sales/.svn/text-base/edit.html.erb.svn-base Dunno! tmp/sessions/.svn/dir-prop-base Dunno! app/helpers/.svn/README.txt Dunno! app/helpers/.svn/wcprops/stores_helper.rb.svn-work Dunno! app/views/users/.svn/entries Dunno! app/.DS_Store Dunno! app/controllers/.svn/prop-base/users_controller.rb.svn-base Dunno! app/views/markets/.svn/wcprops/index.html.erb.svn-work Dunno! spec/views/markets/.svn/text-base/new.html.erb_spec.rb.svn-base Dunno! app/views/stores/.svn/wcprops/index.html.erb.svn-work Dunno! tmp/cache/.svn/format Dunno! app/views/districts/.svn/dir-wcprops Dunno! .svn/wcprops/Capfile.svn-work Dunno! spec/views/markets/.svn/wcprops/edit.html.erb_spec.rb.svn-work Like I said, my specs still run, so things aren't broken per se but this behaviour doesn't really seem right to me. Is this happening for anyone else or am I some sort of edge case? take care, tim On 10-Jan-08, at 10:29 PM, David Chelimsky wrote: > 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 you can use to plug into > autotest's hooks to extend/modify it's behaviour. > > Previously, subclasses got loaded after .autotest, causing changes to > test_mappings and exceptions to be overridden. With the next release, > the load order is corrected so anything in .autotest will be processed > after Autotest::Rspec or Autotest::RailsRspec is loaded. > > I committed changes to RSpec's trunk r3220 that will break your > current autotest configuration. If it does, you can apply this patch > (http://pastie.caboo.se/138024) to your local copy of ZenTest > (assuming you're up to 3.7.2) and all should be right with the world. > > Again - this is ONLY for people who are following RSpec's trunk and > using autotest. > > Cheers, > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Fri Jan 11 10:52:07 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 11 Jan 2008 09:52:07 -0600 Subject: [rspec-users] changes in rspec's trunk and autotest In-Reply-To: References: <57c63afe0801101929q7be1d50ev5440cc78153d8a08@mail.gmail.com> Message-ID: <57c63afe0801110752s14c5b9c4ud4f75dbfa6b96051@mail.gmail.com> On Jan 11, 2008 9:45 AM, Tim Glen wrote: > since i'm on rspec trunk, I applied your patch and ran into a little > issue. All my specs still run but it seems to be looking at and > "attempting" all of my hidden files and directories (and some other > stuff too?): > > Dunno! Capfile > Dunno! app/helpers/.svn/format > Dunno! app/views/sales/.svn/text-base/edit.html.erb.svn-base > Dunno! tmp/sessions/.svn/dir-prop-base > Dunno! app/helpers/.svn/README.txt > Dunno! app/helpers/.svn/wcprops/stores_helper.rb.svn-work > Dunno! app/views/users/.svn/entries > Dunno! app/.DS_Store > Dunno! app/controllers/.svn/prop-base/users_controller.rb.svn-base > Dunno! app/views/markets/.svn/wcprops/index.html.erb.svn-work > Dunno! spec/views/markets/.svn/text-base/new.html.erb_spec.rb.svn-base > Dunno! app/views/stores/.svn/wcprops/index.html.erb.svn-work > Dunno! tmp/cache/.svn/format > Dunno! app/views/districts/.svn/dir-wcprops > Dunno! .svn/wcprops/Capfile.svn-work > Dunno! spec/views/markets/.svn/wcprops/edit.html.erb_spec.rb.svn-work > This is a new thing autotest is doing. That's just a listing of files in the current directory or below that autotest doesn't see mapped in some way. If you set $VERBOSE to false in .autotest, they won't appear. The other thing you can do, which I think is the better approach, is to add an initialize hook in .autotest. Here's mine: Autotest.add_hook :initialize do |at| %w{.hg .git stories tmtags Rakefile Capfile README spec/spec.opts spec/rcov.opts}.each {|exception|at.add_exception(exception)} end The cool thing is this actually works now. Before, these exceptions got squashed by autotest subclasses (like autotest/rspec). HTH, David > > Like I said, my specs still run, so things aren't broken per se but > this behaviour doesn't really seem right to me. Is this happening for > anyone else or am I some sort of edge case? > > take care, > tim > > > On 10-Jan-08, at 10:29 PM, David Chelimsky wrote: > > > 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 you can use to plug into > > autotest's hooks to extend/modify it's behaviour. > > > > Previously, subclasses got loaded after .autotest, causing changes to > > test_mappings and exceptions to be overridden. With the next release, > > the load order is corrected so anything in .autotest will be processed > > after Autotest::Rspec or Autotest::RailsRspec is loaded. > > > > I committed changes to RSpec's trunk r3220 that will break your > > current autotest configuration. If it does, you can apply this patch > > (http://pastie.caboo.se/138024) to your local copy of ZenTest > > (assuming you're up to 3.7.2) and all should be right with the world. > > > > Again - this is ONLY for people who are following RSpec's trunk and > > using autotest. > > > > Cheers, > > David > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > From ben at benmabey.com Fri Jan 11 10:54:26 2008 From: ben at benmabey.com (Ben Mabey) Date: Fri, 11 Jan 2008 08:54:26 -0700 Subject: [rspec-users] specs on private methods In-Reply-To: <57c63afe0801110223o12ab6746w488584d3576454d8@mail.gmail.com> References: <840215067e9a8ce8de426499acb0d2a5@ruby-forum.com> <071A280E-9D43-497B-ABAE-01FD15716D75@tenner.org> <20080111094914.GF10401@durance.shot.pl> <57c63afe0801110223o12ab6746w488584d3576454d8@mail.gmail.com> Message-ID: <47879132.4080500@benmabey.com> David Chelimsky wrote: > > > In TDD there is a rule of thumb that says don't stub a method in the > same class as the method you're testing. The risk is that as the real > implementation of by_input_sets!() changes over time, it has access to > internal state that could impact the behaviour of decompose!(). > So, stubbing a current_user method on a rails controller would be considered bad practice? I suppose stubbing the find on User would be just as easy but I have always just stubbed controller.current_user. -Ben From dchelimsky at gmail.com Fri Jan 11 10:56:16 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 11 Jan 2008 09:56:16 -0600 Subject: [rspec-users] changes in rspec's trunk and autotest In-Reply-To: <57c63afe0801110752s14c5b9c4ud4f75dbfa6b96051@mail.gmail.com> References: <57c63afe0801101929q7be1d50ev5440cc78153d8a08@mail.gmail.com> <57c63afe0801110752s14c5b9c4ud4f75dbfa6b96051@mail.gmail.com> Message-ID: <57c63afe0801110756n3dce203ds290e2883618af3aa@mail.gmail.com> On Jan 11, 2008 9:52 AM, David Chelimsky wrote: > On Jan 11, 2008 9:45 AM, Tim Glen wrote: > > since i'm on rspec trunk, I applied your patch and ran into a little > > issue. All my specs still run but it seems to be looking at and > > "attempting" all of my hidden files and directories (and some other > > stuff too?): > > > > Dunno! Capfile > > Dunno! app/helpers/.svn/format > > Dunno! app/views/sales/.svn/text-base/edit.html.erb.svn-base > > Dunno! tmp/sessions/.svn/dir-prop-base > > Dunno! app/helpers/.svn/README.txt > > Dunno! app/helpers/.svn/wcprops/stores_helper.rb.svn-work > > Dunno! app/views/users/.svn/entries > > Dunno! app/.DS_Store > > Dunno! app/controllers/.svn/prop-base/users_controller.rb.svn-base > > Dunno! app/views/markets/.svn/wcprops/index.html.erb.svn-work > > Dunno! spec/views/markets/.svn/text-base/new.html.erb_spec.rb.svn-base > > Dunno! app/views/stores/.svn/wcprops/index.html.erb.svn-work > > Dunno! tmp/cache/.svn/format > > Dunno! app/views/districts/.svn/dir-wcprops > > Dunno! .svn/wcprops/Capfile.svn-work > > Dunno! spec/views/markets/.svn/wcprops/edit.html.erb_spec.rb.svn-work > > > > This is a new thing autotest is doing. That's just a listing of files > in the current directory or below that autotest doesn't see mapped in > some way. > > If you set $VERBOSE to false in .autotest, they won't appear. > > The other thing you can do, which I think is the better approach, is > to add an initialize hook in .autotest. Here's mine: > > Autotest.add_hook :initialize do |at| > %w{.hg .git stories tmtags Rakefile Capfile README spec/spec.opts > spec/rcov.opts}.each {|exception|at.add_exception(exception)} > end BTW - you can have this hook in both ~/.autotest and .autotest in the project directory. The hook is addative, so you can have the common things in ~/.autotest and any project specific exceptions in the project's .autotest. Additionally, there are actually three methods related to exceptions: add_exception remove_exception clear_exceptions The load order is: the autotest class ~/.autotest ./.autotest So you get a LOT of control at various levels of granularity. Very cool stuff! Cheers, David > > The cool thing is this actually works now. Before, these exceptions > got squashed by autotest subclasses (like autotest/rspec). > > HTH, > David > > > > > > Like I said, my specs still run, so things aren't broken per se but > > this behaviour doesn't really seem right to me. Is this happening for > > anyone else or am I some sort of edge case? > > > > take care, > > tim > > > > > > On 10-Jan-08, at 10:29 PM, David Chelimsky wrote: > > > > > 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 you can use to plug into > > > autotest's hooks to extend/modify it's behaviour. > > > > > > Previously, subclasses got loaded after .autotest, causing changes to > > > test_mappings and exceptions to be overridden. With the next release, > > > the load order is corrected so anything in .autotest will be processed > > > after Autotest::Rspec or Autotest::RailsRspec is loaded. > > > > > > I committed changes to RSpec's trunk r3220 that will break your > > > current autotest configuration. If it does, you can apply this patch > > > (http://pastie.caboo.se/138024) to your local copy of ZenTest > > > (assuming you're up to 3.7.2) and all should be right with the world. > > > > > > Again - this is ONLY for people who are following RSpec's trunk and > > > using autotest. > > > > > > Cheers, > > > David > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > From jonathan at parkerhill.com Fri Jan 11 11:19:02 2008 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Fri, 11 Jan 2008 11:19:02 -0500 Subject: [rspec-users] Varying test data In-Reply-To: <57c63afe0801110250u5aed4e9eh2e383658ca276ec7@mail.gmail.com> References: <02AB82F9-5F25-4C7F-B0B1-38D40B092D62@kerrybuckley.com> <810a540e0801110248s2d252035u924bd59fd3caf94@mail.gmail.com> <57c63afe0801110250u5aed4e9eh2e383658ca276ec7@mail.gmail.com> Message-ID: On Jan 11, 2008, at 5:50 AM, David Chelimsky wrote: > Apparently, Pat and I are twins separated at birth. Would it then be correct to refactor and eliminate one of them?? :)) From nathan.sutton at gmail.com Fri Jan 11 11:22:02 2008 From: nathan.sutton at gmail.com (Nathan Sutton) Date: Fri, 11 Jan 2008 10:22:02 -0600 Subject: [rspec-users] Varying test data In-Reply-To: References: <02AB82F9-5F25-4C7F-B0B1-38D40B092D62@kerrybuckley.com> <810a540e0801110248s2d252035u924bd59fd3caf94@mail.gmail.com> <57c63afe0801110250u5aed4e9eh2e383658ca276ec7@mail.gmail.com> Message-ID: We're clearly at green! Nathan Sutton fowlduck at gmail.com rspec 1.1 rspec_on_rails 1.1 rails 2.0.2 On Jan 11, 2008, at 10:19 AM, Jonathan Linowes wrote: > > On Jan 11, 2008, at 5:50 AM, David Chelimsky wrote: > >> Apparently, Pat and I are twins separated at birth. > > > Would it then be correct to refactor and eliminate one of them?? > > :)) > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Fri Jan 11 11:54:41 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 11 Jan 2008 10:54:41 -0600 Subject: [rspec-users] Varying test data In-Reply-To: References: <02AB82F9-5F25-4C7F-B0B1-38D40B092D62@kerrybuckley.com> <810a540e0801110248s2d252035u924bd59fd3caf94@mail.gmail.com> <57c63afe0801110250u5aed4e9eh2e383658ca276ec7@mail.gmail.com> Message-ID: <57c63afe0801110854r5fa2ef58kbd048e57ffbcb22d@mail.gmail.com> On Jan 11, 2008 10:19 AM, Jonathan Linowes wrote: > > On Jan 11, 2008, at 5:50 AM, David Chelimsky wrote: > > > Apparently, Pat and I are twins separated at birth. > > Would it then be correct to refactor and eliminate one of them?? If you could argue that we were ultimately composed of 1s and 0s, perhaps. From dchelimsky at gmail.com Fri Jan 11 11:56:34 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 11 Jan 2008 10:56:34 -0600 Subject: [rspec-users] specs on private methods In-Reply-To: <47879132.4080500@benmabey.com> References: <840215067e9a8ce8de426499acb0d2a5@ruby-forum.com> <071A280E-9D43-497B-ABAE-01FD15716D75@tenner.org> <20080111094914.GF10401@durance.shot.pl> <57c63afe0801110223o12ab6746w488584d3576454d8@mail.gmail.com> <47879132.4080500@benmabey.com> Message-ID: <57c63afe0801110856r498d96fap272306abe40f787f@mail.gmail.com> On Jan 11, 2008 9:54 AM, Ben Mabey wrote: > David Chelimsky wrote: > > > > > > In TDD there is a rule of thumb that says don't stub a method in the > > same class as the method you're testing. The risk is that as the real > > implementation of by_input_sets!() changes over time, it has access to > > internal state that could impact the behaviour of decompose!(). > > > > > So, stubbing a current_user method on a rails controller would be > considered bad practice? > I suppose stubbing the find on User would be just as easy but I have > always just stubbed controller.current_user. Rails is tricky. These rules are stem from situations in which you are in complete control of the design. Clearly, Rails makes it easy to work with if you follow its conventions, but the resulting design is far from Object Oriented. This is not an inherently bad thing - don't get me wrong. I use Rails and it's a delight in terms of development. But it's a challenge in terms of this kind of testing. That said, the User class object is a different object than a user instance, so I have no issue w/ stubbing find on it. As for controller.current_user, a purist TDD view would have you move that behaviour elsewhere. I break the rule and just stub it directly. This general advice I learned from Uncle Bob Martin: sometimes you have to break the rules, but when you do you should do it consciously and feel dirty about it ;) > > -Ben > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From tim at pivotib.com Fri Jan 11 12:36:25 2008 From: tim at pivotib.com (Tim Glen) Date: Fri, 11 Jan 2008 12:36:25 -0500 Subject: [rspec-users] changes in rspec's trunk and autotest In-Reply-To: <57c63afe0801110756n3dce203ds290e2883618af3aa@mail.gmail.com> References: <57c63afe0801101929q7be1d50ev5440cc78153d8a08@mail.gmail.com> <57c63afe0801110752s14c5b9c4ud4f75dbfa6b96051@mail.gmail.com> <57c63afe0801110756n3dce203ds290e2883618af3aa@mail.gmail.com> Message-ID: <11D14F4C-2344-48E7-AA8A-A8318580CA4D@pivotib.com> very cool. Funny enough, I never knew this functionality even existed - it was just getting clobbered all this time. Now I see ~10 files that actually need specs, which were totally getting missed before! thanks, tim On 11-Jan-08, at 10:56 AM, David Chelimsky wrote: > On Jan 11, 2008 9:52 AM, David Chelimsky wrote: >> On Jan 11, 2008 9:45 AM, Tim Glen wrote: >>> since i'm on rspec trunk, I applied your patch and ran into a little >>> issue. All my specs still run but it seems to be looking at and >>> "attempting" all of my hidden files and directories (and some other >>> stuff too?): >>> >>> Dunno! Capfile >>> Dunno! app/helpers/.svn/format >>> Dunno! app/views/sales/.svn/text-base/edit.html.erb.svn-base >>> Dunno! tmp/sessions/.svn/dir-prop-base >>> Dunno! app/helpers/.svn/README.txt >>> Dunno! app/helpers/.svn/wcprops/stores_helper.rb.svn-work >>> Dunno! app/views/users/.svn/entries >>> Dunno! app/.DS_Store >>> Dunno! app/controllers/.svn/prop-base/users_controller.rb.svn-base >>> Dunno! app/views/markets/.svn/wcprops/index.html.erb.svn-work >>> Dunno! spec/views/markets/.svn/text-base/new.html.erb_spec.rb.svn- >>> base >>> Dunno! app/views/stores/.svn/wcprops/index.html.erb.svn-work >>> Dunno! tmp/cache/.svn/format >>> Dunno! app/views/districts/.svn/dir-wcprops >>> Dunno! .svn/wcprops/Capfile.svn-work >>> Dunno! spec/views/markets/.svn/wcprops/edit.html.erb_spec.rb.svn- >>> work >>> >> >> This is a new thing autotest is doing. That's just a listing of files >> in the current directory or below that autotest doesn't see mapped in >> some way. >> >> If you set $VERBOSE to false in .autotest, they won't appear. >> >> The other thing you can do, which I think is the better approach, is >> to add an initialize hook in .autotest. Here's mine: >> >> Autotest.add_hook :initialize do |at| >> %w{.hg .git stories tmtags Rakefile Capfile README spec/spec.opts >> spec/rcov.opts}.each {|exception|at.add_exception(exception)} >> end > > BTW - you can have this hook in both ~/.autotest and .autotest in the > project directory. The hook is addative, so you can have the common > things in ~/.autotest and any project specific exceptions in the > project's .autotest. > > Additionally, there are actually three methods related to exceptions: > > add_exception > remove_exception > clear_exceptions > > The load order is: > > the autotest class > ~/.autotest > ./.autotest > > So you get a LOT of control at various levels of granularity. > > Very cool stuff! > > Cheers, > David > >> >> The cool thing is this actually works now. Before, these exceptions >> got squashed by autotest subclasses (like autotest/rspec). >> >> HTH, >> David >> >> >>> >>> Like I said, my specs still run, so things aren't broken per se but >>> this behaviour doesn't really seem right to me. Is this happening >>> for >>> anyone else or am I some sort of edge case? >>> >>> take care, >>> tim >>> >>> >>> On 10-Jan-08, at 10:29 PM, David Chelimsky wrote: >>> >>>> 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 you can use to plug into >>>> autotest's hooks to extend/modify it's behaviour. >>>> >>>> Previously, subclasses got loaded after .autotest, causing >>>> changes to >>>> test_mappings and exceptions to be overridden. With the next >>>> release, >>>> the load order is corrected so anything in .autotest will be >>>> processed >>>> after Autotest::Rspec or Autotest::RailsRspec is loaded. >>>> >>>> I committed changes to RSpec's trunk r3220 that will break your >>>> current autotest configuration. If it does, you can apply this >>>> patch >>>> (http://pastie.caboo.se/138024) to your local copy of ZenTest >>>> (assuming you're up to 3.7.2) and all should be right with the >>>> world. >>>> >>>> Again - this is ONLY for people who are following RSpec's trunk and >>>> using autotest. >>>> >>>> Cheers, >>>> David >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-users at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >>> >> From dchelimsky at gmail.com Fri Jan 11 12:38:51 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 11 Jan 2008 11:38:51 -0600 Subject: [rspec-users] changes in rspec's trunk and autotest In-Reply-To: <11D14F4C-2344-48E7-AA8A-A8318580CA4D@pivotib.com> References: <57c63afe0801101929q7be1d50ev5440cc78153d8a08@mail.gmail.com> <57c63afe0801110752s14c5b9c4ud4f75dbfa6b96051@mail.gmail.com> <57c63afe0801110756n3dce203ds290e2883618af3aa@mail.gmail.com> <11D14F4C-2344-48E7-AA8A-A8318580CA4D@pivotib.com> Message-ID: <57c63afe0801110938u4be48ae0pc012dd1a3ed71f56@mail.gmail.com> On Jan 11, 2008 11:36 AM, Tim Glen wrote: > very cool. > > Funny enough, I never knew this functionality even existed - it was > just getting clobbered all this time. It's only in the last release or two. > Now I see ~10 files that actually need specs, which were totally > getting missed before! Nice benefit. Cheers, David From zach.dennis at gmail.com Fri Jan 11 12:40:24 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Fri, 11 Jan 2008 12:40:24 -0500 Subject: [rspec-users] specs on private methods In-Reply-To: <57c63afe0801110856r498d96fap272306abe40f787f@mail.gmail.com> References: <840215067e9a8ce8de426499acb0d2a5@ruby-forum.com> <071A280E-9D43-497B-ABAE-01FD15716D75@tenner.org> <20080111094914.GF10401@durance.shot.pl> <57c63afe0801110223o12ab6746w488584d3576454d8@mail.gmail.com> <47879132.4080500@benmabey.com> <57c63afe0801110856r498d96fap272306abe40f787f@mail.gmail.com> Message-ID: <85d99afe0801110940h2d71130bv10aa23b00ae20535@mail.gmail.com> On Jan 11, 2008 11:56 AM, David Chelimsky wrote: > On Jan 11, 2008 9:54 AM, Ben Mabey wrote: > > David Chelimsky wrote: > > > > > > > > > In TDD there is a rule of thumb that says don't stub a method in the > > > same class as the method you're testing. The risk is that as the real > > > implementation of by_input_sets!() changes over time, it has access to > > > internal state that could impact the behaviour of decompose!(). > > > > > > > > > So, stubbing a current_user method on a rails controller would be > > considered bad practice? > > I suppose stubbing the find on User would be just as easy but I have > > always just stubbed controller.current_user. > > Rails is tricky. These rules are stem from situations in which you are > in complete control of the design. Clearly, Rails makes it easy to > work with if you follow its conventions, but the resulting design is > far from Object Oriented. This is not an inherently bad thing - don't > get me wrong. I use Rails and it's a delight in terms of development. > But it's a challenge in terms of this kind of testing. > > That said, the User class object is a different object than a user > instance, so I have no issue w/ stubbing find on it. > > As for controller.current_user, a purist TDD view would have you move > that behaviour elsewhere. I break the rule and just stub it directly. > This general advice I learned from Uncle Bob Martin: sometimes you > have to break the rules, but when you do you should do it consciously > and feel dirty about it ;) On the current project we've quit moved all authentication into a LoginManager. This has worked out so nicely as we have simple methods for: login_from_cookie, login_from_session, login_from_user_credentials, etc. This cleans up a lot of the hairy code sprinkled throughout controllers and before filters which were trying to do some form of authentication based on peeking at the sessions themselves or validating users. -- Zach Dennis http://www.continuousthinking.com From dchelimsky at gmail.com Fri Jan 11 12:42:18 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 11 Jan 2008 11:42:18 -0600 Subject: [rspec-users] specs on private methods In-Reply-To: <85d99afe0801110940h2d71130bv10aa23b00ae20535@mail.gmail.com> References: <840215067e9a8ce8de426499acb0d2a5@ruby-forum.com> <071A280E-9D43-497B-ABAE-01FD15716D75@tenner.org> <20080111094914.GF10401@durance.shot.pl> <57c63afe0801110223o12ab6746w488584d3576454d8@mail.gmail.com> <47879132.4080500@benmabey.com> <57c63afe0801110856r498d96fap272306abe40f787f@mail.gmail.com> <85d99afe0801110940h2d71130bv10aa23b00ae20535@mail.gmail.com> Message-ID: <57c63afe0801110942l54912617x21258a2c455d891@mail.gmail.com> On Jan 11, 2008 11:40 AM, Zach Dennis wrote: > On Jan 11, 2008 11:56 AM, David Chelimsky wrote: > > On Jan 11, 2008 9:54 AM, Ben Mabey wrote: > > > David Chelimsky wrote: > > > > > > > > > > > > In TDD there is a rule of thumb that says don't stub a method in the > > > > same class as the method you're testing. The risk is that as the real > > > > implementation of by_input_sets!() changes over time, it has access to > > > > internal state that could impact the behaviour of decompose!(). > > > > > > > > > > > > > So, stubbing a current_user method on a rails controller would be > > > considered bad practice? > > > I suppose stubbing the find on User would be just as easy but I have > > > always just stubbed controller.current_user. > > > > Rails is tricky. These rules are stem from situations in which you are > > in complete control of the design. Clearly, Rails makes it easy to > > work with if you follow its conventions, but the resulting design is > > far from Object Oriented. This is not an inherently bad thing - don't > > get me wrong. I use Rails and it's a delight in terms of development. > > But it's a challenge in terms of this kind of testing. > > > > That said, the User class object is a different object than a user > > instance, so I have no issue w/ stubbing find on it. > > > > As for controller.current_user, a purist TDD view would have you move > > that behaviour elsewhere. I break the rule and just stub it directly. > > This general advice I learned from Uncle Bob Martin: sometimes you > > have to break the rules, but when you do you should do it consciously > > and feel dirty about it ;) > > On the current project we've quit moved all authentication into a > LoginManager. This has worked out so nicely as we have simple methods > for: login_from_cookie, login_from_session, > login_from_user_credentials, etc. > > This cleans up a lot of the hairy code sprinkled throughout > controllers and before filters which were trying to do some form of > authentication based on peeking at the sessions themselves or > validating users. Cool. That sounds like the right way to go. I guess I've just been lazy - not wanting to have to stray too much from the code generated by restful_authentication on each project. Guess it's time for my own internal plugin/engine :) From ben at benmabey.com Fri Jan 11 12:45:41 2008 From: ben at benmabey.com (Ben Mabey) Date: Fri, 11 Jan 2008 10:45:41 -0700 Subject: [rspec-users] specs on private methods In-Reply-To: <85d99afe0801110940h2d71130bv10aa23b00ae20535@mail.gmail.com> References: <840215067e9a8ce8de426499acb0d2a5@ruby-forum.com> <071A280E-9D43-497B-ABAE-01FD15716D75@tenner.org> <20080111094914.GF10401@durance.shot.pl> <57c63afe0801110223o12ab6746w488584d3576454d8@mail.gmail.com> <47879132.4080500@benmabey.com> <57c63afe0801110856r498d96fap272306abe40f787f@mail.gmail.com> <85d99afe0801110940h2d71130bv10aa23b00ae20535@mail.gmail.com> Message-ID: <4787AB45.2030208@benmabey.com> Zach Dennis wrote: > On Jan 11, 2008 11:56 AM, David Chelimsky wrote: > >> On Jan 11, 2008 9:54 AM, Ben Mabey wrote: >> >>> David Chelimsky wrote: >>> >>>> In TDD there is a rule of thumb that says don't stub a method in the >>>> same class as the method you're testing. The risk is that as the real >>>> implementation of by_input_sets!() changes over time, it has access to >>>> internal state that could impact the behaviour of decompose!(). >>>> >>>> >>> So, stubbing a current_user method on a rails controller would be >>> considered bad practice? >>> I suppose stubbing the find on User would be just as easy but I have >>> always just stubbed controller.current_user. >>> >> Rails is tricky. These rules are stem from situations in which you are >> in complete control of the design. Clearly, Rails makes it easy to >> work with if you follow its conventions, but the resulting design is >> far from Object Oriented. This is not an inherently bad thing - don't >> get me wrong. I use Rails and it's a delight in terms of development. >> But it's a challenge in terms of this kind of testing. >> >> That said, the User class object is a different object than a user >> instance, so I have no issue w/ stubbing find on it. >> >> As for controller.current_user, a purist TDD view would have you move >> that behaviour elsewhere. I break the rule and just stub it directly. >> This general advice I learned from Uncle Bob Martin: sometimes you >> have to break the rules, but when you do you should do it consciously >> and feel dirty about it ;) >> > > On the current project we've quit moved all authentication into a > LoginManager. This has worked out so nicely as we have simple methods > for: login_from_cookie, login_from_session, > login_from_user_credentials, etc. > > This cleans up a lot of the hairy code sprinkled throughout > controllers and before filters which were trying to do some form of > authentication based on peeking at the sessions themselves or > validating users. > > Interesting, do you pass in the session in the constructor or how do you get access to the session data? -Ben From zach.dennis at gmail.com Fri Jan 11 12:49:26 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Fri, 11 Jan 2008 12:49:26 -0500 Subject: [rspec-users] specs on private methods In-Reply-To: <4787AB45.2030208@benmabey.com> References: <840215067e9a8ce8de426499acb0d2a5@ruby-forum.com> <071A280E-9D43-497B-ABAE-01FD15716D75@tenner.org> <20080111094914.GF10401@durance.shot.pl> <57c63afe0801110223o12ab6746w488584d3576454d8@mail.gmail.com> <47879132.4080500@benmabey.com> <57c63afe0801110856r498d96fap272306abe40f787f@mail.gmail.com> <85d99afe0801110940h2d71130bv10aa23b00ae20535@mail.gmail.com> <4787AB45.2030208@benmabey.com> Message-ID: <85d99afe0801110949ia964230kf8fc45de2adafe11@mail.gmail.com> We pass the required items in as method arguments. In the spirit of sharing code and getting people to review code. Here is our current LoginManager: class LoginManager include Injection inject :invitation_manager def login_from_cookie(cookies, session) CookieLoginManager.new( :cookies => cookies, :session => session, :invitation_manager => @invitation_manager ).login end def login_from_session(session) SessionLoginManager.new( :session => session, :invitation_manager => @invitation_manager ).login end def login_with_credentials(options, session, cookies) UserCredentialsLoginManager.new( :options => options, :session => session, :cookies => cookies, :invitation_manager => @invitation_manager ).login end def login_from_password_reset(user, session) PasswordResetLoginManager.new( :user => user, :session => session ).login end def login_from_signup(user, session) SignupLoginManager.new( :user => user, :session => session, :invitation_manager => @invitation_manager ).login end end The reason we did this in the first place was that we needed to be able to add functionality (accepting invitations) to the login process and it seemed to get ugly without having it isolated in it's own object. We use additional login managers behind the scenes to have simple testable objects for each type of login we do. The "Injection" module just lets us pull out existing objects from a global app content and assign them as instance variables. That is how we are getting reference to invitation manager. Zach On Jan 11, 2008 12:45 PM, Ben Mabey wrote: > > Zach Dennis wrote: > > On Jan 11, 2008 11:56 AM, David Chelimsky wrote: > > > >> On Jan 11, 2008 9:54 AM, Ben Mabey wrote: > >> > >>> David Chelimsky wrote: > >>> > >>>> In TDD there is a rule of thumb that says don't stub a method in the > >>>> same class as the method you're testing. The risk is that as the real > >>>> implementation of by_input_sets!() changes over time, it has access to > >>>> internal state that could impact the behaviour of decompose!(). > >>>> > >>>> > >>> So, stubbing a current_user method on a rails controller would be > >>> considered bad practice? > >>> I suppose stubbing the find on User would be just as easy but I have > >>> always just stubbed controller.current_user. > >>> > >> Rails is tricky. These rules are stem from situations in which you are > >> in complete control of the design. Clearly, Rails makes it easy to > >> work with if you follow its conventions, but the resulting design is > >> far from Object Oriented. This is not an inherently bad thing - don't > >> get me wrong. I use Rails and it's a delight in terms of development. > >> But it's a challenge in terms of this kind of testing. > >> > >> That said, the User class object is a different object than a user > >> instance, so I have no issue w/ stubbing find on it. > >> > >> As for controller.current_user, a purist TDD view would have you move > >> that behaviour elsewhere. I break the rule and just stub it directly. > >> This general advice I learned from Uncle Bob Martin: sometimes you > >> have to break the rules, but when you do you should do it consciously > >> and feel dirty about it ;) > >> > > > > On the current project we've quit moved all authentication into a > > LoginManager. This has worked out so nicely as we have simple methods > > for: login_from_cookie, login_from_session, > > login_from_user_credentials, etc. > > > > This cleans up a lot of the hairy code sprinkled throughout > > controllers and before filters which were trying to do some form of > > authentication based on peeking at the sessions themselves or > > validating users. > > > > > Interesting, do you pass in the session in the constructor or how do you > get access to the session data? > > -Ben > -- Zach Dennis http://www.continuousthinking.com From zach.dennis at gmail.com Fri Jan 11 12:55:36 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Fri, 11 Jan 2008 12:55:36 -0500 Subject: [rspec-users] specs on private methods In-Reply-To: <85d99afe0801110949ia964230kf8fc45de2adafe11@mail.gmail.com> References: <840215067e9a8ce8de426499acb0d2a5@ruby-forum.com> <071A280E-9D43-497B-ABAE-01FD15716D75@tenner.org> <20080111094914.GF10401@durance.shot.pl> <57c63afe0801110223o12ab6746w488584d3576454d8@mail.gmail.com> <47879132.4080500@benmabey.com> <57c63afe0801110856r498d96fap272306abe40f787f@mail.gmail.com> <85d99afe0801110940h2d71130bv10aa23b00ae20535@mail.gmail.com> <4787AB45.2030208@benmabey.com> <85d99afe0801110949ia964230kf8fc45de2adafe11@mail.gmail.com> Message-ID: <85d99afe0801110955y2436cbd0n31836b8939b6e763@mail.gmail.com> To add, all of our managers return LoginResult objects which contain methods like: - successful? - user - message In the controller our code will look like: if login.successful? self.current_user = login.user else flash[:error] = login.message end This has worked well because it allows each our types of logins to generate an accurate login message based on the type of login. For example when a user logs in from a session you don't need a message, but after someone logs in with their credentials you may want to say "You've successfully logged in". I like this approach because it removes responsibility away from the controller, and it makes things much easier to test (and to understand IMO). And you have a very readable API, Zach On Jan 11, 2008 12:49 PM, Zach Dennis wrote: > We pass the required items in as method arguments. In the spirit of > sharing code and getting people to review code. Here is our current > LoginManager: > > class LoginManager > include Injection > inject :invitation_manager > > def login_from_cookie(cookies, session) > CookieLoginManager.new( > :cookies => cookies, > :session => session, > :invitation_manager => @invitation_manager > ).login > end > > def login_from_session(session) > SessionLoginManager.new( > :session => session, > :invitation_manager => @invitation_manager > ).login > end > > def login_with_credentials(options, session, cookies) > UserCredentialsLoginManager.new( > :options => options, > :session => session, > :cookies => cookies, > :invitation_manager => @invitation_manager > ).login > end > > def login_from_password_reset(user, session) > PasswordResetLoginManager.new( > :user => user, > :session => session > ).login > end > > def login_from_signup(user, session) > SignupLoginManager.new( > :user => user, > :session => session, > :invitation_manager => @invitation_manager > ).login > end > > end > > > The reason we did this in the first place was that we needed to be > able to add functionality (accepting invitations) to the login process > and it seemed to get ugly without having it isolated in it's own > object. We use additional login managers behind the scenes to have > simple testable objects for each type of login we do. > > The "Injection" module just lets us pull out existing objects from a > global app content and assign them as instance variables. That is how > we are getting reference to invitation manager. > > Zach > > > On Jan 11, 2008 12:45 PM, Ben Mabey wrote: > > > > Zach Dennis wrote: > > > On Jan 11, 2008 11:56 AM, David Chelimsky wrote: > > > > > >> On Jan 11, 2008 9:54 AM, Ben Mabey wrote: > > >> > > >>> David Chelimsky wrote: > > >>> > > >>>> In TDD there is a rule of thumb that says don't stub a method in the > > >>>> same class as the method you're testing. The risk is that as the real > > >>>> implementation of by_input_sets!() changes over time, it has access to > > >>>> internal state that could impact the behaviour of decompose!(). > > >>>> > > >>>> > > >>> So, stubbing a current_user method on a rails controller would be > > >>> considered bad practice? > > >>> I suppose stubbing the find on User would be just as easy but I have > > >>> always just stubbed controller.current_user. > > >>> > > >> Rails is tricky. These rules are stem from situations in which you are > > >> in complete control of the design. Clearly, Rails makes it easy to > > >> work with if you follow its conventions, but the resulting design is > > >> far from Object Oriented. This is not an inherently bad thing - don't > > >> get me wrong. I use Rails and it's a delight in terms of development. > > >> But it's a challenge in terms of this kind of testing. > > >> > > >> That said, the User class object is a different object than a user > > >> instance, so I have no issue w/ stubbing find on it. > > >> > > >> As for controller.current_user, a purist TDD view would have you move > > >> that behaviour elsewhere. I break the rule and just stub it directly. > > >> This general advice I learned from Uncle Bob Martin: sometimes you > > >> have to break the rules, but when you do you should do it consciously > > >> and feel dirty about it ;) > > >> > > > > > > On the current project we've quit moved all authentication into a > > > LoginManager. This has worked out so nicely as we have simple methods > > > for: login_from_cookie, login_from_session, > > > login_from_user_credentials, etc. > > > > > > This cleans up a lot of the hairy code sprinkled throughout > > > controllers and before filters which were trying to do some form of > > > authentication based on peeking at the sessions themselves or > > > validating users. > > > > > > > > Interesting, do you pass in the session in the constructor or how do you > > get access to the session data? > > > > -Ben > > > > > > > -- > Zach Dennis > http://www.continuousthinking.com > -- Zach Dennis http://www.continuousthinking.com From cody at skidmore.us Fri Jan 11 12:56:43 2008 From: cody at skidmore.us (Cody P. Skidmore) Date: Fri, 11 Jan 2008 09:56:43 -0800 (PST) Subject: [rspec-users] specs on private methods In-Reply-To: <85d99afe0801110949ia964230kf8fc45de2adafe11@mail.gmail.com> References: <840215067e9a8ce8de426499acb0d2a5@ruby-forum.com> <071A280E-9D43-497B-ABAE-01FD15716D75@tenner.org> <20080111094914.GF10401@durance.shot.pl> <57c63afe0801110223o12ab6746w488584d3576454d8@mail.gmail.com> <47879132.4080500@benmabey.com> <57c63afe0801110856r498d96fap272306abe40f787f@mail.gmail.com> <85d99afe0801110940h2d71130bv10aa23b00ae20535@mail.gmail.com> <4787AB45.2030208@benmabey.com> <85d99afe0801110949ia964230kf8fc45de2adafe11@mail.gmail.com> Message-ID: <61999.216.167.174.66.1200074203.squirrel@webmail.skidmore.us> Thank you Zach. I was just about to ask about this. I'm just getting started with restful_authentication and have missed the context of your point. restful_authentication is such a huge improvement over what I'm use to. Could you elaborate just a little on the use context in controllers? Is this called from the "authenticate" method in the controller? Cody Zach Dennis wrote: > We pass the required items in as method arguments. In the spirit of > sharing code and getting people to review code. Here is our current > LoginManager: > > class LoginManager > include Injection > inject :invitation_manager > > def login_from_cookie(cookies, session) > CookieLoginManager.new( > :cookies => cookies, > :session => session, > :invitation_manager => @invitation_manager > ).login > end > > def login_from_session(session) > SessionLoginManager.new( > :session => session, > :invitation_manager => @invitation_manager > ).login > end > > def login_with_credentials(options, session, cookies) > UserCredentialsLoginManager.new( > :options => options, > :session => session, > :cookies => cookies, > :invitation_manager => @invitation_manager > ).login > end > > def login_from_password_reset(user, session) > PasswordResetLoginManager.new( > :user => user, > :session => session > ).login > end > > def login_from_signup(user, session) > SignupLoginManager.new( > :user => user, > :session => session, > :invitation_manager => @invitation_manager > ).login > end > > end > > > The reason we did this in the first place was that we needed to be > able to add functionality (accepting invitations) to the login process > and it seemed to get ugly without having it isolated in it's own > object. We use additional login managers behind the scenes to have > simple testable objects for each type of login we do. > > The "Injection" module just lets us pull out existing objects from a > global app content and assign them as instance variables. That is how > we are getting reference to invitation manager. > > Zach > > On Jan 11, 2008 12:45 PM, Ben Mabey wrote: >> >> Zach Dennis wrote: >> > On Jan 11, 2008 11:56 AM, David Chelimsky >> wrote: >> > >> >> On Jan 11, 2008 9:54 AM, Ben Mabey wrote: >> >> >> >>> David Chelimsky wrote: >> >>> >> >>>> In TDD there is a rule of thumb that says don't stub a method in >> the >> >>>> same class as the method you're testing. The risk is that as the >> real >> >>>> implementation of by_input_sets!() changes over time, it has access >> to >> >>>> internal state that could impact the behaviour of decompose!(). >> >>>> >> >>>> >> >>> So, stubbing a current_user method on a rails controller would be >> >>> considered bad practice? >> >>> I suppose stubbing the find on User would be just as easy but I have >> >>> always just stubbed controller.current_user. >> >>> >> >> Rails is tricky. These rules are stem from situations in which you >> are >> >> in complete control of the design. Clearly, Rails makes it easy to >> >> work with if you follow its conventions, but the resulting design is >> >> far from Object Oriented. This is not an inherently bad thing - don't >> >> get me wrong. I use Rails and it's a delight in terms of development. >> >> But it's a challenge in terms of this kind of testing. >> >> >> >> That said, the User class object is a different object than a user >> >> instance, so I have no issue w/ stubbing find on it. >> >> >> >> As for controller.current_user, a purist TDD view would have you move >> >> that behaviour elsewhere. I break the rule and just stub it directly. >> >> This general advice I learned from Uncle Bob Martin: sometimes you >> >> have to break the rules, but when you do you should do it consciously >> >> and feel dirty about it ;) >> >> >> > >> > On the current project we've quit moved all authentication into a >> > LoginManager. This has worked out so nicely as we have simple methods >> > for: login_from_cookie, login_from_session, >> > login_from_user_credentials, etc. >> > >> > This cleans up a lot of the hairy code sprinkled throughout >> > controllers and before filters which were trying to do some form of >> > authentication based on peeking at the sessions themselves or >> > validating users. >> > >> > >> Interesting, do you pass in the session in the constructor or how do you >> get access to the session data? >> >> -Ben >> > > > > -- > Zach Dennis > http://www.continuousthinking.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > With Regards, // Signed // Cody P. Skidmore From zach.dennis at gmail.com Fri Jan 11 13:07:58 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Fri, 11 Jan 2008 13:07:58 -0500 Subject: [rspec-users] specs on private methods In-Reply-To: <61999.216.167.174.66.1200074203.squirrel@webmail.skidmore.us> References: <840215067e9a8ce8de426499acb0d2a5@ruby-forum.com> <071A280E-9D43-497B-ABAE-01FD15716D75@tenner.org> <20080111094914.GF10401@durance.shot.pl> <57c63afe0801110223o12ab6746w488584d3576454d8@mail.gmail.com> <47879132.4080500@benmabey.com> <57c63afe0801110856r498d96fap272306abe40f787f@mail.gmail.com> <85d99afe0801110940h2d71130bv10aa23b00ae20535@mail.gmail.com> <4787AB45.2030208@benmabey.com> <85d99afe0801110949ia964230kf8fc45de2adafe11@mail.gmail.com> <61999.216.167.174.66.1200074203.squirrel@webmail.skidmore.us> Message-ID: <85d99afe0801111007y153930fcx61e38c06712d9c93@mail.gmail.com> On Jan 11, 2008 12:56 PM, Cody P. Skidmore wrote: > Thank you Zach. I was just about to ask about this. I'm just getting > started with restful_authentication and have missed the context of your > point. restful_authentication is such a huge improvement over what I'm > use to. > > Could you elaborate just a little on the use context in controllers? Is > this called from the "authenticate" method in the controller? > Here is a before filter in our ApplicationController for attempting to log the user in from a cookie: Here is what we have in our application controller as a before filter for logging in from a controller: def login_from_cookie session[:invitation_code] = params[:code] if params[:code] unless logged_in? login = @login_manager.login_from_cookie(cookies, session) if login.successful? flash[:notice] = login.message self.current_user = login.user unless login.return_to.blank? redirect_to login.return_to return false end end end end And here is our SessionsController#create method for how to log in a user from their credentials: def create login = @login_manager.login_with_credentials(params[:login], session, cookies) if login.successful? self.current_user = login.user flash[:notice] = login.message redirect_to(login.return_to || home_path) session[:return_to] = nil else flash[:error] = login.message redirect_to signup_path(:login => {:email => params[:login][:email]}) end end You'll notice that we already have a @login_manager instance variable accessible in both cases. This is because of our use of the Injection plugin to automatically assign one for us from a global application context. You don't have to do that (but we like it because it decouples our controllers from implementation). You could construct a LoginManager where you need it, ie: LoginManager.new.login_with_credentials(....) We didn't set the methods up as class methods on LoginManager (ie: LoginManager.login_with_credentials) because we like to work with instances. We feel they are easier to test and refactor and it helps us avoid the temptation of adding class methods and instance methods which often times can lead to mixing multiple responsibilities onto an object. We're big fan of single responsibility. HTH, -- Zach Dennis http://www.continuousthinking.com From aslak.hellesoy at gmail.com Fri Jan 11 13:23:05 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Fri, 11 Jan 2008 19:23:05 +0100 Subject: [rspec-users] Varying test data In-Reply-To: <02AB82F9-5F25-4C7F-B0B1-38D40B092D62@kerrybuckley.com> References: <02AB82F9-5F25-4C7F-B0B1-38D40B092D62@kerrybuckley.com> Message-ID: <8d961d900801111023o23759bb8o3e535a30dcb80f82@mail.gmail.com> On Jan 11, 2008 11:33 AM, Kerry Buckley wrote: > This isn't specific to RSpec, but is hopefully on-topic for this list. > > I like (especially when "ping pong pairing") to write a spec, then > write the smallest amount of code I can to pass it (especially when > "ping pong pairing"). Sometimes this means hard-coding a return value, > which means another spec is needed to prove that the code is really > behaving as it should. Trivial example: > > ---------- > describe Adder do > it "should add two numbers" do > Adder.add(2, 2).should == 4 > end > end > > class Adder > def add a, b > 4 > end > end > ---------- > describe Adder do > it "should add 2 and 2" do > Adder.add(2, 2).should == 4 > end > it "should add 3 and 4" do > Adder.add(3, 4).should == 7 > end > end > > class Adder > def add a, b > a + b > end > end > ---------- > > It doesn't seem right though to have all those duplicate specs. An > alternative is to generate random test data, but I'm not really > comfortable doing that because it means the tests aren't strictly > repeatable. I guess this is more of a problem with classic state-based > testing, but even using BDD you still have to test state at the leaf > nodes. > It may not be applicable in your trivial context, but "pair-wise" testing (has nothing to do with pair programming) is a really powerful technique you could consider. It's a mini method that generates input combinations based on a set of possible values, dramatically reducing the number of combinations while still giving you the most important combinations. It's based on a theory that bugs often occur when a pair of data changes, and it tries to generate data that covers as many pairs as possible without going overboard. It's the most interesting test-related practice I have learned in several years (there are separate conferences on the topic!). I haven't tried it myself, but I know several colleagues who've had great success with it. There is also a tool (perl script) you can use to generate input values for you (you figure out the expected results yourself - it doesn't do that for you). And best of all - it looks really easy to use, both as a technique and a tool. http://www.testingeducation.org/wtst5/PairwisePNSQC2004.pdf http://www.pairwise.org/ http://en.wikipedia.org/wiki/All-pairs_testing http://www.developsense.com/2007/11/pairwise-testing.html http://www.developsense.com/testing/PairwiseTesting.html Aslak > Does anyone have an opinion about whether this is a problem, and > whether there's a clean way of dealing with it? > > Thanks, > > Kerry > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jarkko at jlaine.net Fri Jan 11 13:46:02 2008 From: jarkko at jlaine.net (Jarkko Laine) Date: Fri, 11 Jan 2008 20:46:02 +0200 Subject: [rspec-users] specs on private methods In-Reply-To: <47879132.4080500@benmabey.com> References: <840215067e9a8ce8de426499acb0d2a5@ruby-forum.com> <071A280E-9D43-497B-ABAE-01FD15716D75@tenner.org> <20080111094914.GF10401@durance.shot.pl> <57c63afe0801110223o12ab6746w488584d3576454d8@mail.gmail.com> <47879132.4080500@benmabey.com> Message-ID: On Jan 11, 2008, at 5:54 PM, Ben Mabey wrote: > David Chelimsky wrote: >> >> >> In TDD there is a rule of thumb that says don't stub a method in the >> same class as the method you're testing. The risk is that as the real >> implementation of by_input_sets!() changes over time, it has access >> to >> internal state that could impact the behaviour of decompose!(). >> > > > So, stubbing a current_user method on a rails controller would be > considered bad practice? > I suppose stubbing the find on User would be just as easy but I have > always just stubbed controller.current_user. > In my login_as helper, I just call controller.send(:current_user=, user). No need to stub anything. //jarkko > -Ben > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From pergesu at gmail.com Fri Jan 11 16:16:33 2008 From: pergesu at gmail.com (Pat Maddox) Date: Fri, 11 Jan 2008 13:16:33 -0800 Subject: [rspec-users] Role of stories vs specs, revisited Message-ID: <810a540e0801111316i5abb616dg149ee0dbc6b5f1ee@mail.gmail.com> A couple months ago I asked how stories and specs might impact each other. [1] If you look at Dan North's example of what's in a story [2], and you imagine using the spec framework to drive the design, you can probably imagine a significant bit of overlap in the two. Is that a bad thing? I'm not sure. It has made me a bit uncomfortable though, and I've kept that question in the back of my mind these past few months. (please forgive any mistakes in the code, I just typed it all into this email) The traditional way of writing specs has been to organize them around context, or the fixture used. This leads to specs that look like describe Stack, "empty" do it "should be empty" do Stack.new.should be_empty end it "should blow up when sent pop" do lambda { Stack.new.pop }.should raise_error(StackEmptyError) end end describe Stack, "with one item" do before(:each) do @stack = Stack.new @stack.push :foo end it "should not be empty" do @stack.should_not be_empty end it "should return the item when sent pop" do @stack.pop.should == :foo end end One of the guys at work showed me a different style of writing specs. He organizes them mostly around methods. So his spec would look more like: describe Stack do describe "#empty?" do it "should be true with no items" do Stack.new.should be_empty end it "should be false with one item" do s = Stack.new s.push :foo s.should_not be_empty end end describe "#pop" do it "should blow up with no items" do lambda { Stack.new.pop }.should raise_error(StackEmptyError) end it "return the last item added" do s = Stack.new s.push :foo @stack.pop.should == :foo end end end At first I didn't like it so much. It goes against the way I've used for so long, which is to organize the specs around fixtures. Second, I'm concerned that in using this style, one might focus more on the behavior of a method, rather than the object as a whole. I've slowly been coming around to it though. I think the method-focused approach has some significant benefits for the developer. It serves as excellent documentation. If I want to use #pop, I can just look at the spec and see exactly how it's going to behave. If I make any modifications, I know exactly where it goes. Contrast this with the context approach, where I might have to hunt through a couple example groups to find all the examples that use the method. I think writing specs with more focus on methods ends up being a lot more maintainable in the long run. My issues with that approach were that it doesn't follow tradition, and the nebulous "what if I forget how to BDD well?" The benefits are far more concrete and practical. I can use stories to express stuff at a high level, in terms of the domain, and write these method-focused examples to really help me out as a developer. Which is how the benefits are supposed to be derived in the first place. Interestingly, if you take a look at Dan's example, you'll see that it is based around one method. That sort of throws me for a loop. However at a high level, it's actually based around one feature that the customer wants. The fact that it's all the same #withdraw method under the hood is mostly coincidental. I kind of lost steam towards the end here :) I'd love to know what you guys think. Pat [1] http://rubyforge.org/pipermail/rspec-users/2007-November/004455.html [2] http://dannorth.net/whats-in-a-story From dchelimsky at gmail.com Fri Jan 11 16:25:54 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 11 Jan 2008 15:25:54 -0600 Subject: [rspec-users] Role of stories vs specs, revisited In-Reply-To: <810a540e0801111316i5abb616dg149ee0dbc6b5f1ee@mail.gmail.com> References: <810a540e0801111316i5abb616dg149ee0dbc6b5f1ee@mail.gmail.com> Message-ID: <57c63afe0801111325i32313c63u608e19b617b0107a@mail.gmail.com> On Jan 11, 2008 3:16 PM, Pat Maddox wrote: > A couple months ago I asked how stories and specs might impact each > other. [1] If you look at Dan North's example of what's in a story > [2], and you imagine using the spec framework to drive the design, you > can probably imagine a significant bit of overlap in the two. Is that > a bad thing? I'm not sure. It has made me a bit uncomfortable > though, and I've kept that question in the back of my mind these past > few months. > > (please forgive any mistakes in the code, I just typed it all into this email) > > The traditional way of writing specs has been to organize them around > context, or the fixture used. This leads to specs that look like > > describe Stack, "empty" do > it "should be empty" do > Stack.new.should be_empty > end > > it "should blow up when sent pop" do > lambda { Stack.new.pop }.should raise_error(StackEmptyError) > end > end > > describe Stack, "with one item" do > before(:each) do > @stack = Stack.new > @stack.push :foo > end > > it "should not be empty" do > @stack.should_not be_empty > end > > it "should return the item when sent pop" do > @stack.pop.should == :foo > end > end > > One of the guys at work showed me a different style of writing specs. > He organizes them mostly around methods. So his spec would look more > like: > > describe Stack do > describe "#empty?" do > it "should be true with no items" do > Stack.new.should be_empty > end > > it "should be false with one item" do > s = Stack.new > s.push :foo > s.should_not be_empty > end > end > > describe "#pop" do > it "should blow up with no items" do > lambda { Stack.new.pop }.should raise_error(StackEmptyError) > end > > it "return the last item added" do > s = Stack.new > s.push :foo > @stack.pop.should == :foo > end > end > end > > At first I didn't like it so much. It goes against the way I've used > for so long, which is to organize the specs around fixtures. Second, > I'm concerned that in using this style, one might focus more on the > behavior of a method, rather than the object as a whole. > > I've slowly been coming around to it though. I think the > method-focused approach has some significant benefits for the > developer. It serves as excellent documentation. If I want to use > #pop, I can just look at the spec and see exactly how it's going to > behave. If I make any modifications, I know exactly where it goes. > Contrast this with the context approach, where I might have to hunt > through a couple example groups to find all the examples that use the > method. I think writing specs with more focus on methods ends up > being a lot more maintainable in the long run. > > My issues with that approach were that it doesn't follow tradition, > and the nebulous "what if I forget how to BDD well?" The benefits are > far more concrete and practical. I can use stories to express stuff > at a high level, in terms of the domain, and write these > method-focused examples to really help me out as a developer. Which > is how the benefits are supposed to be derived in the first place. > > Interestingly, if you take a look at Dan's example, you'll see that it > is based around one method. That sort of throws me for a loop. > However at a high level, it's actually based around one feature that > the customer wants. The fact that it's all the same #withdraw method > under the hood is mostly coincidental. > > I kind of lost steam towards the end here :) I'd love to know what > you guys think. Personally, I think whatever works for you is fine as long as a) it's focused on behaviour in the exampes and b) ... well ... it works for you! As for the overlap between stories/specs - you need to understand what Acceptance Test Driven Development and ATDPlanning are all about to appreciate that there will, and *should* be overlap. The two tools serve completely different purposes. At least that's their target. If you use them differently, you won't lose your license :) But the target of stories are system level descriptions of behaviour. This will inevitably appear to have some overlap with the specs for the outermost layers of the system. But when you start refactoring, those object specifications are going to change - the system specs (stories) should NOT. At least not as a result of refactoring. Conversely, once your application has some legs to it, as stories change due to changing requirements, you'll find that some stories change without ever needing to change any of the object specs. That's all for now. FWIW, David > > Pat > > > [1] http://rubyforge.org/pipermail/rspec-users/2007-November/004455.html > [2] http://dannorth.net/whats-in-a-story > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From james.deville at gmail.com Fri Jan 11 16:40:51 2008 From: james.deville at gmail.com (James Deville) Date: Fri, 11 Jan 2008 13:40:51 -0800 Subject: [rspec-users] Missing methods In-Reply-To: <4167A6B3-624E-4665-B6FC-26EC8ED547FF@railsnewbie.com> References: <4167A6B3-624E-4665-B6FC-26EC8ED547FF@railsnewbie.com> Message-ID: <968AA56E-E48B-46EF-A087-D1D00105C27F@gmail.com> On Jan 11, 2008, at 7:31 AM, Scott Taylor wrote: > > 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| >> eval <<-EOF >> def self.create_#{klass}(attributes = {}) >> default_attributes = valid_#{klass}_attributes >> #{klass.camelize}.create! default_attributes.merge(attributes) >> end >> EOF >> end >> >> def valid_message_attributes(options = {}) >> { >> #some message options >> } >> end >> >> #more valid_x_attributes methods >> end >> >> When I require this file in a spec file, Factory.create_person works >> fine. When I try to do it in a step file, Factory.create_person is >> defined, but it fails because valid_person_attributes is missing. If >> I'm in a debugger, and I do require 'model_factory' followed by >> Factory.create_person, same deal. >> >> Do we have a blank slate being loaded somewhere, and why is it wiping >> out require files? > > Actually, though, I think John D. Hume is right (and this is a > current bug with FixtureReplacement, as well): your valid_* methods > are not class methods, but instance methods. > > I bet the reason that it has worked in the past is because rspec does > funny things with Module#include, and without having the time to look > at the source, I'd bet that rspec ends up delegating to the class > level (but story runner doesn't) - giving you the appearance that > your software works, but in fact is just taking advantage of rspec's > implementation. > > Prove me wrong, if you can. > > Best, > > Scott > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users I'll probably just try to prove you right James Deville http://devillecompanies.org james.deville at gmail.com rspec r3172 rspec_on_rails r3172 rails r8331 From pergesu at gmail.com Fri Jan 11 16:43:13 2008 From: pergesu at gmail.com (Pat Maddox) Date: Fri, 11 Jan 2008 13:43:13 -0800 Subject: [rspec-users] Role of stories vs specs, revisited In-Reply-To: <57c63afe0801111325i32313c63u608e19b617b0107a@mail.gmail.com> References: <810a540e0801111316i5abb616dg149ee0dbc6b5f1ee@mail.gmail.com> <57c63afe0801111325i32313c63u608e19b617b0107a@mail.gmail.com> Message-ID: <810a540e0801111343r476733ccgf95baf53fc63d82c@mail.gmail.com> I'm going to hijack this a bit :) On Jan 11, 2008 1:25 PM, David Chelimsky wrote: > > But the target of stories are system level descriptions of behaviour. > This will inevitably appear to have some overlap with the specs for > the outermost layers of the system. But when you start refactoring, > those object specifications are going to change - the system specs > (stories) should NOT. At least not as a result of refactoring. In the first thread I linked to, I said something along the lines of "maybe stories are better for refactoring, since you don't have to change them." Examples, on the other hand, sometimes have to be changed when refactoring, particularly if you use mocks. However, stories are probably too slow for refactoring, and some of the problems with refactoring with examples are simply a matter of lacking tool support, which should eventually be fixed. I don't have any problem with that. I do things that way, and I get my work done just fine. However, I'm having a tough time clarifying my position when talking to people who believe that unit tests should not have to change when refactoring either. I don't think they're wrong, actually. It's just a different approach and I'd like to know how to bridge that communication gap better. Pat From dchelimsky at gmail.com Fri Jan 11 16:48:20 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 11 Jan 2008 15:48:20 -0600 Subject: [rspec-users] Role of stories vs specs, revisited In-Reply-To: <810a540e0801111343r476733ccgf95baf53fc63d82c@mail.gmail.com> References: <810a540e0801111316i5abb616dg149ee0dbc6b5f1ee@mail.gmail.com> <57c63afe0801111325i32313c63u608e19b617b0107a@mail.gmail.com> <810a540e0801111343r476733ccgf95baf53fc63d82c@mail.gmail.com> Message-ID: <57c63afe0801111348k4ff3f90bq592dfab42353531b@mail.gmail.com> On Jan 11, 2008 3:43 PM, Pat Maddox wrote: > I'm going to hijack this a bit :) > > On Jan 11, 2008 1:25 PM, David Chelimsky wrote: > > > > But the target of stories are system level descriptions of behaviour. > > This will inevitably appear to have some overlap with the specs for > > the outermost layers of the system. But when you start refactoring, > > those object specifications are going to change - the system specs > > (stories) should NOT. At least not as a result of refactoring. > > In the first thread I linked to, I said something along the lines of > "maybe stories are better for refactoring, since you don't have to > change them." Keep in mind that in Java, where I think refactoring really grew in its formality as part of the process, the tools make the changes in your tests too. When you change a method signature the tool changes it everywhere. I don't recall, ever, seeing anyone complaining about having to change tests when refactoring in java. So this is a price we pay for the benefits of early adoption in our language of choice. > Examples, on the other hand, sometimes have to be > changed when refactoring, particularly if you use mocks. > > However, stories are probably too slow for refactoring, and some of > the problems with refactoring with examples are simply a matter of > lacking tool support, which should eventually be fixed. Right - missed this on the first read - that's what I'm talking about in the paragraph above. > > I don't have any problem with that. I do things that way, and I get > my work done just fine. However, I'm having a tough time clarifying > my position when talking to people who believe that unit tests should > not have to change when refactoring either. I don't think they're > wrong, actually. I do. If you read the refactoring book, every refactoring has a "now change all the clients" step - tests are clients that have to be changed. It's just part of the deal. The thing is that, ideally, you don't want to have to make changes to the tests for object A when you're refactoring B. WDYT? > It's just a different approach and I'd like to know > how to bridge that communication gap better. > > Pat > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From pergesu at gmail.com Fri Jan 11 17:09:30 2008 From: pergesu at gmail.com (Pat Maddox) Date: Fri, 11 Jan 2008 14:09:30 -0800 Subject: [rspec-users] Role of stories vs specs, revisited In-Reply-To: <57c63afe0801111348k4ff3f90bq592dfab42353531b@mail.gmail.com> References: <810a540e0801111316i5abb616dg149ee0dbc6b5f1ee@mail.gmail.com> <57c63afe0801111325i32313c63u608e19b617b0107a@mail.gmail.com> <810a540e0801111343r476733ccgf95baf53fc63d82c@mail.gmail.com> <57c63afe0801111348k4ff3f90bq592dfab42353531b@mail.gmail.com> Message-ID: <810a540e0801111409t1fc126fdj593ee102214eb457@mail.gmail.com> On Jan 11, 2008 1:48 PM, David Chelimsky wrote: > On Jan 11, 2008 3:43 PM, Pat Maddox wrote: > > I don't have any problem with that. I do things that way, and I get > > my work done just fine. However, I'm having a tough time clarifying > > my position when talking to people who believe that unit tests should > > not have to change when refactoring either. I don't think they're > > wrong, actually. > > I do. If you read the refactoring book, every refactoring has a "now > change all the clients" step - tests are clients that have to be > changed. It's just part of the deal. That makes sense. I've never really thought of it that way. > The thing is that, ideally, you don't want to have to make changes to > the tests for object A when you're refactoring B. > > WDYT? Yeah, I buy that. Not everyone does though. Or at least not everyone feels that it's a particularly important goal. Pat From jaydonnell at yahoo.com Fri Jan 11 20:11:18 2008 From: jaydonnell at yahoo.com (Jay Donnell) Date: Fri, 11 Jan 2008 17:11:18 -0800 (PST) Subject: [rspec-users] Role of stories vs specs, revisited Message-ID: <189088.94530.qm@web56012.mail.re3.yahoo.com> >> The thing is that, ideally, you don't want to have to make changes to >> the tests for object A when you're refactoring B. >> >> WDYT? > Yeah, I buy that. Not everyone does though. Or at least not everyone > feels that it's a particularly important goal. I think the fear many of us classicists have is that if A uses B (and Bs interface changes) then A will pass but it shouldn't. We also have to go around updating all the mocks for tests that use B. With a state based approach we wouldn't have to change any tests assuming we've fixed the outer methods already. If we haven't then our tests will fail and tell us we need to. I know, our integration tests should catch this. I'm curious what you guys mean by "integration tests" in this case. For example, in a rails app are the 'integration tests' always or usually testing the full rails stack by sending web requests and verifying against the response? I.e. simulating a user interaction? ____________________________________________________________________________________ Never miss a thing. Make Yahoo your home page. http://www.yahoo.com/r/hs From pergesu at gmail.com Fri Jan 11 22:34:06 2008 From: pergesu at gmail.com (Pat Maddox) Date: Fri, 11 Jan 2008 19:34:06 -0800 Subject: [rspec-users] Role of stories vs specs, revisited In-Reply-To: <189088.94530.qm@web56012.mail.re3.yahoo.com> References: <189088.94530.qm@web56012.mail.re3.yahoo.com> Message-ID: <810a540e0801111934y5c7b325bn9621c6af03c7f312@mail.gmail.com> On Jan 11, 2008 5:11 PM, Jay Donnell wrote: > >> The thing is that, ideally, you don't want to have to make changes to > >> the tests for object A when you're refactoring B. > >> > >> WDYT? > > > Yeah, I buy that. Not everyone does though. Or at least not everyone > > feels that it's a particularly important goal. > > I think the fear many of us classicists have is that if A uses B (and Bs interface changes) then A will pass but it shouldn't. We also have to go around updating all the mocks for tests that use B. With a state based approach we wouldn't have to change any tests assuming we've fixed the outer methods already. If we haven't then our tests will fail and tell us we need to. As David has mentioned before, that's a matter of tool support. Consider how this works if you're using Java. You might have some interface that looks like: public interface Account { void deposit(int amount); void withdraw(int amount); } You've got a BankAccount class that implements it, and in tests that depend on the Account role, you use mock objects. If you were to rename deposit to credit, and withdraw to debit, the first thing that would happen is that the compiler would complain that BankAccount doesn't implement the Account interface anymore. So you can lean on the compiler to fix it. Even better, you would use a refactoring tool, and that'd look for any classes that implement Account and change their method names. Conceptually, the same exact thing is possible and desirable in Ruby. There are some extra hoops to jump through because we can't lean on the compiler like we can in Java. Otoh, we write Ruby a lot faster than Java, and we don't want to stab ourselves. So at this point it's still a worthwhile tradeoff (to me). One problem is that in a language with interfaces, roles are made explicit. In Ruby, any object can play any role, as long as it implements the necessary protocol. Maybe we could do something at the framework level to make the roles more explicit. Something like describe AccountService, " transferring between two accounts" do before(:each) do @source = mock_role(:account) @target = mock_role(:account) @service = AccountService.new end it "should debit the source account" do @source.should_receive(:debit).with(50) @service.transfer 50, @source, @target end it "should credit the target account" do @target.should_receive(:credit).with(50) @service.transfer 50, @source, @target end end Then you have a spec somewhere that verifies that the Account class fulfills the account role. It's an interesting idea, and I remember it being bounced around a while back, as something like "mock integration mode." There are plenty of obstacles though...you can't just use respond_to? on an instance of a class, because objects could use method_missing, be decorated with behavior at runtime, etc. It also doesn't seem practical to try to define instances manually and then swap them in to tests. You probably have to create so many objects for different edge cases that it makes more sense just to use state-based verification in the first place. This latter set of issues is just conjecture though, as I've never given it a shot myself. At this point, we can just use integration tests to catch the things we miss, and be thankful that even large Rails projects seldom pass 25k lines of code :) If demand increases for solutions to the mock maintainability problem, one will arise. > I know, our integration tests should catch this. I'm curious what you guys mean by "integration tests" in this case. For example, in a rails app are the 'integration tests' always or usually testing the full rails stack by sending web requests and verifying against the response? I.e. simulating a user interaction? In Rails apps, yes, a lot of the stories would go through the full Rails stack. They don't have to though. User stories represent some facet of behavior which, once completed, provides value to the customer. In short, working software. By definition, then, stories must use real production implementations of objects instead of mocks. This means they work quite nicely as integration tests as well. Pat From jaydonnell at yahoo.com Sat Jan 12 00:28:14 2008 From: jaydonnell at yahoo.com (Jay Donnell) Date: Fri, 11 Jan 2008 21:28:14 -0800 (PST) Subject: [rspec-users] Role of stories vs specs, revisited Message-ID: <345130.46646.qm@web56006.mail.re3.yahoo.com> > If you were to rename deposit to credit, and withdraw to debit I'm more concerned with adding a parameter or changing the default value of a parameter. My fear is that given enough time and size there will be a fair number of inconsistent mocks or mocks that aren't doing any real testing. It feels a bit like forced exception handling in java. > User stories represent some facet of behavior which, once completed, > provides value to the customer. In short, working software. By > definition, then, stories must use real production implementations of > objects instead of mocks. This means they work quite nicely as > integration tests as well. Does anyone know of any open source ruby apps (preferably rails) that use good BDD so I can see how it's done right rather than ask a bunch of questions? ____________________________________________________________________________________ Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ From ben at benmabey.com Sat Jan 12 15:33:57 2008 From: ben at benmabey.com (Ben Mabey) Date: Sat, 12 Jan 2008 13:33:57 -0700 Subject: [rspec-users] Role of stories vs specs, revisited In-Reply-To: <345130.46646.qm@web56006.mail.re3.yahoo.com> References: <345130.46646.qm@web56006.mail.re3.yahoo.com> Message-ID: <47892435.5050105@benmabey.com> Jay Donnell wrote: > > Does anyone know of any open source ruby apps (preferably rails) that use good BDD so I can see how it's done right rather than ask a bunch of questions? > > > > Hmm.. I don't know of any rails apps that are open source that you could look at.. But I know datamapper (http://www.datamapper.org/) is using rspec. Also, be sure to look at rspec's code if you haven't already. I have learned a great deal by looking over its use of itself. :) -Ben From mailing_lists at railsnewbie.com Sat Jan 12 17:47:52 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sat, 12 Jan 2008 17:47:52 -0500 Subject: [rspec-users] Role of stories vs specs, revisited In-Reply-To: <47892435.5050105@benmabey.com> References: <345130.46646.qm@web56006.mail.re3.yahoo.com> <47892435.5050105@benmabey.com> Message-ID: On Jan 12, 2008, at 3:33 PM, Ben Mabey wrote: > Jay Donnell wrote: >> >> Does anyone know of any open source ruby apps (preferably rails) >> that use good BDD so I can see how it's done right rather than ask >> a bunch of questions? >> >> >> >> > > Hmm.. I don't know of any rails apps that are open source that you > could > look at.. But I know datamapper (http://www.datamapper.org/) is using > rspec. Also, be sure to look at rspec's code if you haven't > already. I > have learned a great deal by looking over its use of itself. :) Yep. Merb, too, as well as Rubinius, which uses "mspec" - a scaled down version of rspec. Plus - the specs should be pretty easy to understand, being that they are of ruby itself. I know Rick Olson has started using rspec - you might want to look at his plugins. I also have a few projects out there using rspec: DatedBackup, and FixtureReplacement, both on rubyforge. Hope that helps, Scott From pergesu at gmail.com Sat Jan 12 19:32:49 2008 From: pergesu at gmail.com (Pat Maddox) Date: Sat, 12 Jan 2008 16:32:49 -0800 Subject: [rspec-users] Role of stories vs specs, revisited In-Reply-To: <345130.46646.qm@web56006.mail.re3.yahoo.com> References: <345130.46646.qm@web56006.mail.re3.yahoo.com> Message-ID: <810a540e0801121632k339762f0g528c3634e54fc25a@mail.gmail.com> http://synthesis.rubyforge.org/ *just* showed up in my feedreader (well, the links at the bottom did) On Jan 11, 2008 9:28 PM, Jay Donnell wrote: > > > If you were to rename deposit to credit, and withdraw to debit > > I'm more concerned with adding a parameter or changing the default value of a parameter. My fear is that given enough time and size there will be a fair number of inconsistent mocks or mocks that aren't doing any real testing. It feels a bit like forced exception handling in java. Yeah. I played with Synthesis a bit, and it doesn't handle this case. It's very early on though. I'm not sure that you'll end up with a number of inconsistent mocks...because if you have integration tests covering everything, then you'll know pretty quickly when your tests aren't up to par. But it's not like you'd have a bunch of passing tests and broken production code, and deploy that out. Using mocks without acceptance tests is like using Ruby without any tests. It's just stupid. > Does anyone know of any open source ruby apps (preferably rails) that use good BDD so I can see how it's done right rather than ask a bunch of questions? Not really. Rick Olsen has a Rails example app that uses specs. There are a bunch of published plugins that use specs. I'm working on a bliki thing in my spare time (which means never) which will be open source. Pat From jaydonnell at yahoo.com Sat Jan 12 21:35:46 2008 From: jaydonnell at yahoo.com (Jay Donnell) Date: Sat, 12 Jan 2008 18:35:46 -0800 (PST) Subject: [rspec-users] Role of stories vs specs, revisited Message-ID: <83111.40078.qm@web56015.mail.re3.yahoo.com> >because if you have integration tests covering everything, >then you'll know pretty quickly when your tests aren't up to par. If we have integration tests that cover everything then why have another set of tests? At that point wouldn't it simply be duplication and wouldn't it create more work for refactorings and such? ____________________________________________________________________________________ Looking for last minute shopping deals? Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping From dchelimsky at gmail.com Sun Jan 13 07:54:52 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 13 Jan 2008 06:54:52 -0600 Subject: [rspec-users] Role of stories vs specs, revisited In-Reply-To: <83111.40078.qm@web56015.mail.re3.yahoo.com> References: <83111.40078.qm@web56015.mail.re3.yahoo.com> Message-ID: <57c63afe0801130454o53b9fd4aw7de9923c21cefc85@mail.gmail.com> On Jan 12, 2008 8:35 PM, Jay Donnell wrote: > >because if you have integration tests covering everything, > >then you'll know pretty quickly when your tests aren't up to par. > > If we have integration tests that cover everything then why have another set of tests? At that point wouldn't it simply be duplication and wouldn't it create more work for refactorings and such? Jay - are you familiar with Acceptance Test Driven Development/Planning and/or Test Driven Development? Cheers, David From ivo.dancet at gmail.com Sun Jan 13 07:56:09 2008 From: ivo.dancet at gmail.com (Ivo Dancet) Date: Sun, 13 Jan 2008 13:56:09 +0100 Subject: [rspec-users] should_receive twice and arguments Message-ID: <6C4D73DB-E44A-4998-9859-787F720A1A13@gmail.com> Hi all, I have a method calling Klass.create! two times with different arguments (this happens in a class reponsable for reading in a csv file) I want to test those like this: in one test: Klass.should_receive(:create!).with(:name => "foo").once in another: Klass.should_receive(:create!).with(:name => "foo2").once This doesn't work because the 'once' is only about the create! call, it doesn't use the arguments to make the call unique. Can I make this work another way (not only should_receive(:create!).twice, I want to test the arguments). Thanks for any feedback. Ivo From dchelimsky at gmail.com Sun Jan 13 08:00:16 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 13 Jan 2008 07:00:16 -0600 Subject: [rspec-users] should_receive twice and arguments In-Reply-To: <6C4D73DB-E44A-4998-9859-787F720A1A13@gmail.com> References: <6C4D73DB-E44A-4998-9859-787F720A1A13@gmail.com> Message-ID: <57c63afe0801130500k3399a325md2c36815dbea9ac5@mail.gmail.com> On Jan 13, 2008 6:56 AM, Ivo Dancet wrote: > Hi all, I have a method calling Klass.create! two times with different > arguments (this happens in a class reponsable for reading in a csv file) > > I want to test those like this: > > in one test: Klass.should_receive(:create!).with(:name => "foo").once > in another: Klass.should_receive(:create!).with(:name => "foo2").once > > This doesn't work because the 'once' is only about the create! call, Actually, that should work. 'once' is about the complete expectation including the arguments. If this isn't working you've uncovered a bug. Please report it to the lighthouse (http://rspec.lighthouseapp.com) with specific examples we can run and the output you're getting. Thanks, David > it doesn't use the arguments to make the call unique. Can I make this > work another way (not only should_receive(:create!).twice, I want to > test the arguments). > > Thanks for any feedback. > > Ivo > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ivo.dancet at gmail.com Sun Jan 13 09:05:32 2008 From: ivo.dancet at gmail.com (Ivo Dancet) Date: Sun, 13 Jan 2008 15:05:32 +0100 Subject: [rspec-users] should_receive twice and arguments In-Reply-To: <57c63afe0801130500k3399a325md2c36815dbea9ac5@mail.gmail.com> References: <6C4D73DB-E44A-4998-9859-787F720A1A13@gmail.com> <57c63afe0801130500k3399a325md2c36815dbea9ac5@mail.gmail.com> Message-ID: <00A9B372-CC8B-4DCF-8001-4DF14C2C7EC9@gmail.com> Ok, found the problem after trying to make an example: I forgot to add a stub! to accept the second call to create! I didn't find it sooner because the error was: Mock 'Class' expected :create! with ({:name=>"foo"}) but received it with ({:name=>"foo2"}) And it did get it with ({:name => "foo"}), but only the first time... Thanks! Ivo Op 13-jan-08, om 14:00 heeft David Chelimsky het volgende geschreven: > On Jan 13, 2008 6:56 AM, Ivo Dancet wrote: >> Hi all, I have a method calling Klass.create! two times with >> different >> arguments (this happens in a class reponsable for reading in a csv >> file) >> >> I want to test those like this: >> >> in one test: Klass.should_receive(:create!).with(:name => "foo").once >> in another: Klass.should_receive(:create!).with(:name => "foo2").once >> >> This doesn't work because the 'once' is only about the create! call, > > Actually, that should work. 'once' is about the complete expectation > including the arguments. If this isn't working you've uncovered a bug. > Please report it to the lighthouse (http://rspec.lighthouseapp.com) > with specific examples we can run and the output you're getting. > > Thanks, > David > >> it doesn't use the arguments to make the call unique. Can I make this >> work another way (not only should_receive(:create!).twice, I want to >> test the arguments). >> >> Thanks for any feedback. >> >> Ivo >> >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From jaydonnell at yahoo.com Sun Jan 13 12:00:02 2008 From: jaydonnell at yahoo.com (Jay Donnell) Date: Sun, 13 Jan 2008 09:00:02 -0800 (PST) Subject: [rspec-users] Role of stories vs specs, revisited Message-ID: <635349.30956.qm@web56011.mail.re3.yahoo.com> > Jay - are you familiar with Acceptance Test Driven > Development/Planning and/or Test Driven Development? I am with TDD and Acceptance testing (not sure if this is the same as Acceptance Test Driven Development) . I use a more classic approach to use Martin Fowler's terminology which is why I asked earlier if there are any open source rails apps that use rspec the way it's intended so I can explore it that way rather than asking a million questions. ____________________________________________________________________________________ Never miss a thing. Make Yahoo your home page. http://www.yahoo.com/r/hs From lists at ruby-forum.com Sun Jan 13 12:14:21 2008 From: lists at ruby-forum.com (Kevin Olbrich) Date: Sun, 13 Jan 2008 18:14:21 +0100 Subject: [rspec-users] View spec'ing style Message-ID: I've been getting my head around view spec'ing lately for a fairly complex project that makes heavy use of partials in views and I have hit up against a style puzzle. I see two strategies for spec'ing views: First: Develop detailed specs for each partial and then make sure that the final view expects that the appropriate partials are included and used. Pros: * it's DRY * you get a single point of failure if an expectation is not met Cons: * the final specs for a view aren't very explicit and it can be challenging to figure out all the things a view does without tracing back the partials. Second: Develop a set of specs for each view that explicitly expect the important UI elements and treat the rest of the view as a black box (i.e., you don't care if a particular partial was rendered so long as the relevant UI elements are there). Pros: * It's explicit and easy to tell what each view does. Cons: * It's not DRY.. you will get multiple points of failure if a partial is changed. * More time consuming and it's easy to miss an expectation in a view. So... What are people doing? The first? The second? or some combination of the two? -- Posted via http://www.ruby-forum.com/. From coreyhaines at gmail.com Sun Jan 13 12:31:32 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Sun, 13 Jan 2008 12:31:32 -0500 Subject: [rspec-users] View spec'ing style In-Reply-To: References: Message-ID: <6bdacb70801130931j162d78ebsbf6afb9d9b304f91@mail.gmail.com> I don't have a lot of experience yet with the view spec'ing, but I do have the first way I will start: Spec a view from the outermost level and Treat extracted partials as a hybrid of "Extract Method" and "Extract Class" This means that I would spec out the top-most view, extract a partial to remove duplication or enhance readability. If I find that two views start using the same partial, then I would extract the view tests that deal with the partial and use those as tests for the partial. -Corey On Jan 13, 2008 12:14 PM, Kevin Olbrich wrote: > I've been getting my head around view spec'ing lately for a fairly > complex project that makes heavy use of partials in views and I have hit > up against a style puzzle. > > I see two strategies for spec'ing views: > > First: > Develop detailed specs for each partial and then make sure that the > final view expects that the appropriate partials are included and used. > > Pros: > * it's DRY > * you get a single point of failure if an expectation is not met > > Cons: > * the final specs for a view aren't very explicit and it can be > challenging > to figure out all the things a view does without tracing back the > partials. > > Second: > Develop a set of specs for each view that explicitly expect the > important UI elements and treat the rest of the view as a black box > (i.e., you don't care if a particular partial was rendered so long as > the relevant UI elements are there). > > Pros: > * It's explicit and easy to tell what each view does. > > Cons: > * It's not DRY.. you will get multiple points of failure if a partial > is changed. > * More time consuming and it's easy to miss an expectation in a view. > > > So... What are people doing? The first? The second? or some > combination of the two? > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080113/5be72eb4/attachment.html From mailing_lists at bengreenberg.net Sun Jan 13 12:31:16 2008 From: mailing_lists at bengreenberg.net (Ben Greenberg) Date: Sun, 13 Jan 2008 12:31:16 -0500 Subject: [rspec-users] How to trace running spec Message-ID: <478A4AE4.1080107@bengreenberg.net> Hey all, I have a spec that is hanging when it is running. How do I get the rspec runner to show what specs it's running so I can which one is hanging? I am calling the runner from my rails project. Thanks, Ben From lists at ruby-forum.com Sun Jan 13 13:11:31 2008 From: lists at ruby-forum.com (Mike Vogel) Date: Sun, 13 Jan 2008 19:11:31 +0100 Subject: [rspec-users] autotest displays no output In-Reply-To: <4728AEE0.6010304@att.net> References: <13510545.post@talk.nabble.com> <4728AEE0.6010304@att.net> Message-ID: There is also a problem with spaces in the file path to ruby or the spec files when running on windows. A quick dumb fix: - change the return result of the ruby method of autotest.rb def ruby ruby = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']) # unless File::ALT_SEPARATOR.nil? then # ruby.gsub! File::SEPARATOR, File::ALT_SEPARATOR # end #hack to del with space in windows path, e.g., 'c:\program files\ruby' doesn't # work unless it is enclosed in quotes. return '"'+ruby+'"' end - change the make_test_cmd method in class Autotest::Rspec (for me this is in ...\gems\rspec-1.1.1\lib\autotest) to put quotes around the @spec_command before using it. I'm sure there are real ways to fix this. I'll do some more digging to see if I can post something less ugly. Can someone educate me about the general approach to spaces in file paths when using ruby? -- Posted via http://www.ruby-forum.com/. From ben at benmabey.com Sun Jan 13 16:28:50 2008 From: ben at benmabey.com (Ben Mabey) Date: Sun, 13 Jan 2008 14:28:50 -0700 Subject: [rspec-users] How to trace running spec In-Reply-To: <478A4AE4.1080107@bengreenberg.net> References: <478A4AE4.1080107@bengreenberg.net> Message-ID: <478A8292.3010909@benmabey.com> Ben Greenberg wrote: > Hey all, > > I have a spec that is hanging when it is running. > > How do I get the rspec runner to show what specs it's running so I can > which one is hanging? I am calling the runner from my rails project. > > Thanks, > Ben > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > Which formatter ate you using? If you use the specdoc formatter it will output the specs as it goes so you can tell where it is hanging. Also, there is a profiling one that will list the slowest specs. Run "spec -h" for more info. -Ben From coreyhaines at gmail.com Sun Jan 13 16:51:38 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Sun, 13 Jan 2008 16:51:38 -0500 Subject: [rspec-users] .html.erb files and autotest Message-ID: <6bdacb70801131351y7b2188beo1ba8e3fe3a090ce9@mail.gmail.com> When I work with a .html.erb file, the autotest rspec on rails stuff doesn't understand the file to map it to the right test. I wanted to submit a patch for this, but I'm unsure where the specs would be to update. I found the necessary mapping in rspec_autotest.rb, but I can't find any specs anywhere. Help? I just need to have /app/views/coupon/index.html.erb to map to /spec/views/coupon/index_spec.rb -Corey -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080113/686bf58f/attachment.html From dchelimsky at gmail.com Sun Jan 13 16:54:32 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 13 Jan 2008 15:54:32 -0600 Subject: [rspec-users] .html.erb files and autotest In-Reply-To: <6bdacb70801131351y7b2188beo1ba8e3fe3a090ce9@mail.gmail.com> References: <6bdacb70801131351y7b2188beo1ba8e3fe3a090ce9@mail.gmail.com> Message-ID: <57c63afe0801131354u3163b0e6v55d66885db203a1b@mail.gmail.com> On Jan 13, 2008 3:51 PM, Corey Haines wrote: > When I work with a .html.erb file, the autotest rspec on rails stuff doesn't > understand the file to map it to the right test. I wanted to submit a patch > for this, but I'm unsure where the specs would be to update. I found the > necessary mapping in rspec_autotest.rb, but I can't find any specs anywhere. > Help? > > I just need to have > /app/views/coupon/index.html.erb to map to /spec/views/coupon/index_spec.rb The right spec is index.html.erb_spec.rb - that's what the mapping is. If you want to change the mapping locally, you can if you're using rspec's trunk and a patched version of ZenTest (see http://rubyforge.org/pipermail/rspec-users/2008-January/005321.html). Cheers, David > > -Corey > > -- > http://www.coreyhaines.com > The Internet's Premiere source of information about Corey Haines > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From coreyhaines at gmail.com Sun Jan 13 17:29:19 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Sun, 13 Jan 2008 17:29:19 -0500 Subject: [rspec-users] .html.erb files and autotest In-Reply-To: <57c63afe0801131354u3163b0e6v55d66885db203a1b@mail.gmail.com> References: <6bdacb70801131351y7b2188beo1ba8e3fe3a090ce9@mail.gmail.com> <57c63afe0801131354u3163b0e6v55d66885db203a1b@mail.gmail.com> Message-ID: <6bdacb70801131429nd2a5836s282d30c6a39e8940@mail.gmail.com> Okay, thanks. On Jan 13, 2008 4:54 PM, David Chelimsky wrote: > On Jan 13, 2008 3:51 PM, Corey Haines wrote: > > When I work with a .html.erb file, the autotest rspec on rails stuff > doesn't > > understand the file to map it to the right test. I wanted to submit a > patch > > for this, but I'm unsure where the specs would be to update. I found the > > necessary mapping in rspec_autotest.rb, but I can't find any specs > anywhere. > > Help? > > > > I just need to have > > /app/views/coupon/index.html.erb to map to > /spec/views/coupon/index_spec.rb > > The right spec is index.html.erb_spec.rb - that's what the mapping is. > If you want to change the mapping locally, you can if you're using > rspec's trunk and a patched version of ZenTest (see > http://rubyforge.org/pipermail/rspec-users/2008-January/005321.html). > > Cheers, > David > > > > > -Corey > > > > -- > > http://www.coreyhaines.com > > The Internet's Premiere source of information about Corey Haines > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080113/13cd0f98/attachment-0001.html From mattwindwer at gmail.com Sun Jan 13 18:47:33 2008 From: mattwindwer at gmail.com (Matthew Windwer) Date: Sun, 13 Jan 2008 15:47:33 -0800 Subject: [rspec-users] TextMate bundle not compatible with nested specs for running focused tests? Message-ID: <2e82acb90801131547u5f1a714fk551b1f7aeca9e62f@mail.gmail.com> Seems like the recently updated (and wonderful) textmate bundle does not take into account running individual tests that are in nested specs. Anybody else notice this? Any ideas? Matt -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080113/15d5cc2f/attachment.html From aslak.hellesoy at gmail.com Sun Jan 13 18:49:40 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Mon, 14 Jan 2008 00:49:40 +0100 Subject: [rspec-users] TextMate bundle not compatible with nested specs for running focused tests? In-Reply-To: <2e82acb90801131547u5f1a714fk551b1f7aeca9e62f@mail.gmail.com> References: <2e82acb90801131547u5f1a714fk551b1f7aeca9e62f@mail.gmail.com> Message-ID: <8d961d900801131549x29554f53s8d979ccd51d0d5ed@mail.gmail.com> On Jan 14, 2008 12:47 AM, Matthew Windwer wrote: > Seems like the recently updated (and wonderful) textmate bundle does not > take into account running individual tests that are in nested specs. > > Anybody else notice this? Any ideas? > I have noticed it too. Please file a bug report. Aslak > Matt > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Sun Jan 13 18:49:59 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 13 Jan 2008 17:49:59 -0600 Subject: [rspec-users] TextMate bundle not compatible with nested specs for running focused tests? In-Reply-To: <2e82acb90801131547u5f1a714fk551b1f7aeca9e62f@mail.gmail.com> References: <2e82acb90801131547u5f1a714fk551b1f7aeca9e62f@mail.gmail.com> Message-ID: <57c63afe0801131549k1c583d44kf1ab62f94aa631c@mail.gmail.com> On Jan 13, 2008 5:47 PM, Matthew Windwer wrote: > Seems like the recently updated (and wonderful) textmate bundle does not > take into account running individual tests that are in nested specs. > > Anybody else notice this? Any ideas? There's an open ticket on this at the lighthouse: http://rspec.lighthouseapp.com/projects/5645/tickets/225 > > Matt > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From rspec-users at kero.tmfweb.nl Sun Jan 13 21:47:01 2008 From: rspec-users at kero.tmfweb.nl (Kero van Gelder) Date: Mon, 14 Jan 2008 03:47:01 +0100 Subject: [rspec-users] How to trace running spec In-Reply-To: <478A8292.3010909@benmabey.com> References: <478A4AE4.1080107@bengreenberg.net> <478A8292.3010909@benmabey.com> Message-ID: <20080114024700.GB6930@chello.nl> > > I have a spec that is hanging when it is running. > > > > How do I get the rspec runner to show what specs it's running so I can > > which one is hanging? I am calling the runner from my rails project. > > Which formatter ate you using? If you use the specdoc formatter it will > output the specs as it goes so you can tell where it is hanging. Also, > there is a profiling one that will list the slowest specs. Run "spec > -h" for more info. Though a formatter is no listener (or is it?), it seems to act like one. Steps do not tell their listeners when they are started, only when they are finished. Assuming a known order, you can figure out which step hangs, but it is not the one listed last (it's the one after that...) Another reason to have s step_started method in listeners, is to format (tell the customer) about a step *before* the step is executed, such that the customer knows what will happen, instead of heard what has just happened. Time to write a ticket on lighthouse? Bye, Kero. From coreyhaines at gmail.com Sun Jan 13 22:10:13 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Sun, 13 Jan 2008 22:10:13 -0500 Subject: [rspec-users] .html.erb files and autotest In-Reply-To: <6bdacb70801131429nd2a5836s282d30c6a39e8940@mail.gmail.com> References: <6bdacb70801131351y7b2188beo1ba8e3fe3a090ce9@mail.gmail.com> <57c63afe0801131354u3163b0e6v55d66885db203a1b@mail.gmail.com> <6bdacb70801131429nd2a5836s282d30c6a39e8940@mail.gmail.com> Message-ID: <6bdacb70801131910t3a533acfm4c26ac28c80288df@mail.gmail.com> I get this Dunno! app/views/coupon/index.html.erb On Jan 13, 2008 5:29 PM, Corey Haines wrote: > Okay, thanks. > > > On Jan 13, 2008 4:54 PM, David Chelimsky wrote: > > > On Jan 13, 2008 3:51 PM, Corey Haines wrote: > > > When I work with a .html.erb file, the autotest rspec on rails stuff > > doesn't > > > understand the file to map it to the right test. I wanted to submit a > > patch > > > for this, but I'm unsure where the specs would be to update. I found > > the > > > necessary mapping in rspec_autotest.rb, but I can't find any specs > > anywhere. > > > Help? > > > > > > I just need to have > > > /app/views/coupon/index.html.erb to map to > > /spec/views/coupon/index_spec.rb > > > > The right spec is index.html.erb_spec.rb - that's what the mapping is. > > If you want to change the mapping locally, you can if you're using > > rspec's trunk and a patched version of ZenTest (see > > http://rubyforge.org/pipermail/rspec-users/2008-January/005321.html). > > > > Cheers, > > David > > > > > > > > -Corey > > > > > > -- > > > http://www.coreyhaines.com > > > The Internet's Premiere source of information about Corey Haines > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > -- > > http://www.coreyhaines.com > The Internet's Premiere source of information about Corey Haines > -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080113/16fdb194/attachment.html From nathan.sutton at gmail.com Sun Jan 13 22:11:31 2008 From: nathan.sutton at gmail.com (Nathan Sutton) Date: Sun, 13 Jan 2008 21:11:31 -0600 Subject: [rspec-users] .html.erb files and autotest In-Reply-To: <6bdacb70801131910t3a533acfm4c26ac28c80288df@mail.gmail.com> References: <6bdacb70801131351y7b2188beo1ba8e3fe3a090ce9@mail.gmail.com> <57c63afe0801131354u3163b0e6v55d66885db203a1b@mail.gmail.com> <6bdacb70801131429nd2a5836s282d30c6a39e8940@mail.gmail.com> <6bdacb70801131910t3a533acfm4c26ac28c80288df@mail.gmail.com> Message-ID: Set $VERBOSE=false in your .autotest file in your home directory. Nathan Sutton fowlduck at gmail.com rspec 1.1 rspec_on_rails 1.1 rails 2.0.2 On Jan 13, 2008, at 9:10 PM, Corey Haines wrote: > I get this > > Dunno! app/views/coupon/index.html.erb > > > > On Jan 13, 2008 5:29 PM, Corey Haines wrote: > Okay, thanks. > > > On Jan 13, 2008 4:54 PM, David Chelimsky wrote: > On Jan 13, 2008 3:51 PM, Corey Haines wrote: > > When I work with a .html.erb file, the autotest rspec on rails > stuff doesn't > > understand the file to map it to the right test. I wanted to > submit a patch > > for this, but I'm unsure where the specs would be to update. I > found the > > necessary mapping in rspec_autotest.rb, but I can't find any specs > anywhere. > > Help? > > > > I just need to have > > /app/views/coupon/index.html.erb to map to /spec/views/coupon/ > index_spec.rb > > The right spec is index.html.erb_spec.rb - that's what the mapping is. > If you want to change the mapping locally, you can if you're using > rspec's trunk and a patched version of ZenTest (see > http://rubyforge.org/pipermail/rspec-users/2008-January/005321.html). > > Cheers, > David > > > > > -Corey > > > > -- > > http://www.coreyhaines.com > > The Internet's Premiere source of information about Corey Haines > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > > > -- > > http://www.coreyhaines.com > The Internet's Premiere source of information about Corey Haines > > > > -- > http://www.coreyhaines.com > The Internet's Premiere source of information about Corey Haines > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080113/b34ba96a/attachment-0001.html From coreyhaines at gmail.com Sun Jan 13 22:14:49 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Sun, 13 Jan 2008 22:14:49 -0500 Subject: [rspec-users] .html.erb files and autotest In-Reply-To: References: <6bdacb70801131351y7b2188beo1ba8e3fe3a090ce9@mail.gmail.com> <57c63afe0801131354u3163b0e6v55d66885db203a1b@mail.gmail.com> <6bdacb70801131429nd2a5836s282d30c6a39e8940@mail.gmail.com> <6bdacb70801131910t3a533acfm4c26ac28c80288df@mail.gmail.com> Message-ID: <6bdacb70801131914v449a247dwa4b9e483cd88cc3e@mail.gmail.com> Awesome! That worked perfectly, Nathan! Thanks. -Corey On Jan 13, 2008 10:11 PM, Nathan Sutton wrote: > Set $VERBOSE=false in your .autotest file in your home directory. > Nathan Sutton > fowlduck at gmail.com > rspec 1.1 > rspec_on_rails 1.1 > rails 2.0.2 > > On Jan 13, 2008, at 9:10 PM, Corey Haines wrote: > > I get this > > Dunno! app/views/coupon/index.html.erb > > > > On Jan 13, 2008 5:29 PM, Corey Haines wrote: > > > Okay, thanks. > > > > > > On Jan 13, 2008 4:54 PM, David Chelimsky wrote: > > > > > On Jan 13, 2008 3:51 PM, Corey Haines wrote: > > > > When I work with a .html.erb file, the autotest rspec on rails stuff > > > doesn't > > > > understand the file to map it to the right test. I wanted to submit > > > a patch > > > > for this, but I'm unsure where the specs would be to update. I found > > > the > > > > necessary mapping in rspec_autotest.rb, but I can't find any specs > > > anywhere. > > > > Help? > > > > > > > > I just need to have > > > > /app/views/coupon/index.html.erb to map to > > > /spec/views/coupon/index_spec.rb > > > > > > The right spec is index.html.erb_spec.rb - that's what the mapping is. > > > > > > If you want to change the mapping locally, you can if you're using > > > rspec's trunk and a patched version of ZenTest (see > > > http://rubyforge.org/pipermail/rspec-users/2008-January/005321.html). > > > > > > Cheers, > > > David > > > > > > > > > > > -Corey > > > > > > > > -- > > > > http://www.coreyhaines.com > > > > The Internet's Premiere source of information about Corey Haines > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > -- > > > > http://www.coreyhaines.com > > The Internet's Premiere source of information about Corey Haines > > > > > > -- > http://www.coreyhaines.com > The Internet's Premiere source of information about Corey Haines > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080113/2269e257/attachment.html From dchelimsky at gmail.com Sun Jan 13 22:33:15 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 13 Jan 2008 21:33:15 -0600 Subject: [rspec-users] .html.erb files and autotest In-Reply-To: <6bdacb70801131914v449a247dwa4b9e483cd88cc3e@mail.gmail.com> References: <6bdacb70801131351y7b2188beo1ba8e3fe3a090ce9@mail.gmail.com> <57c63afe0801131354u3163b0e6v55d66885db203a1b@mail.gmail.com> <6bdacb70801131429nd2a5836s282d30c6a39e8940@mail.gmail.com> <6bdacb70801131910t3a533acfm4c26ac28c80288df@mail.gmail.com> <6bdacb70801131914v449a247dwa4b9e483cd88cc3e@mail.gmail.com> Message-ID: <57c63afe0801131933v34068193vbdf2be241c8e5ad0@mail.gmail.com> On Jan 13, 2008 9:14 PM, Corey Haines wrote: > Awesome! That worked perfectly, Nathan! Thanks. There will soon (like in the next day or two I think) be a ZenTest release which will make setting $VERBOSE obsolete. By default you won't get the Dunno messages, but you can choose to get them by running autotest in verbose mode: autotest -v The benefit of doing that is it spots files that you may not have spec'd that you want spec'd. On the flip side you end up with a bunch of noise but you can eliminate that w/ the :initialize hook: Autotest.add_hook :initialize do |at| at.add_exception 'some_file_i_want_ignored' end That goes in .autotest in the root of your project, where you type the autotest command. HTH, David > > -Corey > > > > On Jan 13, 2008 10:11 PM, Nathan Sutton wrote: > > > > > > > > > > Set $VERBOSE=false in your .autotest file in your home directory. > > > > > > > > > > > > > > > > > > > > > > > > > > > > Nathan Sutton > > fowlduck at gmail.com > > rspec 1.1 > > rspec_on_rails 1.1 > > rails 2.0.2 > > > > > > > > > > > > On Jan 13, 2008, at 9:10 PM, Corey Haines wrote: > > > > > > > > > > I get this > > > > Dunno! app/views/coupon/index.html.erb > > > > > > > > > > On Jan 13, 2008 5:29 PM, Corey Haines < coreyhaines at gmail.com> wrote: > > > > > Okay, thanks. > > > > > > > > > > > > > > > > > > On Jan 13, 2008 4:54 PM, David Chelimsky wrote: > > > > > > > > > > > On Jan 13, 2008 3:51 PM, Corey Haines wrote: > > > > > When I work with a .html.erb file, the autotest rspec on rails stuff > doesn't > > > > > understand the file to map it to the right test. I wanted to submit > a patch > > > > > for this, but I'm unsure where the specs would be to update. I found > the > > > > > necessary mapping in rspec_autotest.rb, but I can't find any specs > anywhere. > > > > > Help? > > > > > > > > > > I just need to have > > > > > /app/views/coupon/index.html.erb to map to > /spec/views/coupon/index_spec.rb > > > > > > > > The right spec is index.html.erb_spec.rb - that's what the mapping is. > > > > If you want to change the mapping locally, you can if you're using > > > > rspec's trunk and a patched version of ZenTest (see > > > > http://rubyforge.org/pipermail/rspec-users/2008-January/005321.html). > > > > > > > > Cheers, > > > > David > > > > > > > > > > > > > > > > > > -Corey > > > > > > > > > > -- > > > > > http://www.coreyhaines.com > > > > > The Internet's Premiere source of information about Corey Haines > > > > > _______________________________________________ > > > > > rspec-users mailing list > > > > > rspec-users at rubyforge.org > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > -- > > > > > > > > > > > > http://www.coreyhaines.com > > > The Internet's Premiere source of information about Corey Haines > > > > > > > > -- > > http://www.coreyhaines.com > > The Internet's Premiere source of information about Corey Haines > _______________________________________________ > > > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > _______________________________________________ > > > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > -- > http://www.coreyhaines.com > The Internet's Premiere source of information about Corey Haines > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From coreyhaines at gmail.com Sun Jan 13 22:35:52 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Sun, 13 Jan 2008 22:35:52 -0500 Subject: [rspec-users] .html.erb files and autotest In-Reply-To: <57c63afe0801131933v34068193vbdf2be241c8e5ad0@mail.gmail.com> References: <6bdacb70801131351y7b2188beo1ba8e3fe3a090ce9@mail.gmail.com> <57c63afe0801131354u3163b0e6v55d66885db203a1b@mail.gmail.com> <6bdacb70801131429nd2a5836s282d30c6a39e8940@mail.gmail.com> <6bdacb70801131910t3a533acfm4c26ac28c80288df@mail.gmail.com> <6bdacb70801131914v449a247dwa4b9e483cd88cc3e@mail.gmail.com> <57c63afe0801131933v34068193vbdf2be241c8e5ad0@mail.gmail.com> Message-ID: <6bdacb70801131935v3084e031u44c77feea7a029b3@mail.gmail.com> Okay. Thanks for the help, guys. I'm back on track! On Jan 13, 2008 10:33 PM, David Chelimsky wrote: > On Jan 13, 2008 9:14 PM, Corey Haines wrote: > > Awesome! That worked perfectly, Nathan! Thanks. > > There will soon (like in the next day or two I think) be a ZenTest > release which will make setting $VERBOSE obsolete. By default you > won't get the Dunno messages, but you can choose to get them by > running autotest in verbose mode: > > autotest -v > > The benefit of doing that is it spots files that you may not have > spec'd that you want spec'd. On the flip side you end up with a bunch > of noise but you can eliminate that w/ the :initialize hook: > > Autotest.add_hook :initialize do |at| > at.add_exception 'some_file_i_want_ignored' > end > > That goes in .autotest in the root of your project, where you type the > autotest command. > > HTH, > David > > > > > -Corey > > > > > > > > On Jan 13, 2008 10:11 PM, Nathan Sutton wrote: > > > > > > > > > > > > > > > Set $VERBOSE=false in your .autotest file in your home directory. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > Nathan Sutton > > > fowlduck at gmail.com > > > rspec 1.1 > > > rspec_on_rails 1.1 > > > rails 2.0.2 > > > > > > > > > > > > > > > > > > On Jan 13, 2008, at 9:10 PM, Corey Haines wrote: > > > > > > > > > > > > > > > I get this > > > > > > Dunno! app/views/coupon/index.html.erb > > > > > > > > > > > > > > > On Jan 13, 2008 5:29 PM, Corey Haines < coreyhaines at gmail.com> wrote: > > > > > > > Okay, thanks. > > > > > > > > > > > > > > > > > > > > > > > > On Jan 13, 2008 4:54 PM, David Chelimsky > wrote: > > > > > > > > > > > > > > On Jan 13, 2008 3:51 PM, Corey Haines > wrote: > > > > > > When I work with a .html.erb file, the autotest rspec on rails > stuff > > doesn't > > > > > > understand the file to map it to the right test. I wanted to > submit > > a patch > > > > > > for this, but I'm unsure where the specs would be to update. I > found > > the > > > > > > necessary mapping in rspec_autotest.rb, but I can't find any > specs > > anywhere. > > > > > > Help? > > > > > > > > > > > > I just need to have > > > > > > /app/views/coupon/index.html.erb to map to > > /spec/views/coupon/index_spec.rb > > > > > > > > > > The right spec is index.html.erb_spec.rb - that's what the mapping > is. > > > > > If you want to change the mapping locally, you can if you're using > > > > > rspec's trunk and a patched version of ZenTest (see > > > > > > http://rubyforge.org/pipermail/rspec-users/2008-January/005321.html). > > > > > > > > > > Cheers, > > > > > David > > > > > > > > > > > > > > > > > > > > > > -Corey > > > > > > > > > > > > -- > > > > > > http://www.coreyhaines.com > > > > > > The Internet's Premiere source of information about Corey Haines > > > > > > _______________________________________________ > > > > > > rspec-users mailing list > > > > > > rspec-users at rubyforge.org > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > _______________________________________________ > > > > > rspec-users mailing list > > > > > rspec-users at rubyforge.org > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > > > > > > -- > > > > > > > > > > > > > > > > http://www.coreyhaines.com > > > > The Internet's Premiere source of information about Corey Haines > > > > > > > > > > > > -- > > > http://www.coreyhaines.com > > > The Internet's Premiere source of information about Corey Haines > > _______________________________________________ > > > > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > _______________________________________________ > > > > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > -- > > http://www.coreyhaines.com > > The Internet's Premiere source of information about Corey Haines > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080113/0b58ff6d/attachment-0001.html From nathan.sutton at gmail.com Sun Jan 13 22:52:26 2008 From: nathan.sutton at gmail.com (Nathan Sutton) Date: Sun, 13 Jan 2008 21:52:26 -0600 Subject: [rspec-users] .html.erb files and autotest In-Reply-To: <57c63afe0801131933v34068193vbdf2be241c8e5ad0@mail.gmail.com> References: <6bdacb70801131351y7b2188beo1ba8e3fe3a090ce9@mail.gmail.com> <57c63afe0801131354u3163b0e6v55d66885db203a1b@mail.gmail.com> <6bdacb70801131429nd2a5836s282d30c6a39e8940@mail.gmail.com> <6bdacb70801131910t3a533acfm4c26ac28c80288df@mail.gmail.com> <6bdacb70801131914v449a247dwa4b9e483cd88cc3e@mail.gmail.com> <57c63afe0801131933v34068193vbdf2be241c8e5ad0@mail.gmail.com> Message-ID: Awesome David, yeah I was quite surprised that verbose was on by default in 3.7.2. Nathan Sutton fowlduck at gmail.com rspec 1.1 rspec_on_rails 1.1 rails 2.0.2 On Jan 13, 2008, at 9:33 PM, David Chelimsky wrote: > On Jan 13, 2008 9:14 PM, Corey Haines wrote: >> Awesome! That worked perfectly, Nathan! Thanks. > > There will soon (like in the next day or two I think) be a ZenTest > release which will make setting $VERBOSE obsolete. By default you > won't get the Dunno messages, but you can choose to get them by > running autotest in verbose mode: > > autotest -v > > The benefit of doing that is it spots files that you may not have > spec'd that you want spec'd. On the flip side you end up with a bunch > of noise but you can eliminate that w/ the :initialize hook: > > Autotest.add_hook :initialize do |at| > at.add_exception 'some_file_i_want_ignored' > end > > That goes in .autotest in the root of your project, where you type the > autotest command. > > HTH, > David > >> >> -Corey >> >> >> >> On Jan 13, 2008 10:11 PM, Nathan Sutton >> wrote: >>> >>> >>> >>> >>> Set $VERBOSE=false in your .autotest file in your home directory. >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> Nathan Sutton >>> fowlduck at gmail.com >>> rspec 1.1 >>> rspec_on_rails 1.1 >>> rails 2.0.2 >>> >>> >>> >>> >>> >>> On Jan 13, 2008, at 9:10 PM, Corey Haines wrote: >>> >>> >>> >>> >>> I get this >>> >>> Dunno! app/views/coupon/index.html.erb >>> >>> >>> >>> >>> On Jan 13, 2008 5:29 PM, Corey Haines < coreyhaines at gmail.com> >>> wrote: >>> >>>> Okay, thanks. >>>> >>>> >>>> >>>> >>>> >>>> On Jan 13, 2008 4:54 PM, David Chelimsky >>>> wrote: >>>> >>>>> >>>>> On Jan 13, 2008 3:51 PM, Corey Haines >>>>> wrote: >>>>>> When I work with a .html.erb file, the autotest rspec on rails >>>>>> stuff >> doesn't >>>>>> understand the file to map it to the right test. I wanted to >>>>>> submit >> a patch >>>>>> for this, but I'm unsure where the specs would be to update. I >>>>>> found >> the >>>>>> necessary mapping in rspec_autotest.rb, but I can't find any >>>>>> specs >> anywhere. >>>>>> Help? >>>>>> >>>>>> I just need to have >>>>>> /app/views/coupon/index.html.erb to map to >> /spec/views/coupon/index_spec.rb >>>>> >>>>> The right spec is index.html.erb_spec.rb - that's what the >>>>> mapping is. >>>>> If you want to change the mapping locally, you can if you're using >>>>> rspec's trunk and a patched version of ZenTest (see >>>>> http://rubyforge.org/pipermail/rspec-users/2008-January/005321.html) >>>>> . >>>>> >>>>> Cheers, >>>>> David >>>>> >>>>> >>>>>> >>>>>> -Corey >>>>>> >>>>>> -- >>>>>> http://www.coreyhaines.com >>>>>> The Internet's Premiere source of information about Corey Haines >>>>>> _______________________________________________ >>>>>> rspec-users mailing list >>>>>> rspec-users at rubyforge.org >>>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>>> >>>>> _______________________________________________ >>>>> rspec-users mailing list >>>>> rspec-users at rubyforge.org >>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>> >>>> >>>> >>>> >>>> -- >>>> >>>> >>>> >>>> http://www.coreyhaines.com >>>> The Internet's Premiere source of information about Corey Haines >>> >>> >>> >>> -- >>> http://www.coreyhaines.com >>> The Internet's Premiere source of information about Corey Haines >> _______________________________________________ >>> >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >>> _______________________________________________ >>> >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> >> >> >> >> -- >> http://www.coreyhaines.com >> The Internet's Premiere source of information about Corey Haines >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From aslak.hellesoy at gmail.com Mon Jan 14 06:33:03 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Mon, 14 Jan 2008 12:33:03 +0100 Subject: [rspec-users] How to trace running spec In-Reply-To: <20080114024700.GB6930@chello.nl> References: <478A4AE4.1080107@bengreenberg.net> <478A8292.3010909@benmabey.com> <20080114024700.GB6930@chello.nl> Message-ID: <8d961d900801140333y5f5e987dl39b139983fa38a19@mail.gmail.com> On Jan 14, 2008 3:47 AM, Kero van Gelder wrote: > > > I have a spec that is hanging when it is running. > > > > > > How do I get the rspec runner to show what specs it's running so I can > > > which one is hanging? I am calling the runner from my rails project. > > > > Which formatter ate you using? If you use the specdoc formatter it will > > output the specs as it goes so you can tell where it is hanging. Also, > > there is a profiling one that will list the slowest specs. Run "spec > > -h" for more info. > > Though a formatter is no listener (or is it?), A formatter "listens" to events related to running of examples (specs), so you can call it a "listener". > it seems to act like one. It does. All our "listeners" output results in some way or another, which is why we call them formatters, both in our code and in the command line api (--formatter). To make things even more confusing, we actually use the term "listener" in the story framework, but only in the code. The command line api still calls them formatter. > Steps do not tell their listeners when they are started, only when they > are finished. > Steps is a concept you only find in the story framework. I think Ben was talking about RSpec "classic". > Assuming a known order, you can figure out which step hangs, but it is > not the one listed last (it's the one after that...) > > Another reason to have s step_started method in listeners, is to format > (tell the customer) about a step *before* the step is executed, such that > the customer knows what will happen, instead of heard what has just > happened. > > Time to write a ticket on lighthouse? > Sure, go ahead. But I think you're talking about a different thing than Ben here. Aslak > Bye, > Kero. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From brian.takita at gmail.com Mon Jan 14 12:23:34 2008 From: brian.takita at gmail.com (Brian Takita) Date: Mon, 14 Jan 2008 09:23:34 -0800 Subject: [rspec-users] TextMate bundle not compatible with nested specs for running focused tests? In-Reply-To: <57c63afe0801131549k1c583d44kf1ab62f94aa631c@mail.gmail.com> References: <2e82acb90801131547u5f1a714fk551b1f7aeca9e62f@mail.gmail.com> <57c63afe0801131549k1c583d44kf1ab62f94aa631c@mail.gmail.com> Message-ID: <1d7ddd110801140923x5d5e6ce2u1cc9a2204206f547@mail.gmail.com> Yes. The fix is coming soon. I'll try to get it out tonight. On Jan 13, 2008 3:49 PM, David Chelimsky wrote: > > On Jan 13, 2008 5:47 PM, Matthew Windwer wrote: > > Seems like the recently updated (and wonderful) textmate bundle does not > > take into account running individual tests that are in nested specs. > > > > Anybody else notice this? Any ideas? > > There's an open ticket on this at the lighthouse: > http://rspec.lighthouseapp.com/projects/5645/tickets/225 > > > > > > Matt > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From brian.takita at gmail.com Mon Jan 14 14:43:18 2008 From: brian.takita at gmail.com (Brian Takita) Date: Mon, 14 Jan 2008 11:43:18 -0800 Subject: [rspec-users] TextMate bundle not compatible with nested specs for running focused tests? In-Reply-To: <1d7ddd110801140923x5d5e6ce2u1cc9a2204206f547@mail.gmail.com> References: <2e82acb90801131547u5f1a714fk551b1f7aeca9e62f@mail.gmail.com> <57c63afe0801131549k1c583d44kf1ab62f94aa631c@mail.gmail.com> <1d7ddd110801140923x5d5e6ce2u1cc9a2204206f547@mail.gmail.com> Message-ID: <1d7ddd110801141143w2918b96eo1c74114d72d4fb0a@mail.gmail.com> On Jan 14, 2008 9:23 AM, Brian Takita wrote: > Yes. The fix is coming soon. I'll try to get it out tonight. Actually, we are going to do a release. I'll do it after the release. > > > On Jan 13, 2008 3:49 PM, David Chelimsky wrote: > > > > On Jan 13, 2008 5:47 PM, Matthew Windwer wrote: > > > Seems like the recently updated (and wonderful) textmate bundle does not > > > take into account running individual tests that are in nested specs. > > > > > > Anybody else notice this? Any ideas? > > > > There's an open ticket on this at the lighthouse: > > http://rspec.lighthouseapp.com/projects/5645/tickets/225 > > > > > > > > > > Matt > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > From byrnejb at harte-lyne.ca Mon Jan 14 15:55:36 2008 From: byrnejb at harte-lyne.ca (James B. Byrne) Date: Mon, 14 Jan 2008 15:55:36 -0500 (EST) Subject: [rspec-users] RSpec stories introduction Message-ID: <56023.216.185.71.22.1200344136.squirrel@webmail.harte-lyne.ca> I have played a bit with RSpec specs and now want to check out stories. I note that there is no generator for rspec stories pre se (unless I managed to miss all references to one ) and that the only directory relating to stories added by installing rspec is ./stories itself. The documentation at rspec.info seems to presume a great deal of prior knowledge. What I am looking for is a guided tour of what should go where and how each file should be called to implement stories. For the moment I have placed everything in ./stories, although I am nearly certain that this is not the way to go. I have created a file called "new_job.txt" in ./stories that contains this: ---> Story: open a new job As an authorized user I want to open a new job So that I can do work For a client Scenario: client is active Given client exists in database And client status is active When I add a new job Then a job number is automatically assigned And a job_parties entry is added for job and client with type "bill" And job_parties status is set to "quote" Scenario: client is held for administrative approval ... <--- I infer that I should also create a file called new_job.rb in stories and that it should contain: ---> with_steps_for :new_jobs_steps do run './new_job.txt' end <--- Then I believe that I require yet another file called "new_job_steps.rb" that has code that looks somewhat like this: ---> steps_for(:new_job_steps) do Given "client exists in database" do Client.destroy_all "short_name == 'test client exists'" Client.create!(:short_name => 'test client exists', :status => 'active') <--- and at this point I am lost. Do I really need more than one step file, say one or more to create the test client with the necessary attributes and another to add the job and perhaps a third to create an authorized user login? Does that mean that new_job.rb should look like this: ---> with_steps_for :login, :client_active, :new_jobs_steps do run './new_job.txt' end <--- Can someone show me how they would wire this together? and with what directories and file names that they would use? I am having a deal of trouble getting my head wrapped around this approach. -- *** E-Mail is NOT a SECURE channel *** James B. Byrne mailto:ByrneJB at Harte-Lyne.ca Harte & Lyne Limited http://www.harte-lyne.ca 9 Brockley Drive vox: +1 905 561 1241 Hamilton, Ontario fax: +1 905 561 0757 Canada L8E 3C3 From andy at r210.com Mon Jan 14 17:11:06 2008 From: andy at r210.com (Andy Leak) Date: Mon, 14 Jan 2008 17:11:06 -0500 Subject: [rspec-users] RSpec stories introduction In-Reply-To: <56023.216.185.71.22.1200344136.squirrel@webmail.harte-lyne.ca> Message-ID: Check out the UserStories video on PeepCode. Cost = $9US - a bargain with your strong currency. Cheers, Andy >I have played a bit with RSpec specs and now want to check out stories. I >note that there is no generator for rspec stories pre se (unless I managed >to miss all references to one ) and that the only directory relating to >stories added by installing rspec is ./stories itself. From rspec-users at kero.tmfweb.nl Mon Jan 14 19:46:46 2008 From: rspec-users at kero.tmfweb.nl (Kero van Gelder) Date: Tue, 15 Jan 2008 01:46:46 +0100 Subject: [rspec-users] .html.erb files and autotest In-Reply-To: <57c63afe0801131933v34068193vbdf2be241c8e5ad0@mail.gmail.com> References: <6bdacb70801131351y7b2188beo1ba8e3fe3a090ce9@mail.gmail.com> <57c63afe0801131354u3163b0e6v55d66885db203a1b@mail.gmail.com> <6bdacb70801131429nd2a5836s282d30c6a39e8940@mail.gmail.com> <6bdacb70801131910t3a533acfm4c26ac28c80288df@mail.gmail.com> <6bdacb70801131914v449a247dwa4b9e483cd88cc3e@mail.gmail.com> <57c63afe0801131933v34068193vbdf2be241c8e5ad0@mail.gmail.com> Message-ID: <20080115004646.GC6930@chello.nl> > The benefit of doing that is it spots files that you may not have > spec'd that you want spec'd. On the flip side you end up with a bunch > of noise but you can eliminate that w/ the :initialize hook: > > Autotest.add_hook :initialize do |at| > at.add_exception 'some_file_i_want_ignored' > end > > That goes in .autotest in the root of your project, where you type the > autotest command. I'm probably too much of a Ruby coder, but an Exception is an existing Ruby class. add_exception seems strange to me. How about at.except, at.ignore_file or at.ignore ? I like the last one best. Bye, Kero. From dchelimsky at gmail.com Mon Jan 14 19:57:42 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 14 Jan 2008 18:57:42 -0600 Subject: [rspec-users] .html.erb files and autotest In-Reply-To: <20080115004646.GC6930@chello.nl> References: <6bdacb70801131351y7b2188beo1ba8e3fe3a090ce9@mail.gmail.com> <57c63afe0801131354u3163b0e6v55d66885db203a1b@mail.gmail.com> <6bdacb70801131429nd2a5836s282d30c6a39e8940@mail.gmail.com> <6bdacb70801131910t3a533acfm4c26ac28c80288df@mail.gmail.com> <6bdacb70801131914v449a247dwa4b9e483cd88cc3e@mail.gmail.com> <57c63afe0801131933v34068193vbdf2be241c8e5ad0@mail.gmail.com> <20080115004646.GC6930@chello.nl> Message-ID: <57c63afe0801141657q11e192e8x2c2e850ef7da944c@mail.gmail.com> On Jan 14, 2008 6:46 PM, Kero van Gelder wrote: > > The benefit of doing that is it spots files that you may not have > > spec'd that you want spec'd. On the flip side you end up with a bunch > > of noise but you can eliminate that w/ the :initialize hook: > > > > Autotest.add_hook :initialize do |at| > > at.add_exception 'some_file_i_want_ignored' > > end > > > > That goes in .autotest in the root of your project, where you type the > > autotest command. > > I'm probably too much of a Ruby coder, but an Exception is an existing > Ruby class. add_exception seems strange to me. > > How about at.except, at.ignore_file or at.ignore ? > I like the last one best. Good point. Wrong list. That's autotest. Try submitting a request in the ZenTest tracer: http://rubyforge.org/projects/zentest Cheers, David > > Bye, > Kero. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From coreyhaines at gmail.com Mon Jan 14 21:31:41 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Mon, 14 Jan 2008 21:31:41 -0500 Subject: [rspec-users] Okay, I'm finally asking for help Message-ID: <6bdacb70801141831q7056f811tb516b496582d6df2@mail.gmail.com> Hi, all! I would love if someone could help me figure this out. I can't seem to see why the following fails: Here's the spec: it "should redirect back to the index page" do Coupon.should_receive (:new).with({"name"=>@expectedName,"amount"=>@expectedAmount}).and_return(@coupon) @coupon.should_receive(:save) response.should redirect_to(:action => 'index') post 'save_coupon',{:coupon=>{:name=>@expectedName,:amount=>@expectedAmount}} end (the @vars are all set up) Here's the method: def save_coupon @coupon = Coupon.new(params[:coupon]) @coupon.save redirect_to :action => :index end Now, I've tried it through the browser, and it works. Any thoughts? I appreciate it. -Corey -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080114/853a4691/attachment-0001.html From dchelimsky at gmail.com Mon Jan 14 21:32:53 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 14 Jan 2008 20:32:53 -0600 Subject: [rspec-users] Okay, I'm finally asking for help In-Reply-To: <6bdacb70801141831q7056f811tb516b496582d6df2@mail.gmail.com> References: <6bdacb70801141831q7056f811tb516b496582d6df2@mail.gmail.com> Message-ID: <57c63afe0801141832j3e02637u57726a75fc4bbcf6@mail.gmail.com> On Jan 14, 2008 8:31 PM, Corey Haines wrote: > Hi, all! > > I would love if someone could help me figure this out. I can't seem to see > why the following fails: > > Here's the spec: > it "should redirect back to the index page" do > Coupon.should_receive > (:new).with({"name"=>@expectedName,"amount"=>@expectedAmount}).and_return(@coupon) > @coupon.should_receive(:save) > response.should redirect_to(:action => 'index') > post > 'save_coupon',{:coupon=>{:name=>@expectedName,:amount=>@expectedAmount}} > end > > (the @vars are all set up) > > Here's the method: > def save_coupon > @coupon = Coupon.new(params[:coupon]) > @coupon.save > redirect_to :action => :index > end > > Now, I've tried it through the browser, and it works. Any thoughts? What's the failure message? > > I appreciate it. > -Corey > > -- > http://www.coreyhaines.com > The Internet's Premiere source of information about Corey Haines > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From omen.king at gmail.com Mon Jan 14 21:34:05 2008 From: omen.king at gmail.com (Andrew WC Brown) Date: Mon, 14 Jan 2008 21:34:05 -0500 Subject: [rspec-users] Okay, I'm finally asking for help In-Reply-To: <57c63afe0801141832j3e02637u57726a75fc4bbcf6@mail.gmail.com> References: <6bdacb70801141831q7056f811tb516b496582d6df2@mail.gmail.com> <57c63afe0801141832j3e02637u57726a75fc4bbcf6@mail.gmail.com> Message-ID: Did your spec failed? Would you paste it? On Jan 14, 2008 9:32 PM, David Chelimsky wrote: > On Jan 14, 2008 8:31 PM, Corey Haines wrote: > > Hi, all! > > > > I would love if someone could help me figure this out. I can't seem to > see > > why the following fails: > > > > Here's the spec: > > it "should redirect back to the index page" do > > Coupon.should_receive > > > (:new).with({"name"=>@expectedName,"amount"=>@expectedAmount}).and_return(@coupon) > > @coupon.should_receive(:save) > > response.should redirect_to(:action => 'index') > > post > > 'save_coupon',{:coupon=>{:name=>@expectedName,:amount=>@expectedAmount}} > > end > > > > (the @vars are all set up) > > > > Here's the method: > > def save_coupon > > @coupon = Coupon.new(params[:coupon]) > > @coupon.save > > redirect_to :action => :index > > end > > > > Now, I've tried it through the browser, and it works. Any thoughts? > > What's the failure message? > > > > > I appreciate it. > > -Corey > > > > -- > > http://www.coreyhaines.com > > The Internet's Premiere source of information about Corey Haines > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080114/c5b06926/attachment.html From rick.denatale at gmail.com Mon Jan 14 21:38:11 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Mon, 14 Jan 2008 21:38:11 -0500 Subject: [rspec-users] Okay, I'm finally asking for help In-Reply-To: <6bdacb70801141831q7056f811tb516b496582d6df2@mail.gmail.com> References: <6bdacb70801141831q7056f811tb516b496582d6df2@mail.gmail.com> Message-ID: On 1/14/08, Corey Haines wrote: > Hi, all! > > I would love if someone could help me figure this out. I can't seem to see > why the following fails: > > Here's the spec: > it "should redirect back to the index page" do > Coupon.should_receive > (:new).with({"name"=>@expectedName,"amount"=>@expectedAmount}).and_return(@coupon) > @coupon.should_receive(:save) > response.should redirect_to(:action => 'index') > post > 'save_coupon',{:coupon=>{:name=>@expectedName,:amount=>@expectedAmount}} I think you need to check the response after the post, not before. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From coreyhaines at gmail.com Mon Jan 14 21:40:32 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Mon, 14 Jan 2008 21:40:32 -0500 Subject: [rspec-users] Okay, I'm finally asking for help In-Reply-To: References: <6bdacb70801141831q7056f811tb516b496582d6df2@mail.gmail.com> Message-ID: <6bdacb70801141840p7abf17acsbc8a987c3cbd6785@mail.gmail.com> That was it! Thanks, Rick! Sorry about not posting the failure. DOH! Thanks again, everyone! -Corey On Jan 14, 2008 9:38 PM, Rick DeNatale wrote: > On 1/14/08, Corey Haines wrote: > > Hi, all! > > > > I would love if someone could help me figure this out. I can't seem to > see > > why the following fails: > > > > Here's the spec: > > it "should redirect back to the index page" do > > Coupon.should_receive > > > (:new).with({"name"=>@expectedName,"amount"=>@expectedAmount}).and_return(@coupon) > > @coupon.should_receive(:save) > > response.should redirect_to(:action => 'index') > > post > > 'save_coupon',{:coupon=>{:name=>@expectedName,:amount=>@expectedAmount}} > > I think you need to check the response after the post, not before. > > -- > Rick DeNatale > > My blog on Ruby > http://talklikeaduck.denhaven2.com/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080114/862db91f/attachment.html From Andreas.Axelsson at combination.se Tue Jan 15 04:00:24 2008 From: Andreas.Axelsson at combination.se (Andreas Axelsson) Date: Tue, 15 Jan 2008 10:00:24 +0100 Subject: [rspec-users] RSpec stories introduction In-Reply-To: <56023.216.185.71.22.1200344136.squirrel@webmail.harte-lyne.ca> References: <56023.216.185.71.22.1200344136.squirrel@webmail.harte-lyne.ca> Message-ID: > -----Original Message----- > From: rspec-users-bounces at rubyforge.org [mailto:rspec-users- > bounces at rubyforge.org] On Behalf Of James B. Byrne > Sent: den 14 januari 2008 21:56 > To: rspec-users at rubyforge.org > Subject: [rspec-users] RSpec stories introduction > > I have played a bit with RSpec specs and now want to check out stories. > I > note that there is no generator for rspec stories pre se (unless I > managed > to miss all references to one ) and that the only directory relating to > stories added by installing rspec is ./stories itself. I had a bit of trouble with this as well, and here's what I've come up with: ????projdir ????bin ????lib ? ????vinfo ????spec ????stories ????helpers ????steps ????stories Lib contains the project, under the vinfo folder (that's the project name, substitute freely), organized like any other ruby module. Spec contains specs, module_spec.rb, etc. Stories contains an all.rb, which sets up the local search paths and loads all story runners from the stories\stories folder. Stories also contain a helper.rb which loads all steps and helper modules from steps and helpers. RUBYLIB points to my lib folder above when developing. ---stories\all.rb--- Dir[File.join(File.dirname(__FILE__), "stories", "*.rb")].each do |file| require File.join(File.dirname(file), File.basename(file)) end ---end--- ---stories\helper.rb--- require 'rubygems' Dir[File.dirname(__FILE__) + "/helpers/**/*.rb"].each do |file| require File.join(File.dirname(file), File.basename(file)) end Dir[File.dirname(__FILE__) + "/steps/**/*.rb"].each do |file| require File.join(File.dirname(file), File.basename(file)) end def runStory file run File.expand_path(file).gsub(".rb", ".story") end ---end--- ---stories\somestory.rb--- require File.join(File.dirname(__FILE__), '..', 'helper') with_steps_for(:versiontool) do runStory __FILE__ end ---end--- Then the steps are defined just as you describe in the various steps\*.rb files with utility code in the helpers\*.rb files. I have no idea if it's the best way to set things up, but it works for me. I've got a Rakefile in the root to run specs, stories, or all. ---Rakefile--- $:.unshift('lib') require 'rubygems' require 'rcov/rcovtask' require 'spec/rake/spectask' task :default => [:rcov_vinfo] task :rcov_vinfo => [:spec, :stories] desc "Run the unit tests with rcovrt." Spec::Rake::SpecTask.new(:spec) do |t| html = '../doc/vinfo_specs.html' t.warning = true t.rcov_dir = '../doc/coverage' t.rcov = true t.spec_opts = ["--color", "--format", "progress", "--format", "html:#{html}"] end desc "Run all stories" task :stories do html = '../doc/vinfo_stories.html' ruby "stories/all.rb --color --format plain --format html:#{html}" end ---end--- Hope this helps, /Axl From Andreas.Axelsson at combination.se Tue Jan 15 04:17:28 2008 From: Andreas.Axelsson at combination.se (Andreas Axelsson) Date: Tue, 15 Jan 2008 10:17:28 +0100 Subject: [rspec-users] RSpec stories introduction In-Reply-To: References: <56023.216.185.71.22.1200344136.squirrel@webmail.harte-lyne.ca> Message-ID: Sorry, but the formatting seems to have gone bad below. You'll most surely figure out how to fix it though. /axl > -----Original Message----- > From: rspec-users-bounces at rubyforge.org [mailto:rspec-users- > bounces at rubyforge.org] On Behalf Of Andreas Axelsson > Sent: den 15 januari 2008 10:00 > To: rspec-users > Subject: Re: [rspec-users] RSpec stories introduction > > > -----Original Message----- > > From: rspec-users-bounces at rubyforge.org [mailto:rspec-users- > > bounces at rubyforge.org] On Behalf Of James B. Byrne > > Sent: den 14 januari 2008 21:56 > > To: rspec-users at rubyforge.org > > Subject: [rspec-users] RSpec stories introduction > > > > I have played a bit with RSpec specs and now want to check out > stories. > > I > > note that there is no generator for rspec stories pre se (unless I > > managed > > to miss all references to one ) and that the only directory relating > to > > stories added by installing rspec is ./stories itself. > > I had a bit of trouble with this as well, and here's what I've come up > with: > > ????projdir > ????bin > ????lib > ? ????vinfo > ????spec > ????stories > ????helpers > ????steps > ????stories > > Lib contains the project, under the vinfo folder (that's the project > name, substitute freely), organized like any other ruby module. > Spec contains specs, module_spec.rb, etc. > Stories contains an all.rb, which sets up the local search paths and > loads all story runners from the stories\stories folder. Stories also > contain a helper.rb which loads all steps and helper modules from steps > and helpers. > RUBYLIB points to my lib folder above when developing. > > ---stories\all.rb--- > Dir[File.join(File.dirname(__FILE__), "stories", "*.rb")].each do > |file| > require File.join(File.dirname(file), File.basename(file)) > end > ---end--- > > ---stories\helper.rb--- > require 'rubygems' > Dir[File.dirname(__FILE__) + "/helpers/**/*.rb"].each do |file| > require File.join(File.dirname(file), File.basename(file)) > end > Dir[File.dirname(__FILE__) + "/steps/**/*.rb"].each do |file| > require File.join(File.dirname(file), File.basename(file)) > end > def runStory file > run File.expand_path(file).gsub(".rb", ".story") > end > ---end--- > > ---stories\somestory.rb--- > require File.join(File.dirname(__FILE__), '..', 'helper') > with_steps_for(:versiontool) do > runStory __FILE__ > end > ---end--- > > Then the steps are defined just as you describe in the various > steps\*.rb files with utility code in the helpers\*.rb files. > > I have no idea if it's the best way to set things up, but it works for > me. I've got a Rakefile in the root to run specs, stories, or all. > > ---Rakefile--- > $:.unshift('lib') > > require 'rubygems' > require 'rcov/rcovtask' > require 'spec/rake/spectask' > > task :default => [:rcov_vinfo] > task :rcov_vinfo => [:spec, :stories] > > desc "Run the unit tests with rcovrt." > Spec::Rake::SpecTask.new(:spec) do |t| > html = '../doc/vinfo_specs.html' > t.warning = true > t.rcov_dir = '../doc/coverage' > t.rcov = true > t.spec_opts = ["--color", "--format", "progress", "--format", > "html:#{html}"] > end > > desc "Run all stories" > task :stories do > html = '../doc/vinfo_stories.html' > ruby "stories/all.rb --color --format plain --format > html:#{html}" > end > ---end--- > > Hope this helps, > /Axl > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From chris at edendevelopment.co.uk Tue Jan 15 04:33:04 2008 From: chris at edendevelopment.co.uk (Chris Parsons) Date: Tue, 15 Jan 2008 09:33:04 +0000 Subject: [rspec-users] RSpec stories introduction In-Reply-To: References: <56023.216.185.71.22.1200344136.squirrel@webmail.harte-lyne.ca> Message-ID: On 15 Jan 2008, at 09:00, Andreas Axelsson wrote: > I had a bit of trouble with this as well, and here's what I've come > up with: > We use something fairly similar to Andreas' method here. For reference, here's a post from last month by David on how he organises his stories by feature: http://rubyforge.org/pipermail/rspec-users/2007-December/005127.html It's important to note though that there isn't a 'right way' agreed yet. Regards Chris From cody at skidmore.us Tue Jan 15 09:27:48 2008 From: cody at skidmore.us (Cody P. Skidmore) Date: Tue, 15 Jan 2008 06:27:48 -0800 (PST) Subject: [rspec-users] broken URL on rspec.info Message-ID: <37794.216.167.174.66.1200407268.squirrel@webmail.skidmore.us> Hey folks. I was looking for the mailing list archive up on rspec.info. I clicked on the "community" link and received the URL "http://ey01-s00414/community/". This isn't correct, obviously. The hint shows it as, "http://rspec.info/community". Where is the mailing list archive? How far back does it go? I'd really like to read back through it and research my own problems as much as possible. With Regards, // Signed // Cody P. Skidmore From lists at ruby-forum.com Tue Jan 15 09:30:23 2008 From: lists at ruby-forum.com (CNNN NICK) Date: Tue, 15 Jan 2008 15:30:23 +0100 Subject: [rspec-users] autotest displays no output In-Reply-To: References: <13510545.post@talk.nabble.com> <4728AEE0.6010304@att.net> Message-ID: Hi all, I wasn't able to solve the problem of autotest not printing or running test until i read this post. I deleted the opts file and everything started working again. I am running autotest from Netbeans though, within my RoR projects. If i use the command line, it doesn't print colored results but i quite am happy with what i have at the moment as long as it's working. Anyway, i recommend using autotest with Netbeans because of the notifications you get within the IDE itself. Cheers, -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Tue Jan 15 09:31:52 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 15 Jan 2008 08:31:52 -0600 Subject: [rspec-users] broken URL on rspec.info In-Reply-To: <37794.216.167.174.66.1200407268.squirrel@webmail.skidmore.us> References: <37794.216.167.174.66.1200407268.squirrel@webmail.skidmore.us> Message-ID: <57c63afe0801150631w6d9f7f80rdc3f5a7356ce2c6e@mail.gmail.com> On Jan 15, 2008 8:27 AM, Cody P. Skidmore wrote: > Hey folks. I was looking for the mailing list archive up on rspec.info. > I clicked on the "community" link and received the URL > "http://ey01-s00414/community/". This isn't correct, obviously. The hint > shows it as, "http://rspec.info/community". Try http://rspec.info/community/ (with a trailing slash). I'll work to get that resolved. > > Where is the mailing list archive? http://rubyforge.org/pipermail/rspec-devel/ http://rubyforge.org/pipermail/rspec-users/ Cheers, David > How far back does it go? I'd really > like to read back through it and research my own problems as much as > possible. > > With Regards, > > // Signed // > > Cody P. Skidmore > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ingo at ingoweiss.com Tue Jan 15 09:55:03 2008 From: ingo at ingoweiss.com (Ingo Weiss) Date: Tue, 15 Jan 2008 15:55:03 +0100 Subject: [rspec-users] fixtures in stories In-Reply-To: <57c63afe0801150631w6d9f7f80rdc3f5a7356ce2c6e@mail.gmail.com> References: <37794.216.167.174.66.1200407268.squirrel@webmail.skidmore.us> <57c63afe0801150631w6d9f7f80rdc3f5a7356ce2c6e@mail.gmail.com> Message-ID: Hi all, how/where do I load fixtures in stories? Ingo From chris at edendevelopment.co.uk Tue Jan 15 10:07:16 2008 From: chris at edendevelopment.co.uk (Chris Parsons) Date: Tue, 15 Jan 2008 15:07:16 +0000 Subject: [rspec-users] fixtures in stories In-Reply-To: References: <37794.216.167.174.66.1200407268.squirrel@webmail.skidmore.us> <57c63afe0801150631w6d9f7f80rdc3f5a7356ce2c6e@mail.gmail.com> Message-ID: <08869BBA-935F-4A5A-95BA-39E1D895242C@edendevelopment.co.uk> Hi Ingo, On 15 Jan 2008, at 14:55, Ingo Weiss wrote: > how/where do I load fixtures in stories? Try loading your data up manually using 'Given' blocks: (my_story.txt) Given a user called Bob And a user called Charlie and: (steps.rb) Given "a user called $name" do |name| User.create! :name => name end Hope this helps Chris From ingo at ingoweiss.com Tue Jan 15 10:23:49 2008 From: ingo at ingoweiss.com (Ingo Weiss) Date: Tue, 15 Jan 2008 16:23:49 +0100 Subject: [rspec-users] fixtures in stories In-Reply-To: <08869BBA-935F-4A5A-95BA-39E1D895242C@edendevelopment.co.uk> References: <37794.216.167.174.66.1200407268.squirrel@webmail.skidmore.us> <57c63afe0801150631w6d9f7f80rdc3f5a7356ce2c6e@mail.gmail.com> <08869BBA-935F-4A5A-95BA-39E1D895242C@edendevelopment.co.uk> Message-ID: <56720F08-FA04-4147-AF30-A4A451FBB354@ingoweiss.com> Thanks, Chris! This is how I create most of my data for stories. However, I have one case (globalize languages/countries) where loading the data from fixtures seems to make more sense. Also, I would like to load them in one place, globally for all stories, as you can do in spec_helper, in order to not have to include a 'Given language ...' in all of my stories. Is that possible? Ingo On Jan 15, 2008, at 4:07 PM, Chris Parsons wrote: > Hi Ingo, > > On 15 Jan 2008, at 14:55, Ingo Weiss wrote: > >> how/where do I load fixtures in stories? > > Try loading your data up manually using 'Given' blocks: > > (my_story.txt) > Given a user called Bob > And a user called Charlie > > and: > > (steps.rb) > Given "a user called $name" do |name| > User.create! :name => name > end > > Hope this helps > Chris > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From evan at protest.net Tue Jan 15 16:52:34 2008 From: evan at protest.net (evan) Date: Tue, 15 Jan 2008 19:52:34 -0200 Subject: [rspec-users] Problem with ruby-debug and rspec Message-ID: <86ec40c10801151352i55782aedpac9178e8ff5c6482@mail.gmail.com> So i've been getting this same thing with both rspec 1.1.1 and now with 1.1.2. ruby-debug works with i'm in the application code, but not when i'm in the 'spec', or spec helper methods i'm loading. Basically any command which should normally work like p, or pp, gets passed through to a method_missing. I'm kind of stumped on this one... any ideas? -rabble I've got the following plugins installed: active_record_base_without_table annotate_models asset_packager exception_logger fixture_replacement query_reviewer rspec rspec_on_rails spatial_adapter svn white_list will_paginate ym4r_gm and am using the following gems: GeoRuby-1.3.2 RedCloth-3.0.4 has_finder-0.1.5 json-1.1.1 mocha-0.5.5 oauth ruby-hmac-0.3.1 brickhouse:~/code/fireeagle-rails/core/trunk rabble$ spec spec/controllers/account_controller_spec.rb /Users/rabble/code/fireeagle-rails/core/trunk/lib/sso_authentication/test_helper.rb:15 @controller.stubs(:current_user).returns(user) (rdb:1) p self INTERNAL ERROR!!! undefined method `remove_method' for # /Users/rabble/code/fireeagle-rails/core/trunk/vendor/rails/actionpack/lib/action_controller/test_process.rb:464:in `method_missing' /opt/local/lib/ruby/gems/1.8/gems/rspec-1.1.2/lib/spec/matchers.rb:149:in `method_missing' /Users/rabble/code/fireeagle-rails/core/trunk/lib/sso_authentication/test_helper.rb:19:in `authenticate' /Users/rabble/code/fireeagle-rails/core/trunk/lib/sso_authentication/test_helper.rb:15:in `authenticate' /Users/rabble/code/fireeagle-rails/core/trunk/lib/sso_authentication/test_helper.rb:106:in `method_missing' ./spec/controllers/account_controller_spec.rb:64:in `test_already_tossed' /Users/rabble/code/fireeagle-rails/core/trunk/lib/sso_authentication/test_helper.rb:58:in `assert_requires_login' ./spec/controllers/account_controller_spec.rb:63:in `test_already_tossed' /opt/local/lib/ruby/gems/1.8/gems/rspec-1.1.2/lib/spec/example/example_group_methods.rb:398:in `__send__' /opt/local/lib/ruby/gems/1.8/gems/rspec-1.1.2/lib/spec/example/example_group_methods.rb:398:in `add_method_examples' /opt/local/lib/ruby/gems/1.8/gems/rspec-1.1.2/lib/spec/example/example_methods.rb:78:in `instance_eval' /opt/local/lib/ruby/gems/1.8/gems/rspec-1.1.2/lib/spec/example/example_methods.rb:78:in `run_with_description_capturing' /opt/local/lib/ruby/gems/1.8/gems/rspec-1.1.2/lib/spec/example/example_methods.rb:19:in `execute' /opt/local/lib/ruby/1.8/timeout.rb:48:in `timeout' /opt/local/lib/ruby/gems/1.8/gems/rspec-1.1.2/lib/spec/example/example_methods.rb:16:in `execute' /opt/local/lib/ruby/gems/1.8/gems/rspec-1.1.2/lib/spec/example/example_group_methods.rb:286:in `execute_examples' /opt/local/lib/ruby/gems/1.8/gems/rspec-1.1.2/lib/spec/example/example_group_methods.rb:285:in `each' /opt/local/lib/ruby/gems/1.8/gems/rspec-1.1.2/lib/spec/example/example_group_methods.rb:285:in `execute_examples' /opt/local/lib/ruby/gems/1.8/gems/rspec-1.1.2/lib/spec/example/example_group_methods.rb:120:in `run' /opt/local/lib/ruby/gems/1.8/gems/rspec-1.1.2/lib/spec/runner/example_group_runner.rb:22:in `run' /opt/local/lib/ruby/gems/1.8/gems/rspec-1.1.2/lib/spec/runner/example_group_runner.rb:21:in `each' /opt/local/lib/ruby/gems/1.8/gems/rspec-1.1.2/lib/spec/runner/example_group_runner.rb:21:in `run' /opt/local/lib/ruby/gems/1.8/gems/rspec-1.1.2/lib/spec/runner/options.rb:87:in `run_examples' /opt/local/lib/ruby/gems/1.8/gems/rspec-1.1.2/lib/spec/runner/command_line.rb:19:in `run' /opt/local/lib/ruby/gems/1.8/gems/rspec-1.1.2/bin/spec:4 /opt/local/bin/spec:19:in `load' /opt/local/bin/spec:19/Users/rabble/code/fireeagle-rails/core/trunk/lib/sso_authentication/test_helper.rb:15 @controller.stubs(:current_user).returns(user) (rdb:1) From james.deville at gmail.com Tue Jan 15 17:33:41 2008 From: james.deville at gmail.com (James Deville) Date: Tue, 15 Jan 2008 14:33:41 -0800 Subject: [rspec-users] fixtures in stories In-Reply-To: <56720F08-FA04-4147-AF30-A4A451FBB354@ingoweiss.com> References: <37794.216.167.174.66.1200407268.squirrel@webmail.skidmore.us> <57c63afe0801150631w6d9f7f80rdc3f5a7356ce2c6e@mail.gmail.com> <08869BBA-935F-4A5A-95BA-39E1D895242C@edendevelopment.co.uk> <56720F08-FA04-4147-AF30-A4A451FBB354@ingoweiss.com> Message-ID: <799FCEAE-D40D-4D3A-9C39-EE99CCC45796@gmail.com> If you do a self.class.fixtures :all (or whatever name) in the given block, then you can read from fixtures, but you won't be able to do users(:tester), you'll have to do a User.find JD On Jan 15, 2008, at 7:23 AM, Ingo Weiss wrote: > Thanks, Chris! > > This is how I create most of my data for stories. However, I have one > case (globalize languages/countries) where loading the data from > fixtures seems to make more sense. Also, I would like to load them in > one place, globally for all stories, as you can do in spec_helper, in > order to not have to include a 'Given language ...' in all of my > stories. Is that possible? > > Ingo > > > On Jan 15, 2008, at 4:07 PM, Chris Parsons wrote: > >> Hi Ingo, >> >> On 15 Jan 2008, at 14:55, Ingo Weiss wrote: >> >>> how/where do I load fixtures in stories? >> >> Try loading your data up manually using 'Given' blocks: >> >> (my_story.txt) >> Given a user called Bob >> And a user called Charlie >> >> and: >> >> (steps.rb) >> Given "a user called $name" do |name| >> User.create! :name => name >> end >> >> Hope this helps >> Chris >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Tue Jan 15 20:18:52 2008 From: lists at ruby-forum.com (James Byrne) Date: Wed, 16 Jan 2008 02:18:52 +0100 Subject: [rspec-users] RSpec stories introduction In-Reply-To: References: <56023.216.185.71.22.1200344136.squirrel@webmail.harte-lyne.ca> Message-ID: <7b5c269b65ec52af92afadcf0b4aeba9@ruby-forum.com> I can get to the RSpec list through ruby-forum. Yes! The things you discover googling for help! I followed the advice to go to peepcode.com, which was somewhat ironic because that is where I started to look last week, before episode 18 for RSpec-Stories was released. However, better late than never. So I have followed the video through to the end, twice, and have a much better idea of where I am going now. I added fixture_replacement to my project as well. I have yet to deeply consider what directory structure makes sense for stories and their associated steps scripts, so I will leave everything in ./stories for now. I have adopted a recommended practice of calling things in the form X_story.txt and X_step.rb however. The rake file example given above is very helpful. Thanks! I wrote up a primitive aide memorie for stories and steps which I will post here when I have more confidence that it actually describes what is happening. -- Posted via http://www.ruby-forum.com/. From jonathan at parkerhill.com Tue Jan 15 20:36:38 2008 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Tue, 15 Jan 2008 20:36:38 -0500 Subject: [rspec-users] RSpec stories introduction In-Reply-To: <7b5c269b65ec52af92afadcf0b4aeba9@ruby-forum.com> References: <56023.216.185.71.22.1200344136.squirrel@webmail.harte-lyne.ca> <7b5c269b65ec52af92afadcf0b4aeba9@ruby-forum.com> Message-ID: <6832A1DD-57D3-483E-B1A0-E4B2264F4A8B@parkerhill.com> similarly, here's my write up: http://www.vaporbase.com/postings/Getting_Started_with_Story_Runner linoj On Jan 15, 2008, at 8:18 PM, James Byrne wrote: > I can get to the RSpec list through ruby-forum. Yes! The things you > discover googling for help! > > I followed the advice to go to peepcode.com, which was somewhat ironic > because that is where I started to look last week, before episode > 18 for > RSpec-Stories was released. However, better late than never. > > So I have followed the video through to the end, twice, and have a > much > better idea of where I am going now. I added fixture_replacement > to my > project as well. > > I have yet to deeply consider what directory structure makes sense for > stories and their associated steps scripts, so I will leave everything > in ./stories for now. I have adopted a recommended practice of > calling > things in the form X_story.txt and X_step.rb however. > > The rake file example given above is very helpful. Thanks! > > I wrote up a primitive aide memorie for stories and steps which I will > post here when I have more confidence that it actually describes > what is > happening. > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From ben at benmabey.com Wed Jan 16 13:58:34 2008 From: ben at benmabey.com (Ben Mabey) Date: Wed, 16 Jan 2008 11:58:34 -0700 Subject: [rspec-users] rspec_on_rails_matchers Message-ID: <478E53DA.3030105@benmabey.com> All, Sorry for spamming this list about this but I think everyone who could help me with this problem is on this list... If there is a better place to post this question let me know. Anyways, I am trying to use rspec_on_rails_matchers in my rails app to improve my view specs but I can't get them to work. The helpers for the form tags never seem to be called. I created a new Rails 2.0.2 app, installed RSpec and rspec_on_rails 1.1.2, then installed the rspec_on_rails_matchers... FYI, I am using ruby 1.8.5 (2006-12-04 patchlevel 2). I then created some simple scaffolding to have some view specs to play with: ./script/generate rspec_scaffold Animal kingdom:string name:string Then running rake db:migrate, rake db:test:prepare, and rake spec will give me all green. I then added the rspec_on_rails_matchers to my view spec.. so I had this: http://pastie.caboo.se/139655 I then removed one of my fields from my actual form to break the specs. The original spec with have_tag and with_tag did break but the rspec_on_rails_matcher version did not break! In fact I can do the following and not even get it to break: it "should render new form" do render "/animals/new.html.erb" response.should have_form_posting_to(animals_path) do with_text_field_for(:animal_kingdom) with_text_field_for(:animal_name) with_text_field_for(:some_non_existent_field) with_text_field_for(:something_else_that_should_break_it) end end Could someone please tell me what the painfully obvious thing that I am doing wrong is? Or are the rspec_on_rails_matchers not working for other people? This is my sample app that is giving me this odd behaviour: http://benmabey.com/rspec_on_rails_matchers_test_app.tar.bz Thanks in advance. -Ben From joshknowles at gmail.com Wed Jan 16 17:50:37 2008 From: joshknowles at gmail.com (Josh Knowles) Date: Wed, 16 Jan 2008 17:50:37 -0500 Subject: [rspec-users] rspec_on_rails_matchers In-Reply-To: <478E53DA.3030105@benmabey.com> References: <478E53DA.3030105@benmabey.com> Message-ID: On 1/16/08, Ben Mabey wrote: > Could someone please tell me what the painfully obvious thing that I am > doing wrong is? Or are the rspec_on_rails_matchers not working for > other people? It very well could be broken most of this plugin was written at 3 am... I'll take a look at it tonight and get it fixed. -- Josh Knowles phone: 509-979-1593 email: joshknowles at gmail.com web: http://joshknowles.com From rick.denatale at gmail.com Wed Jan 16 18:25:43 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Wed, 16 Jan 2008 18:25:43 -0500 Subject: [rspec-users] rspec_on_rails_matchers In-Reply-To: References: <478E53DA.3030105@benmabey.com> Message-ID: On 1/16/08, Josh Knowles wrote: > On 1/16/08, Ben Mabey wrote: > > Could someone please tell me what the painfully obvious thing that I am > > doing wrong is? Or are the rspec_on_rails_matchers not working for > > other people? > > It very well could be broken most of this plugin was written at 3 > am... I'll take a look at it tonight and get it fixed. > Hey Josh, all code is written around 3 am, somewhere. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From gilesb at gmail.com Thu Jan 17 02:20:22 2008 From: gilesb at gmail.com (Giles Bowkett) Date: Wed, 16 Jan 2008 23:20:22 -0800 Subject: [rspec-users] unusual challenges speccing external software Message-ID: <2d81dedb0801162320p42007a29n3005b976dff15f2e@mail.gmail.com> This is something I've come up against twice. First, I have an interactive editor which calls vi, emacs, or TextMate (etc.) via Unix, and then loads the file handed to the editor back into IRB after it's edited and saved. I guess that makes it a special case of a more general question, which is how do you spec external processes, with a slightly more complicated version of the standard answer, mocks. The second instance is more complicated. I'm writing a MIDI code generator and using it to drive Propellerhead Reason, which is third-party closed-source commercial software which will run on my OS X box but which is not actually transparent to Unix in any meaningful way that I'm aware of. (The code generator can very probably also drive any arbitrary MIDI consumer.) I'm using code from Topher Cyll's book "Practical Ruby Projects" to create Ruby wrappers to C methods in Apple's CoreMIDI library. The trap here is I'm calling those C methods to generate MIDI elsewhere in the OS in some unknown way. That makes speccing weird. I've been able to refactor this code in a kind-of spec-first way. I write scripts which use the API successfully and actually generate music I can hear. Then I change the internals of the API and run the scripts again to ensure they still generate the same music. In that sense I'm basically doing the right thing, even though it's not particularly systematic or automated. I'm comparing the output with my ears rather than in a way that code can grok, but it still has the feel of a spec-first workflow. For developing the API itself, especially the parts which generate MIDI, I set up a layer of abstraction. Instead of directly driving the code which sends MIDI to external software, the code which generates the music drives an output adapter, and the output adapter sends MIDI to external software - or, in the case of the TextOutputAdapter, just text-dumps the music. Since it all comes back as text, it's very easy to write specs against. But I've ended up with three artifacts that are *either* byproducts of bad design *or* bad products of a compromised spec process. I created three mock *classes* (as opposed to mock objects). For example, one is the ArrayGenerator. In this system Generators return notes. The ArrayGenerator "generates" an array of notes. It's a silly implementation, but it's useful if you want to spec that some code can take an arbitrary generator, which generates arbitrary notes, and then process those notes correctly. Sometimes I think my design has too many abstract parts. Sometimes I'm happy with it. I want to improve my speccing approach so I can operate with greater certainty. I think probably this approach is a good direction, and that I should change the specs by making them more specific. (For instance, there are places where I check that a Generator subclass can do stuff, even though Generator itself isn't fully specced.) I'm not quite sure though. -- Giles Bowkett Podcast: http://hollywoodgrit.blogspot.com Blog: http://gilesbowkett.blogspot.com Portfolio: http://www.gilesgoatboy.org Tumblelog: http://giles.tumblr.com From daniel.ruby at tenner.org Thu Jan 17 11:15:46 2008 From: daniel.ruby at tenner.org (Daniel Tenner) Date: Thu, 17 Jan 2008 16:15:46 +0000 Subject: [rspec-users] unusual challenges speccing external software In-Reply-To: <2d81dedb0801162320p42007a29n3005b976dff15f2e@mail.gmail.com> References: <2d81dedb0801162320p42007a29n3005b976dff15f2e@mail.gmail.com> Message-ID: <31F93A82-3D2D-470A-9535-B692E3C3B17E@tenner.org> At the risk of sounding a bit silly, what's your question? I couldn't find a question mark in the whole email...? Daniel On 17 Jan 2008, at 07:20 17 Jan 2008, Giles Bowkett wrote: > This is something I've come up against twice. First, I have an > interactive editor which calls vi, emacs, or TextMate (etc.) via Unix, > and then loads the file handed to the editor back into IRB after it's > edited and saved. I guess that makes it a special case of a more > general question, which is how do you spec external processes, with a > slightly more complicated version of the standard answer, mocks. > > The second instance is more complicated. I'm writing a MIDI code > generator and using it to drive Propellerhead Reason, which is > third-party closed-source commercial software which will run on my OS > X box but which is not actually transparent to Unix in any meaningful > way that I'm aware of. (The code generator can very probably also > drive any arbitrary MIDI consumer.) I'm using code from Topher Cyll's > book "Practical Ruby Projects" to create Ruby wrappers to C methods in > Apple's CoreMIDI library. The trap here is I'm calling those C methods > to generate MIDI elsewhere in the OS in some unknown way. That makes > speccing weird. > > I've been able to refactor this code in a kind-of spec-first way. I > write scripts which use the API successfully and actually generate > music I can hear. Then I change the internals of the API and run the > scripts again to ensure they still generate the same music. In that > sense I'm basically doing the right thing, even though it's not > particularly systematic or automated. I'm comparing the output with my > ears rather than in a way that code can grok, but it still has the > feel of a spec-first workflow. > > For developing the API itself, especially the parts which generate > MIDI, I set up a layer of abstraction. Instead of directly driving the > code which sends MIDI to external software, the code which generates > the music drives an output adapter, and the output adapter sends MIDI > to external software - or, in the case of the TextOutputAdapter, just > text-dumps the music. Since it all comes back as text, it's very easy > to write specs against. > > But I've ended up with three artifacts that are *either* byproducts of > bad design *or* bad products of a compromised spec process. I created > three mock *classes* (as opposed to mock objects). For example, one is > the ArrayGenerator. In this system Generators return notes. The > ArrayGenerator "generates" an array of notes. It's a silly > implementation, but it's useful if you want to spec that some code can > take an arbitrary generator, which generates arbitrary notes, and then > process those notes correctly. > > Sometimes I think my design has too many abstract parts. Sometimes I'm > happy with it. I want to improve my speccing approach so I can operate > with greater certainty. I think probably this approach is a good > direction, and that I should change the specs by making them more > specific. (For instance, there are places where I check that a > Generator subclass can do stuff, even though Generator itself isn't > fully specced.) I'm not quite sure though. > > -- > Giles Bowkett > > Podcast: http://hollywoodgrit.blogspot.com > Blog: http://gilesbowkett.blogspot.com > Portfolio: http://www.gilesgoatboy.org > Tumblelog: http://giles.tumblr.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From gilesb at gmail.com Thu Jan 17 11:24:01 2008 From: gilesb at gmail.com (Giles Bowkett) Date: Thu, 17 Jan 2008 08:24:01 -0800 Subject: [rspec-users] unusual challenges speccing external software In-Reply-To: <31F93A82-3D2D-470A-9535-B692E3C3B17E@tenner.org> References: <2d81dedb0801162320p42007a29n3005b976dff15f2e@mail.gmail.com> <31F93A82-3D2D-470A-9535-B692E3C3B17E@tenner.org> Message-ID: <2d81dedb0801170824i32f469a5l760cb849c0ae68d2@mail.gmail.com> > At the risk of sounding a bit silly, what's your question? I couldn't > find a question mark in the whole email...? OK, well, am I on the right track? Should I do it differently? If so, in what particular way? If you were speccing external software, would you do it this way? Do I sound like a crazy person? If yes, more so than usual? Or only as much as I usually do? Is this a sensible way to spec software which interacts with but has no direct access to external software, or should I just isolate my dependencies on external software and write it off as unspeccable while speccing everything else? Is there a good rule of thumb for a BDD workflow when you can't programmatically capture some of the output? Because that's really what the problem is. I built a whole set of spec objects to capture the output as text because the system's real output isn't capturable, and if you can't capture it, you can't check it against the spec. My code has flaws but with good specs it's pretty easy to isolate the flaws. In this case I can't tell yet if the flaws are just flaws in my weird semi-BDD approach or in the code itself. I've probably done enough question marks but basically, is there a good set of guiding principles I can use to apply RSpec well in unconventional contexts? -- Giles Bowkett Podcast: http://hollywoodgrit.blogspot.com Blog: http://gilesbowkett.blogspot.com Portfolio: http://www.gilesgoatboy.org Tumblelog: http://giles.tumblr.com From dchelimsky at gmail.com Thu Jan 17 12:23:21 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 17 Jan 2008 11:23:21 -0600 Subject: [rspec-users] unusual challenges speccing external software In-Reply-To: <2d81dedb0801170824i32f469a5l760cb849c0ae68d2@mail.gmail.com> References: <2d81dedb0801162320p42007a29n3005b976dff15f2e@mail.gmail.com> <31F93A82-3D2D-470A-9535-B692E3C3B17E@tenner.org> <2d81dedb0801170824i32f469a5l760cb849c0ae68d2@mail.gmail.com> Message-ID: <57c63afe0801170923i54533bb1mbe85d2f0959802bd@mail.gmail.com> On Jan 17, 2008 10:24 AM, Giles Bowkett wrote: > > At the risk of sounding a bit silly, what's your question? I couldn't > > find a question mark in the whole email...? > > OK, well, am I on the right track? Should I do it differently? If so, > in what particular way? Giles - I think you'll find more people with more experience in this area on the testdrivendevelopment at yahoogroups.com list. That said, and only having glanced at your mail, here's a thought or two: The TDD line on this, as I understand it, is that you should write your main application code exactly as you want to write it, imagining that you had the perfect API to talk to and stubbing that API in your tests. Then, when hooking up to the real services, you write thin adapters that simply convert messages to the right format. I *think* that's what you said you are doing. HTH, David > > If you were speccing external software, would you do it this way? Do I > sound like a crazy person? If yes, more so than usual? Or only as much > as I usually do? Is this a sensible way to spec software which > interacts with but has no direct access to external software, or > should I just isolate my dependencies on external software and write > it off as unspeccable while speccing everything else? Is there a good > rule of thumb for a BDD workflow when you can't programmatically > capture some of the output? Because that's really what the problem is. > I built a whole set of spec objects to capture the output as text > because the system's real output isn't capturable, and if you can't > capture it, you can't check it against the spec. My code has flaws but > with good specs it's pretty easy to isolate the flaws. In this case I > can't tell yet if the flaws are just flaws in my weird semi-BDD > approach or in the code itself. I've probably done enough question > marks but basically, is there a good set of guiding principles I can > use to apply RSpec well in unconventional contexts? > > > -- > Giles Bowkett > > Podcast: http://hollywoodgrit.blogspot.com > Blog: http://gilesbowkett.blogspot.com > Portfolio: http://www.gilesgoatboy.org > Tumblelog: http://giles.tumblr.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From gilesb at gmail.com Thu Jan 17 12:33:53 2008 From: gilesb at gmail.com (Giles Bowkett) Date: Thu, 17 Jan 2008 09:33:53 -0800 Subject: [rspec-users] unusual challenges speccing external software In-Reply-To: <57c63afe0801170923i54533bb1mbe85d2f0959802bd@mail.gmail.com> References: <2d81dedb0801162320p42007a29n3005b976dff15f2e@mail.gmail.com> <31F93A82-3D2D-470A-9535-B692E3C3B17E@tenner.org> <2d81dedb0801170824i32f469a5l760cb849c0ae68d2@mail.gmail.com> <57c63afe0801170923i54533bb1mbe85d2f0959802bd@mail.gmail.com> Message-ID: <2d81dedb0801170933x6b1a144cie3b88e6cf52ab2dd@mail.gmail.com> > Giles - I think you'll find more people with more experience in this > area on the testdrivendevelopment at yahoogroups.com list. That said, and > only having glanced at your mail, here's a thought or two: > > The TDD line on this, as I understand it, is that you should write > your main application code exactly as you want to write it, imagining > that you had the perfect API to talk to and stubbing that API in your > tests. Then, when hooking up to the real services, you write thin > adapters that simply convert messages to the right format. I *think* > that's what you said you are doing. Yes. Sorry about the Great American Novel - that is pretty much what I'm doing. -- Giles Bowkett Podcast: http://hollywoodgrit.blogspot.com Blog: http://gilesbowkett.blogspot.com Portfolio: http://www.gilesgoatboy.org Tumblelog: http://giles.tumblr.com From dchelimsky at gmail.com Thu Jan 17 12:38:10 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 17 Jan 2008 11:38:10 -0600 Subject: [rspec-users] unusual challenges speccing external software In-Reply-To: <2d81dedb0801170933x6b1a144cie3b88e6cf52ab2dd@mail.gmail.com> References: <2d81dedb0801162320p42007a29n3005b976dff15f2e@mail.gmail.com> <31F93A82-3D2D-470A-9535-B692E3C3B17E@tenner.org> <2d81dedb0801170824i32f469a5l760cb849c0ae68d2@mail.gmail.com> <57c63afe0801170923i54533bb1mbe85d2f0959802bd@mail.gmail.com> <2d81dedb0801170933x6b1a144cie3b88e6cf52ab2dd@mail.gmail.com> Message-ID: <57c63afe0801170938p6efa95fdjeb90a2bc980e622e@mail.gmail.com> On Jan 17, 2008 11:33 AM, Giles Bowkett wrote: > > Giles - I think you'll find more people with more experience in this > > area on the testdrivendevelopment at yahoogroups.com list. That said, and > > only having glanced at your mail, here's a thought or two: > > > > The TDD line on this, as I understand it, is that you should write > > your main application code exactly as you want to write it, imagining > > that you had the perfect API to talk to and stubbing that API in your > > tests. Then, when hooking up to the real services, you write thin > > adapters that simply convert messages to the right format. I *think* > > that's what you said you are doing. > > Yes. Sorry about the Great American Novel - that is pretty much what I'm doing. Then that's sane :) It lets you keep changes to your internal app separate from changes to the service - even allows you to easily swap in new services - and lets you "talk in your language" within the app rather than being subject to an API that may or may not make sense to you most of the time. > > -- > > Giles Bowkett > > Podcast: http://hollywoodgrit.blogspot.com > Blog: http://gilesbowkett.blogspot.com > Portfolio: http://www.gilesgoatboy.org > Tumblelog: http://giles.tumblr.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ermok at tiscali.co.uk Fri Jan 11 15:57:44 2008 From: ermok at tiscali.co.uk (Neil M. Young) Date: Fri, 11 Jan 2008 12:57:44 -0800 (PST) Subject: [rspec-users] testing modules Message-ID: <14764396.post@talk.nabble.com> I've developed a module to include in ActiveRecord derived classes. Can I test the module without having to tie it to a particular class? atm, I'm including it in my User class and writing the tests in user_spec.rb, but I don't like the idea of tying the module tests to those of the class. I may extract the specs to a shared description and include that in the specs for each model which uses the module. is that the right way to do it? I'd appreciate any thoughts or suggestions neil -- View this message in context: http://www.nabble.com/testing-modules-tp14764396p14764396.html Sent from the rspec-users mailing list archive at Nabble.com. From evan.short at gmail.com Wed Jan 16 17:59:23 2008 From: evan.short at gmail.com (Evan Short) Date: Wed, 16 Jan 2008 16:59:23 -0600 Subject: [rspec-users] session data and user stories Message-ID: <44a5a1d0801161459i46ebfd8et53a2080004701f4@mail.gmail.com> hello there, i have been trying my hand at this rbehave material, specifically in terms of integration testing a rails application, and i am curious about the most friendly way to deal with session data. currently, the only way i have found to simulate a session is to open a session and refer to everything afterward via the @session variable stored after open_session. it seems to be workable, but is far from ideal: dir = File.dirname(__FILE__) require 'rubygems' require 'spec/story' require "#{dir}/helper" steps_for(:dealer_login) do Given("I have opened a session") do @session = open_session end Given("I am not logged in") do @session.instance_variable_get("@session").should == nil end Given("I have a valid login/password combo") do @login_with = valid_dealer_credentials end When("I submit my login/ password") do @session.post("/gateway", :user=> @login_with) end #there has to be a better way to address this Then("I should be authenticated") do @session.response.session.data.should == {:id => 1, "flash" => {}} end #and this is just hideous. Then("I should be sent to the dealer landing page") do puts @session.response.instance_variable_get("@redirected_to").should == {:controller => "dealers"} end end with_steps_for(:dealer_login) do run_local_story "dealer_story", :type=>RailsStory end there is a good chance someone has already covered this and i have just managed to miss it. documentation on rbehave is sparse (at best, as i have seen it. i have the peepcode, but if anyone has any other good resources i would be more than appreciative.) in the event that this has not been addressed, i see two possibilities: first, that i am somehow subverting the intention of rbehave. as i understand it, however, rbehave is at least partially intended for integration-level specification, so it seems to me that this session information would be valuable. on the other hand, perhaps this needs to be addressed in some way. i would be happy to help, but i am interested to see the community's opinion on the issue first. regards, evan -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080116/ed685b34/attachment.html From pergesu at gmail.com Fri Jan 18 04:06:07 2008 From: pergesu at gmail.com (Pat Maddox) Date: Fri, 18 Jan 2008 01:06:07 -0800 Subject: [rspec-users] testing modules In-Reply-To: <14764396.post@talk.nabble.com> References: <14764396.post@talk.nabble.com> Message-ID: <810a540e0801180106h2c439f9dm9b19cb4674aea33f@mail.gmail.com> On Jan 11, 2008 12:57 PM, Neil M. Young wrote: > > I've developed a module to include in ActiveRecord derived classes. Can I > test the module without having to tie it to a particular class? atm, I'm > including it in my User class and writing the tests in user_spec.rb, but I > don't like the idea of tying the module tests to those of the class. > > I may extract the specs to a shared description and include that in the > specs for each model which uses the module. is that the right way to do it? > > I'd appreciate any thoughts or suggestions > neil > -- > View this message in context: http://www.nabble.com/testing-modules-tp14764396p14764396.html > Sent from the rspec-users mailing list archive at Nabble.com. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > I like to stick this sort of thing in a plugin, and write specs in the plugin, that way it has nothing to do with your production code. Pat From lists at ruby-forum.com Fri Jan 18 04:57:55 2008 From: lists at ruby-forum.com (Anton Komarov) Date: Fri, 18 Jan 2008 10:57:55 +0100 Subject: [rspec-users] Rspec problem in testing RoR application Message-ID: <3361858a39d0100f1fd08d5decebe8ac@ruby-forum.com> Hello. I install gems rspec and rspec_on_rails I have this Error when try to run Rspec tests on my RoR application: /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:263:in `load_missing_constant': uninitialized constant ActionView::Helpers::JavaScriptMacrosHelper (NameError) And I follow recipes wich are placed in http://rubyforge.org/pipermail/rspec-devel/2007-September/004032.html But it make another one Error: /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:263:in `load_missing_constant': uninitialized constant Spec::VERSION::REV (NameError) from /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:453:in `const_missing' from /home/anton/tele/trunk/vendor/plugins/rspec_on_rails/lib/spec/rails/version.rb:13 from /usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require' from /usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `require' from /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require' from /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in' from /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require' from /home/anton/tele/trunk/vendor/plugins/rspec_on_rails/lib/spec/rails.rb:16 ... 11 levels... from /var/lib/gems/1.8/gems/rspec-1.1.2/lib/spec/runner/example_group_runner.rb:13:in `load_files' from /var/lib/gems/1.8/gems/rspec-1.1.2/lib/spec/runner/options.rb:83:in `run_examples' from /var/lib/gems/1.8/gems/rspec-1.1.2/lib/spec/runner/command_line.rb:19:in `run' from /var/lib/gems/1.8/gems/rspec-1.1.2/bin/spec:4 And I don't now what I must to do. Please help me:) Thanks for replies -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Fri Jan 18 05:05:14 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 18 Jan 2008 04:05:14 -0600 Subject: [rspec-users] session data and user stories In-Reply-To: <44a5a1d0801161459i46ebfd8et53a2080004701f4@mail.gmail.com> References: <44a5a1d0801161459i46ebfd8et53a2080004701f4@mail.gmail.com> Message-ID: <57c63afe0801180205v297c3627w2a89d77cc36d3895@mail.gmail.com> On Jan 16, 2008 4:59 PM, Evan Short wrote: > hello there, > > i have been trying my hand at this rbehave material, specifically in terms > of integration testing a rails application, and i am curious about the most > friendly way to deal with session data. > > currently, the only way i have found to simulate a session is to open a > session and refer to everything afterward via the @session variable stored > after open_session. it seems to be workable, but is far from ideal: > > dir = File.dirname(__FILE__) > require 'rubygems' > require 'spec/story' > require "#{dir}/helper" > > steps_for(:dealer_login) do > Given("I have opened a session") do > @session = open_session > end > > Given("I am not logged in") do > @session.instance_variable_get("@session").should == nil > end > > Given("I have a valid login/password combo") do > @login_with = valid_dealer_credentials > end > > When("I submit my login/ password") do > @session.post("/gateway", :user=> @login_with) > end > > #there has to be a better way to address this > Then("I should be authenticated") do > @session.response.session.data.should == {:id => 1, "flash" => {}} > end > > #and this is just hideous. > Then("I should be sent to the dealer landing page") do > puts @session.response.instance_variable_get("@redirected_to").should > == {:controller => "dealers"} > end > end > > with_steps_for(:dealer_login) do > run_local_story "dealer_story", :type=>RailsStory > end > > there is a good chance someone has already covered this and i have just > managed to miss it. documentation on rbehave is sparse (at best, as i have > seen it. i have the peepcode, but if anyone has any other good resources i > would be more than appreciative.) > > in the event that this has not been addressed, i see two possibilities: > > first, that i am somehow subverting the intention of rbehave. as i > understand it, however, rbehave is at least partially intended for > integration-level specification, so it seems to me that this session > information would be valuable. > > on the other hand, perhaps this needs to be addressed in some way. i would > be happy to help, but i am interested to see the community's opinion on the > issue first. RailsStory derives from ActionController::IntegrationTest, which provides an implicit session. You also get rspec's matchers built right in. Also, being logged in is not really behaviour - it's state. All of that said (the following is not tested, but it's the right idea): Story: dealer visits landing page As a dealer I want the dealer landing page to be secure So that only dealers can see dealer stuff Scenario: anonymous user tries to visit landing page Given I am an anonymous user When I visit the dealer landing page Then I should see the login form Scenario: registered dealer logs in Given I am a registered dealer When I log in Then I should see the dealer landing page steps_for(:dealer_login) do Given("I am an anonymous user") do # noop end Given("I am a registered dealer") do User.create!(registered_dealer_attributes) @credentials = registered_dealer_credentials end Given("I visit the $page") do |page| case page when "dealer landing page" get "/dealers" else raise "I don't know how to get to the #{page}" end follow_redirect if redirect? end When("I log in") do post "/gateway", :user => @credentials end Then("I should see the $page") do |page| case page when "dealer landing page" template = "/dealers/index" else raise "I don't know how what template to expect for #{page}" end follow_redirect if redirect? end end There are more things to generalize here as things build up. For example, I've got one step definition that looks like this: Then("I should see the $page") do |page| page_map = { "user form" => "users/form", "login form" => "sessions/new", "thank you page" => "users/index", "user list" => "users/index", "group list" => "groups/index", "welcome page" => "welcome/index" } unless page_map[page].nil? response.should render_template(page_map[page]) else raise "I don't know what template to look for for #{page.inspect}" end end And a similar one for "When I visit the foo page". You *can* use an explicit session, but this is mostly useful if you have more than one session running simultaneously. Check out docs for rails integration tests to get some more insight on this. There's a lot more to talk about here, but that should get you going. HTH. Cheers, David From dchelimsky at gmail.com Fri Jan 18 05:09:36 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 18 Jan 2008 04:09:36 -0600 Subject: [rspec-users] Rspec problem in testing RoR application In-Reply-To: <3361858a39d0100f1fd08d5decebe8ac@ruby-forum.com> References: <3361858a39d0100f1fd08d5decebe8ac@ruby-forum.com> Message-ID: <57c63afe0801180209x6f727e7bu9a88eb6618253bc9@mail.gmail.com> On Jan 18, 2008 3:57 AM, Anton Komarov wrote: > Hello. > I install gems rspec and rspec_on_rails For rails, don't use the gem. Install both as plugins: http://rspec.info/documentation/rails/install.html > I have this Error when try to run Rspec tests on my RoR application: > /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:263:in > `load_missing_constant': uninitialized constant > ActionView::Helpers::JavaScriptMacrosHelper (NameError) > > And I follow recipes wich are placed in > http://rubyforge.org/pipermail/rspec-devel/2007-September/004032.html > But it make another one Error: > > /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:263:in > `load_missing_constant': uninitialized constant Spec::VERSION::REV > (NameError) > from > /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:453:in > `const_missing' > from > /home/anton/tele/trunk/vendor/plugins/rspec_on_rails/lib/spec/rails/version.rb:13 > from /usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in > `gem_original_require' > from /usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in > `require' > from > /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in > `require' > from > /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in > `new_constants_in' > from > /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in > `require' > from > /home/anton/tele/trunk/vendor/plugins/rspec_on_rails/lib/spec/rails.rb:16 > ... 11 levels... > from > /var/lib/gems/1.8/gems/rspec-1.1.2/lib/spec/runner/example_group_runner.rb:13:in > `load_files' > from > /var/lib/gems/1.8/gems/rspec-1.1.2/lib/spec/runner/options.rb:83:in > `run_examples' > from > /var/lib/gems/1.8/gems/rspec-1.1.2/lib/spec/runner/command_line.rb:19:in > `run' > from /var/lib/gems/1.8/gems/rspec-1.1.2/bin/spec:4 > > And I don't now what I must to do. > Please help me:) > Thanks for replies > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Fri Jan 18 05:31:12 2008 From: lists at ruby-forum.com (Anton Komarov) Date: Fri, 18 Jan 2008 11:31:12 +0100 Subject: [rspec-users] Rspec problem in testing RoR application In-Reply-To: <57c63afe0801180209x6f727e7bu9a88eb6618253bc9@mail.gmail.com> References: <3361858a39d0100f1fd08d5decebe8ac@ruby-forum.com> <57c63afe0801180209x6f727e7bu9a88eb6618253bc9@mail.gmail.com> Message-ID: <05bd7f61c22196b0c38ac45e6651fd99@ruby-forum.com> Thank you for your feedback. I'll try this and it's work now:) -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Fri Jan 18 10:16:28 2008 From: lists at ruby-forum.com (Anton Komarov) Date: Fri, 18 Jan 2008 16:16:28 +0100 Subject: [rspec-users] new in ruby and rspec testing Message-ID: Hi to all I'm a new in ruby and RoR programming. And my problem is Rspec. I don't understand how to write test files in rspec. Maybe it's because I don't know ruby good. Can you send me links to fine examples/screencasts/e-books and other stuff. I found some on google but it not enough :( Thanks for replie's -- Posted via http://www.ruby-forum.com/. From kevwil at gmail.com Fri Jan 18 10:47:20 2008 From: kevwil at gmail.com (Kevin Williams) Date: Fri, 18 Jan 2008 08:47:20 -0700 Subject: [rspec-users] new in ruby and rspec testing In-Reply-To: References: Message-ID: <683a886f0801180747j549b9149q25ad13a625d79732@mail.gmail.com> I find the website to be full of great examples. (wish it were available offline) http://rspec.info On Jan 18, 2008 8:16 AM, Anton Komarov wrote: > Hi to all > I'm a new in ruby and RoR programming. > And my problem is Rspec. > I don't understand how to write test files in rspec. > Maybe it's because I don't know ruby good. > Can you send me links to fine examples/screencasts/e-books and other > stuff. > I found some on google but it not enough :( > Thanks for replie's > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Cheers, Kevin Williams http://www.bantamtech.com/ From mailing_lists at railsnewbie.com Fri Jan 18 10:56:15 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Fri, 18 Jan 2008 10:56:15 -0500 Subject: [rspec-users] new in ruby and rspec testing In-Reply-To: <683a886f0801180747j549b9149q25ad13a625d79732@mail.gmail.com> References: <683a886f0801180747j549b9149q25ad13a625d79732@mail.gmail.com> Message-ID: On Jan 18, 2008, at 10:47 AM, Kevin Williams wrote: > I find the website to be full of great examples. (wish it were > available offline) wget and svn are your friends. Scott From kevwil at gmail.com Fri Jan 18 11:02:12 2008 From: kevwil at gmail.com (Kevin Williams) Date: Fri, 18 Jan 2008 09:02:12 -0700 Subject: [rspec-users] new in ruby and rspec testing In-Reply-To: References: <683a886f0801180747j549b9149q25ad13a625d79732@mail.gmail.com> Message-ID: <683a886f0801180802r408cded6pc4443da0b0e39bd0@mail.gmail.com> I've got the source and tried to build the docs, but it has no css and the links are bad. On Jan 18, 2008 8:56 AM, Scott Taylor wrote: > > On Jan 18, 2008, at 10:47 AM, Kevin Williams wrote: > > > I find the website to be full of great examples. (wish it were > > available offline) > > wget and svn are your friends. > > Scott > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Cheers, Kevin Williams http://www.bantamtech.com/ From george at benevolentcode.com Fri Jan 18 11:04:41 2008 From: george at benevolentcode.com (George Anderson) Date: Fri, 18 Jan 2008 11:04:41 -0500 Subject: [rspec-users] new in ruby and rspec testing In-Reply-To: References: Message-ID: <782d66f30801180804n36c7c981y4949d63fe31f3245@mail.gmail.com> Peepcode is likely your best bet for coherent information, at least until the book comes out: http://peepcode.com/products/test-first-development (this uses Test::Unit IIRC, but gives a good into to BDD) http://peepcode.com/products/rspec-basics http://peepcode.com/products/rspec-mocks-and-models http://peepcode.com/products/rspec-controllers-and-tools http://peepcode.com/products/rspec-user-stories They aren't free, but reasonably priced: $9. /g On 1/18/08, Anton Komarov wrote: > Hi to all > I'm a new in ruby and RoR programming. > And my problem is Rspec. > I don't understand how to write test files in rspec. > Maybe it's because I don't know ruby good. > Can you send me links to fine examples/screencasts/e-books and other > stuff. > I found some on google but it not enough :( > Thanks for replie's > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- George Anderson BenevolentCode LLC O: (410) 461-7553 C: (410) 218-5185 george at benevolentcode.com From hotfusionman at yahoo.com Fri Jan 18 11:00:17 2008 From: hotfusionman at yahoo.com (Al Chou) Date: Fri, 18 Jan 2008 08:00:17 -0800 (PST) Subject: [rspec-users] new in ruby and rspec testing Message-ID: <416477.8855.qm@web58710.mail.re1.yahoo.com> You can always spider the site (e.g., use Web Site Sucker on the Mac). Depending on which spider utility you use, you may have to do some manual editing afterward; Web Site Sucker, for instance, doesn't rewrite the absolute path to the CSS stylesheet into relative paths, which means that you don't get the nice styled appearance until you do that. Or I suppose you could pour the spidered content into a local Web server of your own, to work around that issue. Al ----- Original Message ---- From: Kevin Williams To: rspec-users at rubyforge.org Sent: Friday, January 18, 2008 7:47:20 AM Subject: Re: [rspec-users] new in ruby and rspec testing I find the website to be full of great examples. (wish it were available offline) http://rspec.info On Jan 18, 2008 8:16 AM, Anton Komarov wrote: > Hi to all > I'm a new in ruby and RoR programming. > And my problem is Rspec. > I don't understand how to write test files in rspec. > Maybe it's because I don't know ruby good. > Can you send me links to fine examples/screencasts/e-books and other > stuff. > I found some on google but it not enough :( > Thanks for replie's > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Cheers, Kevin Williams http://www.bantamtech.com/ ____________________________________________________________________________________ Looking for last minute shopping deals? Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080118/7bad8635/attachment.html From dchelimsky at gmail.com Fri Jan 18 11:32:22 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 18 Jan 2008 10:32:22 -0600 Subject: [rspec-users] new in ruby and rspec testing In-Reply-To: <683a886f0801180802r408cded6pc4443da0b0e39bd0@mail.gmail.com> References: <683a886f0801180747j549b9149q25ad13a625d79732@mail.gmail.com> <683a886f0801180802r408cded6pc4443da0b0e39bd0@mail.gmail.com> Message-ID: <57c63afe0801180832w755096f0k3b54be8c2fd25386@mail.gmail.com> On Jan 18, 2008 10:02 AM, Kevin Williams wrote: > I've got the source and tried to build the docs, but it has no css and > the links are bad. How are you trying to build the docs? Are you talking about rdoc or the website docs? From kevwil at gmail.com Fri Jan 18 11:54:12 2008 From: kevwil at gmail.com (Kevin Williams) Date: Fri, 18 Jan 2008 09:54:12 -0700 Subject: [rspec-users] new in ruby and rspec testing In-Reply-To: <57c63afe0801180832w755096f0k3b54be8c2fd25386@mail.gmail.com> References: <683a886f0801180747j549b9149q25ad13a625d79732@mail.gmail.com> <683a886f0801180802r408cded6pc4443da0b0e39bd0@mail.gmail.com> <57c63afe0801180832w755096f0k3b54be8c2fd25386@mail.gmail.com> Message-ID: <683a886f0801180854v1a1c1241h555198f9888dc222@mail.gmail.com> The website. I cd into the /doc directory and ran the rake task to create the site. The pages seem to be there, but some links are broken and there are no css or image files. On Jan 18, 2008 9:32 AM, David Chelimsky wrote: > On Jan 18, 2008 10:02 AM, Kevin Williams wrote: > > I've got the source and tried to build the docs, but it has no css and > > the links are bad. > > How are you trying to build the docs? Are you talking about rdoc or > the website docs? > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Cheers, Kevin Williams http://www.bantamtech.com/ From ben at benmabey.com Fri Jan 18 11:57:06 2008 From: ben at benmabey.com (Ben Mabey) Date: Fri, 18 Jan 2008 09:57:06 -0700 Subject: [rspec-users] new in ruby and rspec testing In-Reply-To: <683a886f0801180854v1a1c1241h555198f9888dc222@mail.gmail.com> References: <683a886f0801180747j549b9149q25ad13a625d79732@mail.gmail.com> <683a886f0801180802r408cded6pc4443da0b0e39bd0@mail.gmail.com> <57c63afe0801180832w755096f0k3b54be8c2fd25386@mail.gmail.com> <683a886f0801180854v1a1c1241h555198f9888dc222@mail.gmail.com> Message-ID: <4790DA62.6050709@benmabey.com> Kevin Williams wrote: > The website. I cd into the /doc directory and ran the rake task to > create the site. The pages seem to be there, but some links are broken > and there are no css or image files. > > On Jan 18, 2008 9:32 AM, David Chelimsky wrote: > >> On Jan 18, 2008 10:02 AM, Kevin Williams wrote: >> >>> I've got the source and tried to build the docs, but it has no css and >>> the links are bad. >>> >> How are you trying to build the docs? Are you talking about rdoc or >> the website docs? >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> >> > > > > As Scott said... wget is your friend: wget --recursive --html-extension --convert-links --domains=rspec.info http://rspec.info That command will put the entire site content along with CSS and all with links made local in a nice little rspec.info dir. :) -Ben From rspec at showcase60.com Fri Jan 18 13:03:43 2008 From: rspec at showcase60.com (David Richards) Date: Fri, 18 Jan 2008 10:03:43 -0800 Subject: [rspec-users] Spam Protection In-Reply-To: References: Message-ID: <47D42C03-89FE-4487-8D4F-30AF69F8032E@showcase60.com> I was disgruntled with the amount of spam I was getting, so I started setting up accounts for the various mailing lists I listen to. I use rspec at showcase60.com to read the mail here. Along with the rspec news that comes over this channel, I'm getting more and more spam addressed to this same account, which means that the open way this list passes around email addresses is being read or fed to spammers. I suggest we rethink our mailing lists so that we're not also subjecting RSpec enthusiasts with tips on various medical enhancements and financial products. Maybe we should use a Google group instead, where they don't broadcast email addresses in open formats with their services. Maybe someone else has a better idea about this. David From nathan.sutton at gmail.com Fri Jan 18 13:21:33 2008 From: nathan.sutton at gmail.com (Nathan Sutton) Date: Fri, 18 Jan 2008 12:21:33 -0600 Subject: [rspec-users] Spam Protection In-Reply-To: <47D42C03-89FE-4487-8D4F-30AF69F8032E@showcase60.com> References: <47D42C03-89FE-4487-8D4F-30AF69F8032E@showcase60.com> Message-ID: <47CB594B-3560-4FFE-ABA8-5F28D6A53AFD@gmail.com> I made this address for mailing lists only, but as it is I only have 14 spam messages at the moment... Nathan Sutton fowlduck at gmail.com rspec 1.1 rspec_on_rails 1.1 rails 2.0.2 On Jan 18, 2008, at 12:03 PM, David Richards wrote: > I was disgruntled with the amount of spam I was getting, so I started > setting up accounts for the various mailing lists I listen to. I use > rspec at showcase60.com to read the mail here. Along with the rspec > news that comes over this channel, I'm getting more and more spam > addressed to this same account, which means that the open way this > list passes around email addresses is being read or fed to spammers. > > I suggest we rethink our mailing lists so that we're not also > subjecting RSpec enthusiasts with tips on various medical > enhancements and financial products. Maybe we should use a Google > group instead, where they don't broadcast email addresses in open > formats with their services. Maybe someone else has a better idea > about this. > > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From mark at mwilden.com Fri Jan 18 13:27:52 2008 From: mark at mwilden.com (Mark Wilden) Date: Fri, 18 Jan 2008 10:27:52 -0800 Subject: [rspec-users] Spam Protection In-Reply-To: <47CB594B-3560-4FFE-ABA8-5F28D6A53AFD@gmail.com> References: <47D42C03-89FE-4487-8D4F-30AF69F8032E@showcase60.com> <47CB594B-3560-4FFE-ABA8-5F28D6A53AFD@gmail.com> Message-ID: <000001c859ff$d740f470$85c2dd50$@com> From: rspec-users-bounces at rubyforge.org [mailto:rspec-users-bounces at rubyforge.org] On Behalf Of Nathan Sutton Sent: Friday, January 18, 2008 10:22 AM To: rspec-users Subject: Re: [rspec-users] Spam Protection >I made this address for mailing lists only, but as it is I only have >14 spam messages at the moment... What's weird is that I've been using the same email address since 1996, I've turned off spam filtering by my ISP, and yet I get very, very little spam these days (maybe 1-2/day). Wonder if it's being filtered upstream? ///ark From pergesu at gmail.com Fri Jan 18 13:36:45 2008 From: pergesu at gmail.com (Pat Maddox) Date: Fri, 18 Jan 2008 10:36:45 -0800 Subject: [rspec-users] Spam Protection In-Reply-To: <47D42C03-89FE-4487-8D4F-30AF69F8032E@showcase60.com> References: <47D42C03-89FE-4487-8D4F-30AF69F8032E@showcase60.com> Message-ID: <810a540e0801181036i7cce6ea8j3aa69f51a5bdf001@mail.gmail.com> > Maybe someone else has a better idea about this. Use gmail. I get spam, but I never see it. see http://www.bofh.org.uk/articles/2007/09/26/slide-of-the-conference Pat From bryan at osesm.com Fri Jan 18 14:40:31 2008 From: bryan at osesm.com (Bryan Liles) Date: Fri, 18 Jan 2008 14:40:31 -0500 Subject: [rspec-users] CC.rb and RSpec Message-ID: <209FBAB1-FBC6-4B31-979F-E6B6FDEE8FF7@osesm.com> When trying to configure a rspec 1.1.2 based app in CC.rb, I came across the following: /home/bryan/cruisecontrolrb-1.2.1/projects/support-engines/work/vendor/ plugins/rspec_on_rails/lib/spec/rails/../../../../rspec/lib/spec/ runner/options.rb:218:in `files_to_load': File or directory not found: cc:build (RuntimeError) from /home/bryan/cruisecontrolrb-1.2.1/projects/support-engines/work/ vendor/plugins/rspec_on_rails/lib/spec/rails/../../../../rspec/lib/ spec/runner/options.rb:212:in `each' from /home/bryan/cruisecontrolrb-1.2.1/projects/support-engines/work/ vendor/plugins/rspec_on_rails/lib/spec/rails/../../../../rspec/lib/ spec/runner/options.rb:212:in `files_to_load' from /home/bryan/cruisecontrolrb-1.2.1/projects/support-engines/work/ vendor/plugins/rspec_on_rails/lib/spec/rails/../../../../rspec/lib/ spec/runner/options.rb:83:in `run_examples' from /home/bryan/cruisecontrolrb-1.2.1/projects/support-engines/work/ vendor/plugins/rspec_on_rails/lib/spec/rails/../../../../rspec/lib/ spec.rb:20:in `run' from /home/bryan/cruisecontrolrb-1.2.1/projects/support-engines/work/ vendor/plugins/rspec_on_rails/lib/spec/rails/../../../../rspec/lib/ spec.rb:35 I had a solution that would monkey patch over this, but now I'm looking for some help in actually explaining why this happens. It looks like rspec is pulling files off the command rake command line. From bryan at osesm.com Fri Jan 18 16:21:00 2008 From: bryan at osesm.com (Bryan Liles) Date: Fri, 18 Jan 2008 16:21:00 -0500 Subject: [rspec-users] CC.rb and RSpec In-Reply-To: <209FBAB1-FBC6-4B31-979F-E6B6FDEE8FF7@osesm.com> References: <209FBAB1-FBC6-4B31-979F-E6B6FDEE8FF7@osesm.com> Message-ID: On Jan 18, 2008, at 2:40 PM, Bryan Liles wrote: > When trying to configure a rspec 1.1.2 based app in CC.rb, I came > across the following: > > ..... > > I had a solution that would monkey patch over this, but now I'm > looking for some help in actually explaining why this happens. It > looks like rspec is pulling files off the command rake command line. I removed the at_exit block from rspec/lib/spec.rb, and life is happy. What exactly did that thing do again? From dchelimsky at gmail.com Fri Jan 18 16:28:13 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 18 Jan 2008 15:28:13 -0600 Subject: [rspec-users] CC.rb and RSpec In-Reply-To: References: <209FBAB1-FBC6-4B31-979F-E6B6FDEE8FF7@osesm.com> Message-ID: <57c63afe0801181328x14ae56e4x3f7ffb010259b96c@mail.gmail.com> On Jan 18, 2008 3:21 PM, Bryan Liles wrote: > > On Jan 18, 2008, at 2:40 PM, Bryan Liles wrote: > > > When trying to configure a rspec 1.1.2 based app in CC.rb, I came > > across the following: > > > > ..... > > > > I had a solution that would monkey patch over this, but now I'm > > looking for some help in actually explaining why this happens. It > > looks like rspec is pulling files off the command rake command line. > > I removed the at_exit block from rspec/lib/spec.rb, and life is > happy. What exactly did that thing do again? http://rspec.lighthouseapp.com/projects/5645-rspec/tickets/242 > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jed.hurt at gmail.com Fri Jan 18 22:16:17 2008 From: jed.hurt at gmail.com (Jed Hurt) Date: Fri, 18 Jan 2008 20:16:17 -0700 Subject: [rspec-users] Quiet Backtrace in RSpec Message-ID: I'm using RSpec on Rails and would like to clean up the backtraces, so I went looking for an RSpec equivalent to ThoughtBot's Quiet Backtrace gem. I found Spec::Runner::QuietBacktraceTweaker in the RDOCS, but I can't figure out how to use it. Can I add something to spec_helper.rb that will utilize Spec::Runner::QuietBacktraceTweaker to quiet the backtraces? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080118/f270c5bf/attachment.html From davidj503 at gmail.com Fri Jan 18 23:47:17 2008 From: davidj503 at gmail.com (David James) Date: Fri, 18 Jan 2008 23:47:17 -0500 Subject: [rspec-users] "should_not ==" vs "should !=" Message-ID: <59b5d4330801182047t6b623098o9487d7477514109d@mail.gmail.com> describe "should_not == vs. should !=" it do 5.should_not == 6 end # passes it do 5.should != 6 end # fails end # I'm running the rspec 1.1.2 gem with the corresponding Textmate bundle # The second failure surprises me. # Is != not supported? # I'd like to hear what you all think. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080118/e36d50ca/attachment.html From dchelimsky at gmail.com Sat Jan 19 01:36:18 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 19 Jan 2008 00:36:18 -0600 Subject: [rspec-users] "should_not ==" vs "should !=" In-Reply-To: <59b5d4330801182047t6b623098o9487d7477514109d@mail.gmail.com> References: <59b5d4330801182047t6b623098o9487d7477514109d@mail.gmail.com> Message-ID: <57c63afe0801182236h67cbfbbj7c923890d064db45@mail.gmail.com> On Jan 18, 2008 10:47 PM, David James wrote: > describe "should_not == vs. should !=" > it do > 5.should_not == 6 > end # passes > > it do > 5.should != 6 > end # fails > end > > # I'm running the rspec 1.1.2 gem with the corresponding Textmate bundle > # The second failure surprises me. > # Is != not supported? Sadly, yes. It is not supported. Because Ruby does not support it. When you say 5 == 3, what that is really saying is 5.==(3), which is how we're able to support 5.should == 3 (becomes 5.should.==(3)). No such luck w/ !=. C'est la vie. Cheers, David > # I'd like to hear what you all think. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From aslak.hellesoy at gmail.com Sat Jan 19 03:39:31 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Sat, 19 Jan 2008 09:39:31 +0100 Subject: [rspec-users] Quiet Backtrace in RSpec In-Reply-To: References: Message-ID: <8d961d900801190039x7c973fb3xad1052df557c2e45@mail.gmail.com> On Jan 19, 2008 4:16 AM, Jed Hurt wrote: > I'm using RSpec on Rails and would like to clean up the backtraces, so I > went looking for an RSpec equivalent to ThoughtBot's Quiet Backtrace gem. I > found Spec::Runner::QuietBacktraceTweaker in the RDOCS, but I can't figure > out how to use it. Can I add something to spec_helper.rb that will utilize > Spec::Runner::QuietBacktraceTweaker to quiet the backtraces? It's on by default, and you can turn it off with -b on the command line Thanks for telling me about the Quiet Backtrace gem, I've added a ticket for that: http://rspec.lighthouseapp.com/projects/5645-rspec/tickets/243-add-support-for-quietbacktrace-gem Aslak > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From coreyhaines at gmail.com Sat Jan 19 12:41:41 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Sat, 19 Jan 2008 12:41:41 -0500 Subject: [rspec-users] autotest problem? Message-ID: <6bdacb70801190941s58cb3aaex1427308ce5ddcb3@mail.gmail.com> I'm hoping someone on this list will be able to help. I just updated zentest, rspec plugin and rspec_on_rails plugin, and I get the following exception when I run autotest. I realize that the -O is causing the problem, but I'm not sure how to get it not to pass it. Also, it seems strange that it is going through the Test::Unit runner, unless that is because of the recent work to get rspec compatible with Test::Unit? Exception below c:\ruby\bin\ruby -rrubygems -e "require 'redgreen'" -S script/spec -O spec/spec.opts spec/controllers/coupon_controlle r_spec.rb spec/models/coupon_spec.rb spec/helpers/coupon_helper_spec.rb spec/views/coupon/index.html.erb_spec.rb invalid option: -O Test::Unit automatic runner. Usage: -e [options] [-- untouched arguments] -r, --runner=RUNNER Use the given RUNNER. (c[onsole], f[ox], g[tk], g[tk]2, t[k]) -b, --basedir=DIR Base directory of test suites. -w, --workdir=DIR Working directory to run tests. -a, --add=TORUN Add TORUN to the list of things to run; can be a file or a directory. -p, --pattern=PATTERN Match files to collect against PATTERN. -x, --exclude=PATTERN Ignore files to collect against PATTERN. -n, --name=NAME Runs tests matching NAME. (patterns may be used). -t, --testcase=TESTCASE Runs tests in TestCases matching TESTCASE. (patterns may be used). -I, --load-path=DIR[;DIR...] Appends directory list to $LOAD_PATH. -v, --verbose=[LEVEL] Set the output level (default is verbose). (s[ilent], p[rogress], n[ormal], v[erbose]) -- Stop processing options so that the remaining options will be passed to the test. -h, --help Display this help. Deprecated options: --console Console runner (use --runner). --gtk GTK runner (use --runner). --fox Fox runner (use --runner). -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080119/b11b35f0/attachment.html From dchelimsky at gmail.com Sat Jan 19 12:47:17 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 19 Jan 2008 11:47:17 -0600 Subject: [rspec-users] autotest problem? In-Reply-To: <6bdacb70801190941s58cb3aaex1427308ce5ddcb3@mail.gmail.com> References: <6bdacb70801190941s58cb3aaex1427308ce5ddcb3@mail.gmail.com> Message-ID: <57c63afe0801190947w6b55240m473c563aa12335df@mail.gmail.com> On Jan 19, 2008 11:41 AM, Corey Haines wrote: > I'm hoping someone on this list will be able to help. I just updated > zentest, rspec plugin and rspec_on_rails plugin What versions? Please include this information when asking questions like this. > and I get the following > exception when I run autotest. I realize that the -O is causing the problem, > but I'm not sure how to get it not to pass it. Also, it seems strange that > it is going through the Test::Unit runner, unless that is because of the > recent work to get rspec compatible with Test::Unit? rspec_on_rails has always gone through test/unit, but this seems a bit odd. There were significant changes to ZenTest-3.8.0 and RSpec-1.1.2 in the way they interact and load files. Any chance that you have a .autotest file set up? If so, what's in it? > > Exception below > > c:\ruby\bin\ruby -rrubygems -e "require 'redgreen'" -S script/spec -O > spec/spec.opts spec/controllers/coupon_controlle > r_spec.rb spec/models/coupon_spec.rb spec/helpers/coupon_helper_spec.rb > spec/views/coupon/index.html.erb_spec.rb > invalid option: -O > Test::Unit automatic runner. > Usage: -e [options] [-- untouched arguments] > > -r, --runner=RUNNER Use the given RUNNER. > (c[onsole], f[ox], g[tk], g[tk]2, t[k]) > -b, --basedir=DIR Base directory of test suites. > -w, --workdir=DIR Working directory to run tests. > -a, --add=TORUN Add TORUN to the list of things to run; > can be a file or a directory. > -p, --pattern=PATTERN Match files to collect against PATTERN. > -x, --exclude=PATTERN Ignore files to collect against > PATTERN. > -n, --name=NAME Runs tests matching NAME. > (patterns may be used). > -t, --testcase=TESTCASE Runs tests in TestCases matching > TESTCASE. > (patterns may be used). > -I, --load-path=DIR[;DIR...] Appends directory list to $LOAD_PATH. > -v, --verbose=[LEVEL] Set the output level (default is > verbose). > (s[ilent], p[rogress], n[ormal], > v[erbose]) > -- Stop processing options so that the > remaining options will be passed to the > test. > -h, --help Display this help. > > Deprecated options: > --console Console runner (use --runner). > --gtk GTK runner (use --runner). > --fox Fox runner (use --runner). > > -- > http://www.coreyhaines.com > The Internet's Premiere source of information about Corey Haines > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From coreyhaines at gmail.com Sat Jan 19 12:54:53 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Sat, 19 Jan 2008 12:54:53 -0500 Subject: [rspec-users] autotest problem? In-Reply-To: <57c63afe0801190947w6b55240m473c563aa12335df@mail.gmail.com> References: <6bdacb70801190941s58cb3aaex1427308ce5ddcb3@mail.gmail.com> <57c63afe0801190947w6b55240m473c563aa12335df@mail.gmail.com> Message-ID: <6bdacb70801190954t6fefb2bamd0e9cda2499f8c9f@mail.gmail.com> sorry, keep forgetting about the versions. Here's the gem list ZenTest (3.8.0, 3.7.2, 3.7.1, 3.6.1) redgreen (1.2.2) ruby-snarl (0.0.8) Here's the rspec plugin RSpec-1.1.2 (build 20080114022430) - BDD for Ruby I'm not totally sure how to get the version for the rspec_on_rails plugin, but I just did an update this morning. Here's my .autotest require 'redgreen/autotest' require 'Win32/Console/ANSI' require 'autotest/snarl' $VERBOSE=false -Corey On Jan 19, 2008 12:47 PM, David Chelimsky wrote: > On Jan 19, 2008 11:41 AM, Corey Haines wrote: > > I'm hoping someone on this list will be able to help. I just updated > > zentest, rspec plugin and rspec_on_rails plugin > > What versions? Please include this information when asking questions like > this. > > > and I get the following > > exception when I run autotest. I realize that the -O is causing the > problem, > > but I'm not sure how to get it not to pass it. Also, it seems strange > that > > it is going through the Test::Unit runner, unless that is because of the > > recent work to get rspec compatible with Test::Unit? > > rspec_on_rails has always gone through test/unit, but this seems a bit > odd. There were significant changes to ZenTest-3.8.0 and RSpec-1.1.2 > in the way they interact and load files. Any chance that you have a > .autotest file set up? If so, what's in it? > > > > > Exception below > > > > c:\ruby\bin\ruby -rrubygems -e "require 'redgreen'" -S script/spec -O > > spec/spec.opts spec/controllers/coupon_controlle > > r_spec.rb spec/models/coupon_spec.rb spec/helpers/coupon_helper_spec.rb > > spec/views/coupon/index.html.erb_spec.rb > > invalid option: -O > > Test::Unit automatic runner. > > Usage: -e [options] [-- untouched arguments] > > > > -r, --runner=RUNNER Use the given RUNNER. > > (c[onsole], f[ox], g[tk], g[tk]2, > t[k]) > > -b, --basedir=DIR Base directory of test suites. > > -w, --workdir=DIR Working directory to run tests. > > -a, --add=TORUN Add TORUN to the list of things to > run; > > can be a file or a directory. > > -p, --pattern=PATTERN Match files to collect against > PATTERN. > > -x, --exclude=PATTERN Ignore files to collect against > > PATTERN. > > -n, --name=NAME Runs tests matching NAME. > > (patterns may be used). > > -t, --testcase=TESTCASE Runs tests in TestCases matching > > TESTCASE. > > (patterns may be used). > > -I, --load-path=DIR[;DIR...] Appends directory list to > $LOAD_PATH. > > -v, --verbose=[LEVEL] Set the output level (default is > > verbose). > > (s[ilent], p[rogress], n[ormal], > > v[erbose]) > > -- Stop processing options so that the > > remaining options will be passed to > the > > test. > > -h, --help Display this help. > > > > Deprecated options: > > --console Console runner (use --runner). > > --gtk GTK runner (use --runner). > > --fox Fox runner (use --runner). > > > > -- > > http://www.coreyhaines.com > > The Internet's Premiere source of information about Corey Haines > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080119/86bfe903/attachment.html From dchelimsky at gmail.com Sat Jan 19 13:02:43 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 19 Jan 2008 12:02:43 -0600 Subject: [rspec-users] autotest problem? In-Reply-To: <6bdacb70801190954t6fefb2bamd0e9cda2499f8c9f@mail.gmail.com> References: <6bdacb70801190941s58cb3aaex1427308ce5ddcb3@mail.gmail.com> <57c63afe0801190947w6b55240m473c563aa12335df@mail.gmail.com> <6bdacb70801190954t6fefb2bamd0e9cda2499f8c9f@mail.gmail.com> Message-ID: <57c63afe0801191002w25fde80ct52baf7ba34fd7c3@mail.gmail.com> On Jan 19, 2008 11:54 AM, Corey Haines wrote: > sorry, keep forgetting about the versions. Here's the gem list > > ZenTest (3.8.0, 3.7.2, 3.7.1, 3.6.1) > redgreen (1.2.2) > ruby-snarl (0.0.8) > > Here's the rspec plugin > RSpec-1.1.2 (build 20080114022430) - BDD for Ruby > > I'm not totally sure how to get the version for the rspec_on_rails plugin, > but I just did an update this morning. > > Here's my .autotest > > require 'redgreen/autotest' > require 'Win32/Console/ANSI' > require 'autotest/snarl' I'm going to guess it's related to one of these libraries. I'm not in a win32 environment so I'm not going to be able to help you debug that - but why don't you try killing these for a moment and see if everything works fine. > > $VERBOSE=false > > -Corey > > > > > On Jan 19, 2008 12:47 PM, David Chelimsky wrote: > > > > On Jan 19, 2008 11:41 AM, Corey Haines < coreyhaines at gmail.com> wrote: > > > I'm hoping someone on this list will be able to help. I just updated > > > zentest, rspec plugin and rspec_on_rails plugin > > > > What versions? Please include this information when asking questions like > this. > > > > > > > and I get the following > > > exception when I run autotest. I realize that the -O is causing the > problem, > > > but I'm not sure how to get it not to pass it. Also, it seems strange > that > > > it is going through the Test::Unit runner, unless that is because of the > > > recent work to get rspec compatible with Test::Unit? > > > > rspec_on_rails has always gone through test/unit, but this seems a bit > > odd. There were significant changes to ZenTest-3.8.0 and RSpec-1.1.2 > > in the way they interact and load files. Any chance that you have a > > .autotest file set up? If so, what's in it? > > > > > > > > > > > > > > Exception below > > > > > > c:\ruby\bin\ruby -rrubygems -e "require 'redgreen'" -S script/spec -O > > > spec/spec.opts spec/controllers/coupon_controlle > > > r_spec.rb spec/models/coupon_spec.rb spec/helpers/coupon_helper_spec.rb > > > spec/views/coupon/index.html.erb_spec.rb > > > invalid option: -O > > > Test::Unit automatic runner. > > > Usage: -e [options] [-- untouched arguments] > > > > > > -r, --runner=RUNNER Use the given RUNNER. > > > (c[onsole], f[ox], g[tk], g[tk]2, > t[k]) > > > -b, --basedir=DIR Base directory of test suites. > > > -w, --workdir=DIR Working directory to run tests. > > > -a, --add=TORUN Add TORUN to the list of things to > run; > > > can be a file or a directory. > > > -p, --pattern=PATTERN Match files to collect against > PATTERN. > > > -x, --exclude=PATTERN Ignore files to collect against > > > PATTERN. > > > -n, --name=NAME Runs tests matching NAME. > > > (patterns may be used). > > > -t, --testcase=TESTCASE Runs tests in TestCases matching > > > TESTCASE. > > > (patterns may be used). > > > -I, --load-path=DIR[;DIR...] Appends directory list to > $LOAD_PATH. > > > -v, --verbose=[LEVEL] Set the output level (default is > > > verbose). > > > (s[ilent], p[rogress], n[ormal], > > > v[erbose]) > > > -- Stop processing options so that the > > > remaining options will be passed to > the > > > test. > > > -h, --help Display this help. > > > > > > Deprecated options: > > > --console Console runner (use --runner). > > > --gtk GTK runner (use --runner). > > > --fox Fox runner (use --runner). > > > > > > -- > > > http://www.coreyhaines.com > > > The Internet's Premiere source of information about Corey Haines > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > -- > > > http://www.coreyhaines.com > The Internet's Premiere source of information about Corey Haines > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From kevwil at gmail.com Sat Jan 19 13:06:08 2008 From: kevwil at gmail.com (Kevin Williams) Date: Sat, 19 Jan 2008 11:06:08 -0700 Subject: [rspec-users] new in ruby and rspec testing In-Reply-To: <4790DA62.6050709@benmabey.com> References: <683a886f0801180747j549b9149q25ad13a625d79732@mail.gmail.com> <683a886f0801180802r408cded6pc4443da0b0e39bd0@mail.gmail.com> <57c63afe0801180832w755096f0k3b54be8c2fd25386@mail.gmail.com> <683a886f0801180854v1a1c1241h555198f9888dc222@mail.gmail.com> <4790DA62.6050709@benmabey.com> Message-ID: <683a886f0801191006g1a8556c0i4c2b86aa9d26bd6@mail.gmail.com> That worked easily enough - thanks! On Jan 18, 2008 9:57 AM, Ben Mabey wrote: > > Kevin Williams wrote: > > The website. I cd into the /doc directory and ran the rake task to > > create the site. The pages seem to be there, but some links are broken > > and there are no css or image files. > > > > On Jan 18, 2008 9:32 AM, David Chelimsky wrote: > > > >> On Jan 18, 2008 10:02 AM, Kevin Williams wrote: > >> > >>> I've got the source and tried to build the docs, but it has no css and > >>> the links are bad. > >>> > >> How are you trying to build the docs? Are you talking about rdoc or > >> the website docs? > >> > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-users at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/rspec-users > >> > >> > > > > > > > > > As Scott said... wget is your friend: > > wget --recursive --html-extension --convert-links --domains=rspec.info > http://rspec.info > > That command will put the entire site content along with CSS and all > with links made local in a nice little rspec.info dir. :) > > -Ben > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Cheers, Kevin Williams http://www.bantamtech.com/ From coreyhaines at gmail.com Sat Jan 19 13:18:54 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Sat, 19 Jan 2008 13:18:54 -0500 Subject: [rspec-users] autotest problem? In-Reply-To: <57c63afe0801191002w25fde80ct52baf7ba34fd7c3@mail.gmail.com> References: <6bdacb70801190941s58cb3aaex1427308ce5ddcb3@mail.gmail.com> <57c63afe0801190947w6b55240m473c563aa12335df@mail.gmail.com> <6bdacb70801190954t6fefb2bamd0e9cda2499f8c9f@mail.gmail.com> <57c63afe0801191002w25fde80ct52baf7ba34fd7c3@mail.gmail.com> Message-ID: <6bdacb70801191018u151c019gb9f828ab2ace4d07@mail.gmail.com> Well, here's something crazy. I took them out, put them back in and it works. Of course, the redgreen coloring isn't working, but autotest seems to be. Strange. Oh well, chalk it up to craziness on my machine (and probably in my head a bit) Thanks, David. -Corey On Jan 19, 2008 1:02 PM, David Chelimsky wrote: > On Jan 19, 2008 11:54 AM, Corey Haines wrote: > > sorry, keep forgetting about the versions. Here's the gem list > > > > ZenTest (3.8.0, 3.7.2, 3.7.1, 3.6.1) > > redgreen (1.2.2) > > ruby-snarl (0.0.8) > > > > Here's the rspec plugin > > RSpec-1.1.2 (build 20080114022430) - BDD for Ruby > > > > I'm not totally sure how to get the version for the rspec_on_rails > plugin, > > but I just did an update this morning. > > > > Here's my .autotest > > > > require 'redgreen/autotest' > > require 'Win32/Console/ANSI' > > require 'autotest/snarl' > > I'm going to guess it's related to one of these libraries. I'm not in > a win32 environment so I'm not going to be able to help you debug that > - but why don't you try killing these for a moment and see if > everything works fine. > > > > > $VERBOSE=false > > > > -Corey > > > > > > > > > > On Jan 19, 2008 12:47 PM, David Chelimsky wrote: > > > > > > On Jan 19, 2008 11:41 AM, Corey Haines < coreyhaines at gmail.com> wrote: > > > > I'm hoping someone on this list will be able to help. I just updated > > > > zentest, rspec plugin and rspec_on_rails plugin > > > > > > What versions? Please include this information when asking questions > like > > this. > > > > > > > > > > and I get the following > > > > exception when I run autotest. I realize that the -O is causing the > > problem, > > > > but I'm not sure how to get it not to pass it. Also, it seems > strange > > that > > > > it is going through the Test::Unit runner, unless that is because of > the > > > > recent work to get rspec compatible with Test::Unit? > > > > > > rspec_on_rails has always gone through test/unit, but this seems a bit > > > odd. There were significant changes to ZenTest-3.8.0 and RSpec-1.1.2 > > > in the way they interact and load files. Any chance that you have a > > > .autotest file set up? If so, what's in it? > > > > > > > > > > > > > > > > > > > > Exception below > > > > > > > > c:\ruby\bin\ruby -rrubygems -e "require 'redgreen'" -S script/spec > -O > > > > spec/spec.opts spec/controllers/coupon_controlle > > > > r_spec.rb spec/models/coupon_spec.rb > spec/helpers/coupon_helper_spec.rb > > > > spec/views/coupon/index.html.erb_spec.rb > > > > invalid option: -O > > > > Test::Unit automatic runner. > > > > Usage: -e [options] [-- untouched arguments] > > > > > > > > -r, --runner=RUNNER Use the given RUNNER. > > > > (c[onsole], f[ox], g[tk], > g[tk]2, > > t[k]) > > > > -b, --basedir=DIR Base directory of test suites. > > > > -w, --workdir=DIR Working directory to run tests. > > > > -a, --add=TORUN Add TORUN to the list of things > to > > run; > > > > can be a file or a directory. > > > > -p, --pattern=PATTERN Match files to collect against > > PATTERN. > > > > -x, --exclude=PATTERN Ignore files to collect against > > > > PATTERN. > > > > -n, --name=NAME Runs tests matching NAME. > > > > (patterns may be used). > > > > -t, --testcase=TESTCASE Runs tests in TestCases > matching > > > > TESTCASE. > > > > (patterns may be used). > > > > -I, --load-path=DIR[;DIR...] Appends directory list to > > $LOAD_PATH. > > > > -v, --verbose=[LEVEL] Set the output level (default > is > > > > verbose). > > > > (s[ilent], p[rogress], > n[ormal], > > > > v[erbose]) > > > > -- Stop processing options so that > the > > > > remaining options will be > passed to > > the > > > > test. > > > > -h, --help Display this help. > > > > > > > > Deprecated options: > > > > --console Console runner (use --runner). > > > > --gtk GTK runner (use --runner). > > > > --fox Fox runner (use --runner). > > > > > > > > -- > > > > http://www.coreyhaines.com > > > > The Internet's Premiere source of information about Corey Haines > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > -- > > > > > > http://www.coreyhaines.com > > The Internet's Premiere source of information about Corey Haines > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080119/e1101761/attachment-0001.html From dchelimsky at gmail.com Sun Jan 20 12:07:12 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 20 Jan 2008 11:07:12 -0600 Subject: [rspec-users] new --pattern option Message-ID: <57c63afe0801200907h588a7fe0ha31f5461cbff5ea0@mail.gmail.com> Hello all, Just a heads up that I made a change (in svn trunk - not yet released) that may change what files get loaded when you run the rake or spec commands. Not a big deal if you've been following convention, but for those who haven't you may need to make a minor adjustment to your rake file or spec.opts. http://blog.davidchelimsky.net/articles/2008/01/20/rspec-new-pattern-option Cheers, David From dchelimsky at gmail.com Sun Jan 20 21:59:02 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 20 Jan 2008 20:59:02 -0600 Subject: [rspec-users] no method error In-Reply-To: <48590bf80801201752p182126d2m1d1033931dc09132@mail.gmail.com> References: <48590bf80801201752p182126d2m1d1033931dc09132@mail.gmail.com> Message-ID: <57c63afe0801201859m46fa4b5fr171bf414f225f644@mail.gmail.com> On Jan 20, 2008 7:52 PM, G-man wrote: > I've set up my tests, and when I run the whole thing, I get this for my > views: > > 3) > NoMethodError in '/chapters/new.html.erb should render new form' > undefined method `process_clean_up_fixtures' for > # > c:/rails/rails_apps/tracker/spec/views/chapters/new.html.erb_spec.rb:15 > script/spec:4: Can we see some code? What do the spec and the view look like? > Also, no word on my autotest question? > > c:\rails\rails_apps\tracker>autotest > loading autotest/rails_rspec > from > C:\Rails\rails_apps\tracker\vendor\plugins\rspec_on_rails\lib\autotest\rails_rspec.rb > C:\Rails\ruby\bin\ruby -rrubygems -e "require 'redgreen'" -S script/spec > -O spec/spec.opts spec/controllers/chapters_routing_spec.rb > invalid option: -O > Test::Unit automatic runner. > Usage: -e [options] [-- untouched arguments] There was another thread about this just a day or two ago. Not sure what exactly the problem is, but there seems to be conflict with redgreen and the changes to autotest in ZenTest-3.8.0. Get rid of that and it should work. > > The script/spec spec/models, etc tests run just fine, however ... it's only > the autotest and these view things that are hanging up ... > > Thanks, > > G > > -- > Happiness is not to have what you want, > But to want what you have! > Gregor Jovanovich 714 651 9969 ... > Father to some, Friend to all From grail at goldweb.com.au Sun Jan 20 20:01:05 2008 From: grail at goldweb.com.au (Alex Satrapa) Date: Mon, 21 Jan 2008 12:01:05 +1100 Subject: [rspec-users] "should_not ==" vs "should !=" In-Reply-To: <57c63afe0801182236h67cbfbbj7c923890d064db45@mail.gmail.com> References: <59b5d4330801182047t6b623098o9487d7477514109d@mail.gmail.com> <57c63afe0801182236h67cbfbbj7c923890d064db45@mail.gmail.com> Message-ID: <9FD30EBC-BB8C-445D-943D-A94C15CE6048@goldweb.com.au> On 19/01/2008, at 17:36 , David Chelimsky wrote: > When you say 5 == 3, what that is really saying is 5.==(3), which is > how we're able to support 5.should == 3 (becomes 5.should.==(3)). Would it be true to say that the reason "5.should != 3" won't work is that somewhere inside Ruby the x != y comparison is remapped to !(x == y), and thus the "5.should != 3" is remapped to "not (5.should.== 3)", with rspec generating a failure when "should" sees false coming back from the "==" method? Or am I barking up the wrong tree and potentially misleading dozens of programmers down the garden path? Alex From grail at goldweb.com.au Sun Jan 20 19:06:49 2008 From: grail at goldweb.com.au (Alex Satrapa) Date: Mon, 21 Jan 2008 11:06:49 +1100 Subject: [rspec-users] Spam Protection In-Reply-To: <000001c859ff$d740f470$85c2dd50$@com> References: <47D42C03-89FE-4487-8D4F-30AF69F8032E@showcase60.com> <47CB594B-3560-4FFE-ABA8-5F28D6A53AFD@gmail.com> <000001c859ff$d740f470$85c2dd50$@com> Message-ID: <748B1948-13CC-4875-818D-B9E0CC0EFF00@goldweb.com.au> On 19/01/2008, at 05:27 , Mark Wilden wrote: > What's weird is that I've been using the same email address since > 1996, I've > turned off spam filtering by my ISP, and yet I get very, very > little spam > these days (maybe 1-2/day). I've been using the same address since 1994, and every time I get spam I complain to the appropriate abuse@ and postmaster@ addresses. I'm not as fortunate as you, today for example I have about 12 spam messages amongst a veritable ocean of articles from mailing lists - the signal to noise ratio is about 20:1 If people are setting up accounts specifically for mailing lists, it might be worth adding a filter to immediately trash messages that don't look like they came from the list. For example, if you have a specific "rspec-users" mail account, filter all messages to the trash if they don't contain "[rspec-users]" in the subject, or "rspec- users at rubyforge.org" in "TO:". In an ideal world there would be no spam, but that's not going to happen until we rid the world of greedy or impure people. I expect that to be at about the same time that Skynet takes over and flying pigs start snowball fights with the legions of hell. Alex From rick.denatale at gmail.com Sun Jan 20 23:57:46 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Sun, 20 Jan 2008 23:57:46 -0500 Subject: [rspec-users] "should_not ==" vs "should !=" In-Reply-To: <9FD30EBC-BB8C-445D-943D-A94C15CE6048@goldweb.com.au> References: <59b5d4330801182047t6b623098o9487d7477514109d@mail.gmail.com> <57c63afe0801182236h67cbfbbj7c923890d064db45@mail.gmail.com> <9FD30EBC-BB8C-445D-943D-A94C15CE6048@goldweb.com.au> Message-ID: On Jan 20, 2008 8:01 PM, Alex Satrapa wrote: > On 19/01/2008, at 17:36 , David Chelimsky wrote: > > > When you say 5 == 3, what that is really saying is 5.==(3), which is > > how we're able to support 5.should == 3 (becomes 5.should.==(3)). > > Would it be true to say that the reason "5.should != 3" won't work is > that somewhere inside Ruby the x != y comparison is remapped to !(x > == y), and thus the "5.should != 3" is remapped to "not (5.should.== > 3)", with rspec generating a failure when "should" sees false coming > back from the "==" method? > > Or am I barking up the wrong tree and potentially misleading dozens > of programmers down the garden path? I'm 99 44/100% sure that you have it right. The expression x != y is syntactic sugar for !(x == y) much like x += y is syntactic sugar for x = (x +y) The parser turns these into an internal representation (abstract syntax tree for 1.8, byte-codes for 1.9) which is identical to the second form. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From rick.denatale at gmail.com Mon Jan 21 00:09:34 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Mon, 21 Jan 2008 00:09:34 -0500 Subject: [rspec-users] Story runner "macros" Message-ID: I've gotten quite a bit out of Pat Maddox's screencast http://evang.eli.st/blog/2007/10/8/story-runner-top-to-bottom-screencast One thing I'm not sure of is the feature where he writes things like: When "I POST to", "/articles", :post => {:title => "Title", :body => "Body") do | path, params| post_via_redirect path, params end This bothers me because it seems an abrupt level jump. Most of the stories are written at a level where the goal donor can understand them, For example, I'm pretty sure that the above when clause started life as somethign more like When "I add an article" I actually changed Pat's example a bit to use article instead of post to keep the domain and implementation nouns different. I'd say that the "add an article" form is easily understood by a client, but the "POST to ", ... form is not. When I try the parameterized form, I notice that the story runner only reports the story as When I post to So the output is even less useful for talking to the client. Now I really like the idea of the parameterized stories, but the step away from client-speak makes me shy away from them. Is there a way to get the power without loosing the intelligibility? -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From raasdnil at gmail.com Mon Jan 21 00:47:44 2008 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Mon, 21 Jan 2008 16:47:44 +1100 Subject: [rspec-users] autotest hanging Message-ID: <57a815bf0801202147u3d7b1883vbdd88668ef225565@mail.gmail.com> Heya guys & gals, I have to do some development on a Windows box, hitting a stupid problem, wondering if anyone on the list knows how to solve it. I had RSpec 1.1.1 and ZenTest 3.6.1 - this was working fine with autotest (though no colour output). I updated to rspec 1.1.2 and zentest 3.8.0 and now autotest hangs, it seems, on initializing the environment. The list of the tests come up, and then it sits there for at least 5 minutes before I have ctrl-c'd it (it then responds and restarts). rake spec works fine and now gives a nice green output. Anyone else had this problem? Regards Mikel From pergesu at gmail.com Mon Jan 21 00:48:25 2008 From: pergesu at gmail.com (Pat Maddox) Date: Sun, 20 Jan 2008 21:48:25 -0800 Subject: [rspec-users] Story runner "macros" In-Reply-To: References: Message-ID: <810a540e0801202148wd90101dx5f138c83a55a3c47@mail.gmail.com> On Jan 20, 2008 9:09 PM, Rick DeNatale wrote: > Now I really like the idea of the parameterized stories, but the step > away from client-speak makes me shy away from them. Is there a way to > get the power without loosing the intelligibility? If I were to redo that, it would be something more like When "I create an article titled 'The Title' with a body of 'this is the body'" I totally agree that you should be speaking entirely in domain terms. I'm still learning too :) Also since this is related, for any Bay Area RSpec'ers, I'm giving a presentation on Story Runner at Tuesday's meetup. Check out http://ruby.meetup.com/6/calendar/6665552/ for time and location info. Pat From ben at benmabey.com Mon Jan 21 01:00:51 2008 From: ben at benmabey.com (Ben Mabey) Date: Sun, 20 Jan 2008 23:00:51 -0700 Subject: [rspec-users] Story runner "macros" In-Reply-To: <810a540e0801202148wd90101dx5f138c83a55a3c47@mail.gmail.com> References: <810a540e0801202148wd90101dx5f138c83a55a3c47@mail.gmail.com> Message-ID: <47943513.3040906@benmabey.com> Pat Maddox wrote: > On Jan 20, 2008 9:09 PM, Rick DeNatale wrote: > >> Now I really like the idea of the parameterized stories, but the step >> away from client-speak makes me shy away from them. Is there a way to >> get the power without loosing the intelligibility? >> > > If I were to redo that, it would be something more like > > When "I create an article titled 'The Title' with a body of 'this is the body'" > > I totally agree that you should be speaking entirely in domain terms. > I'm still learning too :) > > Also since this is related, for any Bay Area RSpec'ers, I'm giving a > presentation on Story Runner at Tuesday's meetup. Check out > http://ruby.meetup.com/6/calendar/6665552/ for time and location info. > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > Rick, If you haven't already you should also check out webrat. It allows you to easily write steps that allow your stories to speak in terms of forms.. which is what my customers relate to the best. Along the lines of what Pat was saying.. I still use steps like the one he suggested but I usually only use them in Give clauses... so stuff like: Given "$resource exists in the system with $params" do |resource, params| resource.gsub!(" ","_") instance_variable_set("@#{resource}",resource.classify.constantize.create!(params.to_hash_from_story)) end class String # Coverts a string found in the steps into a hash. Example: # ISBN: '0967539854' and comment: 'I love this book' and rating: '4' # => {"rating"=>"4", "isbn"=>"0967539854", "comment"=>"I love this book"} def to_hash_from_story self.split(" and ").inject({}){ |hash_so_far, key_value| key, value = key_value.split(":").map{ |v| v.strip} hash_so_far.merge(key.downcase => value.gsub("'","")) } end end -Ben From jimlindley at gmail.com Mon Jan 21 09:22:04 2008 From: jimlindley at gmail.com (Jim Lindley) Date: Mon, 21 Jan 2008 09:22:04 -0500 Subject: [rspec-users] "should_not ==" vs "should !=" In-Reply-To: References: <59b5d4330801182047t6b623098o9487d7477514109d@mail.gmail.com> <57c63afe0801182236h67cbfbbj7c923890d064db45@mail.gmail.com> <9FD30EBC-BB8C-445D-943D-A94C15CE6048@goldweb.com.au> Message-ID: <1b165db00801210622u1b9e49f0qb9434c2d06ae6148@mail.gmail.com> > I'm 99 44/100% sure that you have it right. The expression x != y is > syntactic sugar for !(x == y) much like x += y is syntactic sugar for > x = (x +y) > > The parser turns these into an internal representation (abstract > syntax tree for 1.8, byte-codes for 1.9) which is identical to the > second form. > In 1.8 it's just syntactic sugar. But 1.9 provides actual != and !~ methods so that you can override it in situations like this. (from Ruby-Core: http://www.ruby-forum.com/topic/134608 ) From lists at ruby-forum.com Mon Jan 21 09:23:07 2008 From: lists at ruby-forum.com (CNNN NICK) Date: Mon, 21 Jan 2008 15:23:07 +0100 Subject: [rspec-users] specin' update_attributes! + Hash Message-ID: Hi, I am facing a problem while trying to test a method that updates an attribute. The attribute format should be converted to YAML format before storing in the table which is excatly what is going on. But when testing it using expectations in rspec it returns an error. *** below is the error message : Spec::Mocks::MockExpectationError in 'InteractController (submit) - saving a form to use later should update costumer details using the form params' Mock 'Instance_1039' expected :update_attributes with ({:customer_details=>"--- !map:HashWithIndifferentAccess \\ntitle: Hola\\n"}) but received it with ({:customer_details=>"--- !map:HashWithIndifferentAccess \ntitle: Hola\n"}) C:/webapps/interact/branches/interact_new_features/app/controllers/interact_controller.rb:74:in `submit' ./spec/controllers/interact_controller_spec.rb:200: script/spec:4: *** *** here's how i am testing it: @instance.should_receive(:update_attributes).with(:customer_details=> '--- map:HashWithIndifferentAccess \ntitle: Hola\n') post :submit, { :id => '7770' , :perform => 'Save this form', :form => { :title => 'Hola' } } *** Any tips pls? -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Mon Jan 21 09:26:54 2008 From: lists at ruby-forum.com (CNNN NICK) Date: Mon, 21 Jan 2008 15:26:54 +0100 Subject: [rspec-users] specin' update_attributes! + Hash In-Reply-To: References: Message-ID: <06732165e1ae434ba5056575891031e2@ruby-forum.com> Oh, it's escaping the characters in the YAML format... sorry for that -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Mon Jan 21 09:46:30 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 21 Jan 2008 08:46:30 -0600 Subject: [rspec-users] "should_not ==" vs "should !=" In-Reply-To: <1b165db00801210622u1b9e49f0qb9434c2d06ae6148@mail.gmail.com> References: <59b5d4330801182047t6b623098o9487d7477514109d@mail.gmail.com> <57c63afe0801182236h67cbfbbj7c923890d064db45@mail.gmail.com> <9FD30EBC-BB8C-445D-943D-A94C15CE6048@goldweb.com.au> <1b165db00801210622u1b9e49f0qb9434c2d06ae6148@mail.gmail.com> Message-ID: <57c63afe0801210646g5bf4b611q90ce179adc3386c1@mail.gmail.com> On Jan 21, 2008 8:22 AM, Jim Lindley wrote: > > I'm 99 44/100% sure that you have it right. The expression x != y is > > syntactic sugar for !(x == y) much like x += y is syntactic sugar for > > x = (x +y) > > > > The parser turns these into an internal representation (abstract > > syntax tree for 1.8, byte-codes for 1.9) which is identical to the > > second form. > > > > In 1.8 it's just syntactic sugar. But 1.9 provides actual != and !~ > methods so that you can override it in situations like this. Oooooh. Good to know. We're not 1.9 compatible yet, but when we get there we'll definitely add this! > > (from Ruby-Core: http://www.ruby-forum.com/topic/134608 ) > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From rick.denatale at gmail.com Mon Jan 21 15:12:37 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Mon, 21 Jan 2008 15:12:37 -0500 Subject: [rspec-users] attachment_fu and story runner, any updates Message-ID: I'm trying to write a story for a Rails app which involves using the attachment_fu plugin to upload images. After blunting my pick on this for a while, google found me this: http://www.ruby-forum.com/topic/134743#600831 So it seems that there's a hole in Rails integration testing and multipart form posting. David offered to incorporate a patch to story runner at the end of the reference thread in ruby-talk, although just which patch confuses me, it would seem to be one from http://dev.rubyonrails.org/ticket/4635 So what is the current status here? -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From ben.fyvie at champsoftware.com Mon Jan 21 15:53:50 2008 From: ben.fyvie at champsoftware.com (BenFyvie) Date: Mon, 21 Jan 2008 12:53:50 -0800 (PST) Subject: [rspec-users] Rspec 1.1.2 on Windows Message-ID: <15006297.post@talk.nabble.com> I am using Rspec 1.1.2 on Windows XP SP2 I am receiving the following error when I run 'rake spec' from a brand new project: C:/SVN_Projects/rspec/vendor/plugins/rspec/lib/spec/runner/options.rb:107:in `colour=': You must gem install win32console to use colour on Windows (RuntimeError) I have the win32console gem installed and the error still occurs. It seems that the require statement in options.rb line 105 is throwing an exception and I am not sure why. I have even gone to the extent of replacing 'Win32/Console/ANSI' with the absolute path to the ANSI file and still no luck. When I run the require statement in a console everything works fine and dandy. Now if I remove the --colour option from the spec.opts file then it doesn't need the win32console gem; however, I then receive this error: C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:100:in `const_missing': uninitialized constant Spec::Rails (NameError) I do have the rspec_on_rails plugin installed. Can anyone offer me any suggestions on how to troubleshoot this issue? Thanks in advance! -- View this message in context: http://www.nabble.com/Rspec-1.1.2-on-Windows-tp15006297p15006297.html Sent from the rspec-users mailing list archive at Nabble.com. From luislavena at gmail.com Mon Jan 21 15:58:32 2008 From: luislavena at gmail.com (Luis Lavena) Date: Mon, 21 Jan 2008 18:58:32 -0200 Subject: [rspec-users] Rspec 1.1.2 on Windows In-Reply-To: <15006297.post@talk.nabble.com> References: <15006297.post@talk.nabble.com> Message-ID: <71166b3b0801211258t25569345m17c2aaf4b8c83306@mail.gmail.com> On Jan 21, 2008 6:53 PM, BenFyvie wrote: > > I am using Rspec 1.1.2 on Windows XP SP2 > > I am receiving the following error when I run 'rake spec' from a brand new > project: > C:/SVN_Projects/rspec/vendor/plugins/rspec/lib/spec/runner/options.rb:107:in > `colour=': You must gem install win32console to use colour on Windows > (RuntimeError) > > I have the win32console gem installed and the error still occurs. It seems > that the require statement in options.rb line 105 is throwing an exception > and I am not sure why. I have even gone to the extent of replacing > 'Win32/Console/ANSI' with the absolute path to the ANSI file and still no > luck. When I run the require statement in a console everything works fine > and dandy. > > Now if I remove the --colour option from the spec.opts file then it doesn't > need the win32console gem; however, I then receive this error: > C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:100:in > `const_missing': uninitialized constant Spec::Rails (NameError) > > I do have the rspec_on_rails plugin installed. Can anyone offer me any > suggestions on how to troubleshoot this issue? Thanks in advance! I'll be looking into this tonight, since I already reported that, but using rake and spec command only: http://rspec.lighthouseapp.com/projects/5645/tickets/244-no-coloured-output-on-windows-due-missing-rubyopt It seems that --colour affects not only lib/runner/options.rb, but other places too. Maybe we should change the behavior for windows and revert to false if Win32/Console/ANSI is not found instead of raising a exception. David, Aslak? -- Luis Lavena Multimedia systems - A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools. Douglas Adams From luislavena at gmail.com Mon Jan 21 17:26:57 2008 From: luislavena at gmail.com (Luis Lavena) Date: Mon, 21 Jan 2008 20:26:57 -0200 Subject: [rspec-users] RSpec 1.1.2, --colour and Windows Message-ID: <71166b3b0801211426h10b77c5eu694ed0c86ffcf897@mail.gmail.com> Hello RSpec'ers :-) In reply to this message: http://rubyforge.org/pipermail/rspec-users/2008-January/005477.html I provided a patch against CURRENT for fixing the latest issue introduced in 1.1.2 regarding colour and Windows. http://rspec.lighthouseapp.com/projects/5645/tickets/244-no-coloured-output-on-windows-due-missing-rubyopt just-warn-about-windows-no-colour.patch The patch just warn the user about the lack of win32console gem (prior trying to load rubygems) and then revert the color decision to false to avoid garbled output. Since I lack the time to recreate all the scenario (pre_commit and everything) to run the specs, I assume will not affect any other place (since is just for windows). This fix problems when using rake tasks, script/spec and 'spec' script installed by rubygems. Looking forward for this made into the next version. Regards, -- Luis Lavena Multimedia systems - A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools. Douglas Adams From dchelimsky at gmail.com Mon Jan 21 23:36:16 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 21 Jan 2008 22:36:16 -0600 Subject: [rspec-users] attachment_fu and story runner, any updates In-Reply-To: References: Message-ID: <57c63afe0801212036j242a68ado6ea7f4f1fcb75ee1@mail.gmail.com> On Jan 21, 2008 2:12 PM, Rick DeNatale wrote: > I'm trying to write a story for a Rails app which involves using the > attachment_fu plugin to upload images. > > After blunting my pick on this for a while, google found me this: > http://www.ruby-forum.com/topic/134743#600831 > > So it seems that there's a hole in Rails integration testing and > multipart form posting. David offered to incorporate a patch to story > runner at the end of the reference thread in ruby-talk, although just > which patch confuses me, it would seem to be one from > http://dev.rubyonrails.org/ticket/4635 > > So what is the current status here? "There are no tests for the rails patch. If you're willing to add rspec examples and contribute it to the rspec tracker, I'll add it to rspec as a temporary fix until that ticket is resolved." I think that's where we left it. Probably belongs in a separate plugin though - not as part of rspec. Any takers? > > -- > Rick DeNatale > > My blog on Ruby > http://talklikeaduck.denhaven2.com/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ben.fyvie at champsoftware.com Tue Jan 22 11:08:44 2008 From: ben.fyvie at champsoftware.com (BenFyvie) Date: Tue, 22 Jan 2008 08:08:44 -0800 (PST) Subject: [rspec-users] Rspec 1.1.2 on Windows In-Reply-To: <71166b3b0801211258t25569345m17c2aaf4b8c83306@mail.gmail.com> References: <15006297.post@talk.nabble.com> <71166b3b0801211258t25569345m17c2aaf4b8c83306@mail.gmail.com> Message-ID: <15022159.post@talk.nabble.com> Luis Lavena wrote: > > On Jan 21, 2008 6:53 PM, BenFyvie wrote: >> >> I am using Rspec 1.1.2 on Windows XP SP2 >> >> I am receiving the following error when I run 'rake spec' from a brand >> new >> project: >> C:/SVN_Projects/rspec/vendor/plugins/rspec/lib/spec/runner/options.rb:107:in >> `colour=': You must gem install win32console to use colour on Windows >> (RuntimeError) >> >> I have the win32console gem installed and the error still occurs. It >> seems >> that the require statement in options.rb line 105 is throwing an >> exception >> and I am not sure why. I have even gone to the extent of replacing >> 'Win32/Console/ANSI' with the absolute path to the ANSI file and still no >> luck. When I run the require statement in a console everything works >> fine >> and dandy. >> >> Now if I remove the --colour option from the spec.opts file then it >> doesn't >> need the win32console gem; however, I then receive this error: >> C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:100:in >> `const_missing': uninitialized constant Spec::Rails (NameError) >> >> I do have the rspec_on_rails plugin installed. Can anyone offer me any >> suggestions on how to troubleshoot this issue? Thanks in advance! > > I'll be looking into this tonight, since I already reported that, but > using rake and spec command only: > > http://rspec.lighthouseapp.com/projects/5645/tickets/244-no-coloured-output-on-windows-due-missing-rubyopt > > It seems that --colour affects not only lib/runner/options.rb, but > other places too. > > Maybe we should change the behavior for windows and revert to false if > Win32/Console/ANSI is not found instead of raising a exception. > > David, Aslak? > > -- > Luis Lavena > Multimedia systems > - > A common mistake that people make when trying to design > something completely foolproof is to underestimate > the ingenuity of complete fools. > Douglas Adams > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > Thanks Luis, I used the code in your lighthouse case and I am now able to load the win32console gem. However I am still not able to run tests because of the second problem I that I mentioned before with the uninitialized constant for Spec::Rails. I see at least one other person with this problem, but no resolution. http://www.ruby-forum.com/topic/135888 Care to help me troubleshoot this issue as well? I've got the rspec_on_rails plugin installed and my spec_helper.rb is requiring spec/rails. Thanks! -- View this message in context: http://www.nabble.com/Rspec-1.1.2-on-Windows-tp15006297p15022159.html Sent from the rspec-users mailing list archive at Nabble.com. From luislavena at gmail.com Tue Jan 22 11:31:23 2008 From: luislavena at gmail.com (Luis Lavena) Date: Tue, 22 Jan 2008 14:31:23 -0200 Subject: [rspec-users] Rspec 1.1.2 on Windows In-Reply-To: <15022159.post@talk.nabble.com> References: <15006297.post@talk.nabble.com> <71166b3b0801211258t25569345m17c2aaf4b8c83306@mail.gmail.com> <15022159.post@talk.nabble.com> Message-ID: <71166b3b0801220831w3e382494paa35cfadd7cdf30c@mail.gmail.com> On Jan 22, 2008 2:08 PM, BenFyvie wrote: > > > Thanks Luis, > > I used the code in your lighthouse case and I am now able to load the > win32console gem. However I am still not able to run tests because of the > second problem I that I mentioned before with the uninitialized constant for > Spec::Rails. I see at least one other person with this problem, but no > resolution. http://www.ruby-forum.com/topic/135888 > It's weird since I had done the same step mentioned in that post and couldn't reproduce the problem. Tried with and without rspec gem installed. Also tried using script/spec, without problems. > Care to help me troubleshoot this issue as well? I've got the > rspec_on_rails plugin installed and my spec_helper.rb is requiring > spec/rails. > by CURRENT rspec tag, you mean the 1.1.2 release? can you ditch vendor/plugins/rspec and rspec_on_rails and try again? It's truly odd. Can you try removing the spec.opts, spec_helper files and ran the rspec generator again? -- Luis Lavena Multimedia systems - A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools. Douglas Adams From rick.denatale at gmail.com Tue Jan 22 11:44:54 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Tue, 22 Jan 2008 11:44:54 -0500 Subject: [rspec-users] attachment_fu and story runner, any updates In-Reply-To: <57c63afe0801212036j242a68ado6ea7f4f1fcb75ee1@mail.gmail.com> References: <57c63afe0801212036j242a68ado6ea7f4f1fcb75ee1@mail.gmail.com> Message-ID: On Jan 21, 2008 11:36 PM, David Chelimsky wrote: > On Jan 21, 2008 2:12 PM, Rick DeNatale wrote: > > I'm trying to write a story for a Rails app which involves using the > > attachment_fu plugin to upload images. > > > > After blunting my pick on this for a while, google found me this: > > http://www.ruby-forum.com/topic/134743#600831 > > > > So it seems that there's a hole in Rails integration testing and > > multipart form posting. David offered to incorporate a patch to story > > runner at the end of the reference thread in ruby-talk, although just > > which patch confuses me, it would seem to be one from > > http://dev.rubyonrails.org/ticket/4635 > > > > So what is the current status here? > > "There are no tests for the rails patch. If you're willing to add > rspec examples and contribute it to the rspec tracker, I'll add it to > rspec as a temporary fix until that ticket is resolved." > > I think that's where we left it. > > Probably belongs in a separate plugin though - not as part of rspec. Any takers? After looking at the patches a bit, I decided to dig in and write a new rails patch which will work slightly differently. The current patch explicitly requires the use of a multi_part method. The problem is that this doesn't work if you want to use, say post_via_redirect, and it also doesn't handle multipart put requests, which just might be useful in our RESTful world these days. So instead I'm now debugging a new patch which adds the ability for an integration controller to detect parameter values which are instances of TestUploadedFile and automatically generate a multipart request. In the meantime, I seem to be running into the issue discussed here: http://www.ruby-forum.com/topic/130975#585329 I find I need to have this: Test::Unit::TestCase.fixture_path = RAILS_ROOT + '/spec/fixtures/' I thought that this was fixed? $ svn propget piston:root vendor/plugins/rspec http://rspec.rubyforge.org/svn/tags/CURRENT/rspec $ svn propget piston:root vendor/plugins/rspec_on_rails http://rspec.rubyforge.org/svn/tags/CURRENT/rspec_on_rails $ svn propget piston:remote-revision vendor/plugins/rspec 3225 $ svn propget piston:remote-revision vendor/plugins/rspec_on_rails/ 3223 -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From ben.fyvie at champsoftware.com Tue Jan 22 11:58:59 2008 From: ben.fyvie at champsoftware.com (BenFyvie) Date: Tue, 22 Jan 2008 08:58:59 -0800 (PST) Subject: [rspec-users] Rspec 1.1.2 on Windows In-Reply-To: <71166b3b0801220831w3e382494paa35cfadd7cdf30c@mail.gmail.com> References: <15006297.post@talk.nabble.com> <71166b3b0801211258t25569345m17c2aaf4b8c83306@mail.gmail.com> <15022159.post@talk.nabble.com> <71166b3b0801220831w3e382494paa35cfadd7cdf30c@mail.gmail.com> Message-ID: <15023061.post@talk.nabble.com> Luis Lavena wrote: > > On Jan 22, 2008 2:08 PM, BenFyvie wrote: >> >> >> Thanks Luis, >> >> I used the code in your lighthouse case and I am now able to load the >> win32console gem. However I am still not able to run tests because of >> the >> second problem I that I mentioned before with the uninitialized constant >> for >> Spec::Rails. I see at least one other person with this problem, but no >> resolution. http://www.ruby-forum.com/topic/135888 >> > > It's weird since I had done the same step mentioned in that post and > couldn't reproduce the problem. > > Tried with and without rspec gem installed. Also tried using > script/spec, without problems. > >> Care to help me troubleshoot this issue as well? I've got the >> rspec_on_rails plugin installed and my spec_helper.rb is requiring >> spec/rails. >> > > by CURRENT rspec tag, you mean the 1.1.2 release? can you ditch > vendor/plugins/rspec and rspec_on_rails and try again? > > It's truly odd. > > Can you try removing the spec.opts, spec_helper files and ran the > rspec generator again? > > -- > Luis Lavena > Multimedia systems > - > A common mistake that people make when trying to design > something completely foolproof is to underestimate > the ingenuity of complete fools. > Douglas Adams > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > Thanks for your quick response Luis! I've actually gone to the extent of creating a brand spankin new rails project, installed the plugins, ran the bootstrap, created a simple table with a simple test and I get the same problem. Anything else you can think to try? -- View this message in context: http://www.nabble.com/Rspec-1.1.2-on-Windows-tp15006297p15023061.html Sent from the rspec-users mailing list archive at Nabble.com. From ben.fyvie at champsoftware.com Tue Jan 22 12:21:39 2008 From: ben.fyvie at champsoftware.com (BenFyvie) Date: Tue, 22 Jan 2008 09:21:39 -0800 (PST) Subject: [rspec-users] Rspec 1.1.2 on Windows In-Reply-To: <71166b3b0801220831w3e382494paa35cfadd7cdf30c@mail.gmail.com> References: <15006297.post@talk.nabble.com> <71166b3b0801211258t25569345m17c2aaf4b8c83306@mail.gmail.com> <15022159.post@talk.nabble.com> <71166b3b0801220831w3e382494paa35cfadd7cdf30c@mail.gmail.com> Message-ID: <15023560.post@talk.nabble.com> Luis Lavena wrote: > > On Jan 22, 2008 2:08 PM, BenFyvie wrote: >> >> >> Thanks Luis, >> >> I used the code in your lighthouse case and I am now able to load the >> win32console gem. However I am still not able to run tests because of >> the >> second problem I that I mentioned before with the uninitialized constant >> for >> Spec::Rails. I see at least one other person with this problem, but no >> resolution. http://www.ruby-forum.com/topic/135888 >> > > It's weird since I had done the same step mentioned in that post and > couldn't reproduce the problem. > > Tried with and without rspec gem installed. Also tried using > script/spec, without problems. > >> Care to help me troubleshoot this issue as well? I've got the >> rspec_on_rails plugin installed and my spec_helper.rb is requiring >> spec/rails. >> > > by CURRENT rspec tag, you mean the 1.1.2 release? can you ditch > vendor/plugins/rspec and rspec_on_rails and try again? > > It's truly odd. > > Can you try removing the spec.opts, spec_helper files and ran the > rspec generator again? > > -- > Luis Lavena > Multimedia systems > - > A common mistake that people make when trying to design > something completely foolproof is to underestimate > the ingenuity of complete fools. > Douglas Adams > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > It appears the second error was my fault. The new project I created was using Rails 1.1.6 I created a new project using Rails 2.0.2 and everything seems to work once I put in your patch for the win32console gem. Thanks! -- View this message in context: http://www.nabble.com/Rspec-1.1.2-on-Windows-tp15006297p15023560.html Sent from the rspec-users mailing list archive at Nabble.com. From luislavena at gmail.com Tue Jan 22 18:58:55 2008 From: luislavena at gmail.com (Luis Lavena) Date: Tue, 22 Jan 2008 21:58:55 -0200 Subject: [rspec-users] Trying to spec ExceptionNotifiable behavior Message-ID: <71166b3b0801221558l5d913c8ag33631a6a35beb587@mail.gmail.com> Hello List. I'm trying to overwrite part of ExceptionNotifiable (ExceptionNotification plugin) to render customized error 500 pages based on browser agents. For this, I've created a fake controller that inherits directly from ActionController::Base: class FooExceptionController < ActionController::Base include ExceptionNotifiable # this action should not fail, used for controller.expect_render(...) checking def ok_action render(:file => "#{RAILS_ROOT}/public/ok.html") end # this action should raise an unexpected exception def fail_action raise StandardError.new("manually raised exception") end end I'm running with RSpec 1.0.8 (pistoned as plugin) and respective REL_1_0_8 rspec_on_rails All the specs are ran with 'script/spec -R -c spec' This is my spec: describe FooExceptionController, "dealing with exceptions" do it "should succeed on a good action" do get 'ok_action' response.should be_success end it "should render the action ok_action" do controller.expect_render(:file => "#{RAILS_ROOT}/public/ok.html") get 'ok_action' end # Why we are getting the exception here? # shouldn't be rspec passing it to rails to process it? it "should fail on fail_action" do lambda { get 'fail_action' }.should raise_error(StandardError, /manually raised exception/) end it "should render error template" do controller.expect_render(:file => "#{RAILS_ROOT}/public/500.html") get 'fail_action' end end == First spec "should render the action ok_action" works ok, and the controller render expectation do its work. The second spec, isn't right. I'm not trying to get the Exception to catch it on Rspec, but actully let ExceptionNotifier do its job and actually expect rendering of RAILS_ROOT/public/500.html, as shown in the third spec. Anyway, both 1 and 2, pass, but third fails with "manually raised exception" on the output: StandardError in 'FooExceptionController dealing with exceptions should render error template' manually raised exception I've looked all over, for 1.0.8 and 1.1.2, but the only reference I could find is use_rails_error_handling! in rdoc, but no Spec::Runner configuration option or before behavior that could be change. (http://rspec.info/rdoc-rails/classes/ActionController/Rescue.html#M000007) What I'm doing wrong? What I'm missing? Thanks in advance for your time. Regards, -- Luis Lavena Multimedia systems - A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools. Douglas Adams From jonathan at parkerhill.com Tue Jan 22 23:49:20 2008 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Tue, 22 Jan 2008 23:49:20 -0500 Subject: [rspec-users] sharing specs in a subclass Message-ID: Hi I've spec'd a class and they pass. Now I'd like to assure that any subclass of this class also passes the same specs. Any suggestions for a clever way to handle this? I'd prefer to keep the existing specs as is (eg instead of moving everything into shared behaviors, or doing something to all the 'describe' lines) thanks linoj From dchelimsky at gmail.com Wed Jan 23 00:02:04 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 22 Jan 2008 23:02:04 -0600 Subject: [rspec-users] sharing specs in a subclass In-Reply-To: References: Message-ID: <57c63afe0801222102s56883f22m323e64a950a6588e@mail.gmail.com> On Jan 22, 2008 10:49 PM, Jonathan Linowes wrote: > Hi > > I've spec'd a class and they pass. > > Now I'd like to assure that any subclass of this class also passes > the same specs. > Any suggestions for a clever way to handle this? > I'd prefer to keep the existing specs as is (eg instead of moving > everything into shared behaviors, or doing something to all the > 'describe' lines) How about: [Subclass1, Subclass2, BaseClass].each do |klass| describe klass do ... end end > > thanks > > linoj > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jonathan at parkerhill.com Wed Jan 23 00:31:16 2008 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Wed, 23 Jan 2008 00:31:16 -0500 Subject: [rspec-users] sharing specs in a subclass In-Reply-To: <57c63afe0801222102s56883f22m323e64a950a6588e@mail.gmail.com> References: <57c63afe0801222102s56883f22m323e64a950a6588e@mail.gmail.com> Message-ID: <9E7E3749-7824-4A3F-B005-B495B54B300F@parkerhill.com> cool thx :) On Jan 23, 2008, at 12:02 AM, David Chelimsky wrote: > On Jan 22, 2008 10:49 PM, Jonathan Linowes > wrote: >> Hi >> >> I've spec'd a class and they pass. >> >> Now I'd like to assure that any subclass of this class also passes >> the same specs. >> Any suggestions for a clever way to handle this? >> I'd prefer to keep the existing specs as is (eg instead of moving >> everything into shared behaviors, or doing something to all the >> 'describe' lines) > > How about: > > [Subclass1, Subclass2, BaseClass].each do |klass| > describe klass do > ... > end > end > >> >> thanks >> >> linoj >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From mailing_lists at railsnewbie.com Wed Jan 23 01:04:35 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Wed, 23 Jan 2008 01:04:35 -0500 Subject: [rspec-users] sharing specs in a subclass In-Reply-To: <57c63afe0801222102s56883f22m323e64a950a6588e@mail.gmail.com> References: <57c63afe0801222102s56883f22m323e64a950a6588e@mail.gmail.com> Message-ID: <7FCF6260-1B5B-48C7-BE9D-F653F6336C75@railsnewbie.com> On Jan 23, 2008, at 12:02 AM, David Chelimsky wrote: > On Jan 22, 2008 10:49 PM, Jonathan Linowes > wrote: >> Hi >> >> I've spec'd a class and they pass. >> >> Now I'd like to assure that any subclass of this class also passes >> the same specs. >> Any suggestions for a clever way to handle this? >> I'd prefer to keep the existing specs as is (eg instead of moving >> everything into shared behaviors, or doing something to all the >> 'describe' lines) > > How about: > > [Subclass1, Subclass2, BaseClass].each do |klass| > describe klass do > ... > end > end That's sort of funny, being that I posted this solution on Courtney's blog yesterday. Is this what you actually use in this sort of situations? Are there other (better, or worse) alternatives? Scott From dchelimsky at gmail.com Wed Jan 23 01:26:26 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 23 Jan 2008 00:26:26 -0600 Subject: [rspec-users] sharing specs in a subclass In-Reply-To: <7FCF6260-1B5B-48C7-BE9D-F653F6336C75@railsnewbie.com> References: <57c63afe0801222102s56883f22m323e64a950a6588e@mail.gmail.com> <7FCF6260-1B5B-48C7-BE9D-F653F6336C75@railsnewbie.com> Message-ID: <57c63afe0801222226o6c64144dqaf8ef0a15d300b92@mail.gmail.com> On Jan 23, 2008 12:04 AM, Scott Taylor wrote: > > On Jan 23, 2008, at 12:02 AM, David Chelimsky wrote: > > > On Jan 22, 2008 10:49 PM, Jonathan Linowes > > wrote: > >> Hi > >> > >> I've spec'd a class and they pass. > >> > >> Now I'd like to assure that any subclass of this class also passes > >> the same specs. > >> Any suggestions for a clever way to handle this? > >> I'd prefer to keep the existing specs as is (eg instead of moving > >> everything into shared behaviors, or doing something to all the > >> 'describe' lines) > > > > How about: > > > > [Subclass1, Subclass2, BaseClass].each do |klass| > > describe klass do > > ... > > end > > end > > That's sort of funny, being that I posted this solution on Courtney's > blog yesterday. I saw that. I've also done this before :) > Is this what you actually use in this sort of situations? Are there > other (better, or worse) alternatives? I usually stick w/ shared example groups, but I sometimes use an iterator like this. Not sure why. I'll think about it. Cheers, David > > Scott > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Wed Jan 23 02:17:23 2008 From: lists at ruby-forum.com (Ze No) Date: Wed, 23 Jan 2008 08:17:23 +0100 Subject: [rspec-users] integrate_views is not executing my views Message-ID: <84a657966025033d544c9a39ca092ea1@ruby-forum.com> I wanted to use "integrate_views" as Ryan explains in his RailsCast #71 (http://railscasts.com/episodes/71) ...but I can't get it to work: the view code in not executed I looked everywhere but I can't understand what I am doing wrong. Here is what I did: I created a new application from scratch (Rails 2.0.2), added rspec and rspec_on_rails plugins, and run script/generate rspec_scaffold User name:string This is my users_controller spec: describe UsersController do fixtures :users integrate_views describe "handling GET /users" do it "should be successful" do get :index response.should be_success end end end I then added something wrong (on purpose) in index.html.erb (<% WRONG %>) so that when I visit /users I get a view error (undefined local variable or method....) But when I run the spec everything is ok and the test does NOT fail :-( I can even trash the index.html.erb file and the test still passes -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Wed Jan 23 02:34:59 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 23 Jan 2008 01:34:59 -0600 Subject: [rspec-users] integrate_views is not executing my views In-Reply-To: <84a657966025033d544c9a39ca092ea1@ruby-forum.com> References: <84a657966025033d544c9a39ca092ea1@ruby-forum.com> Message-ID: <57c63afe0801222334hcda0a38heb9206eaba505050@mail.gmail.com> On Jan 23, 2008 1:17 AM, Ze No wrote: > I wanted to use "integrate_views" as Ryan explains in his RailsCast #71 > (http://railscasts.com/episodes/71) > > ...but I can't get it to work: the view code in not executed > > I looked everywhere but I can't understand what I am doing wrong. > Here is what I did: > I created a new application from scratch (Rails 2.0.2), added rspec and > rspec_on_rails plugins, and run > script/generate rspec_scaffold User name:string > > This is my users_controller spec: > > describe UsersController do > fixtures :users > integrate_views > > describe "handling GET /users" do > it "should be successful" do > get :index > response.should be_success > end > end > end Try it without nesting: describe UsersController, "handling GET /users" do fixtures :users integrate_views it "should be successful" do get :index response.should be_success end end If that works, then you've uncovered a bug with integrate_views not working in nested example groups. If so, please report it to the tracker: http://rspec.lighthouseapp.com Thanks, David > > I then added something wrong (on purpose) in index.html.erb (<% WRONG > %>) so that when I visit /users I get a view error (undefined local > variable or method....) > > But when I run the spec everything is ok and the test does NOT fail :-( > I can even trash the index.html.erb file and the test still passes > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From will.sargent at gmail.com Wed Jan 23 03:12:41 2008 From: will.sargent at gmail.com (Will Sargent) Date: Wed, 23 Jan 2008 00:12:41 -0800 Subject: [rspec-users] Changing rspec directory structure Message-ID: I'd like to change the rspec directory structure from /spec /model /controllers etc to /spec /unit /models /controllers /lib /functional /models /controllers etc. Basically the Jay Fields style of testing -- I want the unit tests to be run all the time on a continuous integration server, but the integration/functional and system tests to be run only once a night. How do I break out the rspec tasks so that they cover this heirarchy? It looks like they'll take a pattern, but I don't want to have to redefine every rake task just to specify this. Also, anyone know how hard this would be to maintain? Or if there's an easier way to organize this? Will. From lists at ruby-forum.com Wed Jan 23 05:06:15 2008 From: lists at ruby-forum.com (Ze No) Date: Wed, 23 Jan 2008 11:06:15 +0100 Subject: [rspec-users] integrate_views is not executing my views In-Reply-To: <57c63afe0801222334hcda0a38heb9206eaba505050@mail.gmail.com> References: <84a657966025033d544c9a39ca092ea1@ruby-forum.com> <57c63afe0801222334hcda0a38heb9206eaba505050@mail.gmail.com> Message-ID: <14aeb96efba3ed67950e841ca75c1cc2@ruby-forum.com> You are God. Thanks! You can't imagine the amount of time we wasted on that one ;-) > If that works, then you've uncovered a bug with integrate_views not > working in nested example groups. that was exactly the problem. > If so, please report it to the tracker definitely -- Posted via http://www.ruby-forum.com/. From rob.holland at gmail.com Wed Jan 23 06:25:26 2008 From: rob.holland at gmail.com (Rob Holland) Date: Wed, 23 Jan 2008 11:25:26 +0000 Subject: [rspec-users] expect_render(...).and_return('x') Message-ID: <6ea3a1b80801230325h72e6a30ah3c9a0a8ab8a9466b@mail.gmail.com> Hi, I'm trying to spec a controller method which renders some rjs as part of a render :update block. The problem I'm having is that stub_render or expect_render don't seem to allow and_return to work. The controller method does: if @thing.save render :update do |page| page.insert_html :bottom, 'x_thing_list', :partial => 'thing', :object => @thing page.form.reset 'x_new_thing' end else If I expect/stub_render the partial render (which I need to do if I want to solely test the controller in isolation), I get: new Insertion.Bottom("x_thing_list", null); Form.reset("x_new_thing"); The null is due to the render :partial being stubbed. Unfortunately, this breaks the regex that assert_rjs uses, so my test: response.should have_rjs(:insert, :bottom, "x_thing_list") fails, when it should pass. What I need to be able to do is: expect_render(:partial => 'thing', :object => @thing).and_return('"x"') so that the output satisfies the assert_rjs regex. I would love to provide a patch for this, but I cannot see why it doesn't already work. The expect_render return value seems to be a normal mock, I don't understand why return values aren't working in this case. Thanks for any insights. From coreyhaines at gmail.com Wed Jan 23 07:58:39 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Wed, 23 Jan 2008 07:58:39 -0500 Subject: [rspec-users] Changing rspec directory structure In-Reply-To: References: Message-ID: <6bdacb70801230458u289eb183yb118f3c4bfb488ca@mail.gmail.com> David just posted about the new --patterns option in the trunk. His examples don't include changing the directory structure, but I would think that it would allow that. If not, that would be a good patch. http://blog.davidchelimsky.net/articles/2008/01/20/rspec-new-pattern-option -Corey On Jan 23, 2008 3:12 AM, Will Sargent wrote: > I'd like to change the rspec directory structure from > > /spec > /model > /controllers > etc > > to > > /spec > /unit > /models > /controllers > /lib > /functional > /models > /controllers > > etc. > > Basically the Jay Fields style of testing -- I want the unit tests to > be run all the time on a continuous integration server, but the > integration/functional and system tests to be run only once a night. > > How do I break out the rspec tasks so that they cover this heirarchy? > It looks like they'll take a pattern, but I don't want to have to > redefine every rake task just to specify this. > > Also, anyone know how hard this would be to maintain? Or if there's > an easier way to organize this? > > Will. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080123/c4f805df/attachment.html From luislavena at gmail.com Wed Jan 23 08:39:49 2008 From: luislavena at gmail.com (Luis Lavena) Date: Wed, 23 Jan 2008 11:39:49 -0200 Subject: [rspec-users] Rspec 1.1.2 on Windows In-Reply-To: <15023061.post@talk.nabble.com> References: <15006297.post@talk.nabble.com> <71166b3b0801211258t25569345m17c2aaf4b8c83306@mail.gmail.com> <15022159.post@talk.nabble.com> <71166b3b0801220831w3e382494paa35cfadd7cdf30c@mail.gmail.com> <15023061.post@talk.nabble.com> Message-ID: <71166b3b0801230539u53c141detace21061cfad732a@mail.gmail.com> On Jan 22, 2008 2:58 PM, BenFyvie wrote: > > Thanks for your quick response Luis! > > I've actually gone to the extent of creating a brand spankin new rails > project, installed the plugins, ran the bootstrap, created a simple table > with a simple test and I get the same problem. Anything else you can think > to try? Ben, will be helpful if you provide information about versions of every part you're using: - Ruby version (ruby -v) One-Click Installer? - RubyGems version (gem -v) (0.9.4, 1.0.1)? - Rails gem version (rails -v) - How you installed RSpec and RSpec On Rails (as plugins, using CURRENT or what REL)? - Is the win32console gem installed? - The exact command you used to run the specs (rake spec, script/spec, or just spec). Also, please read my comments on this ticket: http://rspec.lighthouseapp.com/projects/5645/tickets/244-no-coloured-output-on-windows-due-missing-rubyopt If you have RubyGems 0.9.5, please update to 1.0.1 or revert to 0.9.4, since that specific version is broken for Windows, as I commented there and linked to my blog: http://blog.mmediasys.com/2007/12/19/latest-rubygems-and-rails-is-a-deadly-combo/ HTH, -- Luis Lavena Multimedia systems - A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools. Douglas Adams From coreyhaines at gmail.com Wed Jan 23 09:41:41 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Wed, 23 Jan 2008 09:41:41 -0500 Subject: [rspec-users] Not seeing the failure Message-ID: <6bdacb70801230641h18c42784v4e03cc6d5b4eb355@mail.gmail.com> All, I'm missing something simple, I think. I am writing a spec to say that my CouponController should create a new coupon from the form parameters, then set the current user. Here's the spec: describe CouponController, "When posting to save_coupon" do before(:each) do @expectedName = "pepper's" @expectedAmount = 5 coupon = mock_model Coupon current_user = mock_model User controller.stub!(:current_user).and_return(current_user) Coupon.should_receive (:new).with({"name"=>@expectedName,"amount"=>@expectedAmount}).and_return(coupon) coupon.should_receive(:user).with(current_user) coupon.should_receive(:save) end it "should tell the Coupon model to create a new coupon with the given parameters and save" do post 'save_coupon',{:coupon=>{:name=>@expectedName,:amount=>@expectedAmount}} end Here's the controller method: def save_coupon coupon = Coupon.new(params[:coupon]) coupon.user = current_user coupon.save redirect_to_index "Coupon Added!" end And, I get the following failure: Mock 'Coupon_1008' received unexpected message :user= with (#) I'm sure that I'm missing something very simple, but I've been staring at it for too long. (also, if anyone has commented on my style, please feel free to mention it, as I'm still adjusting my mind to rspec) Oh, versions, I almost forgot: rails 2.0.2 rspec(_on_rails) plugins just updated from current a couple days ago, not totally sure how to get the versions of the plugins Thanks. -Corey -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080123/bf783be6/attachment.html From coreyhaines at gmail.com Wed Jan 23 09:42:10 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Wed, 23 Jan 2008 09:42:10 -0500 Subject: [rspec-users] Not seeing the failure In-Reply-To: <6bdacb70801230641h18c42784v4e03cc6d5b4eb355@mail.gmail.com> References: <6bdacb70801230641h18c42784v4e03cc6d5b4eb355@mail.gmail.com> Message-ID: <6bdacb70801230642x31c16929pa920df2fcc474e52@mail.gmail.com> Oh, and one follow-up, the app works how I expect it to work if I run through the browser. On Jan 23, 2008 9:41 AM, Corey Haines wrote: > All, > > I'm missing something simple, I think. I am writing a spec to say that my > CouponController should create a new coupon from the form parameters, then > set the current user. Here's the spec: > > describe CouponController, "When posting to save_coupon" do > > before(:each) do > @expectedName = "pepper's" > @expectedAmount = 5 > > coupon = mock_model Coupon > current_user = mock_model User > controller.stub!(:current_user).and_return(current_user) > Coupon.should_receive > (:new).with({"name"=>@expectedName,"amount"=>@expectedAmount}).and_return(coupon) > coupon.should_receive(:user).with(current_user) > coupon.should_receive(:save) > end > > it "should tell the Coupon model to create a new coupon with the given > parameters and save" do > post > 'save_coupon',{:coupon=>{:name=>@expectedName,:amount=>@expectedAmount}} > end > > Here's the controller method: > > def save_coupon > coupon = Coupon.new(params[:coupon]) > coupon.user = current_user > coupon.save > redirect_to_index "Coupon Added!" > end > > And, I get the following failure: > > Mock 'Coupon_1008' received unexpected message :user= with > (#) > > I'm sure that I'm missing something very simple, but I've been staring at > it for too long. > > (also, if anyone has commented on my style, please feel free to mention > it, as I'm still adjusting my mind to rspec) > > Oh, versions, I almost forgot: > rails 2.0.2 > rspec(_on_rails) plugins just updated from current a couple days ago, not > totally sure how to get the versions of the plugins > > > Thanks. > -Corey > > -- > http://www.coreyhaines.com > The Internet's Premiere source of information about Corey Haines -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080123/a97c0340/attachment.html From dchelimsky at gmail.com Wed Jan 23 09:46:10 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 23 Jan 2008 08:46:10 -0600 Subject: [rspec-users] Not seeing the failure In-Reply-To: <6bdacb70801230641h18c42784v4e03cc6d5b4eb355@mail.gmail.com> References: <6bdacb70801230641h18c42784v4e03cc6d5b4eb355@mail.gmail.com> Message-ID: <57c63afe0801230646s60adff48k5e01920aef26dd04@mail.gmail.com> On Jan 23, 2008 8:41 AM, Corey Haines wrote: > All, > > I'm missing something simple, I think. I am writing a spec to say that my > CouponController should create a new coupon from the form parameters, then > set the current user. Here's the spec: > > describe CouponController, "When posting to save_coupon" do > > before(:each) do > @expectedName = "pepper's" > @expectedAmount = 5 > > coupon = mock_model Coupon > current_user = mock_model User > controller.stub!(:current_user).and_return(current_user) > > Coupon.should_receive(:new).with({"name"=>@expectedName,"amount"=>@expectedAmount}).and_return(coupon) > coupon.should_receive(:user).with(current_user) > coupon.should_receive(:save) > end > > it "should tell the Coupon model to create a new coupon with the given > parameters and save" do > post > 'save_coupon',{:coupon=>{:name=>@expectedName,:amount=>@expectedAmount}} > end > > Here's the controller method: > > def save_coupon > coupon = Coupon.new(params[:coupon]) > coupon.user = current_user > coupon.save > redirect_to_index "Coupon Added!" > end > > And, I get the following failure: > > Mock 'Coupon_1008' received unexpected message :user= with (# @name="User_1009">) That's from this line in save_coupon: coupon.user = current_user Just need to stub that: coupon.stub!(:user=) Or you could expect it: coupon.should_receive(:user=).with(current_user) Cheers, David > > I'm sure that I'm missing something very simple, but I've been staring at it > for too long. > > (also, if anyone has commented on my style, please feel free to mention it, > as I'm still adjusting my mind to rspec) > > Oh, versions, I almost forgot: > rails 2.0.2 > rspec(_on_rails) plugins just updated from current a couple days ago, not > totally sure how to get the versions of the plugins > > > Thanks. > -Corey > > -- > http://www.coreyhaines.com > The Internet's Premiere source of information about Corey Haines > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From coreyhaines at gmail.com Wed Jan 23 09:49:23 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Wed, 23 Jan 2008 09:49:23 -0500 Subject: [rspec-users] Not seeing the failure In-Reply-To: <57c63afe0801230646s60adff48k5e01920aef26dd04@mail.gmail.com> References: <6bdacb70801230641h18c42784v4e03cc6d5b4eb355@mail.gmail.com> <57c63afe0801230646s60adff48k5e01920aef26dd04@mail.gmail.com> Message-ID: <6bdacb70801230649g2bc689acrb2267f5653480276@mail.gmail.com> Of course. Thanks, David! I still am getting used to user=, rather than just user. Thanks again. -Corey On Jan 23, 2008 9:46 AM, David Chelimsky wrote: > On Jan 23, 2008 8:41 AM, Corey Haines wrote: > > All, > > > > I'm missing something simple, I think. I am writing a spec to say that > my > > CouponController should create a new coupon from the form parameters, > then > > set the current user. Here's the spec: > > > > describe CouponController, "When posting to save_coupon" do > > > > before(:each) do > > @expectedName = "pepper's" > > @expectedAmount = 5 > > > > coupon = mock_model Coupon > > current_user = mock_model User > > controller.stub!(:current_user).and_return(current_user) > > > > Coupon.should_receive > (:new).with({"name"=>@expectedName,"amount"=>@expectedAmount}).and_return(coupon) > > coupon.should_receive(:user).with(current_user) > > coupon.should_receive(:save) > > end > > > > it "should tell the Coupon model to create a new coupon with the given > > parameters and save" do > > post > > 'save_coupon',{:coupon=>{:name=>@expectedName,:amount=>@expectedAmount}} > > end > > > > Here's the controller method: > > > > def save_coupon > > coupon = Coupon.new(params[:coupon]) > > coupon.user = current_user > > coupon.save > > redirect_to_index "Coupon Added!" > > end > > > > And, I get the following failure: > > > > Mock 'Coupon_1008' received unexpected message :user= with > (# > @name="User_1009">) > > > That's from this line in save_coupon: > > coupon.user = current_user > > Just need to stub that: > > coupon.stub!(:user=) > > Or you could expect it: > > coupon.should_receive(:user=).with(current_user) > > Cheers, > David > > > > > I'm sure that I'm missing something very simple, but I've been staring > at it > > for too long. > > > > (also, if anyone has commented on my style, please feel free to mention > it, > > as I'm still adjusting my mind to rspec) > > > > Oh, versions, I almost forgot: > > rails 2.0.2 > > rspec(_on_rails) plugins just updated from current a couple days ago, > not > > totally sure how to get the versions of the plugins > > > > > > Thanks. > > -Corey > > > > -- > > http://www.coreyhaines.com > > The Internet's Premiere source of information about Corey Haines > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080123/ee34b335/attachment.html From dchelimsky at gmail.com Wed Jan 23 10:03:25 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 23 Jan 2008 09:03:25 -0600 Subject: [rspec-users] Not seeing the failure In-Reply-To: <6bdacb70801230649g2bc689acrb2267f5653480276@mail.gmail.com> References: <6bdacb70801230641h18c42784v4e03cc6d5b4eb355@mail.gmail.com> <57c63afe0801230646s60adff48k5e01920aef26dd04@mail.gmail.com> <6bdacb70801230649g2bc689acrb2267f5653480276@mail.gmail.com> Message-ID: <57c63afe0801230703r7a5d3897t7b8298ae9c987306@mail.gmail.com> On Jan 23, 2008 8:49 AM, Corey Haines wrote: > Of course. Thanks, David! I still am getting used to user=, rather than just > user. Thanks again. No problem. I certainly got caught by that early on. I have some more general comments. See below: > > -Corey > > > > On Jan 23, 2008 9:46 AM, David Chelimsky < dchelimsky at gmail.com> wrote: > > > > On Jan 23, 2008 8:41 AM, Corey Haines < coreyhaines at gmail.com> wrote: > > > > > > > > > All, > > > > > > I'm missing something simple, I think. I am writing a spec to say that > my > > > CouponController should create a new coupon from the form parameters, > then > > > set the current user. Here's the spec: > > > > > > describe CouponController, "When posting to save_coupon" do > > > > > > before(:each) do > > > @expectedName = "pepper's" > > > @expectedAmount = 5 > > > > > > coupon = mock_model Coupon > > > current_user = mock_model User > > > controller.stub! (:current_user).and_return(current_user) > > > > > > > Coupon.should_receive(:new).with({"name"=>@expectedName,"amount"=>@expectedAmount}).and_return(coupon) > > > coupon.should_receive(:user).with(current_user) > > > coupon.should_receive(:save) > > > end > > > > > > it "should tell the Coupon model to create a new coupon with the given > > > parameters and save" do > > > post > > > 'save_coupon',{:coupon=>{:name=>@expectedName,:amount=>@expectedAmount}} > > > end > > > > > > Here's the controller method: > > > > > > def save_coupon > > > coupon = Coupon.new(params[:coupon]) > > > coupon.user = current_user > > > coupon.save > > > redirect_to_index "Coupon Added!" > > > end This one example is doing too much IMO. You even say "I am writing a spec to say that my CouponController should create a new coupon from the form parameters, then set the current user." That's two things. Generally I try to keep stubs in before(:each), expectations in the examples, and one example for each concept that I'm describing. I took the liberty of pastie-ing what I'd probably do. I haven't run it, so it might not work as/is, but you'll get the idea. http://pastie.caboo.se/142403 Cheers, David PS - I'm really glad to see you getting involved with this list. > > > > > > And, I get the following failure: > > > > > > Mock 'Coupon_1008' received unexpected message :user= with > (# > > @name="User_1009">) > > > > > > That's from this line in save_coupon: > > > > coupon.user = current_user > > > > Just need to stub that: > > > > coupon.stub!(:user=) > > > > Or you could expect it: > > > > > > coupon.should_receive (:user=).with(current_user) > > > > Cheers, > > David > > > > > > > > > > I'm sure that I'm missing something very simple, but I've been staring > at it > > > for too long. > > > > > > (also, if anyone has commented on my style, please feel free to mention > it, > > > as I'm still adjusting my mind to rspec) > > > > > > Oh, versions, I almost forgot: > > > rails 2.0.2 > > > rspec(_on_rails) plugins just updated from current a couple days ago, > not > > > totally sure how to get the versions of the plugins > > > > > > > > > Thanks. > > > -Corey > > > > > > -- > > > http://www.coreyhaines.com > > > The Internet's Premiere source of information about Corey Haines > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > -- > > > http://www.coreyhaines.com > The Internet's Premiere source of information about Corey Haines > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From coreyhaines at gmail.com Wed Jan 23 10:24:47 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Wed, 23 Jan 2008 10:24:47 -0500 Subject: [rspec-users] Not seeing the failure In-Reply-To: <57c63afe0801230703r7a5d3897t7b8298ae9c987306@mail.gmail.com> References: <6bdacb70801230641h18c42784v4e03cc6d5b4eb355@mail.gmail.com> <57c63afe0801230646s60adff48k5e01920aef26dd04@mail.gmail.com> <6bdacb70801230649g2bc689acrb2267f5653480276@mail.gmail.com> <57c63afe0801230703r7a5d3897t7b8298ae9c987306@mail.gmail.com> Message-ID: <6bdacb70801230724x506b1163wd66b8696c0fa69d5@mail.gmail.com> Thanks, David! Here's what I morphed the specs into: http://pastie.caboo.se/142411 And, I ended up with a blog entry that I'll write tonight. Basically, here's the situation I've been running into which is causing my specs to grow. If I don't set up something to tell the coupon that it is going to have :user= called on it, then the other tests fails. I didn't want to stub it, as I want this to be part of my expectations. Luckily, it only took a minute to come up with a possible solution, again relying on the fact that things tend to work how I think they should. The solution I thought of was to set the stub! call in the before(:each), then set an actual expectation in the spec. In my mind, the expectation should override the stub (making sure it gets called), but the stub will allow the other tests to pass. Fantastic! It works. I'm going to write up a blog entry on this pattern, and I'll send a link when I post it. Thanks for your help. -Corey On Jan 23, 2008 10:03 AM, David Chelimsky wrote: > On Jan 23, 2008 8:49 AM, Corey Haines wrote: > > Of course. Thanks, David! I still am getting used to user=, rather than > just > > user. Thanks again. > > No problem. I certainly got caught by that early on. > > I have some more general comments. See below: > > > > > -Corey > > > > > > > > On Jan 23, 2008 9:46 AM, David Chelimsky < dchelimsky at gmail.com> wrote: > > > > > > On Jan 23, 2008 8:41 AM, Corey Haines < coreyhaines at gmail.com> wrote: > > > > > > > > > > > > > All, > > > > > > > > I'm missing something simple, I think. I am writing a spec to say > that > > my > > > > CouponController should create a new coupon from the form > parameters, > > then > > > > set the current user. Here's the spec: > > > > > > > > describe CouponController, "When posting to save_coupon" do > > > > > > > > before(:each) do > > > > @expectedName = "pepper's" > > > > @expectedAmount = 5 > > > > > > > > coupon = mock_model Coupon > > > > current_user = mock_model User > > > > controller.stub! (:current_user).and_return(current_user) > > > > > > > > > > Coupon.should_receive > (:new).with({"name"=>@expectedName,"amount"=>@expectedAmount}).and_return(coupon) > > > > coupon.should_receive(:user).with(current_user) > > > > coupon.should_receive(:save) > > > > end > > > > > > > > it "should tell the Coupon model to create a new coupon with the > given > > > > parameters and save" do > > > > post > > > > > 'save_coupon',{:coupon=>{:name=>@expectedName,:amount=>@expectedAmount}} > > > > end > > > > > > > > Here's the controller method: > > > > > > > > def save_coupon > > > > coupon = Coupon.new(params[:coupon]) > > > > coupon.user = current_user > > > > coupon.save > > > > redirect_to_index "Coupon Added!" > > > > end > > This one example is doing too much IMO. You even say "I am writing a > spec to say that my CouponController should create a new coupon from > the form parameters, then set the current user." That's two things. > > Generally I try to keep stubs in before(:each), expectations in the > examples, and one example for each concept that I'm describing. > > I took the liberty of pastie-ing what I'd probably do. I haven't run > it, so it might not work as/is, but you'll get the idea. > > http://pastie.caboo.se/142403 > > Cheers, > David > > PS - I'm really glad to see you getting involved with this list. > > > > > > > > > > And, I get the following failure: > > > > > > > > Mock 'Coupon_1008' received unexpected message :user= with > > (# > > > @name="User_1009">) > > > > > > > > > That's from this line in save_coupon: > > > > > > coupon.user = current_user > > > > > > Just need to stub that: > > > > > > coupon.stub!(:user=) > > > > > > Or you could expect it: > > > > > > > > > coupon.should_receive (:user=).with(current_user) > > > > > > Cheers, > > > David > > > > > > > > > > > > > > I'm sure that I'm missing something very simple, but I've been > staring > > at it > > > > for too long. > > > > > > > > (also, if anyone has commented on my style, please feel free to > mention > > it, > > > > as I'm still adjusting my mind to rspec) > > > > > > > > Oh, versions, I almost forgot: > > > > rails 2.0.2 > > > > rspec(_on_rails) plugins just updated from current a couple days > ago, > > not > > > > totally sure how to get the versions of the plugins > > > > > > > > > > > > Thanks. > > > > -Corey > > > > > > > > -- > > > > http://www.coreyhaines.com > > > > The Internet's Premiere source of information about Corey Haines > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > -- > > > > > > http://www.coreyhaines.com > > The Internet's Premiere source of information about Corey Haines > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080123/79fdbc49/attachment-0001.html From dchelimsky at gmail.com Wed Jan 23 10:35:45 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 23 Jan 2008 09:35:45 -0600 Subject: [rspec-users] Not seeing the failure In-Reply-To: <6bdacb70801230724x506b1163wd66b8696c0fa69d5@mail.gmail.com> References: <6bdacb70801230641h18c42784v4e03cc6d5b4eb355@mail.gmail.com> <57c63afe0801230646s60adff48k5e01920aef26dd04@mail.gmail.com> <6bdacb70801230649g2bc689acrb2267f5653480276@mail.gmail.com> <57c63afe0801230703r7a5d3897t7b8298ae9c987306@mail.gmail.com> <6bdacb70801230724x506b1163wd66b8696c0fa69d5@mail.gmail.com> Message-ID: <57c63afe0801230735t6e57bc63n2f8ae41c0b91cd9a@mail.gmail.com> On Jan 23, 2008 9:24 AM, Corey Haines wrote: > Thanks, David! > > Here's what I morphed the specs into: > > http://pastie.caboo.se/142411 > > And, I ended up with a blog entry that I'll write tonight. > > Basically, here's the situation I've been running into which is causing my > specs to grow. > > If I don't set up something to tell the coupon that it is going to have > :user= called on it, then the other tests fails. I didn't want to stub it, > as I want this to be part of my expectations. Luckily, it only took a minute > to come up with a possible solution, again relying on the fact that things > tend to work how I think they should. > > The solution I thought of was to set the stub! call in the before(:each), > then set an actual expectation in the spec. Actually - that's what mine did to. These two are the same: coupon = mock_model(Coupon, :user= => nil, :save => true ) coupon = mock_model Coupon coupon.stub!(:user=) coupon.stub!(:save).and_return(true) :) Looking forward to your blog. Cheers, David > In my mind, the expectation > should override the stub (making sure it gets called), but the stub will > allow the other tests to pass. Fantastic! It works. I'm going to write up a > blog entry on this pattern, and I'll send a link when I post it. > > Thanks for your help. > -Corey > > > > > > On Jan 23, 2008 10:03 AM, David Chelimsky wrote: > > > > On Jan 23, 2008 8:49 AM, Corey Haines wrote: > > > Of course. Thanks, David! I still am getting used to user=, rather than > just > > > user. Thanks again. > > > > No problem. I certainly got caught by that early on. > > > > I have some more general comments. See below: > > > > > > > > > > > > > > -Corey > > > > > > > > > > > > On Jan 23, 2008 9:46 AM, David Chelimsky < dchelimsky at gmail.com> wrote: > > > > > > > > On Jan 23, 2008 8:41 AM, Corey Haines < coreyhaines at gmail.com> wrote: > > > > > > > > > > > > > > > > > All, > > > > > > > > > > I'm missing something simple, I think. I am writing a spec to say > that > > > my > > > > > CouponController should create a new coupon from the form > parameters, > > > then > > > > > set the current user. Here's the spec: > > > > > > > > > > describe CouponController, "When posting to save_coupon" do > > > > > > > > > > before(:each) do > > > > > @expectedName = "pepper's" > > > > > @expectedAmount = 5 > > > > > > > > > > coupon = mock_model Coupon > > > > > current_user = mock_model User > > > > > controller.stub! (:current_user).and_return(current_user) > > > > > > > > > > > > > > Coupon.should_receive(:new).with({"name"=>@expectedName,"amount"=>@expectedAmount}).and_return(coupon) > > > > > coupon.should_receive(:user).with(current_user) > > > > > coupon.should_receive(:save) > > > > > end > > > > > > > > > > it "should tell the Coupon model to create a new coupon with the > given > > > > > parameters and save" do > > > > > post > > > > > > 'save_coupon',{:coupon=>{:name=>@expectedName,:amount=>@expectedAmount}} > > > > > end > > > > > > > > > > Here's the controller method: > > > > > > > > > > def save_coupon > > > > > coupon = Coupon.new(params[:coupon]) > > > > > coupon.user = current_user > > > > > coupon.save > > > > > redirect_to_index "Coupon Added!" > > > > > end > > > > This one example is doing too much IMO. You even say "I am writing a > > > > spec to say that my CouponController should create a new coupon from > > the form parameters, then set the current user." That's two things. > > > > Generally I try to keep stubs in before(:each), expectations in the > > examples, and one example for each concept that I'm describing. > > > > I took the liberty of pastie-ing what I'd probably do. I haven't run > > it, so it might not work as/is, but you'll get the idea. > > > > http://pastie.caboo.se/142403 > > > > Cheers, > > David > > > > PS - I'm really glad to see you getting involved with this list. > > > > > > > > > > > > > > > > > > > > And, I get the following failure: > > > > > > > > > > Mock 'Coupon_1008' received unexpected message :user= with > > > (# > > > > @name="User_1009">) > > > > > > > > > > > > That's from this line in save_coupon: > > > > > > > > coupon.user = current_user > > > > > > > > Just need to stub that: > > > > > > > > coupon.stub!(:user=) > > > > > > > > Or you could expect it: > > > > > > > > > > > > coupon.should_receive (:user=).with(current_user) > > > > > > > > Cheers, > > > > David > > > > > > > > > > > > > > > > > > I'm sure that I'm missing something very simple, but I've been > staring > > > at it > > > > > for too long. > > > > > > > > > > (also, if anyone has commented on my style, please feel free to > mention > > > it, > > > > > as I'm still adjusting my mind to rspec) > > > > > > > > > > Oh, versions, I almost forgot: > > > > > rails 2.0.2 > > > > > rspec(_on_rails) plugins just updated from current a couple days > ago, > > > not > > > > > totally sure how to get the versions of the plugins > > > > > > > > > > > > > > > Thanks. > > > > > -Corey > > > > > > > > > > -- > > > > > http://www.coreyhaines.com > > > > > The Internet's Premiere source of information about Corey Haines > > > > > _______________________________________________ > > > > > rspec-users mailing list > > > > > rspec-users at rubyforge.org > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > -- > > > > > > > > > http://www.coreyhaines.com > > > The Internet's Premiere source of information about Corey Haines > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > -- > http://www.coreyhaines.com > The Internet's Premiere source of information about Corey Haines > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Wed Jan 23 10:36:51 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 23 Jan 2008 09:36:51 -0600 Subject: [rspec-users] Not seeing the failure In-Reply-To: <57c63afe0801230735t6e57bc63n2f8ae41c0b91cd9a@mail.gmail.com> References: <6bdacb70801230641h18c42784v4e03cc6d5b4eb355@mail.gmail.com> <57c63afe0801230646s60adff48k5e01920aef26dd04@mail.gmail.com> <6bdacb70801230649g2bc689acrb2267f5653480276@mail.gmail.com> <57c63afe0801230703r7a5d3897t7b8298ae9c987306@mail.gmail.com> <6bdacb70801230724x506b1163wd66b8696c0fa69d5@mail.gmail.com> <57c63afe0801230735t6e57bc63n2f8ae41c0b91cd9a@mail.gmail.com> Message-ID: <57c63afe0801230736r5cfe3701rf061a2e7cf546621@mail.gmail.com> On Jan 23, 2008 9:35 AM, David Chelimsky wrote: > On Jan 23, 2008 9:24 AM, Corey Haines wrote: > > Thanks, David! > > > > Here's what I morphed the specs into: > > > > http://pastie.caboo.se/142411 > > > > And, I ended up with a blog entry that I'll write tonight. > > > > Basically, here's the situation I've been running into which is causing my > > specs to grow. > > > > If I don't set up something to tell the coupon that it is going to have > > :user= called on it, then the other tests fails. I didn't want to stub it, > > as I want this to be part of my expectations. Luckily, it only took a minute > > to come up with a possible solution, again relying on the fact that things > > tend to work how I think they should. > > > > The solution I thought of was to set the stub! call in the before(:each), > > then set an actual expectation in the spec. > > Actually - that's what mine did to. These two are the same: > > coupon = mock_model(Coupon, > :user= => nil, > :save => true > ) > > coupon = mock_model Coupon > coupon.stub!(:user=) > coupon.stub!(:save).and_return(true) > > :) > > Looking forward to your blog. > > Cheers, > David > > > > In my mind, the expectation > > should override the stub (making sure it gets called), but the stub will > > allow the other tests to pass. Fantastic! It works. I'm going to write up a > > blog entry on this pattern, and I'll send a link when I post it. FYI - http://blog.davidchelimsky.net/articles/2006/11/09/tutorial-rspec-stubs-and-mocks > > > > Thanks for your help. > > -Corey > > > > > > > > > > > > On Jan 23, 2008 10:03 AM, David Chelimsky wrote: > > > > > > On Jan 23, 2008 8:49 AM, Corey Haines wrote: > > > > Of course. Thanks, David! I still am getting used to user=, rather than > > just > > > > user. Thanks again. > > > > > > No problem. I certainly got caught by that early on. > > > > > > I have some more general comments. See below: > > > > > > > > > > > > > > > > > > > > -Corey > > > > > > > > > > > > > > > > On Jan 23, 2008 9:46 AM, David Chelimsky < dchelimsky at gmail.com> wrote: > > > > > > > > > > On Jan 23, 2008 8:41 AM, Corey Haines < coreyhaines at gmail.com> wrote: > > > > > > > > > > > > > > > > > > > > > All, > > > > > > > > > > > > I'm missing something simple, I think. I am writing a spec to say > > that > > > > my > > > > > > CouponController should create a new coupon from the form > > parameters, > > > > then > > > > > > set the current user. Here's the spec: > > > > > > > > > > > > describe CouponController, "When posting to save_coupon" do > > > > > > > > > > > > before(:each) do > > > > > > @expectedName = "pepper's" > > > > > > @expectedAmount = 5 > > > > > > > > > > > > coupon = mock_model Coupon > > > > > > current_user = mock_model User > > > > > > controller.stub! (:current_user).and_return(current_user) > > > > > > > > > > > > > > > > > > Coupon.should_receive(:new).with({"name"=>@expectedName,"amount"=>@expectedAmount}).and_return(coupon) > > > > > > coupon.should_receive(:user).with(current_user) > > > > > > coupon.should_receive(:save) > > > > > > end > > > > > > > > > > > > it "should tell the Coupon model to create a new coupon with the > > given > > > > > > parameters and save" do > > > > > > post > > > > > > > > 'save_coupon',{:coupon=>{:name=>@expectedName,:amount=>@expectedAmount}} > > > > > > end > > > > > > > > > > > > Here's the controller method: > > > > > > > > > > > > def save_coupon > > > > > > coupon = Coupon.new(params[:coupon]) > > > > > > coupon.user = current_user > > > > > > coupon.save > > > > > > redirect_to_index "Coupon Added!" > > > > > > end > > > > > > This one example is doing too much IMO. You even say "I am writing a > > > > > > spec to say that my CouponController should create a new coupon from > > > the form parameters, then set the current user." That's two things. > > > > > > Generally I try to keep stubs in before(:each), expectations in the > > > examples, and one example for each concept that I'm describing. > > > > > > I took the liberty of pastie-ing what I'd probably do. I haven't run > > > it, so it might not work as/is, but you'll get the idea. > > > > > > http://pastie.caboo.se/142403 > > > > > > Cheers, > > > David > > > > > > PS - I'm really glad to see you getting involved with this list. > > > > > > > > > > > > > > > > > > > > > > > > > > > And, I get the following failure: > > > > > > > > > > > > Mock 'Coupon_1008' received unexpected message :user= with > > > > (# > > > > > @name="User_1009">) > > > > > > > > > > > > > > > That's from this line in save_coupon: > > > > > > > > > > coupon.user = current_user > > > > > > > > > > Just need to stub that: > > > > > > > > > > coupon.stub!(:user=) > > > > > > > > > > Or you could expect it: > > > > > > > > > > > > > > > coupon.should_receive (:user=).with(current_user) > > > > > > > > > > Cheers, > > > > > David > > > > > > > > > > > > > > > > > > > > > > I'm sure that I'm missing something very simple, but I've been > > staring > > > > at it > > > > > > for too long. > > > > > > > > > > > > (also, if anyone has commented on my style, please feel free to > > mention > > > > it, > > > > > > as I'm still adjusting my mind to rspec) > > > > > > > > > > > > Oh, versions, I almost forgot: > > > > > > rails 2.0.2 > > > > > > rspec(_on_rails) plugins just updated from current a couple days > > ago, > > > > not > > > > > > totally sure how to get the versions of the plugins > > > > > > > > > > > > > > > > > > Thanks. > > > > > > -Corey > > > > > > > > > > > > -- > > > > > > http://www.coreyhaines.com > > > > > > The Internet's Premiere source of information about Corey Haines > > > > > > _______________________________________________ > > > > > > rspec-users mailing list > > > > > > rspec-users at rubyforge.org > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > _______________________________________________ > > > > > rspec-users mailing list > > > > > rspec-users at rubyforge.org > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > > > > > > -- > > > > > > > > > > > > http://www.coreyhaines.com > > > > The Internet's Premiere source of information about Corey Haines > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > -- > > http://www.coreyhaines.com > > The Internet's Premiere source of information about Corey Haines > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > From coreyhaines at gmail.com Wed Jan 23 11:00:59 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Wed, 23 Jan 2008 11:00:59 -0500 Subject: [rspec-users] Not seeing the failure In-Reply-To: <57c63afe0801230735t6e57bc63n2f8ae41c0b91cd9a@mail.gmail.com> References: <6bdacb70801230641h18c42784v4e03cc6d5b4eb355@mail.gmail.com> <57c63afe0801230646s60adff48k5e01920aef26dd04@mail.gmail.com> <6bdacb70801230649g2bc689acrb2267f5653480276@mail.gmail.com> <57c63afe0801230703r7a5d3897t7b8298ae9c987306@mail.gmail.com> <6bdacb70801230724x506b1163wd66b8696c0fa69d5@mail.gmail.com> <57c63afe0801230735t6e57bc63n2f8ae41c0b91cd9a@mail.gmail.com> Message-ID: <6bdacb70801230800s2af098c2xa4b2e8bcc38aae3b@mail.gmail.com> Strange. I'll try it again, but it failed, which was why I added the stub. Let me see if I mis-typed something. On Jan 23, 2008 10:35 AM, David Chelimsky wrote: > On Jan 23, 2008 9:24 AM, Corey Haines wrote: > > Thanks, David! > > > > Here's what I morphed the specs into: > > > > http://pastie.caboo.se/142411 > > > > And, I ended up with a blog entry that I'll write tonight. > > > > Basically, here's the situation I've been running into which is causing > my > > specs to grow. > > > > If I don't set up something to tell the coupon that it is going to have > > :user= called on it, then the other tests fails. I didn't want to stub > it, > > as I want this to be part of my expectations. Luckily, it only took a > minute > > to come up with a possible solution, again relying on the fact that > things > > tend to work how I think they should. > > > > The solution I thought of was to set the stub! call in the > before(:each), > > then set an actual expectation in the spec. > > Actually - that's what mine did to. These two are the same: > > coupon = mock_model(Coupon, > :user= => nil, > :save => true > ) > > coupon = mock_model Coupon > coupon.stub!(:user=) > coupon.stub!(:save).and_return(true) > > :) > > Looking forward to your blog. > > Cheers, > David > > > In my mind, the expectation > > should override the stub (making sure it gets called), but the stub will > > allow the other tests to pass. Fantastic! It works. I'm going to write > up a > > blog entry on this pattern, and I'll send a link when I post it. > > > > Thanks for your help. > > -Corey > > > > > > > > > > > > On Jan 23, 2008 10:03 AM, David Chelimsky wrote: > > > > > > On Jan 23, 2008 8:49 AM, Corey Haines wrote: > > > > Of course. Thanks, David! I still am getting used to user=, rather > than > > just > > > > user. Thanks again. > > > > > > No problem. I certainly got caught by that early on. > > > > > > I have some more general comments. See below: > > > > > > > > > > > > > > > > > > > > -Corey > > > > > > > > > > > > > > > > On Jan 23, 2008 9:46 AM, David Chelimsky < dchelimsky at gmail.com> > wrote: > > > > > > > > > > On Jan 23, 2008 8:41 AM, Corey Haines < coreyhaines at gmail.com> > wrote: > > > > > > > > > > > > > > > > > > > > > All, > > > > > > > > > > > > I'm missing something simple, I think. I am writing a spec to > say > > that > > > > my > > > > > > CouponController should create a new coupon from the form > > parameters, > > > > then > > > > > > set the current user. Here's the spec: > > > > > > > > > > > > describe CouponController, "When posting to save_coupon" do > > > > > > > > > > > > before(:each) do > > > > > > @expectedName = "pepper's" > > > > > > @expectedAmount = 5 > > > > > > > > > > > > coupon = mock_model Coupon > > > > > > current_user = mock_model User > > > > > > controller.stub! (:current_user).and_return(current_user) > > > > > > > > > > > > > > > > > > Coupon.should_receive > (:new).with({"name"=>@expectedName,"amount"=>@expectedAmount}).and_return(coupon) > > > > > > coupon.should_receive(:user).with(current_user) > > > > > > coupon.should_receive(:save) > > > > > > end > > > > > > > > > > > > it "should tell the Coupon model to create a new coupon with > the > > given > > > > > > parameters and save" do > > > > > > post > > > > > > > > 'save_coupon',{:coupon=>{:name=>@expectedName,:amount=>@expectedAmount}} > > > > > > end > > > > > > > > > > > > Here's the controller method: > > > > > > > > > > > > def save_coupon > > > > > > coupon = Coupon.new(params[:coupon]) > > > > > > coupon.user = current_user > > > > > > coupon.save > > > > > > redirect_to_index "Coupon Added!" > > > > > > end > > > > > > This one example is doing too much IMO. You even say "I am writing a > > > > > > spec to say that my CouponController should create a new coupon from > > > the form parameters, then set the current user." That's two things. > > > > > > Generally I try to keep stubs in before(:each), expectations in the > > > examples, and one example for each concept that I'm describing. > > > > > > I took the liberty of pastie-ing what I'd probably do. I haven't run > > > it, so it might not work as/is, but you'll get the idea. > > > > > > http://pastie.caboo.se/142403 > > > > > > Cheers, > > > David > > > > > > PS - I'm really glad to see you getting involved with this list. > > > > > > > > > > > > > > > > > > > > > > > > > > > And, I get the following failure: > > > > > > > > > > > > Mock 'Coupon_1008' received unexpected message :user= with > > > > (# > > > > > @name="User_1009">) > > > > > > > > > > > > > > > That's from this line in save_coupon: > > > > > > > > > > coupon.user = current_user > > > > > > > > > > Just need to stub that: > > > > > > > > > > coupon.stub!(:user=) > > > > > > > > > > Or you could expect it: > > > > > > > > > > > > > > > coupon.should_receive (:user=).with(current_user) > > > > > > > > > > Cheers, > > > > > David > > > > > > > > > > > > > > > > > > > > > > I'm sure that I'm missing something very simple, but I've been > > staring > > > > at it > > > > > > for too long. > > > > > > > > > > > > (also, if anyone has commented on my style, please feel free to > > mention > > > > it, > > > > > > as I'm still adjusting my mind to rspec) > > > > > > > > > > > > Oh, versions, I almost forgot: > > > > > > rails 2.0.2 > > > > > > rspec(_on_rails) plugins just updated from current a couple days > > ago, > > > > not > > > > > > totally sure how to get the versions of the plugins > > > > > > > > > > > > > > > > > > Thanks. > > > > > > -Corey > > > > > > > > > > > > -- > > > > > > http://www.coreyhaines.com > > > > > > The Internet's Premiere source of information about Corey Haines > > > > > > _______________________________________________ > > > > > > rspec-users mailing list > > > > > > rspec-users at rubyforge.org > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > _______________________________________________ > > > > > rspec-users mailing list > > > > > rspec-users at rubyforge.org > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > > > > > > -- > > > > > > > > > > > > http://www.coreyhaines.com > > > > The Internet's Premiere source of information about Corey Haines > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > -- > > http://www.coreyhaines.com > > The Internet's Premiere source of information about Corey Haines > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080123/02efdab8/attachment-0001.html From coreyhaines at gmail.com Wed Jan 23 11:02:51 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Wed, 23 Jan 2008 11:02:51 -0500 Subject: [rspec-users] Not seeing the failure In-Reply-To: <57c63afe0801230735t6e57bc63n2f8ae41c0b91cd9a@mail.gmail.com> References: <6bdacb70801230641h18c42784v4e03cc6d5b4eb355@mail.gmail.com> <57c63afe0801230646s60adff48k5e01920aef26dd04@mail.gmail.com> <6bdacb70801230649g2bc689acrb2267f5653480276@mail.gmail.com> <57c63afe0801230703r7a5d3897t7b8298ae9c987306@mail.gmail.com> <6bdacb70801230724x506b1163wd66b8696c0fa69d5@mail.gmail.com> <57c63afe0801230735t6e57bc63n2f8ae41c0b91cd9a@mail.gmail.com> Message-ID: <6bdacb70801230802v5036e984vc75a80318e1ed960@mail.gmail.com> I get the unexpected message :user= failure. When you set up the mock with the initial parameters, wouldn't those be stubbing: @coupon.stub!(:user).and_return(@current_user) While, my spec says that I want :user= to be called? -corey On Jan 23, 2008 10:35 AM, David Chelimsky wrote: > On Jan 23, 2008 9:24 AM, Corey Haines wrote: > > Thanks, David! > > > > Here's what I morphed the specs into: > > > > http://pastie.caboo.se/142411 > > > > And, I ended up with a blog entry that I'll write tonight. > > > > Basically, here's the situation I've been running into which is causing > my > > specs to grow. > > > > If I don't set up something to tell the coupon that it is going to have > > :user= called on it, then the other tests fails. I didn't want to stub > it, > > as I want this to be part of my expectations. Luckily, it only took a > minute > > to come up with a possible solution, again relying on the fact that > things > > tend to work how I think they should. > > > > The solution I thought of was to set the stub! call in the > before(:each), > > then set an actual expectation in the spec. > > Actually - that's what mine did to. These two are the same: > > coupon = mock_model(Coupon, > :user= => nil, > :save => true > ) > > coupon = mock_model Coupon > coupon.stub!(:user=) > coupon.stub!(:save).and_return(true) > > :) > > Looking forward to your blog. > > Cheers, > David > > > In my mind, the expectation > > should override the stub (making sure it gets called), but the stub will > > allow the other tests to pass. Fantastic! It works. I'm going to write > up a > > blog entry on this pattern, and I'll send a link when I post it. > > > > Thanks for your help. > > -Corey > > > > > > > > > > > > On Jan 23, 2008 10:03 AM, David Chelimsky wrote: > > > > > > On Jan 23, 2008 8:49 AM, Corey Haines wrote: > > > > Of course. Thanks, David! I still am getting used to user=, rather > than > > just > > > > user. Thanks again. > > > > > > No problem. I certainly got caught by that early on. > > > > > > I have some more general comments. See below: > > > > > > > > > > > > > > > > > > > > -Corey > > > > > > > > > > > > > > > > On Jan 23, 2008 9:46 AM, David Chelimsky < dchelimsky at gmail.com> > wrote: > > > > > > > > > > On Jan 23, 2008 8:41 AM, Corey Haines < coreyhaines at gmail.com> > wrote: > > > > > > > > > > > > > > > > > > > > > All, > > > > > > > > > > > > I'm missing something simple, I think. I am writing a spec to > say > > that > > > > my > > > > > > CouponController should create a new coupon from the form > > parameters, > > > > then > > > > > > set the current user. Here's the spec: > > > > > > > > > > > > describe CouponController, "When posting to save_coupon" do > > > > > > > > > > > > before(:each) do > > > > > > @expectedName = "pepper's" > > > > > > @expectedAmount = 5 > > > > > > > > > > > > coupon = mock_model Coupon > > > > > > current_user = mock_model User > > > > > > controller.stub! (:current_user).and_return(current_user) > > > > > > > > > > > > > > > > > > Coupon.should_receive > (:new).with({"name"=>@expectedName,"amount"=>@expectedAmount}).and_return(coupon) > > > > > > coupon.should_receive(:user).with(current_user) > > > > > > coupon.should_receive(:save) > > > > > > end > > > > > > > > > > > > it "should tell the Coupon model to create a new coupon with > the > > given > > > > > > parameters and save" do > > > > > > post > > > > > > > > 'save_coupon',{:coupon=>{:name=>@expectedName,:amount=>@expectedAmount}} > > > > > > end > > > > > > > > > > > > Here's the controller method: > > > > > > > > > > > > def save_coupon > > > > > > coupon = Coupon.new(params[:coupon]) > > > > > > coupon.user = current_user > > > > > > coupon.save > > > > > > redirect_to_index "Coupon Added!" > > > > > > end > > > > > > This one example is doing too much IMO. You even say "I am writing a > > > > > > spec to say that my CouponController should create a new coupon from > > > the form parameters, then set the current user." That's two things. > > > > > > Generally I try to keep stubs in before(:each), expectations in the > > > examples, and one example for each concept that I'm describing. > > > > > > I took the liberty of pastie-ing what I'd probably do. I haven't run > > > it, so it might not work as/is, but you'll get the idea. > > > > > > http://pastie.caboo.se/142403 > > > > > > Cheers, > > > David > > > > > > PS - I'm really glad to see you getting involved with this list. > > > > > > > > > > > > > > > > > > > > > > > > > > > And, I get the following failure: > > > > > > > > > > > > Mock 'Coupon_1008' received unexpected message :user= with > > > > (# > > > > > @name="User_1009">) > > > > > > > > > > > > > > > That's from this line in save_coupon: > > > > > > > > > > coupon.user = current_user > > > > > > > > > > Just need to stub that: > > > > > > > > > > coupon.stub!(:user=) > > > > > > > > > > Or you could expect it: > > > > > > > > > > > > > > > coupon.should_receive (:user=).with(current_user) > > > > > > > > > > Cheers, > > > > > David > > > > > > > > > > > > > > > > > > > > > > I'm sure that I'm missing something very simple, but I've been > > staring > > > > at it > > > > > > for too long. > > > > > > > > > > > > (also, if anyone has commented on my style, please feel free to > > mention > > > > it, > > > > > > as I'm still adjusting my mind to rspec) > > > > > > > > > > > > Oh, versions, I almost forgot: > > > > > > rails 2.0.2 > > > > > > rspec(_on_rails) plugins just updated from current a couple days > > ago, > > > > not > > > > > > totally sure how to get the versions of the plugins > > > > > > > > > > > > > > > > > > Thanks. > > > > > > -Corey > > > > > > > > > > > > -- > > > > > > http://www.coreyhaines.com > > > > > > The Internet's Premiere source of information about Corey Haines > > > > > > _______________________________________________ > > > > > > rspec-users mailing list > > > > > > rspec-users at rubyforge.org > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > _______________________________________________ > > > > > rspec-users mailing list > > > > > rspec-users at rubyforge.org > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > > > > > > -- > > > > > > > > > > > > http://www.coreyhaines.com > > > > The Internet's Premiere source of information about Corey Haines > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > -- > > http://www.coreyhaines.com > > The Internet's Premiere source of information about Corey Haines > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080123/d59a3a47/attachment.html From coreyhaines at gmail.com Wed Jan 23 11:04:18 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Wed, 23 Jan 2008 11:04:18 -0500 Subject: [rspec-users] Not seeing the failure In-Reply-To: <57c63afe0801230736r5cfe3701rf061a2e7cf546621@mail.gmail.com> References: <6bdacb70801230641h18c42784v4e03cc6d5b4eb355@mail.gmail.com> <57c63afe0801230646s60adff48k5e01920aef26dd04@mail.gmail.com> <6bdacb70801230649g2bc689acrb2267f5653480276@mail.gmail.com> <57c63afe0801230703r7a5d3897t7b8298ae9c987306@mail.gmail.com> <6bdacb70801230724x506b1163wd66b8696c0fa69d5@mail.gmail.com> <57c63afe0801230735t6e57bc63n2f8ae41c0b91cd9a@mail.gmail.com> <57c63afe0801230736r5cfe3701rf061a2e7cf546621@mail.gmail.com> Message-ID: <6bdacb70801230804q258c15fpecfd59205655f599@mail.gmail.com> That's what I found. :) I'll reference that with my blog post. (I'll write it mostly for the experience, as it will basically outline just what your post says) On Jan 23, 2008 10:36 AM, David Chelimsky wrote: > > FYI - > http://blog.davidchelimsky.net/articles/2006/11/09/tutorial-rspec-stubs-and-mocks > > -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080123/25f9407a/attachment.html From jarkko at jlaine.net Wed Jan 23 11:50:25 2008 From: jarkko at jlaine.net (Jarkko Laine) Date: Wed, 23 Jan 2008 18:50:25 +0200 Subject: [rspec-users] Not seeing the failure In-Reply-To: <6bdacb70801230802v5036e984vc75a80318e1ed960@mail.gmail.com> References: <6bdacb70801230641h18c42784v4e03cc6d5b4eb355@mail.gmail.com> <57c63afe0801230646s60adff48k5e01920aef26dd04@mail.gmail.com> <6bdacb70801230649g2bc689acrb2267f5653480276@mail.gmail.com> <57c63afe0801230703r7a5d3897t7b8298ae9c987306@mail.gmail.com> <6bdacb70801230724x506b1163wd66b8696c0fa69d5@mail.gmail.com> <57c63afe0801230735t6e57bc63n2f8ae41c0b91cd9a@mail.gmail.com> <6bdacb70801230802v5036e984vc75a80318e1ed960@mail.gmail.com> Message-ID: <7C1E826F-C74A-41EE-A29E-A8B256EF6A2D@jlaine.net> On 23.1.2008, at 18.02, Corey Haines wrote: > I get the unexpected message :user= failure. > > When you set up the mock with the initial parameters, wouldn't those > be stubbing: @coupon.stub!(:user).and_return(@current_user) > You can do it like this: @coupon = mock_model(Coupon, :user= => nil, :user => @current_user, :save => true) That stubs both user= and user. I often create reusable "mock factories" in spec_helper.rb that take care of the normal methods for AR objects: def mock_coupon(opts = {}) mock_model(Coupon, {:user= => nil, :user => mock_user, :save => true}.merge(opts)) end Often I also stub the errors method there because it's called pretty often in controllers and views. //jarkko -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http://odesign.fi From coreyhaines at gmail.com Wed Jan 23 11:57:59 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Wed, 23 Jan 2008 11:57:59 -0500 Subject: [rspec-users] Not seeing the failure In-Reply-To: <7C1E826F-C74A-41EE-A29E-A8B256EF6A2D@jlaine.net> References: <6bdacb70801230641h18c42784v4e03cc6d5b4eb355@mail.gmail.com> <57c63afe0801230646s60adff48k5e01920aef26dd04@mail.gmail.com> <6bdacb70801230649g2bc689acrb2267f5653480276@mail.gmail.com> <57c63afe0801230703r7a5d3897t7b8298ae9c987306@mail.gmail.com> <6bdacb70801230724x506b1163wd66b8696c0fa69d5@mail.gmail.com> <57c63afe0801230735t6e57bc63n2f8ae41c0b91cd9a@mail.gmail.com> <6bdacb70801230802v5036e984vc75a80318e1ed960@mail.gmail.com> <7C1E826F-C74A-41EE-A29E-A8B256EF6A2D@jlaine.net> Message-ID: <6bdacb70801230857x12cb909cyae75aa1267d21a34@mail.gmail.com> Nope, that still didn't work. Still getting @coupon.stub!(:user=).with(@current_user) Here's my spec and code using your recommended way: spec - http://pastie.caboo.se/142451 code - http://pastie.caboo.se/142452 If I add back @coupon.stub!(:user=).with(@current_user) they pass. It seems as though the understanding is that setting up your mock with the options (:user => @current_user) should set stubs for both get and set, but it doesn't. I think it just sets up the stub for the get. -Corey On Jan 23, 2008 11:50 AM, Jarkko Laine wrote: > On 23.1.2008, at 18.02, Corey Haines wrote: > > > I get the unexpected message :user= failure. > > > > When you set up the mock with the initial parameters, wouldn't those > > be stubbing: @coupon.stub!(:user).and_return(@current_user) > > > > You can do it like this: > > @coupon = mock_model(Coupon, :user= => nil, :user => > @current_user, :save => true) > > That stubs both user= and user. I often create reusable "mock > factories" in spec_helper.rb that take care of the normal methods for > AR objects: > > def mock_coupon(opts = {}) > mock_model(Coupon, {:user= => nil, :user => mock_user, :save => > true}.merge(opts)) > end > > Often I also stub the errors method there because it's called pretty > often in controllers and views. > > //jarkko > > -- > Jarkko Laine > http://jlaine.net > http://dotherightthing.com > http://www.railsecommerce.com > http://odesign.fi > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080123/9abf8168/attachment-0001.html From coreyhaines at gmail.com Wed Jan 23 12:01:13 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Wed, 23 Jan 2008 12:01:13 -0500 Subject: [rspec-users] Not seeing the failure In-Reply-To: <6bdacb70801230857x12cb909cyae75aa1267d21a34@mail.gmail.com> References: <6bdacb70801230641h18c42784v4e03cc6d5b4eb355@mail.gmail.com> <57c63afe0801230646s60adff48k5e01920aef26dd04@mail.gmail.com> <6bdacb70801230649g2bc689acrb2267f5653480276@mail.gmail.com> <57c63afe0801230703r7a5d3897t7b8298ae9c987306@mail.gmail.com> <6bdacb70801230724x506b1163wd66b8696c0fa69d5@mail.gmail.com> <57c63afe0801230735t6e57bc63n2f8ae41c0b91cd9a@mail.gmail.com> <6bdacb70801230802v5036e984vc75a80318e1ed960@mail.gmail.com> <7C1E826F-C74A-41EE-A29E-A8B256EF6A2D@jlaine.net> <6bdacb70801230857x12cb909cyae75aa1267d21a34@mail.gmail.com> Message-ID: <6bdacb70801230901r64d28cf6vaa06a84855ec7df6@mail.gmail.com> Ooops, I mean still getting Mock 'Coupon_1011' received unexpected message :user= with (#) On Jan 23, 2008 11:57 AM, Corey Haines wrote: > Nope, that still didn't work. > Still getting > @coupon.stub!(:user=).with(@current_user) > > Here's my spec and code using your recommended way: > > spec - http://pastie.caboo.se/142451 > code - http://pastie.caboo.se/142452 > > If I add back > @coupon.stub!(:user=).with(@current_user) > > they pass. > > It seems as though the understanding is that setting up your mock with the > options (:user => @current_user) should set stubs for both get and set, but > it doesn't. I think it just sets up the stub for the get. > > -Corey > > > On Jan 23, 2008 11:50 AM, Jarkko Laine wrote: > > > On 23.1.2008, at 18.02, Corey Haines wrote: > > > > > I get the unexpected message :user= failure. > > > > > > When you set up the mock with the initial parameters, wouldn't those > > > be stubbing: @ coupon.stub!(:user).and_return(@current_user) > > > > > > > You can do it like this: > > > > @coupon = mock_model(Coupon, :user= => nil, :user => > > @current_user, :save => true) > > > > That stubs both user= and user. I often create reusable "mock > > factories" in spec_helper.rb that take care of the normal methods for > > AR objects: > > > > def mock_coupon(opts = {}) > > mock_model(Coupon, {:user= => nil, :user => mock_user, :save => > > true}.merge(opts)) > > end > > > > Often I also stub the errors method there because it's called pretty > > often in controllers and views. > > > > //jarkko > > > > -- > > Jarkko Laine > > http://jlaine.net > > http://dotherightthing.com > > http://www.railsecommerce.com > > http://odesign.fi > > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > -- > > http://www.coreyhaines.com > The Internet's Premiere source of information about Corey Haines > -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080123/1d42bc74/attachment.html From jarkko at jlaine.net Wed Jan 23 13:05:06 2008 From: jarkko at jlaine.net (Jarkko Laine) Date: Wed, 23 Jan 2008 20:05:06 +0200 Subject: [rspec-users] Not seeing the failure In-Reply-To: <6bdacb70801230857x12cb909cyae75aa1267d21a34@mail.gmail.com> References: <6bdacb70801230641h18c42784v4e03cc6d5b4eb355@mail.gmail.com> <57c63afe0801230646s60adff48k5e01920aef26dd04@mail.gmail.com> <6bdacb70801230649g2bc689acrb2267f5653480276@mail.gmail.com> <57c63afe0801230703r7a5d3897t7b8298ae9c987306@mail.gmail.com> <6bdacb70801230724x506b1163wd66b8696c0fa69d5@mail.gmail.com> <57c63afe0801230735t6e57bc63n2f8ae41c0b91cd9a@mail.gmail.com> <6bdacb70801230802v5036e984vc75a80318e1ed960@mail.gmail.com> <7C1E826F-C74A-41EE-A29E-A8B256EF6A2D@jlaine.net> <6bdacb70801230857x12cb909cyae75aa1267d21a34@mail.gmail.com> Message-ID: <5D7D95CB-C8FF-49A6-9182-C88D61B5B056@jlaine.net> On 23.1.2008, at 18.57, Corey Haines wrote: > Nope, that still didn't work. > Still getting > @coupon.stub!(:user=).with(@current_user) > > Here's my spec and code using your recommended way: > > spec - http://pastie.caboo.se/142451 > code - http://pastie.caboo.se/142452 > > If I add back > @coupon.stub!(:user=).with(@current_user) > > they pass. > > It seems as though the understanding is that setting up your mock > with the options (:user => @current_user) should set stubs for both > get and set, but it doesn't. I think it just sets up the stub for > the get. I didn't say it would (and it doesn't and shouldn't): > You can do it like this: > > @coupon = mock_model(Coupon, :user= => nil, :user => > @current_user, :save => true) Note both :user= and :user. In your pastie you only have :user Cheers, //jarkko -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http://odesign.fi From ermok at tiscali.co.uk Wed Jan 23 16:45:14 2008 From: ermok at tiscali.co.uk (Neil M. Young) Date: Wed, 23 Jan 2008 13:45:14 -0800 (PST) Subject: [rspec-users] DRYing up stories Message-ID: <15053384.post@talk.nabble.com> I'm finding that I'm writing sets of very similar scenarios to check access permissions for each of my actions. Does anyone have suggestions on how to dry this up: Given an existing Account And a logged in Admin When the user visits account/manage Then he should get access Given an existing Account And a logged in Manager When the user visits account/manage Then he should get access Given an existing Account And a logged in Supervisor When the user visits account/manage Then he should not get access Given an existing Account And a logged in Reviewer When the user visits account/manage Then he should not get access Given an existing Account And a logged in User When the user visits account/manage Then he should not get access -- View this message in context: http://www.nabble.com/DRYing-up-stories-tp15053384p15053384.html Sent from the rspec-users mailing list archive at Nabble.com. From omen.king at gmail.com Wed Jan 23 16:47:33 2008 From: omen.king at gmail.com (Andrew WC Brown) Date: Wed, 23 Jan 2008 16:47:33 -0500 Subject: [rspec-users] DRYing up stories In-Reply-To: <15053384.post@talk.nabble.com> References: <15053384.post@talk.nabble.com> Message-ID: Do all of these scenarios exist in the same story? Should they be dried up? Would Clarity over Cleverness apply here? On Jan 23, 2008 4:45 PM, Neil M. Young wrote: > > I'm finding that I'm writing sets of very similar scenarios to check > access > permissions for each of my actions. Does anyone have suggestions on how to > dry this up: > > Given an existing Account > And a logged in Admin > When the user visits account/manage > Then he should get access > > Given an existing Account > And a logged in Manager > When the user visits account/manage > Then he should get access > > Given an existing Account > And a logged in Supervisor > When the user visits account/manage > Then he should not get access > > Given an existing Account > And a logged in Reviewer > When the user visits account/manage > Then he should not get access > > Given an existing Account > And a logged in User > When the user visits account/manage > Then he should not get access > > -- > View this message in context: > http://www.nabble.com/DRYing-up-stories-tp15053384p15053384.html > Sent from the rspec-users mailing list archive at Nabble.com. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080123/19f79cb3/attachment.html From coreyhaines at gmail.com Wed Jan 23 16:48:35 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Wed, 23 Jan 2008 16:48:35 -0500 Subject: [rspec-users] Not seeing the failure In-Reply-To: <5D7D95CB-C8FF-49A6-9182-C88D61B5B056@jlaine.net> References: <6bdacb70801230641h18c42784v4e03cc6d5b4eb355@mail.gmail.com> <57c63afe0801230646s60adff48k5e01920aef26dd04@mail.gmail.com> <6bdacb70801230649g2bc689acrb2267f5653480276@mail.gmail.com> <57c63afe0801230703r7a5d3897t7b8298ae9c987306@mail.gmail.com> <6bdacb70801230724x506b1163wd66b8696c0fa69d5@mail.gmail.com> <57c63afe0801230735t6e57bc63n2f8ae41c0b91cd9a@mail.gmail.com> <6bdacb70801230802v5036e984vc75a80318e1ed960@mail.gmail.com> <7C1E826F-C74A-41EE-A29E-A8B256EF6A2D@jlaine.net> <6bdacb70801230857x12cb909cyae75aa1267d21a34@mail.gmail.com> <5D7D95CB-C8FF-49A6-9182-C88D61B5B056@jlaine.net> Message-ID: <6bdacb70801231348o21561421g800449f6d2534511@mail.gmail.com> Ah, I completely missed the :user= => in your snippet. Sorry about that. It worked, though, just the way you described it. :) Here's my spec now, wonderful: http://pastie.caboo.se/142585 Thanks, David and Jarkko! -Corey On Jan 23, 2008 1:05 PM, Jarkko Laine wrote: > > On 23.1.2008, at 18.57, Corey Haines wrote: > > > Nope, that still didn't work. > > Still getting > > @coupon.stub!(:user=).with(@current_user) > > > > Here's my spec and code using your recommended way: > > > > spec - http://pastie.caboo.se/142451 > > code - http://pastie.caboo.se/142452 > > > > If I add back > > @coupon.stub!(:user=).with(@current_user) > > > > they pass. > > > > It seems as though the understanding is that setting up your mock > > with the options (:user => @current_user) should set stubs for both > > get and set, but it doesn't. I think it just sets up the stub for > > the get. > > I didn't say it would (and it doesn't and shouldn't): > > You can do it like this: > > > > @coupon = mock_model(Coupon, :user= => nil, :user => > > @current_user, :save => true) > > Note both :user= and :user. > > In your pastie you only have :user > > Cheers, > //jarkko > > -- > Jarkko Laine > http://jlaine.net > http://dotherightthing.com > http://www.railsecommerce.com > http://odesign.fi > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080123/612909c6/attachment.html From ben at benmabey.com Wed Jan 23 16:50:43 2008 From: ben at benmabey.com (Ben Mabey) Date: Wed, 23 Jan 2008 14:50:43 -0700 Subject: [rspec-users] DRYing up stories In-Reply-To: <15053384.post@talk.nabble.com> References: <15053384.post@talk.nabble.com> Message-ID: <4797B6B3.4020601@benmabey.com> Neil M. Young wrote: > I'm finding that I'm writing sets of very similar scenarios to check access > permissions for each of my actions. Does anyone have suggestions on how to > dry this up: > > Given an existing Account > And a logged in Admin > When the user visits account/manage > Then he should get access > > Given an existing Account > And a logged in Manager > When the user visits account/manage > Then he should get access > > Given an existing Account > And a logged in Supervisor > When the user visits account/manage > Then he should not get access > > Given an existing Account > And a logged in Reviewer > When the user visits account/manage > Then he should not get access > > Given an existing Account > And a logged in User > When the user visits account/manage > Then he should not get access > > I've been running into the same issue. Ryan Davis came up with the idea of a "functional test matrix": http://blog.zenspider.com/archives/2007/04/functional_test_matrix.html borrowing the spreadsheet idea from FIT.. Anyways, I have been trying to think of a way to apply something similar in conjunction with stories... Maybe generate and run stories based off a matrix for access control reasons? Does this give any one some ideas? -Ben From aslak.hellesoy at gmail.com Wed Jan 23 18:37:46 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Thu, 24 Jan 2008 00:37:46 +0100 Subject: [rspec-users] DRYing up stories In-Reply-To: <15053384.post@talk.nabble.com> References: <15053384.post@talk.nabble.com> Message-ID: <8d961d900801231537j6873fda4n2fc7338874569a24@mail.gmail.com> On Jan 23, 2008 10:45 PM, Neil M. Young wrote: > > I'm finding that I'm writing sets of very similar scenarios to check access > permissions for each of my actions. Does anyone have suggestions on how to > dry this up: > Beware that DRY has a cost. Clarity and readability. David's BDD manifesto (slightly rephrased): We prefer clarity over DRY (that is - while there is value in DRYness, we value clarity more) Aslak > Given an existing Account > And a logged in Admin > When the user visits account/manage > Then he should get access > > Given an existing Account > And a logged in Manager > When the user visits account/manage > Then he should get access > > Given an existing Account > And a logged in Supervisor > When the user visits account/manage > Then he should not get access > > Given an existing Account > And a logged in Reviewer > When the user visits account/manage > Then he should not get access > > Given an existing Account > And a logged in User > When the user visits account/manage > Then he should not get access > > -- > View this message in context: http://www.nabble.com/DRYing-up-stories-tp15053384p15053384.html > Sent from the rspec-users mailing list archive at Nabble.com. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ben at benmabey.com Wed Jan 23 19:04:45 2008 From: ben at benmabey.com (Ben Mabey) Date: Wed, 23 Jan 2008 17:04:45 -0700 Subject: [rspec-users] DRYing up stories In-Reply-To: <8d961d900801231537j6873fda4n2fc7338874569a24@mail.gmail.com> References: <15053384.post@talk.nabble.com> <8d961d900801231537j6873fda4n2fc7338874569a24@mail.gmail.com> Message-ID: <4797D61D.4080902@benmabey.com> While the original post had DRY in the subject line I don't see this as a DRY issue. I see it as a visualization and maintenance issue. If I add a new role and I want to test each action for it's permissions it would be much easier for a customer to go down a spread sheet and designate within each cell what the response should be.. success or failure, etc... This would give the customer a bird's eye view of permissions for the entire app for each class of users. By using a separate scenario for each role in each story you will be creating a lot of copy and past work which will comminucate the same information a spreadsheet would but a lot more inefficently since someone would have to read hundreds of pages of stories. I love the plain text stories. We just have to remember that there are better ways to express large amounts of data than plain English. :) Do you understand the point I'm trying to make? -Ben aslak hellesoy wrote: > On Jan 23, 2008 10:45 PM, Neil M. Young wrote: > >> I'm finding that I'm writing sets of very similar scenarios to check access >> permissions for each of my actions. Does anyone have suggestions on how to >> dry this up: >> >> > > Beware that DRY has a cost. Clarity and readability. > > David's BDD manifesto (slightly rephrased): > > We prefer clarity over DRY (that is - while there is value in DRYness, > we value clarity more) > > Aslak > > >> Given an existing Account >> And a logged in Admin >> When the user visits account/manage >> Then he should get access >> >> Given an existing Account >> And a logged in Manager >> When the user visits account/manage >> Then he should get access >> >> Given an existing Account >> And a logged in Supervisor >> When the user visits account/manage >> Then he should not get access >> >> Given an existing Account >> And a logged in Reviewer >> When the user visits account/manage >> Then he should not get access >> >> Given an existing Account >> And a logged in User >> When the user visits account/manage >> Then he should not get access >> >> -- >> View this message in context: http://www.nabble.com/DRYing-up-stories-tp15053384p15053384.html >> Sent from the rspec-users mailing list archive at Nabble.com. >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From kamal.fariz at gmail.com Wed Jan 23 22:30:28 2008 From: kamal.fariz at gmail.com (Kamal Fariz) Date: Thu, 24 Jan 2008 11:30:28 +0800 Subject: [rspec-users] DRYing up stories In-Reply-To: <4797D61D.4080902@benmabey.com> References: <15053384.post@talk.nabble.com> <8d961d900801231537j6873fda4n2fc7338874569a24@mail.gmail.com> <4797D61D.4080902@benmabey.com> Message-ID: <0055E4E8-73FB-446F-9EC7-BBF6A03DE717@gmail.com> Slightly OT, but what can be done to DRY up steps? For aesthetics and more natural sounding stories, I often have things like Given a user in the system and Given 2 users in the system where the small change is in the pluralization. What I currently do is to have two steps that essentially do the same thing (of course, converting 'a' to 1 before that). How can one alias a step? On Jan 24, 2008, at 8:04 AM, Ben Mabey wrote: > While the original post had DRY in the subject line I don't see this > as > a DRY issue. I see it as a visualization and maintenance issue. If I > add a new role and I want to test each action for it's permissions it > would be much easier for a customer to go down a spread sheet and > designate within each cell what the response should be.. success or > failure, etc... This would give the customer a bird's eye view of > permissions for the entire app for each class of users. By using a > separate scenario for each role in each story you will be creating a > lot > of copy and past work which will comminucate the same information a > spreadsheet would but a lot more inefficently since someone would have > to read hundreds of pages of stories. I love the plain text stories. > We just have to remember that there are better ways to express large > amounts of data than plain English. :) > Do you understand the point I'm trying to make? > > > -Ben > > > > aslak hellesoy wrote: >> On Jan 23, 2008 10:45 PM, Neil M. Young wrote: >> >>> I'm finding that I'm writing sets of very similar scenarios to >>> check access >>> permissions for each of my actions. Does anyone have suggestions >>> on how to >>> dry this up: >>> >>> >> >> Beware that DRY has a cost. Clarity and readability. >> >> David's BDD manifesto (slightly rephrased): >> >> We prefer clarity over DRY (that is - while there is value in >> DRYness, >> we value clarity more) >> >> Aslak >> >> >>> Given an existing Account >>> And a logged in Admin >>> When the user visits account/manage >>> Then he should get access >>> >>> Given an existing Account >>> And a logged in Manager >>> When the user visits account/manage >>> Then he should get access >>> >>> Given an existing Account >>> And a logged in Supervisor >>> When the user visits account/manage >>> Then he should not get access >>> >>> Given an existing Account >>> And a logged in Reviewer >>> When the user visits account/manage >>> Then he should not get access >>> >>> Given an existing Account >>> And a logged in User >>> When the user visits account/manage >>> Then he should not get access >>> >>> -- >>> View this message in context: http://www.nabble.com/DRYing-up-stories-tp15053384p15053384.html >>> Sent from the rspec-users mailing list archive at Nabble.com. >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >>> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Regards, Kamal From dchelimsky at gmail.com Thu Jan 24 00:39:53 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 23 Jan 2008 23:39:53 -0600 Subject: [rspec-users] DRYing up stories In-Reply-To: <0055E4E8-73FB-446F-9EC7-BBF6A03DE717@gmail.com> References: <15053384.post@talk.nabble.com> <8d961d900801231537j6873fda4n2fc7338874569a24@mail.gmail.com> <4797D61D.4080902@benmabey.com> <0055E4E8-73FB-446F-9EC7-BBF6A03DE717@gmail.com> Message-ID: <57c63afe0801232139mc8ab1e5qbd122c18136440d9@mail.gmail.com> On Jan 23, 2008 9:30 PM, Kamal Fariz wrote: > Slightly OT, but what can be done to DRY up steps? For aesthetics and > more natural sounding stories, I often have things like > > Given a user in the system > > and > > Given 2 users in the system > > where the small change is in the pluralization. What I currently do is > to have two steps that essentially do the same thing (of course, > converting 'a' to 1 before that). How can one alias a step? With 1.1.1 you can do this: Given "$n_users in the system" do |num_users| case num_users when "a user" # one user case when /(\d*) users/ # multi user case using $1 end end With 1.1.2 you can do this: Given /(a|\d*) users? in the system/ do |num_users| num_users = (num_users == 'a') ? 1 : num_users.to_i (1..num_users).each do # ... end end HTH, David > > > On Jan 24, 2008, at 8:04 AM, Ben Mabey wrote: > > > While the original post had DRY in the subject line I don't see this > > as > > a DRY issue. I see it as a visualization and maintenance issue. If I > > add a new role and I want to test each action for it's permissions it > > would be much easier for a customer to go down a spread sheet and > > designate within each cell what the response should be.. success or > > failure, etc... This would give the customer a bird's eye view of > > permissions for the entire app for each class of users. By using a > > separate scenario for each role in each story you will be creating a > > lot > > of copy and past work which will comminucate the same information a > > spreadsheet would but a lot more inefficently since someone would have > > to read hundreds of pages of stories. I love the plain text stories. > > We just have to remember that there are better ways to express large > > amounts of data than plain English. :) > > Do you understand the point I'm trying to make? > > > > > > -Ben > > > > > > > > aslak hellesoy wrote: > >> On Jan 23, 2008 10:45 PM, Neil M. Young wrote: > >> > >>> I'm finding that I'm writing sets of very similar scenarios to > >>> check access > >>> permissions for each of my actions. Does anyone have suggestions > >>> on how to > >>> dry this up: > >>> > >>> > >> > >> Beware that DRY has a cost. Clarity and readability. > >> > >> David's BDD manifesto (slightly rephrased): > >> > >> We prefer clarity over DRY (that is - while there is value in > >> DRYness, > >> we value clarity more) > >> > >> Aslak > >> > >> > >>> Given an existing Account > >>> And a logged in Admin > >>> When the user visits account/manage > >>> Then he should get access > >>> > >>> Given an existing Account > >>> And a logged in Manager > >>> When the user visits account/manage > >>> Then he should get access > >>> > >>> Given an existing Account > >>> And a logged in Supervisor > >>> When the user visits account/manage > >>> Then he should not get access > >>> > >>> Given an existing Account > >>> And a logged in Reviewer > >>> When the user visits account/manage > >>> Then he should not get access > >>> > >>> Given an existing Account > >>> And a logged in User > >>> When the user visits account/manage > >>> Then he should not get access > >>> > >>> -- > >>> View this message in context: http://www.nabble.com/DRYing-up-stories-tp15053384p15053384.html > >>> Sent from the rspec-users mailing list archive at Nabble.com. > >>> > >>> _______________________________________________ > >>> rspec-users mailing list > >>> rspec-users at rubyforge.org > >>> http://rubyforge.org/mailman/listinfo/rspec-users > >>> > >>> > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-users at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/rspec-users > >> > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > Regards, > Kamal > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From aslak.hellesoy at gmail.com Thu Jan 24 02:25:49 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Thu, 24 Jan 2008 08:25:49 +0100 Subject: [rspec-users] DRYing up stories In-Reply-To: <4797D61D.4080902@benmabey.com> References: <15053384.post@talk.nabble.com> <8d961d900801231537j6873fda4n2fc7338874569a24@mail.gmail.com> <4797D61D.4080902@benmabey.com> Message-ID: <8d961d900801232325g687ff9dar75c32f16b7d1b1cd@mail.gmail.com> On Jan 24, 2008 1:04 AM, Ben Mabey wrote: > While the original post had DRY in the subject line I don't see this as > a DRY issue. I see it as a visualization and maintenance issue. If I > add a new role and I want to test each action for it's permissions it > would be much easier for a customer to go down a spread sheet and > designate within each cell what the response should be.. success or > failure, etc... This would give the customer a bird's eye view of > permissions for the entire app for each class of users. By using a > separate scenario for each role in each story you will be creating a lot > of copy and past work which will comminucate the same information a > spreadsheet would but a lot more inefficently since someone would have > to read hundreds of pages of stories. I love the plain text stories. > We just have to remember that there are better ways to express large > amounts of data than plain English. :) > Do you understand the point I'm trying to make? > I totally get your point. This is where FIT shines (or maybe Ryan's Matrix). Aslak > > -Ben > > > > > aslak hellesoy wrote: > > On Jan 23, 2008 10:45 PM, Neil M. Young wrote: > > > >> I'm finding that I'm writing sets of very similar scenarios to check access > >> permissions for each of my actions. Does anyone have suggestions on how to > >> dry this up: > >> > >> > > > > Beware that DRY has a cost. Clarity and readability. > > > > David's BDD manifesto (slightly rephrased): > > > > We prefer clarity over DRY (that is - while there is value in DRYness, > > we value clarity more) > > > > Aslak > > > > > >> Given an existing Account > >> And a logged in Admin > >> When the user visits account/manage > >> Then he should get access > >> > >> Given an existing Account > >> And a logged in Manager > >> When the user visits account/manage > >> Then he should get access > >> > >> Given an existing Account > >> And a logged in Supervisor > >> When the user visits account/manage > >> Then he should not get access > >> > >> Given an existing Account > >> And a logged in Reviewer > >> When the user visits account/manage > >> Then he should not get access > >> > >> Given an existing Account > >> And a logged in User > >> When the user visits account/manage > >> Then he should not get access > >> > >> -- > >> View this message in context: http://www.nabble.com/DRYing-up-stories-tp15053384p15053384.html > >> Sent from the rspec-users mailing list archive at Nabble.com. > >> > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-users at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/rspec-users > >> > >> > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ermok at tiscali.co.uk Thu Jan 24 03:25:35 2008 From: ermok at tiscali.co.uk (Neil M. Young) Date: Thu, 24 Jan 2008 00:25:35 -0800 (PST) Subject: [rspec-users] DRYing up stories In-Reply-To: <15053384.post@talk.nabble.com> References: <15053384.post@talk.nabble.com> Message-ID: <15060580.post@talk.nabble.com> some interesting viewpoints so far. How do people feel about something like this: Given every type of user When they visit account/manage Then only Admins and Managers should get access Given("every type of user") do @users = { :admin => new_admin, :manager => new_manager, :supervisor => new_supervisor, :reviewer => new_reviewer, :user => new_user } end When("they visit $url") do |url| @url = url end Then("only $allow_list should get access") do |allow_list| allow_list = allow_list.split(' and ').collect {|x| x.downcase.singularize.intern} allow_list.each do |x| user = @users.delete(x) # log user in get @url response.should_not be_redirect end @users.each do |x| #log user in get @url response.should redirect_to("not_authorised") end end any major BDD violations there? I personally don't mind the somewhat complex steps because as Ben pointed out, the plain text stories are more manageable this way and still very readable. Neil M. Young wrote: > > I'm finding that I'm writing sets of very similar scenarios to check > access permissions for each of my actions. > > snip > -- View this message in context: http://www.nabble.com/DRYing-up-stories-tp15053384p15060580.html Sent from the rspec-users mailing list archive at Nabble.com. From pergesu at gmail.com Thu Jan 24 04:16:58 2008 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 24 Jan 2008 01:16:58 -0800 Subject: [rspec-users] Changing rspec directory structure In-Reply-To: References: Message-ID: <810a540e0801240116m5e712cb3kf2f383d47e2f2e56@mail.gmail.com> On Jan 23, 2008 12:12 AM, Will Sargent wrote: > Basically the Jay Fields style of testing -- I want the unit tests to > be run all the time on a continuous integration server, but the > integration/functional and system tests to be run only once a night. I would suggest letting autotest run your unit tests every couple minutes, and have your CI server run the functional/integration tests. Much tighter feedback loop. Pat From pergesu at gmail.com Thu Jan 24 04:36:23 2008 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 24 Jan 2008 01:36:23 -0800 Subject: [rspec-users] sharing specs in a subclass In-Reply-To: <57c63afe0801222226o6c64144dqaf8ef0a15d300b92@mail.gmail.com> References: <57c63afe0801222102s56883f22m323e64a950a6588e@mail.gmail.com> <7FCF6260-1B5B-48C7-BE9D-F653F6336C75@railsnewbie.com> <57c63afe0801222226o6c64144dqaf8ef0a15d300b92@mail.gmail.com> Message-ID: <810a540e0801240136n786fafa8vb46f68f0adeac57b@mail.gmail.com> On Jan 22, 2008 10:26 PM, David Chelimsky wrote: > On Jan 23, 2008 12:04 AM, Scott Taylor wrote: > > > > On Jan 23, 2008, at 12:02 AM, David Chelimsky wrote: > > > > > On Jan 22, 2008 10:49 PM, Jonathan Linowes > > > wrote: > > >> Hi > > >> > > >> I've spec'd a class and they pass. > > >> > > >> Now I'd like to assure that any subclass of this class also passes > > >> the same specs. > > >> Any suggestions for a clever way to handle this? > > >> I'd prefer to keep the existing specs as is (eg instead of moving > > >> everything into shared behaviors, or doing something to all the > > >> 'describe' lines) > > > > > > How about: > > > > > > [Subclass1, Subclass2, BaseClass].each do |klass| > > > describe klass do > > > ... > > > end > > > end > > > > That's sort of funny, being that I posted this solution on Courtney's > > blog yesterday. > > I saw that. I've also done this before :) > > > Is this what you actually use in this sort of situations? Are there > > other (better, or worse) alternatives? > > I usually stick w/ shared example groups, but I sometimes use an > iterator like this. Not sure why. I'll think about it. I think using an iterator here is weird, and muddles the intent of the specs. Think of what it means to define a class and a subclass. class Foo ... some behavior ... end class Bar < Foo ... all of Foo's behavior ... ... some specialized behavior ... end You don't define all the behavior in Bar - you get a bunch of it from Foo for free, and then specialize whatever you need. Your specs should be similar in spirit. shared_examples_for("the foo role") do it "should have some behavior" ... end describe Bar do it_should_behave_like "the foo role" it "should have some specialized behavior" ... end That is far more clear to me. The downside is that you also end up with On Jan 22, 2008 10:26 PM, David Chelimsky wrote: > On Jan 23, 2008 12:04 AM, Scott Taylor wrote: > > > > On Jan 23, 2008, at 12:02 AM, David Chelimsky wrote: > > > > > On Jan 22, 2008 10:49 PM, Jonathan Linowes > > > wrote: > > >> Hi > > >> > > >> I've spec'd a class and they pass. > > >> > > >> Now I'd like to assure that any subclass of this class also passes > > >> the same specs. > > >> Any suggestions for a clever way to handle this? > > >> I'd prefer to keep the existing specs as is (eg instead of moving > > >> everything into shared behaviors, or doing something to all the > > >> 'describe' lines) > > > > > > How about: > > > > > > [Subclass1, Subclass2, BaseClass].each do |klass| > > > describe klass do > > > ... > > > end > > > end > > > > That's sort of funny, being that I posted this solution on Courtney's > > blog yesterday. > > I saw that. I've also done this before :) > > > Is this what you actually use in this sort of situations? Are there > > other (better, or worse) alternatives? > > I usually stick w/ shared example groups, but I sometimes use an > iterator like this. Not sure why. I'll think about it. I think using an iterator here is weird, and muddles the intent of the specs. Think of what it means to define a class and a subclass. class Foo ... some behavior ... end class Bar < Foo ... all of Foo's behavior ... ... some specialized behavior ... end You don't define all the behavior in Bar - you get a bunch of it from Foo for free, and then specialize whatever you need. Your specs should be similar in spirit. shared_examples_for("the foo role") do it "should have some behavior" ... end The downside is you end up with describe Foo do it_should_behave_like "the foo role" end to specify the behavior, which feels pretty weak to me. Though I assume you feel somewhat similarly, so I'd be interested to know when you use an iterator for full example groups. Actually one example I remember is when I wrote a macro that added a bunch of methods to a class...I wrote the initial example group for just one attribute name. Then when I extracted the macro, I just iterated through a bunch of names over the example group. So it can be useful. Although a whole class feels too coarse grained for that approach, to me. I do use iterators a bunch for stuff like [:name, :email, :phone, :address].each do |field| it "should require a #{field}" do u = build_user(field => nil) u.should_not be_valid u.should have(1).error_on(field) end end Also, since I'm close to the subject, here's a little tip. I've seen people write specs like: it "should require valid attributes" do [:name, :email, :phone, :address].each do |field| u = build_user(field => nil) u.should_not be_valid u.should have(1).error_on(field) end end but that sucks, because if the example fails, you don't have any clue why. Cause it'll just say that user is invalid, but doesn't tell you which field is blank. That was a bit of a tangent. It's late, I'm loopy :) Pat From kamal.fariz at gmail.com Thu Jan 24 04:47:37 2008 From: kamal.fariz at gmail.com (Kamal Fariz) Date: Thu, 24 Jan 2008 17:47:37 +0800 Subject: [rspec-users] DRYing up stories In-Reply-To: <57c63afe0801232139mc8ab1e5qbd122c18136440d9@mail.gmail.com> References: <15053384.post@talk.nabble.com> <8d961d900801231537j6873fda4n2fc7338874569a24@mail.gmail.com> <4797D61D.4080902@benmabey.com> <0055E4E8-73FB-446F-9EC7-BBF6A03DE717@gmail.com> <57c63afe0801232139mc8ab1e5qbd122c18136440d9@mail.gmail.com> Message-ID: > With 1.1.1 you can do this: > > Given "$n_users in the system" do |num_users| > case num_users > when "a user" > # one user case > when /(\d*) users/ > # multi user case using $1 > end > end > > With 1.1.2 you can do this: > > Given /(a|\d*) users? in the system/ do |num_users| > num_users = (num_users == 'a') ? 1 : num_users.to_i > (1..num_users).each do > # ... > end > end Didn't know you could do that! Thanks. So, the step will yield all the matches in the same order regexp will populate the matches array? Regards, kamal From keith at dancingtext.com Thu Jan 24 06:40:47 2008 From: keith at dancingtext.com (Keith McDonnell) Date: Thu, 24 Jan 2008 12:40:47 +0100 Subject: [rspec-users] Meridian case Message-ID: <4798793F.1030209@dancingtext.com> Hi there, I have a *really* weird issue with rspec on rails: Given a time meridian formatted using %p When I run `rake spec` the time meridian is converted to lower case: expected: "Today 08:00 PM", got: "Today 08:00 pm" Yet when I run `rake spec:models` and `spec -cfs app/models` the specs pass, ie the the time meridian is in upper case. Anyone got any ideas how I can troubleshoot this one ? I'm using rails 1.2.3, ruby 1.8.6, i686-darwin8.10.1, RSpec-1.0.6 (r2183) Thanks in advance. Keith From dchelimsky at gmail.com Thu Jan 24 09:44:20 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 24 Jan 2008 08:44:20 -0600 Subject: [rspec-users] DRYing up stories In-Reply-To: <15060580.post@talk.nabble.com> References: <15053384.post@talk.nabble.com> <15060580.post@talk.nabble.com> Message-ID: <57c63afe0801240644q67c0c57fnca8649cfa571f3f3@mail.gmail.com> On Jan 24, 2008 2:25 AM, Neil M. Young wrote: > > some interesting viewpoints so far. How do people feel about something like > this: > > Given every type of user > When they visit account/manage > Then only Admins and Managers should get access > > Given("every type of user") do > @users = { > :admin => new_admin, > :manager => new_manager, > :supervisor => new_supervisor, > :reviewer => new_reviewer, > :user => new_user > } > end > > When("they visit $url") do |url| > @url = url > end > > Then("only $allow_list should get access") do |allow_list| > allow_list = allow_list.split(' and ').collect {|x| > x.downcase.singularize.intern} > allow_list.each do |x| > user = @users.delete(x) > # log user in > get @url > response.should_not be_redirect > end > @users.each do |x| > #log user in > get @url > response.should redirect_to("not_authorised") > end > end > > any major BDD violations there? I personally don't mind the somewhat complex > steps because as Ben pointed out, the plain text stories are more manageable > this way and still very readable. I think I'd rather have the first step be explicit about the different types: Given users in the Manager, Admin, Supervisor and Anonymous roles When they visit account/manage Then only Admins and Managers should get access As for the complexity within the steps, there's a balance to be found between that and clarity of the steps in the scenario (Given blah de blah). The underlying principle should be that you or anyone on your team should be able to quickly understand a failure. As soon as you start debugging steps to understand a failure, those steps are losing part of their value. Where that leads you is going to vary from person to person, team to team. For me, personally, my only beef with the Then step definition here is that I wouldn't likely be able to know which role caused the failure. Otherwise I don't feel there is a fundamental BDD violation. FWIW, Cheers, David > > > Neil M. Young wrote: > > > > I'm finding that I'm writing sets of very similar scenarios to check > > access permissions for each of my actions. > > > > snip > > > > -- > View this message in context: http://www.nabble.com/DRYing-up-stories-tp15053384p15060580.html > > Sent from the rspec-users mailing list archive at Nabble.com. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Thu Jan 24 09:44:45 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 24 Jan 2008 08:44:45 -0600 Subject: [rspec-users] DRYing up stories In-Reply-To: References: <15053384.post@talk.nabble.com> <8d961d900801231537j6873fda4n2fc7338874569a24@mail.gmail.com> <4797D61D.4080902@benmabey.com> <0055E4E8-73FB-446F-9EC7-BBF6A03DE717@gmail.com> <57c63afe0801232139mc8ab1e5qbd122c18136440d9@mail.gmail.com> Message-ID: <57c63afe0801240644k654eed3aocea60f95d9dc5e56@mail.gmail.com> On Jan 24, 2008 3:47 AM, Kamal Fariz wrote: > > With 1.1.1 you can do this: > > > > Given "$n_users in the system" do |num_users| > > case num_users > > when "a user" > > # one user case > > when /(\d*) users/ > > # multi user case using $1 > > end > > end > > > > With 1.1.2 you can do this: > > > > Given /(a|\d*) users? in the system/ do |num_users| > > num_users = (num_users == 'a') ? 1 : num_users.to_i > > (1..num_users).each do > > # ... > > end > > end > > Didn't know you could do that! Thanks. So, the step will yield all the > matches in the same order regexp will populate the matches array? Yep. Cheers, David > > > Regards, > kamal > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Thu Jan 24 09:46:57 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 24 Jan 2008 08:46:57 -0600 Subject: [rspec-users] Meridian case In-Reply-To: <4798793F.1030209@dancingtext.com> References: <4798793F.1030209@dancingtext.com> Message-ID: <57c63afe0801240646k23df1b60n8b02c7ca76be9ebe@mail.gmail.com> On Jan 24, 2008 5:40 AM, Keith McDonnell wrote: > Hi there, > > I have a *really* weird issue with rspec on rails: > > Given a time meridian formatted using %p > > When I run `rake spec` the time meridian is converted to lower case: > > expected: "Today 08:00 PM", > got: "Today 08:00 pm" > > Yet when I run `rake spec:models` and `spec -cfs app/models` the specs > pass, ie the the time meridian is in upper case. > > Anyone got any ideas how I can troubleshoot this one ? I'm using rails > 1.2.3, ruby 1.8.6, i686-darwin8.10.1, RSpec-1.0.6 (r2183) Can we see the code for the example and the method that is returning this value? > > Thanks in advance. > > Keith > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From njacobeus at gmail.com Thu Jan 24 09:56:57 2008 From: njacobeus at gmail.com (Nicolas Jacobeus) Date: Thu, 24 Jan 2008 15:56:57 +0100 Subject: [rspec-users] Constant definition matcher Message-ID: <02B435B8-8B57-4704-85E1-B42EB27B6071@gmail.com> Hello all, I need to specify that a class should define a constant. I couldn't find something such as "should define_const('MY_CONST')" in the RSpec documentation, even though there are similar matchers such as "should respond_to". I know I can write the matcher myself (that wouldn't be so difficult) but is there a reason ? Thanks! -- Nicolas Jacobeus Belighted.com - Web 2.0 Consulting & Training Frailers.net - Communaut? Ruby on Rails francophone From dchelimsky at gmail.com Thu Jan 24 09:59:54 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 24 Jan 2008 08:59:54 -0600 Subject: [rspec-users] Constant definition matcher In-Reply-To: <02B435B8-8B57-4704-85E1-B42EB27B6071@gmail.com> References: <02B435B8-8B57-4704-85E1-B42EB27B6071@gmail.com> Message-ID: <57c63afe0801240659p3aa97eafm250a348ba8000a74@mail.gmail.com> On Jan 24, 2008 8:56 AM, Nicolas Jacobeus wrote: > Hello all, > > I need to specify that a class should define a constant. > > I couldn't find something such as "should define_const('MY_CONST')" in > the RSpec documentation, even though there are similar matchers such > as "should respond_to". > > I know I can write the matcher myself (that wouldn't be so difficult) > but is there a reason ? Nope. Just an oversight. Feel free to contribute your solution to the lighthouse (http://rspec.lighthouseapp.com). Cheers, David > > Thanks! > > -- > Nicolas Jacobeus > Belighted.com - Web 2.0 Consulting & Training > Frailers.net - Communaut? Ruby on Rails francophone > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Thu Jan 24 10:19:13 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Thu, 24 Jan 2008 10:19:13 -0500 Subject: [rspec-users] sharing specs in a subclass In-Reply-To: <810a540e0801240136n786fafa8vb46f68f0adeac57b@mail.gmail.com> References: <57c63afe0801222102s56883f22m323e64a950a6588e@mail.gmail.com> <7FCF6260-1B5B-48C7-BE9D-F653F6336C75@railsnewbie.com> <57c63afe0801222226o6c64144dqaf8ef0a15d300b92@mail.gmail.com> <810a540e0801240136n786fafa8vb46f68f0adeac57b@mail.gmail.com> Message-ID: <826B632B-655B-4B87-BDE8-CF466A38B1F0@railsnewbie.com> On Jan 24, 2008, at 4:36 AM, Pat Maddox wrote: > > On Jan 22, 2008 10:26 PM, David Chelimsky > wrote: >> On Jan 23, 2008 12:04 AM, Scott Taylor >> wrote: >>> >>> On Jan 23, 2008, at 12:02 AM, David Chelimsky wrote: >>> >>>> On Jan 22, 2008 10:49 PM, Jonathan Linowes >>>> wrote: >>>>> Hi >>>>> >>>>> I've spec'd a class and they pass. >>>>> >>>>> Now I'd like to assure that any subclass of this class also passes >>>>> the same specs. >>>>> Any suggestions for a clever way to handle this? >>>>> I'd prefer to keep the existing specs as is (eg instead of moving >>>>> everything into shared behaviors, or doing something to all the >>>>> 'describe' lines) >>>> >>>> How about: >>>> >>>> [Subclass1, Subclass2, BaseClass].each do |klass| >>>> describe klass do >>>> ... >>>> end >>>> end >>> >>> That's sort of funny, being that I posted this solution on >>> Courtney's >>> blog yesterday. >> >> I saw that. I've also done this before :) >> >>> Is this what you actually use in this sort of situations? Are there >>> other (better, or worse) alternatives? >> >> I usually stick w/ shared example groups, but I sometimes use an >> iterator like this. Not sure why. I'll think about it. > > I think using an iterator here is weird, and muddles the intent of > the specs. > > Think of what it means to define a class and a subclass. > > class Foo > ... some behavior ... > end > > class Bar < Foo > ... all of Foo's behavior ... > ... some specialized behavior ... > end > > You don't define all the behavior in Bar - you get a bunch of it from > Foo for free, and then specialize whatever you need. Your specs > should be similar in spirit. In a normal setting, I'd agree with you. In the case where I used it, there was STI involved, and the subclasses had almost no unique behaviour (except one or two methods which were over-ridden). > > shared_examples_for("the foo role") do > it "should have some behavior" > ... > end > > The downside is you end up with > > describe Foo do > it_should_behave_like "the foo role" > end > > to specify the behavior, which feels pretty weak to me. The trouble with the shared specs is that you have to do the same setup multiple times, in various specs. > > Though I assume you feel somewhat similarly, so I'd be interested to > know when you use an iterator for full example groups. > > Actually one example I remember is when I wrote a macro that added a > bunch of methods to a class...I wrote the initial example group for > just one attribute name. Then when I extracted the macro, I just > iterated through a bunch of names over the example group. So it can > be useful. Although a whole class feels too coarse grained for that > approach, to me. > > I do use iterators a bunch for stuff like > > [:name, :email, :phone, :address].each do |field| > it "should require a #{field}" do > u = build_user(field => nil) > u.should_not be_valid > u.should have(1).error_on(field) > end > end > > Also, since I'm close to the subject, here's a little tip. I've seen > people write specs like: > > it "should require valid attributes" do > [:name, :email, :phone, :address].each do |field| > u = build_user(field => nil) > u.should_not be_valid > u.should have(1).error_on(field) > end > end > > but that sucks, because if the example fails, you don't have any clue > why. Cause it'll just say that user is invalid, but doesn't tell you > which field is blank. Yeah, I agree. It's also violating the one test per test case rule. If you had ordered the tests in the opposite manner, it wouldn't be a problem. I usually still use valid?, even though it's less informative, since I let FixtureReplacement take care of making it a valid record in the first place: it "should not be valid with a firstname" do new_user(:firstname => nil).should_not be_valid end it "should be valid with valid attributes" do new_user.should be_valid end Scott From ben at benmabey.com Thu Jan 24 10:29:21 2008 From: ben at benmabey.com (Ben Mabey) Date: Thu, 24 Jan 2008 08:29:21 -0700 Subject: [rspec-users] DRYing up stories In-Reply-To: <15060580.post@talk.nabble.com> References: <15053384.post@talk.nabble.com> <15060580.post@talk.nabble.com> Message-ID: <4798AED1.8050809@benmabey.com> I actually really like this idea. Very neat. Like David said the only problem might be being able to see where the failure occurred. I think that this problem could be solved or at least mitigated with some sort of custom matcher though (maybe even a simple one.) This solves the baseline case for me. The other problem I am having is that based on a certain model's settings the type of user's who have access to it varies. So I could just add an additional Given describing that condition... but I may still have a combinatorial explosion on the amount of stories needed to explain every case.. But I think this approach will work nicely for the time being so I'll try it out. Thanks for the idea. -Ben Neil M. Young wrote: > some interesting viewpoints so far. How do people feel about something like > this: > > Given every type of user > When they visit account/manage > Then only Admins and Managers should get access > > Given("every type of user") do > @users = { > :admin => new_admin, > :manager => new_manager, > :supervisor => new_supervisor, > :reviewer => new_reviewer, > :user => new_user > } > end > > When("they visit $url") do |url| > @url = url > end > > Then("only $allow_list should get access") do |allow_list| > allow_list = allow_list.split(' and ').collect {|x| > x.downcase.singularize.intern} > allow_list.each do |x| > user = @users.delete(x) > # log user in > get @url > response.should_not be_redirect > end > @users.each do |x| > #log user in > get @url > response.should redirect_to("not_authorised") > end > end > > any major BDD violations there? I personally don't mind the somewhat complex > steps because as Ben pointed out, the plain text stories are more manageable > this way and still very readable. > > > Neil M. Young wrote: > >> I'm finding that I'm writing sets of very similar scenarios to check >> access permissions for each of my actions. >> >> snip >> >> > > From benaldred at gmail.com Thu Jan 24 11:00:04 2008 From: benaldred at gmail.com (Ben Aldred) Date: Thu, 24 Jan 2008 16:00:04 +0000 Subject: [rspec-users] Help to spec a rails helper method that uses content_for Message-ID: Hi guys, I am a Rspec newbie and am having problems creating a spec for a RoR helper method. I have in fact already implemented the helper method and am trying to create retrospective specs. I know its the wrong way to do it but I am still learning Rspec. In my view I have a call to a helper method. <% body_class "users" %> which sets a CSS class declaration in the content_for block which is then used in the tag in application.html.erb layout. def body_class(class_name) content_for(:body_class) { " class=\"#{class_name}\"" } end I was trying the following in my view spec: template.should_receive (:body_class).with("users").and_return(' class="users"') render "/admin/users/index.html.erb", :layout => "application" response.should have_tag('body.users') I get a: Expected at least 1 element matching "body.users", found 0. is not true. when I printed the response.body to screen it does not contain he CSS class declaration on the body tag, where as running mongrel and going to the page everything is fine. what am I doing wrong? I ended up doing: render "/admin/users/index.html.erb", :layout => "application" response[:body_class].should == ' class="users"' I am interested to know why my first attempt did not work. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080124/86eb6565/attachment-0001.html From keith at dancingtext.com Thu Jan 24 11:43:38 2008 From: keith at dancingtext.com (Keith McDonnell) Date: Thu, 24 Jan 2008 17:43:38 +0100 Subject: [rspec-users] Meridian case Message-ID: <4798C03A.3030702@dancingtext.com> Hi, Here's the spec: 'absolute_time_in_words should say 'Today 08:00 PM'' FAILED expected: "Today 08:00 PM", got: "Today 08:00 pm" (using ==) absolute_time_in_words(Time.now.utc.change({ :hour => 20, :minute => 0, :second => 0 }), TZInfo::Timezone.get('Europe/Dublin')).should == "Today 08:00 PM" Here's the offending code: def absolute_time_in_words(local_time, timezone) today = timezone.utc_to_local(Time.now.utc).to_date local_date = local_time.to_date local_time.strftime( case when local_date == today; "Today %I:%M %p" when local_date == today + 1; "Tomorrow %I:%M %p" when local_date == today - 1; "Yesterday %I:%M %p" when local_date.year == today.year "%A, %d %b %I:%M %p" else "%A, %d %b %Y %I:%M %p" end ) end Thanks, Keith On Jan 24, 2008 5:40 AM, Keith McDonnell wrote: > Hi there, > > I have a *really* weird issue with rspec on rails: > > Given a time meridian formatted using %p > > When I run `rake spec` the time meridian is converted to lower case: > > expected: "Today 08:00 PM", > got: "Today 08:00 pm" > > Yet when I run `rake spec:models` and `spec -cfs app/models` the specs > pass, ie the the time meridian is in upper case. > > Anyone got any ideas how I can troubleshoot this one ? I'm using rails > 1.2.3, ruby 1.8.6, i686-darwin8.10.1, RSpec-1.0.6 (r2183) Can we see the code for the example and the method that is returning this value? > > Thanks in advance. > > Keith > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ermok at tiscali.co.uk Thu Jan 24 17:12:17 2008 From: ermok at tiscali.co.uk (Neil M. Young) Date: Thu, 24 Jan 2008 14:12:17 -0800 (PST) Subject: [rspec-users] re -raise exceptions in stories? Message-ID: <15076254.post@talk.nabble.com> I see that rails handles exceptions in stories by rendering public/500.html, whereas in controller specs exceptions are re-raised. Is it possible to have this same behaviour in stories so I can check the correct exceptions are being raised? -- View this message in context: http://www.nabble.com/re-raise-exceptions-in-stories--tp15076254p15076254.html Sent from the rspec-users mailing list archive at Nabble.com. From ben at benmabey.com Thu Jan 24 17:53:28 2008 From: ben at benmabey.com (Ben Mabey) Date: Thu, 24 Jan 2008 15:53:28 -0700 Subject: [rspec-users] re -raise exceptions in stories? In-Reply-To: <15076254.post@talk.nabble.com> References: <15076254.post@talk.nabble.com> Message-ID: <479916E8.10900@benmabey.com> Neil M. Young wrote: > I see that rails handles exceptions in stories by rendering public/500.html, > whereas in controller specs exceptions are re-raised. Is it possible to have > this same behaviour in stories so I can check the correct exceptions are > being raised? > I do this by putting the following in my helper.rb: ActionController::Base.class_eval do def perform_action perform_action_without_rescue end end Dispatcher.class_eval do def self.failsafe_response(output, status, exception = nil) raise exception end end From pergesu at gmail.com Fri Jan 25 00:22:52 2008 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 24 Jan 2008 21:22:52 -0800 Subject: [rspec-users] Not seeing the failure In-Reply-To: <6bdacb70801230802v5036e984vc75a80318e1ed960@mail.gmail.com> References: <6bdacb70801230641h18c42784v4e03cc6d5b4eb355@mail.gmail.com> <57c63afe0801230646s60adff48k5e01920aef26dd04@mail.gmail.com> <6bdacb70801230649g2bc689acrb2267f5653480276@mail.gmail.com> <57c63afe0801230703r7a5d3897t7b8298ae9c987306@mail.gmail.com> <6bdacb70801230724x506b1163wd66b8696c0fa69d5@mail.gmail.com> <57c63afe0801230735t6e57bc63n2f8ae41c0b91cd9a@mail.gmail.com> <6bdacb70801230802v5036e984vc75a80318e1ed960@mail.gmail.com> Message-ID: <810a540e0801242122q2291edd1mc48239d3a74cd372@mail.gmail.com> No, the mock is set up to return nil when user= is called. Then he writes an example to actually expect the call to user=. Pat On Jan 23, 2008 8:02 AM, Corey Haines wrote: > I get the unexpected message :user= failure. > > When you set up the mock with the initial parameters, wouldn't those be > stubbing: @coupon.stub!(:user).and_return(@current_user) > > While, my spec says that I want :user= to be called? > > -corey > > > > On Jan 23, 2008 10:35 AM, David Chelimsky wrote: > > > > On Jan 23, 2008 9:24 AM, Corey Haines wrote: > > > Thanks, David! > > > > > > Here's what I morphed the specs into: > > > > > > http://pastie.caboo.se/142411 > > > > > > And, I ended up with a blog entry that I'll write tonight. > > > > > > Basically, here's the situation I've been running into which is causing > my > > > specs to grow. > > > > > > If I don't set up something to tell the coupon that it is going to have > > > :user= called on it, then the other tests fails. I didn't want to stub > it, > > > as I want this to be part of my expectations. Luckily, it only took a > minute > > > to come up with a possible solution, again relying on the fact that > things > > > tend to work how I think they should. > > > > > > The solution I thought of was to set the stub! call in the > before(:each), > > > then set an actual expectation in the spec. > > > > Actually - that's what mine did to. These two are the same: > > > > coupon = mock_model(Coupon, > > :user= => nil, > > :save => true > > ) > > > > coupon = mock_model Coupon > > coupon.stub!(:user=) > > coupon.stub!(:save).and_return(true) > > > > :) > > > > Looking forward to your blog. > > > > Cheers, > > David > > > > > > > > > > > In my mind, the expectation > > > should override the stub (making sure it gets called), but the stub will > > > allow the other tests to pass. Fantastic! It works. I'm going to write > up a > > > blog entry on this pattern, and I'll send a link when I post it. > > > > > > Thanks for your help. > > > -Corey > > > > > > > > > > > > > > > > > > On Jan 23, 2008 10:03 AM, David Chelimsky wrote: > > > > > > > > On Jan 23, 2008 8:49 AM, Corey Haines wrote: > > > > > Of course. Thanks, David! I still am getting used to user=, rather > than > > > just > > > > > user. Thanks again. > > > > > > > > No problem. I certainly got caught by that early on. > > > > > > > > I have some more general comments. See below: > > > > > > > > > > > > > > > > > > > > > > > > > > -Corey > > > > > > > > > > > > > > > > > > > > On Jan 23, 2008 9:46 AM, David Chelimsky < dchelimsky at gmail.com> > wrote: > > > > > > > > > > > > On Jan 23, 2008 8:41 AM, Corey Haines < coreyhaines at gmail.com> > wrote: > > > > > > > > > > > > > > > > > > > > > > > > > All, > > > > > > > > > > > > > > I'm missing something simple, I think. I am writing a spec to > say > > > that > > > > > my > > > > > > > CouponController should create a new coupon from the form > > > parameters, > > > > > then > > > > > > > set the current user. Here's the spec: > > > > > > > > > > > > > > describe CouponController, "When posting to save_coupon" do > > > > > > > > > > > > > > before(:each) do > > > > > > > @expectedName = "pepper's" > > > > > > > @expectedAmount = 5 > > > > > > > > > > > > > > coupon = mock_model Coupon > > > > > > > current_user = mock_model User > > > > > > > controller.stub! (:current_user).and_return(current_user) > > > > > > > > > > > > > > > > > > > > > > > Coupon.should_receive(:new).with({"name"=>@expectedName,"amount"=>@expectedAmount}).and_return(coupon) > > > > > > > coupon.should_receive(:user).with(current_user) > > > > > > > coupon.should_receive(:save) > > > > > > > end > > > > > > > > > > > > > > it "should tell the Coupon model to create a new coupon with > the > > > given > > > > > > > parameters and save" do > > > > > > > post > > > > > > > > > > 'save_coupon',{:coupon=>{:name=>@expectedName,:amount=>@expectedAmount}} > > > > > > > end > > > > > > > > > > > > > > Here's the controller method: > > > > > > > > > > > > > > def save_coupon > > > > > > > coupon = Coupon.new(params[:coupon]) > > > > > > > coupon.user = current_user > > > > > > > coupon.save > > > > > > > redirect_to_index "Coupon Added!" > > > > > > > end > > > > > > > > This one example is doing too much IMO. You even say "I am writing a > > > > > > > > spec to say that my CouponController should create a new coupon from > > > > the form parameters, then set the current user." That's two things. > > > > > > > > Generally I try to keep stubs in before(:each), expectations in the > > > > examples, and one example for each concept that I'm describing. > > > > > > > > I took the liberty of pastie-ing what I'd probably do. I haven't run > > > > it, so it might not work as/is, but you'll get the idea. > > > > > > > > http://pastie.caboo.se/142403 > > > > > > > > Cheers, > > > > David > > > > > > > > PS - I'm really glad to see you getting involved with this list. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > And, I get the following failure: > > > > > > > > > > > > > > Mock 'Coupon_1008' received unexpected message :user= with > > > > > (# > > > > > > @name="User_1009">) > > > > > > > > > > > > > > > > > > That's from this line in save_coupon: > > > > > > > > > > > > coupon.user = current_user > > > > > > > > > > > > Just need to stub that: > > > > > > > > > > > > coupon.stub!(:user=) > > > > > > > > > > > > Or you could expect it: > > > > > > > > > > > > > > > > > > coupon.should_receive (:user=).with(current_user) > > > > > > > > > > > > Cheers, > > > > > > David > > > > > > > > > > > > > > > > > > > > > > > > > > I'm sure that I'm missing something very simple, but I've been > > > staring > > > > > at it > > > > > > > for too long. > > > > > > > > > > > > > > (also, if anyone has commented on my style, please feel free to > > > mention > > > > > it, > > > > > > > as I'm still adjusting my mind to rspec) > > > > > > > > > > > > > > Oh, versions, I almost forgot: > > > > > > > rails 2.0.2 > > > > > > > rspec(_on_rails) plugins just updated from current a couple days > > > ago, > > > > > not > > > > > > > totally sure how to get the versions of the plugins > > > > > > > > > > > > > > > > > > > > > Thanks. > > > > > > > -Corey > > > > > > > > > > > > > > -- > > > > > > > http://www.coreyhaines.com > > > > > > > The Internet's Premiere source of information about Corey Haines > > > > > > > _______________________________________________ > > > > > > > rspec-users mailing list > > > > > > > rspec-users at rubyforge.org > > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > _______________________________________________ > > > > > > rspec-users mailing list > > > > > > rspec-users at rubyforge.org > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > > > > > > > > > > > -- > > > > > > > > > > > > > > > http://www.coreyhaines.com > > > > > The Internet's Premiere source of information about Corey Haines > > > > > _______________________________________________ > > > > > rspec-users mailing list > > > > > rspec-users at rubyforge.org > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > -- > > > http://www.coreyhaines.com > > > The Internet's Premiere source of information about Corey Haines > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > -- > > > http://www.coreyhaines.com > The Internet's Premiere source of information about Corey Haines > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Fri Jan 25 04:02:14 2008 From: lists at ruby-forum.com (Kevin Barnes) Date: Fri, 25 Jan 2008 10:02:14 +0100 Subject: [rspec-users] expect_render(...).and_return('x') In-Reply-To: <6ea3a1b80801230325h72e6a30ah3c9a0a8ab8a9466b@mail.gmail.com> References: <6ea3a1b80801230325h72e6a30ah3c9a0a8ab8a9466b@mail.gmail.com> Message-ID: I've experienced very strange behavior with expect_render and stub_render as well as putting expectations on self in helper tests... It seems a lot of this weirdness started when I upgraded the rails plugin from 1.1.0 to 1.1.2. I use mocha instead of the rspec mocks - don't know if that is a cause... -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Fri Jan 25 07:53:54 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 25 Jan 2008 06:53:54 -0600 Subject: [rspec-users] expect_render(...).and_return('x') In-Reply-To: <6ea3a1b80801230325h72e6a30ah3c9a0a8ab8a9466b@mail.gmail.com> References: <6ea3a1b80801230325h72e6a30ah3c9a0a8ab8a9466b@mail.gmail.com> Message-ID: <57c63afe0801250453s52be073er25d1dde601c5c15a@mail.gmail.com> On Jan 23, 2008 5:25 AM, Rob Holland wrote: > Hi, > > I'm trying to spec a controller method which renders some rjs as part > of a render :update block. The problem I'm having is that stub_render > or expect_render don't seem to allow and_return to work. > > The controller method does: > > if @thing.save > render :update do |page| > page.insert_html :bottom, 'x_thing_list', :partial > => 'thing', :object => @thing > page.form.reset 'x_new_thing' > end > else > > If I expect/stub_render the partial render (which I need to do if I > want to solely test the controller in isolation), I get: > > new Insertion.Bottom("x_thing_list", null); > Form.reset("x_new_thing"); > > The null is due to the render :partial being stubbed. Unfortunately, > this breaks the regex that assert_rjs uses, so my test: > > response.should have_rjs(:insert, :bottom, "x_thing_list") > > fails, when it should pass. > > What I need to be able to do is: > > expect_render(:partial => 'thing', :object => @thing).and_return('"x"') > > so that the output satisfies the assert_rjs regex. I would love to > provide a patch for this, but I cannot see why it doesn't already > work. The expect_render return value seems to be a normal mock, I > don't understand why return values aren't working in this case. The trick here is that render :partial is NOT getting called on the controller - it's getting called on the template that is yielded to render :update. To make matters more confusing, you can't get a handle on the template until the action is already underway - which means you can't say template.expect_render or controller.template.expect_render. Here's the way I would handle this: http://pastie.caboo.se/143246 HTH, David > > Thanks for any insights. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From rob.holland at gmail.com Fri Jan 25 08:19:31 2008 From: rob.holland at gmail.com (Rob Holland) Date: Fri, 25 Jan 2008 13:19:31 +0000 Subject: [rspec-users] expect_render(...).and_return('x') In-Reply-To: <57c63afe0801250453s52be073er25d1dde601c5c15a@mail.gmail.com> References: <6ea3a1b80801230325h72e6a30ah3c9a0a8ab8a9466b@mail.gmail.com> <57c63afe0801250453s52be073er25d1dde601c5c15a@mail.gmail.com> Message-ID: <6ea3a1b80801250519m40b1136fk71f0a66e784ae210@mail.gmail.com> David, Thanks for looking at the problem. > The trick here is that render :partial is NOT getting called on the > controller - it's getting called on the template that is yielded to > render :update. I think I follow, still getting my head around that. > Here's the way I would handle this: http://pastie.caboo.se/143246 I gave that a go, but the render :update line then triggers: Mock 'expect_render_mock_proxy' asked to yield |[#]| but no block was passed From dchelimsky at gmail.com Fri Jan 25 08:42:27 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 25 Jan 2008 07:42:27 -0600 Subject: [rspec-users] expect_render(...).and_return('x') In-Reply-To: <6ea3a1b80801250519m40b1136fk71f0a66e784ae210@mail.gmail.com> References: <6ea3a1b80801230325h72e6a30ah3c9a0a8ab8a9466b@mail.gmail.com> <57c63afe0801250453s52be073er25d1dde601c5c15a@mail.gmail.com> <6ea3a1b80801250519m40b1136fk71f0a66e784ae210@mail.gmail.com> Message-ID: <57c63afe0801250542y5d553bd7vcdd60241bb6e4508@mail.gmail.com> On Jan 25, 2008 7:19 AM, Rob Holland wrote: > David, > > Thanks for looking at the problem. > > > The trick here is that render :partial is NOT getting called on the > > controller - it's getting called on the template that is yielded to > > render :update. > > I think I follow, still getting my head around that. > > > Here's the way I would handle this: http://pastie.caboo.se/143246 > > I gave that a go, but the render :update line then triggers: > > Mock 'expect_render_mock_proxy' asked to yield > |[#]| but no block was > passed Yeah - I was playing around w/ this locally and ran into the same thing. I had made the change in rspec but not committed it yet. As of trunk r3256, the block does get passed to the mock proxy. That said, I've thought about this a bit more and realize that using this approach gives up being able to use should have_rjs, which you may not want to do. It's kind of a catch 22. You can either isolate the controller from the views or not, but you can't isolate it from 1/2 the views in a given request. At least not with a bunch of magic that doesn't yet exist in rspec. To be honest, I'm not sure it should. Cheers, David > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From duelin.markers at gmail.com Fri Jan 25 09:24:31 2008 From: duelin.markers at gmail.com (John D. Hume) Date: Fri, 25 Jan 2008 09:24:31 -0500 Subject: [rspec-users] Changing rspec directory structure In-Reply-To: References: Message-ID: Will, I wanted to do something similar. To avoid losing all the tasks and other goodness Spec::Rails gives you for free, I just created a separate top-level directory. /spec /models /controllers ... /unit /models ... (It bugs me not having it all contained in one directory, but it's consistent with the fact that there's also a top-level /stories folder. More importantly, I didn't have to modify any rspec_on_rails tasks.) I'd go one further than Pat Maddox's point: If your unit specs aren't going to touch the database, then you really ought to be running a tier of more integrated tests on your workstation before every checkin (and again on the CI server). For obvious reasons, purely mock-based unit tests/specs can and eventually will lie to you about your objects actually being ready to work together, so don't trust them to tell you about more than what the unit being spec'd does. Our commit rake task looks something like this: * svn up * run unit specs * bring the dev database up to date (we blow it away and rebuild from scratch) * spec (the Spec::Rails task, which depends on db:test:prepare, cloning the test db from the dev schema) In the /unit spec_helper, we load the rspec plugin, but not rspec_on_rails, ARBS in place of ActiveRecord and (for now at least) require ActiveSupport and the ActionPack but don't actually load the rails environment, which shaves off a second or two. (That second or two isn't a big deal when running rake, but it's great in TextMate when running just one spec. It feels pretty much instantaneous.) -hume. On Wed, Jan 23, 2008 at 3:12 AM, Will Sargent wrote: > I'd like to change the rspec directory structure from > > /spec > /model > /controllers > etc > > to > > /spec > /unit > /models > /controllers > /lib > /functional > /models > /controllers > > etc. > > Basically the Jay Fields style of testing -- I want the unit tests to > be run all the time on a continuous integration server, but the > integration/functional and system tests to be run only once a night. > > How do I break out the rspec tasks so that they cover this heirarchy? > It looks like they'll take a pattern, but I don't want to have to > redefine every rake task just to specify this. > > Also, anyone know how hard this would be to maintain? Or if there's > an easier way to organize this? > > Will. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From james.deville at gmail.com Fri Jan 25 10:26:32 2008 From: james.deville at gmail.com (James Deville) Date: Fri, 25 Jan 2008 07:26:32 -0800 Subject: [rspec-users] Story runner "macros" In-Reply-To: References: Message-ID: <2841617F-65A7-4DFE-A6F5-8AF37D63DCF1@gmail.com> It sounds like what you really want is the plain text stories. David has a few good articles, and there have been some good ones on this list. JD On Jan 20, 2008, at 9:09 PM, Rick DeNatale wrote: > I've gotten quite a bit out of Pat Maddox's screencast > http://evang.eli.st/blog/2007/10/8/story-runner-top-to-bottom-screencast > > One thing I'm not sure of is the feature where he writes things like: > > When "I POST to", "/articles", :post => {:title => "Title", :body > => "Body") do | path, params| > post_via_redirect path, params > end > > This bothers me because it seems an abrupt level jump. Most of the > stories are written at a level where the goal donor can understand > them, For example, I'm pretty sure that the above when clause started > life as somethign more like > > When "I add an article" > > I actually changed Pat's example a bit to use article instead of post > to keep the domain and implementation nouns different. I'd say that > the "add an article" form is easily understood by a client, but the > "POST to ", ... form is not. > > When I try the parameterized form, I notice that the story runner only > reports the story as > > When I post to > > So the output is even less useful for talking to the client. > > Now I really like the idea of the parameterized stories, but the step > away from client-speak makes me shy away from them. Is there a way to > get the power without loosing the intelligibility? > > -- > Rick DeNatale > > My blog on Ruby > http://talklikeaduck.denhaven2.com/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From coreyhaines at gmail.com Sat Jan 26 08:42:16 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Sat, 26 Jan 2008 08:42:16 -0500 Subject: [rspec-users] Not seeing the failure In-Reply-To: <810a540e0801242122q2291edd1mc48239d3a74cd372@mail.gmail.com> References: <6bdacb70801230641h18c42784v4e03cc6d5b4eb355@mail.gmail.com> <57c63afe0801230646s60adff48k5e01920aef26dd04@mail.gmail.com> <6bdacb70801230649g2bc689acrb2267f5653480276@mail.gmail.com> <57c63afe0801230703r7a5d3897t7b8298ae9c987306@mail.gmail.com> <6bdacb70801230724x506b1163wd66b8696c0fa69d5@mail.gmail.com> <57c63afe0801230735t6e57bc63n2f8ae41c0b91cd9a@mail.gmail.com> <6bdacb70801230802v5036e984vc75a80318e1ed960@mail.gmail.com> <810a540e0801242122q2291edd1mc48239d3a74cd372@mail.gmail.com> Message-ID: <6bdacb70801260542lab30059l5f17bd0fab70a74d@mail.gmail.com> Thanks, Pat. -Corey On Jan 25, 2008 12:22 AM, Pat Maddox wrote: > No, the mock is set up to return nil when user= is called. Then he > writes an example to actually expect the call to user=. > > Pat > > On Jan 23, 2008 8:02 AM, Corey Haines wrote: > > I get the unexpected message :user= failure. > > > > When you set up the mock with the initial parameters, wouldn't those be > > stubbing: @coupon.stub!(:user).and_return(@current_user) > > > > While, my spec says that I want :user= to be called? > > > > -corey > > > > > > > > On Jan 23, 2008 10:35 AM, David Chelimsky wrote: > > > > > > On Jan 23, 2008 9:24 AM, Corey Haines wrote: > > > > Thanks, David! > > > > > > > > Here's what I morphed the specs into: > > > > > > > > http://pastie.caboo.se/142411 > > > > > > > > And, I ended up with a blog entry that I'll write tonight. > > > > > > > > Basically, here's the situation I've been running into which is > causing > > my > > > > specs to grow. > > > > > > > > If I don't set up something to tell the coupon that it is going to > have > > > > :user= called on it, then the other tests fails. I didn't want to > stub > > it, > > > > as I want this to be part of my expectations. Luckily, it only took > a > > minute > > > > to come up with a possible solution, again relying on the fact that > > things > > > > tend to work how I think they should. > > > > > > > > The solution I thought of was to set the stub! call in the > > before(:each), > > > > then set an actual expectation in the spec. > > > > > > Actually - that's what mine did to. These two are the same: > > > > > > coupon = mock_model(Coupon, > > > :user= => nil, > > > :save => true > > > ) > > > > > > coupon = mock_model Coupon > > > coupon.stub!(:user=) > > > coupon.stub!(:save).and_return(true) > > > > > > :) > > > > > > Looking forward to your blog. > > > > > > Cheers, > > > David > > > > > > > > > > > > > > > > In my mind, the expectation > > > > should override the stub (making sure it gets called), but the stub > will > > > > allow the other tests to pass. Fantastic! It works. I'm going to > write > > up a > > > > blog entry on this pattern, and I'll send a link when I post it. > > > > > > > > Thanks for your help. > > > > -Corey > > > > > > > > > > > > > > > > > > > > > > > > On Jan 23, 2008 10:03 AM, David Chelimsky > wrote: > > > > > > > > > > On Jan 23, 2008 8:49 AM, Corey Haines > wrote: > > > > > > Of course. Thanks, David! I still am getting used to user=, > rather > > than > > > > just > > > > > > user. Thanks again. > > > > > > > > > > No problem. I certainly got caught by that early on. > > > > > > > > > > I have some more general comments. See below: > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > -Corey > > > > > > > > > > > > > > > > > > > > > > > > On Jan 23, 2008 9:46 AM, David Chelimsky < dchelimsky at gmail.com> > > wrote: > > > > > > > > > > > > > > On Jan 23, 2008 8:41 AM, Corey Haines < coreyhaines at gmail.com> > > wrote: > > > > > > > > > > > > > > > > > > > > > > > > > > > > > All, > > > > > > > > > > > > > > > > I'm missing something simple, I think. I am writing a spec > to > > say > > > > that > > > > > > my > > > > > > > > CouponController should create a new coupon from the form > > > > parameters, > > > > > > then > > > > > > > > set the current user. Here's the spec: > > > > > > > > > > > > > > > > describe CouponController, "When posting to save_coupon" do > > > > > > > > > > > > > > > > before(:each) do > > > > > > > > @expectedName = "pepper's" > > > > > > > > @expectedAmount = 5 > > > > > > > > > > > > > > > > coupon = mock_model Coupon > > > > > > > > current_user = mock_model User > > > > > > > > controller.stub! > (:current_user).and_return(current_user) > > > > > > > > > > > > > > > > > > > > > > > > > > > > Coupon.should_receive > (:new).with({"name"=>@expectedName,"amount"=>@expectedAmount}).and_return(coupon) > > > > > > > > coupon.should_receive(:user).with(current_user) > > > > > > > > coupon.should_receive(:save) > > > > > > > > end > > > > > > > > > > > > > > > > it "should tell the Coupon model to create a new coupon > with > > the > > > > given > > > > > > > > parameters and save" do > > > > > > > > post > > > > > > > > > > > > > 'save_coupon',{:coupon=>{:name=>@expectedName,:amount=>@expectedAmount}} > > > > > > > > end > > > > > > > > > > > > > > > > Here's the controller method: > > > > > > > > > > > > > > > > def save_coupon > > > > > > > > coupon = Coupon.new(params[:coupon]) > > > > > > > > coupon.user = current_user > > > > > > > > coupon.save > > > > > > > > redirect_to_index "Coupon Added!" > > > > > > > > end > > > > > > > > > > This one example is doing too much IMO. You even say "I am writing > a > > > > > > > > > > spec to say that my CouponController should create a new coupon > from > > > > > the form parameters, then set the current user." That's two > things. > > > > > > > > > > Generally I try to keep stubs in before(:each), expectations in > the > > > > > examples, and one example for each concept that I'm describing. > > > > > > > > > > I took the liberty of pastie-ing what I'd probably do. I haven't > run > > > > > it, so it might not work as/is, but you'll get the idea. > > > > > > > > > > http://pastie.caboo.se/142403 > > > > > > > > > > Cheers, > > > > > David > > > > > > > > > > PS - I'm really glad to see you getting involved with this list. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > And, I get the following failure: > > > > > > > > > > > > > > > > Mock 'Coupon_1008' received unexpected message :user= with > > > > > > (# > > > > > > > @name="User_1009">) > > > > > > > > > > > > > > > > > > > > > That's from this line in save_coupon: > > > > > > > > > > > > > > coupon.user = current_user > > > > > > > > > > > > > > Just need to stub that: > > > > > > > > > > > > > > coupon.stub!(:user=) > > > > > > > > > > > > > > Or you could expect it: > > > > > > > > > > > > > > > > > > > > > coupon.should_receive (:user=).with(current_user) > > > > > > > > > > > > > > Cheers, > > > > > > > David > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > I'm sure that I'm missing something very simple, but I've > been > > > > staring > > > > > > at it > > > > > > > > for too long. > > > > > > > > > > > > > > > > (also, if anyone has commented on my style, please feel free > to > > > > mention > > > > > > it, > > > > > > > > as I'm still adjusting my mind to rspec) > > > > > > > > > > > > > > > > Oh, versions, I almost forgot: > > > > > > > > rails 2.0.2 > > > > > > > > rspec(_on_rails) plugins just updated from current a couple > days > > > > ago, > > > > > > not > > > > > > > > totally sure how to get the versions of the plugins > > > > > > > > > > > > > > > > > > > > > > > > Thanks. > > > > > > > > -Corey > > > > > > > > > > > > > > > > -- > > > > > > > > http://www.coreyhaines.com > > > > > > > > The Internet's Premiere source of information about Corey > Haines > > > > > > > > _______________________________________________ > > > > > > > > rspec-users mailing list > > > > > > > > rspec-users at rubyforge.org > > > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > _______________________________________________ > > > > > > > rspec-users mailing list > > > > > > > rspec-users at rubyforge.org > > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > -- > > > > > > > > > > > > > > > > > > http://www.coreyhaines.com > > > > > > The Internet's Premiere source of information about Corey Haines > > > > > > _______________________________________________ > > > > > > rspec-users mailing list > > > > > > rspec-users at rubyforge.org > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > _______________________________________________ > > > > > rspec-users mailing list > > > > > rspec-users at rubyforge.org > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > > > > > > -- > > > > http://www.coreyhaines.com > > > > The Internet's Premiere source of information about Corey Haines > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > -- > > > > > > http://www.coreyhaines.com > > The Internet's Premiere source of information about Corey Haines > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080126/24118f18/attachment-0001.html From rick.denatale at gmail.com Sat Jan 26 14:59:19 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Sat, 26 Jan 2008 14:59:19 -0500 Subject: [rspec-users] RSpec and resource_controller plugin Message-ID: I just discovered James Golick's resource_controller plugin http://jamesgolick.com/resource_controller after spending another stretch of boredom making the changes to nest yet another rails resource controller. I'd actually slowed down this time to think about what I was doing in hopes of automating the task. I've tended to use script/generate rspec_scaffold to get the skeleton set of specs along with the model, migration, controller views, etc. I've been a bit ambivalent about this, for one thing if feels a little un-bdd to have the specs generated, but on the other hand the code tends to be so pro-forma (at least to start out) and the generate specs help as a regression check, and to help me think about how and whether to deviate from things like flows between browser pages. But it's always ugly when I want to nest one of these generated resources. It always seems to take me longer than it should to make the changes in both the controller, the views, and the specs to get to square one. The plugin, which brings back the script/generate scaffold_resource with new meaning turns a controller that looks like this: class HardwaysController < ApplicationController # GET /hardways # GET /hardways.xml def index @hardways = Hardway.find(:all) respond_to do |format| format.html # index.html.erb format.xml { render :xml => @hardways } end end # GET /hardways/1 # GET /hardways/1.xml def show @hardway = Hardway.find(params[:id]) respond_to do |format| format.html # show.html.erb format.xml { render :xml => @hardway } end end # GET /hardways/new # GET /hardways/new.xml def new @hardway = Hardway.new respond_to do |format| format.html # new.html.erb format.xml { render :xml => @hardway } end end # GET /hardways/1/edit def edit @hardway = Hardway.find(params[:id]) end # POST /hardways # POST /hardways.xml def create @hardway = Hardway.new(params[:hardway]) respond_to do |format| if @hardway.save flash[:notice] = 'Hardway was successfully created.' format.html { redirect_to(@hardway) } format.xml { render :xml => @hardway, :status => :created, :location => @hardway } else format.html { render :action => "new" } format.xml { render :xml => @hardway.errors, :status => :unprocessable_entity } end end end # PUT /hardways/1 # PUT /hardways/1.xml def update @hardway = Hardway.find(params[:id]) respond_to do |format| if @hardway.update_attributes(params[:hardway]) flash[:notice] = 'Hardway was successfully updated.' format.html { redirect_to(@hardway) } format.xml { head :ok } else format.html { render :action => "edit" } format.xml { render :xml => @hardway.errors, :status => :unprocessable_entity } end end end # DELETE /hardways/1 # DELETE /hardways/1.xml def destroy @hardway = Hardway.find(params[:id]) @hardway.destroy respond_to do |format| format.html { redirect_to(hardways_url) } format.xml { head :ok } end end end To this: class EasywaysController < ResourceController::Base end And the helpers make it dead easy to use these resource controllers polymorphically (i.e. with multiple parent resources using for example AR polymorphic associations) or in both nested and unnested forms. Anyway, in case you can't tell, I'm pretty pumped about the possibilities of this plugin. BUT Right now it only generates test/unit testcases. I was wondering if any RSpeccers had already gone down this road and whether or not a new generate rspec_scaffold generator might be in the offing when this plugin is installed. Someone asked this question from the other direction on the resource_controller google group in November, but got no reply. I know I should just write it myself, but you cant blame a guy for asking, and I'd love to hear comments on this plugin from other RSpec devotees. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From will.sargent at gmail.com Sat Jan 26 16:06:01 2008 From: will.sargent at gmail.com (Will Sargent) Date: Sat, 26 Jan 2008 13:06:01 -0800 Subject: [rspec-users] Changing rspec directory structure In-Reply-To: References: Message-ID: > I'd go one further than Pat Maddox's point: If your unit specs aren't > going to touch the database, then you really ought to be running a > tier of more integrated tests on your workstation before every checkin > (and again on the CI server). For obvious reasons, purely mock-based > unit tests/specs can and eventually will lie to you about your objects > actually being ready to work together, so don't trust them to tell you > about more than what the unit being spec'd does. I like the idea of running integration tests before every checkin, but I've heard too many horror stories of it taking 30 minutes or more before a checkin actually happens. We have integration tests that are going out to external systems, so it's a single example set can take a full minute -- and this is right now. I very much want integration tests to be run on the CI server on every checkin. The last place I set this up has a test suite that last for 90 minutes though, so it's very much a correctness vs convenience thing. Incidentally, when is cruisecontrol.rb going to have a 'testing' tab that shows passed and failed tests like TextMate? The stack trace is _ugly_. > Our commit rake task looks something like this: > * svn up > * run unit specs > * bring the dev database up to date (we blow it away and rebuild from scratch) > * spec (the Spec::Rails task, which depends on db:test:prepare, > cloning the test db from the dev schema) > > In the /unit spec_helper, we load the rspec plugin, but not > rspec_on_rails, ARBS in place of ActiveRecord and (for now at least) > require ActiveSupport and the ActionPack but don't actually load the > rails environment, which shaves off a second or two. (That second or > two isn't a big deal when running rake, but it's great in TextMate > when running just one spec. It feels pretty much instantaneous.) That sound really good. I like TextMate's integration with RSpec. I'm just using Unitrecord right now and mocking access to db operations in the unit tests. It's working fine for me so far. I'm using fixture_replacement for the integration tests. I read the Factory pattern that Jay Fields is implementing, but I'm not sure it's worth the effort to set up. One thing I have noticed is that moving the specs from the normal directory structure means that I have to specify the type directly, i.e. describe FooController, 'unit tests: ', :type => :controller do end Not a huge deal, but a bit of a surprise. Will. From ben at benmabey.com Sat Jan 26 17:34:46 2008 From: ben at benmabey.com (Ben Mabey) Date: Sat, 26 Jan 2008 15:34:46 -0700 Subject: [rspec-users] Changing rspec directory structure In-Reply-To: References: Message-ID: <479BB586.80205@benmabey.com> Will Sargent wrote: >> I'd go one further than Pat Maddox's point: If your unit specs aren't >> going to touch the database, then you really ought to be running a >> tier of more integrated tests on your workstation before every checkin >> (and again on the CI server). For obvious reasons, purely mock-based >> unit tests/specs can and eventually will lie to you about your objects >> actually being ready to work together, so don't trust them to tell you >> about more than what the unit being spec'd does. >> > > I like the idea of running integration tests before every checkin, but > I've heard too many horror stories of it taking 30 minutes or more > before a checkin actually happens. We have integration tests that are > going out to external systems, so it's a single example set can take a > full minute -- and this is right now. > > I very much want integration tests to be run on the CI server on every > checkin. The last place I set this up has a test suite that last for > 90 minutes though, so it's very much a correctness vs convenience > thing. > > Incidentally, when is cruisecontrol.rb going to have a 'testing' tab > that shows passed and failed tests like TextMate? The stack trace is > _ugly_. > > Are you just talking about the HTML formatted specs that textmate uses? You can already get that with cruisecontrol.rb... All you have to do is have tech spec command output a html file. -Ben From matt at matt-darby.com Sun Jan 27 01:50:29 2008 From: matt at matt-darby.com (Matt Darby) Date: Sun, 27 Jan 2008 01:50:29 -0500 Subject: [rspec-users] Textmate RSpec Bundle 'it' snippet Message-ID: It seems to me that the RSpec bundle's 'it' snippet is in need of some love. By default, a newly inserted spec passes. This seems odd as it is misleading. It also makes it harder find what specs still need to be completed if you return to an RSpec module after a break. I propose that the 'it' snippet is changed to the following: it "${0:should ${1:description}}" ${3:do ${2:pending("Needs to be written")} end} This tweak simply adds a 'pending' statement as the body of a newly created spec. When run, the tester will be alerted to an unfinished test. Thoughts? Thanks! Matt Darby, M.S. IT Manager / Lead Web Developer Dynamix Engineering Ltd. 1108 City Park Ave. Columbus, OH 43206 Cell: (614) 403-5289 www.dynamix-ltd.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080127/6907e92e/attachment.html From pergesu at gmail.com Sun Jan 27 02:32:55 2008 From: pergesu at gmail.com (Pat Maddox) Date: Sat, 26 Jan 2008 23:32:55 -0800 Subject: [rspec-users] Textmate RSpec Bundle 'it' snippet In-Reply-To: References: Message-ID: <810a540e0801262332g48e54ee9m32e116df0136d3b8@mail.gmail.com> On Jan 26, 2008 10:50 PM, Matt Darby wrote: > It seems to me that the RSpec bundle's 'it' snippet is in need of some love. > By default, a newly inserted spec passes. Not if you fill it out...and the BDD way is to write one example at a time, not a complete spec beforehand. > This seems odd as it is > misleading. It also makes it harder find what specs still need to be > completed if you return to an RSpec module after a break. > > I propose that the 'it' snippet is changed to the following: > > > it "${0:should ${1:description}}" ${3:do > ${2:pending("Needs to be written")} > end} > > This tweak simply adds a 'pending' statement as the body of a newly created > spec. When run, the tester will be alerted to an unfinished test. > > Thoughts? That's the wonderful thing about TextMate being so flexible, and RSpec being open source. You're free to change it on your own machine. However I'd say that there's no chance this change gets applied to RSpec trunk, nor should it. Pat From francois.wurmus at infopark.de Sun Jan 27 02:42:36 2008 From: francois.wurmus at infopark.de (Francois Wurmus) Date: Sun, 27 Jan 2008 08:42:36 +0100 Subject: [rspec-users] Textmate RSpec Bundle 'it' snippet In-Reply-To: References: Message-ID: <479C35EC.5090409@infopark.de> Hi Matt, one way of doing this is to leave the block out and just write: it "should bla bla" No 'do', no 'end'. The example will be pending this way. Fran?ois Matt Darby schrieb: > It seems to me that the RSpec bundle's 'it' snippet is in need of some > love. By default, a newly inserted spec passes. This seems odd as it is > misleading. It also makes it harder find what specs still need to be > completed if you return to an RSpec module after a break. > > I propose that the 'it' snippet is changed to the following: > > it "${0:should ${1:description}}" ${3:do > ${2:pending("Needs to be written")} > end} > > This tweak simply adds a 'pending' statement as the body of a newly > created spec. When run, the tester will be alerted to an unfinished test. > > Thoughts? > > Thanks! > ** > *Matt Darby, M.S.* > IT Manager / Lead Web Developer > > Dynamix Engineering Ltd. > 1108 City Park Ave. > Columbus, OH 43206 > Cell: (614) 403-5289 > www.dynamix-ltd.com > > > ------------------------------------------------------------------------ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From matt at matt-darby.com Sun Jan 27 09:50:53 2008 From: matt at matt-darby.com (Matt Darby) Date: Sun, 27 Jan 2008 09:50:53 -0500 Subject: [rspec-users] Textmate RSpec Bundle 'it' snippet In-Reply-To: <479C35EC.5090409@infopark.de> References: <479C35EC.5090409@infopark.de> Message-ID: <1AE4326D-6DB9-4411-BA84-742F3C251407@matt-darby.com> Ah, I was unaware of this. Thanks for the pointer. On Jan 27, 2008, at 2:42 AM, Francois Wurmus wrote: > Hi Matt, > > one way of doing this is to leave the block out and just write: > it "should bla bla" > > No 'do', no 'end'. The example will be pending this way. > > > Fran?ois From duelin.markers at gmail.com Sun Jan 27 12:05:19 2008 From: duelin.markers at gmail.com (John D. Hume) Date: Sun, 27 Jan 2008 12:05:19 -0500 Subject: [rspec-users] Help to spec a rails helper method that uses content_for In-Reply-To: References: Message-ID: Ben, You're trying to test more than one thing in one spec. The gutter that's steered you into here is that you're looking for side-effects of a method you've mocked. Your spec says to make sure the template calls "body_class" and to have the call return a string, but that's not how the body_class method works: the real method passes that string along to "content_for," which is what causes it to end up in the layout. There are really three responsibilities to specify: (1) the template is supposed to provide the right body_class, (2) the body_class method is supposed to format a string and pass it along to content_for, and (3) the layout is supposed to put that content into the body tag. For purposes of specifying the template's responsibility, I think you've got all you need by saying template.should_receive(:body_class).with("users") For the helper, you can just say in your helper spec self.should_receive(:content_for).with(:body_class, " class=\"funclass\"") body_class "funclass" Note that I'm mocking the receiver of the method being tested, which is a smell, but I think it's reasonable when dealing with app-specific helpers that rely on Rails helper methods. Also note that I'm specifying that you change your implementation to pass the content as the second argument to content_for. That's a lot less ugly to mock than the version with the block. I don't have a good recommendation for specifying the layout's responsibility for plopping the "body_class" content into the body tag, but I think it ought to be pretty easy to do readably. Maybe someone with more view-spec experience could help out. -hume. On Thu, Jan 24, 2008 at 11:00 AM, Ben Aldred wrote: > Hi guys, > > I am a Rspec newbie and am having problems creating a spec for a RoR helper > method. > > I have in fact already implemented the helper method and am trying to create > retrospective specs. I know its the wrong way to do it but I am still > learning Rspec. > > In my view I have a call to a helper method. > > <% body_class "users" %> > > which sets a CSS class declaration in the content_for block which is then > used in the tag in application.html.erb layout. > > def body_class(class_name) > content_for(:body_class) { " class=\"#{class_name}\"" } > end > > > I was trying the following in my view spec: > > template.should_receive (:body_class).with("users") > .and_return(' class="users"') > render "/admin/users/index.html.erb", :layout => "application" > response.should have_tag(' body.users') > > I get a: > > Expected at least 1 element matching "body.users", found 0. > is not true. > > when I printed the response.body to screen it does not contain he CSS class > declaration on the body tag, where as running mongrel and going to the page > everything is fine. > > what am I doing wrong? I ended up doing: > > render "/admin/users/index.html.erb", :layout => "application" > response[:body_class].should == ' class="users"' > > I am interested to know why my first attempt did not work. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From coreyhaines at gmail.com Sun Jan 27 15:31:26 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Sun, 27 Jan 2008 15:31:26 -0500 Subject: [rspec-users] Not seeing the failure In-Reply-To: <57c63afe0801230735t6e57bc63n2f8ae41c0b91cd9a@mail.gmail.com> References: <6bdacb70801230641h18c42784v4e03cc6d5b4eb355@mail.gmail.com> <57c63afe0801230646s60adff48k5e01920aef26dd04@mail.gmail.com> <6bdacb70801230649g2bc689acrb2267f5653480276@mail.gmail.com> <57c63afe0801230703r7a5d3897t7b8298ae9c987306@mail.gmail.com> <6bdacb70801230724x506b1163wd66b8696c0fa69d5@mail.gmail.com> <57c63afe0801230735t6e57bc63n2f8ae41c0b91cd9a@mail.gmail.com> Message-ID: <6bdacb70801271231v1fbd8c38m6cb2b1cde2f20850@mail.gmail.com> I just wanted to put one last note here (I will be blogging about this). WOW! I absolutely love that initialization syntax. I just went through some old specs and replaced my stubs with the initialization hash on the mock creation. Really sweet. -Corey On Jan 23, 2008 10:35 AM, David Chelimsky wrote: > On Jan 23, 2008 9:24 AM, Corey Haines wrote: > > Thanks, David! > > > > Here's what I morphed the specs into: > > > > http://pastie.caboo.se/142411 > > > > And, I ended up with a blog entry that I'll write tonight. > > > > Basically, here's the situation I've been running into which is causing > my > > specs to grow. > > > > If I don't set up something to tell the coupon that it is going to have > > :user= called on it, then the other tests fails. I didn't want to stub > it, > > as I want this to be part of my expectations. Luckily, it only took a > minute > > to come up with a possible solution, again relying on the fact that > things > > tend to work how I think they should. > > > > The solution I thought of was to set the stub! call in the > before(:each), > > then set an actual expectation in the spec. > > Actually - that's what mine did to. These two are the same: > > coupon = mock_model(Coupon, > :user= => nil, > :save => true > ) > > coupon = mock_model Coupon > coupon.stub!(:user=) > coupon.stub!(:save).and_return(true) > > :) > > Looking forward to your blog. > > Cheers, > David > > > In my mind, the expectation > > should override the stub (making sure it gets called), but the stub will > > allow the other tests to pass. Fantastic! It works. I'm going to write > up a > > blog entry on this pattern, and I'll send a link when I post it. > > > > Thanks for your help. > > -Corey > > > > > > > > > > > > On Jan 23, 2008 10:03 AM, David Chelimsky wrote: > > > > > > On Jan 23, 2008 8:49 AM, Corey Haines wrote: > > > > Of course. Thanks, David! I still am getting used to user=, rather > than > > just > > > > user. Thanks again. > > > > > > No problem. I certainly got caught by that early on. > > > > > > I have some more general comments. See below: > > > > > > > > > > > > > > > > > > > > -Corey > > > > > > > > > > > > > > > > On Jan 23, 2008 9:46 AM, David Chelimsky < dchelimsky at gmail.com> > wrote: > > > > > > > > > > On Jan 23, 2008 8:41 AM, Corey Haines < coreyhaines at gmail.com> > wrote: > > > > > > > > > > > > > > > > > > > > > All, > > > > > > > > > > > > I'm missing something simple, I think. I am writing a spec to > say > > that > > > > my > > > > > > CouponController should create a new coupon from the form > > parameters, > > > > then > > > > > > set the current user. Here's the spec: > > > > > > > > > > > > describe CouponController, "When posting to save_coupon" do > > > > > > > > > > > > before(:each) do > > > > > > @expectedName = "pepper's" > > > > > > @expectedAmount = 5 > > > > > > > > > > > > coupon = mock_model Coupon > > > > > > current_user = mock_model User > > > > > > controller.stub! (:current_user).and_return(current_user) > > > > > > > > > > > > > > > > > > Coupon.should_receive > (:new).with({"name"=>@expectedName,"amount"=>@expectedAmount}).and_return(coupon) > > > > > > coupon.should_receive(:user).with(current_user) > > > > > > coupon.should_receive(:save) > > > > > > end > > > > > > > > > > > > it "should tell the Coupon model to create a new coupon with > the > > given > > > > > > parameters and save" do > > > > > > post > > > > > > > > 'save_coupon',{:coupon=>{:name=>@expectedName,:amount=>@expectedAmount}} > > > > > > end > > > > > > > > > > > > Here's the controller method: > > > > > > > > > > > > def save_coupon > > > > > > coupon = Coupon.new(params[:coupon]) > > > > > > coupon.user = current_user > > > > > > coupon.save > > > > > > redirect_to_index "Coupon Added!" > > > > > > end > > > > > > This one example is doing too much IMO. You even say "I am writing a > > > > > > spec to say that my CouponController should create a new coupon from > > > the form parameters, then set the current user." That's two things. > > > > > > Generally I try to keep stubs in before(:each), expectations in the > > > examples, and one example for each concept that I'm describing. > > > > > > I took the liberty of pastie-ing what I'd probably do. I haven't run > > > it, so it might not work as/is, but you'll get the idea. > > > > > > http://pastie.caboo.se/142403 > > > > > > Cheers, > > > David > > > > > > PS - I'm really glad to see you getting involved with this list. > > > > > > > > > > > > > > > > > > > > > > > > > > > And, I get the following failure: > > > > > > > > > > > > Mock 'Coupon_1008' received unexpected message :user= with > > > > (# > > > > > @name="User_1009">) > > > > > > > > > > > > > > > That's from this line in save_coupon: > > > > > > > > > > coupon.user = current_user > > > > > > > > > > Just need to stub that: > > > > > > > > > > coupon.stub!(:user=) > > > > > > > > > > Or you could expect it: > > > > > > > > > > > > > > > coupon.should_receive (:user=).with(current_user) > > > > > > > > > > Cheers, > > > > > David > > > > > > > > > > > > > > > > > > > > > > I'm sure that I'm missing something very simple, but I've been > > staring > > > > at it > > > > > > for too long. > > > > > > > > > > > > (also, if anyone has commented on my style, please feel free to > > mention > > > > it, > > > > > > as I'm still adjusting my mind to rspec) > > > > > > > > > > > > Oh, versions, I almost forgot: > > > > > > rails 2.0.2 > > > > > > rspec(_on_rails) plugins just updated from current a couple days > > ago, > > > > not > > > > > > totally sure how to get the versions of the plugins > > > > > > > > > > > > > > > > > > Thanks. > > > > > > -Corey > > > > > > > > > > > > -- > > > > > > http://www.coreyhaines.com > > > > > > The Internet's Premiere source of information about Corey Haines > > > > > > _______________________________________________ > > > > > > rspec-users mailing list > > > > > > rspec-users at rubyforge.org > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > _______________________________________________ > > > > > rspec-users mailing list > > > > > rspec-users at rubyforge.org > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > > > > > > -- > > > > > > > > > > > > http://www.coreyhaines.com > > > > The Internet's Premiere source of information about Corey Haines > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > -- > > http://www.coreyhaines.com > > The Internet's Premiere source of information about Corey Haines > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080127/2bb6d082/attachment.html From coreyhaines at gmail.com Sun Jan 27 16:33:47 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Sun, 27 Jan 2008 16:33:47 -0500 Subject: [rspec-users] OT local version control? Message-ID: <6bdacb70801271333y5825321dp67936e236030aae5@mail.gmail.com> Hi, all, This isn't about rspec, but this list has people whose opinions I respect. So, I'm looking for a new version control system for my local development. I was going to install subversion, but I've heard rumors of people using some newer ones. Thoughts? I'd like to be able to run it either locally or on a home server. If I run it off a home server, then it needs to support offline access, so that I can use a cached version when I'm not on my home network. For simplicity's sake, running it locally is probably a better solution. What do you all use? -Corey -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080127/9121e93d/attachment.html From dchelimsky at gmail.com Sun Jan 27 16:47:02 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 27 Jan 2008 15:47:02 -0600 Subject: [rspec-users] OT local version control? In-Reply-To: <6bdacb70801271333y5825321dp67936e236030aae5@mail.gmail.com> References: <6bdacb70801271333y5825321dp67936e236030aae5@mail.gmail.com> Message-ID: <57c63afe0801271347s7e15a21aw50a121b7874cfe88@mail.gmail.com> On Jan 27, 2008 3:33 PM, Corey Haines wrote: > Hi, all, > > This isn't about rspec, but this list has people whose opinions I respect. > > So, I'm looking for a new version control system for my local development. I > was going to install subversion, but I've heard rumors of people using some > newer ones. Thoughts? I'd like to be able to run it either locally or on a > home server. If I run it off a home server, then it needs to support offline > access, so that I can use a cached version when I'm not on my home network. > For simplicity's sake, running it locally is probably a better solution. > > What do you all use? I use mercurial and git. I really like them both for different reasons. I'd recommend you play with both for a minute and see which one appeals to you. They're both distributed scm, which means what you have locally is a complete repository from which you can checkout, branch, merge, etc. Then you can pull and push changesets (in hg-speak) or commits (in git-speak) from and to other repos. Either way - dscm is a completely different experience from working w/ a remote svn repo. I'm quite certain you'll enjoy exploring it. Cheers, David From marcus at ahnve.com Sun Jan 27 16:54:15 2008 From: marcus at ahnve.com (Marcus Ahnve) Date: Sun, 27 Jan 2008 22:54:15 +0100 Subject: [rspec-users] DRYing up stories In-Reply-To: <8d961d900801232325g687ff9dar75c32f16b7d1b1cd@mail.gmail.com> References: <15053384.post@talk.nabble.com> <8d961d900801231537j6873fda4n2fc7338874569a24@mail.gmail.com> <4797D61D.4080902@benmabey.com> <8d961d900801232325g687ff9dar75c32f16b7d1b1cd@mail.gmail.com> Message-ID: <20080127215415.GD37183@oberkorn.local> On Thu, Jan 24, 2008 at 08:25:49AM +0100, aslak hellesoy wrote: > On Jan 24, 2008 1:04 AM, Ben Mabey wrote: > > While the original post had DRY in the subject line I don't see this as > > a DRY issue. I see it as a visualization and maintenance issue. If I > > add a new role and I want to test each action for it's permissions it > > would be much easier for a customer to go down a spread sheet and > > designate within each cell what the response should be.. success or > > failure, etc... This would give the customer a bird's eye view of > > permissions for the entire app for each class of users. By using a > > separate scenario for each role in each story you will be creating a lot > > of copy and past work which will comminucate the same information a > > spreadsheet would but a lot more inefficently since someone would have > > to read hundreds of pages of stories. I love the plain text stories. > > We just have to remember that there are better ways to express large > > amounts of data than plain English. :) > > Do you understand the point I'm trying to make? > > > > I totally get your point. This is where FIT shines (or maybe Ryan's Matrix). I completely agree. My experience is that you most often end up with two types of specs: flows and rules. Flows are best described in a story format, whereas rules are best described in a clear table format. Just take a simple password rule. Using flows to do this is overly verbose compared to fit. For example: |password|valid?| |short |false | |allchars|false | |goo0d1ne|true | And of course flows are not well documented using Fit. That is my basic theory for why it never took of. I have spent an hour or two trying to write a story runner for Fit, so far mostly reading the arcane Ruby Fit library. I'll get back when I have something to show. /Marcus -- Marcus Ahnve Blog: http://marcus.ahnve.net From tastapod at gmail.com Sun Jan 27 17:00:50 2008 From: tastapod at gmail.com (Dan North) Date: Sun, 27 Jan 2008 22:00:50 +0000 Subject: [rspec-users] OT local version control? In-Reply-To: <6bdacb70801271333y5825321dp67936e236030aae5@mail.gmail.com> References: <6bdacb70801271333y5825321dp67936e236030aae5@mail.gmail.com> Message-ID: I can see this descending into a mercurial vs git religious war :) Hi Corey. I'm using mercurial for both home and work use (supplementing some of subversion's shortcomings, mainly around merging). I looked (briefly) at git and - less briefly - at darcs. I settled on mercurial for purely non-scientific reasons. People whose opinions I respect are using it, the community seems both accommodating and active, and it's python which means it runs anywhere python lives, which is all of my home and work environments. Others on this list - including the lovely David - are using git and having just as much fun and productivity, so I'm sure it comes down to a matter of taste in the end. The big shift, though, is from centralised to distributed source control. This means that any working copy is also a full repository in its own right, so you can do everything you would usually need the server for: branching, tagging, cloning, logging, checking in, rolling back, etc. This page ( http://tinyurl.com/ykcs25) from the Mercurial wiki gives a pretty good overview. The basic model will be the same for any of the distributed SCMs. My experience so far is: git: insanely fast, made up of many shell scripts, big command set, does /BIG/ repositories (currently used for the entire linux kernel), doesn't run on windows. darcs: also fast, written in haskell so less "hackable". Has best cherry-picking support (choosing out-of-sequence changesets). Apparently doesn't do so well under biiig repositories. mercurial: also fast (seeing a pattern here?). Seems to scale well. Has (deliberately) svn/cvs-like command set where it can, so easy to adopt. This is where I've ended up. monotone: the first distributed scm I came across (Dave Astels was using it before any of the rest of us had heard of distributed scm). Never really used it much. At the end of the day it will be a personal preference. But whichever you end up with, my prediction is that you'll enjoy it much more than subversion. Cheers, Dan On 27/01/2008, Corey Haines wrote: > > Hi, all, > > This isn't about rspec, but this list has people whose opinions I respect. > > So, I'm looking for a new version control system for my local development. > I was going to install subversion, but I've heard rumors of people using > some newer ones. Thoughts? I'd like to be able to run it either locally or > on a home server. If I run it off a home server, then it needs to support > offline access, so that I can use a cached version when I'm not on my home > network. For simplicity's sake, running it locally is probably a better > solution. > > What do you all use? > > > -Corey > > -- > http://www.coreyhaines.com > The Internet's Premiere source of information about Corey Haines > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080127/8b133d38/attachment.html From pergesu at gmail.com Sun Jan 27 18:05:14 2008 From: pergesu at gmail.com (Pat Maddox) Date: Sun, 27 Jan 2008 15:05:14 -0800 Subject: [rspec-users] OT local version control? In-Reply-To: References: <6bdacb70801271333y5825321dp67936e236030aae5@mail.gmail.com> Message-ID: <810a540e0801271505p372d7456xde767f4f3f6d501@mail.gmail.com> On Jan 27, 2008 2:00 PM, Dan North wrote: > I can see this descending into a mercurial vs git religious war :) Doubtful. The enlightened among us don't have time to bother with mouthy users of that inferior dvcs. From chad at theedgecase.com Sun Jan 27 17:42:19 2008 From: chad at theedgecase.com (Chad Humphries) Date: Sun, 27 Jan 2008 17:42:19 -0500 Subject: [rspec-users] OT local version control? In-Reply-To: References: <6bdacb70801271333y5825321dp67936e236030aae5@mail.gmail.com> Message-ID: <124a48790801271442k350d7d5dp232e2600f2f3a878@mail.gmail.com> A good thing to note is that you can run many of the distributed scm tools in a 'svn wrapper' mode to ease transition with existing repositories. That made the switch much easier for me. - Chad On Jan 27, 2008 5:00 PM, Dan North wrote: > I can see this descending into a mercurial vs git religious war :) > > Hi Corey. I'm using mercurial for both home and work use (supplementing > some of subversion's shortcomings, mainly around merging). I looked > (briefly) at git and - less briefly - at darcs. I settled on mercurial for > purely non-scientific reasons. People whose opinions I respect are using it, > the community seems both accommodating and active, and it's python which > means it runs anywhere python lives, which is all of my home and work > environments. > > Others on this list - including the lovely David - are using git and > having just as much fun and productivity, so I'm sure it comes down to a > matter of taste in the end. > > The big shift, though, is from centralised to distributed source control. > This means that any working copy is also a full repository in its own right, > so you can do everything you would usually need the server for: branching, > tagging, cloning, logging, checking in, rolling back, etc. This page ( > http://tinyurl.com/ykcs25) from the Mercurial wiki gives a pretty good > overview. The basic model will be the same for any of the distributed SCMs. > > My experience so far is: > > git: insanely fast, made up of many shell scripts, big command set, does > /BIG/ repositories (currently used for the entire linux kernel), doesn't run > on windows. > darcs: also fast, written in haskell so less "hackable". Has best > cherry-picking support (choosing out-of-sequence changesets). Apparently > doesn't do so well under biiig repositories. > mercurial: also fast (seeing a pattern here?). Seems to scale well. Has > (deliberately) svn/cvs-like command set where it can, so easy to adopt. This > is where I've ended up. > monotone: the first distributed scm I came across (Dave Astels was using > it before any of the rest of us had heard of distributed scm). Never really > used it much. > > At the end of the day it will be a personal preference. But whichever you > end up with, my prediction is that you'll enjoy it much more than > subversion. > > Cheers, > Dan > > > On 27/01/2008, Corey Haines wrote: > > > Hi, all, > > > > This isn't about rspec, but this list has people whose opinions I > > respect. > > > > So, I'm looking for a new version control system for my local > > development. I was going to install subversion, but I've heard rumors of > > people using some newer ones. Thoughts? I'd like to be able to run it either > > locally or on a home server. If I run it off a home server, then it needs to > > support offline access, so that I can use a cached version when I'm not on > > my home network. For simplicity's sake, running it locally is probably a > > better solution. > > > > What do you all use? > > > > > > -Corey > > > > -- > > http://www.coreyhaines.com > > The Internet's Premiere source of information about Corey Haines > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080127/68c8bf07/attachment.html From lists at ruby-forum.com Sun Jan 27 19:27:05 2008 From: lists at ruby-forum.com (Matt Darby) Date: Mon, 28 Jan 2008 01:27:05 +0100 Subject: [rspec-users] route_for and nested resources In-Reply-To: <91d2eb6caae733507e424d06a168fe56@ruby-forum.com> References: <91d2eb6caae733507e424d06a168fe56@ruby-forum.com> Message-ID: Chris Olsen wrote: > I can't figure out how to make the updates to allow for the route_form > method to return a url that matches the expected. Sorry to bump such an old post, but the interweb doesn't really show anything for routing specs when it comes to nested resources. I just find this unanswered post repeatedly. Does anyone know how to work with route_for() when it comes to nested resources? -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Sun Jan 27 20:05:58 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 27 Jan 2008 19:05:58 -0600 Subject: [rspec-users] route_for and nested resources In-Reply-To: <91d2eb6caae733507e424d06a168fe56@ruby-forum.com> References: <91d2eb6caae733507e424d06a168fe56@ruby-forum.com> Message-ID: <57c63afe0801271705l422096f0rc18b5a48185c884c@mail.gmail.com> On Nov 21, 2007 3:10 PM, Chris Olsen wrote: > I can't figure out how to make the updates to allow for the route_form > method to return a url that matches the expected. > > Here is a sample > route_for(:controller => :task, :action => :new).should == "/task/new" > > If a task has to be created for a user, how exactly do I do this. The > following doesn't work: > route_for(:controller => :task, :action => :new, :user_id => 1).should > == "/users/1/task/new" (fails) > route_for(:controller => :task, :action => :new, :user_id => 1).should > == "/task/new?user_id=1" (passes) > > Or do you just use: > new_user_task(1,1).should == "/users/1/task/new" > > I haven't been able to find that much documentation on the route_for > method that lists any ways of creating the nested route url. It uses ActionController::Routing::Routes.generate, which is equally un-documented :( You've got a singular task controller (instead of tasks), so I'm not sure how that's affecting things. I can tell you that if you do this: route_for(:controller => 'tasks', :action => 'new', :user_id => '2').should == '/users/2/tasks/new' It will pass when your routes.rb has this: map.resources :users do |users| users.resources :tasks end Give that a whirl. Cheers, David > > Thanks. > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Sun Jan 27 20:06:37 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 27 Jan 2008 19:06:37 -0600 Subject: [rspec-users] route_for and nested resources In-Reply-To: References: <91d2eb6caae733507e424d06a168fe56@ruby-forum.com> Message-ID: <57c63afe0801271706j6f44ad92x2d8261ee9fbce833@mail.gmail.com> On Jan 27, 2008 6:27 PM, Matt Darby wrote: > Chris Olsen wrote: > > I can't figure out how to make the updates to allow for the route_form > > method to return a url that matches the expected. > > > Sorry to bump such an old post, but the interweb doesn't really show > anything for routing specs when it comes to nested resources. I just > find this unanswered post repeatedly. > > Does anyone know how to work with route_for() when it comes to nested > resources? I think I answered that in my response to the OP. Write back if not. > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From matt at matt-darby.com Sun Jan 27 20:26:15 2008 From: matt at matt-darby.com (Matt Darby) Date: Sun, 27 Jan 2008 20:26:15 -0500 Subject: [rspec-users] route_for and nested resources In-Reply-To: <57c63afe0801271705l422096f0rc18b5a48185c884c@mail.gmail.com> References: <91d2eb6caae733507e424d06a168fe56@ruby-forum.com> <57c63afe0801271705l422096f0rc18b5a48185c884c@mail.gmail.com> Message-ID: <5E5168CC-C404-4F68-A793-8EE872C0270B@matt-darby.com> On Jan 27, 2008, at 8:05 PM, David Chelimsky wrote: > On Nov 21, 2007 3:10 PM, Chris Olsen wrote: >> I can't figure out how to make the updates to allow for the >> route_form >> method to return a url that matches the expected. >> >> Here is a sample >> route_for(:controller => :task, :action => :new).should == "/task/ >> new" >> >> If a task has to be created for a user, how exactly do I do this. >> The >> following doesn't work: >> route_for(:controller => :task, :action => :new, :user_id => >> 1).should >> == "/users/1/task/new" (fails) >> route_for(:controller => :task, :action => :new, :user_id => >> 1).should >> == "/task/new?user_id=1" (passes) >> >> Or do you just use: >> new_user_task(1,1).should == "/users/1/task/new" >> >> I haven't been able to find that much documentation on the route_for >> method that lists any ways of creating the nested route url. > > It uses ActionController::Routing::Routes.generate, which is equally > un-documented :( > > You've got a singular task controller (instead of tasks), so I'm not > sure how that's affecting things. I can tell you that if you do this: > > route_for(:controller => 'tasks', :action => 'new', :user_id => > '2').should == '/users/2/tasks/new' > > It will pass when your routes.rb has this: > > map.resources :users do |users| > users.resources :tasks > end > > Give that a whirl. > > Cheers, > David Thanks for the further explanation David! I could've sworn that I tried this, but sure enough, it works like a charm. Thanks! Matt Darby, M.S. IT Manager / Lead Web Developer Dynamix Engineering Ltd. 1108 City Park Ave. Columbus, OH 43206 Cell: (614) 403-5289 www.dynamix-ltd.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080127/2f98f42d/attachment-0001.html From jonathan at parkerhill.com Sun Jan 27 20:47:15 2008 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Sun, 27 Jan 2008 20:47:15 -0500 Subject: [rspec-users] route_for and nested resources In-Reply-To: <5E5168CC-C404-4F68-A793-8EE872C0270B@matt-darby.com> References: <91d2eb6caae733507e424d06a168fe56@ruby-forum.com> <57c63afe0801271705l422096f0rc18b5a48185c884c@mail.gmail.com> <5E5168CC-C404-4F68-A793-8EE872C0270B@matt-darby.com> Message-ID: <288C4B12-82A4-4FE3-A548-6AC0633D64BD@parkerhill.com> Note, named routes cannot be accessed unless you have a response (eg after you've run a controller action) See http://rspec.lighthouseapp.com/projects/5645/tickets/201-enable- named-urls-before-response On Jan 27, 2008, at 8:26 PM, Matt Darby wrote: > On Jan 27, 2008, at 8:05 PM, David Chelimsky wrote: > >> On Nov 21, 2007 3:10 PM, Chris Olsen wrote: >>> Or do you just use: >>> new_user_task(1,1).should == "/users/1/task/new" >>> >>> -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080127/9d049a9f/attachment.html From dchelimsky at gmail.com Sun Jan 27 22:32:04 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 27 Jan 2008 21:32:04 -0600 Subject: [rspec-users] route_for and nested resources In-Reply-To: <288C4B12-82A4-4FE3-A548-6AC0633D64BD@parkerhill.com> References: <91d2eb6caae733507e424d06a168fe56@ruby-forum.com> <57c63afe0801271705l422096f0rc18b5a48185c884c@mail.gmail.com> <5E5168CC-C404-4F68-A793-8EE872C0270B@matt-darby.com> <288C4B12-82A4-4FE3-A548-6AC0633D64BD@parkerhill.com> Message-ID: <57c63afe0801271932k7305502fn335cc8dffe9a6b3d@mail.gmail.com> On Jan 27, 2008 7:47 PM, Jonathan Linowes wrote: > Note, named routes cannot be accessed unless you have a response (eg after > you've run a controller action) > See > http://rspec.lighthouseapp.com/projects/5645/tickets/201-enable-named-urls-before-response Since you bring it up - any ideas on how to make that happen? > > > > On Jan 27, 2008, at 8:26 PM, Matt Darby wrote: > > > On Jan 27, 2008, at 8:05 PM, David Chelimsky wrote: > > On Nov 21, 2007 3:10 PM, Chris Olsen wrote: > > Or do you just use: > new_user_task(1,1).should == "/users/1/task/new" > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From harm.aarts at innovationfactory.nl Mon Jan 28 08:31:50 2008 From: harm.aarts at innovationfactory.nl (Harm Aarts) Date: Mon, 28 Jan 2008 14:31:50 +0100 Subject: [rspec-users] attachment_fu with fixtures Message-ID: Dear list, I can't figure out how to use fixtures with attachment_fu. I know how to use files with RSpec in my controllers, BackgroundPhoto.create(:uploaded_data => fixture_file_upload("files/ some.zip", "application/x-zip")), but this does not work with fixtures(obviously). More importantly I have no idea where to start... Can someone shed some light on this? With kind regards, Harm From jeremy.burks at gmail.com Mon Jan 28 10:24:26 2008 From: jeremy.burks at gmail.com (Jeremy Burks) Date: Mon, 28 Jan 2008 09:24:26 -0600 Subject: [rspec-users] OT local version control? In-Reply-To: <124a48790801271442k350d7d5dp232e2600f2f3a878@mail.gmail.com> References: <6bdacb70801271333y5825321dp67936e236030aae5@mail.gmail.com> <124a48790801271442k350d7d5dp232e2600f2f3a878@mail.gmail.com> Message-ID: although i primarily use mercurial, bazaar (http://bazaar-vcs.org/) is also worth a mention On Jan 27, 2008 4:42 PM, Chad Humphries wrote: > A good thing to note is that you can run many of the distributed scm tools > in a 'svn wrapper' mode to ease transition with existing repositories. That > made the switch much easier for me. > > > - Chad > > > On Jan 27, 2008 5:00 PM, Dan North wrote: > > > > I can see this descending into a mercurial vs git religious war :) > > > > Hi Corey. I'm using mercurial for both home and work use (supplementing > some of subversion's shortcomings, mainly around merging). I looked > (briefly) at git and - less briefly - at darcs. I settled on mercurial for > purely non-scientific reasons. People whose opinions I respect are using it, > the community seems both accommodating and active, and it's python which > means it runs anywhere python lives, which is all of my home and work > environments. > > > > Others on this list - including the lovely David - are using git and > having just as much fun and productivity, so I'm sure it comes down to a > matter of taste in the end. > > > > The big shift, though, is from centralised to distributed source control. > This means that any working copy is also a full repository in its own right, > so you can do everything you would usually need the server for: branching, > tagging, cloning, logging, checking in, rolling back, etc. This page > (http://tinyurl.com/ykcs25) from the Mercurial wiki gives a pretty good > overview. The basic model will be the same for any of the distributed SCMs. > > > > My experience so far is: > > > > git: insanely fast, made up of many shell scripts, big command set, does > /BIG/ repositories (currently used for the entire linux kernel), doesn't run > on windows. > > darcs: also fast, written in haskell so less "hackable". Has best > cherry-picking support (choosing out-of-sequence changesets). Apparently > doesn't do so well under biiig repositories. > > mercurial: also fast (seeing a pattern here?). Seems to scale well. Has > (deliberately) svn/cvs-like command set where it can, so easy to adopt. This > is where I've ended up. > > monotone: the first distributed scm I came across (Dave Astels was using > it before any of the rest of us had heard of distributed scm). Never really > used it much. > > > > At the end of the day it will be a personal preference. But whichever you > end up with, my prediction is that you'll enjoy it much more than > subversion. > > > > Cheers, > > Dan > > > > > > > > > > > > > > On 27/01/2008, Corey Haines wrote: > > > > > > > > > > > > Hi, all, > > > > > > This isn't about rspec, but this list has people whose opinions I > respect. > > > > > > So, I'm looking for a new version control system for my local > development. I was going to install subversion, but I've heard rumors of > people using some newer ones. Thoughts? I'd like to be able to run it either > locally or on a home server. If I run it off a home server, then it needs to > support offline access, so that I can use a cached version when I'm not on > my home network. For simplicity's sake, running it locally is probably a > better solution. > > > > > > What do you all use? > > > > > > > > > -Corey > > > > > > -- > > > http://www.coreyhaines.com > > > The Internet's Premiere source of information about Corey Haines > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From zach.dennis at gmail.com Mon Jan 28 13:00:37 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Mon, 28 Jan 2008 13:00:37 -0500 Subject: [rspec-users] OT local version control? In-Reply-To: References: <6bdacb70801271333y5825321dp67936e236030aae5@mail.gmail.com> <124a48790801271442k350d7d5dp232e2600f2f3a878@mail.gmail.com> Message-ID: <85d99afe0801281000v65fcc2d9qab47460f4dfa87d0@mail.gmail.com> We recently started using git on our project. It still uses a svn repository and we enjoy the use of the git-svn bridge to synchronize things. There are a few things we haven't figured out how to do yet with git-svn: * create tags or branches * commit to tags or branches * see the filenames of files that changed in a particular commit We are very happy with git, and git-svn is making the transition to git itself much easier. In the past I tried darcs on a few personal projects and I was happy with it, but the git-svn bridge won me over when transitioning projects that already used svn. Zach On Jan 28, 2008 10:24 AM, Jeremy Burks wrote: > although i primarily use mercurial, bazaar (http://bazaar-vcs.org/) is > also worth a mention > > > On Jan 27, 2008 4:42 PM, Chad Humphries wrote: > > A good thing to note is that you can run many of the distributed scm tools > > in a 'svn wrapper' mode to ease transition with existing repositories. That > > made the switch much easier for me. > > > > > > - Chad > > > > > > On Jan 27, 2008 5:00 PM, Dan North wrote: > > > > > > > I can see this descending into a mercurial vs git religious war :) > > > > > > Hi Corey. I'm using mercurial for both home and work use (supplementing > > some of subversion's shortcomings, mainly around merging). I looked > > (briefly) at git and - less briefly - at darcs. I settled on mercurial for > > purely non-scientific reasons. People whose opinions I respect are using it, > > the community seems both accommodating and active, and it's python which > > means it runs anywhere python lives, which is all of my home and work > > environments. > > > > > > Others on this list - including the lovely David - are using git and > > having just as much fun and productivity, so I'm sure it comes down to a > > matter of taste in the end. > > > > > > The big shift, though, is from centralised to distributed source control. > > This means that any working copy is also a full repository in its own right, > > so you can do everything you would usually need the server for: branching, > > tagging, cloning, logging, checking in, rolling back, etc. This page > > (http://tinyurl.com/ykcs25) from the Mercurial wiki gives a pretty good > > overview. The basic model will be the same for any of the distributed SCMs. > > > > > > My experience so far is: > > > > > > git: insanely fast, made up of many shell scripts, big command set, does > > /BIG/ repositories (currently used for the entire linux kernel), doesn't run > > on windows. > > > darcs: also fast, written in haskell so less "hackable". Has best > > cherry-picking support (choosing out-of-sequence changesets). Apparently > > doesn't do so well under biiig repositories. > > > mercurial: also fast (seeing a pattern here?). Seems to scale well. Has > > (deliberately) svn/cvs-like command set where it can, so easy to adopt. This > > is where I've ended up. > > > monotone: the first distributed scm I came across (Dave Astels was using > > it before any of the rest of us had heard of distributed scm). Never really > > used it much. > > > > > > At the end of the day it will be a personal preference. But whichever you > > end up with, my prediction is that you'll enjoy it much more than > > subversion. > > > > > > Cheers, > > > Dan > > > > > > > > > > > > > > > > > > > > > On 27/01/2008, Corey Haines wrote: > > > > > > > > > > > > > > > > Hi, all, > > > > > > > > This isn't about rspec, but this list has people whose opinions I > > respect. > > > > > > > > So, I'm looking for a new version control system for my local > > development. I was going to install subversion, but I've heard rumors of > > people using some newer ones. Thoughts? I'd like to be able to run it either > > locally or on a home server. If I run it off a home server, then it needs to > > support offline access, so that I can use a cached version when I'm not on > > my home network. For simplicity's sake, running it locally is probably a > > better solution. > > > > > > > > What do you all use? > > > > > > > > > > > > -Corey > > > > > > > > -- > > > > http://www.coreyhaines.com > > > > The Internet's Premiere source of information about Corey Haines > > > > > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Zach Dennis http://www.continuousthinking.com From lists at ruby-forum.com Mon Jan 28 14:36:46 2008 From: lists at ruby-forum.com (Chris Olsen) Date: Mon, 28 Jan 2008 20:36:46 +0100 Subject: [rspec-users] Could this controller test be made simpler? Message-ID: In a create controller method I am testing the else clause that occurs when the model is unable to be saved. Sounds simple enough, but because model is created before the save and the form has to be re-filled I now have to stub a model and all the attributes. Since the error messages are displayed I also have to stub some methods within the model that allow the error messages to be displayed properly. This small test turns into a lot of code. So I am wondering if there is something that I am missing to make this much simpler. Things did start simple, in the stubbing of the new method within the Account class and then the save method within the @account model. Then I get errors reminding me to stub out the users method for the account model, then the build method, etc I have looked at the generated scaffold code and it is simpler, but it seems that the relationship made between the two models is what starts to make this more complex. Thanks for the help. Here is my current code: =============== before :each do @account = mock_model(Account) #what is being tested here @account.stub!(:save).and_return(false) #User info @user = mock_model(User) users = mock("Userlist") @account.stub!(:users).and_return(users) users.stub!(:build).and_return(@user) #since the form is repopulated the account mock must have stub for all the attributes @account.stub!(:subdomain).and_return("") @account.stub!(:company_name).and_return("") @account.stub!(:filename).and_return("") @user.stub!(:login).and_return("") @user.stub!(:email).and_return("") @user.stub!(:password).and_return("") @user.stub!(:password_confirmation).and_return("") #need these to satisfy the error messages errors = mock("errors") errors.stub!("empty?").and_return(false) errors.stub!("full_messages").and_return(["error 1", "error 2"]) @account.stub!(:errors).and_return(errors) @user.stub!(:errors).and_return(errors) Account.stub!(:new).and_return(@account) end it "should re-render new template" do post "create" #with no submitted params response.should render_template("accounts/new") end # Controller code def create @account = Account.new(params[:account]) @user = @account.users.build(params[:user]) if verify_recaptcha(@account) && @account.save redirect_to admin_listings_url else render :action => "new" end end -- Posted via http://www.ruby-forum.com/. From omen.king at gmail.com Mon Jan 28 14:45:15 2008 From: omen.king at gmail.com (Andrew WC Brown) Date: Mon, 28 Jan 2008 14:45:15 -0500 Subject: [rspec-users] Could this controller test be made simpler? In-Reply-To: References: Message-ID: Been a month since I've rspec, I think you can place the stubs here. @user = mock_model(User, login => "", email => "", password => "", password_confirmation => "" ) @account = mock_model(Account, subdomain => "", company_name => "", filename => "" ) On Jan 28, 2008 2:36 PM, Chris Olsen wrote: > In a create controller method I am testing the else clause that occurs > when the model is unable to be saved. Sounds simple enough, but because > model is created before the save and the form has to be re-filled I now > have to stub a model and all the attributes. Since the error messages > are displayed I also have to stub some methods within the model that > allow the error messages to be displayed properly. > > This small test turns into a lot of code. So I am wondering if there is > something that I am missing to make this much simpler. Things did start > simple, in the stubbing of the new method within the Account class and > then the save method within the @account model. Then I get errors > reminding me to stub out the users method for the account model, then > the build method, etc > > I have looked at the generated scaffold code and it is simpler, but it > seems that the relationship made between the two models is what starts > to make this more complex. > > Thanks for the help. > > Here is my current code: > =============== > before :each do > @account = mock_model(Account) > > #what is being tested here > @account.stub!(:save).and_return(false) > > #User info > @user = mock_model(User) > users = mock("Userlist") > @account.stub!(:users).and_return(users) > users.stub!(:build).and_return(@user) > > #since the form is repopulated the account mock must have stub for > all the attributes > @account.stub!(:subdomain).and_return("") > @account.stub!(:company_name).and_return("") > @account.stub!(:filename).and_return("") > @user.stub!(:login).and_return("") > @user.stub!(:email).and_return("") > @user.stub!(:password).and_return("") > @user.stub!(:password_confirmation).and_return("") > > #need these to satisfy the error messages > errors = mock("errors") > errors.stub!("empty?").and_return(false) > errors.stub!("full_messages").and_return(["error 1", "error 2"]) > @account.stub!(:errors).and_return(errors) > @user.stub!(:errors).and_return(errors) > > Account.stub!(:new).and_return(@account) > end > > it "should re-render new template" do > post "create" #with no submitted params > response.should render_template("accounts/new") > end > > # Controller code > def create > @account = Account.new(params[:account]) > @user = @account.users.build(params[:user]) > > if verify_recaptcha(@account) && @account.save > redirect_to admin_listings_url > else > render :action => "new" > end > end > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080128/ccfb1a56/attachment-0001.html From jaydonnell at yahoo.com Mon Jan 28 15:01:55 2008 From: jaydonnell at yahoo.com (Jay Donnell) Date: Mon, 28 Jan 2008 12:01:55 -0800 (PST) Subject: [rspec-users] client first, top down, outside in, etc with rails Message-ID: <442012.70398.qm@web56002.mail.re3.yahoo.com> I'm starting a new project and I want to try writing the client first. I.e. I want to write my 'views' first and I would like to mock out all the models in such a way that I can run the site and browse it with the mocked out models. Is it easy to use rspec's mocking for this sort of thing and has anyone done it before? Does anyone know of a tutorial out there for doing something like this? ____________________________________________________________________________________ Looking for last minute shopping deals? Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping From lists at ruby-forum.com Mon Jan 28 15:30:28 2008 From: lists at ruby-forum.com (Chris Olsen) Date: Mon, 28 Jan 2008 21:30:28 +0100 Subject: [rspec-users] Could this controller test be made simpler? In-Reply-To: References: Message-ID: <0fcbca80624d0dcc603804c14d4af3c4@ruby-forum.com> Good point. I guess it was the account.user, account.users.build and all the validation methods that I thought may be unnecessary. -- Posted via http://www.ruby-forum.com/. From tastapod at gmail.com Mon Jan 28 16:22:19 2008 From: tastapod at gmail.com (Dan North) Date: Mon, 28 Jan 2008 21:22:19 +0000 Subject: [rspec-users] OT local version control? In-Reply-To: References: <6bdacb70801271333y5825321dp67936e236030aae5@mail.gmail.com> <124a48790801271442k350d7d5dp232e2600f2f3a878@mail.gmail.com> Message-ID: Yes, bazaar deserves extra props because it's the scm powering a lot of the Ubuntu integration projects. It's open source (I think they pretty much all are) but its development is sponsored by Canonical, which is the company behind Ubuntu. I can't remember why I ditched bazaar - I think it was because it didn't have an eclipse plugin, but I've since discovered that really doesn't matter with a decent scm. On 28/01/2008, Jeremy Burks wrote: > > although i primarily use mercurial, bazaar (http://bazaar-vcs.org/) is > also worth a mention > > On Jan 27, 2008 4:42 PM, Chad Humphries wrote: > > A good thing to note is that you can run many of the distributed scm > tools > > in a 'svn wrapper' mode to ease transition with existing > repositories. That > > made the switch much easier for me. > > > > > > - Chad > > > > > > On Jan 27, 2008 5:00 PM, Dan North wrote: > > > > > > > I can see this descending into a mercurial vs git religious war :) > > > > > > Hi Corey. I'm using mercurial for both home and work use > (supplementing > > some of subversion's shortcomings, mainly around merging). I looked > > (briefly) at git and - less briefly - at darcs. I settled on mercurial > for > > purely non-scientific reasons. People whose opinions I respect are using > it, > > the community seems both accommodating and active, and it's python which > > means it runs anywhere python lives, which is all of my home and work > > environments. > > > > > > Others on this list - including the lovely David - are using git and > > having just as much fun and productivity, so I'm sure it comes down to a > > matter of taste in the end. > > > > > > The big shift, though, is from centralised to distributed source > control. > > This means that any working copy is also a full repository in its own > right, > > so you can do everything you would usually need the server for: > branching, > > tagging, cloning, logging, checking in, rolling back, etc. This page > > (http://tinyurl.com/ykcs25) from the Mercurial wiki gives a pretty good > > overview. The basic model will be the same for any of the distributed > SCMs. > > > > > > My experience so far is: > > > > > > git: insanely fast, made up of many shell scripts, big command set, > does > > /BIG/ repositories (currently used for the entire linux kernel), doesn't > run > > on windows. > > > darcs: also fast, written in haskell so less "hackable". Has best > > cherry-picking support (choosing out-of-sequence changesets). Apparently > > doesn't do so well under biiig repositories. > > > mercurial: also fast (seeing a pattern here?). Seems to scale well. > Has > > (deliberately) svn/cvs-like command set where it can, so easy to adopt. > This > > is where I've ended up. > > > monotone: the first distributed scm I came across (Dave Astels was > using > > it before any of the rest of us had heard of distributed scm). Never > really > > used it much. > > > > > > At the end of the day it will be a personal preference. But whichever > you > > end up with, my prediction is that you'll enjoy it much more than > > subversion. > > > > > > Cheers, > > > Dan > > > > > > > > > > > > > > > > > > > > > On 27/01/2008, Corey Haines wrote: > > > > > > > > > > > > > > > > Hi, all, > > > > > > > > This isn't about rspec, but this list has people whose opinions I > > respect. > > > > > > > > So, I'm looking for a new version control system for my local > > development. I was going to install subversion, but I've heard rumors of > > people using some newer ones. Thoughts? I'd like to be able to run it > either > > locally or on a home server. If I run it off a home server, then it > needs to > > support offline access, so that I can use a cached version when I'm not > on > > my home network. For simplicity's sake, running it locally is probably a > > better solution. > > > > > > > > What do you all use? > > > > > > > > > > > > -Corey > > > > > > > > -- > > > > http://www.coreyhaines.com > > > > The Internet's Premiere source of information about Corey Haines > > > > > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080128/5bf545a6/attachment.html From pergesu at gmail.com Mon Jan 28 17:10:02 2008 From: pergesu at gmail.com (Pat Maddox) Date: Mon, 28 Jan 2008 14:10:02 -0800 Subject: [rspec-users] client first, top down, outside in, etc with rails In-Reply-To: <442012.70398.qm@web56002.mail.re3.yahoo.com> References: <442012.70398.qm@web56002.mail.re3.yahoo.com> Message-ID: <810a540e0801281410y305f38a3k6af6bd80e871e5f7@mail.gmail.com> On Jan 28, 2008 12:01 PM, Jay Donnell wrote: > I'm starting a new project and I want to try writing the client first. I.e. I want to write my 'views' first and I would like to mock out all the models in such a way that I can run the site and browse it with the mocked out models. Is it easy to use rspec's mocking for this sort of thing and has anyone done it before? Does anyone know of a tutorial out there for doing something like this? That's not really what mocks are for. Mocks are a testing tool that help you discover the interactions between objects in your code. I'd say the best way is to develop in small iterations. Write a story that represents a very small, but useful bit of functionality. Implement it, going outside-in, and then when the story is completed you've got something. Then work on the next story. It would probably be a bad idea to implement the site backed by mocks, because you end up going top-down instead of outside-in. There's a big difference. Top-down is implementing a layer for the entire application, then moving to the layer it depends on, all the way down until the app runs. The problem with that is that the feedback loop is very wide, both in a development and business sense. In a development sense, you don't really know that your app works until you type that final character that brings the whole thing together. In a business sense, you end up doing a lot of dev work before you find out if the feature you've built is acceptable (that's where stories come in as well, defining acceptance criteria). It *is* a good idea to sometimes work on the interaction flow before writing a bunch of Rails code, but that should really be done with plain HTML wireframes, no application coding. Pat From jaydonnell at yahoo.com Mon Jan 28 18:24:54 2008 From: jaydonnell at yahoo.com (Jay Donnell) Date: Mon, 28 Jan 2008 15:24:54 -0800 (PST) Subject: [rspec-users] client first, top down, outside in, etc with rails Message-ID: <485474.85808.qm@web56007.mail.re3.yahoo.com> I apologize, I oversimplified for the sake of brevity. We have most of the models written but there are some pieces than aren't and won't be written in the near future. I wanted to mock them out in some form so we can implement those portions of the views. Things like certain features of the sidebar, etc. I don't want to make place holder methods in the actual models because they will be worked on at some point and I want the views to continue working until those pieces are complete. I guess I can use dummy methods in my models that simply return some canned result. Maybe even name it 'my_method_dummy' so I can easily track down the dummy methods. The stubbing syntax is so clean In rspec that I was hoping I could define a bunch of mocks in a single place, environment.rb maybe, and be able to easily glance to see what is still being mocked. We also have different people working on the views vs the models and would like for the views to progress separately from the models. We can do this by spec'ing the views in isolation but it would be nice to see the views integrated into a functioning page as well. > you end up doing a lot of dev work before you find out > if the feature you've built is acceptable (that's where stories come > in as well, defining acceptance criteria). I've used my approach with success using flex and web services. I created web services that returned canned data and developed the UI in flex before developing the back-end. I feel this methods works well and lead to less dev work because we didn't implement models only to find out that we didn't really want it to work that way. We fleshed out the way we wanted the site to work with a functioning front-end before doing the heavy dev work on the back-end. jay > That's not really what mocks are for. Mocks are a testing tool that > help you discover the interactions between objects in your code. ... > It would probably be a bad idea to implement the site backed by mocks, > because you end up going top-down instead of outside-in. There's a > big difference. Top-down is implementing a layer for the entire > application, then moving to the layer it depends on, all the way down > until the app runs. The problem with that is that the feedback loop > is very wide, both in a development and business sense. In a > development sense, you don't really know that your app works until you > type that final character that brings the whole thing together. In a > business sense, you end up doing a lot of dev work before you find out > if the feature you've built is acceptable (that's where stories come > in as well, defining acceptance criteria). ____________________________________________________________________________________ Looking for last minute shopping deals? Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping From nathan.sutton at gmail.com Mon Jan 28 18:26:44 2008 From: nathan.sutton at gmail.com (Nathan Sutton) Date: Mon, 28 Jan 2008 17:26:44 -0600 Subject: [rspec-users] client first, top down, outside in, etc with rails In-Reply-To: <485474.85808.qm@web56007.mail.re3.yahoo.com> References: <485474.85808.qm@web56007.mail.re3.yahoo.com> Message-ID: awesome Nathan Sutton fowlduck at gmail.com rspec 1.1 rspec_on_rails 1.1 rails 2.0.2 On Jan 28, 2008, at 5:24 PM, Jay Donnell wrote: > I apologize, I oversimplified for the sake of brevity. We have most > of the models written but there are some pieces than aren't and > won't be written in the near future. I wanted to mock them out in > some form so we can implement those portions of the views. Things > like certain features of the sidebar, etc. I don't want to make > place holder methods in the actual models because they will be > worked on at some point and I want the views to continue working > until those pieces are complete. > > I guess I can use dummy methods in my models that simply return some > canned result. Maybe even name it 'my_method_dummy' so I can easily > track down the dummy methods. The stubbing syntax is so clean In > rspec that I was hoping I could define a bunch of mocks in a single > place, environment.rb maybe, and be able to easily glance to see > what is still being mocked. We also have different people working on > the views vs the models and would like for the views to progress > separately from the models. We can do this by spec'ing the views in > isolation but it would be nice to see the views integrated into a > functioning page as well. > >> you > end > up > doing > a > lot > of > dev > work > before > you > find > out >> if > the > feature > you've > built > is > acceptable > (that's > where > stories > come >> in > as > well, > defining > acceptance > criteria). > > I've used my approach with success using flex and web services. I > created web services that returned canned data and developed the UI > in flex before developing the back-end. I feel this methods works > well and lead to less dev work because we didn't implement models > only to find out that we didn't really want it to work that way. We > fleshed out the way we wanted the site to work with a functioning > front-end before doing the heavy dev work on the back-end. > > jay > >> That's > not > really > what > mocks > are > for. > Mocks > are > a > testing > tool > that >> help > you > discover > the > interactions > between > objects > in > your > code. > ... >> It > would > probably > be > a > bad > idea > to > implement > the > site > backed > by > mocks, >> because > you > end > up > going > top-down > instead > of > outside-in. > There's > a >> big > difference. > Top-down > is > implementing > a > layer > for > the > entire >> application, > then > moving > to > the > layer > it > depends > on, > all > the > way > down >> until > the > app > runs. > The > problem > with > that > is > that > the > feedback > loop >> is > very > wide, > both > in > a > development > and > business > sense. > In > a >> development > sense, > you > don't > really > know > that > your > app > works > until > you >> type > that > final > character > that > brings > the > whole > thing > together. > In > a >> business > sense, > you > end > up > doing > a > lot > of > dev > work > before > you > find > out >> if > the > feature > you've > built > is > acceptable > (that's > where > stories > come >> in > as > well, > defining > acceptance > criteria). > > > > > > > > ____________________________________________________________________________________ > Looking for last minute shopping deals? > Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From jaydonnell at yahoo.com Mon Jan 28 19:30:05 2008 From: jaydonnell at yahoo.com (Jay Donnell) Date: Mon, 28 Jan 2008 16:30:05 -0800 (PST) Subject: [rspec-users] client first, top down, outside in, etc with rails Message-ID: <317423.11022.qm@web56001.mail.re3.yahoo.com> sorry about that, I have no idea how that happened. It looked fine in yahoo mail before I sent it :/ ____________________________________________________________________________________ Looking for last minute shopping deals? Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping From james.deville at gmail.com Mon Jan 28 20:42:28 2008 From: james.deville at gmail.com (James Deville) Date: Mon, 28 Jan 2008 17:42:28 -0800 Subject: [rspec-users] Textmate RSpec Bundle 'it' snippet In-Reply-To: <1AE4326D-6DB9-4411-BA84-742F3C251407@matt-darby.com> References: <479C35EC.5090409@infopark.de> <1AE4326D-6DB9-4411-BA84-742F3C251407@matt-darby.com> Message-ID: Along these lines, I also think that a empty spec should be failing or at least pending. On Jan 27, 2008, at 6:50 AM, Matt Darby wrote: > Ah, I was unaware of this. Thanks for the pointer. > > On Jan 27, 2008, at 2:42 AM, Francois Wurmus wrote: > >> Hi Matt, >> >> one way of doing this is to leave the block out and just write: >> it "should bla bla" >> >> No 'do', no 'end'. The example will be pending this way. >> >> >> Fran?ois > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users James Deville http://devillecompanies.org james.deville at gmail.com rspec r3172 rspec_on_rails r3172 rails r8331 From will.sargent at gmail.com Mon Jan 28 22:41:55 2008 From: will.sargent at gmail.com (Will Sargent) Date: Mon, 28 Jan 2008 19:41:55 -0800 Subject: [rspec-users] Textmate RSpec Bundle 'it' snippet In-Reply-To: References: <479C35EC.5090409@infopark.de> <1AE4326D-6DB9-4411-BA84-742F3C251407@matt-darby.com> Message-ID: On Jan 28, 2008 5:42 PM, James Deville wrote: > Along these lines, I also think that a empty spec should be failing or > at least pending. +1 From pergesu at gmail.com Tue Jan 29 01:34:50 2008 From: pergesu at gmail.com (Pat Maddox) Date: Mon, 28 Jan 2008 22:34:50 -0800 Subject: [rspec-users] client first, top down, outside in, etc with rails In-Reply-To: <485474.85808.qm@web56007.mail.re3.yahoo.com> References: <485474.85808.qm@web56007.mail.re3.yahoo.com> Message-ID: <810a540e0801282234j403183d7ydacd428ce07d9106@mail.gmail.com> On Jan 28, 2008 3:24 PM, Jay Donnell wrote: > I guess I can use dummy methods in my models that simply return some canned result. Maybe even name it 'my_method_dummy' so I can easily track down the dummy methods. The stubbing syntax is so clean In rspec that I was hoping I could define a bunch of mocks in a single place, environment.rb maybe, and be able to easily glance to see what is still being mocked. We also have different people working on the views vs the models and would like for the views to progress separately from the models. We can do this by spec'ing the views in isolation but it would be nice to see the views integrated into a functioning page as well. hrm...well if you want it all in one place, I'd stick it in some mocked_methods.rb file and require that. You can open the classes you want there User.class_eval do def full_name "Johnny Tsunami" end end That way it's easy to see where they all are. You really don't need to introduce RSpec dependencies into your production code. Just define methods on the class you want, or use OpenStruct and return canned values, or write your own simple stub class. If I was doing this a bunch (I never would, of course :) then I might write a macro that defines these stubs for me and includes some diagnostic info, like a logger.warn("*** dude this is a stubbed method ***") and maybe the caller information as well. Then I could just do User.stub_method(:full_name, "Johnny Tsunami") Going that route would let you collect info about how many times they're called, blah blah blah. Or you could just implement your code :) Pat From edvard at majakari.net Tue Jan 29 08:43:55 2008 From: edvard at majakari.net (Edvard Majakari) Date: Tue, 29 Jan 2008 15:43:55 +0200 Subject: [rspec-users] Textmate RSpec Bundle 'it' snippet In-Reply-To: <810a540e0801262332g48e54ee9m32e116df0136d3b8@mail.gmail.com> References: <810a540e0801262332g48e54ee9m32e116df0136d3b8@mail.gmail.com> Message-ID: > Not if you fill it out...and the BDD way is to write one example at a > time, not a complete spec beforehand. I've done it this way too (being lazy), but is it really good thing? Often I get more insight on how an interface should look like, if I think even superficially what kinds of services an object should offer. Thus I _think_ that writing a TODO-list in spec form (marking all as pending) and starting to pick up those that you want to do. Is this really considered non-BDDish by the authoritatives? If I remember correctly, Dave Astels wrote something along these lines in his book Test Driven Development (reminding that BDD is TDD done right): create a TODO list of small tasks to do, related to roles of the object, and pick something start writing tests. IMO, if you don't think of the features at all and just start to spec completely some single functionality, you risk rewriting that test many times when you add new tests for other methods on the same object, no? -- "One day, when he was naughty, Mr Bunnsy looked over the hedge into Farmer Fred's field and it was full of fresh green lettuces. Mr Bunnsy, however, was not full of lettuces. This did not seem fair." -- Terry Pratchett, Mr. Bunnsy Has An Adventure From zach.dennis at gmail.com Tue Jan 29 08:51:46 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Tue, 29 Jan 2008 08:51:46 -0500 Subject: [rspec-users] client first, top down, outside in, etc with rails In-Reply-To: <810a540e0801282234j403183d7ydacd428ce07d9106@mail.gmail.com> References: <485474.85808.qm@web56007.mail.re3.yahoo.com> <810a540e0801282234j403183d7ydacd428ce07d9106@mail.gmail.com> Message-ID: <85d99afe0801290551t22537186qdfa8f1c9b2d9d89f@mail.gmail.com> Another approach to what Pat mentioned is would be to use a presenter approach. We use presenters to encapsulate view logic and they often hide (or delegate) functionality to one or more models based on the UI component you're focusing on. This route doesn't muck up your models with things that may come in the future. When they do come you can refactor your presenter to delegate to your model, when and if your model is the object that is going to do the job. Right now it's all view implementation anyways and the way we use presenters encapsulate the requirements of the view. Here's some info on how we use presenters: http://spin.atomicobject.com/2008/01/27/the-exceptional-presenter/ The way we use presenter's is different then Jay Fields, so if you think you know what a presenter is and how to use them based on Jay Fields talks or blogs, then you should really read the above as its a different take on presenters with different goals in mind. Zach On Jan 29, 2008 1:34 AM, Pat Maddox wrote: > On Jan 28, 2008 3:24 PM, Jay Donnell wrote: > > I guess I can use dummy methods in my models that simply return some canned result. Maybe even name it 'my_method_dummy' so I can easily track down the dummy methods. The stubbing syntax is so clean In rspec that I was hoping I could define a bunch of mocks in a single place, environment.rb maybe, and be able to easily glance to see what is still being mocked. We also have different people working on the views vs the models and would like for the views to progress separately from the models. We can do this by spec'ing the views in isolation but it would be nice to see the views integrated into a functioning page as well. > > hrm...well if you want it all in one place, I'd stick it in some > mocked_methods.rb file and require that. You can open the classes you > want there > > User.class_eval do > def full_name > "Johnny Tsunami" > end > end > > That way it's easy to see where they all are. You really don't need > to introduce RSpec dependencies into your production code. Just > define methods on the class you want, or use OpenStruct and return > canned values, or write your own simple stub class. If I was doing > this a bunch (I never would, of course :) then I might write a macro > that defines these stubs for me and includes some diagnostic info, > like a logger.warn("*** dude this is a stubbed method ***") and maybe > the caller information as well. Then I could just do > > User.stub_method(:full_name, "Johnny Tsunami") > > Going that route would let you collect info about how many times > they're called, blah blah blah. > > Or you could just implement your code :) > > Pat > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Zach Dennis http://www.continuousthinking.com From pergesu at gmail.com Tue Jan 29 10:13:34 2008 From: pergesu at gmail.com (Pat Maddox) Date: Tue, 29 Jan 2008 07:13:34 -0800 Subject: [rspec-users] Textmate RSpec Bundle 'it' snippet In-Reply-To: References: <810a540e0801262332g48e54ee9m32e116df0136d3b8@mail.gmail.com> Message-ID: <810a540e0801290713r7111484u2fe061f88d03cbf6@mail.gmail.com> On Jan 29, 2008 5:43 AM, Edvard Majakari wrote: > > Not if you fill it out...and the BDD way is to write one example at a > > time, not a complete spec beforehand. > > I've done it this way too (being lazy), but is it really good thing? > Often I get more insight on how an interface should look like, > if I think even superficially what kinds of services an object should > offer. Thus I _think_ that writing a TODO-list in spec form > (marking all as pending) and starting to pick up those that you want > to do. Is this really considered non-BDDish by the authoritatives? When I think of extra tests that I need to write, I jot them down on a card. When I work on code, I work on one thing at a time. There are no rules though, so if writing out a bunch of specs before you do anything works for you, cool. > IMO, if you don't think of the features at all and just start to spec > completely some single functionality, you risk rewriting that test > many times > when you add new tests for other methods on the same object, no? That has not been my experience. If you have to rewrite the same test over and over, it's probably testing too much. Pat From rick.denatale at gmail.com Tue Jan 29 17:03:06 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Tue, 29 Jan 2008 17:03:06 -0500 Subject: [rspec-users] I thought the RSPec community might be interested Message-ID: in my latest blog posting :http://talklikeaduck.denhaven2.com/articles/2008/01/29/why-i-dont-mind-using-rspec-in-fact-ive-come-to-love-it -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From dchelimsky at gmail.com Tue Jan 29 17:33:05 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 29 Jan 2008 16:33:05 -0600 Subject: [rspec-users] I thought the RSPec community might be interested In-Reply-To: References: Message-ID: <57c63afe0801291433l2a19d0d8p639def11e999e734@mail.gmail.com> On Jan 29, 2008 4:03 PM, Rick DeNatale wrote: > in my latest blog posting > :http://talklikeaduck.denhaven2.com/articles/2008/01/29/why-i-dont-mind-using-rspec-in-fact-ive-come-to-love-it Nice. And thanks! David > > -- > Rick DeNatale > > My blog on Ruby > http://talklikeaduck.denhaven2.com/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From coreyhaines at gmail.com Tue Jan 29 18:26:43 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Tue, 29 Jan 2008 18:26:43 -0500 Subject: [rspec-users] I thought the RSPec community might be interested In-Reply-To: References: Message-ID: <6bdacb70801291526o40cb2d9dn299029386be538a8@mail.gmail.com> Very nice post, Rick. I, too, would like to hear what people mean when they say it is too "magical." I kind of like the magic. :) -Corey On Jan 29, 2008 5:03 PM, Rick DeNatale wrote: > in my latest blog posting > : > http://talklikeaduck.denhaven2.com/articles/2008/01/29/why-i-dont-mind-using-rspec-in-fact-ive-come-to-love-it > > -- > Rick DeNatale > > My blog on Ruby > http://talklikeaduck.denhaven2.com/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080129/c35fedd6/attachment.html From tastapod at gmail.com Tue Jan 29 18:35:14 2008 From: tastapod at gmail.com (Dan North) Date: Tue, 29 Jan 2008 23:35:14 +0000 Subject: [rspec-users] Textmate RSpec Bundle 'it' snippet In-Reply-To: References: <810a540e0801262332g48e54ee9m32e116df0136d3b8@mail.gmail.com> Message-ID: Warning - bit of a ramble below! On 29/01/2008, Edvard Majakari wrote: > > > Not if you fill it out...and the BDD way is to write one example at a > > time, not a complete spec beforehand. > > I've done it this way too (being lazy), but is it really good thing? > Often I get more insight on how an interface should look like, > if I think even superficially what kinds of services an object should > offer. Thus I _think_ that writing a TODO-list in spec form > (marking all as pending) and starting to pick up those that you want > to do. Is this really considered non-BDDish by the authoritatives? > > If I remember correctly, Dave Astels wrote something along these lines > in his book Test Driven Development > (reminding that BDD is TDD done right): create a TODO list of small > tasks to do, related to roles of the object, and pick something > start writing tests. You make some good observations. The advice to "pick something and start writing tests" was one of the alarm bells early on that told me TDD was about more than testing. I write software to solve a problem - especially commercial software - and there is usually a stakeholder involved who wants to see tangible progress. With respect, BDD is more than TDD-done-right. "Full-scale" BDD (starting at the outside with stories and scenarios and working inwards to the code) grew out of trying to identify "the next most important thing" from the stakeholder's perspective, rather than whatever looked most interesting to me as a programmer. If you only have the close-up view of TDD - or example-level BDD (which unfortunately is what most people consider BDD to be) - it's difficult to see what the most valuable behaviour would be, and therefore the next most important thing to implement, so you end up choosing "somewhere interesting" (i.e. somewhere arbitrary in business terms). Without business-level acceptance criteria in the form of scenarios you don't know what "done" looks like, so it's very tempting to capture a whole bunch of things that occur to you in case one of them is the way forward. That's when you find yourself writing a bunch of "todo" or pending examples. If you start with a narrow, end-to-end piece of functionality and drill into it from the outside, right through until you have it working, you will find that at each layer of abstraction you will have a pretty focused subset of behaviour to implement to get the job done. IMO, if you don't think of the features at all and just start to spec > completely some single functionality, you risk rewriting that test > many times > when you add new tests for other methods on the same object, no? You certainly risk revisiting something many times - often assumptions you made in speccing out the object without any outside-in forces to identify its actual value. If I'm honest, I find myself doing this more often than I would like, especially when I'm reworking legacy code (which is a lot of my time recently). I usually take it as an indication that I haven't broadened my scope enough - I'm not "outside" enough to have a reasonable perspective. I stop, take a couple of steps back (usually reverting all my recent changes!) and reassess exactly who is the client of the code I've been tinkering with. I can relate to your point about writing a few examples to help you understand how an interface might work. Massaging code like that is a great way to explore an API. The important thing is to recognise it as just that - an exploratory exercise. Then you throw away any code you created in the process and start over, outside-in, armed with the knowledge that came out of the spike. Perhaps I ought to write this up - it's a theme that comes up quite often. Thanks for listening, Dan -- > "One day, when he was naughty, Mr Bunnsy looked over the hedge into > Farmer Fred's field and it was full of fresh green lettuces. Mr > Bunnsy, however, was not full of lettuces. This did not seem fair." > -- Terry Pratchett, Mr. Bunnsy Has An Adventure > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080129/473b39f1/attachment-0001.html From omen.king at gmail.com Tue Jan 29 19:48:50 2008 From: omen.king at gmail.com (Andrew WC Brown) Date: Tue, 29 Jan 2008 19:48:50 -0500 Subject: [rspec-users] catching errors, rspec basics Message-ID: Trying to spec the following but don't know if I'm using the right matcher. How do I spec? Plz, sugar on tops. Audience.stats - should have a stats of 80 when passed a flux of 10 - should return an error when passed a string (ERROR - 1) 1) TypeError in 'Audience.stats should return an error when passed a string' String can't be coerced into Fixnum ./audience.rb:11:in `*' ./audience.rb:11:in `stats=' ./audience_spec.rb:29: Finished in 0.006333 seconds 2 examples, 1 failure monsterbox:spec andrew_wc_brown$ class Audience attr_accessor :stats def initialize(name = nil,value = nil) @name ||= 'all' @value ||= value end def stats=(flux) @stats = @value * flux / 0.025 end def market_share "The Market share is for #{@name} at a high of #{@stats}" end end describe "Audience.stats" do before :all do @audience = Audience.new(nil,20) end it "should have a stats of 80 when passed a flux of 10" do @audience.stats = 10 @audience.stats.should == 8000 end it "should return an error when passed a string" do @audience.stats = 'Market Goblin' @audience.stats.should raise_error end end -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080129/2df90486/attachment.html From smingins at elctech.com Tue Jan 29 19:49:12 2008 From: smingins at elctech.com (Shane Mingins) Date: Wed, 30 Jan 2008 13:49:12 +1300 Subject: [rspec-users] catching errors, rspec basics In-Reply-To: References: Message-ID: <1C59F502-9D60-4768-9875-42050B2E0B39@elctech.com> Are you looking for something like this lambda { @audience.stats = 'Market Goblin' }.should raise_error On 30/01/2008, at 1:48 PM, Andrew WC Brown wrote: > Trying to spec the following but don't know if I'm using the right > matcher. > How do I spec? Plz, sugar on tops. > > Audience.stats > - should have a stats of 80 when passed a flux of 10 > - should return an error when passed a string (ERROR - 1) > > 1) > TypeError in 'Audience.stats should return an error when passed a > string' > String can't be coerced into Fixnum > ./audience.rb:11:in `*' > ./audience.rb:11:in `stats=' > ./audience_spec.rb:29: > > Finished in 0.006333 seconds > > 2 examples, 1 failure > monsterbox:spec andrew_wc_brown$ > > > > class Audience > > attr_accessor :stats > > def initialize(name = nil,value = nil) > @name ||= 'all' > @value ||= value > end > > def stats=(flux) > @stats = @value * flux / 0.025 > end > > def market_share > "The Market share is for #{@name} at a high of #{@stats}" > end > > end > > describe "Audience.stats" do > > before :all do > @audience = Audience.new(nil,20) > end > > it "should have a stats of 80 when passed a flux of 10" do > @audience.stats = 10 > @audience.stats.should == 8000 > end > > it "should return an error when passed a string" do > @audience.stats = 'Market Goblin' > @audience.stats.should raise_error > end > end > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080130/28c49eab/attachment.html From omen.king at gmail.com Tue Jan 29 19:55:02 2008 From: omen.king at gmail.com (Andrew WC Brown) Date: Tue, 29 Jan 2008 19:55:02 -0500 Subject: [rspec-users] catching errors, rspec basics In-Reply-To: <1C59F502-9D60-4768-9875-42050B2E0B39@elctech.com> References: <1C59F502-9D60-4768-9875-42050B2E0B39@elctech.com> Message-ID: try it, does the same thing ='( On Jan 29, 2008 7:49 PM, Shane Mingins wrote: > Are you looking for something like this > lambda { @audience.stats = 'Market Goblin' }.should raise_error > > > On 30/01/2008, at 1:48 PM, Andrew WC Brown wrote: > > Trying to spec the following but don't know if I'm using the right > matcher. > How do I spec? Plz, sugar on tops. > > Audience.stats > - should have a stats of 80 when passed a flux of 10 > - should return an error when passed a string (ERROR - 1) > > 1) > TypeError in 'Audience.stats should return an error when passed a string' > String can't be coerced into Fixnum > ./audience.rb:11:in `*' > ./audience.rb:11:in `stats=' > ./audience_spec.rb:29: > > Finished in 0.006333 seconds > > 2 examples, 1 failure > monsterbox:spec andrew_wc_brown$ > > > > class Audience > > attr_accessor :stats > > def initialize(name = nil,value = nil) > @name ||= 'all' > @value ||= value > end > > def stats=(flux) > @stats = @value * flux / 0.025 > end > > def market_share > "The Market share is for #{@name} at a high of #{@stats}" > end > > end > > describe "Audience.stats" do > > before :all do > @audience = Audience.new(nil,20) > end > > it "should have a stats of 80 when passed a flux of 10" do > @audience.stats = 10 > @audience.stats.should == 8000 > end > > it "should return an error when passed a string" do > @audience.stats = 'Market Goblin' > @audience.stats.should raise_error > end > end > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080129/313a1992/attachment.html From smingins at elctech.com Tue Jan 29 19:59:04 2008 From: smingins at elctech.com (Shane Mingins) Date: Wed, 30 Jan 2008 13:59:04 +1300 Subject: [rspec-users] catching errors, rspec basics In-Reply-To: References: <1C59F502-9D60-4768-9875-42050B2E0B39@elctech.com> Message-ID: Hmmmm I just ran this and 2 examples, 0 failures class Audience attr_accessor :stats def initialize(name = nil,value = nil) @name ||= 'all' @value ||= value end def stats=(flux) @stats = @value * flux / 0.025 end def market_share "The Market share is for #{@name} at a high of #{@stats}" end end describe "Audience.stats" do before :all do @audience = Audience.new(nil,20) end it "should have a stats of 80 when passed a flux of 10" do @audience.stats = 10 @audience.stats.should == 8000 end it "should return an error when passed a string" do lambda {@audience.stats = 'Market Goblin'}.should raise_error end end On 30/01/2008, at 1:55 PM, Andrew WC Brown wrote: > try it, does the same thing ='( > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080130/bce87bd0/attachment-0001.html From dchelimsky at gmail.com Tue Jan 29 20:03:21 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 29 Jan 2008 19:03:21 -0600 Subject: [rspec-users] catching errors, rspec basics In-Reply-To: References: <1C59F502-9D60-4768-9875-42050B2E0B39@elctech.com> Message-ID: <57c63afe0801291703w6a928171k7213e5aa88cc719a@mail.gmail.com> On Jan 29, 2008 6:55 PM, Andrew WC Brown wrote: > try it, does the same thing ='( Shouldn't be the exact same thing. What's the whole error? Also - what version of rspec? If trunk, do you have the latest (3268)? > > > > On Jan 29, 2008 7:49 PM, Shane Mingins wrote: > > > > Are you looking for something like this > > > > > > lambda { @audience.stats = 'Market Goblin' }.should raise_error > > > > > > > > > > > > > > > > > > On 30/01/2008, at 1:48 PM, Andrew WC Brown wrote: > > > > > > > > > > > > > > Trying to spec the following but don't know if I'm using the right > matcher. > > How do I spec? Plz, sugar on tops. > > > > > > Audience.stats > > - should have a stats of 80 when passed a flux of 10 > > - should return an error when passed a string (ERROR - 1) > > > > > > 1) > > TypeError in 'Audience.stats should return an error when passed a string' > > String can't be coerced into Fixnum > > ./audience.rb:11:in `*' > > ./audience.rb:11:in `stats=' > > ./audience_spec.rb:29: > > > > > > Finished in 0.006333 seconds > > > > > > 2 examples, 1 failure > > monsterbox:spec andrew_wc_brown$ > > > > > > > > > > > > > > class Audience > > > > attr_accessor :stats > > > > def initialize(name = nil,value = nil) > > @name ||= 'all' > > @value ||= value > > end > > > > def stats=(flux) > > @stats = @value * flux / 0.025 > > end > > > > > > def market_share > > "The Market share is for #{@name} at a high of #{@stats}" > > end > > > > end > > > > > > describe "Audience.stats" do > > > > before :all do > > @audience = Audience.new(nil,20) > > end > > > > it "should have a stats of 80 when passed a flux of 10" do > > @audience.stats = 10 > > @audience.stats.should == 8000 > > end > > > > it "should return an error when passed a string" do > > @audience.stats = 'Market Goblin' > > @audience.stats.should raise_error > > end > > end > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Tue Jan 29 20:23:02 2008 From: lists at ruby-forum.com (Chris Olsen) Date: Wed, 30 Jan 2008 02:23:02 +0100 Subject: [rspec-users] Stubbing controller methods vs model methods Message-ID: <1da51143231791f2aca8eccde47e83fa@ruby-forum.com> I had an error that I couldn't figure out, then when writing up a question for the forum I figured it out. The thing is I don't understand why the change that was made works and why what existed before didn't. Here is the initial post when I had the error: ---------------------------------- In the controllers/application.rb file I have a method that finds the account based on the subdomain. This method is stubbed out for the tests. def find_account @account = Account.for(request.host.split(".").first) #TODO: find out why request.subdomains returns [] end In my controller tests I would like to stub this method. So I created a method within the authenticated_test_helper.rb (I am using RESTful Authentication plugin) def login_with_account(account) # <=== # User current_user = mock_model(User) controller.stub!(:current_user).and_return(current_user) # User's account account.stub!(:users).and_return([current_user]) current_user.stub!(:account).and_return(account) # Application methods controller.stub!(:logged_in?).and_return(true) controller.stub!(:authorized?).and_return(true) controller.stub!(:find_account).and_return(account) # <=== find_account stubbed out end Now in the before methods of my controller specs I have: before :each do account = mock_model(Account, :subdomain => "test2") login_with_account(account) # <=== end The place that keeps throwing up is the controller's index method def index @users = @account.users end where the error message is: NoMethodError in 'Admin::UsersController GET, test2.localhost/users should validate the user' You have a nil object when you didn't expect it! The error occurred while evaluating nil.users *** The fix I found that if I stubbed out the Account.for method instead of the controller helper method it then worked. +>> Account.stub!(:for).and_return(account) ->> controller.stub!(:find_account).and_return(account) # removed As a reminder here is the find_account method def find_account @account = Account.for(request.host.split(".").first) end Am I not stubbing the controller methods properly? That method is in the ApplicationController so it would be inherited and therefore accessible through the "controller" reference right? Thanks for the help. BTW has any heard about the Pragmatic Rspec book? I swear I check the pragprog.com site everyday for that book :) -- Posted via http://www.ruby-forum.com/. From davidj503 at gmail.com Tue Jan 29 20:31:33 2008 From: davidj503 at gmail.com (David James) Date: Tue, 29 Jan 2008 20:31:33 -0500 Subject: [rspec-users] helper methods starting with should In-Reply-To: <57c63afe0711180759l6348dd6eh375b328f4f6d9657@mail.gmail.com> References: <57c63afe0711180759l6348dd6eh375b328f4f6d9657@mail.gmail.com> Message-ID: <59b5d4330801291731u54021dbfo31b64db79c1e711a@mail.gmail.com> -1* I upgraded a Rails project from rspec 0.9 to 1.1.2 -- and this change caused me some pain. Luckily, I figured it out and confirmed it here on the list before things got too bad. :) * That said, I have to admit that I'm not super-pleased about my helper methods that start with should_ -- they probably should be rewritten in some other way. Perhaps as custom matchers. So maybe I will abstain from this vote after all. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080129/25842037/attachment.html From omen.king at gmail.com Tue Jan 29 20:47:41 2008 From: omen.king at gmail.com (Andrew WC Brown) Date: Tue, 29 Jan 2008 20:47:41 -0500 Subject: [rspec-users] catching errors, rspec basics In-Reply-To: References: <1C59F502-9D60-4768-9875-42050B2E0B39@elctech.com> Message-ID: ohhhhh, I left in: it "should return an error when passed a string" do @audience.stats = 'Market Goblin' lambda {@audience.stats = 'Market Goblin'}.should raise_error end when yours is: it "should return an error when passed a string" do lambda {@audience.stats = 'Market Goblin'}.should raise_error end I've seen lambda before but not sure what it does. On Jan 29, 2008 7:59 PM, Shane Mingins wrote: > Hmmmm > I just ran this and 2 examples, 0 failures > > class Audience > > attr_accessor :stats > > def initialize(name = nil,value = nil) > @name ||= 'all' > @value ||= value > end > > def stats=(flux) > @stats = @value * flux / 0.025 > end > > def market_share > "The Market share is for #{@name} at a high of #{@stats}" > end > > end > > > describe "Audience.stats" do > > before :all do > @audience = Audience.new(nil,20) > end > > it "should have a stats of 80 when passed a flux of 10" do > @audience.stats = 10 > @audience.stats.should == 8000 > end > > it "should return an error when passed a string" do > lambda {@audience.stats = 'Market Goblin'}.should raise_error > end > > end > On 30/01/2008, at 1:55 PM, Andrew WC Brown wrote: > > try it, does the same thing ='( > > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080129/81dab006/attachment.html From kevwil at gmail.com Tue Jan 29 21:24:55 2008 From: kevwil at gmail.com (Kevin Williams) Date: Tue, 29 Jan 2008 19:24:55 -0700 Subject: [rspec-users] I thought the RSPec community might be interested In-Reply-To: <6bdacb70801291526o40cb2d9dn299029386be538a8@mail.gmail.com> References: <6bdacb70801291526o40cb2d9dn299029386be538a8@mail.gmail.com> Message-ID: <683a886f0801291824o2e208167s60d919235471e650@mail.gmail.com> I love rspec. I wish the magic extended to ruby 1.9 so I could start looking at 1.9 with spec support. I'd rather not learn bacon + mocha just to work with 1.9, only to port back to rspec once 1.9 support is done. Just my $0.02 though. On Jan 29, 2008 4:26 PM, Corey Haines wrote: > Very nice post, Rick. > > I, too, would like to hear what people mean when they say it is too > "magical." I kind of like the magic. :) > > -Corey > > > > On Jan 29, 2008 5:03 PM, Rick DeNatale wrote: > > > in my latest blog posting > > > :http://talklikeaduck.denhaven2.com/articles/2008/01/29/why-i-dont-mind-using-rspec-in-fact-ive-come-to-love-it > > > > -- > > Rick DeNatale > > > > My blog on Ruby > > http://talklikeaduck.denhaven2.com/ > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > -- > http://www.coreyhaines.com > The Internet's Premiere source of information about Corey Haines > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Cheers, Kevin Williams http://www.bantamtech.com/ http://www.almostserio.us/ http://kevwil.com/ From ben at benmabey.com Tue Jan 29 22:58:30 2008 From: ben at benmabey.com (Ben Mabey) Date: Tue, 29 Jan 2008 20:58:30 -0700 Subject: [rspec-users] catching errors, rspec basics In-Reply-To: References: <1C59F502-9D60-4768-9875-42050B2E0B39@elctech.com> Message-ID: <479FF5E6.8050302@benmabey.com> Andrew WC Brown wrote: > ohhhhh, I left in: > > it "should return an error when passed a string" do > @audience.stats = 'Market Goblin' > lambda {@audience.stats = 'Market Goblin'}.should raise_error > end > > when yours is: > > it "should return an error when passed a string" do > lambda {@audience.stats = 'Market Goblin'}.should raise_error > end > > I've seen lambda before but not sure what it does. A lambda in ruby is like a block or a Proc. There are some differences between them, but for this simple use you can just think of it as a block of code that will be passed to the 'raise_error' matcher that then runs that block of code checking to see if an Exception is raised when it is ran. You can also pass in the specific exception type to be more specific. As a personal preference I like to alias lambda to 'running' in my spec_helper.rb... I think this reads a lot better: running {@audience.stats = 'Market Goblin'}.should raise_error For more on lambdas refer to the pickaxe. If you want more detailed information of the subtle differences between them, Procs, blocks, and methods check this out: http://innig.net/software/ruby/closures-in-ruby.rb -Ben From omen.king at gmail.com Tue Jan 29 23:12:52 2008 From: omen.king at gmail.com (Andrew WC Brown) Date: Tue, 29 Jan 2008 23:12:52 -0500 Subject: [rspec-users] catching errors, rspec basics In-Reply-To: <479FF5E6.8050302@benmabey.com> References: <1C59F502-9D60-4768-9875-42050B2E0B39@elctech.com> <479FF5E6.8050302@benmabey.com> Message-ID: So if I understand correctly, The following didn't raise an error: @audience.stats = 'Market Goblin' @audience.stats.should raise_error because audience.stats didn't return an error. Where as lambda will return an error. On Jan 29, 2008 10:58 PM, Ben Mabey wrote: > Andrew WC Brown wrote: > > ohhhhh, I left in: > > > > it "should return an error when passed a string" do > > @audience.stats = 'Market Goblin' > > lambda {@audience.stats = 'Market Goblin'}.should raise_error > > end > > > > when yours is: > > > > it "should return an error when passed a string" do > > lambda {@audience.stats = 'Market Goblin'}.should raise_error > > end > > > > I've seen lambda before but not sure what it does. > > A lambda in ruby is like a block or a Proc. There are some differences > between them, but for this simple use you can just think of it as a > block of code that will be passed to the 'raise_error' matcher that then > runs that block of code checking to see if an Exception is raised when > it is ran. You can also pass in the specific exception type to be more > specific. > > As a personal preference I like to alias lambda to 'running' in my > spec_helper.rb... I think this reads a lot better: > running {@audience.stats = 'Market Goblin'}.should raise_error > > For more on lambdas refer to the pickaxe. If you want more detailed > information of the subtle differences between them, Procs, blocks, and > methods check this out: > http://innig.net/software/ruby/closures-in-ruby.rb > > -Ben > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080129/7fcdaa98/attachment-0001.html From ben at benmabey.com Tue Jan 29 23:28:15 2008 From: ben at benmabey.com (Ben Mabey) Date: Tue, 29 Jan 2008 21:28:15 -0700 Subject: [rspec-users] Stubbing controller methods vs model methods In-Reply-To: <1da51143231791f2aca8eccde47e83fa@ruby-forum.com> References: <1da51143231791f2aca8eccde47e83fa@ruby-forum.com> Message-ID: <479FFCDF.2060106@benmabey.com> Chris Olsen wrote: > I had an error that I couldn't figure out, then when writing up a > question for the forum I figured it out. The thing is I don't > understand why the change that was made works and why what existed > before didn't. > > Here is the initial post when I had the error: > ---------------------------------- > In the controllers/application.rb file > > I have a method that finds the account based on the subdomain. This > method is stubbed out for the tests. > def find_account > @account = Account.for(request.host.split(".").first) #TODO: find > out why request.subdomains returns [] > end > > In my controller tests I would like to stub this method. So I created a > method within the authenticated_test_helper.rb (I am using RESTful > Authentication plugin) > > def login_with_account(account) # <=== > # User > current_user = mock_model(User) > controller.stub!(:current_user).and_return(current_user) > > # User's account > account.stub!(:users).and_return([current_user]) > current_user.stub!(:account).and_return(account) > > # Application methods > controller.stub!(:logged_in?).and_return(true) > controller.stub!(:authorized?).and_return(true) > controller.stub!(:find_account).and_return(account) # <=== > find_account stubbed out > end > > Now in the before methods of my controller specs I have: > before :each do > account = mock_model(Account, :subdomain => "test2") > login_with_account(account) # <=== > end > > The place that keeps throwing up is the controller's index method > > def index > @users = @account.users > end > > where the error message is: > NoMethodError in 'Admin::UsersController GET, test2.localhost/users > should validate the user' > You have a nil object when you didn't expect it! > The error occurred while evaluating nil.users > > *** The fix > I found that if I stubbed out the Account.for method instead of the > controller helper method it then worked. > +>> Account.stub!(:for).and_return(account) > ->> controller.stub!(:find_account).and_return(account) # removed > > As a reminder here is the find_account method > def find_account > @account = Account.for(request.host.split(".").first) > end > > Am I not stubbing the controller methods properly? That method is in > the ApplicationController so it would be inherited and therefore > accessible through the "controller" reference right? > > Thanks for the help. > > BTW has any heard about the Pragmatic Rspec book? I swear I check the > pragprog.com site everyday for that book :) > Hey Chris, The problem is that you stubbed a method with side effects. Namely, your find_account method not only returned the found account but it set the instance variable @account. I'm guessing that this is a filter you had before your index action. So in your first attempt when you stubbed find_account you had it return the account but because it was stubbed the actual instance variable that the action relies on was never set! The way you did it the second time is correct because that allows your find_account method to actually run and set the @account variable. This is actually the much preferred way because you are stubbing out calls on external objects and not internal methods on the class you are specing. You can then follow up with an expectation using mocking to assure that the correct call to Account is being made in find_account. In a previous thread we were talking about the evils of stubbing/mocking methods on the object that your testing. That said I think most every rspec_on_railer stubs out the current_user methods on there controller when they are testing. As David pointed out though, that doesn't make it right and you should violate that rule consciously knowing that you are doing something wrong. I think the problem that you faced here is a great example of why stubbing an objects own method calls can be dangerous and is a TDD no no. If you have a lot of logic like this in your controller and to make it easier to test you could move all of the authentication code into it's own object. In the same thread Zach Dennis actually posted[1] some of the code they are using that has the authentication logic in another object that allows more easier and better testing. The more and more I think about this the more it makes sense, the controller really shouldn't be burdened with all of that logic... Hope that helps, Ben 1. http://www.mail-archive.com/rspec-users at rubyforge.org/msg03128.html From ben at benmabey.com Tue Jan 29 23:41:18 2008 From: ben at benmabey.com (Ben Mabey) Date: Tue, 29 Jan 2008 21:41:18 -0700 Subject: [rspec-users] catching errors, rspec basics In-Reply-To: References: <1C59F502-9D60-4768-9875-42050B2E0B39@elctech.com> <479FF5E6.8050302@benmabey.com> Message-ID: <479FFFEE.2000409@benmabey.com> Sematics.. the method is never returning an error, it raises one. So you can't say @audience.stats="dsfds" and expect to see an exception returned right? Since an exception is being raised you have to think of another way of testing it aside from checking it's return value... So you could do something like: an_error_was_raised = false begin @audience.stats = 'Market Goblin' rescue an_error_was_raised = true end an_error_was_raised.should == true I am not suggesting you do this. This is just to illustrate how you would going about testing to see if an error was raised. The raise_error matcher is slightly more complicated in order to be able to ensure certain errors are raised but this is the general idea. So the lambda does not return an error but the lambda is passed into the matcher so it can perform a similar operation as the code above illustrates. I hope that clarified things a bit. Here is another example for good measure with a lambda involved.. you can then see how a lambda how be useful in this situation: an_error_was_raised = false my_code = lambda { @audience.stats = 'Market Goblin' } begin my_code.call rescue an_error_was_raised = true end an_error_was_raised.should == true Better? -Ben Andrew WC Brown wrote: > So if I understand correctly, > > The following didn't raise an error: > > @audience.stats = 'Market Goblin' > @audience.stats.should raise_error > > because audience.stats didn't return an error. > > Where as lambda will return an error. > > On Jan 29, 2008 10:58 PM, Ben Mabey > wrote: > > Andrew WC Brown wrote: > > ohhhhh, I left in: > > > > it "should return an error when passed a string" do > > @audience.stats = 'Market Goblin' > > lambda {@audience.stats = 'Market Goblin'}.should raise_error > > end > > > > when yours is: > > > > it "should return an error when passed a string" do > > lambda {@audience.stats = 'Market Goblin'}.should raise_error > > end > > > > I've seen lambda before but not sure what it does. > > A lambda in ruby is like a block or a Proc. There are some > differences > between them, but for this simple use you can just think of it as a > block of code that will be passed to the 'raise_error' matcher > that then > runs that block of code checking to see if an Exception is raised when > it is ran. You can also pass in the specific exception type to be > more > specific. > > As a personal preference I like to alias lambda to 'running' in my > spec_helper.rb... I think this reads a lot better: > running {@audience.stats = 'Market Goblin'}.should raise_error > > For more on lambdas refer to the pickaxe. If you want more detailed > information of the subtle differences between them, Procs, blocks, and > methods check this out: > http://innig.net/software/ruby/closures-in-ruby.rb > > -Ben > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > > ------------------------------------------------------------------------ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From byrnejb at harte-lyne.ca Tue Jan 29 23:48:48 2008 From: byrnejb at harte-lyne.ca (James B. Byrne) Date: Tue, 29 Jan 2008 23:48:48 -0500 (EST) Subject: [rspec-users] (no subject) Message-ID: <60708.65.92.50.114.1201668528.squirrel@webmail.harte-lyne.ca> Message-ID: On: Tue, 29 Jan 2008 20:47:41 -0500, "Andrew WC Brown" wrote: > I've seen lambda before but not sure what it does. A lambda is a fancy name for an anonymous or unbound function. Its significance comes from the fact that it is completely stateless, producing no side effects to its returned result. -- *** E-Mail is NOT a SECURE channel *** James B. Byrne mailto:ByrneJB at Harte-Lyne.ca Harte & Lyne Limited http://www.harte-lyne.ca 9 Brockley Drive vox: +1 905 561 1241 Hamilton, Ontario fax: +1 905 561 0757 Canada L8E 3C3 From pergesu at gmail.com Tue Jan 29 23:55:10 2008 From: pergesu at gmail.com (Pat Maddox) Date: Tue, 29 Jan 2008 20:55:10 -0800 Subject: [rspec-users] (no subject) In-Reply-To: <60708.65.92.50.114.1201668528.squirrel@webmail.harte-lyne.ca> References: <60708.65.92.50.114.1201668528.squirrel@webmail.harte-lyne.ca> Message-ID: <810a540e0801292055n1f1f9d4am682e04f9f3a92010@mail.gmail.com> On Jan 29, 2008 8:48 PM, James B. Byrne wrote: > Message-ID: > > On: Tue, 29 Jan 2008 20:47:41 -0500, "Andrew WC Brown" > wrote: > > > I've seen lambda before but not sure what it does. > > A lambda is a fancy name for an anonymous or unbound function. Its > significance comes from the fact that it is completely stateless, producing no > side effects to its returned result. I don't know about that... irb(main):001:0> a = [1,2,3] => [1, 2, 3] irb(main):002:0> def foo(array) irb(main):003:1> lambda { array.clear } irb(main):004:1> end => nil irb(main):005:0> fun = foo a => # irb(main):006:0> fun.call => [] irb(main):007:0> a => [] From omen.king at gmail.com Wed Jan 30 00:37:17 2008 From: omen.king at gmail.com (Andrew WC Brown) Date: Wed, 30 Jan 2008 00:37:17 -0500 Subject: [rspec-users] catching errors, rspec basics In-Reply-To: <57c63afe0801291703w6a928171k7213e5aa88cc719a@mail.gmail.com> References: <1C59F502-9D60-4768-9875-42050B2E0B39@elctech.com> <57c63afe0801291703w6a928171k7213e5aa88cc719a@mail.gmail.com> Message-ID: lawl, David has been out of the loop a few e-mails.I left in an extra line. Thanks for the expansion Ben, adds much more clarity, On Jan 29, 2008 8:03 PM, David Chelimsky wrote: > On Jan 29, 2008 6:55 PM, Andrew WC Brown wrote: > > try it, does the same thing ='( > > Shouldn't be the exact same thing. What's the whole error? > > Also - what version of rspec? If trunk, do you have the latest (3268)? > > > > > > > > > On Jan 29, 2008 7:49 PM, Shane Mingins wrote: > > > > > > Are you looking for something like this > > > > > > > > > lambda { @audience.stats = 'Market Goblin' }.should raise_error > > > > > > > > > > > > > > > > > > > > > > > > > > > On 30/01/2008, at 1:48 PM, Andrew WC Brown wrote: > > > > > > > > > > > > > > > > > > > > > Trying to spec the following but don't know if I'm using the right > > matcher. > > > How do I spec? Plz, sugar on tops. > > > > > > > > > Audience.stats > > > - should have a stats of 80 when passed a flux of 10 > > > - should return an error when passed a string (ERROR - 1) > > > > > > > > > 1) > > > TypeError in 'Audience.stats should return an error when passed a > string' > > > String can't be coerced into Fixnum > > > ./audience.rb:11:in `*' > > > ./audience.rb:11:in `stats=' > > > ./audience_spec.rb:29: > > > > > > > > > Finished in 0.006333 seconds > > > > > > > > > 2 examples, 1 failure > > > monsterbox:spec andrew_wc_brown$ > > > > > > > > > > > > > > > > > > > > > class Audience > > > > > > attr_accessor :stats > > > > > > def initialize(name = nil,value = nil) > > > @name ||= 'all' > > > @value ||= value > > > end > > > > > > def stats=(flux) > > > @stats = @value * flux / 0.025 > > > end > > > > > > > > > def market_share > > > "The Market share is for #{@name} at a high of #{@stats}" > > > end > > > > > > end > > > > > > > > > describe "Audience.stats" do > > > > > > before :all do > > > @audience = Audience.new(nil,20) > > > end > > > > > > it "should have a stats of 80 when passed a flux of 10" do > > > @audience.stats = 10 > > > @audience.stats.should == 8000 > > > end > > > > > > it "should return an error when passed a string" do > > > @audience.stats = 'Market Goblin' > > > @audience.stats.should raise_error > > > end > > > end > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080130/6a13f4c2/attachment.html From lists at ruby-forum.com Wed Jan 30 01:13:50 2008 From: lists at ruby-forum.com (Chris Olsen) Date: Wed, 30 Jan 2008 07:13:50 +0100 Subject: [rspec-users] Stubbing controller methods vs model methods In-Reply-To: <479FFCDF.2060106@benmabey.com> References: <1da51143231791f2aca8eccde47e83fa@ruby-forum.com> <479FFCDF.2060106@benmabey.com> Message-ID: Hey Ben, That makes perfect sense. Thanks for pointing out the error because I don't think I would've been able to figure it out. Thanks, as well, for the stubbing/mocking tip. I will keep my eyes open for that in the future. -- Posted via http://www.ruby-forum.com/. From coreyhaines at gmail.com Wed Jan 30 07:58:00 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Wed, 30 Jan 2008 07:58:00 -0500 Subject: [rspec-users] (no subject) In-Reply-To: <810a540e0801292055n1f1f9d4am682e04f9f3a92010@mail.gmail.com> References: <60708.65.92.50.114.1201668528.squirrel@webmail.harte-lyne.ca> <810a540e0801292055n1f1f9d4am682e04f9f3a92010@mail.gmail.com> Message-ID: <6bdacb70801300458n1f39c85arb6fbebb9f102b843@mail.gmail.com> Yeah, I thought that lambdas supported closures, so they hold their state and you can pass it around. -Corey On Jan 29, 2008 11:55 PM, Pat Maddox wrote: > On Jan 29, 2008 8:48 PM, James B. Byrne wrote: > > Message-ID: > > > > On: Tue, 29 Jan 2008 20:47:41 -0500, "Andrew WC Brown" < > omen.king at gmail.com> > > wrote: > > > > > I've seen lambda before but not sure what it does. > > > > A lambda is a fancy name for an anonymous or unbound function. Its > > significance comes from the fact that it is completely stateless, > producing no > > side effects to its returned result. > > I don't know about that... > > irb(main):001:0> a = [1,2,3] > => [1, 2, 3] > irb(main):002:0> def foo(array) > irb(main):003:1> lambda { array.clear } > irb(main):004:1> end > => nil > irb(main):005:0> fun = foo a > => # > irb(main):006:0> fun.call > => [] > irb(main):007:0> a > => [] > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080130/b2f20a87/attachment.html From lists at ruby-forum.com Wed Jan 30 15:54:11 2008 From: lists at ruby-forum.com (Chris Olsen) Date: Wed, 30 Jan 2008 21:54:11 +0100 Subject: [rspec-users] Order of the get call and xxx.should Message-ID: <69c3b49e813a8a5c7699a7dbf8884991@ruby-forum.com> Just out of curiosity, why is that the following .should calls have to differ to work? The first is a normal check on the if the user is redirected if not logged in ========= it "should redirect the user to the login screen" do do_get response.should redirect_to(new_session_url) end The second is checking to ensure that the proper user validation method is called ========= it "should validate the user" do controller.should_receive(:authorized?).and_return(true) do_get end **Note: These are specs from different describe blocks run under different authorize conditions. Here is the do_get --- def do_get get :index, {:account_id => 1} end Notice the difference to where the do_get method is called. I had an error and it was due to the order not being as is shown above. In the docs it shows the actual request to be made before the assertion statement, but that doesn't work in the second example. Thanks -- Posted via http://www.ruby-forum.com/. From court3nay at gmail.com Wed Jan 30 16:01:07 2008 From: court3nay at gmail.com (Courtenay) Date: Wed, 30 Jan 2008 13:01:07 -0800 Subject: [rspec-users] Order of the get call and xxx.should In-Reply-To: <69c3b49e813a8a5c7699a7dbf8884991@ruby-forum.com> References: <69c3b49e813a8a5c7699a7dbf8884991@ruby-forum.com> Message-ID: <4b430c8f0801301301v5c3a6912gf7fa09cc0f9babd5@mail.gmail.com> On Jan 30, 2008 12:54 PM, Chris Olsen wrote: > Just out of curiosity, why is that the following .should calls have to > differ to work? > > The first is a normal check on the if the user is redirected if not > logged in > ========= > it "should redirect the user to the login screen" do > do_get > response.should redirect_to(new_session_url) > end Because the response object doesn't exist before the 'get'. > The second is checking to ensure that the proper user validation method > is called > ========= > it "should validate the user" do > controller.should_receive(:authorized?).and_return(true) > do_get > end Because we need to stub the method on the controller before the request is run. i.e., prevent it from running. The former is checking that something happened, which didn't exist before the call was run. Whereas the latter is stubbing the method as well as raising if it doesn't. Courtenay From will.sargent at gmail.com Wed Jan 30 16:02:01 2008 From: will.sargent at gmail.com (Will Sargent) Date: Wed, 30 Jan 2008 13:02:01 -0800 Subject: [rspec-users] How do I get logging with rspec? Message-ID: Say I'm testing a controller with rspec, and I have logger.debug and logger.error calls. Normally I'd like them to write to the appropriate file, but in this case I'd like to see the output on STDOUT. Is there an easy way to redirect logging in rspec to do this? I'm thinking that controller.should_receive(:logger).and_return(logger) should start it off, but then how do I get the new logger to do puts without defining a new class? I'm assuming there must be a "Ruby way" to do it. Will. From ben at benmabey.com Wed Jan 30 16:02:50 2008 From: ben at benmabey.com (Ben Mabey) Date: Wed, 30 Jan 2008 14:02:50 -0700 Subject: [rspec-users] Order of the get call and xxx.should In-Reply-To: <69c3b49e813a8a5c7699a7dbf8884991@ruby-forum.com> References: <69c3b49e813a8a5c7699a7dbf8884991@ruby-forum.com> Message-ID: <47A0E5FA.4020308@benmabey.com> Chris Olsen wrote: > Just out of curiosity, why is that the following .should calls have to > differ to work? > > The first is a normal check on the if the user is redirected if not > logged in > ========= > it "should redirect the user to the login screen" do > do_get > response.should redirect_to(new_session_url) > end > Here you are checking the return value of the do_get essentially, as teh get will populate the response object. So you need to actually make the call to the action before you can look at its response. > The second is checking to ensure that the proper user validation method > is called > ========= > it "should validate the user" do > controller.should_receive(:authorized?).and_return(true) > do_get > end > Here you are setting up an expectation with a mock. You are expecting that that object will receive that call during the action you are about to call. This is the core of mocking- being able to test how things are interacting with each other. The order of the calls can be confusing at first. You just have to keep in mind what you are checking.... The returned response or how the action interacts with other object. For a more unified way of writing tests that are a little more explicit check out this blog post: http://blog.davidchelimsky.net/articles/2007/11/06/before_action-after_action -Ben From lists at ruby-forum.com Wed Jan 30 16:45:12 2008 From: lists at ruby-forum.com (Chris Olsen) Date: Wed, 30 Jan 2008 22:45:12 +0100 Subject: [rspec-users] Order of the get call and xxx.should In-Reply-To: <4b430c8f0801301301v5c3a6912gf7fa09cc0f9babd5@mail.gmail.com> References: <69c3b49e813a8a5c7699a7dbf8884991@ruby-forum.com> <4b430c8f0801301301v5c3a6912gf7fa09cc0f9babd5@mail.gmail.com> Message-ID: <9e34d38e953b92fc1953df80d29d4dc4@ruby-forum.com> > Because the response object doesn't exist before the 'get'. That makes things clearer. There have been a couple times that I have put the response.should call before the do_get based on the reason you mentioned, in setting up a stub before the call to the method is made. Then after getting an error for that I saw in the documentation that it was to be placed after, which is what caused some confusion. Thanks for the help, it is very much appreciated. -- Posted via http://www.ruby-forum.com/. From rick.denatale at gmail.com Wed Jan 30 17:13:00 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Wed, 30 Jan 2008 17:13:00 -0500 Subject: [rspec-users] How do I get logging with rspec? In-Reply-To: References: Message-ID: On 1/30/08, Will Sargent wrote: > Say I'm testing a controller with rspec, and I have logger.debug and > logger.error calls. > > Normally I'd like them to write to the appropriate file, but in this > case I'd like to see the output on STDOUT. > > Is there an easy way to redirect logging in rspec to do this? > > I'm thinking that > > controller.should_receive(:logger).and_return(logger) > > should start it off, but then how do I get the new logger to do puts > without defining a new class? I'm assuming there must be a "Ruby way" > to do it. I'd think that controller.should_receive!(:logger).and_return(Logger.new(STDOUT)) should do it. Not sure whether or not you really want to use stub! vs. should_receive here, do you really want to require that logger be called or just allow it? Also if you want to set expectations on what's actually logged you might want to do @log_stream = StringIO.new controller.stub!(:logger) and_return(Logger.new(@logstream)) and then get at the log output via something like @log_stream.string -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From will.sargent at gmail.com Wed Jan 30 18:02:03 2008 From: will.sargent at gmail.com (Will Sargent) Date: Wed, 30 Jan 2008 15:02:03 -0800 Subject: [rspec-users] How do I get logging with rspec? In-Reply-To: References: Message-ID: > > controller.should_receive(:logger).and_return(logger) > > > > should start it off, but then how do I get the new logger to do puts > > without defining a new class? I'm assuming there must be a "Ruby way" > > to do it. > > I'd think that > controller.should_receive!(:logger).and_return(Logger.new(STDOUT)) > should do it. > > Not sure whether or not you really want to use stub! vs. > should_receive here, do you really want to require that logger be > called or just allow it? Good question. I think there are cases where I might want either or both, depending on whether it's for debugging or for support purposes. > Also if you want to set expectations on what's actually logged you > might want to do > > @log_stream = StringIO.new > controller.stub!(:logger) and_return(Logger.new(@logstream)) > and then get at the log output via something like @log_stream.string Great -- that's exactly what I need. Thank you. Will. From lfeistel at lnstar.com Wed Jan 30 17:16:19 2008 From: lfeistel at lnstar.com (lfeistel) Date: Wed, 30 Jan 2008 14:16:19 -0800 (PST) Subject: [rspec-users] Autotest with RSpec Rails and Engines In-Reply-To: <508B84A5-9262-454F-82FB-882D5A3B5856@elctech.com> References: <508B84A5-9262-454F-82FB-882D5A3B5856@elctech.com> Message-ID: <15193445.post@talk.nabble.com> I am also running into nearly this same issue. I am using NetBeans with autotest as I am developing a new Engine Plugin. I would like the tests for the Engine to live in the plugin's spec directory. But it seems that the only way to run the plugin specs is through rake spec:plugins. I can understand that we wouldn't always want to have the plugin specs getting run along with the app's specs, but in this case I do need this functionality since I am developing an Engine. Has this issue been resolved? I see that there was never any reply to it. Thanks, Lee Shane Mingins-3 wrote: > > > We have a Rails project using an engine which I want to run autotest > with rspec against. > > So the project specific specs are in the specs directory but the > common specs are in the specs directory of the engine plugin (e.g. > vendor/plugin/engine/specs) > > -- View this message in context: http://www.nabble.com/Autotest-with-RSpec-Rails-and-Engines-tp12876700p15193445.html Sent from the rspec-users mailing list archive at Nabble.com. From jaydonnell at yahoo.com Wed Jan 30 19:05:28 2008 From: jaydonnell at yahoo.com (Jay Donnell) Date: Wed, 30 Jan 2008 16:05:28 -0800 (PST) Subject: [rspec-users] reby-debug and rspec Message-ID: <346405.15214.qm@web56009.mail.re3.yahoo.com> How do I use the ruby debugger with a specific test (not the whole spec file)? I want to do something like this. $ rdebug spec/models/user_spec.rb -s "should error if not new_record" ____________________________________________________________________________________ Looking for last minute shopping deals? Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping From rick.denatale at gmail.com Wed Jan 30 19:15:37 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Wed, 30 Jan 2008 19:15:37 -0500 Subject: [rspec-users] reby-debug and rspec In-Reply-To: <346405.15214.qm@web56009.mail.re3.yahoo.com> References: <346405.15214.qm@web56009.mail.re3.yahoo.com> Message-ID: On 1/30/08, Jay Donnell wrote: > How do I use the ruby debugger with a specific test (not the whole spec file)? I want to do something like this. > > $ rdebug spec/models/user_spec.rb -s "should error if not new_record" Almost there: $rdebug spec/models/user_spec -- s "should error if not new_record" The -- separates the rdebug options from the options for the program being debugged. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From james.deville at gmail.com Wed Jan 30 19:21:36 2008 From: james.deville at gmail.com (James Deville) Date: Wed, 30 Jan 2008 16:21:36 -0800 Subject: [rspec-users] reby-debug and rspec In-Reply-To: References: <346405.15214.qm@web56009.mail.re3.yahoo.com> Message-ID: <16D09F86-C5FA-4987-AB1D-368DA9333608@gmail.com> The other options is to do require 'ruby-debug' in your development.rb and test.rb environment files, and just do debugger where you want the breakpoint in your test On Jan 30, 2008, at 4:15 PM, Rick DeNatale wrote: > On 1/30/08, Jay Donnell wrote: >> How do I use the ruby debugger with a specific test (not the whole >> spec file)? I want to do something like this. >> >> $ rdebug spec/models/user_spec.rb -s "should error if not new_record" > > Almost there: > > $rdebug spec/models/user_spec -- s "should error if not new_record" > > The -- separates the rdebug options from the options for the program > being debugged. > > > -- > Rick DeNatale > > My blog on Ruby > http://talklikeaduck.denhaven2.com/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users James Deville http://devillecompanies.org james.deville at gmail.com rspec r3172 rspec_on_rails r3172 rails r8331 From dchelimsky at gmail.com Wed Jan 30 19:21:47 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 30 Jan 2008 18:21:47 -0600 Subject: [rspec-users] Autotest with RSpec Rails and Engines In-Reply-To: <508B84A5-9262-454F-82FB-882D5A3B5856@elctech.com> References: <508B84A5-9262-454F-82FB-882D5A3B5856@elctech.com> Message-ID: <57c63afe0801301621i562c3134sd7fe45afae5331da@mail.gmail.com> On Sep 25, 2007 4:16 AM, Shane Mingins wrote: > > Hi > > We have a Rails project using an engine which I want to run autotest with > rspec against. > > So the project specific specs are in the specs directory but the common > specs are in the specs directory of the engine plugin (e.g. > vendor/plugin/engine/specs) > > Just wondering where I would be looking to change configuration so that > autotest will also look for the specs in the engine directory? > > is there some way of configuring using a .autotest file? The > tests_for_file method did not seem to be what I wanted in that it determines > the spec to run for a file where I want to determine the files themselves? > > It would seem that the initialize method of the class Autotest::RailsRspec > sets up where it is finding the tests, yes? And is it here that I should be > looking to change? > > And pointers would be appreciated. http://blog.davidchelimsky.net/articles/2008/01/15/rspec-1-1-2-and-zentest-3-8-0 Cheers, David > > Cheers > Shane > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Wed Jan 30 19:23:37 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 30 Jan 2008 18:23:37 -0600 Subject: [rspec-users] Autotest with RSpec Rails and Engines In-Reply-To: <15193445.post@talk.nabble.com> References: <508B84A5-9262-454F-82FB-882D5A3B5856@elctech.com> <15193445.post@talk.nabble.com> Message-ID: <57c63afe0801301623l3de69bb1p68a3c09e610934c6@mail.gmail.com> On Jan 30, 2008 4:16 PM, lfeistel wrote: > > I am also running into nearly this same issue. I am using NetBeans with > autotest as I am developing a new Engine Plugin. I would like the tests for > the Engine to live in the plugin's spec directory. But it seems that the > only way to run the plugin specs is through rake spec:plugins. I can > understand that we wouldn't always want to have the plugin specs getting run > along with the app's specs, but in this case I do need this functionality > since I am developing an Engine. > > Has this issue been resolved? I see that there was never any reply to it. If you're looking to run them using rake, just write your own rake task. If you're looking to run them using autotest, check this out: http://blog.davidchelimsky.net/articles/2008/01/15/rspec-1-1-2-and-zentest-3-8-0 HTH, David > > Thanks, > Lee > > > > Shane Mingins-3 wrote: > > > > > > We have a Rails project using an engine which I want to run autotest > > with rspec against. > > > > So the project specific specs are in the specs directory but the > > common specs are in the specs directory of the engine plugin (e.g. > > vendor/plugin/engine/specs) > > > > > -- > View this message in context: http://www.nabble.com/Autotest-with-RSpec-Rails-and-Engines-tp12876700p15193445.html > Sent from the rspec-users mailing list archive at Nabble.com. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From luislavena at gmail.com Wed Jan 30 19:43:11 2008 From: luislavena at gmail.com (Luis Lavena) Date: Wed, 30 Jan 2008 22:43:11 -0200 Subject: [rspec-users] DRb does not activate using options file Message-ID: <71166b3b0801301643n1e8f1624y7cc79c24b00e8eb0@mail.gmail.com> Hello List, For a small project I've been using 'ruby script/spec -X spec' to execute my specs. Now that I added ZenTest on it, found that the test takes longer to run due the complete load of test environment. Since autotest uses 'script/spec -O spec/spec.opts' as the command, I decided to add --drb to spec.opts Using --drb or -X, spec_server is just ignored and environment get loaded locally. Trying to pinpoint the problem, it seems that using -O don't handle/load set --drb, but when you put all the options in the command line, works as expected. Couldn't find anything besides this (rspec/lib/spec/runner/option_parser.rb:111) on(*OPTIONS[:drb]) {} == Maybe I'm missing something, did anyone get it working? Thanks in advance, -- Luis Lavena Multimedia systems - A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools. Douglas Adams From mailing_lists at railsnewbie.com Wed Jan 30 20:30:44 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Wed, 30 Jan 2008 20:30:44 -0500 Subject: [rspec-users] reby-debug and rspec In-Reply-To: <16D09F86-C5FA-4987-AB1D-368DA9333608@gmail.com> References: <346405.15214.qm@web56009.mail.re3.yahoo.com> <16D09F86-C5FA-4987-AB1D-368DA9333608@gmail.com> Message-ID: <433E8097-628D-4E6F-BE9B-032F1892AAD1@railsnewbie.com> On Jan 30, 2008, at 7:21 PM, James Deville wrote: > The other options is to do require 'ruby-debug' in your development.rb > and test.rb environment files, and just do debugger where you want the > breakpoint in your test > > I just have a 'debug' snippet in textmate where 'debug' => tab expands to: require 'rubygems'; require 'ruby-debug'; debugger; So I just insert this into my spec, and then rerun the specs. the debugger will pop right into the spec, allowing you to step into the method call, and so on. The only disadvantage to this approach is that you will need to run through the rest of the test in the file before hitting the debug line. Scott > On Jan 30, 2008, at 4:15 PM, Rick DeNatale wrote: > >> On 1/30/08, Jay Donnell wrote: >>> How do I use the ruby debugger with a specific test (not the whole >>> spec file)? I want to do something like this. >>> >>> $ rdebug spec/models/user_spec.rb -s "should error if not >>> new_record" >> >> Almost there: >> >> $rdebug spec/models/user_spec -- s "should error if not new_record" >> >> The -- separates the rdebug options from the options for the program >> being debugged. >> >> >> -- >> Rick DeNatale >> >> My blog on Ruby >> http://talklikeaduck.denhaven2.com/ >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > > > James Deville > http://devillecompanies.org > james.deville at gmail.com > rspec r3172 > rspec_on_rails r3172 > rails r8331 > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From rick.denatale at gmail.com Wed Jan 30 22:33:48 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Wed, 30 Jan 2008 22:33:48 -0500 Subject: [rspec-users] reby-debug and rspec In-Reply-To: <433E8097-628D-4E6F-BE9B-032F1892AAD1@railsnewbie.com> References: <346405.15214.qm@web56009.mail.re3.yahoo.com> <16D09F86-C5FA-4987-AB1D-368DA9333608@gmail.com> <433E8097-628D-4E6F-BE9B-032F1892AAD1@railsnewbie.com> Message-ID: On 1/30/08, Scott Taylor wrote: > > On Jan 30, 2008, at 7:21 PM, James Deville wrote: > > > The other options is to do require 'ruby-debug' in your development.rb > > and test.rb environment files, and just do debugger where you want the > > breakpoint in your test > > > > > > I just have a 'debug' snippet in textmate where 'debug' => tab > expands to: > > require 'rubygems'; require 'ruby-debug'; debugger; > > So I just insert this into my spec, and then rerun the specs. the > debugger will pop right into the spec, allowing you to step into the > method call, and so on. > > The only disadvantage to this approach is that you will need to run > through the rest of the test in the file before hitting the debug line. > > Scott > > > > On Jan 30, 2008, at 4:15 PM, Rick DeNatale wrote: > > > >> On 1/30/08, Jay Donnell wrote: > >>> How do I use the ruby debugger with a specific test (not the whole > >>> spec file)? I want to do something like this. > >>> > >>> $ rdebug spec/models/user_spec.rb -s "should error if not > >>> new_record" > >> > >> Almost there: > >> > >> $rdebug spec/models/user_spec -- s "should error if not new_record" > >> > >> The -- separates the rdebug options from the options for the program > >> being debugged. Inspired by this thread, I just submitted a patch which adds a debugger option (either -u or --debugger like the Rails script/server script) which includes ruby-debug, and also ensures that the debugger method is defined if it isn't already. This allows you to put debugger invocations in examples and stories and control whether or not they do anything using the option. http://rspec.lighthouseapp.com/projects/5645-rspec/tickets/262-patch-add-debug-option-to-rspec-runner -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From dchelimsky at gmail.com Thu Jan 31 06:25:23 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 31 Jan 2008 05:25:23 -0600 Subject: [rspec-users] ZenTest-3.9.0 incompatible with RSpec-1.1.2 Message-ID: <57c63afe0801310325w3b44adfhf829b54c123a9b33@mail.gmail.com> Hey all, Just a heads up that the ZenTest-3.9.0 release is not compatible with RSpec-1.1.2. I thought I had a release ready to go, but differences between a preview release of ZenTest that I received and the actual release seem to have broken compatibility. We'll get this resolved soon, but in the mean time please hold off on upgrading to ZenTest-3.9.0 if you're using RSpec. Thanks, David From dchelimsky at gmail.com Thu Jan 31 07:42:55 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 31 Jan 2008 06:42:55 -0600 Subject: [rspec-users] [ANN] RSpec-1.1.3 Message-ID: <57c63afe0801310442r7cbf7494we006ba5ef4571eec@mail.gmail.com> RSpec-1.1.3 has been released. If you're using RSpec and autotest, you'll have to upgrade to RSpec-1.1.3 and ZenTest-3.9.0 at the same time. == Version 1.1.3 Maintenance release. * Tightened up exceptions list in autotest/rails_spec. Closes #264. * Applied patch from Ryan Davis for ZenTest-3.9.0 compatibility * Applied patch from Kero to add step_upcoming to story listeners. Closes #253. * Fixed bug where the wrong named error was not always caught by "should raise_error" * Applied patch from Luis Lavena: No coloured output on Windows due missing RUBYOPT. Closes #244. * Applied patch from Craig Demyanovich to add support for "should_not render_template" to rspec_on_rails. Closes #241. * Added --pattern (-p for short) option to control what files get loaded. Defaults to '**/*_spec.rb' * Exit with non-0 exit code if examples *or tests* (in test/unit interop mode) fail. Closes #203. * Moved at_exit hook to a method in Spec::Runner which only runs if specs get loaded. Closes #242. * Applied patch from kakutani ensuring that base_view_path gets cleared after each view example. Closes #235. * More tweaks to regexp step names * Fixed focused specs in nested ExampleGroups. Closes #225. More info at http://rspec.info. Cheers, David From ladislav.martincik at gmail.com Thu Jan 31 09:47:23 2008 From: ladislav.martincik at gmail.com (Ladislav Martincik) Date: Thu, 31 Jan 2008 14:47:23 +0000 Subject: [rspec-users] ZenTest-3.9.0 incompatible with RSpec-1.1.2 In-Reply-To: <57c63afe0801310325w3b44adfhf829b54c123a9b33@mail.gmail.com> References: <57c63afe0801310325w3b44adfhf829b54c123a9b33@mail.gmail.com> Message-ID: <98ac62f50801310647y40923980y983ee2f3b63519d8@mail.gmail.com> Good to know. Thanx David On Jan 31, 2008 11:25 AM, David Chelimsky wrote: > Hey all, > > Just a heads up that the ZenTest-3.9.0 release is not compatible with > RSpec-1.1.2. I thought I had a release ready to go, but differences > between a preview release of ZenTest that I received and the actual > release seem to have broken compatibility. > > We'll get this resolved soon, but in the mean time please hold off on > upgrading to ZenTest-3.9.0 if you're using RSpec. > > Thanks, > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080131/bc3ee629/attachment.html From dchelimsky at gmail.com Thu Jan 31 10:19:00 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 31 Jan 2008 09:19:00 -0600 Subject: [rspec-users] ZenTest-3.9.0 incompatible with RSpec-1.1.2 In-Reply-To: <57c63afe0801310325w3b44adfhf829b54c123a9b33@mail.gmail.com> References: <57c63afe0801310325w3b44adfhf829b54c123a9b33@mail.gmail.com> Message-ID: <57c63afe0801310719u7d523f6eg4cddc32158f7bf36@mail.gmail.com> This is resolved with the RSpece-1.1.3 release which went out early this morning. On Jan 31, 2008 5:25 AM, David Chelimsky wrote: > Hey all, > > Just a heads up that the ZenTest-3.9.0 release is not compatible with > RSpec-1.1.2. I thought I had a release ready to go, but differences > between a preview release of ZenTest that I received and the actual > release seem to have broken compatibility. > > We'll get this resolved soon, but in the mean time please hold off on > upgrading to ZenTest-3.9.0 if you're using RSpec. > > Thanks, > David > From dchelimsky at gmail.com Thu Jan 31 10:19:16 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 31 Jan 2008 09:19:16 -0600 Subject: [rspec-users] ZenTest-3.9.0 incompatible with RSpec-1.1.2 In-Reply-To: <57c63afe0801310719u7d523f6eg4cddc32158f7bf36@mail.gmail.com> References: <57c63afe0801310325w3b44adfhf829b54c123a9b33@mail.gmail.com> <57c63afe0801310719u7d523f6eg4cddc32158f7bf36@mail.gmail.com> Message-ID: <57c63afe0801310719g5caf561cq2b01c7caf9130916@mail.gmail.com> On Jan 31, 2008 9:19 AM, David Chelimsky wrote: > This is resolved with the RSpece-1.1.3 release which went out early > this morning. So early that I can't spell :) > > > On Jan 31, 2008 5:25 AM, David Chelimsky wrote: > > Hey all, > > > > Just a heads up that the ZenTest-3.9.0 release is not compatible with > > RSpec-1.1.2. I thought I had a release ready to go, but differences > > between a preview release of ZenTest that I received and the actual > > release seem to have broken compatibility. > > > > We'll get this resolved soon, but in the mean time please hold off on > > upgrading to ZenTest-3.9.0 if you're using RSpec. > > > > Thanks, > > David > > > From dbcurrin at gmail.com Thu Jan 31 09:31:48 2008 From: dbcurrin at gmail.com (desaperados) Date: Thu, 31 Jan 2008 06:31:48 -0800 (PST) Subject: [rspec-users] RSpec and the Basecamp API Message-ID: <15205668.post@talk.nabble.com> I realise that this is kind of a basic question but I'm new to rspec and still trying to work out how to do things. I'm working on a rails project that requires basecamp integration via the api, which is fairly trivial to use via the basecamp.rb wrapper: Connection: basecamp = Basecamp.new(APP_CONFIG['api_host'], APP_CONFIG['api_username'], APP_CONFIG['api_pwd']) And to retrieve a list of Projects: puts "Projects: #{basecamp.projects}" I know how to make this work in the model, I'm just having trouble working out how to create a usable mock for this in rspec. I can't work out to mock 'basecamp.projects' with an object which can then be used in the tests. Sorry if this is a stupid question but I'm just a bit stuck with it. -- View this message in context: http://www.nabble.com/RSpec-and-the-Basecamp-API-tp15205668p15205668.html Sent from the rspec-users mailing list archive at Nabble.com. From james.deville at gmail.com Thu Jan 31 11:19:10 2008 From: james.deville at gmail.com (James Deville) Date: Thu, 31 Jan 2008 08:19:10 -0800 Subject: [rspec-users] RSpec and the Basecamp API In-Reply-To: <15205668.post@talk.nabble.com> References: <15205668.post@talk.nabble.com> Message-ID: basecamp = mock("basecamp api",;projects => <>) Basecamp.stub!(:new).and_return(basecamp) So for the projects one, you could return an array, or a bunch of mocks, or a string. Just make it match how the Basecamp API is behaving. On Jan 31, 2008, at 6:31 AM, desaperados wrote: > > I realise that this is kind of a basic question but I'm new to rspec > and > still trying to work out how to do things. I'm working on a rails > project > that requires basecamp integration via the api, which is fairly > trivial to > use via the basecamp.rb wrapper: > > Connection: > basecamp = Basecamp.new(APP_CONFIG['api_host'], > APP_CONFIG['api_username'], > APP_CONFIG['api_pwd']) > > And to retrieve a list of Projects: > puts "Projects: #{basecamp.projects}" > > I know how to make this work in the model, I'm just having trouble > working > out how to create a usable mock for this in rspec. I can't work out > to mock > 'basecamp.projects' with an object which can then be used in the > tests. > > Sorry if this is a stupid question but I'm just a bit stuck with it. > > > > > > -- > View this message in context: http://www.nabble.com/RSpec-and-the-Basecamp-API-tp15205668p15205668.html > Sent from the rspec-users mailing list archive at Nabble.com. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users James Deville http://devillecompanies.org james.deville at gmail.com rspec r3172 rspec_on_rails r3172 rails r8331 From dchelimsky at gmail.com Thu Jan 31 15:14:16 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 31 Jan 2008 14:14:16 -0600 Subject: [rspec-users] ZenTest-3.9.0 incompatible with RSpec-1.1.2 In-Reply-To: <57c63afe0801310325w3b44adfhf829b54c123a9b33@mail.gmail.com> References: <57c63afe0801310325w3b44adfhf829b54c123a9b33@mail.gmail.com> Message-ID: <57c63afe0801311214o2ea1903ao1163bbd95ec3a7ea@mail.gmail.com> On Jan 31, 2008 5:25 AM, David Chelimsky wrote: > Hey all, > > Just a heads up that the ZenTest-3.9.0 release is not compatible with > RSpec-1.1.2. I thought I had a release ready to go, but differences > between a preview release of ZenTest that I received and the actual > release seem to have broken compatibility. Hey spec'ers: it turns out that this was NOT a problem w/ ZenTest. I had actually missed a step when checking RSpec against the preview release. All should be working now as long as you're using either ZenTest-3.8.0/RSpec-1.1.2 or ZenTest-3.9.0/RSpec-1.1.3. Cheers, David From lfeistel at lnstar.com Thu Jan 31 15:33:03 2008 From: lfeistel at lnstar.com (lfeistel) Date: Thu, 31 Jan 2008 12:33:03 -0800 (PST) Subject: [rspec-users] Autotest with RSpec Rails and Engines In-Reply-To: <57c63afe0801301623l3de69bb1p68a3c09e610934c6@mail.gmail.com> References: <508B84A5-9262-454F-82FB-882D5A3B5856@elctech.com> <15193445.post@talk.nabble.com> <57c63afe0801301623l3de69bb1p68a3c09e610934c6@mail.gmail.com> Message-ID: <15214164.post@talk.nabble.com> Thanks, your blog post was very helpful. I've got autotest working in my plugin. One hurdle I had to jump was that the new autotest defines an exception for vendor/plugins by default. So you can sit and define mappings all day and never get any results because the whole plugins directory is not being scanned. Once I added a RemoveException('vendor/plugin') to the top of my .autotest I was able to see my mappings work and moved on with fine tuning them. Lee David Chelimsky-2 wrote: > > > If you're looking to run them using rake, just write your own rake task. > > If you're looking to run them using autotest, check this out: > > http://blog.davidchelimsky.net/articles/2008/01/15/rspec-1-1-2-and-zentest-3-8-0 > > HTH, > David > >> >> Thanks, >> Lee >> >> >> >> Shane Mingins-3 wrote: >> > >> > >> > We have a Rails project using an engine which I want to run autotest >> > with rspec against. >> > >> > So the project specific specs are in the specs directory but the >> > common specs are in the specs directory of the engine plugin (e.g. >> > vendor/plugin/engine/specs) >> > >> > >> -- >> View this message in context: >> http://www.nabble.com/Autotest-with-RSpec-Rails-and-Engines-tp12876700p15193445.html >> Sent from the rspec-users mailing list archive at Nabble.com. >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > -- View this message in context: http://www.nabble.com/Autotest-with-RSpec-Rails-and-Engines-tp12876700p15214164.html Sent from the rspec-users mailing list archive at Nabble.com. From omen.king at gmail.com Thu Jan 31 17:52:01 2008 From: omen.king at gmail.com (Andrew WC Brown) Date: Thu, 31 Jan 2008 17:52:01 -0500 Subject: [rspec-users] loading fixtures? Message-ID: How do you load fixtures from specs as you would test? eg. rake db:fixtures:load RAILS_ENV=development -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080131/38c3b0ab/attachment.html From coreyhaines at gmail.com Thu Jan 31 18:56:13 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Thu, 31 Jan 2008 18:56:13 -0500 Subject: [rspec-users] loading fixtures? In-Reply-To: References: Message-ID: <6bdacb70801311556l3967255fr2e3355d52ef6047f@mail.gmail.com> Do you want to load them in your controller? You can put class MyController fixtures :fixturename end -Corey On Jan 31, 2008 5:52 PM, Andrew WC Brown wrote: > How do you load fixtures from specs as you would test? > > eg. rake db:fixtures:load RAILS_ENV=development > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080131/1373012d/attachment.html From omen.king at gmail.com Thu Jan 31 18:57:11 2008 From: omen.king at gmail.com (Andrew WC Brown) Date: Thu, 31 Jan 2008 18:57:11 -0500 Subject: [rspec-users] loading fixtures? In-Reply-To: <6bdacb70801311556l3967255fr2e3355d52ef6047f@mail.gmail.com> References: <6bdacb70801311556l3967255fr2e3355d52ef6047f@mail.gmail.com> Message-ID: no, just database On Jan 31, 2008 6:56 PM, Corey Haines wrote: > Do you want to load them in your controller? You can put > > class MyController > fixtures :fixturename > > end > > > -Corey > > On Jan 31, 2008 5:52 PM, Andrew WC Brown wrote: > > > How do you load fixtures from specs as you would test? > > > > eg. rake db:fixtures:load RAILS_ENV=development > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > -- > http://www.coreyhaines.com > The Internet's Premiere source of information about Corey Haines > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080131/4583e5c9/attachment.html From coreyhaines at gmail.com Thu Jan 31 19:03:24 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Thu, 31 Jan 2008 19:03:24 -0500 Subject: [rspec-users] loading fixtures? In-Reply-To: References: <6bdacb70801311556l3967255fr2e3355d52ef6047f@mail.gmail.com> Message-ID: <6bdacb70801311603x26d65dd8h217349e9ff32b078@mail.gmail.com> rake db:fixtures:load doesn't work? On Jan 31, 2008 6:57 PM, Andrew WC Brown wrote: > no, just database > > > On Jan 31, 2008 6:56 PM, Corey Haines wrote: > > > Do you want to load them in your controller? You can put > > > > class MyController > > fixtures :fixturename > > > > end > > > > > > -Corey > > > > On Jan 31, 2008 5:52 PM, Andrew WC Brown wrote: > > > > > How do you load fixtures from specs as you would test? > > > > > > eg. rake db:fixtures:load RAILS_ENV=development > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > -- > > http://www.coreyhaines.com > > The Internet's Premiere source of information about Corey Haines > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080131/5447d6fd/attachment-0001.html From omen.king at gmail.com Thu Jan 31 23:22:54 2008 From: omen.king at gmail.com (Andrew WC Brown) Date: Thu, 31 Jan 2008 23:22:54 -0500 Subject: [rspec-users] loading fixtures? In-Reply-To: <6bdacb70801311603x26d65dd8h217349e9ff32b078@mail.gmail.com> References: <6bdacb70801311556l3967255fr2e3355d52ef6047f@mail.gmail.com> <6bdacb70801311603x26d65dd8h217349e9ff32b078@mail.gmail.com> Message-ID: loads the test fixtures, instead of the spec fixtures directory.Does it work for you? On Jan 31, 2008 7:03 PM, Corey Haines wrote: > rake db:fixtures:load doesn't work? > > > On Jan 31, 2008 6:57 PM, Andrew WC Brown wrote: > > > no, just database > > > > > > On Jan 31, 2008 6:56 PM, Corey Haines wrote: > > > > > Do you want to load them in your controller? You can put > > > > > > class MyController > > > fixtures :fixturename > > > > > > end > > > > > > > > > -Corey > > > > > > On Jan 31, 2008 5:52 PM, Andrew WC Brown wrote: > > > > > > > How do you load fixtures from specs as you would test? > > > > > > > > eg. rake db:fixtures:load RAILS_ENV=development > > > > > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > -- > > > http://www.coreyhaines.com > > > The Internet's Premiere source of information about Corey Haines > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > -- > http://www.coreyhaines.com > The Internet's Premiere source of information about Corey Haines > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080131/62c15ae2/attachment.html From qpadla at gmail.com Thu Jan 31 23:48:38 2008 From: qpadla at gmail.com (Nikolay Pavlov) Date: Fri, 1 Feb 2008 06:48:38 +0200 Subject: [rspec-users] [ANN] RSpec-1.1.3 In-Reply-To: <57c63afe0801310442r7cbf7494we006ba5ef4571eec@mail.gmail.com> References: <57c63afe0801310442r7cbf7494we006ba5ef4571eec@mail.gmail.com> Message-ID: <200802010648.39065.qpadla@gmail.com> On Thursday 31 January 2008 14:42:55 David Chelimsky wrote: > RSpec-1.1.3 has been released. > > If you're using RSpec and autotest, you'll have to upgrade to > RSpec-1.1.3 and ZenTest-3.9.0 at the same time. > > == Version 1.1.3 > > Maintenance release. > > * Tightened up exceptions list in autotest/rails_spec. Closes #264. > * Applied patch from Ryan Davis for ZenTest-3.9.0 compatibility > * Applied patch from Kero to add step_upcoming to story listeners. > Closes #253. * Fixed bug where the wrong named error was not always > caught by "should raise_error" > * Applied patch from Luis Lavena: No coloured output on Windows due > missing RUBYOPT. Closes #244. > * Applied patch from Craig Demyanovich to add support for "should_not > render_template" to rspec_on_rails. Closes #241. > * Added --pattern (-p for short) option to control what files get > loaded. Defaults to '**/*_spec.rb' > * Exit with non-0 exit code if examples *or tests* (in test/unit > interop mode) fail. Closes #203. > * Moved at_exit hook to a method in Spec::Runner which only runs if > specs get loaded. Closes #242. > * Applied patch from kakutani ensuring that base_view_path gets > cleared after each view example. Closes #235. > * More tweaks to regexp step names > * Fixed focused specs in nested ExampleGroups. Closes #225. Hello all, hello David. I am not sure were to go with this, but after upgrading to RSpec-1.1.3 and ZenTest-3.9.0 i am observing memory leaks in autotest process: 32001 quetzal 18 0 97472 93m 1464 S 25 9.2 1:43.28 autotest After 5 minutes: 32001 quetzal 18 0 102m 100m 1464 S 13 9.9 2:07.35 autotest A few minutes later: 32001 quetzal 18 0 112m 110m 1464 R 29 11.0 2:40.67 autotest And so on... There are only two requirements in my .autotest file: require 'autotest/redgreen' require 'autotest/timestamp' Could some one confirm this behavior? -- ====================================================================== - Best regards, Nikolay Pavlov. <<<----------------------------------- ======================================================================