From lenny at aps.org Tue Dec 1 11:46:07 2009 From: lenny at aps.org (Lenny Marks) Date: Tue, 1 Dec 2009 11:46:07 -0500 Subject: [rspec-users] should_receive(:x).at_most/exactly... ignored when method is previously stubbed? Message-ID: <1A7C99E5-1F83-4F88-81A1-80FF1AE5FA6B@aps.org> I've always used the idiom of stub collaborations in a before block and then focus in specific examples with should_receive. (e.g. should_receive takes presence over stub). I was just attempting to write an example for caching behavior and ran into something counter- intuitive, at least IMHO. See the following(contrived) example. class ExpensiveOperation def self.lookup(question) "This goes to the database" end end class UsesExpensiveOperation def initialize @cache = {} end def answer_for(question) # oops, this is broken, it was supposed to be cached # @cache[question] ||= ExpensiveOperation.lookup(question) @cache[question] = ExpensiveOperation.lookup(question) end end describe "suprising behavior" do before do @object = UsesExpensiveOperation.new ExpensiveOperation.stub(:lookup).and_return('whatever') end it "should fail because I'm specifying that lookup should be called at most one time, but that's not true" do ExpensiveOperation .should_receive(:lookup).at_most(:once).and_return('an answer') @object.answer_for("my question") @object.answer_for("my question") end end This seems dangerous to me. Assuming I hadn't initially stubbed in the before block and everything worked as expected, if someone later stubs :lookup in the before block because they are adding new examples that don't care about it, my explicit example becomes misleadingly useless. Does this surprise anyone else? -lenny From lenny at aps.org Tue Dec 1 12:39:25 2009 From: lenny at aps.org (Lenny Marks) Date: Tue, 1 Dec 2009 12:39:25 -0500 Subject: [rspec-users] should_receive(:x).at_most/exactly... ignored when method is previously stubbed? In-Reply-To: <1A7C99E5-1F83-4F88-81A1-80FF1AE5FA6B@aps.org> References: <1A7C99E5-1F83-4F88-81A1-80FF1AE5FA6B@aps.org> Message-ID: <732163EF-8993-4FF1-9E6A-0B8A05C10FEF@aps.org> Forgot to mention: rspec 1.2.9 On Dec 1, 2009, at 11:46 AM, Lenny Marks wrote: > I've always used the idiom of stub collaborations in a before block > and then focus in specific examples with should_receive. (e.g. > should_receive takes presence over stub). I was just attempting to > write an example for caching behavior and ran into something counter- > intuitive, at least IMHO. See the following(contrived) example. > > class ExpensiveOperation > def self.lookup(question) > "This goes to the database" > end > end > > class UsesExpensiveOperation > def initialize > @cache = {} > end > > def answer_for(question) > # oops, this is broken, it was supposed to be cached > # @cache[question] ||= ExpensiveOperation.lookup(question) > @cache[question] = ExpensiveOperation.lookup(question) > end > end > > describe "suprising behavior" do > before do > @object = UsesExpensiveOperation.new > > ExpensiveOperation.stub(:lookup).and_return('whatever') > end > > it "should fail because I'm specifying that lookup should be > called at most one time, but that's not true" do > > ExpensiveOperation > .should_receive(:lookup).at_most(:once).and_return('an answer') > > @object.answer_for("my question") > @object.answer_for("my question") > end > > end > > This seems dangerous to me. Assuming I hadn't initially stubbed in > the before block and everything worked as expected, if someone later > stubs :lookup in the before block because they are adding new > examples that don't care about it, my explicit example becomes > misleadingly useless. > > Does this surprise anyone else? > > -lenny > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ashley.moran at patchspace.co.uk Tue Dec 1 13:24:17 2009 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Tue, 1 Dec 2009 18:24:17 +0000 Subject: [rspec-users] should_receive(:x).at_most/exactly... ignored when method is previously stubbed? In-Reply-To: <1A7C99E5-1F83-4F88-81A1-80FF1AE5FA6B@aps.org> References: <1A7C99E5-1F83-4F88-81A1-80FF1AE5FA6B@aps.org> Message-ID: <9D189F8B-44E4-445F-A36B-2AD6A6286458@patchspace.co.uk> On Dec 01, 2009, at 4:46 pm, Lenny Marks wrote: > This seems dangerous to me. Assuming I hadn't initially stubbed in the before block and everything worked as expected, if someone later stubs :lookup in the before block because they are adding new examples that don't care about it, my explicit example becomes misleadingly useless. > > Does this surprise anyone else? Hi Lenny Yes it does, so much so that I filed a ticket[1] :) Well, I think it's the same issue. If so, maybe you'll find the discussion between me and David useful. HTH Ashley [1] https://rspec.lighthouseapp.com/projects/5645/tickets/618-exactlyntimes-incorrectly-failing-for-n-actual -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashleymoran From lenny at aps.org Tue Dec 1 14:34:57 2009 From: lenny at aps.org (Lenny Marks) Date: Tue, 1 Dec 2009 14:34:57 -0500 Subject: [rspec-users] should_receive(:x).at_most/exactly... ignored when method is previously stubbed? In-Reply-To: <9D189F8B-44E4-445F-A36B-2AD6A6286458@patchspace.co.uk> References: <1A7C99E5-1F83-4F88-81A1-80FF1AE5FA6B@aps.org> <9D189F8B-44E4-445F-A36B-2AD6A6286458@patchspace.co.uk> Message-ID: On Dec 1, 2009, at 1:24 PM, Ashley Moran wrote: > > On Dec 01, 2009, at 4:46 pm, Lenny Marks wrote: > >> This seems dangerous to me. Assuming I hadn't initially stubbed in >> the before block and everything worked as expected, if someone >> later stubs :lookup in the before block because they are adding new >> examples that don't care about it, my explicit example becomes >> misleadingly useless. >> >> Does this surprise anyone else? > > Hi Lenny > > Yes it does, so much so that I filed a ticket[1] :) > > Well, I think it's the same issue. If so, maybe you'll find the > discussion between me and David useful. > > HTH > > Ashley > > [1] https://rspec.lighthouseapp.com/projects/5645/tickets/618-exactlyntimes-incorrectly-failing-for-n-actual > Thanks Ashley. I added my 2 cents to the ticket. -lenny From ashley.moran at patchspace.co.uk Tue Dec 1 14:49:20 2009 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Tue, 1 Dec 2009 19:49:20 +0000 Subject: [rspec-users] should_receive(:x).at_most/exactly... ignored when method is previously stubbed? In-Reply-To: References: <1A7C99E5-1F83-4F88-81A1-80FF1AE5FA6B@aps.org> <9D189F8B-44E4-445F-A36B-2AD6A6286458@patchspace.co.uk> Message-ID: <4D9E32DF-A1C4-48F6-B551-B4464CC4925E@patchspace.co.uk> On Dec 01, 2009, at 7:34 pm, Lenny Marks wrote: > Thanks Ashley. I added my 2 cents to the ticket. Just had a look over your comments. It's a complicated issue... I hope David can reconcile it. I'm not sure what the best solution is. Ashley -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashleymoran From lists at ruby-forum.com Tue Dec 1 16:32:18 2009 From: lists at ruby-forum.com (Jon Pincus) Date: Tue, 1 Dec 2009 22:32:18 +0100 Subject: [rspec-users] Introductory recommendations? In-Reply-To: References: <2c7e61990911251007j12d4b652u5b5540327fa6c74e@mail.gmail.com> Message-ID: Thanks all for the feedback, excellent suggestions! -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Wed Dec 2 10:06:15 2009 From: lists at ruby-forum.com (P. A.) Date: Wed, 2 Dec 2009 16:06:15 +0100 Subject: [rspec-users] Color output in pagers Message-ID: Hi. Is it possible to get color text in less, more or other pagers while piping the color output of Cucumber and RSpec? If it's not possible is there any other methods to work with the color text in a console without permanent ?rewinding? the output back to the beginning? Thanks. -- Posted via http://www.ruby-forum.com/. From paul.t.hinze at gmail.com Wed Dec 2 10:40:15 2009 From: paul.t.hinze at gmail.com (Paul Hinze) Date: Wed, 2 Dec 2009 09:40:15 -0600 Subject: [rspec-users] Color output in pagers In-Reply-To: References: Message-ID: <20091202154015.GA4432@vpr1000> P. A. on 2009-12-02 at 09:08: > Is it possible to get color text in less, more or other pagers while > piping the color output of Cucumber and RSpec? Have a look at these options for `less`: >From LESS(1) man page: > -r or --raw-control-chars > > Causes "raw" control characters to be displayed. The default is to > display control characters using the caret notation; for example, a > control-A (octal 001) is displayed as "^A". Warning: when the -r > option is used, less cannot keep track of the actual appearance of > the screen (since this depends on how the screen responds to each > type of control character). Thus, various display problems may > result, such as long lines being split in the wrong place. > > -R or --RAW-CONTROL-CHARS > > Like -r, but only ANSI "color" escape sequences are output in > "raw" form. Unlike -r, the screen appearance is maintained correctly > in most cases. You can set default options for less to use via the LESS evironment variable. As an example, here is the value of mine: $ echo $LESS -X -e -R Cheers, Paul From lists at ruby-forum.com Wed Dec 2 11:12:21 2009 From: lists at ruby-forum.com (P. A.) Date: Wed, 2 Dec 2009 17:12:21 +0100 Subject: [rspec-users] Color output in pagers In-Reply-To: <20091202154015.GA4432@vpr1000> References: <20091202154015.GA4432@vpr1000> Message-ID: I've known about the -R option but it doesn't work for me. $ cucumber #=> color output $ cucumber | less -R #=> monochrome $ spec -c #=> color output $ spec -c | less -R #=> monochrome but $ ls --color=always | less -R #=> color output It seems that your system has addition preferences that enables you to pipe the color tags in output to less. Could you tell me how did you achive it? -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Wed Dec 2 15:16:03 2009 From: lists at ruby-forum.com (P. A.) Date: Wed, 2 Dec 2009 21:16:03 +0100 Subject: [rspec-users] Color output in pagers In-Reply-To: References: <20091202154015.GA4432@vpr1000> Message-ID: <612b0328f4254705b1b673f3d97b9e62@ruby-forum.com> I solve it by myself. To enable piping color output in Cucumber it needs to run the cucumber command with the -c option. $ cucumber -c | less #=> color output To enable piping color output in RSpec it needs to set the RSPEC_COLOR environment variable to true. $ export RSPEC_COLOR=true $ spec path/to/spec | less #=> color output However, if RSPEC_COLOR is set to true the output to a file will include color tags. To prevent it, it needs to unset RSPEC_COLOR. $ unset RSPEC_COLOR $ spec path/to/spec > file #=> no color tags Cheers! -- Posted via http://www.ruby-forum.com/. From paul.t.hinze at gmail.com Wed Dec 2 15:38:13 2009 From: paul.t.hinze at gmail.com (Paul Hinze) Date: Wed, 2 Dec 2009 14:38:13 -0600 Subject: [rspec-users] Color output in pagers In-Reply-To: References: <20091202154015.GA4432@vpr1000> Message-ID: <20091202203813.GC4432@vpr1000> P. A. on 2009-12-02 at 10:13: > $ cucumber #=> color output > $ cucumber | less -R #=> monochrome Ah now I see what you're saying. We're getting burned by this line: http://github.com/aslakhellesoy/cucumber/blob/master/lib/cucumber/formatter/ansicolor.rb#L20 > Term::ANSIColor.coloring = false if !STDOUT.tty? and not ENV.has_key?("AUTOTEST") So, we can either feature request an override variable for this line, or perhaps there is a way to trick a program that STDOUT is actually a tty...? Paul From itsterry at gmail.com Wed Dec 2 08:40:47 2009 From: itsterry at gmail.com (itsterry) Date: Wed, 2 Dec 2009 05:40:47 -0800 (PST) Subject: [rspec-users] HTML array problem Message-ID: <0440d3eb-2d37-4a3e-ab91-a6d4f0b3584f@f16g2000yqm.googlegroups.com> Hi all. Apologies if this is an easy one, but I've spent a while Googling and trying trial-and-error, and can't find the solution. I'm trying to spec a controller. It accepts an HTML array, then processes items matching the id param. So I'm passing (in meta form) controller/action/id?thing[thing_id]=value The controller looks at the id, finds the ActiveRecord object which matches id, then looks for the thing with a thing_id matching id and processes it The real example is a little involved, but a simpler example would be something like comments/rate/4?score[4]=10&score[5]=9 so that comment 4 is rated 10, and comment 5 is untouched In my controller spec I've been trying (for the above easy example) post 'comments/rate', :id=>4, :score=>{4=>10} but my params array doesn't appear to be going through the test This doesn't do it: post 'comments/rate', :id=>4, :score[4]=>10 Nor this: post 'comments/rate', :id=>4, :score['4']=>10 Nor this: post 'comments/rate', :id=>4, "score[4]".to_sym=>10 Any ideas? Have I given enough info? Trying to give relevant details without too much extraneous info. Thanks in advance for any help! From daniel.varrin at gmail.com Thu Dec 3 04:01:07 2009 From: daniel.varrin at gmail.com (Daniel Varrin) Date: Thu, 3 Dec 2009 10:01:07 +0100 Subject: [rspec-users] Rspec - Creation of stories Message-ID: <9b445ef00912030101l474821c0uab3623624285700c@mail.gmail.com> Hi, I'm new to RSpec and installed the version 1.2.9. I was trying to write some of the stories' examples on the web, but I was not able to let one run. The RDoc contains many examples, but should we write them in a .rb file as is or do we have to copy only the scenario part or what ever? There is a whole folder of examples with version 1.2.9, but none of them is an example about how to create a story or scenario. Am I missing an other lib for stories? I hope you can help me. Best regards, Daniel Varrin -------------- next part -------------- An HTML attachment was scrubbed... URL: From rick.denatale at gmail.com Thu Dec 3 08:04:06 2009 From: rick.denatale at gmail.com (Rick DeNatale) Date: Thu, 3 Dec 2009 08:04:06 -0500 Subject: [rspec-users] Rspec - Creation of stories In-Reply-To: <9b445ef00912030101l474821c0uab3623624285700c@mail.gmail.com> References: <9b445ef00912030101l474821c0uab3623624285700c@mail.gmail.com> Message-ID: On Thu, Dec 3, 2009 at 4:01 AM, Daniel Varrin wrote: > Hi, > > I'm new to RSpec and installed the version 1.2.9. I was trying to write some > of the stories' examples on the web, but I was not able to let one run. The > RDoc contains many examples, but should we write them in a .rb file as is or > do we have to copy only the scenario part or what ever? > > There is a whole folder of examples with version 1.2.9, but none of them is > an example about how to create a story or scenario. Am I missing an other > lib for stories? RSpec is for specifying lower level specifications. For stories/scenarios you are probably looking for Cucumber, which is a separate project which fits together with RSpec like a hand and glove. The best way to use them, in my opinion, is in the style of outside in development, in which you write cucumber features (a collection of scenarios) to drive out what needs to be implemented, then use RSpec to do behaviour driven development on those pieces and get the features to successfully run, then go back and define more features, rinse and repeat. There are many blog articles about this, but the best way to understand it is probably via the RSpec book which is currently under development and covers both RSpec and Cucumber. Although it's pre-production, it's available under the Pragmatic Programmers beta program. http://pragprog.com/titles/achbd/the-rspec-book -- 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 Dec 3 10:50:35 2009 From: rogerpack2005 at gmail.com (rogerdpack) Date: Thu, 3 Dec 2009 07:50:35 -0800 (PST) Subject: [rspec-users] surprising... In-Reply-To: <57c63afe0911290553r24236678me64827698d21011d@mail.gmail.com> References: <69c47f23-5014-423b-b263-ca162c4447a0@m38g2000yqd.googlegroups.com> <57c63afe0911290553r24236678me64827698d21011d@mail.gmail.com> Message-ID: <5d2c0b11-af5d-42de-815e-2db90cca3b29@p35g2000yqh.googlegroups.com> > You're about 4 years late to the party. We were playing around with a > variety of options back in 2005 and went with the current syntax because it > gave us the most flexibility and the highest level of decoupling, making it > easier for others to create their own matcher libraries. While it would be > technically feasible to support should.matcher, doing so now would cause > more confusion for more people than be helpful, IMO. I guess the confusion comes from being able to do a.should == 'b' a.should.== 'b' but not anything like a.should.equal('b') == appears to be special cased? But I'm sure I'll get used to it. Thanks for the replies. -r From cflipse at gmail.com Thu Dec 3 11:35:59 2009 From: cflipse at gmail.com (Chris Flipse) Date: Thu, 3 Dec 2009 11:35:59 -0500 Subject: [rspec-users] HTML array problem In-Reply-To: <0440d3eb-2d37-4a3e-ab91-a6d4f0b3584f@f16g2000yqm.googlegroups.com> References: <0440d3eb-2d37-4a3e-ab91-a6d4f0b3584f@f16g2000yqm.googlegroups.com> Message-ID: Your first attempt is the correct way to go about it post 'comments/rate', :id=>4, :score=>{4=>10} However, note that in your controller, the parameters are stringified / symbolized. params["score"]["4"] will get you 10, but params["score"][4] will get you nil On Wed, Dec 2, 2009 at 8:40 AM, itsterry wrote: > Hi all. Apologies if this is an easy one, but I've spent a while > Googling and trying trial-and-error, and can't find the solution. > > I'm trying to spec a controller. > > It accepts an HTML array, then processes items matching the id param. > > So I'm passing (in meta form) > > controller/action/id?thing[thing_id]=value > > The controller looks at the id, finds the ActiveRecord object which > matches id, then looks for the thing with a thing_id matching id and > processes it > > The real example is a little involved, but a simpler example would be > something like > > comments/rate/4?score[4]=10&score[5]=9 > > so that comment 4 is rated 10, and comment 5 is untouched > > In my controller spec I've been trying (for the above easy example) > > post 'comments/rate', :id=>4, :score=>{4=>10} > > but my params array doesn't appear to be going through the test > > This doesn't do it: > post 'comments/rate', :id=>4, :score[4]=>10 > > Nor this: > post 'comments/rate', :id=>4, :score['4']=>10 > > Nor this: > post 'comments/rate', :id=>4, "score[4]".to_sym=>10 > > Any ideas? Have I given enough info? Trying to give relevant details > without too much extraneous info. > > Thanks in advance for any help! > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- // anything worth taking seriously is worth making fun of // http://blog.devcaffeine.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From brandon.goodin at gmail.com Thu Dec 3 12:09:24 2009 From: brandon.goodin at gmail.com (Brandon Goodin) Date: Thu, 3 Dec 2009 11:09:24 -0600 Subject: [rspec-users] form_for problem Message-ID: <2fe5ef5b0912030909w5055fc57o95c3bc80e2b67313@mail.gmail.com> Greetings All, I have an interesting issue that I can only assume is me doing something dumb. ====== I have the following route defined ====== map.namespace(:admin) do |admin| admin.resources :users end ====== I have a form: ====== - form_for @user, :url=>admin_user_path do |f| ====== and an rspec ====== require 'spec_helper' describe "/admin/users/edit.html.haml" do it "renders edit admin user form" do @user = mock_model(User)#Factory.create(:valid_user) assigns[:user] = @user render end end ====== it produces the following error when ran ====== ActionView::TemplateError: admin_user_url failed to generate from {:action=>"show", :controller=>"admin/users"} - you may have ambiguous routes, or you may need to supply additional parameters for this route. content_url has the following required parameters: ["admin", "users", :id] - are they all satisfied? On line #1 of app/views/admin/users/edit.html.haml 1: - form_for @user, :url=>admin_user_path do |f| 2: %p (eval):16:in `admin_user_path' ======== This form works when I fire up WEBrick and navigate to it manually.

======== What am I doing wrong? Brandon -------------- next part -------------- An HTML attachment was scrubbed... URL: From brandon.goodin at gmail.com Thu Dec 3 16:01:24 2009 From: brandon.goodin at gmail.com (Brandon Goodin) Date: Thu, 3 Dec 2009 15:01:24 -0600 Subject: [rspec-users] form_for problem In-Reply-To: <2fe5ef5b0912030909w5055fc57o95c3bc80e2b67313@mail.gmail.com> References: <2fe5ef5b0912030909w5055fc57o95c3bc80e2b67313@mail.gmail.com> Message-ID: <2fe5ef5b0912031301q34efeba9w7bc4f934c940938b@mail.gmail.com> Okay I figured out my error. I needed to specify my form_for like: - form_for [:admin, @user] do |f| This is obviously cleaner. It is strange that a running rails app would accept this while rspec rendered view would not. Anyway, I'm glad that rspec didn't accept this since the way i'm using it now is cleaner. Thanks, Brandon On Thu, Dec 3, 2009 at 11:09 AM, Brandon Goodin wrote: > Greetings All, > > I have an interesting issue that I can only assume is me doing something > dumb. > > ====== > I have the following route defined > ====== > > map.namespace(:admin) do |admin| > admin.resources :users > end > > ====== > I have a form: > ====== > > - form_for @user, :url=>admin_user_path do |f| > > ====== > and an rspec > ====== > > require 'spec_helper' > > describe "/admin/users/edit.html.haml" do > > it "renders edit admin user form" do > @user = mock_model(User)#Factory.create(:valid_user) > assigns[:user] = @user > render > end > end > > ====== > it produces the following error when ran > ====== > > ActionView::TemplateError: admin_user_url failed to generate from > {:action=>"show", :controller=>"admin/users"} - you may have ambiguous > routes, or you may need to supply additional parameters for this route. > content_url has the following required parameters: ["admin", "users", :id] > - are they all satisfied? > On line #1 of app/views/admin/users/edit.html.haml > > 1: - form_for @user, :url=>admin_user_path do |f| > 2: %p > > (eval):16:in `admin_user_path' > > ======== > > This form works when I fire up WEBrick and navigate to it manually. > >
method="post"> >
type="hidden" value="put" /> > value="lnRnobSwBwf8lQcPzqE/uxndBzCaSey89ebEe9djFEU=" /> >
>

>
> > ======== > > What am I doing wrong? > > Brandon -------------- next part -------------- An HTML attachment was scrubbed... URL: From itsterry at gmail.com Fri Dec 4 04:42:58 2009 From: itsterry at gmail.com (itsterry) Date: Fri, 4 Dec 2009 01:42:58 -0800 (PST) Subject: [rspec-users] HTML array problem In-Reply-To: References: <0440d3eb-2d37-4a3e-ab91-a6d4f0b3584f@f16g2000yqm.googlegroups.com> Message-ID: <185c2186-e358-437a-98cd-cacba4b4ca08@m25g2000yqc.googlegroups.com> Aha! That explains it. Thank you ! On Dec 3, 4:35?pm, Chris Flipse wrote: > Your first attempt is the correct way to go about it > ? ?post 'comments/rate', :id=>4, :score=>{4=>10} > > However, note that in your controller, the parameters are stringified / > symbolized. > params["score"]["4"] ?will get you 10, but params["score"][4] will get you > nil > > > > On Wed, Dec 2, 2009 at 8:40 AM, itsterry wrote: > > Hi all. Apologies if this is an easy one, but I've spent a while > > Googling and trying trial-and-error, and can't find the solution. > > > I'm trying to spec a controller. > > > It accepts an HTML array, then processes items matching the id param. > > > So I'm passing (in meta form) > > > controller/action/id?thing[thing_id]=value > > > The controller looks at the id, finds the ActiveRecord object which > > matches id, then looks for the thing with a thing_id matching id and > > processes it > > > The real example is a little involved, but a simpler example would be > > something like > > > comments/rate/4?score[4]=10&score[5]=9 > > > so that comment 4 is rated 10, and comment 5 is untouched > > > In my controller spec I've been trying (for the above easy example) > > > post 'comments/rate', :id=>4, :score=>{4=>10} > > > but my params array doesn't appear to be going through the test > > > This doesn't do it: > > post 'comments/rate', :id=>4, :score[4]=>10 > > > Nor this: > > post 'comments/rate', :id=>4, :score['4']=>10 > > > Nor this: > > post 'comments/rate', :id=>4, "score[4]".to_sym=>10 > > > Any ideas? Have I given enough info? Trying to give relevant details > > without too much extraneous info. > > > Thanks in advance for any help! > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > -- > // anything worth taking seriously is worth making fun of > //http://blog.devcaffeine.com/ > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From andy.koch at pc-doctor.com Fri Dec 4 15:35:46 2009 From: andy.koch at pc-doctor.com (Andy Koch) Date: Fri, 4 Dec 2009 12:35:46 -0800 (PST) Subject: [rspec-users] [rspec-rails] spec vs. autospec Message-ID: <76038964-b51e-4219-997f-99998d8f0c88@g22g2000prf.googlegroups.com> Hi All, any reason why some tests might pass via spec ... and fail from within autospec? I have a rails app using AuthLogic and Declarative Authorization. I have tests that create user_sessions and assign roles against which CRUD rules are tested. This has bee working just fine. But this morning I updated the Declarative Auth gem and suddenly started seeing failing tests. I immediately blamed DA, or really my usage of it. But then I started running the spec files individually via "spec ..." commands and everything started passing - which was actually more disturbing for me. so now I wonder what autospec might be doing that is different from straight "spec ..." commands? when I run "rake spec" they fail just like in autospec - there's some comforting consistency, failing tests notwithstanding. thanks for any insights From apremdas at gmail.com Sat Dec 5 05:11:26 2009 From: apremdas at gmail.com (Andrew Premdas) Date: Sat, 5 Dec 2009 10:11:26 +0000 Subject: [rspec-users] [rspec-rails] spec vs. autospec In-Reply-To: <76038964-b51e-4219-997f-99998d8f0c88@g22g2000prf.googlegroups.com> References: <76038964-b51e-4219-997f-99998d8f0c88@g22g2000prf.googlegroups.com> Message-ID: <88fd8ddc0912050211t33c3fdf3n5a38f4c1a644456a@mail.gmail.com> 2009/12/4 Andy Koch > Hi All, > > any reason why some tests might pass via spec ... and fail from within > autospec? > > I have a rails app using AuthLogic and Declarative Authorization. I > have tests that create user_sessions and assign roles against which > CRUD rules are tested. > > This has bee working just fine. > > But this morning I updated the Declarative Auth gem and suddenly > started seeing failing tests. I immediately blamed DA, or really my > usage of it. But then I started running the spec files individually > via "spec ..." commands and everything started passing - which was > actually more disturbing for me. > > so now I wonder what autospec might be doing that is different from > straight "spec ..." commands? > > when I run "rake spec" they fail just like in autospec - there's some > comforting consistency, failing tests notwithstanding. > > thanks for any insights > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > Generally this indicates a problem with one spec interfering with another. Run separately the specs run fine, because the state is completely reset between each run. However run together (and this can be order dependent, just to add to the confusion) and they break. Debugging this can be quite tricky, monitoring the test database, and the test.log should help. However generally I find that you just have to pay real close attention to any specs that create any sort of permanent artifact, and any specs that rely on there being a certain number of artifacts e.g. the first role. All best Andrew -------------- next part -------------- An HTML attachment was scrubbed... URL: From andy.koch at pc-doctor.com Sat Dec 5 09:31:32 2009 From: andy.koch at pc-doctor.com (Andy Koch) Date: Sat, 5 Dec 2009 06:31:32 -0800 (PST) Subject: [rspec-users] [rspec-rails] spec vs. autospec In-Reply-To: <88fd8ddc0912050211t33c3fdf3n5a38f4c1a644456a@mail.gmail.com> References: <76038964-b51e-4219-997f-99998d8f0c88@g22g2000prf.googlegroups.com> <88fd8ddc0912050211t33c3fdf3n5a38f4c1a644456a@mail.gmail.com> Message-ID: Thanks Andrew, That was the right hint. I took the autospec command list of all specs and ran them in smaller groups - which led to discovering a Declarative Auth config switch that was heretofore isolated. Apparently in the new version of this gem it does not get reset between tests. Once I removed those WMD's of auth control all my tests returned to normal. Another lesson learned, muchas gracias. regards, Andy On Dec 5, 2:11?am, Andrew Premdas wrote: > 2009/12/4 Andy Koch > > > > > Hi All, > > > any reason why some tests might pass via spec ... and fail from within > > autospec? > > > I have a rails app using AuthLogic and Declarative Authorization. ?I > > have tests that create user_sessions and assign roles against which > > CRUD rules are tested. > > > This has bee working just fine. > > > But this morning I updated the Declarative Auth gem and suddenly > > started seeing failing tests. ?I immediately blamed DA, or really my > > usage of it. ?But then I started running the spec files individually > > via "spec ..." commands and everything started passing - which was > > actually more disturbing for me. > > > so now I wonder what autospec might be doing that is different from > > straight "spec ..." commands? > > > when I run "rake spec" they fail just like in autospec - there's some > > comforting consistency, failing tests notwithstanding. > > > thanks for any insights > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > Generally this indicates a problem with one spec interfering with another. > Run separately the specs run fine, because the state is completely reset > between each run. However run together (and this can be order dependent, > just to add to the confusion) and they break. Debugging this can be quite > tricky, monitoring the test database, and the test.log should help. However > generally I find that you just have to pay real close attention to any specs > that create any sort of permanent artifact, and any specs that rely on there > being a certain number of artifacts e.g. the first role. > > All best > > Andrew > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Mon Dec 7 05:32:27 2009 From: lists at ruby-forum.com (Amit Kulkarni) Date: Mon, 7 Dec 2009 11:32:27 +0100 Subject: [rspec-users] undefined method `route_for In-Reply-To: <57c63afe0911260501g764cb865q8f500247bced26bd@mail.gmail.com> References: <57c63afe0911100659s296f97e2i96827851ea429bd@mail.gmail.com> <57c63afe0911110446n57225546ib288100d05cee61c@mail.gmail.com> <4A036CC1-A71C-48A8-A511-5CB829C8DEF8@gmail.com> <57c63afe0911121957h1449181bm93a1eb2f8a1fe3c9@mail.gmail.com> <1c7ec52a97eaaf0945deaa7461ba76c4@ruby-forum.com> <57c63afe0911122356n78f5c09fk89abea677f702dea@mail.gmail.com> <57c63afe0911130639w1168fdbav5aebcb019f563eb@mail.gmail.com> <37480320c538326c804860007ae1e26b@ruby-forum.com> <097b6352040480b2f8a6f78ea85769cd@ruby-forum.com> <57c63afe0911170711k4f04bdb8weadb244ccab7d540@mail.gmail.com> <5d0aadafba7ad1b891fca2111c341e9f@ruby-forum.com> <57c63afe0911260501g764cb865q8f500247bced26bd@mail.gmail.com> Message-ID: Hi David, I have some query regarding running spec command. When i tried to run normal testcase by command "spec test_controller_spec.rb" then that particular test case runs but the routing testcase fails. Now if i run through the command "spec spec/controllers/test_controller_spec.rb" then all the spec runs including the routing spec. Can you tell me why is this happening? -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Mon Dec 7 07:10:33 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 7 Dec 2009 07:10:33 -0500 Subject: [rspec-users] undefined method `route_for In-Reply-To: References: <57c63afe0911130639w1168fdbav5aebcb019f563eb@mail.gmail.com> <37480320c538326c804860007ae1e26b@ruby-forum.com> <097b6352040480b2f8a6f78ea85769cd@ruby-forum.com> <57c63afe0911170711k4f04bdb8weadb244ccab7d540@mail.gmail.com> <5d0aadafba7ad1b891fca2111c341e9f@ruby-forum.com> <57c63afe0911260501g764cb865q8f500247bced26bd@mail.gmail.com> Message-ID: <57c63afe0912070410q39801df8yfae88c8b53f896fc@mail.gmail.com> On Mon, Dec 7, 2009 at 5:32 AM, Amit Kulkarni wrote: > Hi David, > I have some query regarding running spec command. > When i tried to run normal testcase by command "spec > test_controller_spec.rb" > then that particular test case runs but the routing testcase fails. > > Now if i run through the command "spec > spec/controllers/test_controller_spec.rb" then all the spec runs > including the routing spec. > > Can you tell me why is this happening? > rspec-rails creates different ExampleGroup subclasses for each type of spec (model, view, controller, helper). It knows which type to create based on the presence of "spec/controllers" (in this case) in the file's runtime path, so you need to run specs from the project root in order for rspec to make this determination. HTH, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben at benmabey.com Mon Dec 7 23:57:16 2009 From: ben at benmabey.com (Ben Mabey) Date: Mon, 7 Dec 2009 21:57:16 -0700 Subject: [rspec-users] Fwd: [ANN] Announcing MountainWest RubyConf 2010 References: Message-ID: FYI, MWRC 2010 is accepting presentation proposals now (see link below). I've been to this conference every year and it has been great each time. If you have anything you would like to present please send in a proposal. :) -Ben Begin forwarded message: > From: Mike Moore > Date: December 7, 2009 5:47:17 PM MST > To: Ruby and URUG Discussion > Subject: [urug] [ANN] Announcing MountainWest RubyConf 2010 > Reply-To: urug at googlegroups.com > > I'm pleased to announce the 4th iteration of MountainWest RubyConf > on March 11-12, 2010 in Salt Lake City, Utah. MWRC is a two-day > single-track Ruby conference full of WIN. Registration is not yet > open, but our Call for Proposals is. > > http://bit.ly/mwrc2010cfp > > We are looking for code-heavy presentations about Ruby and Ruby- > based technology that blows our minds. Give it a thought and submit > a proposal. But don't over-think it, 'because you've only got until > midnight (MST) on December 31st. > > http://mtnwestrubyconf.org/ > > Questions? Comments? Let us know. > > http://twitter.com/mwrc > proposals at mtnwestrubyconf.org > > Mark your calendar now, then go get working on your proposal! > > -- > Utah Ruby Users Group > urug at googlegroups.com > http://groups.google.com/group/urug/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Tue Dec 8 02:17:44 2009 From: lists at ruby-forum.com (Sam Woodard) Date: Tue, 8 Dec 2009 08:17:44 +0100 Subject: [rspec-users] Rspec, Mocha Expectations Not Met Bug? Message-ID: <45bee9394857e261b4e21ca78f7aef98@ruby-forum.com> Code and tests at, http://gist.github.com/251480 I have debugged this code and both destroy and email! are being called! However, rspec/mocha says that the two expectations at the bottom of these tests are not met: both tests fail. Any help would be greatly appreciated. Thanks you in advance, Sam 1) Mocha::ExpectationError in 'ContactImport email should destroy the ear if the user is already a vbn member' not all expectations were satisfied unsatisfied expectations: - expected exactly once, not yet invoked: #.destroy(any_parameters) ... ./spec/models/contact_import_spec.rb:110: 2) Mocha::ExpectationError in 'ContactImport email should email the ear if the user is not already a vbn member' not all expectations were satisfied unsatisfied expectations: - expected exactly once, not yet invoked: #.email!(any_parameters) ./spec/models/contact_import_spec.rb:120: Finished in 1.967623 seconds 16 examples, 2 failures -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Tue Dec 8 07:40:04 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 8 Dec 2009 07:40:04 -0500 Subject: [rspec-users] Rspec, Mocha Expectations Not Met Bug? In-Reply-To: <45bee9394857e261b4e21ca78f7aef98@ruby-forum.com> References: <45bee9394857e261b4e21ca78f7aef98@ruby-forum.com> Message-ID: <57c63afe0912080440w2dd32b3ch2d6a4dd3a3b33b13@mail.gmail.com> On Tue, Dec 8, 2009 at 2:17 AM, Sam Woodard wrote: > Code and tests at, > > http://gist.github.com/251480 The objects you're setting expectations on are not the same objects that are being loaded by emailed_association_requests.to_send on line 4 of the gist. They may have the same database IDs, but they don't have the same object_id values. You've got two options here. One is to use mocha's any_instance on whatever class emailed_association_request is written on. The other, which I would recommend in this case, is to not use a mock. Mocks are really best for cases where you have direct control over the collaborator in a code example and deliver it directly to the object being spec'd. In this case, the collaborator (ear) is retrieved through a side door inside the contact import. The other side benefit we can get from mocks and stubs is isolation from the database, but these examples use real records, so that is obviously not a concern in this case. The first one can be spec'd by getting the id of ear before calling ci.email, and then expecting RecordNotFound if you try to find using that id. The 2nd one can be spec'd using a tool like email spec [1]. All of that said, there is a Feature Envy code smell [2] in the email method. This method is asking the ear for data, acquiring other data using that data, and then sending commands to the ear based on the state of that user. I'd recommend simplifying this code per [3], moving the part of the work that is based on the ear's data to the ear. If you do that, using a mock in the spec for the email method makes a lot more sense (using any_instance) because we're just concerned with a simple protocol and no conditional logic. The conditional logic would move to the AssociationRequest, and you can spec the create_association_with method more simply because there are fewer objects to set up. HTH, David [1] http://github.com/bmabey/email-spec [2] http://c2.com/cgi-bin/wiki?FeatureEnvySmell [3] http://gist.github.com/251599 I have debugged this code and both destroy and email! are being called! > However, rspec/mocha says that the two expectations at the bottom of > these tests are not met: both tests fail. > > Any help would be greatly appreciated. > > Thanks you in advance, > Sam > > > 1) > Mocha::ExpectationError in 'ContactImport email should destroy the ear > if the user is already a vbn member' > not all expectations were satisfied > unsatisfied expectations: > - expected exactly once, not yet invoked: > #.destroy(any_parameters) > ... > ./spec/models/contact_import_spec.rb:110: > > 2) > Mocha::ExpectationError in 'ContactImport email should email the ear if > the user is not already a vbn member' > not all expectations were satisfied > unsatisfied expectations: > - expected exactly once, not yet invoked: > #.email!(any_parameters) > ./spec/models/contact_import_spec.rb:120: > > Finished in 1.967623 seconds > > 16 examples, 2 failures > -- > 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 Tue Dec 8 11:01:36 2009 From: lists at ruby-forum.com (Sam Woodard) Date: Tue, 8 Dec 2009 17:01:36 +0100 Subject: [rspec-users] Rspec, Mocha Expectations Not Met Bug? In-Reply-To: <57c63afe0912080440w2dd32b3ch2d6a4dd3a3b33b13@mail.gmail.com> References: <45bee9394857e261b4e21ca78f7aef98@ruby-forum.com> <57c63afe0912080440w2dd32b3ch2d6a4dd3a3b33b13@mail.gmail.com> Message-ID: <07413add575a88e4cc041995c831c334@ruby-forum.com> Thank you so much for your detailed reply. This really helped! Sam -- Posted via http://www.ruby-forum.com/. From vanweerd at gmail.com Tue Dec 8 17:10:48 2009 From: vanweerd at gmail.com (Nicholas Van Weerdenburg) Date: Tue, 8 Dec 2009 17:10:48 -0500 Subject: [rspec-users] Can't run specs after upgrading gems... get 0 tests, 0 assertions... In-Reply-To: <128f4f21-00e0-4627-ab9a-71049b10cb80@l13g2000yqb.googlegroups.com> References: <128f4f21-00e0-4627-ab9a-71049b10cb80@l13g2000yqb.googlegroups.com> Message-ID: <632154f70912081410p6ef7978dj9c768cb0f420d294@mail.gmail.com> On Tue, Sep 29, 2009 at 9:37 PM, ignu wrote: > > So after I updated all my gems, I started getting: > > /Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/active_support/ > dependencies.rb:105:in `const_missing': uninitialized constant > Test::Unit::TestResult::TestResultFailureSupport (NameError) > from /Library/Ruby/Gems/1.8/gems/test-unit-2.0.3/lib/test/unit/ > testresult.rb:28 > from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in > `gem_original_require' > from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in > `require' > from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/ > active_support/dependencies.rb:158:in `require' > from > /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/interop/test.rb: > 8 > from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in > `gem_original_require' > from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in > `require' > from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/ > active_support/dependencies.rb:158:in `require' > from /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/test/unit.rb:1 > from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in > `gem_original_require' > from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in > `require' > from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/ > active_support/dependencies.rb:158:in `require' > from /Library/Ruby/Gems/1.8/gems/rspec-rails-1.2.7.1/lib/spec/ > rails.rb:13 > from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in > `gem_original_require' > from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in > `require' > from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/ > active_support/dependencies.rb:158:in `require' > from /Users/ignu/code/surveighor/spec/spec_helper.rb:6 > > > Then I added > > config.gem 'test-unit', :lib => 'test/unit' > > to environment.rb > > Now I get: > > 0 tests, 0 assertions, 0 failures, 0 errors, 0 pendings, 0 > omissions, 0 notifications > > And I can't figure out why. :-( > > Any ideas? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > I had the same problem, but it suddenly went away while updating some gems. Unfortunately, I'm not sure which one. It may have been treetop. -------------- next part -------------- An HTML attachment was scrubbed... URL: From lbocseg at yahoo.com.br Tue Dec 8 17:04:06 2009 From: lbocseg at yahoo.com.br (Rodrigo Rosenfeld Rosas) Date: Tue, 08 Dec 2009 20:04:06 -0200 Subject: [rspec-users] Custom Matcher and Webrat methods Message-ID: <4B1ECD56.4040303@yahoo.com.br> I would like to be able to write a custom matcher so that I could call this test, for instance: @user.should be_allowed_to_visit(url) @non_welcome.should_not be_allowed_to_visit(url) The matcher would call Webrat methods such as 'visit'. The problem is that it would try to call 'visit' from User class instead of the binding in which @user access is verified... I have manually set the binding to the Matcher in a before(:all), to avoid calling 'be_allowed_to_visit(url, binding)', but I would like to know if there would be a better way to "get" this binding... Any thoughts on that? Thanks, Rodrigo. __________________________________________________ Fa?a liga??es para outros computadores com o novo Yahoo! Messenger http://br.beta.messenger.yahoo.com/ From ed.howland at gmail.com Tue Dec 8 19:09:25 2009 From: ed.howland at gmail.com (Ed Howland) Date: Tue, 8 Dec 2009 19:09:25 -0500 Subject: [rspec-users] RSpec wire protocol Was:Re: describe "RSpec's documentation" do Message-ID: <3df642dd0912081609g3d5d2a51kb81d68074e025375@mail.gmail.com> Matt, I was facinated to read the email thread on Cuke's wire protoccol. You guys collaborated well. I have been working on my own to develop a similar protocol for RSpec. It is totally external to RSpec right now and very primitive. Whereas with Cucumber, the step definitions are run on some other language's server, my protocol executes all the code in Ruby in the "it" blocks and proxies objects and method calls to a server. Currently the protocol is CGIish+XML. The current server is PHP but could be anything like .Net. In the next iteration, I plan to use REST+JSON sort of like CounchDB or CounchREST. With REST you get all the error checking/responses with all the simplicity of the existing HTTP protocol, My first version used ActiveResource but there are other REST clients for Ruby, And JSON you already know. It seemed to me that part of your discussion revolved around encoding the protocol in JSON or externally. Did you consider REST. Did you reject it because of performance? If anyone has any thoughts on this, I'd be interested. Should we : o continue to use web proxies for objects and method calls? o -or- switch to running the matchers (should ==, etc.) over the wire protocol, more like cucumber? Thanks and great work, Ed BTW, anyone working on a Cuke4PHP? On Mon, Nov 9, 2009 at 5:03 PM, Matt Wynne wrote: > > On 6 Nov 2009, at 12:49, David Chelimsky wrote: > > >> [3] > http://github.com/aslakhellesoy/cucumber/blob/master/features/wire_protocol.feature > > I'm well behind this effort and would like to offer my help on the Cucumber > end to make it possible to use the features to generate the user > documentation - I think this would make a terrific use case for us to > support. > > cheers, > Matt > > http://mattwynne.net > +447974 430184 > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Ed Howland http://greenprogrammer.wordpress.com http://twitter.com/ed_howland -------------- next part -------------- An HTML attachment was scrubbed... URL: From matt at mattwynne.net Wed Dec 9 05:41:35 2009 From: matt at mattwynne.net (Matt Wynne) Date: Wed, 9 Dec 2009 10:41:35 +0000 Subject: [rspec-users] Custom Matcher and Webrat methods In-Reply-To: <4B1ECD56.4040303@yahoo.com.br> References: <4B1ECD56.4040303@yahoo.com.br> Message-ID: On 8 Dec 2009, at 22:04, Rodrigo Rosenfeld Rosas wrote: > I would like to be able to write a custom matcher so that I could > call this test, for instance: > > @user.should be_allowed_to_visit(url) > @non_welcome.should_not be_allowed_to_visit(url) > > The matcher would call Webrat methods such as 'visit'. > > The problem is that it would try to call 'visit' from User class > instead of the binding in which @user access is verified... > > I have manually set the binding to the Matcher in a before(:all), to > avoid calling 'be_allowed_to_visit(url, binding)', but I would like > to know if there would be a better way to "get" this binding... > > Any thoughts on that? How have you defined the matcher? If you use the old-school technique where you create a matcher class and a helper method to construct the class (instead of using the shiny new matcher DSL) then the method should execute in the context that can see the binding, so you can pick it up and pass it into the matcher class at that point. Make sense? cheers, Matt http://mattwynne.net +447974 430184 From lbocseg at yahoo.com.br Wed Dec 9 05:41:35 2009 From: lbocseg at yahoo.com.br (Rodrigo Rosenfeld Rosas) Date: Wed, 09 Dec 2009 08:41:35 -0200 Subject: [rspec-users] New RSpec methods to Object proposal: should_all and should_none Message-ID: <4B1F7EDF.1050905@yahoo.com.br> I was thinking that it would be great to add 2 additional methods to Object: should_all and should_none. The idea is that we would be able to write tests like: [@admin, @allowed_user].should_all be_allowed_to_visit(url) [@unprivileged, @non_welcome].should_none be_allowed_to_visit(url) Implementation is trivial, but I think that tests would become much cleaner than: [@admin, @allowed_user].each{|u| u.should be_allowed_to_visit(url)} Any thoughts on that? Rodrigo. __________________________________________________ Fa?a liga??es para outros computadores com o novo Yahoo! Messenger http://br.beta.messenger.yahoo.com/ From dchelimsky at gmail.com Wed Dec 9 08:27:43 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 9 Dec 2009 08:27:43 -0500 Subject: [rspec-users] New RSpec methods to Object proposal: should_all and should_none In-Reply-To: <4B1F7EDF.1050905@yahoo.com.br> References: <4B1F7EDF.1050905@yahoo.com.br> Message-ID: <57c63afe0912090527j74e40c03u6e71b20a517c3edf@mail.gmail.com> On Wed, Dec 9, 2009 at 5:41 AM, Rodrigo Rosenfeld Rosas < lbocseg at yahoo.com.br> wrote: > I was thinking that it would be great to add 2 additional methods to > Object: should_all and should_none. > > The idea is that we would be able to write tests like: > > [@admin, @allowed_user].should_all be_allowed_to_visit(url) > > [@unprivileged, @non_welcome].should_none be_allowed_to_visit(url) > > Implementation is trivial, but I think that tests would become much cleaner > than: > > [@admin, @allowed_user].each{|u| u.should be_allowed_to_visit(url)} > > Any thoughts on that? > How about: each_of(@admin, @allowed_user).should be_allowed_to_visit(url) none_of(@admin, @allowed_user).should be_allowed_to_visit(url) This gets the cleanliness without adding to Object. WDYT? David > Rodrigo. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mailinglists at patmaddox.com Wed Dec 9 11:55:02 2009 From: mailinglists at patmaddox.com (Pat Maddox) Date: Wed, 9 Dec 2009 08:55:02 -0800 Subject: [rspec-users] New RSpec methods to Object proposal: should_all and should_none In-Reply-To: <57c63afe0912090527j74e40c03u6e71b20a517c3edf@mail.gmail.com> References: <4B1F7EDF.1050905@yahoo.com.br> <57c63afe0912090527j74e40c03u6e71b20a517c3edf@mail.gmail.com> Message-ID: [@admin, @allowed_user].should all(be_allowed_to_visit(url)) [@admin, @allowed_user].should all_be_allowed_to_visit(url) I prefer the first so as not to introduce more "magic" but if it catches on then moving to the second might be worthwhile. Pat On Dec 9, 2009, at 5:27 AM, David Chelimsky wrote: > On Wed, Dec 9, 2009 at 5:41 AM, Rodrigo Rosenfeld Rosas wrote: > I was thinking that it would be great to add 2 additional methods to Object: should_all and should_none. > > The idea is that we would be able to write tests like: > > [@admin, @allowed_user].should_all be_allowed_to_visit(url) > > [@unprivileged, @non_welcome].should_none be_allowed_to_visit(url) > > Implementation is trivial, but I think that tests would become much cleaner than: > > [@admin, @allowed_user].each{|u| u.should be_allowed_to_visit(url)} > > Any thoughts on that? > > How about: > > each_of(@admin, @allowed_user).should be_allowed_to_visit(url) > none_of(@admin, @allowed_user).should be_allowed_to_visit(url) > > This gets the cleanliness without adding to Object. > > WDYT? > > David > > Rodrigo. > > _______________________________________________ > 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 Wed Dec 9 13:15:28 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 9 Dec 2009 13:15:28 -0500 Subject: [rspec-users] New RSpec methods to Object proposal: should_all and should_none In-Reply-To: References: <4B1F7EDF.1050905@yahoo.com.br> <57c63afe0912090527j74e40c03u6e71b20a517c3edf@mail.gmail.com> Message-ID: <57c63afe0912091015y14e2c905sfa682f80fba17460@mail.gmail.com> On Wed, Dec 9, 2009 at 11:55 AM, Pat Maddox wrote: > [@admin, @allowed_user].should all(be_allowed_to_visit(url)) > [@admin, @allowed_user].should all_be_allowed_to_visit(url) > I prefer the first so as not to introduce more "magic" but if it catches on > then moving to the second might be worthwhile. Seems like there are a few approaches to syntax that might work, but we also have to consider failure messages. Either of Pat's suggestions would make it easier to provide a meaningful failure message. Something like: Expected <#User @role => 'admin'>, <#User @role => 'allowed'> to be allowed to visit /some/path: - <#User @role => 'allowed'> was not - <#User @role => 'admin'> was I'd like to see this developed outside rspec first, let a few ppl play w/ different approaches. Once the idea has been fleshed out and in use we can merge in the one that gets community consensus - or not :) Cheers, David > Pat > On Dec 9, 2009, at 5:27 AM, David Chelimsky wrote: > > On Wed, Dec 9, 2009 at 5:41 AM, Rodrigo Rosenfeld Rosas > wrote: >> >> I was thinking that it would be great to add 2 additional methods to >> Object: should_all and should_none. >> >> The idea is that we would be able to write tests like: >> >> [@admin, @allowed_user].should_all be_allowed_to_visit(url) >> >> [@unprivileged, @non_welcome].should_none be_allowed_to_visit(url) >> >> Implementation is trivial, but I think that tests would become much >> cleaner than: >> >> [@admin, @allowed_user].each{|u| u.should be_allowed_to_visit(url)} >> >> Any thoughts on that? > > How about: > each_of(@admin, @allowed_user).should be_allowed_to_visit(url) > none_of(@admin, @allowed_user).should be_allowed_to_visit(url) > This gets the cleanliness without adding to Object. > WDYT? > David > >> >> Rodrigo. From win at wincent.com Wed Dec 9 14:16:33 2009 From: win at wincent.com (Wincent Colaiuta) Date: Wed, 9 Dec 2009 20:16:33 +0100 Subject: [rspec-users] New RSpec methods to Object proposal: should_all and should_none In-Reply-To: <57c63afe0912091015y14e2c905sfa682f80fba17460@mail.gmail.com> References: <4B1F7EDF.1050905@yahoo.com.br> <57c63afe0912090527j74e40c03u6e71b20a517c3edf@mail.gmail.com> <57c63afe0912091015y14e2c905sfa682f80fba17460@mail.gmail.com> Message-ID: <5CF5C3ED-1249-4515-A36C-6D7D97E7829D@wincent.com> El 09/12/2009, a las 19:15, David Chelimsky escribi?: > On Wed, Dec 9, 2009 at 11:55 AM, Pat Maddox > wrote: >> [@admin, @allowed_user].should all(be_allowed_to_visit(url)) >> [@admin, @allowed_user].should all_be_allowed_to_visit(url) >> On Dec 9, 2009, at 5:27 AM, David Chelimsky wrote: >> >> On Wed, Dec 9, 2009 at 5:41 AM, Rodrigo Rosenfeld Rosas >> wrote: >>> >>> I was thinking that it would be great to add 2 additional methods to >>> Object: should_all and should_none. >>> >>> The idea is that we would be able to write tests like: >>> >>> [@admin, @allowed_user].should_all be_allowed_to_visit(url) >>> >>> [@unprivileged, @non_welcome].should_none be_allowed_to_visit(url) >>> >>> Implementation is trivial, but I think that tests would become much >>> cleaner than: >>> >>> [@admin, @allowed_user].each{|u| u.should be_allowed_to_visit(url)} >>> >>> Any thoughts on that? >> >> How about: >> each_of(@admin, @allowed_user).should be_allowed_to_visit(url) >> none_of(@admin, @allowed_user).should be_allowed_to_visit(url) >> This gets the cleanliness without adding to Object. I'm puzzled as to why people are so focussed on making specs read like plain text English when they are still developer-facing Ruby code. Especially suprised in this case of wanting to avoid the "each + block" enumeration idiom, which is about as "bread and butter" Ruby as you can get, readable to anybody who's ever read the first chapter of a Ruby book. Cheers, Wincent From rick.denatale at gmail.com Wed Dec 9 15:01:09 2009 From: rick.denatale at gmail.com (Rick DeNatale) Date: Wed, 9 Dec 2009 15:01:09 -0500 Subject: [rspec-users] New RSpec methods to Object proposal: should_all and should_none In-Reply-To: <5CF5C3ED-1249-4515-A36C-6D7D97E7829D@wincent.com> References: <4B1F7EDF.1050905@yahoo.com.br> <57c63afe0912090527j74e40c03u6e71b20a517c3edf@mail.gmail.com> <57c63afe0912091015y14e2c905sfa682f80fba17460@mail.gmail.com> <5CF5C3ED-1249-4515-A36C-6D7D97E7829D@wincent.com> Message-ID: On Wed, Dec 9, 2009 at 2:16 PM, Wincent Colaiuta wrote: > El 09/12/2009, a las 19:15, David Chelimsky escribi?: > >> On Wed, Dec 9, 2009 at 11:55 AM, Pat Maddox >> wrote: >>> >>> [@admin, @allowed_user].should all(be_allowed_to_visit(url)) >>> [@admin, @allowed_user].should all_be_allowed_to_visit(url) > >>> On Dec 9, 2009, at 5:27 AM, David Chelimsky wrote: >>> >>> On Wed, Dec 9, 2009 at 5:41 AM, Rodrigo Rosenfeld Rosas >>> wrote: >>>> >>>> I was thinking that it would be great to add 2 additional methods to >>>> Object: should_all and should_none. >>>> >>>> The idea is that we would be able to write tests like: >>>> >>>> [@admin, @allowed_user].should_all be_allowed_to_visit(url) >>>> >>>> [@unprivileged, @non_welcome].should_none be_allowed_to_visit(url) >>>> >>>> Implementation is trivial, but I think that tests would become much >>>> cleaner than: >>>> >>>> [@admin, @allowed_user].each{|u| u.should be_allowed_to_visit(url)} >>>> >>>> Any thoughts on that? >>> >>> How about: >>> each_of(@admin, @allowed_user).should be_allowed_to_visit(url) >>> none_of(@admin, @allowed_user).should be_allowed_to_visit(url) >>> This gets the cleanliness without adding to Object. > > I'm puzzled as to why people are so focussed on making specs read like plain > text English when they are still developer-facing Ruby code. > > Especially suprised in this case of wanting to avoid the "each + block" > enumeration idiom, which is about as "bread and butter" Ruby as you can get, > readable to anybody who's ever read the first chapter of a Ruby book. I think that the english text is secondary to doing something which doesn't require mixing another method or methods into all objects. In the early days RSpec added quite a few more methods to Object besides (or perhaps instead of) should and should_not. One of the goals is to minimize disturbing the system being speced. -- 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 matt at mattwynne.net Wed Dec 9 15:08:50 2009 From: matt at mattwynne.net (Matt Wynne) Date: Wed, 9 Dec 2009 20:08:50 +0000 Subject: [rspec-users] New RSpec methods to Object proposal: should_all and should_none In-Reply-To: <5CF5C3ED-1249-4515-A36C-6D7D97E7829D@wincent.com> References: <4B1F7EDF.1050905@yahoo.com.br> <57c63afe0912090527j74e40c03u6e71b20a517c3edf@mail.gmail.com> <57c63afe0912091015y14e2c905sfa682f80fba17460@mail.gmail.com> <5CF5C3ED-1249-4515-A36C-6D7D97E7829D@wincent.com> Message-ID: On 9 Dec 2009, at 19:16, Wincent Colaiuta wrote: > El 09/12/2009, a las 19:15, David Chelimsky escribi?: > >> On Wed, Dec 9, 2009 at 11:55 AM, Pat Maddox > > wrote: >>> [@admin, @allowed_user].should all(be_allowed_to_visit(url)) >>> [@admin, @allowed_user].should all_be_allowed_to_visit(url) > >>> On Dec 9, 2009, at 5:27 AM, David Chelimsky wrote: >>> >>> On Wed, Dec 9, 2009 at 5:41 AM, Rodrigo Rosenfeld Rosas >>> wrote: >>>> >>>> I was thinking that it would be great to add 2 additional methods >>>> to >>>> Object: should_all and should_none. >>>> >>>> The idea is that we would be able to write tests like: >>>> >>>> [@admin, @allowed_user].should_all be_allowed_to_visit(url) >>>> >>>> [@unprivileged, @non_welcome].should_none be_allowed_to_visit(url) >>>> >>>> Implementation is trivial, but I think that tests would become much >>>> cleaner than: >>>> >>>> [@admin, @allowed_user].each{|u| u.should be_allowed_to_visit(url)} >>>> >>>> Any thoughts on that? >>> >>> How about: >>> each_of(@admin, @allowed_user).should be_allowed_to_visit(url) >>> none_of(@admin, @allowed_user).should be_allowed_to_visit(url) >>> This gets the cleanliness without adding to Object. > > I'm puzzled as to why people are so focussed on making specs read > like plain text English when they are still developer-facing Ruby > code. > > Especially suprised in this case of wanting to avoid the "each + > block" enumeration idiom, which is about as "bread and butter" Ruby > as you can get, readable to anybody who's ever read the first > chapter of a Ruby book. +1 Personally I'd use Cucumber for testing this sort of behaviour, but if I was using RSpec for some reason, I'd be inclined to use macros so I got a separate failing example for each type of user: url = 'http://some/url' [:admin, :allowed_user].each do |user_type| it "should allow an #{user_type} to visit #{url}" do user = instance_variable_get("@#{user_type}.to_sym) user.should be_allowed_to_visit(url) end end Either that or just simply a separate nested describe block for each type of user: describe "an admin user" do before(:each) do @user = Factory(:user, :admin => true) end it "should be allowed to access the URL" end etc. cheers, Matt http://mattwynne.net +447974 430184 From paul.t.hinze at gmail.com Wed Dec 9 15:09:08 2009 From: paul.t.hinze at gmail.com (Paul Hinze) Date: Wed, 9 Dec 2009 14:09:08 -0600 Subject: [rspec-users] New RSpec methods to Object proposal: should_all and should_none In-Reply-To: <5CF5C3ED-1249-4515-A36C-6D7D97E7829D@wincent.com> References: <4B1F7EDF.1050905@yahoo.com.br> <57c63afe0912090527j74e40c03u6e71b20a517c3edf@mail.gmail.com> <57c63afe0912091015y14e2c905sfa682f80fba17460@mail.gmail.com> <5CF5C3ED-1249-4515-A36C-6D7D97E7829D@wincent.com> Message-ID: <20091209200908.GK14328@malachai> Wincent Colaiuta on 2009-12-09 at 13:39: > El 09/12/2009, a las 19:15, David Chelimsky escribi?: > >> On Wed, Dec 9, 2009 at 11:55 AM, Pat Maddox > > wrote: >>> [@admin, @allowed_user].should all(be_allowed_to_visit(url)) >>> [@admin, @allowed_user].should all_be_allowed_to_visit(url) > >>> On Dec 9, 2009, at 5:27 AM, David Chelimsky wrote: >>> >>> On Wed, Dec 9, 2009 at 5:41 AM, Rodrigo Rosenfeld Rosas >>> wrote: >>>> >>>> I was thinking that it would be great to add 2 additional methods to >>>> Object: should_all and should_none. >>>> >>>> The idea is that we would be able to write tests like: >>>> >>>> [@admin, @allowed_user].should_all be_allowed_to_visit(url) >>>> >>>> [@unprivileged, @non_welcome].should_none be_allowed_to_visit(url) >>>> >>>> Implementation is trivial, but I think that tests would become much >>>> cleaner than: >>>> >>>> [@admin, @allowed_user].each{|u| u.should be_allowed_to_visit(url)} >>>> >>>> Any thoughts on that? >>> >>> How about: >>> each_of(@admin, @allowed_user).should be_allowed_to_visit(url) >>> none_of(@admin, @allowed_user).should be_allowed_to_visit(url) >>> This gets the cleanliness without adding to Object. > > I'm puzzled as to why people are so focussed on making specs read like > plain text English when they are still developer-facing Ruby code. > > Especially suprised in this case of wanting to avoid the "each + block" > enumeration idiom, which is about as "bread and butter" Ruby as you can > get, readable to anybody who's ever read the first chapter of a Ruby book. For me the benefit would be clearer error messages on failures, because of the potential to continue execution through the entirety of the collection of inputs, rather than bailing on the first failed 'should'. This allowing a developer to diagnose classes of problems with the collection rather than seeing failures one-by-one. Compare the following two options: [:foo, :bar, :baz, :qux].each { |x| x.should ==(:qux) } "Expected :foo to equal :qux" (...fix :foo...) "Expected :bar to equal :qux" (...fix :bar...) "Expected :baz to equal :qux" (...realize the _real_ problem is in dependent code that affects all of foo bar and baz, and fix that...) PASS each_of(:foo, :bar, :baz, :qux).should ==(:qux) "Expected each of :foo, :bar, :baz, :qux to equal :qux, but :foo, :bar, :baz did not." (...fix dependent code that affects all of foo bar and baz...) PASS I look forward to continuing this discussion. Cheers, Paul From david.spurr at gmail.com Wed Dec 9 17:28:10 2009 From: david.spurr at gmail.com (DEfusion) Date: Wed, 9 Dec 2009 14:28:10 -0800 (PST) Subject: [rspec-users] Autospec is running the full suite too often Message-ID: This is a problem I experience quite a bit: 1) Create a spec and outline all the examples (as not yet implemented) 2) Write the body of a example 3) Autospec runs spec -> fail 4) Make that example pass 5) Autospec runs spec -> pass 6) Autospec then runs the entire test suite again 7) Goto 2 (but now wait for entire suite to finish) before repeating This is a little annoying especially when you get to the point of tens of specs and hundreds of examples. I seem to remember back when I was using Autotest you could limit how often it re-runs the full test suite in these circumstances, but I've not being able to find the options nor anything for Autospec. -D From lbocseg at yahoo.com.br Wed Dec 9 17:56:42 2009 From: lbocseg at yahoo.com.br (Rodrigo Rosenfeld Rosas) Date: Wed, 09 Dec 2009 20:56:42 -0200 Subject: [rspec-users] New RSpec methods to Object proposal: should_all and should_none In-Reply-To: <20091209200908.GK14328@malachai> References: <4B1F7EDF.1050905@yahoo.com.br> <57c63afe0912090527j74e40c03u6e71b20a517c3edf@mail.gmail.com> <57c63afe0912091015y14e2c905sfa682f80fba17460@mail.gmail.com> <5CF5C3ED-1249-4515-A36C-6D7D97E7829D@wincent.com> <20091209200908.GK14328@malachai> Message-ID: <4B202B2A.7050808@yahoo.com.br> Paul Hinze escreveu: > Wincent Colaiuta on 2009-12-09 at 13:39: > >> El 09/12/2009, a las 19:15, David Chelimsky escribi?: >> >> >>> On Wed, Dec 9, 2009 at 11:55 AM, Pat Maddox >> >>>> wrote: >>>> [@admin, @allowed_user].should all(be_allowed_to_visit(url)) >>>> [@admin, @allowed_user].should all_be_allowed_to_visit(url) >>>> >>>> On Dec 9, 2009, at 5:27 AM, David Chelimsky wrote: >>>> >>>> On Wed, Dec 9, 2009 at 5:41 AM, Rodrigo Rosenfeld Rosas >>>> wrote: >>>> >>>>> I was thinking that it would be great to add 2 additional methods to >>>>> Object: should_all and should_none. >>>>> >>>>> The idea is that we would be able to write tests like: >>>>> >>>>> [@admin, @allowed_user].should_all be_allowed_to_visit(url) >>>>> >>>>> [@unprivileged, @non_welcome].should_none be_allowed_to_visit(url) >>>>> >>>>> Implementation is trivial, but I think that tests would become much >>>>> cleaner than: >>>>> >>>>> [@admin, @allowed_user].each{|u| u.should be_allowed_to_visit(url)} >>>>> >>>>> Any thoughts on that? >>>>> >>>> How about: >>>> each_of(@admin, @allowed_user).should be_allowed_to_visit(url) >>>> none_of(@admin, @allowed_user).should be_allowed_to_visit(url) >>>> This gets the cleanliness without adding to Object. >>>> >> I'm puzzled as to why people are so focussed on making specs read like >> plain text English when they are still developer-facing Ruby code. >> >> Especially suprised in this case of wanting to avoid the "each + block" >> enumeration idiom, which is about as "bread and butter" Ruby as you can >> get, readable to anybody who's ever read the first chapter of a Ruby book. >> > > For me the benefit would be clearer error messages on failures, because > of the potential to continue execution through the entirety of the > collection of inputs, rather than bailing on the first failed 'should'. > > This allowing a developer to diagnose classes of problems with the > collection rather than seeing failures one-by-one. > > Compare the following two options: > > [:foo, :bar, :baz, :qux].each { |x| x.should ==(:qux) } > "Expected :foo to equal :qux" > (...fix :foo...) > "Expected :bar to equal :qux" > (...fix :bar...) > "Expected :baz to equal :qux" > (...realize the _real_ problem is in dependent code that > affects all of foo bar and baz, and fix that...) > PASS > > each_of(:foo, :bar, :baz, :qux).should ==(:qux) > "Expected each of :foo, :bar, :baz, :qux to equal :qux, but > :foo, :bar, :baz did not." > (...fix dependent code that affects all of foo bar and > baz...) > PASS > I've read all the proposed syntax and I really like them all. I don't think the syntax below is as clear as the others proposed but I understand that it may help improving the failure message: [@admin, @allowed_user].should all(be_allowed_to_visit(url)) The syntax each_of/none_of is the clearer to me. The point for the tests to read like English sentences is that it easies test reading. Of course programmers will understand the statement using Ruby. But when you have tons of tests to read, this kind of improvement can make tests easier to be read, even by non-technical users when using XP techniques for instance if you try to pair-reading the tests to see if both programmer and client are expecting the same results... Also, the Java community is experiencing the use of JRuby and RSpec to test their Java applications and maybe they would prefer the "should_all/should all" syntax. I don't like Cucumber, for instance, because I would take much more time to write the stories from what I take writing the tests directly in RSpec. And I personally find specs as simple to read as Cucumber stories. But let's not get on this discussion, please... The point that the spec doesn't need to stop in the first error from the collection items is also a good one. There is also another point. Some failure messages don't mention the object being tested. In that case, the error message may be unclear because one won't know which of the tested items caused the error when using an "each" constructor. Anyway, it is not a serious limitation of Rspec since it is trivial to write such solutions if we want in our test suite. I can certainly leave without these extensions, but I think that if they get into Rspec core, it would be standardized among different projects and probably better documented, which makes it easier to integrate a new team member. Thank you for your proposals. Best regards, Rodrigo. __________________________________________________ Fa?a liga??es para outros computadores com o novo Yahoo! Messenger http://br.beta.messenger.yahoo.com/ From rick.denatale at gmail.com Wed Dec 9 18:13:20 2009 From: rick.denatale at gmail.com (Rick DeNatale) Date: Wed, 9 Dec 2009 18:13:20 -0500 Subject: [rspec-users] New RSpec methods to Object proposal: should_all and should_none In-Reply-To: <57c63afe0912091015y14e2c905sfa682f80fba17460@mail.gmail.com> References: <4B1F7EDF.1050905@yahoo.com.br> <57c63afe0912090527j74e40c03u6e71b20a517c3edf@mail.gmail.com> <57c63afe0912091015y14e2c905sfa682f80fba17460@mail.gmail.com> Message-ID: On Wed, Dec 9, 2009 at 1:15 PM, David Chelimsky wrote: > On Wed, Dec 9, 2009 at 11:55 AM, Pat Maddox wrote: >> [@admin, @allowed_user].should all(be_allowed_to_visit(url)) >> [@admin, @allowed_user].should all_be_allowed_to_visit(url) >> I prefer the first so as not to introduce more "magic" but if it catches on >> then moving to the second might be worthwhile. > > Seems like there are a few approaches to syntax that might work, but > we also have to consider failure messages. Either of Pat's suggestions > would make it easier to provide a meaningful failure message. > Something like: > > Expected <#User @role => 'admin'>, <#User @role => 'allowed'> to be > allowed to visit /some/path: > - <#User @role => 'allowed'> was not > - <#User @role => 'admin'> was I like Pat's idea too, but [x, y, z].should_not all_be_allowed_to(...) doesn't seem to be the same thing as none_of(x, y, z).should be_allowed_to(...) maybe [x, y, z].should all_not_be_alllowed_to(...) but I'm not sure -- 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 lbocseg at yahoo.com.br Wed Dec 9 18:40:37 2009 From: lbocseg at yahoo.com.br (Rodrigo Rosenfeld Rosas) Date: Wed, 09 Dec 2009 21:40:37 -0200 Subject: [rspec-users] New RSpec methods to Object proposal: should_all and should_none In-Reply-To: References: <4B1F7EDF.1050905@yahoo.com.br> <57c63afe0912090527j74e40c03u6e71b20a517c3edf@mail.gmail.com> <57c63afe0912091015y14e2c905sfa682f80fba17460@mail.gmail.com> Message-ID: <4B203575.3080609@yahoo.com.br> Rick DeNatale escreveu: > On Wed, Dec 9, 2009 at 1:15 PM, David Chelimsky wrote: > >> On Wed, Dec 9, 2009 at 11:55 AM, Pat Maddox wrote: >> >>> [@admin, @allowed_user].should all(be_allowed_to_visit(url)) >>> [@admin, @allowed_user].should all_be_allowed_to_visit(url) >>> I prefer the first so as not to introduce more "magic" but if it catches on >>> then moving to the second might be worthwhile. >>> >> Seems like there are a few approaches to syntax that might work, but >> we also have to consider failure messages. Either of Pat's suggestions >> would make it easier to provide a meaningful failure message. >> Something like: >> >> Expected <#User @role => 'admin'>, <#User @role => 'allowed'> to be >> allowed to visit /some/path: >> - <#User @role => 'allowed'> was not >> - <#User @role => 'admin'> was >> > > I like Pat's idea too, but > > [x, y, z].should_not all_be_allowed_to(...) > > doesn't seem to be the same thing as > > none_of(x, y, z).should be_allowed_to(...) > > maybe > [x, y, z].should all_not_be_alllowed_to(...) > > but I'm not sure > > I was just thinking about that. Maybe "all" should be documented as in "have_at_least": "should have_at_least(number).items Warning: should_not have_at_least is not supported" The correct way should be: @collection.should none(be_allowed_to(...)) Of course the "none_of" syntax would be easier to read, but the option above is also acceptable in my opinion... Rodrigo. __________________________________________________ Fa?a liga??es para outros computadores com o novo Yahoo! Messenger http://br.beta.messenger.yahoo.com/ From lbocseg at yahoo.com.br Wed Dec 9 19:53:43 2009 From: lbocseg at yahoo.com.br (Rodrigo Rosenfeld Rosas) Date: Wed, 09 Dec 2009 22:53:43 -0200 Subject: [rspec-users] Custom Matcher and Webrat methods In-Reply-To: References: <4B1ECD56.4040303@yahoo.com.br> Message-ID: <4B204697.8050603@yahoo.com.br> Matt Wynne escreveu: > > On 8 Dec 2009, at 22:04, Rodrigo Rosenfeld Rosas wrote: > >> I would like to be able to write a custom matcher so that I could >> call this test, for instance: >> >> @user.should be_allowed_to_visit(url) >> @non_welcome.should_not be_allowed_to_visit(url) >> >> The matcher would call Webrat methods such as 'visit'. >> >> The problem is that it would try to call 'visit' from User class >> instead of the binding in which @user access is verified... >> >> I have manually set the binding to the Matcher in a before(:all), to >> avoid calling 'be_allowed_to_visit(url, binding)', but I would like >> to know if there would be a better way to "get" this binding... >> >> Any thoughts on that? > > How have you defined the matcher? If you use the old-school technique > where you create a matcher class and a helper method to construct the > class (instead of using the shiny new matcher DSL) then the method > should execute in the context that can see the binding, so you can > pick it up and pass it into the matcher class at that point. > > Make sense? Thank you, Matt, I have finally got it working. The trick is passing self to the initialize of the matcher class like: def be_allowed_to_visit(url) BeAllowedToVisit.new(url, self) # def initialize(url, scope); scope.visit url...;end end One problem less :) Next one to be solved: making Selenium work faster with Webrat :) Thanks, Rodrigo. __________________________________________________ Fa?a liga??es para outros computadores com o novo Yahoo! Messenger http://br.beta.messenger.yahoo.com/ From brad.forsyth at inspire2go.com Wed Dec 9 19:48:01 2009 From: brad.forsyth at inspire2go.com (Brad) Date: Wed, 9 Dec 2009 16:48:01 -0800 (PST) Subject: [rspec-users] Need Help with Specs failing when using ActionMailer Message-ID: <9cd70a2a-320d-4c48-867a-7ca459858daa@l13g2000yqb.googlegroups.com> 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' 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 From lists at ruby-forum.com Thu Dec 10 02:32:34 2009 From: lists at ruby-forum.com (Amit Kulkarni) Date: Thu, 10 Dec 2009 08:32:34 +0100 Subject: [rspec-users] Problem with Before Filters Message-ID: <7c7324efe6944c042c05cc925af1cbe5@ruby-forum.com> Hello, I am writing controller specs.I want to know how can i write specs which invlove before filters in controllers. -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Thu Dec 10 04:51:28 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 10 Dec 2009 04:51:28 -0500 Subject: [rspec-users] Problem with Before Filters In-Reply-To: <7c7324efe6944c042c05cc925af1cbe5@ruby-forum.com> References: <7c7324efe6944c042c05cc925af1cbe5@ruby-forum.com> Message-ID: <57c63afe0912100151t142af49ds259ef7d9ddfe2953@mail.gmail.com> On Thu, Dec 10, 2009 at 2:32 AM, Amit Kulkarni wrote: > Hello, > I am writing controller specs.I want to know how can i write specs which > invlove before filters in controllers. Generally, before filters are part of the internal implementation and don't warrant specification that knows about their existence. For example, consider a controller action that should only be invoked by an admin. The spec might look like this: describe WidgetController do describe "POST create" do context "with an anonymous visitor" do it "redirects to login" do post :create, :widget => valid_widget_attributes response.should redirect_to(login_path) end end context "with an 'admin'" do it "redirects to the widget list" do login_as :admin post :create, :widget => valid_widget_attributes response.should redirect_to(widgets_path) end end end end Typically this authorization would be implemented in a before filter, but, as you can see, there is no mention of before filters in the spec. HTH, David From dchelimsky at gmail.com Thu Dec 10 04:55:46 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 10 Dec 2009 04:55:46 -0500 Subject: [rspec-users] Need Help with Specs failing when using ActionMailer In-Reply-To: <9cd70a2a-320d-4c48-867a-7ca459858daa@l13g2000yqb.googlegroups.com> References: <9cd70a2a-320d-4c48-867a-7ca459858daa@l13g2000yqb.googlegroups.com> Message-ID: <57c63afe0912100155t15cb1531p438b0ecbbcfbf81a@mail.gmail.com> 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 From dchelimsky at gmail.com Thu Dec 10 05:03:50 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 10 Dec 2009 05:03:50 -0500 Subject: [rspec-users] Autospec is running the full suite too often In-Reply-To: References: Message-ID: <57c63afe0912100203v6ba61722p938a2d64e9b1c789@mail.gmail.com> On Wed, Dec 9, 2009 at 5:28 PM, DEfusion wrote: > This is a problem I experience quite a bit: > > 1) Create a spec and outline all the examples (as not yet implemented) > 2) Write the body of a example > 3) Autospec runs spec -> fail > 4) Make that example pass > 5) Autospec runs spec -> pass > 6) Autospec then runs the entire test suite again > 7) Goto 2 (but now wait for entire suite to finish) before repeating This is how autotest works by default. See the first paragraph of http://zentest.rubyforge.org/ZenTest/Autotest.html. > This is a little annoying especially when you get to the point of tens > of specs and hundreds of examples. > > I seem to remember back when I was using Autotest you could limit how > often it re-runs the full test suite in these circumstances, but I've > not being able to find the options nor anything for Autospec. Autospec is a simple wrapper for autotest that essentially sets an environment variable that lets RSpec know that it's in use so autotest loads the right autotest class. Beyond that, anything you can configure in a .autotest file will work with autospec. HTH, David > -D From matt at mattwynne.net Thu Dec 10 05:14:20 2009 From: matt at mattwynne.net (Matt Wynne) Date: Thu, 10 Dec 2009 10:14:20 +0000 Subject: [rspec-users] Custom Matcher and Webrat methods In-Reply-To: <4B204697.8050603@yahoo.com.br> References: <4B1ECD56.4040303@yahoo.com.br> <4B204697.8050603@yahoo.com.br> Message-ID: <10EE7477-6CDA-49FA-81BE-7DFC338F99B5@mattwynne.net> On 10 Dec 2009, at 00:53, Rodrigo Rosenfeld Rosas wrote: > Matt Wynne escreveu: >> >> On 8 Dec 2009, at 22:04, Rodrigo Rosenfeld Rosas wrote: >> >>> I would like to be able to write a custom matcher so that I could >>> call this test, for instance: >>> >>> @user.should be_allowed_to_visit(url) >>> @non_welcome.should_not be_allowed_to_visit(url) >>> >>> The matcher would call Webrat methods such as 'visit'. >>> >>> The problem is that it would try to call 'visit' from User class >>> instead of the binding in which @user access is verified... >>> >>> I have manually set the binding to the Matcher in a before(:all), >>> to avoid calling 'be_allowed_to_visit(url, binding)', but I would >>> like to know if there would be a better way to "get" this binding... >>> >>> Any thoughts on that? >> >> How have you defined the matcher? If you use the old-school >> technique where you create a matcher class and a helper method to >> construct the class (instead of using the shiny new matcher DSL) >> then the method should execute in the context that can see the >> binding, so you can pick it up and pass it into the matcher class >> at that point. >> >> Make sense? > Thank you, Matt, I have finally got it working. The trick is passing > self to the initialize of the matcher class like: > > def be_allowed_to_visit(url) > BeAllowedToVisit.new(url, self) # def initialize(url, scope); > scope.visit url...;end > end > > One problem less :) Next one to be solved: making Selenium work > faster with Webrat :) You might want to look at replacing webrat with Capybara then. I've not tried it myself, but I understand Selenium2 (which Capybara supports) is much faster. > > Thanks, > > Rodrigo. > > __________________________________________________ > Fa?a liga??es para outros computadores com o novo Yahoo! Messenger http://br.beta.messenger.yahoo.com/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users cheers, Matt +447974 430184 matt at mattwynne.net http://mattwynne.net From lbocseg at yahoo.com.br Thu Dec 10 05:51:23 2009 From: lbocseg at yahoo.com.br (Rodrigo Rosenfeld Rosas) Date: Thu, 10 Dec 2009 08:51:23 -0200 Subject: [rspec-users] Custom Matcher and Webrat methods In-Reply-To: <10EE7477-6CDA-49FA-81BE-7DFC338F99B5@mattwynne.net> References: <4B1ECD56.4040303@yahoo.com.br> <4B204697.8050603@yahoo.com.br> <10EE7477-6CDA-49FA-81BE-7DFC338F99B5@mattwynne.net> Message-ID: <4B20D2AB.7060001@yahoo.com.br> Matt Wynne escreveu: > > On 10 Dec 2009, at 00:53, Rodrigo Rosenfeld Rosas wrote: > >> Matt Wynne escreveu: >>> >>> ... >> >> One problem less :) Next one to be solved: making Selenium work >> faster with Webrat :) > > You might want to look at replacing webrat with Capybara then. I've > not tried it myself, but I understand Selenium2 (which Capybara > supports) is much faster. Thank you once again Matt. I wonder how you get updated by these new gems... :) I'll give Capybara a try. It seems well documented and also the Webrat list is almost dead lately... Only a few questions and no answer lately... Thank you for the suggestion. Best Regards, Rodrigo. __________________________________________________ Fa?a liga??es para outros computadores com o novo Yahoo! Messenger http://br.beta.messenger.yahoo.com/ From brad.forsyth at inspire2go.com Thu Dec 10 09:20:47 2009 From: brad.forsyth at inspire2go.com (Brad) Date: Thu, 10 Dec 2009 06:20:47 -0800 (PST) Subject: [rspec-users] Need Help with Specs failing when using ActionMailer In-Reply-To: <57c63afe0912100155t15cb1531p438b0ecbbcfbf81a@mail.gmail.com> References: <9cd70a2a-320d-4c48-867a-7ca459858daa@l13g2000yqb.googlegroups.com> <57c63afe0912100155t15cb1531p438b0ecbbcfbf81a@mail.gmail.com> Message-ID: 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 < ActionMailer::Base 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 From matt at mattwynne.net Fri Dec 11 09:03:44 2009 From: matt at mattwynne.net (Matt Wynne) Date: Fri, 11 Dec 2009 14:03:44 +0000 Subject: [rspec-users] RSpec wire protocol Was:Re: describe "RSpec's documentation" do In-Reply-To: <3df642dd0912081609g3d5d2a51kb81d68074e025375@mail.gmail.com> References: <3df642dd0912081609g3d5d2a51kb81d68074e025375@mail.gmail.com> Message-ID: On 9 Dec 2009, at 00:09, Ed Howland wrote: > Matt, > > I was facinated to read the email thread on Cuke's wire protoccol. > You guys collaborated well. > > I have been working on my own to develop a similar protocol for > RSpec. It is totally external to RSpec right now and very primitive. > > Whereas with Cucumber, the step definitions are run on some other > language's server, my protocol executes all the code in Ruby in the > "it" blocks and proxies objects and method calls to a server. > Currently the protocol is CGIish+XML. The current server is PHP but > could be anything like .Net. > > In the next iteration, I plan to use REST+JSON sort of like CounchDB > or CounchREST. With REST you get all the error checking/responses > with all the simplicity of the existing HTTP protocol, My first > version used ActiveResource but there are other REST clients for > Ruby, And JSON you already know. > > It seemed to me that part of your discussion revolved around > encoding the protocol in JSON or externally. Did you consider REST. > Did you reject it because of performance? Yes we did, briefly - probably before the discussion went online on the lighthouse ticket. I think there were a couple of reasons why not REST: (1) simplicity - we wanted the wire server to be as low-tech as possible so it would be easy and lightweight to implement on any platform (think Cuke4EmbeddedDevice). Everyone's got a TCP stack but not everyone's got a simple web server like sinatra - I'm not even sure there's an especially simple one for .NET (2) flexibility - as the protocol has emerged, it's become clear that the relationship is pretty much client / server, but when we first started we weren't sure how much chatter would need to go back & forth. Obviously a REST server can't start making requests back to a client (unless that client also starts offering a web server), but if you've got two peers talking over a socket you can have two-way comms. > If anyone has any thoughts on this, I'd be interested. If you're using your protocol to effectively get remote control over objects, have you considered writing something to support DRB[1] on the server side? Otherwise you could also look at SLIM[2], which is the protocol Fitnesse uses in much the same way as Cucumber uses the wire protocol. We did consider using slim in Cucumber - it's widely supported with server implementations on many platforms, but since SLIM has much more flexibility that we needed, we decided to keep things simple. > Should we : > o continue to use web proxies for objects and method calls? > o -or- switch to running the matchers (should ==, etc.) over the > wire protocol, more like cucumber? I'm not really clear what the goal of your app is, but to go more into line with what cucumber's doing, I think what you'd do would be to allow RSpec to remotely invoke entire examples ("it blocks") remotely. You could then write those examples entirely in the native language. > Thanks and great work, > Ed > BTW, anyone working on a Cuke4PHP? That's the first time I've heard anyone even suggest it :) I'd be happy to collaborate with someone if they wanted some help with that. [1]http://segment7.net/projects/ruby/drb/introduction.html [2]http://fitnesse.org/FitNesse.UserGuide.SliM > On Mon, Nov 9, 2009 at 5:03 PM, Matt Wynne wrote: > > On 6 Nov 2009, at 12:49, David Chelimsky wrote: > > > [3]http://github.com/aslakhellesoy/cucumber/blob/master/features/wire_protocol.feature > > I'm well behind this effort and would like to offer my help on the > Cucumber end to make it possible to use the features to generate the > user documentation - I think this would make a terrific use case for > us to support. > > cheers, > Matt > > http://mattwynne.net > +447974 430184 > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > > > -- > Ed Howland > http://greenprogrammer.wordpress.com > http://twitter.com/ed_howland > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users cheers, Matt http://mattwynne.net +447974 430184 From erdoss at gmail.com Fri Dec 11 10:32:32 2009 From: erdoss at gmail.com (Andrei Erdoss) Date: Fri, 11 Dec 2009 17:32:32 +0200 Subject: [rspec-users] Stubbing calls to S3 from Paperclip Message-ID: Any idea on how to stub calls to Amazon S3 from the Paperclip plugin? -- Andrei Erdoss -------------- next part -------------- An HTML attachment was scrubbed... URL: From erdoss at gmail.com Fri Dec 11 12:27:02 2009 From: erdoss at gmail.com (Andrei Erdoss) Date: Fri, 11 Dec 2009 19:27:02 +0200 Subject: [rspec-users] Stubbing calls to S3 from Paperclip In-Reply-To: References: Message-ID: Ok, I found something that works. @photo.stub!(:save_attached_files).and_return(true) On Fri, Dec 11, 2009 at 5:32 PM, Andrei Erdoss wrote: > Any idea on how to stub calls to Amazon S3 from the Paperclip plugin? > > -- > Andrei Erdoss > -- Andrei Erdoss -------------- next part -------------- An HTML attachment was scrubbed... URL: From ed.howland at gmail.com Fri Dec 11 17:29:21 2009 From: ed.howland at gmail.com (Ed Howland) Date: Fri, 11 Dec 2009 17:29:21 -0500 Subject: [rspec-users] RSpec wire protocol Was:Re: describe "RSpec's documentation" do In-Reply-To: References: <3df642dd0912081609g3d5d2a51kb81d68074e025375@mail.gmail.com> Message-ID: <3df642dd0912111429m1bed93e0xaf8d91841cb802f1@mail.gmail.com> On Fri, Dec 11, 2009 at 9:03 AM, Matt Wynne wrote: > Yes we did, briefly - probably before the discussion went online on the > lighthouse ticket. I think there were a couple of reasons why not REST: > (1) simplicity - we wanted the wire server to be as low-tech as possible so > it would be easy and lightweight to implement on any platform (think > Cuke4EmbeddedDevice). Everyone's got a TCP stack but not everyone's got a > simple web server like sinatra - I'm not even sure there's an especially > simple one for .NET > (2) flexibility - as the protocol has emerged, it's become clear that the > relationship is pretty much client / server, but when we first started we > weren't sure how much chatter would need to go back & forth. Obviously a > REST server can't start making requests back to a client (unless that client > also starts offering a web server), but if you've got two peers talking over > a socket you can have two-way comms. > >> If anyone has any thoughts on this, I'd be interested. > > If you're using your protocol to effectively get remote control over > objects, have you considered writing something to support DRB[1] on the > server side? Otherwise you could also look at SLIM[2], which is the protocol > Fitnesse uses in much the same way as Cucumber uses the wire protocol. We > did consider using slim in Cucumber - it's widely supported with server > implementations on many platforms, but since SLIM has much more flexibility > that we needed, we decided to keep things simple. Thanks, Matt. [2] has some really good ideas and some that I've already thought of. I kinda like the multiple instructions per transaction. I don't know if I need that yet. I considered [1] but wasn't sure how easy it would be to write a server for DRb in another language. All I'm doing is representing the Ruby object protocol (object.send :message, args) in REST. JSON suffices for just about any object serialization and you can customize it for your class. I currently don't need to layer any command structure on top of JSON. Only the message's arguments payload and return values get serialized/deserialized. JSON is built-in or supported via a standard lib or module in all of my targeted languages. .Net/PHP/Perl and Python. REST works to supply the basics of the command layer. Resources are classes, objects and bare functions. E.g. To create a new object from a class. obj=MyObject.new => POST: http://server/class/MyObject obj-MyObject.new(1,2) POST: http://server/class/MyObject 'args=[1,2]' These return an object id along with json_cerate args. To call a method on said object: obj.f(:a=>10) => PUT : http://server/object/1/msg/f 'args={"a":1,"b":2}' .. and returning results as above. To call a class level method, return a single object or a list of them, use GET. obj=MyClass.get(1) => GET http://server/class/MyClass/msg/get?args=1 -- raw method -- obj =JSON.parse GET http://server/object/1 List (via a query): array = MyClass.query('where active = ?', true) => GET http://server/class/MyClass/msg/query?'args=["WHERE active = ?",true]' # with URL encoding -- raw list of all objects of a class -- GET http://server/class/MyClass/* -- raw list of all objects -- GET http://server/object/* ... and so on All returned objects on the Ruby side are just handles that only hold the id. They don't contain any marshaled data from the target language side. The reasoning is that all variable access must be done via accessor methods since that is the case in Ruby. However, given a REST call like this in a target server: PUT http://server/object/2/msg/a the implementation is free to decide that that is a variable access, and assuming it is public, return its value. Setting the contents of a variable is just the same, but with Ruby conventions that the target language has to obey: obj.a=1 => PUT http://server/object/3/a= 'args=[1]' The motivation behind this is to use both Cuke and RSpec to test legacy (or BDD develop new) projects w/o having to install and learn another BDD/xUnit framework. I think this suffices for all RSpec use cases, but it may be incomplete. If you are anyone think of anything I have missed, let me know. Already you can: sudo gem install (in ../spec_helper.rb: require '') describe MyObject before(:each) @obj = MyObject.new end it "should be valid" @obj.should be_valid # would PUT/ object/msg/valid? end it "should have x == ['avg', 10.0]" do @obj.x.should == ['avg', 10.0] end end Note there is no need to declare a class on the RSpec side, or to include a module or inherit from some other class. In PHP to get the specs to pass: --- my_object.php -- class MyObject { var x; function MyObject() {x=array("avg", 10.0);} function isValid() { return true; } // another convention } You get in to a R-G-R rhythm just as quickly as with native Ruby code. The server code for this would need to reflect on MyObject to determine variable access and discover methods that start with 'isXXX' Currently this is very primitive. There is no support for passing objects to other objects. I don't know about class level methods in all target languages yet. I thought the user could provide class factory classes for those if they don't exist, like in PHP4. It requires an object store on the server side, each implementation is free to decide on that. In Sinatra I it is just a class variable for now, the object ids are the indexes. >> Should we : >> o continue to use web proxies for objects and method calls? >> o -or- switch to running the matchers (should ==, etc.) over the wire >> protocol, more like cucumber? > > I'm not really clear what the goal of your app is, but to go more into line > with what cucumber's doing, I think what you'd do would be to allow RSpec to > remotely invoke entire examples ("it blocks") remotely. You could then write > those examples entirely in the native language. I mentioned the goal above. Writing those examples in the target language is not what I had in mind. I only want code in the actual SUT to be written in that SUT's language. You'd have to port ALL of RSpec's matchers there or use another framework's assertion lib. It'd be interesting but __way__ beyond the scope of what I am doing. Also, I am not sure what an it block would look like it it were sent over the wire. I imagine it queries the SUT wire server for any matching "it"s and any left over are just reported as unimplemented. BTW, does Cuke's wire protocol allow for a mixture of Ruby side and SUT side step definitions? >> BTW, anyone working on a Cuke4PHP? > > That's the first time I've heard anyone even suggest it :) I'd be happy to > collaborate with someone if they wanted some help with that. I seriously need this. And am willing to help. Currently we are using Cuke+Webrat+Mechanize to test only the web facing surface of the app. But to get things like 'Given I have a user named "Ted" with password "Secret"' to work and insert into the legacy DB is tricky. If that step could execute on the PHP side, life would be sweet! AFAIK, there seems to be simple REST servers in at least .Net and PHP. Fitzgerald for PHP and just using IIS and writing handlers in .Net. Ed > > [1]http://segment7.net/projects/ruby/drb/introduction.html > [2]http://fitnesse.org/FitNesse.UserGuide.SliM > Ed Howland http://greenprogrammer.wordpress.com http://twitter.com/ed_howland From matt at mattwynne.net Fri Dec 11 21:53:54 2009 From: matt at mattwynne.net (Matt Wynne) Date: Sat, 12 Dec 2009 02:53:54 +0000 Subject: [rspec-users] Cuke4PHP Was: RSpec wire protocol Was:Re: describe "RSpec's documentation" do In-Reply-To: <3df642dd0912111429m1bed93e0xaf8d91841cb802f1@mail.gmail.com> References: <3df642dd0912081609g3d5d2a51kb81d68074e025375@mail.gmail.com> <3df642dd0912111429m1bed93e0xaf8d91841cb802f1@mail.gmail.com> Message-ID: Let's move this bit of the discussion over to the cukes mailing list. Are you on that list Ed? On 11 Dec 2009, at 22:29, Ed Howland wrote: > > BTW, does Cuke's wire protocol allow for a mixture of Ruby side and > SUT side step definitions? Yes. With Cucumber you can implement steps in a mixture of any of the supported languages, including Ruby code, and any number of wire servers. > >>> BTW, anyone working on a Cuke4PHP? >> >> That's the first time I've heard anyone even suggest it :) I'd be >> happy to >> collaborate with someone if they wanted some help with that. > > I seriously need this. And am willing to help. Currently we are using > Cuke+Webrat+Mechanize to test only the web facing surface of the app. > But to get things like 'Given I have a user named "Ted" with password > "Secret"' to work and insert into the legacy DB is tricky. If that > step could execute on the PHP side, life would be sweet! The protocol is documented in the features here: http://github.com/mattwynne/cucumber/blob/master/features/wire_protocol.feature http://github.com/mattwynne/cucumber/blob/master/features/wire_protocol_table_diffing.feature Richard Lawrence has written the reference implementation of a server in .NET: http://github.com/richardlawrence/Cuke4Nuke The great thing about how Richard has implemented his server is he's written end-to-end tests (in cucumber) that make sure the whole thing works. See for example http://github.com/richardlawrence/Cuke4Nuke/blob/master/features/cuke4nuke.feature > AFAIK, there seems to be simple REST servers in at least .Net and PHP. > Fitzgerald for PHP and just using IIS and writing handlers in .Net. That's great, but we don't use REST for cucumber's wire protocol as I explained. Dragging the might of IIS around in order to test a winforms app, for example, would be pretty bonkers IMO. cheers, Matt http://mattwynne.net +447974 430184 From allan.m.miller at gmail.com Sat Dec 12 12:28:48 2009 From: allan.m.miller at gmail.com (athem) Date: Sat, 12 Dec 2009 09:28:48 -0800 (PST) Subject: [rspec-users] Error Running Standalone/Command Line rspec: undefined method Pathname Message-ID: <4d618141-cf06-46ff-9f2e-59c090aed007@z4g2000prh.googlegroups.com> Hello, I've written the following simple rspec test that I'm trying to run (rspec 1.2.9) standalone (outside Rails) from the command line and getting the following error. Any idea for how to fix this? Thanks. $> spec foo_rspec.rb /Users/athem/.gem/ruby/1.8/gems/rspec-1.2.9/lib/spec/runner/options.rb: 108:in `determine_project_root': undefined method `Pathname' for # (NoMethodError). foo_rspec.rb file: require 'spec_helper' class Foo end describe "A Foo that says boo" do before(:each) do @foo = Foo.new end it "should say boo" do @foo.should say_boo end end From dchelimsky at gmail.com Sat Dec 12 13:29:40 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 12 Dec 2009 12:29:40 -0600 Subject: [rspec-users] Error Running Standalone/Command Line rspec: undefined method Pathname In-Reply-To: <4d618141-cf06-46ff-9f2e-59c090aed007@z4g2000prh.googlegroups.com> References: <4d618141-cf06-46ff-9f2e-59c090aed007@z4g2000prh.googlegroups.com> Message-ID: <57c63afe0912121029s46c26cey4cc83da4372ec82e@mail.gmail.com> On Sat, Dec 12, 2009 at 11:28 AM, athem wrote: > Hello, > > I've written the following simple rspec test that I'm trying to run > (rspec 1.2.9) standalone (outside Rails) from the command line and > getting the following error. ?Any idea for how to fix this? ?Thanks. > > $> ?spec foo_rspec.rb > > /Users/athem/.gem/ruby/1.8/gems/rspec-1.2.9/lib/spec/runner/options.rb: > 108:in `determine_project_root': undefined method `Pathname' for > # (NoMethodError). There is a require 'pathname' statement in the method in options.rb that calls determine_project_root. Please try adding that to the beginning of your spec file and see if it works. If so, we'll need to investigate more to find out why it doesn't work for you as/is when it works for everyone else. HTH, David > > foo_rspec.rb file: > > > require 'spec_helper' > > class Foo > end > > describe "A Foo that says boo" do > ?before(:each) do > ? ?@foo = Foo.new > ?end > > ?it "should say boo" do > ? ?@foo.should say_boo > ?end > end > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Sat Dec 12 14:35:10 2009 From: lists at ruby-forum.com (Saverio Miroddi) Date: Sat, 12 Dec 2009 20:35:10 +0100 Subject: [rspec-users] Stub activerecord find given instance? In-Reply-To: <4A3616AC-32C2-478C-B20D-DF65FE1C031E@experthuman.com> References: <4A3616AC-32C2-478C-B20D-DF65FE1C031E@experthuman.com> Message-ID: Tom Stuart wrote: > On 10 Nov 2009, at 14:08, Saverio Miroddi wrote: >> Is there a clean/simple way of stubbing the activerecord find() for a >> single instance? > > MyModel.stub(:find).with(42).and_return(myModel) Didn't work as expected - I'll do a bit of research and post again. -- Posted via http://www.ruby-forum.com/. From sean at saucelabs.com Sun Dec 13 15:58:37 2009 From: sean at saucelabs.com (Sean Grove) Date: Sun, 13 Dec 2009 12:58:37 -0800 Subject: [rspec-users] Example vs ExampleProxy Message-ID: <5E4E6AF2-39A2-45B7-8B59-AF0E87B215DE@saucelabs.com> Hey all, I'm working on bring DeepTest up to compatibility with rspec 1.2.9 in order to parallelize tests, and hit a few roadblocks after 1.1.12. Specifically, I was wondering about ExampleProxy (which I know now is for the custom formatter) vs Example. Previously I would call run() on an Example, but that's no longer a method on the ExampleProxy objects - is there a way to grab the Example object from an ExampleProxy, or am I going about this the wrong way(TM)? Thanks for your help. Sean From dchelimsky at gmail.com Sun Dec 13 22:59:14 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 13 Dec 2009 21:59:14 -0600 Subject: [rspec-users] Example vs ExampleProxy In-Reply-To: <5E4E6AF2-39A2-45B7-8B59-AF0E87B215DE@saucelabs.com> References: <5E4E6AF2-39A2-45B7-8B59-AF0E87B215DE@saucelabs.com> Message-ID: <57c63afe0912131959u640136f5wf048df56e6efd238@mail.gmail.com> On Sun, Dec 13, 2009 at 2:58 PM, Sean Grove wrote: > Hey all, > > I'm working on bring DeepTest up to compatibility with rspec 1.2.9 in order > to parallelize tests, and hit a few roadblocks after 1.1.12. Specifically, I > was wondering about ExampleProxy (which I know now is for the custom > formatter) vs Example. Any formatter - builtin or custom. > Previously I would call run() on an Example, but > that's no longer a method on the ExampleProxy objects - is there a way to > grab the Example object from an ExampleProxy, or am I going about this the > wrong way(TM)? The proxies don't have refs back to the examples by design. Need to find a means of accessing the examples directly, not their proxies. Unfortunately, there is not really a good extension point for this right now. I'll add one for the next release, but in the mean time you'll need to replace line 30 in deep_test/spec/runner.rb with something like this: examples = example_groups.map do |g| proxies = g.send(:examples_to_run) proxies.map {|p| g.new(p, &g.example_implementations[p])} end.flatten That's untested, but should give you the basic idea. If this can wait a bit, let's coordinate off list and work out a good extension point - I'll do a release in the next week or so that exposes it and you can follow up w/ your release. Good? Cheers, David > Thanks for your help. > > Sean > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Mon Dec 14 02:05:21 2009 From: lists at ruby-forum.com (Amit Kulkarni) Date: Mon, 14 Dec 2009 08:05:21 +0100 Subject: [rspec-users] Problem with Before Filters In-Reply-To: <57c63afe0912100151t142af49ds259ef7d9ddfe2953@mail.gmail.com> References: <7c7324efe6944c042c05cc925af1cbe5@ruby-forum.com> <57c63afe0912100151t142af49ds259ef7d9ddfe2953@mail.gmail.com> Message-ID: <39be7cb7deb7e167fe2adfe9bc610316@ruby-forum.com> Thanks David, Now in spec when i write login_as :admin then there must be some method written for login_as? Now if there are before filters in controller then do we need to write each and every method or it is indeed taken care of but the developer and we need to just have to pass the value for that particular before filters. For e.g. If i have a before filter in controller as before_filter :admin_access_required, :except=>[ :view, :update_presentation] Now in my spec do i need to pass only the value like admin_access_required :admin or i need to write some method for the same -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Mon Dec 14 02:18:17 2009 From: lists at ruby-forum.com (Amit Kulkarni) Date: Mon, 14 Dec 2009 08:18:17 +0100 Subject: [rspec-users] undefined method `route_for In-Reply-To: <57c63afe0912070410q39801df8yfae88c8b53f896fc@mail.gmail.com> References: <57c63afe0911100659s296f97e2i96827851ea429bd@mail.gmail.com> <57c63afe0911110446n57225546ib288100d05cee61c@mail.gmail.com> <4A036CC1-A71C-48A8-A511-5CB829C8DEF8@gmail.com> <57c63afe0911121957h1449181bm93a1eb2f8a1fe3c9@mail.gmail.com> <1c7ec52a97eaaf0945deaa7461ba76c4@ruby-forum.com> <57c63afe0911122356n78f5c09fk89abea677f702dea@mail.gmail.com> <57c63afe0911130639w1168fdbav5aebcb019f563eb@mail.gmail.com> <37480320c538326c804860007ae1e26b@ruby-forum.com> <097b6352040480b2f8a6f78ea85769cd@ruby-forum.com> <57c63afe0911170711k4f04bdb8weadb244ccab7d540@mail.gmail.com> <5d0aadafba7ad1b891fca2111c341e9f@ruby-forum.com> <57c63afe0911260501g764cb865q8f500247bced26bd@mail.gmail.com> <57c63afe0912070410q39801df8yfae88c8b53f896fc@mail.gmail.com> Message-ID: Thanks David. Also i am little bit confused regarding routes. Consider a routing example it "should map { :controller => 'channels', :action => 'new' } to /channels/new" do route_for(:controller => "channels", :action => "new").should == "/channels/new" end Now i can see all the routing methods by rake routes.In that i can see this new action defined. Now imagine if i write an action which is not defined in the rake routes then instead of failing it is passing.For e.g. it "should map { :controller => 'channels', :action => 'test' } to /channels/test" do route_for(:controller => "channels", :action => "test").should == "/channels/test" end Now here 'test' action is not defined in the routes.So it should fail but it isn't. May be i am missing something here. -- Posted via http://www.ruby-forum.com/. From erdoss at gmail.com Mon Dec 14 04:26:07 2009 From: erdoss at gmail.com (Andrei Erdoss) Date: Mon, 14 Dec 2009 11:26:07 +0200 Subject: [rspec-users] Problem with Before Filters In-Reply-To: <39be7cb7deb7e167fe2adfe9bc610316@ruby-forum.com> References: <7c7324efe6944c042c05cc925af1cbe5@ruby-forum.com> <57c63afe0912100151t142af49ds259ef7d9ddfe2953@mail.gmail.com> <39be7cb7deb7e167fe2adfe9bc610316@ruby-forum.com> Message-ID: You can write a stub method that would return a value such that your object meets the admin_required_access requirement. controller.stub(:admin_access_required).and_return(true) On Mon, Dec 14, 2009 at 9:05 AM, Amit Kulkarni wrote: > Thanks David, > Now in spec when i write login_as :admin then there must be some method > written for login_as? > Now if there are before filters in controller then do we need to write > each and every method or it is indeed taken care of but the developer > and we need to just have to pass the value for that particular before > filters. > For e.g. > If i have a before filter in controller as > before_filter :admin_access_required, :except=>[ :view, > :update_presentation] > Now in my spec do i need to pass only the value like > admin_access_required :admin > or i need to write some method for the same > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Andrei Erdoss -------------- next part -------------- An HTML attachment was scrubbed... URL: From apremdas at gmail.com Mon Dec 14 05:01:14 2009 From: apremdas at gmail.com (Andrew Premdas) Date: Mon, 14 Dec 2009 10:01:14 +0000 Subject: [rspec-users] undefined method `route_for In-Reply-To: References: <37480320c538326c804860007ae1e26b@ruby-forum.com> <097b6352040480b2f8a6f78ea85769cd@ruby-forum.com> <57c63afe0911170711k4f04bdb8weadb244ccab7d540@mail.gmail.com> <5d0aadafba7ad1b891fca2111c341e9f@ruby-forum.com> <57c63afe0911260501g764cb865q8f500247bced26bd@mail.gmail.com> <57c63afe0912070410q39801df8yfae88c8b53f896fc@mail.gmail.com> Message-ID: <88fd8ddc0912140201h50f43ef6wf17494c885d0db76@mail.gmail.com> 2009/12/14 Amit Kulkarni > Thanks David. > Also i am little bit confused regarding routes. > > Consider a routing example > > it "should map { :controller => 'channels', :action => 'new' } to > /channels/new" do > route_for(:controller => "channels", :action => "new").should == > "/channels/new" > end > > Now i can see all the routing methods by rake routes.In that i can see > this new action defined. > > Now imagine if i write an action which is not defined in the rake routes > then instead of failing it is passing.For e.g. > > it "should map { :controller => 'channels', :action => 'test' } to > /channels/test" do > route_for(:controller => "channels", :action => "test").should == > "/channels/test" > end > > Now here 'test' action is not defined in the routes.So it should fail > but it isn't. > May be i am missing something here. > -- > Are you sure you have the default last two lines commented out in routes.rb. If you haven't they will match that action - I think. All best Andrew > 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 Dec 14 07:39:20 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 14 Dec 2009 06:39:20 -0600 Subject: [rspec-users] Stub activerecord find given instance? In-Reply-To: References: <4A3616AC-32C2-478C-B20D-DF65FE1C031E@experthuman.com> Message-ID: <57c63afe0912140439y4c5a00fbtb65d155eccd5426f@mail.gmail.com> On Sat, Dec 12, 2009 at 1:35 PM, Saverio Miroddi wrote: > Tom Stuart wrote: >> On 10 Nov 2009, at 14:08, Saverio Miroddi wrote: >>> Is there a clean/simple way of stubbing the activerecord find() for a >>> single instance? >> >> 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? From dchelimsky at gmail.com Mon Dec 14 14:22:32 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 14 Dec 2009 13:22:32 -0600 Subject: [rspec-users] Problem with Before Filters In-Reply-To: <39be7cb7deb7e167fe2adfe9bc610316@ruby-forum.com> References: <7c7324efe6944c042c05cc925af1cbe5@ruby-forum.com> <57c63afe0912100151t142af49ds259ef7d9ddfe2953@mail.gmail.com> <39be7cb7deb7e167fe2adfe9bc610316@ruby-forum.com> Message-ID: <57c63afe0912141122m3dbf704eu2c0e4afff5335cb3@mail.gmail.com> On Mon, Dec 14, 2009 at 1:05 AM, Amit Kulkarni wrote: > Thanks David, > Now in spec when i write login_as :admin then there must be some method > written for login_as? That would be a helper that you write yourself or is provided by the authentication framework you're using. It lives in the spec suite, not in the controller code, and does whatever is necessary to either actually log in. The most black box approach is to post to the controller that manages logging in. What it looks like depends on how you design your authentication system. restful_authentication, for example, ships with login_as and authorize_as methods that set session variables directly. HTH, David From dchelimsky at gmail.com Mon Dec 14 14:25:29 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 14 Dec 2009 13:25:29 -0600 Subject: [rspec-users] Problem with Before Filters In-Reply-To: References: <7c7324efe6944c042c05cc925af1cbe5@ruby-forum.com> <57c63afe0912100151t142af49ds259ef7d9ddfe2953@mail.gmail.com> <39be7cb7deb7e167fe2adfe9bc610316@ruby-forum.com> Message-ID: <57c63afe0912141125q62b92938o37a90a876d237bac@mail.gmail.com> On Mon, Dec 14, 2009 at 3:26 AM, Andrei Erdoss wrote: > On Mon, Dec 14, 2009 at 9:05 AM, Amit Kulkarni wrote: >> >> Thanks David, >> Now in spec when i write login_as :admin then there must be some method >> written for login_as? >> Now if there are before filters in controller then do we need to write >> each and every method or it is indeed taken care of but the developer >> and we need to just have to pass the value for that particular before >> filters. >> For e.g. >> If i have a before filter in controller as >> before_filter :admin_access_required, :except=>[ :view, >> :update_presentation] >> Now in my spec do i need to pass only the value like >> admin_access_required :admin >> or i need to write some method for the same > > You can write a stub method that would return a value such that your object > meets the admin_required_access requirement. > > controller.stub(:admin_access_required).and_return(true) That _could_ work, but methods like admin_access_required are often implemented such that they modify the internal state of the controller, setting the user on its internal session or request object. If the behaviour subsequently invoked by the example needs to access that state, this wouldn't work. Cheers, David > > -- > Andrei Erdoss From mattriches at gmail.com Mon Dec 14 15:36:48 2009 From: mattriches at gmail.com (Matt Riches) Date: Mon, 14 Dec 2009 20:36:48 +0000 Subject: [rspec-users] RSPEC and RoR undefined method for hash when running model tests Message-ID: <5d86970f0912141236j53f50b89vc116efcc9d0c9448@mail.gmail.com> Within my project, I have a number of models that have additional methods within them other than those provided by active record. as an example (to keep it short and sweet) class foo < ActiveRecod::Base def status "New Record" end def reset "Reset" end end in my spec file I have require 'spec_helper' describe Foo do before(:each) do @foo = Foo.new() end it "should have a status of New Record" @foo.status.should == "New Record" end it "should have a status of Reset after reset" @foo.reset.should == "Reset" end end however, when I run rake spec I get NoMethodError in 'Foo should have a status of New Record' undefined method 'status' for # and an equivalent one for the other method. I am sure that this is something fundamental in my understanding, but I'm scuppered. I have spent the best part of a day trying to resolve this. so, 1) Why are my methods undefined, when they are there (I can create the object via script/console and call the status and reset methods and see them work) 2) What is the best way of resolving the issue Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From tom at experthuman.com Mon Dec 14 15:54:26 2009 From: tom at experthuman.com (Tom Stuart) Date: Mon, 14 Dec 2009 20:54:26 +0000 Subject: [rspec-users] RSPEC and RoR undefined method for hash when running model tests In-Reply-To: <5d86970f0912141236j53f50b89vc116efcc9d0c9448@mail.gmail.com> References: <5d86970f0912141236j53f50b89vc116efcc9d0c9448@mail.gmail.com> Message-ID: On 14 Dec 2009, at 20:36, Matt Riches wrote: > 1) Why are my methods undefined, when they are there (I can create the object via script/console and call the status and reset methods and see them work) > 2) What is the best way of resolving the issue You'd be much better off using pastie.org to show us the real code that's having the problem, because your example contains all sorts of omissions and typos (which is likely to be the sort of thing that causes your problem!) and it's impossible to tell how much of it is wrong in the original code versus how much was introduced by you rewriting it as an example. Cheers, -Tom From david at digitalronin.com Mon Dec 14 16:04:09 2009 From: david at digitalronin.com (David Salgado) Date: Mon, 14 Dec 2009 21:04:09 +0000 Subject: [rspec-users] RSPEC and RoR undefined method for hash when running model tests In-Reply-To: References: <5d86970f0912141236j53f50b89vc116efcc9d0c9448@mail.gmail.com> Message-ID: <8c90cb7d0912141304t8746435ne6cfd960c40b667f@mail.gmail.com> Looks like you forgot to put "do" at the end of your specs. I do that all the time; it "should have a status of New Record" ... Should be it "should have a status of New Record" do ... HTH David 2009/12/14 Tom Stuart : > On 14 Dec 2009, at 20:36, Matt Riches wrote: >> 1) Why are my methods undefined, when they are there (I can create the object via script/console and call the status and reset methods and see them work) >> 2) What is the best way of resolving the issue > > You'd be much better off using pastie.org to show us the real code that's having the problem, because your example contains all sorts of omissions and typos (which is likely to be the sort of thing that causes your problem!) and it's impossible to tell how much of it is wrong in the original code versus how much was introduced by you rewriting it as an example. > > Cheers, > -Tom > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mattriches at gmail.com Mon Dec 14 16:28:42 2009 From: mattriches at gmail.com (Matt Riches) Date: Mon, 14 Dec 2009 21:28:42 +0000 Subject: [rspec-users] RSPEC and RoR undefined method for hash when running model tests In-Reply-To: References: <5d86970f0912141236j53f50b89vc116efcc9d0c9448@mail.gmail.com> Message-ID: <5d86970f0912141328q2c860224t84799701904c5756@mail.gmail.com> Fair point, thought you could also assume that the omissions are down to my newness at RSpec and RoR :-) The whole of the code is rather large, I am being asked to retrofit rspec onto the code base as things are changed, so I am only showing what I think are the relevent things.. Code Section 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 class Address < ActiveRecord::Base #Status Codes as Constants JUST_REGISTERED = 0 DELETED = 1 DECLINED = 2 APPROVED = 3 def status DELETED end def reset #We don't actually delete the record #Instead a status field is set #And all the data is blanked for data protection reasons self.status = DELETED self.business_name = '' self.first_line = '' self.second_line = '' self.town = '' self.county = '' self.postcode = '' #MR - added in the following fields self.lat = 0.0 self.lng = 0.0 self.route_id = 0 self.save end #.. other code elided end ------------------------------ RSpec 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 require 'spec_helper' describe Address do #Test Fixture - Before Each test Create a Standard Bread with the following attributes and properties before(:each) do @address = { :business_name => 'business', :first_line => '10, This Street', :second_line=> 'erewhon', :town=> 'town', :county=>'county', :postcode =>'AB12 3CD', :user_id => 1, :lat=>1.01, :lng=>2.02, :status=>Address::JUST_REGISTERED, :route_id=>1 } end it "should have a status of deleted after reset" do @address.reset @address.status.should == :Address::DELETED end end Thanks David as well, but Tom was right, it was my typing that caused that issue. Regards Matt 2009/12/14 Tom Stuart > On 14 Dec 2009, at 20:36, Matt Riches wrote: > > 1) Why are my methods undefined, when they are there (I can create the > object via script/console and call the status and reset methods and see them > work) > > 2) What is the best way of resolving the issue > > You'd be much better off using pastie.org to show us the real code that's > having the problem, because your example contains all sorts of omissions and > typos (which is likely to be the sort of thing that causes your problem!) > and it's impossible to tell how much of it is wrong in the original code > versus how much was introduced by you rewriting it as an example. > > Cheers, > -Tom > _______________________________________________ > 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 vishu at thinklinkr.com Mon Dec 14 16:33:06 2009 From: vishu at thinklinkr.com (Vishu Ramanathan) Date: Mon, 14 Dec 2009 15:33:06 -0600 Subject: [rspec-users] RSPEC and RoR undefined method for hash when running model tests In-Reply-To: <5d86970f0912141328q2c860224t84799701904c5756@mail.gmail.com> References: <5d86970f0912141236j53f50b89vc116efcc9d0c9448@mail.gmail.com> <5d86970f0912141328q2c860224t84799701904c5756@mail.gmail.com> Message-ID: This should have been the giveaway > undefined method 'status' for #<*Hash*...> In your before you're assigning @address to the parameters, not to a new address @address = {:foo => 'bar'} instead of @address = Address.new({:foo => 'bar'}) -V On Mon, Dec 14, 2009 at 3:28 PM, Matt Riches wrote: > Fair point, thought you could also assume that the omissions are down to my > newness at RSpec and RoR :-) > > The whole of the code is rather large, I am being asked to retrofit rspec > onto the code base as things are changed, so I am only showing what I think > are the relevent things.. > > Code Section > > 1 > 2 > 3 > 4 > 5 > 6 > 7 > 8 > 9 > 10 > 11 > 12 > 13 > 14 > 15 > 16 > 17 > 18 > 19 > 20 > 21 > 22 > 23 > 24 > 25 > 26 > 27 > 28 > 29 > 30 > 31 > 32 > > 33 > 34 > > class Address < ActiveRecord::Base > > > #Status Codes as Constants > JUST_REGISTERED = 0 > > DELETED = 1 > > DECLINED = 2 > > APPROVED = 3 > > def status > > DELETED > end > > def reset > #We don't actually delete the record > #Instead a status field is set > #And all the data is blanked for data protection reasons > > self.status = DELETED > > self.business_name = '' > > self.first_line = '' > > self.second_line = '' > > self.town = '' > > self.county = '' > > self.postcode = '' > #MR - added in the following fields > self.lat = 0.0 > > self.lng = 0.0 > > self.route_id = 0 > > self.save > end > #.. other code elided > end > > ------------------------------ > RSpec > > 1 > 2 > 3 > 4 > 5 > 6 > 7 > 8 > 9 > 10 > 11 > 12 > 13 > 14 > 15 > 16 > 17 > 18 > 19 > 20 > > require 'spec_helper' > > describe Address do > #Test Fixture - Before Each test Create a Standard Bread with the following attributes and properties > before(:each) do > > @address = { > > :business_name => 'business', :first_line => '10, This Street', :second_line=> 'erewhon', :town=> 'town', :county=>'county', > > :postcode =>'AB12 3CD', :user_id => 1, :lat=>1.01, :lng=>2.02, :status=>Address::JUST_REGISTERED, :route_id=>1 > > } > end > > > it "should have a status of deleted after reset" do > > @address.reset > > @address.status.should == :Address::DELETED > > end > > > end > > > > Thanks David as well, but Tom was right, it was my typing that caused that > issue. > > Regards > > Matt > > 2009/12/14 Tom Stuart > >> On 14 Dec 2009, at 20:36, Matt Riches wrote: >> >> > 1) Why are my methods undefined, when they are there (I can create the >> object via script/console and call the status and reset methods and see them >> work) >> > 2) What is the best way of resolving the issue >> >> You'd be much better off using pastie.org to show us the real code that's >> having the problem, because your example contains all sorts of omissions and >> typos (which is likely to be the sort of thing that causes your problem!) >> and it's impossible to tell how much of it is wrong in the original code >> versus how much was introduced by you rewriting it as an example. >> >> Cheers, >> -Tom >> _______________________________________________ >> 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 > -- Vishu Ramanathan co-founder thinklink llc 312.436.1627 new homepage! ---> thinklinkllc.com mocklinkr.com makes web mockups come to life thinklinkr.com is the web-based collaborative outliner -------------- next part -------------- An HTML attachment was scrubbed... URL: From tom at experthuman.com Mon Dec 14 16:39:22 2009 From: tom at experthuman.com (Tom Stuart) Date: Mon, 14 Dec 2009 21:39:22 +0000 Subject: [rspec-users] RSPEC and RoR undefined method for hash when running model tests In-Reply-To: <5d86970f0912141328q2c860224t84799701904c5756@mail.gmail.com> References: <5d86970f0912141236j53f50b89vc116efcc9d0c9448@mail.gmail.com> <5d86970f0912141328q2c860224t84799701904c5756@mail.gmail.com> Message-ID: On 14 Dec 2009, at 21:28, Matt Riches wrote: > describe Address do > #Test Fixture - Before Each test Create a Standard Bread with the following attributes and properties > before(:each) do > @address = { > :business_name => 'business', :first_line => '10, This Street', :second_line=> 'erewhon', :town=> 'town', :county=>'county', > :postcode =>'AB12 3CD', :user_id => 1, :lat=>1.01, :lng=>2.02, :status=>Address::JUST_REGISTERED, :route_id=>1 > } > end > > it "should have a status of deleted after reset" do > @address.reset > @address.status.should == :Address::DELETED > end > end The problem is that you're setting @address to a hash, not an instance of Address. Did you mean @address = Address.new :business_name => ...? Cheers, -Tom From mattriches at gmail.com Mon Dec 14 16:48:49 2009 From: mattriches at gmail.com (Matt Riches) Date: Mon, 14 Dec 2009 21:48:49 +0000 Subject: [rspec-users] RSPEC and RoR undefined method for hash when running model tests In-Reply-To: References: <5d86970f0912141236j53f50b89vc116efcc9d0c9448@mail.gmail.com> <5d86970f0912141328q2c860224t84799701904c5756@mail.gmail.com> Message-ID: <5d86970f0912141348l3a5fb4bg9a85ca22a019dacc@mail.gmail.com> I am still learning, and its been along and frustrating day, but thanks ! Sometimes a fresh (more experienced pair of eyes) can spot the blindingly obvious :) ok, one more quick question, and its slightly more general and then Im going home for the day. When I run my tests now I get a series of lines warning: already initialised constant JUST_REGISTERED warning: already initialised constant DELETED etc. as its only a warning I am not too bothered, but ideally I'd like to stop it if I can. Is this an artefact of me creating constants in the class, then it being called before(:each) ? Is there some way of supressing the warnings, or making the constants only get assigned once? (Maybe another class that just implements the constants?) Regards Matt 2009/12/14 Vishu Ramanathan > This should have been the giveaway > >> undefined method 'status' for #<*Hash*...> > > > In your before you're assigning @address to the parameters, not to a new > address > @address = {:foo => 'bar'} > instead of > @address = Address.new({:foo => 'bar'}) > > -V > > > On Mon, Dec 14, 2009 at 3:28 PM, Matt Riches wrote: > >> Fair point, thought you could also assume that the omissions are down to >> my newness at RSpec and RoR :-) >> >> The whole of the code is rather large, I am being asked to retrofit rspec >> onto the code base as things are changed, so I am only showing what I think >> are the relevent things.. >> >> Code Section >> >> 1 >> 2 >> 3 >> 4 >> 5 >> 6 >> 7 >> 8 >> 9 >> 10 >> 11 >> 12 >> 13 >> 14 >> 15 >> 16 >> 17 >> 18 >> 19 >> 20 >> 21 >> 22 >> 23 >> 24 >> 25 >> 26 >> 27 >> 28 >> 29 >> 30 >> 31 >> 32 >> >> 33 >> 34 >> >> class Address < ActiveRecord::Base >> >> >> #Status Codes as Constants >> JUST_REGISTERED = 0 >> >> DELETED = 1 >> >> DECLINED = 2 >> >> APPROVED = 3 >> >> def status >> >> DELETED >> end >> >> def reset >> #We don't actually delete the record >> #Instead a status field is set >> #And all the data is blanked for data protection reasons >> >> self.status = DELETED >> >> self.business_name = '' >> >> self.first_line = '' >> >> self.second_line = '' >> >> self.town = '' >> >> self.county = '' >> >> self.postcode = '' >> #MR - added in the following fields >> self.lat = 0.0 >> >> self.lng = 0.0 >> >> self.route_id = 0 >> >> self.save >> end >> #.. other code elided >> end >> >> ------------------------------ >> RSpec >> >> 1 >> 2 >> 3 >> 4 >> 5 >> 6 >> 7 >> 8 >> 9 >> 10 >> 11 >> 12 >> 13 >> 14 >> 15 >> 16 >> 17 >> 18 >> 19 >> 20 >> >> require 'spec_helper' >> >> describe Address do >> #Test Fixture - Before Each test Create a Standard Bread with the following attributes and properties >> before(:each) do >> >> @address = { >> >> :business_name => 'business', :first_line => '10, This Street', :second_line=> 'erewhon', :town=> 'town', :county=>'county', >> >> >> :postcode =>'AB12 3CD', :user_id => 1, :lat=>1.01, :lng=>2.02, :status=>Address::JUST_REGISTERED, :route_id=>1 >> >> >> } >> end >> >> >> it "should have a status of deleted after reset" do >> >> @address.reset >> >> @address.status.should == :Address::DELETED >> >> end >> >> >> end >> >> >> >> Thanks David as well, but Tom was right, it was my typing that caused that >> issue. >> >> Regards >> >> Matt >> >> 2009/12/14 Tom Stuart >> >>> On 14 Dec 2009, at 20:36, Matt Riches wrote: >>> >>> > 1) Why are my methods undefined, when they are there (I can create the >>> object via script/console and call the status and reset methods and see them >>> work) >>> > 2) What is the best way of resolving the issue >>> >>> You'd be much better off using pastie.org to show us the real code >>> that's having the problem, because your example contains all sorts of >>> omissions and typos (which is likely to be the sort of thing that causes >>> your problem!) and it's impossible to tell how much of it is wrong in the >>> original code versus how much was introduced by you rewriting it as an >>> example. >>> >>> Cheers, >>> -Tom >>> _______________________________________________ >>> 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 >> > > > > -- > Vishu Ramanathan > co-founder thinklink llc 312.436.1627 > new homepage! ---> thinklinkllc.com > mocklinkr.com makes web mockups come to life > thinklinkr.com is the web-based collaborative outliner > > _______________________________________________ > 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 mattriches at gmail.com Mon Dec 14 16:50:04 2009 From: mattriches at gmail.com (Matt Riches) Date: Mon, 14 Dec 2009 21:50:04 +0000 Subject: [rspec-users] RSPEC and RoR undefined method for hash when running model tests In-Reply-To: References: <5d86970f0912141236j53f50b89vc116efcc9d0c9448@mail.gmail.com> <5d86970f0912141328q2c860224t84799701904c5756@mail.gmail.com> Message-ID: <5d86970f0912141350x5ed6f827r452be829ffec7a64@mail.gmail.com> Yup, I did. Thanks all. (unless anyone has any comments on the constants question I just asked in a previous post?) Regards Matt 2009/12/14 Tom Stuart > On 14 Dec 2009, at 21:28, Matt Riches wrote: > > describe Address do > > #Test Fixture - Before Each test Create a Standard Bread with the > following attributes and properties > > before(:each) do > > @address = { > > :business_name => 'business', :first_line => '10, This Street', > :second_line=> 'erewhon', :town=> 'town', :county=>'county', > > :postcode =>'AB12 3CD', :user_id => 1, :lat=>1.01, :lng=>2.02, > :status=>Address::JUST_REGISTERED, :route_id=>1 > > } > > end > > > > it "should have a status of deleted after reset" do > > @address.reset > > @address.status.should == :Address::DELETED > > end > > end > > The problem is that you're setting @address to a hash, not an instance of > Address. Did you mean @address = Address.new :business_name => ...? > > Cheers, > -Tom > _______________________________________________ > 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 sean at clipperadams.com Mon Dec 14 16:57:36 2009 From: sean at clipperadams.com (DeNigris Sean) Date: Mon, 14 Dec 2009 16:57:36 -0500 Subject: [rspec-users] "have" matcher special case for owned collection with 1 item Message-ID: If I'm reading the docs right, the current implementation would be: my_workspace.should have(1).documents Would it be hard to have it be: my_workspace.should have(1).document ^ (no s) Sean DeNigris sean at clipperadams.com From dchelimsky at gmail.com Tue Dec 15 00:59:55 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 14 Dec 2009 23:59:55 -0600 Subject: [rspec-users] "have" matcher special case for owned collection with 1 item In-Reply-To: References: Message-ID: <57c63afe0912142159s15f95bf3v4ad984bfcbe2781d@mail.gmail.com> On Mon, Dec 14, 2009 at 3:57 PM, DeNigris Sean wrote: > If I'm reading the docs right, the current implementation would be: ?my_workspace.should have(1).documents > > Would it be hard to have it be: ?my_workspace.should have(1).document > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?^ > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?(no s) Should be pretty simple. Why don't you file a feature request at http://rspec.lighthouseapp.com? If you submit a patch w/ specs it'll likely get in sooner than later. > Sean DeNigris > sean at clipperadams.com From rogerpack2005 at gmail.com Tue Dec 15 12:05:43 2009 From: rogerpack2005 at gmail.com (rogerdpack) Date: Tue, 15 Dec 2009 09:05:43 -0800 (PST) Subject: [rspec-users] cleanup pendings? Message-ID: <3e05719a-a809-4c3d-bb1d-f9e61dba65c7@r5g2000yqb.googlegroups.com> Currently with pending... it "should do something"; or it "should do something" do pending "some work" end I get this type of output: Pending: After should immediately return if the other process doesn't exist (Not Yet Implemented) C:/dev/ruby/wait_for/test/spec.after.rb:5:in `block in ' that part in block in is a bit confusing to me. Anyway to get rid of that, or what is going on? Thanks! -r From stefan.kanev at gmail.com Wed Dec 16 11:56:46 2009 From: stefan.kanev at gmail.com (Stefan Kanev) Date: Wed, 16 Dec 2009 17:56:46 +0100 Subject: [rspec-users] spec'ing controllers Message-ID: <285b75bb0912160856k36473d4ag38dc1deb7008a37@mail.gmail.com> Hey guys. I switched completely to RSpec and Cucumber this spring and I am really happy with. While I think I've gotten quite good with it, I'm not sure I understand the value of spec'ing controllers (in Rails). I would appreciate if you can give me some suggestions. Let me elaborate: The RSpec book suggests mocking models and not integrating vies controller specs. Following that, I usually end up with something like this: http://gist.github.com/257946 I see a few benefits: - It helps keeping the controllers simple. For example, while writing that spec I discovered that Topic should have #update_topic_hits (as opposed to inlining it there). That improved the design. - When mocking gets tricky, I treat this as a code smell and start refactoring. Usually it works out well. - Specs are faster. Remembering how much time it took to run the functional tests on an old project, I can really appreciate that. - Small changes in models (or views) don't result in broken controller specs. It took some time, but I can see it now. However, I still don't feel too confident about the way I'm doing it. Some of my worries: - It feels like lots and lots of code. I'm normally at 2:1 test:code, but it feels I'm overdoing it. *feels* is the key word here -- I might be worrying too much. - I have a similar spec for each RESTful controller. Looks like duplication, but I'm not sure what to do about it - Often the specs are passing when the code is broken (due to the mocks). While Cucumber catches those errors for me, I'm not sure if they shouldn't be in the specs in some way. - It's a lot of effort. Eventually ones gets used to it, but I can't decide whether it pays of or not. Can you validate (or invalidate) my reasoning? It will be very nice to hear a comment from more experienced rspec users. Comments on the the spec I posted would be appreciated too, of course. Thanks very much, Stefan -------------- next part -------------- An HTML attachment was scrubbed... URL: From matt at mattwynne.net Wed Dec 16 12:31:04 2009 From: matt at mattwynne.net (Matt Wynne) Date: Wed, 16 Dec 2009 17:31:04 +0000 Subject: [rspec-users] spec'ing controllers In-Reply-To: <285b75bb0912160856k36473d4ag38dc1deb7008a37@mail.gmail.com> References: <285b75bb0912160856k36473d4ag38dc1deb7008a37@mail.gmail.com> Message-ID: On 16 Dec 2009, at 16:56, Stefan Kanev wrote: > Hey guys. > > I switched completely to RSpec and Cucumber this spring and I am > really happy with. While I think I've gotten quite good with it, I'm > not sure I understand the value of spec'ing controllers (in Rails). > I would appreciate if you can give me some suggestions. Let me > elaborate: > > The RSpec book suggests mocking models and not integrating vies > controller specs. Following that, I usually end up with something > like this: http://gist.github.com/257946 > > I see a few benefits: > ? It helps keeping the controllers simple. For example, while > writing that spec I discovered that Topic should have > #update_topic_hits (as opposed to inlining it there). That improved > the design. > ? When mocking gets tricky, I treat this as a code smell and start > refactoring. Usually it works out well. > ? Specs are faster. Remembering how much time it took to run the > functional tests on an old project, I can really appreciate that. > ? Small changes in models (or views) don't result in broken > controller specs. It took some time, but I can see it now. > However, I still don't feel too confident about the way I'm doing > it. Some of my worries: > ? It feels like lots and lots of code. I'm normally at 2:1 > test:code, but it feels I'm overdoing it. *feels* is the key word > here -- I might be worrying too much. > ? I have a similar spec for each RESTful controller. Looks like > duplication, but I'm not sure what to do about it > ? Often the specs are passing when the code is broken (due to the > mocks). While Cucumber catches those errors for me, I'm not sure if > they shouldn't be in the specs in some way. > ? It's a lot of effort. Eventually ones gets used to it, but I > can't decide whether it pays of or not. > Can you validate (or invalidate) my reasoning? It will be very nice > to hear a comment from more experienced rspec users. Comments on the > the spec I posted would be appreciated too, of course. > > Thanks very much, > Stefan Sounds like you've got it just about right to me :) I think the excess overhead thing will pass. Partly because you'll get faster at it, but also partly as your design skill improves (guided by mocks) you'll feel less need to drive out every single change with a unit test, and rely a little more on Cucumber. Your observation about specs passing when mocks are wrong is a common one, and one I remember struggling with when I first learned TDD, but again as you learn to trust Cucumber you'll find that this is OK. cheers, Matt +447974 430184 matt at mattwynne.net http://mattwynne.net From mailinglists at patmaddox.com Wed Dec 16 12:33:56 2009 From: mailinglists at patmaddox.com (Pat Maddox) Date: Wed, 16 Dec 2009 09:33:56 -0800 Subject: [rspec-users] spec'ing controllers In-Reply-To: <285b75bb0912160856k36473d4ag38dc1deb7008a37@mail.gmail.com> References: <285b75bb0912160856k36473d4ag38dc1deb7008a37@mail.gmail.com> Message-ID: <27A5277F-1D92-4B7E-B4AB-2E27A8BB712D@patmaddox.com> http://archive.patmaddox.com/blog/2009/1/15/how-i-test-controllers-2009-remix is my take on things. Due for an update though looks like :) On Dec 16, 2009, at 8:56 AM, Stefan Kanev wrote: > Hey guys. > > I switched completely to RSpec and Cucumber this spring and I am really happy with. While I think I've gotten quite good with it, I'm not sure I understand the value of spec'ing controllers (in Rails). I would appreciate if you can give me some suggestions. Let me elaborate: > > The RSpec book suggests mocking models and not integrating vies controller specs. Following that, I usually end up with something like this: http://gist.github.com/257946 > > I see a few benefits: > It helps keeping the controllers simple. For example, while writing that spec I discovered that Topic should have #update_topic_hits (as opposed to inlining it there). That improved the design. > When mocking gets tricky, I treat this as a code smell and start refactoring. Usually it works out well. > Specs are faster. Remembering how much time it took to run the functional tests on an old project, I can really appreciate that. > Small changes in models (or views) don't result in broken controller specs. It took some time, but I can see it now. > However, I still don't feel too confident about the way I'm doing it. Some of my worries: > It feels like lots and lots of code. I'm normally at 2:1 test:code, but it feels I'm overdoing it. *feels* is the key word here -- I might be worrying too much. > I have a similar spec for each RESTful controller. Looks like duplication, but I'm not sure what to do about it > Often the specs are passing when the code is broken (due to the mocks). While Cucumber catches those errors for me, I'm not sure if they shouldn't be in the specs in some way. > It's a lot of effort. Eventually ones gets used to it, but I can't decide whether it pays of or not. > Can you validate (or invalidate) my reasoning? It will be very nice to hear a comment from more experienced rspec users. Comments on the the spec I posted would be appreciated too, of course. > > Thanks very much, > Stefan > _______________________________________________ > 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 Dec 18 09:35:55 2009 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Fri, 18 Dec 2009 14:35:55 +0000 Subject: [rspec-users] State-based expectations (as per jMock in GOOS) Message-ID: Hi all I'm working my way through Growing Object-Oriented Software[1], currently at the start of chapter 15. Chapter 14 introduces a concept I haven't seen before, state-based expectations based on sent messages. The principle appears to be object O has sent message M => O is in state S followed by O is in state S => (expectation E met) passes spec O is not in state S => (expectation E met) violates spec Has anyone tried this with RSpec (mocks) yet? Just wondered if it was doable with the current syntax support or would need an extension. I thought I'd fire this off now to get ideas, as I won't be coding using this technique until I've finished the book (a week at least, I imagine). Cheers Ashley [1] http://www.amazon.co.uk/gp/product/0321503627/ -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashleymoran From tom at experthuman.com Fri Dec 18 09:46:50 2009 From: tom at experthuman.com (Tom Stuart) Date: Fri, 18 Dec 2009 14:46:50 +0000 Subject: [rspec-users] State-based expectations (as per jMock in GOOS) In-Reply-To: References: Message-ID: <2F2A7824-AD66-494F-829C-BAB860C7E7D5@experthuman.com> On 18 Dec 2009, at 14:35, Ashley Moran wrote: > The principle appears to be > object O has sent message M => O is in state S > followed by > O is in state S => (expectation E met) passes spec > O is not in state S => (expectation E met) violates spec Can you elaborate? From a position of no knowledge, the most obvious question to me is: why would I care about the state of O? Either the change in O's state is observable through its behaviour (in which case I specify that behaviour) or it's not (in which case I don't care). Cheers, -Tom From ashley.moran at patchspace.co.uk Fri Dec 18 10:15:59 2009 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Fri, 18 Dec 2009 15:15:59 +0000 Subject: [rspec-users] State-based expectations (as per jMock in GOOS) In-Reply-To: <2F2A7824-AD66-494F-829C-BAB860C7E7D5@experthuman.com> References: <2F2A7824-AD66-494F-829C-BAB860C7E7D5@experthuman.com> Message-ID: <80F03C90-6CBE-4FC9-ACB7-2E7711B87102@patchspace.co.uk> On Dec 18, 2009, at 2:46 pm, Tom Stuart wrote: > Can you elaborate? From a position of no knowledge, the most obvious question to me is: why would I care about the state of O? Either the change in O's state is observable through its behaviour (in which case I specify that behaviour) or it's not (in which case I don't care). The example given is for an auction sniper (S). So, Given S has just notified one of its listeners that it's bidding When S is informed that a bid has been made by a competitor And the auction is closed Then S should notify its listeners that it lost the auction Given S has just notified one of its listeners that it's bidding When S is informed that its bid is highest And the auction is closed Then S should notify its listeners that it won the auction The last one looks like the code below in Java[1], but note this is further on from the code in chapter 14. Interestingly, writing it as GWT transforms the style of the expectations. eg, "When S is informed that a bid has been made by a competitor" replaces (something like) Allow S to notify its listeners that it's in the bidding state Am I making sense? Not sure if these examples capture the essense. Ashley @Test public void reportsWonIfAuctionClosesWhenWinning() { allowingSniperBidding(); allowingSniperWinning(); ignoringAuction(); context.checking(new Expectations() {{ atLeast(1).of(sniperListener).sniperStateChanged( new SniperSnapshot(ITEM_ID, 135, 135, WON)); when(sniperState.is("winning")); }}); sniper.currentPrice(123, 12, PriceSource.FromOtherBidder); sniper.currentPrice(135, 45, PriceSource.FromSniper); sniper.auctionClosed(); } private void allowingSniperBidding() { allowSniperStateChange(BIDDING, "bidding"); } private void allowingSniperWinning() { allowSniperStateChange(WINNING, "winning"); } private void allowSniperStateChange(final SniperState newState, final String oldState) { context.checking(new Expectations() {{ allowing(sniperListener).sniperStateChanged(with(aSniperThatIs(newState))); then(sniperState.is(oldState)); }}); } [1] http://github.com/sf105/goos-code/blob/master/test/unit/test/auctionsniper/AuctionSniperTest.java -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashleymoran From ashley.moran at patchspace.co.uk Sat Dec 19 20:54:05 2009 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Sun, 20 Dec 2009 01:54:05 +0000 Subject: [rspec-users] State-based expectations (as per jMock in GOOS) In-Reply-To: <2F2A7824-AD66-494F-829C-BAB860C7E7D5@experthuman.com> References: <2F2A7824-AD66-494F-829C-BAB860C7E7D5@experthuman.com> Message-ID: <21CDC753-6E25-494D-A715-DA301FD8CB80@patchspace.co.uk> On 18 Dec 2009, at 14:46, Tom Stuart wrote: > Can you elaborate? From a position of no knowledge, the most obvious question to me is: why would I care about the state of O? Either the change in O's state is observable through its behaviour (in which case I specify that behaviour) or it's not (in which case I don't care). On further investigation (aka reading up to chapter 24) it's apparent that this state-based testing is effectively a flexible form of message expectation ordering. What's clever is that it gives an intermediate level between no ordering and sequential ordering. It's like ordering "sets" of expectations, at least that's how it appears to me at first glance. Worth more investigation, I think... Ashley -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashleymoran From rogerpack2005 at gmail.com Sun Dec 20 00:12:48 2009 From: rogerpack2005 at gmail.com (rogerdpack) Date: Sat, 19 Dec 2009 21:12:48 -0800 (PST) Subject: [rspec-users] no should raise_exception Message-ID: <0ec63fb0-0f54-4304-8286-3e57cfcffa53@b2g2000yqi.googlegroups.com> I know there's a raise_error however...exceptions are not always errors, so I had expected a raise_exception matcher...would this be a reasonable addition (I'd be happy to do it). Thanks. -r From elliot.winkler at gmail.com Sun Dec 20 01:07:14 2009 From: elliot.winkler at gmail.com (Elliot Winkler) Date: Sun, 20 Dec 2009 00:07:14 -0600 Subject: [rspec-users] no should raise_exception In-Reply-To: <0ec63fb0-0f54-4304-8286-3e57cfcffa53@b2g2000yqi.googlegroups.com> References: <0ec63fb0-0f54-4304-8286-3e57cfcffa53@b2g2000yqi.googlegroups.com> Message-ID: <4e78b7b60912192207x3217c51dxa71c1038af415b42@mail.gmail.com> raise_error already catches any type of exception, error or not: ??class BlahException < Exception; end ??class BlahError < StandardError; end lambda { raise BlahException }.should raise_error(BlahException) lambda { raise BlahError }.should raise_error(BlahError) lambda { raise "blah" }.should raise_error(RuntimeError, "blah") -- Elliot On Sat, Dec 19, 2009 at 11:12 PM, rogerdpack wrote: > > I know there's a raise_error > however...exceptions are not always errors, so I had expected a > raise_exception matcher...would this be a reasonable addition (I'd be > happy to do it). > Thanks. > -r > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From ashley.moran at patchspace.co.uk Sun Dec 20 13:51:23 2009 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Sun, 20 Dec 2009 18:51:23 +0000 Subject: [rspec-users] no should raise_exception In-Reply-To: <4e78b7b60912192207x3217c51dxa71c1038af415b42@mail.gmail.com> References: <0ec63fb0-0f54-4304-8286-3e57cfcffa53@b2g2000yqi.googlegroups.com> <4e78b7b60912192207x3217c51dxa71c1038af415b42@mail.gmail.com> Message-ID: On Dec 20, 2009, at 6:07 am, Elliot Winkler wrote: > raise_error already catches any type of exception, error or not: > > class BlahException < Exception; end > class BlahError < StandardError; end > > lambda { raise BlahException }.should raise_error(BlahException) > lambda { raise BlahError }.should raise_error(BlahError) > lambda { raise "blah" }.should raise_error(RuntimeError, "blah") Although it would be unusual to catch non-Error Exceptions in most cases? Most indicate unrecoverable failure; only the SignalException looks like something you might want to catch - I don't know, though. I assume you'd normally register a handler for that. Ashley -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashleymoran From lists at ruby-forum.com Tue Dec 22 06:26:23 2009 From: lists at ruby-forum.com (Gnagno Gnagno) Date: Tue, 22 Dec 2009 12:26:23 +0100 Subject: [rspec-users] spec with user culture Message-ID: <36d804b2ba4c11f72c4d24e6fa858d4c@ruby-forum.com> Hello all, I am making my first experiments with rspec, I wanted to do something like this: when a user visit the home page of my site he will be redirected depending on his culture, so if his culture is english he will be redirected to myapp/en if he is italian to myapp/it and so on.... how can I say this with rspec? I was trying something like: it "should redirect to spanish home page" do get 'index' #don't know how to say the culture is spanish response.should redirect_to(spanish_home_page) end any help? Thanks Gnagno -- Posted via http://www.ruby-forum.com/. From tom at experthuman.com Tue Dec 22 06:41:01 2009 From: tom at experthuman.com (Tom Stuart) Date: Tue, 22 Dec 2009 11:41:01 +0000 Subject: [rspec-users] spec with user culture In-Reply-To: <36d804b2ba4c11f72c4d24e6fa858d4c@ruby-forum.com> References: <36d804b2ba4c11f72c4d24e6fa858d4c@ruby-forum.com> Message-ID: <05636E3B-3C29-4A8F-9521-A0AF64AC5DE1@experthuman.com> On 22 Dec 2009, at 11:26, Gnagno Gnagno wrote: > it "should redirect to spanish home page" do > get 'index' > #don't know how to say the culture is spanish > response.should redirect_to(spanish_home_page) > end How does the application detect the user's "culture"? Cheers, -Tom From lists at ruby-forum.com Tue Dec 22 09:25:12 2009 From: lists at ruby-forum.com (Gnagno Gnagno) Date: Tue, 22 Dec 2009 15:25:12 +0100 Subject: [rspec-users] spec with user culture In-Reply-To: <05636E3B-3C29-4A8F-9521-A0AF64AC5DE1@experthuman.com> References: <36d804b2ba4c11f72c4d24e6fa858d4c@ruby-forum.com> <05636E3B-3C29-4A8F-9521-A0AF64AC5DE1@experthuman.com> Message-ID: <512e58f45378a9d2caa0c04eaa2196e9@ruby-forum.com> Tom Stuart wrote: > How does the application detect the user's "culture"? > > Cheers, > -Tom Thanks for your reply Tom, in my home controller I have a line like this for each language: redirect_to localized_home_page_path :culture => 'es' and return if request.env['HTTP_ACCEPT_LANGUAGE'].include? 'es-ES' as I said before I am just 'experimenting and playing' so any suggestion is accepted :) maybe I should access to the request object from my spec code? -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Tue Dec 22 09:33:32 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 22 Dec 2009 08:33:32 -0600 Subject: [rspec-users] spec with user culture In-Reply-To: <512e58f45378a9d2caa0c04eaa2196e9@ruby-forum.com> References: <36d804b2ba4c11f72c4d24e6fa858d4c@ruby-forum.com> <05636E3B-3C29-4A8F-9521-A0AF64AC5DE1@experthuman.com> <512e58f45378a9d2caa0c04eaa2196e9@ruby-forum.com> Message-ID: <57c63afe0912220633k50bf02eeg84cab7d1c9ec8d1e@mail.gmail.com> On Tue, Dec 22, 2009 at 8:25 AM, Gnagno Gnagno wrote: > Tom Stuart wrote: > > How does the application detect the user's "culture"? > > > > Cheers, > > -Tom > > Thanks for your reply Tom, > > in my home controller I have a line like this for each language: > redirect_to localized_home_page_path :culture => 'es' and return if > request.env['HTTP_ACCEPT_LANGUAGE'].include? 'es-ES' > You can set that explicitly in the example: it "should redirect to spanish home page" do request.env['HTTP_ACCEPT_LANGUAGE'] = 'es-ES' get 'index' response.should redirect_to(spanish_home_page) end HTH, David > > as I said before I am just 'experimenting and playing' so any suggestion > is accepted :) > > > maybe I should access to the request object from my spec code? > > > > -- > 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 peter.fitzgibbons at gmail.com Tue Dec 22 10:14:28 2009 From: peter.fitzgibbons at gmail.com (Peter Fitzgibbons) Date: Tue, 22 Dec 2009 09:14:28 -0600 Subject: [rspec-users] class variables different between spec and runtime? Message-ID: <670a00380912220714x76a03379tcdfcee3d8479656a@mail.gmail.com> Hello Folks, This gist http://gist.github.com/261791 has an example user.rb, user_spec.rb At runtime, this snippet fails u = User.find(123) u.update_with_profile({...}) The error occurred while evaluating nil.select): app/models/user.rb:6:in `moderator_fields' app/models/user.rb:118:in `update_with_profile' The spec passes all-green. Could you tell me how this might be ? Thanks, Peter Fitzgibbons (847) 687-7646 Email: peter.fitzgibbons at gmail.com IM GTalk: peter.fitzgibbons IM AOL: peter.fitzgibbons at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Tue Dec 22 10:22:15 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 22 Dec 2009 09:22:15 -0600 Subject: [rspec-users] class variables different between spec and runtime? In-Reply-To: <670a00380912220714x76a03379tcdfcee3d8479656a@mail.gmail.com> References: <670a00380912220714x76a03379tcdfcee3d8479656a@mail.gmail.com> Message-ID: <57c63afe0912220722sa3b1042qd28235544dc71e3b@mail.gmail.com> On Tue, Dec 22, 2009 at 9:14 AM, Peter Fitzgibbons < peter.fitzgibbons at gmail.com> wrote: > Hello Folks, > > This gist http://gist.github.com/261791 has an example user.rb, > user_spec.rb > At runtime, this snippet fails > > u = User.find(123) > u.update_with_profile({...}) > The error occurred while evaluating nil.select): > app/models/user.rb:6:in `moderator_fields' > app/models/user.rb:118:in `update_with_profile' > > The spec passes all-green. > > Could you tell me how this might be ? > The user in the spec comes from new_with_profile(), which sets instance variables on the User class. The user in the console comes from find(), and those ivars are not yet set. > > Thanks, > > Peter Fitzgibbons > (847) 687-7646 > Email: peter.fitzgibbons at gmail.com > IM GTalk: peter.fitzgibbons > IM AOL: peter.fitzgibbons at gmail.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 Tue Dec 22 10:24:33 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 22 Dec 2009 09:24:33 -0600 Subject: [rspec-users] class variables different between spec and runtime? In-Reply-To: <57c63afe0912220722sa3b1042qd28235544dc71e3b@mail.gmail.com> References: <670a00380912220714x76a03379tcdfcee3d8479656a@mail.gmail.com> <57c63afe0912220722sa3b1042qd28235544dc71e3b@mail.gmail.com> Message-ID: <57c63afe0912220724l2971c8c6x43313e70b32a1f74@mail.gmail.com> On Tue, Dec 22, 2009 at 9:22 AM, David Chelimsky wrote: > > > On Tue, Dec 22, 2009 at 9:14 AM, Peter Fitzgibbons < > peter.fitzgibbons at gmail.com> wrote: > >> Hello Folks, >> >> This gist http://gist.github.com/261791 has an example user.rb, >> user_spec.rb >> At runtime, this snippet fails >> >> u = User.find(123) >> u.update_with_profile({...}) >> The error occurred while evaluating nil.select): >> app/models/user.rb:6:in `moderator_fields' >> app/models/user.rb:118:in `update_with_profile' >> >> The spec passes all-green. >> >> Could you tell me how this might be ? >> > > The user in the spec comes from new_with_profile(), which sets instance > variables on the User class. > > The user in the console comes from find(), and those ivars are not yet set. > Also - @params in the User class (in the class methods) is not the same @params in the User instances (in update_with_profile). HTH, David > > >> >> Thanks, >> >> Peter Fitzgibbons >> (847) 687-7646 >> Email: peter.fitzgibbons at gmail.com >> IM GTalk: peter.fitzgibbons >> IM AOL: peter.fitzgibbons at gmail.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 rick.denatale at gmail.com Tue Dec 22 10:30:41 2009 From: rick.denatale at gmail.com (Rick DeNatale) Date: Tue, 22 Dec 2009 10:30:41 -0500 Subject: [rspec-users] class variables different between spec and runtime? In-Reply-To: <57c63afe0912220724l2971c8c6x43313e70b32a1f74@mail.gmail.com> References: <670a00380912220714x76a03379tcdfcee3d8479656a@mail.gmail.com> <57c63afe0912220722sa3b1042qd28235544dc71e3b@mail.gmail.com> <57c63afe0912220724l2971c8c6x43313e70b32a1f74@mail.gmail.com> Message-ID: On Tue, Dec 22, 2009 at 10:24 AM, David Chelimsky wrote: > > > On Tue, Dec 22, 2009 at 9:22 AM, David Chelimsky > wrote: >> >> >> On Tue, Dec 22, 2009 at 9:14 AM, Peter Fitzgibbons >> wrote: >>> >>> Hello Folks, >>> >>> This gist http://gist.github.com/261791 has an example user.rb, >>> user_spec.rb >>> At runtime, this snippet fails >>> >>> u = User.find(123) >>> u.update_with_profile({...}) >>> The error occurred while evaluating nil.select): >>> ? app/models/user.rb:6:in `moderator_fields' >>> ? app/models/user.rb:118:in `update_with_profile' >>> >>> The spec passes all-green. >>> >>> Could you tell me how this might be ? >> >> The user in the spec comes from?new_with_profile(), which sets instance >> variables on the User class. >> The user in the console comes from find(), and those ivars are not yet >> set. > > Also - @params in the User class (in the class methods) is not the same > @params in the User instances (in update_with_profile). > HTH, > David Also counting on class variables to retain state in Rails is a recipe for disaster. -- 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 Tue Dec 22 10:33:30 2009 From: rogerpack2005 at gmail.com (rogerdpack) Date: Tue, 22 Dec 2009 07:33:30 -0800 (PST) Subject: [rspec-users] no should raise_exception In-Reply-To: <4e78b7b60912192207x3217c51dxa71c1038af415b42@mail.gmail.com> References: <0ec63fb0-0f54-4304-8286-3e57cfcffa53@b2g2000yqi.googlegroups.com> <4e78b7b60912192207x3217c51dxa71c1038af415b42@mail.gmail.com> Message-ID: > raise_error already catches any type of exception, error or not: > > ??class BlahException < Exception; end > ??class BlahError < StandardError; end > > ? lambda { raise BlahException }.should raise_error(BlahException) > ? lambda { raise BlahError }.should raise_error(BlahError) > ? lambda { raise "blah" }.should raise_error(RuntimeError, "blah") Thanks for the response. I think my request was more of a "why call them errors--in my head one doesn't raise errors--one raises exceptions and interprets them as errors, so allowing for the syntax raise_exception would be more mind friendly to me." -r From rogerpack2005 at gmail.com Tue Dec 22 10:35:18 2009 From: rogerpack2005 at gmail.com (rogerdpack) Date: Tue, 22 Dec 2009 07:35:18 -0800 (PST) Subject: [rspec-users] concept of given Message-ID: <0d9c77f2-5e59-49d9-8d3e-7de9f83bb885@d21g2000yqn.googlegroups.com> Forgive me if the question is a common one... does rspec have any concept like given "a certain set of paths" do it "should be able to recreate them" do; end it "..."; end end ? Thanks. -r From dchelimsky at gmail.com Tue Dec 22 10:36:01 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 22 Dec 2009 09:36:01 -0600 Subject: [rspec-users] class variables different between spec and runtime? In-Reply-To: References: <670a00380912220714x76a03379tcdfcee3d8479656a@mail.gmail.com> <57c63afe0912220722sa3b1042qd28235544dc71e3b@mail.gmail.com> <57c63afe0912220724l2971c8c6x43313e70b32a1f74@mail.gmail.com> Message-ID: <57c63afe0912220736k47b7341ne6fc79385173d207@mail.gmail.com> On Tue, Dec 22, 2009 at 9:30 AM, Rick DeNatale wrote: > Also counting on class variables to retain state in Rails is a recipe > for disaster. > Did you read that in rails recipes? :-/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Tue Dec 22 10:38:12 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 22 Dec 2009 09:38:12 -0600 Subject: [rspec-users] concept of given In-Reply-To: <0d9c77f2-5e59-49d9-8d3e-7de9f83bb885@d21g2000yqn.googlegroups.com> References: <0d9c77f2-5e59-49d9-8d3e-7de9f83bb885@d21g2000yqn.googlegroups.com> Message-ID: <57c63afe0912220738j6fdbdca8y22821da2e377e98e@mail.gmail.com> On Tue, Dec 22, 2009 at 9:35 AM, rogerdpack wrote: > Forgive me if the question is a common one... > > does rspec have any concept like > > given "a certain set of paths" do > > it "should be able to recreate them" do; end > it "..."; end > end > Not built into rspec. There is a merb extension that does that, but there is no "when" and "then" counterpart, so I didn't want to add it to rspec. HTH, David > ? > Thanks. > -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 rick.denatale at gmail.com Tue Dec 22 11:15:53 2009 From: rick.denatale at gmail.com (Rick DeNatale) Date: Tue, 22 Dec 2009 11:15:53 -0500 Subject: [rspec-users] concept of given In-Reply-To: <57c63afe0912220738j6fdbdca8y22821da2e377e98e@mail.gmail.com> References: <0d9c77f2-5e59-49d9-8d3e-7de9f83bb885@d21g2000yqn.googlegroups.com> <57c63afe0912220738j6fdbdca8y22821da2e377e98e@mail.gmail.com> Message-ID: On Tue, Dec 22, 2009 at 10:38 AM, David Chelimsky wrote: > On Tue, Dec 22, 2009 at 9:35 AM, rogerdpack wrote: >> >> Forgive me if the question is a common one... >> >> does rspec have any concept like >> >> given "a certain set of paths" do >> >> ?it "should be able to recreate them" do; end >> ?it "..."; end >> end > > Not built into rspec. There is a merb extension that does that, but there is > no "when" and "then" counterpart, so I didn't want to add it to rspec. It looks like that merb extension was about injecting a part of a before block by adding an option to describe, yes? http://www.mail-archive.com/rspec-users at rubyforge.org/msg07327.html I don't see that that's what Roger is asking for though. It seems to me that he's asking more for yet another synonym for describe or context. In which case I'd suggest just using describe or context as in: context "given a certain set of paths" do before(:each) do # code to set up the paths however the included specs need them, e.g. @paths = ["a/b", "c/d"] end it "should be able to recreate them" do; end it "..."; end end I tend to use describe for the top level, and context when nested. -- 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 Tue Dec 22 11:19:08 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 22 Dec 2009 10:19:08 -0600 Subject: [rspec-users] concept of given In-Reply-To: References: <0d9c77f2-5e59-49d9-8d3e-7de9f83bb885@d21g2000yqn.googlegroups.com> <57c63afe0912220738j6fdbdca8y22821da2e377e98e@mail.gmail.com> Message-ID: <57c63afe0912220819u50dc5294m95b61dfa48295d26@mail.gmail.com> On Tue, Dec 22, 2009 at 10:15 AM, Rick DeNatale wrote: > On Tue, Dec 22, 2009 at 10:38 AM, David Chelimsky > wrote: > > On Tue, Dec 22, 2009 at 9:35 AM, rogerdpack > wrote: > >> > >> Forgive me if the question is a common one... > >> > >> does rspec have any concept like > >> > >> given "a certain set of paths" do > >> > >> it "should be able to recreate them" do; end > >> it "..."; end > >> end > > > > Not built into rspec. There is a merb extension that does that, but there > is > > no "when" and "then" counterpart, so I didn't want to add it to rspec. > > It looks like that merb extension was about injecting a part of a > before block by adding an option to describe, yes? > http://www.mail-archive.com/rspec-users at rubyforge.org/msg07327.html > > I don't see that that's what Roger is asking for though. It seems to > me that he's asking more for yet another synonym for describe or > context. > > In which case I'd suggest just using describe or context as in: > > context "given a certain set of paths" do > before(:each) do > # code to set up the paths however the included specs need them, e.g. > @paths = ["a/b", "c/d"] > end > > it "should be able to recreate them" do; end > it "..."; end > end > > I tend to use describe for the top level, and context when nested. > Ah - I see what you mean. Though, I tend to use describe() for nouns and context for context. describe "something" do context "in some state" do Usuall that works out that the outer block starts w/ describe and the inner starts w/ context, but sometimes there are describe blocks nested within describe blocks as well. -- > 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 > _______________________________________________ > 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 Tue Dec 22 11:31:04 2009 From: rogerpack2005 at gmail.com (rogerdpack) Date: Tue, 22 Dec 2009 08:31:04 -0800 (PST) Subject: [rspec-users] concept of given In-Reply-To: References: <0d9c77f2-5e59-49d9-8d3e-7de9f83bb885@d21g2000yqn.googlegroups.com> <57c63afe0912220738j6fdbdca8y22821da2e377e98e@mail.gmail.com> Message-ID: > context "given a certain set of paths" do Ahh so it's called context. Cool (though I'll admit that naming it "given" can make it sound more like an English sentence, so an alias would be a suggestion). Much thanks. -r From dchelimsky at gmail.com Tue Dec 22 11:34:59 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 22 Dec 2009 10:34:59 -0600 Subject: [rspec-users] concept of given In-Reply-To: References: <0d9c77f2-5e59-49d9-8d3e-7de9f83bb885@d21g2000yqn.googlegroups.com> <57c63afe0912220738j6fdbdca8y22821da2e377e98e@mail.gmail.com> Message-ID: <57c63afe0912220834k2227ee09mb8b533202abd9be@mail.gmail.com> On Tue, Dec 22, 2009 at 10:31 AM, rogerdpack wrote: > > > context "given a certain set of paths" do > > Ahh so it's called context. > > Cool (though I'll admit that naming it "given" can make it sound more > like an English sentence, so an alias would be a suggestion). > http://gist.github.com/206969 I'm not adding that to rspec though, as we already have enough confusion just between context and describe :) Cheers, David > Much thanks. > -r > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From peter.fitzgibbons at gmail.com Tue Dec 22 13:51:45 2009 From: peter.fitzgibbons at gmail.com (Peter Fitzgibbons) Date: Tue, 22 Dec 2009 12:51:45 -0600 Subject: [rspec-users] class variables different between spec and runtime? In-Reply-To: <57c63afe0912220724l2971c8c6x43313e70b32a1f74@mail.gmail.com> References: <670a00380912220714x76a03379tcdfcee3d8479656a@mail.gmail.com> <57c63afe0912220722sa3b1042qd28235544dc71e3b@mail.gmail.com> <57c63afe0912220724l2971c8c6x43313e70b32a1f74@mail.gmail.com> Message-ID: <670a00380912221051y2c9569f4n44af757368c19896@mail.gmail.com> DOH! Thanks David, Happy Holidays! Peter Fitzgibbons (847) 687-7646 Email: peter.fitzgibbons at gmail.com IM GTalk: peter.fitzgibbons IM AOL: peter.fitzgibbons at gmail.com On Tue, Dec 22, 2009 at 9:24 AM, David Chelimsky wrote: > > > On Tue, Dec 22, 2009 at 9:22 AM, David Chelimsky wrote: > >> >> >> On Tue, Dec 22, 2009 at 9:14 AM, Peter Fitzgibbons < >> peter.fitzgibbons at gmail.com> wrote: >> >>> Hello Folks, >>> >>> This gist http://gist.github.com/261791 has an example user.rb, >>> user_spec.rb >>> At runtime, this snippet fails >>> >>> u = User.find(123) >>> u.update_with_profile({...}) >>> The error occurred while evaluating nil.select): >>> app/models/user.rb:6:in `moderator_fields' >>> app/models/user.rb:118:in `update_with_profile' >>> >>> The spec passes all-green. >>> >>> Could you tell me how this might be ? >>> >> >> The user in the spec comes from new_with_profile(), which sets instance >> variables on the User class. >> >> The user in the console comes from find(), and those ivars are not yet >> set. >> > > Also - @params in the User class (in the class methods) is not the same > @params in the User instances (in update_with_profile). > > HTH, > David > > >> >> >>> >>> Thanks, >>> >>> Peter Fitzgibbons >>> (847) 687-7646 >>> Email: peter.fitzgibbons at gmail.com >>> IM GTalk: peter.fitzgibbons >>> IM AOL: peter.fitzgibbons at gmail.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 > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Tue Dec 22 17:08:49 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 22 Dec 2009 16:08:49 -0600 Subject: [rspec-users] no should raise_exception In-Reply-To: References: <0ec63fb0-0f54-4304-8286-3e57cfcffa53@b2g2000yqi.googlegroups.com> <4e78b7b60912192207x3217c51dxa71c1038af415b42@mail.gmail.com> Message-ID: <57c63afe0912221408m4e23b599qd9b0f56b847aa26a@mail.gmail.com> On Tue, Dec 22, 2009 at 9:33 AM, rogerdpack wrote: > > raise_error already catches any type of exception, error or not: > > > > class BlahException < Exception; end > > class BlahError < StandardError; end > > > > lambda { raise BlahException }.should raise_error(BlahException) > > lambda { raise BlahError }.should raise_error(BlahError) > > lambda { raise "blah" }.should raise_error(RuntimeError, "blah") > > Thanks for the response. I think my request was more of a "why call > them errors--in my head one doesn't raise errors--one raises > exceptions and interprets them as errors, so allowing for the syntax > raise_exception would be more mind friendly to me." > What I really want to say is "should raise(Blah)" but Ruby already defines raise as a keyword :) I'd be open to aliasing raise_error with raise_exception, renaming it to raise_exception and aliasing raise_error for compatibility, but I think this might just add confusion rather than clarifying intent. Thoughts? David > -r > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Wed Dec 23 05:01:59 2009 From: lists at ruby-forum.com (Gnagno Gnagno) Date: Wed, 23 Dec 2009 11:01:59 +0100 Subject: [rspec-users] spec with user culture In-Reply-To: <57c63afe0912220633k50bf02eeg84cab7d1c9ec8d1e@mail.gmail.com> References: <36d804b2ba4c11f72c4d24e6fa858d4c@ruby-forum.com> <05636E3B-3C29-4A8F-9521-A0AF64AC5DE1@experthuman.com> <512e58f45378a9d2caa0c04eaa2196e9@ruby-forum.com> <57c63afe0912220633k50bf02eeg84cab7d1c9ec8d1e@mail.gmail.com> Message-ID: Thank you very much :) I didn't know I could access request.env['HTTP_ACCEPT_LANGUAGE'] in writing, and didn't even try it -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Wed Dec 23 05:07:38 2009 From: lists at ruby-forum.com (Gnagno Gnagno) Date: Wed, 23 Dec 2009 11:07:38 +0100 Subject: [rspec-users] spec with user culture In-Reply-To: References: <36d804b2ba4c11f72c4d24e6fa858d4c@ruby-forum.com> <05636E3B-3C29-4A8F-9521-A0AF64AC5DE1@experthuman.com> <512e58f45378a9d2caa0c04eaa2196e9@ruby-forum.com> <57c63afe0912220633k50bf02eeg84cab7d1c9ec8d1e@mail.gmail.com> Message-ID: <34e57c323e388687505f941fa0a5097c@ruby-forum.com> Sorry, I have one more question, I didn't find the cucumber forum, so please forgive me if I am too much out of topic here. I was trying to achieve the same with cucumber, so I wrote this: Scenario Outline: visit home page and get redirect to localized home page Given my culture is When I go to the home page Then I should be redirected to the Examples: | culture | page | | italian | italian_home_page | | english | english_home_page | | french | french_home_page | | spanish | spanish_home_page | | german | german_home_page | | japanese | japanese_home_page | but I cannot access request.env from a cucumber step, and moreover I think accessing to request.env from cucumber could tie it too much to the application, am I right? -- Posted via http://www.ruby-forum.com/. From matt at mattwynne.net Wed Dec 23 05:14:47 2009 From: matt at mattwynne.net (Matt Wynne) Date: Wed, 23 Dec 2009 10:14:47 +0000 Subject: [rspec-users] spec with user culture In-Reply-To: <34e57c323e388687505f941fa0a5097c@ruby-forum.com> References: <36d804b2ba4c11f72c4d24e6fa858d4c@ruby-forum.com> <05636E3B-3C29-4A8F-9521-A0AF64AC5DE1@experthuman.com> <512e58f45378a9d2caa0c04eaa2196e9@ruby-forum.com> <57c63afe0912220633k50bf02eeg84cab7d1c9ec8d1e@mail.gmail.com> <34e57c323e388687505f941fa0a5097c@ruby-forum.com> Message-ID: On 23 Dec 2009, at 10:07, Gnagno Gnagno wrote: > Sorry, I have one more question, > > I didn't find the cucumber forum, so please forgive me if I am too > much > out of topic here. http://wiki.github.com/aslakhellesoy/cucumber/get-in-touch > I was trying to achieve the same with cucumber, so I wrote this: > > Scenario Outline: visit home page and get redirect to localized home > page > Given my culture is > When I go to the home page > Then I should be redirected to the > > Examples: > | culture | page | > | italian | italian_home_page | > | english | english_home_page | > | french | french_home_page | > | spanish | spanish_home_page | > | german | german_home_page | > | japanese | japanese_home_page | > > but I cannot access request.env from a cucumber step, and moreover I > think accessing to request.env from cucumber could tie it too much to > the application, am I right? Right. You need to ask the cukes group (or the webrat group, or the rails group) about how you pass HTTP headers with your in the step "When I go to the home page". > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > 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 Wed Dec 23 07:34:53 2009 From: lists at ruby-forum.com (Gnagno Gnagno) Date: Wed, 23 Dec 2009 13:34:53 +0100 Subject: [rspec-users] spec with user culture In-Reply-To: <34e57c323e388687505f941fa0a5097c@ruby-forum.com> References: <36d804b2ba4c11f72c4d24e6fa858d4c@ruby-forum.com> <05636E3B-3C29-4A8F-9521-A0AF64AC5DE1@experthuman.com> <512e58f45378a9d2caa0c04eaa2196e9@ruby-forum.com> <57c63afe0912220633k50bf02eeg84cab7d1c9ec8d1e@mail.gmail.com> <34e57c323e388687505f941fa0a5097c@ruby-forum.com> Message-ID: <348422319c120a0670dba38d78564710@ruby-forum.com> I solved the question concerning cucumber, I will post here the solution in case someone else will need it: in my step definitions I just put: Given /^my culture is (.+)$/ do |culture| header "HTTP_ACCEPT_LANGUAGE", "it-IT" if culture == 'italian' header "HTTP_ACCEPT_LANGUAGE", "en-GB" if culture == 'english' header "HTTP_ACCEPT_LANGUAGE", "fr-FR" if culture == 'french' header "HTTP_ACCEPT_LANGUAGE", "es-ES" if culture == 'spanish' header "HTTP_ACCEPT_LANGUAGE", "de-DE" if culture == 'german' header "HTTP_ACCEPT_LANGUAGE", "en-US" if culture == 'american' header "HTTP_ACCEPT_LANGUAGE", "jp-JP" if culture == 'japanese' end and it works :) -- Posted via http://www.ruby-forum.com/. From mailinglists at patmaddox.com Wed Dec 23 11:35:03 2009 From: mailinglists at patmaddox.com (Pat Maddox) Date: Wed, 23 Dec 2009 08:35:03 -0800 Subject: [rspec-users] no should raise_exception In-Reply-To: <57c63afe0912221408m4e23b599qd9b0f56b847aa26a@mail.gmail.com> References: <0ec63fb0-0f54-4304-8286-3e57cfcffa53@b2g2000yqi.googlegroups.com> <4e78b7b60912192207x3217c51dxa71c1038af415b42@mail.gmail.com> <57c63afe0912221408m4e23b599qd9b0f56b847aa26a@mail.gmail.com> Message-ID: <80D30B12-2E11-4D1A-9B79-AFEA42B19589@patmaddox.com> On Dec 22, 2009, at 2:08 PM, David Chelimsky wrote: > On Tue, Dec 22, 2009 at 9:33 AM, rogerdpack wrote: > > raise_error already catches any type of exception, error or not: > > > > class BlahException < Exception; end > > class BlahError < StandardError; end > > > > lambda { raise BlahException }.should raise_error(BlahException) > > lambda { raise BlahError }.should raise_error(BlahError) > > lambda { raise "blah" }.should raise_error(RuntimeError, "blah") > > Thanks for the response. I think my request was more of a "why call > them errors--in my head one doesn't raise errors--one raises > exceptions and interprets them as errors, so allowing for the syntax > raise_exception would be more mind friendly to me." > > What I really want to say is "should raise(Blah)" but Ruby already defines raise as a keyword :) > > I'd be open to aliasing raise_error with raise_exception, renaming it to raise_exception and aliasing raise_error for compatibility, but I think this might just add confusion rather than clarifying intent. Thoughts? lambda { raise BlahException }.should raise_error(BlahException) is perfectly readable. I don't see why you would need to change anything to make it more so. An alias provides no extra value. And raise_error should only pass on StandardError or subclasses if no class is specified. Ruby makes you specify the class if it's an Exception, and Ruby semantics should be RSpec defaults. Pat p.s. I don't know if raise_error should even allow you to skip the error type. I've seen way too many tests that look like it "should raise an error" do lambda { foo.stupid_typo_that_will_raise_a(NoMethodError) foo.some_method_that_raises(TheRealError) }.should raise_error end But that's another thread -------------- next part -------------- An HTML attachment was scrubbed... URL: From dgoldie15 at gmail.com Thu Dec 24 01:09:43 2009 From: dgoldie15 at gmail.com (Doug) Date: Wed, 23 Dec 2009 22:09:43 -0800 (PST) Subject: [rspec-users] be_true and be_false are suddenly undefined Message-ID: <18dffef7-0450-4097-9cab-17cfdc722d7a@s21g2000prm.googlegroups.com> after upgrading cucumber to 5.1 be_true and be_false are undefined switching to == true or == false works. ??? thanks. Then there is an invalid item with 1 "upc" error # features/step_definitions/extract_steps.rb: 56 undefined method `be_true' for # (NoMethodError) ./features/step_definitions/extract_steps.rb:45:in `/^retrieve file$/' Then /^retrieve file$/ do basename = File.basename(@filename) ExtractReport.exists?(:file_name => basename).should == true **** this is line 45 @file = ExtractReport.find_by_file_name(basename) count = @file.record_count.to_i - 2 # count includes header and trailer @file.should have(count).items end From lists at ruby-forum.com Thu Dec 24 02:45:39 2009 From: lists at ruby-forum.com (Juanma Cervera) Date: Thu, 24 Dec 2009 08:45:39 +0100 Subject: [rspec-users] Spec'ing Inherited Resource Controllers Message-ID: <442b53a5015730f6aa6918da75fccfb8@ruby-forum.com> Hello, I am trying to write the specs for controllers that use InheritedResource. Can somebody tell me if this is possible? I have read that I have to use integrated_views, but even in that case it doesn't work. I have posted a message in the InheritedResources group and Jose Valim, has answered, telling something about responders used in InheritedResources and Rails 3. This is the link for the message in that group. http://groups.google.es/group/inherited_resources/browse_thread/thread/1f2b7c18478896bb The sample specs are written with Remarkable (only for give a shorter example), but the problems are the same when I write specs like in the Rspec book. response.should redirect_to(path) and response.should render_template("new") both fails. I would thank anybody that could give me some clue for a solution that I could try. And a question, which is the state of rspec with Rails 3? Is this going to change and I have to pospone the use of rspec with InheritedResource until then? Thank you very much. Juan M. Cervera -- Posted via http://www.ruby-forum.com/. From matt at mattwynne.net Thu Dec 24 04:14:21 2009 From: matt at mattwynne.net (Matt Wynne) Date: Thu, 24 Dec 2009 09:14:21 +0000 Subject: [rspec-users] be_true and be_false are suddenly undefined In-Reply-To: <18dffef7-0450-4097-9cab-17cfdc722d7a@s21g2000prm.googlegroups.com> References: <18dffef7-0450-4097-9cab-17cfdc722d7a@s21g2000prm.googlegroups.com> Message-ID: On 24 Dec 2009, at 06:09, Doug wrote: > after upgrading cucumber to 5.1 be_true and be_false are undefined > switching to == true or == false works. > > ??? thanks. The rails integration changed quite a bit for that release. See [1] plus a few recent threads on this list. It sounds like your specific problem is you don't have rspec's matchers required anymore. [1] http://wiki.github.com/aslakhellesoy/cucumber/upgrading > > > Then there is an invalid item with 1 "upc" > error # features/step_definitions/ > extract_steps.rb: > 56 > undefined method `be_true' for > # (NoMethodError) > ./features/step_definitions/extract_steps.rb:45:in `/^retrieve > file$/' > > > > Then /^retrieve file$/ do > basename = File.basename(@filename) > ExtractReport.exists?(:file_name => basename).should == > true **** this is line 45 > @file = ExtractReport.find_by_file_name(basename) > count = @file.record_count.to_i - 2 # count includes header and > trailer > @file.should have(count).items > end > _______________________________________________ > 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 Dec 24 06:29:43 2009 From: lists at ruby-forum.com (Amit Kulkarni) Date: Thu, 24 Dec 2009 12:29:43 +0100 Subject: [rspec-users] Problem with Before Filters In-Reply-To: <57c63afe0912141125q62b92938o37a90a876d237bac@mail.gmail.com> References: <7c7324efe6944c042c05cc925af1cbe5@ruby-forum.com> <57c63afe0912100151t142af49ds259ef7d9ddfe2953@mail.gmail.com> <39be7cb7deb7e167fe2adfe9bc610316@ruby-forum.com> <57c63afe0912141125q62b92938o37a90a876d237bac@mail.gmail.com> Message-ID: Thanks a lot David. I am now getting familiar with before filters. I am writing spec without using mocks so i need to just pass the proper parameter to get pass the filter. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Thu Dec 24 06:38:31 2009 From: lists at ruby-forum.com (Amit Kulkarni) Date: Thu, 24 Dec 2009 12:38:31 +0100 Subject: [rspec-users] undefined method `route_for In-Reply-To: <88fd8ddc0912140201h50f43ef6wf17494c885d0db76@mail.gmail.com> References: <57c63afe0911100659s296f97e2i96827851ea429bd@mail.gmail.com> <57c63afe0911110446n57225546ib288100d05cee61c@mail.gmail.com> <4A036CC1-A71C-48A8-A511-5CB829C8DEF8@gmail.com> <57c63afe0911121957h1449181bm93a1eb2f8a1fe3c9@mail.gmail.com> <1c7ec52a97eaaf0945deaa7461ba76c4@ruby-forum.com> <57c63afe0911122356n78f5c09fk89abea677f702dea@mail.gmail.com> <57c63afe0911130639w1168fdbav5aebcb019f563eb@mail.gmail.com> <37480320c538326c804860007ae1e26b@ruby-forum.com> <097b6352040480b2f8a6f78ea85769cd@ruby-forum.com> <57c63afe0911170711k4f04bdb8weadb244ccab7d540@mail.gmail.com> <5d0aadafba7ad1b891fca2111c341e9f@ruby-forum.com> <57c63afe0911260501g764cb865q8f500247bced26bd@mail.gmail.com> <57c63afe0912070410q39801df8yfae88c8b53f896fc@mail.gmail.com> <88fd8ddc0912140201h50f43ef6wf17494c885d0db76@mail.gmail.com> Message-ID: Yes,Thanks a lot Andrew. The last two lines were not commented in routes.rb because of that it was matching default.Now i commented out those line and it was catching if undefined routes are given. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Thu Dec 24 06:39:52 2009 From: lists at ruby-forum.com (Amit Kulkarni) Date: Thu, 24 Dec 2009 12:39:52 +0100 Subject: [rspec-users] Display Rspec output in an html file In-Reply-To: <57c63afe0911270258r73d1b432wdbcc999a93a8bdd8@mail.gmail.com> References: <6bb97fe564ebbb30e16ad7e753473ca0@ruby-forum.com> <6E9E130A-B144-4AAC-9EEF-CA69E189D553@mattwynne.net> <744c997fb5fe43cbb5987ef33930c18b@ruby-forum.com> <57c63afe0911270258r73d1b432wdbcc999a93a8bdd8@mail.gmail.com> Message-ID: <519fdc75a55cf41ee085070ec152b883@ruby-forum.com> Ok.Thanks a lot David -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Thu Dec 24 08:50:34 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 24 Dec 2009 07:50:34 -0600 Subject: [rspec-users] Spec'ing Inherited Resource Controllers In-Reply-To: <442b53a5015730f6aa6918da75fccfb8@ruby-forum.com> References: <442b53a5015730f6aa6918da75fccfb8@ruby-forum.com> Message-ID: <57c63afe0912240550x3d79f03aoa6ec2f4d3986f445@mail.gmail.com> On Thu, Dec 24, 2009 at 1:45 AM, Juanma Cervera wrote: > Hello, > > I am trying to write the specs for controllers that use > InheritedResource. > Can somebody tell me if this is possible? > I have read that I have to use integrated_views, but even in that case > it doesn't work. > I have posted a message in the InheritedResources group and Jose Valim, > has answered, telling something about responders used in > InheritedResources and Rails 3. > > This is the link for the message in that group. > > http://groups.google.es/group/inherited_resources/browse_thread/thread/1f2b7c18478896bb > > The sample specs are written with Remarkable (only for give a shorter > example), but the problems are the same when I write specs like in the > Rspec book. > response.should redirect_to(path) > and response.should render_template("new") both fails. > > I would thank anybody that could give me some clue for a solution that I > could try. > And a question, which is the state of rspec with Rails 3? > Is this going to change and I have to pospone the use of rspec with > InheritedResource until then? > I haven't taken the time to look at inherited resources yet, so I can't help you with that issue. As Jos? suggests, rspec does not monkey patch render if integrate_views is set to true, so I'm not sure what the conflict would be. In terms of rspec-rails for rails 3, we haven't started work on it yet, but plans are being formulated as we speak, and I'll be posting about them soon. Loosely, the plan is to do a preview release shortly after the initial rails-3 preview release, and then a final release of rspec-rails-2.0 right after the final release of rails-3.0. This will be a significant re-write of the rspec-rails, and will rely primarily on APIs exposed by rspec and rails, which should help to avoid conflicts like the one you are now experiencing. Cheers, David Thank you very much. > Juan M. Cervera > -- > 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 dgoldie15 at gmail.com Fri Dec 25 03:09:27 2009 From: dgoldie15 at gmail.com (Doug) Date: Fri, 25 Dec 2009 00:09:27 -0800 (PST) Subject: [rspec-users] be_true and be_false are suddenly undefined In-Reply-To: References: <18dffef7-0450-4097-9cab-17cfdc722d7a@s21g2000prm.googlegroups.com> Message-ID: <3f0ca8d6-f401-4b86-bb88-cb31cc582982@d4g2000pra.googlegroups.com> I agree.... I did notice that my feature/support/my_env.rb (custom) had: require 'spec' require 'spec/rails' so I changed first line require 'spec/autorun' in keeping with http://wiki.github.com/dchelimsky/rspec/configgem-for-rails seems to me that really should do it, but it doesn't work.???? I've tried requiring spec_helper, etc. putting the requires closer to my code.,etc. nothing works!!!! btw: be_true and be_false work in my existing spec test; it's just in cucumber steps. ???? On Dec 24, 1:14?am, Matt Wynne wrote: > On 24 Dec 2009, at 06:09, Doug wrote: > > > after upgrading cucumber to 5.1 be_true and be_false are undefined > > switching to == true ?or == false works. > > > ??? thanks. > > The rails integration changed quite a bit for that release. See [1] ? > plus a few recent threads on this list. > > It sounds like your specific problem is you don't have rspec's ? > matchers required anymore. > > [1]http://wiki.github.com/aslakhellesoy/cucumber/upgrading > > > > > > > ? ?Then there is an invalid item with 1 "upc" > > error ? ? ? ? ? ? ? ? ? ? # features/step_definitions/ > > extract_steps.rb: > > 56 > > ? ? ?undefined method `be_true' for > > # (NoMethodError) > > ? ? ?./features/step_definitions/extract_steps.rb:45:in `/^retrieve > > file$/' > > > Then /^retrieve file$/ do > > ?basename = File.basename(@filename) > > ?ExtractReport.exists?(:file_name => basename).should == > > true ? ? ? ? ? ? ? ? ? **** this is line 45 > > ?@file = ExtractReport.find_by_file_name(basename) > > ?count = @file.record_count.to_i - 2 # count includes header and > > trailer > > ?@file.should have(count).items > > end > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > cheers, > Matt > > http://mattwynne.net > +447974 430184 > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From aslak.hellesoy at gmail.com Fri Dec 25 05:45:29 2009 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Fri, 25 Dec 2009 11:45:29 +0100 Subject: [rspec-users] be_true and be_false are suddenly undefined In-Reply-To: <3f0ca8d6-f401-4b86-bb88-cb31cc582982@d4g2000pra.googlegroups.com> References: <18dffef7-0450-4097-9cab-17cfdc722d7a@s21g2000prm.googlegroups.com> <3f0ca8d6-f401-4b86-bb88-cb31cc582982@d4g2000pra.googlegroups.com> Message-ID: <8d961d900912250245u7e61b732rc8cbb62fec206cd9@mail.gmail.com> > I agree.... > > I did notice that my feature/support/my_env.rb (custom) had: > require 'spec' > require 'spec/rails' > > so I changed first line > require 'spec/autorun' > > You shouldn't do that. You don't want the RSpec runner to run when you're using Cucumber. In fact, you shouldn't do any RSpec requires in my_env.rb at all - all that setup is done in env.rb. > in keeping with > http://wiki.github.com/dchelimsky/rspec/configgem-for-rails > > seems to me that really should do it, but it doesn't work.???? > I'm assuming you have followed the upgrade instructions that Matt mentioned. However your setup still seems broken so I'm wondering if you succeeded. Could you pastie or gist your env.rb and my_env.rb files so we can take a peek? I've tried requiring spec_helper, etc. putting the requires closer to > my code.,etc. > You should never load your spec_helper.rb from Cucumber. > > nothing works!!!! > > btw: be_true and be_false work in my existing spec test; it's just in > cucumber steps. > > ???? > > > > On Dec 24, 1:14 am, Matt Wynne wrote: > > On 24 Dec 2009, at 06:09, Doug wrote: > > > > > after upgrading cucumber to 5.1 be_true and be_false are undefined > > > switching to == true or == false works. > > > > > ??? thanks. > > > > The rails integration changed quite a bit for that release. See [1] > > plus a few recent threads on this list. > > > > It sounds like your specific problem is you don't have rspec's > > matchers required anymore. > > > > [1]http://wiki.github.com/aslakhellesoy/cucumber/upgrading > > > > > > > > > > > > > Then there is an invalid item with 1 "upc" > > > error # features/step_definitions/ > > > extract_steps.rb: > > > 56 > > > undefined method `be_true' for > > > # (NoMethodError) > > > ./features/step_definitions/extract_steps.rb:45:in `/^retrieve > > > file$/' > > > > > Then /^retrieve file$/ do > > > basename = File.basename(@filename) > > > ExtractReport.exists?(:file_name => basename).should == > > > true **** this is line 45 > > > @file = ExtractReport.find_by_file_name(basename) > > > count = @file.record_count.to_i - 2 # count includes header and > > > trailer > > > @file.should have(count).items > > > end > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-us... at rubyforge.org > > >http://rubyforge.org/mailman/listinfo/rspec-users > > > > cheers, > > Matt > > > > http://mattwynne.net > > +447974 430184 > > > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.orghttp:// > 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 t73net at t73.biz Wed Dec 23 16:44:29 2009 From: t73net at t73.biz (Ronald Chaplin) Date: Wed, 23 Dec 2009 16:44:29 -0500 Subject: [rspec-users] What does as_null_object do? Message-ID: <1261604669.10968.3.camel@ronald-desktop> So I'm going through the rspec book right now, and get to page 72, as it introduces Spec::Mocks::Methods#as_null_object . In the book, it doesn't describe how it operates, or much detail about it other than it tells to expect certain data, and ignore the rest. ri Spec::Mocks::Methods#as_null_object simply states "no definition".??? So, does anyone else have some more info on this? What is it, what's it's total useage? what can I cook with it? Can I bbq it? What exactly? -- Ronald Chaplin T73 Biz From dchelimsky at gmail.com Fri Dec 25 11:22:25 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 25 Dec 2009 10:22:25 -0600 Subject: [rspec-users] What does as_null_object do? In-Reply-To: <1261604669.10968.3.camel@ronald-desktop> References: <1261604669.10968.3.camel@ronald-desktop> Message-ID: <57c63afe0912250822l2cc12a91x8a59e9596e5d6f28@mail.gmail.com> On Wed, Dec 23, 2009 at 3:44 PM, Ronald Chaplin wrote: > So I'm going through the rspec book right now, and get to page 72, as it > introduces Spec::Mocks::Methods#as_null_object . In the book, it doesn't > describe how it operates, or much detail about it other than it tells to > expect certain data, and ignore the rest. > > ri Spec::Mocks::Methods#as_null_object simply states "no definition".??? > http://github.com/dchelimsky/rspec/commit/14deb19ca4abff2f1a0339e881732f9c8cf55f5b Just added that so you'll be able to get that definition from ri after the next release. Cheers, David > > So, does anyone else have some more info on this? What is it, what's > it's total useage? what can I cook with it? Can I bbq it? What exactly? > > -- > Ronald Chaplin > T73 Biz > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dgoldie15 at gmail.com Fri Dec 25 20:22:10 2009 From: dgoldie15 at gmail.com (Doug) Date: Fri, 25 Dec 2009 17:22:10 -0800 (PST) Subject: [rspec-users] be_true and be_false are suddenly undefined In-Reply-To: <8d961d900912250245u7e61b732rc8cbb62fec206cd9@mail.gmail.com> References: <18dffef7-0450-4097-9cab-17cfdc722d7a@s21g2000prm.googlegroups.com> <3f0ca8d6-f401-4b86-bb88-cb31cc582982@d4g2000pra.googlegroups.com> <8d961d900912250245u7e61b732rc8cbb62fec206cd9@mail.gmail.com> Message-ID: <995cd5a2-5985-453b-8db2-f5512725656e@u8g2000prd.googlegroups.com> I figured it out last night. ...sorry I didn't post then I created a blank rails project and used: $ script/generate --webrat --rspec then compared the features/support/env.rb; mine was missing: require 'cucumber/rails/rspec' after adding that statement, the be_true and be_falses worked fine then I removed all the other requires as you suggested above NOTE: I believe that's the way the file was generated. I don't remember editing the env.rb file -- per the instructions, but I don't remember. using the options: --webrat --rspec --testunit .....Now I only included the option for testunit out of curiousity; was that a mistake? I'll try to reproduce it. thanks On Dec 25, 2:45?am, aslak hellesoy wrote: > > I agree.... > > > I did notice that my feature/support/my_env.rb (custom) had: > > require 'spec' > > require 'spec/rails' > > > so I changed first line > > require 'spec/autorun' > > You shouldn't do that. You don't want the RSpec runner to run when you're > using Cucumber. > In fact, you shouldn't do any RSpec requires in my_env.rb at all - all that > setup is done in env.rb. > > > in keeping with > >http://wiki.github.com/dchelimsky/rspec/configgem-for-rails > > > seems to me that really should do it, but it doesn't work.???? > > I'm assuming you have followed the upgrade instructions that Matt mentioned. > However your setup still seems broken so I'm wondering if you succeeded. > > Could you pastie or gist your env.rb and my_env.rb files so we can take a > peek? > > I've tried requiring spec_helper, etc. putting the requires closer to > > > my code.,etc. > > You should never load your spec_helper.rb from Cucumber. > > > > > > nothing works!!!! > > > btw: be_true and be_false work in my existing spec test; it's just in > > cucumber steps. > > > ???? > > > On Dec 24, 1:14 am, Matt Wynne wrote: > > > On 24 Dec 2009, at 06:09, Doug wrote: > > > > > after upgrading cucumber to 5.1 be_true and be_false are undefined > > > > switching to == true ?or == false works. > > > > > ??? thanks. > > > > The rails integration changed quite a bit for that release. See [1] > > > plus a few recent threads on this list. > > > > It sounds like your specific problem is you don't have rspec's > > > matchers required anymore. > > > > [1]http://wiki.github.com/aslakhellesoy/cucumber/upgrading > > > > > ? ?Then there is an invalid item with 1 "upc" > > > > error ? ? ? ? ? ? ? ? ? ? # features/step_definitions/ > > > > extract_steps.rb: > > > > 56 > > > > ? ? ?undefined method `be_true' for > > > > # (NoMethodError) > > > > ? ? ?./features/step_definitions/extract_steps.rb:45:in `/^retrieve > > > > file$/' > > > > > Then /^retrieve file$/ do > > > > ?basename = File.basename(@filename) > > > > ?ExtractReport.exists?(:file_name => basename).should == > > > > true ? ? ? ? ? ? ? ? ? **** this is line 45 > > > > ?@file = ExtractReport.find_by_file_name(basename) > > > > ?count = @file.record_count.to_i - 2 # count includes header and > > > > trailer > > > > ?@file.should have(count).items > > > > end > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-us... at rubyforge.org > > > >http://rubyforge.org/mailman/listinfo/rspec-users > > > > cheers, > > > Matt > > > >http://mattwynne.net > > > +447974 430184 > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-us... at rubyforge.orghttp:// > > 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 dgoldie15 at gmail.com Fri Dec 25 20:39:53 2009 From: dgoldie15 at gmail.com (Doug) Date: Fri, 25 Dec 2009 17:39:53 -0800 (PST) Subject: [rspec-users] be_true and be_false are suddenly undefined In-Reply-To: <995cd5a2-5985-453b-8db2-f5512725656e@u8g2000prd.googlegroups.com> References: <18dffef7-0450-4097-9cab-17cfdc722d7a@s21g2000prm.googlegroups.com> <3f0ca8d6-f401-4b86-bb88-cb31cc582982@d4g2000pra.googlegroups.com> <8d961d900912250245u7e61b732rc8cbb62fec206cd9@mail.gmail.com> <995cd5a2-5985-453b-8db2-f5512725656e@u8g2000prd.googlegroups.com> Message-ID: <601922c8-e32a-442d-ace9-f372f45b4c9b@u16g2000pru.googlegroups.com> I tried to reproduce....very strange I'm back to being confused again. ..as to why of course in my blank, demo project I ran > script/generate --webrat --rspec --testunit it does produce a different env.rb file -- without a "require cucumber/rails/rspec" statement but the be_true still works. ????? does this make any sense? =================================== the demo project env.rb file now looks like: ENV["RAILS_ENV"] ||= "cucumber" require File.expand_path(File.dirname(__FILE__) + '/../../config/ environment') require 'cucumber/formatter/unicode' # Remove this line if you don't want Cucumber Unicode support require 'cucumber/rails/world' require 'cucumber/rails/active_record' require 'cucumber/web/tableish' require 'webrat' require 'webrat/core/matchers' require 'cucumber/webrat/element_locator' # Deprecated in favor of #tableish - remove this line if you don't use #element_at or #table_at Webrat.configure do |config| config.mode = :rails config.open_error_files = false # Set to true if you want error pages to pop up in the browser end =============================== after running > script/generate --webrat --rspec it looks like: ( oh, and be_true and be_false still work!) ENV["RAILS_ENV"] ||= "cucumber" require File.expand_path(File.dirname(__FILE__) + '/../../config/ environment') require 'cucumber/formatter/unicode' # Remove this line if you don't want Cucumber Unicode support require 'cucumber/rails/rspec' require 'cucumber/rails/world' require 'cucumber/rails/active_record' require 'cucumber/web/tableish' require 'webrat' require 'webrat/core/matchers' require 'cucumber/webrat/element_locator' # Deprecated in favor of #tableish - remove this line if you don't use #element_at or #table_at Webrat.configure do |config| config.mode = :rails config.open_error_files = false # Set to true if you want error pages to pop up in the browser end On Dec 25, 5:22?pm, Doug wrote: > I figured it out last night. > ...sorry I didn't post then > > I created a blank rails project and used: > $ script/generate --webrat --rspec > > then compared the features/support/env.rb; mine was missing: > require 'cucumber/rails/rspec' > > after adding that statement, the be_true and be_falses worked fine > then I removed all the other requires as you suggested above > > NOTE: I believe that's the way the file was generated. I don't > remember editing the env.rb file -- per the instructions, but I don't > remember. > using the options: --webrat --rspec --testunit > .....Now I only included the option for testunit out of curiousity; > was that a mistake? > > I'll try to reproduce it. > > thanks > > On Dec 25, 2:45?am, aslak hellesoy wrote: > > > > I agree.... > > > > I did notice that my feature/support/my_env.rb (custom) had: > > > require 'spec' > > > require 'spec/rails' > > > > so I changed first line > > > require 'spec/autorun' > > > You shouldn't do that. You don't want the RSpec runner to run when you're > > using Cucumber. > > In fact, you shouldn't do any RSpec requires in my_env.rb at all - all that > > setup is done in env.rb. > > > > in keeping with > > >http://wiki.github.com/dchelimsky/rspec/configgem-for-rails > > > > seems to me that really should do it, but it doesn't work.???? > > > I'm assuming you have followed the upgrade instructions that Matt mentioned. > > However your setup still seems broken so I'm wondering if you succeeded. > > > Could you pastie or gist your env.rb and my_env.rb files so we can take a > > peek? > > > I've tried requiring spec_helper, etc. putting the requires closer to > > > > my code.,etc. > > > You should never load your spec_helper.rb from Cucumber. > > > nothing works!!!! > > > > btw: be_true and be_false work in my existing spec test; it's just in > > > cucumber steps. > > > > ???? > > > > On Dec 24, 1:14 am, Matt Wynne wrote: > > > > On 24 Dec 2009, at 06:09, Doug wrote: > > > > > > after upgrading cucumber to 5.1 be_true and be_false are undefined > > > > > switching to == true ?or == false works. > > > > > > ??? thanks. > > > > > The rails integration changed quite a bit for that release. See [1] > > > > plus a few recent threads on this list. > > > > > It sounds like your specific problem is you don't have rspec's > > > > matchers required anymore. > > > > > [1]http://wiki.github.com/aslakhellesoy/cucumber/upgrading > > > > > > ? ?Then there is an invalid item with 1 "upc" > > > > > error ? ? ? ? ? ? ? ? ? ? # features/step_definitions/ > > > > > extract_steps.rb: > > > > > 56 > > > > > ? ? ?undefined method `be_true' for > > > > > # (NoMethodError) > > > > > ? ? ?./features/step_definitions/extract_steps.rb:45:in `/^retrieve > > > > > file$/' > > > > > > Then /^retrieve file$/ do > > > > > ?basename = File.basename(@filename) > > > > > ?ExtractReport.exists?(:file_name => basename).should == > > > > > true ? ? ? ? ? ? ? ? ? **** this is line 45 > > > > > ?@file = ExtractReport.find_by_file_name(basename) > > > > > ?count = @file.record_count.to_i - 2 # count includes header and > > > > > trailer > > > > > ?@file.should have(count).items > > > > > end > > > > > _______________________________________________ > > > > > rspec-users mailing list > > > > > rspec-us... at rubyforge.org > > > > >http://rubyforge.org/mailman/listinfo/rspec-users > > > > > cheers, > > > > Matt > > > > >http://mattwynne.net > > > > +447974 430184 > > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-us... at rubyforge.orghttp:// > > > 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 > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From aslak.hellesoy at gmail.com Fri Dec 25 20:51:26 2009 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Sat, 26 Dec 2009 02:51:26 +0100 Subject: [rspec-users] be_true and be_false are suddenly undefined In-Reply-To: <601922c8-e32a-442d-ace9-f372f45b4c9b@u16g2000pru.googlegroups.com> References: <18dffef7-0450-4097-9cab-17cfdc722d7a@s21g2000prm.googlegroups.com> <3f0ca8d6-f401-4b86-bb88-cb31cc582982@d4g2000pra.googlegroups.com> <8d961d900912250245u7e61b732rc8cbb62fec206cd9@mail.gmail.com> <995cd5a2-5985-453b-8db2-f5512725656e@u8g2000prd.googlegroups.com> <601922c8-e32a-442d-ace9-f372f45b4c9b@u16g2000pru.googlegroups.com> Message-ID: <8d961d900912251751m60cc1374y98d7284e48c269c8@mail.gmail.com> > I tried to reproduce....very strange > I'm back to being confused again. > ..as to why of course > > in my blank, demo project I ran > > script/generate --webrat --rspec --testunit > it does produce a different env.rb file > -- without a "require cucumber/rails/rspec" statement > > but the be_true still works. ????? > > does this make any sense? > > RSpec and Test::Unit are two complimentory libraries for making low-level assertions, so you want to pick one and only one. I would love to get some insight into why you tried both at the same time. I'm always trying to write software and documentation that is as intuitive as possible, but I'm realising I'll never quite get there. Aslak > =================================== > the demo project env.rb file now looks like: > > ENV["RAILS_ENV"] ||= "cucumber" > require File.expand_path(File.dirname(__FILE__) + '/../../config/ > environment') > > require 'cucumber/formatter/unicode' # Remove this line if you don't > want Cucumber Unicode support > require 'cucumber/rails/world' > require 'cucumber/rails/active_record' > require 'cucumber/web/tableish' > > require 'webrat' > require 'webrat/core/matchers' > require 'cucumber/webrat/element_locator' # Deprecated in favor of > #tableish - remove this line if you don't use #element_at or #table_at > > Webrat.configure do |config| > config.mode = :rails > config.open_error_files = false # Set to true if you want error > pages to pop up in the browser > end > > =============================== > after running > > script/generate --webrat --rspec > > it looks like: ( oh, and be_true and be_false still work!) > > ENV["RAILS_ENV"] ||= "cucumber" > require File.expand_path(File.dirname(__FILE__) + '/../../config/ > environment') > > require 'cucumber/formatter/unicode' # Remove this line if you don't > want Cucumber Unicode support > require 'cucumber/rails/rspec' > require 'cucumber/rails/world' > require 'cucumber/rails/active_record' > require 'cucumber/web/tableish' > > require 'webrat' > require 'webrat/core/matchers' > require 'cucumber/webrat/element_locator' # Deprecated in favor of > #tableish - remove this line if you don't use #element_at or #table_at > > Webrat.configure do |config| > config.mode = :rails > config.open_error_files = false # Set to true if you want error > pages to pop up in the browser > end > > > > On Dec 25, 5:22 pm, Doug wrote: > > I figured it out last night. > > ...sorry I didn't post then > > > > I created a blank rails project and used: > > $ script/generate --webrat --rspec > > > > then compared the features/support/env.rb; mine was missing: > > require 'cucumber/rails/rspec' > > > > after adding that statement, the be_true and be_falses worked fine > > then I removed all the other requires as you suggested above > > > > NOTE: I believe that's the way the file was generated. I don't > > remember editing the env.rb file -- per the instructions, but I don't > > remember. > > using the options: --webrat --rspec --testunit > > .....Now I only included the option for testunit out of curiousity; > > was that a mistake? > > > > I'll try to reproduce it. > > > > thanks > > > > On Dec 25, 2:45 am, aslak hellesoy wrote: > > > > > > I agree.... > > > > > > I did notice that my feature/support/my_env.rb (custom) had: > > > > require 'spec' > > > > require 'spec/rails' > > > > > > so I changed first line > > > > require 'spec/autorun' > > > > > You shouldn't do that. You don't want the RSpec runner to run when > you're > > > using Cucumber. > > > In fact, you shouldn't do any RSpec requires in my_env.rb at all - all > that > > > setup is done in env.rb. > > > > > > in keeping with > > > >http://wiki.github.com/dchelimsky/rspec/configgem-for-rails > > > > > > seems to me that really should do it, but it doesn't work.???? > > > > > I'm assuming you have followed the upgrade instructions that Matt > mentioned. > > > However your setup still seems broken so I'm wondering if you > succeeded. > > > > > Could you pastie or gist your env.rb and my_env.rb files so we can take > a > > > peek? > > > > > I've tried requiring spec_helper, etc. putting the requires closer to > > > > > > my code.,etc. > > > > > You should never load your spec_helper.rb from Cucumber. > > > > > nothing works!!!! > > > > > > btw: be_true and be_false work in my existing spec test; it's just in > > > > cucumber steps. > > > > > > ???? > > > > > > On Dec 24, 1:14 am, Matt Wynne wrote: > > > > > On 24 Dec 2009, at 06:09, Doug wrote: > > > > > > > > after upgrading cucumber to 5.1 be_true and be_false are > undefined > > > > > > switching to == true or == false works. > > > > > > > > ??? thanks. > > > > > > > The rails integration changed quite a bit for that release. See [1] > > > > > plus a few recent threads on this list. > > > > > > > It sounds like your specific problem is you don't have rspec's > > > > > matchers required anymore. > > > > > > > [1]http://wiki.github.com/aslakhellesoy/cucumber/upgrading > > > > > > > > Then there is an invalid item with 1 "upc" > > > > > > error # features/step_definitions/ > > > > > > extract_steps.rb: > > > > > > 56 > > > > > > undefined method `be_true' for > > > > > > # > (NoMethodError) > > > > > > ./features/step_definitions/extract_steps.rb:45:in > `/^retrieve > > > > > > file$/' > > > > > > > > Then /^retrieve file$/ do > > > > > > basename = File.basename(@filename) > > > > > > ExtractReport.exists?(:file_name => basename).should == > > > > > > true **** this is line 45 > > > > > > @file = ExtractReport.find_by_file_name(basename) > > > > > > count = @file.record_count.to_i - 2 # count includes header and > > > > > > trailer > > > > > > @file.should have(count).items > > > > > > end > > > > > > _______________________________________________ > > > > > > rspec-users mailing list > > > > > > rspec-us... at rubyforge.org > > > > > >http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > cheers, > > > > > Matt > > > > > > >http://mattwynne.net > > > > > +447974 430184 > > > > > > > _______________________________________________ > > > > > rspec-users mailing list > > > > > rspec-us... at rubyforge.orghttp:// > > > > 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 > > > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.orghttp:// > 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 dgoldie15 at gmail.com Fri Dec 25 23:04:41 2009 From: dgoldie15 at gmail.com (Doug) Date: Fri, 25 Dec 2009 20:04:41 -0800 (PST) Subject: [rspec-users] be_true and be_false are suddenly undefined In-Reply-To: <8d961d900912251751m60cc1374y98d7284e48c269c8@mail.gmail.com> References: <18dffef7-0450-4097-9cab-17cfdc722d7a@s21g2000prm.googlegroups.com> <3f0ca8d6-f401-4b86-bb88-cb31cc582982@d4g2000pra.googlegroups.com> <8d961d900912250245u7e61b732rc8cbb62fec206cd9@mail.gmail.com> <995cd5a2-5985-453b-8db2-f5512725656e@u8g2000prd.googlegroups.com> <601922c8-e32a-442d-ace9-f372f45b4c9b@u16g2000pru.googlegroups.com> <8d961d900912251751m60cc1374y98d7284e48c269c8@mail.gmail.com> Message-ID: <767652d4-a87f-40ca-ba72-69abb959661b@m7g2000prd.googlegroups.com> Aslak, I have admit, when I saw the option: testunit, I was just curious as to what it would do .....assumed it would be something additional...I guess we have some critical legacy unit/integration tests that will probably survive forever. but going forward everything is rspec and cucumber in cucumber steps, I'm only using rspec assertions/matchers we do have some complex test setup requirements that we are currently satisfying with methods in rspec -- shared with cucumber steps. ..that seems to work, but is slow of course may try to replace with some pickle / machinist, not sure thanks again, -doug. On Dec 25, 5:51?pm, aslak hellesoy wrote: > > I tried to reproduce....very strange > > I'm back to being confused again. > > ..as to why of course > > > in my blank, demo project I ran > > > script/generate --webrat --rspec --testunit > > it does produce a different env.rb file > > -- without a "require cucumber/rails/rspec" statement > > > but the be_true still works. ????? > > > does this make any sense? > > RSpec and Test::Unit are two complimentory libraries for making low-level > assertions, so you want to pick one and only one. > > I would love to get some insight into why you tried both at the same time. > I'm always trying to write software and documentation that is as intuitive > as possible, but I'm realising I'll never quite get there. > > Aslak > > > =================================== > > the demo project env.rb file now looks like: > > > ENV["RAILS_ENV"] ||= "cucumber" > > require File.expand_path(File.dirname(__FILE__) + '/../../config/ > > environment') > > > require 'cucumber/formatter/unicode' # Remove this line if you don't > > want Cucumber Unicode support > > require 'cucumber/rails/world' > > require 'cucumber/rails/active_record' > > require 'cucumber/web/tableish' > > > require 'webrat' > > require 'webrat/core/matchers' > > require 'cucumber/webrat/element_locator' # Deprecated in favor of > > #tableish - remove this line if you don't use #element_at or #table_at > > > Webrat.configure do |config| > > ?config.mode = :rails > > ?config.open_error_files = false # Set to true if you want error > > pages to pop up in the browser > > end > > > =============================== > > after running > > > script/generate --webrat --rspec > > > it looks like: ( oh, and be_true and be_false still work!) > > > ENV["RAILS_ENV"] ||= "cucumber" > > require File.expand_path(File.dirname(__FILE__) + '/../../config/ > > environment') > > > require 'cucumber/formatter/unicode' # Remove this line if you don't > > want Cucumber Unicode support > > require 'cucumber/rails/rspec' > > require 'cucumber/rails/world' > > require 'cucumber/rails/active_record' > > require 'cucumber/web/tableish' > > > require 'webrat' > > require 'webrat/core/matchers' > > require 'cucumber/webrat/element_locator' # Deprecated in favor of > > #tableish - remove this line if you don't use #element_at or #table_at > > > Webrat.configure do |config| > > ?config.mode = :rails > > ?config.open_error_files = false # Set to true if you want error > > pages to pop up in the browser > > end > > > On Dec 25, 5:22 pm, Doug wrote: > > > I figured it out last night. > > > ...sorry I didn't post then > > > > I created a blank rails project and used: > > > $ script/generate --webrat --rspec > > > > then compared the features/support/env.rb; mine was missing: > > > require 'cucumber/rails/rspec' > > > > after adding that statement, the be_true and be_falses worked fine > > > then I removed all the other requires as you suggested above > > > > NOTE: I believe that's the way the file was generated. I don't > > > remember editing the env.rb file -- per the instructions, but I don't > > > remember. > > > using the options: --webrat --rspec --testunit > > > .....Now I only included the option for testunit out of curiousity; > > > was that a mistake? > > > > I'll try to reproduce it. > > > > thanks > > > > On Dec 25, 2:45 am, aslak hellesoy wrote: > > > > > > I agree.... > > > > > > I did notice that my feature/support/my_env.rb (custom) had: > > > > > require 'spec' > > > > > require 'spec/rails' > > > > > > so I changed first line > > > > > require 'spec/autorun' > > > > > You shouldn't do that. You don't want the RSpec runner to run when > > you're > > > > using Cucumber. > > > > In fact, you shouldn't do any RSpec requires in my_env.rb at all - all > > that > > > > setup is done in env.rb. > > > > > > in keeping with > > > > >http://wiki.github.com/dchelimsky/rspec/configgem-for-rails > > > > > > seems to me that really should do it, but it doesn't work.???? > > > > > I'm assuming you have followed the upgrade instructions that Matt > > mentioned. > > > > However your setup still seems broken so I'm wondering if you > > succeeded. > > > > > Could you pastie or gist your env.rb and my_env.rb files so we can take > > a > > > > peek? > > > > > I've tried requiring spec_helper, etc. putting the requires closer to > > > > > > my code.,etc. > > > > > You should never load your spec_helper.rb from Cucumber. > > > > > nothing works!!!! > > > > > > btw: be_true and be_false work in my existing spec test; it's just in > > > > > cucumber steps. > > > > > > ???? > > > > > > On Dec 24, 1:14 am, Matt Wynne wrote: > > > > > > On 24 Dec 2009, at 06:09, Doug wrote: > > > > > > > > after upgrading cucumber to 5.1 be_true and be_false are > > undefined > > > > > > > switching to == true ?or == false works. > > > > > > > > ??? thanks. > > > > > > > The rails integration changed quite a bit for that release. See [1] > > > > > > plus a few recent threads on this list. > > > > > > > It sounds like your specific problem is you don't have rspec's > > > > > > matchers required anymore. > > > > > > > [1]http://wiki.github.com/aslakhellesoy/cucumber/upgrading > > > > > > > > ? ?Then there is an invalid item with 1 "upc" > > > > > > > error ? ? ? ? ? ? ? ? ? ? # features/step_definitions/ > > > > > > > extract_steps.rb: > > > > > > > 56 > > > > > > > ? ? ?undefined method `be_true' for > > > > > > > # > > (NoMethodError) > > > > > > > ? ? ?./features/step_definitions/extract_steps.rb:45:in > > `/^retrieve > > > > > > > file$/' > > > > > > > > Then /^retrieve file$/ do > > > > > > > ?basename = File.basename(@filename) > > > > > > > ?ExtractReport.exists?(:file_name => basename).should == > > > > > > > true ? ? ? ? ? ? ? ? ? **** this is line 45 > > > > > > > ?@file = ExtractReport.find_by_file_name(basename) > > > > > > > ?count = @file.record_count.to_i - 2 # count includes header and > > > > > > > trailer > > > > > > > ?@file.should have(count).items > > > > > > > end > > > > > > > _______________________________________________ > > > > > > > rspec-users mailing list > > > > > > > rspec-us... at rubyforge.org > > > > > > >http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > cheers, > > > > > > Matt > > > > > > >http://mattwynne.net > > > > > > +447974 430184 > > > > > > > _______________________________________________ > > > > > > rspec-users mailing list > > > > > > rspec-us... at rubyforge.orghttp:// > > > > > 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 > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-us... at rubyforge.orghttp:// > > 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 ed.howland at gmail.com Sat Dec 26 18:53:19 2009 From: ed.howland at gmail.com (Ed Howland) Date: Sat, 26 Dec 2009 18:53:19 -0500 Subject: [rspec-users] Custom matcher for predicates Message-ID: <3df642dd0912261553p4bd4ce1dpc26c29de02bc4cf5@mail.gmail.com> I hope this isn't a dumb question, but can a custom matcher be written for a possibly non-existant predicate? I know that if the object responds to some predicate? message, RSpec will breate a custom matcher on the fly for it. Such as be_naughty or be_nice for sarah.naughty? and jane.nice? But what if you want to create your own where this is not the case. Like sarah.should_not be_on_santas_list: Spec::Matchers.define :be_on_santas_list do |expected| matcher do |actual| $santas_list.include? actual end end Or in the situation where the object has a predicate that returns a string and not true or false. As is the case with REXML::Document#stand_alone?: match do |actual| actual.stand_alone? == 'yes' end This works, but the value of expected is nil. Is this Ok? How do others handle this? . Thanks, and Happy Holidays. Ed -- Ed Howland http://greenprogrammer.wordpress.com http://twitter.com/ed_howland From dchelimsky at gmail.com Sat Dec 26 19:55:13 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 26 Dec 2009 18:55:13 -0600 Subject: [rspec-users] Custom matcher for predicates In-Reply-To: <3df642dd0912261553p4bd4ce1dpc26c29de02bc4cf5@mail.gmail.com> References: <3df642dd0912261553p4bd4ce1dpc26c29de02bc4cf5@mail.gmail.com> Message-ID: <57c63afe0912261655y2ef59a9epb6861412b0abc324@mail.gmail.com> On Sat, Dec 26, 2009 at 5:53 PM, Ed Howland wrote: > I hope this isn't a dumb question, but can a custom matcher be written > for a possibly non-existant predicate? I know that if the object > responds to some predicate? message, RSpec will breate a custom > matcher on the fly for it. Such as be_naughty or be_nice for > sarah.naughty? and jane.nice? > It's not that RSpec looks at your code and creates predicates for it. When you say "jane.should be_nice", RSpec looks to see if jane has a nice?() method and uses that if it's there. Subtle, but important difference. > But what if you want to create your own where this is not the case. > Like sarah.should_not be_on_santas_list: > > Spec::Matchers.define :be_on_santas_list do |expected| > matcher do |actual| > $santas_list.include? actual > end > end > The block arguments should align with the arguments you pass to the matcher. So if you intend to write this in the example: sarah.should_not be_on_santas_list Then the definition should be like this: Spec::Matchers.define :be_on_santas_list do matcher do |actual| $santas_list.include? actual end end ... with no block arguments. > Or in the situation where the object has a predicate that returns a > string and not true or false. As is the case with > REXML::Document#stand_alone?: > > match do |actual| > actual.stand_alone? == 'yes' > end > > This works, but the value of expected is nil. > That's because you didn't pass anything to the matcher, as described above. The fact that expected is nil at that point should not matter, since you're not evaluating against expected in the match block. As long as as "actual.stand_alone? == 'yes'" returns true or false (which it should unless you've gone and redefined ==) you should be ok. > Is this Ok? Yes. Why do you ask? What are your concerns? What problems have you had? > How do others handle this? . > > Thanks, and Happy Holidays. > And to you. Cheers, David > Ed > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Sat Dec 26 19:56:47 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 26 Dec 2009 18:56:47 -0600 Subject: [rspec-users] Custom matcher for predicates In-Reply-To: <57c63afe0912261655y2ef59a9epb6861412b0abc324@mail.gmail.com> References: <3df642dd0912261553p4bd4ce1dpc26c29de02bc4cf5@mail.gmail.com> <57c63afe0912261655y2ef59a9epb6861412b0abc324@mail.gmail.com> Message-ID: <57c63afe0912261656p51c1c0b2j624dc610d683bcf4@mail.gmail.com> On Sat, Dec 26, 2009 at 6:55 PM, David Chelimsky wrote: > On Sat, Dec 26, 2009 at 5:53 PM, Ed Howland wrote: > >> I hope this isn't a dumb question, but can a custom matcher be written >> for a possibly non-existant predicate? I know that if the object >> responds to some predicate? message, RSpec will breate a custom >> matcher on the fly for it. Such as be_naughty or be_nice for >> sarah.naughty? and jane.nice? >> > > It's not that RSpec looks at your code and creates predicates for it. When > you say "jane.should be_nice", RSpec looks to see if jane has a nice?() > method and uses that if it's there. Subtle, but important difference. > I should add here, that if you've already defined a be_nice method, it will be called. RSpec only checks for a predicate when it gets method_missing, which it wouldn't if you've defined a method already. HTH, David > > >> But what if you want to create your own where this is not the case. >> Like sarah.should_not be_on_santas_list: >> >> Spec::Matchers.define :be_on_santas_list do |expected| >> matcher do |actual| >> $santas_list.include? actual >> end >> end >> > > The block arguments should align with the arguments you pass to the > matcher. So if you intend to write this in the example: > > sarah.should_not be_on_santas_list > > Then the definition should be like this: > > Spec::Matchers.define :be_on_santas_list do > matcher do |actual| > $santas_list.include? actual > end > end > > ... with no block arguments. > > >> Or in the situation where the object has a predicate that returns a >> string and not true or false. As is the case with >> REXML::Document#stand_alone?: >> >> match do |actual| >> actual.stand_alone? == 'yes' >> end >> >> This works, but the value of expected is nil. >> > > That's because you didn't pass anything to the matcher, as described above. > > The fact that expected is nil at that point should not matter, since you're > not evaluating against expected in the match block. As long as as > "actual.stand_alone? == 'yes'" returns true or false (which it should unless > you've gone and redefined ==) you should be ok. > > >> Is this Ok? > > > Yes. Why do you ask? What are your concerns? What problems have you had? > > >> How do others handle this? . >> >> Thanks, and Happy Holidays. >> > > And to you. > > Cheers, > David > > >> Ed >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ed.howland at gmail.com Sat Dec 26 23:29:47 2009 From: ed.howland at gmail.com (Ed Howland) Date: Sat, 26 Dec 2009 23:29:47 -0500 Subject: [rspec-users] Custom matcher for predicates In-Reply-To: <57c63afe0912261656p51c1c0b2j624dc610d683bcf4@mail.gmail.com> References: <3df642dd0912261553p4bd4ce1dpc26c29de02bc4cf5@mail.gmail.com> <57c63afe0912261655y2ef59a9epb6861412b0abc324@mail.gmail.com> <57c63afe0912261656p51c1c0b2j624dc610d683bcf4@mail.gmail.com> Message-ID: <3df642dd0912262029h236908bbh8bf80f51db13a913@mail.gmail.com> On Sat, Dec 26, 2009 at 7:56 PM, David Chelimsky wrote: > On Sat, Dec 26, 2009 at 6:55 PM, David Chelimsky > wrote: >> >> On Sat, Dec 26, 2009 at 5:53 PM, Ed Howland wrote: >>> >>> I hope this isn't a dumb question, but can a custom matcher be written >>> for a possibly non-existant predicate? I know that if the object >>> responds to some predicate? message, RSpec will breate a custom >>> matcher on the fly for it. Such as be_naughty or be_nice for >>> sarah.naughty? and jane.nice? >> >> It's not that RSpec looks at your code and creates predicates for it. When >> you say "jane.should be_nice", RSpec looks to see if jane has a nice?() >> method and uses that if it's there. Subtle, but important difference. > > I should add here, that if you've already defined a be_nice method, it will > be called. RSpec only checks for a predicate when it gets method_missing, > which it wouldn't if you've defined a method already. > HTH, > David Thanks, David. That helps my understanding a lot. Happy Boxing day, or what's left of it Ed > -- Ed Howland http://greenprogrammer.wordpress.com http://twitter.com/ed_howland From magic6435 at gmail.com Sun Dec 27 02:08:47 2009 From: magic6435 at gmail.com (Michael) Date: Sat, 26 Dec 2009 23:08:47 -0800 (PST) Subject: [rspec-users] DB does not reset between runs Message-ID: <5c8aeeaa-0c98-433e-8cc1-f139d232b7ea@c3g2000yqd.googlegroups.com> For some reason any thing that is created while running specs like users from a Factory remain in the database between runs which leads to errors such as "Validation failed: Email has already been taken" and yes i have config.use_transactional_fixtures = true. Anyone have a idea why this is happening, I'm kinda stuck on moving my app forward until i can get this fixed. Thanks for any help. Mike From magic6435 at gmail.com Sun Dec 27 02:11:17 2009 From: magic6435 at gmail.com (Michael) Date: Sat, 26 Dec 2009 23:11:17 -0800 (PST) Subject: [rspec-users] DB does not reset between runs In-Reply-To: <5c8aeeaa-0c98-433e-8cc1-f139d232b7ea@c3g2000yqd.googlegroups.com> References: 5c8aeeaa-0c98-433e-8cc1-f139d232b7ea@c3g2000yqd.googlegroups.com Message-ID: i should also mention that i have the some problem when running cucumber features. On Dec 27, 2:08?am, Michael wrote: > For some reason any thing that is created while running specs like > users from a Factory remain in the database between runs which leads > to errors such as "Validation failed: Email has already been taken" > and yes i have config.use_transactional_fixtures = true. Anyone have a > idea why this is happening, I'm kinda stuck on moving my app forward > until i can get this fixed. > > Thanks for any help. > Mike > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From matt at mattwynne.net Sun Dec 27 03:24:45 2009 From: matt at mattwynne.net (Matt Wynne) Date: Sun, 27 Dec 2009 08:24:45 +0000 Subject: [rspec-users] DB does not reset between runs In-Reply-To: <5c8aeeaa-0c98-433e-8cc1-f139d232b7ea@c3g2000yqd.googlegroups.com> References: <5c8aeeaa-0c98-433e-8cc1-f139d232b7ea@c3g2000yqd.googlegroups.com> Message-ID: Look at your rails logs very carefully and see what's going on, paying special attention to each call to BEGIN TRANSACTION, COMMIT TRANSACTION. When this has happened to me in the past, it was because I had a call to ActiveRecord::Base.connection to do some dirty raw SQL query, and those calls will implicitly commit the whole test-case transaction to the database. On 27 Dec 2009, at 07:08, Michael wrote: > For some reason any thing that is created while running specs like > users from a Factory remain in the database between runs which leads > to errors such as "Validation failed: Email has already been taken" > and yes i have config.use_transactional_fixtures = true. Anyone have a > idea why this is happening, I'm kinda stuck on moving my app forward > until i can get this fixed. > > > Thanks for any help. > Mike > _______________________________________________ > 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 Sun Dec 27 11:12:08 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 27 Dec 2009 10:12:08 -0600 Subject: [rspec-users] generated gem config? Message-ID: <57c63afe0912270812v5d5e77nc4cdf1b633c2518f@mail.gmail.com> Hey all, The cucumber-rails generator generates config/environments/cucumber.rb for us, which means we don't need to do any gem configuration. As things stand now, rspec-rails does not do the same thing for us. I'm thinking of having the generator update config/environments/test.rb, adding gem configuration to the bottom of the file if it doesn't already have the configuration. This would mean that all we need do is type "script/generate rspec" and, assuming rspec-rails is installed on the system, the gem configuration will be set up (whereas now you have to manually add the gem configuration yourself). Questions: 1 - good idea? 2 - what are the drawbacks? -------------- next part -------------- An HTML attachment was scrubbed... URL: From ed.howland at gmail.com Sun Dec 27 15:03:55 2009 From: ed.howland at gmail.com (Ed Howland) Date: Sun, 27 Dec 2009 15:03:55 -0500 Subject: [rspec-users] Submitting a Custom Matcher: gem or other method? Message-ID: <3df642dd0912271203m3559eee5x48edac890e3d44e4@mail.gmail.com> Hi, I have a custom matcher that I call XMLDiff that takes an actual XML string and an expected one and uses RSpec's normal line differ to show the difference at the node level. It uses a method called be_functionaly_eql, because two XML strings can be the same regardless of whitespece. I.e. they are functionaly equivalent. If you ran both through the same parser, they would (should) result in the same behavior. So: actual_xml.should be_functionally_eql("") If they are not, you get a context diff right to the element level. Useful for finding errors in long XML strings. I have searched for such a thing to no avail. There may be other solutions and I;d be interested in seeing them. But this is what I came up with. The question is, how would you recommend sharing it? I am new to gem-ing, but can it be packaheged that way, or is there some other method for sharing custom matchers? I can host it on Github, if that is a recommended way to do so. Thanks Ed -- Ed Howland http://greenprogrammer.wordpress.com http://twitter.com/ed_howland From apremdas at gmail.com Mon Dec 28 00:18:13 2009 From: apremdas at gmail.com (Andrew Premdas) Date: Mon, 28 Dec 2009 05:18:13 +0000 Subject: [rspec-users] class variables different between spec and runtime? In-Reply-To: References: <670a00380912220714x76a03379tcdfcee3d8479656a@mail.gmail.com> <57c63afe0912220722sa3b1042qd28235544dc71e3b@mail.gmail.com> <57c63afe0912220724l2971c8c6x43313e70b32a1f74@mail.gmail.com> Message-ID: <88fd8ddc0912272118r10ec31e7p437b617e63580b7a@mail.gmail.com> 2009/12/22 Rick DeNatale > On Tue, Dec 22, 2009 at 10:24 AM, David Chelimsky > wrote: > > > > > > On Tue, Dec 22, 2009 at 9:22 AM, David Chelimsky > > wrote: > >> > >> > >> On Tue, Dec 22, 2009 at 9:14 AM, Peter Fitzgibbons > >> wrote: > >>> > >>> Hello Folks, > >>> > >>> This gist http://gist.github.com/261791 has an example user.rb, > >>> user_spec.rb > >>> At runtime, this snippet fails > >>> > >>> u = User.find(123) > >>> u.update_with_profile({...}) > >>> The error occurred while evaluating nil.select): > >>> app/models/user.rb:6:in `moderator_fields' > >>> app/models/user.rb:118:in `update_with_profile' > >>> > >>> The spec passes all-green. > >>> > >>> Could you tell me how this might be ? > >> > >> The user in the spec comes from new_with_profile(), which sets instance > >> variables on the User class. > >> The user in the console comes from find(), and those ivars are not yet > >> set. > > > > Also - @params in the User class (in the class methods) is not the same > > @params in the User instances (in update_with_profile). > > HTH, > > David > > > Also counting on class variables to retain state in Rails is a recipe > for disaster. > > Please explain why - thanks. Andrew > -- > 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 > _______________________________________________ > 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 Mon Dec 28 08:24:58 2009 From: rick.denatale at gmail.com (Rick DeNatale) Date: Mon, 28 Dec 2009 08:24:58 -0500 Subject: [rspec-users] class variables different between spec and runtime? In-Reply-To: <88fd8ddc0912272118r10ec31e7p437b617e63580b7a@mail.gmail.com> References: <670a00380912220714x76a03379tcdfcee3d8479656a@mail.gmail.com> <57c63afe0912220722sa3b1042qd28235544dc71e3b@mail.gmail.com> <57c63afe0912220724l2971c8c6x43313e70b32a1f74@mail.gmail.com> <88fd8ddc0912272118r10ec31e7p437b617e63580b7a@mail.gmail.com> Message-ID: On Mon, Dec 28, 2009 at 12:18 AM, Andrew Premdas wrote: > 2009/12/22 Rick DeNatale > Please explain why - thanks. Because, classes and class variables aren't guaranteed to be persistent. In development mode, classes can get reloaded, which wipes out class (and class instance) variables. In most deployment scenarios requests from a single user might be handled by different processes, each with it's own state. State that needs to be around between requests needs to be somewhere persistent like the DB, or the session. -- 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 Mon Dec 28 11:27:30 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 28 Dec 2009 10:27:30 -0600 Subject: [rspec-users] Submitting a Custom Matcher: gem or other method? In-Reply-To: <3df642dd0912271203m3559eee5x48edac890e3d44e4@mail.gmail.com> References: <3df642dd0912271203m3559eee5x48edac890e3d44e4@mail.gmail.com> Message-ID: <57c63afe0912280827s18798766r834fe06da2bdee0b@mail.gmail.com> On Sun, Dec 27, 2009 at 2:03 PM, Ed Howland wrote: > Hi, I have a custom matcher that I call XMLDiff that takes an actual > XML string and an expected one and uses RSpec's normal line differ to > show the difference at the node level. It uses a method called > be_functionaly_eql, because two XML strings can be the same regardless > of whitespece. I.e. they are functionaly equivalent. If you ran both > through the same parser, they would (should) result in the same > behavior. So: > > actual_xml.should be_functionally_eql("") > > If they are not, you get a context diff right to the element level. > Useful for finding errors in long XML strings. > > I have searched for such a thing to no avail. There may be other > solutions and I;d be interested in seeing them. But this is what I > came up with. > > The question is, how would you recommend sharing it? I am new to > gem-ing, but can it be packaheged that way, or is there some other > method for sharing custom matchers? I can host it on Github, if that > is a recommended way to do so. > For most users, gems are the easiest answer. By all means, host source on github if you want people to contribute, or have a place to inspect code, but you don't need a public source repository in order to push gems to gemcutter. HTH, David > Thanks > Ed > > > -- > Ed Howland > http://greenprogrammer.wordpress.com > http://twitter.com/ed_howland > _______________________________________________ > 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 sean at saucelabs.com Mon Dec 28 11:48:04 2009 From: sean at saucelabs.com (Sean Grove) Date: Mon, 28 Dec 2009 08:48:04 -0800 Subject: [rspec-users] Listing all specs in a given file In-Reply-To: References: Message-ID: <9D83323C-1B1B-4128-8214-E6D3E30C127F@saucelabs.com> I'm trying to write a simple spec dispatcher, the client-side of which essentially does the following: options = Spec::Runner::OptionParser.parse( "#{file}", $stderr, std_out ) options.line_number = line Spec::Runner::CommandLine.run(options) Given a spec file and a line number, it'll run the spec. Simple enough. My problem is on the server side trying to pull out individual specs to be run out of a file/series of files. The above code works well if I pre-populate and array as follows: queue = [["spec/one_spec.rb", 9], ["spec/one_spec.rb", 28], ["spec/one_spec.rb", 35]] But I'm having a hard time figuring out how to pull out a list of examples given a spec filename. Is this parsed at some point before running, and can I get to that list easily enough? Thanks for all the help! Sean From dchelimsky at gmail.com Mon Dec 28 11:59:07 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 28 Dec 2009 10:59:07 -0600 Subject: [rspec-users] Listing all specs in a given file In-Reply-To: <9D83323C-1B1B-4128-8214-E6D3E30C127F@saucelabs.com> References: <9D83323C-1B1B-4128-8214-E6D3E30C127F@saucelabs.com> Message-ID: <57c63afe0912280859j61550cc3r84715416923091da@mail.gmail.com> On Mon, Dec 28, 2009 at 10:48 AM, Sean Grove wrote: > I'm trying to write a simple spec dispatcher, the client-side of which > essentially does the following: > > options = Spec::Runner::OptionParser.parse( "#{file}", $stderr, std_out ) > options.line_number = line > Spec::Runner::CommandLine.run(options) > > Given a spec file and a line number, it'll run the spec. Simple enough. > > My problem is on the server side trying to pull out individual specs to be > run out of a file/series of files. The above code works well if I > pre-populate and array as follows: > > queue = [["spec/one_spec.rb", 9], > ["spec/one_spec.rb", 28], > ["spec/one_spec.rb", 35]] > > But I'm having a hard time figuring out how to pull out a list of examples > given a spec filename. Is this parsed at some point before running, and can > I get to that list easily enough? > I'm not clear on what your goal is here. Can you give a little more context? Why do you need a list of examples from a filename? > > Thanks for all the help! > > Sean > > _______________________________________________ > 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 sean at saucelabs.com Mon Dec 28 12:06:59 2009 From: sean at saucelabs.com (Sean Grove) Date: Mon, 28 Dec 2009 09:06:59 -0800 Subject: [rspec-users] Listing all specs in a given file In-Reply-To: References: Message-ID: I'm writing a very simple spec dispatcher, but I want to do it on the level of examples. I'd like to be able to send individual examples to my clients, have it run and receive the result back. Currently I can send a file name and have the entire file run (thus distributing the rspec tasks at the file-level), but I'm trying to distribute each individual example out. Thus if I can get a list of examples from a file along with their line number, I can put them in a queue and have clients pull them out one by one. On Dec 28, 2009, at 8:59 AM, rspec-users-request at rubyforge.org wrote: > Date: Mon, 28 Dec 2009 10:59:07 -0600 > From: David Chelimsky > To: rspec-users > Subject: Re: [rspec-users] Listing all specs in a given file > Message-ID: > <57c63afe0912280859j61550cc3r84715416923091da at mail.gmail.com> > Content-Type: text/plain; charset="iso-8859-1" > > On Mon, Dec 28, 2009 at 10:48 AM, Sean Grove > wrote: > >> I'm trying to write a simple spec dispatcher, the client-side of >> which >> essentially does the following: >> >> options = Spec::Runner::OptionParser.parse( "#{file}", $stderr, >> std_out ) >> options.line_number = line >> Spec::Runner::CommandLine.run(options) >> >> Given a spec file and a line number, it'll run the spec. Simple >> enough. >> >> My problem is on the server side trying to pull out individual >> specs to be >> run out of a file/series of files. The above code works well if I >> pre-populate and array as follows: >> >> queue = [["spec/one_spec.rb", 9], >> ["spec/one_spec.rb", 28], >> ["spec/one_spec.rb", 35]] >> >> But I'm having a hard time figuring out how to pull out a list of >> examples >> given a spec filename. Is this parsed at some point before running, >> and can >> I get to that list easily enough? >> > > I'm not clear on what your goal is here. Can you give a little more > context? > Why do you need a list of examples from a filename? > > >> >> Thanks for all the help! >> >> Sean >> >> _______________________________________________ >> 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 Dec 28 14:04:56 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 28 Dec 2009 13:04:56 -0600 Subject: [rspec-users] be_true and be_false Message-ID: <57c63afe0912281104h43232837g48bb41f91f5a87d0@mail.gmail.com> Hi all, The be_true and be_false matchers pass if the actual object is the singleton instance of true or false respectively. e.g. true.should be_true # passes 1.should be_true # fails "true".should be_true #fails false.should be_false # passes nil.should be_false # fails http://rspec.lighthouseapp.com/projects/5645/tickets/931 suggests that be_true should pass for anything that Ruby would evaluate as true (i.e. anything but false or nil) and be_false would pass for anything that Ruby would evaluate as false (i.e. false or nil). Please comment _in that ticket_ if you have an opinion about this. Cheers, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Mon Dec 28 14:12:12 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 28 Dec 2009 13:12:12 -0600 Subject: [rspec-users] be_true and be_false In-Reply-To: <57c63afe0912281104h43232837g48bb41f91f5a87d0@mail.gmail.com> References: <57c63afe0912281104h43232837g48bb41f91f5a87d0@mail.gmail.com> Message-ID: <57c63afe0912281112k2460a866g8681e2c64278eee2@mail.gmail.com> On Mon, Dec 28, 2009 at 1:04 PM, David Chelimsky wrote: > Hi all, > > The be_true and be_false matchers pass if the actual object is the > singleton instance of true or false respectively. e.g. > > true.should be_true # passes > 1.should be_true # fails > Actually, "1.should be_true" passes, but based on the current spec it shouldn't :) > "true".should be_true #fails > > false.should be_false # passes > nil.should be_false # fails > > http://rspec.lighthouseapp.com/projects/5645/tickets/931 suggests that > be_true should pass for anything that Ruby would evaluate as true (i.e. > anything but false or nil) and be_false would pass for anything that Ruby > would evaluate as false (i.e. false or nil). > > Please comment _in that ticket_ if you have an opinion about this. > > Cheers, > David > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Mon Dec 28 14:33:17 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 28 Dec 2009 13:33:17 -0600 Subject: [rspec-users] eq(expected) Message-ID: <57c63afe0912281133v12dd746ft8597689613c0ea92@mail.gmail.com> Hey all, I'm thinking of adding an eq(expected) matcher. Please comment in https://rspec.lighthouseapp.com/projects/5645-rspec/tickets/932 if you're interested. Cheers, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From ed.howland at gmail.com Mon Dec 28 14:49:24 2009 From: ed.howland at gmail.com (Ed Howland) Date: Mon, 28 Dec 2009 14:49:24 -0500 Subject: [rspec-users] Submitting a Custom Matcher: gem or other method? In-Reply-To: <57c63afe0912280827s18798766r834fe06da2bdee0b@mail.gmail.com> References: <3df642dd0912271203m3559eee5x48edac890e3d44e4@mail.gmail.com> <57c63afe0912280827s18798766r834fe06da2bdee0b@mail.gmail.com> Message-ID: <3df642dd0912281149g76a6f54fl637b19daedf4ff1f@mail.gmail.com> On Mon, Dec 28, 2009 at 11:27 AM, David Chelimsky wrote: > On Sun, Dec 27, 2009 at 2:03 PM, Ed Howland wrote: >> >> Hi, I have a custom matcher that I call XMLDiff that takes an actual >> XML string and an expected one and uses RSpec's normal line differ to >> show the difference at the node level. It uses a method called >> be_functionaly_eql, because two XML strings can be the same regardless >> of whitespece. I.e. they are functionaly equivalent. If you ran both >> through the same parser, they would (should) result in the same >> behavior. So: >> >> ?actual_xml.should be_functionally_eql("") >> >> If they are not, you get a context diff right to the element level. >> Useful for finding errors in long XML strings. >> >> I have searched for such a thing to no avail. There may be other >> solutions and I;d be interested in seeing them. But this is what I >> came up with. >> >> The question is, how would you recommend sharing it? I am new to >> gem-ing, but can it be packaheged that way, or is there some other >> method for sharing custom matchers? I can host it on Github, if that >> is a recommended way to do so. > > For most users, gems are the easiest answer. By all means, host source on > github if you want people to contribute, or have a place to inspect code, > but you don't need a public source repository in order to push gems to > gemcutter. > HTH, Yes it does. That was my plan, to add a gem to my github account. I'll search out other DSLs for RSpec and see how they packaged them as a gem. I imagine the easiest way to use it is to add the require to spec_helper.rb (assuming you have one) and then call the be_functionally_eql in your specs as normal. Thanks, And Happy New Year! Ed > David > >> >> Thanks >> Ed >> >> >> -- >> Ed Howland >> http://greenprogrammer.wordpress.com >> http://twitter.com/ed_howland >> _______________________________________________ >> 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 > -- Ed Howland http://greenprogrammer.wordpress.com http://twitter.com/ed_howland From rogerpack2005 at gmail.com Mon Dec 28 15:08:19 2009 From: rogerpack2005 at gmail.com (rogerdpack) Date: Mon, 28 Dec 2009 12:08:19 -0800 (PST) Subject: [rspec-users] no should raise_exception In-Reply-To: <57c63afe0912221408m4e23b599qd9b0f56b847aa26a@mail.gmail.com> References: <0ec63fb0-0f54-4304-8286-3e57cfcffa53@b2g2000yqi.googlegroups.com> <4e78b7b60912192207x3217c51dxa71c1038af415b42@mail.gmail.com> <57c63afe0912221408m4e23b599qd9b0f56b847aa26a@mail.gmail.com> Message-ID: <3c4ed96e-9e75-4d09-8f84-a9d7e12d6d46@a6g2000yqm.googlegroups.com> > What I really want to say is "should raise(Blah)" but Ruby already defines > raise as a keyword :) > > I'd be open to aliasing raise_error with raise_exception, renaming it to > raise_exception and aliasing raise_error for compatibility, but I think this > might just add confusion rather than clarifying intent. Thoughts? (obviously) I like raise_exception The only drawback would be that I suppose in keeping with the new name it "could" be redefined to catch Exception by default, if it currently catches StandardError(?) raise_error seems less readable to me, as there is no Error class. Having both would be fine by me, too. Happy holidays. -r From dchelimsky at gmail.com Mon Dec 28 15:33:06 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 28 Dec 2009 14:33:06 -0600 Subject: [rspec-users] no should raise_exception In-Reply-To: <3c4ed96e-9e75-4d09-8f84-a9d7e12d6d46@a6g2000yqm.googlegroups.com> References: <0ec63fb0-0f54-4304-8286-3e57cfcffa53@b2g2000yqi.googlegroups.com> <4e78b7b60912192207x3217c51dxa71c1038af415b42@mail.gmail.com> <57c63afe0912221408m4e23b599qd9b0f56b847aa26a@mail.gmail.com> <3c4ed96e-9e75-4d09-8f84-a9d7e12d6d46@a6g2000yqm.googlegroups.com> Message-ID: <57c63afe0912281233j44a9721ei5f046043b06b7b55@mail.gmail.com> On Mon, Dec 28, 2009 at 2:08 PM, rogerdpack wrote: > > What I really want to say is "should raise(Blah)" but Ruby already > defines > > raise as a keyword :) > > > > I'd be open to aliasing raise_error with raise_exception, renaming it to > > raise_exception and aliasing raise_error for compatibility, but I think > this > > might just add confusion rather than clarifying intent. Thoughts? > > (obviously) I like raise_exception > > The only drawback would be that I suppose in keeping with the new name > it "could" be redefined to catch Exception by default, if it currently > catches StandardError(?) > As luck (irony?) would have it, the default _is_ Exception. So if you alias it in your project, you'll get what you're after. > raise_error seems less readable to me, as there is no Error class. > This is sound logic, but I think it would do more harm than good at this point. If we were starting today, I'd probably want to have raise_exception and raise_error, with the defaults being Exception and StandardError respectively. That would certainly improve the accuracy of the intent expressed in specs. The problem at this point is that it changes the meaning of raise_error, which would lead to new failures (which cause pain), and false positives (which cause pain you don't even know is being caused). If we just alias raise_error with raise_exception, now we have two methods that do the same thing, and the fact that they have names that might mean different things to different people, I think we'd end up with more confusion. If we replace raise_error with raise_exception, we'd have to deprecate raise_error, which causes pain that would be difficult to justify to many. So we're going to leave it as raise_error for now. If you'd like to push on this (which you're welcome to), please add a ticket to lighthouse so it's easy to find the discussions around it. If we can get general consensus that this would be a good move in spite of the negatives I just outlined, I'm happy to do it. Cheers, David Having both would be fine by me, too. > > Happy holidays. > -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 dgoldie15 at gmail.com Mon Dec 28 18:56:13 2009 From: dgoldie15 at gmail.com (Doug) Date: Mon, 28 Dec 2009 15:56:13 -0800 (PST) Subject: [rspec-users] rake spec seems to not clean the database after failing specs Message-ID: <57203df4-9ed9-467e-aa6f-f295f1eeac49@d20g2000yqh.googlegroups.com> running all specs with 'rake spec' working on a spec that gets run last. when run individually, it is green. but in 'rake spec' it fails because the database is dirty I'm guessing this is caused by early specs that fail as well ???? is this normal? if that's the problem, what's the best way to force the database to be cleaned after each scenario? I have database_cleaner (with cucumber), but just the default configuration thanks From rick.denatale at gmail.com Mon Dec 28 19:22:49 2009 From: rick.denatale at gmail.com (Rick DeNatale) Date: Mon, 28 Dec 2009 19:22:49 -0500 Subject: [rspec-users] rake spec seems to not clean the database after failing specs In-Reply-To: <57203df4-9ed9-467e-aa6f-f295f1eeac49@d20g2000yqh.googlegroups.com> References: <57203df4-9ed9-467e-aa6f-f295f1eeac49@d20g2000yqh.googlegroups.com> Message-ID: On Mon, Dec 28, 2009 at 6:56 PM, Doug wrote: > running all specs with 'rake spec' > > working on a spec that gets run last. > when run individually, it is green. > but in 'rake spec' it fails because the database is dirty > > I'm guessing this is caused by early specs that fail as well > ???? > is this normal? > > if that's the problem, what's the best way to force the database to be > cleaned after each scenario? Be careful what you wish for. I normally want to set the database to a known state BEFORE running specs rather than cleaning up afterwards. Why? Because it's easier to debug failures if you preserve the evidence. -- 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 fausto.galli at email.it Mon Dec 28 18:16:19 2009 From: fausto.galli at email.it (mix) Date: Mon, 28 Dec 2009 15:16:19 -0800 (PST) Subject: [rspec-users] Help with w3c html validation on every rspec requests Message-ID: <6e9ee5ee-f98c-4b8a-9f3b-dba2a1f1a4d2@a6g2000yqm.googlegroups.com> Hi, I'm studying rspec in these days (the rspec book is really great... i'll wait for the missing chapters and a next "rspec advanced book" :) ). But for now i'm trying to solve a problem. I'm a kind of w3c validation fanatic, i mean, i like to give my clients well written code (following "The Standard" when possible.... and we all know that is better having not messed up html to avoid bad layout....eg a missing closed table tag or stuff like that). So i want to add an automated w3c check for all the requests (get, post, put and delete) Currently i'm having a cucumber step, but that's not really something the client would care about (but i do, as i don't call my variables "xyz" :) ), and because of this i'd move the check into the controller specs (using response.body.should be_xhtml_strict). The problem about this is that i'd do for all the requests another line after them with the validity check...but that's valid for all of the requests, and that would be quite a repetition (if i wan't to change from strict to transitional i'll have to make N changes).. so the question is... Which is the easier way? Should i write a method like: def check_xhtml_validation(response) do response.body.should be_xhtml_strict end and then put check_xhtml_validation(response) after every request, or is there another way to do it? (maybe without having to call everytime that method....as it would be forgotten, and difficult to track in that case... but instead having something which is called everytime after a request that check it, without explicitly call it...in this case, how would achieve this?) Thanks From lbocseg at yahoo.com.br Mon Dec 28 20:12:13 2009 From: lbocseg at yahoo.com.br (Rodrigo Rosenfeld Rosas) Date: Mon, 28 Dec 2009 23:12:13 -0200 Subject: [rspec-users] no should raise_exception In-Reply-To: <57c63afe0912281233j44a9721ei5f046043b06b7b55@mail.gmail.com> References: <0ec63fb0-0f54-4304-8286-3e57cfcffa53@b2g2000yqi.googlegroups.com> <4e78b7b60912192207x3217c51dxa71c1038af415b42@mail.gmail.com> <57c63afe0912221408m4e23b599qd9b0f56b847aa26a@mail.gmail.com> <3c4ed96e-9e75-4d09-8f84-a9d7e12d6d46@a6g2000yqm.googlegroups.com> <57c63afe0912281233j44a9721ei5f046043b06b7b55@mail.gmail.com> Message-ID: <4B39576D.9060001@yahoo.com.br> David Chelimsky escreveu: > On Mon, Dec 28, 2009 at 2:08 PM, rogerdpack > wrote: > > > What I really want to say is "should raise(Blah)" but Ruby > already defines > > raise as a keyword :) > > > > I'd be open to aliasing raise_error with raise_exception, > renaming it to > > raise_exception and aliasing raise_error for compatibility, but > I think this > > might just add confusion rather than clarifying intent. Thoughts? > > (obviously) I like raise_exception > > The only drawback would be that I suppose in keeping with the new name > it "could" be redefined to catch Exception by default, if it currently > catches StandardError(?) > > > As luck (irony?) would have it, the default _is_ Exception. So if you > alias it in your project, you'll get what you're after. > > > raise_error seems less readable to me, as there is no Error class. > > > This is sound logic, but I think it would do more harm than good at > this point. > > If we were starting today, I'd probably want to have raise_exception > and raise_error, with the defaults being Exception and StandardError > respectively. That would certainly improve the accuracy of the intent > expressed in specs. The problem at this point is that it changes the > meaning of raise_error, which would lead to new failures (which cause > pain), and false positives (which cause pain you don't even know is > being caused). > > If we just alias raise_error with raise_exception, now we have two > methods that do the same thing, and the fact that they have names that > might mean different things to different people, I think we'd end up > with more confusion. > > If we replace raise_error with raise_exception, we'd have to deprecate > raise_error, which causes pain that would be difficult to justify to many. > > So we're going to leave it as raise_error for now. If you'd like to > push on this (which you're welcome to), please add a ticket to > lighthouse so it's easy to find the discussions around it. If we can > get general consensus that this would be a good move in spite of the > negatives I just outlined, I'm happy to do it. Maybe a voting process would be a good idea... But where to get visibility? I don't think a deprecation would cause that much of pain, once it is justified in a changelog. Maybe it would be a change for the next major version, where people are more willing to accept major changes... My vote would be to include raise_exception (independently to aliasing it or not) as the specs turns out more concise when the exception is not an error. Best regards and have a great new year! Rodrigo. __________________________________________________ Fa?a liga??es para outros computadores com o novo Yahoo! Messenger http://br.beta.messenger.yahoo.com/ From ashley.moran at patchspace.co.uk Tue Dec 29 05:28:41 2009 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Tue, 29 Dec 2009 10:28:41 +0000 Subject: [rspec-users] Submitting a Custom Matcher: gem or other method? In-Reply-To: <57c63afe0912280827s18798766r834fe06da2bdee0b@mail.gmail.com> References: <3df642dd0912271203m3559eee5x48edac890e3d44e4@mail.gmail.com> <57c63afe0912280827s18798766r834fe06da2bdee0b@mail.gmail.com> Message-ID: <95B93821-FB39-4644-A07D-C2F92D3052C4@patchspace.co.uk> On 28 Dec 2009, at 16:27, David Chelimsky wrote: > For most users, gems are the easiest answer. By all means, host source on github if you want people to contribute, or have a place to inspect code, but you don't need a public source repository in order to push gems to gemcutter. A standard location for RSpec matchers would be pretty handy though, WDYT? -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashleymoran From dchelimsky at gmail.com Tue Dec 29 10:09:41 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 29 Dec 2009 09:09:41 -0600 Subject: [rspec-users] Submitting a Custom Matcher: gem or other method? In-Reply-To: <95B93821-FB39-4644-A07D-C2F92D3052C4@patchspace.co.uk> References: <3df642dd0912271203m3559eee5x48edac890e3d44e4@mail.gmail.com> <57c63afe0912280827s18798766r834fe06da2bdee0b@mail.gmail.com> <95B93821-FB39-4644-A07D-C2F92D3052C4@patchspace.co.uk> Message-ID: <57c63afe0912290709g7f92a41vfdacb59d09208f5d@mail.gmail.com> On Tue, Dec 29, 2009 at 4:28 AM, Ashley Moran wrote: > > On 28 Dec 2009, at 16:27, David Chelimsky wrote: > > > For most users, gems are the easiest answer. By all means, host source on > github if you want people to contribute, or have a place to inspect code, > but you don't need a public source repository in order to push gems to > gemcutter. > > A standard location for RSpec matchers would be pretty handy though, WDYT? > First, I have no cycles to start setting something up like this for a while now. I'm trying to wrap up the loose ends on the book and get it to production. After that, any spare time I have is going to be devoted to getting the rspec-2.0 and rspec-rails-2.0 (for rails-3.0) projects rolling in earnest. That said, I definitely think we need a home for information about matchers. Hosting them, however, is something I'd rather leave to the professionals :) I've imagined a website where folks can list info about matcher libraries and others can comment and possibly vote on them. If anybody wants to volunteer to drive this in the short run, that would be great, but I won't be able to do it myself for several months. Cheers, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From rogerpack2005 at gmail.com Tue Dec 29 10:26:24 2009 From: rogerpack2005 at gmail.com (rogerdpack) Date: Tue, 29 Dec 2009 07:26:24 -0800 (PST) Subject: [rspec-users] no should raise_exception In-Reply-To: <57c63afe0912281233j44a9721ei5f046043b06b7b55@mail.gmail.com> References: <0ec63fb0-0f54-4304-8286-3e57cfcffa53@b2g2000yqi.googlegroups.com> <4e78b7b60912192207x3217c51dxa71c1038af415b42@mail.gmail.com> <57c63afe0912221408m4e23b599qd9b0f56b847aa26a@mail.gmail.com> <3c4ed96e-9e75-4d09-8f84-a9d7e12d6d46@a6g2000yqm.googlegroups.com> <57c63afe0912281233j44a9721ei5f046043b06b7b55@mail.gmail.com> Message-ID: > So we're going to leave it as raise_error for now. If you'd like to push on > this (which you're welcome to), please add a ticket to lighthouse so it's > easy to find the discussions around it. If we can get general consensus that > this would be a good move in spite of the negatives I just outlined, I'm > happy to do it. All righty let the voting begin. https://rspec.lighthouseapp.com/projects/5645-rspec/tickets/933-add-raise_exception My current leaning is actually (re a previous comment), to add a new method raise_exception, which requires them to pass in the ExceptionClass to be raised, but feel free to discuss this suggestion at the ticket above. -r From dchelimsky at gmail.com Tue Dec 29 10:27:25 2009 From: dchelimsky at gmail.com (dchelimsky at gmail.com) Date: Tue, 29 Dec 2009 07:27:25 -0800 (PST) Subject: [rspec-users] no should raise_exception In-Reply-To: <57c63afe0912281233j44a9721ei5f046043b06b7b55@mail.gmail.com> References: <0ec63fb0-0f54-4304-8286-3e57cfcffa53@b2g2000yqi.googlegroups.com> <4e78b7b60912192207x3217c51dxa71c1038af415b42@mail.gmail.com> <57c63afe0912221408m4e23b599qd9b0f56b847aa26a@mail.gmail.com> <3c4ed96e-9e75-4d09-8f84-a9d7e12d6d46@a6g2000yqm.googlegroups.com> <57c63afe0912281233j44a9721ei5f046043b06b7b55@mail.gmail.com> Message-ID: <0357c189-afa4-4c97-95dc-4bc89edb130d@n16g2000yqm.googlegroups.com> On Dec 28, 2:33?pm, David Chelimsky wrote: > So we're going to leave it as raise_error for now. If you'd like to push on > this (which you're welcome to), please add a ticket to lighthouse so it's > easy to find the discussions around it. If we can get general consensus that > this would be a good move in spite of the negatives I just outlined, I'm > happy to do it. Hey all - Roger submitted https://rspec.lighthouseapp.com/projects/5645/tickets/933 on this, so if anybody else has more thoughts on it, please add them to the ticket. Cheers, David From ed.howland at gmail.com Tue Dec 29 10:53:09 2009 From: ed.howland at gmail.com (Ed Howland) Date: Tue, 29 Dec 2009 10:53:09 -0500 Subject: [rspec-users] Submitting a Custom Matcher: gem or other method? In-Reply-To: <57c63afe0912290709g7f92a41vfdacb59d09208f5d@mail.gmail.com> References: <3df642dd0912271203m3559eee5x48edac890e3d44e4@mail.gmail.com> <57c63afe0912280827s18798766r834fe06da2bdee0b@mail.gmail.com> <95B93821-FB39-4644-A07D-C2F92D3052C4@patchspace.co.uk> <57c63afe0912290709g7f92a41vfdacb59d09208f5d@mail.gmail.com> Message-ID: <3df642dd0912290753h2402b3caw2db4b0efe81cabe2@mail.gmail.com> On Tue, Dec 29, 2009 at 10:09 AM, David Chelimsky wrote: > On Tue, Dec 29, 2009 at 4:28 AM, Ashley Moran > wrote: >> >> On 28 Dec 2009, at 16:27, David Chelimsky wrote: >> > First, I have no cycles to start setting something up like this for a while > now. I'm trying to wrap up the loose ends on the book and get it to > production. After that, any spare time I have is going to be devoted to > getting the rspec-2.0 and rspec-rails-2.0 (for rails-3.0) projects rolling > in earnest. Good luck on the book. I am eager to buy it! > That said,?I definitely think we need a home for information about matchers. > Hosting them, however, is something I'd rather leave to the professionals :) > I've imagined a website where folks can list info about matcher libraries > and others can comment and possibly vote on them. If anybody wants to > volunteer to drive this in the short run, that would be great, but I won't > be able to do it myself for several months. > Cheers, > David Just a suggestion, several other projects have contributions listed on their Git hub wiki. Can we create a page for them, linking to other Github accounts. I don't knoe about voting and such, but it might be a start. The rspec.info page can just link to the Github wiki for a user submitted contributions page and people can go from there. Thereby offloading the responsibility. If I can help help in any way, let me know. Ed -- Ed Howland http://greenprogrammer.wordpress.com http://twitter.com/ed_howland From dchelimsky at gmail.com Tue Dec 29 10:59:18 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 29 Dec 2009 09:59:18 -0600 Subject: [rspec-users] Submitting a Custom Matcher: gem or other method? In-Reply-To: <3df642dd0912290753h2402b3caw2db4b0efe81cabe2@mail.gmail.com> References: <3df642dd0912271203m3559eee5x48edac890e3d44e4@mail.gmail.com> <57c63afe0912280827s18798766r834fe06da2bdee0b@mail.gmail.com> <95B93821-FB39-4644-A07D-C2F92D3052C4@patchspace.co.uk> <57c63afe0912290709g7f92a41vfdacb59d09208f5d@mail.gmail.com> <3df642dd0912290753h2402b3caw2db4b0efe81cabe2@mail.gmail.com> Message-ID: <57c63afe0912290759s26f0edbbuc348b70291669c58@mail.gmail.com> On Tue, Dec 29, 2009 at 9:53 AM, Ed Howland wrote: > On Tue, Dec 29, 2009 at 10:09 AM, David Chelimsky > wrote:> That said, I definitely think we need a home for information about > matchers. > > Hosting them, however, is something I'd rather leave to the professionals > :) > > I've imagined a website where folks can list info about matcher libraries > > and others can comment and possibly vote on them. If anybody wants to > > volunteer to drive this in the short run, that would be great, but I > won't > > be able to do it myself for several months. > > Cheers, > > David > > Just a suggestion, several other projects have contributions listed on > their Git hub wiki. Can we create a page for them, linking to other > Github accounts. I don't knoe about voting and such, but it might be a > start. The rspec.info page can just link to the Github wiki for a user > submitted contributions page and people can go from there. Thereby > offloading the responsibility. > > If I can help help in any way, let me know. > I started http://wiki.github.com/dchelimsky/rspec/matcher-libraries. Please feel free to modify/add. Ed > > -- > Ed Howland > http://greenprogrammer.wordpress.com > http://twitter.com/ed_howland > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Tue Dec 29 22:25:32 2009 From: lists at ruby-forum.com (John Smith) Date: Wed, 30 Dec 2009 04:25:32 +0100 Subject: [rspec-users] Running cucumber against an application Message-ID: Hello, I have a very simple non-web application I am trying to test against. Say I have a library folder with several .rb files, and the one that is to be executed is main.rb ('ruby main.rb' via command line). How would I set up cucumber to run the above script and test against the output generated? -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Tue Dec 29 22:29:58 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 29 Dec 2009 21:29:58 -0600 Subject: [rspec-users] Running cucumber against an application In-Reply-To: References: Message-ID: <57c63afe0912291929j3fbb5293ka7d7c9f79286b37d@mail.gmail.com> On Tue, Dec 29, 2009 at 9:25 PM, John Smith wrote: > Hello, I have a very simple non-web application I am trying to test > against. Say I have a library folder with several .rb files, and the one > that is to be executed is main.rb ('ruby main.rb' via command line). > How would I set up cucumber to run the above script and test against the > output generated? > Please direct Cucumber questions to http://groups.google.com/group/cukes. Cheers, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From t73net at t73.biz Wed Dec 30 07:20:57 2009 From: t73net at t73.biz (Ronald Chaplin) Date: Wed, 30 Dec 2009 07:20:57 -0500 Subject: [rspec-users] Spec time reporting precision Message-ID: <1262175657.6860.8.camel@ronald-desktop> Hey all, So I woke up early this morning, and was running some tests through autospec, and it returned a time as follows: Finished in 0.0151600000000001 seconds I know that there are alot of other more important issues being addressed right now for the rspec project, (2.0 for Rails 3.0). However, do we really need this level of precision for spec tests? I know that it's nice to see if your refactoring made any changes in overall performance. But do we really need it carried out to 16 decimal places? Just seems like over kill to me. One solution I had thought about was simply having a boolean switch option for rspec called precise, wherein it would print shortened, less precise times for those who wanted it. I'd even be willing to do the leg work/patches for it if this doesn't seem like a crazy idea. Just self.trying_to + something.useful? -- Ronald Chaplin T73 Biz From dchelimsky at gmail.com Wed Dec 30 10:26:15 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 30 Dec 2009 09:26:15 -0600 Subject: [rspec-users] Spec time reporting precision In-Reply-To: <1262175657.6860.8.camel@ronald-desktop> References: <1262175657.6860.8.camel@ronald-desktop> Message-ID: <57c63afe0912300726n79ff1bbbr690dbf782888cbd2@mail.gmail.com> On Wed, Dec 30, 2009 at 6:20 AM, Ronald Chaplin wrote: > Hey all, > So I woke up early this morning, and was running some tests through > autospec, and it returned a time as follows: > > Finished in 0.0151600000000001 seconds > > I know that there are alot of other more important issues being > addressed right now for the rspec project, (2.0 for Rails 3.0). However, > do we really need this level of precision for spec tests? I know that > it's nice to see if your refactoring made any changes in overall > performance. But do we really need it carried out to 16 decimal places? > Just seems like over kill to me. > Hey Ronald, Is this actually causing you pain? RSpec isn't doing anything special to get 16 decimal places here. It just uses Timeout from the standard lib, which offers no API for precision. Reducing the precision would require additional code in RSpec, and _that_ seems like overkill to me :) Cheers, David One solution I had thought about was simply having a boolean switch > option for rspec called precise, wherein it would print shortened, less > precise times for those who wanted it. I'd even be willing to do the leg > work/patches for it if this doesn't seem like a crazy idea. > > Just self.trying_to + something.useful? > > -- > Ronald Chaplin > T73 Biz > > _______________________________________________ > 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 t73net at t73.biz Wed Dec 30 11:26:49 2009 From: t73net at t73.biz (Ronald Chaplin) Date: Wed, 30 Dec 2009 11:26:49 -0500 Subject: [rspec-users] Spec time reporting precision In-Reply-To: <57c63afe0912300726n79ff1bbbr690dbf782888cbd2@mail.gmail.com> References: <1262175657.6860.8.camel@ronald-desktop> <57c63afe0912300726n79ff1bbbr690dbf782888cbd2@mail.gmail.com> Message-ID: <1262190409.6860.12.camel@ronald-desktop> On Wed, 2009-12-30 at 09:26 -0600, David Chelimsky wrote: > On Wed, Dec 30, 2009 at 6:20 AM, Ronald Chaplin > wrote: > Hey all, > So I woke up early this morning, and was running some tests > through > autospec, and it returned a time as follows: > > Finished in 0.0151600000000001 seconds > > I know that there are alot of other more important issues > being > addressed right now for the rspec project, (2.0 for Rails > 3.0). However, > do we really need this level of precision for spec tests? I > know that > it's nice to see if your refactoring made any changes in > overall > performance. But do we really need it carried out to 16 > decimal places? > Just seems like over kill to me. > > > Hey Ronald, > > > Is this actually causing you pain? RSpec isn't doing anything special > to get 16 decimal places here. It just uses Timeout from the standard > lib, which offers no API for precision. Reducing the precision would > require additional code in RSpec, and _that_ seems like overkill to > me :) Hey David, Great book btw. I'm learning so much and it has really helped me in my newbie days to ruby. No, it's not a pain. Just seemed like overkill that it would report to such a finite decimal place is all. I guess that's the PHPer in me ackking @ the wasted numbers :p -- Ronald Chaplin T73 Biz > > Cheers, > David > > > One solution I had thought about was simply having a boolean > switch > option for rspec called precise, wherein it would print > shortened, less > precise times for those who wanted it. I'd even be willing to > do the leg > work/patches for it if this doesn't seem like a crazy idea. > > Just self.trying_to + something.useful? > > -- > Ronald Chaplin > T73 Biz > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Wed Dec 30 11:31:09 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 30 Dec 2009 10:31:09 -0600 Subject: [rspec-users] Spec time reporting precision In-Reply-To: <1262190409.6860.12.camel@ronald-desktop> References: <1262175657.6860.8.camel@ronald-desktop> <57c63afe0912300726n79ff1bbbr690dbf782888cbd2@mail.gmail.com> <1262190409.6860.12.camel@ronald-desktop> Message-ID: <57c63afe0912300831x39101d2avcb45826bfde28694@mail.gmail.com> On Wed, Dec 30, 2009 at 10:26 AM, Ronald Chaplin wrote: > On Wed, 2009-12-30 at 09:26 -0600, David Chelimsky wrote: > > On Wed, Dec 30, 2009 at 6:20 AM, Ronald Chaplin > > wrote: > > Hey all, > > So I woke up early this morning, and was running some tests > > through > > autospec, and it returned a time as follows: > > > > Finished in 0.0151600000000001 seconds > > > > I know that there are alot of other more important issues > > being > > addressed right now for the rspec project, (2.0 for Rails > > 3.0). However, > > do we really need this level of precision for spec tests? I > > know that > > it's nice to see if your refactoring made any changes in > > overall > > performance. But do we really need it carried out to 16 > > decimal places? > > Just seems like over kill to me. > > > > > > Hey Ronald, > > > > > > Is this actually causing you pain? RSpec isn't doing anything special > > to get 16 decimal places here. It just uses Timeout from the standard > > lib, which offers no API for precision. Reducing the precision would > > require additional code in RSpec, and _that_ seems like overkill to > > me :) > > Hey David, > Great book btw. I'm learning so much and it has really helped me in my > newbie days to ruby. > That's great to hear. Thanks! > No, it's not a pain. Just seemed like overkill that it would report to > such a finite decimal place is all. I guess that's the PHPer in me > ackking @ the wasted numbers :p > :) Thanks for playing! Cheers, David > -- > Ronald Chaplin > T73 Biz > > > > Cheers, > > David > > > > > > One solution I had thought about was simply having a boolean > > switch > > option for rspec called precise, wherein it would print > > shortened, less > > precise times for those who wanted it. I'd even be willing to > > do the leg > > work/patches for it if this doesn't seem like a crazy idea. > > > > Just self.trying_to + something.useful? > > > > -- > > Ronald Chaplin > > T73 Biz > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rogerpack2005 at gmail.com Wed Dec 30 14:33:58 2009 From: rogerpack2005 at gmail.com (rogerdpack) Date: Wed, 30 Dec 2009 11:33:58 -0800 (PST) Subject: [rspec-users] more verbosity for be_an? Message-ID: before I hack up a patch for it. Would a patch to change "expected Fixnum to be a kind of Fixnum" to "expected Fixnum to be a kind of Fixnum (is a Class)" or possibly "expected Fixnum to be a kind of Fixnum (is a Class, Module, Object, Kernel, BasicObject)" have any chance of being accepted? Thanks. -r From dchelimsky at gmail.com Wed Dec 30 15:19:00 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 30 Dec 2009 14:19:00 -0600 Subject: [rspec-users] more verbosity for be_an? In-Reply-To: References: Message-ID: <57c63afe0912301219l43937dc6he78256e600eeeb30@mail.gmail.com> On Wed, Dec 30, 2009 at 1:33 PM, rogerdpack wrote: > before I hack up a patch for it. Would a patch to change > > "expected Fixnum to be a kind of Fixnum" > > to > > "expected Fixnum to be a kind of Fixnum (is a Class)" > > or possibly > > "expected Fixnum to be a kind of Fixnum (is a Class, Module, Object, > Kernel, BasicObject)" > > > have any chance of being accepted? > Probably not with that exact wording, but if you feel the message is not telling you what you need to know, I'm open to other ideas. What about something like: expected # => Fixnum to be a kind of Fixnum That is more aligned with other failure messages. WDYT? > Thanks. > -r > -------------- next part -------------- An HTML attachment was scrubbed... URL: From paul.t.hinze at gmail.com Wed Dec 30 16:04:46 2009 From: paul.t.hinze at gmail.com (Paul Hinze) Date: Wed, 30 Dec 2009 15:04:46 -0600 Subject: [rspec-users] 'Expected NoMethodError, got NameError' Message-ID: <20091230210446.GS12080@malachai> 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 # ./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 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 From ashley.moran at patchspace.co.uk Wed Dec 30 17:27:11 2009 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Wed, 30 Dec 2009 22:27:11 +0000 Subject: [rspec-users] more verbosity for be_an? In-Reply-To: <57c63afe0912301219l43937dc6he78256e600eeeb30@mail.gmail.com> References: <57c63afe0912301219l43937dc6he78256e600eeeb30@mail.gmail.com> Message-ID: <2122523E-48CF-4596-AAAB-A348F992E932@patchspace.co.uk> On 30 Dec 2009, at 20:19, David Chelimsky wrote: > What about something like: > > expected # => Fixnum to be a kind of Fixnum > > That is more aligned with other failure messages. WDYT? I like that. You have to read the current message _very_ carefully to see what it's actually saying. Thinking about it though, isn't the current format wrong anyway? "Fixnum is the kind of 1" sounds (torturously) correct. For want of ability to say what I mean in terms of types, here are examples instead: Integer is a kind of Object* Object.new is an (instance of) Object Integer is a(n instance of) Class Fixnum is a kind of Integer 1 is a(n instance of) Fixnum Gets a bit harder with modules though: [] is an (instance of) a Class that includes Enumerable [] is Enumerable (second one only works if the module name is an adjective) * Actually, this satisfies both definitions, as Integer is an instance Class, which is an Object... 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. Ashley -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashleymoran From ashley.moran at patchspace.co.uk Wed Dec 30 17:31:06 2009 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Wed, 30 Dec 2009 22:31:06 +0000 Subject: [rspec-users] Submitting a Custom Matcher: gem or other method? In-Reply-To: <57c63afe0912290759s26f0edbbuc348b70291669c58@mail.gmail.com> References: <3df642dd0912271203m3559eee5x48edac890e3d44e4@mail.gmail.com> <57c63afe0912280827s18798766r834fe06da2bdee0b@mail.gmail.com> <95B93821-FB39-4644-A07D-C2F92D3052C4@patchspace.co.uk> <57c63afe0912290709g7f92a41vfdacb59d09208f5d@mail.gmail.com> <3df642dd0912290753h2402b3caw2db4b0efe81cabe2@mail.gmail.com> <57c63afe0912290759s26f0edbbuc348b70291669c58@mail.gmail.com> Message-ID: <5C670473-0AB4-42FF-8C58-BFB6647C1E61@patchspace.co.uk> On 29 Dec 2009, at 15:59, David Chelimsky wrote: > I started http://wiki.github.com/dchelimsky/rspec/matcher-libraries. Please feel free to modify/add. I like! A wiki solves 90% of problems like this with 2% of the effort. I hadn't realised the wiki had moved along - unlike Cucumber, I still see the static site as the primary reference. Wasn't expecting you to drop everything and build a matcher hosting platform :) Cheers Ashley -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashleymoran From rogerpack2005 at gmail.com Wed Dec 30 18:27:34 2009 From: rogerpack2005 at gmail.com (rogerdpack) Date: Wed, 30 Dec 2009 15:27:34 -0800 (PST) Subject: [rspec-users] more verbosity for be_an? In-Reply-To: <57c63afe0912301219l43937dc6he78256e600eeeb30@mail.gmail.com> References: <57c63afe0912301219l43937dc6he78256e600eeeb30@mail.gmail.com> Message-ID: > 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. -r From matt at mattwynne.net Thu Dec 31 12:38:47 2009 From: matt at mattwynne.net (Matt Wynne) Date: Thu, 31 Dec 2009 17:38:47 +0000 Subject: [rspec-users] Submitting a Custom Matcher: gem or other method? In-Reply-To: <5C670473-0AB4-42FF-8C58-BFB6647C1E61@patchspace.co.uk> References: <3df642dd0912271203m3559eee5x48edac890e3d44e4@mail.gmail.com> <57c63afe0912280827s18798766r834fe06da2bdee0b@mail.gmail.com> <95B93821-FB39-4644-A07D-C2F92D3052C4@patchspace.co.uk> <57c63afe0912290709g7f92a41vfdacb59d09208f5d@mail.gmail.com> <3df642dd0912290753h2402b3caw2db4b0efe81cabe2@mail.gmail.com> <57c63afe0912290759s26f0edbbuc348b70291669c58@mail.gmail.com> <5C670473-0AB4-42FF-8C58-BFB6647C1E61@patchspace.co.uk> Message-ID: <131679F2-7037-4461-821E-820E1EE54E2A@mattwynne.net> On 30 Dec 2009, at 22:31, Ashley Moran wrote: > Wasn't expecting you to drop everything and build a matcher hosting > platform :) I think he should. It is Christmas, and it's not like David ever does anything else for the community ;) cheers, Matt http://mattwynne.net +447974 430184 From phillipkoebbe at gmail.com Thu Dec 31 13:54:34 2009 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Thu, 31 Dec 2009 10:54:34 -0800 (PST) Subject: [rspec-users] Private method in custom module Message-ID: <68c47dab-7ee9-48a2-b8d0-5fa7d6f5b097@k19g2000yqc.googlegroups.com> I have a module of custom examples, such as module ControllerHelperMethods module MyExampleGroupMethods def should_set_the_body_id(body_id) it "should set the body id to '#{body_id}'" do assigns[:body_id].should == body_id end end end def self.included(receiver) receiver.extend MyExampleGroupMethods end end and in spec_helper: Spec::Runner.configure do |config| config.include(ControllerHelperMethods, :type => :controllers) end I have duplicate code in two of my custom examples, so I want to refactor it to a private method, but I can't seem to get the private method to work. I have tried the most obvious way (private keyword followed by the method), and also a couple of more clever approaches that involved doing an instance_eval in self.included. First, should I be able to call private methods in my custom examples? If so, how. Peace. Phillip From dchelimsky at gmail.com Thu Dec 31 13:58:08 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 31 Dec 2009 12:58:08 -0600 Subject: [rspec-users] naming help, please Message-ID: <57c63afe0912311058r6afb548am488061adf92cb57e@mail.gmail.com> Hey all, If you like coming up with the perfect method name, please join the fun at https://rspec.lighthouseapp.com/projects/5645-rspec/tickets/935. Cheers, and happy new year! David -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Thu Dec 31 14:04:48 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 31 Dec 2009 13:04:48 -0600 Subject: [rspec-users] Private method in custom module In-Reply-To: <68c47dab-7ee9-48a2-b8d0-5fa7d6f5b097@k19g2000yqc.googlegroups.com> References: <68c47dab-7ee9-48a2-b8d0-5fa7d6f5b097@k19g2000yqc.googlegroups.com> Message-ID: <57c63afe0912311104h55abf100s27c9b2f51102dcc9@mail.gmail.com> On Thu, Dec 31, 2009 at 12:54 PM, Phillip Koebbe wrote: > I have a module of custom examples, such as > > module ControllerHelperMethods > module MyExampleGroupMethods > def should_set_the_body_id(body_id) > it "should set the body id to '#{body_id}'" do > assigns[:body_id].should == body_id > end > end > end > > def self.included(receiver) > receiver.extend MyExampleGroupMethods > end > end > > and in spec_helper: > > Spec::Runner.configure do |config| > config.include(ControllerHelperMethods, :type => :controllers) > end > First of all, you can simplify this by using extend() instead of include() on the config object: module ControllerMacros def should_set_the_body_id(body_id) it "should set the body id to '#{body_id}'" do assigns[:body_id].should == body_id end end end Spec::Runner.configure do |config| config.extend(ControllerMacros, :type => :controllers) end Note that we generally referred to as "macros," so I recommend using that name for consistency. > I have duplicate code in two of my custom examples, so I want to > refactor it to a private method, but I can't seem to get the private > method to work. I have tried the most obvious way (private keyword > followed by the method), and also a couple of more clever approaches > that involved doing an instance_eval in self.included. > I *think* that if you use extend instead of include + included hook, you can just use the private keyword and all will be well. HTH, David > First, should I be able to call private methods in my custom examples? > If so, how. > > Peace. > Phillip > -------------- next part -------------- An HTML attachment was scrubbed... URL: From phillipkoebbe at gmail.com Thu Dec 31 15:05:21 2009 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Thu, 31 Dec 2009 12:05:21 -0800 (PST) Subject: [rspec-users] Private method in custom module In-Reply-To: <57c63afe0912311104h55abf100s27c9b2f51102dcc9@mail.gmail.com> References: <68c47dab-7ee9-48a2-b8d0-5fa7d6f5b097@k19g2000yqc.googlegroups.com> <57c63afe0912311104h55abf100s27c9b2f51102dcc9@mail.gmail.com> Message-ID: <95bec282-a8b1-4839-a6ff-6e23ad8fd5c1@a6g2000yqm.googlegroups.com> Hi David, First, thanks for the suggestion. I like that better. Second, my motivation for doing this was born out of not being able to do something I wanted to do in Remarkable. However, as I was trying to explain what it was I wanted to do, I just discovered how to do it in Remarkable. So, the immediate need for knowing how to call a private method is no longer valid, but I would like to go ahead and explain what I was trying to do to see if it is actually possible. I still have custom macros that I might need to refactor at some point. Here is the relevant code example: http://gist.github.com/266873 [By the way, I didn't intend for the gist to be formatted quite like that. I am fond of 4 character tabs, but I realize that most people in the ruby community use 2 spaces, so I copied the code to a new textmate window, reformatted it, then copied and pasted into the gist. But it still come out like that, so I don't know what I'm supposed to do.] I was attempting to create my own should_set_session so I could use values from instance variables. I didn't see how to do that in Remarkable until just a few minutes ago. It can be accomplished by using :to => proc { @user.id }. I was experimenting with where to call get_value_from_options from. When I try inside the "it", I get the NoMethodError. When I call it from outside of the it, get_value_from_options gets called, but then I don't get the instance variable like I expect. I believe I understand why that is, though. The instance var is created in the before, which is more or less an it, so it has the same scope. So when called from outside of the it, there is no instance var @user. So my question now is simply: Can I even do what I want to do? Thanks, Phillip From dchelimsky at gmail.com Thu Dec 31 15:21:57 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 31 Dec 2009 14:21:57 -0600 Subject: [rspec-users] Private method in custom module In-Reply-To: <95bec282-a8b1-4839-a6ff-6e23ad8fd5c1@a6g2000yqm.googlegroups.com> References: <68c47dab-7ee9-48a2-b8d0-5fa7d6f5b097@k19g2000yqc.googlegroups.com> <57c63afe0912311104h55abf100s27c9b2f51102dcc9@mail.gmail.com> <95bec282-a8b1-4839-a6ff-6e23ad8fd5c1@a6g2000yqm.googlegroups.com> Message-ID: <57c63afe0912311221w1412bb04g91cc055a96812e5b@mail.gmail.com> On Thu, Dec 31, 2009 at 2:05 PM, Phillip Koebbe wrote: > Hi David, > > First, thanks for the suggestion. I like that better. > > Second, my motivation for doing this was born out of not being able to > do something I wanted to do in Remarkable. However, as I was trying to > explain what it was I wanted to do, I just discovered how to do it in > Remarkable. So, the immediate need for knowing how to call a private > method is no longer valid, but I would like to go ahead and explain > what I was trying to do to see if it is actually possible. I still > have custom macros that I might need to refactor at some point. > > Here is the relevant code example: > > http://gist.github.com/266873 Ok - now I understand the problem :) You'll see that even if you make the method public, it still won't work. Here's why: By default, the describe() method returns a class which is a subclass of ExampleGroup. Any methods defined in the describe() block become class methods on that subclass of ExampleGroup. The module is extending the ExampleGroup class, so should_set_session and get_value_from_options are both class methods. The it() method (sort of) returns an _instance_ of the same class. It can only access instance methods directly, _but_ because it is an instance of the class that was extended with the module, you can access get_value_from_options like this: ... it "should set session[:#{key}]" do value = self.class. get_value_from_options(options) ... Make sense? Cheers, David [By the way, I didn't intend for the gist to be formatted quite like > that. I am fond of 4 character tabs, but I realize that most people in > the ruby community use 2 spaces, so I copied the code to a new > textmate window, reformatted it, then copied and pasted into the gist. > But it still come out like that, so I don't know what I'm supposed to > do.] > > I was attempting to create my own should_set_session so I could use > values from instance variables. I didn't see how to do that in > Remarkable until just a few minutes ago. It can be accomplished by > using :to => proc { @user.id }. > > I was experimenting with where to call get_value_from_options from. > When I try inside the "it", I get the NoMethodError. When I call it > from outside of the it, get_value_from_options gets called, but then I > don't get the instance variable like I expect. I believe I understand > why that is, though. The instance var is created in the before, which > is more or less an it, so it has the same scope. So when called from > outside of the it, there is no instance var @user. > > So my question now is simply: Can I even do what I want to do? > > Thanks, > Phillip > -------------- next part -------------- An HTML attachment was scrubbed... URL: From phillipkoebbe at gmail.com Thu Dec 31 16:22:35 2009 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Thu, 31 Dec 2009 13:22:35 -0800 (PST) Subject: [rspec-users] Private method in custom module In-Reply-To: <57c63afe0912311221w1412bb04g91cc055a96812e5b@mail.gmail.com> References: <68c47dab-7ee9-48a2-b8d0-5fa7d6f5b097@k19g2000yqc.googlegroups.com> <57c63afe0912311104h55abf100s27c9b2f51102dcc9@mail.gmail.com> <95bec282-a8b1-4839-a6ff-6e23ad8fd5c1@a6g2000yqm.googlegroups.com> <57c63afe0912311221w1412bb04g91cc055a96812e5b@mail.gmail.com> Message-ID: <85e40d80-c52b-467d-96bf-ccb3d8c8450e@m3g2000yqf.googlegroups.com> David, On Dec 31, 2:21?pm, David Chelimsky wrote: > Make sense? > Yes. Thanks for taking the time to explain! Peace, Phillip From carsupb at yahoo.com Wed Dec 30 11:30:50 2009 From: carsupb at yahoo.com (John j. Cuckler) Date: Wed, 30 Dec 2009 08:30:50 -0800 (PST) Subject: [rspec-users] Fixtures problem with Rails plugin Message-ID: <6a4e6e88-a045-407f-9ffc-720a3fff8261@o28g2000yqh.googlegroups.com> 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 Everything is up to date, both rails and rspec gems. Any idea? Thanks JJ