From peter.hicks at poggs.co.uk Sat Jan 2 06:17:45 2010 From: peter.hicks at poggs.co.uk (Peter Hicks) Date: Sat, 02 Jan 2010 11:17:45 +0000 Subject: [rspec-users] Loading numerous data structures from YAML files Message-ID: <4B3F2B59.8000700@poggs.co.uk> All, I am writing specs for some multi-stage tests which require a lot of input data. A simplified overview of the tests is as follows: * Provide list of network interfaces, confirm they are added to the database * Provide list of network interfaces as above, but with one entry added, and confirm this entry is added to the database * Provide list of network interfaces as above, but with a different entry removed, and confirm this entry is added to the database I want to isolate the test data from the specs themselves for cleanliness, and I am thinking of putting them in YAML files. How best should I tackle this? Where should I put the YAML files and is there any functionality in RSpec that will help? Should I roll my own "load test data" code and present that to the test code? Best wishes, Peter From apremdas at gmail.com Sat Jan 2 16:23:23 2010 From: apremdas at gmail.com (Andrew Premdas) Date: Sat, 2 Jan 2010 21:23:23 +0000 Subject: [rspec-users] more verbosity for be_an? In-Reply-To: References: <57c63afe0912301219l43937dc6he78256e600eeeb30@mail.gmail.com> Message-ID: <88fd8ddc1001021323o5537de65x8519b91c867acc69@mail.gmail.com> 2009/12/30 rogerdpack > > What about something like: > > > > expected # => Fixnum to be a kind of Fixnum > > > > That is more aligned with other failure messages. WDYT? > > I quite like it. > In this instance it was > > 3.class.should be_a Fixnum # fails > > I suppose it would be something like > expected # => Class to be a kind of Fixnum > > ? > > > And just out of curiosity, Roger, what's your use case? I can't remember > ever using be_a/be_an, at least not in any code that has survived. > > The very first test I thought up was "this method should return an > integer" so kind of a basic test for a not yet existent method. > > Isn't this a bit anti-ruby though. Surely the things we should be testing is that the object exists, responds to certain messages and gives certain values back for those messages. Thinking about types is so Java, C++ :-) all best Andrew > -r > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Sat Jan 2 16:35:53 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 2 Jan 2010 15:35:53 -0600 Subject: [rspec-users] more verbosity for be_an? In-Reply-To: <88fd8ddc1001021323o5537de65x8519b91c867acc69@mail.gmail.com> References: <57c63afe0912301219l43937dc6he78256e600eeeb30@mail.gmail.com> <88fd8ddc1001021323o5537de65x8519b91c867acc69@mail.gmail.com> Message-ID: <57c63afe1001021335m326fda84jca91d57962a70182@mail.gmail.com> On Sat, Jan 2, 2010 at 3:23 PM, Andrew Premdas wrote: > 2009/12/30 rogerdpack > > > What about something like: >> > >> > expected # => Fixnum to be a kind of Fixnum >> > >> > That is more aligned with other failure messages. WDYT? >> >> I quite like it. >> In this instance it was >> >> 3.class.should be_a Fixnum # fails >> >> I suppose it would be something like >> expected # => Class to be a kind of Fixnum >> >> ? >> >> > And just out of curiosity, Roger, what's your use case? I can't >> remember ever using be_a/be_an, at least not in any code that has survived. >> >> The very first test I thought up was "this method should return an >> integer" so kind of a basic test for a not yet existent method. >> >> > Isn't this a bit anti-ruby though. Surely the things we should be testing > is that the object exists, responds to certain messages and gives certain > values back for those messages. Thinking about types is so Java, C++ :-) > Generally speaking, you're correct, but there are cases where this is valuable - like if you're spec'ing a factory in a lib for others to use, etc. > > > all best > > Andrew > >> -r >> _______________________________________________ >> 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: From phillipkoebbe at gmail.com Sat Jan 2 17:02:40 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Sat, 2 Jan 2010 14:02:40 -0800 (PST) Subject: [rspec-users] Loading numerous data structures from YAML files In-Reply-To: <4B3F2B59.8000700@poggs.co.uk> References: <4B3F2B59.8000700@poggs.co.uk> Message-ID: <4f5cdb8b-068e-4b0c-803a-7fd0ebb57ef7@21g2000yqj.googlegroups.com> On Jan 2, 5:17?am, Peter Hicks wrote: > > How best should I tackle this? ?Where should I put the YAML files and is > there any functionality in RSpec that will help? ?Should I roll my own > "load test data" code and present that to the test code? > > Best wishes, > > Peter Hi Peter, Have you read about fixtures? It sounds like just what you're looking for. Peace, Phillip From peter.hicks at poggs.co.uk Sat Jan 2 17:12:03 2010 From: peter.hicks at poggs.co.uk (Peter Hicks) Date: Sat, 02 Jan 2010 22:12:03 +0000 Subject: [rspec-users] Loading numerous data structures from YAML files In-Reply-To: <4f5cdb8b-068e-4b0c-803a-7fd0ebb57ef7@21g2000yqj.googlegroups.com> References: <4B3F2B59.8000700@poggs.co.uk> <4f5cdb8b-068e-4b0c-803a-7fd0ebb57ef7@21g2000yqj.googlegroups.com> Message-ID: <4B3FC4B3.5080001@poggs.co.uk> Hi Phillip Phillip Koebbe wrote: > Have you read about fixtures? It sounds like just what you're looking > for. I'm using fixtures already - they're great. I can't find a way to load a specific fixture in to a table. If I could do that, I could load a set of data, run the code, check the results, and repeat again for the next test. Peter From rick.denatale at gmail.com Sat Jan 2 17:50:02 2010 From: rick.denatale at gmail.com (Rick DeNatale) Date: Sat, 2 Jan 2010 17:50:02 -0500 Subject: [rspec-users] more verbosity for be_an? In-Reply-To: <57c63afe1001021335m326fda84jca91d57962a70182@mail.gmail.com> References: <57c63afe0912301219l43937dc6he78256e600eeeb30@mail.gmail.com> <88fd8ddc1001021323o5537de65x8519b91c867acc69@mail.gmail.com> <57c63afe1001021335m326fda84jca91d57962a70182@mail.gmail.com> Message-ID: On Sat, Jan 2, 2010 at 4:35 PM, David Chelimsky wrote: > > > On Sat, Jan 2, 2010 at 3:23 PM, Andrew Premdas wrote: >> >> 2009/12/30 rogerdpack >>> >>> > What about something like: >>> > >>> > ? expected # => Fixnum to be a kind of Fixnum >>> > >>> > That is more aligned with other failure messages. WDYT? >>> >>> I quite like it. >>> In this instance it was >>> >>> 3.class.should be_a Fixnum # fails >>> >>> I suppose it would be something like >>> expected # => Class to be a kind of Fixnum >>> >>> ? >>> >>> > And just out of curiosity, Roger, what's your use case? ?I can't >>> > remember ever using be_a/be_an, at least not in any code that has survived. >>> >>> The very first test I thought up was "this method should return an >>> integer" so kind of a basic test for a not yet existent method. >>> >> >> Isn't this a bit anti-ruby though. Surely the things we should be testing >> is that the object exists, responds to certain messages and gives certain >> values back for those messages. Thinking about types is so Java, C++ :-) > > Generally speaking, you're correct, but there are cases where this is > valuable - like if you're spec'ing a factory in a lib for others to use, > etc. However, I need to point out that although 1.should be_a Fixnum that 1.class.should_not be_a Fixnum because 1.class == Fixnum which is after all a Class, and not a Fixnum itself. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale From dchelimsky at gmail.com Sat Jan 2 18:49:39 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 2 Jan 2010 17:49:39 -0600 Subject: [rspec-users] more verbosity for be_an? In-Reply-To: References: <57c63afe0912301219l43937dc6he78256e600eeeb30@mail.gmail.com> <88fd8ddc1001021323o5537de65x8519b91c867acc69@mail.gmail.com> <57c63afe1001021335m326fda84jca91d57962a70182@mail.gmail.com> Message-ID: <57c63afe1001021549w1bf09fb7o59d0aa12bf74101b@mail.gmail.com> On Sat, Jan 2, 2010 at 4:50 PM, Rick DeNatale wrote: > On Sat, Jan 2, 2010 at 4:35 PM, David Chelimsky > wrote: > > > > > > On Sat, Jan 2, 2010 at 3:23 PM, Andrew Premdas > wrote: > >> > >> 2009/12/30 rogerdpack > >>> > >>> > What about something like: > >>> > > >>> > expected # => Fixnum to be a kind of Fixnum > >>> > > >>> > That is more aligned with other failure messages. WDYT? > >>> > >>> I quite like it. > >>> In this instance it was > >>> > >>> 3.class.should be_a Fixnum # fails > >>> > >>> I suppose it would be something like > >>> expected # => Class to be a kind of Fixnum > >>> > >>> ? > >>> > >>> > And just out of curiosity, Roger, what's your use case? I can't > >>> > remember ever using be_a/be_an, at least not in any code that has > survived. > >>> > >>> The very first test I thought up was "this method should return an > >>> integer" so kind of a basic test for a not yet existent method. > >>> > >> > >> Isn't this a bit anti-ruby though. Surely the things we should be > testing > >> is that the object exists, responds to certain messages and gives > certain > >> values back for those messages. Thinking about types is so Java, C++ :-) > > > > Generally speaking, you're correct, but there are cases where this is > > valuable - like if you're spec'ing a factory in a lib for others to use, > > etc. > > However, I need to point out that > > although > > 1.should be_a Fixnum > > that > > 1.class.should_not be_a Fixnum > > because > > 1.class == Fixnum which is after all a Class, and not a Fixnum itself. > Right - the initial problem that Roger was reporting was that "1.class.should be_a(Fixnum)" produced a failure message wasn't that helpful, not that it failed to fail :) -------------- next part -------------- An HTML attachment was scrubbed... URL: From rogerdpack at gmail.com Sat Jan 2 21:43:14 2010 From: rogerdpack at gmail.com (rogerdpack) Date: Sat, 2 Jan 2010 18:43:14 -0800 (PST) Subject: [rspec-users] more verbosity for be_an? In-Reply-To: <88fd8ddc1001021323o5537de65x8519b91c867acc69@mail.gmail.com> References: <57c63afe0912301219l43937dc6he78256e600eeeb30@mail.gmail.com> <88fd8ddc1001021323o5537de65x8519b91c867acc69@mail.gmail.com> Message-ID: <67e65dc5-321e-4959-816a-7bdd091026e1@b2g2000yqi.googlegroups.com> > > The very first test I thought up was "this method should return an > > integer" so kind of a basic test for a not yet existent method. > > Isn't this a bit anti-ruby though. Surely the things we should be testing is > that the object exists, responds to certain messages and gives certain > values back for those messages. Thinking about types is so Java, C++ :-) Yeah, though it's a bit hard when it's supposed to return the pid of some external process :) -r From apremdas at gmail.com Sun Jan 3 16:29:29 2010 From: apremdas at gmail.com (Andrew Premdas) Date: Sun, 3 Jan 2010 21:29:29 +0000 Subject: [rspec-users] more verbosity for be_an? In-Reply-To: <67e65dc5-321e-4959-816a-7bdd091026e1@b2g2000yqi.googlegroups.com> References: <57c63afe0912301219l43937dc6he78256e600eeeb30@mail.gmail.com> <88fd8ddc1001021323o5537de65x8519b91c867acc69@mail.gmail.com> <67e65dc5-321e-4959-816a-7bdd091026e1@b2g2000yqi.googlegroups.com> Message-ID: <88fd8ddc1001031329hf205636lff2c3c889e3166e5@mail.gmail.com> 2010/1/3 rogerdpack > > > The very first test I thought up was "this method should return an > > > integer" so kind of a basic test for a not yet existent method. > > > > Isn't this a bit anti-ruby though. Surely the things we should be testing > is > > that the object exists, responds to certain messages and gives certain > > values back for those messages. Thinking about types is so Java, C++ :-) > > Yeah, though it's a bit hard when it's supposed to return the pid of > some external process :) > > Well your pid could be a string or an integer, or even some a bizarre proprietary un-docomented PID construct from planet foo . But as far as Ruby is concerned you'll be getting back an object thats for sure, and anything else is completely up in the air. However as soon as you start specifying that a Fixnum should be returned, then you've removed the possibility of receiving a string or a bizarre proprietary un-docomented PID construct from planet foo. This is very anti-ruby (its a dynamic language). And it means that your method will have to do all sorts of type conversion rubbish to go from String, 'construct to Fixnum to pass your test. In ruby all your interested in is that you get something that responds to to_s (to_i) and gives you a suitable value -r > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From apremdas at gmail.com Sun Jan 3 16:39:41 2010 From: apremdas at gmail.com (Andrew Premdas) Date: Sun, 3 Jan 2010 21:39:41 +0000 Subject: [rspec-users] more verbosity for be_an? In-Reply-To: <57c63afe1001021335m326fda84jca91d57962a70182@mail.gmail.com> References: <57c63afe0912301219l43937dc6he78256e600eeeb30@mail.gmail.com> <88fd8ddc1001021323o5537de65x8519b91c867acc69@mail.gmail.com> <57c63afe1001021335m326fda84jca91d57962a70182@mail.gmail.com> Message-ID: <88fd8ddc1001031339l7ab8fe76p76f6b1ba64ff5327@mail.gmail.com> 2010/1/2 David Chelimsky > > > On Sat, Jan 2, 2010 at 3:23 PM, Andrew Premdas wrote: > >> 2009/12/30 rogerdpack >> >> > What about something like: >>> > >>> > expected # => Fixnum to be a kind of Fixnum >>> > >>> > That is more aligned with other failure messages. WDYT? >>> >>> I quite like it. >>> In this instance it was >>> >>> 3.class.should be_a Fixnum # fails >>> >>> I suppose it would be something like >>> expected # => Class to be a kind of Fixnum >>> >>> ? >>> >>> > And just out of curiosity, Roger, what's your use case? I can't >>> remember ever using be_a/be_an, at least not in any code that has survived. >>> >>> The very first test I thought up was "this method should return an >>> integer" so kind of a basic test for a not yet existent method. >>> >>> >> Isn't this a bit anti-ruby though. Surely the things we should be testing >> is that the object exists, responds to certain messages and gives certain >> values back for those messages. Thinking about types is so Java, C++ :-) >> > > Generally speaking, you're correct, but there are cases where this is > valuable - like if you're spec'ing a factory in a lib for others to use, > etc. > > I don't think those cases apply to this thread (judging from its context), but I can see benefits from the improved error message that may result from this discussion. Andrew > >> >> all best >> >> Andrew >> >>> -r >>> _______________________________________________ >>> 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: From timo.roessner at googlemail.com Sun Jan 3 19:56:26 2010 From: timo.roessner at googlemail.com (jollyroger) Date: Sun, 3 Jan 2010 16:56:26 -0800 (PST) Subject: [rspec-users] disabling before filters in rspec? Message-ID: Hey guys, i have this before-filter in my application-controller: def login_required if !current_user redirect_to join_welcome_path and return end end This before-filter is prepended before all other before-filters in my application_controller.rb like this prepend_before_filter :login_required, Now i want to test a controller which should only be accessible if the user is logged in like that: describe "new action" do describe "before-filter requirements are not met" do before(:each) do activate_authlogic end it "should redirect to join_welcome_path if not logged in" do controller.stub(:login_required).and_return(false) get :new response.should redirect_to(join_welcome_path) end The thing is, I would have expected this spec to pass - a call to "new" invokes the login-required before-filter which redirects to the join_welcome_path. Instead i get: NoMethodError in 'Shopping::PaymentsController new action before- filter requirements are not met should redirect to join_welcome_path if not logged in' undefined method `current_cart_size' for nil:NilClass which is from a before-filter which is triggered _after_ the login- required before-filter. How do I even get there? As far as I understood the docs, this line: controller.stub(:login_required).and_return(false) should cause a redirect, so how do i even get to subsequent before- filters? In a nutshell: Why do I even reach subsequent before-filters? What am I doing wrong here? From dchelimsky at gmail.com Mon Jan 4 05:20:39 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 4 Jan 2010 04:20:39 -0600 Subject: [rspec-users] disabling before filters in rspec? In-Reply-To: References: Message-ID: <57c63afe1001040220h790a7c64m6f14cf3f7ad5c688@mail.gmail.com> On Sun, Jan 3, 2010 at 6:56 PM, jollyroger wrote: > Hey guys, > > i have this before-filter in my application-controller: > > def login_required > if !current_user > redirect_to join_welcome_path and return > end > end > > This before-filter is prepended before all other before-filters in my > application_controller.rb like this > > prepend_before_filter :login_required, > > Now i want to test a controller which should only be accessible if > the user is logged in like that: > > describe "new action" do > > describe "before-filter requirements are not met" do > > before(:each) do > activate_authlogic > end > > it "should redirect to join_welcome_path if not logged in" do > controller.stub(:login_required).and_return(false) > get :new > response.should redirect_to(join_welcome_path) > end > > The thing is, I would have expected this spec to pass - a call to > "new" invokes the login-required before-filter which redirects to the > join_welcome_path. > > Instead i get: > > NoMethodError in 'Shopping::PaymentsController new action before- > filter requirements are not met should redirect to join_welcome_path > if not logged in' > undefined method `current_cart_size' for nil:NilClass > > which is from a before-filter which is triggered _after_ the login- > required before-filter. > > How do I even get there? > As far as I understood the docs, this line: > > controller.stub(:login_required).and_return(false) > > should cause a redirect, That is not correct. That line completely replaces the login_required() method with a stub that returns false. The code in the real login_required() method is not executed at all, and therefore the redirect does not happen. > so how do i even get to subsequent before- > filters? Filters only halt execution if they invoke a redirect or return. In this case, because the filter is stubbed and the redirect is never called, execution continues. In a nutshell: > > Why do I even reach subsequent before-filters? > What am I doing wrong here? > You have a couple of options here, but I think the simplest thing would be to stub current_user instead of login_required: it "should redirect to join_welcome_path if not logged in" do controller.stub(:current_user).and_return(nil) get :new response.should redirect_to(join_welcome_path) end HTH, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From ijonas.kisselbach at gmail.com Mon Jan 4 05:33:38 2010 From: ijonas.kisselbach at gmail.com (Ijonas Kisselbach) Date: Mon, 4 Jan 2010 10:33:38 +0000 Subject: [rspec-users] Question about structuring specs Message-ID: <510d57f61001040233m562f137du1e1ca16fa9f75714@mail.gmail.com> Hi, I'm struggling with structuring my specs describing a large process in my app. There are multiple paths of execution through that process each of which I'm trying to describe using a different rspec context, eg. describe Violation do context ", when nothing has changed since the last run" context ", when new content has been created, but policies remain the same" context ", when new policies are activated, but content remains the same" end Each of the three scenarios/context above have got a bunch of "it should..." blocks in it which in turn contain a whole bunch of should_receives and should_not_receives on various mocked objects, thereby exercising the functionality of the large process. I would like the context to read as follows: context ", when new policies are activated, but content remains the same" do it "should create the new policy" do # a whole bunch of expectations testing the policy creation part of the process end it "should create a new violation and location" do # a whole bunch of expectations testing the violation creation part of the process end it "should resolve previous violations" do # a whole bunch of expections testing retrieval of previous violations and performing updates on them end .... end The problem is: if I compartmentalize my expectations into the individual it-should-blocks then something will fail in the execution of the large process, typically caused by a mock not being setup. If I lump all my expectations in the before(:each)-block then the whole thing springs to life, but I lose my compartmentalization of the specs and the whole thing becomes unreadable. I guess I'm looking for help and advice on how best combat the lumping of expectations into the before-block. Should I separate my stubbing from my expectations ? Many thanks for your advice. (I'm using rspec 1.2.9 and Rails 2.2.2 on OSX) Regards, Ijonas. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Mon Jan 4 06:16:14 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 4 Jan 2010 05:16:14 -0600 Subject: [rspec-users] Question about structuring specs In-Reply-To: <510d57f61001040233m562f137du1e1ca16fa9f75714@mail.gmail.com> References: <510d57f61001040233m562f137du1e1ca16fa9f75714@mail.gmail.com> Message-ID: <57c63afe1001040316k40c050ado361175883a69ea6e@mail.gmail.com> On Mon, Jan 4, 2010 at 4:33 AM, Ijonas Kisselbach < ijonas.kisselbach at gmail.com> wrote: > Hi, > > I'm struggling with structuring my specs describing a large process in my > app. There are multiple paths of execution through that process each of > which I'm trying to describe using a different rspec context, eg. > > describe Violation do > context ", when nothing has changed since the last run" > context ", when new content has been created, but policies remain the > same" > context ", when new policies are activated, but content remains the > same" > end > > Each of the three scenarios/context above have got a bunch of "it > should..." blocks in it which in turn contain a whole bunch of > should_receives and should_not_receives on various mocked objects, thereby > exercising the functionality of the large process. > > I would like the context to read as follows: > > context ", when new policies are activated, but content remains the same" > do > it "should create the new policy" do > # a whole bunch of expectations testing the policy creation part of > the process > end > it "should create a new violation and location" do > # a whole bunch of expectations testing the violation creation part of > the process > end > it "should resolve previous violations" do > # a whole bunch of expections testing retrieval of previous violations > and performing updates on them > end > .... > end > > The problem is: if I compartmentalize my expectations into the individual > it-should-blocks then something will fail in the execution of the large > process, typically caused by a mock not being setup. If I lump all my > expectations in the before(:each)-block then the whole thing springs to > life, but I lose my compartmentalization of the specs and the whole thing > becomes unreadable. > > I guess I'm looking for help and advice on how best combat the lumping of > expectations into the before-block. Should I separate my stubbing from my > expectations ? > > Many thanks for your advice. > I'd need to see the actual code to respond in any precise way here, but generally, it sounds like you're specifying too much about the implementation rather than the outcomes. What happens if you eliminate all of the mocks in these examples and just have expectations like "Policy.find(@policy_id).should_not be_nil"? David > > (I'm using rspec 1.2.9 and Rails 2.2.2 on OSX) > > Regards, > Ijonas. -------------- next part -------------- An HTML attachment was scrubbed... URL: From timo.roessner at googlemail.com Mon Jan 4 06:20:41 2010 From: timo.roessner at googlemail.com (jollyroger) Date: Mon, 4 Jan 2010 03:20:41 -0800 (PST) Subject: [rspec-users] disabling before filters in rspec? In-Reply-To: <57c63afe1001040220h790a7c64m6f14cf3f7ad5c688@mail.gmail.com> References: <57c63afe1001040220h790a7c64m6f14cf3f7ad5c688@mail.gmail.com> Message-ID: <287fc8e0-b61d-4ca0-ba09-1ff5e4567790@e27g2000yqd.googlegroups.com> Hi David, well, the way you put it it all sounds totally logical...:-) Thanks a lot for the suggestions, I guess I need to improve my specs.... On Jan 4, 11:20?am, David Chelimsky wrote: > On Sun, Jan 3, 2010 at 6:56 PM, jollyroger wrote: > > > > > Hey guys, > > > i have this before-filter in my application-controller: > > > ?def login_required > > ? ?if !current_user > > ? ? ?redirect_to join_welcome_path and return > > ? ?end > > ?end > > > This before-filter is prepended before all other before-filters in my > > application_controller.rb like this > > > ?prepend_before_filter :login_required, > > > Now i want ?to test ?a controller which should only be accessible if > > the user is logged in like that: > > > ?describe "new action" do > > > ? ?describe "before-filter requirements are not met" do > > > ? ? ?before(:each) do > > ? ? ? ?activate_authlogic > > ? ? ?end > > > ? ? ?it "should redirect to join_welcome_path if not logged in" do > > ? ? ? ?controller.stub(:login_required).and_return(false) > > ? ? ? ?get :new > > ? ? ? ?response.should redirect_to(join_welcome_path) > > ? ? ? end > > > The thing is, I would have expected this spec to pass - a call to > > "new" invokes the login-required before-filter which redirects to the > > join_welcome_path. > > > Instead i get: > > > NoMethodError in 'Shopping::PaymentsController new action before- > > filter requirements are not met should redirect to join_welcome_path > > if not logged in' > > undefined method `current_cart_size' for nil:NilClass > > > which is from a before-filter which is triggered _after_ the login- > > required before-filter. > > > How do I even get there? > > As far as I understood the docs, this line: > > > ?controller.stub(:login_required).and_return(false) > > > should cause a redirect, > > That is not correct. That line completely replaces the login_required() > method with a stub that returns false. The code in the real login_required() > method is not executed at all, and therefore the redirect does not happen. > > > so how do i even get to subsequent before- > > filters? > > Filters only halt execution if they invoke a redirect or return. In this > case, because the filter is stubbed and the redirect is never called, > execution continues. > > In a nutshell: > > > > > Why do I even reach subsequent before-filters? > > What am I doing wrong here? > > You have a couple of options here, but I think the simplest thing would be > to stub current_user instead of login_required: > > it "should redirect to join_welcome_path if not logged in" do > ? controller.stub(:current_user).and_return(nil) > ? get :new > ? response.should redirect_to(join_welcome_path) > end > > HTH, > David > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From ijonas.kisselbach at gmail.com Mon Jan 4 06:26:42 2010 From: ijonas.kisselbach at gmail.com (Ijonas Kisselbach) Date: Mon, 4 Jan 2010 11:26:42 +0000 Subject: [rspec-users] Question about structuring specs In-Reply-To: <57c63afe1001040316k40c050ado361175883a69ea6e@mail.gmail.com> References: <510d57f61001040233m562f137du1e1ca16fa9f75714@mail.gmail.com> <57c63afe1001040316k40c050ado361175883a69ea6e@mail.gmail.com> Message-ID: <510d57f61001040326w70db3372pca9ce80b8cc8f9f7@mail.gmail.com> Hi David, I see your point about concentrating on outcomes rather than implementation. I suppose who cares about implementation, its the effect code on the "state of the world" that is important. Here's an unmodified sample: context ", when a new policy is activated on unchanged content" do before(:each) do setup_common_mocks end it "should create a new policy, the new violation and location, resolve previous violations, recalculate location MD5, and refresh caches" do # content hasn't changed @content = mock(:content, :content_md5 => "84290324908230948", :most_recent_violations => [mock(:violation_mr, :update_folder_count => nil)]) @content_descriptor = mock(:content_descriptor, :contents => [@content], :most_recent_content => @content, :folder => mock(:folder)) ContentDescriptor.should_receive(:by_path_md5_and_site).once.and_return([@content_descriptor]) # Policy is new, gets created once Policy.should_receive(:find_by_account_category_and_name).once PolicyCategory.should_receive(:find_by_account_and_name).once.and_return(mock(:policy_category)) Policy.should_receive(:create!).once.and_return(mock(:policy)) # below are the changes affected Violation.should_receive(:resolve_violations).once Violation.should_receive(:recalculate_violation_md5).once.and_return(10) Violation.should_receive(:find_by_content_id_and_policy_id).once.and_return(nil) violation = mock(:new_violation1, :location_md5= => nil, :save => true) Violation.should_receive(:new).once.and_return(violation) violation.should_receive(:save).once Location.should_receive(:create!).once.and_return(mock(:location1)) @content.should_receive(:most_recent_violations=).once @content.should_receive(:unresolved_violation_count=).once @content.should_receive(:save).once CacheMaintenance.should_receive(:remove_folder_cache_keys).twice record end end I'm going to try and refactor the specs so that anything that doesn't directly modify state of the app is removed. Thanks, Ijonas. On Mon, Jan 4, 2010 at 11:16 AM, David Chelimsky wrote: > On Mon, Jan 4, 2010 at 4:33 AM, Ijonas Kisselbach < > ijonas.kisselbach at gmail.com> wrote: > >> Hi, >> >> I'm struggling with structuring my specs describing a large process in my >> app. There are multiple paths of execution through that process each of >> which I'm trying to describe using a different rspec context, eg. >> >> describe Violation do >> context ", when nothing has changed since the last run" >> context ", when new content has been created, but policies remain the >> same" >> context ", when new policies are activated, but content remains the >> same" >> end >> >> Each of the three scenarios/context above have got a bunch of "it >> should..." blocks in it which in turn contain a whole bunch of >> should_receives and should_not_receives on various mocked objects, thereby >> exercising the functionality of the large process. >> >> I would like the context to read as follows: >> >> context ", when new policies are activated, but content remains the same" >> do >> it "should create the new policy" do >> # a whole bunch of expectations testing the policy creation part of >> the process >> end >> it "should create a new violation and location" do >> # a whole bunch of expectations testing the violation creation part >> of the process >> end >> it "should resolve previous violations" do >> # a whole bunch of expections testing retrieval of previous >> violations and performing updates on them >> end >> .... >> end >> >> The problem is: if I compartmentalize my expectations into the individual >> it-should-blocks then something will fail in the execution of the large >> process, typically caused by a mock not being setup. If I lump all my >> expectations in the before(:each)-block then the whole thing springs to >> life, but I lose my compartmentalization of the specs and the whole thing >> becomes unreadable. >> >> I guess I'm looking for help and advice on how best combat the lumping of >> expectations into the before-block. Should I separate my stubbing from my >> expectations ? >> >> Many thanks for your advice. >> > > I'd need to see the actual code to respond in any precise way here, but > generally, it sounds like you're specifying too much about the > implementation rather than the outcomes. What happens if you eliminate all > of the mocks in these examples and just have expectations like > "Policy.find(@policy_id).should_not be_nil"? > > David > > >> >> (I'm using rspec 1.2.9 and Rails 2.2.2 on OSX) >> >> Regards, >> Ijonas. > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Mon Jan 4 07:56:09 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 4 Jan 2010 06:56:09 -0600 Subject: [rspec-users] Question about structuring specs In-Reply-To: <510d57f61001040326w70db3372pca9ce80b8cc8f9f7@mail.gmail.com> References: <510d57f61001040233m562f137du1e1ca16fa9f75714@mail.gmail.com> <57c63afe1001040316k40c050ado361175883a69ea6e@mail.gmail.com> <510d57f61001040326w70db3372pca9ce80b8cc8f9f7@mail.gmail.com> Message-ID: <57c63afe1001040456s5cc46a4and2a2c23bb7ca94a4@mail.gmail.com> On Mon, Jan 4, 2010 at 5:26 AM, Ijonas Kisselbach < ijonas.kisselbach at gmail.com> wrote: > Hi David, > > I see your point about concentrating on outcomes rather than > implementation. I suppose who cares about implementation, its the effect > code on the "state of the world" that is important. > > Here's an unmodified sample: > context ", when a new policy is activated on unchanged content" do > before(:each) do > setup_common_mocks > end > > it "should create a new policy, the new violation and location, resolve > previous violations, recalculate location MD5, and refresh caches" do > # content hasn't changed > @content = mock(:content, :content_md5 => "84290324908230948", > :most_recent_violations => [mock(:violation_mr, :update_folder_count => > nil)]) > @content_descriptor = mock(:content_descriptor, :contents => > [@content], :most_recent_content => @content, :folder => mock(:folder)) > > ContentDescriptor.should_receive(:by_path_md5_and_site).once.and_return([@content_descriptor]) > > > # Policy is new, gets created once > Policy.should_receive(:find_by_account_category_and_name).once > > PolicyCategory.should_receive(:find_by_account_and_name).once.and_return(mock(:policy_category)) > Policy.should_receive(:create!).once.and_return(mock(:policy)) > > # below are the changes affected > Violation.should_receive(:resolve_violations).once > > Violation.should_receive(:recalculate_violation_md5).once.and_return(10) > > Violation.should_receive(:find_by_content_id_and_policy_id).once.and_return(nil) > violation = mock(:new_violation1, :location_md5= => nil, :save => > true) > Violation.should_receive(:new).once.and_return(violation) > violation.should_receive(:save).once > > Location.should_receive(:create!).once.and_return(mock(:location1)) > > @content.should_receive(:most_recent_violations=).once > @content.should_receive(:unresolved_violation_count=).once > @content.should_receive(:save).once > CacheMaintenance.should_receive(:remove_folder_cache_keys).twice > record > end > > end > > I'm going to try and refactor the specs so that anything that doesn't > directly modify state of the app is removed. > Why are you mocking so much here? Why not set up the db in a known state, invoke the action you want to invoke (record???) and set expectations about the outcomes? If you're concerned about database access and speed, this is a case where I think the benefits of just invoking the code outweighs the cost of database access. I'm imagining something more like this: context ", when a new policy is activated on unchanged content" do it "creates a new policy" do record # expect to find the policy by known attributes # something like this: # Policy.find_by_account_category_and_name(....).should_not be_nil end it "creates a new violation" do record # same as the policy - find the Violation by known attributes end it "updates most_recent_violations" do record # query for most recent violations and expect the violation # to be found end it "updates the violation count" do expect { record }.to change {content.unresolved_violation_count}.by(1) end # etc, etc end Yes, this means that the process needs to happen more than once, but each example becomes much easier to grok. WDYT? Thanks, > Ijonas. > > On Mon, Jan 4, 2010 at 11:16 AM, David Chelimsky wrote: > >> On Mon, Jan 4, 2010 at 4:33 AM, Ijonas Kisselbach < >> ijonas.kisselbach at gmail.com> wrote: >> >>> Hi, >>> >>> I'm struggling with structuring my specs describing a large process in my >>> app. There are multiple paths of execution through that process each of >>> which I'm trying to describe using a different rspec context, eg. >>> >>> describe Violation do >>> context ", when nothing has changed since the last run" >>> context ", when new content has been created, but policies remain the >>> same" >>> context ", when new policies are activated, but content remains the >>> same" >>> end >>> >>> Each of the three scenarios/context above have got a bunch of "it >>> should..." blocks in it which in turn contain a whole bunch of >>> should_receives and should_not_receives on various mocked objects, thereby >>> exercising the functionality of the large process. >>> >>> I would like the context to read as follows: >>> >>> context ", when new policies are activated, but content remains the same" >>> do >>> it "should create the new policy" do >>> # a whole bunch of expectations testing the policy creation part of >>> the process >>> end >>> it "should create a new violation and location" do >>> # a whole bunch of expectations testing the violation creation part >>> of the process >>> end >>> it "should resolve previous violations" do >>> # a whole bunch of expections testing retrieval of previous >>> violations and performing updates on them >>> end >>> .... >>> end >>> >>> The problem is: if I compartmentalize my expectations into the individual >>> it-should-blocks then something will fail in the execution of the large >>> process, typically caused by a mock not being setup. If I lump all my >>> expectations in the before(:each)-block then the whole thing springs to >>> life, but I lose my compartmentalization of the specs and the whole thing >>> becomes unreadable. >>> >>> I guess I'm looking for help and advice on how best combat the lumping of >>> expectations into the before-block. Should I separate my stubbing from my >>> expectations ? >>> >>> Many thanks for your advice. >>> >> >> I'd need to see the actual code to respond in any precise way here, but >> generally, it sounds like you're specifying too much about the >> implementation rather than the outcomes. What happens if you eliminate all >> of the mocks in these examples and just have expectations like >> "Policy.find(@policy_id).should_not be_nil"? >> >> David >> >> >>> >>> (I'm using rspec 1.2.9 and Rails 2.2.2 on OSX) >>> >>> Regards, >>> Ijonas. >> >> >> _______________________________________________ >> 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: From ijonas.kisselbach at gmail.com Mon Jan 4 08:06:15 2010 From: ijonas.kisselbach at gmail.com (Ijonas Kisselbach) Date: Mon, 4 Jan 2010 13:06:15 +0000 Subject: [rspec-users] Question about structuring specs In-Reply-To: <57c63afe1001040456s5cc46a4and2a2c23bb7ca94a4@mail.gmail.com> References: <510d57f61001040233m562f137du1e1ca16fa9f75714@mail.gmail.com> <57c63afe1001040316k40c050ado361175883a69ea6e@mail.gmail.com> <510d57f61001040326w70db3372pca9ce80b8cc8f9f7@mail.gmail.com> <57c63afe1001040456s5cc46a4and2a2c23bb7ca94a4@mail.gmail.com> Message-ID: <510d57f61001040506k6f3b4a00w901bfc445b18b554@mail.gmail.com> Hi David, Thanks for the suggestions... Yes I am mocking to avoid DB access, but if the cost is DB access vs. readability: I'll choose readability. Would you use something like Factory Girl or Machinist to setup the DB? To avoid too much mocking and to avoid old-skool fixtures. Thanks for the help. On Mon, Jan 4, 2010 at 12:56 PM, David Chelimsky wrote: > On Mon, Jan 4, 2010 at 5:26 AM, Ijonas Kisselbach < > ijonas.kisselbach at gmail.com> wrote: > >> Hi David, >> >> I see your point about concentrating on outcomes rather than >> implementation. I suppose who cares about implementation, its the effect >> code on the "state of the world" that is important. >> >> Here's an unmodified sample: >> context ", when a new policy is activated on unchanged content" do >> before(:each) do >> setup_common_mocks >> end >> >> it "should create a new policy, the new violation and location, >> resolve previous violations, recalculate location MD5, and refresh caches" >> do >> # content hasn't changed >> @content = mock(:content, :content_md5 => "84290324908230948", >> :most_recent_violations => [mock(:violation_mr, :update_folder_count => >> nil)]) >> @content_descriptor = mock(:content_descriptor, :contents => >> [@content], :most_recent_content => @content, :folder => mock(:folder)) >> >> ContentDescriptor.should_receive(:by_path_md5_and_site).once.and_return([@content_descriptor]) >> >> >> # Policy is new, gets created once >> Policy.should_receive(:find_by_account_category_and_name).once >> >> PolicyCategory.should_receive(:find_by_account_and_name).once.and_return(mock(:policy_category)) >> Policy.should_receive(:create!).once.and_return(mock(:policy)) >> >> # below are the changes affected >> Violation.should_receive(:resolve_violations).once >> >> Violation.should_receive(:recalculate_violation_md5).once.and_return(10) >> >> Violation.should_receive(:find_by_content_id_and_policy_id).once.and_return(nil) >> violation = mock(:new_violation1, :location_md5= => nil, :save => >> true) >> Violation.should_receive(:new).once.and_return(violation) >> violation.should_receive(:save).once >> >> Location.should_receive(:create!).once.and_return(mock(:location1)) >> >> @content.should_receive(:most_recent_violations=).once >> @content.should_receive(:unresolved_violation_count=).once >> @content.should_receive(:save).once >> CacheMaintenance.should_receive(:remove_folder_cache_keys).twice >> record >> end >> >> end >> >> I'm going to try and refactor the specs so that anything that doesn't >> directly modify state of the app is removed. >> > > Why are you mocking so much here? Why not set up the db in a known state, > invoke the action you want to invoke (record???) and set expectations about > the outcomes? If you're concerned about database access and speed, this is a > case where I think the benefits of just invoking the code outweighs the cost > of database access. I'm imagining something more like this: > > context ", when a new policy is activated on unchanged content" do > it "creates a new policy" do > record > # expect to find the policy by known attributes > # something like this: > # Policy.find_by_account_category_and_name(....).should_not be_nil > end > > it "creates a new violation" do > record > # same as the policy - find the Violation by known attributes > end > > it "updates most_recent_violations" do > record > # query for most recent violations and expect the violation > # to be found > end > > it "updates the violation count" do > expect { record }.to change {content.unresolved_violation_count}.by(1) > end > > # etc, etc > end > > Yes, this means that the process needs to happen more than once, but each > example becomes much easier to grok. > > WDYT? > > Thanks, >> Ijonas. >> >> On Mon, Jan 4, 2010 at 11:16 AM, David Chelimsky wrote: >> >>> On Mon, Jan 4, 2010 at 4:33 AM, Ijonas Kisselbach < >>> ijonas.kisselbach at gmail.com> wrote: >>> >>>> Hi, >>>> >>>> I'm struggling with structuring my specs describing a large process in >>>> my app. There are multiple paths of execution through that process each of >>>> which I'm trying to describe using a different rspec context, eg. >>>> >>>> describe Violation do >>>> context ", when nothing has changed since the last run" >>>> context ", when new content has been created, but policies remain the >>>> same" >>>> context ", when new policies are activated, but content remains the >>>> same" >>>> end >>>> >>>> Each of the three scenarios/context above have got a bunch of "it >>>> should..." blocks in it which in turn contain a whole bunch of >>>> should_receives and should_not_receives on various mocked objects, thereby >>>> exercising the functionality of the large process. >>>> >>>> I would like the context to read as follows: >>>> >>>> context ", when new policies are activated, but content remains the >>>> same" do >>>> it "should create the new policy" do >>>> # a whole bunch of expectations testing the policy creation part >>>> of the process >>>> end >>>> it "should create a new violation and location" do >>>> # a whole bunch of expectations testing the violation creation part >>>> of the process >>>> end >>>> it "should resolve previous violations" do >>>> # a whole bunch of expections testing retrieval of previous >>>> violations and performing updates on them >>>> end >>>> .... >>>> end >>>> >>>> The problem is: if I compartmentalize my expectations into the >>>> individual it-should-blocks then something will fail in the execution of the >>>> large process, typically caused by a mock not being setup. If I lump all my >>>> expectations in the before(:each)-block then the whole thing springs to >>>> life, but I lose my compartmentalization of the specs and the whole thing >>>> becomes unreadable. >>>> >>>> I guess I'm looking for help and advice on how best combat the lumping >>>> of expectations into the before-block. Should I separate my stubbing from my >>>> expectations ? >>>> >>>> Many thanks for your advice. >>>> >>> >>> I'd need to see the actual code to respond in any precise way here, but >>> generally, it sounds like you're specifying too much about the >>> implementation rather than the outcomes. What happens if you eliminate all >>> of the mocks in these examples and just have expectations like >>> "Policy.find(@policy_id).should_not be_nil"? >>> >>> David >>> >>> >>>> >>>> (I'm using rspec 1.2.9 and Rails 2.2.2 on OSX) >>>> >>>> Regards, >>>> Ijonas. >>> >>> >>> _______________________________________________ >>> 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: From dchelimsky at gmail.com Mon Jan 4 08:08:30 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 4 Jan 2010 07:08:30 -0600 Subject: [rspec-users] Question about structuring specs In-Reply-To: <510d57f61001040506k6f3b4a00w901bfc445b18b554@mail.gmail.com> References: <510d57f61001040233m562f137du1e1ca16fa9f75714@mail.gmail.com> <57c63afe1001040316k40c050ado361175883a69ea6e@mail.gmail.com> <510d57f61001040326w70db3372pca9ce80b8cc8f9f7@mail.gmail.com> <57c63afe1001040456s5cc46a4and2a2c23bb7ca94a4@mail.gmail.com> <510d57f61001040506k6f3b4a00w901bfc445b18b554@mail.gmail.com> Message-ID: <57c63afe1001040508w75cdddefh396aeeb429ae68c1@mail.gmail.com> On Mon, Jan 4, 2010 at 7:06 AM, Ijonas Kisselbach < ijonas.kisselbach at gmail.com> wrote: > Hi David, > > Thanks for the suggestions... Yes I am mocking to avoid DB access, but if > the cost is DB access vs. readability: I'll choose readability. > > Would you use something like Factory Girl or Machinist to setup the DB? To > avoid too much mocking and to avoid old-skool fixtures. > YES! Thanks for the help. > Assuming it was helpful, you're welcome. Cheers, David > > On Mon, Jan 4, 2010 at 12:56 PM, David Chelimsky wrote: > >> On Mon, Jan 4, 2010 at 5:26 AM, Ijonas Kisselbach < >> ijonas.kisselbach at gmail.com> wrote: >> >>> Hi David, >>> >>> I see your point about concentrating on outcomes rather than >>> implementation. I suppose who cares about implementation, its the effect >>> code on the "state of the world" that is important. >>> >>> Here's an unmodified sample: >>> context ", when a new policy is activated on unchanged content" do >>> before(:each) do >>> setup_common_mocks >>> end >>> >>> it "should create a new policy, the new violation and location, >>> resolve previous violations, recalculate location MD5, and refresh caches" >>> do >>> # content hasn't changed >>> @content = mock(:content, :content_md5 => "84290324908230948", >>> :most_recent_violations => [mock(:violation_mr, :update_folder_count => >>> nil)]) >>> @content_descriptor = mock(:content_descriptor, :contents => >>> [@content], :most_recent_content => @content, :folder => mock(:folder)) >>> >>> ContentDescriptor.should_receive(:by_path_md5_and_site).once.and_return([@content_descriptor]) >>> >>> >>> # Policy is new, gets created once >>> Policy.should_receive(:find_by_account_category_and_name).once >>> >>> PolicyCategory.should_receive(:find_by_account_and_name).once.and_return(mock(:policy_category)) >>> Policy.should_receive(:create!).once.and_return(mock(:policy)) >>> >>> # below are the changes affected >>> Violation.should_receive(:resolve_violations).once >>> >>> Violation.should_receive(:recalculate_violation_md5).once.and_return(10) >>> >>> Violation.should_receive(:find_by_content_id_and_policy_id).once.and_return(nil) >>> violation = mock(:new_violation1, :location_md5= => nil, :save => >>> true) >>> Violation.should_receive(:new).once.and_return(violation) >>> violation.should_receive(:save).once >>> >>> Location.should_receive(:create!).once.and_return(mock(:location1)) >>> >>> @content.should_receive(:most_recent_violations=).once >>> @content.should_receive(:unresolved_violation_count=).once >>> @content.should_receive(:save).once >>> CacheMaintenance.should_receive(:remove_folder_cache_keys).twice >>> record >>> end >>> >>> end >>> >>> I'm going to try and refactor the specs so that anything that doesn't >>> directly modify state of the app is removed. >>> >> >> Why are you mocking so much here? Why not set up the db in a known state, >> invoke the action you want to invoke (record???) and set expectations about >> the outcomes? If you're concerned about database access and speed, this is a >> case where I think the benefits of just invoking the code outweighs the cost >> of database access. I'm imagining something more like this: >> >> context ", when a new policy is activated on unchanged content" do >> it "creates a new policy" do >> record >> # expect to find the policy by known attributes >> # something like this: >> # Policy.find_by_account_category_and_name(....).should_not be_nil >> end >> >> it "creates a new violation" do >> record >> # same as the policy - find the Violation by known attributes >> end >> >> it "updates most_recent_violations" do >> record >> # query for most recent violations and expect the violation >> # to be found >> end >> >> it "updates the violation count" do >> expect { record }.to change {content.unresolved_violation_count}.by(1) >> end >> >> # etc, etc >> end >> >> Yes, this means that the process needs to happen more than once, but each >> example becomes much easier to grok. >> >> WDYT? >> >> Thanks, >>> Ijonas. >>> >>> On Mon, Jan 4, 2010 at 11:16 AM, David Chelimsky wrote: >>> >>>> On Mon, Jan 4, 2010 at 4:33 AM, Ijonas Kisselbach < >>>> ijonas.kisselbach at gmail.com> wrote: >>>> >>>>> Hi, >>>>> >>>>> I'm struggling with structuring my specs describing a large process in >>>>> my app. There are multiple paths of execution through that process each of >>>>> which I'm trying to describe using a different rspec context, eg. >>>>> >>>>> describe Violation do >>>>> context ", when nothing has changed since the last run" >>>>> context ", when new content has been created, but policies remain >>>>> the same" >>>>> context ", when new policies are activated, but content remains the >>>>> same" >>>>> end >>>>> >>>>> Each of the three scenarios/context above have got a bunch of "it >>>>> should..." blocks in it which in turn contain a whole bunch of >>>>> should_receives and should_not_receives on various mocked objects, thereby >>>>> exercising the functionality of the large process. >>>>> >>>>> I would like the context to read as follows: >>>>> >>>>> context ", when new policies are activated, but content remains the >>>>> same" do >>>>> it "should create the new policy" do >>>>> # a whole bunch of expectations testing the policy creation part >>>>> of the process >>>>> end >>>>> it "should create a new violation and location" do >>>>> # a whole bunch of expectations testing the violation creation >>>>> part of the process >>>>> end >>>>> it "should resolve previous violations" do >>>>> # a whole bunch of expections testing retrieval of previous >>>>> violations and performing updates on them >>>>> end >>>>> .... >>>>> end >>>>> >>>>> The problem is: if I compartmentalize my expectations into the >>>>> individual it-should-blocks then something will fail in the execution of the >>>>> large process, typically caused by a mock not being setup. If I lump all my >>>>> expectations in the before(:each)-block then the whole thing springs to >>>>> life, but I lose my compartmentalization of the specs and the whole thing >>>>> becomes unreadable. >>>>> >>>>> I guess I'm looking for help and advice on how best combat the lumping >>>>> of expectations into the before-block. Should I separate my stubbing from my >>>>> expectations ? >>>>> >>>>> Many thanks for your advice. >>>>> >>>> >>>> I'd need to see the actual code to respond in any precise way here, but >>>> generally, it sounds like you're specifying too much about the >>>> implementation rather than the outcomes. What happens if you eliminate all >>>> of the mocks in these examples and just have expectations like >>>> "Policy.find(@policy_id).should_not be_nil"? >>>> >>>> David >>>> >>>> >>>>> >>>>> (I'm using rspec 1.2.9 and Rails 2.2.2 on OSX) >>>>> >>>>> Regards, >>>>> Ijonas. >>>> >>>> >>>> _______________________________________________ >>>> 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: From ijonas.kisselbach at gmail.com Mon Jan 4 08:21:22 2010 From: ijonas.kisselbach at gmail.com (Ijonas Kisselbach) Date: Mon, 4 Jan 2010 13:21:22 +0000 Subject: [rspec-users] Question about structuring specs In-Reply-To: <57c63afe1001040508w75cdddefh396aeeb429ae68c1@mail.gmail.com> References: <510d57f61001040233m562f137du1e1ca16fa9f75714@mail.gmail.com> <57c63afe1001040316k40c050ado361175883a69ea6e@mail.gmail.com> <510d57f61001040326w70db3372pca9ce80b8cc8f9f7@mail.gmail.com> <57c63afe1001040456s5cc46a4and2a2c23bb7ca94a4@mail.gmail.com> <510d57f61001040506k6f3b4a00w901bfc445b18b554@mail.gmail.com> <57c63afe1001040508w75cdddefh396aeeb429ae68c1@mail.gmail.com> Message-ID: <510d57f61001040521g4850f551l2c5f083020dbe16c@mail.gmail.com> Definitely helpful. Thanks, its much appreciated. On Mon, Jan 4, 2010 at 1:08 PM, David Chelimsky wrote: > On Mon, Jan 4, 2010 at 7:06 AM, Ijonas Kisselbach < > ijonas.kisselbach at gmail.com> wrote: > >> Hi David, >> >> Thanks for the suggestions... Yes I am mocking to avoid DB access, but if >> the cost is DB access vs. readability: I'll choose readability. >> >> Would you use something like Factory Girl or Machinist to setup the DB? To >> avoid too much mocking and to avoid old-skool fixtures. >> > > YES! > > Thanks for the help. >> > > Assuming it was helpful, you're welcome. > > Cheers, > David > > >> >> On Mon, Jan 4, 2010 at 12:56 PM, David Chelimsky wrote: >> >>> On Mon, Jan 4, 2010 at 5:26 AM, Ijonas Kisselbach < >>> ijonas.kisselbach at gmail.com> wrote: >>> >>>> Hi David, >>>> >>>> I see your point about concentrating on outcomes rather than >>>> implementation. I suppose who cares about implementation, its the effect >>>> code on the "state of the world" that is important. >>>> >>>> Here's an unmodified sample: >>>> context ", when a new policy is activated on unchanged content" do >>>> before(:each) do >>>> setup_common_mocks >>>> end >>>> >>>> it "should create a new policy, the new violation and location, >>>> resolve previous violations, recalculate location MD5, and refresh caches" >>>> do >>>> # content hasn't changed >>>> @content = mock(:content, :content_md5 => "84290324908230948", >>>> :most_recent_violations => [mock(:violation_mr, :update_folder_count => >>>> nil)]) >>>> @content_descriptor = mock(:content_descriptor, :contents => >>>> [@content], :most_recent_content => @content, :folder => mock(:folder)) >>>> >>>> ContentDescriptor.should_receive(:by_path_md5_and_site).once.and_return([@content_descriptor]) >>>> >>>> >>>> # Policy is new, gets created once >>>> Policy.should_receive(:find_by_account_category_and_name).once >>>> >>>> PolicyCategory.should_receive(:find_by_account_and_name).once.and_return(mock(:policy_category)) >>>> Policy.should_receive(:create!).once.and_return(mock(:policy)) >>>> >>>> # below are the changes affected >>>> Violation.should_receive(:resolve_violations).once >>>> >>>> Violation.should_receive(:recalculate_violation_md5).once.and_return(10) >>>> >>>> Violation.should_receive(:find_by_content_id_and_policy_id).once.and_return(nil) >>>> violation = mock(:new_violation1, :location_md5= => nil, :save => >>>> true) >>>> Violation.should_receive(:new).once.and_return(violation) >>>> violation.should_receive(:save).once >>>> >>>> >>>> Location.should_receive(:create!).once.and_return(mock(:location1)) >>>> >>>> @content.should_receive(:most_recent_violations=).once >>>> @content.should_receive(:unresolved_violation_count=).once >>>> @content.should_receive(:save).once >>>> CacheMaintenance.should_receive(:remove_folder_cache_keys).twice >>>> record >>>> end >>>> >>>> end >>>> >>>> I'm going to try and refactor the specs so that anything that doesn't >>>> directly modify state of the app is removed. >>>> >>> >>> Why are you mocking so much here? Why not set up the db in a known state, >>> invoke the action you want to invoke (record???) and set expectations about >>> the outcomes? If you're concerned about database access and speed, this is a >>> case where I think the benefits of just invoking the code outweighs the cost >>> of database access. I'm imagining something more like this: >>> >>> context ", when a new policy is activated on unchanged content" do >>> it "creates a new policy" do >>> record >>> # expect to find the policy by known attributes >>> # something like this: >>> # Policy.find_by_account_category_and_name(....).should_not be_nil >>> end >>> >>> it "creates a new violation" do >>> record >>> # same as the policy - find the Violation by known attributes >>> end >>> >>> it "updates most_recent_violations" do >>> record >>> # query for most recent violations and expect the violation >>> # to be found >>> end >>> >>> it "updates the violation count" do >>> expect { record }.to change >>> {content.unresolved_violation_count}.by(1) >>> end >>> >>> # etc, etc >>> end >>> >>> Yes, this means that the process needs to happen more than once, but each >>> example becomes much easier to grok. >>> >>> WDYT? >>> >>> Thanks, >>>> Ijonas. >>>> >>>> On Mon, Jan 4, 2010 at 11:16 AM, David Chelimsky >>> > wrote: >>>> >>>>> On Mon, Jan 4, 2010 at 4:33 AM, Ijonas Kisselbach < >>>>> ijonas.kisselbach at gmail.com> wrote: >>>>> >>>>>> Hi, >>>>>> >>>>>> I'm struggling with structuring my specs describing a large process in >>>>>> my app. There are multiple paths of execution through that process each of >>>>>> which I'm trying to describe using a different rspec context, eg. >>>>>> >>>>>> describe Violation do >>>>>> context ", when nothing has changed since the last run" >>>>>> context ", when new content has been created, but policies remain >>>>>> the same" >>>>>> context ", when new policies are activated, but content remains the >>>>>> same" >>>>>> end >>>>>> >>>>>> Each of the three scenarios/context above have got a bunch of "it >>>>>> should..." blocks in it which in turn contain a whole bunch of >>>>>> should_receives and should_not_receives on various mocked objects, thereby >>>>>> exercising the functionality of the large process. >>>>>> >>>>>> I would like the context to read as follows: >>>>>> >>>>>> context ", when new policies are activated, but content remains the >>>>>> same" do >>>>>> it "should create the new policy" do >>>>>> # a whole bunch of expectations testing the policy creation part >>>>>> of the process >>>>>> end >>>>>> it "should create a new violation and location" do >>>>>> # a whole bunch of expectations testing the violation creation >>>>>> part of the process >>>>>> end >>>>>> it "should resolve previous violations" do >>>>>> # a whole bunch of expections testing retrieval of previous >>>>>> violations and performing updates on them >>>>>> end >>>>>> .... >>>>>> end >>>>>> >>>>>> The problem is: if I compartmentalize my expectations into the >>>>>> individual it-should-blocks then something will fail in the execution of the >>>>>> large process, typically caused by a mock not being setup. If I lump all my >>>>>> expectations in the before(:each)-block then the whole thing springs to >>>>>> life, but I lose my compartmentalization of the specs and the whole thing >>>>>> becomes unreadable. >>>>>> >>>>>> I guess I'm looking for help and advice on how best combat the lumping >>>>>> of expectations into the before-block. Should I separate my stubbing from my >>>>>> expectations ? >>>>>> >>>>>> Many thanks for your advice. >>>>>> >>>>> >>>>> I'd need to see the actual code to respond in any precise way here, but >>>>> generally, it sounds like you're specifying too much about the >>>>> implementation rather than the outcomes. What happens if you eliminate all >>>>> of the mocks in these examples and just have expectations like >>>>> "Policy.find(@policy_id).should_not be_nil"? >>>>> >>>>> David >>>>> >>>>> >>>>>> >>>>>> (I'm using rspec 1.2.9 and Rails 2.2.2 on OSX) >>>>>> >>>>>> Regards, >>>>>> Ijonas. >>>>> >>>>> >>>>> _______________________________________________ >>>>> 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 >> > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tom at experthuman.com Mon Jan 4 10:16:52 2010 From: tom at experthuman.com (Tom Stuart) Date: Mon, 4 Jan 2010 15:16:52 +0000 Subject: [rspec-users] 'Expected NoMethodError, got NameError' In-Reply-To: <20091230210446.GS12080@malachai> References: <20091230210446.GS12080@malachai> Message-ID: <50CCC7C0-B6ED-48EC-8E63-716D9596F2E8@experthuman.com> On 30 Dec 2009, at 21:04, Paul Hinze wrote: > I'm fighting with this error messages that _only_ shows up in certain situations that I can't quite pin down Sounds eerily familiar: http://yehudakatz.com/2010/01/02/the-craziest-fing-bug-ive-ever-seen/ Cheers, -Tom From hi at nicolassanguinetti.info Mon Jan 4 14:16:52 2010 From: hi at nicolassanguinetti.info (=?ISO-8859-1?Q?Nicol=E1s_Sanguinetti?=) Date: Mon, 4 Jan 2010 17:16:52 -0200 Subject: [rspec-users] "RESTful" controller specs in rails Message-ID: So, what's the awesome sauce everyone is using for this? In the past I've used shared behaviors, and rspec_on_rails_on_crack to solve all the repetition in the controller specs, but I've been away from rspec for a while, and the controller specs in the rails project I'm working on are a mess. So? what's the best/recommended approach these days? Cheers, -foca From apremdas at gmail.com Mon Jan 4 15:57:22 2010 From: apremdas at gmail.com (Andrew Premdas) Date: Mon, 4 Jan 2010 20:57:22 +0000 Subject: [rspec-users] 'Expected NoMethodError, got NameError' In-Reply-To: <20091230210446.GS12080@malachai> References: <20091230210446.GS12080@malachai> Message-ID: <88fd8ddc1001041257p5acf8d11v4e0a7fbd1d8b7c63@mail.gmail.com> 2009/12/30 Paul Hinze > Given this simple cucumber feature (related to another rspec bug I am > working on): > > http://gist.github.com/266335 > > I'm fighting with this error messages that _only_ shows up in certain > situations that I can't quite pin down (rake features breaks, individual > cucumber run works, rake with debugger beforehand works...) > > > expected NoMethodError, got # method `nap' for Time:Class > > ./features/step_definitions/stubs_dont_leak_steps.rb:10:in `/^nap time > should not be defined$/' > > features/either/stubs_dont_leak.feature:11:in `Then nap time should not > be defined' > > I've tracked it down to this line: > > http://github.com/dchelimsky/rspec/blob/master/lib/spec/mocks/proxy.rb#L117 This method is really unpleasant, perhaps some standard refactorings to remove the complex conditional conditions and remove the nested if's would be useful first of all. > > def message_received(sym, *args, &block) > expectation = find_matching_expectation(sym, *args) > stub = find_matching_method_stub(sym, *args) > > if (stub && expectation && expectation.called_max_times?) || (stub && > !expectation) > if expectation = find_almost_matching_expectation(sym, *args) > expectation.advise(args, block) unless > expectation.expected_messages_received? > end > stub.invoke(*args, &block) > elsif expectation > expectation.invoke(*args, &block) > elsif expectation = find_almost_matching_expectation(sym, *args) > expectation.advise(args, block) if null_object? unless > expectation.expected_messages_received? > raise_unexpected_message_args_error(expectation, *args) unless > (has_negative_expectation?(sym) or null_object?) > else > --> @target.__send__ :method_missing, sym, *args, &block > end > end > > My question is this... why do we fall back to method_missing here rather > than a simple 'send' to the target? I figure there is likely a reason, > so if someone could help me understand I'll happily open up my > expectation to should_raise(NameError) and move along. :) > > Cheers, > > Paul > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Mon Jan 4 16:00:29 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 4 Jan 2010 15:00:29 -0600 Subject: [rspec-users] 'Expected NoMethodError, got NameError' In-Reply-To: <88fd8ddc1001041257p5acf8d11v4e0a7fbd1d8b7c63@mail.gmail.com> References: <20091230210446.GS12080@malachai> <88fd8ddc1001041257p5acf8d11v4e0a7fbd1d8b7c63@mail.gmail.com> Message-ID: <57c63afe1001041300q2ebf4055q2c2c7c6fb48b54f3@mail.gmail.com> On Mon, Jan 4, 2010 at 2:57 PM, Andrew Premdas wrote: > 2009/12/30 Paul Hinze > > Given this simple cucumber feature (related to another rspec bug I am >> working on): >> >> http://gist.github.com/266335 >> >> I'm fighting with this error messages that _only_ shows up in certain >> situations that I can't quite pin down (rake features breaks, individual >> cucumber run works, rake with debugger beforehand works...) >> >> > expected NoMethodError, got #> method `nap' for Time:Class >> > ./features/step_definitions/stubs_dont_leak_steps.rb:10:in `/^nap time >> should not be defined$/' >> > features/either/stubs_dont_leak.feature:11:in `Then nap time should not >> be defined' >> >> I've tracked it down to this line: >> >> >> http://github.com/dchelimsky/rspec/blob/master/lib/spec/mocks/proxy.rb#L117 > > > This method is really unpleasant, perhaps some standard refactorings to > remove the complex conditional conditions and remove the nested if's would > be useful first of all. > Agreed. Patches welcome! > def message_received(sym, *args, &block) >> expectation = find_matching_expectation(sym, *args) >> stub = find_matching_method_stub(sym, *args) >> >> if (stub && expectation && expectation.called_max_times?) || (stub && >> !expectation) >> if expectation = find_almost_matching_expectation(sym, *args) >> expectation.advise(args, block) unless >> expectation.expected_messages_received? >> end >> stub.invoke(*args, &block) >> elsif expectation >> expectation.invoke(*args, &block) >> elsif expectation = find_almost_matching_expectation(sym, *args) >> expectation.advise(args, block) if null_object? unless >> expectation.expected_messages_received? >> raise_unexpected_message_args_error(expectation, *args) unless >> (has_negative_expectation?(sym) or null_object?) >> else >> --> @target.__send__ :method_missing, sym, *args, &block >> end >> end >> >> My question is this... why do we fall back to method_missing here rather >> than a simple 'send' to the target? I figure there is likely a reason, >> so if someone could help me understand I'll happily open up my >> expectation to should_raise(NameError) and move along. :) >> >> Cheers, >> >> Paul >> _______________________________________________ >> 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: From mailinglists at patmaddox.com Mon Jan 4 17:46:20 2010 From: mailinglists at patmaddox.com (Pat Maddox) Date: Mon, 4 Jan 2010 14:46:20 -0800 Subject: [rspec-users] "RESTful" controller specs in rails In-Reply-To: References: Message-ID: I use resource_controller, and then don't need to write controller specs because it's all boiler-plate. If I add any custom behavior that needs more focused testing than cucumber provides, I can just write a couple specs to cover it. Pat On Jan 4, 2010, at 11:16 AM, Nicol?s Sanguinetti wrote: > So, what's the awesome sauce everyone is using for this? In the past > I've used shared behaviors, and rspec_on_rails_on_crack to solve all > the repetition in the controller specs, but I've been away from rspec > for a while, and the controller specs in the rails project I'm working > on are a mess. So? what's the best/recommended approach these days? > > Cheers, > -foca > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From tom at experthuman.com Mon Jan 4 18:02:51 2010 From: tom at experthuman.com (Tom Stuart) Date: Mon, 4 Jan 2010 23:02:51 +0000 Subject: [rspec-users] "RESTful" controller specs in rails In-Reply-To: References: Message-ID: On 4 Jan 2010, at 22:46, Pat Maddox wrote: > I use resource_controller, and then don't need to write controller specs because it's all boiler-plate. If I add any custom behavior that needs more focused testing than cucumber provides, I can just write a couple specs to cover it. Ditto: I use resources_controller (note different name!), which already has comprehensive tests, and only write specs for any non-boilerplate behaviour which I add. Cheers, -Tom From paul.t.hinze at gmail.com Mon Jan 4 21:58:49 2010 From: paul.t.hinze at gmail.com (Paul Hinze) Date: Mon, 4 Jan 2010 20:58:49 -0600 Subject: [rspec-users] Loading numerous data structures from YAML files In-Reply-To: <4B3FC4B3.5080001@poggs.co.uk> References: <4B3F2B59.8000700@poggs.co.uk> <4f5cdb8b-068e-4b0c-803a-7fd0ebb57ef7@21g2000yqj.googlegroups.com> <4B3FC4B3.5080001@poggs.co.uk> Message-ID: <20100105025849.GC6554@malachai> Peter Hicks on 2010-01-02 at 16:13: > Hi Phillip > > Phillip Koebbe wrote: > >> Have you read about fixtures? It sounds like just what you're looking >> for. > > I'm using fixtures already - they're great. I can't find a way to load a > specific fixture in to a table. If I could do that, I could load a set of > data, run the code, check the results, and repeat again for the next test. My group has mostly moved off fixtures towards factory_girl, but we still depend on a couple of tables' worth of data to get a basic environment set up for some of our cucumber features. For this I use the little-documented method that is used internally by ActiveRecord::Fixtures called 'create_fixtures'. > create_fixtures(fixtures_directory, table_names, class_names = {}) http://apidock.com/rails/Fixtures/create_fixtures/class Since it accepts a directory first, you can store the YAML files wherever you'd like, and load them when you choose -- in spec/spec_helper.rb or in individual example groups if you wanted. Here's a snippet from my features/support/env.rb to give you an idea: Fixtures.create_fixtures('test/fixtures', 'roles') Fixtures.create_fixtures('test/fixtures', 'role_members') Fixtures.create_fixtures('test/fixtures', 'rights') Hope this helps! Paul From dchelimsky at gmail.com Tue Jan 5 03:38:37 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 5 Jan 2010 02:38:37 -0600 Subject: [rspec-users] 'Expected NoMethodError, got NameError' In-Reply-To: <57c63afe1001041300q2ebf4055q2c2c7c6fb48b54f3@mail.gmail.com> References: <20091230210446.GS12080@malachai> <88fd8ddc1001041257p5acf8d11v4e0a7fbd1d8b7c63@mail.gmail.com> <57c63afe1001041300q2ebf4055q2c2c7c6fb48b54f3@mail.gmail.com> Message-ID: <57c63afe1001050038l38c71741pc931ac63fbd4c621@mail.gmail.com> On Mon, Jan 4, 2010 at 3:00 PM, David Chelimsky wrote: > >>> >>> http://github.com/dchelimsky/rspec/blob/master/lib/spec/mocks/proxy.rb#L117 >> >> >> This method is really unpleasant, perhaps some standard refactorings to >> remove the complex conditional conditions and remove the nested if's would >> be useful first of all. >> > http://github.com/dchelimsky/rspec/commit/386e3347ed7cecbb2ea3095909b93ac8c97bb638 -------------- next part -------------- An HTML attachment was scrubbed... URL: From matt-lists at reprocessed.org Tue Jan 5 07:17:44 2010 From: matt-lists at reprocessed.org (Matt Patterson) Date: Tue, 5 Jan 2010 12:17:44 +0000 Subject: [rspec-users] describe "RSpec's documentation" do In-Reply-To: <98A6AC6B-BECC-4564-AF04-C49429AC7C75@mattwynne.net> References: <98A6AC6B-BECC-4564-AF04-C49429AC7C75@mattwynne.net> Message-ID: On 9 Nov 2009, at 22:03, Matt Wynne wrote: > > On 6 Nov 2009, at 12:49, David Chelimsky wrote: > >> In the long run, what I'd like is the following: >> >> * Cucumber features that ship with RSpec become the authoritative end-user documentation. This is something that anybody can contribute to with patches, as it's all in files that ship with RSpec. I'd also like to use such an effort to push the envelope on Cucumber features as executable documentation. I think that with a little bit of work we could use the features to generate a website with meaningful organization/navigation. Is anybody already doing that? > > +1 > > I had a little epiphany working on the wire protocol feature for cucumber[3]. We were trying to design the protocol via email and lighthouse ticket discussion, started using a wiki to document the desired protocol when I realised - why don't we just use the features!? I would like to see more people pushing Cucumber in this direction, and I think it would be interesting to consider adding mark-up to comments to allow us to build RDoc-style websites from a features folder. I've been looking at the documentation again recently, and I'd be happy to start work on this, particularly if Matt W is wanting to look at the cucumber end since he's just up the road from me. I'm very keen on the executable documentation aspects of this, and I did a whole load of work back in 2008 on this kind of stuff using RSpec, so I've got a bit of history here :-) Matt -- Matt Patterson | Design & Code | http://www.reprocessed.org/ From apremdas at gmail.com Tue Jan 5 08:35:25 2010 From: apremdas at gmail.com (Andrew Premdas) Date: Tue, 5 Jan 2010 13:35:25 +0000 Subject: [rspec-users] 'Expected NoMethodError, got NameError' In-Reply-To: <57c63afe1001041300q2ebf4055q2c2c7c6fb48b54f3@mail.gmail.com> References: <20091230210446.GS12080@malachai> <88fd8ddc1001041257p5acf8d11v4e0a7fbd1d8b7c63@mail.gmail.com> <57c63afe1001041300q2ebf4055q2c2c7c6fb48b54f3@mail.gmail.com> Message-ID: <88fd8ddc1001050535k1c24c30bl7022b43762a3a924@mail.gmail.com> 2010/1/4 David Chelimsky > On Mon, Jan 4, 2010 at 2:57 PM, Andrew Premdas wrote: > >> 2009/12/30 Paul Hinze >> >> Given this simple cucumber feature (related to another rspec bug I am >>> working on): >>> >>> http://gist.github.com/266335 >>> >>> I'm fighting with this error messages that _only_ shows up in certain >>> situations that I can't quite pin down (rake features breaks, individual >>> cucumber run works, rake with debugger beforehand works...) >>> >>> > expected NoMethodError, got #>> method `nap' for Time:Class >>> > ./features/step_definitions/stubs_dont_leak_steps.rb:10:in `/^nap time >>> should not be defined$/' >>> > features/either/stubs_dont_leak.feature:11:in `Then nap time should not >>> be defined' >>> >>> I've tracked it down to this line: >>> >>> >>> http://github.com/dchelimsky/rspec/blob/master/lib/spec/mocks/proxy.rb#L117 >> >> >> This method is really unpleasant, perhaps some standard refactorings to >> remove the complex conditional conditions and remove the nested if's would >> be useful first of all. >> > > Agreed. Patches welcome! > David, I hope my comment didn't come out as sniping/bitchy/negative, and the suggested refactorings were useful. Couldn't really make a patch as I don't have the context to name things correctly. Anyhow thanks once again for all your wonderful work on rspec and on this mailing list it really is very much appreciated. All best Andrew > > >> def message_received(sym, *args, &block) >>> expectation = find_matching_expectation(sym, *args) >>> stub = find_matching_method_stub(sym, *args) >>> >>> if (stub && expectation && expectation.called_max_times?) || (stub && >>> !expectation) >>> if expectation = find_almost_matching_expectation(sym, *args) >>> expectation.advise(args, block) unless >>> expectation.expected_messages_received? >>> end >>> stub.invoke(*args, &block) >>> elsif expectation >>> expectation.invoke(*args, &block) >>> elsif expectation = find_almost_matching_expectation(sym, *args) >>> expectation.advise(args, block) if null_object? unless >>> expectation.expected_messages_received? >>> raise_unexpected_message_args_error(expectation, *args) unless >>> (has_negative_expectation?(sym) or null_object?) >>> else >>> --> @target.__send__ :method_missing, sym, *args, &block >>> end >>> end >>> >>> My question is this... why do we fall back to method_missing here rather >>> than a simple 'send' to the target? I figure there is likely a reason, >>> so if someone could help me understand I'll happily open up my >>> expectation to should_raise(NameError) and move along. :) >>> >>> Cheers, >>> >>> Paul >>> _______________________________________________ >>> 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: From dchelimsky at gmail.com Tue Jan 5 11:16:50 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 5 Jan 2010 10:16:50 -0600 Subject: [rspec-users] 'Expected NoMethodError, got NameError' In-Reply-To: <88fd8ddc1001050535k1c24c30bl7022b43762a3a924@mail.gmail.com> References: <20091230210446.GS12080@malachai> <88fd8ddc1001041257p5acf8d11v4e0a7fbd1d8b7c63@mail.gmail.com> <57c63afe1001041300q2ebf4055q2c2c7c6fb48b54f3@mail.gmail.com> <88fd8ddc1001050535k1c24c30bl7022b43762a3a924@mail.gmail.com> Message-ID: <57c63afe1001050816v2cff1df4ie05abed4bb0ba8e8@mail.gmail.com> On Tue, Jan 5, 2010 at 7:35 AM, Andrew Premdas wrote: > 2010/1/4 David Chelimsky > > On Mon, Jan 4, 2010 at 2:57 PM, Andrew Premdas wrote: >> >>> 2009/12/30 Paul Hinze >>> >>> Given this simple cucumber feature (related to another rspec bug I am >>>> working on): >>>> >>>> http://gist.github.com/266335 >>>> >>>> I'm fighting with this error messages that _only_ shows up in certain >>>> situations that I can't quite pin down (rake features breaks, individual >>>> cucumber run works, rake with debugger beforehand works...) >>>> >>>> > expected NoMethodError, got #>>> method `nap' for Time:Class >>>> > ./features/step_definitions/stubs_dont_leak_steps.rb:10:in `/^nap time >>>> should not be defined$/' >>>> > features/either/stubs_dont_leak.feature:11:in `Then nap time should >>>> not be defined' >>>> >>>> I've tracked it down to this line: >>>> >>>> >>>> http://github.com/dchelimsky/rspec/blob/master/lib/spec/mocks/proxy.rb#L117 >>> >>> >>> This method is really unpleasant, perhaps some standard refactorings to >>> remove the complex conditional conditions and remove the nested if's would >>> be useful first of all. >>> >> >> Agreed. Patches welcome! >> > > David, > > I hope my comment didn't come out as sniping/bitchy/negative, > Absolutely not! You were spot on. > and the suggested refactorings were useful. > I learned a lot about that code going through it. > Couldn't really make a patch as I don't have the context to name things > correctly. > Understood. Hopefully that will improve over time. > Anyhow thanks once again for all your wonderful work on rspec and on this > mailing list it really is very much appreciated. > Thank you for saying so. Appreciation is always appreciated :) Cheers, David > > All best > > Andrew > > >> >> >>> def message_received(sym, *args, &block) >>>> expectation = find_matching_expectation(sym, *args) >>>> stub = find_matching_method_stub(sym, *args) >>>> >>>> if (stub && expectation && expectation.called_max_times?) || (stub && >>>> !expectation) >>>> if expectation = find_almost_matching_expectation(sym, *args) >>>> expectation.advise(args, block) unless >>>> expectation.expected_messages_received? >>>> end >>>> stub.invoke(*args, &block) >>>> elsif expectation >>>> expectation.invoke(*args, &block) >>>> elsif expectation = find_almost_matching_expectation(sym, *args) >>>> expectation.advise(args, block) if null_object? unless >>>> expectation.expected_messages_received? >>>> raise_unexpected_message_args_error(expectation, *args) unless >>>> (has_negative_expectation?(sym) or null_object?) >>>> else >>>> --> @target.__send__ :method_missing, sym, *args, &block >>>> end >>>> end >>>> >>>> My question is this... why do we fall back to method_missing here rather >>>> than a simple 'send' to the target? I figure there is likely a reason, >>>> so if someone could help me understand I'll happily open up my >>>> expectation to should_raise(NameError) and move along. :) >>>> >>>> Cheers, >>>> >>>> Paul >>>> _______________________________________________ >>>> 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: From edvard.majakari at gmail.com Tue Jan 5 05:09:32 2010 From: edvard.majakari at gmail.com (Edvard Majakari) Date: Tue, 5 Jan 2010 02:09:32 -0800 (PST) Subject: [rspec-users] Adding stubs for an included argument Message-ID: Hi, My scenario is as follows, and so far I have not found the clean way to implement the following. In a method I have a method called allowed_for?(*args) used as follows: ... if o.allowed_for?(:foo, :bar) #case a elsif o.allowed_for(:quux, :bif) #case b elsif o.allowed_for(:baz) #case c else #case default end now in the spec, I'd like to say something like obj.should_allow_for(:foo) obj.stub!(:allowed_for? => false) that is, if allowed_for? is called with varargs containing :foo it should return true, false otherwise. At the moment the only way I can make the spec to run is to create exact expectation, which is a bit too tightly coupled to the implementation: obj.should_receive(:allowed_for?).with(:foo, :bar).and_return ... another solution would wrap allow_for?(*args) into a single method call without parameter names and stubbing the wrapper methods: if o.fooey? #case a elsif o.quuxy? #case b elsif o.bazy? #case c else #case default end but I don't like it - the rules are simple and the whole method is now quite readable as it is. Creating one-line private methods would IMO add superfluous cruft and reduce legibility. From dchelimsky at gmail.com Tue Jan 5 11:54:51 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 5 Jan 2010 10:54:51 -0600 Subject: [rspec-users] Adding stubs for an included argument In-Reply-To: References: Message-ID: <57c63afe1001050854v6e3f8b31j6274ccc358f40bc3@mail.gmail.com> On Tue, Jan 5, 2010 at 4:09 AM, Edvard Majakari wrote: > Hi, > > My scenario is as follows, and so far I have not found the clean way > to implement the following. > > In a method I have a method called allowed_for?(*args) used as > follows: > > ... > > if o.allowed_for?(:foo, :bar) > #case a > elsif o.allowed_for(:quux, :bif) > #case b > elsif o.allowed_for(:baz) > #case c > else > #case default > end > > > now in the spec, I'd like to say something like > > obj.should_allow_for(:foo) > obj.stub!(:allowed_for? => false) > Try this: obj.stub(:allowed_for) {|*args| args.include?(:foo)} HTH, David > > that is, if allowed_for? is called with varargs containing :foo it > should return true, false otherwise. > > At the moment the only way I can make the spec to run is to create > exact expectation, which is a bit too tightly coupled to the > implementation: > > obj.should_receive(:allowed_for?).with(:foo, :bar).and_return ... > > another solution would wrap allow_for?(*args) into a single method > call without parameter names and stubbing the wrapper methods: > > if o.fooey? > #case a > elsif o.quuxy? > #case b > elsif o.bazy? > #case c > else > #case default > end > > but I don't like it - the rules are simple and the whole method is now > quite readable as it is. Creating one-line private methods would IMO > add superfluous cruft and reduce legibility. > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From phillipkoebbe at gmail.com Tue Jan 5 12:36:53 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Tue, 05 Jan 2010 11:36:53 -0600 Subject: [rspec-users] get to a different controller Message-ID: <4B4378B5.4000404@gmail.com> I'm trying to implement a base controller that other controllers descend from, and am having a bit of difficulty in testing the sole "feature" of the base controller. http://gist.github.com/269544 In the "not redirecting when user is an admin" context, I keep getting an error that "no action responded to ". Obviously, there are no actions in this controller, nor should there be. I want to hit an action in a descendant controller and make sure that it goes through. How do I do that? Thanks, Phillip From mailinglists at patmaddox.com Tue Jan 5 15:12:38 2010 From: mailinglists at patmaddox.com (Pat Maddox) Date: Tue, 5 Jan 2010 12:12:38 -0800 Subject: [rspec-users] get to a different controller In-Reply-To: <4B4378B5.4000404@gmail.com> References: <4B4378B5.4000404@gmail.com> Message-ID: <2E305F4A-D13B-4E6F-8C7F-6A846BA4213A@patmaddox.com> The spec has Admin::BaseController as the described type. So of course it's going to test against that. If you want to test a different class, you need to describe that instead! On Jan 5, 2010, at 9:36 AM, Phillip Koebbe wrote: > I'm trying to implement a base controller that other controllers descend from, and am having a bit of difficulty in testing the sole "feature" of the base controller. > > http://gist.github.com/269544 > > In the "not redirecting when user is an admin" context, I keep getting an error that "no action responded to ". Obviously, there are no actions in this controller, nor should there be. I want to hit an action in a descendant controller and make sure that it goes through. > > How do I do that? > > Thanks, > Phillip > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From matt at mattwynne.net Tue Jan 5 14:46:18 2010 From: matt at mattwynne.net (Matt Wynne) Date: Tue, 5 Jan 2010 19:46:18 +0000 Subject: [rspec-users] get to a different controller In-Reply-To: <4B4378B5.4000404@gmail.com> References: <4B4378B5.4000404@gmail.com> Message-ID: Subclass it in your spec with class TestController < Admin::BaseController def index end end ...then use the TestController in your tests for Admin::BaseController. That might mean you'll need to add special routing for TestController which is annoying but can be done. On 5 Jan 2010, at 17:36, Phillip Koebbe wrote: > I'm trying to implement a base controller that other controllers > descend from, and am having a bit of difficulty in testing the sole > "feature" of the base controller. > > http://gist.github.com/269544 > > In the "not redirecting when user is an admin" context, I keep > getting an error that "no action responded to ". > Obviously, there are no actions in this controller, nor should there > be. I want to hit an action in a descendant controller and make sure > that it goes through. > > How do I do that? > > Thanks, > Phillip > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users cheers, Matt http://mattwynne.net +447974 430184 From dchelimsky at gmail.com Tue Jan 5 15:37:10 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 5 Jan 2010 14:37:10 -0600 Subject: [rspec-users] get to a different controller In-Reply-To: References: <4B4378B5.4000404@gmail.com> Message-ID: <57c63afe1001051237u2237908ch41075eaca582ee48@mail.gmail.com> On Tue, Jan 5, 2010 at 1:46 PM, Matt Wynne wrote: > Subclass it in your spec with > > class TestController < Admin::BaseController > def index > end > end > > ...then use the TestController in your tests for Admin::BaseController. > > That might mean you'll need to add special routing for TestController which > is annoying but can be done. >From The RSpec Book: http://media.pragprog.com/titles/achbd/code/rails_controllers/messages/15/spec/controllers/application_controller5_spec.rb > > On 5 Jan 2010, at 17:36, Phillip Koebbe wrote: > > I'm trying to implement a base controller that other controllers descend >> from, and am having a bit of difficulty in testing the sole "feature" of the >> base controller. >> >> http://gist.github.com/269544 >> >> In the "not redirecting when user is an admin" context, I keep getting an >> error that "no action responded to ". Obviously, there are >> no actions in this controller, nor should there be. I want to hit an action >> in a descendant controller and make sure that it goes through. >> >> How do I do that? >> >> Thanks, >> Phillip >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > cheers, > Matt > > http://mattwynne.net > +447974 430184 > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From phillipkoebbe at gmail.com Tue Jan 5 15:52:25 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Tue, 05 Jan 2010 14:52:25 -0600 Subject: [rspec-users] get to a different controller In-Reply-To: <2E305F4A-D13B-4E6F-8C7F-6A846BA4213A@patmaddox.com> References: <4B4378B5.4000404@gmail.com> <2E305F4A-D13B-4E6F-8C7F-6A846BA4213A@patmaddox.com> Message-ID: <4B43A689.8090505@gmail.com> Pat Maddox wrote: > The spec has Admin::BaseController as the described type. So of course it's going to test against that. If you want to test a different class, you need to describe that instead! Hi Pat, Right. But, I'm not really wanting to test a different class. My intention is to put the require_admin in the base_controller and have all the admin controllers descend from it, so I don't have to duplicate the before_filter. I was trying to be simple and make a request to a controller that descends from base_controller, thinking that if it got through and didn't redirect to the error page, it worked. How would you suggest I test that Peace, Phillip From phillipkoebbe at gmail.com Tue Jan 5 15:53:50 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Tue, 05 Jan 2010 14:53:50 -0600 Subject: [rspec-users] get to a different controller In-Reply-To: References: <4B4378B5.4000404@gmail.com> Message-ID: <4B43A6DE.4080302@gmail.com> > Subclass it in your spec with > > class TestController < Admin::BaseController > def index > end > end > > ...then use the TestController in your tests for Admin::BaseController. > > That might mean you'll need to add special routing for TestController > which is annoying but can be done. Thanks, Matt. Between your post and David's, I'll see if I can put it all together. Peace, Phillip From dchelimsky at gmail.com Tue Jan 5 16:37:06 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 5 Jan 2010 15:37:06 -0600 Subject: [rspec-users] get to a different controller In-Reply-To: <4B43A6DE.4080302@gmail.com> References: <4B4378B5.4000404@gmail.com> <4B43A6DE.4080302@gmail.com> Message-ID: <57c63afe1001051337s473e05fei33274e3e53a2caf6@mail.gmail.com> On Tue, Jan 5, 2010 at 2:53 PM, Phillip Koebbe wrote: > Subclass it in your spec with >> >> class TestController < Admin::BaseController >> def index >> end >> end >> >> ...then use the TestController in your tests for Admin::BaseController. >> >> That might mean you'll need to add special routing for TestController >> which is annoying but can be done. >> > > Thanks, Matt. Between your post and David's, I'll see if I can put it all > together. > Phillip - one thing to keep in mind is that subclasses can always override super class behaviour. So on the one hand, we want to minimize duplication and only spec one thing once. On the other hand, if we're spec'ing that every controller should behave some way, we should spec every controller. I'm not advocating one approach or the other, just pointing out a couple of costs/benefits. > > Peace, > > Phillip > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rick.denatale at gmail.com Tue Jan 5 18:10:23 2010 From: rick.denatale at gmail.com (Rick DeNatale) Date: Tue, 5 Jan 2010 18:10:23 -0500 Subject: [rspec-users] 'Expected NoMethodError, got NameError' In-Reply-To: <57c63afe1001050816v2cff1df4ie05abed4bb0ba8e8@mail.gmail.com> References: <20091230210446.GS12080@malachai> <88fd8ddc1001041257p5acf8d11v4e0a7fbd1d8b7c63@mail.gmail.com> <57c63afe1001041300q2ebf4055q2c2c7c6fb48b54f3@mail.gmail.com> <88fd8ddc1001050535k1c24c30bl7022b43762a3a924@mail.gmail.com> <57c63afe1001050816v2cff1df4ie05abed4bb0ba8e8@mail.gmail.com> Message-ID: On Tue, Jan 5, 2010 at 11:16 AM, David Chelimsky wrote: > On Tue, Jan 5, 2010 at 7:35 AM, Andrew Premdas wrote: >> Anyhow thanks once again for all your wonderful work on rspec and on this >> mailing list it really is very much appreciated. > > Thank you for saying so. Appreciation is always appreciated :) I can appreciate that! -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale From win at wincent.com Tue Jan 5 19:44:20 2010 From: win at wincent.com (Wincent Colaiuta) Date: Wed, 6 Jan 2010 01:44:20 +0100 Subject: [rspec-users] get to a different controller In-Reply-To: <4B43A689.8090505@gmail.com> References: <4B4378B5.4000404@gmail.com> <2E305F4A-D13B-4E6F-8C7F-6A846BA4213A@patmaddox.com> <4B43A689.8090505@gmail.com> Message-ID: <93374C22-9461-4EF5-82A1-4D3EF01E4F3E@wincent.com> El 05/01/2010, a las 21:52, Phillip Koebbe escribi?: > Pat Maddox wrote: >> The spec has Admin::BaseController as the described type. So of >> course it's going to test against that. If you want to test a >> different class, you need to describe that instead! > > Hi Pat, > > Right. But, I'm not really wanting to test a different class. My > intention is to put the require_admin in the base_controller and > have all the admin controllers descend from it, so I don't have to > duplicate the before_filter. I was trying to be simple and make a > request to a controller that descends from base_controller, thinking > that if it got through and didn't redirect to the error page, it > worked. How would you suggest I test that I test inherited stuff with shared behaviors. It might be something you could use here. Basically, I have a bunch of behavior in my ApplicationController, for example, and in my spec/controllers/application_controller_spec.rb file I have a bunch of blocks like this: describe ApplicationController, 'protected methods', :shared => true do ... end describe ApplicationController, 'parameter filtering', :shared => true do ... end And I then group them all together in one more shared behavior: describe ApplicationController, :shared => true do it_should_behave_like 'ApplicationController protected methods' it_should_behave_like 'ApplicationController parameter filtering' ... end And finally in all subclasses which inherit I can now just do: describe ArticlesController do it_should_behave_like 'ApplicationController' ... end So the behavior inherited from the superclass is specified, but it is also tested independently by the inheriting subclasses. I imagine the same idea might be adaptable in some way for your use case. Cheers, Wincent From dchelimsky at gmail.com Tue Jan 5 20:01:39 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 5 Jan 2010 19:01:39 -0600 Subject: [rspec-users] get to a different controller In-Reply-To: <93374C22-9461-4EF5-82A1-4D3EF01E4F3E@wincent.com> References: <4B4378B5.4000404@gmail.com> <2E305F4A-D13B-4E6F-8C7F-6A846BA4213A@patmaddox.com> <4B43A689.8090505@gmail.com> <93374C22-9461-4EF5-82A1-4D3EF01E4F3E@wincent.com> Message-ID: <57c63afe1001051701q324ac8do92a74159f6a1b6f7@mail.gmail.com> On Tue, Jan 5, 2010 at 6:44 PM, Wincent Colaiuta wrote: > El 05/01/2010, a las 21:52, Phillip Koebbe escribi?: > > > Pat Maddox wrote: >> >>> The spec has Admin::BaseController as the described type. So of course >>> it's going to test against that. If you want to test a different class, you >>> need to describe that instead! >>> >> >> Hi Pat, >> >> Right. But, I'm not really wanting to test a different class. My intention >> is to put the require_admin in the base_controller and have all the admin >> controllers descend from it, so I don't have to duplicate the before_filter. >> I was trying to be simple and make a request to a controller that descends >> from base_controller, thinking that if it got through and didn't redirect to >> the error page, it worked. How would you suggest I test that >> > > I test inherited stuff with shared behaviors. It might be something you > could use here. > > Basically, I have a bunch of behavior in my ApplicationController, for > example, and in my spec/controllers/application_controller_spec.rb file I > have a bunch of blocks like this: > > describe ApplicationController, 'protected methods', :shared => true do > ... > end > > describe ApplicationController, 'parameter filtering', :shared => true do > ... > end > > And I then group them all together in one more shared behavior: > > describe ApplicationController, :shared => true do > it_should_behave_like 'ApplicationController protected methods' > it_should_behave_like 'ApplicationController parameter filtering' > ... > end > > And finally in all subclasses which inherit I can now just do: > > describe ArticlesController do > it_should_behave_like 'ApplicationController' > ... > end > > So the behavior inherited from the superclass is specified, but it is also > tested independently by the inheriting subclasses. > Yay! > > I imagine the same idea might be adaptable in some way for your use case. > > Cheers, > Wincent > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From edvard.majakari at gmail.com Wed Jan 6 08:22:58 2010 From: edvard.majakari at gmail.com (Edvard Majakari) Date: Wed, 6 Jan 2010 05:22:58 -0800 (PST) Subject: [rspec-users] Adding stubs for an included argument In-Reply-To: <57c63afe1001050854v6e3f8b31j6274ccc358f40bc3@mail.gmail.com> References: <57c63afe1001050854v6e3f8b31j6274ccc358f40bc3@mail.gmail.com> Message-ID: <69e2ef21-d6e3-4d19-8db6-de54c4161e58@a32g2000yqm.googlegroups.com> Woohoo! I was aware of the block construct, but didn't know it worked with stub! as well (with should_receive, I had to use at_least... and it broke the system, making it unusable). Thanks! From phillipkoebbe at gmail.com Wed Jan 6 10:17:33 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Wed, 06 Jan 2010 09:17:33 -0600 Subject: [rspec-users] get to a different controller In-Reply-To: <93374C22-9461-4EF5-82A1-4D3EF01E4F3E@wincent.com> References: <4B4378B5.4000404@gmail.com> <2E305F4A-D13B-4E6F-8C7F-6A846BA4213A@patmaddox.com> <4B43A689.8090505@gmail.com> <93374C22-9461-4EF5-82A1-4D3EF01E4F3E@wincent.com> Message-ID: <4B44A98D.3090609@gmail.com> Wincent Colaiuta wrote: > > I test inherited stuff with shared behaviors. It might be something > you could use here. > > Basically, I have a bunch of behavior in my ApplicationController, for > example, and in my spec/controllers/application_controller_spec.rb > file I have a bunch of blocks like this: > > describe ApplicationController, 'protected methods', :shared => true do > ... > end > > describe ApplicationController, 'parameter filtering', :shared => > true do > ... > end > > And I then group them all together in one more shared behavior: > > describe ApplicationController, :shared => true do > it_should_behave_like 'ApplicationController protected methods' > it_should_behave_like 'ApplicationController parameter filtering' > ... > end > > And finally in all subclasses which inherit I can now just do: > > describe ArticlesController do > it_should_behave_like 'ApplicationController' > ... > end > > So the behavior inherited from the superclass is specified, but it is > also tested independently by the inheriting subclasses. > > I imagine the same idea might be adaptable in some way for your use case. > > Cheers, > Wincent Hi Wincent, Thanks for the input. I like the idea of the shared behavior so it gets tested at all points of execution. [And I really enjoyed David's "Yay!", too. :) ] I am going to keep that in mind as I go forward. In this particular case, my dilemma was how to test the behavior in the base_controller to begin with. The problem stemmed from the fact that there were no actions in the controller to call so I couldn't do a get on it. With Matt and David's help, I have achieved what I was originally after. The gist is updated if you are interested: http://gist.github.com/269544 I'm not sure how to share the behavior now, though. As I look at the context that implements the testing of the before_filter, sharing it doesn't seem to make sense since it creates a bogus derived class to do the testing. If I share the behavior to real derived controllers, it doesn't seem to me that they will, in fact, be tested. Do you have any thoughts on that? Peace, Phillip From win at wincent.com Wed Jan 6 16:45:37 2010 From: win at wincent.com (Wincent Colaiuta) Date: Wed, 6 Jan 2010 22:45:37 +0100 Subject: [rspec-users] get to a different controller In-Reply-To: <4B44A98D.3090609@gmail.com> References: <4B4378B5.4000404@gmail.com> <2E305F4A-D13B-4E6F-8C7F-6A846BA4213A@patmaddox.com> <4B43A689.8090505@gmail.com> <93374C22-9461-4EF5-82A1-4D3EF01E4F3E@wincent.com> <4B44A98D.3090609@gmail.com> Message-ID: <386396F2-A3D0-46A0-8273-57608D912A55@wincent.com> El 06/01/2010, a las 16:17, Phillip Koebbe escribi?: > Wincent Colaiuta wrote: >> >> I test inherited stuff with shared behaviors. It might be something >> you could use here. >> >> Basically, I have a bunch of behavior in my ApplicationController, >> for example, and in my spec/controllers/ >> application_controller_spec.rb file I have a bunch of blocks like >> this: >> >> describe ApplicationController, 'protected methods', :shared => >> true do >> ... >> end >> >> describe ApplicationController, 'parameter filtering', :shared => >> true do >> ... >> end >> >> And I then group them all together in one more shared behavior: >> >> describe ApplicationController, :shared => true do >> it_should_behave_like 'ApplicationController protected methods' >> it_should_behave_like 'ApplicationController parameter filtering' >> ... >> end >> >> And finally in all subclasses which inherit I can now just do: >> >> describe ArticlesController do >> it_should_behave_like 'ApplicationController' >> ... >> end >> >> So the behavior inherited from the superclass is specified, but it >> is also tested independently by the inheriting subclasses. >> >> I imagine the same idea might be adaptable in some way for your use >> case. >> >> Cheers, >> Wincent > Hi Wincent, > > Thanks for the input. I like the idea of the shared behavior so it > gets tested at all points of execution. [And I really enjoyed > David's "Yay!", too. :) ] I am going to keep that in mind as I go > forward. In this particular case, my dilemma was how to test the > behavior in the base_controller to begin with. The problem stemmed > from the fact that there were no actions in the controller to call > so I couldn't do a get on it. With Matt and David's help, I have > achieved what I was originally after. The gist is updated if you > are interested: > > http://gist.github.com/269544 > > I'm not sure how to share the behavior now, though. As I look at the > context that implements the testing of the before_filter, sharing it > doesn't seem to make sense since it creates a bogus derived class to > do the testing. If I share the behavior to real derived controllers, > it doesn't seem to me that they will, in fact, be tested. > > Do you have any thoughts on that? Well, there is more than one way to skin a cat, but the thing I like about my proposed solution is that: - the specification of the behavior appears in the "describe" block that corresponds to the controller where the behavior is implemented - but given that the implementing controller is an abstract one, you actually test the behavior where it is actually exercised (ie. in the subclasses) - you don't need to make a fictional controller which isn't actually part of your application purely for testing purposes Looking at the gist you pasted it looks like it could be very straightforward to test, especially if you're using a RESTful access pattern. Your admin controllers all inherit from your abstract base class, and if they're RESTful you know before you even start which actions they'll respond to (the usual index, new, create etc). Perhaps they only respond to a subset; but even if they only respond to one ("show" or "index", say) you have enough of a common basis to test that the require_admin before filter is actually hit and does what you think it should (ie. you only need to hit "show" or "index", there is no need to test all actions). Cheers, Wincent From dchelimsky at gmail.com Wed Jan 6 18:18:16 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 6 Jan 2010 17:18:16 -0600 Subject: [rspec-users] Fixtures problem with Rails plugin In-Reply-To: <6a4e6e88-a045-407f-9ffc-720a3fff8261@o28g2000yqh.googlegroups.com> References: <6a4e6e88-a045-407f-9ffc-720a3fff8261@o28g2000yqh.googlegroups.com> Message-ID: <57c63afe1001061518n64e8cc32se7be194375f72153@mail.gmail.com> On Wed, Dec 30, 2009 at 10:30 AM, John j. Cuckler wrote: > Hi, I just wrote some specs for a rails plugin, I'm using some > fixtures and rake:spec:plugins works fine as long as there is only > this plugin loaded in the application, but if I add another one it > doesn't load fixtures. Apart from that, everything is working. > > I added this in my plugin spec file to make it look for fixtures in > the right place: > > Spec::Runner.configure do |config| > config.fixture_path = File.dirname(__FILE__) + '/fixtures' > end > Where is this declared, relative to RAILS_ROOT? > Everything is up to date, both rails and rspec gems. > Any idea? > Do the other plugins use rspec too? And fixtures? > Thanks > > JJ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From matt at mattwynne.net Wed Jan 6 19:53:14 2010 From: matt at mattwynne.net (Matt Wynne) Date: Thu, 7 Jan 2010 00:53:14 +0000 Subject: [rspec-users] describe "RSpec's documentation" do In-Reply-To: References: <98A6AC6B-BECC-4564-AF04-C49429AC7C75@mattwynne.net> Message-ID: On 5 Jan 2010, at 12:17, Matt Patterson wrote: > On 9 Nov 2009, at 22:03, Matt Wynne wrote: > >> >> On 6 Nov 2009, at 12:49, David Chelimsky wrote: >> >>> In the long run, what I'd like is the following: >>> >>> * Cucumber features that ship with RSpec become the authoritative >>> end-user documentation. This is something that anybody can >>> contribute to with patches, as it's all in files that ship with >>> RSpec. I'd also like to use such an effort to push the envelope on >>> Cucumber features as executable documentation. I think that with a >>> little bit of work we could use the features to generate a website >>> with meaningful organization/navigation. Is anybody already doing >>> that? >> >> +1 >> >> I had a little epiphany working on the wire protocol feature for >> cucumber[3]. We were trying to design the protocol via email and >> lighthouse ticket discussion, started using a wiki to document the >> desired protocol when I realised - why don't we just use the >> features!? I would like to see more people pushing Cucumber in this >> direction, and I think it would be interesting to consider adding >> mark-up to comments to allow us to build RDoc-style websites from a >> features folder. > > I've been looking at the documentation again recently, and I'd be > happy to start work on this, particularly if Matt W is wanting to > look at the cucumber end since he's just up the road from me. > > I'm very keen on the executable documentation aspects of this, and I > did a whole load of work back in 2008 on this kind of stuff using > RSpec, so I've got a bit of history here :-) Great. I think it's time we really started dogfooding cucumber in terms of producing executable documentation. The features for Cucumber itself could do with some housekeeping, but right now the focus there is on the code, so RSpec seems like a nice place to work on this from. I would like to see us try to build a flat HTML website (or PDF reference book) from rspec's features directory which could be used as reference by a new or curious user. As David says, I think we could drive out a bunch of really nice features from Cucumber to help make it much easier to build and maintain large suites of features. So what's the first step? A pint or two at the Reliance perhaps Mr Patterson? cheers, Matt http://mattwynne.net +447974 430184 From ben.fyvie at champsoftware.com Wed Jan 6 20:15:49 2010 From: ben.fyvie at champsoftware.com (Ben Fyvie) Date: Wed, 6 Jan 2010 19:15:49 -0600 Subject: [rspec-users] Problem with should_not when passing a multiple args to a matcher Message-ID: <4862558A4CDA426D80C03F951C599CA8@champ.net> We seem to be hitting some undesirable behavior with should_not in combination with matchers that accept collections. Let me use the "include" matcher for example (a co-worker reported similar problems using "be_any" so I don't believe this is limited to "include"). The RDoc states: Passes if actual includes expected. This works for collections and Strings. You can also pass in multiple args and it will only pass if all args are found in collection. Examples [1,2,3].should include(3) [1,2,3].should include(2,3) #would pass [1,2,3].should include(2,3,4) #would fail [1,2,3].should_not include(4) "spread".should include("read") "spread".should_not include("red") The RDoc doesn't give any examples of using a "should_not" along with multiple args being passed to "include", but since I couldn't find any documentation on why it would not work I assume that it should work. Here is a list of tests I came up with to find out what works and what doesn't. Note: All of these tests SHOULD fail; the problem is with the tests that do NOT fail. it "does properly fail on a collection when using \"should\" with multiple args" do [1,2,3].should include(2,3,4) end it "does NOT properly fail on a collection when using \"should_not\" with multiple args when at least one value in the expected args is in the actual collection" do [1,2,3].should_not include(3,4,5) end it "does properly fail on a collection when using \"should_not\" with multiple args when all of the values in the expected args are in the actual collection" do [1,2,3].should_not include(1,2,3) end it "does properly fail on a collection when using \"should_not\" with multiple args when all of the values in the expected args are in the actual collection and when the expected args don't cover all of the values in the actual collection" do [1,2,3].should_not include(1,2) end it "does properly fail on a collection when using \"should_not\" with a single arg" do [1,2,3].should_not include(3) end it "does properly fail on a string when using \"should_not\" with multiple args when all of the values in the expected args are in the actual string" do "abc".should_not include("a", "b", "c") end it "does NOT properly fail when using \"should_not\" with multiple args when at least one of the values in the expected args is in the actual string" do "abc".should_not include("a", "b", "e") end it "does properly fail on a string when using \"should_not\" with multiple args when all of the values in the expected args are in the actual collection and when the expected args don't cover all of the values in the actual string" do "abc".should_not include("a","b") end it "does properly fail on a string when using \"should_not\" with a single arg" do "abc".should_not include("a") end We are using the following rspec gems: Rspec-1.2.9 Rspec-rails-1.2.7.1 So I think one of two things needs to happen here dependent on whether this is desired behavior or not. 1. If this is desired behavior then an exception really should be raised if you try to use "should_not" in combination with passing a collection to a matcher. At the very least there needs to be some documentation to inform RSpec users that tests will not always fail as they might expect when using "should_not" in combination with a matcher that accepts multiple args. 2. If this is not desired behavior then of course we need a fix. I apologize if this has been brought up previously; I did as much searching on this issue as possible. Thanks in advance! Ben Fyvie -------------- next part -------------- An HTML attachment was scrubbed... URL: From phillipkoebbe at gmail.com Wed Jan 6 21:53:15 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Wed, 06 Jan 2010 20:53:15 -0600 Subject: [rspec-users] get to a different controller In-Reply-To: <386396F2-A3D0-46A0-8273-57608D912A55@wincent.com> References: <4B4378B5.4000404@gmail.com> <2E305F4A-D13B-4E6F-8C7F-6A846BA4213A@patmaddox.com> <4B43A689.8090505@gmail.com> <93374C22-9461-4EF5-82A1-4D3EF01E4F3E@wincent.com> <4B44A98D.3090609@gmail.com> <386396F2-A3D0-46A0-8273-57608D912A55@wincent.com> Message-ID: <4B454C9B.2040604@gmail.com> Wincent Colaiuta wrote: > > Well, there is more than one way to skin a cat, but the thing I like > about my proposed solution is that: > > - the specification of the behavior appears in the "describe" block > that corresponds to the controller where the behavior is implemented > > - but given that the implementing controller is an abstract one, you > actually test the behavior where it is actually exercised (ie. in the > subclasses) > > - you don't need to make a fictional controller which isn't actually > part of your application purely for testing purposes > > Looking at the gist you pasted it looks like it could be very > straightforward to test, especially if you're using a RESTful access > pattern. > > Your admin controllers all inherit from your abstract base class, and > if they're RESTful you know before you even start which actions > they'll respond to (the usual index, new, create etc). Perhaps they > only respond to a subset; but even if they only respond to one ("show" > or "index", say) you have enough of a common basis to test that the > require_admin before filter is actually hit and does what you think it > should (ie. you only need to hit "show" or "index", there is no need > to test all actions). > > Cheers, > Wincent > Are you basically saying that you wouldn't worry about testing the before_filter in the base_controller at all? Maybe part of the reason I am not "getting this" is my lack of familiarity with shared behaviors. If I share the behavior in the base_controller_spec, will it get tested when I run that spec? If it won't, then my concern is moot. If it will, then I'm just as confused as I was before. Peace, Phillip From dchelimsky at gmail.com Thu Jan 7 02:19:18 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 7 Jan 2010 01:19:18 -0600 Subject: [rspec-users] Problem with should_not when passing a multiple args to a matcher In-Reply-To: <4862558A4CDA426D80C03F951C599CA8@champ.net> References: <4862558A4CDA426D80C03F951C599CA8@champ.net> Message-ID: <57c63afe1001062319p1ff0afc7ta72ea71f222623b3@mail.gmail.com> On Wed, Jan 6, 2010 at 7:15 PM, Ben Fyvie wrote: > We seem to be hitting some undesirable behavior with should_not in > combination with matchers that accept collections. Let me use the ?include? > matcher for example (a co-worker reported similar problems using ?be_any? so > I don?t believe this is limited to ?include?). The RDoc states: > > Passes if actual includes expected. This works for collections and Strings. > You can also pass in multiple args and it will only pass if all args are > found in collection. > > Examples > > [1,2,3].should include(3) > > [1,2,3].should include(2,3) #would pass > > [1,2,3].should include(2,3,4) #would fail > > [1,2,3].should_not include(4) > > "spread".should include("read") > > "spread".should_not include("red") > > > > The RDoc doesn?t give any examples of using a ?should_not? along with > multiple args being passed to ?include?, but since I couldn?t find any > documentation on why it would not work I assume that it should work. Here is > a list of tests I came up with to find out what works and what doesn?t. > Note: All of these tests SHOULD fail; the problem is with the tests that do > NOT fail. > > it "does properly fail on a collection when using \"should\" with > multiple args" do > > [1,2,3].should include(2,3,4) > > end > > > > it "does NOT properly fail on a collection when using \"should_not\" > with multiple args when at least one value in the expected args is in the > actual collection" do > > [1,2,3].should_not include(3,4,5) > > end > > > > it "does properly fail on a collection when using \"should_not\" with > multiple args when all of the values in the expected args are in the actual > collection" do > > [1,2,3].should_not include(1,2,3) > > end > > > > it "does properly fail on a collection when using \"should_not\" with > multiple args when all of the values in the expected args are in the actual > collection and when the expected args don't cover all of the values in the > actual collection" do > > [1,2,3].should_not include(1,2) > > end > > > > it "does properly fail on a collection when using \"should_not\" with a > single arg" do > > [1,2,3].should_not include(3) > > end > > > > it "does properly fail on a string when using \"should_not\" with > multiple args when all of the values in the expected args are in the actual > string" do > > "abc".should_not include("a", "b", "c") > > end > > > > it "does NOT properly fail when using \"should_not\" with multiple args > when at least one of the values in the expected args is in the actual > string" do > > "abc".should_not include("a", "b", "e") > > end > > > > it "does properly fail on a string when using \"should_not\" with > multiple args when all of the values in the expected args are in the actual > collection and when the expected args don't cover all of the values in the > actual string" do > > "abc".should_not include("a","b") > > end > > > > it "does properly fail on a string when using \"should_not\" with a > single arg" do > > "abc".should_not include("a") > > end > > > > We are using the following rspec gems: > > Rspec-1.2.9 > > Rspec-rails-1.2.7.1 > > > > So I think one of two things needs to happen here dependent on whether this > is desired behavior or not. > > 1. If this is desired behavior then an exception really should be raised if > you try to use ?should_not? in combination with passing a collection to a > matcher. At the very least there needs to be some documentation to inform > RSpec users that tests will not always fail as they might expect when using > ?should_not? in combination with a matcher that accepts multiple args. > > 2. If this is not desired behavior then of course we need a fix. > > I apologize if this has been brought up previously; I did as much searching > on this issue as possible. > > Thanks in advance! > > Ben Fyvie > Hi Ben, First, thank you for such a detailed, yet grok'able report. Second - I don't agree with your assessment that this is working incorrectly :) Unless I'm misreading your assessment, I'm reading that you expect "should include(*args)" to mean "should include ALL of these args" whereas "should_not include(*args)" means "should not include ANY of these args." Make sense? IMO, I think this is a documentation problem and that it is neither in need of an exception, nor in need of a fix. That said, perhaps we need a couple of matchers: include_all and include_any, with include being an alias for include_all. That would certainly clear up the confusion. WDYT? Cheers, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Thu Jan 7 02:27:11 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 7 Jan 2010 01:27:11 -0600 Subject: [rspec-users] get to a different controller In-Reply-To: <4B454C9B.2040604@gmail.com> References: <4B4378B5.4000404@gmail.com> <2E305F4A-D13B-4E6F-8C7F-6A846BA4213A@patmaddox.com> <4B43A689.8090505@gmail.com> <93374C22-9461-4EF5-82A1-4D3EF01E4F3E@wincent.com> <4B44A98D.3090609@gmail.com> <386396F2-A3D0-46A0-8273-57608D912A55@wincent.com> <4B454C9B.2040604@gmail.com> Message-ID: <57c63afe1001062327h2f6d6e5cs90d0d75c4f1b7370@mail.gmail.com> On Wed, Jan 6, 2010 at 8:53 PM, Phillip Koebbe wrote: > > > Wincent Colaiuta wrote: > >> >> Well, there is more than one way to skin a cat, but the thing I like about >> my proposed solution is that: >> >> - the specification of the behavior appears in the "describe" block that >> corresponds to the controller where the behavior is implemented >> >> - but given that the implementing controller is an abstract one, you >> actually test the behavior where it is actually exercised (ie. in the >> subclasses) >> >> - you don't need to make a fictional controller which isn't actually part >> of your application purely for testing purposes >> >> Looking at the gist you pasted it looks like it could be very >> straightforward to test, especially if you're using a RESTful access >> pattern. >> >> Your admin controllers all inherit from your abstract base class, and if >> they're RESTful you know before you even start which actions they'll respond >> to (the usual index, new, create etc). Perhaps they only respond to a >> subset; but even if they only respond to one ("show" or "index", say) you >> have enough of a common basis to test that the require_admin before filter >> is actually hit and does what you think it should (ie. you only need to hit >> "show" or "index", there is no need to test all actions). >> >> Cheers, >> Wincent >> >> > Are you basically saying that you wouldn't worry about testing the > before_filter in the base_controller at all? Maybe part of the reason I am > not "getting this" is my lack of familiarity with shared behaviors. If I > share the behavior in the base_controller_spec, will it get tested when I > run that spec? If it won't, then my concern is moot. If it will, then I'm > just as confused as I was before. > A shared example group is a lot like a module. It is only run when it is invoked in a non-shared example group: ********************************** SPECS: shared_examples_for "any controller" do it "does something shared" { ... } end describe SpecificController do it_should_behave_like "any controller" it "does something specific" { ... } end ********************************** OUTPUT: SpecificController does something shared does something specific ********************************** Does that clear anything up? Cheers, David > Peace, > Phillip -------------- next part -------------- An HTML attachment was scrubbed... URL: From win at wincent.com Thu Jan 7 02:22:50 2010 From: win at wincent.com (Wincent Colaiuta) Date: Thu, 7 Jan 2010 08:22:50 +0100 Subject: [rspec-users] get to a different controller In-Reply-To: <4B454C9B.2040604@gmail.com> References: <4B4378B5.4000404@gmail.com> <2E305F4A-D13B-4E6F-8C7F-6A846BA4213A@patmaddox.com> <4B43A689.8090505@gmail.com> <93374C22-9461-4EF5-82A1-4D3EF01E4F3E@wincent.com> <4B44A98D.3090609@gmail.com> <386396F2-A3D0-46A0-8273-57608D912A55@wincent.com> <4B454C9B.2040604@gmail.com> Message-ID: El 07/01/2010, a las 03:53, Phillip Koebbe escribi?: > Wincent Colaiuta wrote: >> >> Well, there is more than one way to skin a cat, but the thing I >> like about my proposed solution is that: >> >> - the specification of the behavior appears in the "describe" block >> that corresponds to the controller where the behavior is implemented >> >> - but given that the implementing controller is an abstract one, >> you actually test the behavior where it is actually exercised (ie. >> in the subclasses) >> >> - you don't need to make a fictional controller which isn't >> actually part of your application purely for testing purposes >> >> Looking at the gist you pasted it looks like it could be very >> straightforward to test, especially if you're using a RESTful >> access pattern. >> >> Your admin controllers all inherit from your abstract base class, >> and if they're RESTful you know before you even start which actions >> they'll respond to (the usual index, new, create etc). Perhaps they >> only respond to a subset; but even if they only respond to one >> ("show" or "index", say) you have enough of a common basis to test >> that the require_admin before filter is actually hit and does what >> you think it should (ie. you only need to hit "show" or "index", >> there is no need to test all actions). >> >> Cheers, >> Wincent >> > > Are you basically saying that you wouldn't worry about testing the > before_filter in the base_controller at all? Exactly. The base_controller is never directly instantiated and its "behaviour" is only ever manifested in the context of its subclasses, so you can test the behavior by testing that it exists in the subclasses. As you have seen, you can't really test the abstract base_controller directly itself because it has no actions. > Maybe part of the reason I am not "getting this" is my lack of > familiarity with shared behaviors. If I share the behavior in the > base_controller_spec, will it get tested when I run that spec? If it > won't, then my concern is moot. If it will, then I'm just as > confused as I was before. Shared behaviors are just a convenient way to define in behaviors once in a single place, which will be exercised in multiple places, so that you can keep things DRY. If you run the file with the "describe foo :shared => true" block in it, nothing will actually happen. Your assertions get exercised only when you run other "describe" blocks containing "it_should_behave_like ..." They can be useful not just in cases like this where you have an abstract superclass. You can use them wherever you have a bunch of common behavior across different classes. Cheers, Wincent From matt at mattwynne.net Thu Jan 7 05:09:35 2010 From: matt at mattwynne.net (Matt Wynne) Date: Thu, 7 Jan 2010 10:09:35 +0000 Subject: [rspec-users] get to a different controller In-Reply-To: References: <4B4378B5.4000404@gmail.com> <2E305F4A-D13B-4E6F-8C7F-6A846BA4213A@patmaddox.com> <4B43A689.8090505@gmail.com> <93374C22-9461-4EF5-82A1-4D3EF01E4F3E@wincent.com> <4B44A98D.3090609@gmail.com> <386396F2-A3D0-46A0-8273-57608D912A55@wincent.com> <4B454C9B.2040604@gmail.com> Message-ID: <7365D4F8-7A51-49A2-8AE0-5A59A8C00CFD@mattwynne.net> On 7 Jan 2010, at 07:22, Wincent Colaiuta wrote: > El 07/01/2010, a las 03:53, Phillip Koebbe escribi?: > >> Wincent Colaiuta wrote: >>> >>> Well, there is more than one way to skin a cat, but the thing I >>> like about my proposed solution is that: >>> >>> - the specification of the behavior appears in the "describe" >>> block that corresponds to the controller where the behavior is >>> implemented >>> >>> - but given that the implementing controller is an abstract one, >>> you actually test the behavior where it is actually exercised (ie. >>> in the subclasses) >>> >>> - you don't need to make a fictional controller which isn't >>> actually part of your application purely for testing purposes >>> >>> Looking at the gist you pasted it looks like it could be very >>> straightforward to test, especially if you're using a RESTful >>> access pattern. >>> >>> Your admin controllers all inherit from your abstract base class, >>> and if they're RESTful you know before you even start which >>> actions they'll respond to (the usual index, new, create etc). >>> Perhaps they only respond to a subset; but even if they only >>> respond to one ("show" or "index", say) you have enough of a >>> common basis to test that the require_admin before filter is >>> actually hit and does what you think it should (ie. you only need >>> to hit "show" or "index", there is no need to test all actions). >>> >>> Cheers, >>> Wincent >>> >> >> Are you basically saying that you wouldn't worry about testing the >> before_filter in the base_controller at all? > > Exactly. The base_controller is never directly instantiated and its > "behaviour" is only ever manifested in the context of its > subclasses, so you can test the behavior by testing that it exists > in the subclasses. > > As you have seen, you can't really test the abstract base_controller > directly itself because it has no actions. > >> Maybe part of the reason I am not "getting this" is my lack of >> familiarity with shared behaviors. If I share the behavior in the >> base_controller_spec, will it get tested when I run that spec? If >> it won't, then my concern is moot. If it will, then I'm just as >> confused as I was before. > > Shared behaviors are just a convenient way to define in behaviors > once in a single place, which will be exercised in multiple places, > so that you can keep things DRY. > > If you run the file with the "describe foo :shared => true" block in > it, nothing will actually happen. > > Your assertions get exercised only when you run other "describe" > blocks containing "it_should_behave_like ..." > > They can be useful not just in cases like this where you have an > abstract superclass. You can use them wherever you have a bunch of > common behavior across different classes. OK I'm going to bite on this one. Shared behaviours are indeed useful and a really nice idea. When I first started working with RSpec I used them exactly like this - I wrote no specs for abstract classes or modules, and wrote shared behaviour specs which I mixed in to all the classes that used the abstract class or module. I told myself: "this is much better - I'm not being distracted by the implementation details (inheritance, mixins) I'm just specifying the behaviour of the class". I think that method probably works great for small models, but I have found that over time on the Songkick codebase, I've come to rather dislike the shared behaviours. This is mainly, I think, because when I get a failure, the error message doesn't point me very clearly at which class was actually being tested when the failure occurred. I also think I resent them because I know that for a popular module, I might be running the exact same specs over the exact same code several times, for no purpose. What I now prefer to do is keep the interface between a module (or even an abstract class) and the class it's mixed into quite clean, and specify that re-usable unit in isolation, with an example using a temporary class created in the test. I might have one or two specs in the class which mixes in the module to prove that the module is mixed in and working, but most of the specs for the behaviour of that module itself will live alongside the module and run only once. As David said earlier there are strengths and weaknesses to both approaches so you have to find your own path here. I just wanted to share my experience. cheers, Matt http://mattwynne.net +447974 430184 From apremdas at gmail.com Thu Jan 7 05:20:06 2010 From: apremdas at gmail.com (Andrew Premdas) Date: Thu, 7 Jan 2010 10:20:06 +0000 Subject: [rspec-users] get to a different controller In-Reply-To: <4B454C9B.2040604@gmail.com> References: <4B4378B5.4000404@gmail.com> <2E305F4A-D13B-4E6F-8C7F-6A846BA4213A@patmaddox.com> <4B43A689.8090505@gmail.com> <93374C22-9461-4EF5-82A1-4D3EF01E4F3E@wincent.com> <4B44A98D.3090609@gmail.com> <386396F2-A3D0-46A0-8273-57608D912A55@wincent.com> <4B454C9B.2040604@gmail.com> Message-ID: <88fd8ddc1001070220t496d3b45v2064795924bb5a8f@mail.gmail.com> 2010/1/7 Phillip Koebbe > > > Wincent Colaiuta wrote: > >> >> Well, there is more than one way to skin a cat, but the thing I like about >> my proposed solution is that: >> >> - the specification of the behavior appears in the "describe" block that >> corresponds to the controller where the behavior is implemented >> >> - but given that the implementing controller is an abstract one, you >> actually test the behavior where it is actually exercised (ie. in the >> subclasses) >> >> - you don't need to make a fictional controller which isn't actually part >> of your application purely for testing purposes >> >> Looking at the gist you pasted it looks like it could be very >> straightforward to test, especially if you're using a RESTful access >> pattern. >> >> Your admin controllers all inherit from your abstract base class, and if >> they're RESTful you know before you even start which actions they'll respond >> to (the usual index, new, create etc). Perhaps they only respond to a >> subset; but even if they only respond to one ("show" or "index", say) you >> have enough of a common basis to test that the require_admin before filter >> is actually hit and does what you think it should (ie. you only need to hit >> "show" or "index", there is no need to test all actions). >> >> Cheers, >> Wincent >> >> > Are you basically saying that you wouldn't worry about testing the > before_filter in the base_controller at all? Maybe part of the reason I am > not "getting this" is my lack of familiarity with shared behaviors. If I > share the behavior in the base_controller_spec, will it get tested when I > run that spec? If it won't, then my concern is moot. If it will, then I'm > just as confused as I was before. > > You are using your base controller like an Abstract Class. In classic OO you can't test such classes because you can't instantiate them. Things are a little different here in Rails, but the parallel holds because you can't route this class. The classic way to test an abstract class is to instantiate a concrete class from it and test that. This is what you've done, created a concrete test class with a route. The only problem is you think the class is bogus, but its not, its just what you want, you can see that by how easy it is to spec. Once you've specified how this class works you should be able to share that specification using the techniques Wincent has shown. Saying that your other classes should behave like this special test class is perfectly fine. All best Andrew > Peace, > Phillip > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From phillipkoebbe at gmail.com Thu Jan 7 10:03:48 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Thu, 7 Jan 2010 07:03:48 -0800 (PST) Subject: [rspec-users] get to a different controller In-Reply-To: <88fd8ddc1001070220t496d3b45v2064795924bb5a8f@mail.gmail.com> References: <4B4378B5.4000404@gmail.com> <2E305F4A-D13B-4E6F-8C7F-6A846BA4213A@patmaddox.com> <4B43A689.8090505@gmail.com> <93374C22-9461-4EF5-82A1-4D3EF01E4F3E@wincent.com> <4B44A98D.3090609@gmail.com> <386396F2-A3D0-46A0-8273-57608D912A55@wincent.com> <4B454C9B.2040604@gmail.com> <88fd8ddc1001070220t496d3b45v2064795924bb5a8f@mail.gmail.com> Message-ID: To all involved, Great discussion! Thank you so much for taking the time out of your busy lives to contribute. Please believe me when I say that I appreciate it *very* much! Here is the latest version of my code: http://gist.github.com/269544 I like the idea of shared examples (trying to use the right terminology!). It took me a bit to realize that the shared examples have to be required somewhere. [I didn't see anything on rspec.info about it, but did not consult the RSpec Book. Maybe it's there.] I decided on the shared_controller_examples.rb file for now, but might change it later. I have some further refactoring to do regarding the chain of requiring files, but I'm pretty pleased at the moment. I can go both ways on where to test implementation: at the source or the execution. I worked on a Rails project last year that used Single Table Inheritance, and there was quite a bit of functionality defined in the base class with some additional functionality in the derived classes. We opted to test the different parts where they were, not where they would be exercised. It worked out well there. But in this case, I am convinced that shared examples are the way to go. I do *not* like creating classes in my specs just to run a test. That's akin to having routes or actions in my application that would be used only during testing. I can't bring myself to do it. Peace, Phillip From matt at reprocessed.org Thu Jan 7 09:15:12 2010 From: matt at reprocessed.org (Matt Patterson) Date: Thu, 7 Jan 2010 14:15:12 +0000 Subject: [rspec-users] describe "RSpec's documentation" do In-Reply-To: References: <98A6AC6B-BECC-4564-AF04-C49429AC7C75@mattwynne.net> Message-ID: <8A6FAA3A-5DAE-4343-98DB-B9F82FDE50C1@reprocessed.org> On 7 Jan 2010, at 00:53, Matt Wynne wrote: > On 5 Jan 2010, at 12:17, Matt Patterson wrote: > >> I've been looking at the documentation again recently, and I'd be happy to start work on this, particularly if Matt W is wanting to look at the cucumber end since he's just up the road from me. >> >> I'm very keen on the executable documentation aspects of this, and I did a whole load of work back in 2008 on this kind of stuff using RSpec, so I've got a bit of history here :-) > > Great. I think it's time we really started dogfooding cucumber in terms of producing executable documentation. The features for Cucumber itself could do with some housekeeping, but right now the focus there is on the code, so RSpec seems like a nice place to work on this from. > > I would like to see us try to build a flat HTML website (or PDF reference book) from rspec's features directory which could be used as reference by a new or curious user. As David says, I think we could drive out a bunch of really nice features from Cucumber to help make it much easier to build and maintain large suites of features. > > So what's the first step? A pint or two at the Reliance perhaps Mr Patterson? That sounds about right :-) Matt -- Matt Patterson | Design & Code | http://www.reprocessed.org/ From zach.dennis at gmail.com Thu Jan 7 11:42:28 2010 From: zach.dennis at gmail.com (Zach Dennis) Date: Thu, 7 Jan 2010 11:42:28 -0500 Subject: [rspec-users] get to a different controller In-Reply-To: <7365D4F8-7A51-49A2-8AE0-5A59A8C00CFD@mattwynne.net> References: <4B4378B5.4000404@gmail.com> <2E305F4A-D13B-4E6F-8C7F-6A846BA4213A@patmaddox.com> <4B43A689.8090505@gmail.com> <93374C22-9461-4EF5-82A1-4D3EF01E4F3E@wincent.com> <4B44A98D.3090609@gmail.com> <386396F2-A3D0-46A0-8273-57608D912A55@wincent.com> <4B454C9B.2040604@gmail.com> <7365D4F8-7A51-49A2-8AE0-5A59A8C00CFD@mattwynne.net> Message-ID: <85d99afe1001070842h41487ee9ode3c49a9cb0aefd3@mail.gmail.com> On Thu, Jan 7, 2010 at 5:09 AM, Matt Wynne wrote: > > On 7 Jan 2010, at 07:22, Wincent Colaiuta wrote: > >> El 07/01/2010, a las 03:53, Phillip Koebbe escribi?: >> >>> Wincent Colaiuta wrote: >>>> >>>> Well, there is more than one way to skin a cat, but the thing I like >>>> about my proposed solution is that: >>>> >>>> - the specification of the behavior appears in the "describe" block that >>>> corresponds to the controller where the behavior is implemented >>>> >>>> - but given that the implementing controller is an abstract one, you >>>> actually test the behavior where it is actually exercised (ie. in the >>>> subclasses) >>>> >>>> - you don't need to make a fictional controller which isn't actually >>>> part of your application purely for testing purposes >>>> >>>> Looking at the gist you pasted it looks like it could be very >>>> straightforward to test, especially if you're using a RESTful access >>>> pattern. >>>> >>>> Your admin controllers all inherit from your abstract base class, and if >>>> they're RESTful you know before you even start which actions they'll respond >>>> to (the usual index, new, create etc). Perhaps they only respond to a >>>> subset; but even if they only respond to one ("show" or "index", say) you >>>> have enough of a common basis to test that the require_admin before filter >>>> is actually hit and does what you think it should (ie. you only need to hit >>>> "show" or "index", there is no need to test all actions). >>>> >>>> Cheers, >>>> Wincent >>>> >>> >>> Are you basically saying that you wouldn't worry about testing the >>> before_filter in the base_controller at all? >> >> Exactly. The base_controller is never directly instantiated and its >> "behaviour" is only ever manifested in the context of its subclasses, so you >> can test the behavior by testing that it exists in the subclasses. >> >> As you have seen, you can't really test the abstract base_controller >> directly itself because it has no actions. >> >>> Maybe part of the reason I am not "getting this" is my lack of >>> familiarity with shared behaviors. If I share the behavior in the >>> base_controller_spec, will it get tested when I run that spec? If it won't, >>> then my concern is moot. If it will, then I'm just as confused as I was >>> before. >> >> Shared behaviors are just a convenient way to define in behaviors once in >> a single place, which will be exercised in multiple places, so that you can >> keep things DRY. >> >> If you run the file with the "describe foo :shared => true" block in it, >> nothing will actually happen. >> >> Your assertions get exercised only when you run other "describe" blocks >> containing "it_should_behave_like ..." >> >> They can be useful not just in cases like this where you have an abstract >> superclass. You can use them wherever you have a bunch of common behavior >> across different classes. > > OK I'm going to bite on this one. > > Shared behaviours are indeed useful and a really nice idea. When I first > started working with RSpec I used them exactly like this - I wrote no specs > for abstract classes or modules, and wrote shared behaviour specs which I > mixed in to all the classes that used the abstract class or module. I told > myself: "this is much better - I'm not being distracted by the > implementation details (inheritance, mixins) I'm just specifying the > behaviour of the class". > > > I think that method probably works great for small models, but I have found > that over time on the Songkick codebase, I've come to rather dislike the > shared behaviours. This is mainly, I think, because when I get a failure, > the error message doesn't point me very clearly at which class was actually > being tested when the failure occurred. I don't really see a correlation between size and usefulness of shared behaviours either through rspec's it_should_behave_like or a custom macro. When you describe a class in a spec that class is prepended to all of the example descriptions. For example: describe "a bar", :shared => true it "should serve up tequila" { ... } end describe Foo do it_should_behave_like "a bar" end will produce: Foo should serve up tequila If the top-level describe for an object isn't descriptive enough to communicate what class/module/etc is being spec'ed then I see what you're saying as a problem because the backtrace of a failed shared example won't help either, since the backtrace stems from the file that the shared example is stored in rather than the actual spec using it (I wonder if there is a way around this). > I also think I resent them because I > know that for a popular module, I might be running the exact same specs over > the exact same code several times, for no purpose. This doesn't bother me a whole lot. While I don't want to needlessly run examples multiple times to ensure something is working, I like err on the side of my objects are behaving correctly rather than an object includes a module. One of my reasons for this is because in the past I've unfortunately had to find the hard way classes that were buggy because of module inclusion order and one module overwrote another module's method, yada yada yada. I have personally also gotten into a groove for writing my own little shared macros and it makes it super simple to build new classes which re-use that functionality and know it actually works. > > What I now prefer to do is keep the interface between a module (or even an > abstract class) and the class it's mixed into quite clean, and specify that > re-usable unit in isolation, with an example using a temporary class created > in the test. I might have one or two specs in the class which mixes in the > module to prove that the module is mixed in and working, but most of the > specs for the behaviour of that module itself will live alongside the module > and run only once. This is excellent advice regardless of using shared examples, although it isn't always practical (clean interfaces are always practical, what isn't is creating new specs with test classes). Some modules are simply a grouping of certain behaviour that relies on other behaviour existing on an object. Creating a new test class to put in a spec can require a good amount of time and thinking based on the functionality and where what you're module's functionality falls into the overall chain of dependencies. There are times to be disciplined and put in that time and thinking. At other times, it's important to not misplace a bunch of time and energy if what you're working on doesn't warrant it. Unfortunately, making knowing when to make good decisions often comes from making bad ones. So as Corey Haines would suggest, practice practice practice! > > As David said earlier there are strengths and weaknesses to both approaches > so you have to find your own path here. I just wanted to share my > experience. Ditto. -- Zach Dennis http://www.continuousthinking.com (personal) http://www.mutuallyhuman.com (hire me) http://ideafoundry.info/behavior-driven-development (first rate BDD training) @zachdennis (twitter) From ben.fyvie at champsoftware.com Thu Jan 7 13:32:43 2010 From: ben.fyvie at champsoftware.com (Ben Fyvie) Date: Thu, 7 Jan 2010 12:32:43 -0600 Subject: [rspec-users] Problem with should_not when passing a multipleargs to a matcher In-Reply-To: <57c63afe1001062319p1ff0afc7ta72ea71f222623b3@mail.gmail.com> References: <4862558A4CDA426D80C03F951C599CA8@champ.net> <57c63afe1001062319p1ff0afc7ta72ea71f222623b3@mail.gmail.com> Message-ID: Thanks for looking at this David, Just so I am clear on what you are suggesting: 1. renaming the "include" matcher to "include_all" a. create an alias method for "include" for backwards compatibility 2. create a new matcher called "include_any" If this is indeed what you are suggesting, I think this would be great! Not only does it add the functionality we are looking for but the method names are self documenting and much easier to understand what functionality to expect from each one. Ben Fyvie _____ From: rspec-users-bounces at rubyforge.org [mailto:rspec-users-bounces at rubyforge.org] On Behalf Of David Chelimsky Sent: Thursday, January 07, 2010 1:19 AM To: rspec-users Subject: Re: [rspec-users] Problem with should_not when passing a multipleargs to a matcher On Wed, Jan 6, 2010 at 7:15 PM, Ben Fyvie wrote: We seem to be hitting some undesirable behavior with should_not in combination with matchers that accept collections. Let me use the "include" matcher for example (a co-worker reported similar problems using "be_any" so I don't believe this is limited to "include"). The RDoc states: Passes if actual includes expected. This works for collections and Strings. You can also pass in multiple args and it will only pass if all args are found in collection. Examples [1,2,3].should include(3) [1,2,3].should include(2,3) #would pass [1,2,3].should include(2,3,4) #would fail [1,2,3].should_not include(4) "spread".should include("read") "spread".should_not include("red") The RDoc doesn't give any examples of using a "should_not" along with multiple args being passed to "include", but since I couldn't find any documentation on why it would not work I assume that it should work. Here is a list of tests I came up with to find out what works and what doesn't. Note: All of these tests SHOULD fail; the problem is with the tests that do NOT fail. it "does properly fail on a collection when using \"should\" with multiple args" do [1,2,3].should include(2,3,4) end it "does NOT properly fail on a collection when using \"should_not\" with multiple args when at least one value in the expected args is in the actual collection" do [1,2,3].should_not include(3,4,5) end it "does properly fail on a collection when using \"should_not\" with multiple args when all of the values in the expected args are in the actual collection" do [1,2,3].should_not include(1,2,3) end it "does properly fail on a collection when using \"should_not\" with multiple args when all of the values in the expected args are in the actual collection and when the expected args don't cover all of the values in the actual collection" do [1,2,3].should_not include(1,2) end it "does properly fail on a collection when using \"should_not\" with a single arg" do [1,2,3].should_not include(3) end it "does properly fail on a string when using \"should_not\" with multiple args when all of the values in the expected args are in the actual string" do "abc".should_not include("a", "b", "c") end it "does NOT properly fail when using \"should_not\" with multiple args when at least one of the values in the expected args is in the actual string" do "abc".should_not include("a", "b", "e") end it "does properly fail on a string when using \"should_not\" with multiple args when all of the values in the expected args are in the actual collection and when the expected args don't cover all of the values in the actual string" do "abc".should_not include("a","b") end it "does properly fail on a string when using \"should_not\" with a single arg" do "abc".should_not include("a") end We are using the following rspec gems: Rspec-1.2.9 Rspec-rails-1.2.7.1 So I think one of two things needs to happen here dependent on whether this is desired behavior or not. 1. If this is desired behavior then an exception really should be raised if you try to use "should_not" in combination with passing a collection to a matcher. At the very least there needs to be some documentation to inform RSpec users that tests will not always fail as they might expect when using "should_not" in combination with a matcher that accepts multiple args. 2. If this is not desired behavior then of course we need a fix. I apologize if this has been brought up previously; I did as much searching on this issue as possible. Thanks in advance! Ben Fyvie Hi Ben, First, thank you for such a detailed, yet grok'able report. Second - I don't agree with your assessment that this is working incorrectly :) Unless I'm misreading your assessment, I'm reading that you expect "should include(*args)" to mean "should include ALL of these args" whereas "should_not include(*args)" means "should not include ANY of these args." Make sense? IMO, I think this is a documentation problem and that it is neither in need of an exception, nor in need of a fix. That said, perhaps we need a couple of matchers: include_all and include_any, with include being an alias for include_all. That would certainly clear up the confusion. WDYT? Cheers, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Thu Jan 7 14:15:53 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 7 Jan 2010 13:15:53 -0600 Subject: [rspec-users] Problem with should_not when passing a multipleargs to a matcher In-Reply-To: References: <4862558A4CDA426D80C03F951C599CA8@champ.net> <57c63afe1001062319p1ff0afc7ta72ea71f222623b3@mail.gmail.com> Message-ID: <57c63afe1001071115j687ed513o7156dda1b009e0bb@mail.gmail.com> On Thu, Jan 7, 2010 at 12:32 PM, Ben Fyvie wrote: > Thanks for looking at this David, > > > > Just so I am clear on what you are suggesting: > > 1. renaming the ?include? matcher to ?include_all? > 1. create an alias method for ?include? for backwards compatibility > 2. create a new matcher called ?include_any? > > Yep. > > > If this is indeed what you are suggesting, I think this would be great! Not > only does it add the functionality we are looking for but the method names > are self documenting and much easier to understand what functionality to > expect from each one. > Cool. I'm not sure when I'll get to this, but I'm pretty sure this would work for you for now (untested): Spec::Matchers.define :include_all do |*expected| match do |actual| expected.all? {|e| actual.include?(e)} end end Spec::Matchers.define :include_any do |*expected| match do |actual| expected.any? {|e| actual.include?(e)} end end Cheers, David > > > > > Ben Fyvie > > ------------------------------ > > *From:* rspec-users-bounces at rubyforge.org [mailto: > rspec-users-bounces at rubyforge.org] *On Behalf Of *David Chelimsky > *Sent:* Thursday, January 07, 2010 1:19 AM > *To:* rspec-users > *Subject:* Re: [rspec-users] Problem with should_not when passing a > multipleargs to a matcher > > > > On Wed, Jan 6, 2010 at 7:15 PM, Ben Fyvie > wrote: > > We seem to be hitting some undesirable behavior with should_not in > combination with matchers that accept collections. Let me use the ?include? > matcher for example (a co-worker reported similar problems using ?be_any? so > I don?t believe this is limited to ?include?). The RDoc states: > > Passes if actual includes expected. This works for collections and Strings. > You can also pass in multiple args and it will only pass if all args are > found in collection. > > Examples > > [1,2,3].should include(3) > > [1,2,3].should include(2,3) #would pass > > [1,2,3].should include(2,3,4) #would fail > > [1,2,3].should_not include(4) > > "spread".should include("read") > > "spread".should_not include("red") > > > > The RDoc doesn?t give any examples of using a ?should_not? along with > multiple args being passed to ?include?, but since I couldn?t find any > documentation on why it would not work I assume that it should work. Here is > a list of tests I came up with to find out what works and what doesn?t. > Note: All of these tests SHOULD fail; the problem is with the tests that do > NOT fail. > > it "does properly fail on a collection when using \"should\" with > multiple args" do > > [1,2,3].should include(2,3,4) > > end > > > > it "does NOT properly fail on a collection when using \"should_not\" > with multiple args when at least one value in the expected args is in the > actual collection" do > > [1,2,3].should_not include(3,4,5) > > end > > > > it "does properly fail on a collection when using \"should_not\" with > multiple args when all of the values in the expected args are in the actual > collection" do > > [1,2,3].should_not include(1,2,3) > > end > > > > it "does properly fail on a collection when using \"should_not\" with > multiple args when all of the values in the expected args are in the actual > collection and when the expected args don't cover all of the values in the > actual collection" do > > [1,2,3].should_not include(1,2) > > end > > > > it "does properly fail on a collection when using \"should_not\" with a > single arg" do > > [1,2,3].should_not include(3) > > end > > > > it "does properly fail on a string when using \"should_not\" with > multiple args when all of the values in the expected args are in the actual > string" do > > "abc".should_not include("a", "b", "c") > > end > > > > it "does NOT properly fail when using \"should_not\" with multiple args > when at least one of the values in the expected args is in the actual > string" do > > "abc".should_not include("a", "b", "e") > > end > > > > it "does properly fail on a string when using \"should_not\" with > multiple args when all of the values in the expected args are in the actual > collection and when the expected args don't cover all of the values in the > actual string" do > > "abc".should_not include("a","b") > > end > > > > it "does properly fail on a string when using \"should_not\" with a > single arg" do > > "abc".should_not include("a") > > end > > > > We are using the following rspec gems: > > Rspec-1.2.9 > > Rspec-rails-1.2.7.1 > > > > So I think one of two things needs to happen here dependent on whether this > is desired behavior or not. > > 1. If this is desired behavior then an exception really should be raised if > you try to use ?should_not? in combination with passing a collection to a > matcher. At the very least there needs to be some documentation to inform > RSpec users that tests will not always fail as they might expect when using > ?should_not? in combination with a matcher that accepts multiple args. > > 2. If this is not desired behavior then of course we need a fix. > > I apologize if this has been brought up previously; I did as much searching > on this issue as possible. > > Thanks in advance! > > Ben Fyvie > > > > Hi Ben, > > > > First, thank you for such a detailed, yet grok'able report. > > > > Second - I don't agree with your assessment that this is working > incorrectly :) > > > > Unless I'm misreading your assessment, I'm reading that you expect "should > include(*args)" to mean "should include ALL of these args" whereas > "should_not include(*args)" means "should not include ANY of these args." > > > > Make sense? > > > > IMO, I think this is a documentation problem and that it is neither in need > of an exception, nor in need of a fix. > > > > That said, perhaps we need a couple of matchers: include_all and > include_any, with include being an alias for include_all. That would > certainly clear up the confusion. WDYT? > > > > Cheers, > > 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: From ashley.moran at patchspace.co.uk Thu Jan 7 14:23:32 2010 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Thu, 7 Jan 2010 19:23:32 +0000 Subject: [rspec-users] Problem with should_not when passing a multipleargs to a matcher In-Reply-To: <57c63afe1001071115j687ed513o7156dda1b009e0bb@mail.gmail.com> References: <4862558A4CDA426D80C03F951C599CA8@champ.net> <57c63afe1001062319p1ff0afc7ta72ea71f222623b3@mail.gmail.com> <57c63afe1001071115j687ed513o7156dda1b009e0bb@mail.gmail.com> Message-ID: On 7 Jan 2010, at 19:15, David Chelimsky wrote: > Cool. I'm not sure when I'll get to this, but I'm pretty sure this would work for you for now (untested): > > Spec::Matchers.define :include_all do |*expected| > match do |actual| > expected.all? {|e| actual.include?(e)} > end > end > > Spec::Matchers.define :include_any do |*expected| > match do |actual| > expected.any? {|e| actual.include?(e)} > end > end Hi Ben/David If it's any help, I've been using three extra matchers for a while now: * include_all_once * include_all_at_least_times * include_any I've put them in a gist[1], as the code to produce the error messages makes them a bit verbose. HTH Ashley [1] http://gist.github.com/271475 -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashleymoran From fausto.galli at email.it Fri Jan 8 08:24:32 2010 From: fausto.galli at email.it (mix) Date: Fri, 8 Jan 2010 05:24:32 -0800 (PST) Subject: [rspec-users] How call a method/something after ALL specs? Message-ID: hi, is there a way to call a method/print something after ALL the specs are run ? (with all, i mean all, after all the spec files, just before the rspec output which say how many spec have passed).. i want to print some text telling which is the average response time and which is the action which takes more time I've tried with the ruby at_exit method, but it puts the result 3 times, any hint? From dchelimsky at gmail.com Fri Jan 8 08:48:26 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 8 Jan 2010 07:48:26 -0600 Subject: [rspec-users] How call a method/something after ALL specs? In-Reply-To: References: Message-ID: <57c63afe1001080548k56b79e91q8366f0f73e780c4e@mail.gmail.com> On Fri, Jan 8, 2010 at 7:24 AM, mix wrote: > hi, is there a way to call a method/print something after ALL the > specs are run ? (with all, i mean all, after all the spec files, just > before the rspec output which say how many spec have passed).. > > i want to print some text telling which is the average response time > and which is the action which takes more time > > I've tried with the ruby at_exit method, but it puts the result 3 > times, any hint? > Best bet is probably a custom formatter. I'd make a subclass of the formatter you want to use, for example Spec::Runner::Formatter::ProgressBarFormatter, and override the dump_summary method (which is defined in Spec::Runner::Formatter::BaseTextFormatter). Then you can say: spec spec --formatter HTH, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From sean at clipperadams.com Fri Jan 8 22:37:13 2010 From: sean at clipperadams.com (DeNigris Sean) Date: Fri, 8 Jan 2010 22:37:13 -0500 Subject: [rspec-users] Stubbing through multiple layers Message-ID: <75262705-0B32-48BF-9555-8271CE607E58@clipperadams.com> Hi list, I'm writing an example for a class that represents the "pickaxe" e-book, which I view in Preview.app: describe PickaxeBook do ... it "should tell whether it's ready to read" do preview = stub('preview') preview.stub!(:******this is what I'm not sure about - see below*******).returns("programming_ruby_1.9.pdf") my_pickaxe_book = PickaxeBook.new(preview) my_pickaxe_book.should be_ready_to_read end end class PickaxeBook ... def ready_to_read? #****** this is the dependency I want to stub: preview.front_window.title ******** preview.front_window.title =~ /programming_ruby_1.9\.pdf.*/ end end Can you see the problem? ready_to_read wants to query the object returned by front_window, but how do I stub that? I should note that the Preview class is in a different library, which is why I don't just change front_window.title I thought of a few things, like introducing a role (something like "PreviewInfoRetriever") with a method "front_window_title" that forwards to preview.front_window.title, but that seems like a lot of complexity. To summarize: what's the best way to handle a dependency like object.method.method? Thanks! Sean DeNigris sean at clipperadams.com From dchelimsky at gmail.com Sat Jan 9 07:02:59 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 9 Jan 2010 06:02:59 -0600 Subject: [rspec-users] Stubbing through multiple layers In-Reply-To: <75262705-0B32-48BF-9555-8271CE607E58@clipperadams.com> References: <75262705-0B32-48BF-9555-8271CE607E58@clipperadams.com> Message-ID: <57c63afe1001090402v36f17bafp1540aade31e256d2@mail.gmail.com> On Fri, Jan 8, 2010 at 9:37 PM, DeNigris Sean wrote: > Hi list, > > I'm writing an example for a class that represents the "pickaxe" e-book, > which I view in Preview.app: > > describe PickaxeBook do > ... > it "should tell whether it's ready to read" do > preview = stub('preview') > preview.stub!(:******this is what I'm not sure about - see > below*******).returns("programming_ruby_1.9.pdf") > > my_pickaxe_book = PickaxeBook.new(preview) > > my_pickaxe_book.should be_ready_to_read > end > end > > class PickaxeBook > ... > def ready_to_read? > #****** this is the dependency I want to stub: > preview.front_window.title ******** > preview.front_window.title =~ /programming_ruby_1.9\.pdf.*/ > end > end > > Can you see the problem? ready_to_read wants to query the object returned > by front_window, but how do I stub that? I should note that the Preview > class is in a different library, which is why I don't just change > front_window.title > > I thought of a few things, like introducing a role (something like > "PreviewInfoRetriever") with a method "front_window_title" that forwards to > preview.front_window.title, but that seems like a lot of complexity. > > To summarize: what's the best way to handle a dependency like > object.method.method? > There is no universally best way. Stubbing it is fairly straightforward: window = stub('window', :title => "programming_ruby_1.9.pdf") preview = stub('preview', :front_window => window) The risk is that this example is now bound to the internal structure of an object provided by a 3rd party, which can change in a future release. If that happened, this example might continue passing with a false positive, and the app won't work. If you have good high level specs with something like Cucumber or FitNesse, this risk is diminished. You'll still have to change the example when the internal structure of Preview changes, but you're less likely to get burned by deploying code that passes its tests but doesn't work. If it's easy and inexpensive to create a real instance of Preview, I'd sooner do that. HTH, David > Thanks! > > Sean DeNigris > sean at clipperadams.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: From matt at mattwynne.net Sat Jan 9 07:28:27 2010 From: matt at mattwynne.net (Matt Wynne) Date: Sat, 9 Jan 2010 12:28:27 +0000 Subject: [rspec-users] Stubbing through multiple layers In-Reply-To: <57c63afe1001090402v36f17bafp1540aade31e256d2@mail.gmail.com> References: <75262705-0B32-48BF-9555-8271CE607E58@clipperadams.com> <57c63afe1001090402v36f17bafp1540aade31e256d2@mail.gmail.com> Message-ID: <65A2622F-EFB3-491D-9195-07E8E27309DE@mattwynne.net> On 9 Jan 2010, at 12:02, David Chelimsky wrote: > On Fri, Jan 8, 2010 at 9:37 PM, DeNigris Sean > wrote: > Hi list, > > I'm writing an example for a class that represents the "pickaxe" e- > book, which I view in Preview.app: > > describe PickaxeBook do > ... > it "should tell whether it's ready to read" do > preview = stub('preview') > preview.stub!(:******this is what I'm not sure about > - see below*******).returns("programming_ruby_1.9.pdf") > > my_pickaxe_book = PickaxeBook.new(preview) > > my_pickaxe_book.should be_ready_to_read > end > end > > class PickaxeBook > ... > def ready_to_read? > #****** this is the dependency I want to stub: > preview.front_window.title ******** > preview.front_window.title =~ / > programming_ruby_1.9\.pdf.*/ > end > end > > Can you see the problem? ready_to_read wants to query the object > returned by front_window, but how do I stub that? I should note > that the Preview class is in a different library, which is why I > don't just change front_window.title > > I thought of a few things, like introducing a role (something like > "PreviewInfoRetriever") with a method "front_window_title" that > forwards to preview.front_window.title, but that seems like a lot of > complexity. > > To summarize: what's the best way to handle a dependency like > object.method.method? > > There is no universally best way. Stubbing it is fairly > straightforward: > > window = stub('window', :title => "programming_ruby_1.9.pdf") > preview = stub('preview', :front_window => window) > > The risk is that this example is now bound to the internal structure > of an object provided by a 3rd party, which can change in a future > release. If that happened, this example might continue passing with > a false positive, and the app won't work. > > If you have good high level specs with something like Cucumber or > FitNesse, this risk is diminished. You'll still have to change the > example when the internal structure of Preview changes, but you're > less likely to get burned by deploying code that passes its tests > but doesn't work. > > If it's easy and inexpensive to create a real instance of Preview, > I'd sooner do that. Or wrap the Preview object with your own (maybe PreviewWindow?) and offer a #has_title? method on that wrapper. > > HTH, > David > > Thanks! > > Sean DeNigris > sean at clipperadams.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 cheers, Matt http://mattwynne.net +447974 430184 From rogerpack2005 at gmail.com Sat Jan 9 13:33:26 2010 From: rogerpack2005 at gmail.com (rogerdpack) Date: Sat, 9 Jan 2010 10:33:26 -0800 (PST) Subject: [rspec-users] more verbosity for be_an? In-Reply-To: <57c63afe0912301219l43937dc6he78256e600eeeb30@mail.gmail.com> References: <57c63afe0912301219l43937dc6he78256e600eeeb30@mail.gmail.com> Message-ID: <2d721d86-2f09-4343-ae34-e02c17fa5b99@r24g2000yqd.googlegroups.com> > What about something like: > > ? expected # => Fixnum to be a kind of Fixnum Still in favor of something like this... :) -rp From rogerpack2005 at gmail.com Sat Jan 9 13:34:32 2010 From: rogerpack2005 at gmail.com (rogerdpack) Date: Sat, 9 Jan 2010 10:34:32 -0800 (PST) Subject: [rspec-users] straight strings? Message-ID: I saw some tests like this the other day: it "the nodes are the contents of the directory" do ... end Made me wonder if the idea had been proposed to skip the it, like. "the nodes are the contents of the directory".do { ... } or what not. Thoughts? -r From rick.denatale at gmail.com Sat Jan 9 13:51:04 2010 From: rick.denatale at gmail.com (Rick DeNatale) Date: Sat, 9 Jan 2010 13:51:04 -0500 Subject: [rspec-users] more verbosity for be_an? In-Reply-To: <2d721d86-2f09-4343-ae34-e02c17fa5b99@r24g2000yqd.googlegroups.com> References: <57c63afe0912301219l43937dc6he78256e600eeeb30@mail.gmail.com> <2d721d86-2f09-4343-ae34-e02c17fa5b99@r24g2000yqd.googlegroups.com> Message-ID: On Sat, Jan 9, 2010 at 1:33 PM, rogerdpack wrote: > >> What about something like: >> >> ? expected # => Fixnum to be a kind of Fixnum Truthfully, I find this much less clear than the original message. I've got no idea what # => Fixnum means. Expected Fixnum to be kind of Fixnum makes a lot of sense to me because I know that x.kind_of? Y means that x is an INSTANCE of Y or one of it's subclasses, and Fixnum is not a Fixnum but a class. Pondering this if you don't know that should lead to doing a little reading and then realizing that you probably wanted 1.should be_a FixNum instead of 1.class.should be_a Fixnum -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale From tom at experthuman.com Sat Jan 9 14:38:54 2010 From: tom at experthuman.com (Tom Stuart) Date: Sat, 9 Jan 2010 19:38:54 +0000 Subject: [rspec-users] straight strings? In-Reply-To: References: Message-ID: <4B8832E0-B29F-44D5-9B02-960DDE056EED@experthuman.com> On 9 Jan 2010, at 18:34, rogerdpack wrote: > I saw some tests like this the other day: > it "the nodes are the contents of the directory" do In this case I say "specify" instead. From trusted08 at clipperadams.com Sat Jan 9 22:38:39 2010 From: trusted08 at clipperadams.com (Sean DeNigris) Date: Sat, 9 Jan 2010 19:38:39 -0800 (PST) Subject: [rspec-users] Stubbing through multiple layers In-Reply-To: <57c63afe1001090402v36f17bafp1540aade31e256d2@mail.gmail.com> References: <75262705-0B32-48BF-9555-8271CE607E58@clipperadams.com> <57c63afe1001090402v36f17bafp1540aade31e256d2@mail.gmail.com> Message-ID: <4cfb8f2c-7372-43ea-9cc1-ad4acc46f78b@p8g2000yqb.googlegroups.com> > window = stub('window', :title => "programming_ruby_1.9.pdf") > preview = stub('preview', :front_window => window) Perfect - so easy! Thanks. > If you have good high level specs with something like Cucumber or FitNesse, > this risk is diminished. You'll still have to change the example when the > internal structure of Preview changes, but you're less likely to get burned > by deploying code that passes its tests but doesn't work. This is something I've been going back and forth with a lot lately - how much implementation detail to allow to leak out into the examples/ features. If I start using software other than Preview to read my eBooks, obviously all these examples will require reworking. The problem is magnified because I do have Cucumber tests that use the real Preview: Then /^I should see the pickaxe book$/ do front_preview_window = Appscript::app('System Events').processes ['Preview'].windows[1] Appscript::app('System Events').processes ['Preview'].frontmost.get.should be(true) front_preview_window.name.get.should =~ /programming_ruby_1.9.* \.pdf.*/ end Now details about Preview appear in Cucumber and Rspec! I'm tempted to put an EBookViewer role in right off the bat (similar to what Matt sugested), and use it in both the features and examples, but I don't want to add too much complexity. I'm very interested in how other people handle external dependencies in features/examples... Thanks again! Sean From dchelimsky at gmail.com Sun Jan 10 08:42:41 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 10 Jan 2010 07:42:41 -0600 Subject: [rspec-users] Stubbing through multiple layers In-Reply-To: <4cfb8f2c-7372-43ea-9cc1-ad4acc46f78b@p8g2000yqb.googlegroups.com> References: <75262705-0B32-48BF-9555-8271CE607E58@clipperadams.com> <57c63afe1001090402v36f17bafp1540aade31e256d2@mail.gmail.com> <4cfb8f2c-7372-43ea-9cc1-ad4acc46f78b@p8g2000yqb.googlegroups.com> Message-ID: <57c63afe1001100542x5e1bb3b0l8c7e3e4f854b6e53@mail.gmail.com> On Sat, Jan 9, 2010 at 9:38 PM, Sean DeNigris wrote: > > window = stub('window', :title => "programming_ruby_1.9.pdf") > > preview = stub('preview', :front_window => window) > Perfect - so easy! Thanks. > > > If you have good high level specs with something like Cucumber or > FitNesse, > > this risk is diminished. You'll still have to change the example when the > > internal structure of Preview changes, but you're less likely to get > burned > > by deploying code that passes its tests but doesn't work. > This is something I've been going back and forth with a lot lately - > how much implementation detail to allow to leak out into the examples/ > features. If I start using software other than Preview to read my > eBooks, obviously all these examples will require reworking. The > problem is magnified because I do have Cucumber tests that use the > real Preview: > > Then /^I should see the pickaxe book$/ do > front_preview_window = Appscript::app('System Events').processes > ['Preview'].windows[1] > Appscript::app('System Events').processes > ['Preview'].frontmost.get.should be(true) > front_preview_window.name.get.should =~ /programming_ruby_1.9.* > \.pdf.*/ > end > > Now details about Preview appear in Cucumber and Rspec! I'm tempted > to put an EBookViewer role in right off the bat (similar to what Matt > sugested), and use it in both the features and examples, but I don't > want to add too much complexity. > I think it's clear that there is already too much complexity in this case :) I'd go with the wrapper. It should not be expensive to maintain, and it does give you the freedom to change the dependencies, localizing the cost of that change to a single object. > I'm very interested in how other people handle external dependencies > in features/examples... > > Thanks again! > > Sean > -------------- next part -------------- An HTML attachment was scrubbed... URL: From court3nay at gmail.com Sun Jan 10 08:40:40 2010 From: court3nay at gmail.com (Courtenay) Date: Sun, 10 Jan 2010 05:40:40 -0800 Subject: [rspec-users] Stubbing through multiple layers In-Reply-To: <4cfb8f2c-7372-43ea-9cc1-ad4acc46f78b@p8g2000yqb.googlegroups.com> References: <75262705-0B32-48BF-9555-8271CE607E58@clipperadams.com> <57c63afe1001090402v36f17bafp1540aade31e256d2@mail.gmail.com> <4cfb8f2c-7372-43ea-9cc1-ad4acc46f78b@p8g2000yqb.googlegroups.com> Message-ID: <4b430c8f1001100540x45ed6f56u900e301de36c1bbd@mail.gmail.com> On Sat, Jan 9, 2010 at 7:38 PM, Sean DeNigris wrote: >> ? window = stub('window', :title => "programming_ruby_1.9.pdf") >> ? preview = stub('preview', :front_window => window) > Perfect - so easy! ?Thanks. > There's also stub_chain, which is probably a Bad Thing but helps break through layers of dependencies. From onno.van.der.straaten at gmail.com Sun Jan 10 16:22:28 2010 From: onno.van.der.straaten at gmail.com (Onno van der Straaten) Date: Sun, 10 Jan 2010 22:22:28 +0100 Subject: [rspec-users] Code for the RSpec book Message-ID: Hi, I'm trying to download the code for the RSpec book from github http://wiki.github.com/dchelimsky/rspec/code-for-the-rspec-book-beta. When I click 'Download Source' a window with a busy icon appears and then nothing happens. I am using FireFox and Linux Mint. Any thoughts on this? Is this a GitHub issue? is there a alternate location to get the source for the book? Thanks and Regards, Onno -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Sun Jan 10 21:55:46 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 10 Jan 2010 20:55:46 -0600 Subject: [rspec-users] Code for the RSpec book In-Reply-To: References: Message-ID: <57c63afe1001101855u1c6ef4f3y3f25aabc28becc85@mail.gmail.com> On Sun, Jan 10, 2010 at 3:22 PM, Onno van der Straaten < onno.van.der.straaten at gmail.com> wrote: > Hi, > I'm trying to download the code for the RSpec book from github > http://wiki.github.com/dchelimsky/rspec/code-for-the-rspec-book-beta. > > When I click 'Download Source' a window with a busy icon appears and then > nothing happens. I am using FireFox and Linux Mint. > > Any thoughts on this? Is this a GitHub issue? is there a alternate location > to get the source for the book? > Github does not host The RSpec Book. That was just the easiest place for me to post information about what library versions you need. The source code for the exercises in The RSpec Book can be downloaded from http://pragprog.com/titles/achbd/source_code. Cheers, David > Thanks and Regards, > Onno > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Sun Jan 10 23:58:24 2010 From: lists at ruby-forum.com (Nick Hoffman) Date: Mon, 11 Jan 2010 05:58:24 +0100 Subject: [rspec-users] Troubles with route_for Message-ID: Hey guys. I'm having some trouble with a route spec. In routes.rb , I have: map.connect 'foods/search/:name', :controller => :foods, :action => :search foods_controller_spec.rb has: http://codepad.org/dg3FERKw Unfortunately, that fails: http://codepad.org/lck4r1S0 After reading the rspec-rails 1.2.0 upgrade notes (http://tr.im/K1zx), I haven't been able to figure out what I'm doing wrong. Any hints? Thanks! Nick PS: I'm using 1.2.9 and Rails 2.3.4 . -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Mon Jan 11 01:40:11 2010 From: lists at ruby-forum.com (Amit Kulkarni) Date: Mon, 11 Jan 2010 07:40:11 +0100 Subject: [rspec-users] Troubles with route_for In-Reply-To: References: Message-ID: <8f6569048bcdaa178282f69aaa31c4c0@ruby-forum.com> Nick Hoffman wrote: > Hey guys. I'm having some trouble with a route spec. In routes.rb , I > have: > map.connect 'foods/search/:name', :controller => :foods, :action => > :search > > foods_controller_spec.rb has: http://codepad.org/dg3FERKw > Unfortunately, that fails: http://codepad.org/lck4r1S0 > > After reading the rspec-rails 1.2.0 upgrade notes (http://tr.im/K1zx), I > haven't been able to figure out what I'm doing wrong. Any hints? > > Thanks! > Nick > > PS: I'm using 1.2.9 and Rails 2.3.4 . Hi Nick, You need to add quotes while writing in routs.rb file. So your route will be define as : map.connect 'foods/search/:name', :controller => 'foods', :action => 'search' Now try running the code again.You will see it pass. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Mon Jan 11 01:56:48 2010 From: lists at ruby-forum.com (Nick Hoffman) Date: Mon, 11 Jan 2010 07:56:48 +0100 Subject: [rspec-users] Troubles with route_for In-Reply-To: <8f6569048bcdaa178282f69aaa31c4c0@ruby-forum.com> References: <8f6569048bcdaa178282f69aaa31c4c0@ruby-forum.com> Message-ID: Amit Kulkarni wrote: > Nick Hoffman wrote: >> Hey guys. I'm having some trouble with a route spec. In routes.rb , I >> have: >> map.connect 'foods/search/:name', :controller => :foods, :action => >> :search >> >> foods_controller_spec.rb has: http://codepad.org/dg3FERKw >> Unfortunately, that fails: http://codepad.org/lck4r1S0 >> >> After reading the rspec-rails 1.2.0 upgrade notes (http://tr.im/K1zx), I >> haven't been able to figure out what I'm doing wrong. Any hints? >> >> Thanks! >> Nick >> >> PS: I'm using 1.2.9 and Rails 2.3.4 . > Hi Nick, > You need to add quotes while writing in routs.rb file. > So your route will be define as : > map.connect 'foods/search/:name', :controller => 'foods', :action => > 'search' > Now try running the code again.You will see it pass. Thanks for the suggestion, Amit. I changed the symbols to strings. Unfortunately, the same error is still occurring: http://codepad.org/lck4r1S0 -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Mon Jan 11 08:46:54 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 11 Jan 2010 07:46:54 -0600 Subject: [rspec-users] Troubles with route_for In-Reply-To: References: Message-ID: <57c63afe1001110546g762cb3e5pfba7227cc8b0b960@mail.gmail.com> On Sun, Jan 10, 2010 at 10:58 PM, Nick Hoffman wrote: > Hey guys. I'm having some trouble with a route spec. In routes.rb , I > have: > map.connect 'foods/search/:name', :controller => :foods, :action => > :search > > foods_controller_spec.rb has: http://codepad.org/dg3FERKw > Unfortunately, that fails: http://codepad.org/lck4r1S0 > > After reading the rspec-rails 1.2.0 upgrade notes (http://tr.im/K1zx), I > haven't been able to figure out what I'm doing wrong. Any hints? > I'd recommend using the route_to matcher that was added in 1.2.9 instead. http://codepad.org/fLcxyA9N http://rspec.rubyforge.org/rspec-rails/1.2.9/classes/Spec/Rails/Matchers.html#M000029 It's more reliable, and aligns better with the rspec matchers API. Cheers, David > > Thanks! > Nick > > PS: I'm using 1.2.9 and Rails 2.3.4 . > -- > 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: From dchelimsky at gmail.com Mon Jan 11 22:48:46 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 11 Jan 2010 21:48:46 -0600 Subject: [rspec-users] [ANN] rspec 1.3.0 Released Message-ID: <57c63afe1001111948p218f59c2k4acd86948f548f51@mail.gmail.com> rspec version 1.3.0 has been released! * * * * * Behaviour Driven Development for Ruby. Changes: ### Version 1.3.0 / 2010-01-11 * enhancements * capture ExpectationNotMet error by default in matcher DSL * supports wrapping other expectations * added match_unless_raises to matcher DSL * supports easy wrapping of t/u assertions in matchers * thanks to Chad Fowler and Glenn Vanderburg for the name * add chain to matcher DSL (Joe Ferris - #935) * see rdoc for Spec::Matchers * and_yield provides configurable eval_context * Eric Meyer & David Chelimsky * CTRL-C actually stops execution! (Bryan Helmkamp - #911) * make drb port configurable (Chris Flipse - #875) * changed raise_error to raise_exception (#933) * kept raise_error aliased, so this is completely backwards compatible * bug fixes * don't define top-level context() method when running in IRB (#899) * remove Ruby warning for uninitialized ivar (Bryan Helmkamp - #892) * fully qualify reference to Default (Alex Sharp - #895) * use runtime version of Test::Unit::VERSION in incompatibility message (Ryan Bigg - #916) * quote paths in RSpec's own specs so people running in paths with spaces in them can achieve green too (Ryan Bigg - #917) * ensure drb specs run when EADDRNOTAVAIL (Michael Klett - #881) * throw_symbol matcher correctly bubbles errors up (#918) * make Rakefile work without Cucumber installed (#919 - devrandom) * escape . in regexp (#925) * align be_true and be_false with Ruby's conditional semantics (#931) * print duplicate nested descriptions (when appropriate) (#936) -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Mon Jan 11 22:48:52 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 11 Jan 2010 21:48:52 -0600 Subject: [rspec-users] [ANN] rspec-rails 1.3.0 Released Message-ID: <57c63afe1001111948i7c64f25dx27e8d162eb0d9fba@mail.gmail.com> rspec-rails version 1.3.0 has been released! * * * * * Behaviour Driven Development for Ruby on Rails. Changes: ### Version 1.3.0 / 2010-01-11 * enhancements * use stub() instead of stub!() in generators * generate gem config in test.rb with 'script/generate rspec' -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Mon Jan 11 23:16:54 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 11 Jan 2010 22:16:54 -0600 Subject: [rspec-users] Chad Humphries Message-ID: <57c63afe1001112016v4dc456f1sf393c84484b654be@mail.gmail.com> Welcome Chad Humphries to the Rspec Development Team! http://blog.davidchelimsky.net/2010/01/12/welcome-chad-humphries/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Tue Jan 12 00:22:01 2010 From: lists at ruby-forum.com (Nick Hoffman) Date: Tue, 12 Jan 2010 06:22:01 +0100 Subject: [rspec-users] Troubles with route_for In-Reply-To: <57c63afe1001110546g762cb3e5pfba7227cc8b0b960@mail.gmail.com> References: <57c63afe1001110546g762cb3e5pfba7227cc8b0b960@mail.gmail.com> Message-ID: David Chelimsky wrote: > I'd recommend using the route_to matcher that was added in 1.2.9 > instead. > > http://codepad.org/fLcxyA9N > http://rspec.rubyforge.org/rspec-rails/1.2.9/classes/Spec/Rails/Matchers.html#M000029 > > It's more reliable, and aligns better with the rspec matchers API. > > Cheers, > David Thanks for that, David. I updated my spec (http://codepad.org/F828X7Fg). For some reason though, it's still failing: http://codepad.org/s65Ckubc Just in case, this is what I have in routes.rb: http://codepad.org/rJfIhbM6 There must be some tiny detail that I'm missing here... -- Posted via http://www.ruby-forum.com/. From r_j_h_box-sf at yahoo.com Tue Jan 12 02:06:04 2010 From: r_j_h_box-sf at yahoo.com (Randy Harmon) Date: Mon, 11 Jan 2010 23:06:04 -0800 Subject: [rspec-users] Troubles with route_for In-Reply-To: References: <57c63afe1001110546g762cb3e5pfba7227cc8b0b960@mail.gmail.com> Message-ID: <4B4C1F5C.3010506@yahoo.com> On 1/11/10 9:22 PM, Nick Hoffman wrote: > David Chelimsky wrote: > >> I'd recommend using the route_to matcher that was added in 1.2.9 >> instead. >> >> http://codepad.org/fLcxyA9N >> http://rspec.rubyforge.org/rspec-rails/1.2.9/classes/Spec/Rails/Matchers.html#M000029 >> >> It's more reliable, and aligns better with the rspec matchers API. >> >> Cheers, >> David >> > Thanks for that, David. I updated my spec (http://codepad.org/F828X7Fg). > For some reason though, it's still failing: http://codepad.org/s65Ckubc > > Just in case, this is what I have in routes.rb: > http://codepad.org/rJfIhbM6 > > There must be some tiny detail that I'm missing here... > Yes, there must. I think you've tried to twice define the route, and the test shows you which one actually is being used. I'll suggest commenting out one of those routes at a time, and see whether the new test results are illuminating. Randy From lists at ruby-forum.com Tue Jan 12 12:25:20 2010 From: lists at ruby-forum.com (Nick Hoffman) Date: Tue, 12 Jan 2010 18:25:20 +0100 Subject: [rspec-users] Troubles with route_for In-Reply-To: <4B4C1F5C.3010506@yahoo.com> References: <57c63afe1001110546g762cb3e5pfba7227cc8b0b960@mail.gmail.com> <4B4C1F5C.3010506@yahoo.com> Message-ID: <0cc23fb5c587c4e1232fe5adbbfaa208@ruby-forum.com> Randy Harmon wrote: > On 1/11/10 9:22 PM, Nick Hoffman wrote: >>> Cheers, >>> David >>> >> Thanks for that, David. I updated my spec (http://codepad.org/F828X7Fg). >> For some reason though, it's still failing: http://codepad.org/s65Ckubc >> >> Just in case, this is what I have in routes.rb: >> http://codepad.org/rJfIhbM6 >> >> There must be some tiny detail that I'm missing here... >> > Yes, there must. I think you've tried to twice define the route, and > the test shows you which one actually is being used. I'll suggest > commenting out one of those routes at a time, and see whether the new > test results are illuminating. > > Randy I swapped the order of the 2 lines in routes.rb to this: map.connect 'foods/search/:name', :controller => 'foods', :action => 'search' map.resources :foods, :collection => {:search => :get} and the spec passes now. Thanks, guys! -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Tue Jan 12 12:35:13 2010 From: lists at ruby-forum.com (Nick Hoffman) Date: Tue, 12 Jan 2010 18:35:13 +0100 Subject: [rspec-users] Troubles with route_for In-Reply-To: <0cc23fb5c587c4e1232fe5adbbfaa208@ruby-forum.com> References: <57c63afe1001110546g762cb3e5pfba7227cc8b0b960@mail.gmail.com> <4B4C1F5C.3010506@yahoo.com> <0cc23fb5c587c4e1232fe5adbbfaa208@ruby-forum.com> Message-ID: <93f60ccf6698a5d0e8d470ce7cc280ec@ruby-forum.com> By the way, does this spec: {:get => '/path'}.should route_to(...) make this spec redundant?: params_from(:get, '/path').should == {...} They read the same, but it feels like they each check one end of the route's translation. -- Posted via http://www.ruby-forum.com/. From rogerpack2005 at gmail.com Tue Jan 12 17:40:09 2010 From: rogerpack2005 at gmail.com (rogerdpack) Date: Tue, 12 Jan 2010 14:40:09 -0800 (PST) Subject: [rspec-users] nested steps Message-ID: Question. Currently rspec appears to allow for a two-step test system, like context "abc" it 'should do y' do end end It might be convenient to have an arbitrary number of nests, like context "abc" it 'should do y' do it 'should also be able to do x' end end end Thoughts? -r From dchelimsky at gmail.com Tue Jan 12 17:46:36 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 12 Jan 2010 16:46:36 -0600 Subject: [rspec-users] nested steps In-Reply-To: References: Message-ID: <57c63afe1001121446g3392b95aq4807378b31228ee4@mail.gmail.com> On Tue, Jan 12, 2010 at 4:40 PM, rogerdpack wrote: > Question. > Currently rspec appears to allow for a two-step test system, like > > context "abc" > it 'should do y' do > end > end > > It might be convenient to have an arbitrary number of nests, like > > context "abc" > it 'should do y' do > > it 'should also be able to do x' > end > > end > end > > Thoughts? > -r > Why would that be more convenient? Can you give a more concrete example (with some sample code)? David -------------- next part -------------- An HTML attachment was scrubbed... URL: From rogerpack2005 at gmail.com Tue Jan 12 17:49:17 2010 From: rogerpack2005 at gmail.com (rogerdpack) Date: Tue, 12 Jan 2010 14:49:17 -0800 (PST) Subject: [rspec-users] default to just call the method? Message-ID: <8936163d-331b-49c8-aac7-2fc089556f18@a6g2000yqm.googlegroups.com> Any interest in the following idea? a.should include?("1:4") # if there's no matcher called include? then just call include? or something along those lines? -r From matt at mattwynne.net Tue Jan 12 17:50:11 2010 From: matt at mattwynne.net (Matt Wynne) Date: Tue, 12 Jan 2010 22:50:11 +0000 Subject: [rspec-users] nested steps In-Reply-To: References: Message-ID: <76DB06A5-9A23-47AF-A27D-733BB43BF41D@mattwynne.net> On 12 Jan 2010, at 22:40, rogerdpack wrote: > Question. > Currently rspec appears to allow for a two-step test system, like > > context "abc" > it 'should do y' do > end > end > > It might be convenient to have an arbitrary number of nests, like > > context "abc" > it 'should do y' do > > it 'should also be able to do x' > end > > end You do realise you can already nest contexts don't you? That makes much more sense to me than what you've suggested. > end > > Thoughts? > -r > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users cheers, Matt http://mattwynne.net +447974 430184 From rogerpack2005 at gmail.com Tue Jan 12 17:41:46 2010 From: rogerpack2005 at gmail.com (rogerdpack) Date: Tue, 12 Jan 2010 14:41:46 -0800 (PST) Subject: [rspec-users] [ANN] rspec 1.3.0 Released In-Reply-To: <57c63afe1001111948p218f59c2k4acd86948f548f51@mail.gmail.com> References: <57c63afe1001111948p218f59c2k4acd86948f548f51@mail.gmail.com> Message-ID: <2c132262-1951-488d-a59c-82cff4750394@f5g2000yqh.googlegroups.com> > rspec version 1.3.0 has been released! Thanks for the release. -r From phillipkoebbe at gmail.com Tue Jan 12 19:46:42 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Tue, 12 Jan 2010 16:46:42 -0800 (PST) Subject: [rspec-users] nested steps In-Reply-To: <76DB06A5-9A23-47AF-A27D-733BB43BF41D@mattwynne.net> References: <76DB06A5-9A23-47AF-A27D-733BB43BF41D@mattwynne.net> Message-ID: <3b3d4608-f403-46c6-acc5-015d9de62359@j5g2000yqm.googlegroups.com> > > You do realise you can already nest contexts don't you? That makes ? > much more sense to me than what you've suggested. > Hi Roger, Here's an example of nesting contexts that Matt is talking about: http://gist.github.com/275798 Peace, Phillip From lists at ruby-forum.com Tue Jan 12 19:58:41 2010 From: lists at ruby-forum.com (Saverio Miroddi) Date: Wed, 13 Jan 2010 01:58:41 +0100 Subject: [rspec-users] Stub activerecord find given instance? In-Reply-To: <57c63afe0912140439y4c5a00fbtb65d155eccd5426f@mail.gmail.com> References: <4A3616AC-32C2-478C-B20D-DF65FE1C031E@experthuman.com> <57c63afe0912140439y4c5a00fbtb65d155eccd5426f@mail.gmail.com> Message-ID: David Chelimsky wrote: >>> MyModel.stub(:find).with(42).and_return(myModel) >> Didn't work as expected - I'll do a bit of research and post again. > What is expected? What are you trying to accomplish? Example in horror-code: ################################################## class MyController < ApplicationController def show MyModel.find_by_code( params[:code] ) head :ok end end describe "MySuite" do it "should" do MyModel.stub!( :find_by_code ).with( "abc" ) do puts "triggered 'abc'!" end get :show, :code => "kkk" end end ################################################## I'm expecting nothing to be printed, instead "triggered 'abc'!" is printed. The example is, as I said, completely meaningless, but would simplify some tests in our suites. -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Tue Jan 12 22:49:09 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 12 Jan 2010 21:49:09 -0600 Subject: [rspec-users] Stub activerecord find given instance? In-Reply-To: References: <4A3616AC-32C2-478C-B20D-DF65FE1C031E@experthuman.com> <57c63afe0912140439y4c5a00fbtb65d155eccd5426f@mail.gmail.com> Message-ID: <57c63afe1001121949h444bc715x89fee7e8bc81f84c@mail.gmail.com> On Tue, Jan 12, 2010 at 6:58 PM, Saverio Miroddi wrote: > David Chelimsky wrote: > > >>> MyModel.stub(:find).with(42).and_return(myModel) > >> Didn't work as expected - I'll do a bit of research and post again. > > What is expected? What are you trying to accomplish? > > Example in horror-code: > > ################################################## > > class MyController < ApplicationController > def show > MyModel.find_by_code( params[:code] ) > head :ok > end > end > > describe "MySuite" do > it "should" do > MyModel.stub!( :find_by_code ).with( "abc" ) do > puts "triggered 'abc'!" > end > > get :show, :code => "kkk" > end > end > > ################################################## > > I'm expecting nothing to be printed, instead "triggered 'abc'!" is > printed. > That's actually the expected behaviour. When you pass a block to a call to stub, with, or and_return, the block is evaluated and the resulting value is returned to the caller. So in the show method, when MyModel.find_by_code( params[:code] ), the block in the example is invoked. It'd be much easier to help you if you could provide an example more representative of what you are actually trying to accomplish. > The example is, as I said, completely meaningless, but would simplify > some tests in our suites. > -- > 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: From onno.van.der.straaten at gmail.com Wed Jan 13 01:38:03 2010 From: onno.van.der.straaten at gmail.com (Onno van der Straaten) Date: Wed, 13 Jan 2010 07:38:03 +0100 Subject: [rspec-users] Cucumber generator Message-ID: Hi, I'm new to RSpec and Cucumber and I'm following the RSpec book. I have cucumber gem installed but when I use script/generate cucumber it responds with Couldn't find 'cucumber' generator? Thanks, Onno -------------- next part -------------- An HTML attachment was scrubbed... URL: From benjamin.lovell at gmail.com Wed Jan 13 02:32:18 2010 From: benjamin.lovell at gmail.com (Ben Lovell) Date: Wed, 13 Jan 2010 07:32:18 +0000 Subject: [rspec-users] Cucumber generator In-Reply-To: References: Message-ID: Try gem install cucumber-rails In a recent release the generators were split from the main project. Sent from my iPhone On 13 Jan 2010, at 06:38, Onno van der Straaten wrote: > Hi, > I'm new to RSpec and Cucumber and I'm following the RSpec book. > > I have cucumber gem installed but when I use script/generate > cucumber it responds with Couldn't find 'cucumber' generator? > Thanks, > Onno > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Wed Jan 13 09:33:12 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 13 Jan 2010 08:33:12 -0600 Subject: [rspec-users] Troubles with route_for In-Reply-To: <93f60ccf6698a5d0e8d470ce7cc280ec@ruby-forum.com> References: <57c63afe1001110546g762cb3e5pfba7227cc8b0b960@mail.gmail.com> <4B4C1F5C.3010506@yahoo.com> <0cc23fb5c587c4e1232fe5adbbfaa208@ruby-forum.com> <93f60ccf6698a5d0e8d470ce7cc280ec@ruby-forum.com> Message-ID: <57c63afe1001130633l3d96bb9ev657c760c5d31ce61@mail.gmail.com> On Tue, Jan 12, 2010 at 11:35 AM, Nick Hoffman wrote: > By the way, does this spec: > {:get => '/path'}.should route_to(...) > make this spec redundant?: > params_from(:get, '/path').should == {...} > Yes - route_to checks both sides of the translation. > They read the same, but it feels like they each check one end of the > route's translation. > -- > 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: From lists at ruby-forum.com Wed Jan 13 11:20:27 2010 From: lists at ruby-forum.com (Nick Hoffman) Date: Wed, 13 Jan 2010 17:20:27 +0100 Subject: [rspec-users] Troubles with route_for In-Reply-To: <57c63afe1001130633l3d96bb9ev657c760c5d31ce61@mail.gmail.com> References: <57c63afe1001110546g762cb3e5pfba7227cc8b0b960@mail.gmail.com> <4B4C1F5C.3010506@yahoo.com> <0cc23fb5c587c4e1232fe5adbbfaa208@ruby-forum.com> <93f60ccf6698a5d0e8d470ce7cc280ec@ruby-forum.com> <57c63afe1001130633l3d96bb9ev657c760c5d31ce61@mail.gmail.com> Message-ID: David Chelimsky wrote: > On Tue, Jan 12, 2010 at 11:35 AM, Nick Hoffman > wrote: > >> By the way, does this spec: >> {:get => '/path'}.should route_to(...) >> make this spec redundant?: >> params_from(:get, '/path').should == {...} >> > > Yes - route_to checks both sides of the translation. Great, thanks for that, David! And thanks again for all of your sweat and blood with RSpec and RSpec-Rails! -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Wed Jan 13 11:27:47 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 13 Jan 2010 10:27:47 -0600 Subject: [rspec-users] Troubles with route_for In-Reply-To: References: <57c63afe1001110546g762cb3e5pfba7227cc8b0b960@mail.gmail.com> <4B4C1F5C.3010506@yahoo.com> <0cc23fb5c587c4e1232fe5adbbfaa208@ruby-forum.com> <93f60ccf6698a5d0e8d470ce7cc280ec@ruby-forum.com> <57c63afe1001130633l3d96bb9ev657c760c5d31ce61@mail.gmail.com> Message-ID: <57c63afe1001130827m4b1d1cdan30799db17b98a163@mail.gmail.com> On Wed, Jan 13, 2010 at 10:20 AM, Nick Hoffman wrote: > David Chelimsky wrote: > > On Tue, Jan 12, 2010 at 11:35 AM, Nick Hoffman > > wrote: > > > >> By the way, does this spec: > >> {:get => '/path'}.should route_to(...) > >> make this spec redundant?: > >> params_from(:get, '/path').should == {...} > >> > > > > Yes - route_to checks both sides of the translation. > > Great, thanks for that, David! Thank Randy Harmon for this one. It was he who recognized and solved the problems with params_from by adding the route_to matcher. > And thanks again for all of your sweat > and blood with RSpec and RSpec-Rails! > It's a labor of love, but you're welcome :) -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Wed Jan 13 12:57:48 2010 From: lists at ruby-forum.com (Nick Hoffman) Date: Wed, 13 Jan 2010 18:57:48 +0100 Subject: [rspec-users] Troubles with route_for In-Reply-To: <57c63afe1001130827m4b1d1cdan30799db17b98a163@mail.gmail.com> References: <57c63afe1001110546g762cb3e5pfba7227cc8b0b960@mail.gmail.com> <4B4C1F5C.3010506@yahoo.com> <0cc23fb5c587c4e1232fe5adbbfaa208@ruby-forum.com> <93f60ccf6698a5d0e8d470ce7cc280ec@ruby-forum.com> <57c63afe1001130633l3d96bb9ev657c760c5d31ce61@mail.gmail.com> <57c63afe1001130827m4b1d1cdan30799db17b98a163@mail.gmail.com> Message-ID: David Chelimsky wrote: > On Wed, Jan 13, 2010 at 10:20 AM, Nick Hoffman > wrote: > >> > Yes - route_to checks both sides of the translation. >> >> Great, thanks for that, David! > > > Thank Randy Harmon for this one. It was he who recognized and solved > the > problems with params_from by adding the route_to matcher. Whoops, you're right. Thanks, Randy! -- Posted via http://www.ruby-forum.com/. From rogerpack2005 at gmail.com Wed Jan 13 13:28:29 2010 From: rogerpack2005 at gmail.com (rogerdpack) Date: Wed, 13 Jan 2010 10:28:29 -0800 (PST) Subject: [rspec-users] nested steps In-Reply-To: <76DB06A5-9A23-47AF-A27D-733BB43BF41D@mattwynne.net> References: <76DB06A5-9A23-47AF-A27D-733BB43BF41D@mattwynne.net> Message-ID: <063ba53f-582e-48df-96f5-a640a4f87716@d20g2000yqh.googlegroups.com> > You do realise you can already nest contexts don't you? That makes ? > much more sense to me than what you've suggested. Ahh that is what I lacked. That should suffice. Thanks! -r From onno.van.der.straaten at gmail.com Wed Jan 13 14:16:12 2010 From: onno.van.der.straaten at gmail.com (Onno van der Straaten) Date: Wed, 13 Jan 2010 20:16:12 +0100 Subject: [rspec-users] Cucumber generator In-Reply-To: References: Message-ID: Thanks! On Wed, Jan 13, 2010 at 8:32 AM, Ben Lovell wrote: > Try > > gem install cucumber-rails > > In a recent release the generators were split from the main project. > > Sent from my iPhone > > > On 13 Jan 2010, at 06:38, Onno van der Straaten < > onno.van.der.straaten at gmail.com> wrote: > > Hi, >> I'm new to RSpec and Cucumber and I'm following the RSpec book. >> >> I have cucumber gem installed but when I use script/generate cucumber it >> responds with Couldn't find 'cucumber' generator? >> Thanks, >> Onno >> >> _______________________________________________ >> 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: From rogerpack2005 at gmail.com Wed Jan 13 21:43:27 2010 From: rogerpack2005 at gmail.com (rogerdpack) Date: Wed, 13 Jan 2010 18:43:27 -0800 (PST) Subject: [rspec-users] test-unit oddities Message-ID: I think I've tracked down why rspec dislikes test-unit gems > 1.3.5 this code: gem 'rails', '= 2.3.5' puts $LOAD_PATH.find{|l| l.instance_variables.include? (:@gem_prelude_index)} puts $LOAD_PATH.uniq.find{|l| l.instance_variables.include? (:@gem_prelude_index)} [if you take off the '= 2.3.5' it gives different results] Anyway rails itself ends up doing a $LOAD_PATH.uniq! which clears the gem_prelude_index, causing test-unit '= 1.3.5' to be added at the end of $LOAD_PATH, which means that its brother , v 2.0.6, precedes it, and gets loaded. so the question is...whose fault is this? gems? rails? -r From rogerpack2005 at gmail.com Wed Jan 13 22:18:27 2010 From: rogerpack2005 at gmail.com (rogerdpack) Date: Wed, 13 Jan 2010 19:18:27 -0800 (PST) Subject: [rspec-users] test-unit oddities In-Reply-To: References: Message-ID: <5364f14a-7f6c-40d1-b0f0-934d6b9d9b02@m25g2000yqc.googlegroups.com> > so the question is...whose fault is this? gems? rails? I think it's rails' fault for not being careful when running $LOAD_PATH.uniq! ... -r From lists at ruby-forum.com Thu Jan 14 06:46:19 2010 From: lists at ruby-forum.com (John Polling) Date: Thu, 14 Jan 2010 12:46:19 +0100 Subject: [rspec-users] Testing .Net Newbie Message-ID: <02f00e6de887ca39f0ae635ae87fda1b@ruby-forum.com> Hi, I've been a .Net developer for a number of years now and I'm a big fan of TDD / BDD. I have been following these principles for a couple of years and use tools such as NUnit for testing purposes. I am now looking at moving across to using RoR for a number of projects and I'm still getting my head around how everything works. I've been reading up on RSpec and Cucumber and I have one question looming in my head. (This may be my .Net head messing things up for me). Normally in .Net when TDDing a controller class I would mock out other library classes that the controller calls, such as Repository layer classes. However I notice when using Cucumber people _very_ rarely mock anything and I'm assuming this is because Cucumber is meant for testing the full stack (Integration testing). I'd normally do this with something like Selenium in .Net. My question is, when creating a controller (or other class) that relies on other library classes is it best to just use RSpec rather than Cucumber to mock out the other dependencies and then bring in Cucumber scenarios later when you know your RSpec tests are passing? Thanks John -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Thu Jan 14 07:15:23 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 14 Jan 2010 06:15:23 -0600 Subject: [rspec-users] Testing .Net Newbie In-Reply-To: <02f00e6de887ca39f0ae635ae87fda1b@ruby-forum.com> References: <02f00e6de887ca39f0ae635ae87fda1b@ruby-forum.com> Message-ID: <57c63afe1001140415h519d8fedt5a2d7a4da79bde0a@mail.gmail.com> On Thu, Jan 14, 2010 at 5:46 AM, John Polling wrote: > Hi, > > I've been a .Net developer for a number of years now and I'm a big fan > of TDD / BDD. I have been following these principles for a couple of > years and use tools such as NUnit for testing purposes. > > I am now looking at moving across to using RoR for a number of projects > and I'm still getting my head around how everything works. I've been > reading up on RSpec and Cucumber and I have one question looming in my > head. (This may be my .Net head messing things up for me). > > Normally in .Net when TDDing a controller class I would mock out other > library classes that the controller calls, such as Repository layer > classes. However I notice when using Cucumber people _very_ rarely mock > anything and I'm assuming this is because Cucumber is meant for testing > the full stack (Integration testing). Cucumber is intended for Acceptance Testing. The entry point into the system can vary. With Rails you can go through the browser (driving Selenium, Watir, etc from Cucumber), start at the router, or even go directly to the model in cases where that's appropriate. re: Integration testing, everybody has a different definition. Before Rails came along, the prevalent definition that I was aware of was "testing the behaviour of two non-trivial components together." More recently, the definition that makes most sense to me comes from Growing Object Oriented Software [1]. I don't have the book in front of me, but from memory it is something like "testing your code with other code that you don't have any control over." Because we need a database for all levels of Rails testing, this suggests that all Rails testing is Integration Testing. In Rails' terminology, however, "integration testing" means very specifically testing the full stack minus the browser. > I'd normally do this with something like Selenium in .Net. > > My question is, when creating a controller (or other class) that relies > on other library classes is it best to just use RSpec rather than > Cucumber to mock out the other dependencies and then bring in Cucumber > scenarios later when you know your RSpec tests are passing? > "is it best?" is always relative. YMMV. That said, the outside-in process of BDD using Cucumber and RSpec together works well like this (borrowed and modified from the 2nd post in http://groups.google.com/group/cukes/browse_thread/thread/2598d6fcd29bfd86): 1) Identify business need (the very outside) 2) Discuss what feature would solve this need (feature injection) 3) Write a Cucumber scenario that interacts with the system boundaries (that have yet to be written) 4) Run the scenario and watch it fail because the code doesn't exist yet 5) Write a little piece of the system boundary code that was missing and caused the test to fail 6) Run the scenario and watch it fail again, this time because the code doesn't do what it needs to yet 7) Write a code example in RSpec 8) Run the code example and watch it fail 9) Write enough code to make it pass 10) Run the scenario and check its status 11) Repeat 7-10 until you have enough code (and not more than just enough) to make the scenario pass. One catch-phrase that comes to mind is "use Cucumber to learn what code to write, use RSpec to write the right code." You should know that there is a trend these days among Cucumber/RSpec/Rails users to _not_ write controller specs on the basis that controllers are covered by the Cucumber scenarios. The benefit is a faster suite that appears to have less duplication between testing layers. The drawback is that you lose the benefit of discovering model interfaces when you're specifying the controllers in isolation. My view is that this makes sense for the boilerplate stuff, but customizations of the controller are well served with isolated specs in RSpec. More answer than you bargained for, I imagine. HTH, David [1] http://www.amazon.com/Growing-Object-Oriented-Software-Guided-Tests/dp/0321503627 > > Thanks > > John > -- > 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: From lists at ruby-forum.com Thu Jan 14 07:33:03 2010 From: lists at ruby-forum.com (John Polling) Date: Thu, 14 Jan 2010 13:33:03 +0100 Subject: [rspec-users] Testing .Net Newbie In-Reply-To: <57c63afe1001140415h519d8fedt5a2d7a4da79bde0a@mail.gmail.com> References: <02f00e6de887ca39f0ae635ae87fda1b@ruby-forum.com> <57c63afe1001140415h519d8fedt5a2d7a4da79bde0a@mail.gmail.com> Message-ID: <89770f45f02c8e364029d29b45c7813c@ruby-forum.com> Thanks for this David. I suppose the thing I am so used to is testing classes in isolation whereas Cucumber is about testing everything together. Do Rails developers generally not test things in isolation using mocking and stubbing? John -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Thu Jan 14 07:50:16 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 14 Jan 2010 06:50:16 -0600 Subject: [rspec-users] Testing .Net Newbie In-Reply-To: <89770f45f02c8e364029d29b45c7813c@ruby-forum.com> References: <02f00e6de887ca39f0ae635ae87fda1b@ruby-forum.com> <57c63afe1001140415h519d8fedt5a2d7a4da79bde0a@mail.gmail.com> <89770f45f02c8e364029d29b45c7813c@ruby-forum.com> Message-ID: <57c63afe1001140450h62916cf5t20446f351ee732b5@mail.gmail.com> On Thu, Jan 14, 2010 at 6:33 AM, John Polling wrote: > Thanks for this David. > > I suppose the thing I am so used to is testing classes in isolation > whereas Cucumber is about testing everything together. > Did you do all of your testing in NUnit? When I was working on .NET apps, I used FitNesse for acceptance testing and NUnit for isolation testing. With Rails, these same roles are played by Cucumber and RSpec. > Do Rails developers generally not test things in isolation using > mocking and stubbing? > Some do all the time, some never do. I probably do more than most, but I've not experienced a lot of the pain that folks who are new to mocks and stubs experience. You've got to know when it's appropriate. HTH, David ps - please be sure to quote the relevant portions of the email you're responding to so people reading email on their phones don't have to go digging around for context. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tom at experthuman.com Thu Jan 14 07:48:47 2010 From: tom at experthuman.com (Tom Stuart) Date: Thu, 14 Jan 2010 12:48:47 +0000 Subject: [rspec-users] Testing .Net Newbie In-Reply-To: <89770f45f02c8e364029d29b45c7813c@ruby-forum.com> References: <02f00e6de887ca39f0ae635ae87fda1b@ruby-forum.com> <57c63afe1001140415h519d8fedt5a2d7a4da79bde0a@mail.gmail.com> <89770f45f02c8e364029d29b45c7813c@ruby-forum.com> Message-ID: On 14 Jan 2010, at 12:33, John Polling wrote: > Do Rails developers generally not test things in isolation using mocking > and stubbing? Yes, that's what RSpec is for. From lists at ruby-forum.com Thu Jan 14 08:17:15 2010 From: lists at ruby-forum.com (John Polling) Date: Thu, 14 Jan 2010 14:17:15 +0100 Subject: [rspec-users] Testing .Net Newbie In-Reply-To: <57c63afe1001140450h62916cf5t20446f351ee732b5@mail.gmail.com> References: <02f00e6de887ca39f0ae635ae87fda1b@ruby-forum.com> <57c63afe1001140415h519d8fedt5a2d7a4da79bde0a@mail.gmail.com> <89770f45f02c8e364029d29b45c7813c@ruby-forum.com> <57c63afe1001140450h62916cf5t20446f351ee732b5@mail.gmail.com> Message-ID: <9b9852bfc1c89531bc323f7246bf65e8@ruby-forum.com> David Chelimsky wrote: > Did you do all of your testing in NUnit? > > When I was working on .NET apps, I used FitNesse for acceptance testing > and > NUnit for isolation testing. With Rails, these same roles are played by > Cucumber and RSpec. > Generally what I do is drive all my individual classes out using NUnit and Rhino.Mocks and then do the acceptance testing later with FitNesse. I think this is the part that I'm confusing myself with as most Cucumber information talks about using scenarios to drive the code out. So Cucumber comes first, whereas I used to do the Acceptance testing after all the other TDD stuff. Maybe that is me doing it wrong though. John -- Posted via http://www.ruby-forum.com/. From phillipkoebbe at gmail.com Thu Jan 14 09:46:27 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Thu, 14 Jan 2010 08:46:27 -0600 Subject: [rspec-users] Testing .Net Newbie In-Reply-To: <9b9852bfc1c89531bc323f7246bf65e8@ruby-forum.com> References: <02f00e6de887ca39f0ae635ae87fda1b@ruby-forum.com> <57c63afe1001140415h519d8fedt5a2d7a4da79bde0a@mail.gmail.com> <89770f45f02c8e364029d29b45c7813c@ruby-forum.com> <57c63afe1001140450h62916cf5t20446f351ee732b5@mail.gmail.com> <9b9852bfc1c89531bc323f7246bf65e8@ruby-forum.com> Message-ID: <4B4F2E43.7010407@gmail.com> John Polling wrote: > Generally what I do is drive all my individual classes out using NUnit > and Rhino.Mocks and then do the acceptance testing later with FitNesse. > > I think this is the part that I'm confusing myself with as most Cucumber > information talks about using scenarios to drive the code out. So > Cucumber comes first, whereas I used to do the Acceptance testing after > all the other TDD stuff. Maybe that is me doing it wrong though. > > John > Hi John. Maybe this will help: http://www.pragprog.com/titles/achbd/the-rspec-book It's a good book. But when you get to the part about Webrat and Selenium, just know that there are other options if you need them. Peace, Phillip From dchelimsky at gmail.com Thu Jan 14 09:56:47 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 14 Jan 2010 08:56:47 -0600 Subject: [rspec-users] Testing .Net Newbie In-Reply-To: <4B4F2E43.7010407@gmail.com> References: <02f00e6de887ca39f0ae635ae87fda1b@ruby-forum.com> <57c63afe1001140415h519d8fedt5a2d7a4da79bde0a@mail.gmail.com> <89770f45f02c8e364029d29b45c7813c@ruby-forum.com> <57c63afe1001140450h62916cf5t20446f351ee732b5@mail.gmail.com> <9b9852bfc1c89531bc323f7246bf65e8@ruby-forum.com> <4B4F2E43.7010407@gmail.com> Message-ID: <367BFEAD-5AFF-4296-9A7A-F99556BB3974@gmail.com> On Jan 14, 2010, at 8:46 AM, Phillip Koebbe wrote: > John Polling wrote: >> Generally what I do is drive all my individual classes out using >> NUnit >> and Rhino.Mocks and then do the acceptance testing later with >> FitNesse. >> >> I think this is the part that I'm confusing myself with as most >> Cucumber >> information talks about using scenarios to drive the code out. So >> Cucumber comes first, whereas I used to do the Acceptance testing >> after >> all the other TDD stuff. Maybe that is me doing it wrong though. >> >> John >> > > Hi John. Maybe this will help: > > http://www.pragprog.com/titles/achbd/the-rspec-book D'oh! I should have thought of that! Thanks for the plug :) Cheers, David > It's a good book. But when you get to the part about Webrat and > Selenium, just know that there are other options if you need them. > > Peace, > Phillip From lists at ruby-forum.com Thu Jan 14 10:13:39 2010 From: lists at ruby-forum.com (John Polling) Date: Thu, 14 Jan 2010 16:13:39 +0100 Subject: [rspec-users] Testing .Net Newbie In-Reply-To: <4B4F2E43.7010407@gmail.com> References: <02f00e6de887ca39f0ae635ae87fda1b@ruby-forum.com> <57c63afe1001140415h519d8fedt5a2d7a4da79bde0a@mail.gmail.com> <89770f45f02c8e364029d29b45c7813c@ruby-forum.com> <57c63afe1001140450h62916cf5t20446f351ee732b5@mail.gmail.com> <9b9852bfc1c89531bc323f7246bf65e8@ruby-forum.com> <4B4F2E43.7010407@gmail.com> Message-ID: <5127addfd11425023336d346a5c828d5@ruby-forum.com> Phillip Koebbe wrote: > Hi John. Maybe this will help: > > http://www.pragprog.com/titles/achbd/the-rspec-book > > It's a good book. But when you get to the part about Webrat and > Selenium, just know that there are other options if you need them. Already reading that one thanks :-) It is a good book and it's helping me get my head around it all. It's just a case of understanding when to develop using Cucumber and when to user RSpec on it's own. I think this will come with experience. John -- Posted via http://www.ruby-forum.com/. From joahking at gmail.com Thu Jan 14 10:26:44 2010 From: joahking at gmail.com (Joaquin Rivera Padron) Date: Thu, 14 Jan 2010 16:26:44 +0100 Subject: [rspec-users] Testing .Net Newbie In-Reply-To: <5127addfd11425023336d346a5c828d5@ruby-forum.com> References: <02f00e6de887ca39f0ae635ae87fda1b@ruby-forum.com> <57c63afe1001140415h519d8fedt5a2d7a4da79bde0a@mail.gmail.com> <89770f45f02c8e364029d29b45c7813c@ruby-forum.com> <57c63afe1001140450h62916cf5t20446f351ee732b5@mail.gmail.com> <9b9852bfc1c89531bc323f7246bf65e8@ruby-forum.com> <4B4F2E43.7010407@gmail.com> <5127addfd11425023336d346a5c828d5@ruby-forum.com> Message-ID: <8277b7f41001140726i301f0d50ped9c55e25b549463@mail.gmail.com> hi 2010/1/14 John Polling > Phillip Koebbe wrote: > > > Hi John. Maybe this will help: > > > > http://www.pragprog.com/titles/achbd/the-rspec-book > > > > It's a good book. But when you get to the part about Webrat and > > Selenium, just know that there are other options if you need them. > > Already reading that one thanks :-) It is a good book and it's helping > me get my head around it all. It's just a case of understanding when to > develop using Cucumber and when to user RSpec on it's own. I think this > will come with experience. > there's also this very good presentation by Ben Mabey about when to use which (cucumber or rspec) with the analagy with bikes and bike-gears, only I don't find the link :-( hth (a bit), joaquin > > John > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- www.least-significant-bit.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Thu Jan 14 10:28:39 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 14 Jan 2010 09:28:39 -0600 Subject: [rspec-users] Testing .Net Newbie In-Reply-To: <8277b7f41001140726i301f0d50ped9c55e25b549463@mail.gmail.com> References: <02f00e6de887ca39f0ae635ae87fda1b@ruby-forum.com> <57c63afe1001140415h519d8fedt5a2d7a4da79bde0a@mail.gmail.com> <89770f45f02c8e364029d29b45c7813c@ruby-forum.com> <57c63afe1001140450h62916cf5t20446f351ee732b5@mail.gmail.com> <9b9852bfc1c89531bc323f7246bf65e8@ruby-forum.com> <4B4F2E43.7010407@gmail.com> <5127addfd11425023336d346a5c828d5@ruby-forum.com> <8277b7f41001140726i301f0d50ped9c55e25b549463@mail.gmail.com> Message-ID: <57c63afe1001140728u3c92d0b1u5962c0c5994d27a6@mail.gmail.com> On Thu, Jan 14, 2010 at 9:26 AM, Joaquin Rivera Padron wrote: > hi > > 2010/1/14 John Polling > > Phillip Koebbe wrote: >> >> > Hi John. Maybe this will help: >> > >> > http://www.pragprog.com/titles/achbd/the-rspec-book >> > >> > It's a good book. But when you get to the part about Webrat and >> > Selenium, just know that there are other options if you need them. >> >> Already reading that one thanks :-) It is a good book and it's helping >> me get my head around it all. It's just a case of understanding when to >> develop using Cucumber and when to user RSpec on it's own. I think this >> will come with experience. >> > > there's also this very good presentation by Ben Mabey about when to use > which (cucumber or rspec) with the analagy with bikes and bike-gears, only I > don't find the link :-( > http://mwrc2009.confreaks.com/14-mar-2009-15-00-bdd-with-cucumber-ben-mabey.html He leaves out a couple of steps here and there for the sake of time in the presentation, but this gives a great overview. Cheers, David > > hth (a bit), > joaquin > > >> >> John >> >> >> -- >> Posted via http://www.ruby-forum.com/. >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > > -- > www.least-significant-bit.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: From phillipkoebbe at gmail.com Thu Jan 14 10:31:21 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Thu, 14 Jan 2010 09:31:21 -0600 Subject: [rspec-users] Testing .Net Newbie In-Reply-To: <5127addfd11425023336d346a5c828d5@ruby-forum.com> References: <02f00e6de887ca39f0ae635ae87fda1b@ruby-forum.com> <57c63afe1001140415h519d8fedt5a2d7a4da79bde0a@mail.gmail.com> <89770f45f02c8e364029d29b45c7813c@ruby-forum.com> <57c63afe1001140450h62916cf5t20446f351ee732b5@mail.gmail.com> <9b9852bfc1c89531bc323f7246bf65e8@ruby-forum.com> <4B4F2E43.7010407@gmail.com> <5127addfd11425023336d346a5c828d5@ruby-forum.com> Message-ID: <4B4F38C9.6030600@gmail.com> John Polling wrote: > Already reading that one thanks :-) It is a good book and it's helping > me get my head around it all. It's just a case of understanding when to > develop using Cucumber and when to user RSpec on it's own. I think this > will come with experience. > > John > Others can explain it better than me (and have), but in a nutshell: - use Cucumber for full stack (as the user would see it) testing. Some call it User Acceptance Testing (UAT) - use RSpec for unit/functional testing (controllers, models, views, helpers) I think of it like this: RSpec is for the developer, Cucumber is for the user. That may be a gross oversimplification, but it works for me. :) But one thing to keep in mind is that you can (and maybe should) use them together. Through Cucumber, you establish the context of what the user will expect. Through RSpec, you establish expectations for the different pieces of the application. That's why it's called "Outside In Development": You start with the outside of the black box (what the user interacts with) and then step into the black box (the nuts and bolts that the user doesn't care about, but you, the developer, do). Yes, it will come with experience. Just be patient, learn from your mistakes, and ask lots of questions! That you have testing knowledge already will help. Once the RSpec/Cucumber light goes on, there will be no stopping you! Peace, Phillip From ashley.moran at patchspace.co.uk Thu Jan 14 10:32:48 2010 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Thu, 14 Jan 2010 15:32:48 +0000 Subject: [rspec-users] default to just call the method? In-Reply-To: <8936163d-331b-49c8-aac7-2fc089556f18@a6g2000yqm.googlegroups.com> References: <8936163d-331b-49c8-aac7-2fc089556f18@a6g2000yqm.googlegroups.com> Message-ID: <779312C2-9522-4325-8D6D-E00DF214F1BD@patchspace.co.uk> On Jan 12, 2010, at 10:49 pm, rogerdpack wrote: > a.should include?("1:4") # if there's no matcher called include? then > just call include? Am I right thinking that this would mean writing a method_missing that creates a matcher for every unhandled message on the example object (whatever scope the #it block runs in)? If so, that could produce surprising behaviour if methods were silently turned into matchers and ignored. Maybe if you restricted it to ? methods it would not be so bad. But then, that's the point of the be_* handler. The only problem is that #include? is a verb not an adjective/noun. Can't say I've come across many of them, so it might be better in these cases to just write a method #a_container_for? ? Ashley -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashleymoran From ashley.moran at patchspace.co.uk Thu Jan 14 10:48:49 2010 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Thu, 14 Jan 2010 15:48:49 +0000 Subject: [rspec-users] Testing .Net Newbie In-Reply-To: <57c63afe1001140415h519d8fedt5a2d7a4da79bde0a@mail.gmail.com> References: <02f00e6de887ca39f0ae635ae87fda1b@ruby-forum.com> <57c63afe1001140415h519d8fedt5a2d7a4da79bde0a@mail.gmail.com> Message-ID: <4AD49805-EA25-4299-856D-481CCF8BF34A@patchspace.co.uk> On Jan 14, 2010, at 12:15 pm, David Chelimsky wrote: > re: Integration testing, everybody has a different definition. Before Rails came along, the prevalent definition that I was aware of was "testing the behaviour of two non-trivial components together." > > More recently, the definition that makes most sense to me comes from Growing Object Oriented Software [1]. I don't have the book in front of me, but from memory it is something like "testing your code with other code that you don't have any control over." Because we need a database for all levels of Rails testing, this suggests that all Rails testing is Integration Testing. And yet, JB Rainsberger sticks absolutely uncompromisingly to the first definition[1]. I wonder if you could take it to yet another extreme and include tests for objects with private methods as "integration tests". The thing I got most from GOOS is to protect all domain code with adapters. If all Rails testing is integration testing, that means a lot of duplication and coupling that could be reduced... I have yet to do it for real though. But GOOS is the book that convinced me it's worth trying. Ashley [1] http://www.infoq.com/presentations/integration-tests-scam -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashleymoran From ashley.moran at patchspace.co.uk Thu Jan 14 10:56:15 2010 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Thu, 14 Jan 2010 15:56:15 +0000 Subject: [rspec-users] Testing .Net Newbie In-Reply-To: <9b9852bfc1c89531bc323f7246bf65e8@ruby-forum.com> References: <02f00e6de887ca39f0ae635ae87fda1b@ruby-forum.com> <57c63afe1001140415h519d8fedt5a2d7a4da79bde0a@mail.gmail.com> <89770f45f02c8e364029d29b45c7813c@ruby-forum.com> <57c63afe1001140450h62916cf5t20446f351ee732b5@mail.gmail.com> <9b9852bfc1c89531bc323f7246bf65e8@ruby-forum.com> Message-ID: <16DB33D1-20DC-442D-BF3A-E54E7D009846@patchspace.co.uk> On Jan 14, 2010, at 1:17 pm, John Polling wrote: > I think this is the part that I'm confusing myself with as most Cucumber > information talks about using scenarios to drive the code out. So > Cucumber comes first, whereas I used to do the Acceptance testing after > all the other TDD stuff. Maybe that is me doing it wrong though. The book David mentioned earlier - before the one he wrote himself :) - GOOS[1] has a diagram on p40 that shows how the unit test cycle fits inside the acceptance test cycle. You can extend this to as many layers as you like. I wrote a blog post which has a pretty picture of the idea[2]. Ignore the text, it's long and rambling and is about something else. I thought it was a great insight, until I realised Kent Beck wrote about self-similarity something like 5+ years ago[3]. Ashley [1] http://www.amazon.com/Growing-Object-Oriented-Software-Guided-Tests/dp/0321503627 [2] http://blog.patchspace.co.uk/2009/12/customers-input-and-russian-doll-of.html [3] http://www.goodreads.com/book/show/67833.Extreme_Programming_Explained_Embrace_Change -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashleymoran From rick.denatale at gmail.com Thu Jan 14 12:02:44 2010 From: rick.denatale at gmail.com (Rick DeNatale) Date: Thu, 14 Jan 2010 12:02:44 -0500 Subject: [rspec-users] default to just call the method? In-Reply-To: <8936163d-331b-49c8-aac7-2fc089556f18@a6g2000yqm.googlegroups.com> References: <8936163d-331b-49c8-aac7-2fc089556f18@a6g2000yqm.googlegroups.com> Message-ID: On Tue, Jan 12, 2010 at 5:49 PM, rogerdpack wrote: > Any interest in the following idea? > > > a.should include?("1:4") # if there's no matcher called include? then > just call include? > > or something along those lines? -1 You can already say a.should include("1:4") which is clearer IMHO. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale From onno.van.der.straaten at gmail.com Thu Jan 14 15:12:40 2010 From: onno.van.der.straaten at gmail.com (Onno van der Straaten) Date: Thu, 14 Jan 2010 21:12:40 +0100 Subject: [rspec-users] Selenium client gem Message-ID: Hi, I'm trying to install the selenium client with gem install selenium-client. This returns the following message ERROR: could not find gem selenium-client locally or in a repository BTW, I'm following the RSpec book chapter 22 Automating the Browser with Webrat and Selenium. Wat this gem removed from the repository? Thanks, Onno -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Thu Jan 14 15:37:49 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 14 Jan 2010 14:37:49 -0600 Subject: [rspec-users] Selenium client gem In-Reply-To: References: Message-ID: <57c63afe1001141237r537697cdv1229de5cad291b67@mail.gmail.com> On Thu, Jan 14, 2010 at 2:12 PM, Onno van der Straaten < onno.van.der.straaten at gmail.com> wrote: > Hi, > I'm trying to install the selenium client with gem install selenium-client. > This returns the following message > ERROR: could not find gem selenium-client locally or in a repository > > BTW, I'm following the RSpec book chapter 22 Automating the Browser with > Webrat and Selenium. > > Wat this gem removed from the repository? > Something is definitely out of whack. If you go to http://gemcutter.org/gems/selenium-client, you'll see plenty of versions of it - you can download the 1.2.17 version from that page. However, here's what I get from a gem search: $ gem q -rn selenium-client *** REMOTE GEMS *** Selenium-Client (0.1) First, note the caps. Second, the version is way old. I'm in IRC trying to resolve that, but in the mean time you can download it from the page listed above. Cheers, David > Thanks, > Onno > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Thu Jan 14 15:57:34 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 14 Jan 2010 14:57:34 -0600 Subject: [rspec-users] Selenium client gem In-Reply-To: <57c63afe1001141237r537697cdv1229de5cad291b67@mail.gmail.com> References: <57c63afe1001141237r537697cdv1229de5cad291b67@mail.gmail.com> Message-ID: <57c63afe1001141257r22198f61i5de1dc3fb1ff1fb6@mail.gmail.com> On Thu, Jan 14, 2010 at 2:37 PM, David Chelimsky wrote: > On Thu, Jan 14, 2010 at 2:12 PM, Onno van der Straaten < > onno.van.der.straaten at gmail.com> wrote: > >> Hi, >> I'm trying to install the selenium client with gem install >> selenium-client. >> This returns the following message >> ERROR: could not find gem selenium-client locally or in a repository >> >> BTW, I'm following the RSpec book chapter 22 Automating the Browser with >> Webrat and Selenium. >> >> Wat this gem removed from the repository? >> > > Something is definitely out of whack. If you go to > http://gemcutter.org/gems/selenium-client, you'll see plenty of versions > of it - you can download the 1.2.17 version from that page. > > However, here's what I get from a gem search: > > $ gem q -rn selenium-client > > *** REMOTE GEMS *** > > Selenium-Client (0.1) > > First, note the caps. Second, the version is way old. > > I'm in IRC trying to resolve that, but in the mean time you can download it > from the page listed above. > Problem resolved in gemcutter source code - will be fixed on next deploy of gemcutter. Not sure when that will be though :) > > Cheers, > David > > > >> Thanks, >> Onno >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sean at clipperadams.com Thu Jan 14 23:10:30 2010 From: sean at clipperadams.com (DeNigris Sean) Date: Thu, 14 Jan 2010 23:10:30 -0500 Subject: [rspec-users] autospec: non-standard filenames & redirecting output Message-ID: <92828442-D3ED-4D2D-905B-2634D9B05A14@clipperadams.com> Rspec gurus, I have 2 questions about autospec. I've played around quite a bit, but can't figure it out... 1. I got autospec to work with my directory structure ("examples/*_example.rb"), but it only works if I have an empty spec/ directory. Otherwise it reverts to running tests instead of examples... Current ./.autotest: Autotest.add_discovery do "rspec" if File.directory?('examples') end Autotest.add_hook(:initialize) {|at| ##at.add_exception %r{^\.git} # ignore Version Control System at.clear_mappings # take out the default (test/test*rb) at.add_mapping(%r%^examples/.*_example.rb$%) { |filename, _| filename } at.add_mapping(%r%^lib/(.*)\.rb$%) { |_, m| ["examples/#{m[1]}_example.rb"] } at.add_mapping(%r%^examples/(example_helper|shared/.*)\.rb$%) { at.files_matching %r%^examples/.*_example\.rb$% } nil } 2. Does anyone have a technique for redirecting the output (in my case to MacVim)? I really only want it to happen if there are errors. If everything went smoothly, probably a growl notification would be easier. Thanks! Sean DeNigris sean at clipperadams.com Mac OS X 10.6.2 rspec 1.2.9 ZenTest 4.2.1 From joahking at gmail.com Fri Jan 15 03:23:17 2010 From: joahking at gmail.com (Joaquin Rivera Padron) Date: Fri, 15 Jan 2010 09:23:17 +0100 Subject: [rspec-users] Testing .Net Newbie In-Reply-To: <16DB33D1-20DC-442D-BF3A-E54E7D009846@patchspace.co.uk> References: <02f00e6de887ca39f0ae635ae87fda1b@ruby-forum.com> <57c63afe1001140415h519d8fedt5a2d7a4da79bde0a@mail.gmail.com> <89770f45f02c8e364029d29b45c7813c@ruby-forum.com> <57c63afe1001140450h62916cf5t20446f351ee732b5@mail.gmail.com> <9b9852bfc1c89531bc323f7246bf65e8@ruby-forum.com> <16DB33D1-20DC-442D-BF3A-E54E7D009846@patchspace.co.uk> Message-ID: <8277b7f41001150023x3b793bc2h9920a92cb527bd5b@mail.gmail.com> hey there there's also http://bddcasts.com with railscasts like bdd screencasts haven't check it much myself, but might deserve a look hth, joaquin 2010/1/14 Ashley Moran > > On Jan 14, 2010, at 1:17 pm, John Polling wrote: > > > I think this is the part that I'm confusing myself with as most Cucumber > > information talks about using scenarios to drive the code out. So > > Cucumber comes first, whereas I used to do the Acceptance testing after > > all the other TDD stuff. Maybe that is me doing it wrong though. > > The book David mentioned earlier - before the one he wrote himself :) - > GOOS[1] has a diagram on p40 that shows how the unit test cycle fits inside > the acceptance test cycle. You can extend this to as many layers as you > like. I wrote a blog post which has a pretty picture of the idea[2]. > Ignore the text, it's long and rambling and is about something else. I > thought it was a great insight, until I realised Kent Beck wrote about > self-similarity something like 5+ years ago[3]. > > Ashley > > > [1] > http://www.amazon.com/Growing-Object-Oriented-Software-Guided-Tests/dp/0321503627 > [2] > http://blog.patchspace.co.uk/2009/12/customers-input-and-russian-doll-of.html > [3] > http://www.goodreads.com/book/show/67833.Extreme_Programming_Explained_Embrace_Change > > -- > http://www.patchspace.co.uk/ > http://www.linkedin.com/in/ashleymoran > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- www.least-significant-bit.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From diwakar at angleritech.com Fri Jan 15 03:42:31 2010 From: diwakar at angleritech.com (Diwakar, ANGLER - EIT) Date: Fri, 15 Jan 2010 14:12:31 +0530 Subject: [rspec-users] Testing .Net Newbie References: <02f00e6de887ca39f0ae635ae87fda1b@ruby-forum.com> <57c63afe1001140415h519d8fedt5a2d7a4da79bde0a@mail.gmail.com> <89770f45f02c8e364029d29b45c7813c@ruby-forum.com> <57c63afe1001140450h62916cf5t20446f351ee732b5@mail.gmail.com> <9b9852bfc1c89531bc323f7246bf65e8@ruby-forum.com> <4B4F2E43.7010407@gmail.com><5127addfd11425023336d346a5c828d5@ruby-forum.com> <4B4F38C9.6030600@gmail.com> Message-ID: <16F1D498F4CD4545BB3C49972B5082714ECAA5@itech.angleritech.com> Good explanation Phillip. It gives a clear idea... Thanks Regards, Diwakar Others can explain it better than me (and have), but in a nutshell: - use Cucumber for full stack (as the user would see it) testing. Some call it User Acceptance Testing (UAT) - use RSpec for unit/functional testing (controllers, models, views, helpers) I think of it like this: RSpec is for the developer, Cucumber is for the user. That may be a gross oversimplification, but it works for me. :) But one thing to keep in mind is that you can (and maybe should) use them together. Through Cucumber, you establish the context of what the user will expect. Through RSpec, you establish expectations for the different pieces of the application. That's why it's called "Outside In Development": You start with the outside of the black box (what the user interacts with) and then step into the black box (the nuts and bolts that the user doesn't care about, but you, the developer, do). Yes, it will come with experience. Just be patient, learn from your mistakes, and ask lots of questions! That you have testing knowledge already will help. Once the RSpec/Cucumber light goes on, there will be no stopping you! Peace, Phillip _______________________________________________ rspec-users mailing list rspec-users at rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Fri Jan 15 09:09:43 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 15 Jan 2010 08:09:43 -0600 Subject: [rspec-users] autospec: non-standard filenames & redirecting output In-Reply-To: <92828442-D3ED-4D2D-905B-2634D9B05A14@clipperadams.com> References: <92828442-D3ED-4D2D-905B-2634D9B05A14@clipperadams.com> Message-ID: <57c63afe1001150609i2a59e08ey3fc1e901694f6e8a@mail.gmail.com> On Thu, Jan 14, 2010 at 10:10 PM, DeNigris Sean wrote: > Rspec gurus, > > I have 2 questions about autospec. I've played around quite a bit, but > can't figure it out... > > 1. I got autospec to work with my directory structure > ("examples/*_example.rb"), but it only works if I have an empty spec/ > directory. Otherwise it reverts to running tests instead of examples... > Current ./.autotest: > Autotest.add_discovery do > "rspec" if File.directory?('examples') > end > If you crack open ZenTest and look at these files: bin/autotest lib/autotest.rb you'll see (eventually) that ./.autotest is loaded too late in the process. It's actually loaded during the initialization of an Autotest object (or subclass), so the class must already be determined. Per the docs for autodiscover, all autotest/discover.rb files on your path are loaded in order to determine what file to load. Try adding an autotest directory in your project with a discover.rb file in it with: Autotest.add_discovery { "rpspec" } > Autotest.add_hook(:initialize) {|at| > ##at.add_exception %r{^\.git} # ignore Version Control System > at.clear_mappings # take out the default (test/test*rb) > > at.add_mapping(%r%^examples/.*_example.rb$%) { |filename, _| > filename > } > at.add_mapping(%r%^lib/(.*)\.rb$%) { |_, m| > ["examples/#{m[1]}_example.rb"] > } > at.add_mapping(%r%^examples/(example_helper|shared/.*)\.rb$%) { > at.files_matching %r%^examples/.*_example\.rb$% > } > nil > } > > 2. Does anyone have a technique for redirecting the output (in my case to > MacVim)? I really only want it to happen if there are errors. If > everything went smoothly, probably a growl notification would be easier. > I'm not sure about redirecting to MacVim, but I do use growl notifications for success and failure. If there's a failure, I go look at the shell output. FWIW. HTH, David > > Thanks! > > Sean DeNigris > sean at clipperadams.com > > Mac OS X 10.6.2 > rspec 1.2.9 > ZenTest 4.2.1 > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ashley.moran at patchspace.co.uk Fri Jan 15 09:19:16 2010 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Fri, 15 Jan 2010 14:19:16 +0000 Subject: [rspec-users] default to just call the method? In-Reply-To: References: <8936163d-331b-49c8-aac7-2fc089556f18@a6g2000yqm.googlegroups.com> Message-ID: On 14 Jan 2010, at 17:02, Rick DeNatale wrote: > -1 > > You can already say > > a.should include("1:4") > > which is clearer IMHO. I assume Roger was referring to the general case though (which I still don't like) - and just happened to pick an example with an existing matcher. -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashleymoran From jko170 at gmail.com Sat Jan 16 01:23:13 2010 From: jko170 at gmail.com (jko170) Date: Fri, 15 Jan 2010 22:23:13 -0800 (PST) Subject: [rspec-users] Specs fail in rake spec but not command R Message-ID: Surely I cannot be the only one experiencing this issue. I have some code that is "time/date sensitive". Why do some specs fail when I run rake spec, but they do not when I use command R? From vladimirrybas at gmail.com Sat Jan 16 05:49:48 2010 From: vladimirrybas at gmail.com (Vladimir Rybas) Date: Sat, 16 Jan 2010 02:49:48 -0800 (PST) Subject: [rspec-users] Cucumber generator In-Reply-To: References: Message-ID: <8f15610d-a58b-41e4-b223-42a02a09c91f@r24g2000yqd.googlegroups.com> Thanks! Also you need to install webrat gem for cucumber generators to work. If you use Ubuntu, make sure you got 'libxslt-ruby' and 'libxslt1-dev' packages installed. On Jan 14, 1:16?am, Onno van der Straaten wrote: > Thanks! > > On Wed, Jan 13, 2010 at 8:32 AM, Ben Lovell wrote: > > > > > Try > > > gem install cucumber-rails > > > In a recent release the generators were split from the main project. > > > Sent from my iPhone > > > On 13 Jan 2010, at 06:38, Onno van der Straaten < > > onno.van.der.straa... at gmail.com> wrote: > > > ?Hi, > >> I'm new to RSpec and Cucumber and I'm following the RSpec book. > > >> I have cucumber gem installed but when I use script/generate cucumber it > >> responds with Couldn't find 'cucumber' generator? > >> Thanks, > >> Onno > > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-us... at rubyforge.org > >>http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Sat Jan 16 07:59:33 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 16 Jan 2010 06:59:33 -0600 Subject: [rspec-users] Specs fail in rake spec but not command R In-Reply-To: References: Message-ID: <57c63afe1001160459h255b94fch2eb7abcf60a38496@mail.gmail.com> On Sat, Jan 16, 2010 at 12:23 AM, jko170 wrote: > Surely I cannot be the only one experiencing this issue. > > I have some code that is "time/date sensitive". > > Why do some specs fail when I run rake spec, but they do not when I > use command R? > Please read http://wiki.github.com/dchelimsky/rspec/get-in-touch and help us help you by providing some context. -------------- next part -------------- An HTML attachment was scrubbed... URL: From sean at clipperadams.com Sat Jan 16 11:50:17 2010 From: sean at clipperadams.com (Sean DeNigris) Date: Sat, 16 Jan 2010 08:50:17 -0800 (PST) Subject: [rspec-users] autospec: non-standard filenames & redirecting output In-Reply-To: <57c63afe1001150609i2a59e08ey3fc1e901694f6e8a@mail.gmail.com> References: <92828442-D3ED-4D2D-905B-2634D9B05A14@clipperadams.com> <57c63afe1001150609i2a59e08ey3fc1e901694f6e8a@mail.gmail.com> Message-ID: <04decc61-fe15-481e-b468-a1df2ea458bc@p8g2000yqb.googlegroups.com> > Per the docs for autodiscover, all autotest/discover.rb files on your path > are loaded in order to determine what file to load. Try adding an autotest > directory in your project with a discover.rb file in it with: > > Autotest.add_discovery { "rpspec" } Beautiful, worked like a charm, thanks! Still experimenting with getting the results to MacVim... I'll post anything I figure out. Sean From jko170 at gmail.com Sat Jan 16 13:32:37 2010 From: jko170 at gmail.com (jko170) Date: Sat, 16 Jan 2010 10:32:37 -0800 (PST) Subject: [rspec-users] Specs fail in rake spec but not command R In-Reply-To: <57c63afe1001160459h255b94fch2eb7abcf60a38496@mail.gmail.com> References: <57c63afe1001160459h255b94fch2eb7abcf60a38496@mail.gmail.com> Message-ID: My code stubs Time.current by using mocha and Time.parse ('1984-01-28'). I fixed the problem by using Time.zone.parse ('1984-01-28'). Thank you for the reply. On Jan 16, 4:59?am, David Chelimsky wrote: > On Sat, Jan 16, 2010 at 12:23 AM, jko170 wrote: > > Surely I cannot be the only one experiencing this issue. > > > I have some code that is "time/date sensitive". > > > Why do some specs fail when I run rake spec, but they do not when I > > use command R? > > Please readhttp://wiki.github.com/dchelimsky/rspec/get-in-touchand help us > help you by providing some context. > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From rogerpack2005 at gmail.com Sat Jan 16 22:43:31 2010 From: rogerpack2005 at gmail.com (rogerdpack) Date: Sat, 16 Jan 2010 19:43:31 -0800 (PST) Subject: [rspec-users] specify line for autorun? Message-ID: <7f6744c0-8ce6-4f38-94da-bcb9c7d7635a@j5g2000yqm.googlegroups.com> Am I correct in assuming this should work (bug)? # spec.fast_require.rb contains the line require 'spec/autorun' E:\dev\ruby\fast_ruby_require\spec>ruby spec.fast_require.rb -l25 Only one file can be specified when providing a line number: [] -rp From dchelimsky at gmail.com Sun Jan 17 11:24:56 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 17 Jan 2010 10:24:56 -0600 Subject: [rspec-users] specify line for autorun? In-Reply-To: <7f6744c0-8ce6-4f38-94da-bcb9c7d7635a@j5g2000yqm.googlegroups.com> References: <7f6744c0-8ce6-4f38-94da-bcb9c7d7635a@j5g2000yqm.googlegroups.com> Message-ID: <57c63afe1001170824v3c7fe76fvea0c00744644a39b@mail.gmail.com> Yep - that's a bug - please file a ticket at http://rspec.lighthouseapp.com Thx! On Sat, Jan 16, 2010 at 9:43 PM, rogerdpack wrote: > Am I correct in assuming this should work (bug)? > > # spec.fast_require.rb contains the line require 'spec/autorun' > E:\dev\ruby\fast_ruby_require\spec>ruby spec.fast_require.rb -l25 > Only one file can be specified when providing a line number: [] > > -rp > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From npdepolonia at gmail.com Sun Jan 17 21:17:13 2010 From: npdepolonia at gmail.com (Nin) Date: Sun, 17 Jan 2010 18:17:13 -0800 (PST) Subject: [rspec-users] testing named_scope Message-ID: Hi! I'm new to rspec and was wondering how named_scopes are usually tested? Is it enough to test that it's defined? or do you need to test the behavior as well? I've been reading around and this seems to be the tester's choice, i just want to get people's opinion on this :D From dchelimsky at gmail.com Sun Jan 17 21:56:22 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 17 Jan 2010 20:56:22 -0600 Subject: [rspec-users] testing named_scope In-Reply-To: References: Message-ID: <57c63afe1001171856ue858614nc4b0fd0c3b8efd7f@mail.gmail.com> On Sun, Jan 17, 2010 at 8:17 PM, Nin wrote: > Hi! I'm new to rspec and was wondering how named_scopes are usually > tested? Is it enough to test that it's defined? or do you need to test > the behavior as well? I've been reading around and this seems to be > the tester's choice, i just want to get people's opinion on this :D > _Specify_ the behaviour, don't _test_ the implementation. The fact that a method is defined with a named_scope declaration is irrelevant to the behaviour. One reason for this is keeping things decoupled. Consider the fact that named_scope just changed to scope today [1]. If your specs specify a call to named_scope, they'll have to change, whereas if they they only specify the name you define then you'll only need to update the implementation when you upgrade. [1] http://github.com/rails/rails/commit/d60bb0a9e4be2ac0a9de9a69041a4ddc2e0cc914 That all make sense? -------------- next part -------------- An HTML attachment was scrubbed... URL: From mailinglists at patmaddox.com Mon Jan 18 04:31:09 2010 From: mailinglists at patmaddox.com (Pat Maddox) Date: Mon, 18 Jan 2010 01:31:09 -0800 Subject: [rspec-users] default to just call the method? In-Reply-To: References: <8936163d-331b-49c8-aac7-2fc089556f18@a6g2000yqm.googlegroups.com> Message-ID: <8D614E43-9043-4336-8BE7-FE0822193848@patmaddox.com> On Jan 15, 2010, at 6:19 AM, Ashley Moran wrote: > > On 14 Jan 2010, at 17:02, Rick DeNatale wrote: > >> -1 >> >> You can already say >> >> a.should include("1:4") >> >> which is clearer IMHO. > > > I assume Roger was referring to the general case though (which I still don't like) - and just happened to pick an example with an existing matcher. If that's the case then I'd say it would be worth making a little macro to try it out. Something like define_simple_predicate_matcher :rise_from_the_ashes? It would need to define a simple matcher, allowing you to do Phoenix.new.should rise_from_the_ashes? which would naturally expand to Phoenix.new.rise_from_the_ashes?.should be_true Roger, if you're just talking about include?, follow Rick's suggestion. If you're talking about arbitrary predicates, then you can accomplish it in your own codebase with some simple metaprogramming, and see if it catches on with other folks. Pat From mailinglists at patmaddox.com Mon Jan 18 05:01:08 2010 From: mailinglists at patmaddox.com (Pat Maddox) Date: Mon, 18 Jan 2010 02:01:08 -0800 Subject: [rspec-users] testing named_scope In-Reply-To: References: Message-ID: <6BE00C1F-8409-401E-A5C6-B7C9D578EF67@patmaddox.com> class User < ActiveRecord::Base named_scope :admins, :conditions => {:admin => true} end describe User, "admins" do it "should include users with admin flag" do admin = User.create! :admin => true User.admin.should include(admin) end it "should not include users without admin flag" do admin = User.create! :admin => false User.admin.should_not include(admin) end end On Jan 17, 2010, at 6:17 PM, Nin wrote: > Hi! I'm new to rspec and was wondering how named_scopes are usually > tested? Is it enough to test that it's defined? or do you need to test > the behavior as well? I've been reading around and this seems to be > the tester's choice, i just want to get people's opinion on this :D > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Mon Jan 18 05:17:32 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 18 Jan 2010 04:17:32 -0600 Subject: [rspec-users] testing named_scope In-Reply-To: <6BE00C1F-8409-401E-A5C6-B7C9D578EF67@patmaddox.com> References: <6BE00C1F-8409-401E-A5C6-B7C9D578EF67@patmaddox.com> Message-ID: <57c63afe1001180217y22cd503au769201f5ff9d7a6e@mail.gmail.com> On Mon, Jan 18, 2010 at 4:01 AM, Pat Maddox wrote: > On Jan 17, 2010, at 6:17 PM, Nin wrote: > > Hi! I'm new to rspec and was wondering how named_scopes are usually > > tested? Is it enough to test that it's defined? or do you need to test > > the behavior as well? I've been reading around and this seems to be > > the tester's choice, i just want to get people's opinion on this :D > > class User < ActiveRecord::Base > ?named_scope :admins, :conditions => {:admin => true} > end > > describe User, "admins" do > ?it "should include users with admin flag" do > ? ?admin = User.create! :admin => true > ? ?User.admin.should include(admin) > ?end > > ?it "should not include users without admin flag" do > ? ?admin = User.create! :admin => false > ? ?User.admin.should_not include(admin) > ?end > end Small style matter, but I've leaning towards more declarative sounding example names: describe User, ".admins" do ??it "includes users with admin flag" do ?? ?admin = User.create! :admin => true ?? ?User.admin.should include(admin) ??end ??it "excludes users without admin flag" do ?? ?non_admin = User.create! :admin => false ?? ?User.admin.should_not include(non_admin) ??end end class User < ActiveRecord::Base ??named_scope :admins, :conditions => {:admin => true} end We still have 'should' in the examples, but this produces more 'spec-like' output: User.admins ??includes users with admin flag ??excludes users without admin flag FWIW, David From ashley.moran at patchspace.co.uk Mon Jan 18 10:03:40 2010 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Mon, 18 Jan 2010 15:03:40 +0000 Subject: [rspec-users] default to just call the method? In-Reply-To: <8D614E43-9043-4336-8BE7-FE0822193848@patmaddox.com> References: <8936163d-331b-49c8-aac7-2fc089556f18@a6g2000yqm.googlegroups.com> <8D614E43-9043-4336-8BE7-FE0822193848@patmaddox.com> Message-ID: On Jan 18, 2010, at 9:31 am, Pat Maddox wrote: > define_simple_predicate_matcher :rise_from_the_ashes? As an extension, how about: define_simple_predicate_matcher :risen_from_the_ashes => :rise_from_the_ashes? Also, in general, I think specs look better without ? symbols on methods, my preference though Ashley -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashleymoran From phillipkoebbe at gmail.com Mon Jan 18 10:06:07 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Mon, 18 Jan 2010 09:06:07 -0600 Subject: [rspec-users] Something like tags in cucumber Message-ID: <4B5478DF.6090106@gmail.com> In cucumber, I use tags in a very simple, yet helpful (to me) way: to number my scenarios. For example: @1 Scenario: This is a scenario @2 Scenario: This is another scenario @3 Scenario: You get the idea This allows me to focus in on a single scenario quite easily while I'm working on it. Once I have that scenario working correctly, I will run the entire feature to make sure nothing else is broken. I'm finding that I'd like to do something quite similar in RSpec. For example, when I'm working on a model spec, I generally have contexts for what database fields should exist, what validations should exist, and what associations should exist. When I am later adding a couple of custom methods to do something, I'd like to be able to run the spec just for what I'm presently working on. Is this possible? Peace, Phillip From dchelimsky at gmail.com Mon Jan 18 10:12:49 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 18 Jan 2010 09:12:49 -0600 Subject: [rspec-users] default to just call the method? In-Reply-To: References: <8936163d-331b-49c8-aac7-2fc089556f18@a6g2000yqm.googlegroups.com> <8D614E43-9043-4336-8BE7-FE0822193848@patmaddox.com> Message-ID: <57c63afe1001180712s41591463wdc61baf4f3b65241@mail.gmail.com> On Mon, Jan 18, 2010 at 9:03 AM, Ashley Moran wrote: > > On Jan 18, 2010, at 9:31 am, Pat Maddox wrote: > >> define_simple_predicate_matcher :rise_from_the_ashes? > > As an extension, how about: > > define_simple_predicate_matcher :risen_from_the_ashes => :rises_from_the_ashes? I'd rather not add a new DSL for the few cases in which we want to essentially delegate a predicate. We can already do this with the matcher DSL: Spec::Matchers.define :risen_from_the_ashes do match {|actual| actual.risen_from_the_ashes?} end This is better aligned w/ other matchers, more clear as to what it does, and isn't much more code. FWIW, David > > Also, in general, I think specs look better without ? symbols on methods, my preference though > > Ashley > > -- > http://www.patchspace.co.uk/ > http://www.linkedin.com/in/ashleymoran > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Mon Jan 18 10:21:43 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 18 Jan 2010 09:21:43 -0600 Subject: [rspec-users] Something like tags in cucumber In-Reply-To: <4B5478DF.6090106@gmail.com> References: <4B5478DF.6090106@gmail.com> Message-ID: <57c63afe1001180721y2d182f91v135222cd33c7105f@mail.gmail.com> On Mon, Jan 18, 2010 at 9:06 AM, Phillip Koebbe wrote: > In cucumber, I use tags in a very simple, yet helpful (to me) way: to number > my scenarios. For example: > > @1 > > Scenario: This is a scenario > > @2 > > Scenario: This is another scenario > > @3 > > Scenario: You get the idea > > This allows me to focus in on a single scenario quite easily while I'm > working on it. Once I have that scenario working correctly, I will run the > entire feature to make sure nothing else is broken. > > I'm finding that I'd like to do something quite similar in RSpec. For > example, when I'm working on a model spec, I generally have contexts for > what database fields should exist, what validations should exist, and what > associations should exist. > > When I am later adding a couple of custom methods > to do something, I'd like to be able to run the spec just for what I'm > presently working on. Is this possible? Not yet, but it will be in rspec-2. Internal syntax will be different, but we'll try to make the CLI work like cuke's. Cheers, David > > Peace, > Phillip From phillipkoebbe at gmail.com Mon Jan 18 10:29:00 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Mon, 18 Jan 2010 09:29:00 -0600 Subject: [rspec-users] Something like tags in cucumber In-Reply-To: <57c63afe1001180721y2d182f91v135222cd33c7105f@mail.gmail.com> References: <4B5478DF.6090106@gmail.com> <57c63afe1001180721y2d182f91v135222cd33c7105f@mail.gmail.com> Message-ID: <4B547E3C.2050109@gmail.com> David Chelimsky wrote: > On Mon, Jan 18, 2010 at 9:06 AM, Phillip Koebbe wrote: > >> In cucumber, I use tags in a very simple, yet helpful (to me) way: to number >> my scenarios. For example: >> >> @1 >> >> Scenario: This is a scenario >> >> @2 >> >> Scenario: This is another scenario >> >> @3 >> >> Scenario: You get the idea >> >> This allows me to focus in on a single scenario quite easily while I'm >> working on it. Once I have that scenario working correctly, I will run the >> entire feature to make sure nothing else is broken. >> >> I'm finding that I'd like to do something quite similar in RSpec. For >> example, when I'm working on a model spec, I generally have contexts for >> what database fields should exist, what validations should exist, and what >> associations should exist. >> >> When I am later adding a couple of custom methods >> to do something, I'd like to be able to run the spec just for what I'm >> presently working on. Is this possible? >> > > Not yet, but it will be in rspec-2. Internal syntax will be different, > but we'll try to make the CLI work like cuke's. > > Looking forward to it! Thanks, Phillip > Cheers, > David > > >> Peace, >> Phillip >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ashley.moran at patchspace.co.uk Mon Jan 18 10:43:19 2010 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Mon, 18 Jan 2010 15:43:19 +0000 Subject: [rspec-users] default to just call the method? In-Reply-To: <57c63afe1001180712s41591463wdc61baf4f3b65241@mail.gmail.com> References: <8936163d-331b-49c8-aac7-2fc089556f18@a6g2000yqm.googlegroups.com> <8D614E43-9043-4336-8BE7-FE0822193848@patmaddox.com> <57c63afe1001180712s41591463wdc61baf4f3b65241@mail.gmail.com> Message-ID: <71261D2F-B24B-4E6D-A395-55278902B836@patchspace.co.uk> On Jan 18, 2010, at 3:12 pm, David Chelimsky wrote: > I'd rather not add a new DSL for the few cases in which we want to > essentially delegate a predicate. We can already do this with the > matcher DSL: I think Pat was just suggesting Roger try this in his own code. It's not something I especially want in RSpec, that was just a suggestion how Roger could play with the macro idea. Ashley -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashleymoran From cdemyanovich at gmail.com Mon Jan 18 14:55:05 2010 From: cdemyanovich at gmail.com (Craig Demyanovich) Date: Mon, 18 Jan 2010 14:55:05 -0500 Subject: [rspec-users] testing named_scope In-Reply-To: <57c63afe1001180217y22cd503au769201f5ff9d7a6e@mail.gmail.com> References: <6BE00C1F-8409-401E-A5C6-B7C9D578EF67@patmaddox.com> <57c63afe1001180217y22cd503au769201f5ff9d7a6e@mail.gmail.com> Message-ID: <61c885db1001181155u1c52e7b4id0d61b4be2fa4f78@mail.gmail.com> On Mon, Jan 18, 2010 at 5:17 AM, David Chelimsky wrote: > On Mon, Jan 18, 2010 at 4:01 AM, Pat Maddox > wrote: > ... > > class User < ActiveRecord::Base > > named_scope :admins, :conditions => {:admin => true} > > end > > > > describe User, "admins" do > > it "should include users with admin flag" do > > admin = User.create! :admin => true > > User.admin.should include(admin) > > end > > > > it "should not include users without admin flag" do > > admin = User.create! :admin => false > > User.admin.should_not include(admin) > > end > > end > > Small style matter, but I've leaning towards more declarative sounding > example names: > > describe User, ".admins" do > it "includes users with admin flag" do > admin = User.create! :admin => true > User.admin.should include(admin) > end > > it "excludes users without admin flag" do > non_admin = User.create! :admin => false > User.admin.should_not include(non_admin) > end > end > > class User < ActiveRecord::Base > named_scope :admins, :conditions => {:admin => true} > end > > We still have 'should' in the examples, but this produces more > 'spec-like' output: > > User.admins > includes users with admin flag > excludes users without admin flag I agree, David. I've been omitting "should" from the beginning. For me, it made the start of every example look too similar. Regards, Craig -------------- next part -------------- An HTML attachment was scrubbed... URL: From mailinglists at patmaddox.com Mon Jan 18 15:33:28 2010 From: mailinglists at patmaddox.com (Pat Maddox) Date: Mon, 18 Jan 2010 12:33:28 -0800 Subject: [rspec-users] default to just call the method? In-Reply-To: <57c63afe1001180712s41591463wdc61baf4f3b65241@mail.gmail.com> References: <8936163d-331b-49c8-aac7-2fc089556f18@a6g2000yqm.googlegroups.com> <8D614E43-9043-4336-8BE7-FE0822193848@patmaddox.com> <57c63afe1001180712s41591463wdc61baf4f3b65241@mail.gmail.com> Message-ID: <88ECC3D6-8B7E-4CE6-AF93-AF0C4575CEE5@patmaddox.com> On Jan 18, 2010, at 7:12 AM, David Chelimsky wrote: > On Mon, Jan 18, 2010 at 9:03 AM, Ashley Moran > wrote: >> >> On Jan 18, 2010, at 9:31 am, Pat Maddox wrote: >> >>> define_simple_predicate_matcher :rise_from_the_ashes? >> >> As an extension, how about: >> >> define_simple_predicate_matcher :risen_from_the_ashes => :rises_from_the_ashes? > > I'd rather not add a new DSL for the few cases in which we want to > essentially delegate a predicate. We can already do this with the > matcher DSL: > > Spec::Matchers.define :risen_from_the_ashes do > match {|actual| actual.risen_from_the_ashes?} > end > > This is better aligned w/ other matchers, more clear as to what it > does, and isn't much more code. This was a suggestion for OP to add to his own codebase, not RSpec, if he wanted to make the matcher definition even more concise. Pat From dchelimsky at gmail.com Mon Jan 18 15:46:08 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 18 Jan 2010 14:46:08 -0600 Subject: [rspec-users] default to just call the method? In-Reply-To: <88ECC3D6-8B7E-4CE6-AF93-AF0C4575CEE5@patmaddox.com> References: <8936163d-331b-49c8-aac7-2fc089556f18@a6g2000yqm.googlegroups.com> <8D614E43-9043-4336-8BE7-FE0822193848@patmaddox.com> <57c63afe1001180712s41591463wdc61baf4f3b65241@mail.gmail.com> <88ECC3D6-8B7E-4CE6-AF93-AF0C4575CEE5@patmaddox.com> Message-ID: <57c63afe1001181246m1fe2924ci17445a1fdbe76ca2@mail.gmail.com> On Mon, Jan 18, 2010 at 2:33 PM, Pat Maddox wrote: > On Jan 18, 2010, at 7:12 AM, David Chelimsky wrote: > >> On Mon, Jan 18, 2010 at 9:03 AM, Ashley Moran >> wrote: >>> >>> On Jan 18, 2010, at 9:31 am, Pat Maddox wrote: >>> >>>> define_simple_predicate_matcher :rise_from_the_ashes? >>> >>> As an extension, how about: >>> >>> define_simple_predicate_matcher :risen_from_the_ashes => :rises_from_the_ashes? >> >> I'd rather not add a new DSL for the few cases in which we want to >> essentially delegate a predicate. We can already do this with the >> matcher DSL: >> >> Spec::Matchers.define :risen_from_the_ashes do >> ?match {|actual| actual.risen_from_the_ashes?} >> end >> >> This is better aligned w/ other matchers, more clear as to what it >> does, and isn't much more code. > > This was a suggestion for OP to add to his own codebase, not RSpec, if he wanted to make the matcher definition even more concise. Understood. Thx. > Pat From lists at ruby-forum.com Tue Jan 19 07:03:43 2010 From: lists at ruby-forum.com (Juanma Cervera) Date: Tue, 19 Jan 2010 13:03:43 +0100 Subject: [rspec-users] Singleton classes Message-ID: <3d96bba10469cd5b9ce607c2a9e538b5@ruby-forum.com> Hello I am trying to spec a singleton ruby class, And I am having a little trouble because my specs are not more isolated, as I am getting the same instace of the class for all my examples. How should I do this.? Which is the correct way of specing a singleton class? Thanks Juanma -- Posted via http://www.ruby-forum.com/. From tom at experthuman.com Tue Jan 19 08:13:45 2010 From: tom at experthuman.com (Tom Stuart) Date: Tue, 19 Jan 2010 13:13:45 +0000 Subject: [rspec-users] RSpec for Rails 3 Message-ID: Hi folks, DHH has tentatively suggested a Rails 3 beta this month, so an innocent question: what's the plan, such as it is, for Rails 3 support in RSpec? Personally there's no way I'll be able to move any of my applications to Rails 3 until I can run the specs. Absent any specific information I've been assuming the answer is a Debian-style "it'll be done when it's done", i.e. there's no plan to roll out Rails 3 compatibility in the immediate future. However, if there's anything more detailed than that, I'd love to hear it. Presumably nobody on the list is yet using RSpec with Rails 3? Bonus question: are we likely to see Rails 3 compatibility in RSpec 1 as an interim measure, or is it only slated for an eventual appearance in RSpec 2? Cheers, -Tom From dchelimsky at gmail.com Tue Jan 19 08:22:39 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 19 Jan 2010 07:22:39 -0600 Subject: [rspec-users] RSpec for Rails 3 In-Reply-To: References: Message-ID: <57c63afe1001190522r20ea4e2dt656dbf09a2eec8d4@mail.gmail.com> On Tue, Jan 19, 2010 at 7:13 AM, Tom Stuart wrote: > Hi folks, > > DHH has tentatively suggested a Rails 3 beta this month, so an innocent question: what's the plan, such as it is, for Rails 3 support in RSpec? Personally there's no way I'll be able to move any of my applications to Rails 3 until I can run the specs. > > Absent any specific information I've been assuming the answer is a Debian-style "it'll be done when it's done", i.e. there's no plan to roll out Rails 3 compatibility in the immediate future. However, if there's anything more detailed than that, I'd love to hear it. Presumably nobody on the list is yet using RSpec with Rails 3? > > Bonus question: are we likely to see Rails 3 compatibility in RSpec 1 as an interim measure, or is it only slated for an eventual appearance in RSpec 2? Start here: http://blog.davidchelimsky.net/2010/01/12/rspec-2-and-rails-3/ I'll be making some more announcements about rspec-2 soon. Our goal is to release rspec-rails-2.0.0.a1 when rails-3.0.0.pre comes out. Cheers, David > > Cheers, > -Tom > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From tom at experthuman.com Tue Jan 19 08:25:49 2010 From: tom at experthuman.com (Tom Stuart) Date: Tue, 19 Jan 2010 13:25:49 +0000 Subject: [rspec-users] RSpec for Rails 3 In-Reply-To: <57c63afe1001190522r20ea4e2dt656dbf09a2eec8d4@mail.gmail.com> References: <57c63afe1001190522r20ea4e2dt656dbf09a2eec8d4@mail.gmail.com> Message-ID: <4122EB58-5F25-445C-A30C-A2BF7DDF7DD9@experthuman.com> On 19 Jan 2010, at 13:22, David Chelimsky wrote: > Start here: http://blog.davidchelimsky.net/2010/01/12/rspec-2-and-rails-3/ > I'll be making some more announcements about rspec-2 soon. Our goal is > to release rspec-rails-2.0.0.a1 when rails-3.0.0.pre comes out. Oh, that's great, thanks David. Sorry I missed the blog post -- I only read the list. Cheers, -Tom From dchelimsky at gmail.com Tue Jan 19 08:35:59 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 19 Jan 2010 07:35:59 -0600 Subject: [rspec-users] Singleton classes In-Reply-To: <3d96bba10469cd5b9ce607c2a9e538b5@ruby-forum.com> References: <3d96bba10469cd5b9ce607c2a9e538b5@ruby-forum.com> Message-ID: <57c63afe1001190535s5d115550w1a4ae54348f064bb@mail.gmail.com> On Tue, Jan 19, 2010 at 6:03 AM, Juanma Cervera wrote: > Hello > I am trying to spec a singleton ruby class, > And I am having a little trouble because my specs are not more isolated, > as I am getting the same instace of the class for all my examples. > > How should I do this.? > Which is the correct way of specing a singleton class? I'm assuming you mean singleton as in the Singleton Pattern, as opposed to the singleton class of an object, yes? If so, you'll have to dup it or subclass it in your spec if you want to isolation. Why do you need a Singleton, though? David > > Thanks > Juanma > -- > 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 Tue Jan 19 08:37:25 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 19 Jan 2010 07:37:25 -0600 Subject: [rspec-users] RSpec for Rails 3 In-Reply-To: <4122EB58-5F25-445C-A30C-A2BF7DDF7DD9@experthuman.com> References: <57c63afe1001190522r20ea4e2dt656dbf09a2eec8d4@mail.gmail.com> <4122EB58-5F25-445C-A30C-A2BF7DDF7DD9@experthuman.com> Message-ID: <57c63afe1001190537n743e106eo8ff1db1f3bc47010@mail.gmail.com> On Tue, Jan 19, 2010 at 7:25 AM, Tom Stuart wrote: > On 19 Jan 2010, at 13:22, David Chelimsky wrote: >> Start here: http://blog.davidchelimsky.net/2010/01/12/rspec-2-and-rails-3/ >> I'll be making some more announcements about rspec-2 soon. Our goal is >> to release rspec-rails-2.0.0.a1 when rails-3.0.0.pre comes out. > > Oh, that's great, thanks David. Sorry I missed the blog post -- I only read the list. No apologies necessary. I'll follow up in the next day or so w/ more information. Cheers, David > > Cheers, > -Tom > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Tue Jan 19 09:33:54 2010 From: lists at ruby-forum.com (Juanma Cervera) Date: Tue, 19 Jan 2010 15:33:54 +0100 Subject: [rspec-users] Singleton classes In-Reply-To: <57c63afe1001190535s5d115550w1a4ae54348f064bb@mail.gmail.com> References: <3d96bba10469cd5b9ce607c2a9e538b5@ruby-forum.com> <57c63afe1001190535s5d115550w1a4ae54348f064bb@mail.gmail.com> Message-ID: Yes, I mean the Singleton Pattern. I am not an expert with OO, but I supposed this pattern was what best fits my needs of a class that represent a unique resource in the system, in this case it's something like a queue of jobs that I have to administrate in real time. Am I right? Maybe not, because I am writing a web app and not using globals or session state to store this class, and I am accessing the instance of the class in each http request. In that case the dup option sounds good for me. But what do you think? Thanks David Juanma David Chelimsky wrote: > On Tue, Jan 19, 2010 at 6:03 AM, Juanma Cervera > wrote: >> Hello >> I am trying to spec a singleton ruby class, >> And I am having a little trouble because my specs are not more isolated, >> as I am getting the same instace of the class for all my examples. >> >> How should I do this.? >> Which is the correct way of specing a singleton class? > > I'm assuming you mean singleton as in the Singleton Pattern, as > opposed to the singleton class of an object, yes? > > If so, you'll have to dup it or subclass it in your spec if you want > to isolation. > > Why do you need a Singleton, though? > > David -- Posted via http://www.ruby-forum.com/. From ashley.moran at patchspace.co.uk Tue Jan 19 10:13:40 2010 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Tue, 19 Jan 2010 15:13:40 +0000 Subject: [rspec-users] Singleton classes In-Reply-To: References: <3d96bba10469cd5b9ce607c2a9e538b5@ruby-forum.com> <57c63afe1001190535s5d115550w1a4ae54348f064bb@mail.gmail.com> Message-ID: <5C3284AB-2AAB-45F4-90A4-1B8002AFA8E3@patchspace.co.uk> On Jan 19, 2010, at 2:33 pm, Juanma Cervera wrote: > Yes, I mean the Singleton Pattern. > I am not an expert with OO, but I supposed this pattern was what best > fits my needs of a class that represent a unique resource in the system, > in this case it's something like a queue of jobs that I have to > administrate in real time. > Am I right? What would be the implications of *not* using a singleton? Bear in mind that if you're writing a webapp, you will at some point have two of these objects simultaneously in different processes. What is the responsibility of the object itself, and where does the responsibility for enforcing that the resource is only used by one client at a time live? Ashley -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashleymoran From lists at ruby-forum.com Wed Jan 20 06:03:04 2010 From: lists at ruby-forum.com (Amit Kulkarni) Date: Wed, 20 Jan 2010 12:03:04 +0100 Subject: [rspec-users] Display Rspec output in an html file In-Reply-To: <519fdc75a55cf41ee085070ec152b883@ruby-forum.com> References: <6bb97fe564ebbb30e16ad7e753473ca0@ruby-forum.com> <6E9E130A-B144-4AAC-9EEF-CA69E189D553@mattwynne.net> <744c997fb5fe43cbb5987ef33930c18b@ruby-forum.com> <57c63afe0911270258r73d1b432wdbcc999a93a8bdd8@mail.gmail.com> <519fdc75a55cf41ee085070ec152b883@ruby-forum.com> Message-ID: Amit Kulkarni wrote: > Ok.Thanks a lot David Hello, Is there any way to display rspec result in .csv or .xls format. -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Wed Jan 20 07:23:44 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 20 Jan 2010 06:23:44 -0600 Subject: [rspec-users] Display Rspec output in an html file In-Reply-To: References: <6bb97fe564ebbb30e16ad7e753473ca0@ruby-forum.com> <6E9E130A-B144-4AAC-9EEF-CA69E189D553@mattwynne.net> <744c997fb5fe43cbb5987ef33930c18b@ruby-forum.com> <57c63afe0911270258r73d1b432wdbcc999a93a8bdd8@mail.gmail.com> <519fdc75a55cf41ee085070ec152b883@ruby-forum.com> Message-ID: <57c63afe1001200423p1bf1c9e7nbf0e1cb0fd9205ac@mail.gmail.com> On Wed, Jan 20, 2010 at 5:03 AM, Amit Kulkarni wrote: > Amit Kulkarni wrote: >> Ok.Thanks a lot David > > Hello, > Is there any way to display rspec result in .csv or .xls format. You can write a custom formatter and invoke it with: spec spec --require my_formatter.rb --formatter MyFormatter See http://rspec.rubyforge.org/rspec/1.3.0/classes/Spec/Runner/Formatter/BaseFormatter.html for all the methods you'll want to implement in the formatter. HTH, David From lists at ruby-forum.com Wed Jan 20 08:39:13 2010 From: lists at ruby-forum.com (Amit Kulkarni) Date: Wed, 20 Jan 2010 14:39:13 +0100 Subject: [rspec-users] Display Rspec output in an html file In-Reply-To: <57c63afe1001200423p1bf1c9e7nbf0e1cb0fd9205ac@mail.gmail.com> References: <6bb97fe564ebbb30e16ad7e753473ca0@ruby-forum.com> <6E9E130A-B144-4AAC-9EEF-CA69E189D553@mattwynne.net> <744c997fb5fe43cbb5987ef33930c18b@ruby-forum.com> <57c63afe0911270258r73d1b432wdbcc999a93a8bdd8@mail.gmail.com> <519fdc75a55cf41ee085070ec152b883@ruby-forum.com> <57c63afe1001200423p1bf1c9e7nbf0e1cb0fd9205ac@mail.gmail.com> Message-ID: <121adbf4a9037f3a64748cc11bb2e5c2@ruby-forum.com> Thanks a lot David. I generated a the output to xls with the command "spec user_spec.rb --format progress:a.xls" Under the xls it is displaying only those examples which are failing like for e.g. 1) 'User User should not be created if email format is different' FAILED expected: "Please check the email format", got: ["is too short (minimum is 6 characters)", "should look like an email address."] (using ==) ./user_spec.rb:39: In html it looks like: should not be created if email format is different expected: "Please check the email format", got: ["is too short (minimum is 6 characters)", "should look like an email address."] (using ==)./user_spec.rb:39:37 @user.email = "abcd" 38 @user.should_not be_valid 39 @user.errors.on(:email).should == "Please check the email format" 40 end Now how can i change the code so that output in xls will look similar to html atleast passing examples should be visible I also wanted to know how and where i should write my custom formatter? Also it would be good if i can see some links which contains examples of the same -- Posted via http://www.ruby-forum.com/. From coreyhaines at gmail.com Wed Jan 20 10:27:24 2010 From: coreyhaines at gmail.com (Corey Haines) Date: Wed, 20 Jan 2010 09:27:24 -0600 Subject: [rspec-users] default to just call the method? Message-ID: <6bdacb71001200727r66d083bfm95b70a334abf264b@mail.gmail.com> Is something like this what you were thinking of? http://gist.github.com/281907 >>> On Jan 18, 2010, at 9:31 am, Pat Maddox wrote: >>> >>>> define_simple_predicate_matcher :rise_from_the_ashes? >>> >>> As an extension, how about: >>> >>> define_simple_predicate_matcher :risen_from_the_ashes => :rises_from_the_ashes? >> -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines From mailinglists at patmaddox.com Wed Jan 20 14:20:44 2010 From: mailinglists at patmaddox.com (Pat Maddox) Date: Wed, 20 Jan 2010 11:20:44 -0800 Subject: [rspec-users] default to just call the method? In-Reply-To: <6bdacb71001200727r66d083bfm95b70a334abf264b@mail.gmail.com> References: <6bdacb71001200727r66d083bfm95b70a334abf264b@mail.gmail.com> Message-ID: exactamundo On Jan 20, 2010, at 7:27 AM, Corey Haines wrote: > Is something like this what you were thinking of? > > http://gist.github.com/281907 > > >>>> On Jan 18, 2010, at 9:31 am, Pat Maddox wrote: >>>> >>>>> define_simple_predicate_matcher :rise_from_the_ashes? >>>> >>>> As an extension, how about: >>>> >>>> define_simple_predicate_matcher :risen_from_the_ashes => :rises_from_the_ashes? >>> > > > -- > 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 dansteinicke at gmail.com Wed Jan 20 13:00:51 2010 From: dansteinicke at gmail.com (Dan Steinicke) Date: Wed, 20 Jan 2010 10:00:51 -0800 Subject: [rspec-users] [rails] undefined method `handling_predicate!' Message-ID: I'm trying to use authlogic and factory_girl with rspec and I am getting an error I don't understand. Basically I have this failing spec: it "should succeed in creating a user from a factory" do testuser = Factory.create(:user) debugger testuser.should be_valid end When I stop in the debugger I see this: (rdb:1) testuser.valid? true (rdb:1) testuser.should be_valid NoMethodError Exception: undefined method `handling_predicate!' for # My (limited) understanding of rSpec is that if the "testuser.valid?" works then "testuser.should be_valid" should work as well. I'm confused because its not working. Can someone help me understand what is going on here? I am using the following gem versions: rspec (1.3.0) rspec-rails (1.3.2) authlogic (2.1.3) factory_girl (1.2.3) rails (2.3.5) I have uninstalled/ reinstalled rspec, rspec-rails and rerun script/generate rspec letting it overwrite everything. Gist with full terminal output from running the spec and files: http://gist.github.com/282045 spec/models/user_spec.rb spec/spec_helper.rb spec/factories/users.rb thanks Dan Steinicke From dchelimsky at gmail.com Wed Jan 20 22:07:35 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 20 Jan 2010 21:07:35 -0600 Subject: [rspec-users] [rails] undefined method `handling_predicate!' In-Reply-To: References: Message-ID: <57c63afe1001201907y37b802e0h71b09cf572537122@mail.gmail.com> On Wed, Jan 20, 2010 at 12:00 PM, Dan Steinicke wrote: > I'm trying to use authlogic and factory_girl with rspec ?and I am > getting an error I don't understand. ?Basically I have this failing > spec: > > it "should succeed in creating a user from a factory" do > ? ? testuser = Factory.create(:user) > ? ? debugger > ? ? testuser.should be_valid > end > > When I stop in the debugger I see this: > > (rdb:1) testuser.valid? > true > (rdb:1) testuser.should be_valid > NoMethodError Exception: undefined method `handling_predicate!' for > # > > My (limited) understanding of rSpec is that if the "testuser.valid?" > works then "testuser.should be_valid" should work as well. ?I'm > confused because its not working. > > Can someone help me understand what is going on here? > > I am using the following gem versions: > rspec (1.3.0) > rspec-rails (1.3.2) > authlogic (2.1.3) > factory_girl (1.2.3) > rails (2.3.5) > > I have uninstalled/ reinstalled rspec, rspec-rails and rerun > script/generate rspec letting it overwrite everything. > > Gist with full terminal output from running the spec and files: > http://gist.github.com/282045 > spec/models/user_spec.rb > spec/spec_helper.rb > spec/factories/users.rb > > thanks > Dan Steinicke Hey Dan, If you're seeing that error it means you have an older version of rspec-rails than 1.3.2 that is being loaded. Try running the spec with --backtrace so you can see a full backtrace. Do you see any other versions being loaded? Maybe from vendor/plugins? From brad.forsyth at inspire2go.com Wed Jan 20 22:38:28 2010 From: brad.forsyth at inspire2go.com (Brad) Date: Wed, 20 Jan 2010 19:38:28 -0800 (PST) Subject: [rspec-users] Need Help with Specs failing when using ActionMailer In-Reply-To: References: <9cd70a2a-320d-4c48-867a-7ca459858daa@l13g2000yqb.googlegroups.com> <57c63afe0912100155t15cb1531p438b0ecbbcfbf81a@mail.gmail.com> Message-ID: Finally solved the problem. Even though the application is Rails 2.3.5 it was started on a much earlier version and the view files were using the old rhtml extensions. The newer auto format detection uses html.erb, or in the case of the mailer, likes file_name.text.html.erb. All I had to do was rename the view files and the specifications passed. Not sure why the application ran fine with the old file name extensions whereas controller spec's failed, but at least it is now working. On Dec 10 2009, 9:20?am, Brad wrote: > Dave > Thanks for looking at this. ?I really appreciate it. > > Here is the method being called: > > 144 ?# Sign up a new user with a default role of USER and with a state > of pending. > 145 ?# The user must activate their account via e-mail before they can > login > 146 ?def self.create_from_signup(params = {} ) > 147 ? ?user = new(params) > 148 ? ?if user.valid? > 149 ? ? ?user.register! > 150 ? ? ?UserNotifier.deliver_signup_notification(user) > 151 ? ?end > 152 ? ?return user > 153 ?end > > Line 150 is calling UserNotifier > > class UserNotifier ? def signup_notification(user) > ? ? setup_email(user) > ? ? @subject ? ?+= "#{user.login}, Please activate your new account" > ? ? @body[:url] ?= "http://#{SITE_HOST}/activate/# > {user.activation_code}" > ? end > > ? def password_reset_notification(user, newpassword) > ? ? setup_email(user) > ? ? @subject ? ?+= "#{user.login}, Account changes" > ? ? @body[:password] ?= newpassword > ? end > > ? protected > ? def setup_email(user) > ? ? @recipients ?= "#{user.email}" > ? ? @from ? ? ? ?= ?SITE > ? ? @subject ? ? = "[CONFIRMATION] " > ? ? @sent_on ? ? = Time.now > ? ? @body[:user] = user > ? end > end > > Everything works well in the standalone model spec. ?It's when I > combine it with controller spec's that the problem occurs. > > Brad > > On Dec 10, 4:55?am, David Chelimsky wrote: > > > > > On Wed, Dec 9, 2009 at 7:48 PM, Brad wrote: > > > No one was able to help me with the last post so I thought I would try > > > again with more details. ?I am having problems with specs that invoke > > > the mailer. ?My User model has a method that invokes a mailer as part > > > of the create_from_signup method. > > > > First an example of the test that passes in my spec/models/user_spec > > > when run in isolation (i.e. spec spec/models/user_spec.rb). > > > > ? ?before do > > > ? ? ?UserNotifier.deliveries = [] > > > ? ?end > > > > ? ?it "should signup a valid user and send an activation e-mail" do > > > ? ? ?u = User.create_from_signup(params) > > > ? ? ?u.state.should == 'pending' > > > ? ? ?UserNotifier.should have(1).deliveries > > > ? ? ?mail = UserNotifier.deliveries.first > > > ? ? ?mail.to.should eql( [u.email] ) > > > ? ? ?mail.subject.should eql( "#{u.login}, Please activate your new > > > account" ) > > > ? ?end > > > > The spec passes with no problems [ all green :) ] > > > > When I run this same spec within my entire suite (spec spec), it fails > > > with the following backtrace > > > > ArgumentError in 'User Signup - should signup a valid user and send an > > > activation e-mail" > > > wrong number of arguments (0 for 1) > > > ruby/lib/ruby/gems/1.8/gems/actionmailer-2.3.5/lib/action_mailer/ > > > base.rb:551:in 'content_type' > > > ruby/lib/ruby/gems/1.8/gems/actionmailer-2.3.5/lib/action_mailer/ > > > base.rb:551:in 'render_message' > > > ruby/lib/ruby/gems/1.8/gems/actionmailer-2.3.5/lib/action_mailer/ > > > base.rb:493:in 'create!' > > > ruby/lib/ruby/gems/1.8/gems/actionmailer-2.3.5/lib/action_mailer/ > > > base.rb:452:in 'initialize' > > > ruby/lib/ruby/gems/1.8/gems/actionmailer-2.3.5/lib/action_mailer/ > > > base.rb:395:in 'new' > > > ruby/lib/ruby/gems/1.8/gems/actionmailer-2.3.5/lib/action_mailer/ > > > base.rb:395:in 'method_missing' > > > rails/app/models/user.rb:150:in 'create_from_signup' > > > What's on line 150 in user.rb? Please post the entire method > > surrounding that line. > > > > I get this same error in my user controller tests, whether I run it > > > standalone or within the suite. > > > > Does anyone have any idea what could be causing this? > > > > Thanks in advance > > > > Brad > > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From ben at benmabey.com Thu Jan 21 11:11:37 2010 From: ben at benmabey.com (Ben Mabey) Date: Thu, 21 Jan 2010 09:11:37 -0700 Subject: [rspec-users] running specs on JRuby w/nailgun Message-ID: <4B587CB9.103@benmabey.com> Hi all, I know this is probably more of a JRuby question but I'm guessing that people on this list may have gone down this path before. At work we are starting a new project using JRuby. The startup speed for testing an app is very painful. Nailgun helps a lot with that. It only helps with the slow startup time of JRuby though and does not address the use case of having gems preloaded like Spork does for MRI. We would like to have all of our gems (esp Rails) preloaded in Nailgun so we can run our tests against it with minimal startup time (just the loading of the app and specs). Has anyone solved this problem to get lightning fast specs on JRuby just like we can with MRI and Spork? Thanks, Ben From onno.van.der.straaten at gmail.com Thu Jan 21 16:31:13 2010 From: onno.van.der.straaten at gmail.com (Onno van der Straaten) Date: Thu, 21 Jan 2010 22:31:13 +0100 Subject: [rspec-users] Within method (and other Webrat methods) Message-ID: Hi, Another newbie question. I'm sort of confused as I often find instructions on the internet that don't work. Now I was looking for ways to click a link that can only be selected in a complex way using CSS selectors. I found an example within "#entry_2" do |scope| scope.click_link "Delete" end The article suggests this done using Webrat but when I try to use it the message is that 'within' does not exist. I am using Webrat right? I have this in env.rb require 'webrat' require 'webrat/core/matchers' Best Regards, Onno -------------- next part -------------- An HTML attachment was scrubbed... URL: From dansteinicke at gmail.com Thu Jan 21 17:38:01 2010 From: dansteinicke at gmail.com (DanS) Date: Thu, 21 Jan 2010 14:38:01 -0800 (PST) Subject: [rspec-users] [rails] undefined method `handling_predicate!' In-Reply-To: <57c63afe1001201907y37b802e0h71b09cf572537122@mail.gmail.com> References: <57c63afe1001201907y37b802e0h71b09cf572537122@mail.gmail.com> Message-ID: On Jan 20, 7:07?pm, David Chelimsky wrote: > On Wed, Jan 20, 2010 at 12:00 PM, Dan Steinicke wrote: > > I'm trying to use authlogic and factory_girl with rspec ?and I am > > getting an error I don't understand. ?Basically I have this failing > > spec: > > > it "should succeed in creating a user from a factory" do > > ? ? testuser = Factory.create(:user) > > ? ? debugger > > ? ? testuser.should be_valid > > end > > > When I stop in the debugger I see this: > > > (rdb:1) testuser.valid? > > true > > (rdb:1) testuser.should be_valid > > NoMethodError Exception: undefined method `handling_predicate!' for > > # > > > My (limited) understanding of rSpec is that if the "testuser.valid?" > > works then "testuser.should be_valid" should work as well. ?I'm > > confused because its not working. > > > Can someone help me understand what is going on here? > > > I am using the following gem versions: > > rspec (1.3.0) > > rspec-rails (1.3.2) > > authlogic (2.1.3) > > factory_girl (1.2.3) > > rails (2.3.5) > > > I have uninstalled/ reinstalled rspec, rspec-rails and rerun > > script/generate rspec letting it overwrite everything. > > > Gist with full terminal output from running the spec and files: > >http://gist.github.com/282045 > > spec/models/user_spec.rb > > spec/spec_helper.rb > > spec/factories/users.rb > > > thanks > > Dan Steinicke > > Hey Dan, > > If you're seeing that error it means you have an older version of > rspec-rails than 1.3.2 that is being loaded. Try running the spec with > --backtrace so you can see a full backtrace. Do you see any other > versions being loaded? Maybe from vendor/plugins? > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users David, That indeed was the problem. The gist from the original post shows the test run with --backtrace and it does show rspec-rails in vendor/ plugins (I didn't see a version number tho). I did the following: rm -fr vendor/plugin/rspec-rails rm -fr vendor/plugin/rsecp sudo gem install rspec rspec-rails After which the spec no longer produces a NoMethodError and in fact passes. Thanks for taking the time to help me understand this, I was really stuck. Dan From rogerpack2005 at gmail.com Thu Jan 21 17:54:43 2010 From: rogerpack2005 at gmail.com (rogerdpack) Date: Thu, 21 Jan 2010 14:54:43 -0800 (PST) Subject: [rspec-users] running specs on JRuby w/nailgun In-Reply-To: <4B587CB9.103@benmabey.com> References: <4B587CB9.103@benmabey.com> Message-ID: > Has anyone solved this problem to get lightning fast specs on JRuby just > like we can with MRI and Spork? I'm working on a single threaded spork http://github.com/rdp/spork it might work with jruby it sure does speed things up mightily here in windows land -r From yalong1976 at gmail.com Thu Jan 21 22:40:44 2010 From: yalong1976 at gmail.com (aaron zhang) Date: Fri, 22 Jan 2010 11:40:44 +0800 Subject: [rspec-users] error: stack level too deep Message-ID: <83740ebc1001211940t50bcf542pbe9ce84d320d1198@mail.gmail.com> hi, guys i write follow code : it "The default should be based on readers to recommend a book tastes" do @pick_book = mock_model(PickBook) @pick_books = [@pick_book] @recommend_count = 1 PickBook.should_receive(:recommend_books).with(@recommend_count, at user).and_return(@pick_books) post 'create','format'=>'json' assigns['pick_books'].should equal(@pick_books) response.should be_success response.should have_text(@pick_books.to_json) end The following error occurred: stack level too deep Best regards, -- Aaron ????? www.nonobo.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From mailinglists at patmaddox.com Thu Jan 21 23:52:28 2010 From: mailinglists at patmaddox.com (Pat Maddox) Date: Thu, 21 Jan 2010 20:52:28 -0800 Subject: [rspec-users] error: stack level too deep In-Reply-To: <83740ebc1001211940t50bcf542pbe9ce84d320d1198@mail.gmail.com> References: <83740ebc1001211940t50bcf542pbe9ce84d320d1198@mail.gmail.com> Message-ID: <1D6727BB-D996-45B1-8585-5964768DCD3C@patmaddox.com> Please provide more context. There should be a stack trace that tells you at which line the error occurs. This problem typically occurs when you have a method that calls itself and has no return mechanism. Sometimes that can be a sloppily implemented method_missing. I can't see anything obviously wrong with what you've posted, but there's a lot missing: * the rest of the spec code * full error message * relevant production code Pat On Jan 21, 2010, at 7:40 PM, aaron zhang wrote: > hi, guys > > i write follow code : > > it "The default should be based on readers to recommend a book tastes" do > @pick_book = mock_model(PickBook) > @pick_books = [@pick_book] > @recommend_count = 1 > PickBook.should_receive(:recommend_books).with(@recommend_count, at user).and_return(@pick_books) > > post 'create','format'=>'json' > assigns['pick_books'].should equal(@pick_books) > response.should be_success > response.should have_text(@pick_books.to_json) > end > > The following error occurred: > stack level too deep > > > Best regards, > -- > Aaron ????? > www.nonobo.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: From dchelimsky at gmail.com Fri Jan 22 00:11:14 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 21 Jan 2010 23:11:14 -0600 Subject: [rspec-users] Within method (and other Webrat methods) In-Reply-To: References: Message-ID: <57c63afe1001212111o517a0a5diacbdb71c17a64b13@mail.gmail.com> On Thu, Jan 21, 2010 at 3:31 PM, Onno van der Straaten wrote: > Hi, > Another newbie question. I'm sort of confused as I often find instructions > on the internet that don't work. > > Now I was looking for ways to click a link that can only be selected in a > complex way using CSS selectors. > > I found an example > > within "#entry_2" do |scope| > scope.click_link "Delete" > end > > The article suggests this done using Webrat but when I try to use it the > message is that 'within' does not exist. I am using Webrat right? I have > this in env.rb Are you having this trouble with rspec or cucumber? If cucumber, please post to http://groups.google.com/group/cukes. If rspec, env.rb is not loaded by rspec, so that would need to go in a file that either holds your spec or is required by a spec file. HTH, David > > require 'webrat' > require 'webrat/core/matchers' > > Best Regards, > Onno From lists at ruby-forum.com Fri Jan 22 02:34:14 2010 From: lists at ruby-forum.com (Amit Kulkarni) Date: Fri, 22 Jan 2010 08:34:14 +0100 Subject: [rspec-users] Testing Email thriugh Rspec Message-ID: <59890594d0de59b0496d0010538b7cef@ruby-forum.com> Hi i am testing email through rspec but some problem occured. This is the whole scenario: What i want to do is when my user is created it should send mail to for activation. This is the code under user_spec.rb require File.expand_path(File.dirname(__FILE__) + ?/../spec_helper?) def valid_user_attributes { :email => ?testing at joshsoftware.com?, :login => ?test?, :password => ?test123?, :password_confirmation => ?test123?, :role_id => 1 } end describe User do before(:each) do @user = User.create ActionMailer::Base.delivery_method = :test ActionMailer::Base.perform_deliveries = true ActionMailer::Base.deliveries = [] end fixtures :users context ?User? do it ?should be create if all the credentials are provided? do @user.attributes = valid_user_attributes mail = Notifier.signup_notification(?user_1?) ActionMailer::Base.deliveries.size.should == 1 mail.body.should =~ /Please signup/ @user.should be_valid @user.save end Under notifier.rb it contains: class Notifier < ActionMailer::Base helper :application #user notification def signup_notification( user ) setup_email( user.email ) @subject = "Please signup" @body[:user] = user end end Now here Notifier is another model which contains signup_ notification method. Is it the case that i would need to test that in notifier spec or is it possible to get notifier model in user like by using include method I tried using include like "include Notifier" but is is showing me error as user_spec.rb:2:in `include': wrong argument type Class (expected Module) (TypeError) -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Fri Jan 22 04:01:39 2010 From: lists at ruby-forum.com (Amit Kulkarni) Date: Fri, 22 Jan 2010 10:01:39 +0100 Subject: [rspec-users] Testing Email thriugh Rspec In-Reply-To: <59890594d0de59b0496d0010538b7cef@ruby-forum.com> References: <59890594d0de59b0496d0010538b7cef@ruby-forum.com> Message-ID: <4356a8c4fbe02d499f9b3d2bdb5fe4a3@ruby-forum.com> I got the Notifier model included in the user spec like require 'notifier.rb' By adding this i can now access Notifier.deliver_signup_notification method(i checked up in the code and it user deliver before that) Now i can access the method. But another problem is i am getting error as "undefined method `email' for 327378:Fixnum" in app/models/notifier.rb:5:in `signup_notification' i.e. on this line "setup_email( user.email )" This means that it is getting the user object.But i have added user in fixtures. How can i add this user to point it to notifier object? -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Fri Jan 22 05:24:48 2010 From: lists at ruby-forum.com (Amit Kulkarni) Date: Fri, 22 Jan 2010 11:24:48 +0100 Subject: [rspec-users] Testing Email thriugh Rspec In-Reply-To: <4356a8c4fbe02d499f9b3d2bdb5fe4a3@ruby-forum.com> References: <59890594d0de59b0496d0010538b7cef@ruby-forum.com> <4356a8c4fbe02d499f9b3d2bdb5fe4a3@ruby-forum.com> Message-ID: <547f2fe7007020c5b75cf9a7365de1df@ruby-forum.com> Hello all, I got my problem solved.It was really a simple mistake. I have a doubt that in development i can send a mail but in while testing(through Rspec) mail is not getting sent. Do i need to change some configuration for testing? -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Fri Jan 22 06:23:11 2010 From: lists at ruby-forum.com (Sh Sr) Date: Fri, 22 Jan 2010 12:23:11 +0100 Subject: [rspec-users] Call for a browser from command line in rakefile Message-ID: <9d53c5056782edce67f7f35ef3de2812@ruby-forum.com> I have a rakefile which run few tasks. I want to run my tests for different browsers using the rakefile. What would be the best suited way to achieve this? Please help. -- Posted via http://www.ruby-forum.com/. From jko170 at gmail.com Fri Jan 22 08:55:25 2010 From: jko170 at gmail.com (jko170) Date: Fri, 22 Jan 2010 05:55:25 -0800 (PST) Subject: [rspec-users] Testing Email thriugh Rspec In-Reply-To: <547f2fe7007020c5b75cf9a7365de1df@ruby-forum.com> References: <59890594d0de59b0496d0010538b7cef@ruby-forum.com> <4356a8c4fbe02d499f9b3d2bdb5fe4a3@ruby-forum.com> <547f2fe7007020c5b75cf9a7365de1df@ruby-forum.com> Message-ID: There is also the excellent email_spec gem: http://github.com/bmabey/email-spec/ On Jan 22, 2:24?am, Amit Kulkarni wrote: > Hello all, > I got my problem solved.It was really a simple mistake. > I have a doubt that in development i can send a mail but in while > testing(through Rspec) mail is not getting sent. > Do i need to change some configuration for testing? > -- > Posted viahttp://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From railsthinker at gmail.com Fri Jan 22 14:46:49 2010 From: railsthinker at gmail.com (gokul murthy) Date: Sat, 23 Jan 2010 01:16:49 +0530 Subject: [rspec-users] STDIN gets method issue with rspec Message-ID: <99bb0f4f1001221146p30315958xdc20ec764dd7aa1f@mail.gmail.com> Hi, I am new to rspec. I am trying to write a spec for a simple ruby program i.e class First def test a = gets.chomp return a end end I have tried in different ways test method is called from the spec file. but gets.chomp is not executing? Please kindly advise me, how to write spec for this. Thanks Gokul -------------- next part -------------- An HTML attachment was scrubbed... URL: From rogerdpack at gmail.com Fri Jan 22 15:18:47 2010 From: rogerdpack at gmail.com (rogerdpack) Date: Fri, 22 Jan 2010 12:18:47 -0800 (PST) Subject: [rspec-users] double warning in doze Message-ID: <9113c723-90a9-4bd3-9a5d-a627f98fc03f@l11g2000yqb.googlegroups.com> When I run autospec, I typically see this double warning--might be nice to clean it up a bit. You must 'gem install win32console' to use colour on Windows You must 'gem install win32console' to use colour on Windows From itsme213 at hotmail.com Fri Jan 22 17:27:36 2010 From: itsme213 at hotmail.com (Sophie) Date: Fri, 22 Jan 2010 16:27:36 -0600 Subject: [rspec-users] Basic cucumber setup / usage question (OSX) Message-ID: I just installed cucumber and tried to run it on the included examples/self_test. I get the error below: self_test > cucumber features/lots_of_undefined.feature no such file to load -- spec/expectations (LoadError) /Users/s/.rvm/ruby-1.8.7-p174/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' Any ideas? From dchelimsky at gmail.com Fri Jan 22 18:06:33 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 22 Jan 2010 17:06:33 -0600 Subject: [rspec-users] Basic cucumber setup / usage question (OSX) In-Reply-To: References: Message-ID: <39A273C9-6A97-44FC-B40A-ED54190D3CA7@gmail.com> On Jan 22, 2010, at 4:27 PM, Sophie wrote: > I just installed cucumber and tried to run it on the included examples/self_test. I get the error below: Please address cucumber questions to the cucumber list: http://groups.google.com/group/cukes RSpec questions are always welcome here, though :) Cheers, David > > self_test > cucumber features/lots_of_undefined.feature > no such file to load -- spec/expectations (LoadError) > /Users/s/.rvm/ruby-1.8.7-p174/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' > > Any ideas? > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Sat Jan 23 07:36:01 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 23 Jan 2010 06:36:01 -0600 Subject: [rspec-users] STDIN gets method issue with rspec In-Reply-To: <99bb0f4f1001221146p30315958xdc20ec764dd7aa1f@mail.gmail.com> References: <99bb0f4f1001221146p30315958xdc20ec764dd7aa1f@mail.gmail.com> Message-ID: <57c63afe1001230436k4de8cae6l3d0a31634b726137@mail.gmail.com> On Fri, Jan 22, 2010 at 1:46 PM, gokul murthy wrote: > Hi, > I am new to rspec. I am trying to write a spec for a simple ruby program i.e > class First > def test > a = gets.chomp > return a > end > end > I have tried in different ways test method is called from the spec file. but > gets.chomp is not executing? > Please kindly advise me, how to write spec for this. Even though it seems simple, you've chosen a rather complex situation to try to learn Rspec from. Did you pick this because you really need to solve it, or is this just an academic exercise? If the latter, let's start somewhere simpler, and get to things like simulating IO later :) It is always easiest to start with examples in which you can create an object with some state, send it a message (call a method), and set expectations about the result: given/when/then. describe Person, "full name" do context "with a first and last name" do it "concats the names with a space between them" do #given person = Person.new(:first_name => "Gokul", :last_name => "Murthy") # when full_name = person.full_name #then full_name.should == "Gokul Murthy" end end end I separated out the When and Then to make it clear which is which, but in practice I'd likely just write this: it "concats the names with a space between them" do person = Person.new(:first_name => "Gokul", :last_name => "Murthy") person.full_name.should == "Gokul Murthy" end Now we have a pretty clear picture of how we want to create a Person and how we want to ask for its name, and what our expected outcome is. If you really want to know about specifying IO, let me know and I'll show you a couple of ways to do it, but they are much less straightforward. Cheers, David > Thanks > Gokul From mguterl at gmail.com Sat Jan 23 09:16:42 2010 From: mguterl at gmail.com (Michael Guterl) Date: Sat, 23 Jan 2010 09:16:42 -0500 Subject: [rspec-users] testing named_scope In-Reply-To: References: Message-ID: <944a03771001230616g1b986a69o5bd4be4271ca6531@mail.gmail.com> On Sun, Jan 17, 2010 at 9:17 PM, Nin wrote: > Hi! I'm new to rspec and was wondering how named_scopes are usually > tested? Is it enough to test that it's defined? or do you need to test > the behavior as well? I've been reading around and this seems to be > the tester's choice, i just want to get people's opinion on this :D While this is focused on shoulda, I still found it helpful for demonstrating how to properly deal with testing named_scopes. http://robots.thoughtbot.com/post/200254501/testing-named-scopes Best regards, Michael Guterl From ben at benmabey.com Sat Jan 23 19:29:13 2010 From: ben at benmabey.com (Ben Mabey) Date: Sat, 23 Jan 2010 17:29:13 -0700 Subject: [rspec-users] testing named_scope In-Reply-To: <57c63afe1001180217y22cd503au769201f5ff9d7a6e@mail.gmail.com> References: <6BE00C1F-8409-401E-A5C6-B7C9D578EF67@patmaddox.com> <57c63afe1001180217y22cd503au769201f5ff9d7a6e@mail.gmail.com> Message-ID: <4B5B9459.8060405@benmabey.com> David Chelimsky wrote: > On Mon, Jan 18, 2010 at 4:01 AM, Pat Maddox wrote: > >> On Jan 17, 2010, at 6:17 PM, Nin wrote: >> >>> Hi! I'm new to rspec and was wondering how named_scopes are usually >>> tested? Is it enough to test that it's defined? or do you need to test >>> the behavior as well? I've been reading around and this seems to be >>> the tester's choice, i just want to get people's opinion on this :D >>> >> class User < ActiveRecord::Base >> named_scope :admins, :conditions => {:admin => true} >> end >> >> describe User, "admins" do >> it "should include users with admin flag" do >> admin = User.create! :admin => true >> User.admin.should include(admin) >> end >> >> it "should not include users without admin flag" do >> admin = User.create! :admin => false >> User.admin.should_not include(admin) >> end >> end >> > > Small style matter, but I've leaning towards more declarative sounding > example names: > > describe User, ".admins" do > it "includes users with admin flag" do > admin = User.create! :admin => true > User.admin.should include(admin) > end > > it "excludes users without admin flag" do > non_admin = User.create! :admin => false > User.admin.should_not include(non_admin) > end > end > > class User < ActiveRecord::Base > named_scope :admins, :conditions => {:admin => true} > end > > We still have 'should' in the examples, but this produces more > 'spec-like' output: > > User.admins > includes users with admin flag > excludes users without admin flag > > FWIW, > David > Another small style matter.. I like using the :: notation for class methods as that is what the documentation tools tend to use (RDoc and Yard): describe User, "::admins" do ... ... end On the topic of RSpec as a form of documentation has anyone used the yard-doc rspec plugin? It appears to be pretty limited ATM but seems very cool with a lot of potential. Just like Ioke's docs it embeds the specs as part of the documentation with the option to view the source. Here is the example from the projects home page: http://lsegal.github.com/yard-spec-plugin/String.html#pig_latin-instance_method -Ben From lists at ruby-forum.com Sat Jan 23 22:24:51 2010 From: lists at ruby-forum.com (Nick Hoffman) Date: Sun, 24 Jan 2010 04:24:51 +0100 Subject: [rspec-users] Troubles with route_for In-Reply-To: References: <57c63afe1001110546g762cb3e5pfba7227cc8b0b960@mail.gmail.com> <4B4C1F5C.3010506@yahoo.com> <0cc23fb5c587c4e1232fe5adbbfaa208@ruby-forum.com> <93f60ccf6698a5d0e8d470ce7cc280ec@ruby-forum.com> <57c63afe1001130633l3d96bb9ev657c760c5d31ce61@mail.gmail.com> <57c63afe1001130827m4b1d1cdan30799db17b98a163@mail.gmail.com> Message-ID: Hey guys. I have two different paths that lead to the same controller and action: map.connect 'foods/search/:name', :controller => 'foods', :action => 'search' map.food ':name', :controller => 'foods', :action => 'search' Unfortunately, the spec for the second route fails because #route_to finds and uses the first route when generating the path for :controller => 'foods', :action => 'search', :name => 'almonds' routes.rb: http://codepad.org/CjKRynr5 specs: http://codepad.org/838oV3mW Is there a solution to this problem? Thanks, Nick -- Posted via http://www.ruby-forum.com/. From rjharmon0316 at yahoo.com Sun Jan 24 13:43:01 2010 From: rjharmon0316 at yahoo.com (Randy Harmon) Date: Sun, 24 Jan 2010 10:43:01 -0800 Subject: [rspec-users] Troubles with route_for In-Reply-To: References: <57c63afe1001110546g762cb3e5pfba7227cc8b0b960@mail.gmail.com> <4B4C1F5C.3010506@yahoo.com> <0cc23fb5c587c4e1232fe5adbbfaa208@ruby-forum.com> <93f60ccf6698a5d0e8d470ce7cc280ec@ruby-forum.com> <57c63afe1001130633l3d96bb9ev657c760c5d31ce61@mail.gmail.com> <57c63afe1001130827m4b1d1cdan30799db17b98a163@mail.gmail.com> Message-ID: <4B5C94B5.2000407@yahoo.com> I guess the distinction is that you generate food_path()'s based on existing food names, and search comes from users - but you don't have a distinct landing page for each food, hence no need for resource-based routing for foods. You could define a :show action in your controller, which simply calls the 'search' action. def show search end Then they'll have different controller-actions and different paths, yet the implementations would be identical. And the specs can describe them distinctly. I'd be curious if there are other ways to do this. Randy On 1/23/10 7:24 PM, Nick Hoffman wrote: > Hey guys. I have two different paths that lead to the same controller > and action: > map.connect 'foods/search/:name', :controller => 'foods', :action => > 'search' > map.food ':name', :controller => 'foods', :action => > 'search' > > Unfortunately, the spec for the second route fails because #route_to > finds and uses the first route when generating the path for > :controller => 'foods', :action => 'search', :name => 'almonds' > > routes.rb: http://codepad.org/CjKRynr5 > specs: http://codepad.org/838oV3mW > > Is there a solution to this problem? > > Thanks, > Nick > From lists at ruby-forum.com Sun Jan 24 18:10:32 2010 From: lists at ruby-forum.com (Saverio Miroddi) Date: Mon, 25 Jan 2010 00:10:32 +0100 Subject: [rspec-users] Stub activerecord find given instance? In-Reply-To: <57c63afe1001121949h444bc715x89fee7e8bc81f84c@mail.gmail.com> References: <4A3616AC-32C2-478C-B20D-DF65FE1C031E@experthuman.com> <57c63afe0912140439y4c5a00fbtb65d155eccd5426f@mail.gmail.com> <57c63afe1001121949h444bc715x89fee7e8bc81f84c@mail.gmail.com> Message-ID: David Chelimsky wrote: > It'd be much easier to help you if you could provide an example more > representative of what you are actually trying to accomplish. So, here it is (note: this is NOT representative of a properly engineered behavior): class MyModel def my_parent self.find( my_parent_id ) end end class MyController < ... def show m = MyModel.find( params[ :id ] ) mp = m.my_parent @m_value = m.value @mp_value = mp.value end end now, suppose I want to stub a behavior only for the child object ('m'). so my intention in the spec is to: - create the child and his parent - stub MyModel#value in the child - stub MyModel.find to return "m" _only_ when called with the child id, otherwise it should do its usual business. if I stub generically, m#my_parent would return "m" itself. the test would be: it "should display a stubbed value for the children" do mp = MyModel.create!( :value => 0xCAFEBABE ) m = MyModel.create!( :my_parent_id => mp.id, :value => 64738 ) m.stub!( :value ).with( m.id ).and_return( 42 ) get :show, :id => m.id end what happens is: - if I don't use ".with( m.id )", @m_value and @mp_value will have m.value assigned. - if I use ".with( m.id )", I even get an error "undefined method `find' for #" at the line "self.find( my_parent_id )" inside the method MyModel#my_parent. Hope this clarified, it's not real production code, but it models a behavior sometimes I actually needed. Saverio -- Posted via http://www.ruby-forum.com/. From paul.t.hinze at gmail.com Sun Jan 24 22:05:15 2010 From: paul.t.hinze at gmail.com (Paul Hinze) Date: Sun, 24 Jan 2010 21:05:15 -0600 Subject: [rspec-users] Stub activerecord find given instance? In-Reply-To: References: <4A3616AC-32C2-478C-B20D-DF65FE1C031E@experthuman.com> <57c63afe0912140439y4c5a00fbtb65d155eccd5426f@mail.gmail.com> <57c63afe1001121949h444bc715x89fee7e8bc81f84c@mail.gmail.com> Message-ID: <6c35a5c91001241905r1205fc12me243fb28f1c2cca5@mail.gmail.com> On Sun, Jan 24, 2010 at 5:10 PM, Saverio Miroddi wrote: > David Chelimsky wrote: >> It'd be much easier to help you if you could provide an example more >> representative of what you are actually trying to accomplish. > > class MyModel > ?def my_parent > ? ?self.find( my_parent_id ) > ?end > end > > class MyController < ... > ?def show > ? ?m = MyModel.find( params[ :id ] ) > ? ?mp = m.my_parent > > ? ?@m_value = m.value > ? ?@mp_value = mp.value > ?end > end Hi Saverio, Following this thread, and still having trouble understanding what it it you are trying to accomplish. > now, suppose I want to stub a behavior only for the child object ('m'). > so my intention in the spec is to: > > - create the child and his parent > - stub MyModel#value in the child > - stub MyModel.find to return "m" _only_ when called with the child id, > otherwise it should do its usual business. if I stub generically, > m#my_parent would return "m" itself. The below test does not accomplish this third point... I'll explain below. > the test would be: > > it "should display a stubbed value for the children" do > ?mp = MyModel.create!( :value => 0xCAFEBABE ) > ?m ?= MyModel.create!( :my_parent_id => mp.id, :value => 64738 ) > > ?m.stub!( :value ).with( m.id ).and_return( 42 ) Here you are creating a stub on the instance `m`, not stubbing `MyModel.find` as you explain above. Perhaps you meant something more like this? m.stub!(:value).and_return(42) MyModel.stub!(:find).with(m.id).and_return(m) > get :show, :id => m.id Given the text you use in the example description ('should display a value for the children') I wonder why you are passing the _child's_ id into the show action. This seems off to me... are you actually testing that the _parent's_ value is shown in the action? > end In fact, since it looks like `value` is just an attribute of MyModel here, I wonder why you would need to stub at all, when you can just specify the value you are expecting when you create the `m` instance in the test? It is hard to tell since you aren't including any verification in the example you gave. What is it you are actually trying to test here? My best guess would be that you're going for something like this: it "displays parent's :value attribute" do expected_value = 386438247 value_i_dont_care_about = 123 mp = MyModel.create!( :value => expected_value ) m = MyModel.create!( :my_parent_id => mp.id, :value => value_i_dont_care_about ) get "show", :id => m.id response.should include(expected_value) end The above tests that when you render a "show" for instance `m` that `m`'s parent's 'value' attribute shows up somewhere on the page. What are you hoping for the stub to accomplish for you in this test? > what happens is: > - if I don't use ".with( m.id )", @m_value and @mp_value will have > m.value assigned. This makes sense if you are indeed stubbing `MyModel.find` without using `with` similar to my guess above, since any arguments you pass would be ignored and the instance `m` would be returned in all cases. > - if I use ".with( m.id )", I even get an error "undefined method `find' > for #" at the line "self.find( my_parent_id )" > inside the method MyModel#my_parent. This is odd, and I'm not sure without more context why this would be happening. My guess is that something else wasn't wired up correctly when you tried to do this. > Hope this clarified, it's not real production code, but it models a > behavior sometimes I actually needed. I think some more clarification is needed in order for us to properly help you. a) What is the exact behavior you are trying to test? b) Why do you believe that a stub would help you test this behavior? Hope this helps get us going in the right direction at least, :) Paul From rogerpack2005 at gmail.com Wed Jan 27 00:21:40 2010 From: rogerpack2005 at gmail.com (rogerdpack) Date: Tue, 26 Jan 2010 21:21:40 -0800 (PST) Subject: [rspec-users] unable to describe...expected? Message-ID: <6f688f9a-2811-4a31-a03b-7a695327d75b@f12g2000yqn.googlegroups.com> Question. I noticed that this code: class Redcar::Project describe FileMirror do is allowed, however this code module Redcar describe Project do ... is not. Is this expected? -r From rogerpack2005 at gmail.com Wed Jan 27 00:37:27 2010 From: rogerpack2005 at gmail.com (rogerdpack) Date: Tue, 26 Jan 2010 21:37:27 -0800 (PST) Subject: [rspec-users] unable to describe...expected? In-Reply-To: <6f688f9a-2811-4a31-a03b-7a695327d75b@f12g2000yqn.googlegroups.com> References: <6f688f9a-2811-4a31-a03b-7a695327d75b@f12g2000yqn.googlegroups.com> Message-ID: <2c1a68a6-b876-4eb7-ab7f-168a56df6faf@a5g2000yqi.googlegroups.com> > is allowed, however this code > > module Redcar > ?describe Project do > ? ? ... > > is not. Oops--appears the problem was that I was running it as ruby instead of spec (and/or including autorun). Sorry for the noise. -r From firatcanbasarir at gmail.com Wed Jan 27 04:39:15 2010 From: firatcanbasarir at gmail.com (Firat Can Basarir) Date: Wed, 27 Jan 2010 11:39:15 +0200 Subject: [rspec-users] Typo on web-page Message-ID: <68f1c5511001270139l59ee8afeh989ad3cfcb72766c@mail.gmail.com> There is a typo on the documentation page: http://rspec.info/rails/writing/controllers.html "Spec::Raiks" on the 2nd line of 2nd paragraph. I don't know whom to contact about this. I hope the website maintainer is subscribed to this list or someone can redirect this to him. F?rat From paul.t.hinze at gmail.com Thu Jan 28 08:29:49 2010 From: paul.t.hinze at gmail.com (Paul Hinze) Date: Thu, 28 Jan 2010 07:29:49 -0600 Subject: [rspec-users] Message expectation that verifies result of passed block Message-ID: <20100128132949.GV6554@malachai> Hey speclers, My spec-fu is failing me on a message expectation in which I would like to verify that the block passed to a certain method yields the proper value. I would like to be able to say something like: def bar # .. some code foo do 'bar' # want to verify this value end end describe 'bar' do it 'calls foo with proper block' do should_receive(:foo).with(block_yielding('bar')) end end The problem I've been banging my head against is the fact that I can't seem to capture the passed block using this notation: should_receive(:foo) { |*args, &block| yield.should == 'bar' # breaks block.call.should == 'bar' # no dice } I believe the lack of ability to use this notation comes down to a ruby limitation, but I'm not sure. If that's the case, then we would need a specific argument expectation (along the lines of my suggestion) that executes in a context in which it can call the block. Am I missing something obvious here, or does rspec currently not allow for this easily? If not, let's discuss how it should look and I can work on adding feature. Cheers, Paul From rick.denatale at gmail.com Thu Jan 28 12:49:42 2010 From: rick.denatale at gmail.com (Rick DeNatale) Date: Thu, 28 Jan 2010 12:49:42 -0500 Subject: [rspec-users] Can I set an expectation that a method invokes super? Message-ID: Not sure if I can easily do this Just ran into a bug in a rails app where ApplicationController overrides rescue_action_in_public leading to the error page not being displayed. The fix was to call super at the end of the method. I'd like to write a spec to ensure that this doesn't regress, but my imagination is failing me as to how to do it. Any ideas? -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale From rogerpack2005 at gmail.com Thu Jan 28 13:54:22 2010 From: rogerpack2005 at gmail.com (rogerdpack) Date: Thu, 28 Jan 2010 10:54:22 -0800 (PST) Subject: [rspec-users] somewhat confused by the help instructions... Message-ID: <2a39e8e4-72b7-4f37-9e1e-f358eebf5d3c@b2g2000yqi.googlegroups.com> As a note of feedback, when I do a spec --help, I saw this line... -e, --example [NAME|FILE_NAME] Execute example(s) with matching name(s). If the argument is the path to an existing file (typically generated by a previous run using --format failing_examples:file.txt), then the examples on each line of that file will be executed. If the file is empty, all examples will be run (as if -- example was not specified). so I, trying to be clever, passed it something to match: E:\dev\ruby\spork>spec spec/spork/run_strategy/single* -e"the result" Finished in 0.125 seconds 0 examples, 0 failures Passing it the full test name seems to work, however: E:\dev\ruby\spork>spec spec/spork/run_strategy/single* -e"returns the result of the run_tests method from the forked child" ... Finished in 0.34375 seconds 3 examples, 0 failures Suggestion: rephrase the help as "runs the test whose name equals the one specified" (instead of using the word "matches" which to me somehow meant "regex"), or change the matching to be regex matching (this one is what I would personally prefer--then you don't have to put full test names on the command line). Thoughts? -r From ashley.moran at patchspace.co.uk Thu Jan 28 14:14:44 2010 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Thu, 28 Jan 2010 19:14:44 +0000 Subject: [rspec-users] Can I set an expectation that a method invokes super? In-Reply-To: References: Message-ID: <748A6120-8765-4228-B826-52279FAC1C16@patchspace.co.uk> On Jan 28, 2010, at 5:49 pm, Rick DeNatale wrote: > I'd like to write a spec to ensure that this doesn't regress, but my > imagination is failing me as to how to do it. > > Any ideas? Yes: don't use inheritance for implementations. The bug you describe is arguably a violation of the Liskov Substitution Principle, ie the derived class changed the functionality it inherited in a way that broke the expected behaviour of all derived classes. If you can write a spec (possibly shared examples) that defines the contract you expect *all* controllers to follow - eg display an error page in this situation - you can run that against all your controllers. Checking that you call `super` doesn't necessarily give you this security. If you want to post #rescue_action_in_public there might be another way, depending on your code. I'm no Rails guru though. BTW if this sounds like a rant, it is :) I am constantly stamping my feet over the way controllers in Rails, Merb etc are implemented, as they make writing specs extremely difficult. Let me know if this is not clear as I've thrown the email together in a hurry before going home for the night... Ashley -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashleymoran From ashley.moran at patchspace.co.uk Thu Jan 28 14:27:17 2010 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Thu, 28 Jan 2010 19:27:17 +0000 Subject: [rspec-users] Message expectation that verifies result of passed block In-Reply-To: <20100128132949.GV6554@malachai> References: <20100128132949.GV6554@malachai> Message-ID: On Jan 28, 2010, at 1:29 pm, Paul Hinze wrote: > I believe the lack of ability to use this notation comes down to a ruby > limitation, but I'm not sure. If that's the case, then we would need a > specific argument expectation (along the lines of my suggestion) that > executes in a context in which it can call the block. I can't find a solution, I suspect Ruby 1.8 can't do this, but I'm guessing. Can I ask why you want to do this though? As another example, it would be unusual to spec something like: @array = [1, 2, 3] @array.should_receive(:map).with(block_that_doubles_values) You'd instead check that the array that came out was [2, 4, 6]. Ashley -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashleymoran From paul.t.hinze at gmail.com Thu Jan 28 16:14:02 2010 From: paul.t.hinze at gmail.com (Paul Hinze) Date: Thu, 28 Jan 2010 15:14:02 -0600 Subject: [rspec-users] Message expectation that verifies result of passed block In-Reply-To: References: <20100128132949.GV6554@malachai> Message-ID: <20100128211402.GY6554@malachai> Ashley Moran on 2010-01-28 at 13:28: > > On Jan 28, 2010, at 1:29 pm, Paul Hinze wrote: > > > I believe the lack of ability to use this notation comes down to a ruby > > limitation, but I'm not sure. If that's the case, then we would need a > > specific argument expectation (along the lines of my suggestion) that > > executes in a context in which it can call the block. > > I can't find a solution, I suspect Ruby 1.8 can't do this, but I'm guessing. > > Can I ask why you want to do this though? As another example, it > would be unusual to spec something like: > > @array = [1, 2, 3] > @array.should_receive(:map).with(block_that_doubles_values) > > You'd instead check that the array that came out was [2, 4, 6]. I'm trying to spec a large set of what essentially come down to decorator methods in a Rails FormBuilder extension plugin. What this boils down to is methods that wrap rails FormBuilder methods, so `f.text(*args)` ends up calling `f.text_field(*args)` to generate an tag, but only after it does its own logic and wrapping, which among a bunch of other things wraps the output in an
  • . So the methods run the gamut in complexity from 'f.radio' to 'f.dependent_collection' to 'f.sigma', but much of the common code is wrapped up in a method called 'f.question', which does the outer
  • wrapping, required field detection, label and error display, and a few other common things required by every control we use in our forms. So most of our methods have this basic structure: class OurFormBuilder < ActionView::Helpers::FormBuilder def foo_text(method, options={}) foo_option = options.delete(:foo_option) options[:value] ||= 'FOO' # some logic, using foo_option somewhere... question(method, options) do |remaining_options| 'FOO -->' + text_field(method, remaining_options) + '<-- FOO' end end end I started out with a nice spec for `question`'s behavior and made it all in a shared group, but because of the number of examples just for question and the number of methods that call it (so both performance and complexity), I'm thinking about switching to message expectations in all of my `foo_text`-style method specs: describe 'foo_text' it 'calls text field with the proper options' do @builder.should_receive(:text_field).with(:some_method, :proper_args) @builder.foo_text(:some_method) end it 'yields a wrapped text_field into question' do # dont test rails text_field text_field_return = "BOOGA" @builder.stub!(:text_field).and_return(text_field_return) expected = "FOO -->" + text_field_return + "<-- FOO" @builder.should_receive(:question).with(:some_method).with_a_block_yielding(expected) @builder.foo_text(:some_method, :some => options) end it 'properly returns the result of the call to question' do @builder.stub!(:question).and_return('BOOGA') xhtml = @builder.foo_text(:some_method) xhtml.should == 'BOOGA' end end I'd appreciate any feedback that folks might be willing to give. Particularly I realize the following: (a) This might be testing implementation too much (possible) (b) The architecture of the whole plugin needs a serious refactor to increase modularity and decouple the components (very likely); a dash of decent OO design could really help this whole situation, and it's something I'm planning on tackling down the road For now, I'm just trying to push things in the right direction, and I _think_ the .with_a_block_yielding(value) or .with(block_yielding(value)) argument verification would help me do that. Thanks for your time! Paul From godfoca at gmail.com Thu Jan 28 16:43:35 2010 From: godfoca at gmail.com (=?ISO-8859-1?Q?Nicol=E1s_Sanguinetti?=) Date: Thu, 28 Jan 2010 19:43:35 -0200 Subject: [rspec-users] Message expectation that verifies result of passed block In-Reply-To: <20100128211402.GY6554@malachai> References: <20100128132949.GV6554@malachai> <20100128211402.GY6554@malachai> Message-ID: You're definitely testing too much implementation and not enough behavior. Basically, what you want to spec, is that provided some options, when you call a certain method of your form builder, you get a certain html output. At least that's how I would approach the problem. So I would have something like this: it "produces a correctly formatted FOO input" do html = @builder.foo_text(...) html.should == " " end Since testing generated HTML like that sucks, I would proceed to use something like http://github.com/fnando/rspec-hpricot-matchers, and say it "produces a correctly formatted FOO input" do html = @builder.foo_text(...) html.should have_tag("label", :for => "foo") html.should have_tag("input", :id => "foo") end Or something like that. But then if you stop using that question(*args, &block) method, and refactor to a different implementation, specs should continue to pass. -foca On Thu, Jan 28, 2010 at 7:14 PM, Paul Hinze wrote: > Ashley Moran on 2010-01-28 at 13:28: >> >> On Jan 28, 2010, at 1:29 pm, Paul Hinze wrote: >> >> > I believe the lack of ability to use this notation comes down to a ruby >> > limitation, but I'm not sure. ?If that's the case, then we would need a >> > specific argument expectation (along the lines of my suggestion) that >> > executes in a context in which it can call the block. >> >> I can't find a solution, I suspect Ruby 1.8 can't do this, but I'm guessing. >> >> Can I ask why you want to do this though? ?As another example, it >> would be unusual to spec something like: >> >> ? @array = [1, 2, 3] >> ? @array.should_receive(:map).with(block_that_doubles_values) >> >> You'd instead check that the array that came out was [2, 4, 6]. > > I'm trying to spec a large set of what essentially come down to > decorator methods in a Rails FormBuilder extension plugin. ?What this > boils down to is methods that wrap rails FormBuilder methods, so > `f.text(*args)` ends up calling `f.text_field(*args)` to generate an > tag, but only after it does its own logic and wrapping, which > among a bunch of other things wraps the output in an
  • . > > So the methods run the gamut in complexity from 'f.radio' to > 'f.dependent_collection' to 'f.sigma', but much of the common code is > wrapped up in a method called 'f.question', which does the outer
  • > wrapping, required field detection, label and error display, and a few > other common things required by every control we use in our forms. > > So most of our methods have this basic structure: > > ?class OurFormBuilder < ActionView::Helpers::FormBuilder > ? ?def foo_text(method, options={}) > ? ? ?foo_option = options.delete(:foo_option) > ? ? ?options[:value] ||= 'FOO' > > ? ? ?# some logic, using foo_option somewhere... > > ? ? ?question(method, options) do |remaining_options| > ? ? ? ?'FOO -->' + text_field(method, remaining_options) + '<-- FOO' > ? ? ?end > ? ?end > ?end > > I started out with a nice spec for `question`'s behavior and made it all > in a shared group, but because of the number of examples just for > question and the number of methods that call it (so both performance and > complexity), I'm thinking about switching to message expectations in all > of my `foo_text`-style method specs: > > ?describe 'foo_text' > ? ?it 'calls text field with the proper options' do > ? ? ?@builder.should_receive(:text_field).with(:some_method, :proper_args) > ? ? ?@builder.foo_text(:some_method) > ? ?end > ? ?it 'yields a wrapped text_field into question' do > ? ? ?# dont test rails text_field > ? ? ?text_field_return = "BOOGA" > ? ? ?@builder.stub!(:text_field).and_return(text_field_return) > > ? ? ?expected = "FOO -->" + text_field_return + "<-- FOO" > ? ? ?@builder.should_receive(:question).with(:some_method).with_a_block_yielding(expected) > > ? ? ?@builder.foo_text(:some_method, :some => options) > ? ?end > ? ?it 'properly returns the result of the call to question' do > ? ? ?@builder.stub!(:question).and_return('BOOGA') > ? ? ?xhtml = @builder.foo_text(:some_method) > ? ? ?xhtml.should == 'BOOGA' > ? ?end > ?end > > I'd appreciate any feedback that folks might be willing to give. > Particularly I realize the following: > > ?(a) This might be testing implementation too much (possible) > ?(b) The architecture of the whole plugin needs a serious refactor to > ? ? increase modularity and decouple the components (very likely); a > ? ? dash of decent OO design could really help this whole situation, > ? ? and it's something I'm planning on tackling down the road > > For now, I'm just trying to push things in the right direction, and I > _think_ the .with_a_block_yielding(value) or .with(block_yielding(value)) > argument verification would help me do that. > > Thanks for your time! > > Paul > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From matt at mattwynne.net Thu Jan 28 17:45:01 2010 From: matt at mattwynne.net (Matt Wynne) Date: Thu, 28 Jan 2010 22:45:01 +0000 Subject: [rspec-users] Message expectation that verifies result of passed block In-Reply-To: <20100128211402.GY6554@malachai> References: <20100128132949.GV6554@malachai> <20100128211402.GY6554@malachai> Message-ID: <20F2C73D-2BE2-43B0-AFB0-B05BE6A633CF@mattwynne.net> On 28 Jan 2010, at 21:14, Paul Hinze wrote: > Ashley Moran on 2010-01-28 at 13:28: >> >> On Jan 28, 2010, at 1:29 pm, Paul Hinze wrote: >> >>> I believe the lack of ability to use this notation comes down to a >>> ruby >>> limitation, but I'm not sure. If that's the case, then we would >>> need a >>> specific argument expectation (along the lines of my suggestion) >>> that >>> executes in a context in which it can call the block. >> >> I can't find a solution, I suspect Ruby 1.8 can't do this, but I'm >> guessing. >> >> Can I ask why you want to do this though? As another example, it >> would be unusual to spec something like: >> >> @array = [1, 2, 3] >> @array.should_receive(:map).with(block_that_doubles_values) >> >> You'd instead check that the array that came out was [2, 4, 6]. > > I'm trying to spec a large set of what essentially come down to > decorator methods in a Rails FormBuilder extension plugin. What this > boils down to is methods that wrap rails FormBuilder methods, so > `f.text(*args)` ends up calling `f.text_field(*args)` to generate an > tag, but only after it does its own logic and wrapping, which > among a bunch of other things wraps the output in an
  • . > > So the methods run the gamut in complexity from 'f.radio' to > 'f.dependent_collection' to 'f.sigma', but much of the common code is > wrapped up in a method called 'f.question', which does the outer
  • > wrapping, required field detection, label and error display, and a few > other common things required by every control we use in our forms. > > So most of our methods have this basic structure: > > class OurFormBuilder < ActionView::Helpers::FormBuilder > def foo_text(method, options={}) > foo_option = options.delete(:foo_option) > options[:value] ||= 'FOO' > > # some logic, using foo_option somewhere... > > question(method, options) do |remaining_options| > 'FOO -->' + text_field(method, remaining_options) + '<-- FOO' > end > end > end > > I started out with a nice spec for `question`'s behavior and made it > all > in a shared group, but because of the number of examples just for > question and the number of methods that call it (so both performance > and > complexity), I'm thinking about switching to message expectations in > all > of my `foo_text`-style method specs: > > describe 'foo_text' > it 'calls text field with the proper options' do > > @builder.should_receive(:text_field).with(:some_method, :proper_args) > @builder.foo_text(:some_method) > end > it 'yields a wrapped text_field into question' do > # dont test rails text_field > text_field_return = "BOOGA" > @builder.stub!(:text_field).and_return(text_field_return) > > expected = "FOO -->" + text_field_return + "<-- FOO" > > @builder > .should_receive > (:question).with(:some_method).with_a_block_yielding(expected) > > @builder.foo_text(:some_method, :some => options) > end > it 'properly returns the result of the call to question' do > @builder.stub!(:question).and_return('BOOGA') > xhtml = @builder.foo_text(:some_method) > xhtml.should == 'BOOGA' > end > end > > I'd appreciate any feedback that folks might be willing to give. > Particularly I realize the following: > > (a) This might be testing implementation too much (possible) I'd say so. I would think the most stable seam around which to write tests for this is where you call the FormBuilder to make HTML. I would not start tinkering around inside it with mocks between inheritance layers like that - it's a path that will make it very hard to do any refactoring in future. > (b) The architecture of the whole plugin needs a serious refactor to > increase modularity and decouple the components (very likely); a > dash of decent OO design could really help this whole situation, > and it's something I'm planning on tackling down the road > > For now, I'm just trying to push things in the right direction, and I > _think_ the .with_a_block_yielding(value) > or .with(block_yielding(value)) > argument verification would help me do that. > > Thanks for your time! > > Paul > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users cheers, Matt http://mattwynne.net +447974 430184 From matt at mattwynne.net Thu Jan 28 17:45:50 2010 From: matt at mattwynne.net (Matt Wynne) Date: Thu, 28 Jan 2010 22:45:50 +0000 Subject: [rspec-users] Message expectation that verifies result of passed block In-Reply-To: References: <20100128132949.GV6554@malachai> <20100128211402.GY6554@malachai> Message-ID: On 28 Jan 2010, at 21:43, Nicol?s Sanguinetti wrote: > You're definitely testing too much implementation and not enough > behavior. > > Basically, what you want to spec, is that provided some options, when > you call a certain method of your form builder, you get a certain html > output. At least that's how I would approach the problem. > > So I would have something like this: > > it "produces a correctly formatted FOO input" do > html = @builder.foo_text(...) > html.should == " " > end > > Since testing generated HTML like that sucks, I would proceed to use > something like http://github.com/fnando/rspec-hpricot-matchers, and > say > > it "produces a correctly formatted FOO input" do > html = @builder.foo_text(...) > html.should have_tag("label", :for => "foo") > html.should have_tag("input", :id => "foo") > end > > Or something like that. But then if you stop using that > question(*args, &block) method, and refactor to a different > implementation, specs should continue to pass. What he said. > -foca > > On Thu, Jan 28, 2010 at 7:14 PM, Paul Hinze > wrote: >> Ashley Moran on 2010-01-28 at 13:28: >>> >>> On Jan 28, 2010, at 1:29 pm, Paul Hinze wrote: >>> >>>> I believe the lack of ability to use this notation comes down to >>>> a ruby >>>> limitation, but I'm not sure. If that's the case, then we would >>>> need a >>>> specific argument expectation (along the lines of my suggestion) >>>> that >>>> executes in a context in which it can call the block. >>> >>> I can't find a solution, I suspect Ruby 1.8 can't do this, but I'm >>> guessing. >>> >>> Can I ask why you want to do this though? As another example, it >>> would be unusual to spec something like: >>> >>> @array = [1, 2, 3] >>> @array.should_receive(:map).with(block_that_doubles_values) >>> >>> You'd instead check that the array that came out was [2, 4, 6]. >> >> I'm trying to spec a large set of what essentially come down to >> decorator methods in a Rails FormBuilder extension plugin. What this >> boils down to is methods that wrap rails FormBuilder methods, so >> `f.text(*args)` ends up calling `f.text_field(*args)` to generate an >> tag, but only after it does its own logic and wrapping, which >> among a bunch of other things wraps the output in an
  • . >> >> So the methods run the gamut in complexity from 'f.radio' to >> 'f.dependent_collection' to 'f.sigma', but much of the common code is >> wrapped up in a method called 'f.question', which does the outer
  • >> wrapping, required field detection, label and error display, and a >> few >> other common things required by every control we use in our forms. >> >> So most of our methods have this basic structure: >> >> class OurFormBuilder < ActionView::Helpers::FormBuilder >> def foo_text(method, options={}) >> foo_option = options.delete(:foo_option) >> options[:value] ||= 'FOO' >> >> # some logic, using foo_option somewhere... >> >> question(method, options) do |remaining_options| >> 'FOO -->' + text_field(method, remaining_options) + '<-- FOO' >> end >> end >> end >> >> I started out with a nice spec for `question`'s behavior and made >> it all >> in a shared group, but because of the number of examples just for >> question and the number of methods that call it (so both >> performance and >> complexity), I'm thinking about switching to message expectations >> in all >> of my `foo_text`-style method specs: >> >> describe 'foo_text' >> it 'calls text field with the proper options' do >> >> @builder.should_receive(:text_field).with(:some_method, :proper_args) >> @builder.foo_text(:some_method) >> end >> it 'yields a wrapped text_field into question' do >> # dont test rails text_field >> text_field_return = "BOOGA" >> @builder.stub!(:text_field).and_return(text_field_return) >> >> expected = "FOO -->" + text_field_return + "<-- FOO" >> >> @builder >> .should_receive >> (:question).with(:some_method).with_a_block_yielding(expected) >> >> @builder.foo_text(:some_method, :some => options) >> end >> it 'properly returns the result of the call to question' do >> @builder.stub!(:question).and_return('BOOGA') >> xhtml = @builder.foo_text(:some_method) >> xhtml.should == 'BOOGA' >> end >> end >> >> I'd appreciate any feedback that folks might be willing to give. >> Particularly I realize the following: >> >> (a) This might be testing implementation too much (possible) >> (b) The architecture of the whole plugin needs a serious refactor to >> increase modularity and decouple the components (very likely); a >> dash of decent OO design could really help this whole situation, >> and it's something I'm planning on tackling down the road >> >> For now, I'm just trying to push things in the right direction, and I >> _think_ the .with_a_block_yielding(value) >> or .with(block_yielding(value)) >> argument verification would help me do that. >> >> Thanks for your time! >> >> Paul >> _______________________________________________ >> 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 cheers, Matt http://mattwynne.net +447974 430184 From lists at ruby-forum.com Thu Jan 28 23:49:32 2010 From: lists at ruby-forum.com (Deven Patel) Date: Fri, 29 Jan 2010 05:49:32 +0100 Subject: [rspec-users] Testing file attachment with Paperclip In-Reply-To: <998249DD-DBC1-43C7-B3DD-41EDC97CCF88@gmail.com> References: <998249DD-DBC1-43C7-B3DD-41EDC97CCF88@gmail.com> Message-ID: <8b756e5cc8f7030d615744894d977794@ruby-forum.com> Nicholas Wieland wrote: > Does someone have an example on faking a file upload for just ensuring > it gets called, without actually uploading the file to s3. > I thought that stubbing Model.has_attached_file would be enough, but > it doesn't seem so ... > > This is what I did: > > Video.stub!( :has_attached_file ).with( :name ).and_return( true ) > > has_attached_file is from paperclip, it gets mixed to the model. > > 1) > RightAws::AwsError in 'VideosController should create a valid Video' > AWS access keys are required to operate on S3 > /Users/ngw/zooppa-4/app/controllers/videos_controller.rb:6:in `create' > /Users/ngw/zooppa-4/spec/controllers/videos_controller_spec.rb:17: > > Maybe I missed something ? > > TIA, > ngw hello dear..... have u got the solution 4 that...then please tell me... and second one is, from where u get S3 aws_access_key and aws_secret_access_key and bucket_base_name .. or from wher to set this......... thanks replay me on deven.patel at trinitywebtech.com -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Thu Jan 28 23:49:56 2010 From: lists at ruby-forum.com (Deven Patel) Date: Fri, 29 Jan 2010 05:49:56 +0100 Subject: [rspec-users] Testing file attachment with Paperclip In-Reply-To: <998249DD-DBC1-43C7-B3DD-41EDC97CCF88@gmail.com> References: <998249DD-DBC1-43C7-B3DD-41EDC97CCF88@gmail.com> Message-ID: <34d4486bd5ae42b9868e5beb103424f1@ruby-forum.com> Nicholas Wieland wrote: > Does someone have an example on faking a file upload for just ensuring > it gets called, without actually uploading the file to s3. > I thought that stubbing Model.has_attached_file would be enough, but > it doesn't seem so ... > > This is what I did: > > Video.stub!( :has_attached_file ).with( :name ).and_return( true ) > > has_attached_file is from paperclip, it gets mixed to the model. > > 1) > RightAws::AwsError in 'VideosController should create a valid Video' > AWS access keys are required to operate on S3 > /Users/ngw/zooppa-4/app/controllers/videos_controller.rb:6:in `create' > /Users/ngw/zooppa-4/spec/controllers/videos_controller_spec.rb:17: > > Maybe I missed something ? > > TIA, > ngw hello dear..... have u got the solution 4 that...then please tell me... and second one is, from where u get S3 aws_access_key and aws_secret_access_key and bucket_base_name .. or from wher to set this......... thanks replay me on deven.patel at trinitywebtech.com -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Fri Jan 29 06:53:04 2010 From: lists at ruby-forum.com (Amit Kulkarni) Date: Fri, 29 Jan 2010 12:53:04 +0100 Subject: [rspec-users] testing controllers using cucumber Message-ID: Hello, Is there any way to test controllers using cucumber. I was doing it with rspec but since cucumber's description is good how can i proceed testing it with cucumber? For e.g. I have a scenario of user creation like Feature: User Scenarios Scenario: Successfull creation of user Given a new user When the user fill all the mandatory details Then that user should get created And success message should get displayed and email should be sent for activation In step definition: Given /^a new user$/ do end When /^the user fill all the mandatory details$/ do end When /^that user should get created$/ do end Then /^success message should get displayed and email should be sent for activation$/ do end In this how i need to call the users controller and in that create method. Also i searched in the net but didn't found any examples for cucumber testing controllers. Please suggest -- Posted via http://www.ruby-forum.com/. From matt-lists at reprocessed.org Fri Jan 29 07:16:20 2010 From: matt-lists at reprocessed.org (Matt Patterson) Date: Fri, 29 Jan 2010 12:16:20 +0000 Subject: [rspec-users] testing controllers using cucumber In-Reply-To: References: Message-ID: <2ADC6B7D-E312-49FC-B8A7-20A26582DDED@reprocessed.org> On 29 Jan 2010, at 11:53, Amit Kulkarni wrote: > Hello, > Is there any way to test controllers using cucumber. > I was doing it with rspec but since cucumber's description is good how > can i proceed testing it with cucumber? Hi Amit. There's a Cucumber specific mailing list at http://groups.google.com/group/cukes?pli=1, which is a better place to ask Cucumbetr questions. With Cucumber, you don't tend to test controllers directly, instead you're testing the whole app, much like Rails' own Integration Tests. > For e.g. > I have a scenario of user creation like > Feature: User Scenarios > > Scenario: Successfull creation of user > Given a new user > When the user fill all the mandatory details > Then that user should get created > And success message should get displayed and email should be sent > for activation So, your example might be implemented like this: Given /^I'm on the new user page$/ do visit new_user_path end When /^I fill all the mandatory details$/ do fill_in("name", :with =>"Joe") end Then /^that user should get created$/ do User.find_by_name("Joe").should_not be_nil end > In this how i need to call the users controller and in that create > method. > Also i searched in the net but didn't found any examples for cucumber > testing controllers. There are lots of examples on the Cucumber site http://cukes.info/ HTH Matt -- Matt Patterson | Design & Code | http://www.reprocessed.org/ From dchelimsky at gmail.com Sat Jan 30 01:45:25 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 30 Jan 2010 00:45:25 -0600 Subject: [rspec-users] somewhat confused by the help instructions... In-Reply-To: <2a39e8e4-72b7-4f37-9e1e-f358eebf5d3c@b2g2000yqi.googlegroups.com> References: <2a39e8e4-72b7-4f37-9e1e-f358eebf5d3c@b2g2000yqi.googlegroups.com> Message-ID: <57c63afe1001292245o21772b63h843b7ea6d4b79d47@mail.gmail.com> On Thu, Jan 28, 2010 at 12:54 PM, rogerdpack wrote: > As a note of feedback, when I do a spec --help, I saw this line... > > ? ?-e, --example [NAME|FILE_NAME] ? Execute example(s) with matching > name(s). If the argument is > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? the path to an existing file > (typically generated by a previous > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? run using --format > failing_examples:file.txt), then the examples > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? on each line of that file will be > executed. If the file is empty, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? all examples will be run (as if -- > example was not specified). > > so I, trying to be clever, passed it something to match: > > E:\dev\ruby\spork>spec spec/spork/run_strategy/single* -e"the result" > > > Finished in 0.125 seconds > > 0 examples, 0 failures > > > Passing it the full test name seems to work, however: > > E:\dev\ruby\spork>spec spec/spork/run_strategy/single* -e"returns the > result of the run_tests method from the forked child" > ... > > Finished in 0.34375 seconds > > 3 examples, 0 failures > > > Suggestion: > > rephrase the help as "runs the test whose name equals the one > specified" (instead of using the word "matches" which to me somehow > meant "regex"), or > > change the matching to be regex matching (this one is what I would > personally prefer--then you don't have to put full test names on the > command line). > > Thoughts? Actually, I'm thinking of not supporting this in rspec-2. I personally find the line number much more useful, since you can just copy it directly from the failure messages to re-run something: spec path/to/spec.rb:37 WDYT? > -r > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From matt-lists at reprocessed.org Sat Jan 30 04:50:33 2010 From: matt-lists at reprocessed.org (Matt Patterson) Date: Sat, 30 Jan 2010 09:50:33 +0000 Subject: [rspec-users] Can I set an expectation that a method invokes super? In-Reply-To: References: Message-ID: On 28 Jan 2010, at 17:49, Rick DeNatale wrote: > Not sure if I can easily do this > > Just ran into a bug in a rails app where ApplicationController > overrides rescue_action_in_public leading to the error page not being > displayed. > > The fix was to call super at the end of the method. > > I'd like to write a spec to ensure that this doesn't regress, but my > imagination is failing me as to how to do it. Two thoughts, one not very helpful, the other hopefully more so. My approach with this area has been to ignore the mechanics of error catching in controllers, to steer clear of rescue_action_in_public in apps - using rescue_from instead - and using a custom matcher to check that particular controllers declare that they rescue particular errors. To ensure that, in practice, the right stuff happens I use Cucumber to check that in a 404 type situation the right stuff happens across the whole stack. HTH Matt -- Matt Patterson | Design & Code | http://www.reprocessed.org/ From matt at mattwynne.net Sat Jan 30 08:31:20 2010 From: matt at mattwynne.net (Matt Wynne) Date: Sat, 30 Jan 2010 13:31:20 +0000 Subject: [rspec-users] somewhat confused by the help instructions... In-Reply-To: <57c63afe1001292245o21772b63h843b7ea6d4b79d47@mail.gmail.com> References: <2a39e8e4-72b7-4f37-9e1e-f358eebf5d3c@b2g2000yqi.googlegroups.com> <57c63afe1001292245o21772b63h843b7ea6d4b79d47@mail.gmail.com> Message-ID: On 30 Jan 2010, at 06:45, David Chelimsky wrote: > On Thu, Jan 28, 2010 at 12:54 PM, rogerdpack > wrote: >> As a note of feedback, when I do a spec --help, I saw this line... >> >> -e, --example [NAME|FILE_NAME] Execute example(s) with matching >> name(s). If the argument is >> the path to an existing file >> (typically generated by a previous >> run using --format >> failing_examples:file.txt), then the examples >> on each line of that file will be >> executed. If the file is empty, >> all examples will be run (as if >> -- >> example was not specified). >> >> so I, trying to be clever, passed it something to match: >> >> E:\dev\ruby\spork>spec spec/spork/run_strategy/single* -e"the result" >> >> >> Finished in 0.125 seconds >> >> 0 examples, 0 failures >> >> >> Passing it the full test name seems to work, however: >> >> E:\dev\ruby\spork>spec spec/spork/run_strategy/single* -e"returns the >> result of the run_tests method from the forked child" >> ... >> >> Finished in 0.34375 seconds >> >> 3 examples, 0 failures >> >> >> Suggestion: >> >> rephrase the help as "runs the test whose name equals the one >> specified" (instead of using the word "matches" which to me somehow >> meant "regex"), or >> >> change the matching to be regex matching (this one is what I would >> personally prefer--then you don't have to put full test names on the >> command line). >> >> Thoughts? > > Actually, I'm thinking of not supporting this in rspec-2. I personally > find the line number much more useful, since you can just copy it > directly from the failure messages to re-run something: > > spec path/to/spec.rb:37 This is great except when you use macros or other tricks to generate examples - then there isn't a 1:1: mapping from line number to example. I often find it quite annoying to have to quote the whole example description, so I actually quite like Roger's idea about using regexp matching. > WDYT? > >> -r >> >> _______________________________________________ >> 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 cheers, Matt http://mattwynne.net +447974 430184 From dchelimsky at gmail.com Sat Jan 30 09:38:59 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 30 Jan 2010 08:38:59 -0600 Subject: [rspec-users] somewhat confused by the help instructions... In-Reply-To: References: <2a39e8e4-72b7-4f37-9e1e-f358eebf5d3c@b2g2000yqi.googlegroups.com> <57c63afe1001292245o21772b63h843b7ea6d4b79d47@mail.gmail.com> Message-ID: <57c63afe1001300638h15cc15eai8c97d15634197ec3@mail.gmail.com> On Sat, Jan 30, 2010 at 7:31 AM, Matt Wynne wrote: > > On 30 Jan 2010, at 06:45, David Chelimsky wrote: > >> On Thu, Jan 28, 2010 at 12:54 PM, rogerdpack >> wrote: >>> >>> As a note of feedback, when I do a spec --help, I saw this line... >>> >>> ? -e, --example [NAME|FILE_NAME] ? Execute example(s) with matching >>> name(s). If the argument is >>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?the path to an existing file >>> (typically generated by a previous >>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?run using --format >>> failing_examples:file.txt), then the examples >>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?on each line of that file will be >>> executed. If the file is empty, >>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?all examples will be run (as if -- >>> example was not specified). >>> >>> so I, trying to be clever, passed it something to match: >>> >>> E:\dev\ruby\spork>spec spec/spork/run_strategy/single* -e"the result" >>> >>> >>> Finished in 0.125 seconds >>> >>> 0 examples, 0 failures >>> >>> >>> Passing it the full test name seems to work, however: >>> >>> E:\dev\ruby\spork>spec spec/spork/run_strategy/single* -e"returns the >>> result of the run_tests method from the forked child" >>> ... >>> >>> Finished in 0.34375 seconds >>> >>> 3 examples, 0 failures >>> >>> >>> Suggestion: >>> >>> rephrase the help as "runs the test whose name equals the one >>> specified" (instead of using the word "matches" which to me somehow >>> meant "regex"), or >>> >>> change the matching to be regex matching (this one is what I would >>> personally prefer--then you don't have to put full test names on the >>> command line). >>> >>> Thoughts? >> >> Actually, I'm thinking of not supporting this in rspec-2. I personally >> find the line number much more useful, since you can just copy it >> directly from the failure messages to re-run something: >> >> spec path/to/spec.rb:37 > > This is great except when you use macros or other tricks to generate > examples - then there isn't a 1:1: mapping from line number to example. I > often find it quite annoying to have to quote the whole example description, > so I actually quite like Roger's idea about using regexp matching. Excellent news for you both. It turns out that the underlying machinery is already in place for this in rspec2's new runner. Just need to hook it to the command line. But right now, in rspec-core-2.0.0.a2, you can say this in any Ruby that gets loaded (like spec_helper.rb): Rspec::Core.configure do |c| c.filter_run :description => /should match this string/ end Hooking that from the CLI will be pretty simple, so coming soon. Cheers, David > >> WDYT? >> >>> -r >>> >>> _______________________________________________ >>> 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 > > cheers, > Matt > > http://mattwynne.net > +447974 430184 > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Sat Jan 30 10:35:09 2010 From: lists at ruby-forum.com (Ravi Shankar) Date: Sat, 30 Jan 2010 16:35:09 +0100 Subject: [rspec-users] Why we use RSpec Message-ID: <519191666db4f509513b1157cfc0f5e8@ruby-forum.com> Hi all, I am new to the RSpec, I have many questions related to the RSpec. 1. Why one should use RSpec instead of other testing technique 2. Which are the best tools than RSpec 3. Where can i get RSpec demo -- Posted via http://www.ruby-forum.com/. From tristam29 at gmail.com Sun Jan 31 10:30:54 2010 From: tristam29 at gmail.com (Tristam29) Date: Sun, 31 Jan 2010 07:30:54 -0800 (PST) Subject: [rspec-users] Why we use RSpec In-Reply-To: <519191666db4f509513b1157cfc0f5e8@ruby-forum.com> References: <519191666db4f509513b1157cfc0f5e8@ruby-forum.com> Message-ID: <7497627f-8243-40b4-9f01-f849d695c08a@g29g2000yqe.googlegroups.com> On Jan 30, 10:35?am, Ravi Shankar wrote: > Hi all, > > I am new to the RSpec, I have many questions related to the RSpec. > > 1. Why one should use RSpec instead of other testing technique RSpec is designed for Behavior Driven Development, whereas many testing tools are designed for Test Driven Development or even post- development testing. So basically, your question could be rephrased as "What are the benefits of Behavior Driven Development?" Here are a few places to look for more introductory material: http://behaviour-driven.org/Introduction http://en.wikipedia.org/wiki/Behavior_Driven_Development > 2. Which are the best tools than RSpec Many people use RSpec with Cucumber. In fact, the RSpec book (linked below) talks about how to use both of them for effective behavior driven development. It's important to remember that tools cannot be measured on an abstract, absolute scale. (i.e. There is no *best* tool because some tools were designed to do different things.) RSpec is often compared to Ruby's built-in unit testing framework (Test::Unit), and many people like the shoulda macros that work with either RSpec or Test::Unit. RSpec book: http://www.pragprog.com/titles/achbd/the-rspec-book Test::Unit: http://en.wikibooks.org/wiki/Ruby_Programming/Unit_testing Shoulda macros: http://github.com/thoughtbot/shoulda > 3. Where can i get RSpec demo There are several demos available online. Here's a demo that shows RSpec, Test::Unit, and Cucumber using Ruby on Rails: http://github.com/marcoow/rspec-demo There's also a lengthy introduction to RSpec available on PeepCode: http://peepcode.com/products/rspec-basics I hope that helps! > -- > Posted viahttp://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Sun Jan 31 12:13:53 2010 From: lists at ruby-forum.com (Ravi Shankar) Date: Sun, 31 Jan 2010 18:13:53 +0100 Subject: [rspec-users] What is difference between TDD & BDD In-Reply-To: <519191666db4f509513b1157cfc0f5e8@ruby-forum.com> References: <519191666db4f509513b1157cfc0f5e8@ruby-forum.com> Message-ID: What is the difference between test driven development & behavior driven development, which one is better. what are the options available in BDD. -- Posted via http://www.ruby-forum.com/. From ashley.moran at patchspace.co.uk Sun Jan 31 12:48:17 2010 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Sun, 31 Jan 2010 17:48:17 +0000 Subject: [rspec-users] What is difference between TDD & BDD In-Reply-To: References: <519191666db4f509513b1157cfc0f5e8@ruby-forum.com> Message-ID: <1DA05DD1-F715-4DC3-8A71-59E2A46E1C11@patchspace.co.uk> On Jan 31, 2010, at 5:13 pm, Ravi Shankar wrote: > What is the difference between test driven development & behavior driven > development, which one is better. The link to behaviour-driven.org that Tristam already posted[1] tells you exactly that. Did you read it? I'm having flashbacks to an older thread here :-/ > what are the options available in BDD. Your question is not clear. Can you be more specific? Ashley [1] http://behaviour-driven.org/Introduction -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashleymoran From cwdinfo at gmail.com Sun Jan 31 14:02:53 2010 From: cwdinfo at gmail.com (steve ross) Date: Sun, 31 Jan 2010 11:02:53 -0800 Subject: [rspec-users] What is difference between TDD & BDD In-Reply-To: References: <519191666db4f509513b1157cfc0f5e8@ruby-forum.com> Message-ID: <8CFE4A19-69CB-469A-8FBF-9B4FD60A6151@gmail.com> On Jan 31, 2010, at 9:13 AM, Ravi Shankar wrote: > > What is the difference between test driven development & behavior driven > development, which one is better. > > what are the options available in BDD. Make up a simple project like a blog that you can do in couple of hours. Try it using one, then the other technology. See which you like better. Your research will be the ultimate arbiter of which is better for you and your project. Nobody can tell you which will feel more natural to you. From dchelimsky at gmail.com Sun Jan 31 15:51:27 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 31 Jan 2010 14:51:27 -0600 Subject: [rspec-users] somewhat confused by the help instructions... In-Reply-To: <57c63afe1001300638h15cc15eai8c97d15634197ec3@mail.gmail.com> References: <2a39e8e4-72b7-4f37-9e1e-f358eebf5d3c@b2g2000yqi.googlegroups.com> <57c63afe1001292245o21772b63h843b7ea6d4b79d47@mail.gmail.com> <57c63afe1001300638h15cc15eai8c97d15634197ec3@mail.gmail.com> Message-ID: <57c63afe1001311251i67a56d6am8bf1c32d1604b833@mail.gmail.com> On Sat, Jan 30, 2010 at 8:38 AM, David Chelimsky wrote: > On Sat, Jan 30, 2010 at 7:31 AM, Matt Wynne wrote: >> >> On 30 Jan 2010, at 06:45, David Chelimsky wrote: >> >>> On Thu, Jan 28, 2010 at 12:54 PM, rogerdpack >>> wrote: >>>> >>>> As a note of feedback, when I do a spec --help, I saw this line... >>>> >>>> ? -e, --example [NAME|FILE_NAME] ? Execute example(s) with matching >>>> name(s). If the argument is >>>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?the path to an existing file >>>> (typically generated by a previous >>>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?run using --format >>>> failing_examples:file.txt), then the examples >>>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?on each line of that file will be >>>> executed. If the file is empty, >>>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?all examples will be run (as if -- >>>> example was not specified). >>>> >>>> so I, trying to be clever, passed it something to match: >>>> >>>> E:\dev\ruby\spork>spec spec/spork/run_strategy/single* -e"the result" >>>> >>>> >>>> Finished in 0.125 seconds >>>> >>>> 0 examples, 0 failures >>>> >>>> >>>> Passing it the full test name seems to work, however: >>>> >>>> E:\dev\ruby\spork>spec spec/spork/run_strategy/single* -e"returns the >>>> result of the run_tests method from the forked child" >>>> ... >>>> >>>> Finished in 0.34375 seconds >>>> >>>> 3 examples, 0 failures >>>> >>>> >>>> Suggestion: >>>> >>>> rephrase the help as "runs the test whose name equals the one >>>> specified" (instead of using the word "matches" which to me somehow >>>> meant "regex"), or >>>> >>>> change the matching to be regex matching (this one is what I would >>>> personally prefer--then you don't have to put full test names on the >>>> command line). >>>> >>>> Thoughts? >>> >>> Actually, I'm thinking of not supporting this in rspec-2. I personally >>> find the line number much more useful, since you can just copy it >>> directly from the failure messages to re-run something: >>> >>> spec path/to/spec.rb:37 >> >> This is great except when you use macros or other tricks to generate >> examples - then there isn't a 1:1: mapping from line number to example. I >> often find it quite annoying to have to quote the whole example description, >> so I actually quite like Roger's idea about using regexp matching. > > Excellent news for you both. It turns out that the underlying > machinery is already in place for this in rspec2's new runner. Just > need to hook it to the command line. But right now, in > rspec-core-2.0.0.a2, you can say this in any Ruby that gets loaded > (like spec_helper.rb): > > Rspec::Core.configure do |c| > ?c.filter_run :description => /should match this string/ > end > > Hooking that from the CLI will be pretty simple, so coming soon. Done: http://github.com/rspec/rspec-core/blob/master/features/command_line/example_name_option.feature > > Cheers, > David > >> >>> WDYT? >>> >>>> -r >>>> >>>> _______________________________________________ >>>> 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 >> >> cheers, >> Matt >> >> http://mattwynne.net >> +447974 430184 >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > From phillipkoebbe at gmail.com Sun Jan 31 16:55:45 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Sun, 31 Jan 2010 15:55:45 -0600 Subject: [rspec-users] somewhat confused by the help instructions... In-Reply-To: <57c63afe1001311251i67a56d6am8bf1c32d1604b833@mail.gmail.com> References: <2a39e8e4-72b7-4f37-9e1e-f358eebf5d3c@b2g2000yqi.googlegroups.com> <57c63afe1001292245o21772b63h843b7ea6d4b79d47@mail.gmail.com> <57c63afe1001300638h15cc15eai8c97d15634197ec3@mail.gmail.com> <57c63afe1001311251i67a56d6am8bf1c32d1604b833@mail.gmail.com> Message-ID: <4B65FC61.6080209@gmail.com> David Chelimsky wrote: > Done: > http://github.com/rspec/rspec-core/blob/master/features/command_line/example_name_option.feature > > Cool stuff! Does that match the describe groups as well? I would like to be able to run all of the examples in either "first group" or "second group". Will it match? Phillip From lists at ruby-forum.com Sun Jan 31 17:02:05 2010 From: lists at ruby-forum.com (Nick Hoffman) Date: Sun, 31 Jan 2010 23:02:05 +0100 Subject: [rspec-users] GET a path in a controller spec Message-ID: One of my controller actions sends a redirect if the request URI begins with /foods/search 34 def search 35 return redirect_to "/#{params[:name]}" if request.request_uri.match /^\/foods\/search/ Unfortunately, I can't figure out how to spec this. >From everything that I've read while researching this problem, it seems that #get and #post only accept the action to call, and a hash of parameters. IE: get :action, :some => 'param' As a result, I can't do this: 121 it 'redirects /foods/search/almonds to /almonds' do 122 get '/foods/search/almonds' 123 response.should redirect_to "/almonds" 124 end How can I spec this? Thanks for your help, Nick -- Posted via http://www.ruby-forum.com/. From rick.denatale at gmail.com Sun Jan 31 17:21:57 2010 From: rick.denatale at gmail.com (Rick DeNatale) Date: Sun, 31 Jan 2010 17:21:57 -0500 Subject: [rspec-users] somewhat confused by the help instructions... In-Reply-To: <4B65FC61.6080209@gmail.com> References: <2a39e8e4-72b7-4f37-9e1e-f358eebf5d3c@b2g2000yqi.googlegroups.com> <57c63afe1001292245o21772b63h843b7ea6d4b79d47@mail.gmail.com> <57c63afe1001300638h15cc15eai8c97d15634197ec3@mail.gmail.com> <57c63afe1001311251i67a56d6am8bf1c32d1604b833@mail.gmail.com> <4B65FC61.6080209@gmail.com> Message-ID: On Sun, Jan 31, 2010 at 4:55 PM, Phillip Koebbe wrote: > > > David Chelimsky wrote: >> >> Done: >> >> http://github.com/rspec/rspec-core/blob/master/features/command_line/example_name_option.feature >> >> > > Cool stuff! > > Does that match the describe groups as well? I would like to be able to run > all of the examples in either "first group" or "second group". Will it > match? Also, does anyone but me find the expectation in the case where there's no match surprising? -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale From dchelimsky at gmail.com Sun Jan 31 17:58:26 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 31 Jan 2010 16:58:26 -0600 Subject: [rspec-users] somewhat confused by the help instructions... In-Reply-To: <4B65FC61.6080209@gmail.com> References: <2a39e8e4-72b7-4f37-9e1e-f358eebf5d3c@b2g2000yqi.googlegroups.com> <57c63afe1001292245o21772b63h843b7ea6d4b79d47@mail.gmail.com> <57c63afe1001300638h15cc15eai8c97d15634197ec3@mail.gmail.com> <57c63afe1001311251i67a56d6am8bf1c32d1604b833@mail.gmail.com> <4B65FC61.6080209@gmail.com> Message-ID: <57c63afe1001311458w11673dcave38d1eac92da5aab@mail.gmail.com> On Sun, Jan 31, 2010 at 3:55 PM, Phillip Koebbe wrote: > David Chelimsky wrote: >> >> Done: >> >> http://github.com/rspec/rspec-core/blob/master/features/command_line/example_name_option.feature > > Cool stuff! > > Does that match the describe groups as well? I would like to be able to run > all of the examples in either "first group" or "second group". Will it > match? Yes. I added some narrative text to explain: http://github.com/rspec/rspec-core/blob/master/features/command_line/example_name_option.feature From phillipkoebbe at gmail.com Sun Jan 31 18:28:36 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Sun, 31 Jan 2010 17:28:36 -0600 Subject: [rspec-users] somewhat confused by the help instructions... In-Reply-To: References: <2a39e8e4-72b7-4f37-9e1e-f358eebf5d3c@b2g2000yqi.googlegroups.com> <57c63afe1001292245o21772b63h843b7ea6d4b79d47@mail.gmail.com> <57c63afe1001300638h15cc15eai8c97d15634197ec3@mail.gmail.com> <57c63afe1001311251i67a56d6am8bf1c32d1604b833@mail.gmail.com> <4B65FC61.6080209@gmail.com> Message-ID: <4B661224.6060002@gmail.com> Rick DeNatale wrote: > On Sun, Jan 31, 2010 at 4:55 PM, Phillip Koebbe wrote: > >> David Chelimsky wrote: >> >>> Done: >>> >>> http://github.com/rspec/rspec-core/blob/master/features/command_line/example_name_option.feature >>> >>> >>> >> Cool stuff! >> >> Does that match the describe groups as well? I would like to be able to run >> all of the examples in either "first group" or "second group". Will it >> match? >> > > Also, does anyone but me find the expectation in the case where > there's no match surprising? > > I thought about that, as well. I would expect nothing to be done if no match was found. Consider the case of misspelling the example or group and having the whole shebang run instead of nothing. Peace, Phillip From dchelimsky at gmail.com Sun Jan 31 21:08:23 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 31 Jan 2010 20:08:23 -0600 Subject: [rspec-users] somewhat confused by the help instructions... In-Reply-To: <4B661224.6060002@gmail.com> References: <2a39e8e4-72b7-4f37-9e1e-f358eebf5d3c@b2g2000yqi.googlegroups.com> <57c63afe1001292245o21772b63h843b7ea6d4b79d47@mail.gmail.com> <57c63afe1001300638h15cc15eai8c97d15634197ec3@mail.gmail.com> <57c63afe1001311251i67a56d6am8bf1c32d1604b833@mail.gmail.com> <4B65FC61.6080209@gmail.com> <4B661224.6060002@gmail.com> Message-ID: <57c63afe1001311808x7086cfefr3b1abe569a7150cf@mail.gmail.com> On Sun, Jan 31, 2010 at 5:28 PM, Phillip Koebbe wrote: > > Rick DeNatale wrote: >> >> On Sun, Jan 31, 2010 at 4:55 PM, Phillip Koebbe >> ?wrote: >> >>> >>> David Chelimsky wrote: >>> >>>> >>>> Done: >>>> >>>> >>>> http://github.com/rspec/rspec-core/blob/master/features/command_line/example_name_option.feature >>>> >>>> >>>> >>> >>> Cool stuff! >>> >>> Does that match the describe groups as well? I would like to be able to >>> run >>> all of the examples in either "first group" or "second group". Will it >>> match? >>> >> >> Also, does anyone but me find the expectation in the case where >> there's no match surprising? >> >> > > I thought about that, as well. I would expect nothing to be done if no match > was found. Consider the case of misspelling the example or group and having > the whole shebang run instead of nothing. Agreed: http://github.com/rspec/rspec-core/blob/master/features/command_line/example_name_option.feature > > Peace, > Phillip