From work at ashleymoran.me.uk Thu Feb 1 10:54:48 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Thu, 1 Feb 2007 15:54:48 +0000 Subject: [rspec-users] Structure for library code specs Message-ID: Hi Are there any plans to add a structure for library specs, eg RAILS_ROOT/spec/lib ? There's no equivalent spec:libraries task, and any spec lines for library code are lost from the rake stats output. Ashley From dchelimsky at gmail.com Thu Feb 1 11:35:05 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 1 Feb 2007 10:35:05 -0600 Subject: [rspec-users] Structure for library code specs In-Reply-To: References: Message-ID: <57c63afe0702010835y4df95882o1d5bdb793c8b7af7@mail.gmail.com> There's been no plan for it but we would consider this. If you're interested in seeing it happen, please submit an RFE: http://rspec.rubyforge.org/contribute.html http://rubyforge.org/tracker/?group_id=797 Cheers, David On 2/1/07, Ashley Moran wrote: > Hi > > Are there any plans to add a structure for library specs, eg > RAILS_ROOT/spec/lib ? There's no equivalent spec:libraries task, and > any spec lines for library code are lost from the rake stats output. > > Ashley > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From work at ashleymoran.me.uk Thu Feb 1 12:38:57 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Thu, 1 Feb 2007 17:38:57 +0000 Subject: [rspec-users] Structure for library code specs In-Reply-To: <57c63afe0702010835y4df95882o1d5bdb793c8b7af7@mail.gmail.com> References: <57c63afe0702010835y4df95882o1d5bdb793c8b7af7@mail.gmail.com> Message-ID: <5739D55F-ED92-4D6E-846A-171BBEC056E2@ashleymoran.me.uk> On 1 Feb 2007, at 16:35, David Chelimsky wrote: > There's been no plan for it but we would consider this. If you're > interested in seeing it happen, please submit an RFE: > > http://rspec.rubyforge.org/contribute.html > http://rubyforge.org/tracker/?group_id=797 > > Cheers, > David Thanks - just done From cwdinfo at gmail.com Thu Feb 1 14:23:09 2007 From: cwdinfo at gmail.com (s.ross) Date: Thu, 1 Feb 2007 11:23:09 -0800 Subject: [rspec-users] should_redirect_to in rspec-0.8.0 / rspec_on_rails 1453 Message-ID: <94A8EC69-794A-4951-BD64-4518AB39A75E@gmail.com> I have a spec: specify "a post with no user id should add a record" do post :edit_or_create, :user => {:login => 'joeschmoe', :email => 'joe at shmoe.com', :email_confirmation => 'joe at shmoe.com', :full_name => 'Joe Schmoe'} assigns[:user].should_not_be_nil assigns[:user].new_record?.should_not_be(true) flash[:notice].should_match(/user added/) response.should_be_redirect puts "redirecting to #{response.redirect_url}" puts "this response was #{response.redirect?}" controller.should_redirect_to 'http://test.host/user' end the puts statements output the following: redirecting to http://test.host/user this response was true Any idea why this line: controller.should_redirect_to 'http://test.host/user' would fail with the message: 'Given a UserController edit a post with no user id should add a record' FAILED controller expected call to redirect_to "http://test.host/user" but it was never received From unclebob at objectmentor.com Thu Feb 1 16:20:04 2007 From: unclebob at objectmentor.com (Robert Martin) Date: Thu, 1 Feb 2007 15:20:04 -0600 Subject: [rspec-users] should_redirect_to in rspec-0.8.0 / rspec_on_rails 1453 In-Reply-To: <94A8EC69-794A-4951-BD64-4518AB39A75E@gmail.com> References: <94A8EC69-794A-4951-BD64-4518AB39A75E@gmail.com> Message-ID: <3213E149-A8FB-42B4-889B-D7C57AF9041B@objectmentor.com> The "should-redirect-to" has to be called before the 'post'. I think it's setting up a mock. On Feb 1, 2007, at 1:23 PM, s.ross wrote: > I have a spec: > > specify "a post with no user id should add a record" do > post :edit_or_create, :user => {:login => 'joeschmoe', :email => > 'joe at shmoe.com', :email_confirmation => 'joe at shmoe.com', :full_name > => 'Joe Schmoe'} > assigns[:user].should_not_be_nil > assigns[:user].new_record?.should_not_be(true) > flash[:notice].should_match(/user added/) > response.should_be_redirect > puts "redirecting to #{response.redirect_url}" > puts "this response was #{response.redirect?}" > controller.should_redirect_to 'http://test.host/user' > end > > the puts statements output the following: > > redirecting to http://test.host/user > this response was true > > Any idea why this line: > > controller.should_redirect_to 'http://test.host/user' > > would fail with the message: > > 'Given a UserController edit a post with no user id should add a > record' FAILED > controller expected call to redirect_to "http://test.host/user" but > it was never received > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users ---- Robert C. Martin (Uncle Bob) | email: unclebob at objectmentor.com Object Mentor Inc. | blog: www.butunclebob.com The Agile Transition Experts | web: www.objectmentor.com 800-338-6716 | -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070201/04ad8626/attachment.html From cwdinfo at gmail.com Thu Feb 1 17:22:21 2007 From: cwdinfo at gmail.com (s.ross) Date: Thu, 1 Feb 2007 14:22:21 -0800 Subject: [rspec-users] should_redirect_to in rspec-0.8.0 / rspec_on_rails 1453 In-Reply-To: <3213E149-A8FB-42B4-889B-D7C57AF9041B@objectmentor.com> References: <94A8EC69-794A-4951-BD64-4518AB39A75E@gmail.com> <3213E149-A8FB-42B4-889B-D7C57AF9041B@objectmentor.com> Message-ID: I changed it to: response.should_redirect_to and it worked. I'm most interested in whether, given a set of circumstances, a particular redirection happens, so I think it has to go after the post. I'm not certain how controller.should_redirect_to would answer this question. Thoughts? On Feb 1, 2007, at 1:20 PM, Robert Martin wrote: > The "should-redirect-to" has to be called before the 'post'. I > think it's setting up a mock. > On Feb 1, 2007, at 1:23 PM, s.ross wrote: > >> I have a spec: >> >> specify "a post with no user id should add a record" do >> post :edit_or_create, :user => {:login => 'joeschmoe', :email => >> 'joe at shmoe.com', :email_confirmation => 'joe at shmoe.com', :full_name >> => 'Joe Schmoe'} >> assigns[:user].should_not_be_nil >> assigns[:user].new_record?.should_not_be(true) >> flash[:notice].should_match(/user added/) >> response.should_be_redirect >> puts "redirecting to #{response.redirect_url}" >> puts "this response was #{response.redirect?}" >> controller.should_redirect_to 'http://test.host/user' >> end >> >> the puts statements output the following: >> >> redirecting to http://test.host/user >> this response was true >> >> Any idea why this line: >> >> controller.should_redirect_to 'http://test.host/user' >> >> would fail with the message: >> >> 'Given a UserController edit a post with no user id should add a >> record' FAILED >> controller expected call to redirect_to "http://test.host/user" but >> it was never received >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > > ---- > Robert C. Martin (Uncle Bob) | email: unclebob at objectmentor.com > Object Mentor Inc. | blog: www.butunclebob.com > The Agile Transition Experts | web: www.objectmentor.com > 800-338-6716 | > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070201/310da6fa/attachment.html From dchelimsky at gmail.com Thu Feb 1 18:23:18 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 1 Feb 2007 17:23:18 -0600 Subject: [rspec-users] should_redirect_to in rspec-0.8.0 / rspec_on_rails 1453 In-Reply-To: References: <94A8EC69-794A-4951-BD64-4518AB39A75E@gmail.com> <3213E149-A8FB-42B4-889B-D7C57AF9041B@objectmentor.com> Message-ID: <57c63afe0702011523n29b5a958ud729a0c7ac568165@mail.gmail.com> On 2/1/07, s.ross wrote: > I changed it to: > > response.should_redirect_to > > and it worked. I'm most interested in whether, given a set of circumstances, > a particular redirection happens, so I think it has to go after the post. > > I'm not certain how controller.should_redirect_to would answer this > question. > > Thoughts? Definitely use response.should_redirect_to after the action. The before the action version is going to be deprecated (it is invasive and buggy). Also, if you're using the trunk, I'd recommend that you give the matcher equivalent a shot: response.should redirect_to #no space after should Cheers, David > > > > On Feb 1, 2007, at 1:20 PM, Robert Martin wrote: > The "should-redirect-to" has to be called before the 'post'. I think it's > setting up a mock. > > On Feb 1, 2007, at 1:23 PM, s.ross wrote: > > I have a spec: > > specify "a post with no user id should add a record" do > post :edit_or_create, :user => {:login => 'joeschmoe', :email => > 'joe at shmoe.com', :email_confirmation => 'joe at shmoe.com', :full_name > => 'Joe Schmoe'} > assigns[:user].should_not_be_nil > assigns[:user].new_record?.should_not_be(true) > flash[:notice].should_match(/user added/) > response.should_be_redirect > puts "redirecting to #{response.redirect_url}" > puts "this response was #{response.redirect?}" > controller.should_redirect_to 'http://test.host/user' > end > > the puts statements output the following: > > redirecting to http://test.host/user > this response was true > > Any idea why this line: > > controller.should_redirect_to 'http://test.host/user' > > would fail with the message: > > 'Given a UserController edit a post with no user id should add a > record' FAILED > controller expected call to redirect_to "http://test.host/user" but > it was never received > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > > ---- > Robert C. Martin (Uncle Bob) | email: unclebob at objectmentor.com > Object Mentor Inc. | blog: www.butunclebob.com > The Agile Transition Experts | web: www.objectmentor.com > 800-338-6716 | > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Fri Feb 2 05:53:50 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 2 Feb 2007 04:53:50 -0600 Subject: [rspec-users] Coming Soon... Message-ID: <57c63afe0702020253y5b5597f3odb63df0e8bbed1de@mail.gmail.com> Dear spec'ers, As many of you already know, we're gearing up for a pretty big 0.8 release of RSpec in the next couple of weeks. I'm writing in advance because I want to give you a heads up about upcoming changes and how they may impact your existing specs. Two important things to note first: 1. We will provide a translator that you'll be able to use to convert the majority of your existing specs to the new syntax before we remove deprecated methods. 2. The syntax changes described below will be the last major changes you'll see before a 1.0 release. Here is the plan, though the time line is not yet clear. == rspec-0.8.0-RC1 * Will be released within the next couple of weeks. * Will be fully backwards compatible with 0.7.5.1. * Will also support all of the new syntax using expectation matchers (see below). Because this is such a significant change, we want to do a Release Candidate first. == rspec-0.8.x Between 0.8.0 and 0.9.0, there will be at least one release that will include: * A pre-0.8 to 0.9 translator. * Noisy deprecation warnings that will let you know what methods will be going and what you should use instead. * A simple means of silencing those warnings (at your own peril!) == rspec-0.9 * Will remove all of the old syntax. ======================================= Here are some answers to some questions that some of you may have: == What is changing? All of the should_xyz methods will be losing an underscore and gaining a space: #before actual.should_equal(expected) actual.should_not_equal(expected) #after actual.should equal(expected) actual.should_not equal(expected) #equal, in this example, is a method that returns an expectation matcher, which Ruby passes to #should, which then interacts with the matcher to evaluate whether or not the expectation is met and report accordingly. All args to expectation matchers will require parens, and blocks must be expressed using curly braces. This has to do with ambiguity of arguments and operator precedence. Don't worry, if you do the wrong thing you'll get a warning. More on this below. == Why this change? The current syntax is supported by some very clever use of method_missing. I'm allowed to say it was clever because I didn't write it ;). At first it seemed awesome, but we've found that it conflicts with other frameworks that use metaprogramming techniques to late-bind to method_missing. So we had to make a choice between rethinking RSpec's implementation or commit to a future of monkey patching other frameworks as they introduce new uses of method_missing. Using expectation matchers means that we only need to add 4 methods to Object: #for expectation matchers should should_not #for mocks/stubs should_receive should_not_receive So it is much less invasive than it was before and, because we are not using method_missing on YOUR objects, is much less conflict/error prone. It also supports a clear entry point to writing custom expectation matchers, so if you have some domain-specific expectations like "should travel_more" or "should get_a_raise", you'll have a very easy means of doing so. == Will there be any existing expectations that will no longer be supported at all? Yes, but only a few, and only related to RSpec on Rails. We will NOT be supporting the following in the new syntax: controller.should_render controller.should_redirect_to You will be able to use instead: response.should render_template response.should render_text response.should redirect_to ... but only after the action. == For )(*&)(*'s sake, WHEN will you stop making changes like this? Right now. While we will not commit to 100% backwards compatibility, we on the RSpec Development Team are as anxious for this to stabilize as you are. We just feel that when we get to a 1.0 release we absolutely must have an API that is solid, easy to use, stable and maintainable. We just didn't see an end in sight to the problems we'd been seeing w/ the soon-to-be-ex-syntax, and we are very confident in this move and its potential to fulfill those requirements. == What's up w/ the parens and {} blocks? Parens: When you do this: a.b c d ... Ruby gives you the all familiar: "warning: parenthesize argument(s) for future version" If you can live w/ that, then have at it w/o the parens. Curly braces: This has to do w/ precedence. do/end has a lower precedence than {}, which means that in this expression: target.should satisfy do end ... the block will be passed to #should instead of #satisfy. We need the blocks to be passed to the matcher (#satisfy in this example), so curly braces are required. This will be enforced by RSpec. When #should or #should_not receive a block, the spec will fail with a warning telling you to use {} instead of do/end. So you won't have the opportunity to simply forget. ======================================= We're very excited about this release. I hope this email answers most of your questions. If you have others, please feel free, though I may punt on technical questions as many of those will be answered by documentation in the 0.8.0-RC1 release. Thanks for your patience with this and thanks especially to all of those who contribute to RSpec's evolution by participating with this list and submitting RFEs to the tracker. Cheers, David on behalf of The RSpec Development Team From bkeepers at gmail.com Fri Feb 2 09:31:33 2007 From: bkeepers at gmail.com (Brandon Keepers) Date: Fri, 2 Feb 2007 09:31:33 -0500 Subject: [rspec-users] Coming Soon... In-Reply-To: <57c63afe0702020253y5b5597f3odb63df0e8bbed1de@mail.gmail.com> References: <57c63afe0702020253y5b5597f3odb63df0e8bbed1de@mail.gmail.com> Message-ID: <1FB51DB3-E876-4B86-810E-AB3365140CC2@gmail.com> David & crew, On Feb 2, 2007, at 5:53 AM, David Chelimsky wrote: > == What's up w/ the parens and {} blocks? > > Parens: When you do this: > > a.b c d > > ... Ruby gives you the all familiar: > > "warning: parenthesize argument(s) for future version" > > If you can live w/ that, then have at it w/o the parens. > > Curly braces: This has to do w/ precedence. do/end has a lower > precedence than {}, which means that in this expression: > > target.should satisfy do > end > > ... the block will be passed to #should instead of #satisfy. We need > the blocks to be passed to the matcher (#satisfy in this example), so > curly braces are required. This will be enforced by RSpec. When > #should or #should_not receive a block, the spec will fail with a > warning telling you to use {} instead of do/end. So you won't have the > opportunity to simply forget. You could also do: target.should(satisfy do # block here end) It's not necessarily any cleaner, but it works. Good work! I like the new syntax and am looking forward to being able to write my own expectations. Brandon From dchelimsky at gmail.com Fri Feb 2 09:51:23 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 2 Feb 2007 08:51:23 -0600 Subject: [rspec-users] Coming Soon... In-Reply-To: <1FB51DB3-E876-4B86-810E-AB3365140CC2@gmail.com> References: <57c63afe0702020253y5b5597f3odb63df0e8bbed1de@mail.gmail.com> <1FB51DB3-E876-4B86-810E-AB3365140CC2@gmail.com> Message-ID: <57c63afe0702020651x6c3ef2ah7da1a8f889e726dc@mail.gmail.com> On 2/2/07, Brandon Keepers wrote: > David & crew, > > On Feb 2, 2007, at 5:53 AM, David Chelimsky wrote: > > > == What's up w/ the parens and {} blocks? > > > > Parens: When you do this: > > > > a.b c d > > > > ... Ruby gives you the all familiar: > > > > "warning: parenthesize argument(s) for future version" > > > > If you can live w/ that, then have at it w/o the parens. > > > > Curly braces: This has to do w/ precedence. do/end has a lower > > precedence than {}, which means that in this expression: > > > > target.should satisfy do > > end > > > > ... the block will be passed to #should instead of #satisfy. We need > > the blocks to be passed to the matcher (#satisfy in this example), so > > curly braces are required. This will be enforced by RSpec. When > > #should or #should_not receive a block, the spec will fail with a > > warning telling you to use {} instead of do/end. So you won't have the > > opportunity to simply forget. > > You could also do: > > target.should(satisfy do > # block here > end) > > It's not necessarily any cleaner, but it works. > > Good work! I like the new syntax and am looking forward to being > able to write my own expectations. Cool. Let us know as you do, especially if you come up w/ some that are more general purpose. Thanks, David > > Brandon > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jodi at nnovation.ca Fri Feb 2 10:42:00 2007 From: jodi at nnovation.ca (Jodi Showers) Date: Fri, 2 Feb 2007 10:42:00 -0500 Subject: [rspec-users] Coming Soon... In-Reply-To: <57c63afe0702020253y5b5597f3odb63df0e8bbed1de@mail.gmail.com> References: <57c63afe0702020253y5b5597f3odb63df0e8bbed1de@mail.gmail.com> Message-ID: <219BF561-853F-4E42-B202-301E27DA78EB@nNovation.ca> On 2-Feb-07, at 5:53 AM, David Chelimsky wrote: > Dear spec'ers, > > As many of you already know, we're gearing up for a pretty big 0.8 > release of RSpec in the next couple of weeks. I'm writing in advance > because I want to give you a heads up about upcoming changes and how > they may impact your existing specs. David - I've monkey patched[1] 0.7.5.1 to support simply_helpful, and the rspec on rails plugin to support testing of mime return types (rss, atom, xml, etc). Should I continue to patch, or does big .8 address them? Cheers, Jodi General Partner The nNovation Group inc. www.nnovation.ca/blog [1] http://www.nnovation.ca/2006/12/17/rspec-rails12-and-testing- return-types From lists-rspec at shopwatch.org Fri Feb 2 10:47:09 2007 From: lists-rspec at shopwatch.org (Jay Levitt) Date: Fri, 02 Feb 2007 10:47:09 -0500 Subject: [rspec-users] Coming Soon... In-Reply-To: <57c63afe0702020651x6c3ef2ah7da1a8f889e726dc@mail.gmail.com> References: <57c63afe0702020253y5b5597f3odb63df0e8bbed1de@mail.gmail.com> <1FB51DB3-E876-4B86-810E-AB3365140CC2@gmail.com> <57c63afe0702020651x6c3ef2ah7da1a8f889e726dc@mail.gmail.com> Message-ID: <45C35CFD.4090809@rubyforge.org> David Chelimsky wrote: >>> Parens: When you do this: >>> >>> a.b c d >>> >>> ... Ruby gives you the all familiar: >>> >>> "warning: parenthesize argument(s) for future version" Nutty thought: the code is executed by eval'ing the block passed to context, right? So couldn't context eval a version of the code that was parsed by something like, though more robust than, s/\.should/\.should\(.*\)/ ? Jay From dchelimsky at gmail.com Fri Feb 2 10:48:24 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 2 Feb 2007 09:48:24 -0600 Subject: [rspec-users] Coming Soon... In-Reply-To: <219BF561-853F-4E42-B202-301E27DA78EB@nNovation.ca> References: <57c63afe0702020253y5b5597f3odb63df0e8bbed1de@mail.gmail.com> <219BF561-853F-4E42-B202-301E27DA78EB@nNovation.ca> Message-ID: <57c63afe0702020748t3345d37coe8cf06324f16213e@mail.gmail.com> On 2/2/07, Jodi Showers wrote: > > On 2-Feb-07, at 5:53 AM, David Chelimsky wrote: > > > Dear spec'ers, > > > > As many of you already know, we're gearing up for a pretty big 0.8 > > release of RSpec in the next couple of weeks. I'm writing in advance > > because I want to give you a heads up about upcoming changes and how > > they may impact your existing specs. > > David - > > I've monkey patched[1] 0.7.5.1 to support simply_helpful, and the > rspec on rails plugin to support testing of mime return types (rss, > atom, xml, etc). > > Should I continue to patch, or does big .8 address them? 0.8 includes a complete port of assert_select, so it does support testing feeds, email, etc. I can't be certain though without more specifics. What exactly did you monkey patch? > > Cheers, > Jodi > General Partner > The nNovation Group inc. > www.nnovation.ca/blog > > [1] http://www.nnovation.ca/2006/12/17/rspec-rails12-and-testing- > return-types > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jodi at nnovation.ca Fri Feb 2 11:00:01 2007 From: jodi at nnovation.ca (Jodi Showers) Date: Fri, 2 Feb 2007 11:00:01 -0500 Subject: [rspec-users] Coming Soon... In-Reply-To: <57c63afe0702020748t3345d37coe8cf06324f16213e@mail.gmail.com> References: <57c63afe0702020253y5b5597f3odb63df0e8bbed1de@mail.gmail.com> <219BF561-853F-4E42-B202-301E27DA78EB@nNovation.ca> <57c63afe0702020748t3345d37coe8cf06324f16213e@mail.gmail.com> Message-ID: On 2-Feb-07, at 10:48 AM, David Chelimsky wrote: > On 2/2/07, Jodi Showers wrote: >> >> On 2-Feb-07, at 5:53 AM, David Chelimsky wrote: >> >>> Dear spec'ers, >>> >>> As many of you already know, we're gearing up for a pretty big 0.8 >>> release of RSpec in the next couple of weeks. I'm writing in advance >>> because I want to give you a heads up about upcoming changes and how >>> they may impact your existing specs. >> >> David - >> >> I've monkey patched[1] 0.7.5.1 to support simply_helpful, and the >> rspec on rails plugin to support testing of mime return types (rss, >> atom, xml, etc). >> >> Should I continue to patch, or does big .8 address them? > > 0.8 includes a complete port of assert_select, so it does support > testing feeds, email, etc. I can't be certain though without more > specifics. What exactly did you monkey patch? The patching builds upon Louren's work and is probably best understood here: http://www.nnovation.ca/2006/12/17/rspec-rails12-and-testing-return- types Thanx David. Jodi From dchelimsky at gmail.com Fri Feb 2 11:06:33 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 2 Feb 2007 10:06:33 -0600 Subject: [rspec-users] Coming Soon... In-Reply-To: <45C35CFD.4090809@rubyforge.org> References: <57c63afe0702020253y5b5597f3odb63df0e8bbed1de@mail.gmail.com> <1FB51DB3-E876-4B86-810E-AB3365140CC2@gmail.com> <57c63afe0702020651x6c3ef2ah7da1a8f889e726dc@mail.gmail.com> <45C35CFD.4090809@rubyforge.org> Message-ID: <57c63afe0702020806v55233bf5l631f97b795ac9351@mail.gmail.com> On 2/2/07, Jay Levitt wrote: > David Chelimsky wrote: > >>> Parens: When you do this: > >>> > >>> a.b c d > >>> > >>> ... Ruby gives you the all familiar: > >>> > >>> "warning: parenthesize argument(s) for future version" > > Nutty thought: the code is executed by eval'ing the block passed to > context, right? So couldn't context eval a version of the code that was > parsed by something like, though more robust than, > s/\.should/\.should\(.*\)/ ? It doesn't parse the block - it executes it. I think that parsing it would open up a huge can of worms. Nutty idea though ;) Cheers, David > > Jay > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From cwdinfo at gmail.com Sun Feb 4 13:53:39 2007 From: cwdinfo at gmail.com (s.ross) Date: Sun, 4 Feb 2007 10:53:39 -0800 Subject: [rspec-users] Spec'ing ActionMailer Message-ID: <6062617A-0CEB-4C3E-8174-8037C3B756F7@gmail.com> Good morning (Pacific Time). I have a controller action that, as a side-effect, sends an email to an administrator. I want it to do something like this: specify "when someone successfully signs up, an email should be sent to the administrator with the person's contact page" do post :signup, {...lots o' params} response should_be success # here's where I want to see whether email was sent. Of course, the code is bogus. email.body.should have_tag(:p, :content => /page=/) end Is there some way to reach in and grab the message (what I've written as "email" above) so I can test the various parameters such as the "to" array and the email contents? I'm most interested in whether the controller/mailer interaction is working properly. Also, can I use the DOM select expectations or is it a simple matcher? Thanks From cdemyanovich at gmail.com Sun Feb 4 14:56:51 2007 From: cdemyanovich at gmail.com (Craig Demyanovich) Date: Sun, 4 Feb 2007 14:56:51 -0500 Subject: [rspec-users] Spec'ing ActionMailer In-Reply-To: <6062617A-0CEB-4C3E-8174-8037C3B756F7@gmail.com> References: <6062617A-0CEB-4C3E-8174-8037C3B756F7@gmail.com> Message-ID: <9C0A4BB1-16F3-447B-BAEC-19CAC144A52F@gmail.com> On Feb 4, 2007, at 1:53 PM, s.ross wrote: > Good morning (Pacific Time). I have a controller action that, as a > side-effect, sends an email to an administrator. I want it to do > something like this: > > specify "when someone successfully signs up, an email should be sent > to the administrator with the person's contact page" do > post :signup, {...lots o' params} > response should_be success > > # here's where I want to see whether email was sent. Of course, > the code is bogus. > email.body.should have_tag(:p, :content => /page=/) > end > > Is there some way to reach in and grab the message (what I've written > as "email" above) so I can test the various parameters such as the > "to" array and the email contents? I'm most interested in whether the > controller/mailer interaction is working properly. Also, can I use > the DOM select expectations or is it a simple matcher? On my first Rails project, I had to test whether a controller sent email when a job application was submitted. Fortunately, ActionMailer doesn't deliver email when running in a test environment. Rather, it records deliveries and makes them available via ActionMailer::Base.deliveries. I demonstrate this below. Note that the chapter on ActionMailer in AWDwR was very helpful to me, since it described a couple of ways to test sending email. Anyway, here's the code. Perhaps you can translate it into some specs. Craig require File.dirname(__FILE__) + '/../test_helper' require 'jobs_controller' # Re-raise errors caught by the controller. class JobsController; def rescue_action(e) raise e end; end class JobsControllerTest < Test::Unit::TestCase fixtures #... def setup #... @emails = ActionMailer::Base.deliveries @emails.clear end def test_submit_application post :submit_application, :job_application => { # lots of params } assert_response :success assert_template 'submit_application' assert_equal(2, @emails.size) email = @emails.first assert_match(/Confirm/, email.subject) assert_equal('john at doe.com', email.to()[0]) email = @emails[1] assert_match(/Resume received/, email.subject) assert_equal('jobs at host.com', email.to()[0]) end end From cwdinfo at gmail.com Sun Feb 4 16:14:08 2007 From: cwdinfo at gmail.com (s.ross) Date: Sun, 4 Feb 2007 13:14:08 -0800 Subject: [rspec-users] Spec'ing ActionMailer In-Reply-To: <9C0A4BB1-16F3-447B-BAEC-19CAC144A52F@gmail.com> References: <6062617A-0CEB-4C3E-8174-8037C3B756F7@gmail.com> <9C0A4BB1-16F3-447B-BAEC-19CAC144A52F@gmail.com> Message-ID: <676E68F2-5DEE-4743-BF4F-52FE33823220@gmail.com> Yes, this works in the Test::Unit framework, but the rSpec behavior specing is -- to me -- different in spirit. My scenario is less about testing whether the mailer should send mail than it is about whether the action should trigger an email and then what the email should contain. I settled on this hack: specify "should send a ping when a signup occurs" do post :signup, {"member"=>{ "email_confirmation"=>"joe at schmoe.com", "last"=>"Schmoe", "first"=>"Joe", "phone"=>"111-222-3333", "working_with_agent"=>"0", "preferred_contact_method"=>"email", "agent_name"=>"", "email"=>"joe at schmoe.com"}, "projects"=>["3"]} response.should be_success email = ActionMailer::Base.deliveries[0] email.body.should include('joe at schmoe.com') email.body.should include(projects(:trace).name) email.body.should include('member/show') email.to.should include('webmaster at test.host') end end The code works, but relies on me knowing something about how ActionMailer collects emails in test mode. My question is: Should my spec presume this much knowledge or is there a better way to accomplish it? Steve On Feb 4, 2007, at 11:56 AM, Craig Demyanovich wrote: > On Feb 4, 2007, at 1:53 PM, s.ross wrote: > >> Good morning (Pacific Time). I have a controller action that, as a >> side-effect, sends an email to an administrator. I want it to do >> something like this: >> >> specify "when someone successfully signs up, an email should be sent >> to the administrator with the person's contact page" do >> post :signup, {...lots o' params} >> response should_be success >> >> # here's where I want to see whether email was sent. Of course, >> the code is bogus. >> email.body.should have_tag(:p, :content => /page=/) >> end >> >> Is there some way to reach in and grab the message (what I've written >> as "email" above) so I can test the various parameters such as the >> "to" array and the email contents? I'm most interested in whether the >> controller/mailer interaction is working properly. Also, can I use >> the DOM select expectations or is it a simple matcher? > > On my first Rails project, I had to test whether a controller sent > email when a job application was submitted. Fortunately, ActionMailer > doesn't deliver email when running in a test environment. Rather, it > records deliveries and makes them available via > ActionMailer::Base.deliveries. I demonstrate this below. Note that > the chapter on ActionMailer in AWDwR was very helpful to me, since it > described a couple of ways to test sending email. Anyway, here's the > code. Perhaps you can translate it into some specs. > > Craig > > > > require File.dirname(__FILE__) + '/../test_helper' > require 'jobs_controller' > > # Re-raise errors caught by the controller. > class JobsController; def rescue_action(e) raise e end; end > > class JobsControllerTest < Test::Unit::TestCase > fixtures #... > > def setup > #... > @emails = ActionMailer::Base.deliveries > @emails.clear > end > > def test_submit_application > post :submit_application, :job_application => { > # lots of params > } > > assert_response :success > assert_template 'submit_application' > > assert_equal(2, @emails.size) > > email = @emails.first > assert_match(/Confirm/, email.subject) > assert_equal('john at doe.com', email.to()[0]) > > email = @emails[1] > assert_match(/Resume received/, email.subject) > assert_equal('jobs at host.com', email.to()[0]) > end > end > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Sun Feb 4 16:35:05 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 4 Feb 2007 15:35:05 -0600 Subject: [rspec-users] Spec'ing ActionMailer In-Reply-To: <676E68F2-5DEE-4743-BF4F-52FE33823220@gmail.com> References: <6062617A-0CEB-4C3E-8174-8037C3B756F7@gmail.com> <9C0A4BB1-16F3-447B-BAEC-19CAC144A52F@gmail.com> <676E68F2-5DEE-4743-BF4F-52FE33823220@gmail.com> Message-ID: <57c63afe0702041335j4f56988egb786e6d9f77518c6@mail.gmail.com> Steve - are you using the RSpec trunk? If you are, AND your email is html email, you can use this right now: response.should send_email { with_tag("div", "joe at shmoe.com") with_tag("div", projects(:trace).name) with_tag("div", member/show) } There is no specific support yet for email headers, nor raw text, though I can see now there is a need for that and will raise the appropriate RFE. David On 2/4/07, s.ross wrote: > Yes, this works in the Test::Unit framework, but the rSpec behavior > specing is -- to me -- different in spirit. My scenario is less about > testing whether the mailer should send mail than it is about whether > the action should trigger an email and then what the email should > contain. I settled on this hack: > > specify "should send a ping when a signup occurs" do > post :signup, {"member"=>{ > "email_confirmation"=>"joe at schmoe.com", > "last"=>"Schmoe", > "first"=>"Joe", > "phone"=>"111-222-3333", > "working_with_agent"=>"0", > "preferred_contact_method"=>"email", > "agent_name"=>"", > "email"=>"joe at schmoe.com"}, "projects"=>["3"]} > > response.should be_success > email = ActionMailer::Base.deliveries[0] > email.body.should include('joe at schmoe.com') > email.body.should include(projects(:trace).name) > email.body.should include('member/show') > email.to.should include('webmaster at test.host') > end > end > > The code works, but relies on me knowing something about how > ActionMailer collects emails in test mode. My question is: Should my > spec presume this much knowledge or is there a better way to > accomplish it? > > Steve > > On Feb 4, 2007, at 11:56 AM, Craig Demyanovich wrote: > > > On Feb 4, 2007, at 1:53 PM, s.ross wrote: > > > >> Good morning (Pacific Time). I have a controller action that, as a > >> side-effect, sends an email to an administrator. I want it to do > >> something like this: > >> > >> specify "when someone successfully signs up, an email should be sent > >> to the administrator with the person's contact page" do > >> post :signup, {...lots o' params} > >> response should_be success > >> > >> # here's where I want to see whether email was sent. Of course, > >> the code is bogus. > >> email.body.should have_tag(:p, :content => /page=/) > >> end > >> > >> Is there some way to reach in and grab the message (what I've written > >> as "email" above) so I can test the various parameters such as the > >> "to" array and the email contents? I'm most interested in whether the > >> controller/mailer interaction is working properly. Also, can I use > >> the DOM select expectations or is it a simple matcher? > > > > On my first Rails project, I had to test whether a controller sent > > email when a job application was submitted. Fortunately, ActionMailer > > doesn't deliver email when running in a test environment. Rather, it > > records deliveries and makes them available via > > ActionMailer::Base.deliveries. I demonstrate this below. Note that > > the chapter on ActionMailer in AWDwR was very helpful to me, since it > > described a couple of ways to test sending email. Anyway, here's the > > code. Perhaps you can translate it into some specs. > > > > Craig > > > > > > > > require File.dirname(__FILE__) + '/../test_helper' > > require 'jobs_controller' > > > > # Re-raise errors caught by the controller. > > class JobsController; def rescue_action(e) raise e end; end > > > > class JobsControllerTest < Test::Unit::TestCase > > fixtures #... > > > > def setup > > #... > > @emails = ActionMailer::Base.deliveries > > @emails.clear > > end > > > > def test_submit_application > > post :submit_application, :job_application => { > > # lots of params > > } > > > > assert_response :success > > assert_template 'submit_application' > > > > assert_equal(2, @emails.size) > > > > email = @emails.first > > assert_match(/Confirm/, email.subject) > > assert_equal('john at doe.com', email.to()[0]) > > > > email = @emails[1] > > assert_match(/Resume received/, email.subject) > > assert_equal('jobs at host.com', email.to()[0]) > > end > > end > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Sun Feb 4 16:47:55 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 4 Feb 2007 15:47:55 -0600 Subject: [rspec-users] Spec'ing ActionMailer In-Reply-To: <57c63afe0702041335j4f56988egb786e6d9f77518c6@mail.gmail.com> References: <6062617A-0CEB-4C3E-8174-8037C3B756F7@gmail.com> <9C0A4BB1-16F3-447B-BAEC-19CAC144A52F@gmail.com> <676E68F2-5DEE-4743-BF4F-52FE33823220@gmail.com> <57c63afe0702041335j4f56988egb786e6d9f77518c6@mail.gmail.com> Message-ID: <57c63afe0702041347p51c4ecdeyad91dc79cfa6c096@mail.gmail.com> On 2/4/07, David Chelimsky wrote: > Steve - are you using the RSpec trunk? > > If you are, AND your email is html email, you can use this right now: > > response.should send_email { > with_tag("div", "joe at shmoe.com") > with_tag("div", projects(:trace).name) > with_tag("div", member/show) > } I forgot to mention that you'll need this in setup/teardown when interacting w/ mail: setup do ActionMailer::Base.delivery_method = :test ActionMailer::Base.perform_deliveries = true ActionMailer::Base.deliveries = [] end teardown ActionMailer::Base.deliveries.clear end This email support is from a port of assert_select, and that's how assert_select works. > > There is no specific support yet for email headers, nor raw text, > though I can see now there is a need for that and will raise the > appropriate RFE. > > David > > On 2/4/07, s.ross wrote: > > Yes, this works in the Test::Unit framework, but the rSpec behavior > > specing is -- to me -- different in spirit. My scenario is less about > > testing whether the mailer should send mail than it is about whether > > the action should trigger an email and then what the email should > > contain. I settled on this hack: > > > > specify "should send a ping when a signup occurs" do > > post :signup, {"member"=>{ > > "email_confirmation"=>"joe at schmoe.com", > > "last"=>"Schmoe", > > "first"=>"Joe", > > "phone"=>"111-222-3333", > > "working_with_agent"=>"0", > > "preferred_contact_method"=>"email", > > "agent_name"=>"", > > "email"=>"joe at schmoe.com"}, "projects"=>["3"]} > > > > response.should be_success > > email = ActionMailer::Base.deliveries[0] > > email.body.should include('joe at schmoe.com') > > email.body.should include(projects(:trace).name) > > email.body.should include('member/show') > > email.to.should include('webmaster at test.host') > > end > > end > > > > The code works, but relies on me knowing something about how > > ActionMailer collects emails in test mode. My question is: Should my > > spec presume this much knowledge or is there a better way to > > accomplish it? > > > > Steve > > > > On Feb 4, 2007, at 11:56 AM, Craig Demyanovich wrote: > > > > > On Feb 4, 2007, at 1:53 PM, s.ross wrote: > > > > > >> Good morning (Pacific Time). I have a controller action that, as a > > >> side-effect, sends an email to an administrator. I want it to do > > >> something like this: > > >> > > >> specify "when someone successfully signs up, an email should be sent > > >> to the administrator with the person's contact page" do > > >> post :signup, {...lots o' params} > > >> response should_be success > > >> > > >> # here's where I want to see whether email was sent. Of course, > > >> the code is bogus. > > >> email.body.should have_tag(:p, :content => /page=/) > > >> end > > >> > > >> Is there some way to reach in and grab the message (what I've written > > >> as "email" above) so I can test the various parameters such as the > > >> "to" array and the email contents? I'm most interested in whether the > > >> controller/mailer interaction is working properly. Also, can I use > > >> the DOM select expectations or is it a simple matcher? > > > > > > On my first Rails project, I had to test whether a controller sent > > > email when a job application was submitted. Fortunately, ActionMailer > > > doesn't deliver email when running in a test environment. Rather, it > > > records deliveries and makes them available via > > > ActionMailer::Base.deliveries. I demonstrate this below. Note that > > > the chapter on ActionMailer in AWDwR was very helpful to me, since it > > > described a couple of ways to test sending email. Anyway, here's the > > > code. Perhaps you can translate it into some specs. > > > > > > Craig > > > > > > > > > > > > require File.dirname(__FILE__) + '/../test_helper' > > > require 'jobs_controller' > > > > > > # Re-raise errors caught by the controller. > > > class JobsController; def rescue_action(e) raise e end; end > > > > > > class JobsControllerTest < Test::Unit::TestCase > > > fixtures #... > > > > > > def setup > > > #... > > > @emails = ActionMailer::Base.deliveries > > > @emails.clear > > > end > > > > > > def test_submit_application > > > post :submit_application, :job_application => { > > > # lots of params > > > } > > > > > > assert_response :success > > > assert_template 'submit_application' > > > > > > assert_equal(2, @emails.size) > > > > > > email = @emails.first > > > assert_match(/Confirm/, email.subject) > > > assert_equal('john at doe.com', email.to()[0]) > > > > > > email = @emails[1] > > > assert_match(/Resume received/, email.subject) > > > assert_equal('jobs at host.com', email.to()[0]) > > > end > > > end > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > From cwdinfo at gmail.com Mon Feb 5 00:09:19 2007 From: cwdinfo at gmail.com (s.ross) Date: Sun, 4 Feb 2007 21:09:19 -0800 Subject: [rspec-users] Spec'ing ActionMailer In-Reply-To: <57c63afe0702041347p51c4ecdeyad91dc79cfa6c096@mail.gmail.com> References: <6062617A-0CEB-4C3E-8174-8037C3B756F7@gmail.com> <9C0A4BB1-16F3-447B-BAEC-19CAC144A52F@gmail.com> <676E68F2-5DEE-4743-BF4F-52FE33823220@gmail.com> <57c63afe0702041335j4f56988egb786e6d9f77518c6@mail.gmail.com> <57c63afe0702041347p51c4ecdeyad91dc79cfa6c096@mail.gmail.com> Message-ID: I'm running trunk and tried this. I put a pastie on: http://pastie.caboo.se/37928 Everything up to line 37 passes, but there it fails. The actual html sent to the mailer is:

Joe Schmoe signed the form and expressed interest in the following project(s): #snip#. You may reach Joe at: (111) 222-3333 or email at joe at schmoe.com.

Full contact information has been saved to your database and you may view it at here.

Perhaps I misunderstand how to use with_tag. I've tried: with_tag("p", "joe at schmoe.com") and I tried: with_tag("p", /joe at schmoe.com/) At this point, I'm really guessing but I know the results are good but the spec isn't satisfied. Thoughts? On Feb 4, 2007, at 1:47 PM, David Chelimsky wrote: > On 2/4/07, David Chelimsky wrote: >> Steve - are you using the RSpec trunk? >> >> If you are, AND your email is html email, you can use this right now: >> >> response.should send_email { >> with_tag("div", "joe at shmoe.com") >> with_tag("div", projects(:trace).name) >> with_tag("div", member/show) >> } > > I forgot to mention that you'll need this in setup/teardown when > interacting w/ mail: > > setup do > ActionMailer::Base.delivery_method = :test > ActionMailer::Base.perform_deliveries = true > ActionMailer::Base.deliveries = [] > end > > teardown > ActionMailer::Base.deliveries.clear > end > > This email support is from a port of assert_select, and that's how > assert_select works. > >> >> There is no specific support yet for email headers, nor raw text, >> though I can see now there is a need for that and will raise the >> appropriate RFE. >> >> David >> >> On 2/4/07, s.ross wrote: >>> Yes, this works in the Test::Unit framework, but the rSpec behavior >>> specing is -- to me -- different in spirit. My scenario is less >>> about >>> testing whether the mailer should send mail than it is about whether >>> the action should trigger an email and then what the email should >>> contain. I settled on this hack: >>> >>> specify "should send a ping when a signup occurs" do >>> post :signup, {"member"=>{ >>> "email_confirmation"=>"joe at schmoe.com", >>> "last"=>"Schmoe", >>> "first"=>"Joe", >>> "phone"=>"111-222-3333", >>> "working_with_agent"=>"0", >>> "preferred_contact_method"=>"email", >>> "agent_name"=>"", >>> "email"=>"joe at schmoe.com"}, "projects"=>["3"]} >>> >>> response.should be_success >>> email = ActionMailer::Base.deliveries[0] >>> email.body.should include('joe at schmoe.com') >>> email.body.should include(projects(:trace).name) >>> email.body.should include('member/show') >>> email.to.should include('webmaster at test.host') >>> end >>> end >>> >>> The code works, but relies on me knowing something about how >>> ActionMailer collects emails in test mode. My question is: Should my >>> spec presume this much knowledge or is there a better way to >>> accomplish it? >>> >>> Steve >>> >>> On Feb 4, 2007, at 11:56 AM, Craig Demyanovich wrote: >>> >>>> On Feb 4, 2007, at 1:53 PM, s.ross wrote: >>>> >>>>> Good morning (Pacific Time). I have a controller action that, as a >>>>> side-effect, sends an email to an administrator. I want it to do >>>>> something like this: >>>>> >>>>> specify "when someone successfully signs up, an email should be >>>>> sent >>>>> to the administrator with the person's contact page" do >>>>> post :signup, {...lots o' params} >>>>> response should_be success >>>>> >>>>> # here's where I want to see whether email was sent. Of course, >>>>> the code is bogus. >>>>> email.body.should have_tag(:p, :content => /page=/) >>>>> end >>>>> >>>>> Is there some way to reach in and grab the message (what I've >>>>> written >>>>> as "email" above) so I can test the various parameters such as the >>>>> "to" array and the email contents? I'm most interested in >>>>> whether the >>>>> controller/mailer interaction is working properly. Also, can I use >>>>> the DOM select expectations or is it a simple matcher? >>>> >>>> On my first Rails project, I had to test whether a controller sent >>>> email when a job application was submitted. Fortunately, >>>> ActionMailer >>>> doesn't deliver email when running in a test environment. >>>> Rather, it >>>> records deliveries and makes them available via >>>> ActionMailer::Base.deliveries. I demonstrate this below. Note that >>>> the chapter on ActionMailer in AWDwR was very helpful to me, >>>> since it >>>> described a couple of ways to test sending email. Anyway, here's >>>> the >>>> code. Perhaps you can translate it into some specs. >>>> >>>> Craig >>>> >>>> >>>> >>>> require File.dirname(__FILE__) + '/../test_helper' >>>> require 'jobs_controller' >>>> >>>> # Re-raise errors caught by the controller. >>>> class JobsController; def rescue_action(e) raise e end; end >>>> >>>> class JobsControllerTest < Test::Unit::TestCase >>>> fixtures #... >>>> >>>> def setup >>>> #... >>>> @emails = ActionMailer::Base.deliveries >>>> @emails.clear >>>> end >>>> >>>> def test_submit_application >>>> post :submit_application, :job_application => { >>>> # lots of params >>>> } >>>> >>>> assert_response :success >>>> assert_template 'submit_application' >>>> >>>> assert_equal(2, @emails.size) >>>> >>>> email = @emails.first >>>> assert_match(/Confirm/, email.subject) >>>> assert_equal('john at doe.com', email.to()[0]) >>>> >>>> email = @emails[1] >>>> assert_match(/Resume received/, email.subject) >>>> assert_equal('jobs at host.com', email.to()[0]) >>>> end >>>> end >>>> >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-users at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From jchris at mfdz.com Mon Feb 5 01:47:32 2007 From: jchris at mfdz.com (Chris Anderson) Date: Sun, 4 Feb 2007 22:47:32 -0800 Subject: [rspec-users] long jumping out of code in specs Message-ID: I wrote this abomination just now, and wonder if anyone else has had experience with the pattern behind it. In short, I'm specing an after_create hook on an ActiveRecord model, that calls a bunch of private methods. Instead of stubbing all those private methods (which is verboten anyway, as well as impossible because creating the object which owns those methods is what I'm specing, so I don't have the object until I call do_action.) I'm stubbing a public method that would only get called if control-flow worked out like it should (the proverbial canary in the coal mine), and telling it to raise an exception which I catch in my spec. This way I don't have to bother with either stubbing all the private methods called in my after_create hook, or making the mock I'm sending though this gauntlet respond properly to all the calls it gets. In my case calling RssParser.new is evidence enough that my code executed like it should. class SpecShortcut < Exception; end specify "should call the standard parsing methods" do RssParser.should_receive(:new).and_raise(SpecShortcut) lambda{do_action}.should_raise(SpecShortcut) end Feeling pain like this while writing specs is usally an indication that the code could be better designed. But I don't see how else one could spec ActiveRecord's after_create hook, without going through with mocking and stubbing all the code the after_create hook uses. Stopping execution at the point where the expectation is satisfied is also appealing, in a premature optimization kind of way. Like I said, an abomination, but maybe a useful one. -- Chris Anderson http://jchris.mfdz.com From crafterm at gmail.com Mon Feb 5 06:11:40 2007 From: crafterm at gmail.com (Marcus Crafter) Date: Mon, 5 Feb 2007 22:11:40 +1100 Subject: [rspec-users] Structure for library code specs In-Reply-To: <5739D55F-ED92-4D6E-846A-171BBEC056E2@ashleymoran.me.uk> References: <57c63afe0702010835y4df95882o1d5bdb793c8b7af7@mail.gmail.com> <5739D55F-ED92-4D6E-846A-171BBEC056E2@ashleymoran.me.uk> Message-ID: Just catching up on messages after being away for a few days - cool - I've been looking for this too - thanks for submitting the RFE. Cheers, Marcus On 02/02/2007, at 4:38 AM, Ashley Moran wrote: > > On 1 Feb 2007, at 16:35, David Chelimsky wrote: > >> There's been no plan for it but we would consider this. If you're >> interested in seeing it happen, please submit an RFE: >> >> http://rspec.rubyforge.org/contribute.html >> http://rubyforge.org/tracker/?group_id=797 >> >> Cheers, >> David > > > Thanks - just done From dchelimsky at gmail.com Mon Feb 5 07:53:05 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 5 Feb 2007 06:53:05 -0600 Subject: [rspec-users] long jumping out of code in specs In-Reply-To: References: Message-ID: <57c63afe0702050453s7a98ea45q4627a7971be23487@mail.gmail.com> On 2/5/07, Chris Anderson wrote: > I wrote this abomination just now, and wonder if anyone else has had > experience with the pattern behind it. In short, I'm specing an > after_create hook on an ActiveRecord model, that calls a bunch of > private methods. Instead of stubbing all those private methods (which > is verboten anyway, as well as impossible because creating the object > which owns those methods is what I'm specing, so I don't have the > object until I call do_action.) > > I'm stubbing a public method that would only get called if > control-flow worked out like it should (the proverbial canary in the > coal mine), and telling it to raise an exception which I catch in my > spec. This way I don't have to bother with either stubbing all the > private methods called in my after_create hook, or making the mock I'm > sending though this gauntlet respond properly to all the calls it > gets. > > In my case calling RssParser.new is evidence enough that my code > executed like it should. > > class SpecShortcut < Exception; end > > specify "should call the standard parsing methods" do > RssParser.should_receive(:new).and_raise(SpecShortcut) > lambda{do_action}.should_raise(SpecShortcut) > end > > Feeling pain like this while writing specs is usally an indication > that the code could be better designed. But I don't see how else one > could spec ActiveRecord's after_create hook, without going through > with mocking and stubbing all the code the after_create hook uses. > Stopping execution at the point where the expectation is satisfied is > also appealing, in a premature optimization kind of way. > > Like I said, an abomination, but maybe a useful one. ActiveRecord puts us in an interesting bind with regard to the rules that come out of TDD. Testing privates is a no-no, but testing that a public method on the same class gets called is almost as dirty for the same reasons. It's less likely to be a problem than private methods because it's more stable (public methods are inherently more stable than privates), but it still feels like a design smell - especially if you have to intercept calls to that method (partial mocks), as you are doing. This is not your fault! It is because ActiveRecord violates and/or encourages the violation several OO design principles: Single Responsibility Principle Liskov Substitutiion Principle Dependency Inversion Principle Law of Demeter Tell, Don't Ask All of these principles, when applied, help you to build systems that are highly decoupled and easy to test. When ignored you often end up with tightly bound systems that, in spite of their up-front productivity, are difficult to test and difficult to change over time. Rails is difficult to test outside of the built-in testing support that you get. If you take a look at that support, it goes a long way to monkey patch itself into something usable in a test environment. This is true of our own 'spec/rails' as well. As for the ability to make changes later, try to use some other persistence framework like Og in a Rails app and you'll see the problem. Also, good luck trying to put plugins somewhere other than inside your rails app. These are trade-offs that one accepts when one uses Rails, and the benefits we get in terms of elegant feel, up-front productivity, low barrier to entry, etc, seem to make it worth it. My hope is that over time the Rails code base will improve from community contributions that make it a more highly decoupled system. Admittedly, we have a similar problem in RSpec: you can't (yet) easily plug in a different mocking framework because things are too tightly bound to RSpec's own. This is something that we're looking at changing in the near future, but there are other priorities at the forefront. But it was an easy trap to fall into. All of this must lead to looking at testing practices slightly differently in the short run. Jay Fields blogs quite a bit about solutions to problems like this. One thing he's doing for declarations like ActiveRecord validations is really interesting to me. You can read about it: http://jayfields.blogspot.com/2006/12/rails-unit-testing-activerecord.html but in a nutshell, he mocks ActiveRecord::Base telling it to expect a declaration when a file is loaded. This solution to your problem might look like this: context "RssParser" do specify "should do x after_create" do Thing.should_receive(:after_create).with(:x) load "#{RAILS_ROOT}/app/models/rss_parser.rb" end end I'm not ready to advocate this as THE solution. This approach does have its own problems, at least one of which is noted in a comment on the blog. Still, I've done this in a couple of places and it has worked well. WDYT? David > > -- > Chris Anderson > http://jchris.mfdz.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From cwdinfo at gmail.com Mon Feb 5 13:52:04 2007 From: cwdinfo at gmail.com (s.ross) Date: Mon, 5 Feb 2007 10:52:04 -0800 Subject: [rspec-users] Spec'ing ActionMailer In-Reply-To: <57c63afe0702041335j4f56988egb786e6d9f77518c6@mail.gmail.com> References: <6062617A-0CEB-4C3E-8174-8037C3B756F7@gmail.com> <9C0A4BB1-16F3-447B-BAEC-19CAC144A52F@gmail.com> <676E68F2-5DEE-4743-BF4F-52FE33823220@gmail.com> <57c63afe0702041335j4f56988egb786e6d9f77518c6@mail.gmail.com> Message-ID: David-- I still don't have this working (see my previous email with the pastie attached), but now have another ActionMailer/rSpec question. I'm spec'ing a different mailer model directly (instead of through the controller). It's meant to be invoked through script/runner, so I won't have a response object. I can see in the plugin source that there is assert_select_email support, but I'm pretty sure there is no expectation that starts with "assert." How would one spec something like: setup do ActionMailer::Base.delivery_method = :test ActionMailer::Base.perform_deliveries = true ActionMailer::Base.deliveries = [] MyMailer.trigger_emails # invokes model method to send 4 emails end specify "d'oh! should have a non-empty recipient list" do ActionMailer::Base.deliveries.size.should be(4) ActionMailer::Base.deliveries.each do |email| email.recipients.should_not be_empty end end specify "first email should have a list item with the name of the first guy" do ActionMailer::Base.deliveries[0].should select_tag('li', members (:joe).name) end The above code is truly bogus and doesn't work. I'm trying to figure out where to get the messages and how to specify the expectations on them. Thanks, Steve On Feb 4, 2007, at 1:35 PM, David Chelimsky wrote: > Steve - are you using the RSpec trunk? > > If you are, AND your email is html email, you can use this right now: > > response.should send_email { > with_tag("div", "joe at shmoe.com") > with_tag("div", projects(:trace).name) > with_tag("div", member/show) > } > > There is no specific support yet for email headers, nor raw text, > though I can see now there is a need for that and will raise the > appropriate RFE. > > David > From dchelimsky at gmail.com Mon Feb 5 14:12:25 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 5 Feb 2007 13:12:25 -0600 Subject: [rspec-users] Spec'ing ActionMailer In-Reply-To: References: <6062617A-0CEB-4C3E-8174-8037C3B756F7@gmail.com> <9C0A4BB1-16F3-447B-BAEC-19CAC144A52F@gmail.com> <676E68F2-5DEE-4743-BF4F-52FE33823220@gmail.com> <57c63afe0702041335j4f56988egb786e6d9f77518c6@mail.gmail.com> Message-ID: <57c63afe0702051112p7097624cj85fc813c30839653@mail.gmail.com> On 2/5/07, s.ross wrote: > David-- > > I still don't have this working (see my previous email with the > pastie attached), but now have another ActionMailer/rSpec question. > I'm spec'ing a different mailer model directly (instead of through > the controller). It's meant to be invoked through script/runner, so I > won't have a response object. > > I can see in the plugin source that there is assert_select_email > support, but I'm pretty sure there is no expectation that starts with > "assert." How would one spec something like: > > setup do > ActionMailer::Base.delivery_method = :test > ActionMailer::Base.perform_deliveries = true > ActionMailer::Base.deliveries = [] > MyMailer.trigger_emails # invokes model method to send 4 emails > end > > specify "d'oh! should have a non-empty recipient list" do > ActionMailer::Base.deliveries.size.should be(4) > ActionMailer::Base.deliveries.each do |email| > email.recipients.should_not be_empty > end > end assert_select doesn't wrap this sort of access, so neither does the port. What you've got there is probably what I'd do. Anything that RSpec would provide would wrap that anyhow. One thing you can do slightly differently is this: ActionMailer::Base.should have(4).deliveries That's in rspec core. > > specify "first email should have a list item with the name of the > first guy" do > ActionMailer::Base.deliveries[0].should select_tag('li', members > (:joe).name) > end This one you shold be able to do like this: specify "first email should have a list item with the name of the first guy" do response.should be_email { with_tag('li', members(:joe).name) } end Hope that helps a little. David > > > The above code is truly bogus and doesn't work. I'm trying to figure > out where to get the messages and how to specify the expectations on > them. > > Thanks, > > Steve > > > On Feb 4, 2007, at 1:35 PM, David Chelimsky wrote: > > > Steve - are you using the RSpec trunk? > > > > If you are, AND your email is html email, you can use this right now: > > > > response.should send_email { > > with_tag("div", "joe at shmoe.com") > > with_tag("div", projects(:trace).name) > > with_tag("div", member/show) > > } > > > > There is no specific support yet for email headers, nor raw text, > > though I can see now there is a need for that and will raise the > > appropriate RFE. > > > > David > > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From cdemyanovich at gmail.com Mon Feb 5 14:22:04 2007 From: cdemyanovich at gmail.com (Craig Demyanovich) Date: Mon, 5 Feb 2007 14:22:04 -0500 Subject: [rspec-users] Spec'ing ActionMailer In-Reply-To: References: <6062617A-0CEB-4C3E-8174-8037C3B756F7@gmail.com> <9C0A4BB1-16F3-447B-BAEC-19CAC144A52F@gmail.com> <676E68F2-5DEE-4743-BF4F-52FE33823220@gmail.com> <57c63afe0702041335j4f56988egb786e6d9f77518c6@mail.gmail.com> Message-ID: <9C71BD00-27F6-497C-AFF7-55700C335A9A@gmail.com> On Feb 5, 2007, at 1:52 PM, s.ross wrote: > David-- > > I still don't have this working (see my previous email with the > pastie attached), but now have another ActionMailer/rSpec question. > I'm spec'ing a different mailer model directly (instead of through > the controller). It's meant to be invoked through script/runner, so I > won't have a response object. Steve, Your comments got me thinking about this again. First, there is the behavior that you expect your controller to exhibit: that certain actions send email. Second, there is the behavior that your ActionMailer::Base derivative should exhibit: that it creates email as you like. Furthermore, you write that you want to invoke an ActionMailer::Base derivative via script/runner instead of or in addition to a controller. Therefore, you should specify their respective behaviors independently of one another. I'm including a code snippet from _Agile Web Development with Rails, 2nd ed._, that shows an example of testing the ActionMailer::Base derivative by itself. I'm sure you can translate the test to a spec. require File.dirname(__FILE__) + '/../test_helper' require 'order_mailer' class OrderMailerTest < Test::Unit::TestCase def setup @order = Order.new(:name =>"Dave Thomas", :email => "dave at pragprog.com") end def test_confirm response = OrderMailer.create_confirm(@order) assert_equal("Pragmatic Store Order Confirmation", response.subject) assert_equal("dave at pragprog.com", response.to[0]) assert_match(/Dear Dave Thomas/, response.body) end end Taking this approach will allow you to minimize the number of tests that you write to prove that the controller behaves as it should. Then, you can focus your attention on the ActionMailer::Base derivative alone for all the things you want to verify about the content of email. I hope this helps somehow. Regards, Craig From cwdinfo at gmail.com Mon Feb 5 14:45:56 2007 From: cwdinfo at gmail.com (s.ross) Date: Mon, 5 Feb 2007 11:45:56 -0800 Subject: [rspec-users] Spec'ing ActionMailer In-Reply-To: <9C71BD00-27F6-497C-AFF7-55700C335A9A@gmail.com> References: <6062617A-0CEB-4C3E-8174-8037C3B756F7@gmail.com> <9C0A4BB1-16F3-447B-BAEC-19CAC144A52F@gmail.com> <676E68F2-5DEE-4743-BF4F-52FE33823220@gmail.com> <57c63afe0702041335j4f56988egb786e6d9f77518c6@mail.gmail.com> <9C71BD00-27F6-497C-AFF7-55700C335A9A@gmail.com> Message-ID: <1B5F5370-7A4A-43CA-AD9E-764FE9D57DE8@gmail.com> David/Craig-- Two tests are actually what I'm doing. I'm testing two separate mailers. The first is triggered as a side effect of an action. That mailer is inextricably intertwined with the controller, as it has to provide a URL to the page of someone who signed up, etc. I suppose I could mock the controller object, but does that really provide better results? The second mailer is, as mentioned, triggered from the command line and is being tested in a fashion similar to AWDROR's. Here is the (acckkk!) code I settled on, which IMO violates a lot of OO principles. require File.dirname(__FILE__) + '/../spec_helper.rb' context "A MemberDigest" do fixtures :members setup do ActionMailer::Base.delivery_method = :test ActionMailer::Base.perform_deliveries = true ActionMailer::Base.deliveries = [] MemberDigest.trigger_emails # invokes model method to send 4 emails end specify "d'oh! should have a non-empty recipient list" do ActionMailer::Base.deliveries.size.should be(4) ActionMailer::Base.deliveries.inspect ActionMailer::Base.deliveries.each do |email| email.to_addrs.should_not be_empty end end specify "first email should have a list item with the name of the first guy" do ActionMailer::Base.deliveries.first.body.should_include(members (:existing_user_1).first) end teardown do ActionMailer::Base.deliveries.clear end end Comments? On Feb 5, 2007, at 11:22 AM, Craig Demyanovich wrote: > > On Feb 5, 2007, at 1:52 PM, s.ross wrote: > >> David-- >> >> I still don't have this working (see my previous email with the >> pastie attached), but now have another ActionMailer/rSpec question. >> I'm spec'ing a different mailer model directly (instead of through >> the controller). It's meant to be invoked through script/runner, so I >> won't have a response object. > > Steve, > > Your comments got me thinking about this again. First, there is the > behavior that you expect your controller to exhibit: that certain > actions send email. Second, there is the behavior that your > ActionMailer::Base derivative should exhibit: that it creates email > as you like. Furthermore, you write that you want to invoke an > ActionMailer::Base derivative via script/runner instead of or in > addition to a controller. > > Therefore, you should specify their respective behaviors > independently of one another. I'm including a code snippet from > _Agile Web Development with Rails, 2nd ed._, that shows an example of > testing the ActionMailer::Base derivative by itself. I'm sure you can > translate the test to a spec. > > require File.dirname(__FILE__) + '/../test_helper' > require 'order_mailer' > > class OrderMailerTest < Test::Unit::TestCase > def setup > @order = Order.new(:name =>"Dave Thomas", :email => > "dave at pragprog.com") > end > > def test_confirm > response = OrderMailer.create_confirm(@order) > assert_equal("Pragmatic Store Order Confirmation", > response.subject) > assert_equal("dave at pragprog.com", response.to[0]) > assert_match(/Dear Dave Thomas/, response.body) > end > end > > Taking this approach will allow you to minimize the number of tests > that you write to prove that the controller behaves as it should. > Then, you can focus your attention on the ActionMailer::Base > derivative alone for all the things you want to verify about the > content of email. I hope this helps somehow. > > Regards, > Craig > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From cdemyanovich at gmail.com Mon Feb 5 19:02:26 2007 From: cdemyanovich at gmail.com (Craig Demyanovich) Date: Mon, 5 Feb 2007 19:02:26 -0500 Subject: [rspec-users] Spec'ing ActionMailer In-Reply-To: <1B5F5370-7A4A-43CA-AD9E-764FE9D57DE8@gmail.com> References: <6062617A-0CEB-4C3E-8174-8037C3B756F7@gmail.com> <9C0A4BB1-16F3-447B-BAEC-19CAC144A52F@gmail.com> <676E68F2-5DEE-4743-BF4F-52FE33823220@gmail.com> <57c63afe0702041335j4f56988egb786e6d9f77518c6@mail.gmail.com> <9C71BD00-27F6-497C-AFF7-55700C335A9A@gmail.com> <1B5F5370-7A4A-43CA-AD9E-764FE9D57DE8@gmail.com> Message-ID: <2D3A5909-BA53-4DF1-95E4-EBFE2E7EB8DA@gmail.com> On Feb 5, 2007, at 2:45 PM, s.ross wrote: > David/Craig-- > > Two tests are actually what I'm doing. I'm testing two separate > mailers. The first is triggered as a side effect of an action. That > mailer is inextricably intertwined with the controller, as it has to > provide a URL to the page of someone who signed up, etc. I suppose I > could mock the controller object, but does that really provide better > results? Isolating the controller and mailer as much as possible is the best approach, IMHO. And, I don't think any mailer has to be bound tightly to a controller. Here's what I'd do. Specify each mailer in isolation, focusing on all the interesting bits of the email messages that the mailers will create. For example: context "An email for a new member" do ... specify "includes the URL used at sign up" do mail = MemberDigest.create_welcome(@member) mail.body.should_match /"#{@member.url}"/ end ... end Then I'd mock/stub the one mailer and verify that the controller uses it correctly. As a second option, I'd just let the controller use the mailer and verify that I had one delivery; I wouldn't pick apart the delivery, though, since I'd be comfortable that I'd specified the mailer well enough already. > > The second mailer is, as mentioned, triggered from the command line > and is being tested in a fashion similar to AWDROR's. Here is the > (acckkk!) code I settled on, which IMO violates a lot of OO > principles. > > require File.dirname(__FILE__) + '/../spec_helper.rb' > > context "A MemberDigest" do > fixtures :members > > setup do > ActionMailer::Base.delivery_method = :test > ActionMailer::Base.perform_deliveries = true > ActionMailer::Base.deliveries = [] > MemberDigest.trigger_emails # invokes model method to send 4 > emails > end > > specify "d'oh! should have a non-empty recipient list" do > ActionMailer::Base.deliveries.size.should be(4) > ActionMailer::Base.deliveries.inspect > ActionMailer::Base.deliveries.each do |email| > email.to_addrs.should_not be_empty > end > end > > specify "first email should have a list item with the name of the > first guy" do > ActionMailer::Base.deliveries.first.body.should_include(members > (:existing_user_1).first) > end > > teardown do > ActionMailer::Base.deliveries.clear > end > end > > Comments? Again, I'm tempted to specify the mailer in isolation and either trust that delivery will happen if I ask for it or specify delivery in isolation. Bear in mind that I might be missing something about this example, as my experience with Rails is still somewhat limited. > > > On Feb 5, 2007, at 11:22 AM, Craig Demyanovich wrote: > >> >> On Feb 5, 2007, at 1:52 PM, s.ross wrote: >> >>> David-- >>> >>> I still don't have this working (see my previous email with the >>> pastie attached), but now have another ActionMailer/rSpec question. >>> I'm spec'ing a different mailer model directly (instead of through >>> the controller). It's meant to be invoked through script/runner, >>> so I >>> won't have a response object. >> >> Steve, >> >> Your comments got me thinking about this again. First, there is the >> behavior that you expect your controller to exhibit: that certain >> actions send email. Second, there is the behavior that your >> ActionMailer::Base derivative should exhibit: that it creates email >> as you like. Furthermore, you write that you want to invoke an >> ActionMailer::Base derivative via script/runner instead of or in >> addition to a controller. >> >> Therefore, you should specify their respective behaviors >> independently of one another. I'm including a code snippet from >> _Agile Web Development with Rails, 2nd ed._, that shows an example of >> testing the ActionMailer::Base derivative by itself. I'm sure you can >> translate the test to a spec. >> >> require File.dirname(__FILE__) + '/../test_helper' >> require 'order_mailer' >> >> class OrderMailerTest < Test::Unit::TestCase >> def setup >> @order = Order.new(:name =>"Dave Thomas", :email => >> "dave at pragprog.com") >> end >> >> def test_confirm >> response = OrderMailer.create_confirm(@order) >> assert_equal("Pragmatic Store Order Confirmation", >> response.subject) >> assert_equal("dave at pragprog.com", response.to[0]) >> assert_match(/Dear Dave Thomas/, response.body) >> end >> end >> >> Taking this approach will allow you to minimize the number of tests >> that you write to prove that the controller behaves as it should. >> Then, you can focus your attention on the ActionMailer::Base >> derivative alone for all the things you want to verify about the >> content of email. I hope this helps somehow. >> >> Regards, >> Craig >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From pergesu at gmail.com Tue Feb 6 21:11:17 2007 From: pergesu at gmail.com (Pat Maddox) Date: Tue, 6 Feb 2007 18:11:17 -0800 Subject: [rspec-users] Mocking ActiveResource Message-ID: <810a540e0702061811n5036f613i6070d24df05f82aa@mail.gmail.com> I want to use ActiveResource in my app. Instead of hitting server though, I want it to load from a file when I call find. Any clue how I do that? Pat From aslak.hellesoy at gmail.com Wed Feb 7 03:41:35 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Wed, 7 Feb 2007 09:41:35 +0100 Subject: [rspec-users] Mocking ActiveResource In-Reply-To: <810a540e0702061811n5036f613i6070d24df05f82aa@mail.gmail.com> References: <810a540e0702061811n5036f613i6070d24df05f82aa@mail.gmail.com> Message-ID: <8d961d900702070041l5ee5d43dv743386b3cfbb3fed@mail.gmail.com> On 2/7/07, Pat Maddox wrote: > I want to use ActiveResource in my app. Instead of hitting server > though, I want it to load from a file when I call find. Any clue how > I do that? > In the same way as you'd mock ActiveRecord I would think. Is this not working for you? Aslak > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mlangenberg at gmail.com Wed Feb 7 03:53:20 2007 From: mlangenberg at gmail.com (Matthijs Langenberg) Date: Wed, 7 Feb 2007 09:53:20 +0100 Subject: [rspec-users] Mocking ActiveResource In-Reply-To: <810a540e0702061811n5036f613i6070d24df05f82aa@mail.gmail.com> References: <810a540e0702061811n5036f613i6070d24df05f82aa@mail.gmail.com> Message-ID: <27c0ac6d0702070053y3bf14754k6474d91df5d32c0e@mail.gmail.com> I think you need to stub the ActiveResource methods like 'create' and 'find', assuming the ActiveResource library is well tested you should be able to test only the behaviour you are writing instead of the REST communication. On 2/7/07, Pat Maddox wrote: > I want to use ActiveResource in my app. Instead of hitting server > though, I want it to load from a file when I call find. Any clue how > I do that? > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From pergesu at gmail.com Wed Feb 7 05:55:29 2007 From: pergesu at gmail.com (Pat Maddox) Date: Wed, 7 Feb 2007 02:55:29 -0800 Subject: [rspec-users] Mocking ActiveResource In-Reply-To: <8d961d900702070041l5ee5d43dv743386b3cfbb3fed@mail.gmail.com> References: <810a540e0702061811n5036f613i6070d24df05f82aa@mail.gmail.com> <8d961d900702070041l5ee5d43dv743386b3cfbb3fed@mail.gmail.com> Message-ID: <810a540e0702070255o31b21bc7w1d42e5c0935a2716@mail.gmail.com> On 2/7/07, aslak hellesoy wrote: > On 2/7/07, Pat Maddox wrote: > > I want to use ActiveResource in my app. Instead of hitting server > > though, I want it to load from a file when I call find. Any clue how > > I do that? > > > > In the same way as you'd mock ActiveRecord I would think. Is this not > working for you? No I want it to actually go through the process of finding something, but just have it use a file rather than an actual server. Takes a couple steps (with my current solution): 1. Mock Net::HTTP.new to return some mock http object 2. mock http_object.get to return a mock http response 3. mock http_response.body to return the contents of your file I think http_object has to have :null_object => true if you want to keep things simple. I ended up tossing ARes altogether, so I'm not actually using it at this point. But that's at least pretty close to what I did. Ugly, but it worked. Pat From aslak.hellesoy at gmail.com Wed Feb 7 06:49:40 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Wed, 7 Feb 2007 12:49:40 +0100 Subject: [rspec-users] Mocking ActiveResource In-Reply-To: <810a540e0702070255o31b21bc7w1d42e5c0935a2716@mail.gmail.com> References: <810a540e0702061811n5036f613i6070d24df05f82aa@mail.gmail.com> <8d961d900702070041l5ee5d43dv743386b3cfbb3fed@mail.gmail.com> <810a540e0702070255o31b21bc7w1d42e5c0935a2716@mail.gmail.com> Message-ID: <8d961d900702070349v534aed03l7616279e5f717783@mail.gmail.com> On 2/7/07, Pat Maddox wrote: > On 2/7/07, aslak hellesoy wrote: > > On 2/7/07, Pat Maddox wrote: > > > I want to use ActiveResource in my app. Instead of hitting server > > > though, I want it to load from a file when I call find. Any clue how > > > I do that? > > > > > > > In the same way as you'd mock ActiveRecord I would think. Is this not > > working for you? > > No I want it to actually go through the process of finding something, > but just have it use a file rather than an actual server. > I see, so you don't want to mock ActiveResource, but the transport used by it. This is an approach that I generally don't recommend. The lower level you're mocking at (HTTP, database connections, File I/O etc) the more you have to set up and things become very verbose and fragile. As a general rule: Don't mock APIs you don't own. Why don't you just mock at a higher level - your ActiveResource classes? The ActiveResource classes themselves I would verify against the real transport, without mocking. The same goes for ActiveRecord. Their specs run against the database, but specs for anything *using* ActiveRecord/ActiveResource will talk to mock instances. Aslak > Takes a couple steps (with my current solution): > 1. Mock Net::HTTP.new to return some mock http object > 2. mock http_object.get to return a mock http response > 3. mock http_response.body to return the contents of your file > > I think http_object has to have :null_object => true if you want to > keep things simple. > > I ended up tossing ARes altogether, so I'm not actually using it at > this point. But that's at least pretty close to what I did. Ugly, > but it worked. > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From pergesu at gmail.com Wed Feb 7 12:10:16 2007 From: pergesu at gmail.com (Pat Maddox) Date: Wed, 7 Feb 2007 09:10:16 -0800 Subject: [rspec-users] Mocking ActiveResource In-Reply-To: <8d961d900702070349v534aed03l7616279e5f717783@mail.gmail.com> References: <810a540e0702061811n5036f613i6070d24df05f82aa@mail.gmail.com> <8d961d900702070041l5ee5d43dv743386b3cfbb3fed@mail.gmail.com> <810a540e0702070255o31b21bc7w1d42e5c0935a2716@mail.gmail.com> <8d961d900702070349v534aed03l7616279e5f717783@mail.gmail.com> Message-ID: <810a540e0702070910p5f4656ecp370fece7306c51fb@mail.gmail.com> On 2/7/07, aslak hellesoy wrote: > On 2/7/07, Pat Maddox wrote: > > On 2/7/07, aslak hellesoy wrote: > > > On 2/7/07, Pat Maddox wrote: > > > > I want to use ActiveResource in my app. Instead of hitting server > > > > though, I want it to load from a file when I call find. Any clue how > > > > I do that? > > > > > > > > > > In the same way as you'd mock ActiveRecord I would think. Is this not > > > working for you? > > > > No I want it to actually go through the process of finding something, > > but just have it use a file rather than an actual server. > > > > I see, so you don't want to mock ActiveResource, but the transport used by it. Right > This is an approach that I generally don't recommend. The lower level > you're mocking at (HTTP, database connections, File I/O etc) the more > you have to set up and things become very verbose and fragile. As a > general rule: > > Don't mock APIs you don't own. I agree with you. This is certainly how I work with my AR classes. However there's a big difference in maturity between AR and ARes. ARes isn't even "official" yet. So while with AR I can mock MyClass.find and know that AR does the right thing, I'm not entirely sure with ARes. I don't know how it's going to parse an XML document. Turns out it did some funky things and I couldn't use it. Once I had one spec that demonstrated ARes worked for my purposes, I'd just mock out all subsequent specs. Pat From jeremy.burks at gmail.com Wed Feb 7 12:14:20 2007 From: jeremy.burks at gmail.com (Jeremy Burks) Date: Wed, 7 Feb 2007 11:14:20 -0600 Subject: [rspec-users] advice on a spec'ing best practice Message-ID: i am in the process of converting the tests in two projects that i am working on (one rails, one ruby) to rspec. i felt like i was doing ok applying BDD and using rspec properly until i read a comment in another topic on the list from David (subject "long jumping out of code in specs"). In there it was said: --- Testing privates is a no-no, but testing that a public method on the same class gets called is almost as dirty for the same reasons. It's less likely to be a problem than private methods because it's more stable (public methods are inherently more stable than privates), but it still feels like a design smell - especially if you have to intercept calls to that method (partial mocks), as you are doing. --- Hopefully i didn't take that out of context. This statement got me thinking about how i am witting my sepcs because i have been intercepting calls to methods on the class that is being spec'd. I do it mostly to isolate the code being tested as much as possible. I am hoping to get some advice on how to spec this method. class Foo def each_project projects.each do|project| yield(project, project.name) end end end projects is an attribute of class Foo. Normally i would mock the projects attribute to return an array of mocks. That would allow me to verify the yield is working as it should. Based on David's comment that seems to be a smell. Is that correct? The alternative i see is to use dependency injection and pass the list of projects in the initialize method of class Foo. Or maybe inject the class responsible for initializing the projects. class Foo def initialize(projects) @projects = projects end end Thoughts? From micah at 8thlight.com Wed Feb 7 11:59:25 2007 From: micah at 8thlight.com (Micah Martin) Date: Wed, 7 Feb 2007 10:59:25 -0600 Subject: [rspec-users] odd mock behavior Message-ID: <2BE5CDA0-BF97-495D-8577-699FEA57257E@8thlight.com> I'm seeing some odd behavior around the should_receive() when given a block combined with some cardinality. For example, with the following... my_mock.should_receive(:foo).twice do |i| puts i end ... the spec passes but i never gets puts'ed. With the following... my_mock.should_receive(:foo) do |i| puts i end ... i gets puts'ed twice but the spec fails because it was only expecting one call to :foo. Micah Martin 8th Light, Inc. 8thlight.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070207/19e5c667/attachment-0001.html From dchelimsky at gmail.com Wed Feb 7 12:45:44 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 7 Feb 2007 11:45:44 -0600 Subject: [rspec-users] odd mock behavior In-Reply-To: <2BE5CDA0-BF97-495D-8577-699FEA57257E@8thlight.com> References: <2BE5CDA0-BF97-495D-8577-699FEA57257E@8thlight.com> Message-ID: <57c63afe0702070945x7486fe17r474e2668378b96c@mail.gmail.com> On 2/7/07, Micah Martin wrote: > I'm seeing some odd behavior around the should_receive() when given a block > combined with some cardinality. > > For example, with the following... > > my_mock.should_receive(:foo).twice do |i| > puts i > end Blocks aren't currently supported in any form besides: my_mock.should_receive(args) { } Since none of the other methods (#with, #once, #twice, etc) deal with a block, the block is never being invoked. Feel free to submit an RFE if you feel this should be supported. Cheers, David > > ... the spec passes but i never gets puts'ed. > > With the following... > > my_mock.should_receive(:foo) do |i| > puts i > end > > ... i gets puts'ed twice but the spec fails because it was only expecting > one call to :foo. > > > Micah Martin > 8th Light, Inc. > 8thlight.com > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Wed Feb 7 12:54:13 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 7 Feb 2007 11:54:13 -0600 Subject: [rspec-users] advice on a spec'ing best practice In-Reply-To: References: Message-ID: <57c63afe0702070954n709602fcg7264c0eea78b036a@mail.gmail.com> On 2/7/07, Jeremy Burks wrote: > i am in the process of converting the tests in two projects that i am > working on (one rails, one ruby) to rspec. i felt like i was doing ok > applying BDD and using rspec properly until i read a comment in > another topic on the list from David (subject "long jumping out of > code in specs"). In there it was said: > > --- > Testing privates is a no-no, but testing that a public method on the > same class gets called is almost as dirty for the same reasons. It's > less likely to be a problem than private methods > because it's more stable (public methods are inherently more stable > than privates), but it still feels like a design smell - especially if > you have to intercept calls to that method (partial mocks), as you are > doing. > --- > > Hopefully i didn't take that out of context. > > This statement got me thinking about how i am witting my sepcs because > i have been intercepting calls to methods on the class that is being > spec'd. I do it mostly to isolate the code being tested as much as > possible. > > I am hoping to get some advice on how to spec this method. > > class Foo > def each_project > projects.each do|project| > yield(project, project.name) > end > end > end > > projects is an attribute of class Foo. Normally i would mock the > projects attribute to return an array of mocks. That would allow me to > verify the yield is working as it should. Based on David's comment > that seems to be a smell. > > Is that correct? > > The alternative i see is to use dependency injection and pass the list > of projects in the initialize method of class Foo. Or maybe inject the > class responsible for initializing the projects. > > class Foo > def initialize(projects) > @projects = projects > end > end I'd rather add an add_project method than have a list passed in. Otherwise, this is probably how I'd approach it. > > Thoughts? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From micah at 8thlight.com Wed Feb 7 14:29:47 2007 From: micah at 8thlight.com (Micah Martin) Date: Wed, 7 Feb 2007 13:29:47 -0600 Subject: [rspec-users] odd mock behavior In-Reply-To: <57c63afe0702070945x7486fe17r474e2668378b96c@mail.gmail.com> References: <2BE5CDA0-BF97-495D-8577-699FEA57257E@8thlight.com> <57c63afe0702070945x7486fe17r474e2668378b96c@mail.gmail.com> Message-ID: <6C49DA98-FAE0-4ACF-838D-92023D0AB923@8thlight.com> Thanks David. That explains it. RFE submitted with specs: https://rubyforge.org/tracker/index.php? func=detail&aid=8484&group_id=797&atid=3152 Micah Martin 8th Light, Inc. 8thlight.com On Feb 7, 2007, at 11:45 AM, David Chelimsky wrote: > > Blocks aren't currently supported in any form besides: > > my_mock.should_receive(args) { > } > > Since none of the other methods (#with, #once, #twice, etc) deal with > a block, the block is never being invoked. > > Feel free to submit an RFE if you feel this should be supported. > > Cheers, > David -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070207/4e8ae9a4/attachment.html From dchelimsky at gmail.com Wed Feb 7 15:07:31 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 7 Feb 2007 14:07:31 -0600 Subject: [rspec-users] odd mock behavior In-Reply-To: <6C49DA98-FAE0-4ACF-838D-92023D0AB923@8thlight.com> References: <2BE5CDA0-BF97-495D-8577-699FEA57257E@8thlight.com> <57c63afe0702070945x7486fe17r474e2668378b96c@mail.gmail.com> <6C49DA98-FAE0-4ACF-838D-92023D0AB923@8thlight.com> Message-ID: <57c63afe0702071207q4c396bcbt71ba351569e15a9b@mail.gmail.com> On 2/7/07, Micah Martin wrote: > Thanks David. That explains it. > > RFE submitted with specs: > https://rubyforge.org/tracker/index.php?func=detail&aid=8484&group_id=797&atid=3152 Thanks. I'm already on this and will commit the fix tonight. Cheers > > Micah Martin > 8th Light, Inc. > 8thlight.com > > On Feb 7, 2007, at 11:45 AM, David Chelimsky wrote: > > Blocks aren't currently supported in any form besides: > > my_mock.should_receive(args) { > } > > Since none of the other methods (#with, #once, #twice, etc) deal with > a block, the block is never being invoked. > > Feel free to submit an RFE if you feel this should be supported. > > Cheers, > David > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From kevwil at gmail.com Thu Feb 8 00:17:41 2007 From: kevwil at gmail.com (Kevin Williams) Date: Wed, 7 Feb 2007 22:17:41 -0700 Subject: [rspec-users] testing ajax responder actions Message-ID: <683a886f0702072117i3aaa4fbcs52c9a2fe1fa2cf27@mail.gmail.com> I have an Ajax responder method which uses respond_to to make sure it only works with Ajax. I'm having trouble figuring out how to call this action successfully. I'm using Rails 1.2.x. Any thoughts? -- Cheers, Kevin Williams http://www.almostserio.us/ "Any sufficiently advanced technology is indistinguishable from Magic." - Arthur C. Clarke From jerry.west at ntlworld.com Thu Feb 8 08:46:34 2007 From: jerry.west at ntlworld.com (Jerry West) Date: Thu, 08 Feb 2007 13:46:34 +0000 Subject: [rspec-users] testing ajax responder actions In-Reply-To: <683a886f0702072117i3aaa4fbcs52c9a2fe1fa2cf27@mail.gmail.com> References: <683a886f0702072117i3aaa4fbcs52c9a2fe1fa2cf27@mail.gmail.com> Message-ID: <45CB29BA.8030108@ntlworld.com> An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070208/067b6733/attachment.html From kevwil at gmail.com Thu Feb 8 10:05:51 2007 From: kevwil at gmail.com (Kevin Williams) Date: Thu, 8 Feb 2007 08:05:51 -0700 Subject: [rspec-users] testing ajax responder actions In-Reply-To: <45CB29BA.8030108@ntlworld.com> References: <683a886f0702072117i3aaa4fbcs52c9a2fe1fa2cf27@mail.gmail.com> <45CB29BA.8030108@ntlworld.com> Message-ID: <683a886f0702080705g3e3970bbx303b8face5ff9713@mail.gmail.com> Sweet! I can't wait to try that tonight. Thanks! On 2/8/07, Jerry West wrote: > > Kevin, > > You can use #xhr instead of #get or #post, thus... > > xhr :post, :create, :id => etc... > > this will send something that the controller is able to recognise as an > AJAX request. > > #xhr is inherited from the original Rails test framework, but rather taken > for granted in the Rspec docs (I'll submit a request to improve them). > > Hope this helps, > Jerry > > Kevin Williams wrote: > I have an Ajax responder method which uses respond_to to make sure it > only works with Ajax. I'm having trouble figuring out how to call this > action successfully. I'm using Rails 1.2.x. Any thoughts? > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Cheers, Kevin Williams http://www.almostserio.us/ "Any sufficiently advanced technology is indistinguishable from Magic." - Arthur C. Clarke From ed.howland at gmail.com Fri Feb 9 11:49:35 2007 From: ed.howland at gmail.com (Ed Howland) Date: Fri, 9 Feb 2007 10:49:35 -0600 Subject: [rspec-users] testing ajax responder actions In-Reply-To: <45CB29BA.8030108@ntlworld.com> References: <683a886f0702072117i3aaa4fbcs52c9a2fe1fa2cf27@mail.gmail.com> <45CB29BA.8030108@ntlworld.com> Message-ID: <3df642dd0702090849x5c5a0eaboc63590998e5d3f3c@mail.gmail.com> On 2/8/07, Jerry West wrote: > > Kevin, > > You can use #xhr instead of #get or #post, thus... > > xhr :post, :create, :id => etc... > > this will send something that the controller is able to recognise as an > AJAX request. This part seems to work, but when I do: controller.should_render_rjs :replace_html 'div_id', 'some text' I get nil does not respond to 'rjs' or 'has_rjs' Any help would be appreciated. Thanks > > #xhr is inherited from the original Rails test framework, but rather taken > for granted in the Rspec docs (I'll submit a request to improve them). > > Hope this helps, > Jerry > > Kevin Williams wrote: > I have an Ajax responder method which uses respond_to to make sure it > only works with Ajax. I'm having trouble figuring out how to call this > action successfully. I'm using Rails 1.2.x. Any thoughts? > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Ed Howland http://greenprogrammer.blogspot.com From justnothing at tiscali.co.uk Sat Feb 10 09:43:48 2007 From: justnothing at tiscali.co.uk (David Green) Date: Sat, 10 Feb 2007 06:43:48 -0800 (PST) Subject: [rspec-users] rspec and cookies In-Reply-To: <41d5fadf0701291203y6b4fb291l234a32000594ede2@mail.gmail.com> References: <8686339.post@talk.nabble.com> <41d5fadf0701291203y6b4fb291l234a32000594ede2@mail.gmail.com> Message-ID: <8901309.post@talk.nabble.com> Hello David, 2007/1/29, David Green : > I know I can use cookies[:name] = 'value' to set a cookie but how would I > set expiry information on such a cookie? when i try to pass a hash {:value > => 'value', :expires => 3.days.from_now} the entire hash becomes the value > of cookies[:name] When the cookie comes back through the browser, it never has any expiration or options. The browser handles that information. That's why you can't set those options on the requesting side. When responding, however... that's another story. Hope that helps ! -- thanks Francois. That explains a lot. -- View this message in context: http://www.nabble.com/rspec-and-cookies-tf3134883.html#a8901309 Sent from the rspec-users mailing list archive at Nabble.com. From graeme.nelson at gmail.com Sun Feb 11 16:07:19 2007 From: graeme.nelson at gmail.com (Graeme Nelson) Date: Sun, 11 Feb 2007 13:07:19 -0800 Subject: [rspec-users] Specing Rails Views Message-ID: Hello - I'm currently trying to write some specs for my rails views. My views depend upon the restful authentication plugin method logged_in? Like so, <% if logged_in? %>
    <%= link_to "create a new product", new_product_url %>
<% end %> However, when I have the following in my specification: render "products/show" I get an error 'logged_in?' isn't defined for <#Class....> My rails app gets 'logged_in?' via 'include AuthenticatedSystem' in my application controller. I understand that views are tested in isolation from their controller counterpart in rpsec, so 'include AuthenticatedSystem' isn't called and thus 'logged_in?' isn't available for the test/spec. I found a couple of work arounds. 1) add a method logged_in? into the application_helper.rb or _helper.rb (where is the controller associated with the current view being tested.) 2) add a method in my setup to mock the :logged_in? call in the template, like so: @controller.template.stub!(:logged_in?).and_return(true) I am sure there are other ways to make 'logged_in?' available to the template being tested. I am currently leaning towards #2 since it doesn't touch any of my application code. Anyone else have some ideas? Thanks in advanced. graeme nelson From jchris at mfdz.com Sun Feb 11 17:47:03 2007 From: jchris at mfdz.com (Chris Anderson) Date: Sun, 11 Feb 2007 14:47:03 -0800 Subject: [rspec-users] Specing Rails Views In-Reply-To: References: Message-ID: On 2/11/07, Graeme Nelson wrote: > 2) add a method in my setup to mock the :logged_in? call in the > template, like so: > > > @controller.template.stub!(:logged_in?).and_return(true) > This looks like a fine way to do it, to me. Treating logged_in? as just another attribute to be passed to the view (albeit in a slightly specialized way, as it is a method called in the view) seems like the right thing. This would make it easy to spec views in both the logged in and logged out cases. I still haven't gotten into specing views - as long as they don't throw nasty errors, and they are valid xml, I let my designers handle the work. But once we stablize the look and feel, I'll probably be looking to add some regression type verification on the views. -- Chris Anderson http://jchris.mfdz.com From work at ashleymoran.me.uk Mon Feb 12 09:43:23 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Mon, 12 Feb 2007 14:43:23 +0000 Subject: [rspec-users] Specs for Ajax partials with unicode characters Message-ID: <4E6DFE03-2915-4E6F-AEAD-F91056FE23A0@ashleymoran.me.uk> Hi Not sure if this is more Rails or RSpec related... I've got an app with an RJS view that updates a div in a page with the contents of a partial. The partial contains a non-ascii character namely a pound sign. I set up a simple test app with this RJS view: page.replace_html("test_div", :partial => "test_action") and this _test_action.rhtml:

?500

Now this spec fails: require File.dirname(__FILE__) + '/../../spec_helper' context "Given a request to render view_test/test_action" do setup do render 'view_test/test_action' end specify "the response should have a p with ?500" do response.should_have_tag 'p', :content => '?500' end specify "the response should definitely have a p with ?500" do response.should_have 'p', :text => '?500' end end The error for the should_have_tag gives this error message: Element.update("test_div", "

\u00a3500

"); should include ["[\"p\", {:content=>\"?500\"}]"] I don't know, well, anything about JavaScript but I'm informed by one of our developers that the replacement string is in JSON format. Either way the only way to make the specs pass is to use :content (or :text) => '\u00a3500' which is completely different from the contents of the partial, so not a brilliant solution. An alternative is to use £ for ?, but that kinda defeats the point of using UTF8. Any ideas how I can get round this? Cheers Ashley From dchelimsky at gmail.com Mon Feb 12 10:13:38 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 12 Feb 2007 08:13:38 -0700 Subject: [rspec-users] Specs for Ajax partials with unicode characters In-Reply-To: <4E6DFE03-2915-4E6F-AEAD-F91056FE23A0@ashleymoran.me.uk> References: <4E6DFE03-2915-4E6F-AEAD-F91056FE23A0@ashleymoran.me.uk> Message-ID: <57c63afe0702120713s1003d1cbm2ee7a6482ea05795@mail.gmail.com> On 2/12/07, Ashley Moran wrote: > Hi > > Not sure if this is more Rails or RSpec related... > > I've got an app with an RJS view that updates a div in a page with > the contents of a partial. The partial contains a non-ascii > character namely a pound sign. > > I set up a simple test app with this RJS view: > page.replace_html("test_div", :partial => "test_action") > > and this _test_action.rhtml: >

?500

> > Now this spec fails: > require File.dirname(__FILE__) + '/../../spec_helper' > > context "Given a request to render view_test/test_action" do > setup do > render 'view_test/test_action' > end > > specify "the response should have a p with ?500" do > response.should_have_tag 'p', :content => '?500' > end > > specify "the response should definitely have a p with ?500" do > response.should_have 'p', :text => '?500' > end > end > > The error for the should_have_tag gives this error message: > Element.update("test_div", "

\u00a3500

"); should include > ["[\"p\", {:content=>\"?500\"}]"] Ashley - are both specs failing? Or just the one using "should_have_tag"? > > I don't know, well, anything about JavaScript but I'm informed by one > of our developers that the replacement string is in JSON format. > Either way the only way to make the specs pass is to use :content > (or :text) => '\u00a3500' which is completely different from the > contents of the partial, so not a brilliant solution. An alternative > is to use £ for ?, but that kinda defeats the point of using UTF8. > > Any ideas how I can get round this? > > Cheers > Ashley > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From work at ashleymoran.me.uk Mon Feb 12 11:30:00 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Mon, 12 Feb 2007 16:30:00 +0000 Subject: [rspec-users] Specs for Ajax partials with unicode characters In-Reply-To: <57c63afe0702120713s1003d1cbm2ee7a6482ea05795@mail.gmail.com> References: <4E6DFE03-2915-4E6F-AEAD-F91056FE23A0@ashleymoran.me.uk> <57c63afe0702120713s1003d1cbm2ee7a6482ea05795@mail.gmail.com> Message-ID: <1B7BC488-E5AA-41CA-9924-89A4DECC2636@ashleymoran.me.uk> On 12 Feb 2007, at 15:13, David Chelimsky wrote: > Ashley - are both specs failing? Or just the one using > "should_have_tag"? David Both specs fail. The text mangling must happen before it reaches RSpec, so that both assertions see the same encoded string. Ashley From deepak.jois at gmail.com Tue Feb 13 01:33:54 2007 From: deepak.jois at gmail.com (Deepak Jois) Date: Tue, 13 Feb 2007 14:33:54 +0800 Subject: [rspec-users] Error against latest trunk while testing via spec for model Message-ID: <24dc07380702122233n264be62bqe5d3dffb59536684@mail.gmail.com> Hi I just did an update to lates trunk ================= context "Given a generated venue_spec.rb with fixtures loaded" do fixtures :venues specify "fixtures should load two Venues" do Venue.should have(2).records end end ================== gives me ========== 1) TypeError in 'Given a generated venue_spec.rb with fixtures loaded fixtures should load two Venues' can't convert nil into String ========== This was working fine before I did an update. Could anyone tell me what is going on? From aslak.hellesoy at gmail.com Tue Feb 13 02:20:16 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 13 Feb 2007 08:20:16 +0100 Subject: [rspec-users] Error against latest trunk while testing via spec for model In-Reply-To: <24dc07380702122233n264be62bqe5d3dffb59536684@mail.gmail.com> References: <24dc07380702122233n264be62bqe5d3dffb59536684@mail.gmail.com> Message-ID: <8d961d900702122320v780ce47av32586be83fae90ce@mail.gmail.com> We need the backtrace. Can you run again with --backtrace Aslak On 2/13/07, Deepak Jois wrote: > Hi > I just did an update to lates trunk > ================= > context "Given a generated venue_spec.rb with fixtures loaded" do > fixtures :venues > > specify "fixtures should load two Venues" do > Venue.should have(2).records > end > end > ================== > > gives me > > ========== > 1) > TypeError in 'Given a generated venue_spec.rb with fixtures loaded > fixtures should load two Venues' > can't convert nil into String > ========== > > This was working fine before I did an update. Could anyone tell me > what is going on? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From deepak.jois at gmail.com Tue Feb 13 02:28:49 2007 From: deepak.jois at gmail.com (Deepak Jois) Date: Tue, 13 Feb 2007 15:28:49 +0800 Subject: [rspec-users] Error against latest trunk while testing via spec for model In-Reply-To: <8d961d900702122320v780ce47av32586be83fae90ce@mail.gmail.com> References: <24dc07380702122233n264be62bqe5d3dffb59536684@mail.gmail.com> <8d961d900702122320v780ce47av32586be83fae90ce@mail.gmail.com> Message-ID: <24dc07380702122328x3dbcd8b1g6018dbd8848048fc@mail.gmail.com> On 2/13/07, aslak hellesoy wrote: > We need the backtrace. Can you run again with --backtrace > > =============== 1) TypeError in 'Given a generated venue_spec.rb with fixtures loaded fixtures should load two Venues' can't convert nil into String /home/deepak/personalcode/worlds/config/../vendor/rails/activerecord/lib/active_record/fixtures.rb:251:in `join' /home/deepak/personalcode/worlds/config/../vendor/rails/activerecord/lib/active_record/fixtures.rb:251:in `create_fixtures' /home/deepak/personalcode/worlds/config/../vendor/rails/activerecord/lib/active_record/fixtures.rb:250:in `create_fixtures' /home/deepak/personalcode/worlds/config/../vendor/rails/activerecord/lib/active_record/base.rb:890:in `silence' /home/deepak/personalcode/worlds/config/../vendor/rails/activerecord/lib/active_record/fixtures.rb:248:in `create_fixtures' /home/deepak/personalcode/worlds/config/../vendor/rails/activerecord/lib/active_record/fixtures.rb:581:in `load_fixtures' /home/deepak/personalcode/worlds/config/../vendor/rails/activerecord/lib/active_record/fixtures.rb:535:in `setup_with_fixtures' /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/context_eval.rb:131:in `create_block_from_parts' /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/context_eval.rb:129:in `create_block_from_parts' /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/specification.rb:47:in `setup_spec' /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/specification.rb:29:in `run' /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/context.rb:58:in `run' /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/context.rb:55:in `run' /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/context_runner.rb:23:in `run' /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/context_runner.rb:22:in `run' /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/command_line.rb:27:in `run' vendor/plugins/rspec/bin/spec:4: ======================== FWIW, here is my fixtures file file ======= one: id: 1 name: LT1 description: Lecture Theatre 1 active: 1 two: id: 2 name: LT2 description: Lecture Theatre 2 active: 0 ========= The schema of the table matches the fields in the YAML file From aslak.hellesoy at gmail.com Tue Feb 13 03:11:47 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 13 Feb 2007 09:11:47 +0100 Subject: [rspec-users] Error against latest trunk while testing via spec for model In-Reply-To: <24dc07380702122328x3dbcd8b1g6018dbd8848048fc@mail.gmail.com> References: <24dc07380702122233n264be62bqe5d3dffb59536684@mail.gmail.com> <8d961d900702122320v780ce47av32586be83fae90ce@mail.gmail.com> <24dc07380702122328x3dbcd8b1g6018dbd8848048fc@mail.gmail.com> Message-ID: <8d961d900702130011q63f52ffbja0f69bd90bb937be@mail.gmail.com> Rails version? svn revision? On 2/13/07, Deepak Jois wrote: > On 2/13/07, aslak hellesoy wrote: > > We need the backtrace. Can you run again with --backtrace > > > > > =============== > 1) > TypeError in 'Given a generated venue_spec.rb with fixtures loaded > fixtures should load two Venues' > can't convert nil into String > /home/deepak/personalcode/worlds/config/../vendor/rails/activerecord/lib/active_record/fixtures.rb:251:in > `join' > /home/deepak/personalcode/worlds/config/../vendor/rails/activerecord/lib/active_record/fixtures.rb:251:in > `create_fixtures' > /home/deepak/personalcode/worlds/config/../vendor/rails/activerecord/lib/active_record/fixtures.rb:250:in > `create_fixtures' > /home/deepak/personalcode/worlds/config/../vendor/rails/activerecord/lib/active_record/base.rb:890:in > `silence' > /home/deepak/personalcode/worlds/config/../vendor/rails/activerecord/lib/active_record/fixtures.rb:248:in > `create_fixtures' > /home/deepak/personalcode/worlds/config/../vendor/rails/activerecord/lib/active_record/fixtures.rb:581:in > `load_fixtures' > /home/deepak/personalcode/worlds/config/../vendor/rails/activerecord/lib/active_record/fixtures.rb:535:in > `setup_with_fixtures' > /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/context_eval.rb:131:in > `create_block_from_parts' > /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/context_eval.rb:129:in > `create_block_from_parts' > /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/specification.rb:47:in > `setup_spec' > /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/specification.rb:29:in > `run' > /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/context.rb:58:in > `run' > /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/context.rb:55:in > `run' > /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/context_runner.rb:23:in > `run' > /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/context_runner.rb:22:in > `run' > /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/command_line.rb:27:in > `run' > vendor/plugins/rspec/bin/spec:4: > ======================== > > FWIW, here is my fixtures file file > > ======= > one: > id: 1 > name: LT1 > description: Lecture Theatre 1 > active: 1 > two: > id: 2 > name: LT2 > description: Lecture Theatre 2 > active: 0 > ========= > > The schema of the table matches the fields in the YAML file > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From deepak.jois at gmail.com Tue Feb 13 03:23:43 2007 From: deepak.jois at gmail.com (Deepak Jois) Date: Tue, 13 Feb 2007 16:23:43 +0800 Subject: [rspec-users] Error against latest trunk while testing via spec for model In-Reply-To: <8d961d900702130011q63f52ffbja0f69bd90bb937be@mail.gmail.com> References: <24dc07380702122233n264be62bqe5d3dffb59536684@mail.gmail.com> <8d961d900702122320v780ce47av32586be83fae90ce@mail.gmail.com> <24dc07380702122328x3dbcd8b1g6018dbd8848048fc@mail.gmail.com> <8d961d900702130011q63f52ffbja0f69bd90bb937be@mail.gmail.com> Message-ID: <24dc07380702130023r2a033f07q5dc5a9d3b6efe8f1@mail.gmail.com> On 2/13/07, aslak hellesoy wrote: > Rails version? svn revision? > I am running edge rails (HEAD) with rspec trunk HEAD. > On 2/13/07, Deepak Jois wrote: > > On 2/13/07, aslak hellesoy wrote: > > > We need the backtrace. Can you run again with --backtrace > > > > > > > > =============== > > 1) > > TypeError in 'Given a generated venue_spec.rb with fixtures loaded > > fixtures should load two Venues' > > can't convert nil into String > > /home/deepak/personalcode/worlds/config/../vendor/rails/activerecord/lib/active_record/fixtures.rb:251:in > > `join' > > /home/deepak/personalcode/worlds/config/../vendor/rails/activerecord/lib/active_record/fixtures.rb:251:in > > `create_fixtures' > > /home/deepak/personalcode/worlds/config/../vendor/rails/activerecord/lib/active_record/fixtures.rb:250:in > > `create_fixtures' > > /home/deepak/personalcode/worlds/config/../vendor/rails/activerecord/lib/active_record/base.rb:890:in > > `silence' > > /home/deepak/personalcode/worlds/config/../vendor/rails/activerecord/lib/active_record/fixtures.rb:248:in > > `create_fixtures' > > /home/deepak/personalcode/worlds/config/../vendor/rails/activerecord/lib/active_record/fixtures.rb:581:in > > `load_fixtures' > > /home/deepak/personalcode/worlds/config/../vendor/rails/activerecord/lib/active_record/fixtures.rb:535:in > > `setup_with_fixtures' > > /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/context_eval.rb:131:in > > `create_block_from_parts' > > /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/context_eval.rb:129:in > > `create_block_from_parts' > > /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/specification.rb:47:in > > `setup_spec' > > /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/specification.rb:29:in > > `run' > > /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/context.rb:58:in > > `run' > > /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/context.rb:55:in > > `run' > > /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/context_runner.rb:23:in > > `run' > > /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/context_runner.rb:22:in > > `run' > > /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/command_line.rb:27:in > > `run' > > vendor/plugins/rspec/bin/spec:4: > > ======================== > > > > FWIW, here is my fixtures file file > > > > ======= > > one: > > id: 1 > > name: LT1 > > description: Lecture Theatre 1 > > active: 1 > > two: > > id: 2 > > name: LT2 > > description: Lecture Theatre 2 > > active: 0 > > ========= > > > > The schema of the table matches the fields in the YAML file > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From aslak.hellesoy at gmail.com Tue Feb 13 04:18:58 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 13 Feb 2007 10:18:58 +0100 Subject: [rspec-users] Error against latest trunk while testing via spec for model In-Reply-To: <24dc07380702130023r2a033f07q5dc5a9d3b6efe8f1@mail.gmail.com> References: <24dc07380702122233n264be62bqe5d3dffb59536684@mail.gmail.com> <8d961d900702122320v780ce47av32586be83fae90ce@mail.gmail.com> <24dc07380702122328x3dbcd8b1g6018dbd8848048fc@mail.gmail.com> <8d961d900702130011q63f52ffbja0f69bd90bb937be@mail.gmail.com> <24dc07380702130023r2a033f07q5dc5a9d3b6efe8f1@mail.gmail.com> Message-ID: <8d961d900702130118w7eab765bwd9d1e2b867f80acc@mail.gmail.com> On 2/13/07, Deepak Jois wrote: > On 2/13/07, aslak hellesoy wrote: > > Rails version? svn revision? > > > I am running edge rails (HEAD) with rspec trunk HEAD. > We haven't tested RSpec on Rails with Rails Edge because Rails (or some of its dependencies) seems to exit the ruby interpreter while running the test suite. Until we solve this problem, we cannot ensure compatibility with Edge Rails > > On 2/13/07, Deepak Jois wrote: > > > On 2/13/07, aslak hellesoy wrote: > > > > We need the backtrace. Can you run again with --backtrace > > > > > > > > > > > =============== > > > 1) > > > TypeError in 'Given a generated venue_spec.rb with fixtures loaded > > > fixtures should load two Venues' > > > can't convert nil into String > > > /home/deepak/personalcode/worlds/config/../vendor/rails/activerecord/lib/active_record/fixtures.rb:251:in > > > `join' > > > /home/deepak/personalcode/worlds/config/../vendor/rails/activerecord/lib/active_record/fixtures.rb:251:in > > > `create_fixtures' > > > /home/deepak/personalcode/worlds/config/../vendor/rails/activerecord/lib/active_record/fixtures.rb:250:in > > > `create_fixtures' > > > /home/deepak/personalcode/worlds/config/../vendor/rails/activerecord/lib/active_record/base.rb:890:in > > > `silence' > > > /home/deepak/personalcode/worlds/config/../vendor/rails/activerecord/lib/active_record/fixtures.rb:248:in > > > `create_fixtures' > > > /home/deepak/personalcode/worlds/config/../vendor/rails/activerecord/lib/active_record/fixtures.rb:581:in > > > `load_fixtures' > > > /home/deepak/personalcode/worlds/config/../vendor/rails/activerecord/lib/active_record/fixtures.rb:535:in > > > `setup_with_fixtures' > > > /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/context_eval.rb:131:in > > > `create_block_from_parts' > > > /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/context_eval.rb:129:in > > > `create_block_from_parts' > > > /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/specification.rb:47:in > > > `setup_spec' > > > /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/specification.rb:29:in > > > `run' > > > /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/context.rb:58:in > > > `run' > > > /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/context.rb:55:in > > > `run' > > > /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/context_runner.rb:23:in > > > `run' > > > /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/context_runner.rb:22:in > > > `run' > > > /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/command_line.rb:27:in > > > `run' > > > vendor/plugins/rspec/bin/spec:4: > > > ======================== > > > > > > FWIW, here is my fixtures file file > > > > > > ======= > > > one: > > > id: 1 > > > name: LT1 > > > description: Lecture Theatre 1 > > > active: 1 > > > two: > > > id: 2 > > > name: LT2 > > > description: Lecture Theatre 2 > > > active: 0 > > > ========= > > > > > > The schema of the table matches the fields in the YAML file > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Tue Feb 13 06:23:06 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 13 Feb 2007 04:23:06 -0700 Subject: [rspec-users] Error against latest trunk while testing via spec for model In-Reply-To: <8d961d900702130118w7eab765bwd9d1e2b867f80acc@mail.gmail.com> References: <24dc07380702122233n264be62bqe5d3dffb59536684@mail.gmail.com> <8d961d900702122320v780ce47av32586be83fae90ce@mail.gmail.com> <24dc07380702122328x3dbcd8b1g6018dbd8848048fc@mail.gmail.com> <8d961d900702130011q63f52ffbja0f69bd90bb937be@mail.gmail.com> <24dc07380702130023r2a033f07q5dc5a9d3b6efe8f1@mail.gmail.com> <8d961d900702130118w7eab765bwd9d1e2b867f80acc@mail.gmail.com> Message-ID: <57c63afe0702130323l6c6a3037u72b26c95dd99d154@mail.gmail.com> On 2/13/07, aslak hellesoy wrote: > On 2/13/07, Deepak Jois wrote: > > On 2/13/07, aslak hellesoy wrote: > > > Rails version? svn revision? > > > > > I am running edge rails (HEAD) with rspec trunk HEAD. Deepak - please provide revision numbers. HEAD is a moving target. > We haven't tested RSpec on Rails with Rails Edge because Rails (or > some of its dependencies) seems to exit the ruby interpreter while > running the test suite. > > Until we solve this problem, we cannot ensure compatibility with Edge Rails Even after we solve this problem, we will not ensure compatibility with edge. There is simply no way for us to do that. That said, it is important that we hear about problems so that we can be reasonably up to date when releases of Rails come out, so thanks Deepak for bringing this up. Again, please do include revision numbers in the future. Cheers, David > > > > On 2/13/07, Deepak Jois wrote: > > > > On 2/13/07, aslak hellesoy wrote: > > > > > We need the backtrace. Can you run again with --backtrace > > > > > > > > > > > > > > =============== > > > > 1) > > > > TypeError in 'Given a generated venue_spec.rb with fixtures loaded > > > > fixtures should load two Venues' > > > > can't convert nil into String > > > > /home/deepak/personalcode/worlds/config/../vendor/rails/activerecord/lib/active_record/fixtures.rb:251:in > > > > `join' > > > > /home/deepak/personalcode/worlds/config/../vendor/rails/activerecord/lib/active_record/fixtures.rb:251:in > > > > `create_fixtures' > > > > /home/deepak/personalcode/worlds/config/../vendor/rails/activerecord/lib/active_record/fixtures.rb:250:in > > > > `create_fixtures' > > > > /home/deepak/personalcode/worlds/config/../vendor/rails/activerecord/lib/active_record/base.rb:890:in > > > > `silence' > > > > /home/deepak/personalcode/worlds/config/../vendor/rails/activerecord/lib/active_record/fixtures.rb:248:in > > > > `create_fixtures' > > > > /home/deepak/personalcode/worlds/config/../vendor/rails/activerecord/lib/active_record/fixtures.rb:581:in > > > > `load_fixtures' > > > > /home/deepak/personalcode/worlds/config/../vendor/rails/activerecord/lib/active_record/fixtures.rb:535:in > > > > `setup_with_fixtures' > > > > /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/context_eval.rb:131:in > > > > `create_block_from_parts' > > > > /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/context_eval.rb:129:in > > > > `create_block_from_parts' > > > > /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/specification.rb:47:in > > > > `setup_spec' > > > > /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/specification.rb:29:in > > > > `run' > > > > /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/context.rb:58:in > > > > `run' > > > > /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/context.rb:55:in > > > > `run' > > > > /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/context_runner.rb:23:in > > > > `run' > > > > /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/context_runner.rb:22:in > > > > `run' > > > > /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/command_line.rb:27:in > > > > `run' > > > > vendor/plugins/rspec/bin/spec:4: > > > > ======================== > > > > > > > > FWIW, here is my fixtures file file > > > > > > > > ======= > > > > one: > > > > id: 1 > > > > name: LT1 > > > > description: Lecture Theatre 1 > > > > active: 1 > > > > two: > > > > id: 2 > > > > name: LT2 > > > > description: Lecture Theatre 2 > > > > active: 0 > > > > ========= > > > > > > > > The schema of the table matches the fields in the YAML file > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Tue Feb 13 06:37:17 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 13 Feb 2007 04:37:17 -0700 Subject: [rspec-users] Error against latest trunk while testing via spec for model In-Reply-To: <57c63afe0702130323l6c6a3037u72b26c95dd99d154@mail.gmail.com> References: <24dc07380702122233n264be62bqe5d3dffb59536684@mail.gmail.com> <8d961d900702122320v780ce47av32586be83fae90ce@mail.gmail.com> <24dc07380702122328x3dbcd8b1g6018dbd8848048fc@mail.gmail.com> <8d961d900702130011q63f52ffbja0f69bd90bb937be@mail.gmail.com> <24dc07380702130023r2a033f07q5dc5a9d3b6efe8f1@mail.gmail.com> <8d961d900702130118w7eab765bwd9d1e2b867f80acc@mail.gmail.com> <57c63afe0702130323l6c6a3037u72b26c95dd99d154@mail.gmail.com> Message-ID: <57c63afe0702130337m3c0fe277re12a0ee05bfc3c63@mail.gmail.com> FYI - I just ran our suite and everything related to models ran just fine with the following: RSpec rev 1493 Rails rev 6149 ruby 1.8.5 mysql 4.1 On 2/13/07, David Chelimsky wrote: > On 2/13/07, aslak hellesoy wrote: > > On 2/13/07, Deepak Jois wrote: > > > On 2/13/07, aslak hellesoy wrote: > > > > Rails version? svn revision? > > > > > > > I am running edge rails (HEAD) with rspec trunk HEAD. > > Deepak - please provide revision numbers. HEAD is a moving target. > > > We haven't tested RSpec on Rails with Rails Edge because Rails (or > > some of its dependencies) seems to exit the ruby interpreter while > > running the test suite. > > > > Until we solve this problem, we cannot ensure compatibility with Edge Rails > > Even after we solve this problem, we will not ensure compatibility > with edge. There is simply no way for us to do that. > > That said, it is important that we hear about problems so that we can > be reasonably up to date when releases of Rails come out, so thanks > Deepak for bringing this up. Again, please do include revision numbers > in the future. > > Cheers, > David > > > > > > > > On 2/13/07, Deepak Jois wrote: > > > > > On 2/13/07, aslak hellesoy wrote: > > > > > > We need the backtrace. Can you run again with --backtrace > > > > > > > > > > > > > > > > > =============== > > > > > 1) > > > > > TypeError in 'Given a generated venue_spec.rb with fixtures loaded > > > > > fixtures should load two Venues' > > > > > can't convert nil into String > > > > > /home/deepak/personalcode/worlds/config/../vendor/rails/activerecord/lib/active_record/fixtures.rb:251:in > > > > > `join' > > > > > /home/deepak/personalcode/worlds/config/../vendor/rails/activerecord/lib/active_record/fixtures.rb:251:in > > > > > `create_fixtures' > > > > > /home/deepak/personalcode/worlds/config/../vendor/rails/activerecord/lib/active_record/fixtures.rb:250:in > > > > > `create_fixtures' > > > > > /home/deepak/personalcode/worlds/config/../vendor/rails/activerecord/lib/active_record/base.rb:890:in > > > > > `silence' > > > > > /home/deepak/personalcode/worlds/config/../vendor/rails/activerecord/lib/active_record/fixtures.rb:248:in > > > > > `create_fixtures' > > > > > /home/deepak/personalcode/worlds/config/../vendor/rails/activerecord/lib/active_record/fixtures.rb:581:in > > > > > `load_fixtures' > > > > > /home/deepak/personalcode/worlds/config/../vendor/rails/activerecord/lib/active_record/fixtures.rb:535:in > > > > > `setup_with_fixtures' > > > > > /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/context_eval.rb:131:in > > > > > `create_block_from_parts' > > > > > /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/context_eval.rb:129:in > > > > > `create_block_from_parts' > > > > > /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/specification.rb:47:in > > > > > `setup_spec' > > > > > /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/specification.rb:29:in > > > > > `run' > > > > > /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/context.rb:58:in > > > > > `run' > > > > > /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/context.rb:55:in > > > > > `run' > > > > > /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/context_runner.rb:23:in > > > > > `run' > > > > > /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/context_runner.rb:22:in > > > > > `run' > > > > > /home/deepak/personalcode/worlds/vendor/plugins/rspec/lib/spec/runner/command_line.rb:27:in > > > > > `run' > > > > > vendor/plugins/rspec/bin/spec:4: > > > > > ======================== > > > > > > > > > > FWIW, here is my fixtures file file > > > > > > > > > > ======= > > > > > one: > > > > > id: 1 > > > > > name: LT1 > > > > > description: Lecture Theatre 1 > > > > > active: 1 > > > > > two: > > > > > id: 2 > > > > > name: LT2 > > > > > description: Lecture Theatre 2 > > > > > active: 0 > > > > > ========= > > > > > > > > > > The schema of the table matches the fields in the YAML file > > > > > _______________________________________________ > > > > > rspec-users mailing list > > > > > rspec-users at rubyforge.org > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > From work at ashleymoran.me.uk Tue Feb 13 07:28:45 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Tue, 13 Feb 2007 12:28:45 +0000 Subject: [rspec-users] Specs of code that use Time.now Message-ID: <74705A2E-1F3F-49C5-A8B9-3AD091A0590F@ashleymoran.me.uk> Hi Just trying to spec a Rails model that defaults a valid_until date to this time tomorrow. I've done something similar involving Dates, and you can stub the :today method to return something fixed. But when I tried this with Time, I found that RSpec calls Time.now four times per spec. So there's no way to spec code like 1.days.from_now . The best I can come up with is this: context "A Quote" do setup do @quote = Quote.new end specify "should set the default valid_until date to this time tomorrow" do @quote.valid_until.should_be_between(1.days.from_now - 1.second, 1.days.from_now + 1.second) end end Is there a better way? I'm not sure I like "dynamic" specs like this. What's the recommendation for time- and date-related specs? Ashley From work at ashleymoran.me.uk Tue Feb 13 09:51:50 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Tue, 13 Feb 2007 14:51:50 +0000 Subject: [rspec-users] RJS specs Message-ID: <6CD3A982-165C-4548-9BC3-8B83F9D28956@ashleymoran.me.uk> Hi again... This is wierd spec problem no. 3. I've got a simple one line RJS file that renders a partial specified by the controller page.replace_html("product_info", :partial => @product_partial) The partials in question will contain purely static content - the idea is to have some dynamic links, so you hit http://localhost:3000/gap/product_info/product_1 http://localhost:3000/gap/product_info/product_2 it will render _product_1.rhtml, _product_2.rhtml in a div etc. Ideally I'd like to write something like: page.should_receive(:replace_html).with("product_info", "product_1") So far the best I can find is to add a div with a known id to each partial and test like this: context "A rendered gap/product_info" do specify "should have RJS to update the product_info div" do assigns[:product_partial] = "product_info_rti" render 'gap/product_info' response.should_have_rjs :replace_html, 'product_info' end %w[ rti finance ].each do |product_type| specify "should have a product_info_#{product_type} div when the " do assigns[:product_partial] = "product_info_#{product_type}" render 'gap/product_info' response.should_have "div#product_info_#{product_type}" end end end It's far from ideal, because it relies on someone remembering to update the spec if a new product type is added. I can't see a more direct way to test the RJS though. Thanks Ashley From esad at esse.at Tue Feb 13 10:22:47 2007 From: esad at esse.at (Esad Hajdarevic) Date: Tue, 13 Feb 2007 16:22:47 +0100 Subject: [rspec-users] "should.be_in [values]" and "each_should_satisfy" Message-ID: <45D1D7C7.9090400@esse.at> Hi! I just started using RSpec and have some question that I couldn't find answers to. If I have a result that can have two valid values, is there a better way of writing the following assertion? [value1,value2].should_include actual Is there a more elegant way of performing should_satisfy on a collection, for example I currently use something like collection.each {|x| x.should_satisfy {|x| ... } } which is very ugly. Is there something like each_should_satisfy? Thanks, Esad From work at ashleymoran.me.uk Tue Feb 13 10:53:41 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Tue, 13 Feb 2007 15:53:41 +0000 Subject: [rspec-users] RJS specs In-Reply-To: <6CD3A982-165C-4548-9BC3-8B83F9D28956@ashleymoran.me.uk> References: <6CD3A982-165C-4548-9BC3-8B83F9D28956@ashleymoran.me.uk> Message-ID: <3D8CCA91-E064-474F-9F5D-4A82FBEC5977@ashleymoran.me.uk> Sorry ignore the noise... I was doing the Ajax updates wrong and introducing an unnecessary extra RJS step, so my specs will be different From court3nay at gmail.com Tue Feb 13 11:15:03 2007 From: court3nay at gmail.com (Courtenay) Date: Tue, 13 Feb 2007 08:15:03 -0800 Subject: [rspec-users] Specs of code that use Time.now In-Reply-To: <74705A2E-1F3F-49C5-A8B9-3AD091A0590F@ashleymoran.me.uk> References: <74705A2E-1F3F-49C5-A8B9-3AD091A0590F@ashleymoran.me.uk> Message-ID: <4b430c8f0702130815o58c331d5me429095bed04dc2@mail.gmail.com> On 2/13/07, Ashley Moran wrote: > Just trying to spec a Rails model that defaults a valid_until date to > this time tomorrow. I've done something similar involving Dates, and > you can stub the :today method to return something fixed. But when I > tried this with Time, I found that RSpec calls Time.now four times > per spec. Personally I like to put this in spec_helper def Time.now Time.local(2006,12,01,0,0,0) end Then all dates are fixed (1 day from now is 2006-12-02 for example). No clue if this is best practise, works well here though. From work at ashleymoran.me.uk Tue Feb 13 12:50:10 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Tue, 13 Feb 2007 17:50:10 +0000 Subject: [rspec-users] Specs of code that use Time.now In-Reply-To: <4b430c8f0702130815o58c331d5me429095bed04dc2@mail.gmail.com> References: <74705A2E-1F3F-49C5-A8B9-3AD091A0590F@ashleymoran.me.uk> <4b430c8f0702130815o58c331d5me429095bed04dc2@mail.gmail.com> Message-ID: On 13 Feb 2007, at 16:15, Courtenay wrote: > Personally I like to put this in spec_helper > > def Time.now > Time.local(2006,12,01,0,0,0) > end > > Then all dates are fixed (1 day from now is 2006-12-02 for example). > No clue if this is best practise, works well here though. Does this not interfere with RSpec? I noticed it calling Time.now four times without any code on my part. I suppose something has to give though Ashley From court3nay at gmail.com Tue Feb 13 13:18:46 2007 From: court3nay at gmail.com (Courtenay) Date: Tue, 13 Feb 2007 10:18:46 -0800 Subject: [rspec-users] Specs of code that use Time.now In-Reply-To: References: <74705A2E-1F3F-49C5-A8B9-3AD091A0590F@ashleymoran.me.uk> <4b430c8f0702130815o58c331d5me429095bed04dc2@mail.gmail.com> Message-ID: <4b430c8f0702131018m6b2fd985o2f727b78bf0b8d46@mail.gmail.com> On 2/13/07, Ashley Moran wrote: > > def Time.now > > Time.local(2006,12,01,0,0,0) > > end > > > > Then all dates are fixed (1 day from now is 2006-12-02 for example). > > No clue if this is best practise, works well here though. > > Does this not interfere with RSpec? I noticed it calling Time.now > four times without any code on my part. I suppose something has to > give though > Dunno :) May be it's using time.now or benchmark to time things. From court3nay at gmail.com Tue Feb 13 13:22:22 2007 From: court3nay at gmail.com (Courtenay) Date: Tue, 13 Feb 2007 10:22:22 -0800 Subject: [rspec-users] Specs of code that use Time.now In-Reply-To: References: <74705A2E-1F3F-49C5-A8B9-3AD091A0590F@ashleymoran.me.uk> <4b430c8f0702130815o58c331d5me429095bed04dc2@mail.gmail.com> Message-ID: <4b430c8f0702131022p910233fxee85d6b0ba93e956@mail.gmail.com> On 2/13/07, Ashley Moran wrote: > On 13 Feb 2007, at 16:15, Courtenay wrote: > > > Personally I like to put this in spec_helper > > > > def Time.now > > Time.local(2006,12,01,0,0,0) > > end > > > > Then all dates are fixed (1 day from now is 2006-12-02 for example). > > No clue if this is best practise, works well here though. > > Does this not interfere with RSpec? I noticed it calling Time.now > four times without any code on my part. I suppose something has to > give though > Try this: class Foo class Time < ::Time def self.now Time.local(2006,10,1,0,0,0) end end def test_local Time.now.inspect end end f = Foo.new f.test_local => "Sun Oct 01 00:00:00 -0700 2006" Time.new => Tue Feb 13 10:14:03 -0800 2007 So, just make a new subclass of your model called Time that inherits from ::Time but overrides the .now to fix the date, and it shouldn't be that much of a problem :) From cwdinfo at gmail.com Tue Feb 13 14:04:30 2007 From: cwdinfo at gmail.com (s.ross) Date: Tue, 13 Feb 2007 11:04:30 -0800 Subject: [rspec-users] Specs of code that use Time.now In-Reply-To: <4b430c8f0702131022p910233fxee85d6b0ba93e956@mail.gmail.com> References: <74705A2E-1F3F-49C5-A8B9-3AD091A0590F@ashleymoran.me.uk> <4b430c8f0702130815o58c331d5me429095bed04dc2@mail.gmail.com> <4b430c8f0702131022p910233fxee85d6b0ba93e956@mail.gmail.com> Message-ID: Why not try this in the applicable spec: the_time = Time.local(2006,12,01,0,0,0) Time.should_receive(:now).and_return(the_time) Will this break other stuff? On Feb 13, 2007, at 10:22 AM, Courtenay wrote: > On 2/13/07, Ashley Moran wrote: >> On 13 Feb 2007, at 16:15, Courtenay wrote: >> >>> Personally I like to put this in spec_helper >>> >>> def Time.now >>> Time.local(2006,12,01,0,0,0) >>> end >>> >>> Then all dates are fixed (1 day from now is 2006-12-02 for example). >>> No clue if this is best practise, works well here though. >> >> Does this not interfere with RSpec? I noticed it calling Time.now >> four times without any code on my part. I suppose something has to >> give though >> > > Try this: > > class Foo > class Time < ::Time > def self.now > Time.local(2006,10,1,0,0,0) > end > end > > def test_local > Time.now.inspect > end > end > > f = Foo.new > f.test_local > => "Sun Oct 01 00:00:00 -0700 2006" > Time.new > => Tue Feb 13 10:14:03 -0800 2007 > > So, just make a new subclass of your model called Time that inherits > from ::Time but overrides the .now to fix the date, and it shouldn't > be that much of a problem :) > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From aslak.hellesoy at gmail.com Tue Feb 13 14:20:36 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 13 Feb 2007 20:20:36 +0100 Subject: [rspec-users] Specs of code that use Time.now In-Reply-To: <4b430c8f0702130815o58c331d5me429095bed04dc2@mail.gmail.com> References: <74705A2E-1F3F-49C5-A8B9-3AD091A0590F@ashleymoran.me.uk> <4b430c8f0702130815o58c331d5me429095bed04dc2@mail.gmail.com> Message-ID: <8d961d900702131120y51f55c41h2e747e364b6847a6@mail.gmail.com> On 2/13/07, Courtenay wrote: > On 2/13/07, Ashley Moran wrote: > > Just trying to spec a Rails model that defaults a valid_until date to > > this time tomorrow. I've done something similar involving Dates, and > > you can stub the :today method to return something fixed. But when I > > tried this with Time, I found that RSpec calls Time.now four times > > per spec. > > Personally I like to put this in spec_helper > > def Time.now > Time.local(2006,12,01,0,0,0) > end > > Then all dates are fixed (1 day from now is 2006-12-02 for example). > No clue if this is best practise, works well here though. There are no best practices. But this seems like a good practice. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From hughes.james at gmail.com Tue Feb 13 14:21:39 2007 From: hughes.james at gmail.com (James Hughes) Date: Tue, 13 Feb 2007 11:21:39 -0800 Subject: [rspec-users] spec.opts Message-ID: <765a2c230702131121r464a7d1hf261e26f1588ace3@mail.gmail.com> Hi, Just built the gem from trunk for the first time and ran into an issue with the generated spec.opts file (rev. 1493). Moving the file out of the way fixed the problem. I'm not on windows, so this is not a win32console gem issue as per the README. /usr/lib/ruby/gems/1.8/gems/rspec-0.8.0/lib/spec/expectations/sugar.rb:13:in `call': undefined local variable or method `colour' for # (NameError) from /usr/lib/ruby/gems/1.8/gems/rspec-0.8.0/lib/spec/expectations/sugar.rb:13:in `_method_missing' from /usr/lib/ruby/gems/1.8/gems/rspec-0.8.0/lib/spec/expectations/sugar.rb:9:in `method_missing' from ./spec/spec.opts:1 from /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active_support/dependencies.rb:489:in `load' from /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active_support/dependencies.rb:343:in `new_constants_in' from /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active_support/dependencies.rb:489:in `load' from /usr/lib/ruby/gems/1.8/gems/rspec-0.8.0/lib/spec/runner/command_line.rb:22:in `run' from /usr/lib/ruby/gems/1.8/gems/rspec-0.8.0/lib/spec/runner/command_line.rb:16:in `run' from /usr/lib/ruby/gems/1.8/gems/rspec-0.8.0/bin/spec:4 from /usr/bin/spec:18 James Hughes From court3nay at gmail.com Tue Feb 13 15:16:58 2007 From: court3nay at gmail.com (Courtenay) Date: Tue, 13 Feb 2007 12:16:58 -0800 Subject: [rspec-users] Specs of code that use Time.now In-Reply-To: <8d961d900702131120y51f55c41h2e747e364b6847a6@mail.gmail.com> References: <74705A2E-1F3F-49C5-A8B9-3AD091A0590F@ashleymoran.me.uk> <4b430c8f0702130815o58c331d5me429095bed04dc2@mail.gmail.com> <8d961d900702131120y51f55c41h2e747e364b6847a6@mail.gmail.com> Message-ID: <4b430c8f0702131216m3a2dd2e4l1115617f242871f6@mail.gmail.com> On 2/13/07, aslak hellesoy wrote: > On 2/13/07, Courtenay wrote: > > On 2/13/07, Ashley Moran wrote: > > > Just trying to spec a Rails model that defaults a valid_until date to > > > this time tomorrow. I've done something similar involving Dates, and > > > you can stub the :today method to return something fixed. But when I > > > tried this with Time, I found that RSpec calls Time.now four times > > > per spec. > > > > Personally I like to put this in spec_helper > > > > def Time.now > > Time.local(2006,12,01,0,0,0) > > end > > > > Then all dates are fixed (1 day from now is 2006-12-02 for example). > > No clue if this is best practise, works well here though. > > There are no best practices. > But this seems like a good practice. > Time.stub! and only use should_receive when you're specifically testing that Time.now is called. From aslak.hellesoy at gmail.com Tue Feb 13 16:01:47 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 13 Feb 2007 22:01:47 +0100 Subject: [rspec-users] spec.opts In-Reply-To: <765a2c230702131121r464a7d1hf261e26f1588ace3@mail.gmail.com> References: <765a2c230702131121r464a7d1hf261e26f1588ace3@mail.gmail.com> Message-ID: <8d961d900702131301ybff40bbn6f7b291f0d020471@mail.gmail.com> On 2/13/07, James Hughes wrote: > Hi, > > Just built the gem from trunk for the first time and ran into an issue > with the generated spec.opts file (rev. 1493). Moving the file out of > the way fixed the problem. I'm not on windows, so this is not a > win32console gem issue as per the README. > You have to tell us the steps to reproduce this. It's odd that the spec.opts file is part of the backtrace. > /usr/lib/ruby/gems/1.8/gems/rspec-0.8.0/lib/spec/expectations/sugar.rb:13:in > `call': undefined local variable or method `colour' for > # (NameError) > from /usr/lib/ruby/gems/1.8/gems/rspec-0.8.0/lib/spec/expectations/sugar.rb:13:in > `_method_missing' > from /usr/lib/ruby/gems/1.8/gems/rspec-0.8.0/lib/spec/expectations/sugar.rb:9:in > `method_missing' > from ./spec/spec.opts:1 > from /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active_support/dependencies.rb:489:in > `load' > from /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active_support/dependencies.rb:343:in > `new_constants_in' > from /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active_support/dependencies.rb:489:in > `load' > from /usr/lib/ruby/gems/1.8/gems/rspec-0.8.0/lib/spec/runner/command_line.rb:22:in > `run' > from /usr/lib/ruby/gems/1.8/gems/rspec-0.8.0/lib/spec/runner/command_line.rb:16:in > `run' > from /usr/lib/ruby/gems/1.8/gems/rspec-0.8.0/bin/spec:4 > from /usr/bin/spec:18 > > > James Hughes > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From hughes.james at gmail.com Tue Feb 13 16:26:49 2007 From: hughes.james at gmail.com (James Hughes) Date: Tue, 13 Feb 2007 13:26:49 -0800 Subject: [rspec-users] spec.opts In-Reply-To: <8d961d900702131301ybff40bbn6f7b291f0d020471@mail.gmail.com> References: <765a2c230702131121r464a7d1hf261e26f1588ace3@mail.gmail.com> <8d961d900702131301ybff40bbn6f7b291f0d020471@mail.gmail.com> Message-ID: <765a2c230702131326s30ad549buba452ecc7dc43f3e@mail.gmail.com> On 2/13/07, aslak hellesoy wrote: > On 2/13/07, James Hughes wrote: > > Hi, > > > > Just built the gem from trunk for the first time and ran into an issue > > with the generated spec.opts file (rev. 1493). Moving the file out of > > the way fixed the problem. I'm not on windows, so this is not a > > win32console gem issue as per the README. > > > > You have to tell us the steps to reproduce this. > It's odd that the spec.opts file is part of the backtrace. I've discovered that this was due to the fact that I wasn't using the rake task ('rake spec'). This particular time I ran the specs with 'spec spec/*'. I won't do that anymore. Everything is fine when running 'rake spec', or even 'spec spec/'. Sorry for the confusion. jh > > > /usr/lib/ruby/gems/1.8/gems/rspec-0.8.0/lib/spec/expectations/sugar.rb:13:in > > `call': undefined local variable or method `colour' for > > # (NameError) > > from /usr/lib/ruby/gems/1.8/gems/rspec-0.8.0/lib/spec/expectations/sugar.rb:13:in > > `_method_missing' > > from /usr/lib/ruby/gems/1.8/gems/rspec-0.8.0/lib/spec/expectations/sugar.rb:9:in > > `method_missing' > > from ./spec/spec.opts:1 > > from /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active_support/dependencies.rb:489:in > > `load' > > from /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active_support/dependencies.rb:343:in > > `new_constants_in' > > from /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active_support/dependencies.rb:489:in > > `load' > > from /usr/lib/ruby/gems/1.8/gems/rspec-0.8.0/lib/spec/runner/command_line.rb:22:in > > `run' > > from /usr/lib/ruby/gems/1.8/gems/rspec-0.8.0/lib/spec/runner/command_line.rb:16:in > > `run' > > from /usr/lib/ruby/gems/1.8/gems/rspec-0.8.0/bin/spec:4 > > from /usr/bin/spec:18 > > > > > > James Hughes > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From wayne at larsen.st Tue Feb 13 16:40:12 2007 From: wayne at larsen.st (Wayne Larsen) Date: Tue, 13 Feb 2007 16:40:12 -0500 Subject: [rspec-users] spec.opts In-Reply-To: <8d961d900702131301ybff40bbn6f7b291f0d020471@mail.gmail.com> References: <765a2c230702131121r464a7d1hf261e26f1588ace3@mail.gmail.com> <8d961d900702131301ybff40bbn6f7b291f0d020471@mail.gmail.com> Message-ID: On 13-Feb-07, at 4:01 PM, aslak hellesoy wrote: > On 2/13/07, James Hughes wrote: >> Hi, >> >> Just built the gem from trunk for the first time and ran into an >> issue >> with the generated spec.opts file (rev. 1493). Moving the file out of >> the way fixed the problem. I'm not on windows, so this is not a >> win32console gem issue as per the README. >> > > You have to tell us the steps to reproduce this. > It's odd that the spec.opts file is part of the backtrace. > spec.opts seems to be very picky about extra whitespace. I ran into a very similar stack trace (I had to first test --color in place of -- colour to se if that was the problem.. :). After I removed extra whitespace from the end of the file it worked. I also ran into a problem when there is no spec.opts file: /opt/local/lib/ruby/gems/1.8/gems/rspec-0.8.0/lib/spec/runner/ option_parser.rb:143:in `readlines': No such file or directory - / Users/wlarsen/Sites/roar/roar_test/config/../spec/spec.opts (Errno::ENOENT) from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.8.0/lib/spec/ runner/option_parser.rb:143:in `parse' It would be nice if there is a test for the file, and it is only used if it exists. Wayne --- http://waynelarsen.com http://nanoware.com From cwdinfo at gmail.com Tue Feb 13 18:42:32 2007 From: cwdinfo at gmail.com (s.ross) Date: Tue, 13 Feb 2007 15:42:32 -0800 Subject: [rspec-users] Controller/View User Agent Strings In-Reply-To: <57c63afe0702130337m3c0fe277re12a0ee05bfc3c63@mail.gmail.com> References: <24dc07380702122233n264be62bqe5d3dffb59536684@mail.gmail.com> <8d961d900702122320v780ce47av32586be83fae90ce@mail.gmail.com> <24dc07380702122328x3dbcd8b1g6018dbd8848048fc@mail.gmail.com> <8d961d900702130011q63f52ffbja0f69bd90bb937be@mail.gmail.com> <24dc07380702130023r2a033f07q5dc5a9d3b6efe8f1@mail.gmail.com> <8d961d900702130118w7eab765bwd9d1e2b867f80acc@mail.gmail.com> <57c63afe0702130323l6c6a3037u72b26c95dd99d154@mail.gmail.com> <57c63afe0702130337m3c0fe277re12a0ee05bfc3c63@mail.gmail.com> Message-ID: <51320D91-926F-4D8C-9679-385AF0F7504D@gmail.com> I have conditional logic in my view (I know, obligatory slap on the wrist) so that an add-on stylesheet is linked in for IE users. The code is: <%= stylesheet_link_tag('ie', :media => 'screen') if request.user_agent && request.user_agent =~ /msie/i %> The spec is: specify "should display index page" do get :index response.should_be_success end There is no user_agent in the request object passed to the view. Now, I can change all of this by simply: setup do request.stub!(:user_agent).and_return('msie') end but I was wondering if there was a better way? Thanks, Steve From dchelimsky at gmail.com Tue Feb 13 19:27:15 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 13 Feb 2007 17:27:15 -0700 Subject: [rspec-users] "should.be_in [values]" and "each_should_satisfy" In-Reply-To: <45D1D7C7.9090400@esse.at> References: <45D1D7C7.9090400@esse.at> Message-ID: <57c63afe0702131627j4fe781e5p473883d4899c5c26@mail.gmail.com> On 2/13/07, Esad Hajdarevic wrote: > Hi! > > I just started using RSpec and have some question that I couldn't find > answers to. > > If I have a result that can have two valid values, is there a better way > of writing > the following assertion? > > [value1,value2].should_include actual No, but you'll soon (0.8) be able to write your own custom expectation matchers. So you'd be able to write, for example: actual.should be_in(value1,value2) > > Is there a more elegant way of performing should_satisfy on a > collection, for > example I currently use something like collection.each {|x| > x.should_satisfy {|x| ... } } > which is very ugly. Is there something like each_should_satisfy? There's not. Again, when 0.8 is released you'll be able to right this yourself. Probably something like: collection.should satisfy_for_each { |x| ... } Coming soon.... Cheers, David > > Thanks, > > Esad > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Tue Feb 13 19:27:37 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 13 Feb 2007 17:27:37 -0700 Subject: [rspec-users] "should.be_in [values]" and "each_should_satisfy" In-Reply-To: <57c63afe0702131627j4fe781e5p473883d4899c5c26@mail.gmail.com> References: <45D1D7C7.9090400@esse.at> <57c63afe0702131627j4fe781e5p473883d4899c5c26@mail.gmail.com> Message-ID: <57c63afe0702131627t68d82eb3m6a397c13f7979879@mail.gmail.com> PS - you can do that now if you're a trunkster. On 2/13/07, David Chelimsky wrote: > On 2/13/07, Esad Hajdarevic wrote: > > Hi! > > > > I just started using RSpec and have some question that I couldn't find > > answers to. > > > > If I have a result that can have two valid values, is there a better way > > of writing > > the following assertion? > > > > [value1,value2].should_include actual > > No, but you'll soon (0.8) be able to write your own custom expectation > matchers. So you'd be able to write, for example: > > actual.should be_in(value1,value2) > > > > > Is there a more elegant way of performing should_satisfy on a > > collection, for > > example I currently use something like collection.each {|x| > > x.should_satisfy {|x| ... } } > > which is very ugly. Is there something like each_should_satisfy? > > There's not. Again, when 0.8 is released you'll be able to right this > yourself. Probably something like: > > collection.should satisfy_for_each { |x| ... } > > Coming soon.... > > Cheers, > David > > > > > > Thanks, > > > > Esad > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > From dchelimsky at gmail.com Tue Feb 13 19:28:00 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 13 Feb 2007 17:28:00 -0700 Subject: [rspec-users] "should.be_in [values]" and "each_should_satisfy" In-Reply-To: <57c63afe0702131627t68d82eb3m6a397c13f7979879@mail.gmail.com> References: <45D1D7C7.9090400@esse.at> <57c63afe0702131627j4fe781e5p473883d4899c5c26@mail.gmail.com> <57c63afe0702131627t68d82eb3m6a397c13f7979879@mail.gmail.com> Message-ID: <57c63afe0702131628x68c0ea4dr5b67b55216e4ab9b@mail.gmail.com> PPS - s/right/write On 2/13/07, David Chelimsky wrote: > PS - you can do that now if you're a trunkster. > > On 2/13/07, David Chelimsky wrote: > > On 2/13/07, Esad Hajdarevic wrote: > > > Hi! > > > > > > I just started using RSpec and have some question that I couldn't find > > > answers to. > > > > > > If I have a result that can have two valid values, is there a better way > > > of writing > > > the following assertion? > > > > > > [value1,value2].should_include actual > > > > No, but you'll soon (0.8) be able to write your own custom expectation > > matchers. So you'd be able to write, for example: > > > > actual.should be_in(value1,value2) > > > > > > > > Is there a more elegant way of performing should_satisfy on a > > > collection, for > > > example I currently use something like collection.each {|x| > > > x.should_satisfy {|x| ... } } > > > which is very ugly. Is there something like each_should_satisfy? > > > > There's not. Again, when 0.8 is released you'll be able to right this > > yourself. Probably something like: > > > > collection.should satisfy_for_each { |x| ... } > > > > Coming soon.... > > > > Cheers, > > David > > > > > > > > > > Thanks, > > > > > > Esad > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > From deepak.jois at gmail.com Tue Feb 13 19:37:08 2007 From: deepak.jois at gmail.com (Deepak Jois) Date: Wed, 14 Feb 2007 08:37:08 +0800 Subject: [rspec-users] Error against latest trunk while testing via spec for model In-Reply-To: <57c63afe0702130337m3c0fe277re12a0ee05bfc3c63@mail.gmail.com> References: <24dc07380702122233n264be62bqe5d3dffb59536684@mail.gmail.com> <8d961d900702122320v780ce47av32586be83fae90ce@mail.gmail.com> <24dc07380702122328x3dbcd8b1g6018dbd8848048fc@mail.gmail.com> <8d961d900702130011q63f52ffbja0f69bd90bb937be@mail.gmail.com> <24dc07380702130023r2a033f07q5dc5a9d3b6efe8f1@mail.gmail.com> <8d961d900702130118w7eab765bwd9d1e2b867f80acc@mail.gmail.com> <57c63afe0702130323l6c6a3037u72b26c95dd99d154@mail.gmail.com> <57c63afe0702130337m3c0fe277re12a0ee05bfc3c63@mail.gmail.com> Message-ID: <24dc07380702131637k3febb411v1ab07d8f39b0eb3b@mail.gmail.com> On 2/13/07, David Chelimsky wrote: > FYI - I just ran our suite and everything related to models ran just > fine with the following: > > RSpec rev 1493 > Rails rev 6149 > ruby 1.8.5 > mysql 4.1 > Almost the same for me RSpec rev 1493 Rails rev 6149 ruby 1.8.5 mysql 5.0.27 The error seems to be related to loading the fixture because other specs not related to specs pass as normal. And I can replicate it both on my Mac as well as Linux machines. I could be doing something stupud, but here is my code: The Venue Model: === class Venue < ActiveRecord::Base validates_uniqueness_of :name, :on => :create, :message => "must be unique" validates_presence_of :name, :description end === The Venue Fixture: === one: id: 1 name: LT1 description: Lecture Theatre 1 active: 1 two: id: 2 name: LT2 description: Lecture Theatre 2 active: 0 === Spec file using fixtures. As I said above, I have another context where I do not use specs and it works just fine. ==== context "Given a generated venue_spec.rb with fixtures loaded" do fixtures :venues specify "fixtures should load two Venues" do Venue.should have(2).records end specify "a new venue cannot have the same name" do v = Venue.new(:name => "LT2", :description => "Lecture Theatre 2 (duplicate)", :active => false) v.should_not_be_valid end end ==== From deepak.jois at gmail.com Tue Feb 13 19:38:06 2007 From: deepak.jois at gmail.com (Deepak Jois) Date: Wed, 14 Feb 2007 08:38:06 +0800 Subject: [rspec-users] Error against latest trunk while testing via spec for model In-Reply-To: <24dc07380702131637k3febb411v1ab07d8f39b0eb3b@mail.gmail.com> References: <24dc07380702122233n264be62bqe5d3dffb59536684@mail.gmail.com> <8d961d900702122320v780ce47av32586be83fae90ce@mail.gmail.com> <24dc07380702122328x3dbcd8b1g6018dbd8848048fc@mail.gmail.com> <8d961d900702130011q63f52ffbja0f69bd90bb937be@mail.gmail.com> <24dc07380702130023r2a033f07q5dc5a9d3b6efe8f1@mail.gmail.com> <8d961d900702130118w7eab765bwd9d1e2b867f80acc@mail.gmail.com> <57c63afe0702130323l6c6a3037u72b26c95dd99d154@mail.gmail.com> <57c63afe0702130337m3c0fe277re12a0ee05bfc3c63@mail.gmail.com> <24dc07380702131637k3febb411v1ab07d8f39b0eb3b@mail.gmail.com> Message-ID: <24dc07380702131638h32327500wbb799b1464f6ec08@mail.gmail.com> > The error seems to be related to loading the fixture because other > specs not related to specs pass as normal. > I meant to say "The other specs not loading fixtures pass as normal". From dchelimsky at gmail.com Tue Feb 13 19:40:42 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 13 Feb 2007 17:40:42 -0700 Subject: [rspec-users] Controller/View User Agent Strings In-Reply-To: <51320D91-926F-4D8C-9679-385AF0F7504D@gmail.com> References: <24dc07380702122233n264be62bqe5d3dffb59536684@mail.gmail.com> <8d961d900702122320v780ce47av32586be83fae90ce@mail.gmail.com> <24dc07380702122328x3dbcd8b1g6018dbd8848048fc@mail.gmail.com> <8d961d900702130011q63f52ffbja0f69bd90bb937be@mail.gmail.com> <24dc07380702130023r2a033f07q5dc5a9d3b6efe8f1@mail.gmail.com> <8d961d900702130118w7eab765bwd9d1e2b867f80acc@mail.gmail.com> <57c63afe0702130323l6c6a3037u72b26c95dd99d154@mail.gmail.com> <57c63afe0702130337m3c0fe277re12a0ee05bfc3c63@mail.gmail.com> <51320D91-926F-4D8C-9679-385AF0F7504D@gmail.com> Message-ID: <57c63afe0702131640n60550fe8h4ee98835f8b8dd31@mail.gmail.com> On 2/13/07, s.ross wrote: > I have conditional logic in my view (I know, obligatory slap on the > wrist) so that an add-on stylesheet is linked in for IE users. The > code is: > > <%= stylesheet_link_tag('ie', :media => 'screen') if > request.user_agent && request.user_agent =~ /msie/i %> > > The spec is: > > specify "should display index page" do > get :index > response.should_be_success > end > > There is no user_agent in the request object passed to the view. Now, > I can change all of this by simply: > > setup do > request.stub!(:user_agent).and_return('msie') > end > > but I was wondering if there was a better way? That seems pretty simple to me. What is bugging you about it? > > Thanks, > > Steve > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From cwdinfo at gmail.com Tue Feb 13 20:22:05 2007 From: cwdinfo at gmail.com (s.ross) Date: Tue, 13 Feb 2007 17:22:05 -0800 Subject: [rspec-users] Controller/View User Agent Strings In-Reply-To: <57c63afe0702131640n60550fe8h4ee98835f8b8dd31@mail.gmail.com> References: <24dc07380702122233n264be62bqe5d3dffb59536684@mail.gmail.com> <8d961d900702122320v780ce47av32586be83fae90ce@mail.gmail.com> <24dc07380702122328x3dbcd8b1g6018dbd8848048fc@mail.gmail.com> <8d961d900702130011q63f52ffbja0f69bd90bb937be@mail.gmail.com> <24dc07380702130023r2a033f07q5dc5a9d3b6efe8f1@mail.gmail.com> <8d961d900702130118w7eab765bwd9d1e2b867f80acc@mail.gmail.com> <57c63afe0702130323l6c6a3037u72b26c95dd99d154@mail.gmail.com> <57c63afe0702130337m3c0fe277re12a0ee05bfc3c63@mail.gmail.com> <51320D91-926F-4D8C-9679-385AF0F7504D@gmail.com> <57c63afe0702131640n60550fe8h4ee98835f8b8dd31@mail.gmail.com> Message-ID: <284E8837-1009-4959-808C-628FF30F498C@gmail.com> Just checking. I guess it just seemed too easy :) What happens when this page renders is a tag like: Or something like that with the Rails asset tagging. What I want to do is test that I'm responding to the user agent string correctly using a matcher that looks for the filename, but disregards the asset tag: response.should have_tag('link', :attributes => {:href => / application.css/}) response.should_not have_tag('link', :attributes => {:href => /ie.css/}) However, the "should have" expectations always pass no matter what. Not coincidentally, the "should_not have" ones always fail. I can see, looking at the Rails plugin source that my syntax is broken and that the have_tag expectation was meant more to determine whether the tag exists and how many times it occurs. Is there a matcher that peers into the tag the way the old Test::Unit assertions did? Thanks On Feb 13, 2007, at 4:40 PM, David Chelimsky wrote: > On 2/13/07, s.ross wrote: >> I have conditional logic in my view (I know, obligatory slap on the >> wrist) so that an add-on stylesheet is linked in for IE users. The >> code is: >> >> <%= stylesheet_link_tag('ie', :media => 'screen') if >> request.user_agent && request.user_agent =~ /msie/i %> >> >> The spec is: >> >> specify "should display index page" do >> get :index >> response.should_be_success >> end >> >> There is no user_agent in the request object passed to the view. Now, >> I can change all of this by simply: >> >> setup do >> request.stub!(:user_agent).and_return('msie') >> end >> >> but I was wondering if there was a better way? > > That seems pretty simple to me. What is bugging you about it? > >> >> Thanks, >> >> Steve >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From tils-rspec at tils.net Wed Feb 14 07:39:17 2007 From: tils-rspec at tils.net (Tilmann Singer) Date: Wed, 14 Feb 2007 13:39:17 +0100 Subject: [rspec-users] Emacs spec parsing? In-Reply-To: <20070130110657.GD25504@tils.net> References: <20070130110657.GD25504@tils.net> Message-ID: <20070214123917.GO22477@tils.net> * Tilmann Singer [20070130 16:56]: > Did anyone with better emacs lisp knowledge than me already come up > with a function like spec-at-point which finds the specify and context > declaration for the current cursor position and returns a string which > can be used to be passed to the --spec option of the spec runner? Answering my own question, in case someone else is interested in this: below is the relevant part of my .emacs with a function that finds and runs the spec under the current cursor position. (defun spec-at-point () "Run specification at point" (interactive) (let ( (old_point (point)) (specify (progn (move-end-of-line nil) (re-search-backward "^ *specify +\"\\(.*\\)\" +do") (match-string 1))) (context (progn (re-search-backward "^ *context +\"\\(.*\\)\" +do") (match-string 1)))) (goto-char old_point) (compile (concat "spec -s \"" context " " specify "\" " (buffer-file-name))) ) ) (global-set-key "\C-cs" 'spec-at-point) (defun spec-file() "Run current spec file" (interactive) (compile (concat "spec " (buffer-file-name))) ) (defun save-and-recompile () "Save and recompile" (interactive) (save-buffer) (recompile) ) (define-key global-map "\C-x\C-y" 'save-and-recompile) Til From hughes.james at gmail.com Wed Feb 14 19:00:37 2007 From: hughes.james at gmail.com (James Hughes) Date: Wed, 14 Feb 2007 16:00:37 -0800 Subject: [rspec-users] Odd parameter munging with with() Message-ID: <765a2c230702141600j33b98be7w22dab72e5c2cbc10@mail.gmail.com> Hi, I have this setup block: setup do session[:login] = 'jhughes' @user = mock("user") User.stub!(:find).and_return(@user) @params = {:cn => "Bilbo Baggins", :telephoneNumber => "416-277-4418", :mail => "bilbo at baggins.com"} end And then this spec: specify "should update and save the attributes for user" do @user.should_receive(:update_attributes).with(@params).and_return(true) post :update, :id => "jhughes", :user => @params end This fails like this: Mock 'user' expected :update_attributes with ([:telephoneNumber, "416-277-4418"], [:mail, "bilbo at baggins.com"], [:cn, "Bilbo Baggins"]) but received it with ({"cn"=>"Bilbo Baggins", "telephoneNumber"=>"416-277-4418", "mail"=>"bilbo at baggins.com"}) Puzzling, especially since inspecting the @params variable just before the should_receive shows the expected hash. What am I doing wrong? James From deepak.jois at gmail.com Thu Feb 15 01:25:06 2007 From: deepak.jois at gmail.com (Deepak Jois) Date: Thu, 15 Feb 2007 14:25:06 +0800 Subject: [rspec-users] Error against latest trunk while testing via spec for model In-Reply-To: <24dc07380702131637k3febb411v1ab07d8f39b0eb3b@mail.gmail.com> References: <24dc07380702122233n264be62bqe5d3dffb59536684@mail.gmail.com> <8d961d900702122320v780ce47av32586be83fae90ce@mail.gmail.com> <24dc07380702122328x3dbcd8b1g6018dbd8848048fc@mail.gmail.com> <8d961d900702130011q63f52ffbja0f69bd90bb937be@mail.gmail.com> <24dc07380702130023r2a033f07q5dc5a9d3b6efe8f1@mail.gmail.com> <8d961d900702130118w7eab765bwd9d1e2b867f80acc@mail.gmail.com> <57c63afe0702130323l6c6a3037u72b26c95dd99d154@mail.gmail.com> <57c63afe0702130337m3c0fe277re12a0ee05bfc3c63@mail.gmail.com> <24dc07380702131637k3febb411v1ab07d8f39b0eb3b@mail.gmail.com> Message-ID: <24dc07380702142225j133c4417jdf035023e0d0a077@mail.gmail.com> > The error seems to be related to loading the fixture because other > specs not related to specs pass as normal. > Ok I know the cause of the error now. It is because the fixtures path is not being passed correctly. turns out that my spec_helper file was outdated, here is a diff. Hope it helps Index: spec/spec_helper.rb =================================================================== --- spec/spec_helper.rb (revision 134) +++ spec/spec_helper.rb (working copy) @@ -1,6 +1,6 @@ # This file is copied to ~/spec when you run 'ruby script/generate rspec' # from the project root directory. -ENV["RAILS_ENV"] = "test" +ENV["RAILS_ENV"] ||= "test" require File.expand_path(File.dirname(__FILE__) + "/../config/environment") require 'spec/rails' @@ -10,15 +10,17 @@ # tightly coupled to Test::Unit in Rails, which is why you're seeing it here. module Spec module Rails - class EvalContext < Test::Unit::TestCase - self.use_transactional_fixtures = true - self.use_instantiated_fixtures = false - self.fixture_path = RAILS_ROOT + '/spec/fixtures' + module Runner + class EvalContext < Test::Unit::TestCase + self.use_transactional_fixtures = true + self.use_instantiated_fixtures = false + self.fixture_path = RAILS_ROOT + '/spec/fixtures' - # You can set up your global fixtures here, or you - # can do it in individual contexts using "fixtures :table_a, table_b". - # - #self.global_fixtures = :table_a, :table_b + # You can set up your global fixtures here, or you + # can do it in individual contexts using "fixtures :table_a, table_b". + # + #self.global_fixtures = :table_a, :table_b + end end end end From jerry.west at ntlworld.com Thu Feb 15 04:20:07 2007 From: jerry.west at ntlworld.com (Jerry West) Date: Thu, 15 Feb 2007 09:20:07 +0000 Subject: [rspec-users] Odd parameter munging with with() In-Reply-To: <765a2c230702141600j33b98be7w22dab72e5c2cbc10@mail.gmail.com> References: <765a2c230702141600j33b98be7w22dab72e5c2cbc10@mail.gmail.com> Message-ID: <45D425C7.3030807@ntlworld.com> An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070215/c12f8434/attachment.html From dchelimsky at gmail.com Thu Feb 15 10:09:15 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 15 Feb 2007 09:09:15 -0600 Subject: [rspec-users] Odd parameter munging with with() In-Reply-To: <45D425C7.3030807@ntlworld.com> References: <765a2c230702141600j33b98be7w22dab72e5c2cbc10@mail.gmail.com> <45D425C7.3030807@ntlworld.com> Message-ID: <57c63afe0702150709x3376b7a3y4797a2be11be1e9c@mail.gmail.com> On 2/15/07, Jerry West wrote: > > James, > > the gem is converting your hash to an array of arrays when it builds the > mock expectation. This is really an artifact of Ruby's hash/array handling > - the code in the gem looks perfectly reasonable, it just has this > side-effect. > > If you check out > $GEM_DIR/rspec-0.7.5.1/lib/spec/mocks/message_expectation.rb > you will see that #with() passes your hash to a new instance of > ArgumentExpectation, which is defined in > $GEM_DIR/rspec-0.7.5.1/lib/spec/mocks/argument_expectation.rb > . There you will see that a hash is a LiteralArgConstraint (as opposed to > :anything, :numeric, and the other parameters that #with() accepts). The > interesting code is around line 89 in #process_arg_constraints() where your > hash is converted one item at a time using the normal Ruby Enumerable > routine #collect(). Which is where the side-effect happens. > > Try this in irb: > > $ irb > irb(main):001:0> @params = {:cn => "Bilbo Baggins", :telephoneNumber => > "416-277-4418", :mail => "bilbo at baggins.com"} > > irb(main):002:0> @params.collect{|c| c} > => [[:cn, "Bilbo Baggins"], [:telephoneNumber, "416-277-4418"], [:mail, > "bilbo at baggins.com"]] > irb(main):003:0> > > and you will see that your hash has been converted into the array of > arrays. That's what happening in the gem once you strip away > #convert_constraint() etc. > > You have a choice of workarounds; the simplest of which is a separate array > @params_for_mock_user = @params.collect ; (null body returns each element as > above) and then > User.should_receive(:update_attributes).with(@params_for_mock_user). > > It might be worth filing an RFE on this as it's counter-intuitive and > likely to bite others as well Jerry - thanks for explaining this. James - an RFE would be great. Cheers, David > > Hope this helps. > > Rgds, > Jerry > > > > James Hughes wrote: > Hi, > > I have this setup block: > > setup do > session[:login] = 'jhughes' > @user = mock("user") > User.stub!(:find).and_return(@user) > @params = {:cn => "Bilbo Baggins", > :telephoneNumber => "416-277-4418", > :mail => "bilbo at baggins.com"} > end > > And then this spec: > > specify "should update and save the attributes for user" do > @user.should_receive(:update_attributes).with(@params).and_return(true) > post :update, :id => "jhughes", :user => @params > end > > This fails like this: > > Mock 'user' expected :update_attributes with ([:telephoneNumber, > "416-277-4418"], [:mail, "bilbo at baggins.com"], [:cn, "Bilbo Baggins"]) > but received it with ({"cn"=>"Bilbo Baggins", > "telephoneNumber"=>"416-277-4418", > "mail"=>"bilbo at baggins.com"}) > > Puzzling, especially since inspecting the @params variable just before > the should_receive shows the expected hash. > > What am I doing wrong? > > James > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From work at ashleymoran.me.uk Thu Feb 15 10:42:34 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Thu, 15 Feb 2007 15:42:34 +0000 Subject: [rspec-users] Specs for RJS HTML output NOT containing an element Message-ID: <31CCCBE7-A297-4903-A9BB-F5507DC19A54@ashleymoran.me.uk> Hi I have an RJS template that renders a partial to update a page. I just added a parameter to get passed into this partial to eliminate a row in the table it generates, but I can't find a way to test that the unwanted output is in fact missing. should(_not)_have_tag doesn't work with RJS, and there's no should_not_have from assert select. What I've just cobbled together is this addition to my spec_helper.rb: module Spec module Rails class AssertSelectWrapper def should_not_have(*opts) begin should_have(*opts) rescue Spec::Expectations::ExpectationNotMetError else fail_with("Expected no matching elements but at least one was detected.") end end end end end module ActionController class TestResponse def should_not_have(*opts) __assert_select_wrapper.should_not_have(*opts) end end end Is there already a way of doing this, or a better (shorter) way than above? Ashley From dchelimsky at gmail.com Thu Feb 15 10:56:48 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 15 Feb 2007 09:56:48 -0600 Subject: [rspec-users] Controller/View User Agent Strings In-Reply-To: <284E8837-1009-4959-808C-628FF30F498C@gmail.com> References: <24dc07380702122233n264be62bqe5d3dffb59536684@mail.gmail.com> <24dc07380702122328x3dbcd8b1g6018dbd8848048fc@mail.gmail.com> <8d961d900702130011q63f52ffbja0f69bd90bb937be@mail.gmail.com> <24dc07380702130023r2a033f07q5dc5a9d3b6efe8f1@mail.gmail.com> <8d961d900702130118w7eab765bwd9d1e2b867f80acc@mail.gmail.com> <57c63afe0702130323l6c6a3037u72b26c95dd99d154@mail.gmail.com> <57c63afe0702130337m3c0fe277re12a0ee05bfc3c63@mail.gmail.com> <51320D91-926F-4D8C-9679-385AF0F7504D@gmail.com> <57c63afe0702131640n60550fe8h4ee98835f8b8dd31@mail.gmail.com> <284E8837-1009-4959-808C-628FF30F498C@gmail.com> Message-ID: <57c63afe0702150756m3952cd29g17e1a0944c8eb46@mail.gmail.com> Given this in views/layouts/person.rhtml: <%= stylesheet_link_tag('ie', :media => 'screen') if request.user_agent && request.user_agent =~ /msie/i %> The following passes for me: ==================================== context "layout for person w/ user_agent = msie" do setup do request.stub!(:user_agent).and_return('msie') render 'layouts/person' end specify "should have msie stylesheet" do response.should have_tag("link[href*=ie.css]") end specify "should not have firefox stylesheet" do response.should_not have_tag("link[href*=firefox.css]") end end context "layout for person w/ user_agent = firefox" do setup do request.stub!(:user_agent).and_return('mozilla') render 'layouts/person' end specify "should have no link tag" do response.should_not have_tag("link") end end ==================================== Take a look at the assert_select cheat sheet for more info: http://labnotes.org/svn/public/ruby/rails_plugins/assert_select/cheat/assert_select.html have_tag just wraps that w/ rspec syntax. Let me know if this helps. Cheers, David On 2/13/07, s.ross wrote: > Just checking. I guess it just seemed too easy :) > > What happens when this page renders is a tag like: > > > > Or something like that with the Rails asset tagging. What I want to > do is test that I'm responding to the user agent string correctly > using a matcher that looks for the filename, but disregards the asset > tag: > > response.should have_tag('link', :attributes => {:href => / > application.css/}) > response.should_not have_tag('link', :attributes => {:href => /ie.css/}) > > However, the "should have" expectations always pass no matter what. > Not coincidentally, the "should_not have" ones always fail. > > I can see, looking at the Rails plugin source that my syntax is > broken and that the have_tag expectation was meant more to determine > whether the tag exists and how many times it occurs. Is there a > matcher that peers into the tag the way the old Test::Unit assertions > did? > > Thanks > > On Feb 13, 2007, at 4:40 PM, David Chelimsky wrote: > > > On 2/13/07, s.ross wrote: > >> I have conditional logic in my view (I know, obligatory slap on the > >> wrist) so that an add-on stylesheet is linked in for IE users. The > >> code is: > >> > >> <%= stylesheet_link_tag('ie', :media => 'screen') if > >> request.user_agent && request.user_agent =~ /msie/i %> > >> > >> The spec is: > >> > >> specify "should display index page" do > >> get :index > >> response.should_be_success > >> end > >> > >> There is no user_agent in the request object passed to the view. Now, > >> I can change all of this by simply: > >> > >> setup do > >> request.stub!(:user_agent).and_return('msie') > >> end > >> > >> but I was wondering if there was a better way? > > > > That seems pretty simple to me. What is bugging you about it? > > > >> > >> Thanks, > >> > >> Steve > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-users at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/rspec-users > >> > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Thu Feb 15 10:58:54 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 15 Feb 2007 09:58:54 -0600 Subject: [rspec-users] Controller/View User Agent Strings In-Reply-To: <57c63afe0702150756m3952cd29g17e1a0944c8eb46@mail.gmail.com> References: <24dc07380702122233n264be62bqe5d3dffb59536684@mail.gmail.com> <8d961d900702130011q63f52ffbja0f69bd90bb937be@mail.gmail.com> <24dc07380702130023r2a033f07q5dc5a9d3b6efe8f1@mail.gmail.com> <8d961d900702130118w7eab765bwd9d1e2b867f80acc@mail.gmail.com> <57c63afe0702130323l6c6a3037u72b26c95dd99d154@mail.gmail.com> <57c63afe0702130337m3c0fe277re12a0ee05bfc3c63@mail.gmail.com> <51320D91-926F-4D8C-9679-385AF0F7504D@gmail.com> <57c63afe0702131640n60550fe8h4ee98835f8b8dd31@mail.gmail.com> <284E8837-1009-4959-808C-628FF30F498C@gmail.com> <57c63afe0702150756m3952cd29g17e1a0944c8eb46@mail.gmail.com> Message-ID: <57c63afe0702150758v68301093pfc26e8ceb36b6136@mail.gmail.com> Wait - Steve - that was based on what's in the trunk. It *might* work w/ 0.7.5.1, but I haven't tried it. What version are you using? On 2/15/07, David Chelimsky wrote: > Given this in views/layouts/person.rhtml: > > <%= stylesheet_link_tag('ie', :media => 'screen') if > request.user_agent && request.user_agent =~ /msie/i %> > > The following passes for me: > > ==================================== > context "layout for person w/ user_agent = msie" do > setup do > request.stub!(:user_agent).and_return('msie') > render 'layouts/person' > end > > specify "should have msie stylesheet" do > response.should have_tag("link[href*=ie.css]") > end > > specify "should not have firefox stylesheet" do > response.should_not have_tag("link[href*=firefox.css]") > end > > end > > context "layout for person w/ user_agent = firefox" do > setup do > request.stub!(:user_agent).and_return('mozilla') > render 'layouts/person' > end > > specify "should have no link tag" do > response.should_not have_tag("link") > end > > end > ==================================== > > Take a look at the assert_select cheat sheet for more info: > > http://labnotes.org/svn/public/ruby/rails_plugins/assert_select/cheat/assert_select.html > > have_tag just wraps that w/ rspec syntax. > > Let me know if this helps. > > Cheers, > David > > On 2/13/07, s.ross wrote: > > Just checking. I guess it just seemed too easy :) > > > > What happens when this page renders is a tag like: > > > > > > > > Or something like that with the Rails asset tagging. What I want to > > do is test that I'm responding to the user agent string correctly > > using a matcher that looks for the filename, but disregards the asset > > tag: > > > > response.should have_tag('link', :attributes => {:href => / > > application.css/}) > > response.should_not have_tag('link', :attributes => {:href => /ie.css/}) > > > > However, the "should have" expectations always pass no matter what. > > Not coincidentally, the "should_not have" ones always fail. > > > > I can see, looking at the Rails plugin source that my syntax is > > broken and that the have_tag expectation was meant more to determine > > whether the tag exists and how many times it occurs. Is there a > > matcher that peers into the tag the way the old Test::Unit assertions > > did? > > > > Thanks > > > > On Feb 13, 2007, at 4:40 PM, David Chelimsky wrote: > > > > > On 2/13/07, s.ross wrote: > > >> I have conditional logic in my view (I know, obligatory slap on the > > >> wrist) so that an add-on stylesheet is linked in for IE users. The > > >> code is: > > >> > > >> <%= stylesheet_link_tag('ie', :media => 'screen') if > > >> request.user_agent && request.user_agent =~ /msie/i %> > > >> > > >> The spec is: > > >> > > >> specify "should display index page" do > > >> get :index > > >> response.should_be_success > > >> end > > >> > > >> There is no user_agent in the request object passed to the view. Now, > > >> I can change all of this by simply: > > >> > > >> setup do > > >> request.stub!(:user_agent).and_return('msie') > > >> end > > >> > > >> but I was wondering if there was a better way? > > > > > > That seems pretty simple to me. What is bugging you about it? > > > > > >> > > >> Thanks, > > >> > > >> Steve > > >> _______________________________________________ > > >> rspec-users mailing list > > >> rspec-users at rubyforge.org > > >> http://rubyforge.org/mailman/listinfo/rspec-users > > >> > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > From dchelimsky at gmail.com Thu Feb 15 11:01:01 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 15 Feb 2007 10:01:01 -0600 Subject: [rspec-users] Specs for RJS HTML output NOT containing an element In-Reply-To: <31CCCBE7-A297-4903-A9BB-F5507DC19A54@ashleymoran.me.uk> References: <31CCCBE7-A297-4903-A9BB-F5507DC19A54@ashleymoran.me.uk> Message-ID: <57c63afe0702150801q6152fae4m492ff6f5efba03a0@mail.gmail.com> On 2/15/07, Ashley Moran wrote: > Hi > > I have an RJS template that renders a partial to update a page. I > just added a parameter to get passed into this partial to eliminate a > row in the table it generates, but I can't find a way to test that > the unwanted output is in fact missing. should(_not)_have_tag > doesn't work with RJS, and there's no should_not_have from assert > select. > > What I've just cobbled together is this addition to my spec_helper.rb: > > module Spec > module Rails > class AssertSelectWrapper > def should_not_have(*opts) > begin > should_have(*opts) > rescue Spec::Expectations::ExpectationNotMetError > else > fail_with("Expected no matching elements but at least > one was detected.") > end > end > end > end > end > > module ActionController > class TestResponse > def should_not_have(*opts) > __assert_select_wrapper.should_not_have(*opts) > end > end > end > > Is there already a way of doing this, or a better (shorter) way than > above? If you're using trunk (if you're not, there is a release candidate coming in the next few days), you can do this: response.should_not have_tag(...) Cheers, David > > Ashley > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jerry.west at ntlworld.com Thu Feb 15 11:49:17 2007 From: jerry.west at ntlworld.com (Jerry West) Date: Thu, 15 Feb 2007 16:49:17 +0000 Subject: [rspec-users] defining context(s) dynamically Message-ID: <45D48F0D.4070306@ntlworld.com> An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070215/23b36d2b/attachment.html From dchelimsky at gmail.com Thu Feb 15 11:49:29 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 15 Feb 2007 10:49:29 -0600 Subject: [rspec-users] Specs for Ajax partials with unicode characters In-Reply-To: <1B7BC488-E5AA-41CA-9924-89A4DECC2636@ashleymoran.me.uk> References: <4E6DFE03-2915-4E6F-AEAD-F91056FE23A0@ashleymoran.me.uk> <57c63afe0702120713s1003d1cbm2ee7a6482ea05795@mail.gmail.com> <1B7BC488-E5AA-41CA-9924-89A4DECC2636@ashleymoran.me.uk> Message-ID: <57c63afe0702150849v330ed2ecw7ac2c0b2fac409b9@mail.gmail.com> On 2/12/07, Ashley Moran wrote: > > On 12 Feb 2007, at 15:13, David Chelimsky wrote: > > > Ashley - are both specs failing? Or just the one using > > "should_have_tag"? > > > David > > Both specs fail. The text mangling must happen before it reaches > RSpec, so that both assertions see the same encoded string. Yes - looks like json does that transformation. My feeling is that you should probably use '\u00a3500' and that's OK. The reality is that is what shows up in the response. WDYT? David > > Ashley > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From hughes.james at gmail.com Thu Feb 15 11:59:39 2007 From: hughes.james at gmail.com (James Hughes) Date: Thu, 15 Feb 2007 08:59:39 -0800 Subject: [rspec-users] Odd parameter munging with with() In-Reply-To: <57c63afe0702150709x3376b7a3y4797a2be11be1e9c@mail.gmail.com> References: <765a2c230702141600j33b98be7w22dab72e5c2cbc10@mail.gmail.com> <45D425C7.3030807@ntlworld.com> <57c63afe0702150709x3376b7a3y4797a2be11be1e9c@mail.gmail.com> Message-ID: <765a2c230702150859r7333dfceqdc83fcb70a9b45e2@mail.gmail.com> On 2/15/07, David Chelimsky wrote: > On 2/15/07, Jerry West wrote: > > > > James, > > > > the gem is converting your hash to an array of arrays when it builds the > > mock expectation. This is really an artifact of Ruby's hash/array handling > > - the code in the gem looks perfectly reasonable, it just has this > > side-effect. > > > > If you check out > > $GEM_DIR/rspec-0.7.5.1/lib/spec/mocks/message_expectation.rb > > you will see that #with() passes your hash to a new instance of > > ArgumentExpectation, which is defined in > > $GEM_DIR/rspec-0.7.5.1/lib/spec/mocks/argument_expectation.rb > > . There you will see that a hash is a LiteralArgConstraint (as opposed to > > :anything, :numeric, and the other parameters that #with() accepts). The > > interesting code is around line 89 in #process_arg_constraints() where your > > hash is converted one item at a time using the normal Ruby Enumerable > > routine #collect(). Which is where the side-effect happens. > > > > Try this in irb: > > > > $ irb > > irb(main):001:0> @params = {:cn => "Bilbo Baggins", :telephoneNumber => > > "416-277-4418", :mail => "bilbo at baggins.com"} > > > > irb(main):002:0> @params.collect{|c| c} > > => [[:cn, "Bilbo Baggins"], [:telephoneNumber, "416-277-4418"], [:mail, > > "bilbo at baggins.com"]] > > irb(main):003:0> > > > > and you will see that your hash has been converted into the array of > > arrays. That's what happening in the gem once you strip away > > #convert_constraint() etc. > > > > You have a choice of workarounds; the simplest of which is a separate array > > @params_for_mock_user = @params.collect ; (null body returns each element as > > above) and then > > User.should_receive(:update_attributes).with(@params_for_mock_user). > > > > It might be worth filing an RFE on this as it's counter-intuitive and > > likely to bite others as well > > Jerry - thanks for explaining this. > James - an RFE would be great. Ok, I'll take a crack at it after I've had a chance to assimilate Jerry's explanation. (Thanks, Jerry.) James From work at ashleymoran.me.uk Thu Feb 15 13:02:56 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Thu, 15 Feb 2007 18:02:56 +0000 Subject: [rspec-users] Specs for Ajax partials with unicode characters In-Reply-To: <57c63afe0702150849v330ed2ecw7ac2c0b2fac409b9@mail.gmail.com> References: <4E6DFE03-2915-4E6F-AEAD-F91056FE23A0@ashleymoran.me.uk> <57c63afe0702120713s1003d1cbm2ee7a6482ea05795@mail.gmail.com> <1B7BC488-E5AA-41CA-9924-89A4DECC2636@ashleymoran.me.uk> <57c63afe0702150849v330ed2ecw7ac2c0b2fac409b9@mail.gmail.com> Message-ID: <825110CC-6E9F-4567-B1B7-D191F98E7275@ashleymoran.me.uk> On 15 Feb 2007, at 16:49, David Chelimsky wrote: > Yes - looks like json does that transformation. My feeling is that you > should probably use '\u00a3500' and that's OK. The reality is that is > what shows up in the response. > > WDYT? Eventually I decided to do js_pound_sign = '\u00a3' and test for js_pound_sign + '500' This works for me. On the one hand, I agree that it makes sense to test the output that is actually rendered. On the other hand, it's counter-intuitive to have a partial containing "??czno??" (or so my Polish colleague tells me) and test for "\u0142\u0105czno\u015b \u0107". The Rails file activesupport/lib/json/encoders/core.rb only contains a JSON string ENcoder, but I assume the decoding is straightforward enough. What would be nice is something like context "my view" setup do render "moo/quack", :json_to_utf8 => true end ... specs all receive UTF8 strings ... end I don't know if it's worth the effort right now though, seeing as you probably can just put dummy text in for most stuff that would need UTF8 characters. Non-English speakers will probably disagree :) Ashley From dchelimsky at gmail.com Thu Feb 15 13:31:45 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 15 Feb 2007 12:31:45 -0600 Subject: [rspec-users] Specs for Ajax partials with unicode characters In-Reply-To: <825110CC-6E9F-4567-B1B7-D191F98E7275@ashleymoran.me.uk> References: <4E6DFE03-2915-4E6F-AEAD-F91056FE23A0@ashleymoran.me.uk> <57c63afe0702120713s1003d1cbm2ee7a6482ea05795@mail.gmail.com> <1B7BC488-E5AA-41CA-9924-89A4DECC2636@ashleymoran.me.uk> <57c63afe0702150849v330ed2ecw7ac2c0b2fac409b9@mail.gmail.com> <825110CC-6E9F-4567-B1B7-D191F98E7275@ashleymoran.me.uk> Message-ID: <57c63afe0702151031g13de0890uf4694437b86ce0e7@mail.gmail.com> On 2/15/07, Ashley Moran wrote: > > On 15 Feb 2007, at 16:49, David Chelimsky wrote: > > > Yes - looks like json does that transformation. My feeling is that you > > should probably use '\u00a3500' and that's OK. The reality is that is > > what shows up in the response. > > > > WDYT? > > > Eventually I decided to do > js_pound_sign = '\u00a3' > > and test for > js_pound_sign + '500' > > This works for me. On the one hand, I agree that it makes sense to > test the output that is actually rendered. On the other hand, it's > counter-intuitive to have a partial containing "??czno??" (or so > my Polish colleague tells me) and test for "\u0142\u0105czno\u015b > \u0107". > > The Rails file activesupport/lib/json/encoders/core.rb only contains > a JSON string ENcoder, but I assume the decoding is straightforward > enough. What would be nice is something like > > context "my view" > setup do > render "moo/quack", :json_to_utf8 => true > end > > ... specs all receive UTF8 strings ... > end My concern w/ this approach is that it adds a new potential point of failure. IF the decoder has a bug you'll get false pass/fail and it would be difficult to track down. This is something that's been bugging me about Rails in general lately. Why should it need custom testing tools? That smells funny to me. WDYT? > > I don't know if it's worth the effort right now though, seeing as you > probably can just put dummy text in for most stuff that would need > UTF8 characters. Non-English speakers will probably disagree :) > > Ashley > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Thu Feb 15 13:54:50 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 15 Feb 2007 12:54:50 -0600 Subject: [rspec-users] defining context(s) dynamically In-Reply-To: <45D48F0D.4070306@ntlworld.com> References: <45D48F0D.4070306@ntlworld.com> Message-ID: <57c63afe0702151054n2edd3d03j51b2eeb6a1b7bb0d@mail.gmail.com> On 2/15/07, Jerry West wrote: > > Q. Why does code which defines a context work in the controller_spec file > and not in a 'require'd helper file? > > A. Because spec uses the filename to tell it what type of context > (:controller, :model) it is creating. > > Fix: use the (undocumented?) second parameter to #context(), :context_type > => :controller. > > Quite how this works, I do not know; the rdocs don't mention it and > according to the source context doesn't take a second argument (except a > block). My Ruby-fu isn't up to explaining it; if anyone else would like to > do so that would be nice. > > Hope this helps someone else save a half hour or so. > > Rgds, > Jerry > > Further details: > > If I define a method which dynamically constructs a context in my > controller_spec.rb file it works fine: > > def restful_edit_specs(resource) > context "GET /#{resource}/:id;edit (:edit)" do > controller_name resource > > resource = resource.to_s > sym = resource.singularize > klass = resource.classify > > setup do > @mock = mock_model sym # based on > http://metaclass.org/2006/12/22/making-a-mockery-of-activerecord > @model = Object.const_get(klass) > @model.should_receive(:find).with(@mock.id).and_return(@mock) > end > > def do_get() get :edit, :id => @mock.id end > > specify "should be successful" do > do_get > response.should_be_success > end > specify "should render edit.rhtml" do > do_get > controller.should_render :edit > end > specify "should find the #{klass} requested" do > @model.should_receive(:find).and_return(@mock) > do_get > end > specify "should assign the found #{klass} for the view" do > do_get > assigns(sym).should_equal @mock > end > end > end > > restful_edit_specs(:assessments) > > This all works fine when defined in the xx_controller_spec.rb file. > > But if I move the exact same code to a helper file and require it, spec > gets confused: > > .../rspec-0.7.5.1/lib/spec/expectations/sugar.rb:13:in > `call': undefined method `controller_name' for > # > (NoMethodError) > ... etc etc... > > Clearly, there's some magic involved which means the context does not know > what it's about (it was at this point in typing my original plea for help > that I remembered seeing the :context_type parameter in the specs for the > rspec_on_rails plugin itself). > > Changing the context line to > > context "GET /#{resource}/:id;edit (:edit)", :context_type => > :controller do > > allows the specs to function as ex-spec-ted. This is one of those "convention over configuration" things. Spec::Rails goes out of its way to provide different contexts for different types of specs, each providing specific facilities that are relevant to that kind of spec (model/view/controller/helper). Put your specs in the right directories and you get the right kind of context. The undocumented-second-parameter was added, as you note, to support our own specs of the plugin. The likelihood is that it will remain, but it is undocumented and subject to change without notice, so you do absorb some risk in using it. What is the value you are looking for by bypassing the convention here? I'm asking because perhaps there is a missing feature we can tease out of this. Cheers, David > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From cwdinfo at gmail.com Thu Feb 15 19:12:58 2007 From: cwdinfo at gmail.com (s.ross) Date: Thu, 15 Feb 2007 16:12:58 -0800 Subject: [rspec-users] Controller/View User Agent Strings In-Reply-To: <57c63afe0702150758v68301093pfc26e8ceb36b6136@mail.gmail.com> References: <24dc07380702122233n264be62bqe5d3dffb59536684@mail.gmail.com> <8d961d900702130011q63f52ffbja0f69bd90bb937be@mail.gmail.com> <24dc07380702130023r2a033f07q5dc5a9d3b6efe8f1@mail.gmail.com> <8d961d900702130118w7eab765bwd9d1e2b867f80acc@mail.gmail.com> <57c63afe0702130323l6c6a3037u72b26c95dd99d154@mail.gmail.com> <57c63afe0702130337m3c0fe277re12a0ee05bfc3c63@mail.gmail.com> <51320D91-926F-4D8C-9679-385AF0F7504D@gmail.com> <57c63afe0702131640n60550fe8h4ee98835f8b8dd31@mail.gmail.com> <284E8837-1009-4959-808C-628FF30F498C@gmail.com> <57c63afe0702150756m3952cd29g17e1a0944c8eb46@mail.gmail.com> <57c63afe0702150758v68301093pfc26e8ceb36b6136@mail.gmail.com> Message-ID: Thanks for the reply. I'm about 4 days off trunk, so depending on what you checked in when, I'm pretty current. I'll mess around with this more. Thanks for the code and the link. Steve On Feb 15, 2007, at 7:58 AM, David Chelimsky wrote: > Wait - Steve - that was based on what's in the trunk. It *might* work > w/ 0.7.5.1, but I haven't tried it. > > What version are you using? > > On 2/15/07, David Chelimsky wrote: >> Given this in views/layouts/person.rhtml: >> >> <%= stylesheet_link_tag('ie', :media => 'screen') if >> request.user_agent && request.user_agent =~ /msie/i %> >> >> The following passes for me: >> >> ==================================== >> context "layout for person w/ user_agent = msie" do >> setup do >> request.stub!(:user_agent).and_return('msie') >> render 'layouts/person' >> end >> >> specify "should have msie stylesheet" do >> response.should have_tag("link[href*=ie.css]") >> end >> >> specify "should not have firefox stylesheet" do >> response.should_not have_tag("link[href*=firefox.css]") >> end >> >> end >> >> context "layout for person w/ user_agent = firefox" do >> setup do >> request.stub!(:user_agent).and_return('mozilla') >> render 'layouts/person' >> end >> >> specify "should have no link tag" do >> response.should_not have_tag("link") >> end >> >> end >> ==================================== >> >> Take a look at the assert_select cheat sheet for more info: >> >> http://labnotes.org/svn/public/ruby/rails_plugins/assert_select/ >> cheat/assert_select.html >> >> have_tag just wraps that w/ rspec syntax. >> >> Let me know if this helps. >> >> Cheers, >> David >> >> On 2/13/07, s.ross wrote: >>> Just checking. I guess it just seemed too easy :) >>> >>> What happens when this page renders is a tag like: >>> >>> >>> >>> Or something like that with the Rails asset tagging. What I want to >>> do is test that I'm responding to the user agent string correctly >>> using a matcher that looks for the filename, but disregards the >>> asset >>> tag: >>> >>> response.should have_tag('link', :attributes => {:href => / >>> application.css/}) >>> response.should_not have_tag('link', :attributes => {:href => / >>> ie.css/}) >>> >>> However, the "should have" expectations always pass no matter what. >>> Not coincidentally, the "should_not have" ones always fail. >>> >>> I can see, looking at the Rails plugin source that my syntax is >>> broken and that the have_tag expectation was meant more to determine >>> whether the tag exists and how many times it occurs. Is there a >>> matcher that peers into the tag the way the old Test::Unit >>> assertions >>> did? >>> >>> Thanks >>> >>> On Feb 13, 2007, at 4:40 PM, David Chelimsky wrote: >>> >>>> On 2/13/07, s.ross wrote: >>>>> I have conditional logic in my view (I know, obligatory slap on >>>>> the >>>>> wrist) so that an add-on stylesheet is linked in for IE users. The >>>>> code is: >>>>> >>>>> <%= stylesheet_link_tag('ie', :media => 'screen') if >>>>> request.user_agent && request.user_agent =~ /msie/i %> >>>>> >>>>> The spec is: >>>>> >>>>> specify "should display index page" do >>>>> get :index >>>>> response.should_be_success >>>>> end >>>>> >>>>> There is no user_agent in the request object passed to the >>>>> view. Now, >>>>> I can change all of this by simply: >>>>> >>>>> setup do >>>>> request.stub!(:user_agent).and_return('msie') >>>>> end >>>>> >>>>> but I was wondering if there was a better way? >>>> >>>> That seems pretty simple to me. What is bugging you about it? >>>> >>>>> >>>>> Thanks, >>>>> >>>>> Steve >>>>> _______________________________________________ >>>>> rspec-users mailing list >>>>> rspec-users at rubyforge.org >>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>> >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-users at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From jerry.west at ntlworld.com Fri Feb 16 04:24:21 2007 From: jerry.west at ntlworld.com (Jerry West) Date: Fri, 16 Feb 2007 09:24:21 +0000 Subject: [rspec-users] defining context(s) dynamically In-Reply-To: <57c63afe0702151054n2edd3d03j51b2eeb6a1b7bb0d@mail.gmail.com> References: <45D48F0D.4070306@ntlworld.com> <57c63afe0702151054n2edd3d03j51b2eeb6a1b7bb0d@mail.gmail.com> Message-ID: <45D57845.7070804@ntlworld.com> An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070216/50f0b39f/attachment.html From work at ashleymoran.me.uk Fri Feb 16 05:30:57 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Fri, 16 Feb 2007 10:30:57 +0000 Subject: [rspec-users] Specs for Ajax partials with unicode characters In-Reply-To: <57c63afe0702151031g13de0890uf4694437b86ce0e7@mail.gmail.com> References: <4E6DFE03-2915-4E6F-AEAD-F91056FE23A0@ashleymoran.me.uk> <57c63afe0702120713s1003d1cbm2ee7a6482ea05795@mail.gmail.com> <1B7BC488-E5AA-41CA-9924-89A4DECC2636@ashleymoran.me.uk> <57c63afe0702150849v330ed2ecw7ac2c0b2fac409b9@mail.gmail.com> <825110CC-6E9F-4567-B1B7-D191F98E7275@ashleymoran.me.uk> <57c63afe0702151031g13de0890uf4694437b86ce0e7@mail.gmail.com> Message-ID: On Feb 15, 2007, at 6:31 pm, David Chelimsky wrote: > My concern w/ this approach is that it adds a new potential point of > failure. IF the decoder has a bug you'll get false pass/fail and it > would be difficult to track down. > That's a good point I hadn't considered. It seems risky to add a layer of code between the output of Rails and the tests. Unfortunately I don't know *any* JavaScript - haven't written a line of it in my life. So I can't say why the Rails team escapes UTF8. All the other content in my Rails apps gets served as UTF8, so I don't see why JavaScript should be any different. Maybe it's a browser workaround. I might ask on the Rails list. > This is something that's been bugging me about Rails in general > lately. Why should it need custom testing tools? That smells funny to > me. > > WDYT? > Not sure I'm in a position to comment. Like I say, maybe in this case there's a reason for the bizarre text munging. However, I agree with what you said a while back about ActiveRecord impeding mocking (I can't say about the other components as I haven't seen the source). I've had a look at the Og code recently, and it seems to have much better separation of concerns. (Having said that, I saw a blog post by the main developer saying he thought it was getting crufty.) Much as I like ActiveRecord, the code is incredibly tightly bound. I did some work at the end of last year to add class-table inheritance to ActiveRecord. I had to hack pretty much all of the Base class code, and it can be really tough to follow the flow through all the methods it contains. Testing changes it tough too because it's all pretty monolithic. I got to the point with CTI where it was working but without associations. I realised that adding support to the patch for associations would end up with me duplicating virtually all of the unit tests. They are frustrating to work on because the fixtures have become quite brittle. I was about to suggest to the core team that I rewrite all the unit tests in RSpec, which would give an opportunity to audit the tests, probably clean them up a bit, and also give me the opportunity to slot in CTI without turning the unit tests into an unmaintainable copy-and-paste frenzy. (Kinda depends on them wanting CTI though.) I actually tried to port one of the basic tests, but I couldn't manage to integrate RSpec into the Test::Unit stuff. There might be some opportunities to refactor ActiveRecord a bit, see if the code can't be made more isolated and testable. When I get 30 continuous seconds free I'll put all this to the core team. Unfortunately I don't have a staggering amount of free time to work on it. Ashley From dchelimsky at gmail.com Fri Feb 16 08:51:20 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 16 Feb 2007 07:51:20 -0600 Subject: [rspec-users] defining context(s) dynamically In-Reply-To: <45D57845.7070804@ntlworld.com> References: <45D48F0D.4070306@ntlworld.com> <57c63afe0702151054n2edd3d03j51b2eeb6a1b7bb0d@mail.gmail.com> <45D57845.7070804@ntlworld.com> Message-ID: <57c63afe0702160551r48244fc3hed697afc50b147df@mail.gmail.com> On 2/16/07, Jerry West wrote: > > What is the value you are looking for by bypassing the convention > here? I'm asking because perhaps there is a missing feature we can > tease out of this. > > I was trying to refactor out some shared (restful controller) specs, more > as an experiment than anything else. > > I really do like to be DRY so any essentially identical code (e.g. that > generated by rspec_resource) is a candidate to be refactored into a > parameter-ised function. Actions like edit and destroy seem hardly to > differ between controllers. However, actions like new will tend to set > defaults and create usually does some sanity checking, so I'm not sure how > successful this refactoring would be in the long run. Luke Redpath has some thoughts on this as well: http://www.lukeredpath.co.uk/2007/2/2/refactoring-rest-searching-for-an-abstraction Please do keep us posted on your own experimentation. As Spec::Rails becomes less volatile, I'd like to see plugins emerge that work in conjunction with it (as opposed to beefing up Spec::Rails itself). Perhaps you could be among the first to contribute such to the community. > Refactored code would be in a helper file of course. I put the helper > file into my standard 'extensions' library plugin which is easy to share > between rails apps. It appears that spec uses the full directory path to > identify the context - so even re-naming the helper file as > 'lib/helper_controller_spec.rb' is not enough. If I put that same file in > the spec/controllers directory then the :context argument is not necessary. > I could live with that if it ever disappeared. As it turns out, I see that I actually DID document it in the Spec::Rails::Runner::ContextFactory (in trunk), so I had already considered making it official (sorry for not remembering that - there is a lot going on right now and that aspect was low on my radar). So I guess you can go ahead and count on it. Cheers, David > > Bottom line: No big deal; if it goes it goes, if it stays it's very > occasionally helpful. My vote would be keep it unless it becomes awkward to > maintain - extra flexibility can be very useful and if there's no > opportunity cost there's no reason to bin it. > > Best wishes, > Jerry > > > > David Chelimsky wrote: > On 2/15/07, Jerry West wrote: > > > Q. Why does code which defines a context work in the controller_spec file > and not in a 'require'd helper file? > > A. Because spec uses the filename to tell it what type of context > (:controller, :model) it is creating. > > Fix: use the (undocumented?) second parameter to #context(), :context_type > => :controller. > > Quite how this works, I do not know; the rdocs don't mention it and > according to the source context doesn't take a second argument (except a > block). My Ruby-fu isn't up to explaining it; if anyone else would like to > do so that would be nice. > > Hope this helps someone else save a half hour or so. > > Rgds, > Jerry > > Further details: > > If I define a method which dynamically constructs a context in my > controller_spec.rb file it works fine: > > def restful_edit_specs(resource) > context "GET /#{resource}/:id;edit (:edit)" do > controller_name resource > > resource = resource.to_s > sym = resource.singularize > klass = resource.classify > > setup do > @mock = mock_model sym # based on > http://metaclass.org/2006/12/22/making-a-mockery-of-activerecord > @model = Object.const_get(klass) > @model.should_receive(:find).with(@mock.id).and_return(@mock) > end > > def do_get() get :edit, :id => @mock.id end > > specify "should be successful" do > do_get > response.should_be_success > end > specify "should render edit.rhtml" do > do_get > controller.should_render :edit > end > specify "should find the #{klass} requested" do > @model.should_receive(:find).and_return(@mock) > do_get > end > specify "should assign the found #{klass} for the view" do > do_get > assigns(sym).should_equal @mock > end > end > end > > restful_edit_specs(:assessments) > > This all works fine when defined in the xx_controller_spec.rb file. > > But if I move the exact same code to a helper file and require it, spec > gets confused: > > .../rspec-0.7.5.1/lib/spec/expectations/sugar.rb:13:in > `call': undefined method `controller_name' for > # > (NoMethodError) > ... etc etc... > > Clearly, there's some magic involved which means the context does not know > what it's about (it was at this point in typing my original plea for help > that I remembered seeing the :context_type parameter in the specs for the > rspec_on_rails plugin itself). > > Changing the context line to > > context "GET /#{resource}/:id;edit (:edit)", :context_type => > :controller do > > allows the specs to function as ex-spec-ted. > > This is one of those "convention over configuration" things. > Spec::Rails goes out of its way to provide different contexts for > different types of specs, each providing specific facilities that are > relevant to that kind of spec (model/view/controller/helper). Put your > specs in the right directories and you get the right kind of context. > > The undocumented-second-parameter was added, as you note, to support > our own specs of the plugin. The likelihood is that it will remain, > but it is undocumented and subject to change without notice, so you do > absorb some risk in using it. > > What is the value you are looking for by bypassing the convention > here? I'm asking because perhaps there is a missing feature we can > tease out of this. > > Cheers, > David > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From bhelmkamp at gmail.com Fri Feb 16 11:40:38 2007 From: bhelmkamp at gmail.com (Bryan Helmkamp) Date: Fri, 16 Feb 2007 11:40:38 -0500 Subject: [rspec-users] defining context(s) dynamically In-Reply-To: <57c63afe0702151054n2edd3d03j51b2eeb6a1b7bb0d@mail.gmail.com> References: <45D48F0D.4070306@ntlworld.com> <57c63afe0702151054n2edd3d03j51b2eeb6a1b7bb0d@mail.gmail.com> Message-ID: On 2/15/07, David Chelimsky wrote: > What is the value you are looking for by bypassing the convention > here? I'm asking because perhaps there is a missing feature we can > tease out of this. David, I make use of the :context_type feature to allow me to maintain separate model unit specs and integration specs. What we term "integration specs" are specs that test a cluster of models (often with a fair amount of necessary DB access), not customer-level acceptance tests (as in the Rails terminology). We found that in order to make those specs run correctly in database transactions, we had to add :context_type => :model to their context declaration. Anyway, looks like :context_type is on it's way to being fully documented, but I figured I'd let you know why we find it useful in case it might uncover a missing feature. -Bryan From yrashk at gmail.com Fri Feb 16 14:06:09 2007 From: yrashk at gmail.com (Yurii Rashkovskii) Date: Fri, 16 Feb 2007 21:06:09 +0200 Subject: [rspec-users] [ANN] rspec-ext 0.0.1 Message-ID: Hello, I've just released rspec-ext 0.0.1 (http://rubyforge.org/projects/ rspec-ext/) It is gem-installable (rspec-ext gem) It is simply two _experimental_ (and may be not well tested) extensions of rspec as for now: * specify_negatively (http://rashkovskii.com/articles/2007/1/25/rspec- specify_negatively, http://rashkovskii.com/articles/2007/2/3/ specify_negatively-updated) * aspects (http://rashkovskii.com/articles/2007/2/13/rspec-aspects) As I've said above, all this stuff is pretty much experimental, though I use it in some real projects now. I plan to work on these and other ideas to make at least my own spec- ing even more better. Thank you for your attention, Yurii. From court3nay at gmail.com Fri Feb 16 18:20:21 2007 From: court3nay at gmail.com (Courtenay) Date: Fri, 16 Feb 2007 15:20:21 -0800 Subject: [rspec-users] some fun functionality for all your specs Message-ID: <4b430c8f0702161520k11fca94ah43e116ee8ad0b61e@mail.gmail.com> I've found these two snippets of code useful and would love some feedback. first, .should_have_valid_associations usage: context "A new Product" do specify "should have valid associations" do @product.should_have_valid_associations end end code: (thanks to Wilson/Defiler for converting to rspec) module Spec module Expectations module Should class Base def have_valid_associations @target.save_without_validation @target.class.reflect_on_all_associations.each do |assoc| lambda { @target.send(assoc.name, true) }.should_not_raise end self end end end end end second, I had a problem where I'd renamed some fields in the model and didn't want to manually spec out each method, but also didn't want to go the 'null object' route. assigns[:cart] = @cart = mock("cart") @cart.stub!(:attr_name).and_return('cart') @cart.stub!(:to_param).and_return('99') @cart.stub!(:class).and_return(Cart) Cart.content_columns.each { |c| @cart.stub!(c.name.to_sym) } Cart.reflect_on_all_associations.each do |assoc| @cart.stub!(assoc.name.to_sym).and_return([]) end @cart.stub!(:name).and_return('cart') As you can see it rapidly spirals out of control, but this snippet sets up all the associations and field names as stubs. Comments? From dchelimsky at gmail.com Fri Feb 16 19:08:24 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 16 Feb 2007 18:08:24 -0600 Subject: [rspec-users] some fun functionality for all your specs In-Reply-To: <4b430c8f0702161520k11fca94ah43e116ee8ad0b61e@mail.gmail.com> References: <4b430c8f0702161520k11fca94ah43e116ee8ad0b61e@mail.gmail.com> Message-ID: <57c63afe0702161608l181ec8ccna5fb8b8dd850569f@mail.gmail.com> On 2/16/07, Courtenay wrote: > I've found these two snippets of code useful and would love some feedback. > > first, .should_have_valid_associations > usage: > > context "A new Product" do > specify "should have valid associations" do > @product.should_have_valid_associations > end > end > > code: (thanks to Wilson/Defiler for converting to rspec) > > module Spec > module Expectations > module Should > class Base > def have_valid_associations > @target.save_without_validation > @target.class.reflect_on_all_associations.each do |assoc| > lambda { @target.send(assoc.name, true) }.should_not_raise > end > self > end > end > end > end > end A couple of things. First, VERY COOL. Second, here's how you can do it in 0.8 and later (coming soon): module ActiveRecordExpectations def have_valid_associations return Class.new do def matches?(model) @model = model @model.save_without_validation @invalid_associations = [] @target.class.reflect_on_all_associations.each do |assoc| begin @target.send(assoc.name, true) rescue @invalid_associations << assoc end end @invalid_associations.empty? end def failure_message "expected all valid associations, but the following were not valid: #{@invalid_associations.inspect}" end end end.new end context "A new Product" do include ActiveRecordExpectations specify "should have valid associations" do @product.should have_valid_associations end end The nice thing here is that you can give it better failure messages. Also, the expectation is not monkey patched onto Object. WDYT? > > > second, I had a problem where I'd renamed some fields in the model and > didn't want to manually spec out each method, but also didn't want to > go the 'null object' route. assigns[:cart] = @cart = mock("cart") > > @cart.stub!(:attr_name).and_return('cart') > @cart.stub!(:to_param).and_return('99') > @cart.stub!(:class).and_return(Cart) > > Cart.content_columns.each { |c| > @cart.stub!(c.name.to_sym) > } > Cart.reflect_on_all_associations.each do |assoc| > @cart.stub!(assoc.name.to_sym).and_return([]) > end > @cart.stub!(:name).and_return('cart') > > As you can see it rapidly spirals out of control, but this snippet > sets up all the associations and field names as stubs. > Cool. We just added a mock_model method that does some similar stuff but on an instance of Mock (not an instance of a Model). This would be a good addition, wrapped in a method named stub_model: stub_model(Person) Would you consider submitting a patch w/ this method added to Spec::Rails::Runner::EvalContext? David > Comments? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From bhelmkamp at gmail.com Sat Feb 17 04:48:56 2007 From: bhelmkamp at gmail.com (Bryan Helmkamp) Date: Sat, 17 Feb 2007 04:48:56 -0500 Subject: [rspec-users] RSpec usage Message-ID: Hey all, Trying to get feel for RSpec usage so I'm taking a straw poll... What's the largest project you've used RSpec on in terms of app LOC app and spec LOC? Also, how long have you been using RSpec in "production" code? -Bryan From jonathan.tron.mailings at gmail.com Sat Feb 17 10:52:44 2007 From: jonathan.tron.mailings at gmail.com (Jonathan Tron) Date: Sat, 17 Feb 2007 16:52:44 +0100 Subject: [rspec-users] RSpec usage In-Reply-To: References: Message-ID: <196C592E-2E79-477A-9AAA-CECD753270D6@gmail.com> Le 17 f?vr. 07 ? 10:48, Bryan Helmkamp a ?crit : > Trying to get feel for RSpec usage so I'm taking a straw poll... Here we go... > What's the largest project you've used RSpec on in terms of app LOC > app and spec LOC? Also, how long have you been using RSpec in > "production" code? Actually I used RSpec in one unreleased project (deadline 23 March...), here's my rails stats : +----------------------+-------+-------+---------+---------+----- +-------+ | Name | Lines | LOC | Classes | Methods | M/C | LOC/M | +----------------------+-------+-------+---------+---------+----- +-------+ | Controllers | 1487 | 1059 | 21 | 132 | 6 | 6 | | Helpers | 43 | 42 | 0 | 0 | 0 | 0 | | Models | 1168 | 489 | 23 | 42 | 1 | 9 | | Libraries | 233 | 145 | 3 | 30 | 10 | 2 | | Components | 0 | 0 | 0 | 0 | 0 | 0 | | Model specs | 1697 | 1366 | 2 | 25 | 12 | 52 | | View specs | 1581 | 1161 | 0 | 0 | 0 | 0 | | Controller specs | 5998 | 4741 | 0 | 168 | 0 | 26 | | Helper specs | 1581 | 1161 | 0 | 0 | 0 | 0 | +----------------------+-------+-------+---------+---------+----- +-------+ | Total | 13788 | 10164 | 49 | 397 | 8 | 23 | +----------------------+-------+-------+---------+---------+----- +-------+ Code LOC: 1735 Test LOC: 8429 Code to Test Ratio: 1:4.9 My code to test ratio is a bit high, but I'm really a newbie at both RSpec AND (T/B)DD in general, so I assumed the more I'll be used to it the more I can refactor my specs to use less LOC, my RCov code coverage is around 98% (another one which is probably to high). FYI, I'm using RSpec/RSpecOnRails trunk and RoR 1.2 Stable branch, RSpec and RSpecOnRails are both installed as plugin (this only require minors changes in rake tasks and some plugins like RSpec::Autotest to use the command in vendor/plugin/rspec/bin/spec if present and not the RubyGems one). Jonathan -- Tron Jonathan http://jonathan.tron.name From dchelimsky at gmail.com Sat Feb 17 12:10:46 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 17 Feb 2007 11:10:46 -0600 Subject: [rspec-users] [ANN] RSpec 0.8.0-RC1 Message-ID: <57c63afe0702170910j76331701ka66f9d1de73fc26c@mail.gmail.com> The RSpec Development Team is pleased to announce Release Candidate 1 of RSpec 0.8.0. Since we're doing a Release Candidate and we don't really have a separate gem server set up, everything you need is tagged in subversion. See the install instructions below. As we noted a few weeks back, this release comprises a new approach to RSpec's expectation syntax using Expectation Matchers, as well as dozens of new features and bug fixes. The new and old syntax are living side by side for the moment, and will do so until we release 0.9, at which point the old syntax will no longer be supported. In subsequent 0.8.x releases, we'll provide both deprecation warnings and a translator tool that will help you to convert your old specs to the new format well in advance of the 0.9 release. Please note that this is a Release Candidate, which means it is subject to changes before the official release. We do hope, however, that many of you will install this release so we can get a lot of feedback and get to the official release quickly. For those who do, please prefix any RFEs with "[0.8.0-RC1]" so we can easily separate them out from the rest. Many thanks to all who are using RSpec, whether just experimenting or really using it on your business critical projects! Cheers, The RSpec Development Team ============================== Installing the gem svn co svn://rubyforge.org/var/svn/rspec/tags/REL_0_8_0_RC1/gem gem install gem/rspec-0.8.0-RC1.gem ============================== Get the docs svn co svn://rubyforge.org/var/svn/rspec/tags/REL_0_8_0_RC1/doc/output doc open doc/index.html NOTE that most of the stuff in the website docs is deprecated. What you want to look at is the RDoc for both RSpec and Spec::Rails. ============================== Installing Spec::Rails (the rails plugin) script/plugin install svn://rubyforge.org/var/svn/rspec/tags/REL_0_8_0_RC1/rspec_on_rails/vendor/plugins/rspec_on_rails ============================== From court3nay at gmail.com Sat Feb 17 14:54:58 2007 From: court3nay at gmail.com (Courtenay) Date: Sat, 17 Feb 2007 11:54:58 -0800 Subject: [rspec-users] RSpec usage In-Reply-To: <196C592E-2E79-477A-9AAA-CECD753270D6@gmail.com> References: <196C592E-2E79-477A-9AAA-CECD753270D6@gmail.com> Message-ID: <4b430c8f0702171154r4254c422qa86eb9d911a6f283@mail.gmail.com> On 2/17/07, Jonathan Tron wrote: > Le 17 f?vr. 07 ? 10:48, Bryan Helmkamp a ?crit : > > > Trying to get feel for RSpec usage so I'm taking a straw poll... 3 months. All apps are in production. I was lucky enough to have some good rspec-ers (rspectacles?) set up my projects. Code LOC: 1845 Test LOC: 3710 Code to Test Ratio: 1:2.0 Code LOC: 1294 Test LOC: 1073 Code to Test Ratio: 1:0.8 Code LOC: 634 Test LOC: 1136 Code to Test Ratio: 1:1.8 Code LOC: 2789 Test LOC: 3130 Code to Test Ratio: 1:1.1 court3 From dchelimsky at gmail.com Sat Feb 17 15:27:38 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 17 Feb 2007 14:27:38 -0600 Subject: [rspec-users] RSpec usage In-Reply-To: References: Message-ID: <57c63afe0702171227w7f94510bo941a453d6a127a6b@mail.gmail.com> On 2/17/07, Bryan Helmkamp wrote: > Hey all, > > Trying to get feel for RSpec usage so I'm taking a straw poll... > > What's the largest project you've used RSpec on in terms of app LOC > app and spec LOC? Also, how long have you been using RSpec in > "production" code? I'd like to add to this question. Based on experience doing apps using test/unit and rspec, what benefits do you perceive of each approach during initial development and during subsequent maintenance? Thanks, David > > -Bryan > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From justnothing at tiscali.co.uk Sat Feb 17 16:45:22 2007 From: justnothing at tiscali.co.uk (David Green) Date: Sat, 17 Feb 2007 13:45:22 -0800 (PST) Subject: [rspec-users] "warning: object#id will be deprecated" with mocks Message-ID: <9024353.post@talk.nabble.com> hi all I have the following code in a spec: @user = mock("user") User.stub!(:authenticate).and_return(@user) @user.should_receive(:id).once.and_return(99) post :login, {:username => 'username', :password => 'password'} session[:user_id].should == 99 it works as expected but I get the following warning when I run the spec: warning: object#id will be deprecated; use Object#object_id instead I'm new to testing with mocks, am I using them correctly and does anyone know how to disable the warning? thanks -- View this message in context: http://www.nabble.com/%22warning%3A-object-id-will-be-deprecated%22-with-mocks-tf3246300.html#a9024353 Sent from the rspec-users mailing list archive at Nabble.com. From graeme.nelson at gmail.com Sat Feb 17 17:27:04 2007 From: graeme.nelson at gmail.com (Graeme Nelson) Date: Sat, 17 Feb 2007 14:27:04 -0800 Subject: [rspec-users] some fun functionality for all your specs In-Reply-To: <57c63afe0702161608l181ec8ccna5fb8b8dd850569f@mail.gmail.com> References: <4b430c8f0702161520k11fca94ah43e116ee8ad0b61e@mail.gmail.com> <57c63afe0702161608l181ec8ccna5fb8b8dd850569f@mail.gmail.com> Message-ID: Hi. I am not sure what the have_valid_associations is really testing. If I have a model, like so: class Address < ActiveRecord::Base belongs_to :order end and my spec looks like: context "A new address" do setup do @address = Address.new end specify "should have valid associations" do @address.should_have_valid_associations end end I have this false of security that should_have_valid_associations is testing my associations. However, if I or some other developer comes along and removes the :order association by accident, the spec will still pass. I think the following reads a little better, plus it will fail if someone comes along and accidently removes the order association: context "A new address" do setup do @address = Address.new end specify "should have order association" do Address.reflect_on_association(:order).should_not_be_nil end end Just my 2 cents. Thanks, Graeme Nelson On Feb 16, 2007, at 4:08 PM, David Chelimsky wrote: > On 2/16/07, Courtenay wrote: >> I've found these two snippets of code useful and would love some >> feedback. >> >> first, .should_have_valid_associations >> usage: >> >> context "A new Product" do >> specify "should have valid associations" do >> @product.should_have_valid_associations >> end >> end >> >> code: (thanks to Wilson/Defiler for converting to rspec) >> >> module Spec >> module Expectations >> module Should >> class Base >> def have_valid_associations >> @target.save_without_validation >> @target.class.reflect_on_all_associations.each do |assoc| >> lambda { @target.send(assoc.name, >> true) }.should_not_raise >> end >> self >> end >> end >> end >> end >> end > > A couple of things. First, VERY COOL. Second, here's how you can do it > in 0.8 and later (coming soon): > > module ActiveRecordExpectations > def have_valid_associations > return Class.new do > def matches?(model) > @model = model > @model.save_without_validation > @invalid_associations = [] > @target.class.reflect_on_all_associations.each do |assoc| > begin > @target.send(assoc.name, true) > rescue > @invalid_associations << assoc > end > end > @invalid_associations.empty? > end > > def failure_message > "expected all valid associations, but the following were not > valid: #{@invalid_associations.inspect}" > end > end > end.new > end > > context "A new Product" do > include ActiveRecordExpectations > specify "should have valid associations" do > @product.should have_valid_associations > end > end > > The nice thing here is that you can give it better failure messages. > Also, the expectation is not monkey patched onto Object. > > WDYT? > >> >> >> second, I had a problem where I'd renamed some fields in the model >> and >> didn't want to manually spec out each method, but also didn't want to >> go the 'null object' route. assigns[:cart] = @cart = mock("cart") >> >> @cart.stub!(:attr_name).and_return('cart') >> @cart.stub!(:to_param).and_return('99') >> @cart.stub!(:class).and_return(Cart) >> >> Cart.content_columns.each { |c| >> @cart.stub!(c.name.to_sym) >> } >> Cart.reflect_on_all_associations.each do |assoc| >> @cart.stub!(assoc.name.to_sym).and_return([]) >> end >> @cart.stub!(:name).and_return('cart') >> >> As you can see it rapidly spirals out of control, but this snippet >> sets up all the associations and field names as stubs. >> > > Cool. We just added a mock_model method that does some similar stuff > but on an instance of Mock (not an instance of a Model). This would be > a good addition, wrapped in a method named stub_model: > > stub_model(Person) > > Would you consider submitting a patch w/ this method added to > Spec::Rails::Runner::EvalContext? > > David > >> Comments? >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From aslak.hellesoy at gmail.com Sat Feb 17 21:40:40 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Sun, 18 Feb 2007 03:40:40 +0100 Subject: [rspec-users] "warning: object#id will be deprecated" with mocks In-Reply-To: <9024353.post@talk.nabble.com> References: <9024353.post@talk.nabble.com> Message-ID: <8d961d900702171840o7652f79ey5ed62ffbfd14a0e6@mail.gmail.com> On 2/17/07, David Green wrote: > > hi all > > I have the following code in a spec: > > @user = mock("user") > User.stub!(:authenticate).and_return(@user) > @user.should_receive(:id).once.and_return(99) > post :login, {:username => 'username', :password => 'password'} > session[:user_id].should == 99 > > it works as expected but I get the following warning when I run the spec: > warning: object#id will be deprecated; use Object#object_id instead > > I'm new to testing with mocks, am I using them correctly and does anyone > know how to disable the warning? > I'm assuming you are using RSpec with Rails (as opposed to a non-Rails codebase). Try the latest RSpec on Rails release's mock_model method - it stubs out default ActiveRecord methods like #id, #to_param in order to make stubbing/mocking easier with ActiveRecord. Aslak > thanks > -- > View this message in context: http://www.nabble.com/%22warning%3A-object-id-will-be-deprecated%22-with-mocks-tf3246300.html#a9024353 > Sent from the rspec-users mailing list archive at Nabble.com. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From court3nay at gmail.com Sun Feb 18 00:41:55 2007 From: court3nay at gmail.com (Courtenay) Date: Sat, 17 Feb 2007 21:41:55 -0800 Subject: [rspec-users] some fun functionality for all your specs In-Reply-To: References: <4b430c8f0702161520k11fca94ah43e116ee8ad0b61e@mail.gmail.com> <57c63afe0702161608l181ec8ccna5fb8b8dd850569f@mail.gmail.com> Message-ID: <4b430c8f0702172141i67a1d0a7x8935c490ee173a1f@mail.gmail.com> On 2/17/07, Graeme Nelson wrote: > Hi. > > I am not sure what the have_valid_associations is really testing. If > I have a model, like so: > > class Address < ActiveRecord::Base > belongs_to :order > end > try this class Address < ActiveRecord::Base belongs_to :fooxl end make sure there's no Fooxl model. the 'valid associations' there means that your association actually would work, were you to call it. It's surprising how many associations don't get tested at the model level. From court3nay at gmail.com Sun Feb 18 00:52:07 2007 From: court3nay at gmail.com (Courtenay) Date: Sat, 17 Feb 2007 21:52:07 -0800 Subject: [rspec-users] some fun functionality for all your specs In-Reply-To: <4b430c8f0702172141i67a1d0a7x8935c490ee173a1f@mail.gmail.com> References: <4b430c8f0702161520k11fca94ah43e116ee8ad0b61e@mail.gmail.com> <57c63afe0702161608l181ec8ccna5fb8b8dd850569f@mail.gmail.com> <4b430c8f0702172141i67a1d0a7x8935c490ee173a1f@mail.gmail.com> Message-ID: <4b430c8f0702172152u40916d6ehcba8d44e08c01ad7@mail.gmail.com> On 2/17/07, Courtenay wrote: > On 2/17/07, Graeme Nelson wrote: > > Hi. > > > > I am not sure what the have_valid_associations is really testing. If > > I have a model, like so: > > > > class Address < ActiveRecord::Base > > belongs_to :order > > end > > > > try this > > class Address < ActiveRecord::Base > belongs_to :fooxl > end > > make sure there's no Fooxl model. > > the 'valid associations' there means that your association actually > would work, were you to call it. It's surprising how many > associations don't get tested at the model level. > you could also try belongs_to :order, :foreign_key => 'monkey_id' and it'll fail the spec. From justnothing at tiscali.co.uk Sun Feb 18 08:12:15 2007 From: justnothing at tiscali.co.uk (David Green) Date: Sun, 18 Feb 2007 05:12:15 -0800 (PST) Subject: [rspec-users] [0.8.0-RC1] problem with drbspec Message-ID: <9029451.post@talk.nabble.com> I'm getting the following error with version 0.8.0 (I updated the gem and the rails plugin, and re-ran generate/rspec): c:\wd\clarks>drbspec spec/models/user_spec.rb c:/ruby/bin/drbspec:16:in `load': no such file to load -- drbspec (LoadError) from c:/ruby/bin/drbspec:16 the same command works fine under 0.7.5.1. Windows XP, rails 1.2.2 and rubygems 0.9.1 -- View this message in context: http://www.nabble.com/-0.8.0-RC1--problem-with-drbspec-tf3248194.html#a9029451 Sent from the rspec-users mailing list archive at Nabble.com. From aslak.hellesoy at gmail.com Sun Feb 18 08:21:13 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Sun, 18 Feb 2007 14:21:13 +0100 Subject: [rspec-users] [0.8.0-RC1] problem with drbspec In-Reply-To: <9029451.post@talk.nabble.com> References: <9029451.post@talk.nabble.com> Message-ID: <8d961d900702180521n46041c67y62446505e0e27e8a@mail.gmail.com> >From the 0.8 CHANGELOG: * The drbspec command is gone. Use spec --drb instead. Aslak On 2/18/07, David Green wrote: > > I'm getting the following error with version 0.8.0 (I updated the gem and the > rails plugin, and re-ran generate/rspec): > > c:\wd\clarks>drbspec spec/models/user_spec.rb > c:/ruby/bin/drbspec:16:in `load': no such file to load -- drbspec > (LoadError) > from c:/ruby/bin/drbspec:16 > > the same command works fine under 0.7.5.1. Windows XP, rails 1.2.2 and > rubygems 0.9.1 > -- > View this message in context: http://www.nabble.com/-0.8.0-RC1--problem-with-drbspec-tf3248194.html#a9029451 > Sent from the rspec-users mailing list archive at Nabble.com. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Sun Feb 18 08:22:14 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 18 Feb 2007 07:22:14 -0600 Subject: [rspec-users] [0.8.0-RC1] problem with drbspec In-Reply-To: <9029451.post@talk.nabble.com> References: <9029451.post@talk.nabble.com> Message-ID: <57c63afe0702180522y2667ff6ct7f0b328300114724@mail.gmail.com> drbspec is replaced w/ a command line option for the spec command: spec spec/models/user_spec.rb --drb This is documented in two places (that you may not know about) - in the website docs (the ones you have to download for 0.8 - see Tools > Spec Runner) and also in the spec command itself: $ spec No files specified. Usage: spec [options] (FILE|DIRECTORY|GLOB)+ ... Cheers, David On 2/18/07, David Green wrote: > > I'm getting the following error with version 0.8.0 (I updated the gem and the > rails plugin, and re-ran generate/rspec): > > c:\wd\clarks>drbspec spec/models/user_spec.rb > c:/ruby/bin/drbspec:16:in `load': no such file to load -- drbspec > (LoadError) > from c:/ruby/bin/drbspec:16 > > the same command works fine under 0.7.5.1. Windows XP, rails 1.2.2 and > rubygems 0.9.1 > -- > View this message in context: http://www.nabble.com/-0.8.0-RC1--problem-with-drbspec-tf3248194.html#a9029451 > Sent from the rspec-users mailing list archive at Nabble.com. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From justnothing at tiscali.co.uk Sun Feb 18 08:58:25 2007 From: justnothing at tiscali.co.uk (David Green) Date: Sun, 18 Feb 2007 05:58:25 -0800 (PST) Subject: [rspec-users] [0.8.0-RC1] problem with drbspec In-Reply-To: <8d961d900702180521n46041c67y62446505e0e27e8a@mail.gmail.com> References: <9029451.post@talk.nabble.com> <8d961d900702180521n46041c67y62446505e0e27e8a@mail.gmail.com> Message-ID: <9029761.post@talk.nabble.com> >From the 0.8 CHANGELOG: * The drbspec command is gone. Use spec --drb instead. Aslak thanks both! -- View this message in context: http://www.nabble.com/-0.8.0-RC1--problem-with-drbspec-tf3248194.html#a9029761 Sent from the rspec-users mailing list archive at Nabble.com. From graeme.nelson at gmail.com Sun Feb 18 10:27:02 2007 From: graeme.nelson at gmail.com (Graeme Nelson) Date: Sun, 18 Feb 2007 07:27:02 -0800 Subject: [rspec-users] some fun functionality for all your specs In-Reply-To: <4b430c8f0702172152u40916d6ehcba8d44e08c01ad7@mail.gmail.com> References: <4b430c8f0702161520k11fca94ah43e116ee8ad0b61e@mail.gmail.com> <57c63afe0702161608l181ec8ccna5fb8b8dd850569f@mail.gmail.com> <4b430c8f0702172141i67a1d0a7x8935c490ee173a1f@mail.gmail.com> <4b430c8f0702172152u40916d6ehcba8d44e08c01ad7@mail.gmail.com> Message-ID: <52E8972B-74BF-4C5C-B87D-B866DEDF9647@gmail.com> Thanks for the clarification, Courtenay. I didn't realize that you were testing to see if :order actually exists. I would still want to know if someone removed the 'belongs_to :orders', so I might still include Address.reflect_on_association :orders. Thanks Graeme Nelson On Feb 17, 2007, at 9:52 PM, Courtenay wrote: > On 2/17/07, Courtenay wrote: >> On 2/17/07, Graeme Nelson wrote: >>> Hi. >>> >>> I am not sure what the have_valid_associations is really >>> testing. If >>> I have a model, like so: >>> >>> class Address < ActiveRecord::Base >>> belongs_to :order >>> end >>> >> >> try this >> >> class Address < ActiveRecord::Base >> belongs_to :fooxl >> end >> >> make sure there's no Fooxl model. >> >> the 'valid associations' there means that your association actually >> would work, were you to call it. It's surprising how many >> associations don't get tested at the model level. >> > > you could also try > > belongs_to :order, :foreign_key => 'monkey_id' > > and it'll fail the spec. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From justnothing at tiscali.co.uk Sun Feb 18 14:38:30 2007 From: justnothing at tiscali.co.uk (David Green) Date: Sun, 18 Feb 2007 11:38:30 -0800 (PST) Subject: [rspec-users] get() method in custom expectation matcher? Message-ID: <9032900.post@talk.nabble.com> I'm trying to write a custom expectation: controller.should_require_login_for(:action_name). I'm using the example in the docs for 'Custom Expectation Matchers' but I'm unsure how to make the get() method available to my ShouldRequireLogin class. I've tried requiring spec_helper but no joy. can anyone help? thanks -- View this message in context: http://www.nabble.com/get%28%29-method-in-custom-expectation-matcher--tf3249458.html#a9032900 Sent from the rspec-users mailing list archive at Nabble.com. From justnothing at tiscali.co.uk Sun Feb 18 14:51:51 2007 From: justnothing at tiscali.co.uk (David Green) Date: Sun, 18 Feb 2007 11:51:51 -0800 (PST) Subject: [rspec-users] get() method in custom expectation matcher? In-Reply-To: <9032900.post@talk.nabble.com> References: <9032900.post@talk.nabble.com> Message-ID: <9033065.post@talk.nabble.com> David Green wrote: > > I'm trying to write a custom expectation: > controller.should_require_login_for(:action_name). > I'm using the example in the docs for 'Custom Expectation Matchers' but > I'm unsure how to make the get() method available to my ShouldRequireLogin > class. I've tried requiring spec_helper but no joy. > > can anyone help? > thanks > sorry, I should have said I'm using 0.8.0 with the rails plugin -- View this message in context: http://www.nabble.com/get%28%29-method-in-custom-expectation-matcher--tf3249458.html#a9033065 Sent from the rspec-users mailing list archive at Nabble.com. From work at ashleymoran.me.uk Mon Feb 19 06:23:54 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Mon, 19 Feb 2007 11:23:54 +0000 Subject: [rspec-users] RSpec usage In-Reply-To: <57c63afe0702171227w7f94510bo941a453d6a127a6b@mail.gmail.com> References: <57c63afe0702171227w7f94510bo941a453d6a127a6b@mail.gmail.com> Message-ID: <4950EDEA-9FAA-4183-A67E-9975CA7DBAA2@ashleymoran.me.uk> On 17 Feb 2007, at 20:27, David Chelimsky wrote: > I'd like to add to this question. > > Based on experience doing apps using test/unit and rspec, what > benefits do you perceive of each approach during initial development > and during subsequent maintenance? > > Thanks, > David Can't really say about maintenance because we've only got one app finished and it hasn't needed going back to. (Well, we've got two finished, but I wasn't involved on the first one and there are no unit tests.) As for initial development: - you can focus on implementing specific features, rather than trying to remember what other bits of code might be affected by any given change (which I find very tiring, as I'm a cautious programmer by nature, rather than a change-it-and-see type) - you can code at a more consistent rate because you're working on discrete pieces of functionality, so breakages tend to be localised and easily identifiable (it's probably not the most flattering way to describe it, but I told my boss that programming with rspec was like digging a hole - put shovel in ground, throw soil over shoulder, repeat) - I'm only working with one other person on our current project, but when I read his code I get a good idea what he was thinking by looking at the specs - it's far less stressful - I get this wierd feeling of creativity writing the specs first, like I want the code to do *this* and *this* and why not *this* too. It feels like half the battle is over just by figuring out what I want the code to look like. There is one downside, which is that on the rare occasions my office is quiet enough to do any useful work (generally around the time hell places an order for hats and scarves, the moon changes a nice shade of #0000ff, and local porcine aviation increases noticeably), it's possible to code so fast I'm exhausted by the end of the day. Fortunately, the phone stops this happening too often. And on the other hand, it beats chasing a typo around for most the afternoon slowly losing the will to live. Ashley From work at ashleymoran.me.uk Mon Feb 19 08:57:05 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Mon, 19 Feb 2007 13:57:05 +0000 Subject: [rspec-users] some fun functionality for all your specs In-Reply-To: <4b430c8f0702172141i67a1d0a7x8935c490ee173a1f@mail.gmail.com> References: <4b430c8f0702161520k11fca94ah43e116ee8ad0b61e@mail.gmail.com> <57c63afe0702161608l181ec8ccna5fb8b8dd850569f@mail.gmail.com> <4b430c8f0702172141i67a1d0a7x8935c490ee173a1f@mail.gmail.com> Message-ID: <2B091973-62B9-4417-B2C8-A97B798DF9E4@ashleymoran.me.uk> On 18 Feb 2007, at 05:41, Courtenay wrote: > the 'valid associations' there means that your association actually > would work, were you to call it. It's surprising how many > associations don't get tested at the model level. We've been pretty good at this on our current project. I think our test:code ratio would pretty much half if we could test associations in one line :( From hughes.james at gmail.com Mon Feb 19 16:32:45 2007 From: hughes.james at gmail.com (James Hughes) Date: Mon, 19 Feb 2007 13:32:45 -0800 Subject: [rspec-users] Odd parameter munging with with() In-Reply-To: <45D425C7.3030807@ntlworld.com> References: <765a2c230702141600j33b98be7w22dab72e5c2cbc10@mail.gmail.com> <45D425C7.3030807@ntlworld.com> Message-ID: <765a2c230702191332h2e254ebek5a52db625548ebe@mail.gmail.com> Hi again, On 2/15/07, Jerry West wrote: > > James, > > the gem is converting your hash to an array of arrays when it builds the > mock expectation. This is really an artifact of Ruby's hash/array handling > - the code in the gem looks perfectly reasonable, it just has this > side-effect. > > If you check out > $GEM_DIR/rspec-0.7.5.1/lib/spec/mocks/message_expectation.rb > you will see that #with() passes your hash to a new instance of > ArgumentExpectation, which is defined in > $GEM_DIR/rspec-0.7.5.1/lib/spec/mocks/argument_expectation.rb > . There you will see that a hash is a LiteralArgConstraint (as opposed to > :anything, :numeric, and the other parameters that #with() accepts). The > interesting code is around line 89 in #process_arg_constraints() where your > hash is converted one item at a time using the normal Ruby Enumerable > routine #collect(). Which is where the side-effect happens. > > Try this in irb: > > $ irb > irb(main):001:0> @params = {:cn => "Bilbo Baggins", :telephoneNumber => > "416-277-4418", :mail => "bilbo at baggins.com"} > > irb(main):002:0> @params.collect{|c| c} > => [[:cn, "Bilbo Baggins"], [:telephoneNumber, "416-277-4418"], [:mail, > "bilbo at baggins.com"]] > irb(main):003:0> > > and you will see that your hash has been converted into the array of > arrays. That's what happening in the gem once you strip away > #convert_constraint() etc. > > You have a choice of workarounds; the simplest of which is a separate array > @params_for_mock_user = @params.collect ; (null body returns each element as > above) and then > User.should_receive(:update_attributes).with(@params_for_mock_user). Ok, this works (once I figured out that you have to send the @params_for_mock_user with the post as well, duh;), but I have another method that does this: user_klass = params[:user].delete(:ou).capitalize.constantize @user = user_klass.create(params[:user]) When the spec runs I'm calling delete on an array instead of the expected hash, which returns nil. Jerry, you mentioned a choice of workarounds: anything come to mind that might work around this? > > It might be worth filing an RFE on this as it's counter-intuitive and > likely to bite others as well > I'm writing this up right now.. James > James Hughes wrote: > > Hi, > > I have this setup block: > > setup do > session[:login] = 'jhughes' > @user = mock("user") > User.stub!(:find).and_return(@user) > @params = {:cn => "Bilbo Baggins", > :telephoneNumber => "416-277-4418", > :mail => "bilbo at baggins.com"} > end > > And then this spec: > > specify "should update and save the attributes for user" do > @user.should_receive(:update_attributes).with(@params).and_return(true) > post :update, :id => "jhughes", :user => @params > end > > This fails like this: > > Mock 'user' expected :update_attributes with ([:telephoneNumber, > "416-277-4418"], [:mail, "bilbo at baggins.com"], [:cn, "Bilbo Baggins"]) > but received it with ({"cn"=>"Bilbo Baggins", > "telephoneNumber"=>"416-277-4418", > "mail"=>"bilbo at baggins.com"}) > > Puzzling, especially since inspecting the @params variable just before > the should_receive shows the expected hash. > > What am I doing wrong? > > James > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From hughes.james at gmail.com Mon Feb 19 19:13:47 2007 From: hughes.james at gmail.com (James Hughes) Date: Mon, 19 Feb 2007 16:13:47 -0800 Subject: [rspec-users] Odd parameter munging with with() In-Reply-To: <45D425C7.3030807@ntlworld.com> References: <765a2c230702141600j33b98be7w22dab72e5c2cbc10@mail.gmail.com> <45D425C7.3030807@ntlworld.com> Message-ID: <765a2c230702191613j7de77519jf4afb7cc559bf9f7@mail.gmail.com> On 2/15/07, Jerry West wrote: > > It might be worth filing an RFE on this as it's counter-intuitive and > likely to bite others as well Hello again, In trying to create some simple code that would reproduce this without all the rails dependencies for an RFE, I came up with this: class Test def Test.amethod params true end end context "passing a hash to #with" do specify "should pass a hash to #with" do @params = { :param1 => "foo", :param2 => "bar"} Test.should_receive(:amethod).with(@params).and_return(true) Test.amethod @params end end I thought this was conceptually the same as my failing spec from the original post, but obviously it's not, as it passes. Can anyone explain what the difference is? thanks, James > James Hughes wrote: > > Hi, > > I have this setup block: > > setup do > session[:login] = 'jhughes' > @user = mock("user") > User.stub!(:find).and_return(@user) > @params = {:cn => "Bilbo Baggins", > :telephoneNumber => "416-277-4418", > :mail => "bilbo at baggins.com"} > end > > And then this spec: > > specify "should update and save the attributes for user" do > @user.should_receive(:update_attributes).with(@params).and_return(true) > post :update, :id => "jhughes", :user => @params > end > > This fails like this: > > Mock 'user' expected :update_attributes with ([:telephoneNumber, > "416-277-4418"], [:mail, "bilbo at baggins.com"], [:cn, "Bilbo Baggins"]) > but received it with ({"cn"=>"Bilbo Baggins", > "telephoneNumber"=>"416-277-4418", > "mail"=>"bilbo at baggins.com"}) > > Puzzling, especially since inspecting the @params variable just before > the should_receive shows the expected hash. > > What am I doing wrong? > > James From dchelimsky at gmail.com Mon Feb 19 19:58:59 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 19 Feb 2007 18:58:59 -0600 Subject: [rspec-users] Odd parameter munging with with() In-Reply-To: <765a2c230702191613j7de77519jf4afb7cc559bf9f7@mail.gmail.com> References: <765a2c230702141600j33b98be7w22dab72e5c2cbc10@mail.gmail.com> <45D425C7.3030807@ntlworld.com> <765a2c230702191613j7de77519jf4afb7cc559bf9f7@mail.gmail.com> Message-ID: <57c63afe0702191658p15535fc9se76361819e2a3b2d@mail.gmail.com> On 2/19/07, James Hughes wrote: > On 2/15/07, Jerry West wrote: > > > > It might be worth filing an RFE on this as it's counter-intuitive and > > likely to bite others as well > > Hello again, > > In trying to create some simple code that would reproduce this without > all the rails dependencies for an RFE, I came up with this: > > class Test > def Test.amethod params > true > end > end > context "passing a hash to #with" do > specify "should pass a hash to #with" do > @params = { :param1 => "foo", > :param2 => "bar"} > Test.should_receive(:amethod).with(@params).and_return(true) > Test.amethod @params > end > end > > I thought this was conceptually the same as my failing spec from the > original post, but obviously it's not, as it passes. Can anyone > explain what the difference is? The difference that I see is that the new example passes @params directly to Test.amethod, whereas the earlier example uses "post :update". So I'm guessing that the problem is related specifically to how "post :update" packages up the arguments to pass to the model. WDYT? > > thanks, > James > > > James Hughes wrote: > > > > Hi, > > > > I have this setup block: > > > > setup do > > session[:login] = 'jhughes' > > @user = mock("user") > > User.stub!(:find).and_return(@user) > > @params = {:cn => "Bilbo Baggins", > > :telephoneNumber => "416-277-4418", > > :mail => "bilbo at baggins.com"} > > end > > > > And then this spec: > > > > specify "should update and save the attributes for user" do > > @user.should_receive(:update_attributes).with(@params).and_return(true) > > post :update, :id => "jhughes", :user => @params > > end > > > > This fails like this: > > > > Mock 'user' expected :update_attributes with ([:telephoneNumber, > > "416-277-4418"], [:mail, "bilbo at baggins.com"], [:cn, "Bilbo Baggins"]) > > but received it with ({"cn"=>"Bilbo Baggins", > > "telephoneNumber"=>"416-277-4418", > > "mail"=>"bilbo at baggins.com"}) > > > > Puzzling, especially since inspecting the @params variable just before > > the should_receive shows the expected hash. > > > > What am I doing wrong? > > > > James > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From hughes.james at gmail.com Mon Feb 19 23:14:45 2007 From: hughes.james at gmail.com (James Hughes) Date: Mon, 19 Feb 2007 20:14:45 -0800 Subject: [rspec-users] Odd parameter munging with with() In-Reply-To: <57c63afe0702191658p15535fc9se76361819e2a3b2d@mail.gmail.com> References: <765a2c230702141600j33b98be7w22dab72e5c2cbc10@mail.gmail.com> <45D425C7.3030807@ntlworld.com> <765a2c230702191613j7de77519jf4afb7cc559bf9f7@mail.gmail.com> <57c63afe0702191658p15535fc9se76361819e2a3b2d@mail.gmail.com> Message-ID: <765a2c230702192014j7a365acfg3563a61301413815@mail.gmail.com> On 2/19/07, David Chelimsky wrote: > On 2/19/07, James Hughes wrote: > > On 2/15/07, Jerry West wrote: > > > > > > It might be worth filing an RFE on this as it's counter-intuitive and > > > likely to bite others as well > > > > Hello again, > > > > In trying to create some simple code that would reproduce this without > > all the rails dependencies for an RFE, I came up with this: > > > > class Test > > def Test.amethod params > > true > > end > > end > > context "passing a hash to #with" do > > specify "should pass a hash to #with" do > > @params = { :param1 => "foo", > > :param2 => "bar"} > > Test.should_receive(:amethod).with(@params).and_return(true) > > Test.amethod @params > > end > > end > > > > I thought this was conceptually the same as my failing spec from the > > original post, but obviously it's not, as it passes. Can anyone > > explain what the difference is? > > The difference that I see is that the new example passes @params > directly to Test.amethod, whereas the earlier example uses "post > :update". So I'm guessing that the problem is related specifically to > how "post :update" packages up the arguments to pass to the model. > > WDYT? If the failure message is to be believed, it's #with that is packaging up the arguments in an odd way. Take a look at the failure message again: > > > Mock 'user' expected :update_attributes with ([:telephoneNumber, > > > "416-277-4418"], [:mail, "bilbo at baggins.com"], [:cn, "Bilbo Baggins"]) > > > but received it with ({"cn"=>"Bilbo Baggins", > > > "telephoneNumber"=>"416-277-4418", > > > "mail"=>"bilbo at baggins.com"}) See what I mean? (I just checked, and post was doing one modification to @params: it was changing the keys from symbols to strings. However, changing the @params keys to strings in the spec still produces the same error as above, so that's not the problem.) For final proof, here's the output from a couple of print statements, one in the spec just before post(), and one in the controller action, just before calling update_attributes: ............in spec {"cn"=>"Bilbo Baggins", "telephoneNumber"=>"416-277-4418", "mail"=>"bilbo at baggins.com"} in controller {"cn"=>"Bilbo Baggins", "telephoneNumber"=>"416-277-4418", "mail"=>"bilbo at baggins.com"} So, I still say my app code and my reduction look conceptually the same, but I'm stumped as to why they don't behave the same way (not to mention I don't understand the need for #with to mangle it's args as it does). James From dchelimsky at gmail.com Tue Feb 20 06:03:02 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 20 Feb 2007 05:03:02 -0600 Subject: [rspec-users] Odd parameter munging with with() In-Reply-To: <765a2c230702192014j7a365acfg3563a61301413815@mail.gmail.com> References: <765a2c230702141600j33b98be7w22dab72e5c2cbc10@mail.gmail.com> <45D425C7.3030807@ntlworld.com> <765a2c230702191613j7de77519jf4afb7cc559bf9f7@mail.gmail.com> <57c63afe0702191658p15535fc9se76361819e2a3b2d@mail.gmail.com> <765a2c230702192014j7a365acfg3563a61301413815@mail.gmail.com> Message-ID: <57c63afe0702200303w5ea6c9a3od0d7cf86edeb1b6@mail.gmail.com> On 2/19/07, James Hughes wrote: > On 2/19/07, David Chelimsky wrote: > > On 2/19/07, James Hughes wrote: > > > On 2/15/07, Jerry West wrote: > > > > > > > > It might be worth filing an RFE on this as it's counter-intuitive and > > > > likely to bite others as well > > > > > > Hello again, > > > > > > In trying to create some simple code that would reproduce this without > > > all the rails dependencies for an RFE, I came up with this: > > > > > > class Test > > > def Test.amethod params > > > true > > > end > > > end > > > context "passing a hash to #with" do > > > specify "should pass a hash to #with" do > > > @params = { :param1 => "foo", > > > :param2 => "bar"} > > > Test.should_receive(:amethod).with(@params).and_return(true) > > > Test.amethod @params > > > end > > > end > > > > > > I thought this was conceptually the same as my failing spec from the > > > original post, but obviously it's not, as it passes. Can anyone > > > explain what the difference is? > > > > The difference that I see is that the new example passes @params > > directly to Test.amethod, whereas the earlier example uses "post > > :update". So I'm guessing that the problem is related specifically to > > how "post :update" packages up the arguments to pass to the model. > > > > WDYT? > > If the failure message is to be believed, it's #with that is packaging > up the arguments in an odd way. > Take a look at the failure message again: > > > > > Mock 'user' expected :update_attributes with ([:telephoneNumber, > > > > "416-277-4418"], [:mail, "bilbo at baggins.com"], [:cn, "Bilbo Baggins"]) > > > > but received it with ({"cn"=>"Bilbo Baggins", > > > > "telephoneNumber"=>"416-277-4418", > > > > "mail"=>"bilbo at baggins.com"}) > > See what I mean? (I just checked, and post was doing one modification > to @params: it was changing the keys from symbols to strings. However, > changing the @params keys to strings in the spec still produces the > same error as above, so that's not the problem.) For final proof, > here's the output from a couple of print statements, one in the spec > just before post(), and one in the controller action, just before > calling update_attributes: > > ............in spec > {"cn"=>"Bilbo Baggins", "telephoneNumber"=>"416-277-4418", > "mail"=>"bilbo at baggins.com"} > in controller > {"cn"=>"Bilbo Baggins", "telephoneNumber"=>"416-277-4418", > "mail"=>"bilbo at baggins.com"} > > So, I still say my app code and my reduction look conceptually the > same, but I'm stumped as to why they don't behave the same way (not to > mention I don't understand the need for #with to mangle it's args as > it does). RSpec is doing the comparison correctly. The Rails version is comparing a Hash with stringified keys w/ a Hash w/ symbols as keys, whereas the other version is comparing the exact same Hash (w/ symbol keys) with itself. The bug is really in the message. I'm fixing the message so it'll correctly show you the expected Hash, but IMO RSpec shouldn't be messing around w/ keys. WDYT? David > > James > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jerry.west at ntlworld.com Tue Feb 20 06:22:34 2007 From: jerry.west at ntlworld.com (Jerry West) Date: Tue, 20 Feb 2007 11:22:34 +0000 Subject: [rspec-users] Odd parameter munging with with() In-Reply-To: <765a2c230702192014j7a365acfg3563a61301413815@mail.gmail.com> References: <765a2c230702141600j33b98be7w22dab72e5c2cbc10@mail.gmail.com> <45D425C7.3030807@ntlworld.com> <765a2c230702191613j7de77519jf4afb7cc559bf9f7@mail.gmail.com> <57c63afe0702191658p15535fc9se76361819e2a3b2d@mail.gmail.com> <765a2c230702192014j7a365acfg3563a61301413815@mail.gmail.com> Message-ID: <45DAD9FA.50406@ntlworld.com> An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070220/6b546471/attachment.html From work at ashleymoran.me.uk Tue Feb 20 07:07:14 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Tue, 20 Feb 2007 12:07:14 +0000 Subject: [rspec-users] How to spec code with multiple (interacting) paths Message-ID: Hi Code with a large number of different paths is probably the biggest problem I have right now. I've made a sample class that illustrates the simplest case of one parameter that takes two values: class DataStorer def initialize(logger, emailer, db_updater, do_update_db_step) @logger = logger; @emailer = emailer; @db_updater = db_updater @do_update_db_step = do_update_db_step end def store(data) @logger.log("I was told to store '#{data}'") @emailer.send_email("Somebody stored '#{data}'") @db_updater.update_db("SET data = '#{data}' WHERE id = 1") if @do_update_db_step end end I need to specify the behaviour of my DataStorer objects when they told to/not to update the database. Here's a full spec for the case when we do want to update the database: context "A DataStorer where 'do_update_db_step' is true" do setup do @logger = mock("logger"); @logger.stub!(:log) @emailer = mock("emailer"); @emailer.stub!(:send_email) @db_updater = mock("db_updater"); @db_updater.stub! (:update_db) @data_storer = DataStorer.new(@logger, @emailer, @db_updater, true) end specify "should log the data given when asked to store" do @logger.should_receive(:log).with("I was told to store 'moo'") @data_storer.store("moo") end specify "should email the data given when asked to store" do @emailer.should_receive(:send_email).with("Somebody stored 'moo'") @data_storer.store("moo") end specify "should store the data given to the DB when asked to store" do @db_updater.should_receive(:update_db).with("SET data = 'moo' WHERE id = 1") @data_storer.store("moo") end end Now the problem is we don't know what it should do when we tell it to NOT update the database. Here are things I've done in the past. First, a separate spec for the differences in behaviour. # Solution 1 - separate spec for differences context "S1 A DataStorer where 'do_update_db_step' is false" do setup do @logger = mock("logger"); @logger.stub!(:log) @emailer = mock("emailer"); @emailer.stub!(:send_email) @db_updater = mock("db_updater"); @db_updater.stub! (:update_db) @data_storer = DataStorer.new(@logger, @emailer, @db_updater, false) end specify "should NOT store the data given to the DB when asked to store" do @db_updater.should_not_receive(:update_db) @data_storer.store("moo") end end I have a bad feeling about this. If I change the emailer line in the store method to this: @emailer.send_email("Somebody stored '#{data}'") if @do_update_db_step The behaviour has changed and the specs still pass. This seems bad. Next try, duplicate the entire spec and change the relevant bits: # Solution 2 - copy, paste, update context "A DataStorer where 'do_update_db_step' is false" do setup do # ... end specify "should log the data given when asked to store" do # ... end specify "should email the data given when asked to store" do # ... end specify "should NOT store the data given to the DB when asked to store" do # ... end end Great for a boolean, not so hot when 6 different things can change - you end up with 7 times the code of the single spec. Probably a very bad idea with two parameters that can each take significant 10 values. This violates DRY. I don't know if that's a priority in specs or not. I'm sure code coverage is more important, but it quickly gets out of hand. Next attempt - generate the specs in a loop. I've done this before, and the exact structure of the contexts and specs depend on exactly what the parameters do. Some times I've been tempted to do this, but the difference in specs are significant enough, and the number of variants small enough, that copy-paste-update seems better. # Solution 3 - dynamic contexts and specs [true, false].each do |do_update_db_step| context "A DataStorer where 'do_update_db_step' is # {do_update_db_step}" do setup do @logger = mock("logger"); @logger.stub!(:log) @emailer = mock("emailer"); @emailer.stub! (:send_email) @db_updater = mock("db_updater"); @db_updater.stub! (:update_db) @data_storer = DataStorer.new(@logger, @emailer, @db_updater, do_update_db_step) end specify "should log the data given when asked to store" do @logger.should_receive(:log).with("I was told to store 'moo'") @data_storer.store("moo") end specify "should email the data given when asked to store" do @emailer.should_receive(:send_email).with("Somebody stored 'moo'") @data_storer.store("moo") end case do_update_db_step when true specify "should store the data given to the DB when asked to store" do @db_updater.should_receive(:update_db).with("SET data = 'moo' WHERE id = 1") @data_storer.store("moo") end when false specify "should NOT store the data given to the DB when asked to store" do @db_updater.should_not_receive(:update_db) @data_storer.store("moo") end end end end This works well if you like reading the formatted output (eg in TextMate). Unfortunately it makes the spec code a lot harder to read. I can't find an ideal solution to this situation, but unfortunately it crops up quite often for me. Has anyone got any experiences or opinions that will help? Cheers Ashley From jerry.west at ntlworld.com Tue Feb 20 07:40:35 2007 From: jerry.west at ntlworld.com (Jerry West) Date: Tue, 20 Feb 2007 12:40:35 +0000 Subject: [rspec-users] Odd parameter munging with with() In-Reply-To: <765a2c230702192014j7a365acfg3563a61301413815@mail.gmail.com> References: <765a2c230702141600j33b98be7w22dab72e5c2cbc10@mail.gmail.com> <45D425C7.3030807@ntlworld.com> <765a2c230702191613j7de77519jf4afb7cc559bf9f7@mail.gmail.com> <57c63afe0702191658p15535fc9se76361819e2a3b2d@mail.gmail.com> <765a2c230702192014j7a365acfg3563a61301413815@mail.gmail.com> Message-ID: <45DAEC43.5090704@ntlworld.com> An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070220/135aa8a7/attachment-0001.html From jerry.west at ntlworld.com Tue Feb 20 08:05:06 2007 From: jerry.west at ntlworld.com (Jerry West) Date: Tue, 20 Feb 2007 13:05:06 +0000 Subject: [rspec-users] How to spec code with multiple (interacting) paths In-Reply-To: References: Message-ID: <45DAF202.8090902@ntlworld.com> I doubt there is an ideal solution. You might try to encapsulate the different behaviours in different classes (each spec'd separately). Where there are true alternatives, you could use SimpleDelegator to delegate to the appropriate class depending on your flag. No less work but conceptually cleaner perhaps. Alternatively (better?) work to eliminate the flag. especially if it's a do / don't do choice. If you don't need to do something, don't call the code. Push the decision and hence the spec up a level. The calling routine should not do anything if the flag is false. This is the boundary case of delegation: there's no need to spec a class that doesn't do anything. Lastly, you might think of the spec from the point of view of the flag, not the object. In other words, the customer wants something to happen under these circumstances and these other things to happen under those circumstances. Write your code to match these specs and refactor the commonality into shared routines, using your specs to increase your confidence that you haven't introduced (too many!) bugs. BTW, it's almost always possible to change code somewhere and still pass the spec - the trick is to write the spec before you change the code! BDD isn't a guarantee of correctness, merely an aid to design and coding that increases your confidence that your code will do (only) what is required. Best wishes, Jerry > I can't find an ideal solution to this situation, but unfortunately > it crops up quite often for me. Has anyone got any experiences or > opinions that will help? > > Cheers > Ashley > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Tue Feb 20 10:42:51 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 20 Feb 2007 09:42:51 -0600 Subject: [rspec-users] Odd parameter munging with with() In-Reply-To: <45DAEC43.5090704@ntlworld.com> References: <765a2c230702141600j33b98be7w22dab72e5c2cbc10@mail.gmail.com> <45D425C7.3030807@ntlworld.com> <765a2c230702191613j7de77519jf4afb7cc559bf9f7@mail.gmail.com> <57c63afe0702191658p15535fc9se76361819e2a3b2d@mail.gmail.com> <765a2c230702192014j7a365acfg3563a61301413815@mail.gmail.com> <45DAEC43.5090704@ntlworld.com> Message-ID: <57c63afe0702200742x487743fag32972f32bd476b4e@mail.gmail.com> On 2/20/07, Jerry West wrote: > > > > So, I still say my app code and my reduction look conceptually the > same, but I'm stumped as to why they don't behave the same way > > David seems to have picked that up. Ignore my blatherings about > HashArgConstraint (though the rest is valid). > > Here's another twist under Rails 1.2.2 (which may not be supported but > works fine for what I am doing so far). > > Basically, a different expectation seems to be set up depending on whether > the argument to get/post is a variable or not. That cannot be right. What > am I missing? > > require File.dirname(__FILE__) + '/../spec_helper' > > class TestController < ActionController::Base > def index() self.amethod(params) end > end > > context 'a test controller' do > controller_name :test > > setup do > @plist = { "id" => "1", "param2" => "bar" } > > controller.should_receive(:amethod).with(@plist).and_return(true) > end > > specify "should pass a hash to #with (1)" do > get :index, "id" => "1", "param2" => "bar" > end > specify "should pass a hash to #with (2)" do > get :index, { "id" => "1", "param2" => "bar" } > end > specify "should pass a hash to #with (3)" do > get :index, @plist > end > end > > $ spec -cfs spec/controllers/test_controller_spec.rb > /usr/bin/spec:17:Warning: require_gem is obsolete. Use gem instead. > /home/jjw/rails/playground/config/boot.rb:29:Warning: > require_gem is obsolete. Use gem instead. > > a test controller > - should pass a hash to #with (1) (FAILED - 1) > - should pass a hash to #with (2) (FAILED - 2) > - should pass a hash to #with (3) (FAILED - 3) > > 1) > 'a test controller should pass a hash to #with (1)' FAILED (ignore the > failure, look at the expectation) > # expected :amethod with (["param2", "bar"], > ["id", "1"]) but received it with ({"action"=>"index", "id"=>"1", > "param2"=>"bar", "controller"=>"test"}) > (eval):3:in `amethod' > ./spec/controllers/test_controller_spec.rb:4:in `index' > /usr/local/lib/site_ruby/1.8/benchmark.rb:300:in `measure' > ./spec/controllers/test_controller_spec.rb:13: > > 2) > 'a test controller should pass a hash to #with (2)' FAILED (ignore the > failure, look at the expectation) > # expected :amethod with (["param2", "bar"], > ["id", "1"]) but received it with ({"action"=>"index", "id"=>"1", > "param2"=>"bar", "controller"=>"test"}) > (eval):3:in `amethod' > ./spec/controllers/test_controller_spec.rb:4:in `index' > /usr/local/lib/site_ruby/1.8/benchmark.rb:300:in `measure' > ./spec/controllers/test_controller_spec.rb:18: > > 3) > 'a test controller should pass a hash to #with (3)' FAILED (ignore the > failure, look at the expectation) > # expected :amethod with ([:only_path, true], > ["param2", "bar"], ["id", "1"], [:action, :index]) but received it with > ({"action"=>"index", "id"=>"1", "param2"=>"bar", "controller"=>"test"}) > (eval):3:in `amethod' > ./spec/controllers/test_controller_spec.rb:4:in `index' > /usr/local/lib/site_ruby/1.8/benchmark.rb:300:in `measure' > ./spec/controllers/test_controller_spec.rb:23: > > Finished in 0.022612 seconds > > 3 specifications, 3 failures > > > Where the heck did the :only_path stuff come from in the expectation for > case 3?? They weren't there in ArgumentExpectation#initialize. > > As expected, creating the 'right' expectation (@plist = { "id" => > "1","param2" => "bar", "action" => "index", "controller" => "test" } ) > allows the spec to pass in cases 1 & 2, but #3 still fails. Here's the same output w/ the latest trunk. Note that it shows #with correctly receiving a Hash now. 1) Spec::Mocks::MockExpectationError in 'a test controller should pass a hash to #with (1)' # expected :amethod with ({"param2"=>"bar", "id"=>"1"}) but received it with ({"action"=>"index", "id"=>"1", "param2"=>"bar", "controller"=>"test"}) ./spec/controllers/temp_spec.rb:4:in `index' ./spec/controllers/temp_spec.rb:16: 2) Spec::Mocks::MockExpectationError in 'a test controller should pass a hash to #with (2)' # expected :amethod with ({"param2"=>"bar", "id"=>"1"}) but received it with ({"action"=>"index", "id"=>"1", "param2"=>"bar", "controller"=>"test"}) ./spec/controllers/temp_spec.rb:4:in `index' ./spec/controllers/temp_spec.rb:19: 3) Spec::Mocks::MockExpectationError in 'a test controller should pass a hash to #with (3)' # expected :amethod with ({:only_path=>true, "param2"=>"bar", "id"=>"1", :action=>:index}) but received it with ({"action"=>"index", "id"=>"1", "param2"=>"bar", "controller"=>"test"}) ./spec/controllers/temp_spec.rb:4:in `index' ./spec/controllers/temp_spec.rb:22: I have NO idea yet about :only_path. I'll keep you posted... > > rgds from "Confused of Hampshire". > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Tue Feb 20 11:12:03 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 20 Feb 2007 10:12:03 -0600 Subject: [rspec-users] Odd parameter munging with with() In-Reply-To: <57c63afe0702200742x487743fag32972f32bd476b4e@mail.gmail.com> References: <765a2c230702141600j33b98be7w22dab72e5c2cbc10@mail.gmail.com> <45D425C7.3030807@ntlworld.com> <765a2c230702191613j7de77519jf4afb7cc559bf9f7@mail.gmail.com> <57c63afe0702191658p15535fc9se76361819e2a3b2d@mail.gmail.com> <765a2c230702192014j7a365acfg3563a61301413815@mail.gmail.com> <45DAEC43.5090704@ntlworld.com> <57c63afe0702200742x487743fag32972f32bd476b4e@mail.gmail.com> Message-ID: <57c63afe0702200812x7ff76307v84668551761f70dc@mail.gmail.com> On 2/20/07, David Chelimsky wrote: > On 2/20/07, Jerry West wrote: > > > > > > > > So, I still say my app code and my reduction look conceptually the > > same, but I'm stumped as to why they don't behave the same way > > > > David seems to have picked that up. Ignore my blatherings about > > HashArgConstraint (though the rest is valid). > > > > Here's another twist under Rails 1.2.2 (which may not be supported but > > works fine for what I am doing so far). > > > > Basically, a different expectation seems to be set up depending on whether > > the argument to get/post is a variable or not. That cannot be right. What > > am I missing? > > > > require File.dirname(__FILE__) + '/../spec_helper' > > > > class TestController < ActionController::Base > > def index() self.amethod(params) end > > end > > > > context 'a test controller' do > > controller_name :test > > > > setup do > > @plist = { "id" => "1", "param2" => "bar" } > > > > controller.should_receive(:amethod).with(@plist).and_return(true) > > end > > > > specify "should pass a hash to #with (1)" do > > get :index, "id" => "1", "param2" => "bar" > > end > > specify "should pass a hash to #with (2)" do > > get :index, { "id" => "1", "param2" => "bar" } > > end > > specify "should pass a hash to #with (3)" do > > get :index, @plist > > end > > end > > > > $ spec -cfs spec/controllers/test_controller_spec.rb > > /usr/bin/spec:17:Warning: require_gem is obsolete. Use gem instead. > > /home/jjw/rails/playground/config/boot.rb:29:Warning: > > require_gem is obsolete. Use gem instead. > > > > a test controller > > - should pass a hash to #with (1) (FAILED - 1) > > - should pass a hash to #with (2) (FAILED - 2) > > - should pass a hash to #with (3) (FAILED - 3) > > > > 1) > > 'a test controller should pass a hash to #with (1)' FAILED (ignore the > > failure, look at the expectation) > > # expected :amethod with (["param2", "bar"], > > ["id", "1"]) but received it with ({"action"=>"index", "id"=>"1", > > "param2"=>"bar", "controller"=>"test"}) > > (eval):3:in `amethod' > > ./spec/controllers/test_controller_spec.rb:4:in `index' > > /usr/local/lib/site_ruby/1.8/benchmark.rb:300:in `measure' > > ./spec/controllers/test_controller_spec.rb:13: > > > > 2) > > 'a test controller should pass a hash to #with (2)' FAILED (ignore the > > failure, look at the expectation) > > # expected :amethod with (["param2", "bar"], > > ["id", "1"]) but received it with ({"action"=>"index", "id"=>"1", > > "param2"=>"bar", "controller"=>"test"}) > > (eval):3:in `amethod' > > ./spec/controllers/test_controller_spec.rb:4:in `index' > > /usr/local/lib/site_ruby/1.8/benchmark.rb:300:in `measure' > > ./spec/controllers/test_controller_spec.rb:18: > > > > 3) > > 'a test controller should pass a hash to #with (3)' FAILED (ignore the > > failure, look at the expectation) > > # expected :amethod with ([:only_path, true], > > ["param2", "bar"], ["id", "1"], [:action, :index]) but received it with > > ({"action"=>"index", "id"=>"1", "param2"=>"bar", "controller"=>"test"}) > > (eval):3:in `amethod' > > ./spec/controllers/test_controller_spec.rb:4:in `index' > > /usr/local/lib/site_ruby/1.8/benchmark.rb:300:in `measure' > > ./spec/controllers/test_controller_spec.rb:23: > > > > Finished in 0.022612 seconds > > > > 3 specifications, 3 failures > > > > > > Where the heck did the :only_path stuff come from in the expectation for > > case 3?? They weren't there in ArgumentExpectation#initialize. > > > > As expected, creating the 'right' expectation (@plist = { "id" => > > "1","param2" => "bar", "action" => "index", "controller" => "test" } ) > > allows the spec to pass in cases 1 & 2, but #3 still fails. > > Here's the same output w/ the latest trunk. Note that it shows #with > correctly receiving a Hash now. > > 1) > Spec::Mocks::MockExpectationError in 'a test controller should pass a > hash to #with (1)' > # expected :amethod with ({"param2"=>"bar", > "id"=>"1"}) but received it with ({"action"=>"index", "id"=>"1", > "param2"=>"bar", "controller"=>"test"}) > ./spec/controllers/temp_spec.rb:4:in `index' > ./spec/controllers/temp_spec.rb:16: > > 2) > Spec::Mocks::MockExpectationError in 'a test controller should pass a > hash to #with (2)' > # expected :amethod with ({"param2"=>"bar", > "id"=>"1"}) but received it with ({"action"=>"index", "id"=>"1", > "param2"=>"bar", "controller"=>"test"}) > ./spec/controllers/temp_spec.rb:4:in `index' > ./spec/controllers/temp_spec.rb:19: > > 3) > Spec::Mocks::MockExpectationError in 'a test controller should pass a > hash to #with (3)' > # expected :amethod with ({:only_path=>true, > "param2"=>"bar", "id"=>"1", :action=>:index}) but received it with > ({"action"=>"index", "id"=>"1", "param2"=>"bar", > "controller"=>"test"}) > ./spec/controllers/temp_spec.rb:4:in `index' > ./spec/controllers/temp_spec.rb:22: > > I have NO idea yet about :only_path. I'll keep you posted... OK, I now have SOME idea, but I'm still trying to figure out specifics. The following passes. Note that it uses @plist.dup each time. require File.dirname(__FILE__) + '/../spec_helper' class TestController < ActionController::Base def index() self.amethod(params) end end context 'a test controller' do controller_name :test setup do @plist = { "id" => "1", "param2" => "bar" , "controller" => "test", "action" => "index" } controller.should_receive(:amethod).with(@plist.dup).and_return(true) end specify "should pass a hash to #with (1)" do get :index, "id" => "1", "param2" => "bar" end specify "should pass a hash to #with (2)" do get :index, { "id" => "1", "param2" => "bar" } end specify "should pass a hash to #with (3)" do get :index, @plist.dup end end If you search through Rails you'll find dozens of instances of :only_path. So the problem SEEMS to be that by the time we reach the third spec, @plist has been touched by Rails. BTW - here's a variation that passes and allows you to deal only w/ the subset of keys you want. context 'a test controller' do controller_name :test setup do controller.should_receive(:amethod).and_return(true) { |params| params["id"].should == "1" params["param2"].should == "bar" } end specify "should pass a hash to #with (1)" do get :index, "id" => "1", "param2" => "bar" end specify "should pass a hash to #with (2)" do get :index, { "id" => "1", "param2" => "bar" } end specify "should pass a hash to #with (3)" do @plist = { "id" => "1", "param2" => "bar" } get :index, @plist.dup end end Cheers, David > > > > > rgds from "Confused of Hampshire". > > > > > > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > From dchelimsky at gmail.com Tue Feb 20 11:37:18 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 20 Feb 2007 10:37:18 -0600 Subject: [rspec-users] Odd parameter munging with with() In-Reply-To: <57c63afe0702200812x7ff76307v84668551761f70dc@mail.gmail.com> References: <765a2c230702141600j33b98be7w22dab72e5c2cbc10@mail.gmail.com> <45D425C7.3030807@ntlworld.com> <765a2c230702191613j7de77519jf4afb7cc559bf9f7@mail.gmail.com> <57c63afe0702191658p15535fc9se76361819e2a3b2d@mail.gmail.com> <765a2c230702192014j7a365acfg3563a61301413815@mail.gmail.com> <45DAEC43.5090704@ntlworld.com> <57c63afe0702200742x487743fag32972f32bd476b4e@mail.gmail.com> <57c63afe0702200812x7ff76307v84668551761f70dc@mail.gmail.com> Message-ID: <57c63afe0702200837v6a1539bbl216b4ab8124fda30@mail.gmail.com> On 2/20/07, David Chelimsky wrote: > On 2/20/07, David Chelimsky wrote: > > On 2/20/07, Jerry West wrote: > > > > > > > > > > > > So, I still say my app code and my reduction look conceptually the > > > same, but I'm stumped as to why they don't behave the same way > > > > > > David seems to have picked that up. Ignore my blatherings about > > > HashArgConstraint (though the rest is valid). > > > > > > Here's another twist under Rails 1.2.2 (which may not be supported but > > > works fine for what I am doing so far). > > > > > > Basically, a different expectation seems to be set up depending on whether > > > the argument to get/post is a variable or not. That cannot be right. What > > > am I missing? > > > > > > require File.dirname(__FILE__) + '/../spec_helper' > > > > > > class TestController < ActionController::Base > > > def index() self.amethod(params) end > > > end > > > > > > context 'a test controller' do > > > controller_name :test > > > > > > setup do > > > @plist = { "id" => "1", "param2" => "bar" } > > > > > > controller.should_receive(:amethod).with(@plist).and_return(true) > > > end > > > > > > specify "should pass a hash to #with (1)" do > > > get :index, "id" => "1", "param2" => "bar" > > > end > > > specify "should pass a hash to #with (2)" do > > > get :index, { "id" => "1", "param2" => "bar" } > > > end > > > specify "should pass a hash to #with (3)" do > > > get :index, @plist > > > end > > > end > > > > > > $ spec -cfs spec/controllers/test_controller_spec.rb > > > /usr/bin/spec:17:Warning: require_gem is obsolete. Use gem instead. > > > /home/jjw/rails/playground/config/boot.rb:29:Warning: > > > require_gem is obsolete. Use gem instead. > > > > > > a test controller > > > - should pass a hash to #with (1) (FAILED - 1) > > > - should pass a hash to #with (2) (FAILED - 2) > > > - should pass a hash to #with (3) (FAILED - 3) > > > > > > 1) > > > 'a test controller should pass a hash to #with (1)' FAILED (ignore the > > > failure, look at the expectation) > > > # expected :amethod with (["param2", "bar"], > > > ["id", "1"]) but received it with ({"action"=>"index", "id"=>"1", > > > "param2"=>"bar", "controller"=>"test"}) > > > (eval):3:in `amethod' > > > ./spec/controllers/test_controller_spec.rb:4:in `index' > > > /usr/local/lib/site_ruby/1.8/benchmark.rb:300:in `measure' > > > ./spec/controllers/test_controller_spec.rb:13: > > > > > > 2) > > > 'a test controller should pass a hash to #with (2)' FAILED (ignore the > > > failure, look at the expectation) > > > # expected :amethod with (["param2", "bar"], > > > ["id", "1"]) but received it with ({"action"=>"index", "id"=>"1", > > > "param2"=>"bar", "controller"=>"test"}) > > > (eval):3:in `amethod' > > > ./spec/controllers/test_controller_spec.rb:4:in `index' > > > /usr/local/lib/site_ruby/1.8/benchmark.rb:300:in `measure' > > > ./spec/controllers/test_controller_spec.rb:18: > > > > > > 3) > > > 'a test controller should pass a hash to #with (3)' FAILED (ignore the > > > failure, look at the expectation) > > > # expected :amethod with ([:only_path, true], > > > ["param2", "bar"], ["id", "1"], [:action, :index]) but received it with > > > ({"action"=>"index", "id"=>"1", "param2"=>"bar", "controller"=>"test"}) > > > (eval):3:in `amethod' > > > ./spec/controllers/test_controller_spec.rb:4:in `index' > > > /usr/local/lib/site_ruby/1.8/benchmark.rb:300:in `measure' > > > ./spec/controllers/test_controller_spec.rb:23: > > > > > > Finished in 0.022612 seconds > > > > > > 3 specifications, 3 failures > > > > > > > > > Where the heck did the :only_path stuff come from in the expectation for > > > case 3?? They weren't there in ArgumentExpectation#initialize. > > > > > > As expected, creating the 'right' expectation (@plist = { "id" => > > > "1","param2" => "bar", "action" => "index", "controller" => "test" } ) > > > allows the spec to pass in cases 1 & 2, but #3 still fails. > > > > Here's the same output w/ the latest trunk. Note that it shows #with > > correctly receiving a Hash now. > > > > 1) > > Spec::Mocks::MockExpectationError in 'a test controller should pass a > > hash to #with (1)' > > # expected :amethod with ({"param2"=>"bar", > > "id"=>"1"}) but received it with ({"action"=>"index", "id"=>"1", > > "param2"=>"bar", "controller"=>"test"}) > > ./spec/controllers/temp_spec.rb:4:in `index' > > ./spec/controllers/temp_spec.rb:16: > > > > 2) > > Spec::Mocks::MockExpectationError in 'a test controller should pass a > > hash to #with (2)' > > # expected :amethod with ({"param2"=>"bar", > > "id"=>"1"}) but received it with ({"action"=>"index", "id"=>"1", > > "param2"=>"bar", "controller"=>"test"}) > > ./spec/controllers/temp_spec.rb:4:in `index' > > ./spec/controllers/temp_spec.rb:19: > > > > 3) > > Spec::Mocks::MockExpectationError in 'a test controller should pass a > > hash to #with (3)' > > # expected :amethod with ({:only_path=>true, > > "param2"=>"bar", "id"=>"1", :action=>:index}) but received it with > > ({"action"=>"index", "id"=>"1", "param2"=>"bar", > > "controller"=>"test"}) > > ./spec/controllers/temp_spec.rb:4:in `index' > > ./spec/controllers/temp_spec.rb:22: > > > > I have NO idea yet about :only_path. I'll keep you posted... > > OK, I now have SOME idea, but I'm still trying to figure out > specifics. The following passes. Note that it uses @plist.dup each > time. > > require File.dirname(__FILE__) + '/../spec_helper' > > class TestController < ActionController::Base > def index() self.amethod(params) end > end > > context 'a test controller' do > controller_name :test > > setup do > @plist = { "id" => "1", "param2" => "bar" , "controller" => > "test", "action" => "index" } > controller.should_receive(:amethod).with(@plist.dup).and_return(true) > end > > specify "should pass a hash to #with (1)" do > get :index, "id" => "1", "param2" => "bar" > end > > specify "should pass a hash to #with (2)" do > get :index, { "id" => "1", "param2" => "bar" } > end > > specify "should pass a hash to #with (3)" do > get :index, @plist.dup > end > end > > If you search through Rails you'll find dozens of instances of > :only_path. So the problem SEEMS to be that by the time we reach the > third spec, @plist has been touched by Rails. > > BTW - here's a variation that passes and allows you to deal only w/ > the subset of keys you want. > > context 'a test controller' do > controller_name :test > > setup do > controller.should_receive(:amethod).and_return(true) { |params| > params["id"].should == "1" > params["param2"].should == "bar" > } > end > > specify "should pass a hash to #with (1)" do > get :index, "id" => "1", "param2" => "bar" > end > > specify "should pass a hash to #with (2)" do > get :index, { "id" => "1", "param2" => "bar" } > end > > specify "should pass a hash to #with (3)" do > @plist = { "id" => "1", "param2" => "bar" } > get :index, @plist.dup > end > end OK - I figured it out. Because the third spec is passing the actual Hash instance to "get :index", Rails gets a direct reference to it and can do what it wants. If you're interested in details in this case, take a look at test_process.rb:430/431. So the lesson here is don't use expectation objects as parameters to your system as the system may produce unwanted side effects. Cheers, David > > Cheers, > David > > > > > > > > > rgds from "Confused of Hampshire". > > > > > > > > > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > From dchelimsky at gmail.com Tue Feb 20 11:57:40 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 20 Feb 2007 10:57:40 -0600 Subject: [rspec-users] How to spec code with multiple (interacting) paths In-Reply-To: <45DAF202.8090902@ntlworld.com> References: <45DAF202.8090902@ntlworld.com> Message-ID: <57c63afe0702200857h195577d1h138b17494c5104e6@mail.gmail.com> On 2/20/07, Jerry West wrote: > I doubt there is an ideal solution. You might try to encapsulate the > different behaviours in different classes (each spec'd separately). > Where there are true alternatives, you could use SimpleDelegator to > delegate to the appropriate class depending on your flag. No less work > but conceptually cleaner perhaps. > > Alternatively (better?) work to eliminate the flag. especially if it's a > do / don't do choice. If you don't need to do something, don't call the > code. Push the decision and hence the spec up a level. The calling > routine should not do anything if the flag is false. This is the > boundary case of delegation: there's no need to spec a class that > doesn't do anything. > > Lastly, you might think of the spec from the point of view of the flag, > not the object. In other words, the customer wants something to happen > under these circumstances and these other things to happen under those > circumstances. Write your code to match these specs and refactor the > commonality into shared routines, using your specs to increase your > confidence that you haven't introduced (too many!) bugs. BTW, it's > almost always possible to change code somewhere and still pass the spec > - the trick is to write the spec before you change the code! AND watch it fail. That is key!!!!!! The cycle (from TDD) is: 1. write a failing spec 2. make it pass with the simplest thing that could possibly work 3. refactor to eliminate duplication Note that "duplication" here refers to duplication either in the subject code or between the spec and the subject code. IMO, some duplication is OK in specs. As to Ashley's initial post, I agree with Jerry in that the first thing I'd look to do is see how I could break up some of these responsibilities. FWIW, whenever I find that something is hard to spec/test, I look at that as a design problem. But sometimes the simplest thing that could possibly work isn't all that simple and you have to find trade-offs between complexity in the system and complexity in the specs. Not too helpful, I realize. Cheers, David > BDD isn't > a guarantee of correctness, merely an aid to design and coding that > increases your confidence that your code will do (only) what is required. > > Best wishes, > Jerry > > I can't find an ideal solution to this situation, but unfortunately > > it crops up quite often for me. Has anyone got any experiences or > > opinions that will help? > > > > Cheers > > Ashley > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From hughes.james at gmail.com Tue Feb 20 14:17:13 2007 From: hughes.james at gmail.com (James Hughes) Date: Tue, 20 Feb 2007 11:17:13 -0800 Subject: [rspec-users] Odd parameter munging with with() In-Reply-To: <57c63afe0702200742x487743fag32972f32bd476b4e@mail.gmail.com> References: <765a2c230702141600j33b98be7w22dab72e5c2cbc10@mail.gmail.com> <45D425C7.3030807@ntlworld.com> <765a2c230702191613j7de77519jf4afb7cc559bf9f7@mail.gmail.com> <57c63afe0702191658p15535fc9se76361819e2a3b2d@mail.gmail.com> <765a2c230702192014j7a365acfg3563a61301413815@mail.gmail.com> <45DAEC43.5090704@ntlworld.com> <57c63afe0702200742x487743fag32972f32bd476b4e@mail.gmail.com> Message-ID: <765a2c230702201117l61704205n223df4e25251f99f@mail.gmail.com> On 2/20/07, David Chelimsky wrote: > > Here's the same output w/ the latest trunk. Note that it shows #with > correctly receiving a Hash now. David, thanks. I updated to latest trunk and can now pass the same params hash to both #with and #post and get the expected results. Note that I didn't have to deal with the :only_path stuff as I was looking at params[:user] and not just params. > > 1) > Spec::Mocks::MockExpectationError in 'a test controller should pass a > hash to #with (1)' > # expected :amethod with ({"param2"=>"bar", > "id"=>"1"}) but received it with ({"action"=>"index", "id"=>"1", > "param2"=>"bar", "controller"=>"test"}) > ./spec/controllers/temp_spec.rb:4:in `index' > ./spec/controllers/temp_spec.rb:16: > > 2) > Spec::Mocks::MockExpectationError in 'a test controller should pass a > hash to #with (2)' > # expected :amethod with ({"param2"=>"bar", > "id"=>"1"}) but received it with ({"action"=>"index", "id"=>"1", > "param2"=>"bar", "controller"=>"test"}) > ./spec/controllers/temp_spec.rb:4:in `index' > ./spec/controllers/temp_spec.rb:19: > > 3) > Spec::Mocks::MockExpectationError in 'a test controller should pass a > hash to #with (3)' > # expected :amethod with ({:only_path=>true, > "param2"=>"bar", "id"=>"1", :action=>:index}) but received it with > ({"action"=>"index", "id"=>"1", "param2"=>"bar", > "controller"=>"test"}) > ./spec/controllers/temp_spec.rb:4:in `index' > ./spec/controllers/temp_spec.rb:22: > > I have NO idea yet about :only_path. I'll keep you posted... > > > > > rgds from "Confused of Hampshire". > > > > > > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From hughes.james at gmail.com Tue Feb 20 14:40:10 2007 From: hughes.james at gmail.com (James Hughes) Date: Tue, 20 Feb 2007 11:40:10 -0800 Subject: [rspec-users] Odd parameter munging with with() In-Reply-To: <57c63afe0702200742x487743fag32972f32bd476b4e@mail.gmail.com> References: <765a2c230702141600j33b98be7w22dab72e5c2cbc10@mail.gmail.com> <45D425C7.3030807@ntlworld.com> <765a2c230702191613j7de77519jf4afb7cc559bf9f7@mail.gmail.com> <57c63afe0702191658p15535fc9se76361819e2a3b2d@mail.gmail.com> <765a2c230702192014j7a365acfg3563a61301413815@mail.gmail.com> <45DAEC43.5090704@ntlworld.com> <57c63afe0702200742x487743fag32972f32bd476b4e@mail.gmail.com> Message-ID: <765a2c230702201140w767e20d3qf0c1d156197481cf@mail.gmail.com> On 2/20/07, David Chelimsky wrote: > Here's the same output w/ the latest trunk. Note that it shows #with > correctly receiving a Hash now. Ok, just one more comment here and then I'll shut up. David, I just now noticed your comment on the RFE: "I've fixed the message so it will show you the two hashes (expected and actual), but I think that getting RSpec to make decisions about stringifying keys would be a mistake. To that end, I think the right thing is for you to change your spec to expect a Hash with stringy keys." You're right, changing the hash to have string keys was not a burden but doing this had zero effect on whether the spec passed or not; my point all along (and sorry if this was never made clear enough) was that it did seem like a burden to convert my hash to an array of 2-element arrays in order for the spec to pass. Not to mention, this would break any code under test that was expecting to deal with a hash (as in the #delete example that I mentioned in a separate mail). Anyways, thanks again for looking into this. As an aside, I'm really enjoying using rspec! James > > 1) > Spec::Mocks::MockExpectationError in 'a test controller should pass a > hash to #with (1)' > # expected :amethod with ({"param2"=>"bar", > "id"=>"1"}) but received it with ({"action"=>"index", "id"=>"1", > "param2"=>"bar", "controller"=>"test"}) > ./spec/controllers/temp_spec.rb:4:in `index' > ./spec/controllers/temp_spec.rb:16: > > 2) > Spec::Mocks::MockExpectationError in 'a test controller should pass a > hash to #with (2)' > # expected :amethod with ({"param2"=>"bar", > "id"=>"1"}) but received it with ({"action"=>"index", "id"=>"1", > "param2"=>"bar", "controller"=>"test"}) > ./spec/controllers/temp_spec.rb:4:in `index' > ./spec/controllers/temp_spec.rb:19: > > 3) > Spec::Mocks::MockExpectationError in 'a test controller should pass a > hash to #with (3)' > # expected :amethod with ({:only_path=>true, > "param2"=>"bar", "id"=>"1", :action=>:index}) but received it with > ({"action"=>"index", "id"=>"1", "param2"=>"bar", > "controller"=>"test"}) > ./spec/controllers/temp_spec.rb:4:in `index' > ./spec/controllers/temp_spec.rb:22: > > I have NO idea yet about :only_path. I'll keep you posted... > > > > > rgds from "Confused of Hampshire". > > > > > > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Tue Feb 20 14:51:48 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 20 Feb 2007 13:51:48 -0600 Subject: [rspec-users] Odd parameter munging with with() In-Reply-To: <765a2c230702201140w767e20d3qf0c1d156197481cf@mail.gmail.com> References: <765a2c230702141600j33b98be7w22dab72e5c2cbc10@mail.gmail.com> <45D425C7.3030807@ntlworld.com> <765a2c230702191613j7de77519jf4afb7cc559bf9f7@mail.gmail.com> <57c63afe0702191658p15535fc9se76361819e2a3b2d@mail.gmail.com> <765a2c230702192014j7a365acfg3563a61301413815@mail.gmail.com> <45DAEC43.5090704@ntlworld.com> <57c63afe0702200742x487743fag32972f32bd476b4e@mail.gmail.com> <765a2c230702201140w767e20d3qf0c1d156197481cf@mail.gmail.com> Message-ID: <57c63afe0702201151h228d46c9mcd07c4ecd5085dbb@mail.gmail.com> On 2/20/07, James Hughes wrote: > On 2/20/07, David Chelimsky wrote: > > Here's the same output w/ the latest trunk. Note that it shows #with > > correctly receiving a Hash now. > > Ok, just one more comment here and then I'll shut up. David, I just > now noticed your comment on the RFE: > > "I've fixed the message so it will show you the two hashes (expected > and actual), but I think that getting RSpec to make decisions about > stringifying keys would be a mistake. To that end, I think the right > thing is for you to change your spec to expect a Hash with stringy > keys." > > You're right, changing the hash to have string keys was not a burden > but doing this had zero effect on whether the spec passed or not; my > point all along (and sorry if this was never made clear enough) was > that it did seem like a burden to convert my hash to an array of > 2-element arrays in order for the spec to pass. Not to mention, this > would break any code under test that was expecting to deal with a hash > (as in the #delete example that I mentioned in a separate mail). OK - now I'm confused. As I understand it, the problem was that the failure message was incorrectly displaying a Hash as an Array of 2-element Arrays. This was ONLY in the message, which was only invoked after the Hash's had been correctly compared. There was never an Array of Array's being compared. With that understanding, I don't see how the spec could have passed simply by saying #with([[][]]). Please help me understand. > > Anyways, thanks again for looking into this. As an aside, I'm really > enjoying using rspec! Glad to hear it. And thanks for the feedback in general. Cheers, David > > James > > > > > > 1) > > Spec::Mocks::MockExpectationError in 'a test controller should pass a > > hash to #with (1)' > > # expected :amethod with ({"param2"=>"bar", > > "id"=>"1"}) but received it with ({"action"=>"index", "id"=>"1", > > "param2"=>"bar", "controller"=>"test"}) > > ./spec/controllers/temp_spec.rb:4:in `index' > > ./spec/controllers/temp_spec.rb:16: > > > > 2) > > Spec::Mocks::MockExpectationError in 'a test controller should pass a > > hash to #with (2)' > > # expected :amethod with ({"param2"=>"bar", > > "id"=>"1"}) but received it with ({"action"=>"index", "id"=>"1", > > "param2"=>"bar", "controller"=>"test"}) > > ./spec/controllers/temp_spec.rb:4:in `index' > > ./spec/controllers/temp_spec.rb:19: > > > > 3) > > Spec::Mocks::MockExpectationError in 'a test controller should pass a > > hash to #with (3)' > > # expected :amethod with ({:only_path=>true, > > "param2"=>"bar", "id"=>"1", :action=>:index}) but received it with > > ({"action"=>"index", "id"=>"1", "param2"=>"bar", > > "controller"=>"test"}) > > ./spec/controllers/temp_spec.rb:4:in `index' > > ./spec/controllers/temp_spec.rb:22: > > > > I have NO idea yet about :only_path. I'll keep you posted... > > > > > > > > rgds from "Confused of Hampshire". > > > > > > > > > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From esad at esse.at Tue Feb 20 16:20:37 2007 From: esad at esse.at (Esad Hajdarevic) Date: Tue, 20 Feb 2007 22:20:37 +0100 Subject: [rspec-users] having should_receive expectation for things that happen in setup Message-ID: <45DB6625.5070207@esse.at> Hi! The following example doesn't work for me: http://pastie.caboo.se/41732 However, if the call to msg() happens in the specify block after the expecation and not in the setup, it will pass. Why is this? I thought the setup method was there to actually 'construct' the context and the specifications are some kind of "postconditions" that only need to be validated after that - am I thinking wrong here? Greetings, Esad From hughes.james at gmail.com Tue Feb 20 17:10:20 2007 From: hughes.james at gmail.com (James Hughes) Date: Tue, 20 Feb 2007 14:10:20 -0800 Subject: [rspec-users] Odd parameter munging with with() In-Reply-To: <57c63afe0702201151h228d46c9mcd07c4ecd5085dbb@mail.gmail.com> References: <765a2c230702141600j33b98be7w22dab72e5c2cbc10@mail.gmail.com> <45D425C7.3030807@ntlworld.com> <765a2c230702191613j7de77519jf4afb7cc559bf9f7@mail.gmail.com> <57c63afe0702191658p15535fc9se76361819e2a3b2d@mail.gmail.com> <765a2c230702192014j7a365acfg3563a61301413815@mail.gmail.com> <45DAEC43.5090704@ntlworld.com> <57c63afe0702200742x487743fag32972f32bd476b4e@mail.gmail.com> <765a2c230702201140w767e20d3qf0c1d156197481cf@mail.gmail.com> <57c63afe0702201151h228d46c9mcd07c4ecd5085dbb@mail.gmail.com> Message-ID: <765a2c230702201410k5b587647v4b379b81971fedae@mail.gmail.com> On 2/20/07, David Chelimsky wrote: > On 2/20/07, James Hughes wrote: > > On 2/20/07, David Chelimsky wrote: > > > Here's the same output w/ the latest trunk. Note that it shows #with > > > correctly receiving a Hash now. > > > > Ok, just one more comment here and then I'll shut up. David, I just > > now noticed your comment on the RFE: > > > > "I've fixed the message so it will show you the two hashes (expected > > and actual), but I think that getting RSpec to make decisions about > > stringifying keys would be a mistake. To that end, I think the right > > thing is for you to change your spec to expect a Hash with stringy > > keys." > > > > You're right, changing the hash to have string keys was not a burden > > but doing this had zero effect on whether the spec passed or not; my > > point all along (and sorry if this was never made clear enough) was > > that it did seem like a burden to convert my hash to an array of > > 2-element arrays in order for the spec to pass. Not to mention, this > > would break any code under test that was expecting to deal with a hash > > (as in the #delete example that I mentioned in a separate mail). > > OK - now I'm confused. It would appear that I am the one who is confused. I had a distinct memory of my spec still failing after I had changed the keys to strings, but I just reverted to r1514 to double check that, and indeed, it passed with string keys, and failed with symbol keys. I got so caught up in chasing down all the possible combinations of how to do this that I somehow convinced myself that the keys issue was a red herring. My apologies. At least you fixed the message bug ;) James From dchelimsky at gmail.com Tue Feb 20 17:21:01 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 20 Feb 2007 16:21:01 -0600 Subject: [rspec-users] having should_receive expectation for things that happen in setup In-Reply-To: <45DB6625.5070207@esse.at> References: <45DB6625.5070207@esse.at> Message-ID: <57c63afe0702201421u30f174c8s2bc087c6fcee0b4@mail.gmail.com> should_receive sets up expectations for things that will happen subsequently. In your example, foo.msg gets called before foo.should_receive(:msg) Make sense? On 2/20/07, Esad Hajdarevic wrote: > Hi! > > The following example doesn't work for me: http://pastie.caboo.se/41732 > > However, if the call to msg() happens in the specify block after the > expecation and not in the setup, it will pass. > > Why is this? I thought the setup method was there to actually > 'construct' the context and the specifications are some kind of > "postconditions" that only need to be validated after that - am I > thinking wrong here? > > Greetings, > > Esad > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From sataylor at sjca.edu Wed Feb 21 17:37:59 2007 From: sataylor at sjca.edu (Scott Taylor) Date: Wed, 21 Feb 2007 17:37:59 -0500 Subject: [rspec-users] Using rspec_on_rails without a test database Message-ID: I think my solution may be to use the drb server to speed up tests. Does anyone know who maintains the spec:autotest plugin? I'd be interested in contributing a patch to use drb instead of the typical spec task. Best Regards, Scott From scotttaylor at bigfoot.com Wed Feb 21 16:52:36 2007 From: scotttaylor at bigfoot.com (Scott Taylor) Date: Wed, 21 Feb 2007 16:52:36 -0500 Subject: [rspec-users] Using rspec_on_rails without a test database Message-ID: <7B034AA0-4D79-493B-8D14-7FB5D81B5DA8@bigfoot.com> Is there some way to remove the database hit when running rake rspec:models ? I'd like to mock all of my objects (or at least remove all reliance on fixtures and the database itself) - both for speed and because static fixtures are brittle. Best Regards, Scott Taylor From dchelimsky at gmail.com Wed Feb 21 19:47:06 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 21 Feb 2007 18:47:06 -0600 Subject: [rspec-users] Using rspec_on_rails without a test database In-Reply-To: References: Message-ID: <57c63afe0702211647l590482e9w5b91f3d1eb51fd4d@mail.gmail.com> On 2/21/07, Scott Taylor wrote: > > I think my solution may be to use the drb server to speed up tests. > > Does anyone know who maintains the spec:autotest plugin? I'd be > interested in contributing a patch to use drb instead of the typical > spec task. Try Nick Sieger: http://blog.nicksieger.com/articles/tag/autotest. Cheers, David > > Best Regards, > > Scott > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Wed Feb 21 19:55:22 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 21 Feb 2007 18:55:22 -0600 Subject: [rspec-users] Using rspec_on_rails without a test database In-Reply-To: <7B034AA0-4D79-493B-8D14-7FB5D81B5DA8@bigfoot.com> References: <7B034AA0-4D79-493B-8D14-7FB5D81B5DA8@bigfoot.com> Message-ID: <57c63afe0702211655p2421e32t97b92c64404fb4d8@mail.gmail.com> On 2/21/07, Scott Taylor wrote: > > Is there some way to remove the database hit when running rake > rspec:models ? There's not yet, but you're not the first to ask: http://rubyforge.org/tracker/index.php?func=detail&aid=6523&group_id=797&atid=3152 It's something that we'll add sooner or later. In the mean time, there is some writing about how to test Rails w/o a database using the tools that ship w/ Rails that might help you. Check out Chad Fowler's book, Rails Recipes, and also Jay Field's blog: http://jayfields.blogspot.com/. Hope that helps. Cheers, David > I'd like to mock all of my objects (or at least > remove all reliance on fixtures and the database itself) - both for > speed and because static fixtures are brittle. > > Best Regards, > > Scott Taylor > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From scotttaylor at bigfoot.com Wed Feb 21 20:06:26 2007 From: scotttaylor at bigfoot.com (Scott Taylor) Date: Wed, 21 Feb 2007 20:06:26 -0500 Subject: [rspec-users] drbserver and --color In-Reply-To: References: Message-ID: <2635ABD7-95DB-4A40-8672-3018CC8BB5D3@bigfoot.com> For whatever reason, running drbserver --color doesn't seem to be working. Any reason for this? Has it just not been built in yet? Best, and thanks for the help on the previous post. Scott From aslak.hellesoy at gmail.com Thu Feb 22 02:00:16 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Thu, 22 Feb 2007 08:00:16 +0100 Subject: [rspec-users] drbserver and --color In-Reply-To: <2635ABD7-95DB-4A40-8672-3018CC8BB5D3@bigfoot.com> References: <2635ABD7-95DB-4A40-8672-3018CC8BB5D3@bigfoot.com> Message-ID: <8d961d900702212300h119f049as162cd7985613a0d6@mail.gmail.com> On 2/22/07, Scott Taylor wrote: > > For whatever reason, running drbserver --color doesn't seem to be > working. Any reason for this? Has it just not been built in yet? > OS? revision/version? Works fine for me on os x/trunk. I don't think it's working on Windows yet. You can file a RFE if you want. Aslak > Best, and thanks for the help on the previous post. > > Scott > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From work at ashleymoran.me.uk Thu Feb 22 10:40:04 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Thu, 22 Feb 2007 15:40:04 +0000 Subject: [rspec-users] How to spec code with multiple (interacting) paths In-Reply-To: <45DAF202.8090902@ntlworld.com> References: <45DAF202.8090902@ntlworld.com> Message-ID: <29D1AF28-B6C3-4026-8381-38BD7D96F147@ashleymoran.me.uk> On 20 Feb 2007, at 13:05, Jerry West wrote: > I doubt there is an ideal solution. You might try to encapsulate the > different behaviours in different classes (each spec'd separately). > Where there are true alternatives, you could use SimpleDelegator to > delegate to the appropriate class depending on your flag. No less > work > but conceptually cleaner perhaps. Jerry One of the times this crops up most is with Rails controllers that behave differently based on their parameters. So, for example, I'm writing a credit card form now that behaves differently if there is a start date or not. Another one was a case when a form action was receiving 3 models and 3 confirmation checkboxes, and I wanted to spec the behaviour in the case of each being invalid. I'm not sure I could really split these up anyway. > Alternatively (better?) work to eliminate the flag. especially if > it's a > do / don't do choice. If you don't need to do something, don't > call the > code. Push the decision and hence the spec up a level. The calling > routine should not do anything if the flag is false. This is the > boundary case of delegation: there's no need to spec a class that > doesn't do anything. I gave a boolean as a simple example. I've wrote other code that does all sorts of wierd stuff depending on where values lie, so there are many possible paths. Again, I'm mainly concerned right now with controllers, so the only layer above is the browser. And if I'm writing models, the last thing I want to do is push decisions up into the controller, because it would divide the business logic. I suppose what I could do with controllers is split out the code that deals with the parameters, something along the lines of (but better thought out than) this brain dump: class ApplicantController < ApplicationController class SaveDetailsParameterParser def new(params) # create models end # models def applicant; end def address; end def vehicle; end def models_valid?; end end def save_details p = SaveDetailsParameterParser.new(params) redirect_to :action => 'error_page' if !p.models_valid? end end This would be acting like a factory for all objects required by the action, and could be specified independently. Then I wouldn't need to check that the controller behaves correctly under 3 different invalid models, just that if anything is invalid it behaves correctly. (Pretty much identical to the way you spec the individual validations in a model, then spec that the controller behaves correctly if its invalid.) Maybe you were thinking along these lines? It's hard to put things across sometimes without writing code out. Ashley From work at ashleymoran.me.uk Thu Feb 22 10:54:05 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Thu, 22 Feb 2007 15:54:05 +0000 Subject: [rspec-users] How to spec code with multiple (interacting) paths In-Reply-To: <57c63afe0702200857h195577d1h138b17494c5104e6@mail.gmail.com> References: <45DAF202.8090902@ntlworld.com> <57c63afe0702200857h195577d1h138b17494c5104e6@mail.gmail.com> Message-ID: On 20 Feb 2007, at 16:57, David Chelimsky wrote: > AND watch it fail. That is key!!!!!! The cycle (from TDD) is: > > 1. write a failing spec Oh I've been caught out by writing incorrectly passing specs because I didn't run them before I wrote the code. It happened today to the guy I'm working with on some RJS code. > 2. make it pass with the simplest thing that could possibly work > 3. refactor to eliminate duplication > > Note that "duplication" here refers to duplication either in the > subject code or between the spec and the subject code. IMO, some > duplication is OK in specs. > > As to Ashley's initial post, I agree with Jerry in that the first > thing I'd look to do is see how I could break up some of these > responsibilities. FWIW, whenever I find that something is hard to > spec/test, I look at that as a design problem. But sometimes the > simplest thing that could possibly work isn't all that simple and you > have to find trade-offs between complexity in the system and > complexity in the specs. I suspect I'm getting far too much duplication in specs. I'm forced to generate contexts in a loop, or copy-and-paste whole contexts far too often. I'll try and modularise some of the application logic in my controllers and see if it sorts itself out. I never thought before about refactoring to eliminate duplication in specs, but it makes sense really. Ashley From dchelimsky at gmail.com Thu Feb 22 12:05:54 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 22 Feb 2007 11:05:54 -0600 Subject: [rspec-users] How to spec code with multiple (interacting) paths In-Reply-To: References: <45DAF202.8090902@ntlworld.com> <57c63afe0702200857h195577d1h138b17494c5104e6@mail.gmail.com> Message-ID: <57c63afe0702220905t6929f657o2edb2501a70f213@mail.gmail.com> On 2/22/07, Ashley Moran wrote: > > On 20 Feb 2007, at 16:57, David Chelimsky wrote: > > > AND watch it fail. That is key!!!!!! The cycle (from TDD) is: > > > > 1. write a failing spec > > Oh I've been caught out by writing incorrectly passing specs because > I didn't run them before I wrote the code. It happened today to the > guy I'm working with on some RJS code. > > > 2. make it pass with the simplest thing that could possibly work > > 3. refactor to eliminate duplication > > > > Note that "duplication" here refers to duplication either in the > > subject code or between the spec and the subject code. IMO, some > > duplication is OK in specs. > > > > As to Ashley's initial post, I agree with Jerry in that the first > > thing I'd look to do is see how I could break up some of these > > responsibilities. FWIW, whenever I find that something is hard to > > spec/test, I look at that as a design problem. But sometimes the > > simplest thing that could possibly work isn't all that simple and you > > have to find trade-offs between complexity in the system and > > complexity in the specs. > > I suspect I'm getting far too much duplication in specs. I'm forced > to generate contexts in a loop, or copy-and-paste whole contexts far > too often. I'll try and modularise some of the application logic in > my controllers and see if it sorts itself out. > > I never thought before about refactoring to eliminate duplication in > specs, but it makes sense really. My only bit of unsolicited advice w/ this is that you keep reminding yourself that specs are not the same as production code. Eliminating duplication is helpful, but it's equally (if not more) important that you don't have to debug your specs (i.e. trace paths through several files, etc). Everything you need to know for a given spec should be right in front of you. Hope that is helpful. Cheers, David > > Ashley > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From pergesu at gmail.com Thu Feb 22 15:41:35 2007 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 22 Feb 2007 13:41:35 -0700 Subject: [rspec-users] We can't 100% remove our unit tests from the database, can we? Message-ID: <810a540e0702221241w41597932k3710e427b6a04ea0@mail.gmail.com> I hope this isn't too rambly. This is sort of a brain dump of a subject I've been thinking about for months as I've used RSpec. Let's say we've got a simple query method, that will find all the users in the DB older than 18. Our model could look like class User < ActiveRecord::Base def self.find_older_than(age) find :all, :conditions => ["age > ?", age] end end What would our spec look like? specify "should find all users over the given age" do User.should_receive(:find).with(:all, :conditions => ["age > ?", 18]) User.find_older_than 18 end I don't know about you, but to me that sucks. There is no TDD rhythm there. We write a failing spec, but it's a fairly complex spec. On top of that we've basically implemented the method from within the spec. That's not TDD. We also can't refactor. Let's say that at some point we decided to change the method to def User.find_older_than(age) find(:all).select {|u| u.age > age } end Our spec would break, even though the semantics of User.find_older_than hasn't changed. Okay, so it's just a crappy spec. But how do we change it? Lots of people suggest stubbing out DB calls. There's no sense in testing the same thing over and over - namely that you have a connection and your ORM tool is working correctly. I'm beginning to think that most of the time, you don't want to use a test DB at all. When you're testing an AR model, just use an in-memory record and stub any associations you need. But when you do do something that interacts with the database - like doing a custom find - you need to use the database to make sure that you're getting the right results. Whether you use fixtures or create some records in the setup method, you have to actually hit the db. Let me know what you think. I'm completely open to the idea that I've missed something pathetically obvious. Pat From aslak.hellesoy at gmail.com Thu Feb 22 16:42:14 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Thu, 22 Feb 2007 22:42:14 +0100 Subject: [rspec-users] We can't 100% remove our unit tests from the database, can we? In-Reply-To: <810a540e0702221241w41597932k3710e427b6a04ea0@mail.gmail.com> References: <810a540e0702221241w41597932k3710e427b6a04ea0@mail.gmail.com> Message-ID: <8d961d900702221342t4c889305s2ecd0b7681be08fc@mail.gmail.com> On 2/22/07, Pat Maddox wrote: > I hope this isn't too rambly. This is sort of a brain dump of a > subject I've been thinking about for months as I've used RSpec. > > Let's say we've got a simple query method, that will find all the > users in the DB older than 18. Our model could look like > > class User < ActiveRecord::Base > def self.find_older_than(age) > find :all, :conditions => ["age > ?", age] > end > end > > What would our spec look like? > > specify "should find all users over the given age" do > User.should_receive(:find).with(:all, :conditions => ["age > ?", 18]) > User.find_older_than 18 > end > > I don't know about you, but to me that sucks. There is no TDD rhythm > there. We write a failing spec, but it's a fairly complex spec. On > top of that we've basically implemented the method from within the > spec. That's not TDD. > > We also can't refactor. Let's say that at some point we decided to > change the method to > > def User.find_older_than(age) > find(:all).select {|u| u.age > age } > end > > Our spec would break, even though the semantics of > User.find_older_than hasn't changed. > > Okay, so it's just a crappy spec. But how do we change it? Lots of > people suggest stubbing out DB calls. There's no sense in testing the > same thing over and over - namely that you have a connection and your > ORM tool is working correctly. > > I'm beginning to think that most of the time, you don't want to use a > test DB at all. When you're testing an AR model, just use an > in-memory record and stub any associations you need. But when you do > do something that interacts with the database - like doing a custom > find - you need to use the database to make sure that you're getting > the right results. Whether you use fixtures or create some records in > the setup method, you have to actually hit the db. > > Let me know what you think. I'm completely open to the idea that I've > missed something pathetically obvious. > Only mock AR when you're speccing code that *interacts* with AR (controllers and views). Don't mock AR in specs for AR subclasses - let them go against a real database. Don't mock APIs you don't own. See http://www.jmock.org/oopsla2004.pdf for more on this HTH, Aslak > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From srbaker at pobox.com Thu Feb 22 16:33:09 2007 From: srbaker at pobox.com (Steven Baker) Date: Thu, 22 Feb 2007 13:33:09 -0800 Subject: [rspec-users] We can't 100% remove our unit tests from the database, can we? In-Reply-To: <810a540e0702221241w41597932k3710e427b6a04ea0@mail.gmail.com> References: <810a540e0702221241w41597932k3710e427b6a04ea0@mail.gmail.com> Message-ID: <6AB78F93-9EA6-469A-BFB2-C73D8DCB9D12@pobox.com> On 22-Feb-07, at 12:41 PM, Pat Maddox wrote: > I hope this isn't too rambly. This is sort of a brain dump of a > subject I've been thinking about for months as I've used RSpec. > > Let's say we've got a simple query method, that will find all the > users in the DB older than 18. Our model could look like The way you describe is the way to do this. It sucks, but it's not our fault, it's ActiveRecord's fault. AcitveRecord has extra suckage, baked in for free. You don't even have to pay extra. -Steven From nicksieger at gmail.com Thu Feb 22 17:08:29 2007 From: nicksieger at gmail.com (Nick Sieger) Date: Thu, 22 Feb 2007 16:08:29 -0600 Subject: [rspec-users] We can't 100% remove our unit tests from the database, can we? In-Reply-To: <810a540e0702221241w41597932k3710e427b6a04ea0@mail.gmail.com> References: <810a540e0702221241w41597932k3710e427b6a04ea0@mail.gmail.com> Message-ID: On 2/22/07, Pat Maddox wrote: > > > specify "should find all users over the given age" do > User.should_receive(:find).with(:all, :conditions => ["age > ?", 18]) > User.find_older_than 18 > end I don't have a good suggestion here, but an observation is that the spec is too fine-grained and brittle, which, as you mention below, inhibits refactoring and TDD flow, etc. I don't know about you, but to me that sucks. There is no TDD rhythm > there. We write a failing spec, but it's a fairly complex spec. On > top of that we've basically implemented the method from within the > spec. That's not TDD. > > We also can't refactor. Let's say that at some point we decided to > change the method to > > def User.find_older_than(age) > find(:all).select {|u| u.age > age } > end > > Our spec would break, even though the semantics of > User.find_older_than hasn't changed. I have experienced similar troubles as you have in the past, and the usage of mock-based testing in these scenarios still hasn't fully clicked for me either. I know something's not right, but I can't put my finger on what it is. I suspect it's that the APIs you're working with are too data-intensive and not message-intensive (i.e., "tell don't ask"), which is where mock testing really shines. I'll defer to this post from Steve Freeman (there are probably other entries too that are similar), and the quote that apparently originates from Joe Walnes, "Don't mock types you don't own". http://stevef.truemesh.com/archives/000194.html I'm beginning to think that most of the time, you don't want to use a > test DB at all. When you're testing an AR model, just use an > in-memory record and stub any associations you need. But when you do > do something that interacts with the database - like doing a custom > find - you need to use the database to make sure that you're getting > the right results. Whether you use fixtures or create some records in > the setup method, you have to actually hit the db. I don't have a better answer, so maybe your instinct is right here -- don't fight with brittle mocks, if the database works for you and doesn't slow you down too much. I would think Dave, David and Aslak would have good input on this topic, and hope they have a moment to share their experiences. Cheers, /Nick -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070222/0dfbdffa/attachment-0001.html From dchelimsky at gmail.com Thu Feb 22 17:09:11 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 22 Feb 2007 16:09:11 -0600 Subject: [rspec-users] We can't 100% remove our unit tests from the database, can we? In-Reply-To: <810a540e0702221241w41597932k3710e427b6a04ea0@mail.gmail.com> References: <810a540e0702221241w41597932k3710e427b6a04ea0@mail.gmail.com> Message-ID: <57c63afe0702221409l4a3fddfcs33e7ba0c49bd4942@mail.gmail.com> On 2/22/07, Pat Maddox wrote: > I hope this isn't too rambly. This is sort of a brain dump of a > subject I've been thinking about for months as I've used RSpec. > > Let's say we've got a simple query method, that will find all the > users in the DB older than 18. Our model could look like > > class User < ActiveRecord::Base > def self.find_older_than(age) > find :all, :conditions => ["age > ?", age] > end > end > > What would our spec look like? > > specify "should find all users over the given age" do > User.should_receive(:find).with(:all, :conditions => ["age > ?", 18]) > User.find_older_than 18 > end > > I don't know about you, but to me that sucks. There is no TDD rhythm > there. We write a failing spec, but it's a fairly complex spec. On > top of that we've basically implemented the method from within the > spec. That's not TDD. > > We also can't refactor. Let's say that at some point we decided to > change the method to > > def User.find_older_than(age) > find(:all).select {|u| u.age > age } > end > > Our spec would break, even though the semantics of > User.find_older_than hasn't changed. > > Okay, so it's just a crappy spec. But how do we change it? Lots of > people suggest stubbing out DB calls. There's no sense in testing the > same thing over and over - namely that you have a connection and your > ORM tool is working correctly. > > I'm beginning to think that most of the time, you don't want to use a > test DB at all. When you're testing an AR model, just use an > in-memory record and stub any associations you need. But when you do > do something that interacts with the database - like doing a custom > find - you need to use the database to make sure that you're getting > the right results. Whether you use fixtures or create some records in > the setup method, you have to actually hit the db. > > Let me know what you think. I'm completely open to the idea that I've > missed something pathetically obvious. This is a tricky thing in Rails. Michael Feathers sets some good boundaries around unit testing in a blog entry: http://www.artima.com/weblogs/viewpost.jsp?thread=126923. You'll note that the first thing it says is "A test is not a unit test if: it talks to a database." So along comes Rails and Rails says "unit tests test models, which talk to the database". So we have some confusion to get past right away. So let's say we agree that unit tests should never talk to a database. If we agree on that definition, then we can agree that testing that custom finds work correctly can not really be a unit test. So then the question becomes not whether we should use the database for those tests, but rather what we call those tests and where they go in our test or spec directories. One option is to leave them under test/units or spec/models. If the time to run the suite isn't impeding your work, then this might be OK. Another option is to separate out model specs that interact w/ the DB from those that don't in two separate directories and set up rake tasks to run all the non-db stuff or include the db stuff at your whim. Keep in mind that the important thing about all of this is that the quicker you can run specs the more often you will, and tighter the feedback loop, and the less time you'll spend debugging code that you just wrote! Hope that's helpful. Cheers, David > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Thu Feb 22 17:22:21 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 22 Feb 2007 16:22:21 -0600 Subject: [rspec-users] specking, speccing, or spec'ing Message-ID: <57c63afe0702221422s420b4f03hcad37e1a97e3f834@mail.gmail.com> I vote for spec'ing. Anybody else? From dchelimsky at gmail.com Thu Feb 22 17:32:21 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 22 Feb 2007 16:32:21 -0600 Subject: [rspec-users] We can't 100% remove our unit tests from the database, can we? In-Reply-To: <8d961d900702221342t4c889305s2ecd0b7681be08fc@mail.gmail.com> References: <810a540e0702221241w41597932k3710e427b6a04ea0@mail.gmail.com> <8d961d900702221342t4c889305s2ecd0b7681be08fc@mail.gmail.com> Message-ID: <57c63afe0702221432w2ca36ba8h6b16bac7b64e3107@mail.gmail.com> On 2/22/07, aslak hellesoy wrote: > On 2/22/07, Pat Maddox wrote: > > I hope this isn't too rambly. This is sort of a brain dump of a > > subject I've been thinking about for months as I've used RSpec. > > > > Let's say we've got a simple query method, that will find all the > > users in the DB older than 18. Our model could look like > > > > class User < ActiveRecord::Base > > def self.find_older_than(age) > > find :all, :conditions => ["age > ?", age] > > end > > end > > > > What would our spec look like? > > > > specify "should find all users over the given age" do > > User.should_receive(:find).with(:all, :conditions => ["age > ?", 18]) > > User.find_older_than 18 > > end > > > > I don't know about you, but to me that sucks. There is no TDD rhythm > > there. We write a failing spec, but it's a fairly complex spec. On > > top of that we've basically implemented the method from within the > > spec. That's not TDD. > > > > We also can't refactor. Let's say that at some point we decided to > > change the method to > > > > def User.find_older_than(age) > > find(:all).select {|u| u.age > age } > > end > > > > Our spec would break, even though the semantics of > > User.find_older_than hasn't changed. > > > > Okay, so it's just a crappy spec. But how do we change it? Lots of > > people suggest stubbing out DB calls. There's no sense in testing the > > same thing over and over - namely that you have a connection and your > > ORM tool is working correctly. > > > > I'm beginning to think that most of the time, you don't want to use a > > test DB at all. When you're testing an AR model, just use an > > in-memory record and stub any associations you need. But when you do > > do something that interacts with the database - like doing a custom > > find - you need to use the database to make sure that you're getting > > the right results. Whether you use fixtures or create some records in > > the setup method, you have to actually hit the db. > > > > Let me know what you think. I'm completely open to the idea that I've > > missed something pathetically obvious. > > > > Only mock AR when you're speccing code that *interacts* with AR > (controllers and views). > > Don't mock AR in specs for AR subclasses - let them go against a real database. > > Don't mock APIs you don't own. > See http://www.jmock.org/oopsla2004.pdf for more on this > > HTH, > Aslak I agree w/ Aslak in principle. The problem is that in an effort to make life seemingly easier for you and me, AR forces us to couple our business logic with our persistence logic, which puts us in a catch 22 vis a vis pre-Rails thinking about testing and mocking. We can either test these things separately, which requires that we mock code we didn't write, or we adhere to only mocking code we don't own, which requires us to test two concepts together. Alternatively, we could add concepts to our rails apps to decouple these things - non-AR model classes that delegate to AR backed models - ModelFactories so we don't call class methods on the model classes, etc. My instinct is that it would be more complicated that its worth. Has anyone experimented w/ anything like that? > > > Pat > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From graeme.nelson at gmail.com Thu Feb 22 17:43:53 2007 From: graeme.nelson at gmail.com (Graeme Nelson) Date: Thu, 22 Feb 2007 14:43:53 -0800 Subject: [rspec-users] specking, speccing, or spec'ing In-Reply-To: <57c63afe0702221422s420b4f03hcad37e1a97e3f834@mail.gmail.com> References: <57c63afe0702221422s420b4f03hcad37e1a97e3f834@mail.gmail.com> Message-ID: I vote for spec'ing too! Graeme On Feb 22, 2007, at 2:22 PM, David Chelimsky wrote: > I vote for spec'ing. > > Anybody else? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From court3nay at gmail.com Thu Feb 22 18:15:05 2007 From: court3nay at gmail.com (Courtenay) Date: Thu, 22 Feb 2007 15:15:05 -0800 Subject: [rspec-users] specking, speccing, or spec'ing In-Reply-To: <57c63afe0702221422s420b4f03hcad37e1a97e3f834@mail.gmail.com> References: <57c63afe0702221422s420b4f03hcad37e1a97e3f834@mail.gmail.com> Message-ID: <4b430c8f0702221515t254c73b9oa9243367d194ae2a@mail.gmail.com> On 2/22/07, David Chelimsky wrote: > I vote for spec'ing. > what a spectacle From work at ashleymoran.me.uk Fri Feb 23 06:27:09 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Fri, 23 Feb 2007 11:27:09 +0000 Subject: [rspec-users] specking, speccing, or spec'ing In-Reply-To: <57c63afe0702221422s420b4f03hcad37e1a97e3f834@mail.gmail.com> References: <57c63afe0702221422s420b4f03hcad37e1a97e3f834@mail.gmail.com> Message-ID: <000C3D79-7C6D-4981-92AB-F401FCAF6477@ashleymoran.me.uk> On 22 Feb 2007, at 22:22, David Chelimsky wrote: > I vote for spec'ing. I've always typed speccing, but according to /usr/share/dict/web2 there isn't another english word that ends 'ccing', and all the words that end 'cking' are made from words that end 'ck' anyway. So I'll have to go with spec'ing, even if it does look like its written in klingon. (Actually I might just write my emails in TextMate, and write spec) From work at ashleymoran.me.uk Fri Feb 23 07:20:00 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Fri, 23 Feb 2007 12:20:00 +0000 Subject: [rspec-users] We can't 100% remove our unit tests from the database, can we? In-Reply-To: <57c63afe0702221432w2ca36ba8h6b16bac7b64e3107@mail.gmail.com> References: <810a540e0702221241w41597932k3710e427b6a04ea0@mail.gmail.com> <8d961d900702221342t4c889305s2ecd0b7681be08fc@mail.gmail.com> <57c63afe0702221432w2ca36ba8h6b16bac7b64e3107@mail.gmail.com> Message-ID: <84F1CA1D-1DBA-4756-B6EA-421375DF95F7@ashleymoran.me.uk> Three replies for the price of one... I was about to reply to this: On 22 Feb 2007, at 22:08, Nick Sieger wrote: > Joe Walnes, "Don't mock types you don't own" Idiot question... doesn't this preclude stubbing methods like ActiveRecord::Base.find? Or have I misunderstood? Then I saw this, which kinda answers it: On 22 Feb 2007, at 22:32, David Chelimsky wrote: > The problem is that in an effort to make life seemingly easier for you > and me, AR forces us to couple our business logic with our persistence > logic, which puts us in a catch 22 vis a vis pre-Rails thinking about > testing and mocking. We can either test these things separately, which > requires that we mock code we didn't write, or we adhere to only > mocking code we don't own, which requires us to test two concepts > together. > > Alternatively, we could add concepts to our rails apps to decouple > these things - non-AR model classes that delegate to AR backed models > - ModelFactories so we don't call class methods on the model classes, > etc. My instinct is that it would be more complicated that its worth. > > Has anyone experimented w/ anything like that? Not tried that, but I've been thinking for a while. Is it time ActiveRecord became a data mapper, that defaulted to model -> table mapping? I mean something like, class Person persistence_mapper :auto # usual stuff validates_presence_of :name end creates dynamically: PersonMapper < ActiveRecord::Base end and if you want more control, class FinanceProposal # make it call ComplexFinanceProposalMapper.new or whatever persistence_mapper :complex_finance_proposal_mapper end class FinanceProposalMapper # all the overcomplicated stuff you need to do to save finance proposals, # possibly using ActiveRecord::Base subclasses to save to tables end This way you get separation of validation so you can test it independently, without losing any of the out-of-the-box simplicity. On 22 Feb 2007, at 21:33, Steven Baker wrote: > The way you describe is the way to do this. It sucks, but it's not > our fault, it's ActiveRecord's fault. AcitveRecord has extra > suckage, baked in for free. You don't even have to pay extra. It seems a bit unfair to throw too much criticism at ActiveRecord. After all, it was intended to follow the ActiveRecord pattern for simplicity (presumably convention over configuration). On the other hand, seeing as testability is pretty essential for agile development, which is one of the big selling points of Rails, it sounds like something has to be done. Might make more sense to take this to the Rails list, but I seem to spend all my time here lately. Has anyone got any experience of Og? I looked at the source recently but haven't tried to use it. How does it compare test-wise? Ashley From kevwil at gmail.com Fri Feb 23 09:28:35 2007 From: kevwil at gmail.com (Kevin Williams) Date: Fri, 23 Feb 2007 07:28:35 -0700 Subject: [rspec-users] specking, speccing, or spec'ing In-Reply-To: <000C3D79-7C6D-4981-92AB-F401FCAF6477@ashleymoran.me.uk> References: <57c63afe0702221422s420b4f03hcad37e1a97e3f834@mail.gmail.com> <000C3D79-7C6D-4981-92AB-F401FCAF6477@ashleymoran.me.uk> Message-ID: <683a886f0702230628p72fa5b68lccee849a903560b2@mail.gmail.com> I think spec'ing is pretty close to correct, but the apostrophe is a bit disconcerting. Perhaps spec-ing? Then again, why do we need a non-alphabetic character in there at all? I'd go with specing. On 2/23/07, Ashley Moran wrote: > > On 22 Feb 2007, at 22:22, David Chelimsky wrote: > > > I vote for spec'ing. > > > I've always typed speccing, but according to /usr/share/dict/web2 > there isn't another english word that ends 'ccing', and all the words > that end 'cking' are made from words that end 'ck' anyway. So I'll > have to go with spec'ing, even if it does look like its written in > klingon. (Actually I might just write my emails in TextMate, and > write spec) > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Cheers, Kevin Williams http://www.almostserio.us/ "Any sufficiently advanced technology is indistinguishable from Magic." - Arthur C. Clarke From work at ashleymoran.me.uk Fri Feb 23 10:59:02 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Fri, 23 Feb 2007 15:59:02 +0000 Subject: [rspec-users] Deferred success for specs? Message-ID: <5B7C1D16-6323-4E3A-B9E0-D5A819B76FDC@ashleymoran.me.uk> I've started using specs as a to-do list. I write explicitly violated specs so I know what to come back to. But a lot of the time, that means if I start to work on another piece of functionality covered by the same spec, it's hard to tell what I'm working on now from the explicit failues. I run all my specs through TextMate to use the HTML output, so I go by the "95 specifications, 3 failures" line at the top. I'd find it useful if I could mark specs as failing but unimportant, eg "95 specifications, 1 failure, 2 deferred". You could even display these limbo specs in orange to separate them visually. Anyone else think this is a good idea, or is there too much chance of it being abused as a way of saying, "I'll get round to it when I can be bothered"? It's definitely better than commenting out specs, which is really risky. Ashley From dchelimsky at gmail.com Fri Feb 23 12:08:42 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 23 Feb 2007 11:08:42 -0600 Subject: [rspec-users] Deferred success for specs? In-Reply-To: <5B7C1D16-6323-4E3A-B9E0-D5A819B76FDC@ashleymoran.me.uk> References: <5B7C1D16-6323-4E3A-B9E0-D5A819B76FDC@ashleymoran.me.uk> Message-ID: <57c63afe0702230908h1eb1d771x7abfd26253bf9fc7@mail.gmail.com> On 2/23/07, Ashley Moran wrote: > I've started using specs as a to-do list. I write explicitly > violated specs so I know what to come back to. But a lot of the > time, that means if I start to work on another piece of functionality > covered by the same spec, it's hard to tell what I'm working on now > from the explicit failues. > > I run all my specs through TextMate to use the HTML output, so I go > by the "95 specifications, 3 failures" line at the top. I'd find it > useful if I could mark specs as failing but unimportant, eg "95 > specifications, 1 failure, 2 deferred". You could even display these > limbo specs in orange to separate them visually. > > Anyone else think this is a good idea, or is there too much chance of > it being abused as a way of saying, "I'll get round to it when I can > be bothered"? It's definitely better than commenting out specs, > which is really risky. There is a similar RFE: http://rubyforge.org/tracker/index.php?func=detail&aid=8139&group_id=797&atid=3152 Also, the rspec-ext project does something like this: http://rashkovskii.com/articles/2007/2/16/rspec-ext-gem > > Ashley > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From svenfuchs at artweb-design.de Fri Feb 23 12:12:37 2007 From: svenfuchs at artweb-design.de (Sven Fuchs) Date: Fri, 23 Feb 2007 18:12:37 +0100 Subject: [rspec-users] Deferred success for specs? In-Reply-To: <5B7C1D16-6323-4E3A-B9E0-D5A819B76FDC@ashleymoran.me.uk> References: <5B7C1D16-6323-4E3A-B9E0-D5A819B76FDC@ashleymoran.me.uk> Message-ID: <48AE3671-652B-417A-85DF-2792283B023D@artweb-design.de> *de-lurking*, ... so let me first thank you guys for rspec! That's an absolute amazing tool :-) Am 23.02.2007 um 16:59 schrieb Ashley Moran: > I've started using specs as a to-do list. I write explicitly > violated specs so I know what to come back to. But a lot of the > time, that means if I start to work on another piece of functionality > covered by the same spec, it's hard to tell what I'm working on now > from the explicit failues. > > I run all my specs through TextMate to use the HTML output, so I go > by the "95 specifications, 3 failures" line at the top. I'd find it > useful if I could mark specs as failing but unimportant, eg "95 > specifications, 1 failure, 2 deferred". You could even display these > limbo specs in orange to separate them visually. seems to describe something similar, does it? -- sven fuchs fon: +49 (58 45) 98 89 58 artweb design fax: +49 (58 45) 98 89 57 breite stra?e 65 www: http://www.artweb-design.de de-29468 bergen mail: svenfuchs at artweb-design.de From keith.mcdonnell at redbrick.dcu.ie Fri Feb 23 11:08:14 2007 From: keith.mcdonnell at redbrick.dcu.ie (Keith McDonnell) Date: Fri, 23 Feb 2007 16:08:14 +0000 Subject: [rspec-users] rspec on rails 0 7 5 1 Message-ID: <45DF116E.8030200@redbrick.dcu.ie> Hi there, I can't upgrade rspec on rails to 0.7.5.1. I followed the install guide on the website without sucsess. Here's my env info: $ rails -v Rails 1.2.2 $ gem -v 0.9.2 $ spec -v RSpec-0.7.5.1 (r1395) - BDD for Ruby http://rspec.rubyforge.org/ $ spec ... ############################################################################ Your RSpec on Rails plugin is incompatible with your installed RSpec. RSpec : 0.7.5.1 (r1395) RSpec on Rails : r1201 Should the RSpec on Rails version number be up around 1500 and not 1201 ? Is spec using the older plugin ? Keith From aslak.hellesoy at gmail.com Fri Feb 23 13:32:06 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Fri, 23 Feb 2007 19:32:06 +0100 Subject: [rspec-users] We can't 100% remove our unit tests from the database, can we? In-Reply-To: <84F1CA1D-1DBA-4756-B6EA-421375DF95F7@ashleymoran.me.uk> References: <810a540e0702221241w41597932k3710e427b6a04ea0@mail.gmail.com> <8d961d900702221342t4c889305s2ecd0b7681be08fc@mail.gmail.com> <57c63afe0702221432w2ca36ba8h6b16bac7b64e3107@mail.gmail.com> <84F1CA1D-1DBA-4756-B6EA-421375DF95F7@ashleymoran.me.uk> Message-ID: <8d961d900702231032r5b32738cw75e774c3b72332f9@mail.gmail.com> On 2/23/07, Ashley Moran wrote: > Three replies for the price of one... > > I was about to reply to this: > > On 22 Feb 2007, at 22:08, Nick Sieger wrote: > > Joe Walnes, "Don't mock types you don't own" > This is a guideline, not an absolute truth. > Idiot question... doesn't this preclude stubbing methods like > ActiveRecord::Base.find? Or have I misunderstood? > It's ok(ish) to stub/mock at the "surface" of an API. But once you start stubbing/mocking methods that the "surface" API calls (i.e. what AR.find calls) then you're in trouble land. > > Then I saw this, which kinda answers it: > > On 22 Feb 2007, at 22:32, David Chelimsky wrote: > > > The problem is that in an effort to make life seemingly easier for you > > and me, AR forces us to couple our business logic with our persistence > > logic, which puts us in a catch 22 vis a vis pre-Rails thinking about > > testing and mocking. We can either test these things separately, which > > requires that we mock code we didn't write, or we adhere to only > > mocking code we don't own, which requires us to test two concepts > > together. > > > > Alternatively, we could add concepts to our rails apps to decouple > > these things - non-AR model classes that delegate to AR backed models > > - ModelFactories so we don't call class methods on the model classes, > > etc. My instinct is that it would be more complicated that its worth. > > > > Has anyone experimented w/ anything like that? > > Not tried that, but I've been thinking for a while. Is it time > ActiveRecord became a data mapper, that defaulted to model -> table > mapping? I mean something like, > > class Person > persistence_mapper :auto > > # usual stuff > validates_presence_of :name > end > > creates dynamically: > > PersonMapper < ActiveRecord::Base > end > > and if you want more control, > > class FinanceProposal > # make it call ComplexFinanceProposalMapper.new or whatever > persistence_mapper :complex_finance_proposal_mapper > end > > class FinanceProposalMapper > # all the overcomplicated stuff you need to do to save finance > proposals, > # possibly using ActiveRecord::Base subclasses to save to tables > end > > This way you get separation of validation so you can test it > independently, without losing any of the out-of-the-box simplicity. > > > On 22 Feb 2007, at 21:33, Steven Baker wrote: > > The way you describe is the way to do this. It sucks, but it's not > > our fault, it's ActiveRecord's fault. AcitveRecord has extra > > suckage, baked in for free. You don't even have to pay extra. > > It seems a bit unfair to throw too much criticism at ActiveRecord. > After all, it was intended to follow the ActiveRecord pattern for > simplicity (presumably convention over configuration). On the other > hand, seeing as testability is pretty essential for agile > development, which is one of the big selling points of Rails, it > sounds like something has to be done. Might make more sense to take > this to the Rails list, but I seem to spend all my time here lately. > > Has anyone got any experience of Og? I looked at the source recently > but haven't tried to use it. How does it compare test-wise? > > Ashley > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From keith at dancingtext.com Fri Feb 23 13:33:35 2007 From: keith at dancingtext.com (Keith McDonnell) Date: Fri, 23 Feb 2007 18:33:35 +0000 Subject: [rspec-users] rspec on rails 0 7 5 1 >> IGNORE last Message-ID: <45DF337F.1050008@dancingtext.com> Hi all, Please ignore my last mail (see below). I forgot to run ./script/generate rspec after upgrading. I thought that generate was for new spec installation not an upgrade. D'oh! Keith ---------------------- Hi there, I can't upgrade rspec on rails to 0.7.5.1. I followed the install guide on the website without sucsess. Here's my env info: $ rails -v Rails 1.2.2 $ gem -v 0.9.2 $ spec -v RSpec-0.7.5.1 (r1395) - BDD for Ruby http://rspec.rubyforge.org/ $ spec ... ############################################################################ Your RSpec on Rails plugin is incompatible with your installed RSpec. RSpec : 0.7.5.1 (r1395) RSpec on Rails : r1201 Should the RSpec on Rails version number be up around 1500 and not 1201 ? Is spec using the older plugin ? Keith From dchelimsky at gmail.com Fri Feb 23 13:41:31 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 23 Feb 2007 12:41:31 -0600 Subject: [rspec-users] rspec on rails 0 7 5 1 In-Reply-To: <45DF116E.8030200@redbrick.dcu.ie> References: <45DF116E.8030200@redbrick.dcu.ie> Message-ID: <57c63afe0702231041pe94f94eu5cf68ea0591a739c@mail.gmail.com> On 2/23/07, Keith McDonnell wrote: > Hi there, > > I can't upgrade rspec on rails to 0.7.5.1. I followed the install guide > on the website without sucsess. Here's my env info: > > $ rails -v > Rails 1.2.2 > > $ gem -v > 0.9.2 > > $ spec -v > RSpec-0.7.5.1 (r1395) - BDD for Ruby > http://rspec.rubyforge.org/ > > $ spec ... > > > ############################################################################ > Your RSpec on Rails plugin is incompatible with your installed RSpec. > > RSpec : 0.7.5.1 (r1395) > RSpec on Rails : r1201 > > Should the RSpec on Rails version number be up around 1500 and not 1201 > ? Is spec using the older plugin ? http://rspec.rubyforge.org/documentation/rails/install.html You need to update your gem. Spec::Rails is an extension of rspec, but it still depends on rspec and, for the time being, the revision numbers must match. > > Keith > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From keith at dancingtext.com Fri Feb 23 13:21:27 2007 From: keith at dancingtext.com (Keith McDonnell) Date: Fri, 23 Feb 2007 18:21:27 +0000 Subject: [rspec-users] rspec on rails 0 7 5 1 Message-ID: <45DF30A7.40308@dancingtext.com> Hi there, I can't upgrade rspec on rails to 0.7.5.1. I followed the install guide on the website without sucsess. Here's my env info: $ rails -v Rails 1.2.2 $ gem -v 0.9.2 $ spec -v RSpec-0.7.5.1 (r1395) - BDD for Ruby http://rspec.rubyforge.org/ $ spec ... ############################################################################ Your RSpec on Rails plugin is incompatible with your installed RSpec. RSpec : 0.7.5.1 (r1395) RSpec on Rails : r1201 Should the RSpec on Rails version number be up around 1500 and not 1201 ? Is spec using the older plugin ? Keith From aslak.hellesoy at gmail.com Fri Feb 23 13:55:41 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Fri, 23 Feb 2007 19:55:41 +0100 Subject: [rspec-users] specking, speccing, or spec'ing In-Reply-To: <683a886f0702230628p72fa5b68lccee849a903560b2@mail.gmail.com> References: <57c63afe0702221422s420b4f03hcad37e1a97e3f834@mail.gmail.com> <000C3D79-7C6D-4981-92AB-F401FCAF6477@ashleymoran.me.uk> <683a886f0702230628p72fa5b68lccee849a903560b2@mail.gmail.com> Message-ID: <8d961d900702231055j3b6aba72s1377c9acb5e9c3d3@mail.gmail.com> On 2/23/07, Kevin Williams wrote: > I think spec'ing is pretty close to correct, but the apostrophe is a > bit disconcerting. Perhaps spec-ing? Then again, why do we need a > non-alphabetic character in there at all? I'd go with specing. > > On 2/23/07, Ashley Moran wrote: > > > > On 22 Feb 2007, at 22:22, David Chelimsky wrote: > > > > > I vote for spec'ing. > > > > > > I've always typed speccing, but according to /usr/share/dict/web2 > > there isn't another english word that ends 'ccing', and all the words > > that end 'cking' are made from words that end 'ck' anyway. So I'll > > have to go with spec'ing, even if it does look like its written in > > klingon. (Actually I might just write my emails in TextMate, and > > write spec) > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > What's wrong with "specifying"? I'm also a little less afraid of "testing" than I used to be. Aslak > > -- > Cheers, > > Kevin Williams > http://www.almostserio.us/ > > "Any sufficiently advanced technology is indistinguishable from > Magic." - Arthur C. Clarke > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From hughes.james at gmail.com Fri Feb 23 14:35:08 2007 From: hughes.james at gmail.com (James Hughes) Date: Fri, 23 Feb 2007 11:35:08 -0800 Subject: [rspec-users] specking, speccing, or spec'ing In-Reply-To: <8d961d900702231055j3b6aba72s1377c9acb5e9c3d3@mail.gmail.com> References: <57c63afe0702221422s420b4f03hcad37e1a97e3f834@mail.gmail.com> <000C3D79-7C6D-4981-92AB-F401FCAF6477@ashleymoran.me.uk> <683a886f0702230628p72fa5b68lccee849a903560b2@mail.gmail.com> <8d961d900702231055j3b6aba72s1377c9acb5e9c3d3@mail.gmail.com> Message-ID: <765a2c230702231135t55143cf9y32e48e549c049c36@mail.gmail.com> On 2/23/07, aslak hellesoy wrote: > On 2/23/07, Kevin Williams wrote: > > I think spec'ing is pretty close to correct, but the apostrophe is a > > bit disconcerting. Perhaps spec-ing? Then again, why do we need a > > non-alphabetic character in there at all? I'd go with specing. > > > > On 2/23/07, Ashley Moran wrote: > > > > > > On 22 Feb 2007, at 22:22, David Chelimsky wrote: > > > > > > > I vote for spec'ing. > > > > > > > > > I've always typed speccing, but according to /usr/share/dict/web2 > > > there isn't another english word that ends 'ccing', and all the words > > > that end 'cking' are made from words that end 'ck' anyway. So I'll > > > have to go with spec'ing, even if it does look like its written in > > > klingon. (Actually I might just write my emails in TextMate, and > > > write spec) > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > What's wrong with "specifying"? > I'm also a little less afraid of "testing" than I used to be. Whoa. My heresy vs. pragmatism meter is wildly fluctuating. +1 for "specifying". What does specing/spec'ing refer to? The act of writing specs, or running them? James > > Aslak > > > > > -- > > Cheers, > > > > Kevin Williams > > http://www.almostserio.us/ > > > > "Any sufficiently advanced technology is indistinguishable from > > Magic." - Arthur C. Clarke > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Fri Feb 23 14:59:17 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 23 Feb 2007 13:59:17 -0600 Subject: [rspec-users] specking, speccing, or spec'ing In-Reply-To: <765a2c230702231135t55143cf9y32e48e549c049c36@mail.gmail.com> References: <57c63afe0702221422s420b4f03hcad37e1a97e3f834@mail.gmail.com> <000C3D79-7C6D-4981-92AB-F401FCAF6477@ashleymoran.me.uk> <683a886f0702230628p72fa5b68lccee849a903560b2@mail.gmail.com> <8d961d900702231055j3b6aba72s1377c9acb5e9c3d3@mail.gmail.com> <765a2c230702231135t55143cf9y32e48e549c049c36@mail.gmail.com> Message-ID: <57c63afe0702231159i34c01dbbgb68533f9eba07fa7@mail.gmail.com> On 2/23/07, James Hughes wrote: > On 2/23/07, aslak hellesoy wrote: > > On 2/23/07, Kevin Williams wrote: > > > I think spec'ing is pretty close to correct, but the apostrophe is a > > > bit disconcerting. Perhaps spec-ing? Then again, why do we need a > > > non-alphabetic character in there at all? I'd go with specing. > > > > > > On 2/23/07, Ashley Moran wrote: > > > > > > > > On 22 Feb 2007, at 22:22, David Chelimsky wrote: > > > > > > > > > I vote for spec'ing. > > > > > > > > > > > > I've always typed speccing, but according to /usr/share/dict/web2 > > > > there isn't another english word that ends 'ccing', and all the words > > > > that end 'cking' are made from words that end 'ck' anyway. So I'll > > > > have to go with spec'ing, even if it does look like its written in > > > > klingon. (Actually I might just write my emails in TextMate, and > > > > write spec) > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > What's wrong with "specifying"? > > I'm also a little less afraid of "testing" than I used to be. > > Whoa. My heresy vs. pragmatism meter is wildly fluctuating. > > +1 for "specifying". > > What does specing/spec'ing refer to? The act of writing specs, or running them? Writing. > > James > > > > > Aslak > > > > > > > > -- > > > Cheers, > > > > > > Kevin Williams > > > http://www.almostserio.us/ > > > > > > "Any sufficiently advanced technology is indistinguishable from > > > Magic." - Arthur C. Clarke > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dgoodlad at gmail.com Fri Feb 23 15:04:50 2007 From: dgoodlad at gmail.com (David Goodlad) Date: Fri, 23 Feb 2007 12:04:50 -0800 Subject: [rspec-users] specking, speccing, or spec'ing In-Reply-To: <57c63afe0702231159i34c01dbbgb68533f9eba07fa7@mail.gmail.com> References: <57c63afe0702221422s420b4f03hcad37e1a97e3f834@mail.gmail.com> <000C3D79-7C6D-4981-92AB-F401FCAF6477@ashleymoran.me.uk> <683a886f0702230628p72fa5b68lccee849a903560b2@mail.gmail.com> <8d961d900702231055j3b6aba72s1377c9acb5e9c3d3@mail.gmail.com> <765a2c230702231135t55143cf9y32e48e549c049c36@mail.gmail.com> <57c63afe0702231159i34c01dbbgb68533f9eba07fa7@mail.gmail.com> Message-ID: On 2/23/07, David Chelimsky wrote: > On 2/23/07, James Hughes wrote: > > On 2/23/07, aslak hellesoy wrote: > > > On 2/23/07, Kevin Williams wrote: > > > > I think spec'ing is pretty close to correct, but the apostrophe is a > > > > bit disconcerting. Perhaps spec-ing? Then again, why do we need a > > > > non-alphabetic character in there at all? I'd go with specing. > > > > > > > > On 2/23/07, Ashley Moran wrote: > > > > > > > > > > On 22 Feb 2007, at 22:22, David Chelimsky wrote: > > > > > > > > > > > I vote for spec'ing. > > > > > > > > > > > > > > > I've always typed speccing, but according to /usr/share/dict/web2 > > > > > there isn't another english word that ends 'ccing', and all the words > > > > > that end 'cking' are made from words that end 'ck' anyway. So I'll > > > > > have to go with spec'ing, even if it does look like its written in > > > > > klingon. (Actually I might just write my emails in TextMate, and > > > > > write spec) > > > > > _______________________________________________ > > > > > rspec-users mailing list > > > > > rspec-users at rubyforge.org > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > What's wrong with "specifying"? > > > I'm also a little less afraid of "testing" than I used to be. > > > > Whoa. My heresy vs. pragmatism meter is wildly fluctuating. > > > > +1 for "specifying". > > > > What does specing/spec'ing refer to? The act of writing specs, or running them? > > Writing. One might say that writing specs would be 'specifying', while running those specs against real code would be 'testing' that code... Just to make things more fun ;) Dave > > > > > James > > > > > > > > Aslak > > > > > > > > > > > -- > > > > Cheers, > > > > > > > > Kevin Williams > > > > http://www.almostserio.us/ > > > > > > > > "Any sufficiently advanced technology is indistinguishable from > > > > Magic." - Arthur C. Clarke > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Dave Goodlad dgoodlad at gmail.com or dave at goodlad.ca http://david.goodlad.ca/ From mailing_lists at railsnewbie.com Fri Feb 23 16:07:10 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Fri, 23 Feb 2007 16:07:10 -0500 Subject: [rspec-users] rspec on rails 0 7 5 1 In-Reply-To: <45DF116E.8030200@redbrick.dcu.ie> References: <45DF116E.8030200@redbrick.dcu.ie> Message-ID: <8F81FF28-222E-48F3-996C-F3DD308C6420@railsnewbie.com> On Feb 23, 2007, at 11:08 AM, Keith McDonnell wrote: > > > I can't upgrade rspec on rails to 0.7.5.1. I followed the install > guide > on the website without sucsess. Here's my env info: I'm having a similar problem. I've upgraded the gem, installed rspec, rspec_autotest, and rspec_on_rails as externals in my rails vendor/plugins directory. I've also run ./script/generate rspec. Here is my message: ######################################################################## #### Your RSpec on Rails plugin is incompatible with your installed RSpec. RSpec : 0.7.5.1 (r1395) RSpec on Rails : r1522 Make sure your RSpec on Rails plugin is compatible with your RSpec gem. See http://rspec.rubyforge.org/documentation/rails/install.html for details. ######################################################################## #### The svn::externals update: euclid% svn update Fetching external item into 'vendor/rails' External at revision 6216. Fetching external item into 'vendor/plugins/rav' External at revision 30. Fetching external item into 'vendor/plugins/acts_as_authenticated' External at revision 2757. Fetching external item into 'vendor/plugins/rspec' External at revision 1522. Fetching external item into 'vendor/plugins/rspec_on_rails' External at revision 1522. Fetching external item into 'vendor/plugins/rspec_autotest' External at revision 69. At revision 42. Scott From mailing_lists at railsnewbie.com Fri Feb 23 15:53:05 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Fri, 23 Feb 2007 15:53:05 -0500 Subject: [rspec-users] Using rspec_on_rails without a test Message-ID: <43C518F3-BB39-4C8F-99C9-67B090D775DF@railsnewbie.com> Looks like you can run rspec w/out hitting the database by doing the following: 1. Setting up a new rake task which does not have db:test:prepare as a dependency: namespace :spec do desc "Run the specs under spec/models without a database" Spec::Rake::SpecTask.new(:models_no_db) do |t| t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""] t.spec_files = FileList['spec/models/**/*_spec.rb'] end end 2. Calling an error on access the database with a new helper: ENV["RAILS_ENV"] = "test" require File.expand_path(File.dirname(__FILE__) + "/../config/ environment") require 'spec/rails' # Even if you're using RSpec, RSpec on Rails is reusing some of the # Rails-specific extensions for fixtures and stubbed requests, response # and other things (via RSpec's inherit mechanism). These extensions are # tightly coupled to Test::Unit in Rails, which is why you're seeing it here. module Spec module Rails class ActiveRecord::Base def self.connection raise InvalidActionError, "You cannot access the database", caller end end end end class InvalidActionError < StandardError end The test database must still be set up in config/database.yml, and I believe it must also exist Should I also post this to the rspec rubyforge site? Best, Scott From mailing_lists at railsnewbie.com Fri Feb 23 16:14:37 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Fri, 23 Feb 2007 16:14:37 -0500 Subject: [rspec-users] Error on http://rspec.rubyforge.org/documentation/rails/install.html Message-ID: <524BF700-91C6-4241-A347-544B42C6965E@railsnewbie.com> One of the links to the subversion repository is wrong. Under the heading which starts: If your own project is in Subversion and you?d like RSpec on Rails to always follow HEAD, install with -x: the second link: ruby script/plugin install -x svn://rubyforge.org/var/svn/rspec/trunk/ rspec_on_rails/vendor/plugin/rspec_on_rails should be: ruby script/plugin install -x svn://rubyforge.org/var/svn/rspec/trunk/ rspec_on_rails/vendor/plugins/rspec_on_rails (The "plugins" is missing an "s") Scott From mailing_lists at railsnewbie.com Fri Feb 23 16:20:37 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Fri, 23 Feb 2007 16:20:37 -0500 Subject: [rspec-users] rspec on rails 0 7 5 1 In-Reply-To: <45DF116E.8030200@redbrick.dcu.ie> References: <45DF116E.8030200@redbrick.dcu.ie> Message-ID: <38F2F592-AE82-407D-AE51-3F7AF7F27747@railsnewbie.com> I should note: my problem with upgrading to the lastest subversion external is *only* a problem with running rake spec:autotest, not the regular rake spec's. I'll contact the author of that plugin for more... Scott On Feb 23, 2007, at 11:08 AM, Keith McDonnell wrote: > Hi there, > > I can't upgrade rspec on rails to 0.7.5.1. I followed the install > guide > on the website without sucsess. Here's my env info: > > $ rails -v > Rails 1.2.2 > > $ gem -v > 0.9.2 > > $ spec -v > RSpec-0.7.5.1 (r1395) - BDD for Ruby > http://rspec.rubyforge.org/ > > $ spec ... > > > ###################################################################### > ###### > Your RSpec on Rails plugin is incompatible with your installed RSpec. > > RSpec : 0.7.5.1 (r1395) > RSpec on Rails : r1201 > > Should the RSpec on Rails version number be up around 1500 and not > 1201 > ? Is spec using the older plugin ? > > Keith > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From pergesu at gmail.com Fri Feb 23 16:29:59 2007 From: pergesu at gmail.com (Pat Maddox) Date: Fri, 23 Feb 2007 14:29:59 -0700 Subject: [rspec-users] How can I spec this? The method gets passed a block... Message-ID: <810a540e0702231329u50867e7fr57c09e508e5c492e@mail.gmail.com> I'm using Jim Weirich's Builder library. The code I want to spec is xml.video do xml.id @video_id xml.views @views xml.date(@date.to_s) if @date end I'd like to mock it, rather than asserting that the XML is the right string. I can do one spec: specify "should create a video tag" do @mock_builder.should_receive(:video) do_report end but I can't do anything else. Setting an expectation for :id, :views, and :date all fail. It's obvious to me why it does...the stubbed :video method doesn't know to execute the stuff in the block. So what's the best way to spec this? Pat From dchelimsky at gmail.com Fri Feb 23 17:12:03 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 23 Feb 2007 16:12:03 -0600 Subject: [rspec-users] Error on http://rspec.rubyforge.org/documentation/rails/install.html In-Reply-To: <524BF700-91C6-4241-A347-544B42C6965E@railsnewbie.com> References: <524BF700-91C6-4241-A347-544B42C6965E@railsnewbie.com> Message-ID: <57c63afe0702231412h69794e18gca7815f179ac3aa1@mail.gmail.com> On 2/23/07, Scott Taylor wrote: > > One of the links to the subversion repository is wrong. Under the > heading which starts: > > If your own project is in Subversion and you'd like RSpec on Rails to > always follow HEAD, install with -x: > > the second link: > > ruby script/plugin install -x svn://rubyforge.org/var/svn/rspec/trunk/ > rspec_on_rails/vendor/plugin/rspec_on_rails > > should be: > > ruby script/plugin install -x svn://rubyforge.org/var/svn/rspec/trunk/ > rspec_on_rails/vendor/plugins/rspec_on_rails > > (The "plugins" is missing an "s") > > Scott Please submit things like this as bugs to the tracker: http://rubyforge.org/tracker/?group_id=797 Thanks Scott, David > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From louis.j.scoras at gmail.com Fri Feb 23 17:16:22 2007 From: louis.j.scoras at gmail.com (Louis J Scoras) Date: Fri, 23 Feb 2007 17:16:22 -0500 Subject: [rspec-users] How can I spec this? The method gets passed a block... In-Reply-To: <810a540e0702231329u50867e7fr57c09e508e5c492e@mail.gmail.com> References: <810a540e0702231329u50867e7fr57c09e508e5c492e@mail.gmail.com> Message-ID: On 2/23/07, Pat Maddox wrote: > but I can't do anything else. Setting an expectation for :id, :views, > and :date all fail. It's obvious to me why it does...the stubbed > :video method doesn't know to execute the stuff in the block. So > what's the best way to spec this? Pat; You can stub the view method in the mock and have it yield so that the block runs: specify "should create a video tag" do @mock_builder.stub!(:video).and_yield @mock_builder.should_receive(:id) do_report end Not really the cleanest solution for this spec since you really shouldn't care that view was called. That's why I stubbed it, rather than using should_receive. Not sure how else you could get around it though. -- Lou. From dchelimsky at gmail.com Fri Feb 23 17:44:08 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 23 Feb 2007 16:44:08 -0600 Subject: [rspec-users] rspec on rails 0 7 5 1 In-Reply-To: <8F81FF28-222E-48F3-996C-F3DD308C6420@railsnewbie.com> References: <45DF116E.8030200@redbrick.dcu.ie> <8F81FF28-222E-48F3-996C-F3DD308C6420@railsnewbie.com> Message-ID: <57c63afe0702231444g5333870ct99a2c807ac44c171@mail.gmail.com> On 2/23/07, Scott Taylor wrote: > > On Feb 23, 2007, at 11:08 AM, Keith McDonnell wrote: > > > > > > > I can't upgrade rspec on rails to 0.7.5.1. I followed the install > > guide > > on the website without sucsess. Here's my env info: > > > I'm having a similar problem. I've upgraded the gem, installed > rspec, rspec_autotest, and rspec_on_rails as externals in my rails > vendor/plugins directory. I've also run ./script/generate rspec. > Here is my message: > > ######################################################################## > #### > Your RSpec on Rails plugin is incompatible with your installed RSpec. > > RSpec : 0.7.5.1 (r1395) > RSpec on Rails : r1522 > > Make sure your RSpec on Rails plugin is compatible with your RSpec gem. > See http://rspec.rubyforge.org/documentation/rails/install.html for > details. > ######################################################################## > #### > > > The svn::externals update: > > euclid% svn update > > Fetching external item into 'vendor/rails' > External at revision 6216. > > > Fetching external item into 'vendor/plugins/rav' > External at revision 30. > > > Fetching external item into 'vendor/plugins/acts_as_authenticated' > External at revision 2757. > > > Fetching external item into 'vendor/plugins/rspec' > External at revision 1522. > > > Fetching external item into 'vendor/plugins/rspec_on_rails' > External at revision 1522. > > > Fetching external item into 'vendor/plugins/rspec_autotest' > External at revision 69. > > At revision 42. If you want to use the spec command as opposed to the rake tasks, then the plugin revision must match the gem revision. In this case it looks like (I might be wrong) you have the 0.7.5.1 gem, but the trunk plugin. Two options (there may be more): 1. Build and install the gem from your vendor/plugins/rspec directory (you'll have to do this every time you update rspec - I realize that is LAME and we'll come w/ a better solution sooner or later) 2. Use the rake tasks and not the spec command. I don't know anything about rspec_autotest - can you get it to use the rake tasks or does it only use the installed spec command? Please let us know if this helps. Thanks, David > > > Scott > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Sat Feb 24 05:21:25 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sat, 24 Feb 2007 05:21:25 -0500 Subject: [rspec-users] Spec failing [Possible Bug with kind_of? and instance_of?] Message-ID: I have a spec which is failing, but I just can't say why. Maybe I'm missing something painfully obvious? Here is the pastie of the results & the spec: http://pastie.caboo.se/42626 The spec to look for is "should have an array of users" I've printed out ("puts'ed") to the terminal the fact that the values are *opposite* to what the spec fails on... Thanks, all, for your help, Best Regards, Scott Taylor P.S. In the future shall I just plop in a bunch of code to my message, or is pastie a good means for delivering somewhat large chunks of code? From aslak.hellesoy at gmail.com Sat Feb 24 06:48:28 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Sat, 24 Feb 2007 12:48:28 +0100 Subject: [rspec-users] How can I spec this? The method gets passed a block... In-Reply-To: <810a540e0702231329u50867e7fr57c09e508e5c492e@mail.gmail.com> References: <810a540e0702231329u50867e7fr57c09e508e5c492e@mail.gmail.com> Message-ID: <8d961d900702240348t76130741o27aa011d62048a02@mail.gmail.com> On 2/23/07, Pat Maddox wrote: > I'm using Jim Weirich's Builder library. The code I want to spec is > > xml.video do > xml.id @video_id > xml.views @views > xml.date(@date.to_s) if @date > end > > I'd like to mock it, rather than asserting that the XML is the right > string. I can do one spec: > > specify "should create a video tag" do > @mock_builder.should_receive(:video) > do_report > end > > but I can't do anything else. Setting an expectation for :id, :views, > and :date all fail. It's obvious to me why it does...the stubbed > :video method doesn't know to execute the stuff in the block. So > what's the best way to spec this? > There is no "best" way to do anything, but in this case I think I would avoid mocking the API I don't own (builder). I would mock the objects that builder *interacts* with, kick of builder and expect the generated XML to eql some expected XML. Makes sense? > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Sat Feb 24 10:07:46 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 24 Feb 2007 09:07:46 -0600 Subject: [rspec-users] Spec failing [Possible Bug with kind_of? and instance_of?] In-Reply-To: References: Message-ID: <57c63afe0702240707w3cff0ac2n34461d4b66cfad4b@mail.gmail.com> On 2/24/07, Scott Taylor wrote: > > I have a spec which is failing, but I just can't say why. Maybe I'm > missing something painfully obvious? > > Here is the pastie of the results & the spec: > > http://pastie.caboo.se/42626 > > The spec to look for is "should have an array of users" I've printed > out ("puts'ed") to the terminal the fact that the values are > *opposite* to what the spec fails on... This is a bug related to the underscore sugar and Active Record, and is one of the many reasons we are eliminating the underscore sugar. If you use 0.8.0-RC1 or the current trunk, you can do this: @bdd.users.should be_an_instance_of(Array) and it will pass. Cheers, David > > Thanks, all, for your help, > > Best Regards, > > Scott Taylor > > > P.S. In the future shall I just plop in a bunch of code to my > message, or is pastie a good means for delivering somewhat large > chunks of code? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From chad at spicycode.com Sat Feb 24 10:23:18 2007 From: chad at spicycode.com (Chad Humphries) Date: Sat, 24 Feb 2007 10:23:18 -0500 Subject: [rspec-users] specking, speccing, or spec'ing In-Reply-To: References: <57c63afe0702221422s420b4f03hcad37e1a97e3f834@mail.gmail.com> <000C3D79-7C6D-4981-92AB-F401FCAF6477@ashleymoran.me.uk> <683a886f0702230628p72fa5b68lccee849a903560b2@mail.gmail.com> <8d961d900702231055j3b6aba72s1377c9acb5e9c3d3@mail.gmail.com> <765a2c230702231135t55143cf9y32e48e549c049c36@mail.gmail.com> <57c63afe0702231159i34c01dbbgb68533f9eba07fa7@mail.gmail.com> Message-ID: <16f722280702240723u6466affbn9f3f17b512925706@mail.gmail.com> +1 for spec'ing On 2/23/07, David Goodlad wrote: > On 2/23/07, David Chelimsky wrote: > > On 2/23/07, James Hughes wrote: > > > On 2/23/07, aslak hellesoy wrote: > > > > On 2/23/07, Kevin Williams wrote: > > > > > I think spec'ing is pretty close to correct, but the apostrophe is a > > > > > bit disconcerting. Perhaps spec-ing? Then again, why do we need a > > > > > non-alphabetic character in there at all? I'd go with specing. > > > > > > > > > > On 2/23/07, Ashley Moran wrote: > > > > > > > > > > > > On 22 Feb 2007, at 22:22, David Chelimsky wrote: > > > > > > > > > > > > > I vote for spec'ing. > > > > > > > > > > > > > > > > > > I've always typed speccing, but according to /usr/share/dict/web2 > > > > > > there isn't another english word that ends 'ccing', and all the words > > > > > > that end 'cking' are made from words that end 'ck' anyway. So I'll > > > > > > have to go with spec'ing, even if it does look like its written in > > > > > > klingon. (Actually I might just write my emails in TextMate, and > > > > > > write spec) > > > > > > _______________________________________________ > > > > > > rspec-users mailing list > > > > > > rspec-users at rubyforge.org > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > > > > What's wrong with "specifying"? > > > > I'm also a little less afraid of "testing" than I used to be. > > > > > > Whoa. My heresy vs. pragmatism meter is wildly fluctuating. > > > > > > +1 for "specifying". > > > > > > What does specing/spec'ing refer to? The act of writing specs, or running them? > > > > Writing. > > One might say that writing specs would be 'specifying', while running > those specs against real code would be 'testing' that code... Just to > make things more fun ;) > > Dave > > > > > > > > > James > > > > > > > > > > > Aslak > > > > > > > > > > > > > > -- > > > > > Cheers, > > > > > > > > > > Kevin Williams > > > > > http://www.almostserio.us/ > > > > > > > > > > "Any sufficiently advanced technology is indistinguishable from > > > > > Magic." - Arthur C. Clarke > > > > > _______________________________________________ > > > > > rspec-users mailing list > > > > > rspec-users at rubyforge.org > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > -- > Dave Goodlad > dgoodlad at gmail.com or dave at goodlad.ca > http://david.goodlad.ca/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jerry.west at ntlworld.com Sat Feb 24 13:36:36 2007 From: jerry.west at ntlworld.com (Jerry West) Date: Sat, 24 Feb 2007 18:36:36 -0000 Subject: [rspec-users] Spec failing [Possible Bug with kind_of? and instance_of?] In-Reply-To: References: Message-ID: Answer written in haste, so may well be wrong... Rails associations are not Arrays even though they claim to be. I think they are ActiveRecord::Associations::AssociationProxies; why they claim to be Array I have no idea, simply being Enumerable would have sufficed I would have imagined. Why they proxy an array rather han extending it I have no idea. I have very few ideas :-). I personally believe proxies that lie to the developer like this should Be Considered Harmful, but it's not my opinion that counts in this particular piece of opinionated software :-). I haven't yet worked out how to tell an AP from an Array. Hope this helps. Hope I've remembered correctly too! Rgds, Jerry On Sat, 24 Feb 2007 10:21:25 -0000, Scott Taylor wrote: > > I have a spec which is failing, but I just can't say why. Maybe I'm > missing something painfully obvious? > > Here is the pastie of the results & the spec: > > http://pastie.caboo.se/42626 > > The spec to look for is "should have an array of users" I've printed > out ("puts'ed") to the terminal the fact that the values are > *opposite* to what the spec fails on... > > Thanks, all, for your help, > > Best Regards, > > Scott Taylor > > > P.S. In the future shall I just plop in a bunch of code to my > message, or is pastie a good means for delivering somewhat large > chunks of code? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ From jerry.west at ntlworld.com Sat Feb 24 13:39:47 2007 From: jerry.west at ntlworld.com (Jerry West) Date: Sat, 24 Feb 2007 18:39:47 -0000 Subject: [rspec-users] associations not arrays In-Reply-To: References: Message-ID: Ah. A quick google reveals more of the mystery.. "The target of AssociationProxy is not always an instance of Array. For example, for BelongsToAssociation it's a ActiveRecord::Base instance." http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/143483 Rgds, Jerry From pergesu at gmail.com Sat Feb 24 16:06:30 2007 From: pergesu at gmail.com (Pat Maddox) Date: Sat, 24 Feb 2007 14:06:30 -0700 Subject: [rspec-users] How can I spec this? The method gets passed a block... In-Reply-To: <8d961d900702240348t76130741o27aa011d62048a02@mail.gmail.com> References: <810a540e0702231329u50867e7fr57c09e508e5c492e@mail.gmail.com> <8d961d900702240348t76130741o27aa011d62048a02@mail.gmail.com> Message-ID: <810a540e0702241306g21d396a3tcb39984dad5cfb7a@mail.gmail.com> On 2/24/07, aslak hellesoy wrote: > On 2/23/07, Pat Maddox wrote: > > I'm using Jim Weirich's Builder library. The code I want to spec is > > > > xml.video do > > xml.id @video_id > > xml.views @views > > xml.date(@date.to_s) if @date > > end > > > > I'd like to mock it, rather than asserting that the XML is the right > > string. I can do one spec: > > > > specify "should create a video tag" do > > @mock_builder.should_receive(:video) > > do_report > > end > > > > but I can't do anything else. Setting an expectation for :id, :views, > > and :date all fail. It's obvious to me why it does...the stubbed > > :video method doesn't know to execute the stuff in the block. So > > what's the best way to spec this? > > > > There is no "best" way to do anything, but in this case I think I > would avoid mocking the API I don't own (builder). I had a feeling when I posted that you would chime in with this very answer :) > I would mock the objects that builder *interacts* with, kick of > builder and expect the generated XML to eql some expected XML. I don't really follow you here with the mocking. What would I mock? I'm trying to write an object that interacts with Builder, not the other way around. In this case, I guess I should just build out the XML and verify that it's what I expect. The easiest way to do it is by converting it into a Hash, which I know should work. Something like: specify "should generate the proper XML" do Hash.from_xml(do_report).should == { "video" => { "id" => "1", "views" => "4" } } end How's that? From aslak.hellesoy at gmail.com Sun Feb 25 04:23:31 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Sun, 25 Feb 2007 10:23:31 +0100 Subject: [rspec-users] How can I spec this? The method gets passed a block... In-Reply-To: <810a540e0702241306g21d396a3tcb39984dad5cfb7a@mail.gmail.com> References: <810a540e0702231329u50867e7fr57c09e508e5c492e@mail.gmail.com> <8d961d900702240348t76130741o27aa011d62048a02@mail.gmail.com> <810a540e0702241306g21d396a3tcb39984dad5cfb7a@mail.gmail.com> Message-ID: <8d961d900702250123r653d99ck872cbcb773f108b@mail.gmail.com> On 2/24/07, Pat Maddox wrote: > On 2/24/07, aslak hellesoy wrote: > > On 2/23/07, Pat Maddox wrote: > > > I'm using Jim Weirich's Builder library. The code I want to spec is > > > > > > xml.video do > > > xml.id @video_id > > > xml.views @views > > > xml.date(@date.to_s) if @date > > > end > > > > > > I'd like to mock it, rather than asserting that the XML is the right > > > string. I can do one spec: > > > > > > specify "should create a video tag" do > > > @mock_builder.should_receive(:video) > > > do_report > > > end > > > > > > but I can't do anything else. Setting an expectation for :id, :views, > > > and :date all fail. It's obvious to me why it does...the stubbed > > > :video method doesn't know to execute the stuff in the block. So > > > what's the best way to spec this? > > > > > > > There is no "best" way to do anything, but in this case I think I > > would avoid mocking the API I don't own (builder). > > I had a feeling when I posted that you would chime in with this very answer :) > He he > > I would mock the objects that builder *interacts* with, kick of > > builder and expect the generated XML to eql some expected XML. > > I don't really follow you here with the mocking. What would I mock? > I'm trying to write an object that interacts with Builder, not the > other way around. > Sorry, I misunderstood what you were trying to do. > In this case, I guess I should just build out the XML and verify that > it's what I expect. The easiest way to do it is by converting it into > a Hash, which I know should work. > > Something like: > > specify "should generate the proper XML" do > Hash.from_xml(do_report).should == { "video" => { "id" => "1", > "views" => "4" } } > end > > How's that? Simple, brilliant. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Sun Feb 25 21:22:37 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sun, 25 Feb 2007 21:22:37 -0500 Subject: [rspec-users] drbspec - "no server running" Message-ID: <865F934A-6471-4A0D-A2F2-47DD4ACFCD25@railsnewbie.com> At times I've gotten the message "No Server Running" from drbspec with my rails app. The thing is, the drb server certainly is running! This happened a few times with my model specs. I'm not sure exactly what the problem was there - I believe I was loading up fixtures that didn't exist. I was calling fixtures :singular_table_name as opposed to fixtures :plural_table_name This time it happened with my controller. I generated the controller with the ./script/generate rspec_controller ControllerName command... It doesn't appear that the specs are setup to fail to begin with, but if this were the default behavior, one certainly shouldn't see a "No Server Running" I could create a short screen cast if someone would like me to, or elaborate... Best, Scott Taylor From mailing_lists at railsnewbie.com Sun Feb 25 22:33:08 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sun, 25 Feb 2007 22:33:08 -0500 Subject: [rspec-users] drbspec - "no server running" In-Reply-To: <865F934A-6471-4A0D-A2F2-47DD4ACFCD25@railsnewbie.com> References: <865F934A-6471-4A0D-A2F2-47DD4ACFCD25@railsnewbie.com> Message-ID: <13E0EBFE-6404-4CC1-B093-7D3A846EB14A@railsnewbie.com> I've created a little 30 second screen cast to show the problem: http://railsnewbie.com/files/screencasts/rspec_on_rails- no_server_running.mov All I did before this, as I've said in the previous email, was generate a controller with: ./script/generate rspec_controller -c CollectiveDictionary index show Best, Scott On Feb 25, 2007, at 9:22 PM, Scott Taylor wrote: > > At times I've gotten the message "No Server Running" from drbspec > with my rails app. The thing is, the drb server certainly is running! > > This happened a few times with my model specs. I'm not sure exactly > what the problem was there - I believe I was loading up fixtures that > didn't exist. I was calling fixtures :singular_table_name as opposed > to fixtures :plural_table_name > > This time it happened with my controller. I generated the controller > with the ./script/generate rspec_controller ControllerName command... > > It doesn't appear that the specs are setup to fail to begin with, but > if this were the default behavior, one certainly shouldn't see a "No > Server Running" > > I could create a short screen cast if someone would like me to, or > elaborate... > > Best, > > Scott Taylor > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From aslak.hellesoy at gmail.com Mon Feb 26 00:41:51 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Mon, 26 Feb 2007 06:41:51 +0100 Subject: [rspec-users] drbspec - "no server running" In-Reply-To: <13E0EBFE-6404-4CC1-B093-7D3A846EB14A@railsnewbie.com> References: <865F934A-6471-4A0D-A2F2-47DD4ACFCD25@railsnewbie.com> <13E0EBFE-6404-4CC1-B093-7D3A846EB14A@railsnewbie.com> Message-ID: <8d961d900702252141h15f1438dgd3f1e3209d3e4c42@mail.gmail.com> On 2/26/07, Scott Taylor wrote: > > I've created a little 30 second screen cast to show the problem: > Hey, that's a neat bug report format! Please try to uninstall your current RSpec release and install 0.8 RC1 release - I think your problem will be gone. http://www.nabble.com/-ANN--RSpec-0.8.0-RC1-t3245509.html In 0.8 you have to say spec --drb instead of drbspec (see the release notes) Also, for the future, please remember to tell us what versions of OS/Ruby/RSpec/Rails you're running. (ok, I could see you have a mac :-) HTH, Aslak > http://railsnewbie.com/files/screencasts/rspec_on_rails- > no_server_running.mov > > All I did before this, as I've said in the previous email, was > generate a controller with: > > ./script/generate rspec_controller -c CollectiveDictionary index show > > Best, > > Scott > > > On Feb 25, 2007, at 9:22 PM, Scott Taylor wrote: > > > > > At times I've gotten the message "No Server Running" from drbspec > > with my rails app. The thing is, the drb server certainly is running! > > > > This happened a few times with my model specs. I'm not sure exactly > > what the problem was there - I believe I was loading up fixtures that > > didn't exist. I was calling fixtures :singular_table_name as opposed > > to fixtures :plural_table_name > > > > This time it happened with my controller. I generated the controller > > with the ./script/generate rspec_controller ControllerName command... > > > > It doesn't appear that the specs are setup to fail to begin with, but > > if this were the default behavior, one certainly shouldn't see a "No > > Server Running" > > > > I could create a short screen cast if someone would like me to, or > > elaborate... > > > > Best, > > > > Scott Taylor > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Mon Feb 26 02:06:44 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Mon, 26 Feb 2007 02:06:44 -0500 Subject: [rspec-users] drbspec - "no server running" In-Reply-To: <8d961d900702252141h15f1438dgd3f1e3209d3e4c42@mail.gmail.com> References: <865F934A-6471-4A0D-A2F2-47DD4ACFCD25@railsnewbie.com> <13E0EBFE-6404-4CC1-B093-7D3A846EB14A@railsnewbie.com> <8d961d900702252141h15f1438dgd3f1e3209d3e4c42@mail.gmail.com> Message-ID: On Feb 26, 2007, at 12:41 AM, aslak hellesoy wrote: > On 2/26/07, Scott Taylor wrote: >> >> I've created a little 30 second screen cast to show the problem: >> > > Hey, that's a neat bug report format! > Well, there is nothing quite like sitting in a room with someone to watch them reproduce the bug; words can be vague. I suppose that this is the closest I'll get to that ideal bug report...(at least over the internet). Plus, I've been looking to put that $70 that I've spent on screencasting software to work. I have my project svn'ed, with an externals on the rspec and rspec_on_rails repositories. I'm at revision 1536 - Is this correct for RC1? Do I also need to update the gem? Best, Scott > Please try to uninstall your current RSpec release and install 0.8 RC1 > release - I think your problem will be gone. > > http://www.nabble.com/-ANN--RSpec-0.8.0-RC1-t3245509.html > > In 0.8 you have to say spec --drb instead of drbspec (see the > release notes) > > Also, for the future, please remember to tell us what versions of > OS/Ruby/RSpec/Rails you're running. (ok, I could see you have a mac > :-) > > HTH, > Aslak > >> http://railsnewbie.com/files/screencasts/rspec_on_rails- >> no_server_running.mov >> >> All I did before this, as I've said in the previous email, was >> generate a controller with: >> >> ./script/generate rspec_controller -c CollectiveDictionary index show >> >> Best, >> >> Scott >> >> >> On Feb 25, 2007, at 9:22 PM, Scott Taylor wrote: >> >>> >>> At times I've gotten the message "No Server Running" from drbspec >>> with my rails app. The thing is, the drb server certainly is >>> running! >>> >>> This happened a few times with my model specs. I'm not sure exactly >>> what the problem was there - I believe I was loading up fixtures >>> that >>> didn't exist. I was calling fixtures :singular_table_name as >>> opposed >>> to fixtures :plural_table_name >>> >>> This time it happened with my controller. I generated the >>> controller >>> with the ./script/generate rspec_controller ControllerName >>> command... >>> >>> It doesn't appear that the specs are setup to fail to begin with, >>> but >>> if this were the default behavior, one certainly shouldn't see a "No >>> Server Running" >>> >>> I could create a short screen cast if someone would like me to, or >>> elaborate... >>> >>> Best, >>> >>> Scott Taylor >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From aslak.hellesoy at gmail.com Mon Feb 26 02:52:42 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Mon, 26 Feb 2007 08:52:42 +0100 Subject: [rspec-users] drbspec - "no server running" In-Reply-To: References: <865F934A-6471-4A0D-A2F2-47DD4ACFCD25@railsnewbie.com> <13E0EBFE-6404-4CC1-B093-7D3A846EB14A@railsnewbie.com> <8d961d900702252141h15f1438dgd3f1e3209d3e4c42@mail.gmail.com> Message-ID: <8d961d900702252352v6c28cfd5v99abcd1bcded857d@mail.gmail.com> On 2/26/07, Scott Taylor wrote: > > On Feb 26, 2007, at 12:41 AM, aslak hellesoy wrote: > > > On 2/26/07, Scott Taylor wrote: > >> > >> I've created a little 30 second screen cast to show the problem: > >> > > > > Hey, that's a neat bug report format! > > > > Well, there is nothing quite like sitting in a room with someone to > watch them reproduce the bug; words can be vague. I suppose that > this is the closest I'll get to that ideal bug report...(at least > over the internet). Plus, I've been looking to put that $70 that > I've spent on screencasting software to work. > > I have my project svn'ed, with an externals on the rspec and > rspec_on_rails repositories. I'm at revision 1536 - Is this correct > for RC1? Do I also need to update the gem? > Yes - like it's described on the announcement I linked to. > Best, > > Scott > > > > > > > > > Please try to uninstall your current RSpec release and install 0.8 RC1 > > release - I think your problem will be gone. > > > > http://www.nabble.com/-ANN--RSpec-0.8.0-RC1-t3245509.html > > > > In 0.8 you have to say spec --drb instead of drbspec (see the > > release notes) > > > > Also, for the future, please remember to tell us what versions of > > OS/Ruby/RSpec/Rails you're running. (ok, I could see you have a mac > > :-) > > > > HTH, > > Aslak > > > >> http://railsnewbie.com/files/screencasts/rspec_on_rails- > >> no_server_running.mov > >> > >> All I did before this, as I've said in the previous email, was > >> generate a controller with: > >> > >> ./script/generate rspec_controller -c CollectiveDictionary index show > >> > >> Best, > >> > >> Scott > >> > >> > >> On Feb 25, 2007, at 9:22 PM, Scott Taylor wrote: > >> > >>> > >>> At times I've gotten the message "No Server Running" from drbspec > >>> with my rails app. The thing is, the drb server certainly is > >>> running! > >>> > >>> This happened a few times with my model specs. I'm not sure exactly > >>> what the problem was there - I believe I was loading up fixtures > >>> that > >>> didn't exist. I was calling fixtures :singular_table_name as > >>> opposed > >>> to fixtures :plural_table_name > >>> > >>> This time it happened with my controller. I generated the > >>> controller > >>> with the ./script/generate rspec_controller ControllerName > >>> command... > >>> > >>> It doesn't appear that the specs are setup to fail to begin with, > >>> but > >>> if this were the default behavior, one certainly shouldn't see a "No > >>> Server Running" > >>> > >>> I could create a short screen cast if someone would like me to, or > >>> elaborate... > >>> > >>> Best, > >>> > >>> Scott Taylor > >>> > >>> _______________________________________________ > >>> rspec-users mailing list > >>> rspec-users at rubyforge.org > >>> http://rubyforge.org/mailman/listinfo/rspec-users > >> > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-users at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/rspec-users > >> > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Mon Feb 26 03:00:28 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Mon, 26 Feb 2007 03:00:28 -0500 Subject: [rspec-users] drbspec - "no server running" In-Reply-To: <8d961d900702252141h15f1438dgd3f1e3209d3e4c42@mail.gmail.com> References: <865F934A-6471-4A0D-A2F2-47DD4ACFCD25@railsnewbie.com> <13E0EBFE-6404-4CC1-B093-7D3A846EB14A@railsnewbie.com> <8d961d900702252141h15f1438dgd3f1e3209d3e4c42@mail.gmail.com> Message-ID: <8F131F5F-5672-4B05-8762-CB5FD0522C53@railsnewbie.com> I removed my gem, installed the RC1...(Congratulations, btw)... I also have the project as an externals at revision 1536. I then ran ./script/generate rspec, and used the new spec --drb command. It worked for my models, but gave the same error for my controller spec. I can create another screencast if you would like, Best, Scott Mac OS X.4.8 ruby 1.8.5 (2006-12-25 patchlevel 12) [powerpc-darwin8.8.0] rails: edge, revision 6239 From aslak.hellesoy at gmail.com Mon Feb 26 05:08:22 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Mon, 26 Feb 2007 11:08:22 +0100 Subject: [rspec-users] drbspec - "no server running" In-Reply-To: <8F131F5F-5672-4B05-8762-CB5FD0522C53@railsnewbie.com> References: <865F934A-6471-4A0D-A2F2-47DD4ACFCD25@railsnewbie.com> <13E0EBFE-6404-4CC1-B093-7D3A846EB14A@railsnewbie.com> <8d961d900702252141h15f1438dgd3f1e3209d3e4c42@mail.gmail.com> <8F131F5F-5672-4B05-8762-CB5FD0522C53@railsnewbie.com> Message-ID: <8d961d900702260208w62534686i4424ec56c768c608@mail.gmail.com> On 2/26/07, Scott Taylor wrote: > > I removed my gem, installed the RC1...(Congratulations, btw)... > > I also have the project as an externals at revision 1536. I then > ran ./script/generate rspec, and used the new spec --drb command. > It worked for my models, but gave the same error for my controller spec. > > I can create another screencast if you would like, > Some detailed steps on how to reproduce this would be more helpful for us. Code. Aslak > Best, > > Scott > > > > Mac OS X.4.8 > ruby 1.8.5 (2006-12-25 patchlevel 12) [powerpc-darwin8.8.0] > rails: edge, revision 6239 > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jerry.west at ntlworld.com Mon Feb 26 05:50:03 2007 From: jerry.west at ntlworld.com (Jerry West) Date: Mon, 26 Feb 2007 10:50:03 +0000 Subject: [rspec-users] How to spec code with multiple (interacting) paths In-Reply-To: <29D1AF28-B6C3-4026-8381-38BD7D96F147@ashleymoran.me.uk> References: <45DAF202.8090902@ntlworld.com> <29D1AF28-B6C3-4026-8381-38BD7D96F147@ashleymoran.me.uk> Message-ID: <45E2BB5B.7080108@ntlworld.com> > This would be acting like a factory for all objects required by the > action, and could be specified independently. Then I wouldn't need > to check that the controller behaves correctly under 3 different > invalid models, just that if anything is invalid it behaves > correctly. (Pretty much identical to the way you spec the individual > validations in a model, then spec that the controller behaves > correctly if its invalid.) > > Maybe you were thinking along these lines? It's hard to put things > across sometimes without writing code out. > > Ashley Yes, I think so; the controller delegates the matter where possible, so your controller spec simply checks that the delegatee is called. The spec for the delegate(e) worries about ensuring that the correct outcomes arising in each of the myriad parameter combinations. I've also been puzzling over the true application of "Tell don't ask", which I haven't really wrapped my head around yet. To quote... The problem is that, as the caller, you should not be making decisions based on the state of the called object that result in you then changing the state of the object. The logic you are implementing is probably the called object's responsibility, not yours. For you to make decisions outside the object violates its encapsulation. Sure, you may say, that's obvious. I'd never write code like that. Still, it's very easy to get lulled into examining some referenced object and then calling different methods based on the results. But that may not be the best way to go about doing it. Tell the object what you want. Let it figure out how to do it. Think declaratively instead of procedurally! It is easier to stay out of this trap if you start by designing classes based on their responsibilities, you can then progress naturally to specifying commands that the class may execute, as opposed to queries that inform you as to the state of the object. From http://www.pragmaticprogrammer.com/ppllc/papers/1998_05.html I'm too used to designing my models around the data which means I always offer the equivialent of #is_valid and #set_status. Tell don't ask suggests I should be writing CreditCard#transact and returning an error if necessary. It's a bit of a sea change for me (and for DHH if I recall his early works correctly!). All part of the heavyweight model thing that seems to be in fashion, perhaps. Best wishes, Jerry From work at ashleymoran.me.uk Mon Feb 26 11:37:14 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Mon, 26 Feb 2007 16:37:14 +0000 Subject: [rspec-users] Specifying Ajax hyperlinks Message-ID: I was about to put this as a feature request but I wasn't sure if anyone would consider it useful so I thought I'd ask here. I'm not sure what the feeling on specifying links is - it strikes me as something that needs doing because it's generated code at the end of the day. I've got a few lines now along the lines of: response.should_have ".moo #quack > a[href='#'][onclick^='new Ajax.Updater('][onclick*='/product_info/rti']" part of the problem is that the CSS selector parser for should_have barfs on an embedded quote. ie, even this selector doesn't work (note extra trailing quote in attribute): %q{a[href='#'][onclick^="new Ajax.Updater('"]} But that's by the by. Another (known) issue is the inability to put the controller name in spec, because specs run in ViewSpecController, Either way, it'd be nice to have an easier way to spec link_to_remote etc, eg (I'm not using the 0.8 RC yet...) response.should_have_link_to_remote ".moo #quack >", :url => "/ product_info/rti", :update => "blah" or something along those lines. Anyone else consider this a good idea? I get the feeling I'm alone almost in using should_have (we've only got one should_have_tag left I think, to specify an attribute must be missing). Ashley From leenoori at quepica.com Mon Feb 26 13:45:04 2007 From: leenoori at quepica.com (leenoori) Date: Mon, 26 Feb 2007 19:45:04 +0100 Subject: [rspec-users] Continuing a "specify" block after failure Message-ID: <26362922-E422-40B0-BB2C-5DF0604F4003@quepica.com> I have some high-level acceptance tests that read a bunch of files, process them, and then confirm that the processed output matches the expected output. That is, for each file "a.input" I have a corresponding file "a.expected" and I basically want to churn through all of them producing "a.processed" and making sure that "a.processed" equals "a.expected" The way I currently have this is: context 'transforming files' do specify 'actual output should match expected output' do @files.each do |file| file.input.process.should == file.expected end end end The problem with this is that a failure on one file prevents all the others from being tested. What would be the "best practice" way to overcome this shortcoming? The solution I used with Test::Unit was to add an "ErrorCollector" as described here: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/138320 Basically it catches exceptions as they are raised, sending messages to the Test::Unit machinery so that the problems can be counted and reported, but continues processing. Would a similar technique be a good idea for RSpec? Or should I just restructure my specs? By that I mean something like the following (although not sure if it will work): context 'transforming files' do files.each do |file| specify 'actual output should match expected output' do file.input.process.should == file.expected end end end From dchelimsky at gmail.com Mon Feb 26 15:22:20 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 26 Feb 2007 14:22:20 -0600 Subject: [rspec-users] Continuing a "specify" block after failure In-Reply-To: <26362922-E422-40B0-BB2C-5DF0604F4003@quepica.com> References: <26362922-E422-40B0-BB2C-5DF0604F4003@quepica.com> Message-ID: <57c63afe0702261222k4b6814f7q4b8d4f196c3613fb@mail.gmail.com> On 2/26/07, leenoori wrote: > I have some high-level acceptance tests that read a bunch of files, > process them, and then confirm that the processed output matches the > expected output. That is, for each file "a.input" I have a > corresponding file "a.expected" and I basically want to churn through > all of them producing "a.processed" and making sure that > "a.processed" equals "a.expected" > > The way I currently have this is: > > context 'transforming files' do > specify 'actual output should match expected output' do > @files.each do |file| > file.input.process.should == file.expected > end > end > end > > The problem with this is that a failure on one file prevents all the > others from being tested. What would be the "best practice" way to > overcome this shortcoming? > > The solution I used with Test::Unit was to add an "ErrorCollector" as > described here: > > http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/138320 > > Basically it catches exceptions as they are raised, sending messages > to the Test::Unit machinery so that the problems can be counted and > reported, but continues processing. > > Would a similar technique be a good idea for RSpec? Or should I just > restructure my specs? By that I mean something like the following > (although not sure if it will work): > > context 'transforming files' do > files.each do |file| > specify 'actual output should match expected output' do > file.input.process.should == file.expected > end > end > end IMO, since statements about each file could fail independently, then each file wants its own specify block. So I would do it this way, with the addition of something to separate out the spec names. For example (possibly to verbose, but you get the idea): context 'transforming files' do files.each do |file| specify "actual output should match expected output (#{file.inspect})" do file.input.process.should == file.expected end end end Cheers, David > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Mon Feb 26 15:36:29 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Mon, 26 Feb 2007 15:36:29 -0500 Subject: [rspec-users] drbspec - "no server running" In-Reply-To: <8d961d900702260208w62534686i4424ec56c768c608@mail.gmail.com> References: <865F934A-6471-4A0D-A2F2-47DD4ACFCD25@railsnewbie.com> <13E0EBFE-6404-4CC1-B093-7D3A846EB14A@railsnewbie.com> <8d961d900702252141h15f1438dgd3f1e3209d3e4c42@mail.gmail.com> <8F131F5F-5672-4B05-8762-CB5FD0522C53@railsnewbie.com> <8d961d900702260208w62534686i4424ec56c768c608@mail.gmail.com> Message-ID: <520B228F-7E9F-4CCB-BB15-B5AA8C303BEE@railsnewbie.com> Here is how I reproduced it (with a new rails project): uninstall gem svn co svn://rubyforge.org/var/svn/rspec/tags/REL_0_8_0_RC1/gem gem install gem/rspec-0.8.0-RC1.gem create new rails project edit config/database.yml for sqlite3 rake rails:freeze:edge ./script/plugin install svn://rubyforge.org/var/svn/rspec/trunk/rspec ./script/plugin install svn://rubyforge.org/var/svn/rspec/trunk/ rspec_on_rails/vendor/plugins/rspec_on_rails ./script/generate rspec ./script/generate rspec_controller MyController rake db:migrate (notice that I have no tables in the database, although I don't think that it matters...) rake db:test:prepare ./script/rails_script/server spec --drb spec/controllers/my_controller_controller_spec.rb I've also created a screen cast of this, but my G4 is slow (the screencast is 6 minutes long)...so you might want to skip ahead of the downloading of edge rails, etc... http://railsnewbie.com/files/screencasts/rspec_on_rails- no_server_running2.mov I notice that if I delete all specify's and the corresponding spec's in the spec file, the error is no longer present. Look at this screen cast (this one is only 1 minute): http://railsnewbie.com/files/screencasts/rspec_on_rails- no_server_running2_part2.mov Once again, my setup: rails edge, Mac OS X.4.8 ruby 1.8.5 (2006-12-25 patchlevel 12) [powerpc-darwin8.8.0] RSpec-0.8.0 (r1497) - BDD for Ruby Let me know if I should open a bug report. Best, Scott Taylor From aslak.hellesoy at gmail.com Mon Feb 26 16:43:57 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Mon, 26 Feb 2007 22:43:57 +0100 Subject: [rspec-users] Continuing a "specify" block after failure In-Reply-To: <26362922-E422-40B0-BB2C-5DF0604F4003@quepica.com> References: <26362922-E422-40B0-BB2C-5DF0604F4003@quepica.com> Message-ID: <8d961d900702261343r3b3eddbfvd77d773284453ff8@mail.gmail.com> On 2/26/07, leenoori wrote: > I have some high-level acceptance tests that read a bunch of files, > process them, and then confirm that the processed output matches the > expected output. That is, for each file "a.input" I have a > corresponding file "a.expected" and I basically want to churn through > all of them producing "a.processed" and making sure that > "a.processed" equals "a.expected" > > The way I currently have this is: > > context 'transforming files' do > specify 'actual output should match expected output' do > @files.each do |file| > file.input.process.should == file.expected > end > end > end > > The problem with this is that a failure on one file prevents all the > others from being tested. What would be the "best practice" way to > overcome this shortcoming? > > The solution I used with Test::Unit was to add an "ErrorCollector" as > described here: > > http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/138320 > > Basically it catches exceptions as they are raised, sending messages > to the Test::Unit machinery so that the problems can be counted and > reported, but continues processing. > > Would a similar technique be a good idea for RSpec? No, because it's already supported by what you suggest below. > Or should I just > restructure my specs? Yes > By that I mean something like the following > (although not sure if it will work): > It will, with a minor modification - you should make sure the name of each specify block is different, otherwise you'll have a hard time knowing shich one failed. > context 'transforming files' do > files.each do |file| > specify 'actual output should match expected output' do > file.input.process.should == file.expected > end > end > end > I have just checked in an example that illustrates this: http://rubyforge.org/viewvc/trunk/rspec/examples/dynamic_spec.rb?revision=1537&root=rspec Aslak > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From aslak.hellesoy at gmail.com Mon Feb 26 18:45:23 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 27 Feb 2007 00:45:23 +0100 Subject: [rspec-users] drbspec - "no server running" In-Reply-To: <520B228F-7E9F-4CCB-BB15-B5AA8C303BEE@railsnewbie.com> References: <865F934A-6471-4A0D-A2F2-47DD4ACFCD25@railsnewbie.com> <13E0EBFE-6404-4CC1-B093-7D3A846EB14A@railsnewbie.com> <8d961d900702252141h15f1438dgd3f1e3209d3e4c42@mail.gmail.com> <8F131F5F-5672-4B05-8762-CB5FD0522C53@railsnewbie.com> <8d961d900702260208w62534686i4424ec56c768c608@mail.gmail.com> <520B228F-7E9F-4CCB-BB15-B5AA8C303BEE@railsnewbie.com> Message-ID: <8d961d900702261545w57d7b27bv2725cb9fa1d8f535@mail.gmail.com> On 2/26/07, Scott Taylor wrote: > > Here is how I reproduced it (with a new rails project): > > uninstall gem > svn co svn://rubyforge.org/var/svn/rspec/tags/REL_0_8_0_RC1/gem > gem install gem/rspec-0.8.0-RC1.gem > > create new rails project > edit config/database.yml for sqlite3 > > rake rails:freeze:edge > > ./script/plugin install svn://rubyforge.org/var/svn/rspec/trunk/rspec > ./script/plugin install svn://rubyforge.org/var/svn/rspec/trunk/ > rspec_on_rails/vendor/plugins/rspec_on_rails > > ./script/generate rspec > ./script/generate rspec_controller MyController > rake db:migrate (notice that I have no tables in the database, > although I don't think that it matters...) > rake db:test:prepare > ./script/rails_script/server > spec --drb spec/controllers/my_controller_controller_spec.rb > > I've also created a screen cast of this, but my G4 is slow (the > screencast is 6 minutes long)...so you might want to skip ahead of > the downloading of edge rails, etc... > > http://railsnewbie.com/files/screencasts/rspec_on_rails- > no_server_running2.mov > > > I notice that if I delete all specify's and the corresponding spec's > in the spec file, the error is no longer present. Look at this > screen cast (this one is only 1 minute): > > http://railsnewbie.com/files/screencasts/rspec_on_rails- > no_server_running2_part2.mov > > Once again, my setup: > > rails edge, > Mac OS X.4.8 > ruby 1.8.5 (2006-12-25 patchlevel 12) [powerpc-darwin8.8.0] > RSpec-0.8.0 (r1497) - BDD for Ruby > > > Let me know if I should open a bug report. > Please do, or we'll forget. Aslak > > Best, > > Scott Taylor > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Mon Feb 26 19:31:54 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Mon, 26 Feb 2007 19:31:54 -0500 Subject: [rspec-users] Fixtures in multiple directories... Message-ID: <7A76C788-E437-4B3E-B005-1D432D9B6239@railsnewbie.com> What is the best way to use fixtures in multiple directories? I have a plugin for rails which has fixtures, and uses Test::Unit. I'd prefer *not* to just copy the fixture over into the spec directory. Scott Taylor From mailing_lists at railsnewbie.com Tue Feb 27 00:43:38 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Tue, 27 Feb 2007 00:43:38 -0500 Subject: [rspec-users] On debugging rspec; running all specs under multiple directories In-Reply-To: <8d961d900702261545w57d7b27bv2725cb9fa1d8f535@mail.gmail.com> References: <865F934A-6471-4A0D-A2F2-47DD4ACFCD25@railsnewbie.com> <13E0EBFE-6404-4CC1-B093-7D3A846EB14A@railsnewbie.com> <8d961d900702252141h15f1438dgd3f1e3209d3e4c42@mail.gmail.com> <8F131F5F-5672-4B05-8762-CB5FD0522C53@railsnewbie.com> <8d961d900702260208w62534686i4424ec56c768c608@mail.gmail.com> <520B228F-7E9F-4CCB-BB15-B5AA8C303BEE@railsnewbie.com> <8d961d900702261545w57d7b27bv2725cb9fa1d8f535@mail.gmail.com> Message-ID: <501C27DA-43F0-48DE-B58D-35E6D0DFEA02@railsnewbie.com> The latest bug - the one that I've just put into the tracker - is halting all work that I'm doing on this rails project. I would like to contribute back to the community, and fix the bug for myself. Any suggestions on how to do this? Maybe some suggestions for how to debug a code base which you are unfamiliar with? One thing I would like to do is run all of the specs in the rspec library to see if they are passing. - the ones that fail will probably point to the culprit. How can I run all of the specs under one directory, if the specs are under subdirectories? This maybe more of a unix question then an rspec one... Thanks for the help, Scott Taylor From jerry.west at ntlworld.com Tue Feb 27 04:03:10 2007 From: jerry.west at ntlworld.com (Jerry West) Date: Tue, 27 Feb 2007 09:03:10 +0000 Subject: [rspec-users] On debugging rspec; running all specs under multiple directories In-Reply-To: <501C27DA-43F0-48DE-B58D-35E6D0DFEA02@railsnewbie.com> References: <865F934A-6471-4A0D-A2F2-47DD4ACFCD25@railsnewbie.com> <13E0EBFE-6404-4CC1-B093-7D3A846EB14A@railsnewbie.com> <8d961d900702252141h15f1438dgd3f1e3209d3e4c42@mail.gmail.com> <8F131F5F-5672-4B05-8762-CB5FD0522C53@railsnewbie.com> <8d961d900702260208w62534686i4424ec56c768c608@mail.gmail.com> <520B228F-7E9F-4CCB-BB15-B5AA8C303BEE@railsnewbie.com> <8d961d900702261545w57d7b27bv2725cb9fa1d8f535@mail.gmail.com> <501C27DA-43F0-48DE-B58D-35E6D0DFEA02@railsnewbie.com> Message-ID: <45E3F3CE.9000602@ntlworld.com> > One thing I would like to do is run all of the specs in the rspec > library to see if they are passing. - the ones that fail will > probably point to the culprit. How can I run all of the specs under > one directory, if the specs are under subdirectories? This maybe > more of a unix question then an rspec one... Well, for the 0.7.5.1 plugin cd $RAILSDIR; spec -cfs vendor/plugins/rspec_on_rails/spec/ I imagine the filesystem layout is the same for 0.8/trunk(?). Ironically, you can't run many of the 0.7.5.1 specs under 0.7.5.1 as they use the latest 'should' syntax available only with 0.8RC1/trunk. Hope this helps, Jerry From aslak.hellesoy at gmail.com Tue Feb 27 04:41:15 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 27 Feb 2007 10:41:15 +0100 Subject: [rspec-users] On debugging rspec; running all specs under multiple directories In-Reply-To: <501C27DA-43F0-48DE-B58D-35E6D0DFEA02@railsnewbie.com> References: <865F934A-6471-4A0D-A2F2-47DD4ACFCD25@railsnewbie.com> <13E0EBFE-6404-4CC1-B093-7D3A846EB14A@railsnewbie.com> <8d961d900702252141h15f1438dgd3f1e3209d3e4c42@mail.gmail.com> <8F131F5F-5672-4B05-8762-CB5FD0522C53@railsnewbie.com> <8d961d900702260208w62534686i4424ec56c768c608@mail.gmail.com> <520B228F-7E9F-4CCB-BB15-B5AA8C303BEE@railsnewbie.com> <8d961d900702261545w57d7b27bv2725cb9fa1d8f535@mail.gmail.com> <501C27DA-43F0-48DE-B58D-35E6D0DFEA02@railsnewbie.com> Message-ID: <8d961d900702270141u76b6ea01p77a31817735338cd@mail.gmail.com> On 2/27/07, Scott Taylor wrote: > > The latest bug - the one that I've just put into the tracker - is > halting all work that I'm doing on this rails project. I would like > to contribute back to the community, and fix the bug for myself. Any > suggestions on how to do this? Maybe some suggestions for how to > debug a code base which you are unfamiliar with? > > One thing I would like to do is run all of the specs in the rspec > library to see if they are passing. - the ones that fail will > probably point to the culprit. How can I run all of the specs under > one directory, if the specs are under subdirectories? This maybe > more of a unix question then an rspec one... > Try this: spec --help The first line of the help tells you that you can pass a directory to the spec command: spec some/dir If you want to run RSpec's own suite of specs, check out the code with svn and read the README. HTH, Aslak > > Thanks for the help, > > Scott Taylor > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Tue Feb 27 07:34:52 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Tue, 27 Feb 2007 07:34:52 -0500 Subject: [rspec-users] Using a subversion repository to spec in a rails app Message-ID: <5F82C709-6106-484D-9646-78557E574BEE@railsnewbie.com> Is it a bad practice to use a subversion repository to the trunk of rspec and rspec_on_rails? Or rather, is it doomed to fail, since my gem will always be out of date? I know I can't use spec, installed from gem,s if I have the latest revision of rspec and rspec_on_rails checked into my plugins directory. But I should still be able to use it with the --drb option, correct? I'm having a new set of bugs with my repository update to Revision 1539... Scott From leenoori at quepica.com Tue Feb 27 07:37:03 2007 From: leenoori at quepica.com (leenoori) Date: Tue, 27 Feb 2007 13:37:03 +0100 Subject: [rspec-users] Continuing a "specify" block after failure In-Reply-To: <57c63afe0702261222k4b6814f7q4b8d4f196c3613fb@mail.gmail.com> References: <26362922-E422-40B0-BB2C-5DF0604F4003@quepica.com> <57c63afe0702261222k4b6814f7q4b8d4f196c3613fb@mail.gmail.com> Message-ID: El 26/2/2007, a las 21:22, David Chelimsky escribi?: > IMO, since statements about each file could fail independently, then > each file wants its own specify block. So I would do it this way, with > the addition of something to separate out the spec names. For example > (possibly to verbose, but you get the idea): > > context 'transforming files' do > files.each do |file| > specify "actual output should match expected output (# > {file.inspect})" do > file.input.process.should == file.expected > end > end > end > > Cheers, > David Many thanks for your advice, David! I will go ahead and do it this way. Cheers! From aslak.hellesoy at gmail.com Tue Feb 27 07:41:15 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 27 Feb 2007 13:41:15 +0100 Subject: [rspec-users] On debugging rspec; running all specs under multiple directories In-Reply-To: <45E3F3CE.9000602@ntlworld.com> References: <865F934A-6471-4A0D-A2F2-47DD4ACFCD25@railsnewbie.com> <13E0EBFE-6404-4CC1-B093-7D3A846EB14A@railsnewbie.com> <8d961d900702252141h15f1438dgd3f1e3209d3e4c42@mail.gmail.com> <8F131F5F-5672-4B05-8762-CB5FD0522C53@railsnewbie.com> <8d961d900702260208w62534686i4424ec56c768c608@mail.gmail.com> <520B228F-7E9F-4CCB-BB15-B5AA8C303BEE@railsnewbie.com> <8d961d900702261545w57d7b27bv2725cb9fa1d8f535@mail.gmail.com> <501C27DA-43F0-48DE-B58D-35E6D0DFEA02@railsnewbie.com> <45E3F3CE.9000602@ntlworld.com> Message-ID: <8d961d900702270441w7dbea4fctc12a5a24360c0acf@mail.gmail.com> On 2/27/07, Jerry West wrote: > > > One thing I would like to do is run all of the specs in the rspec > > library to see if they are passing. - the ones that fail will > > probably point to the culprit. How can I run all of the specs under > > one directory, if the specs are under subdirectories? This maybe > > more of a unix question then an rspec one... > > Well, for the 0.7.5.1 plugin > > cd $RAILSDIR; spec -cfs vendor/plugins/rspec_on_rails/spec/ > > > I imagine the filesystem layout is the same for 0.8/trunk(?). > > Ironically, you can't run many of the 0.7.5.1 specs under 0.7.5.1 as > they use the latest 'should' syntax available only with 0.8RC1/trunk. > You can, but instead of saying "spec" (which will run your gem-installed spec) you have to say "bin/spec" (assuming you're standing in the root directory of rspec core) Aslak > Hope this helps, > Jerry > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From aslak.hellesoy at gmail.com Tue Feb 27 07:47:56 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 27 Feb 2007 13:47:56 +0100 Subject: [rspec-users] Using a subversion repository to spec in a rails app In-Reply-To: <5F82C709-6106-484D-9646-78557E574BEE@railsnewbie.com> References: <5F82C709-6106-484D-9646-78557E574BEE@railsnewbie.com> Message-ID: <8d961d900702270447j21c09252h10d29a251a437df5@mail.gmail.com> On 2/27/07, Scott Taylor wrote: > > Is it a bad practice to use a subversion repository to the trunk of > rspec and rspec_on_rails? Or rather, is it doomed to fail, since my > gem will always be out of date? > > I know I can't use spec, installed from gem,s if I have the latest > revision of rspec and rspec_on_rails checked into my plugins > directory. But I should still be able to use it with the --drb > option, correct? > > I'm having a new set of bugs with my repository update to Revision > 1539... > I recommend installing a compatible set of RSpec/Rspec on Rails in plugins (same revision) Preferrably a tagged revision. Try 0.8RC1. Then use the spec command under plugins: vendor/plugins/rspec/bin/spec Aslak > > Scott > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Tue Feb 27 08:21:57 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Tue, 27 Feb 2007 08:21:57 -0500 Subject: [rspec-users] Using a subversion repository to spec in a rails app In-Reply-To: <8d961d900702270447j21c09252h10d29a251a437df5@mail.gmail.com> References: <5F82C709-6106-484D-9646-78557E574BEE@railsnewbie.com> <8d961d900702270447j21c09252h10d29a251a437df5@mail.gmail.com> Message-ID: <4B8BF1A2-1ABD-427C-9375-BDC1478D5C34@railsnewbie.com> On Feb 27, 2007, at 7:47 AM, aslak hellesoy wrote: > On 2/27/07, Scott Taylor wrote: >> >> Is it a bad practice to use a subversion repository to the trunk of >> rspec and rspec_on_rails? Or rather, is it doomed to fail, since my >> gem will always be out of date? >> >> I know I can't use spec, installed from gem,s if I have the latest >> revision of rspec and rspec_on_rails checked into my plugins >> directory. But I should still be able to use it with the --drb >> option, correct? >> >> I'm having a new set of bugs with my repository update to Revision >> 1539... >> > > I recommend installing a compatible set of RSpec/Rspec on Rails in > plugins (same revision) > Preferrably a tagged revision. Try 0.8RC1. > > Then use the spec command under plugins: vendor/plugins/rspec/bin/spec Is there any need for a gem if I run spec through this path? I'm not using rspec for any other projects. Thanks for all of your help. Best Regards, Scott From dchelimsky at gmail.com Tue Feb 27 08:22:00 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 27 Feb 2007 07:22:00 -0600 Subject: [rspec-users] On debugging rspec; running all specs under multiple directories In-Reply-To: <45E3F3CE.9000602@ntlworld.com> References: <865F934A-6471-4A0D-A2F2-47DD4ACFCD25@railsnewbie.com> <13E0EBFE-6404-4CC1-B093-7D3A846EB14A@railsnewbie.com> <8d961d900702252141h15f1438dgd3f1e3209d3e4c42@mail.gmail.com> <8F131F5F-5672-4B05-8762-CB5FD0522C53@railsnewbie.com> <8d961d900702260208w62534686i4424ec56c768c608@mail.gmail.com> <520B228F-7E9F-4CCB-BB15-B5AA8C303BEE@railsnewbie.com> <8d961d900702261545w57d7b27bv2725cb9fa1d8f535@mail.gmail.com> <501C27DA-43F0-48DE-B58D-35E6D0DFEA02@railsnewbie.com> <45E3F3CE.9000602@ntlworld.com> Message-ID: <57c63afe0702270522p3c42b8bcsaa89b85ceb25193f@mail.gmail.com> On 2/27/07, Jerry West wrote: > > > One thing I would like to do is run all of the specs in the rspec > > library to see if they are passing. - the ones that fail will > > probably point to the culprit. How can I run all of the specs under > > one directory, if the specs are under subdirectories? This maybe > > more of a unix question then an rspec one... > > Well, for the 0.7.5.1 plugin > > cd $RAILSDIR; spec -cfs vendor/plugins/rspec_on_rails/spec/ > > > I imagine the filesystem layout is the same for 0.8/trunk(?). > > Ironically, you can't run many of the 0.7.5.1 specs under 0.7.5.1 as > they use the latest 'should' syntax available only with 0.8RC1/trunk. Hi Jerry, Thanks for your interest in contributing. http://rspec.rubyforge.org/contribute.html might provide a little more insight. We are aware of the problems running Spec::Rails' own specs outside of the project in which it lives in trunk. The problem we ran into is that there are things that are supposed to be configurable which turn out not to be, like where Rails looks for controllers, etc. This is a problem we plan to address before 1.0, but it is not the highest priority right now. That said, if you're going to work on rspec, the best thing to do is to submit a patch against the trunk. Check out the entire trunk and do this from the project root: rake install_dependencies cd rspec_on_rails rake rspec:pre_commit The last command runs rspec against 1.1.6, 1.2.1 and 1.2.2. To run it against edge as well, you need to run the following, all on one line. RSPEC_RAILS_VERSION=edge rake spec:all You can also tweak at rspec_on_rails/Mutlirails.rake if you want to include edge in rake:pre_commit. Please feel free to ask if you run into any problems at all. There are several people on this list who have contributed to rspec and can help if none of the core team are available to respond right away. Cheers, David > > Hope this helps, > Jerry > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Tue Feb 27 08:29:09 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 27 Feb 2007 07:29:09 -0600 Subject: [rspec-users] Using a subversion repository to spec in a rails app In-Reply-To: <8d961d900702270447j21c09252h10d29a251a437df5@mail.gmail.com> References: <5F82C709-6106-484D-9646-78557E574BEE@railsnewbie.com> <8d961d900702270447j21c09252h10d29a251a437df5@mail.gmail.com> Message-ID: <57c63afe0702270529v4a2def8eh808dc83fc9443a8e@mail.gmail.com> On 2/27/07, aslak hellesoy wrote: > On 2/27/07, Scott Taylor wrote: > > > > Is it a bad practice to use a subversion repository to the trunk of > > rspec and rspec_on_rails? Or rather, is it doomed to fail, since my > > gem will always be out of date? > > > > I know I can't use spec, installed from gem,s if I have the latest > > revision of rspec and rspec_on_rails checked into my plugins > > directory. But I should still be able to use it with the --drb > > option, correct? > > > > I'm having a new set of bugs with my repository update to Revision > > 1539... > > > > I recommend installing a compatible set of RSpec/Rspec on Rails in > plugins (same revision) > Preferrably a tagged revision. Try 0.8RC1. > > Then use the spec command under plugins: vendor/plugins/rspec/bin/spec I usually add a modified copy of vendor/plugins/rspec/bin/spec to script/, so I can do this: script/rails_spec_server & script/spec spec --drb Just make sure you change the second line to this: $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../vendor/plugins/rspec/lib")) > > Aslak > > > > > Scott > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Tue Feb 27 08:32:55 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 27 Feb 2007 07:32:55 -0600 Subject: [rspec-users] On debugging rspec; running all specs under multiple directories In-Reply-To: <57c63afe0702270522p3c42b8bcsaa89b85ceb25193f@mail.gmail.com> References: <865F934A-6471-4A0D-A2F2-47DD4ACFCD25@railsnewbie.com> <13E0EBFE-6404-4CC1-B093-7D3A846EB14A@railsnewbie.com> <8d961d900702252141h15f1438dgd3f1e3209d3e4c42@mail.gmail.com> <8F131F5F-5672-4B05-8762-CB5FD0522C53@railsnewbie.com> <8d961d900702260208w62534686i4424ec56c768c608@mail.gmail.com> <520B228F-7E9F-4CCB-BB15-B5AA8C303BEE@railsnewbie.com> <8d961d900702261545w57d7b27bv2725cb9fa1d8f535@mail.gmail.com> <501C27DA-43F0-48DE-B58D-35E6D0DFEA02@railsnewbie.com> <45E3F3CE.9000602@ntlworld.com> <57c63afe0702270522p3c42b8bcsaa89b85ceb25193f@mail.gmail.com> Message-ID: <57c63afe0702270532h7e3c40ax5342e200d501ff35@mail.gmail.com> On 2/27/07, David Chelimsky wrote: > On 2/27/07, Jerry West wrote: > > > > > One thing I would like to do is run all of the specs in the rspec > > > library to see if they are passing. - the ones that fail will > > > probably point to the culprit. How can I run all of the specs under > > > one directory, if the specs are under subdirectories? This maybe > > > more of a unix question then an rspec one... > > > > Well, for the 0.7.5.1 plugin > > > > cd $RAILSDIR; spec -cfs vendor/plugins/rspec_on_rails/spec/ > > > > > > I imagine the filesystem layout is the same for 0.8/trunk(?). > > > > Ironically, you can't run many of the 0.7.5.1 specs under 0.7.5.1 as > > they use the latest 'should' syntax available only with 0.8RC1/trunk. Actually, expression matchers for #should were introduced quietly in 0.7.5, so this is not quite correct. If you check out the entire 0.7.5.1 project and have no other instances of rspec installed you'll be able to run the specs. > > Hi Jerry, > > Thanks for your interest in contributing. > http://rspec.rubyforge.org/contribute.html might provide a little more > insight. > > We are aware of the problems running Spec::Rails' own specs outside of > the project in which it lives in trunk. The problem we ran into is > that there are things that are supposed to be configurable which turn > out not to be, like where Rails looks for controllers, etc. This is a > problem we plan to address before 1.0, but it is not the highest > priority right now. > > That said, if you're going to work on rspec, the best thing to do is > to submit a patch against the trunk. Check out the entire trunk and do > this from the project root: > > rake install_dependencies > cd rspec_on_rails > rake rspec:pre_commit > > The last command runs rspec against 1.1.6, 1.2.1 and 1.2.2. To run it > against edge as well, you need to run the following, all on one line. > > RSPEC_RAILS_VERSION=edge rake spec:all > > You can also tweak at rspec_on_rails/Mutlirails.rake if you want to > include edge in rake:pre_commit. > > Please feel free to ask if you run into any problems at all. There are > several people on this list who have contributed to rspec and can help > if none of the core team are available to respond right away. > > Cheers, > David > > > > > > > > > > > > Hope this helps, > > Jerry > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > From dchelimsky at gmail.com Tue Feb 27 08:51:51 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 27 Feb 2007 07:51:51 -0600 Subject: [rspec-users] Using a subversion repository to spec in a rails app In-Reply-To: <4B8BF1A2-1ABD-427C-9375-BDC1478D5C34@railsnewbie.com> References: <5F82C709-6106-484D-9646-78557E574BEE@railsnewbie.com> <8d961d900702270447j21c09252h10d29a251a437df5@mail.gmail.com> <4B8BF1A2-1ABD-427C-9375-BDC1478D5C34@railsnewbie.com> Message-ID: <57c63afe0702270551k1d5aaf70x93839fbb3e6a2578@mail.gmail.com> On 2/27/07, Scott Taylor wrote: > > On Feb 27, 2007, at 7:47 AM, aslak hellesoy wrote: > > > On 2/27/07, Scott Taylor wrote: > >> > >> Is it a bad practice to use a subversion repository to the trunk of > >> rspec and rspec_on_rails? Or rather, is it doomed to fail, since my > >> gem will always be out of date? > >> > >> I know I can't use spec, installed from gem,s if I have the latest > >> revision of rspec and rspec_on_rails checked into my plugins > >> directory. But I should still be able to use it with the --drb > >> option, correct? > >> > >> I'm having a new set of bugs with my repository update to Revision > >> 1539... > >> > > > > I recommend installing a compatible set of RSpec/Rspec on Rails in > > plugins (same revision) > > Preferrably a tagged revision. Try 0.8RC1. > > > > Then use the spec command under plugins: vendor/plugins/rspec/bin/spec > > Is there any need for a gem if I run spec through this path? I'm not > using rspec for any other projects. As of the current trunk, no, but there has been in the past so you may just want to give it a try. > > Thanks for all of your help. > > Best Regards, > > Scott > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From leenoori at quepica.com Tue Feb 27 08:59:16 2007 From: leenoori at quepica.com (leenoori) Date: Tue, 27 Feb 2007 14:59:16 +0100 Subject: [rspec-users] Continuing a "specify" block after failure In-Reply-To: <8d961d900702261343r3b3eddbfvd77d773284453ff8@mail.gmail.com> References: <26362922-E422-40B0-BB2C-5DF0604F4003@quepica.com> <8d961d900702261343r3b3eddbfvd77d773284453ff8@mail.gmail.com> Message-ID: <9E4DF053-3D24-4768-B505-9B2C4BBFC635@quepica.com> El 26/2/2007, a las 22:43, aslak hellesoy escribi?: > I have just checked in an example that illustrates this: > > http://rubyforge.org/viewvc/trunk/rspec/examples/dynamic_spec.rb? > revision=1537&root=rspec > > Aslak I've discovered one minor problem with this approach; if you have a "context_setup" block inside your context then it will be run *after* the dynamic specify block. For example, look below where I've added a "context_setup" block to your example. Intuition might lead one to believe that it would be executed *before* the specs because it's labelled as a "setup" block and also because it appears physically before the "specify" block. But it actually runs after: context "The month march" do context_setup do @start = 1 @max = 10 end (@start.. at max).each do |n| specify "The root of #{n} square should be #{n}" do Math.sqrt(n*n).should == n end end end No big deal, of course, but it can cause breakage (and does in the case of the contrived example). The workaround is to forget using "context_setup" and do the setup in the same scope as the following "specify" block: context "The month march" do @start = 1 @max = 10 (@start.. at max).each do |n| specify "The root of #{n} square should be #{n}" do Math.sqrt(n*n).should == n end end end I suspect a robust fix would involve evaluating context_setup blocks as soon as they are encountered rather than deferring them until later. Should I file a bug report/enhance request for this? Cheers :-) From dchelimsky at gmail.com Tue Feb 27 09:53:36 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 27 Feb 2007 08:53:36 -0600 Subject: [rspec-users] Continuing a "specify" block after failure In-Reply-To: <9E4DF053-3D24-4768-B505-9B2C4BBFC635@quepica.com> References: <26362922-E422-40B0-BB2C-5DF0604F4003@quepica.com> <8d961d900702261343r3b3eddbfvd77d773284453ff8@mail.gmail.com> <9E4DF053-3D24-4768-B505-9B2C4BBFC635@quepica.com> Message-ID: <57c63afe0702270653x65beb007md7acdcd756c27e5a@mail.gmail.com> On 2/27/07, leenoori wrote: > El 26/2/2007, a las 22:43, aslak hellesoy escribi?: > > > I have just checked in an example that illustrates this: > > > > http://rubyforge.org/viewvc/trunk/rspec/examples/dynamic_spec.rb? > > revision=1537&root=rspec > > > > Aslak > > I've discovered one minor problem with this approach; if you have a > "context_setup" block inside your context then it will be run *after* > the dynamic specify block. For example, look below where I've added a > "context_setup" block to your example. Intuition might lead one to > believe that it would be executed *before* the specs because it's > labelled as a "setup" block and also because it appears physically > before the "specify" block. But it actually runs after: > > context "The month march" do > context_setup do > @start = 1 > @max = 10 > end > (@start.. at max).each do |n| > specify "The root of #{n} square should be #{n}" do > Math.sqrt(n*n).should == n > end > end > end > > No big deal, of course, but it can cause breakage (and does in the > case of the contrived example). The workaround is to forget using > "context_setup" and do the setup in the same scope as the following > "specify" block: > > context "The month march" do > @start = 1 > @max = 10 > (@start.. at max).each do |n| > specify "The root of #{n} square should be #{n}" do > Math.sqrt(n*n).should == n > end > end > end > > I suspect a robust fix would involve evaluating context_setup blocks > as soon as they are encountered rather than deferring them until > later. Should I file a bug report/enhance request for this? This is the only list I've seen where everyone is so polite that they ask whether they should ask for what they want ;) Yes, please, if you want it addressed the best way to ensure that it gets on and stays on the radar is a feature request. Even if we reject it, it's there for posterity and can always be resurrected if appropriate. Cheers, David > > Cheers :-) > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Tue Feb 27 12:28:56 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Tue, 27 Feb 2007 12:28:56 -0500 Subject: [rspec-users] Using a subversion repository to spec in a rails app In-Reply-To: <8d961d900702270447j21c09252h10d29a251a437df5@mail.gmail.com> References: <5F82C709-6106-484D-9646-78557E574BEE@railsnewbie.com> <8d961d900702270447j21c09252h10d29a251a437df5@mail.gmail.com> Message-ID: <7015F0D2-87C6-43E8-9A35-F2B0C6BCDFFE@railsnewbie.com> What is the svn path for the tagged RC1 revision? Scott On Feb 27, 2007, at 7:47 AM, aslak hellesoy wrote: > On 2/27/07, Scott Taylor wrote: >> >> Is it a bad practice to use a subversion repository to the trunk of >> rspec and rspec_on_rails? Or rather, is it doomed to fail, since my >> gem will always be out of date? >> >> I know I can't use spec, installed from gem,s if I have the latest >> revision of rspec and rspec_on_rails checked into my plugins >> directory. But I should still be able to use it with the --drb >> option, correct? >> >> I'm having a new set of bugs with my repository update to Revision >> 1539... >> > > I recommend installing a compatible set of RSpec/Rspec on Rails in > plugins (same revision) > Preferrably a tagged revision. Try 0.8RC1. > > Then use the spec command under plugins: vendor/plugins/rspec/bin/spec > > Aslak > >> >> Scott >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From joshknowles at gmail.com Tue Feb 27 13:02:33 2007 From: joshknowles at gmail.com (Josh Knowles) Date: Tue, 27 Feb 2007 11:02:33 -0700 Subject: [rspec-users] Using a subversion repository to spec in a rails app In-Reply-To: <4B8BF1A2-1ABD-427C-9375-BDC1478D5C34@railsnewbie.com> References: <5F82C709-6106-484D-9646-78557E574BEE@railsnewbie.com> <8d961d900702270447j21c09252h10d29a251a437df5@mail.gmail.com> <4B8BF1A2-1ABD-427C-9375-BDC1478D5C34@railsnewbie.com> Message-ID: On 2/27/07, Scott Taylor wrote: > Is there any need for a gem if I run spec through this path? I'm not > using rspec for any other projects. I'm currently using piston to copy edge rspec/rspec_on_rails into vendor/plugins without requiring the gem. Works great! Josh -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070227/d46647ae/attachment.html From dchelimsky at gmail.com Tue Feb 27 15:18:01 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 27 Feb 2007 14:18:01 -0600 Subject: [rspec-users] Using a subversion repository to spec in a rails app In-Reply-To: <7015F0D2-87C6-43E8-9A35-F2B0C6BCDFFE@railsnewbie.com> References: <5F82C709-6106-484D-9646-78557E574BEE@railsnewbie.com> <8d961d900702270447j21c09252h10d29a251a437df5@mail.gmail.com> <7015F0D2-87C6-43E8-9A35-F2B0C6BCDFFE@railsnewbie.com> Message-ID: <57c63afe0702271218k52631cc7tcc036a3e9fd2c39f@mail.gmail.com> On 2/27/07, Scott Taylor wrote: > > What is the svn path for the tagged RC1 revision? svn://rubyforge.net/var/svn/rspec/tags/REL_0_8_0_RC1 > > Scott > > > > On Feb 27, 2007, at 7:47 AM, aslak hellesoy wrote: > > > On 2/27/07, Scott Taylor wrote: > >> > >> Is it a bad practice to use a subversion repository to the trunk of > >> rspec and rspec_on_rails? Or rather, is it doomed to fail, since my > >> gem will always be out of date? > >> > >> I know I can't use spec, installed from gem,s if I have the latest > >> revision of rspec and rspec_on_rails checked into my plugins > >> directory. But I should still be able to use it with the --drb > >> option, correct? > >> > >> I'm having a new set of bugs with my repository update to Revision > >> 1539... > >> > > > > I recommend installing a compatible set of RSpec/Rspec on Rails in > > plugins (same revision) > > Preferrably a tagged revision. Try 0.8RC1. > > > > Then use the spec command under plugins: vendor/plugins/rspec/bin/spec > > > > Aslak > > > >> > >> Scott > >> > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-users at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/rspec-users > >> > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Tue Feb 27 15:18:41 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 27 Feb 2007 14:18:41 -0600 Subject: [rspec-users] Using a subversion repository to spec in a rails app In-Reply-To: <57c63afe0702271218k52631cc7tcc036a3e9fd2c39f@mail.gmail.com> References: <5F82C709-6106-484D-9646-78557E574BEE@railsnewbie.com> <8d961d900702270447j21c09252h10d29a251a437df5@mail.gmail.com> <7015F0D2-87C6-43E8-9A35-F2B0C6BCDFFE@railsnewbie.com> <57c63afe0702271218k52631cc7tcc036a3e9fd2c39f@mail.gmail.com> Message-ID: <57c63afe0702271218y6d03c7f4pf6e101f57ae7c878@mail.gmail.com> On 2/27/07, David Chelimsky wrote: > On 2/27/07, Scott Taylor wrote: > > > > What is the svn path for the tagged RC1 revision? > > svn://rubyforge.net/var/svn/rspec/tags/REL_0_8_0_RC1 More specifically: svn://rubyforge.net/var/svn/rspec/tags/REL_0_8_0_RC1/rspec svn://rubyforge.net/var/svn/rspec/tags/REL_0_8_0_RC1/rspec_on_rails/vendor/plugins/rspec_on_rails > > > > > Scott > > > > > > > > On Feb 27, 2007, at 7:47 AM, aslak hellesoy wrote: > > > > > On 2/27/07, Scott Taylor wrote: > > >> > > >> Is it a bad practice to use a subversion repository to the trunk of > > >> rspec and rspec_on_rails? Or rather, is it doomed to fail, since my > > >> gem will always be out of date? > > >> > > >> I know I can't use spec, installed from gem,s if I have the latest > > >> revision of rspec and rspec_on_rails checked into my plugins > > >> directory. But I should still be able to use it with the --drb > > >> option, correct? > > >> > > >> I'm having a new set of bugs with my repository update to Revision > > >> 1539... > > >> > > > > > > I recommend installing a compatible set of RSpec/Rspec on Rails in > > > plugins (same revision) > > > Preferrably a tagged revision. Try 0.8RC1. > > > > > > Then use the spec command under plugins: vendor/plugins/rspec/bin/spec > > > > > > Aslak > > > > > >> > > >> Scott > > >> > > >> _______________________________________________ > > >> rspec-users mailing list > > >> rspec-users at rubyforge.org > > >> http://rubyforge.org/mailman/listinfo/rspec-users > > >> > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > From keith at dancingtext.com Wed Feb 28 10:22:03 2007 From: keith at dancingtext.com (Keith McDonnell) Date: Wed, 28 Feb 2007 15:22:03 +0000 Subject: [rspec-users] Fixture name not available as class variable in spec Message-ID: <45E59E1B.1090708@dancingtext.com> Hi there, I can't seem to access the fixture name as a class variable from my specs. I have to set the variable in the spec setup. ... [fixtures] my_fixture: id: 1 ... [rpsec] @my_fixture.id.should == 1 ... [error] You have a nil object when you didn't expect it! The error occurred while evaluating nil.id ... [my setup] RSpec-0.7.5.1 (r1395) - BDD for Ruby Rails 1.2.2 Latest rspec_on_rails plugin Is this this a bug or a feature ? Keith From graeme.nelson at gmail.com Wed Feb 28 11:48:43 2007 From: graeme.nelson at gmail.com (Graeme Nelson) Date: Wed, 28 Feb 2007 08:48:43 -0800 Subject: [rspec-users] Fixture name not available as class variable in spec In-Reply-To: <45E59E1B.1090708@dancingtext.com> References: <45E59E1B.1090708@dancingtext.com> Message-ID: <9BA49959-AF93-44F3-8F82-E001B04F8D4F@gmail.com> Hello Keith - You can get access to your fixtures like so: context "Some content" do fixtures :users setup do end specify "some specification" do end end Thanks graeme On Feb 28, 2007, at 7:22 AM, Keith McDonnell wrote: > Hi there, > > I can't seem to access the fixture name as a class variable from my > specs. I have to set the variable in the spec setup. > > ... [fixtures] > > my_fixture: > id: 1 > > ... [rpsec] > > @my_fixture.id.should == 1 > > ... [error] > > You have a nil object when you didn't expect it! > The error occurred while evaluating nil.id > > ... [my setup] > > RSpec-0.7.5.1 (r1395) - BDD for Ruby > Rails 1.2.2 > Latest rspec_on_rails plugin > > Is this this a bug or a feature ? > > Keith > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From work at ashleymoran.me.uk Wed Feb 28 12:26:46 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Wed, 28 Feb 2007 17:26:46 +0000 Subject: [rspec-users] Specifying that code is called in a block Message-ID: Not sure if this is possible currently. I have a section of code like this: ActiveRecord::Base.transaction do cow.save! duck.save! dog.save! end (Names changed to protect the innocent.) I'd like to specify that the saves run in a transaction. I can do ActiveRecord::Base.should_receive(:transaction).and_yield But is there any way to specify that the code is called as above, and not as cow.save! ActiveRecord::Base.transaction do duck.save! end dog.save! ? Ta Ashley From grant.mcinnes at utoronto.ca Wed Feb 28 08:50:44 2007 From: grant.mcinnes at utoronto.ca (gmcinnes) Date: Wed, 28 Feb 2007 05:50:44 -0800 (PST) Subject: [rspec-users] drbspec - "no server running" In-Reply-To: <8d961d900702252352v6c28cfd5v99abcd1bcded857d@mail.gmail.com> References: <865F934A-6471-4A0D-A2F2-47DD4ACFCD25@railsnewbie.com> <13E0EBFE-6404-4CC1-B093-7D3A846EB14A@railsnewbie.com> <8d961d900702252141h15f1438dgd3f1e3209d3e4c42@mail.gmail.com> <8d961d900702252352v6c28cfd5v99abcd1bcded857d@mail.gmail.com> Message-ID: <9204085.post@talk.nabble.com> Hi: I can't find the bug report. Maybe you didn't make it yet. I solved this by adding my machine name to /etc/localhosts - i.e. my computer is called morgan, and I added: 127.0.0.1 morgan to that file. It seems os x fancypants name lookup system doesn't resolve the machine name when making a gethostbyaddr(host)[0] call unless the machine name is in localhost. Seems to be a drb problem though. aslak hellesoy wrote: > > On 2/26/07, Scott Taylor wrote: >> >> On Feb 26, 2007, at 12:41 AM, aslak hellesoy wrote: >> >> > On 2/26/07, Scott Taylor wrote: >> >> >> >> I've created a little 30 second screen cast to show the problem: >> >> >> > >> > Hey, that's a neat bug report format! >> > >> >> Well, there is nothing quite like sitting in a room with someone to >> watch them reproduce the bug; words can be vague. I suppose that >> this is the closest I'll get to that ideal bug report...(at least >> over the internet). Plus, I've been looking to put that $70 that >> I've spent on screencasting software to work. >> >> I have my project svn'ed, with an externals on the rspec and >> rspec_on_rails repositories. I'm at revision 1536 - Is this correct >> for RC1? Do I also need to update the gem? >> > > Yes - like it's described on the announcement I linked to. > >> Best, >> >> Scott >> >> >> >> >> >> >> >> > Please try to uninstall your current RSpec release and install 0.8 RC1 >> > release - I think your problem will be gone. >> > >> > http://www.nabble.com/-ANN--RSpec-0.8.0-RC1-t3245509.html >> > >> > In 0.8 you have to say spec --drb instead of drbspec (see the >> > release notes) >> > >> > Also, for the future, please remember to tell us what versions of >> > OS/Ruby/RSpec/Rails you're running. (ok, I could see you have a mac >> > :-) >> > >> > HTH, >> > Aslak >> > >> >> http://railsnewbie.com/files/screencasts/rspec_on_rails- >> >> no_server_running.mov >> >> >> >> All I did before this, as I've said in the previous email, was >> >> generate a controller with: >> >> >> >> ./script/generate rspec_controller -c CollectiveDictionary index show >> >> >> >> Best, >> >> >> >> Scott >> >> >> >> >> >> On Feb 25, 2007, at 9:22 PM, Scott Taylor wrote: >> >> >> >>> >> >>> At times I've gotten the message "No Server Running" from drbspec >> >>> with my rails app. The thing is, the drb server certainly is >> >>> running! >> >>> >> >>> This happened a few times with my model specs. I'm not sure exactly >> >>> what the problem was there - I believe I was loading up fixtures >> >>> that >> >>> didn't exist. I was calling fixtures :singular_table_name as >> >>> opposed >> >>> to fixtures :plural_table_name >> >>> >> >>> This time it happened with my controller. I generated the >> >>> controller >> >>> with the ./script/generate rspec_controller ControllerName >> >>> command... >> >>> >> >>> It doesn't appear that the specs are setup to fail to begin with, >> >>> but >> >>> if this were the default behavior, one certainly shouldn't see a "No >> >>> Server Running" >> >>> >> >>> I could create a short screen cast if someone would like me to, or >> >>> elaborate... >> >>> >> >>> Best, >> >>> >> >>> Scott Taylor >> >>> >> >>> _______________________________________________ >> >>> rspec-users mailing list >> >>> rspec-users at rubyforge.org >> >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> >> >> _______________________________________________ >> >> rspec-users mailing list >> >> rspec-users at rubyforge.org >> >> http://rubyforge.org/mailman/listinfo/rspec-users >> >> >> > _______________________________________________ >> > rspec-users mailing list >> > rspec-users at rubyforge.org >> > http://rubyforge.org/mailman/listinfo/rspec-users >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > -- View this message in context: http://www.nabble.com/drbspec---%22no-server-running%22-tf3290701.html#a9204085 Sent from the rspec-users mailing list archive at Nabble.com. From dchelimsky at gmail.com Wed Feb 28 14:30:30 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 28 Feb 2007 13:30:30 -0600 Subject: [rspec-users] [ANN] RSpec-0.8.0 Message-ID: <57c63afe0702281130n2eae9f29j1e3d11a6da0f252b@mail.gmail.com> The RSpec Development Team is pleased to announce the release of RSpec-0.8.0. This release introduces a new approach to handling expectations using Expression Matchers. It also improves the spec command line by adding DRb support and making it possible to store command line options in a file. This means a more flexible RSpec experience with Rails, Rake and editor plugins like TextMate. It also sports myriad new features, bug fixes, patches and general goodness. Please see the following for details: http://rspec.rubyforge.org/index.html http://rspec.rubyforge.org/upgrade.html http://rspec.rubyforge.org/changes.html Happy Spec'ing! The RSpec Development Team From hussein at morsy.de Wed Feb 28 15:26:18 2007 From: hussein at morsy.de (Hussein Morsy) Date: Wed, 28 Feb 2007 21:26:18 +0100 Subject: [rspec-users] rdoc for Spec::Rails ? Message-ID: Hi, where can i find the rdoc for rspec-rails. The content of README-FIle of rspec_rails is: "See Spec::Rails" But i couldn't find Spec::Rails on http://rspec.rubyforge.org/rdoc/ index.html (it is updated to 0.8.0) Best Hussein From hussein at morsy.de Wed Feb 28 16:15:38 2007 From: hussein at morsy.de (Hussein Morsy) Date: Wed, 28 Feb 2007 22:15:38 +0100 Subject: [rspec-users] rdoc for Spec::Rails Message-ID: <0F91AF12-0530-4372-9229-1F3778423176@morsy.de> Hi, where can i find the rdoc for rspec-rails. The content of README-FIle of rspec_rails is: "See Spec::Rails" But i couldn't find Spec::Rails on http://rspec.rubyforge.org/rdoc/ index.html (it is updated to 0.8.0) Best Hussein From aslak.hellesoy at gmail.com Wed Feb 28 16:27:48 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Wed, 28 Feb 2007 22:27:48 +0100 Subject: [rspec-users] Specifying that code is called in a block In-Reply-To: References: Message-ID: <8d961d900702281327t25cb6c5fwc20452d584417065@mail.gmail.com> On 2/28/07, Ashley Moran wrote: > Not sure if this is possible currently. > > I have a section of code like this: > > ActiveRecord::Base.transaction do > cow.save! > duck.save! > dog.save! > end > > (Names changed to protect the innocent.) > > I'd like to specify that the saves run in a transaction. I can do > > ActiveRecord::Base.should_receive(:transaction).and_yield > > But is there any way to specify that the code is called as above, and > not as > > cow.save! > ActiveRecord::Base.transaction do > duck.save! > end > dog.save! > You can specify order of messages (method calls) on one object (http://rspec.rubyforge.org/documentation/mocks/mocks.html) but not between different objects. I can't help but feeling that if you're specifying behaviour at this level of detail you're too specific. You're testing implementation, not verifying behaviour. Aslak > ? > > Ta > Ashley > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Wed Feb 28 16:43:51 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 28 Feb 2007 15:43:51 -0600 Subject: [rspec-users] rdoc for Spec::Rails In-Reply-To: <0F91AF12-0530-4372-9229-1F3778423176@morsy.de> References: <0F91AF12-0530-4372-9229-1F3778423176@morsy.de> Message-ID: <57c63afe0702281343l3344d6eap369a5c538d6ae61@mail.gmail.com> On 2/28/07, Hussein Morsy wrote: > Hi, > > where can i find the rdoc for rspec-rails. > The content of README-FIle of rspec_rails is: > "See Spec::Rails" > > But i couldn't find Spec::Rails on http://rspec.rubyforge.org/rdoc/ > index.html (it is updated to 0.8.0) http://rspec.rubyforge.org/rdoc-rails/ There's also a link to it from http://rspec.rubyforge.org/documentation/rails/index.html Cheers, David > > Best > > Hussein > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From brian at yamabe.net Wed Feb 28 16:47:05 2007 From: brian at yamabe.net (Brian Yamabe) Date: Wed, 28 Feb 2007 13:47:05 -0800 Subject: [rspec-users] rdoc for Spec::Rails In-Reply-To: <0F91AF12-0530-4372-9229-1F3778423176@morsy.de> References: <0F91AF12-0530-4372-9229-1F3778423176@morsy.de> Message-ID: http://rspec.rubyforge.org/rdoc-rails/index.html ---Brian Yamabe On Feb 28, 2007, at 1:15 PM, Hussein Morsy wrote: > Hi, > > where can i find the rdoc for rspec-rails. > The content of README-FIle of rspec_rails is: > "See Spec::Rails" > > But i couldn't find Spec::Rails on http://rspec.rubyforge.org/rdoc/ > index.html (it is updated to 0.8.0) > > Best > > Hussein > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From kevwil at gmail.com Wed Feb 28 17:19:21 2007 From: kevwil at gmail.com (Kevin Williams) Date: Wed, 28 Feb 2007 15:19:21 -0700 Subject: [rspec-users] acts_as_authenticated error with Object#id Message-ID: <683a886f0702281419u463a9f62nb8dee4575b410a7f@mail.gmail.com> I'm getting this when I run my Rails controller specs. /config/../lib/authenticated_system.rb:16: warning: Object#id will be deprecated; use Object#object_id I added "include AuthenticatedTestHelper" to /spec/spec_helper.rb so that my controller tests^H^H^H^H^Hspecs can use the "login_as" helper method. Anyone know how to fix this? -- Cheers, Kevin Williams http://www.almostserio.us/ "Any sufficiently advanced technology is indistinguishable from Magic." - Arthur C. Clarke From mathias at globalinn.com Wed Feb 28 16:45:10 2007 From: mathias at globalinn.com (=?ISO-8859-1?Q?Mathias_Stjernstr=F6m?=) Date: Wed, 28 Feb 2007 22:45:10 +0100 Subject: [rspec-users] rdoc for Spec::Rails ? In-Reply-To: References: Message-ID: <6A79B0A9-C07D-49F8-8B30-900A48C714E1@globalinn.com> Hi Hussein! Try http://rspec.rubyforge.org/rdoc-rails/ Cheers! Mathias Stjernstr?m On Feb 28, 2007, at 21:26, Hussein Morsy wrote: > Hi, > > where can i find the rdoc for rspec-rails. > The content of README-FIle of rspec_rails is: > "See Spec::Rails" > > But i couldn't find Spec::Rails on http://rspec.rubyforge.org/rdoc/ > index.html (it is updated to 0.8.0) > > Best > > Hussein > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -------------- next part -------------- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 478 bytes Desc: This is a digitally signed message part Url : http://rubyforge.org/pipermail/rspec-users/attachments/20070228/eda106f7/attachment-0001.bin From dchelimsky at gmail.com Wed Feb 28 19:02:34 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 28 Feb 2007 18:02:34 -0600 Subject: [rspec-users] acts_as_authenticated error with Object#id In-Reply-To: <683a886f0702281419u463a9f62nb8dee4575b410a7f@mail.gmail.com> References: <683a886f0702281419u463a9f62nb8dee4575b410a7f@mail.gmail.com> Message-ID: <57c63afe0702281602p3b3673f5y46fd0941f82e2001@mail.gmail.com> On 2/28/07, Kevin Williams wrote: > I'm getting this when I run my Rails controller specs. > > /config/../lib/authenticated_system.rb:16: warning: Object#id > will be deprecated; use Object#object_id > > I added "include AuthenticatedTestHelper" to /spec/spec_helper.rb so > that my controller tests^H^H^H^H^Hspecs can use the "login_as" helper > method. Anyone know how to fix this? This usually comes from something calling #id on a mock of a model. Are you mocking any AR models? If so, be sure to stub!(:id).and_return(a_string). David > > > -- > Cheers, > > Kevin Williams > http://www.almostserio.us/ > > "Any sufficiently advanced technology is indistinguishable from > Magic." - Arthur C. Clarke > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From aslak.hellesoy at gmail.com Wed Feb 28 21:37:33 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Thu, 1 Mar 2007 03:37:33 +0100 Subject: [rspec-users] acts_as_authenticated error with Object#id In-Reply-To: <57c63afe0702281602p3b3673f5y46fd0941f82e2001@mail.gmail.com> References: <683a886f0702281419u463a9f62nb8dee4575b410a7f@mail.gmail.com> <57c63afe0702281602p3b3673f5y46fd0941f82e2001@mail.gmail.com> Message-ID: <8d961d900702281837u7ebd80fav6448c06711eeac12@mail.gmail.com> On 3/1/07, David Chelimsky wrote: > On 2/28/07, Kevin Williams wrote: > > I'm getting this when I run my Rails controller specs. > > > > /config/../lib/authenticated_system.rb:16: warning: Object#id > > will be deprecated; use Object#object_id > > > > I added "include AuthenticatedTestHelper" to /spec/spec_helper.rb so > > that my controller tests^H^H^H^H^Hspecs can use the "login_as" helper > > method. Anyone know how to fix this? > > This usually comes from something calling #id on a mock of a model. > Are you mocking any AR models? If so, be sure to > stub!(:id).and_return(a_string). > Or use mock_model(SomeClass) and get it for free. It also takes care of stubbing #to_param, which is heavily used by ActionPack. Aslak > David > > > > > > > -- > > Cheers, > > > > Kevin Williams > > http://www.almostserio.us/ > > > > "Any sufficiently advanced technology is indistinguishable from > > Magic." - Arthur C. Clarke > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Wed Feb 28 22:54:35 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 28 Feb 2007 21:54:35 -0600 Subject: [rspec-users] acts_as_authenticated error with Object#id In-Reply-To: <8d961d900702281837u7ebd80fav6448c06711eeac12@mail.gmail.com> References: <683a886f0702281419u463a9f62nb8dee4575b410a7f@mail.gmail.com> <57c63afe0702281602p3b3673f5y46fd0941f82e2001@mail.gmail.com> <8d961d900702281837u7ebd80fav6448c06711eeac12@mail.gmail.com> Message-ID: <57c63afe0702281954n5fe5b671ib521beb81cc21a52@mail.gmail.com> On 2/28/07, aslak hellesoy wrote: > On 3/1/07, David Chelimsky wrote: > > On 2/28/07, Kevin Williams wrote: > > > I'm getting this when I run my Rails controller specs. > > > > > > /config/../lib/authenticated_system.rb:16: warning: Object#id > > > will be deprecated; use Object#object_id > > > > > > I added "include AuthenticatedTestHelper" to /spec/spec_helper.rb so > > > that my controller tests^H^H^H^H^Hspecs can use the "login_as" helper > > > method. Anyone know how to fix this? > > > > This usually comes from something calling #id on a mock of a model. > > Are you mocking any AR models? If so, be sure to > > stub!(:id).and_return(a_string). > > > > Or use mock_model(SomeClass) and get it for free. It also takes care > of stubbing #to_param, which is heavily used by ActionPack. Here's the deets on that: http://rspec.rubyforge.org/rdoc-rails/classes/Spec/Rails/Runner/EvalContext.html > > Aslak > > > David > > > > > > > > > > > -- > > > Cheers, > > > > > > Kevin Williams > > > http://www.almostserio.us/ > > > > > > "Any sufficiently advanced technology is indistinguishable from > > > Magic." - Arthur C. Clarke > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >