From mlangenberg at gmail.com Thu Mar 1 02:44:23 2007 From: mlangenberg at gmail.com (Matthijs Langenberg) Date: Thu, 1 Mar 2007 08:44:23 +0100 Subject: [rspec-users] Specifying that code is called in a block In-Reply-To: <8d961d900702281327t25cb6c5fwc20452d584417065@mail.gmail.com> References: <8d961d900702281327t25cb6c5fwc20452d584417065@mail.gmail.com> Message-ID: <27c0ac6d0702282344s27a38ddand55c062825163c11@mail.gmail.com> I'm actually interested in the other way around: when do you know the solution should be receiving a block in a method when writing a specification? Can anyone give me an example of that? On 2/28/07, aslak hellesoy wrote: > 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 > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From work at ashleymoran.me.uk Thu Mar 1 05:01:55 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Thu, 1 Mar 2007 10:01:55 +0000 Subject: [rspec-users] Specifying that code is called in a block In-Reply-To: <8d961d900702281327t25cb6c5fwc20452d584417065@mail.gmail.com> References: <8d961d900702281327t25cb6c5fwc20452d584417065@mail.gmail.com> Message-ID: <634A7569-C8E8-431E-859A-D41B0C848A9F@ashleymoran.me.uk> On 28 Feb 2007, at 21:27, aslak hellesoy wrote: > 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 Aslak, I thought about that, but then how can you test that things are being done in the correct transactions? (Which is really important, from where I stand!) The only way would be to involve the database in the tests, raise an exception during the code found in the block and test that the database hasn't been modified. This seems like a step backwards, seeing as everything should be as isolated as possible. Or is the problem that ActiveRecord doesn't have distinct business logic and persistence layers? Ashley From work at ashleymoran.me.uk Thu Mar 1 05:35:13 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Thu, 1 Mar 2007 10:35:13 +0000 Subject: [rspec-users] Specifying that code is called in a block In-Reply-To: <27c0ac6d0702282344s27a38ddand55c062825163c11@mail.gmail.com> References: <8d961d900702281327t25cb6c5fwc20452d584417065@mail.gmail.com> <27c0ac6d0702282344s27a38ddand55c062825163c11@mail.gmail.com> Message-ID: <1FE790F0-F5EB-4570-AE7B-AE81809BBE52@ashleymoran.me.uk> On 1 Mar 2007, at 07:44, Matthijs Langenberg wrote: > I'm actually interested in the other way around: when do you know the > solution should be receiving a block in a method when writing a > specification? Can anyone give me an example of that? Best I can think of is this: class MyClass def moo(quack_block) quack(&quack_block) end private def quack puts yield end end context "description of context" do setup do @mock = mock("mock") @my_object = MyClass.new end specify "descriptive specification" do @mock.should_receive(:woof) @my_object.moo(lambda { @mock.woof; "miaow" }) end end Not sure in the real world it would be practical, or even if this is a good thing to do, but it seems to work Ashley From kevwil at gmail.com Thu Mar 1 09:34:08 2007 From: kevwil at gmail.com (Kevin Williams) Date: Thu, 1 Mar 2007 07:34:08 -0700 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: <683a886f0703010634v78352942p41e7c8eb31cd82a6@mail.gmail.com> No, this isn't a mock AFAIK. The 'login_as(:quentin)' code uses the data from the fixtures, so it should be loading from the test database. On 2/28/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). > > 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 > -- Cheers, Kevin Williams http://www.almostserio.us/ "Any sufficiently advanced technology is indistinguishable from Magic." - Arthur C. Clarke From pergesu at gmail.com Thu Mar 1 15:10:50 2007 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 1 Mar 2007 13:10:50 -0700 Subject: [rspec-users] error_on is deprecated? Message-ID: <810a540e0703011210i3ccc33eak3e23fdb897f59516@mail.gmail.com> The docs say DEPRECATED. See Spec::Rails::Expectations model.should_have(:no).errors_on(:attribute) model.should_have(1).error_on(:attribute) model.should_have(3).errors_on(:attribute) However the rdoc for Spec::Rails::Expectations shows the same code. The only difference is that it's "model.should have(1).error_on(:attribute) instead" So is error_on itself deprecated, or is it just the old should_have? The docs aren't very clear to me in that respect. Pat From dchelimsky at gmail.com Thu Mar 1 16:20:22 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 1 Mar 2007 15:20:22 -0600 Subject: [rspec-users] error_on is deprecated? In-Reply-To: <810a540e0703011210i3ccc33eak3e23fdb897f59516@mail.gmail.com> References: <810a540e0703011210i3ccc33eak3e23fdb897f59516@mail.gmail.com> Message-ID: <57c63afe0703011320h56fb56ffr29b72a03f9a122cd@mail.gmail.com> On 3/1/07, Pat Maddox wrote: > The docs say > > DEPRECATED. See Spec::Rails::Expectations > > model.should_have(:no).errors_on(:attribute) > model.should_have(1).error_on(:attribute) > model.should_have(3).errors_on(:attribute) > > However the rdoc for Spec::Rails::Expectations shows the same code. > The only difference is that it's "model.should > have(1).error_on(:attribute) instead" That's a big difference ;) > So is error_on itself deprecated, or is it just the old should_have? It's specifically "should_have". It'll work fine if you use "should have". > The docs aren't very clear to me in that respect. > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Thu Mar 1 02:48:35 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Thu, 1 Mar 2007 02:48:35 -0500 Subject: [rspec-users] Problems with RC1 & Rails Controllers Message-ID: <001D8363-9785-4477-B51D-570FD5A2A849@railsnewbie.com> I'm now using the 0.8.0 RC1 gem and have the same version of rspec and rspec_on_rails checked out into my vendor/plugins directory. I'm having a problems with controllers... I've generated a controller using the ./script/generate rspec_controller MyController. When I try to run the rake spec:controller task I get the following: euclid% rake spec:controllers (in /Users/smtlaissezfaire/Sites/rails/dictionary) /opt/local/bin/ruby -I"/Users/smtlaissezfaire/Sites/rails/dictionary/ vendor/plugins/rspec/lib" "/Users/smtlaissezfaire/Sites/rails/ dictionary/vendor/plugins/rspec/bin/spec" "spec/controllers/ my_controller_controller_spec.rb" --options "/Users/smtlaissezfaire/ Sites/rails/dictionary/config/../spec/spec.opts" /opt/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.1/lib/sqlite3/ errors.rb:94:in `check': SQL logic error or missing database (SQLite3::SQLException) from /opt/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.1/ lib/sqlite3/resultset.rb:76:in `check' from /opt/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.1/ lib/sqlite3/resultset.rb:68:in `commence' from /opt/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.1/ lib/sqlite3/resultset.rb:61:in `initialize' from /opt/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.1/ lib/sqlite3/statement.rb:163:in `new' from /opt/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.1/ lib/sqlite3/statement.rb:163:in `execute' from /opt/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.1/ lib/sqlite3/database.rb:212:in `execute' from /opt/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.1/ lib/sqlite3/database.rb:187:in `prepare' from /opt/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.1/ lib/sqlite3/database.rb:211:in `execute' ... 29 levels... from /Users/smtlaissezfaire/Sites/rails/dictionary/vendor/ plugins/rspec/lib/spec/runner/option_parser.rb:180:in `parse' from /Users/smtlaissezfaire/Sites/rails/dictionary/vendor/ plugins/rspec/lib/spec/runner/option_parser.rb:13:in `create_context_runner' from /Users/smtlaissezfaire/Sites/rails/dictionary/vendor/ plugins/rspec/lib/spec/runner/command_line.rb:12:in `run' from /Users/smtlaissezfaire/Sites/rails/dictionary/vendor/ plugins/rspec/bin/spec:4 rake aborted! Command failed with status (1): [/opt/local/bin/ruby -I"/Users/ smtlaissezfa...] This looks like the sort of error one would get with a bad fixture file. My only problem is that I can run rake spec:models without a problem. The test log shows this: Spec::Rails::Runner::HelperEvalContextController: missing default helper path spec/rails/runner/helper_eval_context_helper Spec::Rails::Runner::ViewSpecController: missing default helper path spec/rails/runner/view_spec_helper Just to make it clear, I've also run script/generate rspec I'm running OS X.4.8, ruby 1.8.5 (2006-12-25 patchlevel 12) [powerpc-darwin8.8.0] edge rails (revision 6265) and the RC1 gem, as stated before. Let me know If I should post this as a bug report, or if I'm missing something. Best, Scott Taylor From mailing_lists at railsnewbie.com Thu Mar 1 02:58:31 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Thu, 1 Mar 2007 02:58:31 -0500 Subject: [rspec-users] RC1, Rails, and problems with multiple options in spec.opts Message-ID: <445101B3-41F9-476B-B613-9BF94A7B0A93@railsnewbie.com> I am having inconsistent output with multiple options in the spec.opts file. I can, for instance, pass --color or --colour, or, separately, use --drb. But when combining them I get: /opt/local/lib/ruby/1.8/optparse.rb:1381:in `complete': invalid option: --options --color --drb (OptionParser::InvalidOption) from /opt/local/lib/ruby/1.8/optparse.rb:1379:in `catch' from /opt/local/lib/ruby/1.8/optparse.rb:1379:in `complete' from /opt/local/lib/ruby/1.8/optparse.rb:1212:in `order!' from /opt/local/lib/ruby/1.8/optparse.rb:1205:in `catch' from /opt/local/lib/ruby/1.8/optparse.rb:1205:in `order!' from /opt/local/lib/ruby/1.8/optparse.rb:1279:in `permute!' from /opt/local/lib/ruby/1.8/optparse.rb:1300:in `parse!' from /Users/smtlaissezfaire/Sites/rails/dictionary/vendor/ plugins/rspec/lib/spec/runner/option_parser.rb:180:in `parse' ... 9 levels... from /Users/smtlaissezfaire/Sites/rails/dictionary/vendor/ plugins/rspec/lib/spec/runner/option_parser.rb:180:in `parse' from /Users/smtlaissezfaire/Sites/rails/dictionary/vendor/ plugins/rspec/lib/spec/runner/option_parser.rb:13:in `create_context_runner' from /Users/smtlaissezfaire/Sites/rails/dictionary/vendor/ plugins/rspec/lib/spec/runner/command_line.rb:12:in `run' from /Users/smtlaissezfaire/Sites/rails/dictionary/vendor/ plugins/rspec/bin/spec:4 rake aborted! Is anyone else having this problem? I'm on Mac OS X.4.8, using edge rails, ruby 1.8.5, and RC1 Best, Scott Taylor From dchelimsky at gmail.com Thu Mar 1 19:18:42 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 1 Mar 2007 18:18:42 -0600 Subject: [rspec-users] Problems with RC1 & Rails Controllers In-Reply-To: <001D8363-9785-4477-B51D-570FD5A2A849@railsnewbie.com> References: <001D8363-9785-4477-B51D-570FD5A2A849@railsnewbie.com> Message-ID: <57c63afe0703011618l48f9fb1ib4b01b3dd7a7834@mail.gmail.com> On 3/1/07, Scott Taylor wrote: > > I'm now using the 0.8.0 RC1 gem and have the same version of rspec > and rspec_on_rails checked out into my vendor/plugins directory. > > I'm having a problems with controllers... I've generated a controller > using the ./script/generate rspec_controller MyController. When I > try to run the rake spec:controller task I get the following: > > euclid% rake spec:controllers > (in /Users/smtlaissezfaire/Sites/rails/dictionary) > /opt/local/bin/ruby -I"/Users/smtlaissezfaire/Sites/rails/dictionary/ > vendor/plugins/rspec/lib" "/Users/smtlaissezfaire/Sites/rails/ > dictionary/vendor/plugins/rspec/bin/spec" "spec/controllers/ > my_controller_controller_spec.rb" --options "/Users/smtlaissezfaire/ > Sites/rails/dictionary/config/../spec/spec.opts" > > /opt/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.1/lib/sqlite3/ > errors.rb:94:in `check': SQL logic error or missing database > (SQLite3::SQLException) > from /opt/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.1/ > lib/sqlite3/resultset.rb:76:in `check' > from /opt/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.1/ > lib/sqlite3/resultset.rb:68:in `commence' > from /opt/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.1/ > lib/sqlite3/resultset.rb:61:in `initialize' > from /opt/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.1/ > lib/sqlite3/statement.rb:163:in `new' > from /opt/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.1/ > lib/sqlite3/statement.rb:163:in `execute' > from /opt/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.1/ > lib/sqlite3/database.rb:212:in `execute' > from /opt/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.1/ > lib/sqlite3/database.rb:187:in `prepare' > from /opt/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.1/ > lib/sqlite3/database.rb:211:in `execute' > ... 29 levels... > from /Users/smtlaissezfaire/Sites/rails/dictionary/vendor/ > plugins/rspec/lib/spec/runner/option_parser.rb:180:in `parse' > from /Users/smtlaissezfaire/Sites/rails/dictionary/vendor/ > plugins/rspec/lib/spec/runner/option_parser.rb:13:in > `create_context_runner' > from /Users/smtlaissezfaire/Sites/rails/dictionary/vendor/ > plugins/rspec/lib/spec/runner/command_line.rb:12:in `run' > from /Users/smtlaissezfaire/Sites/rails/dictionary/vendor/ > plugins/rspec/bin/spec:4 > rake aborted! > Command failed with status (1): [/opt/local/bin/ruby -I"/Users/ > smtlaissezfa...] > > > This looks like the sort of error one would get with a bad fixture > file. My only problem is that I can run rake spec:models without a > problem. > > The test log shows this: > > Spec::Rails::Runner::HelperEvalContextController: missing default > helper path spec/rails/runner/helper_eval_context_helper > Spec::Rails::Runner::ViewSpecController: missing default helper path > spec/rails/runner/view_spec_helper > > Just to make it clear, I've also run script/generate rspec > > > I'm running OS X.4.8, > ruby 1.8.5 (2006-12-25 patchlevel 12) [powerpc-darwin8.8.0] > edge rails (revision 6265) > and the RC1 gem, as stated before. > > Let me know If I should post this as a bug report, or if I'm missing > something. > > Best, > > Scott Taylor Hi Scott - this was fixed along w/ http://rubyforge.org/tracker/?group_id=797&atid=3149&func=detail&aid=8928. You have two options to address: 1. (recommended) - upgrade to the official release rspec-0.8.1 2. (not recommended, but it will work) - go into lib/spec/rails/runner/context/functional.rb in the rails plugin and remove the call to super at the beginning of setup (line 7). Cheers, David > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From cwdinfo at gmail.com Thu Mar 1 23:03:02 2007 From: cwdinfo at gmail.com (s.ross) Date: Thu, 1 Mar 2007 20:03:02 -0800 Subject: [rspec-users] Installing as Plugin In-Reply-To: <8d961d900702281327t25cb6c5fwc20452d584417065@mail.gmail.com> References: <8d961d900702281327t25cb6c5fwc20452d584417065@mail.gmail.com> Message-ID: Big thank-you for allowing rSpec core to be installed as a plugin. I've been on a merry-go-round of updating some 5 active projects to keep up with trunk. Whew! Thanks again. Steve From pergesu at gmail.com Fri Mar 2 05:12:59 2007 From: pergesu at gmail.com (Pat Maddox) Date: Fri, 2 Mar 2007 03:12:59 -0700 Subject: [rspec-users] error_on is deprecated? In-Reply-To: <57c63afe0703011320h56fb56ffr29b72a03f9a122cd@mail.gmail.com> References: <810a540e0703011210i3ccc33eak3e23fdb897f59516@mail.gmail.com> <57c63afe0703011320h56fb56ffr29b72a03f9a122cd@mail.gmail.com> Message-ID: <810a540e0703020212p6e8a96d8seeb24e101e1efa97@mail.gmail.com> On 3/1/07, David Chelimsky wrote: > On 3/1/07, Pat Maddox wrote: > > The docs say > > > > DEPRECATED. See Spec::Rails::Expectations > > > > model.should_have(:no).errors_on(:attribute) > > model.should_have(1).error_on(:attribute) > > model.should_have(3).errors_on(:attribute) > > > > However the rdoc for Spec::Rails::Expectations shows the same code. > > The only difference is that it's "model.should > > have(1).error_on(:attribute) instead" > > That's a big difference ;) I realize there's a huge difference. In fact...let it be known that I've read basically every OOP design book known to man. I've studied them in depth. Despite that, 80% of my understanding of OOP comes from relatively small discussions from David Chelimsky. > > So is error_on itself deprecated, or is it just the old should_have? > > It's specifically "should_have". It'll work fine if you use "should have". That's all I was asking. Pat From keith at dancingtext.com Fri Mar 2 06:02:46 2007 From: keith at dancingtext.com (Keith McDonnell) Date: Fri, 02 Mar 2007 11:02:46 +0000 Subject: [rspec-users] Fixture name not available as class variable in spec In-Reply-To: References: Message-ID: <45E80456.9070608@dancingtext.com> Hi Graham, Thanks for the reply. Yes, I did have the fixtures method included in the contexts. I've recently upgraded to the latest spec, rails plugin & rails which could be an issue. I'd prefer not to have to instantiate the fixture variables in the setup. It was cleaner & more efficient when they were picked up from the fixtures directly. Regards, Keith > Message: 2 > Date: Wed, 28 Feb 2007 08:48:43 -0800 > From: Graeme Nelson > Subject: Re: [rspec-users] Fixture name not available as class > variable in spec > To: rspec-users > Message-ID: <9BA49959-AF93-44F3-8F82-E001B04F8D4F at gmail.com> > Content-Type: text/plain; charset=US-ASCII; format=flowed > > 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 > > > > ------------------------------ > > Message: 3 > Date: Wed, 28 Feb 2007 17:26:46 +0000 > From: Ashley Moran > Subject: [rspec-users] Specifying that code is called in a block > To: rspec-users > Message-ID: > Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed > > 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 > > > ------------------------------ > > Message: 4 > Date: Wed, 28 Feb 2007 05:50:44 -0800 (PST) > From: gmcinnes > Subject: Re: [rspec-users] drbspec - "no server running" > To: rspec-users at rubyforge.org > Message-ID: <9204085.post at talk.nabble.com> > Content-Type: text/plain; charset=us-ascii > > > 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 >> >> > From bhelmkamp at gmail.com Fri Mar 2 11:04:48 2007 From: bhelmkamp at gmail.com (Bryan Helmkamp) Date: Fri, 2 Mar 2007 11:04:48 -0500 Subject: [rspec-users] Specifying that code is called in a block In-Reply-To: <8d961d900702281327t25cb6c5fwc20452d584417065@mail.gmail.com> References: <8d961d900702281327t25cb6c5fwc20452d584417065@mail.gmail.com> Message-ID: On 2/28/07, aslak hellesoy wrote: > 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, Is there an alternate solution you'd propose, or would you go without this spec entirely? It's easy to imagine a case where the lack of specifying the need for a transaction could allow a bug. More generally, what metrics do you apply to differentiate between testing implementation and verifying behavior? As I understand it, if one were to follow a strict spec-first style of development, each piece of implementation would have to demanded by a failing spec before it could be written. In this particular case, that would mean not adding the transaction block until there is a unit spec requiring it. How do you reconcile these two seemingly conflicting principles? -Bryan From dchelimsky at gmail.com Fri Mar 2 11:26:26 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 2 Mar 2007 10:26:26 -0600 Subject: [rspec-users] [ANN] RSpec-0.8.2 Message-ID: <57c63afe0703020826s3914e94euc2aed83134d164b1@mail.gmail.com> Announcing the release of rspec-0.8.2. This should only affect a small number of you, but I re-wrote the assert_select fork as a wrapper. The only effect this has on the API is that :hide and :effect are not supported by "should have_rjs", as they are not supported by assert_select_rjs. You can, however, still use them both with "should_have_rjs" (with an underscore between "should" and "have"). The reason for this change is that only a day after releasing 0.8, I discovered that the specs for should have_rjs were failing against edge rails. I quickly realized that it makes no sense for us to maintain forks of anything in rails. I guess I knew that already, but simply ignored my better judgment when writing the fork because I wanted better messages (the failure messages in assert_select are not that helpful). Thanks for your patience w/ this. David The RSpec Development Team From dchelimsky at gmail.com Fri Mar 2 12:01:33 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 2 Mar 2007 11:01:33 -0600 Subject: [rspec-users] Specifying that code is called in a block In-Reply-To: References: <8d961d900702281327t25cb6c5fwc20452d584417065@mail.gmail.com> Message-ID: <57c63afe0703020901g63369a48uc03b13993a73093e@mail.gmail.com> On 3/2/07, Bryan Helmkamp wrote: > On 2/28/07, aslak hellesoy wrote: > > 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, > > Is there an alternate solution you'd propose, or would you go without > this spec entirely? It's easy to imagine a case where the lack of > specifying the need for a transaction could allow a bug. If it's easy to imagine the case, then it _should_ (in theory ;) ) be easy to write a spec that exposes that bug. > More generally, what metrics do you apply to differentiate between > testing implementation and verifying behavior? > > As I understand it, if one were to follow a strict spec-first style of > development, each piece of implementation would have to demanded by a > failing spec before it could be written. In this particular case, that > would mean not adding the transaction block until there is a unit spec > requiring it. How do you reconcile these two seemingly conflicting > principles? TDD is not a perfect world, and BDD certainly does not make it so. There are cases in which we know things are important and we do some ugly things to test them. Bob Martin puts something similar into perspective talking about comments. He says that once in a while he'll put a comment somewhere because it is more pragmatic to have the comment than any alternative, but that he views that as a failure. He doesn't let it stop the world. He simply acknowledges that something is wrong and presses on. Similarly, in this case, absent a viable solution using the available tools, I'd probably do some nasty stuff to spec this out, but catalog that in the back of my mind as a failure of some combination of my skill and the available toolset. Tools like rspec are there to help you, and often do. But when they don't, you can't let that be an excuse for not producing software that is solid, maintainable, and meets the requirements at hand. David > > -Bryan > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From meadow.nnick at gmail.com Fri Mar 2 12:41:47 2007 From: meadow.nnick at gmail.com (Lugovoi Nikolai) Date: Fri, 2 Mar 2007 19:41:47 +0200 Subject: [rspec-users] Specifying that code is called in a block In-Reply-To: References: Message-ID: <86924770703020941v6b1ce9c2j185e42d633b3718b@mail.gmail.com> What about such specification? specify "cow, dog and duck must be saved in the same transaction" do $log.clear @connection.stub!(:begin_db_transaction).and_return { $log.record("BEGIN"); nil } @connection.stub!(:commit_db_transaction).and_return { $log.record("COMMIT"); nil } @cow.stub!(:save!).and_return {$log.record("COW SAVE"); true} @dog.stub!(:save!).and_return {$log.record("DOG SAVE"); true} @duck.stub!(:save!).and_return {$log.record("DUCK SAVE"); true} @tested_object.exec_method_about_cow_dog_and_duck txn_intervals = %w(COW DUCK DOG).collect do |beast| [ $log.find("BEGIN", :before, "#{beast} SAVE"), $log.find("COMMIT", :after, "#{beast} SAVE")] end txn_intervals.each do |range| range[0].should_be kind_of(Time) range[1].should_be kind_of(Time) end txn_intervals.uniq.size.should == 1 end where $log can be something like: $log = Struct.new(:events, :timestamps).new def $log.clear events = [] timestamps = [] end def $log.record(what) events << what timestamps << Time.now end def $log.find(what, where, start) # return timestamp of event `what' that is :before or :after (where) event `start' end 2007/2/28, Ashley Moran : > 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 > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From david.smalley.lists at googlemail.com Fri Mar 2 13:18:58 2007 From: david.smalley.lists at googlemail.com (David Smalley) Date: Fri, 2 Mar 2007 18:18:58 +0000 Subject: [rspec-users] database modifications not rolling back Message-ID: Hi, Since moving this morning from 0.7.5.1 to 0.8.2 I've hit some problems and I'm not sure if it's something I'm doing wrong or a change in 0.8.2 Basically I dislike fixtures so I have been using a helper method to create an object I need frequently and setting it up in the setup method, in 0.7.5.1 this all worked fine - but since moving to 0.8.2 I'm finding that the records are not removed from the database after each spec, leading to a failure on the next attempt to create the identical record (there is some uniqueness validation on the model). After all tests have finished the test database is populated entirely with all the records I have created, whereas on 0.7.5.1 I'd find this database completely empty on completion. FYI - I'm using Rspec 0.8.2 with matching revision of rspec_on_rails, Rails 1.2.2 and Mysql. spec_helper.rb module CompetitionSpecHelper def new_competition code_to_create_a_new_competition return the competition end end competition_spec.rb require File.dirname(__FILE__) + '/../spec_helper' context "Given a visible competition" do include CompetitionSpecHelper setup do @competition = new_competition @competition.process! end specify "should return true for started?" do @competition.started? should == true end ...................... Is there something wrong with what I have been doing? All tests were passing before the upgrade, it'll take me a while to go through and change to fixtures if this isn't the correct way to do it. I had seen numerous discussion around Rspec that seemed to validate the way I've been doing things, in spirit at least. Thanks, David From dchelimsky at gmail.com Fri Mar 2 14:09:01 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 2 Mar 2007 13:09:01 -0600 Subject: [rspec-users] database modifications not rolling back In-Reply-To: References: Message-ID: <57c63afe0703021109u4687729y98d122a091d7ae8e@mail.gmail.com> did you run script/generate rspec? There's a new structure in spec_helper.rb. You may need to blow away your test db and recreate it because you've added records to it now. Please let us know if that does the trick. Cheers, David On 3/2/07, David Smalley wrote: > Hi, > > Since moving this morning from 0.7.5.1 to 0.8.2 I've hit some > problems and I'm not sure if it's something I'm doing wrong or a > change in 0.8.2 > > Basically I dislike fixtures so I have been using a helper method to > create an object I need frequently and setting it up in the setup > method, in 0.7.5.1 this all worked fine - but since moving to 0.8.2 > I'm finding that the records are not removed from the database after > each spec, leading to a failure on the next attempt to create the > identical record (there is some uniqueness validation on the model). > After all tests have finished the test database is populated entirely > with all the records I have created, whereas on 0.7.5.1 I'd find this > database completely empty on completion. > > FYI - I'm using Rspec 0.8.2 with matching revision of rspec_on_rails, > Rails 1.2.2 and Mysql. > > > spec_helper.rb > > module CompetitionSpecHelper > def new_competition > code_to_create_a_new_competition > return the competition > end > end > > > competition_spec.rb > > require File.dirname(__FILE__) + '/../spec_helper' > > context "Given a visible competition" do > include CompetitionSpecHelper > > setup do > @competition = new_competition > @competition.process! > end > > specify "should return true for started?" do > @competition.started? should == true > end > ...................... > > > Is there something wrong with what I have been doing? All tests were > passing before the upgrade, it'll take me a while to go through and > change to fixtures if this isn't the correct way to do it. I had seen > numerous discussion around Rspec that seemed to validate the way I've > been doing things, in spirit at least. > > Thanks, > > David > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From david.smalley.lists at googlemail.com Fri Mar 2 17:29:30 2007 From: david.smalley.lists at googlemail.com (David Smalley) Date: Fri, 2 Mar 2007 22:29:30 +0000 Subject: [rspec-users] database modifications not rolling back In-Reply-To: <57c63afe0703021109u4687729y98d122a091d7ae8e@mail.gmail.com> References: <57c63afe0703021109u4687729y98d122a091d7ae8e@mail.gmail.com> Message-ID: <2AEB35E4-E9C1-4AD7-9AB3-3A909F8E7796@googlemail.com> On 2 Mar 2007, at 19:09, David Chelimsky wrote: > did you run script/generate rspec? D'oh > > There's a new structure in spec_helper.rb. > > You may need to blow away your test db and recreate it because you've > added records to it now. > > Please let us know if that does the trick. Yes, that did the trick - I feel silly missing that. Thanks David -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070302/40eb03c0/attachment.html From cwdinfo at gmail.com Sat Mar 3 18:07:12 2007 From: cwdinfo at gmail.com (s.ross) Date: Sat, 3 Mar 2007 15:07:12 -0800 Subject: [rspec-users] ignoring attempt to close td with tr ??? Message-ID: <1509F83D-05E3-424B-B3BA-8C5A74594333@gmail.com> I got the most current rspec and installed as a plugin. Running rake spec:controllers gives me this error: ignoring attempt to close td with tr I dumped response.body and everything looks fine. Is this a known issue? Nothing in Google about it. Thanks, Steve From dchelimsky at gmail.com Sat Mar 3 18:36:00 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 3 Mar 2007 17:36:00 -0600 Subject: [rspec-users] ignoring attempt to close td with tr ??? In-Reply-To: <1509F83D-05E3-424B-B3BA-8C5A74594333@gmail.com> References: <1509F83D-05E3-424B-B3BA-8C5A74594333@gmail.com> Message-ID: <57c63afe0703031536q35d94195x12b49fb0cf7ff313@mail.gmail.com> On 3/3/07, s.ross wrote: > I got the most current rspec and installed as a plugin. Running rake > spec:controllers gives me this error: > > ignoring attempt to close td with tr > > I dumped response.body and everything looks fine. Is this a known > issue? Nothing in Google about it. There is certainly nothing in rspec that produces that error directly. Any chance you also updated other plugins at the same time? Or rails? > > Thanks, > > Steve > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From cwdinfo at gmail.com Sat Mar 3 23:39:46 2007 From: cwdinfo at gmail.com (s.ross) Date: Sat, 3 Mar 2007 20:39:46 -0800 Subject: [rspec-users] ignoring attempt to close td with tr ??? In-Reply-To: <57c63afe0703031536q35d94195x12b49fb0cf7ff313@mail.gmail.com> References: <1509F83D-05E3-424B-B3BA-8C5A74594333@gmail.com> <57c63afe0703031536q35d94195x12b49fb0cf7ff313@mail.gmail.com> Message-ID: <8FDC6E50-D1D8-458C-BE9C-11E1A6D6FAEA@gmail.com> Aha! I found the problem. It actually was a markup issue that the validator missed :( Is the output from hPricot? Thanks, Steve On Mar 3, 2007, at 3:36 PM, David Chelimsky wrote: > On 3/3/07, s.ross wrote: >> I got the most current rspec and installed as a plugin. Running rake >> spec:controllers gives me this error: >> >> ignoring attempt to close td with tr >> >> I dumped response.body and everything looks fine. Is this a known >> issue? Nothing in Google about it. > > There is certainly nothing in rspec that produces that error directly. > Any chance you also updated other plugins at the same time? Or rails? > >> >> 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 francois.beausoleil at gmail.com Sun Mar 4 23:08:10 2007 From: francois.beausoleil at gmail.com (=?UTF-8?Q?Fran=C3=A7ois_Beausoleil?=) Date: Sun, 4 Mar 2007 23:08:10 -0500 Subject: [rspec-users] ignoring attempt to close td with tr ??? In-Reply-To: <8FDC6E50-D1D8-458C-BE9C-11E1A6D6FAEA@gmail.com> References: <1509F83D-05E3-424B-B3BA-8C5A74594333@gmail.com> <57c63afe0703031536q35d94195x12b49fb0cf7ff313@mail.gmail.com> <8FDC6E50-D1D8-458C-BE9C-11E1A6D6FAEA@gmail.com> Message-ID: <41d5fadf0703042008k5cb5fd28i47a9edc459fec026@mail.gmail.com> Hi ! 2007/3/3, s.ross : > Aha! I found the problem. It actually was a markup issue that the > validator missed :( > > Is the output from hPricot? No, the output comes from Rails bundled HTML parser. Look in vendor/rails/actionpack/**/vendor/ Bye ! -- Fran?ois Beausoleil http://blog.teksol.info/ http://piston.rubyforge.org/ From JohnnyButler7 at gmail.com Tue Mar 6 04:05:22 2007 From: JohnnyButler7 at gmail.com (johnnybutler7) Date: Tue, 6 Mar 2007 01:05:22 -0800 (PST) Subject: [rspec-users] Windows rspec "gem install win32console" Message-ID: <9328370.post@talk.nabble.com> Hi, Hi I am trying to use RSPEC on windows and i keep getting the following error "You must gem install win32console to use colour on Windows" I have installed this Gem but i am still getting the same error. The file that error is coming from is: C:\ruby\lib\ruby\gems\1.8\gems\rspec-0.8.2\lib\spec\runner\formatter\base_text_formatter.rb Do i need to put this line of code in? Where do i put it? require 'Win32/Console/ANSI' Can anyone help me, ive searched the web but cant seem to find a solution. JB -- View this message in context: http://www.nabble.com/Windows-rspec-%22gem-install-win32console%22-tf3354239.html#a9328370 Sent from the rspec-users mailing list archive at Nabble.com. From JohnnyButler7 at gmail.com Tue Mar 6 05:13:10 2007 From: JohnnyButler7 at gmail.com (johnnybutler7) Date: Tue, 6 Mar 2007 02:13:10 -0800 (PST) Subject: [rspec-users] Windows rspec "gem install win32console" In-Reply-To: <9328370.post@talk.nabble.com> References: <9328370.post@talk.nabble.com> Message-ID: <9328875.post@talk.nabble.com> I have removed the --colour from the spec.opts file to see if it was just a colour problem. I now get this error below, i am using rails 1.2.2: ** Execute spec:models C:/ruby/bin/ruby -I"C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib" "C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/bin/spec" "spec/models/user_spec.rb" --options "C:/Documents and Settings/JohnButler/My Documents/Ruby on Rails/eclipse/workspace/Workspace/sports/config/../spec/spec.opts" C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/command_line.rb:26:in `run': File or directory not found: (RuntimeError) from C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/command_line.rb:18:in `each' from C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/command_line.rb:18:in `run' from C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/option_parser.rb:149:in `parse' from C:/ruby/lib/ruby/1.8/optparse.rb:1218:in `call' from C:/ruby/lib/ruby/1.8/optparse.rb:1218:in `order!' from C:/ruby/lib/ruby/1.8/optparse.rb:1205:in `catch' from C:/ruby/lib/ruby/1.8/optparse.rb:1205:in `order!' from C:/ruby/lib/ruby/1.8/optparse.rb:1279:in `permute!' from C:/ruby/lib/ruby/1.8/optparse.rb:1300:in `parse!' from C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/option_parser.rb:185:in `parse' from C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/option_parser.rb:18:in `create_context_runner' from C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/command_line.rb:14:in `run' from C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/bin/spec:4 ** Invoke spec:controllers (first_time) ** Invoke db:test:prepare ** Execute spec:controllers ** Invoke spec:helpers (first_time) ** Invoke db:test:prepare ** Execute spec:helpers ** Invoke spec:views (first_time) ** Invoke db:test:prepare ** Execute spec:views rake aborted! RSpec failures C:/Documents and Settings/JohnButler/My Documents/Ruby on Rails/eclipse/workspace/Workspace/sports/config/../vendor/plugins/rspec_on_rails/tasks/rspec.rake:32 C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in `call' C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in `execute' C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in `each' C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in `execute' C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:357:in `invoke' C:/ruby/lib/ruby/1.8/thread.rb:135:in `synchronize' C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:350:in `invoke' C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:in `run' C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:in `each' C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:in `run' C:\ruby\lib\ruby\gems\1.8\gems\rake-0.7.1\bin\rake:7 -e:3:in `load' -e:3 I really want to use RSpec with my rails development but cant it running properly. JB johnnybutler7 wrote: > > Hi, > > Hi I am trying to use RSPEC on windows and i keep getting the following > error > > "You must gem install win32console to use colour on Windows" > > I have installed this Gem but i am still getting the same error. The > file that error is coming from is: > C:\ruby\lib\ruby\gems\1.8\gems\rspec-0.8.2\lib\spec\runner\formatter\base_text_formatter.rb > > Do i need to put this line of code in? Where do i put it? > require 'Win32/Console/ANSI' > > Can anyone help me, ive searched the web but cant seem to find a > solution. > > JB > -- View this message in context: http://www.nabble.com/Windows-rspec-%22gem-install-win32console%22-tf3354239.html#a9328875 Sent from the rspec-users mailing list archive at Nabble.com. From dchelimsky at gmail.com Tue Mar 6 08:19:24 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 6 Mar 2007 07:19:24 -0600 Subject: [rspec-users] Windows rspec "gem install win32console" In-Reply-To: <9328370.post@talk.nabble.com> References: <9328370.post@talk.nabble.com> Message-ID: <57c63afe0703060519u553a90fv4876d008be5701af@mail.gmail.com> On 3/6/07, johnnybutler7 wrote: > > Hi, > > Hi I am trying to use RSPEC on windows and i keep getting the following > error > > "You must gem install win32console to use colour on Windows" > > I have installed this Gem but i am still getting the same error. The > file that error is coming from is: > C:\ruby\lib\ruby\gems\1.8\gems\rspec-0.8.2\lib\spec\runner\formatter\base_text_formatter.rb That line reads as follows: begin ; require 'Win32/Console/ANSI' if @colour && PLATFORM =~ /win32/ ; rescue LoadError ; raise "You must gem install win32console to use colour on Windows" ; end So it seems odd that your rspec was complaining even after you installed the plugin. There are people are using rspec on windows w/ some success, so I'm not convinced the problem is in rspec alone - it seems to be in rspec in conjunction w/ your particular system. Any chance you recently upgraded to Vista? Maybe the environment variables have changed? David > > Do i need to put this line of code in? Where do i put it? > require 'Win32/Console/ANSI' > > Can anyone help me, ive searched the web but cant seem to find a > solution. > > JB > -- > View this message in context: http://www.nabble.com/Windows-rspec-%22gem-install-win32console%22-tf3354239.html#a9328370 > 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 JohnnyButler7 at gmail.com Tue Mar 6 08:47:19 2007 From: JohnnyButler7 at gmail.com (johnnybutler7) Date: Tue, 6 Mar 2007 05:47:19 -0800 (PST) Subject: [rspec-users] Windows rspec "gem install win32console" In-Reply-To: <9328875.post@talk.nabble.com> References: <9328370.post@talk.nabble.com> <9328875.post@talk.nabble.com> Message-ID: <9332300.post@talk.nabble.com> Thanks for your reply. No i have not upgraded to Vista, im still on windows XP. I only installed rspec yesterday and think i have followed the instructions correctly from here http://rspec.rubyforge.org/documentation/rails/install.html. I am running rails 1.2.2 which may be different to current rspec rails windows users. Im stll have the same problems mentioned in the last posts. Im really stumped now. John B johnnybutler7 wrote: > > I have removed the --colour from the spec.opts file to see if it was just > a colour problem. > > I now get this error below, i am using rails 1.2.2: > > ** Execute spec:models > C:/ruby/bin/ruby -I"C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib" > "C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/bin/spec" > "spec/models/user_spec.rb" --options "C:/Documents and > Settings/JohnButler/My Documents/Ruby on > Rails/eclipse/workspace/Workspace/sports/config/../spec/spec.opts" > C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/command_line.rb:26:in > `run': File or directory not found: (RuntimeError) > from > C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/command_line.rb:18:in > `each' > from > C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/command_line.rb:18:in > `run' > from > C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/option_parser.rb:149:in > `parse' > from C:/ruby/lib/ruby/1.8/optparse.rb:1218:in `call' > from C:/ruby/lib/ruby/1.8/optparse.rb:1218:in `order!' > from C:/ruby/lib/ruby/1.8/optparse.rb:1205:in `catch' > from C:/ruby/lib/ruby/1.8/optparse.rb:1205:in `order!' > from C:/ruby/lib/ruby/1.8/optparse.rb:1279:in `permute!' > from C:/ruby/lib/ruby/1.8/optparse.rb:1300:in `parse!' > from > C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/option_parser.rb:185:in > `parse' > from > C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/option_parser.rb:18:in > `create_context_runner' > from > C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/command_line.rb:14:in > `run' > from C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/bin/spec:4 > ** Invoke spec:controllers (first_time) > ** Invoke db:test:prepare > ** Execute spec:controllers > ** Invoke spec:helpers (first_time) > ** Invoke db:test:prepare > ** Execute spec:helpers > ** Invoke spec:views (first_time) > ** Invoke db:test:prepare > ** Execute spec:views > rake aborted! > RSpec failures > C:/Documents and Settings/JohnButler/My Documents/Ruby on > Rails/eclipse/workspace/Workspace/sports/config/../vendor/plugins/rspec_on_rails/tasks/rspec.rake:32 > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in `call' > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in `execute' > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in `each' > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in `execute' > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:357:in `invoke' > C:/ruby/lib/ruby/1.8/thread.rb:135:in `synchronize' > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:350:in `invoke' > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:in `run' > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:in `each' > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:in `run' > C:\ruby\lib\ruby\gems\1.8\gems\rake-0.7.1\bin\rake:7 > -e:3:in `load' > -e:3 > > I really want to use RSpec with my rails development but cant it running > properly. > > JB > > > > > > johnnybutler7 wrote: >> >> Hi, >> >> Hi I am trying to use RSPEC on windows and i keep getting the following >> error >> >> "You must gem install win32console to use colour on Windows" >> >> I have installed this Gem but i am still getting the same error. The >> file that error is coming from is: >> C:\ruby\lib\ruby\gems\1.8\gems\rspec-0.8.2\lib\spec\runner\formatter\base_text_formatter.rb >> >> Do i need to put this line of code in? Where do i put it? >> require 'Win32/Console/ANSI' >> >> Can anyone help me, ive searched the web but cant seem to find a >> solution. >> >> JB >> > > -- View this message in context: http://www.nabble.com/Windows-rspec-%22gem-install-win32console%22-tf3354239.html#a9332300 Sent from the rspec-users mailing list archive at Nabble.com. From JohnnyButler7 at gmail.com Tue Mar 6 09:58:00 2007 From: JohnnyButler7 at gmail.com (johnnybutler7) Date: Tue, 6 Mar 2007 06:58:00 -0800 (PST) Subject: [rspec-users] Windows rspec "gem install win32console" In-Reply-To: <57c63afe0703060519u553a90fv4876d008be5701af@mail.gmail.com> References: <9328370.post@talk.nabble.com> <57c63afe0703060519u553a90fv4876d008be5701af@mail.gmail.com> Message-ID: <9333516.post@talk.nabble.com> Hi, i have got RSpec to work on my machine now. I created a new app and followed the instructions again. If i navigate to the spec folder int he rails directory and type spec user_spec.rb then this works fine. If i try the rake command rake spec:models first of all i get the "gem install win32console", so if i remove the --colour from the options i get the error i posted above. Its basically saying it cannot find the spec files. Do i need to set the path somehwere so when i do a rake spec:models it knows where to find them? John B David Chelimsky-2 wrote: > > On 3/6/07, johnnybutler7 wrote: >> >> Hi, >> >> Hi I am trying to use RSPEC on windows and i keep getting the following >> error >> >> "You must gem install win32console to use colour on Windows" >> >> I have installed this Gem but i am still getting the same error. The >> file that error is coming from is: >> C:\ruby\lib\ruby\gems\1.8\gems\rspec-0.8.2\lib\spec\runner\formatter\base_text_formatter.rb > > That line reads as follows: > > begin ; require 'Win32/Console/ANSI' if @colour && PLATFORM =~ /win32/ > ; rescue LoadError ; raise "You must gem install win32console to use > colour on Windows" ; end > > So it seems odd that your rspec was complaining even after you > installed the plugin. There are people are using rspec on windows w/ > some success, so I'm not convinced the problem is in rspec alone - it > seems to be in rspec in conjunction w/ your particular system. > > Any chance you recently upgraded to Vista? Maybe the environment > variables have changed? > > David > >> >> Do i need to put this line of code in? Where do i put it? >> require 'Win32/Console/ANSI' >> >> Can anyone help me, ive searched the web but cant seem to find a >> solution. >> >> JB >> -- >> View this message in context: >> http://www.nabble.com/Windows-rspec-%22gem-install-win32console%22-tf3354239.html#a9328370 >> Sent from the rspec-users mailing list archive at Nabble.com. >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > -- View this message in context: http://www.nabble.com/Windows-rspec-%22gem-install-win32console%22-tf3354239.html#a9333516 Sent from the rspec-users mailing list archive at Nabble.com. From dchelimsky at gmail.com Tue Mar 6 10:01:40 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 6 Mar 2007 09:01:40 -0600 Subject: [rspec-users] Windows rspec "gem install win32console" In-Reply-To: <9333516.post@talk.nabble.com> References: <9328370.post@talk.nabble.com> <57c63afe0703060519u553a90fv4876d008be5701af@mail.gmail.com> <9333516.post@talk.nabble.com> Message-ID: <57c63afe0703060701pa7acdbam85cd0d2cf0015acf@mail.gmail.com> On 3/6/07, johnnybutler7 wrote: > > Hi, > > i have got RSpec to work on my machine now. I created a new app and > followed the instructions again. If i navigate to the spec folder int he > rails directory and type spec user_spec.rb then this works fine. If i try > the rake command > > rake spec:models This rake task assumes model specs are in spec/models. Is user_spec.rb at spec/models/user_spec.rb? > > first of all i get the "gem install win32console", so if i remove the > --colour from the options i get the error i posted above. Its basically > saying it cannot find the spec files. Do i need to set the path somehwere > so when i do a rake spec:models it knows where to find them? > > John B > > > > > David Chelimsky-2 wrote: > > > > On 3/6/07, johnnybutler7 wrote: > >> > >> Hi, > >> > >> Hi I am trying to use RSPEC on windows and i keep getting the following > >> error > >> > >> "You must gem install win32console to use colour on Windows" > >> > >> I have installed this Gem but i am still getting the same error. The > >> file that error is coming from is: > >> C:\ruby\lib\ruby\gems\1.8\gems\rspec-0.8.2\lib\spec\runner\formatter\base_text_formatter.rb > > > > That line reads as follows: > > > > begin ; require 'Win32/Console/ANSI' if @colour && PLATFORM =~ /win32/ > > ; rescue LoadError ; raise "You must gem install win32console to use > > colour on Windows" ; end > > > > So it seems odd that your rspec was complaining even after you > > installed the plugin. There are people are using rspec on windows w/ > > some success, so I'm not convinced the problem is in rspec alone - it > > seems to be in rspec in conjunction w/ your particular system. > > > > Any chance you recently upgraded to Vista? Maybe the environment > > variables have changed? > > > > David > > > >> > >> Do i need to put this line of code in? Where do i put it? > >> require 'Win32/Console/ANSI' > >> > >> Can anyone help me, ive searched the web but cant seem to find a > >> solution. > >> > >> JB > >> -- > >> View this message in context: > >> http://www.nabble.com/Windows-rspec-%22gem-install-win32console%22-tf3354239.html#a9328370 > >> Sent from the rspec-users mailing list archive at Nabble.com. > >> > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-users at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/rspec-users > >> > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > -- > View this message in context: http://www.nabble.com/Windows-rspec-%22gem-install-win32console%22-tf3354239.html#a9333516 > 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 JohnnyButler7 at gmail.com Tue Mar 6 10:51:24 2007 From: JohnnyButler7 at gmail.com (johnnybutler7) Date: Tue, 6 Mar 2007 07:51:24 -0800 (PST) Subject: [rspec-users] Windows rspec "gem install win32console" In-Reply-To: <57c63afe0703060701pa7acdbam85cd0d2cf0015acf@mail.gmail.com> References: <9328370.post@talk.nabble.com> <57c63afe0703060519u553a90fv4876d008be5701af@mail.gmail.com> <9333516.post@talk.nabble.com> <57c63afe0703060701pa7acdbam85cd0d2cf0015acf@mail.gmail.com> Message-ID: <9334771.post@talk.nabble.com> Yes, thats why i cant understand why i am getting this error message. I used ./script/generate rspec_model User and that created the user_spec.rb file in the spec/models folder. This is the full message with --trace (in C:/Documents and Settings/JohnButler/My Documents/Ruby on Rails/eclipse/workspace/Workspace/sports) ** Invoke spec:models (first_time) ** Invoke db:test:prepare (first_time) ** Invoke environment (first_time) ** Execute environment ** Execute db:test:prepare ** Invoke db:test:clone (first_time) ** Invoke db:schema:dump (first_time) ** Invoke environment ** Execute db:schema:dump ** Invoke db:test:purge (first_time) ** Invoke environment ** Execute db:test:purge ** Execute db:test:clone ** Invoke db:schema:load (first_time) ** Invoke environment ** Execute db:schema:load ** Execute spec:models C:/ruby/bin/ruby -I"C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib" "C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/bin/spec" "spec/models/user_spec.rb" --options "C:/Documents and Settings/JohnButler/My Documents/Ruby on Rails/eclipse/workspace/Workspace/sports/config/../spec/spec.opts" C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/command_line.rb:26:in `run': File or directory not found: (RuntimeError) from C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/command_line.rb:18:in `each' from C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/command_line.rb:18:in `run' from C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/option_parser.rb:149:in `parse' from C:/ruby/lib/ruby/1.8/optparse.rb:1218:in `call' from C:/ruby/lib/ruby/1.8/optparse.rb:1218:in `order!' from C:/ruby/lib/ruby/1.8/optparse.rb:1205:in `catch' from C:/ruby/lib/ruby/1.8/optparse.rb:1205:in `order!' from C:/ruby/lib/ruby/1.8/optparse.rb:1279:in `permute!' from C:/ruby/lib/ruby/1.8/optparse.rb:1300:in `parse!' from C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/option_parser.rb:185:in `parse' from C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/option_parser.rb:18:in `create_context_runner' from C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/command_line.rb:14:in `run' from C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/bin/spec:4 rake aborted! Command failed with status (1): [C:/ruby/bin/ruby -I"C:/ruby/lib/ruby/gems/...] C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:722:in `sh' C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:729:in `call' C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:729:in `sh' C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:812:in `sh' C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:747:in `ruby' C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:812:in `ruby' C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/rake/spectask.rb:126:in `define' C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:831:in `verbose' C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/rake/spectask.rb:105:in `define' C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in `call' C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in `execute' C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in `each' C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in `execute' C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:357:in `invoke' C:/ruby/lib/ruby/1.8/thread.rb:135:in `synchronize' C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:350:in `invoke' C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:in `run' C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:in `each' C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:in `run' C:\ruby\lib\ruby\gems\1.8\gems\rake-0.7.1\bin\rake:7 -e:3:in `load' -e:3 David Chelimsky-2 wrote: > > On 3/6/07, johnnybutler7 wrote: >> >> Hi, >> >> i have got RSpec to work on my machine now. I created a new app and >> followed the instructions again. If i navigate to the spec folder int he >> rails directory and type spec user_spec.rb then this works fine. If i >> try >> the rake command >> >> rake spec:models > > This rake task assumes model specs are in spec/models. Is user_spec.rb > at spec/models/user_spec.rb? > >> >> first of all i get the "gem install win32console", so if i remove the >> --colour from the options i get the error i posted above. Its basically >> saying it cannot find the spec files. Do i need to set the path >> somehwere >> so when i do a rake spec:models it knows where to find them? >> >> John B >> >> >> >> >> David Chelimsky-2 wrote: >> > >> > On 3/6/07, johnnybutler7 wrote: >> >> >> >> Hi, >> >> >> >> Hi I am trying to use RSPEC on windows and i keep getting the >> following >> >> error >> >> >> >> "You must gem install win32console to use colour on Windows" >> >> >> >> I have installed this Gem but i am still getting the same error. The >> >> file that error is coming from is: >> >> >> C:\ruby\lib\ruby\gems\1.8\gems\rspec-0.8.2\lib\spec\runner\formatter\base_text_formatter.rb >> > >> > That line reads as follows: >> > >> > begin ; require 'Win32/Console/ANSI' if @colour && PLATFORM =~ /win32/ >> > ; rescue LoadError ; raise "You must gem install win32console to use >> > colour on Windows" ; end >> > >> > So it seems odd that your rspec was complaining even after you >> > installed the plugin. There are people are using rspec on windows w/ >> > some success, so I'm not convinced the problem is in rspec alone - it >> > seems to be in rspec in conjunction w/ your particular system. >> > >> > Any chance you recently upgraded to Vista? Maybe the environment >> > variables have changed? >> > >> > David >> > >> >> >> >> Do i need to put this line of code in? Where do i put it? >> >> require 'Win32/Console/ANSI' >> >> >> >> Can anyone help me, ive searched the web but cant seem to find a >> >> solution. >> >> >> >> JB >> >> -- >> >> View this message in context: >> >> >> http://www.nabble.com/Windows-rspec-%22gem-install-win32console%22-tf3354239.html#a9328370 >> >> Sent from the rspec-users mailing list archive at Nabble.com. >> >> >> >> _______________________________________________ >> >> rspec-users mailing list >> >> rspec-users at rubyforge.org >> >> http://rubyforge.org/mailman/listinfo/rspec-users >> >> >> > _______________________________________________ >> > rspec-users mailing list >> > rspec-users at rubyforge.org >> > http://rubyforge.org/mailman/listinfo/rspec-users >> > >> > >> >> -- >> View this message in context: >> http://www.nabble.com/Windows-rspec-%22gem-install-win32console%22-tf3354239.html#a9333516 >> Sent from the rspec-users mailing list archive at Nabble.com. >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > -- View this message in context: http://www.nabble.com/Windows-rspec-%22gem-install-win32console%22-tf3354239.html#a9334771 Sent from the rspec-users mailing list archive at Nabble.com. From dchelimsky at gmail.com Tue Mar 6 11:43:08 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 6 Mar 2007 10:43:08 -0600 Subject: [rspec-users] Windows rspec "gem install win32console" In-Reply-To: <9334771.post@talk.nabble.com> References: <9328370.post@talk.nabble.com> <57c63afe0703060519u553a90fv4876d008be5701af@mail.gmail.com> <9333516.post@talk.nabble.com> <57c63afe0703060701pa7acdbam85cd0d2cf0015acf@mail.gmail.com> <9334771.post@talk.nabble.com> Message-ID: <57c63afe0703060843y36b8b0cet37d3aa33835e909c@mail.gmail.com> On 3/6/07, johnnybutler7 wrote: > > Yes, thats why i cant understand why i am getting this error message. I > used ./script/generate rspec_model User and that created the user_spec.rb > file in the spec/models folder. Unfortunately (or fortunately, depending on your view), I don't have a winbox w/ everything set up to troubleshoot this. Is there anyone else on the list who can chime in who is successfully using Spec::Rails 0.8, Rails 1.2.2 on windows? > > This is the full message with --trace > > (in C:/Documents and Settings/JohnButler/My Documents/Ruby on > Rails/eclipse/workspace/Workspace/sports) > ** Invoke spec:models (first_time) > ** Invoke db:test:prepare (first_time) > ** Invoke environment (first_time) > ** Execute environment > ** Execute db:test:prepare > ** Invoke db:test:clone (first_time) > ** Invoke db:schema:dump (first_time) > ** Invoke environment > ** Execute db:schema:dump > ** Invoke db:test:purge (first_time) > ** Invoke environment > ** Execute db:test:purge > ** Execute db:test:clone > ** Invoke db:schema:load (first_time) > ** Invoke environment > ** Execute db:schema:load > ** Execute spec:models > C:/ruby/bin/ruby -I"C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib" > "C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/bin/spec" > "spec/models/user_spec.rb" --options "C:/Documents and > Settings/JohnButler/My Documents/Ruby on > Rails/eclipse/workspace/Workspace/sports/config/../spec/spec.opts" > C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/command_line.rb:26:in > `run': File or directory not found: (RuntimeError) > from > C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/command_line.rb:18:in > `each' > from > C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/command_line.rb:18:in > `run' > from > C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/option_parser.rb:149:in > `parse' > from C:/ruby/lib/ruby/1.8/optparse.rb:1218:in `call' > from C:/ruby/lib/ruby/1.8/optparse.rb:1218:in `order!' > from C:/ruby/lib/ruby/1.8/optparse.rb:1205:in `catch' > from C:/ruby/lib/ruby/1.8/optparse.rb:1205:in `order!' > from C:/ruby/lib/ruby/1.8/optparse.rb:1279:in `permute!' > from C:/ruby/lib/ruby/1.8/optparse.rb:1300:in `parse!' > from > C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/option_parser.rb:185:in > `parse' > from > C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/option_parser.rb:18:in > `create_context_runner' > from > C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/command_line.rb:14:in > `run' > from C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/bin/spec:4 > rake aborted! > Command failed with status (1): [C:/ruby/bin/ruby > -I"C:/ruby/lib/ruby/gems/...] > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:722:in `sh' > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:729:in `call' > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:729:in `sh' > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:812:in `sh' > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:747:in `ruby' > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:812:in `ruby' > C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/rake/spectask.rb:126:in > `define' > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:831:in `verbose' > C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/rake/spectask.rb:105:in > `define' > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in `call' > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in `execute' > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in `each' > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in `execute' > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:357:in `invoke' > C:/ruby/lib/ruby/1.8/thread.rb:135:in `synchronize' > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:350:in `invoke' > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:in `run' > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:in `each' > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:in `run' > C:\ruby\lib\ruby\gems\1.8\gems\rake-0.7.1\bin\rake:7 > -e:3:in `load' > -e:3 > > > > David Chelimsky-2 wrote: > > > > On 3/6/07, johnnybutler7 wrote: > >> > >> Hi, > >> > >> i have got RSpec to work on my machine now. I created a new app and > >> followed the instructions again. If i navigate to the spec folder int he > >> rails directory and type spec user_spec.rb then this works fine. If i > >> try > >> the rake command > >> > >> rake spec:models > > > > This rake task assumes model specs are in spec/models. Is user_spec.rb > > at spec/models/user_spec.rb? > > > >> > >> first of all i get the "gem install win32console", so if i remove the > >> --colour from the options i get the error i posted above. Its basically > >> saying it cannot find the spec files. Do i need to set the path > >> somehwere > >> so when i do a rake spec:models it knows where to find them? > >> > >> John B > >> > >> > >> > >> > >> David Chelimsky-2 wrote: > >> > > >> > On 3/6/07, johnnybutler7 wrote: > >> >> > >> >> Hi, > >> >> > >> >> Hi I am trying to use RSPEC on windows and i keep getting the > >> following > >> >> error > >> >> > >> >> "You must gem install win32console to use colour on Windows" > >> >> > >> >> I have installed this Gem but i am still getting the same error. The > >> >> file that error is coming from is: > >> >> > >> C:\ruby\lib\ruby\gems\1.8\gems\rspec-0.8.2\lib\spec\runner\formatter\base_text_formatter.rb > >> > > >> > That line reads as follows: > >> > > >> > begin ; require 'Win32/Console/ANSI' if @colour && PLATFORM =~ /win32/ > >> > ; rescue LoadError ; raise "You must gem install win32console to use > >> > colour on Windows" ; end > >> > > >> > So it seems odd that your rspec was complaining even after you > >> > installed the plugin. There are people are using rspec on windows w/ > >> > some success, so I'm not convinced the problem is in rspec alone - it > >> > seems to be in rspec in conjunction w/ your particular system. > >> > > >> > Any chance you recently upgraded to Vista? Maybe the environment > >> > variables have changed? > >> > > >> > David > >> > > >> >> > >> >> Do i need to put this line of code in? Where do i put it? > >> >> require 'Win32/Console/ANSI' > >> >> > >> >> Can anyone help me, ive searched the web but cant seem to find a > >> >> solution. > >> >> > >> >> JB > >> >> -- > >> >> View this message in context: > >> >> > >> http://www.nabble.com/Windows-rspec-%22gem-install-win32console%22-tf3354239.html#a9328370 > >> >> Sent from the rspec-users mailing list archive at Nabble.com. > >> >> > >> >> _______________________________________________ > >> >> rspec-users mailing list > >> >> rspec-users at rubyforge.org > >> >> http://rubyforge.org/mailman/listinfo/rspec-users > >> >> > >> > _______________________________________________ > >> > rspec-users mailing list > >> > rspec-users at rubyforge.org > >> > http://rubyforge.org/mailman/listinfo/rspec-users > >> > > >> > > >> > >> -- > >> View this message in context: > >> http://www.nabble.com/Windows-rspec-%22gem-install-win32console%22-tf3354239.html#a9333516 > >> Sent from the rspec-users mailing list archive at Nabble.com. > >> > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-users at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/rspec-users > >> > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > -- > View this message in context: http://www.nabble.com/Windows-rspec-%22gem-install-win32console%22-tf3354239.html#a9334771 > 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 kevwil at gmail.com Tue Mar 6 13:33:47 2007 From: kevwil at gmail.com (Kevin Williams) Date: Tue, 6 Mar 2007 11:33:47 -0700 Subject: [rspec-users] Windows rspec "gem install win32console" In-Reply-To: <57c63afe0703060843y36b8b0cet37d3aa33835e909c@mail.gmail.com> References: <9328370.post@talk.nabble.com> <57c63afe0703060519u553a90fv4876d008be5701af@mail.gmail.com> <9333516.post@talk.nabble.com> <57c63afe0703060701pa7acdbam85cd0d2cf0015acf@mail.gmail.com> <9334771.post@talk.nabble.com> <57c63afe0703060843y36b8b0cet37d3aa33835e909c@mail.gmail.com> Message-ID: <683a886f0703061033n292c0e21nd8ef31cf44db8c12@mail.gmail.com> My rails app seems to be broken today (pgsql 8.2 problem), but I ran the specs successfully yesterday. Rails 1.2.2, rspec 0.8.2, win32console 1.0.8. I'm kind of a power user though. My Start => All Programs menu fills my entire screen, and I have all the UnxUtils binaries in my path. :-] On 3/6/07, David Chelimsky wrote: > On 3/6/07, johnnybutler7 wrote: > > > > Yes, thats why i cant understand why i am getting this error message. I > > used ./script/generate rspec_model User and that created the user_spec.rb > > file in the spec/models folder. > > Unfortunately (or fortunately, depending on your view), I don't have a > winbox w/ everything set up to troubleshoot this. Is there anyone > else on the list who can chime in who is successfully using > Spec::Rails 0.8, Rails 1.2.2 on windows? > > > > > This is the full message with --trace > > > > (in C:/Documents and Settings/JohnButler/My Documents/Ruby on > > Rails/eclipse/workspace/Workspace/sports) > > ** Invoke spec:models (first_time) > > ** Invoke db:test:prepare (first_time) > > ** Invoke environment (first_time) > > ** Execute environment > > ** Execute db:test:prepare > > ** Invoke db:test:clone (first_time) > > ** Invoke db:schema:dump (first_time) > > ** Invoke environment > > ** Execute db:schema:dump > > ** Invoke db:test:purge (first_time) > > ** Invoke environment > > ** Execute db:test:purge > > ** Execute db:test:clone > > ** Invoke db:schema:load (first_time) > > ** Invoke environment > > ** Execute db:schema:load > > ** Execute spec:models > > C:/ruby/bin/ruby -I"C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib" > > "C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/bin/spec" > > "spec/models/user_spec.rb" --options "C:/Documents and > > Settings/JohnButler/My Documents/Ruby on > > Rails/eclipse/workspace/Workspace/sports/config/../spec/spec.opts" > > C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/command_line.rb:26:in > > `run': File or directory not found: (RuntimeError) > > from > > C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/command_line.rb:18:in > > `each' > > from > > C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/command_line.rb:18:in > > `run' > > from > > C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/option_parser.rb:149:in > > `parse' > > from C:/ruby/lib/ruby/1.8/optparse.rb:1218:in `call' > > from C:/ruby/lib/ruby/1.8/optparse.rb:1218:in `order!' > > from C:/ruby/lib/ruby/1.8/optparse.rb:1205:in `catch' > > from C:/ruby/lib/ruby/1.8/optparse.rb:1205:in `order!' > > from C:/ruby/lib/ruby/1.8/optparse.rb:1279:in `permute!' > > from C:/ruby/lib/ruby/1.8/optparse.rb:1300:in `parse!' > > from > > C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/option_parser.rb:185:in > > `parse' > > from > > C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/option_parser.rb:18:in > > `create_context_runner' > > from > > C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/command_line.rb:14:in > > `run' > > from C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/bin/spec:4 > > rake aborted! > > Command failed with status (1): [C:/ruby/bin/ruby > > -I"C:/ruby/lib/ruby/gems/...] > > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:722:in `sh' > > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:729:in `call' > > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:729:in `sh' > > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:812:in `sh' > > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:747:in `ruby' > > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:812:in `ruby' > > C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/rake/spectask.rb:126:in > > `define' > > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:831:in `verbose' > > C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/rake/spectask.rb:105:in > > `define' > > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in `call' > > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in `execute' > > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in `each' > > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in `execute' > > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:357:in `invoke' > > C:/ruby/lib/ruby/1.8/thread.rb:135:in `synchronize' > > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:350:in `invoke' > > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:in `run' > > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:in `each' > > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:in `run' > > C:\ruby\lib\ruby\gems\1.8\gems\rake-0.7.1\bin\rake:7 > > -e:3:in `load' > > -e:3 > > > > > > > > David Chelimsky-2 wrote: > > > > > > On 3/6/07, johnnybutler7 wrote: > > >> > > >> Hi, > > >> > > >> i have got RSpec to work on my machine now. I created a new app and > > >> followed the instructions again. If i navigate to the spec folder int he > > >> rails directory and type spec user_spec.rb then this works fine. If i > > >> try > > >> the rake command > > >> > > >> rake spec:models > > > > > > This rake task assumes model specs are in spec/models. Is user_spec.rb > > > at spec/models/user_spec.rb? > > > > > >> > > >> first of all i get the "gem install win32console", so if i remove the > > >> --colour from the options i get the error i posted above. Its basically > > >> saying it cannot find the spec files. Do i need to set the path > > >> somehwere > > >> so when i do a rake spec:models it knows where to find them? > > >> > > >> John B > > >> > > >> > > >> > > >> > > >> David Chelimsky-2 wrote: > > >> > > > >> > On 3/6/07, johnnybutler7 wrote: > > >> >> > > >> >> Hi, > > >> >> > > >> >> Hi I am trying to use RSPEC on windows and i keep getting the > > >> following > > >> >> error > > >> >> > > >> >> "You must gem install win32console to use colour on Windows" > > >> >> > > >> >> I have installed this Gem but i am still getting the same error. The > > >> >> file that error is coming from is: > > >> >> > > >> C:\ruby\lib\ruby\gems\1.8\gems\rspec-0.8.2\lib\spec\runner\formatter\base_text_formatter.rb > > >> > > > >> > That line reads as follows: > > >> > > > >> > begin ; require 'Win32/Console/ANSI' if @colour && PLATFORM =~ /win32/ > > >> > ; rescue LoadError ; raise "You must gem install win32console to use > > >> > colour on Windows" ; end > > >> > > > >> > So it seems odd that your rspec was complaining even after you > > >> > installed the plugin. There are people are using rspec on windows w/ > > >> > some success, so I'm not convinced the problem is in rspec alone - it > > >> > seems to be in rspec in conjunction w/ your particular system. > > >> > > > >> > Any chance you recently upgraded to Vista? Maybe the environment > > >> > variables have changed? > > >> > > > >> > David > > >> > > > >> >> > > >> >> Do i need to put this line of code in? Where do i put it? > > >> >> require 'Win32/Console/ANSI' > > >> >> > > >> >> Can anyone help me, ive searched the web but cant seem to find a > > >> >> solution. > > >> >> > > >> >> JB > > >> >> -- > > >> >> View this message in context: > > >> >> > > >> http://www.nabble.com/Windows-rspec-%22gem-install-win32console%22-tf3354239.html#a9328370 > > >> >> Sent from the rspec-users mailing list archive at Nabble.com. > > >> >> > > >> >> _______________________________________________ > > >> >> rspec-users mailing list > > >> >> rspec-users at rubyforge.org > > >> >> http://rubyforge.org/mailman/listinfo/rspec-users > > >> >> > > >> > _______________________________________________ > > >> > rspec-users mailing list > > >> > rspec-users at rubyforge.org > > >> > http://rubyforge.org/mailman/listinfo/rspec-users > > >> > > > >> > > > >> > > >> -- > > >> View this message in context: > > >> http://www.nabble.com/Windows-rspec-%22gem-install-win32console%22-tf3354239.html#a9333516 > > >> Sent from the rspec-users mailing list archive at Nabble.com. > > >> > > >> _______________________________________________ > > >> rspec-users mailing list > > >> rspec-users at rubyforge.org > > >> http://rubyforge.org/mailman/listinfo/rspec-users > > >> > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > -- > > View this message in context: http://www.nabble.com/Windows-rspec-%22gem-install-win32console%22-tf3354239.html#a9334771 > > Sent from the rspec-users mailing list archive at Nabble.com. > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Cheers, Kevin Williams http://www.almostserio.us/ "Any sufficiently advanced technology is indistinguishable from Magic." - Arthur C. Clarke From aslak.hellesoy at gmail.com Tue Mar 6 17:19:54 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 6 Mar 2007 16:19:54 -0600 Subject: [rspec-users] Windows rspec "gem install win32console" In-Reply-To: <9334771.post@talk.nabble.com> References: <9328370.post@talk.nabble.com> <57c63afe0703060519u553a90fv4876d008be5701af@mail.gmail.com> <9333516.post@talk.nabble.com> <57c63afe0703060701pa7acdbam85cd0d2cf0015acf@mail.gmail.com> <9334771.post@talk.nabble.com> Message-ID: <8d961d900703061419ydcd8306u3022045bbd5537b7@mail.gmail.com> On 3/6/07, johnnybutler7 wrote: > > Yes, thats why i cant understand why i am getting this error message. I > used ./script/generate rspec_model User and that created the user_spec.rb > file in the spec/models folder. > > This is the full message with --trace > The exception you are getting is thrown from line 26 in command_line.rb (http://rubyforge.org/viewvc/tags/REL_0_8_2/rspec/lib/spec/runner/command_line.rb?revision=1561&root=rspec&view=markup) Looking at line 26 of that file and the error message you are getting: "File or directory not found: (RuntimeError)" it looks like the file_or_dir variable in command_line.rb is nil or an empty string. I see you have lots of spaces in your paths. This could be the source of the problem. Please try to run your code from a path without spaces, then report back. It will tell us whether we should hunt for a bug related to spaces in filenames or something else. Thanks, Aslak > (in C:/Documents and Settings/JohnButler/My Documents/Ruby on > Rails/eclipse/workspace/Workspace/sports) > ** Invoke spec:models (first_time) > ** Invoke db:test:prepare (first_time) > ** Invoke environment (first_time) > ** Execute environment > ** Execute db:test:prepare > ** Invoke db:test:clone (first_time) > ** Invoke db:schema:dump (first_time) > ** Invoke environment > ** Execute db:schema:dump > ** Invoke db:test:purge (first_time) > ** Invoke environment > ** Execute db:test:purge > ** Execute db:test:clone > ** Invoke db:schema:load (first_time) > ** Invoke environment > ** Execute db:schema:load > ** Execute spec:models > C:/ruby/bin/ruby -I"C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib" > "C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/bin/spec" > "spec/models/user_spec.rb" --options "C:/Documents and > Settings/JohnButler/My Documents/Ruby on > Rails/eclipse/workspace/Workspace/sports/config/../spec/spec.opts" > C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/command_line.rb:26:in > `run': File or directory not found: (RuntimeError) > from > C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/command_line.rb:18:in > `each' > from > C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/command_line.rb:18:in > `run' > from > C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/option_parser.rb:149:in > `parse' > from C:/ruby/lib/ruby/1.8/optparse.rb:1218:in `call' > from C:/ruby/lib/ruby/1.8/optparse.rb:1218:in `order!' > from C:/ruby/lib/ruby/1.8/optparse.rb:1205:in `catch' > from C:/ruby/lib/ruby/1.8/optparse.rb:1205:in `order!' > from C:/ruby/lib/ruby/1.8/optparse.rb:1279:in `permute!' > from C:/ruby/lib/ruby/1.8/optparse.rb:1300:in `parse!' > from > C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/option_parser.rb:185:in > `parse' > from > C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/option_parser.rb:18:in > `create_context_runner' > from > C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/command_line.rb:14:in > `run' > from C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/bin/spec:4 > rake aborted! > Command failed with status (1): [C:/ruby/bin/ruby > -I"C:/ruby/lib/ruby/gems/...] > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:722:in `sh' > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:729:in `call' > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:729:in `sh' > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:812:in `sh' > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:747:in `ruby' > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:812:in `ruby' > C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/rake/spectask.rb:126:in > `define' > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:831:in `verbose' > C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/rake/spectask.rb:105:in > `define' > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in `call' > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in `execute' > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in `each' > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in `execute' > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:357:in `invoke' > C:/ruby/lib/ruby/1.8/thread.rb:135:in `synchronize' > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:350:in `invoke' > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:in `run' > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:in `each' > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:in `run' > C:\ruby\lib\ruby\gems\1.8\gems\rake-0.7.1\bin\rake:7 > -e:3:in `load' > -e:3 > > > > David Chelimsky-2 wrote: > > > > On 3/6/07, johnnybutler7 wrote: > >> > >> Hi, > >> > >> i have got RSpec to work on my machine now. I created a new app and > >> followed the instructions again. If i navigate to the spec folder int he > >> rails directory and type spec user_spec.rb then this works fine. If i > >> try > >> the rake command > >> > >> rake spec:models > > > > This rake task assumes model specs are in spec/models. Is user_spec.rb > > at spec/models/user_spec.rb? > > > >> > >> first of all i get the "gem install win32console", so if i remove the > >> --colour from the options i get the error i posted above. Its basically > >> saying it cannot find the spec files. Do i need to set the path > >> somehwere > >> so when i do a rake spec:models it knows where to find them? > >> > >> John B > >> > >> > >> > >> > >> David Chelimsky-2 wrote: > >> > > >> > On 3/6/07, johnnybutler7 wrote: > >> >> > >> >> Hi, > >> >> > >> >> Hi I am trying to use RSPEC on windows and i keep getting the > >> following > >> >> error > >> >> > >> >> "You must gem install win32console to use colour on Windows" > >> >> > >> >> I have installed this Gem but i am still getting the same error. The > >> >> file that error is coming from is: > >> >> > >> C:\ruby\lib\ruby\gems\1.8\gems\rspec-0.8.2\lib\spec\runner\formatter\base_text_formatter.rb > >> > > >> > That line reads as follows: > >> > > >> > begin ; require 'Win32/Console/ANSI' if @colour && PLATFORM =~ /win32/ > >> > ; rescue LoadError ; raise "You must gem install win32console to use > >> > colour on Windows" ; end > >> > > >> > So it seems odd that your rspec was complaining even after you > >> > installed the plugin. There are people are using rspec on windows w/ > >> > some success, so I'm not convinced the problem is in rspec alone - it > >> > seems to be in rspec in conjunction w/ your particular system. > >> > > >> > Any chance you recently upgraded to Vista? Maybe the environment > >> > variables have changed? > >> > > >> > David > >> > > >> >> > >> >> Do i need to put this line of code in? Where do i put it? > >> >> require 'Win32/Console/ANSI' > >> >> > >> >> Can anyone help me, ive searched the web but cant seem to find a > >> >> solution. > >> >> > >> >> JB > >> >> -- > >> >> View this message in context: > >> >> > >> http://www.nabble.com/Windows-rspec-%22gem-install-win32console%22-tf3354239.html#a9328370 > >> >> Sent from the rspec-users mailing list archive at Nabble.com. > >> >> > >> >> _______________________________________________ > >> >> rspec-users mailing list > >> >> rspec-users at rubyforge.org > >> >> http://rubyforge.org/mailman/listinfo/rspec-users > >> >> > >> > _______________________________________________ > >> > rspec-users mailing list > >> > rspec-users at rubyforge.org > >> > http://rubyforge.org/mailman/listinfo/rspec-users > >> > > >> > > >> > >> -- > >> View this message in context: > >> http://www.nabble.com/Windows-rspec-%22gem-install-win32console%22-tf3354239.html#a9333516 > >> Sent from the rspec-users mailing list archive at Nabble.com. > >> > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-users at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/rspec-users > >> > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > -- > View this message in context: http://www.nabble.com/Windows-rspec-%22gem-install-win32console%22-tf3354239.html#a9334771 > 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 work at ashleymoran.me.uk Wed Mar 7 03:02:08 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Wed, 7 Mar 2007 08:02:08 +0000 Subject: [rspec-users] Specifying that code is called in a block In-Reply-To: <86924770703020941v6b1ce9c2j185e42d633b3718b@mail.gmail.com> References: <86924770703020941v6b1ce9c2j185e42d633b3718b@mail.gmail.com> Message-ID: <8730CD7F-7CB7-4CDB-9CF9-AB007AD3A7BD@ashleymoran.me.uk> Hey Lugovoi Not tried that yet but I like the look of it. You'd have to stub out ActiveRecord::Base.transaction to make it work (meddling with another API call!!! it's starting to grate on me how often this is necessary) though which will surely break transactional fixtures? It just occured to me that I haven't used transactional fixtures - I got confused why some specs were failing, although a recent post made me suspect my test database was just full of crap, and wrote a method to SQL delete the contents table by table. So I never noticed the fallout from stubbing ActiveRecord::Base.transaction, if there was any. I get the feeling this is something that could be generalised though. I'm just reading the paper Mock Roles, not Objects by four of the ThoughtWorks crew. Apparently jMock supports ordering of methods across mocks. I don't know if this is something that's been considered for RSpec. Thanks Ashley On 2 Mar 2007, at 17:41, Lugovoi Nikolai wrote: > What about such specification? > specify "cow, dog and duck must be saved in the same transaction" do > $log.clear > @connection.stub!(:begin_db_transaction).and_return { > $log.record("BEGIN"); nil } > @connection.stub!(:commit_db_transaction).and_return { > $log.record("COMMIT"); nil } > @cow.stub!(:save!).and_return {$log.record("COW SAVE"); true} > @dog.stub!(:save!).and_return {$log.record("DOG SAVE"); true} > @duck.stub!(:save!).and_return {$log.record("DUCK SAVE"); true} > > @tested_object.exec_method_about_cow_dog_and_duck > > txn_intervals = %w(COW DUCK DOG).collect do |beast| > [ $log.find("BEGIN", :before, "#{beast} SAVE"), > $log.find("COMMIT", :after, "#{beast} SAVE")] > end > > txn_intervals.each do |range| > range[0].should_be kind_of(Time) > range[1].should_be kind_of(Time) > end > txn_intervals.uniq.size.should == 1 > end > > where $log can be something like: > $log = Struct.new(:events, :timestamps).new > def $log.clear > events = [] > timestamps = [] > end > def $log.record(what) > events << what > timestamps << Time.now > end > def $log.find(what, where, start) > # return timestamp of event `what' that is :before or :after > (where) event `start' > end -- Codeweavers Ltd (Registered in England and Wales No. 04092394. VAT registration no. 823826816) Address: Unit 11, Imex Technology Park, ST4 8LJ. Tel: 0870 443 0888 From JohnnyButler7 at gmail.com Wed Mar 7 03:45:46 2007 From: JohnnyButler7 at gmail.com (johnnybutler7) Date: Wed, 7 Mar 2007 00:45:46 -0800 (PST) Subject: [rspec-users] Windows rspec "gem install win32console" In-Reply-To: <683a886f0703061033n292c0e21nd8ef31cf44db8c12@mail.gmail.com> References: <9328370.post@talk.nabble.com> <57c63afe0703060519u553a90fv4876d008be5701af@mail.gmail.com> <9333516.post@talk.nabble.com> <57c63afe0703060701pa7acdbam85cd0d2cf0015acf@mail.gmail.com> <9334771.post@talk.nabble.com> <57c63afe0703060843y36b8b0cet37d3aa33835e909c@mail.gmail.com> <683a886f0703061033n292c0e21nd8ef31cf44db8c12@mail.gmail.com> Message-ID: <9348730.post@talk.nabble.com> ok, ive made a bit of progress now. If i open a command window and do a spec spec/models --colour this works correctly and gives me my coloured output. If i use rake and add the coloured to the spec.opts file i still get the "gem install win32console error" Everything else is working fine now, suppose i can do without the colour for the rake tasks but it would be nice. thanks JB Kevin Williams-2 wrote: > > My rails app seems to be broken today (pgsql 8.2 problem), but I ran > the specs successfully yesterday. Rails 1.2.2, rspec 0.8.2, > win32console 1.0.8. > > I'm kind of a power user though. My Start => All Programs menu fills > my entire screen, and I have all the UnxUtils binaries in my path. :-] > > On 3/6/07, David Chelimsky wrote: >> On 3/6/07, johnnybutler7 wrote: >> > >> > Yes, thats why i cant understand why i am getting this error message. >> I >> > used ./script/generate rspec_model User and that created the >> user_spec.rb >> > file in the spec/models folder. >> >> Unfortunately (or fortunately, depending on your view), I don't have a >> winbox w/ everything set up to troubleshoot this. Is there anyone >> else on the list who can chime in who is successfully using >> Spec::Rails 0.8, Rails 1.2.2 on windows? >> >> > >> > This is the full message with --trace >> > >> > (in C:/Documents and Settings/JohnButler/My Documents/Ruby on >> > Rails/eclipse/workspace/Workspace/sports) >> > ** Invoke spec:models (first_time) >> > ** Invoke db:test:prepare (first_time) >> > ** Invoke environment (first_time) >> > ** Execute environment >> > ** Execute db:test:prepare >> > ** Invoke db:test:clone (first_time) >> > ** Invoke db:schema:dump (first_time) >> > ** Invoke environment >> > ** Execute db:schema:dump >> > ** Invoke db:test:purge (first_time) >> > ** Invoke environment >> > ** Execute db:test:purge >> > ** Execute db:test:clone >> > ** Invoke db:schema:load (first_time) >> > ** Invoke environment >> > ** Execute db:schema:load >> > ** Execute spec:models >> > C:/ruby/bin/ruby -I"C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib" >> > "C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/bin/spec" >> > "spec/models/user_spec.rb" --options "C:/Documents and >> > Settings/JohnButler/My Documents/Ruby on >> > Rails/eclipse/workspace/Workspace/sports/config/../spec/spec.opts" >> > >> C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/command_line.rb:26:in >> > `run': File or directory not found: (RuntimeError) >> > from >> > >> C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/command_line.rb:18:in >> > `each' >> > from >> > >> C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/command_line.rb:18:in >> > `run' >> > from >> > >> C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/option_parser.rb:149:in >> > `parse' >> > from C:/ruby/lib/ruby/1.8/optparse.rb:1218:in `call' >> > from C:/ruby/lib/ruby/1.8/optparse.rb:1218:in `order!' >> > from C:/ruby/lib/ruby/1.8/optparse.rb:1205:in `catch' >> > from C:/ruby/lib/ruby/1.8/optparse.rb:1205:in `order!' >> > from C:/ruby/lib/ruby/1.8/optparse.rb:1279:in `permute!' >> > from C:/ruby/lib/ruby/1.8/optparse.rb:1300:in `parse!' >> > from >> > >> C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/option_parser.rb:185:in >> > `parse' >> > from >> > >> C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/option_parser.rb:18:in >> > `create_context_runner' >> > from >> > >> C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/runner/command_line.rb:14:in >> > `run' >> > from C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/bin/spec:4 >> > rake aborted! >> > Command failed with status (1): [C:/ruby/bin/ruby >> > -I"C:/ruby/lib/ruby/gems/...] >> > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:722:in `sh' >> > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:729:in `call' >> > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:729:in `sh' >> > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:812:in `sh' >> > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:747:in `ruby' >> > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:812:in `ruby' >> > >> C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/rake/spectask.rb:126:in >> > `define' >> > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:831:in `verbose' >> > >> C:/ruby/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/rake/spectask.rb:105:in >> > `define' >> > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in `call' >> > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in `execute' >> > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in `each' >> > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in `execute' >> > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:357:in `invoke' >> > C:/ruby/lib/ruby/1.8/thread.rb:135:in `synchronize' >> > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:350:in `invoke' >> > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:in `run' >> > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:in `each' >> > C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:in `run' >> > C:\ruby\lib\ruby\gems\1.8\gems\rake-0.7.1\bin\rake:7 >> > -e:3:in `load' >> > -e:3 >> > >> > >> > >> > David Chelimsky-2 wrote: >> > > >> > > On 3/6/07, johnnybutler7 wrote: >> > >> >> > >> Hi, >> > >> >> > >> i have got RSpec to work on my machine now. I created a new app >> and >> > >> followed the instructions again. If i navigate to the spec folder >> int he >> > >> rails directory and type spec user_spec.rb then this works fine. If >> i >> > >> try >> > >> the rake command >> > >> >> > >> rake spec:models >> > > >> > > This rake task assumes model specs are in spec/models. Is >> user_spec.rb >> > > at spec/models/user_spec.rb? >> > > >> > >> >> > >> first of all i get the "gem install win32console", so if i remove >> the >> > >> --colour from the options i get the error i posted above. Its >> basically >> > >> saying it cannot find the spec files. Do i need to set the path >> > >> somehwere >> > >> so when i do a rake spec:models it knows where to find them? >> > >> >> > >> John B >> > >> >> > >> >> > >> >> > >> >> > >> David Chelimsky-2 wrote: >> > >> > >> > >> > On 3/6/07, johnnybutler7 wrote: >> > >> >> >> > >> >> Hi, >> > >> >> >> > >> >> Hi I am trying to use RSPEC on windows and i keep getting the >> > >> following >> > >> >> error >> > >> >> >> > >> >> "You must gem install win32console to use colour on Windows" >> > >> >> >> > >> >> I have installed this Gem but i am still getting the same error. >> The >> > >> >> file that error is coming from is: >> > >> >> >> > >> >> C:\ruby\lib\ruby\gems\1.8\gems\rspec-0.8.2\lib\spec\runner\formatter\base_text_formatter.rb >> > >> > >> > >> > That line reads as follows: >> > >> > >> > >> > begin ; require 'Win32/Console/ANSI' if @colour && PLATFORM =~ >> /win32/ >> > >> > ; rescue LoadError ; raise "You must gem install win32console to >> use >> > >> > colour on Windows" ; end >> > >> > >> > >> > So it seems odd that your rspec was complaining even after you >> > >> > installed the plugin. There are people are using rspec on windows >> w/ >> > >> > some success, so I'm not convinced the problem is in rspec alone - >> it >> > >> > seems to be in rspec in conjunction w/ your particular system. >> > >> > >> > >> > Any chance you recently upgraded to Vista? Maybe the environment >> > >> > variables have changed? >> > >> > >> > >> > David >> > >> > >> > >> >> >> > >> >> Do i need to put this line of code in? Where do i put it? >> > >> >> require 'Win32/Console/ANSI' >> > >> >> >> > >> >> Can anyone help me, ive searched the web but cant seem to find a >> > >> >> solution. >> > >> >> >> > >> >> JB >> > >> >> -- >> > >> >> View this message in context: >> > >> >> >> > >> >> http://www.nabble.com/Windows-rspec-%22gem-install-win32console%22-tf3354239.html#a9328370 >> > >> >> Sent from the rspec-users mailing list archive at Nabble.com. >> > >> >> >> > >> >> _______________________________________________ >> > >> >> rspec-users mailing list >> > >> >> rspec-users at rubyforge.org >> > >> >> http://rubyforge.org/mailman/listinfo/rspec-users >> > >> >> >> > >> > _______________________________________________ >> > >> > rspec-users mailing list >> > >> > rspec-users at rubyforge.org >> > >> > http://rubyforge.org/mailman/listinfo/rspec-users >> > >> > >> > >> > >> > >> >> > >> -- >> > >> View this message in context: >> > >> >> http://www.nabble.com/Windows-rspec-%22gem-install-win32console%22-tf3354239.html#a9333516 >> > >> Sent from the rspec-users mailing list archive at Nabble.com. >> > >> >> > >> _______________________________________________ >> > >> rspec-users mailing list >> > >> rspec-users at rubyforge.org >> > >> http://rubyforge.org/mailman/listinfo/rspec-users >> > >> >> > > _______________________________________________ >> > > rspec-users mailing list >> > > rspec-users at rubyforge.org >> > > http://rubyforge.org/mailman/listinfo/rspec-users >> > > >> > > >> > >> > -- >> > View this message in context: >> http://www.nabble.com/Windows-rspec-%22gem-install-win32console%22-tf3354239.html#a9334771 >> > Sent from the rspec-users mailing list archive at Nabble.com. >> > >> > _______________________________________________ >> > rspec-users mailing list >> > rspec-users at rubyforge.org >> > http://rubyforge.org/mailman/listinfo/rspec-users >> > >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > -- > 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 > > -- View this message in context: http://www.nabble.com/Windows-rspec-%22gem-install-win32console%22-tf3354239.html#a9348730 Sent from the rspec-users mailing list archive at Nabble.com. From work at ashleymoran.me.uk Wed Mar 7 04:14:50 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Wed, 7 Mar 2007 09:14:50 +0000 Subject: [rspec-users] Simulate an enumerable with a mock Message-ID: <0B0958B3-1CA2-49F6-9A25-A99DAEAA4F38@ashleymoran.me.uk> I need to simulate an enumerable class (well, it has one method: each). The code looks something like this OTTOMH: class Processor def initialize(input, output) @input = input; @output = output end def run @input.each do |row| @output << ProcessorEngine.new(row).process end end end This is the best I could come up with: @input = mock("input") class << @input def each [ [:a], [:b] ].each do |value| yield value end end end But that seems like adding behaviour to mocks which is generally recommended against. There is no way to specify that the each method is called. I can't decide if this would be desirable or not. What I did instead was (with the help of a bit more setup) ProcessorEngine.should_receive(:new).with([:a]).and_return #blah ProcessorEngine.should_receive(:new).with([:b]).and_return #blah However, the input class is something we made ourselves, and the each method *is* the interface we defined on it, so I have this nagging feeling I should test that it is called. Any thoughts? Ta Ashley From aslak.hellesoy at gmail.com Wed Mar 7 11:45:23 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Wed, 7 Mar 2007 17:45:23 +0100 Subject: [rspec-users] Specifying that code is called in a block In-Reply-To: <8730CD7F-7CB7-4CDB-9CF9-AB007AD3A7BD@ashleymoran.me.uk> References: <86924770703020941v6b1ce9c2j185e42d633b3718b@mail.gmail.com> <8730CD7F-7CB7-4CDB-9CF9-AB007AD3A7BD@ashleymoran.me.uk> Message-ID: <8d961d900703070845i11c6417bj7c3cd92dd2e83db3@mail.gmail.com> How is JMock supporting ordering of calls across mocks? I have been using JMock for years and have never seen that feature. On 3/7/07, Ashley Moran wrote: > Hey Lugovoi > > Not tried that yet but I like the look of it. You'd have to stub out > ActiveRecord::Base.transaction to make it work (meddling with another > API call!!! it's starting to grate on me how often this is necessary) > though which will surely break transactional fixtures? It just > occured to me that I haven't used transactional fixtures - I got > confused why some specs were failing, although a recent post made me > suspect my test database was just full of crap, and wrote a method to > SQL delete the contents table by table. So I never noticed the > fallout from stubbing ActiveRecord::Base.transaction, if there was any. > > I get the feeling this is something that could be generalised > though. I'm just reading the paper Mock Roles, not Objects by four > of the ThoughtWorks crew. Apparently jMock supports ordering of > methods across mocks. I don't know if this is something that's been > considered for RSpec. > > Thanks > Ashley > > > > On 2 Mar 2007, at 17:41, Lugovoi Nikolai wrote: > > > What about such specification? > > specify "cow, dog and duck must be saved in the same transaction" do > > $log.clear > > @connection.stub!(:begin_db_transaction).and_return { > > $log.record("BEGIN"); nil } > > @connection.stub!(:commit_db_transaction).and_return { > > $log.record("COMMIT"); nil } > > @cow.stub!(:save!).and_return {$log.record("COW SAVE"); true} > > @dog.stub!(:save!).and_return {$log.record("DOG SAVE"); true} > > @duck.stub!(:save!).and_return {$log.record("DUCK SAVE"); true} > > > > @tested_object.exec_method_about_cow_dog_and_duck > > > > txn_intervals = %w(COW DUCK DOG).collect do |beast| > > [ $log.find("BEGIN", :before, "#{beast} SAVE"), > > $log.find("COMMIT", :after, "#{beast} SAVE")] > > end > > > > txn_intervals.each do |range| > > range[0].should_be kind_of(Time) > > range[1].should_be kind_of(Time) > > end > > txn_intervals.uniq.size.should == 1 > > end > > > > where $log can be something like: > > $log = Struct.new(:events, :timestamps).new > > def $log.clear > > events = [] > > timestamps = [] > > end > > def $log.record(what) > > events << what > > timestamps << Time.now > > end > > def $log.find(what, where, start) > > # return timestamp of event `what' that is :before or :after > > (where) event `start' > > end > > > > -- > > Codeweavers Ltd (Registered in England and Wales No. 04092394. VAT > registration no. 823826816) > Address: Unit 11, Imex Technology Park, ST4 8LJ. Tel: 0870 443 0888 > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From JohnnyButler7 at gmail.com Wed Mar 7 12:48:33 2007 From: JohnnyButler7 at gmail.com (johnnybutler7) Date: Wed, 7 Mar 2007 09:48:33 -0800 (PST) Subject: [rspec-users] RC1, Rails, and problems with multiple options in spec.opts In-Reply-To: <445101B3-41F9-476B-B613-9BF94A7B0A93@railsnewbie.com> References: <445101B3-41F9-476B-B613-9BF94A7B0A93@railsnewbie.com> Message-ID: <9358217.post@talk.nabble.com> I too have this problem. What is the format for adding options to spec.opts file, i cant seem to find anything on the web. Are spaces include so for instance are any of the below valid?: --drb --colour --drb--colour --drb colour --drb -colour JB Scott Taylor-6 wrote: > > I am having inconsistent output with multiple options in the > spec.opts file. I can, for instance, pass --color or --colour, or, > separately, use --drb. But when combining them I get: > > /opt/local/lib/ruby/1.8/optparse.rb:1381:in `complete': invalid > option: --options --color --drb (OptionParser::InvalidOption) > from /opt/local/lib/ruby/1.8/optparse.rb:1379:in `catch' > from /opt/local/lib/ruby/1.8/optparse.rb:1379:in `complete' > from /opt/local/lib/ruby/1.8/optparse.rb:1212:in `order!' > from /opt/local/lib/ruby/1.8/optparse.rb:1205:in `catch' > from /opt/local/lib/ruby/1.8/optparse.rb:1205:in `order!' > from /opt/local/lib/ruby/1.8/optparse.rb:1279:in `permute!' > from /opt/local/lib/ruby/1.8/optparse.rb:1300:in `parse!' > from /Users/smtlaissezfaire/Sites/rails/dictionary/vendor/ > plugins/rspec/lib/spec/runner/option_parser.rb:180:in `parse' > ... 9 levels... > from /Users/smtlaissezfaire/Sites/rails/dictionary/vendor/ > plugins/rspec/lib/spec/runner/option_parser.rb:180:in `parse' > from /Users/smtlaissezfaire/Sites/rails/dictionary/vendor/ > plugins/rspec/lib/spec/runner/option_parser.rb:13:in > `create_context_runner' > from /Users/smtlaissezfaire/Sites/rails/dictionary/vendor/ > plugins/rspec/lib/spec/runner/command_line.rb:12:in `run' > from /Users/smtlaissezfaire/Sites/rails/dictionary/vendor/ > plugins/rspec/bin/spec:4 > rake aborted! > > Is anyone else having this problem? > > I'm on Mac OS X.4.8, using edge rails, ruby 1.8.5, and RC1 > > Best, > > Scott Taylor > _______________________________________________ > 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/RC1%2C-Rails%2C-and-problems-with-multiple-options-in-spec.opts-tf3330529.html#a9358217 Sent from the rspec-users mailing list archive at Nabble.com. From dchelimsky at gmail.com Wed Mar 7 13:37:52 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 7 Mar 2007 12:37:52 -0600 Subject: [rspec-users] RC1, Rails, and problems with multiple options in spec.opts In-Reply-To: <9358217.post@talk.nabble.com> References: <445101B3-41F9-476B-B613-9BF94A7B0A93@railsnewbie.com> <9358217.post@talk.nabble.com> Message-ID: <57c63afe0703071037s1b5ca018m185d4778b888e384@mail.gmail.com> On 3/7/07, johnnybutler7 wrote: > > I too have this problem. What is the format for adding options to spec.opts > file, i cant seem to find anything on the web. Are spaces include so for > instance are any of the below valid?: > > --drb --colour > --drb--colour > --drb colour > --drb -colour Try putting each option on a separate line. That works for me, though --colour won't be reflected in the --drb output. You should be able to, however, use something like this: --drb --format specdoc ... for example. > > > JB > > Scott Taylor-6 wrote: > > > > I am having inconsistent output with multiple options in the > > spec.opts file. I can, for instance, pass --color or --colour, or, > > separately, use --drb. But when combining them I get: > > > > /opt/local/lib/ruby/1.8/optparse.rb:1381:in `complete': invalid > > option: --options --color --drb (OptionParser::InvalidOption) > > from /opt/local/lib/ruby/1.8/optparse.rb:1379:in `catch' > > from /opt/local/lib/ruby/1.8/optparse.rb:1379:in `complete' > > from /opt/local/lib/ruby/1.8/optparse.rb:1212:in `order!' > > from /opt/local/lib/ruby/1.8/optparse.rb:1205:in `catch' > > from /opt/local/lib/ruby/1.8/optparse.rb:1205:in `order!' > > from /opt/local/lib/ruby/1.8/optparse.rb:1279:in `permute!' > > from /opt/local/lib/ruby/1.8/optparse.rb:1300:in `parse!' > > from /Users/smtlaissezfaire/Sites/rails/dictionary/vendor/ > > plugins/rspec/lib/spec/runner/option_parser.rb:180:in `parse' > > ... 9 levels... > > from /Users/smtlaissezfaire/Sites/rails/dictionary/vendor/ > > plugins/rspec/lib/spec/runner/option_parser.rb:180:in `parse' > > from /Users/smtlaissezfaire/Sites/rails/dictionary/vendor/ > > plugins/rspec/lib/spec/runner/option_parser.rb:13:in > > `create_context_runner' > > from /Users/smtlaissezfaire/Sites/rails/dictionary/vendor/ > > plugins/rspec/lib/spec/runner/command_line.rb:12:in `run' > > from /Users/smtlaissezfaire/Sites/rails/dictionary/vendor/ > > plugins/rspec/bin/spec:4 > > rake aborted! > > > > Is anyone else having this problem? > > > > I'm on Mac OS X.4.8, using edge rails, ruby 1.8.5, and RC1 > > > > Best, > > > > Scott Taylor > > _______________________________________________ > > 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/RC1%2C-Rails%2C-and-problems-with-multiple-options-in-spec.opts-tf3330529.html#a9358217 > 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 coda.hale at gmail.com Wed Mar 7 13:47:33 2007 From: coda.hale at gmail.com (Coda Hale) Date: Wed, 7 Mar 2007 10:47:33 -0800 Subject: [rspec-users] RC1, Rails, and problems with multiple options in spec.opts In-Reply-To: <9358217.post@talk.nabble.com> References: <445101B3-41F9-476B-B613-9BF94A7B0A93@railsnewbie.com> <9358217.post@talk.nabble.com> Message-ID: You need to have a single option per line. E.g.: --drb --color --diff On 3/7/07, johnnybutler7 wrote: > > I too have this problem. What is the format for adding options to spec.opts > file, i cant seem to find anything on the web. Are spaces include so for > instance are any of the below valid?: > > --drb --colour > --drb--colour > --drb colour > --drb -colour > > > JB > > Scott Taylor-6 wrote: > > > > I am having inconsistent output with multiple options in the > > spec.opts file. I can, for instance, pass --color or --colour, or, > > separately, use --drb. But when combining them I get: > > > > /opt/local/lib/ruby/1.8/optparse.rb:1381:in `complete': invalid > > option: --options --color --drb (OptionParser::InvalidOption) > > from /opt/local/lib/ruby/1.8/optparse.rb:1379:in `catch' > > from /opt/local/lib/ruby/1.8/optparse.rb:1379:in `complete' > > from /opt/local/lib/ruby/1.8/optparse.rb:1212:in `order!' > > from /opt/local/lib/ruby/1.8/optparse.rb:1205:in `catch' > > from /opt/local/lib/ruby/1.8/optparse.rb:1205:in `order!' > > from /opt/local/lib/ruby/1.8/optparse.rb:1279:in `permute!' > > from /opt/local/lib/ruby/1.8/optparse.rb:1300:in `parse!' > > from /Users/smtlaissezfaire/Sites/rails/dictionary/vendor/ > > plugins/rspec/lib/spec/runner/option_parser.rb:180:in `parse' > > ... 9 levels... > > from /Users/smtlaissezfaire/Sites/rails/dictionary/vendor/ > > plugins/rspec/lib/spec/runner/option_parser.rb:180:in `parse' > > from /Users/smtlaissezfaire/Sites/rails/dictionary/vendor/ > > plugins/rspec/lib/spec/runner/option_parser.rb:13:in > > `create_context_runner' > > from /Users/smtlaissezfaire/Sites/rails/dictionary/vendor/ > > plugins/rspec/lib/spec/runner/command_line.rb:12:in `run' > > from /Users/smtlaissezfaire/Sites/rails/dictionary/vendor/ > > plugins/rspec/bin/spec:4 > > rake aborted! > > > > Is anyone else having this problem? > > > > I'm on Mac OS X.4.8, using edge rails, ruby 1.8.5, and RC1 > > > > Best, > > > > Scott Taylor > > _______________________________________________ > > 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/RC1%2C-Rails%2C-and-problems-with-multiple-options-in-spec.opts-tf3330529.html#a9358217 > 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 > -- Coda Hale http://blog.codahale.com From aslak.hellesoy at gmail.com Wed Mar 7 18:00:11 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Thu, 8 Mar 2007 00:00:11 +0100 Subject: [rspec-users] RC1, Rails, and problems with multiple options in spec.opts In-Reply-To: <57c63afe0703071037s1b5ca018m185d4778b888e384@mail.gmail.com> References: <445101B3-41F9-476B-B613-9BF94A7B0A93@railsnewbie.com> <9358217.post@talk.nabble.com> <57c63afe0703071037s1b5ca018m185d4778b888e384@mail.gmail.com> Message-ID: <8d961d900703071500q1fbcc383he3e7a27a5f17f0b5@mail.gmail.com> No, everything must be on a separate line. On 3/7/07, David Chelimsky wrote: > On 3/7/07, johnnybutler7 wrote: > > > > I too have this problem. What is the format for adding options to > spec.opts > > file, i cant seem to find anything on the web. Are spaces include so for > > instance are any of the below valid?: > > > > --drb --colour > > --drb--colour > > --drb colour > > --drb -colour > > Try putting each option on a separate line. That works for me, though > --colour won't be reflected in the --drb output. You should be able > to, however, use something like this: > > --drb > --format specdoc > > ... for example. > > > > > > > JB > > > > Scott Taylor-6 wrote: > > > > > > I am having inconsistent output with multiple options in the > > > spec.opts file. I can, for instance, pass --color or --colour, or, > > > separately, use --drb. But when combining them I get: > > > > > > /opt/local/lib/ruby/1.8/optparse.rb:1381:in `complete': invalid > > > option: --options --color --drb (OptionParser::InvalidOption) > > > from /opt/local/lib/ruby/1.8/optparse.rb:1379:in `catch' > > > from /opt/local/lib/ruby/1.8/optparse.rb:1379:in `complete' > > > from /opt/local/lib/ruby/1.8/optparse.rb:1212:in `order!' > > > from /opt/local/lib/ruby/1.8/optparse.rb:1205:in `catch' > > > from /opt/local/lib/ruby/1.8/optparse.rb:1205:in `order!' > > > from /opt/local/lib/ruby/1.8/optparse.rb:1279:in `permute!' > > > from /opt/local/lib/ruby/1.8/optparse.rb:1300:in `parse!' > > > from /Users/smtlaissezfaire/Sites/rails/dictionary/vendor/ > > > plugins/rspec/lib/spec/runner/option_parser.rb:180:in `parse' > > > ... 9 levels... > > > from /Users/smtlaissezfaire/Sites/rails/dictionary/vendor/ > > > plugins/rspec/lib/spec/runner/option_parser.rb:180:in `parse' > > > from /Users/smtlaissezfaire/Sites/rails/dictionary/vendor/ > > > plugins/rspec/lib/spec/runner/option_parser.rb:13:in > > > `create_context_runner' > > > from /Users/smtlaissezfaire/Sites/rails/dictionary/vendor/ > > > plugins/rspec/lib/spec/runner/command_line.rb:12:in `run' > > > from /Users/smtlaissezfaire/Sites/rails/dictionary/vendor/ > > > plugins/rspec/bin/spec:4 > > > rake aborted! > > > > > > Is anyone else having this problem? > > > > > > I'm on Mac OS X.4.8, using edge rails, ruby 1.8.5, and RC1 > > > > > > Best, > > > > > > Scott Taylor > > > _______________________________________________ > > > 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/RC1%2C-Rails%2C-and-problems-with-multiple-options-in-spec.opts-tf3330529.html#a9358217 > > Sent from the rspec-users mailing list archive at Nabble.com. > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From work at ashleymoran.me.uk Thu Mar 8 06:17:06 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Thu, 8 Mar 2007 11:17:06 +0000 Subject: [rspec-users] Specifying that code is called in a block In-Reply-To: <8d961d900703070845i11c6417bj7c3cd92dd2e83db3@mail.gmail.com> References: <86924770703020941v6b1ce9c2j185e42d633b3718b@mail.gmail.com> <8730CD7F-7CB7-4CDB-9CF9-AB007AD3A7BD@ashleymoran.me.uk> <8d961d900703070845i11c6417bj7c3cd92dd2e83db3@mail.gmail.com> Message-ID: <92F6FB45-0AEA-4ABE-B4A6-702E44C164C4@ashleymoran.me.uk> On 7 Mar 2007, at 16:45, aslak hellesoy wrote: > How is JMock supporting ordering of calls across mocks? I have been > using JMock for years and have never seen that feature. From , section 3.4 public void testReturnsCachedObjectWithinTimeout() { mockLoader.expect(once()) .method("load").with( eq(KEY) ) .will( returnValue(VALUE) ); mockClock.expect(atLeastOnce()) .after(mockLoader, "load") .method("getCurrentTime").withNoArguments() .will( returnValues(loadTime, fetchTime) ); mockReloadPolicy.expect(atLeastOnce()) .method("shouldReload") .with( eq(loadTime), eq(fetchTime) ) .will( returnValue(false) ); assertSame( "should be loaded object", VALUE, cache.lookup(KEY) ); assertSame( "should be cached object", VALUE, cache.lookup(KEY) ); } From jed.hurt at gmail.com Thu Mar 8 23:28:53 2007 From: jed.hurt at gmail.com (Jed Hurt) Date: Thu, 8 Mar 2007 21:28:53 -0700 Subject: [rspec-users] Specifying RESTful Routes Message-ID: What would be the proper way to specify this route? ActionController::Routing::Routes.draw do |map| map.resource :recipes end Would the specification go into recipes_controller_spec? Also, what methods are available for testing RESTful routes (i.e. GET, POST, PUT, DELETE)? From dchelimsky at gmail.com Fri Mar 9 00:07:37 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 8 Mar 2007 23:07:37 -0600 Subject: [rspec-users] Specifying RESTful Routes In-Reply-To: References: Message-ID: <57c63afe0703082107q45649ce7k5c7706c96c4efb8@mail.gmail.com> On 3/8/07, Jed Hurt wrote: > What would be the proper way to specify this route? > > ActionController::Routing::Routes.draw do |map| > map.resource :recipes > end Take a look at the specs that get generated by this: script/generate rspec_resource Recipes David > > > Would the specification go into recipes_controller_spec? Also, what > methods are available for testing RESTful routes (i.e. GET, POST, PUT, > DELETE)? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From tils-rspec at tils.net Fri Mar 9 10:03:50 2007 From: tils-rspec at tils.net (Tilmann Singer) Date: Fri, 9 Mar 2007 16:03:50 +0100 Subject: [rspec-users] AssertSelect for strings? Message-ID: <20070309150350.GA30865@tils.net> Hi, Is there a way to use the have_tag matcher on a string instead of the response body from a view? I have a helper in a method rails project that returns an html fragment which I would like to test. Like this: module SomeHelper def some_helper_method "

foo

" end end context "The SomeHelper" helper_name :some specify do some_helper_method.should have_tag("p", "foo") end end Til ps: the new have_tag / with_tag stuff for testing views and rspec 0.8.2 in general rocks, thanks to all involved! From dchelimsky at gmail.com Fri Mar 9 11:10:39 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 9 Mar 2007 10:10:39 -0600 Subject: [rspec-users] AssertSelect for strings? In-Reply-To: <20070309150350.GA30865@tils.net> References: <20070309150350.GA30865@tils.net> Message-ID: <57c63afe0703090810l34689462lc4257d66ea4b31a2@mail.gmail.com> That's a great idea, but AFAIK it is not supported by assert_select directly. Take a look at vendor/plugins/rspec_on_rails/spec/rails/matchers/assert_select_spec.rb. This is a copy of the assert_select_test from the assert_select_plugin, modified to fit into rspec. It sets up a controller that you can use to render whatever text you like, and set up specs like this: render_html %Q{

foo

} response.should have_tag('p','foo') There's no reason you shouldn't be able to do this: render_html(some_helper_method) response.should have_tag('p','foo') It's a bit sneaky, and perhaps too much work when you could just do: some_helper_method.should == "

foo

" Check it out and let me know if you have any questions. Cheers, David On 3/9/07, Tilmann Singer wrote: > Hi, > > Is there a way to use the have_tag matcher on a string instead of the > response body from a view? I have a helper in a method rails project > that returns an html fragment which I would like to test. > > Like this: > > module SomeHelper > def some_helper_method > "

foo

" > end > end > > context "The SomeHelper" > helper_name :some > specify do > some_helper_method.should have_tag("p", "foo") > end > end > > > > Til > > > ps: the new have_tag / with_tag stuff for testing views and rspec > 0.8.2 in general rocks, thanks to all involved! > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Fri Mar 9 11:11:31 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 9 Mar 2007 10:11:31 -0600 Subject: [rspec-users] AssertSelect for strings? In-Reply-To: <20070309150350.GA30865@tils.net> References: <20070309150350.GA30865@tils.net> Message-ID: <57c63afe0703090811jffbf090nd8324bc25fc9bce6@mail.gmail.com> On 3/9/07, Tilmann Singer wrote: > ps: the new have_tag / with_tag stuff for testing views and rspec > 0.8.2 in general rocks, thanks to all involved! You're welcome. Thanks for saying so. Cheers, David From tils-rspec at tils.net Fri Mar 9 13:40:19 2007 From: tils-rspec at tils.net (Tilmann Singer) Date: Fri, 9 Mar 2007 19:40:19 +0100 Subject: [rspec-users] AssertSelect for strings? In-Reply-To: <57c63afe0703090810l34689462lc4257d66ea4b31a2@mail.gmail.com> References: <20070309150350.GA30865@tils.net> <57c63afe0703090810l34689462lc4257d66ea4b31a2@mail.gmail.com> Message-ID: <20070309184019.GB30865@tils.net> * David Chelimsky [20070309 17:13]: > That's a great idea, but AFAIK it is not supported by assert_select directly. > > Take a look at vendor/plugins/rspec_on_rails/spec/rails/matchers/assert_select_spec.rb. > This is a copy of the assert_select_test from the > assert_select_plugin, modified to fit into rspec. > > It sets up a controller that you can use to render whatever text you > like, and set up specs like this: This sets up a context for spec'ing controllers with :context_type => :controller. As far as I understand it I cannot use that when I want to test it from within a helper context, and I don't know how to set up a controller inside a helper context (and if it would be feasible). I think you can pass a HTML::Node to assert_select somehow, so maybe there is a way, but so far I didn't find it. > It's a bit sneaky, and perhaps too much work when you could just do: > > some_helper_method.should == "

foo

" True. The actual reason why I want to do it is because the helper returns a string that can contain a link which I want to test independently. Here is a less contrived example: module SomeHelper def some_helper_method "

This sentence contains a link.

" end end context "The SomeHelper" helper_name :some specify "should return a sentence" do some_helper_method.should have_tag("p", "This sentence contains a link.") end specify "should include a link" do some_helper_method.should have_tag("a", "link") end end It's not too bad to workaround with regexps somehow like this: context "The SomeHelper" helper_name :some specify "should return a sentence" do some_helper_method.should match(/This sentence contains a.*link.*\./) end specify "should include a link" do some_helper_method.should match(%r{link}) end end but using the assert_select syntax would be much more elegant. Til From dchelimsky at gmail.com Fri Mar 9 15:42:24 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 9 Mar 2007 14:42:24 -0600 Subject: [rspec-users] AssertSelect for strings? In-Reply-To: <20070309184019.GB30865@tils.net> References: <20070309150350.GA30865@tils.net> <57c63afe0703090810l34689462lc4257d66ea4b31a2@mail.gmail.com> <20070309184019.GB30865@tils.net> Message-ID: <57c63afe0703091242q1d4b35d9sbc8e0494bdbd2cc9@mail.gmail.com> On 3/9/07, Tilmann Singer wrote: > * David Chelimsky [20070309 17:13]: > > That's a great idea, but AFAIK it is not supported by assert_select directly. > > > > Take a look at vendor/plugins/rspec_on_rails/spec/rails/matchers/assert_select_spec.rb. > > This is a copy of the assert_select_test from the > > assert_select_plugin, modified to fit into rspec. > > > > It sets up a controller that you can use to render whatever text you > > like, and set up specs like this: > > This sets up a context for spec'ing controllers with :context_type => > :controller. As far as I understand it I cannot use that when I want > to test it from within a helper context, and I don't know how to set > up a controller inside a helper context (and if it would be feasible). > > I think you can pass a HTML::Node to assert_select somehow, so maybe > there is a way, but so far I didn't find it. > > > It's a bit sneaky, and perhaps too much work when you could just do: > > > > some_helper_method.should == "

foo

" > > True. > > The actual reason why I want to do it is because the helper returns a > string that can contain a link which I want to test > independently. Here is a less contrived example: > > module SomeHelper > def some_helper_method > "

This sentence contains a link.

" > end > end > > context "The SomeHelper" > helper_name :some > specify "should return a sentence" do > some_helper_method.should have_tag("p", "This sentence contains a link.") > end > > specify "should include a link" do > some_helper_method.should have_tag("a", "link") > end > end > > > It's not too bad to workaround with regexps somehow like this: > > context "The SomeHelper" > helper_name :some > specify "should return a sentence" do > some_helper_method.should match(/This sentence contains a.*link.*\./) > end > > specify "should include a link" do > some_helper_method.should match(%r{link}) > end > end > > > but using the assert_select syntax would be much more elegant. Agreed. I'd recommend you post a request to both rspec for have_tag and to rails for assert_select. > > > Til > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From cwdinfo at gmail.com Fri Mar 9 16:40:00 2007 From: cwdinfo at gmail.com (s.ross) Date: Fri, 9 Mar 2007 13:40:00 -0800 Subject: [rspec-users] Mocks & Stubs in spec_helper? Message-ID: <2DC48A38-6CCE-455C-BCAD-DFD6A8866FC9@gmail.com> I have to stub out setup do request.stub!(:user_agent).and_return('Mozilla') end in each context because my Rails application.rb relies on it (for IE reasons). Is there a way to create mocks or stubs in spec_helper.rb so I don't have to repeat this? Thanks, Steve From dchelimsky at gmail.com Sat Mar 10 08:56:37 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 10 Mar 2007 07:56:37 -0600 Subject: [rspec-users] AssertSelect for strings? In-Reply-To: <57c63afe0703091242q1d4b35d9sbc8e0494bdbd2cc9@mail.gmail.com> References: <20070309150350.GA30865@tils.net> <57c63afe0703090810l34689462lc4257d66ea4b31a2@mail.gmail.com> <20070309184019.GB30865@tils.net> <57c63afe0703091242q1d4b35d9sbc8e0494bdbd2cc9@mail.gmail.com> Message-ID: <57c63afe0703100556l68ef34eey3e26b2bc70f6ad2e@mail.gmail.com> On 3/9/07, David Chelimsky wrote: > On 3/9/07, Tilmann Singer wrote: > > * David Chelimsky [20070309 17:13]: > > > That's a great idea, but AFAIK it is not supported by assert_select directly. > > > > > > Take a look at vendor/plugins/rspec_on_rails/spec/rails/matchers/assert_select_spec.rb. > > > This is a copy of the assert_select_test from the > > > assert_select_plugin, modified to fit into rspec. > > > > > > It sets up a controller that you can use to render whatever text you > > > like, and set up specs like this: > > > > This sets up a context for spec'ing controllers with :context_type => > > :controller. As far as I understand it I cannot use that when I want > > to test it from within a helper context, and I don't know how to set > > up a controller inside a helper context (and if it would be feasible). > > > > I think you can pass a HTML::Node to assert_select somehow, so maybe > > there is a way, but so far I didn't find it. > > > > > It's a bit sneaky, and perhaps too much work when you could just do: > > > > > > some_helper_method.should == "

foo

" > > > > True. > > > > The actual reason why I want to do it is because the helper returns a > > string that can contain a link which I want to test > > independently. Here is a less contrived example: > > > > module SomeHelper > > def some_helper_method > > "

This sentence contains a link.

" > > end > > end > > > > context "The SomeHelper" > > helper_name :some > > specify "should return a sentence" do > > some_helper_method.should have_tag("p", "This sentence contains a link.") > > end > > > > specify "should include a link" do > > some_helper_method.should have_tag("a", "link") > > end > > end > > > > > > It's not too bad to workaround with regexps somehow like this: > > > > context "The SomeHelper" > > helper_name :some > > specify "should return a sentence" do > > some_helper_method.should match(/This sentence contains a.*link.*\./) > > end > > > > specify "should include a link" do > > some_helper_method.should match(%r{link}) > > end > > end > > > > > > but using the assert_select syntax would be much more elegant. > > Agreed. I'd recommend you post a request to both rspec for have_tag > and to rails for assert_select. Well, curiosity got the better of me on this one. I went ahead and put in the feature request and implemented it: http://rubyforge.org/tracker/?func=detail&atid=3152&aid=9167&group_id=797 So it now works within rspec (trunk) as you requested. As it turns out, if you want to do it using assert_select, you can do this: node = HTML::Document.new(some_helper_method).root assert_select(root, "p", "foo") But it's not quite as pretty as: some_helper_method.should have_tag("p","foo") Cheers, David > > > > > > > > Til > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > From keith at dancingtext.com Mon Mar 12 09:35:31 2007 From: keith at dancingtext.com (Keith McDonnell) Date: Mon, 12 Mar 2007 13:35:31 +0000 Subject: [rspec-users] rspec on rails instantiated fixtures OFF by default ? Message-ID: <45F55723.4070103@dancingtext.com> Hi there, Why are the instantiated fixtures turned off by default in the rspec on rails plugin? This was not the case in older versions. After upgrading (and much head scratching) I had to turn on the instantiated_fixtures in spec_helper thusly ... self.use_instantiated_fixtures = true Regards, Keith From tils-rspec at tils.net Mon Mar 12 12:21:32 2007 From: tils-rspec at tils.net (Tilmann Singer) Date: Mon, 12 Mar 2007 17:21:32 +0100 Subject: [rspec-users] AssertSelect for strings? In-Reply-To: <57c63afe0703100556l68ef34eey3e26b2bc70f6ad2e@mail.gmail.com> References: <20070309150350.GA30865@tils.net> <57c63afe0703090810l34689462lc4257d66ea4b31a2@mail.gmail.com> <20070309184019.GB30865@tils.net> <57c63afe0703091242q1d4b35d9sbc8e0494bdbd2cc9@mail.gmail.com> <57c63afe0703100556l68ef34eey3e26b2bc70f6ad2e@mail.gmail.com> Message-ID: <20070312162132.GW30865@tils.net> * David Chelimsky [20070310 15:30]: > > Agreed. I'd recommend you post a request to both rspec for have_tag > > and to rails for assert_select. > > Well, curiosity got the better of me on this one. I went ahead and put > in the feature request and implemented it: > > http://rubyforge.org/tracker/?func=detail&atid=3152&aid=9167&group_id=797 That's awesome, thanks a lot, and sorry for not replying earlier! Will switch our project now to run rspec and rspec_on_rails off trunk (which works great with piston btw.). Til From jodi at nnovation.ca Mon Mar 12 14:50:43 2007 From: jodi at nnovation.ca (Jodi Showers) Date: Mon, 12 Mar 2007 14:50:43 -0400 Subject: [rspec-users] utc Message-ID: <5A0CC665-719E-40E5-8C52-D7BF8F6F1F00@nNovation.ca> I'm having a helluva time getting Date.today.utc to resolve - "undefined method `utc' for #" model usage in before_create filter is : activated_at = Date.today.utc I'm not stubbing out Date (should I be? [ stub(Date, :utc => Date.today) didn't help any ]. The before filter is working fine within the app, but rspec isn't happy. Should I include something particular? Thanx for any help. Jodi -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070312/db154032/attachment.html From aslak.hellesoy at gmail.com Mon Mar 12 15:52:50 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Mon, 12 Mar 2007 20:52:50 +0100 Subject: [rspec-users] utc In-Reply-To: <5A0CC665-719E-40E5-8C52-D7BF8F6F1F00@nNovation.ca> References: <5A0CC665-719E-40E5-8C52-D7BF8F6F1F00@nNovation.ca> Message-ID: <8d961d900703121252n20b3a97crb25be5b860aa9f4d@mail.gmail.com> On 3/12/07, Jodi Showers wrote: > I'm having a helluva time getting Date.today.utc to resolve - > > "undefined method `utc' for #" > > model usage in before_create filter is : > > activated_at = Date.today.utc > I'm not sure why you think this is RSpec related. Check the RDocs for Date - it has no utc method (but Time does). Aslak > I'm not stubbing out Date (should I be? [ stub(Date, :utc => Date.today) > didn't help any ]. > > The before filter is working fine within the app, but rspec isn't happy. > Should I include something particular? > > Thanx for any help. > > > > Jodi > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jodi at nnovation.ca Mon Mar 12 16:15:30 2007 From: jodi at nnovation.ca (Jodi Showers) Date: Mon, 12 Mar 2007 16:15:30 -0400 Subject: [rspec-users] utc In-Reply-To: <8d961d900703121252n20b3a97crb25be5b860aa9f4d@mail.gmail.com> References: <5A0CC665-719E-40E5-8C52-D7BF8F6F1F00@nNovation.ca> <8d961d900703121252n20b3a97crb25be5b860aa9f4d@mail.gmail.com> Message-ID: On 12-Mar-07, at 3:52 PM, aslak hellesoy wrote: > On 3/12/07, Jodi Showers wrote: >> I'm having a helluva time getting Date.today.utc to resolve - >> >> "undefined method `utc' for #" >> >> model usage in before_create filter is : >> >> activated_at = Date.today.utc >> > > I'm not sure why you think this is RSpec related. > > Check the RDocs for Date - it has no utc method (but Time does). > > Aslak mea culpa I thought my before_filter was succeeding, and rspec wasn't seeing a lib - or Date was being mocked by rspec. turns out the simple answer was the before_filter wasn't working. 8-> thanx Aslak. Jodi From ashley.moran at codeweavers.net Tue Mar 6 09:13:57 2007 From: ashley.moran at codeweavers.net (Ashley Moran) Date: Tue, 6 Mar 2007 14:13:57 +0000 Subject: [rspec-users] Specifying that code is called in a block In-Reply-To: <86924770703020941v6b1ce9c2j185e42d633b3718b@mail.gmail.com> References: <86924770703020941v6b1ce9c2j185e42d633b3718b@mail.gmail.com> Message-ID: <67C23F90-A0A5-4856-B889-518977016CF2@codeweavers.net> Hey Lugovoi Not tried that yet but I like the look of it. You'd have to stub out ActiveRecord::Base.transaction to make it work (meddling with another API call!!! it's starting to grate on me how often this is necessary) though which will surely break transactional fixtures? It just occured to me that I haven't used transactional fixtures - I got confused why some specs were failing, although a recent post made me suspect my test database was just full of crap, and wrote a method to SQL delete the contents table by table. So I never noticed the fallout from stubbing ActiveRecord::Base.transaction, if there was any. I get the feeling this is something that could be generalised though. I'm just reading the paper Mock Roles, not Objects by four of the ThoughtWorks crew. Apparently jMock supports ordering of methods across mocks. I don't know if this is something that's been considered for RSpec. Thanks Ashley On 2 Mar 2007, at 17:41, Lugovoi Nikolai wrote: > What about such specification? > specify "cow, dog and duck must be saved in the same transaction" do > $log.clear > @connection.stub!(:begin_db_transaction).and_return { > $log.record("BEGIN"); nil } > @connection.stub!(:commit_db_transaction).and_return { > $log.record("COMMIT"); nil } > @cow.stub!(:save!).and_return {$log.record("COW SAVE"); true} > @dog.stub!(:save!).and_return {$log.record("DOG SAVE"); true} > @duck.stub!(:save!).and_return {$log.record("DUCK SAVE"); true} > > @tested_object.exec_method_about_cow_dog_and_duck > > txn_intervals = %w(COW DUCK DOG).collect do |beast| > [ $log.find("BEGIN", :before, "#{beast} SAVE"), > $log.find("COMMIT", :after, "#{beast} SAVE")] > end > > txn_intervals.each do |range| > range[0].should_be kind_of(Time) > range[1].should_be kind_of(Time) > end > txn_intervals.uniq.size.should == 1 > end > > where $log can be something like: > $log = Struct.new(:events, :timestamps).new > def $log.clear > events = [] > timestamps = [] > end > def $log.record(what) > events << what > timestamps << Time.now > end > def $log.find(what, where, start) > # return timestamp of event `what' that is :before or :after > (where) event `start' > end -- Codeweavers Ltd (Registered in England and Wales No. 04092394. VAT registration no. 823826816) Address: Unit 11, Imex Technology Park, ST4 8LJ. Tel: 0870 443 0888 From nick at ekenosen.net Mon Mar 12 16:01:02 2007 From: nick at ekenosen.net (nicholas a. evans) Date: Mon, 12 Mar 2007 16:01:02 -0400 Subject: [rspec-users] rspec on rails instantiated fixtures OFF by default ? In-Reply-To: <45F55723.4070103@dancingtext.com> References: <45F55723.4070103@dancingtext.com> Message-ID: <276ff9870703121301t1e151e81p64cc284f9a9c705f@mail.gmail.com> On 3/12/07, Keith McDonnell wrote: > Why are the instantiated fixtures turned off by default in the rspec on > rails plugin? This was not the case in older versions. According to http://clarkware.com/cgi/blosxom/2005/10/24, instantiated fixtures have been turned off by default in rails since version 1.0. I don't know when rspec_on_rails turned them off by default. The reason is that the new defaults give significant performance gains over the old defaults. (See the above link for more details.) -- Nick From pergesu at gmail.com Tue Mar 13 14:58:07 2007 From: pergesu at gmail.com (Pat Maddox) Date: Tue, 13 Mar 2007 12:58:07 -0600 Subject: [rspec-users] Opening the singleton class of mocked objects Message-ID: <810a540e0703131158s7b477f10yf60069fe3414d898@mail.gmail.com> I wrote a plugin [1] a while ago that lets me do validations on a single AR instance. Instead of defining validations in an AR class, I can define them on a AR instance's singleton class: class << @video validates_presence_of :title end One of my specs mocks Video.find, and the above code is run on the mock object. When I run the spec, I get the expected undefined method `validates_presence_of' for #> The code works though, I get the expected behavior. I just don't know how to spec it. Thoughts? Pat [1] http://evang.eli.st/blog/2007/1/20/instance-validations-plugin From pergesu at gmail.com Tue Mar 13 22:35:46 2007 From: pergesu at gmail.com (Pat Maddox) Date: Tue, 13 Mar 2007 20:35:46 -0600 Subject: [rspec-users] Opening the singleton class of mocked objects In-Reply-To: <810a540e0703131158s7b477f10yf60069fe3414d898@mail.gmail.com> References: <810a540e0703131158s7b477f10yf60069fe3414d898@mail.gmail.com> Message-ID: <810a540e0703131935g38f07cefr2d4f192ab0b646bf@mail.gmail.com> On 3/13/07, Pat Maddox wrote: > I wrote a plugin [1] a while ago that lets me do validations on a > single AR instance. Instead of defining validations in an AR class, I > can define them on a AR instance's singleton class: > > class << @video > validates_presence_of :title > end > > One of my specs mocks Video.find, and the above code is run on the > mock object. When I run the spec, I get the expected > > undefined method `validates_presence_of' for > #> > > The code works though, I get the expected behavior. I just don't know > how to spec it. Thoughts? > > Pat > > [1] http://evang.eli.st/blog/2007/1/20/instance-validations-plugin > btw the obvious way to do this would be to make my mock object a null object, then just stub the valid? method (which is what I ultimately call in that action). I know that my instance validations work fine from other tests, so I can get away with that. However it's blowing up because the singleton class can't just accept any method. Pat From pergesu at gmail.com Wed Mar 14 15:40:51 2007 From: pergesu at gmail.com (Pat Maddox) Date: Wed, 14 Mar 2007 13:40:51 -0600 Subject: [rspec-users] What's the new syntax for predicates? Message-ID: <810a540e0703141240w21182c6fi4302bd99544ad91c@mail.gmail.com> @settings.should allow_publish_ip("127.0.0.1") fails with undefined method `allow_publish_ip' for #<#:0x2f5a968> @settings.should_allow_publish_ip("127.0.0.1") works fine This is rspec 0.8.2. http://rspec.rubyforge.org/documentation/expectations.html says that matching arbitrary predicates is deprecated and to see Spec::Matchers...however there's nothing really useful on that page except for matching resulting values. Pat From pergesu at gmail.com Wed Mar 14 15:54:49 2007 From: pergesu at gmail.com (Pat Maddox) Date: Wed, 14 Mar 2007 13:54:49 -0600 Subject: [rspec-users] What's the new syntax for predicates? In-Reply-To: <810a540e0703141240w21182c6fi4302bd99544ad91c@mail.gmail.com> References: <810a540e0703141240w21182c6fi4302bd99544ad91c@mail.gmail.com> Message-ID: <810a540e0703141254q4a2894day5d16d584384e39c3@mail.gmail.com> On 3/14/07, Pat Maddox wrote: > @settings.should allow_publish_ip("127.0.0.1") fails with > undefined method `allow_publish_ip' for #<#:0x2f5a968> > > @settings.should_allow_publish_ip("127.0.0.1") works fine @settings.should_be allow_publish_ip("127.0.0.1") is it From aslak.hellesoy at gmail.com Wed Mar 14 16:14:46 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Wed, 14 Mar 2007 21:14:46 +0100 Subject: [rspec-users] What's the new syntax for predicates? In-Reply-To: <810a540e0703141254q4a2894day5d16d584384e39c3@mail.gmail.com> References: <810a540e0703141240w21182c6fi4302bd99544ad91c@mail.gmail.com> <810a540e0703141254q4a2894day5d16d584384e39c3@mail.gmail.com> Message-ID: <8d961d900703141314y4ea228ecq31a6249d889194cd@mail.gmail.com> On 3/14/07, Pat Maddox wrote: > On 3/14/07, Pat Maddox wrote: > > @settings.should allow_publish_ip("127.0.0.1") fails with > > undefined method `allow_publish_ip' for #<#:0x2f5a968> > > > > @settings.should_allow_publish_ip("127.0.0.1") works fine > > @settings.should_be allow_publish_ip("127.0.0.1") is it Unless I'm mistaken (David?) that's deprecated and will disappear. I believe the way forward is: @settings.should be_allow_publish_ip("127.0.0.1") Aslak > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Wed Mar 14 18:48:16 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 14 Mar 2007 17:48:16 -0500 Subject: [rspec-users] What's the new syntax for predicates? In-Reply-To: <8d961d900703141314y4ea228ecq31a6249d889194cd@mail.gmail.com> References: <810a540e0703141240w21182c6fi4302bd99544ad91c@mail.gmail.com> <810a540e0703141254q4a2894day5d16d584384e39c3@mail.gmail.com> <8d961d900703141314y4ea228ecq31a6249d889194cd@mail.gmail.com> Message-ID: <57c63afe0703141548j5eff74a3sf1432aba62893cf4@mail.gmail.com> On 3/14/07, aslak hellesoy wrote: > On 3/14/07, Pat Maddox wrote: > > On 3/14/07, Pat Maddox wrote: > > > @settings.should allow_publish_ip("127.0.0.1") fails with > > > undefined method `allow_publish_ip' for #<#:0x2f5a968> > > > > > > @settings.should_allow_publish_ip("127.0.0.1") works fine > > > > @settings.should_be allow_publish_ip("127.0.0.1") is it > > Unless I'm mistaken (David?) that's deprecated and will disappear. I > believe the way forward is: > > @settings.should be_allow_publish_ip("127.0.0.1") Sad, but true. You need to prefix w/ be_ because don't want to have method_missing doing any more magic than handling methods that start w/ be_ or have_. If you find this unpleasant, you can always provide your own helper methods. Here's a hack that you can use. Maybe we should add this to rspec? require 'rubygems' gem 'rspec' require 'spec' def predicate_matchers(*args) args.each do |arg| define_method(arg) do |*args| send "be_#{arg}", *args end end end class Thing def allow_publish_ip?(ip) true end end describe Thing do predicate_matchers :allow_publish_ip it "should allow publish ip 123" do Thing.new.should allow_publish_ip(123) end end > > Aslak > > > _______________________________________________ > > 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 Wed Mar 14 23:26:09 2007 From: cwdinfo at gmail.com (s.ross) Date: Wed, 14 Mar 2007 20:26:09 -0700 Subject: [rspec-users] What's the new syntax for predicates? In-Reply-To: <57c63afe0703141548j5eff74a3sf1432aba62893cf4@mail.gmail.com> References: <810a540e0703141240w21182c6fi4302bd99544ad91c@mail.gmail.com> <810a540e0703141254q4a2894day5d16d584384e39c3@mail.gmail.com> <8d961d900703141314y4ea228ecq31a6249d889194cd@mail.gmail.com> <57c63afe0703141548j5eff74a3sf1432aba62893cf4@mail.gmail.com> Message-ID: <9192144A-3AFB-477C-B4B2-47E77BB3024A@gmail.com> One of the most compelling things about rSpec is the English-like way it reads. I'd vote for anything that keeps it that way. If both can "should" and "should be" can be supported it captures things like: email.to.should include('me at mydomain.com') and my_ar_object.should be_valid Just my $.02. Steve On Mar 14, 2007, at 3:48 PM, David Chelimsky wrote: > On 3/14/07, aslak hellesoy wrote: >> On 3/14/07, Pat Maddox wrote: >>> On 3/14/07, Pat Maddox wrote: >>>> @settings.should allow_publish_ip("127.0.0.1") fails with >>>> undefined method `allow_publish_ip' for #<#: >>>> 0x2f5a968> >>>> >>>> @settings.should_allow_publish_ip("127.0.0.1") works fine >>> >>> @settings.should_be allow_publish_ip("127.0.0.1") is it >> >> Unless I'm mistaken (David?) that's deprecated and will disappear. I >> believe the way forward is: >> >> @settings.should be_allow_publish_ip("127.0.0.1") > > Sad, but true. You need to prefix w/ be_ because don't want to have > method_missing doing any more magic than handling methods that start > w/ be_ or have_. > > If you find this unpleasant, you can always provide your own helper > methods. Here's a hack that you can use. Maybe we should add this to > rspec? > > require 'rubygems' > gem 'rspec' > require 'spec' > > def predicate_matchers(*args) > args.each do |arg| > define_method(arg) do |*args| > send "be_#{arg}", *args > end > end > end > > class Thing > def allow_publish_ip?(ip) > true > end > end > > describe Thing do > predicate_matchers :allow_publish_ip > it "should allow publish ip 123" do > Thing.new.should allow_publish_ip(123) > end > end > >> >> Aslak >> >>> _______________________________________________ >>> 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 Wed Mar 14 23:51:29 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 14 Mar 2007 22:51:29 -0500 Subject: [rspec-users] What's the new syntax for predicates? In-Reply-To: <9192144A-3AFB-477C-B4B2-47E77BB3024A@gmail.com> References: <810a540e0703141240w21182c6fi4302bd99544ad91c@mail.gmail.com> <810a540e0703141254q4a2894day5d16d584384e39c3@mail.gmail.com> <8d961d900703141314y4ea228ecq31a6249d889194cd@mail.gmail.com> <57c63afe0703141548j5eff74a3sf1432aba62893cf4@mail.gmail.com> <9192144A-3AFB-477C-B4B2-47E77BB3024A@gmail.com> Message-ID: <57c63afe0703142051w3703a4bkda1c7117961c749@mail.gmail.com> On 3/14/07, s.ross wrote: > One of the most compelling things about rSpec is the English-like way > it reads. I'd vote for anything that keeps it that way. If both can > "should" and "should be" can be supported it captures things like: > > email.to.should include('me at mydomain.com') > > and > > my_ar_object.should be_valid > > Just my $.02. It happens that #include is supported, but explicitly, not by magic. The thing that I want to avoid is method_missing causing headaches for both users and maintainers. With my suggestion earlier this thread, this could be solved - just not automatic. So you could say predicate_matchers :absolutely_anything and then object.should absolutely_anything and it would pass if object.absolutely_anything? So you'd be able to get the nice natural language feel, but at a small price. WDYT? The reason that supporting any arbitrary anything using method_messing is problematic is that we don't know if the method is missing from the context or the object being spec'd. So not finding it would produce a message like: RSpec could not find the method #absolutely_anything. You need to either define #absolutely_anything in the context or #absolutely_anything? on your object. I don't know about you, but that would really piss me off if I saw that. I just wrote it and I have no idea what it means :) Thoughts? David > > Steve > > > On Mar 14, 2007, at 3:48 PM, David Chelimsky wrote: > > > On 3/14/07, aslak hellesoy wrote: > >> On 3/14/07, Pat Maddox wrote: > >>> On 3/14/07, Pat Maddox wrote: > >>>> @settings.should allow_publish_ip("127.0.0.1") fails with > >>>> undefined method `allow_publish_ip' for #<#: > >>>> 0x2f5a968> > >>>> > >>>> @settings.should_allow_publish_ip("127.0.0.1") works fine > >>> > >>> @settings.should_be allow_publish_ip("127.0.0.1") is it > >> > >> Unless I'm mistaken (David?) that's deprecated and will disappear. I > >> believe the way forward is: > >> > >> @settings.should be_allow_publish_ip("127.0.0.1") > > > > Sad, but true. You need to prefix w/ be_ because don't want to have > > method_missing doing any more magic than handling methods that start > > w/ be_ or have_. > > > > If you find this unpleasant, you can always provide your own helper > > methods. Here's a hack that you can use. Maybe we should add this to > > rspec? > > > > require 'rubygems' > > gem 'rspec' > > require 'spec' > > > > def predicate_matchers(*args) > > args.each do |arg| > > define_method(arg) do |*args| > > send "be_#{arg}", *args > > end > > end > > end > > > > class Thing > > def allow_publish_ip?(ip) > > true > > end > > end > > > > describe Thing do > > predicate_matchers :allow_publish_ip > > it "should allow publish ip 123" do > > Thing.new.should allow_publish_ip(123) > > end > > end > > > >> > >> Aslak > >> > >>> _______________________________________________ > >>> 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 dylanegan at gmail.com Thu Mar 15 00:26:02 2007 From: dylanegan at gmail.com (Dylan Egan) Date: Thu, 15 Mar 2007 15:26:02 +1100 Subject: [rspec-users] Rails Helpers Message-ID: Hi, Just trying to spec out my helpers and so far its been working well enough. I now have a helper as follows FooHelper def a b end def b end end But for some reason, probably something really simple, I cant work out how to spec that a calls b. Ive looked at all the variables that get set up and tried playing with them, but no luck. Maybe someone can shed some light on this for me. Apologies in advance if this is really simple and I am just missing it completely. Regards, Dylan. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070315/431473f7/attachment.html From bosshoff at gmail.com Thu Mar 15 12:00:58 2007 From: bosshoff at gmail.com (Chris Hoffman) Date: Thu, 15 Mar 2007 12:00:58 -0400 Subject: [rspec-users] rake spec:views no transaction error Message-ID: <359ebde50703150900m287e2f2auedadad631fe4048e@mail.gmail.com> Hello, I have recently upgraded to the 0.8.2 release of rSpec, and I am receiving the following message with each view spec execution: WARNING: there is no transaction in progress I have upgraded the rspec_on_rails plugin as well, and both the model and controller tests are working flawlessly. Is there some simple step I missed? thanks for the input. -Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070315/dfb03d8b/attachment.html From dchelimsky at gmail.com Thu Mar 15 12:15:28 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 15 Mar 2007 11:15:28 -0500 Subject: [rspec-users] rake spec:views no transaction error In-Reply-To: <359ebde50703150900m287e2f2auedadad631fe4048e@mail.gmail.com> References: <359ebde50703150900m287e2f2auedadad631fe4048e@mail.gmail.com> Message-ID: <57c63afe0703150915y10ebc57and92623b13b8136f@mail.gmail.com> spec/spec_helper.rb has changed. Did you run script/generate rspec? On 3/15/07, Chris Hoffman wrote: > Hello, > I have recently upgraded to the 0.8.2 release of rSpec, and I am receiving > the following message with each view spec execution: > > WARNING: there is no transaction in progress > > I have upgraded the rspec_on_rails plugin as well, and both the model and > controller tests are working flawlessly. Is there some simple step I > missed? thanks for the input. > > -Chris > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From bosshoff at gmail.com Thu Mar 15 12:50:17 2007 From: bosshoff at gmail.com (Chris Hoffman) Date: Thu, 15 Mar 2007 12:50:17 -0400 Subject: [rspec-users] rake spec:views no transaction error In-Reply-To: <57c63afe0703150915y10ebc57and92623b13b8136f@mail.gmail.com> References: <359ebde50703150900m287e2f2auedadad631fe4048e@mail.gmail.com> <57c63afe0703150915y10ebc57and92623b13b8136f@mail.gmail.com> Message-ID: <359ebde50703150950q4e37f03x593f2b297ede2ace@mail.gmail.com> Yes, and I added my own customizations back in. Other than helper methods, I have extended the Spec::Rails::Runner thusly: module Spec module Rails 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 # for breakpoint support require 'active_support/breakpoint' include Breakpoint include HpricotSpecHelper end end end end Is there something that jumps out at you? On 3/15/07, David Chelimsky wrote: > > spec/spec_helper.rb has changed. Did you run script/generate rspec? > > On 3/15/07, Chris Hoffman wrote: > > Hello, > > I have recently upgraded to the 0.8.2 release of rSpec, and I am > receiving > > the following message with each view spec execution: > > > > WARNING: there is no transaction in progress > > > > I have upgraded the rspec_on_rails plugin as well, and both the model > and > > controller tests are working flawlessly. Is there some simple step I > > missed? thanks for the input. > > > > -Chris > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070315/054310d0/attachment.html From aslak.hellesoy at gmail.com Thu Mar 15 13:14:34 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Thu, 15 Mar 2007 18:14:34 +0100 Subject: [rspec-users] rake spec:views no transaction error In-Reply-To: <359ebde50703150950q4e37f03x593f2b297ede2ace@mail.gmail.com> References: <359ebde50703150900m287e2f2auedadad631fe4048e@mail.gmail.com> <57c63afe0703150915y10ebc57and92623b13b8136f@mail.gmail.com> <359ebde50703150950q4e37f03x593f2b297ede2ace@mail.gmail.com> Message-ID: <8d961d900703151014t160f3697v1095e84f574cd8f9@mail.gmail.com> What happens if you turn off transactions? On 3/15/07, Chris Hoffman wrote: > Yes, and I added my own customizations back in. Other than helper methods, > I have extended the Spec::Rails::Runner thusly: > > module Spec > module Rails > 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 > > # for breakpoint support > require 'active_support/breakpoint' > include Breakpoint > > include HpricotSpecHelper > end > end > end > end > > Is there something that jumps out at you? > > > On 3/15/07, David Chelimsky wrote: > > spec/spec_helper.rb has changed. Did you run script/generate rspec? > > > > On 3/15/07, Chris Hoffman wrote: > > > Hello, > > > I have recently upgraded to the 0.8.2 release of rSpec, and I am > receiving > > > the following message with each view spec execution: > > > > > > WARNING: there is no transaction in progress > > > > > > I have upgraded the rspec_on_rails plugin as well, and both the model > and > > > controller tests are working flawlessly. Is there some simple step I > > > missed? thanks for the input. > > > > > > -Chris > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From bosshoff at gmail.com Thu Mar 15 13:28:30 2007 From: bosshoff at gmail.com (Chris Hoffman) Date: Thu, 15 Mar 2007 13:28:30 -0400 Subject: [rspec-users] rake spec:views no transaction error In-Reply-To: <8d961d900703151014t160f3697v1095e84f574cd8f9@mail.gmail.com> References: <359ebde50703150900m287e2f2auedadad631fe4048e@mail.gmail.com> <57c63afe0703150915y10ebc57and92623b13b8136f@mail.gmail.com> <359ebde50703150950q4e37f03x593f2b297ede2ace@mail.gmail.com> <8d961d900703151014t160f3697v1095e84f574cd8f9@mail.gmail.com> Message-ID: <359ebde50703151028j4b1d4a58m431f3b4f67168cc6@mail.gmail.com> That fixes it. Any idea why transactions are throwing that warning? I mean, it's just an annoyance, since all of the tests still run, but I would like to get rid of it if possible. -Chris On 3/15/07, aslak hellesoy wrote: > > What happens if you turn off transactions? > > On 3/15/07, Chris Hoffman wrote: > > Yes, and I added my own customizations back in. Other than helper > methods, > > I have extended the Spec::Rails::Runner thusly: > > > > module Spec > > module Rails > > 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 > > > > # for breakpoint support > > require 'active_support/breakpoint' > > include Breakpoint > > > > include HpricotSpecHelper > > end > > end > > end > > end > > > > Is there something that jumps out at you? > > > > > > On 3/15/07, David Chelimsky wrote: > > > spec/spec_helper.rb has changed. Did you run script/generate rspec? > > > > > > On 3/15/07, Chris Hoffman wrote: > > > > Hello, > > > > I have recently upgraded to the 0.8.2 release of rSpec, and I am > > receiving > > > > the following message with each view spec execution: > > > > > > > > WARNING: there is no transaction in progress > > > > > > > > I have upgraded the rspec_on_rails plugin as well, and both the > model > > and > > > > controller tests are working flawlessly. Is there some simple step > I > > > > missed? thanks for the input. > > > > > > > > -Chris > > > > > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070315/8d525e86/attachment-0001.html From aslak.hellesoy at gmail.com Thu Mar 15 14:18:57 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Thu, 15 Mar 2007 19:18:57 +0100 Subject: [rspec-users] rake spec:views no transaction error In-Reply-To: <359ebde50703151028j4b1d4a58m431f3b4f67168cc6@mail.gmail.com> References: <359ebde50703150900m287e2f2auedadad631fe4048e@mail.gmail.com> <57c63afe0703150915y10ebc57and92623b13b8136f@mail.gmail.com> <359ebde50703150950q4e37f03x593f2b297ede2ace@mail.gmail.com> <8d961d900703151014t160f3697v1095e84f574cd8f9@mail.gmail.com> <359ebde50703151028j4b1d4a58m431f3b4f67168cc6@mail.gmail.com> Message-ID: <8d961d900703151118w23383d1dk55251e36c8e0dd5f@mail.gmail.com> On 3/15/07, Chris Hoffman wrote: > That fixes it. Any idea why transactions are throwing that warning? I > mean, it's just an annoyance, since all of the tests still run, but I would > like to get rid of it if possible. > No idea, sorry. You're welcome to submit a bug report with detailed steps (a patch) that lets us reproduce it easily though. Aslak > -Chris > > > On 3/15/07, aslak hellesoy wrote: > > What happens if you turn off transactions? > > > > On 3/15/07, Chris Hoffman wrote: > > > Yes, and I added my own customizations back in. Other than helper > methods, > > > I have extended the Spec::Rails::Runner thusly: > > > > > > module Spec > > > module Rails > > > 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 > > > > > > # for breakpoint support > > > require 'active_support/breakpoint' > > > include Breakpoint > > > > > > include HpricotSpecHelper > > > end > > > end > > > end > > > end > > > > > > Is there something that jumps out at you? > > > > > > > > > On 3/15/07, David Chelimsky < dchelimsky at gmail.com> wrote: > > > > spec/spec_helper.rb has changed. Did you run script/generate rspec? > > > > > > > > On 3/15/07, Chris Hoffman < bosshoff at gmail.com> wrote: > > > > > Hello, > > > > > I have recently upgraded to the 0.8.2 release of rSpec, and I am > > > receiving > > > > > the following message with each view spec execution: > > > > > > > > > > WARNING: there is no transaction in progress > > > > > > > > > > I have upgraded the rspec_on_rails plugin as well, and both the > model > > > and > > > > > controller tests are working flawlessly. Is there some simple step > I > > > > > missed? thanks for the input. > > > > > > > > > > -Chris > > > > > > > > > > _______________________________________________ > > > > > rspec-users mailing list > > > > > rspec-users at rubyforge.org > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > _______________________________________________ > > > 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 Fri Mar 16 05:15:21 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Fri, 16 Mar 2007 09:15:21 +0000 Subject: [rspec-users] test Message-ID: <55F54204-0B26-4B3D-A1F5-B42A37067B99@ashleymoran.me.uk> An e-mail I sent yesterday didn't reach the list - I'm just checking there's no problems with my email From srbaker at pobox.com Fri Mar 16 05:26:15 2007 From: srbaker at pobox.com (Steven Baker) Date: Fri, 16 Mar 2007 02:26:15 -0700 Subject: [rspec-users] test In-Reply-To: <55F54204-0B26-4B3D-A1F5-B42A37067B99@ashleymoran.me.uk> References: <55F54204-0B26-4B3D-A1F5-B42A37067B99@ashleymoran.me.uk> Message-ID: > An e-mail I sent yesterday didn't reach the list - I'm just checking > there's no problems with my email Your client is only sending test messages. -Steven From work at ashleymoran.me.uk Fri Mar 16 11:53:42 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Fri, 16 Mar 2007 15:53:42 +0000 Subject: [rspec-users] test In-Reply-To: References: <55F54204-0B26-4B3D-A1F5-B42A37067B99@ashleymoran.me.uk> Message-ID: On 16 Mar 2007, at 09:26, Steven Baker wrote: > Your client is only sending test messages. Yes it is! I've just tried to send that e-mail again and it's not got through. Someone's spam filter must be blocking it. Oh well... you get enough emails from me here as it is :) From mailing_lists at railsnewbie.com Mon Mar 19 02:21:57 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Mon, 19 Mar 2007 02:21:57 -0400 Subject: [rspec-users] controller_name with dynamic controllers Message-ID: <2AC1AF6C-022E-4598-8BE0-A9720B658002@railsnewbie.com> I'm writing a controller which should only be inherited from, something like the generic crud controller seen here: http:// geekonomics.blogspot.com/2006/07/crud-and-shared-controllers.html Now, in my spec, I would like to create a controller which inherits from the generic CRUDController, without actually creating the controller. This controller is *only* for testing. How can I do this? I can't do something like this: Object.const_set("MyCrudController", Class.new(CRUDController)) because the method "controller_name" will complain of setting the constant twice. Any ideas? Best, Scott Taylor From dchelimsky at gmail.com Mon Mar 19 07:10:59 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 19 Mar 2007 06:10:59 -0500 Subject: [rspec-users] controller_name with dynamic controllers In-Reply-To: <2AC1AF6C-022E-4598-8BE0-A9720B658002@railsnewbie.com> References: <2AC1AF6C-022E-4598-8BE0-A9720B658002@railsnewbie.com> Message-ID: <57c63afe0703190410p774ba40ct6aab8044315513ab@mail.gmail.com> On 3/19/07, Scott Taylor wrote: > > I'm writing a controller which should only be inherited from, > something like the generic crud controller seen here: http:// > geekonomics.blogspot.com/2006/07/crud-and-shared-controllers.html > > Now, in my spec, I would like to create a controller which inherits > from the generic CRUDController, without actually creating the > controller. This controller is *only* for testing. > > How can I do this? I can't do something like this: > > Object.const_set("MyCrudController", Class.new(CRUDController)) unless defined?(TestingCrudController) TestingCrudController = Class.new(CRUDController) end > > because the method "controller_name" will complain of setting the > constant twice. > > Any ideas? > > Best, > > Scott Taylor > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jerry.west at ntlworld.com Mon Mar 19 07:38:12 2007 From: jerry.west at ntlworld.com (Jerry West) Date: Mon, 19 Mar 2007 11:38:12 +0000 Subject: [rspec-users] cookies Message-ID: <45FE7624.9050403@ntlworld.com> How do I set cookies in a spec so I can see them in my controller, please? Conversely, why doesn't this work... require File.dirname(__FILE__) + '/../spec_helper' class TestApplicationController < ApplicationController def index @seen = cookies['auth_token'] || 'NOT seen!' puts cookies.inspect # {"auth_token"=>42}, see below render :text => 'testing' # don't look for view end end context 'All controllers (via ApplicationController)...' do controller_name :test_application specify 'should see cookie' do request.cookies['auth_token'] = 42 get :index assigns['seen'].should eql(42) end end clean$ spec -cfs spec/controllers/ All controllers (via ApplicationController)... {"auth_token"=>42} - should allow access to url with proper cookie (FAILED - 1) 1) 'All controllers (via ApplicationController)... should see cookie' FAILED expected 42, got "NOT seen!" (using .eql?) ./spec/controllers/application_controller_spec.rb:17: Finished in 0.143717 seconds 1 specification, 1 failure Is it something to do with http://www.40withegg.com/2007/1/5/rails-cookies-mangles-the-hash-interface and if so, is there a workaround? Many thanks, Jerry From mailing_lists at railsnewbie.com Mon Mar 19 08:13:35 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Mon, 19 Mar 2007 08:13:35 -0400 Subject: [rspec-users] controller_name with dynamic controllers In-Reply-To: <57c63afe0703190410p774ba40ct6aab8044315513ab@mail.gmail.com> References: <2AC1AF6C-022E-4598-8BE0-A9720B658002@railsnewbie.com> <57c63afe0703190410p774ba40ct6aab8044315513ab@mail.gmail.com> Message-ID: Thanks for the reply. Actually, both work, but I was making the dumb move of using be_equal instead of be ==, so I was getting a failing spec. Scott On Mar 19, 2007, at 7:10 AM, David Chelimsky wrote: > On 3/19/07, Scott Taylor wrote: >> >> I'm writing a controller which should only be inherited from, >> something like the generic crud controller seen here: http:// >> geekonomics.blogspot.com/2006/07/crud-and-shared-controllers.html >> >> Now, in my spec, I would like to create a controller which inherits >> from the generic CRUDController, without actually creating the >> controller. This controller is *only* for testing. >> >> How can I do this? I can't do something like this: >> >> Object.const_set("MyCrudController", Class.new(CRUDController)) > > unless defined?(TestingCrudController) > TestingCrudController = Class.new(CRUDController) > end > >> >> because the method "controller_name" will complain of setting the >> constant twice. >> >> Any ideas? >> >> 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 dchelimsky at gmail.com Mon Mar 19 08:16:35 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 19 Mar 2007 07:16:35 -0500 Subject: [rspec-users] controller_name with dynamic controllers In-Reply-To: References: <2AC1AF6C-022E-4598-8BE0-A9720B658002@railsnewbie.com> <57c63afe0703190410p774ba40ct6aab8044315513ab@mail.gmail.com> Message-ID: <57c63afe0703190516m328ddbf1te0975a89397e9a12@mail.gmail.com> On 3/19/07, Scott Taylor wrote: > > Thanks for the reply. Actually, both work, but I was making the dumb > move of using be_equal instead of be ==, so I was getting a failing > spec. FWIW, be == is not really supported. You should just use == ... actual.should == expected or actual.should equal(expected) if you want object identity. > > Scott > > > On Mar 19, 2007, at 7:10 AM, David Chelimsky wrote: > > > On 3/19/07, Scott Taylor wrote: > >> > >> I'm writing a controller which should only be inherited from, > >> something like the generic crud controller seen here: http:// > >> geekonomics.blogspot.com/2006/07/crud-and-shared-controllers.html > >> > >> Now, in my spec, I would like to create a controller which inherits > >> from the generic CRUDController, without actually creating the > >> controller. This controller is *only* for testing. > >> > >> How can I do this? I can't do something like this: > >> > >> Object.const_set("MyCrudController", Class.new(CRUDController)) > > > > unless defined?(TestingCrudController) > > TestingCrudController = Class.new(CRUDController) > > end > > > >> > >> because the method "controller_name" will complain of setting the > >> constant twice. > >> > >> Any ideas? > >> > >> 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 cwdinfo at gmail.com Mon Mar 19 12:04:43 2007 From: cwdinfo at gmail.com (s.ross) Date: Mon, 19 Mar 2007 09:04:43 -0700 Subject: [rspec-users] rSpec on Rails Integration Testing Message-ID: I see that there is an integration testing example in the plugin code. What is the thinking about integration specs? Thanks, Steve From mailing_lists at railsnewbie.com Mon Mar 19 12:07:04 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Mon, 19 Mar 2007 12:07:04 -0400 Subject: [rspec-users] spec.opts: questions about formatters, etc. Message-ID: <4078CB0F-9279-4CEE-84E3-02909D470CFC@railsnewbie.com> Questions concerning spec.opts: 1. Am I correct in believing that each option should go on a separate line of spec.opts in the rails spec directory? If this is so, why is it so? 2. Using a formatter in spec.opts doesn't seem to work. Here is my spec.opts file: --colour -f s and this is what happens when I run the rake task: Couldn't find formatter class s Make sure the --require option is specified *before* --format Scott Taylor From chad at spicycode.com Mon Mar 19 12:19:02 2007 From: chad at spicycode.com (Chad Humphries) Date: Mon, 19 Mar 2007 12:19:02 -0400 Subject: [rspec-users] spec.opts: questions about formatters, etc. In-Reply-To: <4078CB0F-9279-4CEE-84E3-02909D470CFC@railsnewbie.com> References: <4078CB0F-9279-4CEE-84E3-02909D470CFC@railsnewbie.com> Message-ID: <16f722280703190919rafc6b44xd8e274e54f3dd4bc@mail.gmail.com> Scott, I use -cfs in my spec.opts (when does the same as --colour -f s) and it works great. I'm not sure about the single/multi-line bits though. -Chad On 3/19/07, Scott Taylor wrote: > > Questions concerning spec.opts: > > 1. Am I correct in believing that each option should go on a > separate line of spec.opts in the rails spec directory? If this is > so, why is it so? > > 2. Using a formatter in spec.opts doesn't seem to work. Here is my > spec.opts file: > > --colour > -f s > > and this is what happens when I run the rake task: > > Couldn't find formatter class s > Make sure the --require option is specified *before* --format > > Scott Taylor > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mlangenberg at gmail.com Mon Mar 19 13:41:04 2007 From: mlangenberg at gmail.com (Matthijs Langenberg) Date: Mon, 19 Mar 2007 18:41:04 +0100 Subject: [rspec-users] spec.opts: questions about formatters, etc. In-Reply-To: <16f722280703190919rafc6b44xd8e274e54f3dd4bc@mail.gmail.com> References: <4078CB0F-9279-4CEE-84E3-02909D470CFC@railsnewbie.com> <16f722280703190919rafc6b44xd8e274e54f3dd4bc@mail.gmail.com> Message-ID: <27c0ac6d0703191041o15317c0cna57105a48b23b58d@mail.gmail.com> Thanks for the tip Chad! On 3/19/07, Chad Humphries wrote: > Scott, > > I use -cfs in my spec.opts (when does the same as --colour -f s) and > it works great. I'm not sure about the single/multi-line bits though. > > -Chad > > On 3/19/07, Scott Taylor wrote: > > > > Questions concerning spec.opts: > > > > 1. Am I correct in believing that each option should go on a > > separate line of spec.opts in the rails spec directory? If this is > > so, why is it so? > > > > 2. Using a formatter in spec.opts doesn't seem to work. Here is my > > spec.opts file: > > > > --colour > > -f s > > > > and this is what happens when I run the rake task: > > > > Couldn't find formatter class s > > Make sure the --require option is specified *before* --format > > > > 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 dchelimsky at gmail.com Mon Mar 19 14:06:18 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 19 Mar 2007 13:06:18 -0500 Subject: [rspec-users] rSpec on Rails Integration Testing In-Reply-To: References: Message-ID: <57c63afe0703191106l6790e1afu6975315e99e8c702@mail.gmail.com> On 3/19/07, s.ross wrote: > I see that there is an integration testing example in the plugin > code. There is? > What is the thinking about integration specs? I use rails integration tests as/is right now in conjunction w/ rspec for more granular testing. It'd probably be a good idea to wrap rails integration tests, but in the long run rbehave will probably be the best choice for this level of testing (when it comes to life ;) ). > > Thanks, > > Steve > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From cwdinfo at gmail.com Mon Mar 19 14:55:34 2007 From: cwdinfo at gmail.com (s.ross) Date: Mon, 19 Mar 2007 11:55:34 -0700 Subject: [rspec-users] rSpec on Rails Integration Testing In-Reply-To: <57c63afe0703191106l6790e1afu6975315e99e8c702@mail.gmail.com> References: <57c63afe0703191106l6790e1afu6975315e99e8c702@mail.gmail.com> Message-ID: On Mar 19, 2007, at 11:06 AM, David Chelimsky wrote: > On 3/19/07, s.ross wrote: >> I see that there is an integration testing example in the plugin >> code. > > There is? Check out vendor/plugins/rspec/examples/test_case_spec.rb. Perhaps not intended as an "integration test," per-se. > >> What is the thinking about integration specs? > > I use rails integration tests as/is right now in conjunction w/ rspec > for more granular testing. It'd probably be a good idea to wrap rails > integration tests, but in the long run rbehave will probably be the > best choice for this level of testing (when it comes to life ;) ). The only reason I'm not using Rails' integration testing out of the box is that 1) I've gotten used to rSpec and like it better; and 2) With the rspec plugin installed things like use_transactional_fixtures= and use_instantiated_fixtures= generate a method_missing in rspec. I'm not sure why or whether anyone else is running into this problem. Is anyone? I'm using pretty close to trunk. > >> >> 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 dchelimsky at gmail.com Mon Mar 19 16:17:08 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 19 Mar 2007 15:17:08 -0500 Subject: [rspec-users] rSpec on Rails Integration Testing In-Reply-To: References: <57c63afe0703191106l6790e1afu6975315e99e8c702@mail.gmail.com> Message-ID: <57c63afe0703191317k4978efedqb48e3c5c8da73fdc@mail.gmail.com> On 3/19/07, s.ross wrote: > > On Mar 19, 2007, at 11:06 AM, David Chelimsky wrote: > > > On 3/19/07, s.ross wrote: > >> I see that there is an integration testing example in the plugin > >> code. > > > > There is? > > Check out vendor/plugins/rspec/examples/test_case_spec.rb. > > Perhaps not intended as an "integration test," per-se. > > > > >> What is the thinking about integration specs? > > > > I use rails integration tests as/is right now in conjunction w/ rspec > > for more granular testing. It'd probably be a good idea to wrap rails > > integration tests, but in the long run rbehave will probably be the > > best choice for this level of testing (when it comes to life ;) ). > > The only reason I'm not using Rails' integration testing out of the > box is that 1) I've gotten used to rSpec and like it better; and 2) > With the rspec plugin installed things like > use_transactional_fixtures= and use_instantiated_fixtures= generate a > method_missing in rspec. I'm not sure why or whether anyone else is > running into this problem. Is anyone? > > I'm using pretty close to trunk. Make sure that you've run script/generate rspec (or at least ensured that your spec_helper.rb matches the module structure of vendor/plugins/rspec_on_rails/generators/rspec/templates/spec_helper.rb. > > > > >> > >> 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 mailing_lists at railsnewbie.com Mon Mar 19 18:31:02 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Mon, 19 Mar 2007 18:31:02 -0400 Subject: [rspec-users] alias method spec? Message-ID: <666ED894-42A3-4BD3-8DEC-0E6D940DC20B@railsnewbie.com> I am completely baffled by this one - My guess is that there is no pure ruby way to do this - but how could I set up a spec to test that one method is an alias of another? Thanks for any help, Scott From dchelimsky at gmail.com Mon Mar 19 18:48:09 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 19 Mar 2007 17:48:09 -0500 Subject: [rspec-users] alias method spec? In-Reply-To: <666ED894-42A3-4BD3-8DEC-0E6D940DC20B@railsnewbie.com> References: <666ED894-42A3-4BD3-8DEC-0E6D940DC20B@railsnewbie.com> Message-ID: <57c63afe0703191548m5d189440ve1cf71a4bae4ebea@mail.gmail.com> On 3/19/07, Scott Taylor wrote: > > I am completely baffled by this one - My guess is that there is no > pure ruby way to do this - but how could I set up a spec to test that > one method is an alias of another? class Foo def bar end alias :baz :bar end context "Foo class" do specify "should use the same method for #baz as #bar" do Foo.instance_method(:baz).should == Foo.instance_method(:bar) end end context "Foo instance" do specify "should use the same method for #baz as #bar" do foo = Foo.new foo.method(:baz).should == foo.method(:bar) end end equal? won't work because the resulting method isn't the same object, but you'll see that == fails when the implementations they point to are different. Hope that works for you. David > > Thanks for any help, > > Scott > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Mon Mar 19 18:55:37 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Mon, 19 Mar 2007 18:55:37 -0400 Subject: [rspec-users] alias method spec? In-Reply-To: <57c63afe0703191548m5d189440ve1cf71a4bae4ebea@mail.gmail.com> References: <666ED894-42A3-4BD3-8DEC-0E6D940DC20B@railsnewbie.com> <57c63afe0703191548m5d189440ve1cf71a4bae4ebea@mail.gmail.com> Message-ID: <425A22C1-B664-42EC-9026-91D10E046EE4@railsnewbie.com> But that doesn't check that the methods are the same, does it? Doesn't it only check if the values returned by the methods are equal (in this case, nil)? Scott On Mar 19, 2007, at 6:48 PM, David Chelimsky wrote: > On 3/19/07, Scott Taylor wrote: >> >> I am completely baffled by this one - My guess is that there is no >> pure ruby way to do this - but how could I set up a spec to test that >> one method is an alias of another? > > class Foo > def bar > end > alias :baz :bar > end > > context "Foo class" do > specify "should use the same method for #baz as #bar" do > Foo.instance_method(:baz).should == Foo.instance_method(:bar) > end > end > > context "Foo instance" do > specify "should use the same method for #baz as #bar" do > foo = Foo.new > foo.method(:baz).should == foo.method(:bar) > end > end > > equal? won't work because the resulting method isn't the same object, > but you'll see that == fails when the implementations they point to > are different. > > Hope that works for you. > > David > >> >> Thanks for any help, >> >> 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 Mon Mar 19 18:59:47 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 19 Mar 2007 17:59:47 -0500 Subject: [rspec-users] alias method spec? In-Reply-To: <425A22C1-B664-42EC-9026-91D10E046EE4@railsnewbie.com> References: <666ED894-42A3-4BD3-8DEC-0E6D940DC20B@railsnewbie.com> <57c63afe0703191548m5d189440ve1cf71a4bae4ebea@mail.gmail.com> <425A22C1-B664-42EC-9026-91D10E046EE4@railsnewbie.com> Message-ID: <57c63afe0703191559p79db6ab9hf1426b7454be3f64@mail.gmail.com> On 3/19/07, Scott Taylor wrote: > > > But that doesn't check that the methods are the same, does it? > Doesn't it only check if the values returned by the methods are equal > (in this case, nil)? That's not what I get from the docs: http://www.ruby-doc.org/core/classes/Module.html#M001682 Seems to me it's an UnboundMethod object (or Method in the second example I gave). WDYT? > > Scott > > > On Mar 19, 2007, at 6:48 PM, David Chelimsky wrote: > > > On 3/19/07, Scott Taylor wrote: > >> > >> I am completely baffled by this one - My guess is that there is no > >> pure ruby way to do this - but how could I set up a spec to test that > >> one method is an alias of another? > > > > class Foo > > def bar > > end > > alias :baz :bar > > end > > > > context "Foo class" do > > specify "should use the same method for #baz as #bar" do > > Foo.instance_method(:baz).should == Foo.instance_method(:bar) > > end > > end > > > > context "Foo instance" do > > specify "should use the same method for #baz as #bar" do > > foo = Foo.new > > foo.method(:baz).should == foo.method(:bar) > > end > > end > > > > equal? won't work because the resulting method isn't the same object, > > but you'll see that == fails when the implementations they point to > > are different. > > > > Hope that works for you. > > > > David > > > >> > >> Thanks for any help, > >> > >> 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 mailing_lists at railsnewbie.com Mon Mar 19 19:00:09 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Mon, 19 Mar 2007 19:00:09 -0400 Subject: [rspec-users] action_web_services error with rspec_on_rails Message-ID: I now have two specs in my rails project which correspond to one rails controller. I can run them individually and they pass, but running them together (either with the rake task just putting both files on the command line): euclid% spec spec/controllers/crud_resource_controller_spec.rb spec/ controllers/crud_resource_controller_with_join_models_spec.rb /Users/smtlaissezfaire/Sites/rails/dictionary/vendor/rails/ actionwebservice/lib/action_web_service/container/ action_controller_container.rb:74:in `require_web_service_api': neither _api or _api found (NameError) from /Users/smtlaissezfaire/Sites/rails/dictionary/vendor/ rails/actionwebservice/lib/action_web_service/container/ action_controller_container.rb:48:in `web_service_api' from /Users/smtlaissezfaire/Sites/rails/dictionary/vendor/ rails/actionwebservice/lib/action_web_service/container/ action_controller_container.rb:85:in `inherited_without_action_controller' from /Users/smtlaissezfaire/Sites/rails/dictionary/vendor/ rails/actionwebservice/lib/action_web_service/dispatcher/ action_controller_dispatcher.rb:32:in `inherited' from ./spec/controllers/ crud_resource_controller_with_join_models_spec.rb:5:in `initialize' from ./spec/controllers/ crud_resource_controller_with_join_models_spec.rb:5:in `new' from ./spec/controllers/ crud_resource_controller_with_join_models_spec.rb:5:in `one_join_model_setup' from ./spec/controllers/ crud_resource_controller_with_join_models_spec.rb:13 from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/ runner/context.rb:14:in `class_eval' ... 11 levels... from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.8.2/lib/spec/ runner/command_line.rb:18:in `run' from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.8.2/bin/spec:4 from /opt/local/bin/spec:16:in `load' from /opt/local/bin/spec:16 I'm not using webservices at all: So can someone clue me into what is going on or point me in the right direction? Here are the two specs: #spec one require File.dirname(__FILE__) + '/../spec_helper' def one_join_model_setup unless defined? CommentController Object.const_set("CommentController", Class.new (CrudResourceController)) end #CommentController.class_eval { join_models :post } controller_name 'comment' end context "join_model" do one_join_model_setup end ## spec two require File.dirname(__FILE__) + '/../spec_helper' def testing_crud_setup unless defined? TestingCrudController Object.const_set("TestingCrudController", Class.new (CrudResourceController)) end controller_name 'testing_crud' end context "An Inherited Controller" do testing_crud_setup specify "should subclass from CrudResourceController" do TestingCrudController.superclass.to_s.should == ("CrudResourceController") end specify "should be an instance of TestingCrudController" do controller.should be_an_instance_of(TestingCrudController) end end # more contexts - I believe the revelent code stops here context "model_name" do testing_crud_setup specify "should be a private method" do controller.private_methods.include?("model_name").should == true end specify "should be the controller name" do controller.send(:model_name).should == "TestingCrud" end end context "generic_variable" do testing_crud_setup specify "should be a private method" do controller.private_methods.include?("generic_variable").should == true end specify "should return the controller name in underscore case" do controller.send(:generic_variable).should == "testing_crud" end end Thanks for all of your help, Scott Taylor From mailing_lists at railsnewbie.com Mon Mar 19 19:19:09 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Mon, 19 Mar 2007 19:19:09 -0400 Subject: [rspec-users] alias method spec? In-Reply-To: <57c63afe0703191559p79db6ab9hf1426b7454be3f64@mail.gmail.com> References: <666ED894-42A3-4BD3-8DEC-0E6D940DC20B@railsnewbie.com> <57c63afe0703191548m5d189440ve1cf71a4bae4ebea@mail.gmail.com> <425A22C1-B664-42EC-9026-91D10E046EE4@railsnewbie.com> <57c63afe0703191559p79db6ab9hf1426b7454be3f64@mail.gmail.com> Message-ID: <61C48EEE-811D-4501-A0EF-31055AE48D83@railsnewbie.com> Wow. Thanks. You've opened up a whole new world of ruby for me. I had never heard of an UnboundMethod object before. I should have RTFM'ed before I was so quick on my reply. Thanks a bunch, Scott On Mar 19, 2007, at 6:59 PM, David Chelimsky wrote: > On 3/19/07, Scott Taylor wrote: >> >> >> But that doesn't check that the methods are the same, does it? >> Doesn't it only check if the values returned by the methods are equal >> (in this case, nil)? > > That's not what I get from the docs: > > http://www.ruby-doc.org/core/classes/Module.html#M001682 > > Seems to me it's an UnboundMethod object (or Method in the second > example I gave). > > WDYT? > > >> >> Scott >> >> >> On Mar 19, 2007, at 6:48 PM, David Chelimsky wrote: >> >>> On 3/19/07, Scott Taylor wrote: >>>> >>>> I am completely baffled by this one - My guess is that there is no >>>> pure ruby way to do this - but how could I set up a spec to test >>>> that >>>> one method is an alias of another? >>> >>> class Foo >>> def bar >>> end >>> alias :baz :bar >>> end >>> >>> context "Foo class" do >>> specify "should use the same method for #baz as #bar" do >>> Foo.instance_method(:baz).should == Foo.instance_method(:bar) >>> end >>> end >>> >>> context "Foo instance" do >>> specify "should use the same method for #baz as #bar" do >>> foo = Foo.new >>> foo.method(:baz).should == foo.method(:bar) >>> end >>> end >>> >>> equal? won't work because the resulting method isn't the same >>> object, >>> but you'll see that == fails when the implementations they point to >>> are different. >>> >>> Hope that works for you. >>> >>> David >>> >>>> >>>> Thanks for any help, >>>> >>>> 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 >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From aslak.hellesoy at gmail.com Mon Mar 19 20:15:20 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 20 Mar 2007 01:15:20 +0100 Subject: [rspec-users] spec.opts: questions about formatters, etc. In-Reply-To: <4078CB0F-9279-4CEE-84E3-02909D470CFC@railsnewbie.com> References: <4078CB0F-9279-4CEE-84E3-02909D470CFC@railsnewbie.com> Message-ID: <8d961d900703191715p40bbaf0awa2a76032ea129587@mail.gmail.com> On 3/19/07, Scott Taylor wrote: > > Questions concerning spec.opts: > > 1. Am I correct in believing that each option should go on a > separate line of spec.opts in the rails spec directory? If this is > so, why is it so? > It's so simply because I was lazy when implementing it. Please file an RFE if you want to be able to put them all on one line. Aslak > 2. Using a formatter in spec.opts doesn't seem to work. Here is my > spec.opts file: > > --colour > -f s > > and this is what happens when I run the rake task: > > Couldn't find formatter class s > Make sure the --require option is specified *before* --format > > Scott Taylor > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From cdemyanovich at gmail.com Mon Mar 19 21:04:06 2007 From: cdemyanovich at gmail.com (Craig Demyanovich) Date: Mon, 19 Mar 2007 21:04:06 -0400 Subject: [rspec-users] spec.opts: questions about formatters, etc. In-Reply-To: <4078CB0F-9279-4CEE-84E3-02909D470CFC@railsnewbie.com> References: <4078CB0F-9279-4CEE-84E3-02909D470CFC@railsnewbie.com> Message-ID: <4E34F24D-C504-4332-B04D-67D2E20CE8C0@gmail.com> On Mar 19, 2007, at 12:07 PM, Scott Taylor wrote: > > Questions concerning spec.opts: > > 1. Am I correct in believing that each option should go on a > separate line of spec.opts in the rails spec directory? If this is > so, why is it so? > > 2. Using a formatter in spec.opts doesn't seem to work. Here is my > spec.opts file: > > --colour > -f s > > and this is what happens when I run the rake task: > > Couldn't find formatter class s > Make sure the --require option is specified *before* --format I ran into this problem recently. I solved it like this: --colour --format specdoc I thought I'd write it all out since it was going in spec.opts and probably wouldn't be looked at again for quite some time. Craig From dchelimsky at gmail.com Mon Mar 19 23:55:44 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 19 Mar 2007 22:55:44 -0500 Subject: [rspec-users] alias method spec? In-Reply-To: <61C48EEE-811D-4501-A0EF-31055AE48D83@railsnewbie.com> References: <666ED894-42A3-4BD3-8DEC-0E6D940DC20B@railsnewbie.com> <57c63afe0703191548m5d189440ve1cf71a4bae4ebea@mail.gmail.com> <425A22C1-B664-42EC-9026-91D10E046EE4@railsnewbie.com> <57c63afe0703191559p79db6ab9hf1426b7454be3f64@mail.gmail.com> <61C48EEE-811D-4501-A0EF-31055AE48D83@railsnewbie.com> Message-ID: <57c63afe0703192055w2bb47913g511f5b5db7dbd56@mail.gmail.com> On 3/19/07, Scott Taylor wrote: > > Wow. Thanks. You've opened up a whole new world of ruby for me. I > had never heard of an UnboundMethod object before. Now the fun begins!!!!! Cheers, David > > I should have RTFM'ed before I was so quick on my reply. > > Thanks a bunch, > > Scott > > > On Mar 19, 2007, at 6:59 PM, David Chelimsky wrote: > > > On 3/19/07, Scott Taylor wrote: > >> > >> > >> But that doesn't check that the methods are the same, does it? > >> Doesn't it only check if the values returned by the methods are equal > >> (in this case, nil)? > > > > That's not what I get from the docs: > > > > http://www.ruby-doc.org/core/classes/Module.html#M001682 > > > > Seems to me it's an UnboundMethod object (or Method in the second > > example I gave). > > > > WDYT? > > > > > >> > >> Scott > >> > >> > >> On Mar 19, 2007, at 6:48 PM, David Chelimsky wrote: > >> > >>> On 3/19/07, Scott Taylor wrote: > >>>> > >>>> I am completely baffled by this one - My guess is that there is no > >>>> pure ruby way to do this - but how could I set up a spec to test > >>>> that > >>>> one method is an alias of another? > >>> > >>> class Foo > >>> def bar > >>> end > >>> alias :baz :bar > >>> end > >>> > >>> context "Foo class" do > >>> specify "should use the same method for #baz as #bar" do > >>> Foo.instance_method(:baz).should == Foo.instance_method(:bar) > >>> end > >>> end > >>> > >>> context "Foo instance" do > >>> specify "should use the same method for #baz as #bar" do > >>> foo = Foo.new > >>> foo.method(:baz).should == foo.method(:bar) > >>> end > >>> end > >>> > >>> equal? won't work because the resulting method isn't the same > >>> object, > >>> but you'll see that == fails when the implementations they point to > >>> are different. > >>> > >>> Hope that works for you. > >>> > >>> David > >>> > >>>> > >>>> Thanks for any help, > >>>> > >>>> 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 > >> > > _______________________________________________ > > 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 Tue Mar 20 01:45:52 2007 From: cwdinfo at gmail.com (s.ross) Date: Mon, 19 Mar 2007 22:45:52 -0700 Subject: [rspec-users] alias method spec? In-Reply-To: <57c63afe0703192055w2bb47913g511f5b5db7dbd56@mail.gmail.com> References: <666ED894-42A3-4BD3-8DEC-0E6D940DC20B@railsnewbie.com> <57c63afe0703191548m5d189440ve1cf71a4bae4ebea@mail.gmail.com> <425A22C1-B664-42EC-9026-91D10E046EE4@railsnewbie.com> <57c63afe0703191559p79db6ab9hf1426b7454be3f64@mail.gmail.com> <61C48EEE-811D-4501-A0EF-31055AE48D83@railsnewbie.com> <57c63afe0703192055w2bb47913g511f5b5db7dbd56@mail.gmail.com> Message-ID: <53EDCAAB-56AD-4BEF-A08F-53A0EE90EEE9@gmail.com> This is cool, but I just gotta ask: Is this kind of a spec about behavior or low-level testing? I thought the whole zen of the spec thing was to describe desired behaviors programmatically. The notion being that these behaviors would be relatively coarse grained and the finer-grained (i.e., implementation details) would sort themselves out as you fix failures. The whole appeal to me is that you write the specs without suggesting too much about the implementation of the solution. What you're describing here appears to be tied intimately with the implementation, so if you change that you break the spec, right? Just a thought :) On Mar 19, 2007, at 8:55 PM, David Chelimsky wrote: > On 3/19/07, Scott Taylor wrote: >> >> Wow. Thanks. You've opened up a whole new world of ruby for me. I >> had never heard of an UnboundMethod object before. > > Now the fun begins!!!!! > > Cheers, > David > >> >> I should have RTFM'ed before I was so quick on my reply. >> >> Thanks a bunch, >> >> Scott >> >> >> On Mar 19, 2007, at 6:59 PM, David Chelimsky wrote: >> >>> On 3/19/07, Scott Taylor wrote: >>>> >>>> >>>> But that doesn't check that the methods are the same, does it? >>>> Doesn't it only check if the values returned by the methods are >>>> equal >>>> (in this case, nil)? >>> >>> That's not what I get from the docs: >>> >>> http://www.ruby-doc.org/core/classes/Module.html#M001682 >>> >>> Seems to me it's an UnboundMethod object (or Method in the second >>> example I gave). >>> >>> WDYT? >>> >>> >>>> >>>> Scott >>>> >>>> >>>> On Mar 19, 2007, at 6:48 PM, David Chelimsky wrote: >>>> >>>>> On 3/19/07, Scott Taylor wrote: >>>>>> >>>>>> I am completely baffled by this one - My guess is that there >>>>>> is no >>>>>> pure ruby way to do this - but how could I set up a spec to test >>>>>> that >>>>>> one method is an alias of another? >>>>> >>>>> class Foo >>>>> def bar >>>>> end >>>>> alias :baz :bar >>>>> end >>>>> >>>>> context "Foo class" do >>>>> specify "should use the same method for #baz as #bar" do >>>>> Foo.instance_method(:baz).should == Foo.instance_method(:bar) >>>>> end >>>>> end >>>>> >>>>> context "Foo instance" do >>>>> specify "should use the same method for #baz as #bar" do >>>>> foo = Foo.new >>>>> foo.method(:baz).should == foo.method(:bar) >>>>> end >>>>> end >>>>> >>>>> equal? won't work because the resulting method isn't the same >>>>> object, >>>>> but you'll see that == fails when the implementations they >>>>> point to >>>>> are different. >>>>> >>>>> Hope that works for you. >>>>> >>>>> David >>>>> >>>>>> >>>>>> Thanks for any help, >>>>>> >>>>>> 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 >>>> >>> _______________________________________________ >>> 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 Tue Mar 20 02:18:44 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Tue, 20 Mar 2007 02:18:44 -0400 Subject: [rspec-users] alias method spec? In-Reply-To: <53EDCAAB-56AD-4BEF-A08F-53A0EE90EEE9@gmail.com> References: <666ED894-42A3-4BD3-8DEC-0E6D940DC20B@railsnewbie.com> <57c63afe0703191548m5d189440ve1cf71a4bae4ebea@mail.gmail.com> <425A22C1-B664-42EC-9026-91D10E046EE4@railsnewbie.com> <57c63afe0703191559p79db6ab9hf1426b7454be3f64@mail.gmail.com> <61C48EEE-811D-4501-A0EF-31055AE48D83@railsnewbie.com> <57c63afe0703192055w2bb47913g511f5b5db7dbd56@mail.gmail.com> <53EDCAAB-56AD-4BEF-A08F-53A0EE90EEE9@gmail.com> Message-ID: <321F7CCA-899F-418D-8AB9-E7A4627B05D1@railsnewbie.com> Well honestly I just wanted a method which could be called in the plural or singular, something like: column_name :a_col or columns_names :a_first_col, :a_second_col but I want it to be the same method, and I want it to work the same way. (namely to return an array or a hash, and/or possibly set an instance variable) That's what led me to the idea in the first place, that I should test them in separate contexts, but assuring that they were indeed the same method in one of the contexts... Scott On Mar 20, 2007, at 1:45 AM, s.ross wrote: > This is cool, but I just gotta ask: Is this kind of a spec about > behavior or low-level testing? I thought the whole zen of the spec > thing was to describe desired behaviors programmatically. The notion > being that these behaviors would be relatively coarse grained and the > finer-grained (i.e., implementation details) would sort themselves > out as you fix failures. > > The whole appeal to me is that you write the specs without suggesting > too much about the implementation of the solution. What you're > describing here appears to be tied intimately with the > implementation, so if you change that you break the spec, right? > > Just a thought :) > > > On Mar 19, 2007, at 8:55 PM, David Chelimsky wrote: > >> On 3/19/07, Scott Taylor wrote: >>> >>> Wow. Thanks. You've opened up a whole new world of ruby for me. I >>> had never heard of an UnboundMethod object before. >> >> Now the fun begins!!!!! >> >> Cheers, >> David >> >>> >>> I should have RTFM'ed before I was so quick on my reply. >>> >>> Thanks a bunch, >>> >>> Scott >>> >>> >>> On Mar 19, 2007, at 6:59 PM, David Chelimsky wrote: >>> >>>> On 3/19/07, Scott Taylor wrote: >>>>> >>>>> >>>>> But that doesn't check that the methods are the same, does it? >>>>> Doesn't it only check if the values returned by the methods are >>>>> equal >>>>> (in this case, nil)? >>>> >>>> That's not what I get from the docs: >>>> >>>> http://www.ruby-doc.org/core/classes/Module.html#M001682 >>>> >>>> Seems to me it's an UnboundMethod object (or Method in the second >>>> example I gave). >>>> >>>> WDYT? >>>> >>>> >>>>> >>>>> Scott >>>>> >>>>> >>>>> On Mar 19, 2007, at 6:48 PM, David Chelimsky wrote: >>>>> >>>>>> On 3/19/07, Scott Taylor wrote: >>>>>>> >>>>>>> I am completely baffled by this one - My guess is that there >>>>>>> is no >>>>>>> pure ruby way to do this - but how could I set up a spec to test >>>>>>> that >>>>>>> one method is an alias of another? >>>>>> >>>>>> class Foo >>>>>> def bar >>>>>> end >>>>>> alias :baz :bar >>>>>> end >>>>>> >>>>>> context "Foo class" do >>>>>> specify "should use the same method for #baz as #bar" do >>>>>> Foo.instance_method(:baz).should == Foo.instance_method(:bar) >>>>>> end >>>>>> end >>>>>> >>>>>> context "Foo instance" do >>>>>> specify "should use the same method for #baz as #bar" do >>>>>> foo = Foo.new >>>>>> foo.method(:baz).should == foo.method(:bar) >>>>>> end >>>>>> end >>>>>> >>>>>> equal? won't work because the resulting method isn't the same >>>>>> object, >>>>>> but you'll see that == fails when the implementations they >>>>>> point to >>>>>> are different. >>>>>> >>>>>> Hope that works for you. >>>>>> >>>>>> David >>>>>> >>>>>>> >>>>>>> Thanks for any help, >>>>>>> >>>>>>> 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 >>>>> >>>> _______________________________________________ >>>> 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 Tue Mar 20 02:23:39 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Tue, 20 Mar 2007 02:23:39 -0400 Subject: [rspec-users] submitting a patch Message-ID: I've created a short patch so that spec.opts can use a single line (or multiple lines for backwards compatibility) for options. I've run the specs against spec:trunk I have two questions: 1. I've run rake pre_commit, but after the specs are done running, I get this error: rake aborted! ERROR while running webgen: /opt/local/lib/ruby/site_ruby/1.8/ rubygems/custom_require.rb:27:in `gem_original_require': no such file to load -- webgen/plugins/tags/tags (LoadError) from /opt/local/lib/ruby/site_ruby/1.8/rubygems/ custom_require.rb:27:in `require' from /Users/smtlaissezfaire/proj/ruby/projects/rspec/trunk/ doc/plugin/version.rb:1:in `load_plugin' from /opt/local/lib/ruby/gems/1.8/gems/webgen-0.4.2/lib/ webgen/plugin.rb:224:in `load_from_file' from /opt/local/lib/ruby/gems/1.8/gems/webgen-0.4.2/lib/ webgen/plugin.rb:223:in `catch' from /opt/local/lib/ruby/gems/1.8/gems/webgen-0.4.2/lib/ webgen/plugin.rb:223:in `load_from_file' from /opt/local/lib/ruby/gems/1.8/gems/webgen-0.4.2/lib/ webgen/plugin.rb:237:in `load_from_block' from /opt/local/lib/ruby/gems/1.8/gems/webgen-0.4.2/lib/ webgen/plugin.rb:237:in `catch' from /opt/local/lib/ruby/gems/1.8/gems/webgen-0.4.2/lib/ webgen/plugin.rb:237:in `load_from_block' ... 13 levels... from /opt/local/lib/ruby/gems/1.8/gems/webgen-0.4.2/lib/ webgen/cli.rb:454:in `cli_main' from /opt/local/lib/ruby/gems/1.8/gems/webgen-0.4.2/bin/ webgen:4 from /opt/local/bin/webgen:16:in `load' from /opt/local/bin/webgen:16 /Users/smtlaissezfaire/proj/ruby/projects/rspec/trunk/rspec/rakefile:63 So - Is this some incompatiblity between the newer version of ruby? I've installed all of the following gems (as the docs say): * rake # Runs the build script * rcov # Verifies that the code is 100% covered by specs * webgen # Generates the static HTML website * RedCloth # Required by webgen * syntax # Required by our own custom webgen extension to highlight ruby code * diff-lcs # Required if you use the --diff switch * meta_project # Required in order to make releases at RubyForge * heckle # Required if you use the --heckle switch What am I missing? 2. The website says to include docs. This is a relatively minor change. Should I just put a comment in front of the methods indicating the changes, in typical rdoc style? Best, Scott Taylor From aslak.hellesoy at gmail.com Tue Mar 20 03:17:27 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 20 Mar 2007 08:17:27 +0100 Subject: [rspec-users] submitting a patch In-Reply-To: References: Message-ID: <8d961d900703200017s56381865jbcd86b13076c7ec6@mail.gmail.com> On 3/20/07, Scott Taylor wrote: > > I've created a short patch so that spec.opts can use a single line > (or multiple lines for backwards compatibility) for options. I've > run the specs against spec:trunk > > I have two questions: > > 1. I've run rake pre_commit, but after the specs are done running, I > get this error: > > rake aborted! > ERROR while running webgen: /opt/local/lib/ruby/site_ruby/1.8/ > rubygems/custom_require.rb:27:in `gem_original_require': no such file > to load -- webgen/plugins/tags/tags (LoadError) > from /opt/local/lib/ruby/site_ruby/1.8/rubygems/ > custom_require.rb:27:in `require' > from /Users/smtlaissezfaire/proj/ruby/projects/rspec/trunk/ > doc/plugin/version.rb:1:in `load_plugin' > from /opt/local/lib/ruby/gems/1.8/gems/webgen-0.4.2/lib/ > webgen/plugin.rb:224:in `load_from_file' > from /opt/local/lib/ruby/gems/1.8/gems/webgen-0.4.2/lib/ > webgen/plugin.rb:223:in `catch' > from /opt/local/lib/ruby/gems/1.8/gems/webgen-0.4.2/lib/ > webgen/plugin.rb:223:in `load_from_file' > from /opt/local/lib/ruby/gems/1.8/gems/webgen-0.4.2/lib/ > webgen/plugin.rb:237:in `load_from_block' > from /opt/local/lib/ruby/gems/1.8/gems/webgen-0.4.2/lib/ > webgen/plugin.rb:237:in `catch' > from /opt/local/lib/ruby/gems/1.8/gems/webgen-0.4.2/lib/ > webgen/plugin.rb:237:in `load_from_block' > ... 13 levels... > from /opt/local/lib/ruby/gems/1.8/gems/webgen-0.4.2/lib/ > webgen/cli.rb:454:in `cli_main' > from /opt/local/lib/ruby/gems/1.8/gems/webgen-0.4.2/bin/ > webgen:4 > from /opt/local/bin/webgen:16:in `load' > from /opt/local/bin/webgen:16 > /Users/smtlaissezfaire/proj/ruby/projects/rspec/trunk/rspec/rakefile:63 > > > So - Is this some incompatiblity between the newer version of ruby? > I've installed all of the following gems (as the docs say): > > * rake # Runs the build script > * rcov # Verifies that the code is 100% covered by specs > * webgen # Generates the static HTML website > * RedCloth # Required by webgen > * syntax # Required by our own custom webgen extension to > highlight ruby code > * diff-lcs # Required if you use the --diff switch > * meta_project # Required in order to make releases at RubyForge > * heckle # Required if you use the --heckle switch > > What am I missing? > RSpec is using webgen 0.3.8. You probably have a newer version. > > 2. The website says to include docs. This is a relatively minor > change. Should I just put a comment in front of the methods > indicating the changes, in typical rdoc style? > We put *changes* in the trunk/rspec/CHANGES file. We use RDoc only for documentation (and not for changes). So you should probably update both. Aslak > Best, > > Scott Taylor > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Tue Mar 20 05:49:02 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 20 Mar 2007 04:49:02 -0500 Subject: [rspec-users] alias method spec? In-Reply-To: <321F7CCA-899F-418D-8AB9-E7A4627B05D1@railsnewbie.com> References: <666ED894-42A3-4BD3-8DEC-0E6D940DC20B@railsnewbie.com> <57c63afe0703191548m5d189440ve1cf71a4bae4ebea@mail.gmail.com> <425A22C1-B664-42EC-9026-91D10E046EE4@railsnewbie.com> <57c63afe0703191559p79db6ab9hf1426b7454be3f64@mail.gmail.com> <61C48EEE-811D-4501-A0EF-31055AE48D83@railsnewbie.com> <57c63afe0703192055w2bb47913g511f5b5db7dbd56@mail.gmail.com> <53EDCAAB-56AD-4BEF-A08F-53A0EE90EEE9@gmail.com> <321F7CCA-899F-418D-8AB9-E7A4627B05D1@railsnewbie.com> Message-ID: <57c63afe0703200249h335c71auf8b60b8abb16acde@mail.gmail.com> On 3/20/07, Scott Taylor wrote: > > Well honestly I just wanted a method which could be called in the > plural or singular, something like: > > column_name :a_col > > or > > columns_names :a_first_col, :a_second_col > > but I want it to be the same method, and I want it to work the same > way. (namely to return an array or a hash, and/or possibly set an > instance variable) > > That's what led me to the idea in the first place, that I should test > them in separate contexts, but assuring that they were indeed the > same method in one of the contexts... What benefit is there to knowing they are the same method, as long as they both do the same thing? > > Scott > > > > On Mar 20, 2007, at 1:45 AM, s.ross wrote: > > > This is cool, but I just gotta ask: Is this kind of a spec about > > behavior or low-level testing? I thought the whole zen of the spec > > thing was to describe desired behaviors programmatically. The notion > > being that these behaviors would be relatively coarse grained and the > > finer-grained (i.e., implementation details) would sort themselves > > out as you fix failures. > > > > The whole appeal to me is that you write the specs without suggesting > > too much about the implementation of the solution. What you're > > describing here appears to be tied intimately with the > > implementation, so if you change that you break the spec, right? > > > > Just a thought :) > > > > > > On Mar 19, 2007, at 8:55 PM, David Chelimsky wrote: > > > >> On 3/19/07, Scott Taylor wrote: > >>> > >>> Wow. Thanks. You've opened up a whole new world of ruby for me. I > >>> had never heard of an UnboundMethod object before. > >> > >> Now the fun begins!!!!! > >> > >> Cheers, > >> David > >> > >>> > >>> I should have RTFM'ed before I was so quick on my reply. > >>> > >>> Thanks a bunch, > >>> > >>> Scott > >>> > >>> > >>> On Mar 19, 2007, at 6:59 PM, David Chelimsky wrote: > >>> > >>>> On 3/19/07, Scott Taylor wrote: > >>>>> > >>>>> > >>>>> But that doesn't check that the methods are the same, does it? > >>>>> Doesn't it only check if the values returned by the methods are > >>>>> equal > >>>>> (in this case, nil)? > >>>> > >>>> That's not what I get from the docs: > >>>> > >>>> http://www.ruby-doc.org/core/classes/Module.html#M001682 > >>>> > >>>> Seems to me it's an UnboundMethod object (or Method in the second > >>>> example I gave). > >>>> > >>>> WDYT? > >>>> > >>>> > >>>>> > >>>>> Scott > >>>>> > >>>>> > >>>>> On Mar 19, 2007, at 6:48 PM, David Chelimsky wrote: > >>>>> > >>>>>> On 3/19/07, Scott Taylor wrote: > >>>>>>> > >>>>>>> I am completely baffled by this one - My guess is that there > >>>>>>> is no > >>>>>>> pure ruby way to do this - but how could I set up a spec to test > >>>>>>> that > >>>>>>> one method is an alias of another? > >>>>>> > >>>>>> class Foo > >>>>>> def bar > >>>>>> end > >>>>>> alias :baz :bar > >>>>>> end > >>>>>> > >>>>>> context "Foo class" do > >>>>>> specify "should use the same method for #baz as #bar" do > >>>>>> Foo.instance_method(:baz).should == Foo.instance_method(:bar) > >>>>>> end > >>>>>> end > >>>>>> > >>>>>> context "Foo instance" do > >>>>>> specify "should use the same method for #baz as #bar" do > >>>>>> foo = Foo.new > >>>>>> foo.method(:baz).should == foo.method(:bar) > >>>>>> end > >>>>>> end > >>>>>> > >>>>>> equal? won't work because the resulting method isn't the same > >>>>>> object, > >>>>>> but you'll see that == fails when the implementations they > >>>>>> point to > >>>>>> are different. > >>>>>> > >>>>>> Hope that works for you. > >>>>>> > >>>>>> David > >>>>>> > >>>>>>> > >>>>>>> Thanks for any help, > >>>>>>> > >>>>>>> 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 > >>>>> > >>>> _______________________________________________ > >>>> 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 > From bhelmkamp at gmail.com Tue Mar 20 12:52:55 2007 From: bhelmkamp at gmail.com (Bryan Helmkamp) Date: Tue, 20 Mar 2007 12:52:55 -0400 Subject: [rspec-users] alias method spec? In-Reply-To: <57c63afe0703200249h335c71auf8b60b8abb16acde@mail.gmail.com> References: <666ED894-42A3-4BD3-8DEC-0E6D940DC20B@railsnewbie.com> <57c63afe0703191548m5d189440ve1cf71a4bae4ebea@mail.gmail.com> <425A22C1-B664-42EC-9026-91D10E046EE4@railsnewbie.com> <57c63afe0703191559p79db6ab9hf1426b7454be3f64@mail.gmail.com> <61C48EEE-811D-4501-A0EF-31055AE48D83@railsnewbie.com> <57c63afe0703192055w2bb47913g511f5b5db7dbd56@mail.gmail.com> <53EDCAAB-56AD-4BEF-A08F-53A0EE90EEE9@gmail.com> <321F7CCA-899F-418D-8AB9-E7A4627B05D1@railsnewbie.com> <57c63afe0703200249h335c71auf8b60b8abb16acde@mail.gmail.com> Message-ID: On 3/20/07, David Chelimsky wrote: > On 3/20/07, Scott Taylor wrote: > > > > Well honestly I just wanted a method which could be called in the > > plural or singular, something like: > > > > column_name :a_col > > > > or > > > > columns_names :a_first_col, :a_second_col > > > > but I want it to be the same method, and I want it to work the same > > way. (namely to return an array or a hash, and/or possibly set an > > instance variable) > > > > That's what led me to the idea in the first place, that I should test > > them in separate contexts, but assuring that they were indeed the > > same method in one of the contexts... > > What benefit is there to knowing they are the same method, as long as > they both do the same thing? I've experienced a similar situation before. The reason I looked at testing that they are the same method is that it seemed more DRY to do that than to copy/paste the specs for that method and replace the name. WDYT? -Bryan From dchelimsky at gmail.com Tue Mar 20 17:49:01 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 20 Mar 2007 16:49:01 -0500 Subject: [rspec-users] alias method spec? In-Reply-To: References: <666ED894-42A3-4BD3-8DEC-0E6D940DC20B@railsnewbie.com> <57c63afe0703191548m5d189440ve1cf71a4bae4ebea@mail.gmail.com> <425A22C1-B664-42EC-9026-91D10E046EE4@railsnewbie.com> <57c63afe0703191559p79db6ab9hf1426b7454be3f64@mail.gmail.com> <61C48EEE-811D-4501-A0EF-31055AE48D83@railsnewbie.com> <57c63afe0703192055w2bb47913g511f5b5db7dbd56@mail.gmail.com> <53EDCAAB-56AD-4BEF-A08F-53A0EE90EEE9@gmail.com> <321F7CCA-899F-418D-8AB9-E7A4627B05D1@railsnewbie.com> <57c63afe0703200249h335c71auf8b60b8abb16acde@mail.gmail.com> Message-ID: <57c63afe0703201449n2dcdd2fasdee1e4992ffed991@mail.gmail.com> On 3/20/07, Bryan Helmkamp wrote: > On 3/20/07, David Chelimsky wrote: > > On 3/20/07, Scott Taylor wrote: > > > > > > Well honestly I just wanted a method which could be called in the > > > plural or singular, something like: > > > > > > column_name :a_col > > > > > > or > > > > > > columns_names :a_first_col, :a_second_col > > > > > > but I want it to be the same method, and I want it to work the same > > > way. (namely to return an array or a hash, and/or possibly set an > > > instance variable) > > > > > > That's what led me to the idea in the first place, that I should test > > > them in separate contexts, but assuring that they were indeed the > > > same method in one of the contexts... > > > > What benefit is there to knowing they are the same method, as long as > > they both do the same thing? > > I've experienced a similar situation before. The reason I looked at > testing that they are the same method is that it seemed more DRY to do > that than to copy/paste the specs for that method and replace the > name. WDYT? That makes sense. Another way to keep the code DRY would be to wrap the example in a loop: (pardon the trunk syntax....) describe Thing do [:b, :c].each do |method| it "should do a when you send it #{method}" do #expect something.... Thing.new.send method end end end This way the same behaviour get specified for both methods, but there's only one set of specs describing the behaviour. WDYT? > > -Bryan > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From cwdinfo at gmail.com Tue Mar 20 18:38:17 2007 From: cwdinfo at gmail.com (s.ross) Date: Tue, 20 Mar 2007 15:38:17 -0700 Subject: [rspec-users] Changes to Trunk Syntax In-Reply-To: <57c63afe0703201449n2dcdd2fasdee1e4992ffed991@mail.gmail.com> References: <666ED894-42A3-4BD3-8DEC-0E6D940DC20B@railsnewbie.com> <57c63afe0703191548m5d189440ve1cf71a4bae4ebea@mail.gmail.com> <425A22C1-B664-42EC-9026-91D10E046EE4@railsnewbie.com> <57c63afe0703191559p79db6ab9hf1426b7454be3f64@mail.gmail.com> <61C48EEE-811D-4501-A0EF-31055AE48D83@railsnewbie.com> <57c63afe0703192055w2bb47913g511f5b5db7dbd56@mail.gmail.com> <53EDCAAB-56AD-4BEF-A08F-53A0EE90EEE9@gmail.com> <321F7CCA-899F-418D-8AB9-E7A4627B05D1@railsnewbie.com> <57c63afe0703200249h335c71auf8b60b8abb16acde@mail.gmail.com> <57c63afe0703201449n2dcdd2fasdee1e4992ffed991@mail.gmail.com> Message-ID: <48B4EE95-5CAC-4A33-93E5-D6897FA0798A@gmail.com> Cool new Trunk syntax? Is there any rss feed where I can monitor the changes? From bhelmkamp at gmail.com Tue Mar 20 18:50:12 2007 From: bhelmkamp at gmail.com (Bryan Helmkamp) Date: Tue, 20 Mar 2007 18:50:12 -0400 Subject: [rspec-users] alias method spec? In-Reply-To: <57c63afe0703201449n2dcdd2fasdee1e4992ffed991@mail.gmail.com> References: <666ED894-42A3-4BD3-8DEC-0E6D940DC20B@railsnewbie.com> <425A22C1-B664-42EC-9026-91D10E046EE4@railsnewbie.com> <57c63afe0703191559p79db6ab9hf1426b7454be3f64@mail.gmail.com> <61C48EEE-811D-4501-A0EF-31055AE48D83@railsnewbie.com> <57c63afe0703192055w2bb47913g511f5b5db7dbd56@mail.gmail.com> <53EDCAAB-56AD-4BEF-A08F-53A0EE90EEE9@gmail.com> <321F7CCA-899F-418D-8AB9-E7A4627B05D1@railsnewbie.com> <57c63afe0703200249h335c71auf8b60b8abb16acde@mail.gmail.com> <57c63afe0703201449n2dcdd2fasdee1e4992ffed991@mail.gmail.com> Message-ID: On 3/20/07, David Chelimsky wrote: > On 3/20/07, Bryan Helmkamp wrote: > > I've experienced a similar situation before. The reason I looked at > > testing that they are the same method is that it seemed more DRY to do > > that than to copy/paste the specs for that method and replace the > > name. WDYT? > > That makes sense. Another way to keep the code DRY would be to wrap > the example in a loop: > > (pardon the trunk syntax....) > > describe Thing do > [:b, :c].each do |method| > it "should do a when you send it #{method}" do > #expect something.... > Thing.new.send method > end > end > end > > This way the same behaviour get specified for both methods, but > there's only one set of specs describing the behaviour. I like that solution, David. I've used loops for defining specify block in some other places, and I'm happy with the results. Just wondering, if instead of having one Thing with two methods that are identical, you instead had two types of things (Foo and Bar) with one method that should behave the same for each, how would you go about specifying that? Would you write a high level custom matcher? Use a loop to create two context blocks? Or something else? -Bryan From dchelimsky at gmail.com Tue Mar 20 19:47:55 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 20 Mar 2007 18:47:55 -0500 Subject: [rspec-users] Changes to Trunk Syntax In-Reply-To: <48B4EE95-5CAC-4A33-93E5-D6897FA0798A@gmail.com> References: <666ED894-42A3-4BD3-8DEC-0E6D940DC20B@railsnewbie.com> <57c63afe0703191559p79db6ab9hf1426b7454be3f64@mail.gmail.com> <61C48EEE-811D-4501-A0EF-31055AE48D83@railsnewbie.com> <57c63afe0703192055w2bb47913g511f5b5db7dbd56@mail.gmail.com> <53EDCAAB-56AD-4BEF-A08F-53A0EE90EEE9@gmail.com> <321F7CCA-899F-418D-8AB9-E7A4627B05D1@railsnewbie.com> <57c63afe0703200249h335c71auf8b60b8abb16acde@mail.gmail.com> <57c63afe0703201449n2dcdd2fasdee1e4992ffed991@mail.gmail.com> <48B4EE95-5CAC-4A33-93E5-D6897FA0798A@gmail.com> Message-ID: <57c63afe0703201647s31f7b7fat8962baca01de08a2@mail.gmail.com> Unless rubyforge makes one available that I don't know about, I don't think so. On 3/20/07, s.ross wrote: > Cool new Trunk syntax? Is there any rss feed where I can monitor the > changes? > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From t.lucas at toolmantim.com Tue Mar 20 19:59:47 2007 From: t.lucas at toolmantim.com (Tim Lucas) Date: Wed, 21 Mar 2007 10:59:47 +1100 Subject: [rspec-users] Changes to Trunk Syntax In-Reply-To: <57c63afe0703201647s31f7b7fat8962baca01de08a2@mail.gmail.com> References: <666ED894-42A3-4BD3-8DEC-0E6D940DC20B@railsnewbie.com> <57c63afe0703191559p79db6ab9hf1426b7454be3f64@mail.gmail.com> <61C48EEE-811D-4501-A0EF-31055AE48D83@railsnewbie.com> <57c63afe0703192055w2bb47913g511f5b5db7dbd56@mail.gmail.com> <53EDCAAB-56AD-4BEF-A08F-53A0EE90EEE9@gmail.com> <321F7CCA-899F-418D-8AB9-E7A4627B05D1@railsnewbie.com> <57c63afe0703200249h335c71auf8b60b8abb16acde@mail.gmail.com> <57c63afe0703201449n2dcdd2fasdee1e4992ffed991@mail.gmail.com> <48B4EE95-5CAC-4A33-93E5-D6897FA0798A@gmail.com> <57c63afe0703201647s31f7b7fat8962baca01de08a2@mail.gmail.com> Message-ID: <824E36A1-B27E-4009-B23A-98293089D8D4@toolmantim.com> On 21/03/2007, at 10:47 AM, David Chelimsky wrote: > Unless rubyforge makes one available that I don't know about, I > don't think so. > > On 3/20/07, s.ross wrote: >> Cool new Trunk syntax? Is there any rss feed where I can monitor the >> changes? yep, thanks to our buddy chris-err-wanstrath: http:// subtlety.errtheblog.com/ -- tim From mailing_lists at railsnewbie.com Tue Mar 20 20:38:30 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Tue, 20 Mar 2007 20:38:30 -0400 Subject: [rspec-users] alias method spec? In-Reply-To: References: <666ED894-42A3-4BD3-8DEC-0E6D940DC20B@railsnewbie.com> <57c63afe0703191548m5d189440ve1cf71a4bae4ebea@mail.gmail.com> <425A22C1-B664-42EC-9026-91D10E046EE4@railsnewbie.com> <57c63afe0703191559p79db6ab9hf1426b7454be3f64@mail.gmail.com> <61C48EEE-811D-4501-A0EF-31055AE48D83@railsnewbie.com> <57c63afe0703192055w2bb47913g511f5b5db7dbd56@mail.gmail.com> <53EDCAAB-56AD-4BEF-A08F-53A0EE90EEE9@gmail.com> <321F7CCA-899F-418D-8AB9-E7A4627B05D1@railsnewbie.com> <57c63afe0703200249h335c71auf8b60b8abb16acde@mail.gmail.com> Message-ID: <27944B0C-5CFB-4F60-A3DC-2EB935656931@railsnewbie.com> On Mar 20, 2007, at 12:52 PM, Bryan Helmkamp wrote: > On 3/20/07, David Chelimsky wrote: >> On 3/20/07, Scott Taylor wrote: >>> >>> Well honestly I just wanted a method which could be called in the >>> plural or singular, something like: >>> >>> column_name :a_col >>> >>> or >>> >>> columns_names :a_first_col, :a_second_col >>> >>> but I want it to be the same method, and I want it to work the same >>> way. (namely to return an array or a hash, and/or possibly set an >>> instance variable) >>> >>> That's what led me to the idea in the first place, that I should >>> test >>> them in separate contexts, but assuring that they were indeed the >>> same method in one of the contexts... >> >> What benefit is there to knowing they are the same method, as long as >> they both do the same thing? > > I've experienced a similar situation before. The reason I looked at > testing that they are the same method is that it seemed more DRY to do > that than to copy/paste the specs for that method and replace the > name. WDYT? Actually I wasn't going for DRY, specifically. I wanted it more for an annotation, or documentation to my code. Scott From dchelimsky at gmail.com Tue Mar 20 20:43:51 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 20 Mar 2007 19:43:51 -0500 Subject: [rspec-users] Changes to Trunk Syntax In-Reply-To: <824E36A1-B27E-4009-B23A-98293089D8D4@toolmantim.com> References: <666ED894-42A3-4BD3-8DEC-0E6D940DC20B@railsnewbie.com> <57c63afe0703192055w2bb47913g511f5b5db7dbd56@mail.gmail.com> <53EDCAAB-56AD-4BEF-A08F-53A0EE90EEE9@gmail.com> <321F7CCA-899F-418D-8AB9-E7A4627B05D1@railsnewbie.com> <57c63afe0703200249h335c71auf8b60b8abb16acde@mail.gmail.com> <57c63afe0703201449n2dcdd2fasdee1e4992ffed991@mail.gmail.com> <48B4EE95-5CAC-4A33-93E5-D6897FA0798A@gmail.com> <57c63afe0703201647s31f7b7fat8962baca01de08a2@mail.gmail.com> <824E36A1-B27E-4009-B23A-98293089D8D4@toolmantim.com> Message-ID: <57c63afe0703201743u50c9f86lc886a4536254844f@mail.gmail.com> On 3/20/07, Tim Lucas wrote: > On 21/03/2007, at 10:47 AM, David Chelimsky wrote: > > > Unless rubyforge makes one available that I don't know about, I > > don't think so. > > > > On 3/20/07, s.ross wrote: > >> Cool new Trunk syntax? Is there any rss feed where I can monitor the > >> changes? > > yep, thanks to our buddy chris-err-wanstrath: http:// > subtlety.errtheblog.com/ WOW! That is soooo cool. Thanks, David > > -- tim > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From cwdinfo at gmail.com Tue Mar 20 22:02:08 2007 From: cwdinfo at gmail.com (s.ross) Date: Tue, 20 Mar 2007 19:02:08 -0700 Subject: [rspec-users] Changes to Trunk Syntax In-Reply-To: <824E36A1-B27E-4009-B23A-98293089D8D4@toolmantim.com> References: <666ED894-42A3-4BD3-8DEC-0E6D940DC20B@railsnewbie.com> <57c63afe0703191559p79db6ab9hf1426b7454be3f64@mail.gmail.com> <61C48EEE-811D-4501-A0EF-31055AE48D83@railsnewbie.com> <57c63afe0703192055w2bb47913g511f5b5db7dbd56@mail.gmail.com> <53EDCAAB-56AD-4BEF-A08F-53A0EE90EEE9@gmail.com> <321F7CCA-899F-418D-8AB9-E7A4627B05D1@railsnewbie.com> <57c63afe0703200249h335c71auf8b60b8abb16acde@mail.gmail.com> <57c63afe0703201449n2dcdd2fasdee1e4992ffed991@mail.gmail.com> <48B4EE95-5CAC-4A33-93E5-D6897FA0798A@gmail.com> <57c63afe0703201647s31f7b7fat8962baca01de08a2@mail.gmail.com> <824E36A1-B27E-4009-B23A-98293089D8D4@toolmantim.com> Message-ID: <46428B77-BD1F-42A9-BF8C-42378CC812A8@gmail.com> Thanks! This rocks. On Mar 20, 2007, at 4:59 PM, Tim Lucas wrote: > On 21/03/2007, at 10:47 AM, David Chelimsky wrote: > >> Unless rubyforge makes one available that I don't know about, I >> don't think so. >> >> On 3/20/07, s.ross wrote: >>> Cool new Trunk syntax? Is there any rss feed where I can monitor the >>> changes? > > yep, thanks to our buddy chris-err-wanstrath: http:// > subtlety.errtheblog.com/ > > -- tim > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From bob.cotton at rallydev.com Wed Mar 21 08:34:01 2007 From: bob.cotton at rallydev.com (Bob Cotton) Date: Wed, 21 Mar 2007 06:34:01 -0600 Subject: [rspec-users] alias method spec? In-Reply-To: (Bryan Helmkamp's message of "Tue, 20 Mar 2007 18:50:12 -0400") References: <666ED894-42A3-4BD3-8DEC-0E6D940DC20B@railsnewbie.com> <425A22C1-B664-42EC-9026-91D10E046EE4@railsnewbie.com> <57c63afe0703191559p79db6ab9hf1426b7454be3f64@mail.gmail.com> <61C48EEE-811D-4501-A0EF-31055AE48D83@railsnewbie.com> <57c63afe0703192055w2bb47913g511f5b5db7dbd56@mail.gmail.com> <53EDCAAB-56AD-4BEF-A08F-53A0EE90EEE9@gmail.com> <321F7CCA-899F-418D-8AB9-E7A4627B05D1@railsnewbie.com> <57c63afe0703200249h335c71auf8b60b8abb16acde@mail.gmail.com> <57c63afe0703201449n2dcdd2fasdee1e4992ffed991@mail.gmail.com> Message-ID: "Bryan Helmkamp" writes: > On 3/20/07, David Chelimsky wrote: >> On 3/20/07, Bryan Helmkamp wrote: >> > I've experienced a similar situation before. The reason I looked at >> > testing that they are the same method is that it seemed more DRY to do >> > that than to copy/paste the specs for that method and replace the >> > name. WDYT? >> >> That makes sense. Another way to keep the code DRY would be to wrap >> the example in a loop: >> >> (pardon the trunk syntax....) >> >> describe Thing do >> [:b, :c].each do |method| >> it "should do a when you send it #{method}" do >> #expect something.... >> Thing.new.send method >> end >> end >> end >> >> This way the same behaviour get specified for both methods, but >> there's only one set of specs describing the behaviour. > > I like that solution, David. I've used loops for defining specify > block in some other places, and I'm happy with the results. Just > wondering, if instead of having one Thing with two methods that are > identical, you instead had two types of things (Foo and Bar) with one > method that should behave the same for each, how would you go about > specifying that? Would you write a high level custom matcher? Use a > loop to create two context blocks? Or something else? We have this exact problem, and the solution I was kicking around was: Module Foo def same; end end Module Bar def same; end end context Foo, Bar, "Foo and Bar" do setup do same end end where 'context' would accept a list of modules to include, and generate a new context for each. -bob From dchelimsky at gmail.com Wed Mar 21 08:59:27 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 21 Mar 2007 07:59:27 -0500 Subject: [rspec-users] alias method spec? In-Reply-To: References: <666ED894-42A3-4BD3-8DEC-0E6D940DC20B@railsnewbie.com> <61C48EEE-811D-4501-A0EF-31055AE48D83@railsnewbie.com> <57c63afe0703192055w2bb47913g511f5b5db7dbd56@mail.gmail.com> <53EDCAAB-56AD-4BEF-A08F-53A0EE90EEE9@gmail.com> <321F7CCA-899F-418D-8AB9-E7A4627B05D1@railsnewbie.com> <57c63afe0703200249h335c71auf8b60b8abb16acde@mail.gmail.com> <57c63afe0703201449n2dcdd2fasdee1e4992ffed991@mail.gmail.com> Message-ID: <57c63afe0703210559l2606e498t15445c6ebcd87f3f@mail.gmail.com> On 3/21/07, Bob Cotton wrote: > "Bryan Helmkamp" writes: > > On 3/20/07, David Chelimsky wrote: > >> On 3/20/07, Bryan Helmkamp wrote: > >> > I've experienced a similar situation before. The reason I looked at > >> > testing that they are the same method is that it seemed more DRY to do > >> > that than to copy/paste the specs for that method and replace the > >> > name. WDYT? > >> > >> That makes sense. Another way to keep the code DRY would be to wrap > >> the example in a loop: > >> > >> (pardon the trunk syntax....) > >> > >> describe Thing do > >> [:b, :c].each do |method| > >> it "should do a when you send it #{method}" do > >> #expect something.... > >> Thing.new.send method > >> end > >> end > >> end > >> > >> This way the same behaviour get specified for both methods, but > >> there's only one set of specs describing the behaviour. > > > > I like that solution, David. I've used loops for defining specify > > block in some other places, and I'm happy with the results. Just > > wondering, if instead of having one Thing with two methods that are > > identical, you instead had two types of things (Foo and Bar) with one > > method that should behave the same for each, how would you go about > > specifying that? Would you write a high level custom matcher? Use a > > loop to create two context blocks? Or something else? > > We have this exact problem, and the solution I was kicking around was: > > Module Foo > def same; end > end > > Module Bar > def same; end > end > > context Foo, Bar, "Foo and Bar" do > setup do > same > end > end > > where 'context' would accept a list of modules to include, and > generate a new context for each. That's a really interesting idea. If Foo and Bar have different initializers, there needs to be a separate setup for each. The first thing that comes to my mind is this: describe Foo, Bar, "#some_method" do setup Foo do @obj = Foo.new(...) end setup Bar do @obj = Bar.new(...) end it "should do something" do ... end end This could match up the module w/ the correct setup block and output this: Foo#some_method - should do something Bar#some_method - should do something The thing I don't like about this is that if you have 10 classes that implement one method, each in its own way, the output could start to get quite verbose, with things like: Foo#a - should blah Foo#b - should other blah etc Now we could solve that by storing all of the output and grouping it together by Class, so you would still get: Foo#a - should blah - should other blah I can see this becoming a problem in terms of finding the code for a given example. Perhaps we can have a CL switch that adds filenames and/or line numbers to the output. Seems like this could spiral into a lot of complexity. But it IS interesting. Thoughts? > > -bob > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From aslak.hellesoy at gmail.com Wed Mar 21 09:44:59 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Wed, 21 Mar 2007 14:44:59 +0100 Subject: [rspec-users] RSpec on Google Summer of Code Message-ID: <8d961d900703210644h287c210bgdd97699502d833df@mail.gmail.com> Google Summer of Code (GSoC) is starting soon, and there are two suggestions for RSpec-related projects: http://www.rubycentral.org/projects/soc2007/ideas Although not on this list (yet) I'd love to see someone taking the challenge to implement RSpec support in RDT/RadRails/Eclipse, NetBeans or IntelliJ IDEA (or all of them!). Other RSpec related projects are of course welcome too. Applications are due March 26th (http://code.google.com/soc), so if you want to be part of it you better get ready! RSpec(t), Aslak From bob.cotton at rallydev.com Wed Mar 21 10:50:04 2007 From: bob.cotton at rallydev.com (Bob Cotton) Date: Wed, 21 Mar 2007 08:50:04 -0600 Subject: [rspec-users] alias method spec? In-Reply-To: <57c63afe0703210559l2606e498t15445c6ebcd87f3f@mail.gmail.com> (David Chelimsky's message of "Wed, 21 Mar 2007 07:59:27 -0500") References: <666ED894-42A3-4BD3-8DEC-0E6D940DC20B@railsnewbie.com> <61C48EEE-811D-4501-A0EF-31055AE48D83@railsnewbie.com> <57c63afe0703192055w2bb47913g511f5b5db7dbd56@mail.gmail.com> <53EDCAAB-56AD-4BEF-A08F-53A0EE90EEE9@gmail.com> <321F7CCA-899F-418D-8AB9-E7A4627B05D1@railsnewbie.com> <57c63afe0703200249h335c71auf8b60b8abb16acde@mail.gmail.com> <57c63afe0703201449n2dcdd2fasdee1e4992ffed991@mail.gmail.com> <57c63afe0703210559l2606e498t15445c6ebcd87f3f@mail.gmail.com> Message-ID: "David Chelimsky" writes: > On 3/21/07, Bob Cotton wrote: >> "Bryan Helmkamp" writes: >> > I like that solution, David. I've used loops for defining specify >> > block in some other places, and I'm happy with the results. Just >> > wondering, if instead of having one Thing with two methods that are >> > identical, you instead had two types of things (Foo and Bar) with one >> > method that should behave the same for each, how would you go about >> > specifying that? Would you write a high level custom matcher? Use a >> > loop to create two context blocks? Or something else? >> >> We have this exact problem, and the solution I was kicking around was: >> >> Module Foo >> def same; end >> end >> >> Module Bar >> def same; end >> end >> >> context Foo, Bar, "Foo and Bar" do >> setup do >> same >> end >> end >> >> where 'context' would accept a list of modules to include, and >> generate a new context for each. > > That's a really interesting idea. If Foo and Bar have different > initializers, there needs to be a separate setup for each. The first > thing that comes to my mind is this: > > describe Foo, Bar, "#some_method" do > setup Foo do > @obj = Foo.new(...) > end > > setup Bar do > @obj = Bar.new(...) > end > > it "should do something" do > ... > end > end > > This could match up the module w/ the correct setup block and output this: > > Foo#some_method > - should do something > > Bar#some_method > - should do something > > The thing I don't like about this is that if you have 10 classes that > implement one method, each in its own way, the output could start to > get quite verbose, with things like: > > Foo#a > - should blah > > Foo#b > - should other blah > > etc > > Now we could solve that by storing all of the output and grouping it > together by Class, so you would still get: > > Foo#a > - should blah > - should other blah > > I can see this becoming a problem in terms of finding the code for a > given example. Perhaps we can have a CL switch that adds filenames > and/or line numbers to the output. Seems like this could spiral into a > lot of complexity. But it IS interesting. > > Thoughts? [ I'm still thinking in context/specify. ] David, your suggestion does answer Bryan's scenario, "you instead had two types of things (Foo and Bar) with one method that should behave the same for each" It is an interesting approach to testing a common behavior between two classes. But what about factoring the specify into a module: module Common specify "..." end then include that into the context? I guess I should have been more specific in my example. My take on it was having modules that contained some helper methods, with the same name, that would be shared across contexts. We are using rspec mostly for defining acceptance tests. We have a system that has multiple "editions", where the behavior of the editions is largely the same. Let's call these editions Large and Small. I would like to write a context that defines the common behavior of all editions, but have setup create the correct edition, for example: module Large def create; end end module Small def create; end end context Large, Small, "All editions" do setup do @system = create end specify ... end It's kind of a dependency injection for contexts. - Bob From dchelimsky at gmail.com Wed Mar 21 11:21:59 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 21 Mar 2007 10:21:59 -0500 Subject: [rspec-users] alias method spec? In-Reply-To: References: <666ED894-42A3-4BD3-8DEC-0E6D940DC20B@railsnewbie.com> <53EDCAAB-56AD-4BEF-A08F-53A0EE90EEE9@gmail.com> <321F7CCA-899F-418D-8AB9-E7A4627B05D1@railsnewbie.com> <57c63afe0703200249h335c71auf8b60b8abb16acde@mail.gmail.com> <57c63afe0703201449n2dcdd2fasdee1e4992ffed991@mail.gmail.com> <57c63afe0703210559l2606e498t15445c6ebcd87f3f@mail.gmail.com> Message-ID: <57c63afe0703210821s2cbf7b33pd9d873d90e2a71ed@mail.gmail.com> On 3/21/07, Bob Cotton wrote: > "David Chelimsky" writes: > > On 3/21/07, Bob Cotton wrote: > >> "Bryan Helmkamp" writes: > >> > I like that solution, David. I've used loops for defining specify > >> > block in some other places, and I'm happy with the results. Just > >> > wondering, if instead of having one Thing with two methods that are > >> > identical, you instead had two types of things (Foo and Bar) with one > >> > method that should behave the same for each, how would you go about > >> > specifying that? Would you write a high level custom matcher? Use a > >> > loop to create two context blocks? Or something else? > >> > >> We have this exact problem, and the solution I was kicking around was: > >> > >> Module Foo > >> def same; end > >> end > >> > >> Module Bar > >> def same; end > >> end > >> > >> context Foo, Bar, "Foo and Bar" do > >> setup do > >> same > >> end > >> end > >> > >> where 'context' would accept a list of modules to include, and > >> generate a new context for each. > > > > That's a really interesting idea. If Foo and Bar have different > > initializers, there needs to be a separate setup for each. The first > > thing that comes to my mind is this: > > > > describe Foo, Bar, "#some_method" do > > setup Foo do > > @obj = Foo.new(...) > > end > > > > setup Bar do > > @obj = Bar.new(...) > > end > > > > it "should do something" do > > ... > > end > > end > > > > This could match up the module w/ the correct setup block and output this: > > > > Foo#some_method > > - should do something > > > > Bar#some_method > > - should do something > > > > The thing I don't like about this is that if you have 10 classes that > > implement one method, each in its own way, the output could start to > > get quite verbose, with things like: > > > > Foo#a > > - should blah > > > > Foo#b > > - should other blah > > > > etc > > > > Now we could solve that by storing all of the output and grouping it > > together by Class, so you would still get: > > > > Foo#a > > - should blah > > - should other blah > > > > I can see this becoming a problem in terms of finding the code for a > > given example. Perhaps we can have a CL switch that adds filenames > > and/or line numbers to the output. Seems like this could spiral into a > > lot of complexity. But it IS interesting. > > > > Thoughts? > > [ I'm still thinking in context/specify. ] > > David, your suggestion does answer Bryan's scenario, > > "you instead had two types of things (Foo and Bar) with one method > that should behave the same for each" > > It is an interesting approach to testing a common behavior between two > classes. But what about factoring the specify into a module: > > module Common > specify "..." > end > > then include that into the context? The problem there is that we'd have to add #specify to Module, which I'm hesitant to do. How about this (using "it" and Examples instead of "specify"): module EditionExamples < SharedExampleGroup it "should " do .. end end describe LargeEdition do include EditionExamples setup do ... end end describe SmallEdition do include EditionExamples setup do ... end end That make sense? > > I guess I should have been more specific in my example. > > My take on it was having modules that contained some helper methods, > with the same name, that would be shared across contexts. > > We are using rspec mostly for defining acceptance tests. We have > a system that has multiple "editions", where the behavior of the > editions is largely the same. Let's call these editions Large and > Small. > > I would like to write a context that defines the common behavior of > all editions, but have setup create the correct edition, for example: > > module Large > def create; end > end > > module Small > def create; end > end > > context Large, Small, "All editions" do > setup do > @system = create > end > specify ... > end > > It's kind of a dependency injection for contexts. > > > - Bob > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From bob.cotton at rallydev.com Wed Mar 21 12:44:38 2007 From: bob.cotton at rallydev.com (Bob Cotton) Date: Wed, 21 Mar 2007 10:44:38 -0600 Subject: [rspec-users] alias method spec? In-Reply-To: <57c63afe0703210821s2cbf7b33pd9d873d90e2a71ed@mail.gmail.com> (David Chelimsky's message of "Wed, 21 Mar 2007 10:21:59 -0500") References: <666ED894-42A3-4BD3-8DEC-0E6D940DC20B@railsnewbie.com> <53EDCAAB-56AD-4BEF-A08F-53A0EE90EEE9@gmail.com> <321F7CCA-899F-418D-8AB9-E7A4627B05D1@railsnewbie.com> <57c63afe0703200249h335c71auf8b60b8abb16acde@mail.gmail.com> <57c63afe0703201449n2dcdd2fasdee1e4992ffed991@mail.gmail.com> <57c63afe0703210559l2606e498t15445c6ebcd87f3f@mail.gmail.com> <57c63afe0703210821s2cbf7b33pd9d873d90e2a71ed@mail.gmail.com> Message-ID: "David Chelimsky" writes: > On 3/21/07, Bob Cotton wrote: >> >> [ I'm still thinking in context/specify. ] >> >> David, your suggestion does answer Bryan's scenario, >> >> "you instead had two types of things (Foo and Bar) with one method >> that should behave the same for each" >> >> It is an interesting approach to testing a common behavior between two >> classes. But what about factoring the specify into a module: >> >> module Common >> specify "..." >> end >> >> then include that into the context? > > The problem there is that we'd have to add #specify to Module, which > I'm hesitant to do. How about this (using "it" and Examples instead of > "specify"): > > module EditionExamples < SharedExampleGroup > it "should " do > .. > end > end > > describe LargeEdition do > include EditionExamples > setup do > ... > end > end > > describe SmallEdition do > include EditionExamples > setup do > ... > end > end > > That make sense? Sure does, except, can you have modules subclass? > module EditionExamples < SharedExampleGroup Instead of factoring out the setup bits and having a common behavior, factor out the common behavior and have the #describe be the thing we are defining, which makes more sense. That fells right. I'd be all for adding specify/it to Module. *or* rspec, through #describe, is creating classes on the fly. Could you have something that defines common behavior that writes Modules on the fly? describe_common AllEditions do it "should" do end end describe "LargeEdition" do include AllEditions setup ... end describe "SmallEdition" do include AllEditions setup ... end - Bob From work at ashleymoran.me.uk Wed Mar 21 13:03:46 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Wed, 21 Mar 2007 17:03:46 +0000 Subject: [rspec-users] How to spec error_messages_for Message-ID: <9A6D414A-3992-4725-8BF6-4F62B9C5AEE9@ashleymoran.me.uk> Hi I'm trying to spec a call to error_messages_for to avoid stubbing out whole models. Something like this: context "A rendered calculate_quote view" do setup do @form = mock("form") assigns[:form] = @form end specify "should render the error messages" do .should_receive(:error_messages_for).with ('form', :anything) render 'gap/calculate_quote' end end What can I put as ? Thanks... Ashley From dchelimsky at gmail.com Wed Mar 21 13:05:57 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 21 Mar 2007 12:05:57 -0500 Subject: [rspec-users] alias method spec? In-Reply-To: References: <666ED894-42A3-4BD3-8DEC-0E6D940DC20B@railsnewbie.com> <57c63afe0703200249h335c71auf8b60b8abb16acde@mail.gmail.com> <57c63afe0703201449n2dcdd2fasdee1e4992ffed991@mail.gmail.com> <57c63afe0703210559l2606e498t15445c6ebcd87f3f@mail.gmail.com> <57c63afe0703210821s2cbf7b33pd9d873d90e2a71ed@mail.gmail.com> Message-ID: <57c63afe0703211005o7adf1f8l76c5744a09b6db9b@mail.gmail.com> On 3/21/07, Bob Cotton wrote: > "David Chelimsky" writes: > > On 3/21/07, Bob Cotton wrote: > >> > >> [ I'm still thinking in context/specify. ] > >> > >> David, your suggestion does answer Bryan's scenario, > >> > >> "you instead had two types of things (Foo and Bar) with one method > >> that should behave the same for each" > >> > >> It is an interesting approach to testing a common behavior between two > >> classes. But what about factoring the specify into a module: > >> > >> module Common > >> specify "..." > >> end > >> > >> then include that into the context? > > > > The problem there is that we'd have to add #specify to Module, which > > I'm hesitant to do. How about this (using "it" and Examples instead of > > "specify"): > > > > module EditionExamples < SharedExampleGroup > > it "should " do > > .. > > end > > end > > > > describe LargeEdition do > > include EditionExamples > > setup do > > ... > > end > > end > > > > describe SmallEdition do > > include EditionExamples > > setup do > > ... > > end > > end > > > > That make sense? > > Sure does, except, can you have modules subclass? > > > module EditionExamples < SharedExampleGroup > > Instead of factoring out the setup bits and having a common behavior, > factor out the common behavior and have the #describe be > the thing we are defining, which makes more sense. That fells right. > > I'd be all for adding specify/it to Module. > > *or* > > rspec, through #describe, is creating classes on the fly. Could you > have something that defines common behavior that writes Modules on the > fly? > > describe_common AllEditions do > it "should" do > end > end > > describe "LargeEdition" do > include AllEditions > setup ... > end > > describe "SmallEdition" do > include AllEditions > setup ... > end That's interesting too, though I'd hate to corrupt the beauty of describe w/ _common. How about: describe AllEditions, :shared => true do it "should" do end end etc.. > > - Bob > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Wed Mar 21 13:12:12 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 21 Mar 2007 12:12:12 -0500 Subject: [rspec-users] How to spec error_messages_for In-Reply-To: <9A6D414A-3992-4725-8BF6-4F62B9C5AEE9@ashleymoran.me.uk> References: <9A6D414A-3992-4725-8BF6-4F62B9C5AEE9@ashleymoran.me.uk> Message-ID: <57c63afe0703211012vffe59e8q7eab35fe76c16e6a@mail.gmail.com> On 3/21/07, Ashley Moran wrote: > Hi > > I'm trying to spec a call to error_messages_for to avoid stubbing out > whole models. Something like this: > > context "A rendered calculate_quote view" do > setup do > @form = mock("form") > assigns[:form] = @form > end > > specify "should render the error messages" do > .should_receive(:error_messages_for).with > ('form', :anything) > render 'gap/calculate_quote' > end > end > > What can I put as ? "Danger, danger, Will Robinson!" The fact that you have to ask this question is a sign that you probably shouldn't be doing this. The answer lies in AR internals, which is stuff you really shouldn't be mocking. Imagine that you do this, and a new version of rails implements this differently. You may start getting a bunch of failing integration tests w/o failing isolation tests and they'll be very difficult to track down. .02 David > > Thanks... > Ashley > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From bob.cotton at rallydev.com Wed Mar 21 13:25:16 2007 From: bob.cotton at rallydev.com (Bob Cotton) Date: Wed, 21 Mar 2007 11:25:16 -0600 Subject: [rspec-users] alias method spec? In-Reply-To: <57c63afe0703211005o7adf1f8l76c5744a09b6db9b@mail.gmail.com> (David Chelimsky's message of "Wed, 21 Mar 2007 12:05:57 -0500") References: <666ED894-42A3-4BD3-8DEC-0E6D940DC20B@railsnewbie.com> <57c63afe0703200249h335c71auf8b60b8abb16acde@mail.gmail.com> <57c63afe0703201449n2dcdd2fasdee1e4992ffed991@mail.gmail.com> <57c63afe0703210559l2606e498t15445c6ebcd87f3f@mail.gmail.com> <57c63afe0703210821s2cbf7b33pd9d873d90e2a71ed@mail.gmail.com> <57c63afe0703211005o7adf1f8l76c5744a09b6db9b@mail.gmail.com> Message-ID: "David Chelimsky" writes: > That's interesting too, though I'd hate to corrupt the beauty of > describe w/ _common. How about: > > describe AllEditions, :shared => true do > it "should" do > end > end I like that very much. - Bob From work at ashleymoran.me.uk Wed Mar 21 16:30:52 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Wed, 21 Mar 2007 20:30:52 +0000 Subject: [rspec-users] How to spec error_messages_for In-Reply-To: <57c63afe0703211012vffe59e8q7eab35fe76c16e6a@mail.gmail.com> References: <9A6D414A-3992-4725-8BF6-4F62B9C5AEE9@ashleymoran.me.uk> <57c63afe0703211012vffe59e8q7eab35fe76c16e6a@mail.gmail.com> Message-ID: On Mar 21, 2007, at 5:12 pm, David Chelimsky wrote: > "Danger, danger, Will Robinson!" > > The fact that you have to ask this question is a sign that you > probably shouldn't be doing this. The answer lies in AR internals, > which is stuff you really shouldn't be mocking. David, When I gave up reading through the Rails API and code I had started to come to that conclusion already. Unfortunately I've redefined error_messages_for to give more control over the output (why it takes so few parameters, I don't know). Now, I can spec my new helper method easily enough, but that doesn't help if I can't test if it gets called. It's one thing testing the output of a currency formatter, it's another thing to have to copy and paste tests for multi-line HTML every time it's used. > Imagine that you do this, and a new version of rails implements this > differently. You may start getting a bunch of failing integration > tests w/o failing isolation tests and they'll be very difficult to > track down. Which makes me wonder... why is it so hidden? I know it's nice to have some Ruby magic so I can call helper methods like "<%= my_method ('blah') %>" in the view source, but really, I'd be just as happy writing "<%= page.my_method('blah') %>" if it made it more transparent The only solution I can think of is to find whatever trainwreck takes me from @controller to the thing with error_messages_for, and write an assumption spec for its current implementation, so that if and when that changes, I'm notified of it. The only alternative I can see is lengthy, redundant should-have_tag specs. What do you think of this as a compromise? Ashley From dchelimsky at gmail.com Thu Mar 22 13:52:32 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 22 Mar 2007 12:52:32 -0500 Subject: [rspec-users] How to spec error_messages_for In-Reply-To: References: <9A6D414A-3992-4725-8BF6-4F62B9C5AEE9@ashleymoran.me.uk> <57c63afe0703211012vffe59e8q7eab35fe76c16e6a@mail.gmail.com> Message-ID: <57c63afe0703221052t502da367h5bb95f1aedbd3a91@mail.gmail.com> On 3/21/07, Ashley Moran wrote: > > On Mar 21, 2007, at 5:12 pm, David Chelimsky wrote: > > > "Danger, danger, Will Robinson!" > > > > The fact that you have to ask this question is a sign that you > > probably shouldn't be doing this. The answer lies in AR internals, > > which is stuff you really shouldn't be mocking. > > David, > > When I gave up reading through the Rails API and code I had started > to come to that conclusion already. Unfortunately I've redefined > error_messages_for to give more control over the output (why it takes > so few parameters, I don't know). This is an interesting case because the behaviour you want to describe is no longer in your app - it's actually new behaviour in Rails itself (in your patch of rails). What I prefer to do in this case is patch the rails tests as well, rather than adding tests to my app(s). I keep a set of patches around that patch both tests and implementation and whenever I install rails in a project, I run these patches and don't worry about it in the examples for my app. WDYT? > Now, I can spec my new helper > method easily enough, but that doesn't help if I can't test if it > gets called. It's one thing testing the output of a currency > formatter, it's another thing to have to copy and paste tests for > multi-line HTML every time it's used. > > > > Imagine that you do this, and a new version of rails implements this > > differently. You may start getting a bunch of failing integration > > tests w/o failing isolation tests and they'll be very difficult to > > track down. > > Which makes me wonder... why is it so hidden? I know it's nice to > have some Ruby magic so I can call helper methods like "<%= my_method > ('blah') %>" in the view source, but really, I'd be just as happy > writing "<%= page.my_method('blah') %>" if it made it more transparent Rails is all about opacity. I re-learn that lesson nearly every day. > The only solution I can think of is to find whatever trainwreck takes > me from @controller to the thing with error_messages_for, and write > an assumption spec for its current implementation, so that if and > when that changes, I'm notified of it. The only alternative I can > see is lengthy, redundant should-have_tag specs. What do you think > of this as a compromise? Well, it doesn't make me want to jump for joy, but I might choose to do it this way anyhow. Lesser of many evils and all. David > > Ashley > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From work at ashleymoran.me.uk Fri Mar 23 06:37:50 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Fri, 23 Mar 2007 10:37:50 +0000 Subject: [rspec-users] How to spec error_messages_for In-Reply-To: <57c63afe0703221052t502da367h5bb95f1aedbd3a91@mail.gmail.com> References: <9A6D414A-3992-4725-8BF6-4F62B9C5AEE9@ashleymoran.me.uk> <57c63afe0703211012vffe59e8q7eab35fe76c16e6a@mail.gmail.com> <57c63afe0703221052t502da367h5bb95f1aedbd3a91@mail.gmail.com> Message-ID: <18016487-D97D-473D-9BBB-B6EF25B90783@ashleymoran.me.uk> On 22 Mar 2007, at 17:52, David Chelimsky wrote: > This is an interesting case because the behaviour you want to describe > is no longer in your app - it's actually new behaviour in Rails itself > (in your patch of rails). Well I added the code to ApplicationHelper, so I guess the tests still belong in my app, even if they override some Rails magic (actually, maybe the thing I need to test is that it DOES override the Rails magic but let's not go there...) > Rails is all about opacity. I re-learn that lesson nearly every day. Within Rails, there is a much smaller and cleaner framework struggling to get out? > Well, it doesn't make me want to jump for joy, but I might choose to > do it this way anyhow. Lesser of many evils and all. Eventually I gave up and did this. I added the following to my controller spec: context "ASSUMPTION (about the next spec): the controller" do specify "should have respond to template and return a template that responds to error_messages_for" do @controller.should respond_to(:template) @controller.template.should respond_to(:error_messages_for) end end context "A rendered calculate_quote view with an invalid form" do ... specify "should render the error messages" do @controller.template.should_receive(:error_messages_for).with ('form', :anything).and_return("
ERRORS
") render 'gap/calculate_quote' response.should have_tag("div", :text => "ERRORS") end end Which I think catches it. I don't think given the current Rails architecture that there's a cleaner way. Thanks Ashley From mailing_lists at railsnewbie.com Sat Mar 24 03:08:15 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sat, 24 Mar 2007 03:08:15 -0400 Subject: [rspec-users] State Based vs. Behaviour Based Spec/Testing Message-ID: <3AB63458-C244-43C6-92F5-24061534B606@railsnewbie.com> I've notice that a project like Rubinius has both a spec & a test directory. Rspec has only a spec directory. Obviously I support BDD, but isn't there also a place for state based/verification testing? I sometimes sense that I *do* want to practice Test Driven Development. That is, I want some assurance that my production code will run as intended. But I also want some verification of a bug right after I have implemented it. How can one truly get away from state based testing to some degree? Spec's often seem too "high level" to assure the "testing" of the code. I know that Test::Unit code will always be brittle. What happens when the code is refactored? It is sure to break. Does this suggest that Test::Unit code should be written right after development is done, covering the internals of the project? Maybe BDD specs should be written first, using TDD with Test::Unit for verification (as throw-away code)? Or do mock objects solve all of these problems? The real question is, do you spec'ers think there is any place for a testing framework next to a spec'ing framework? Best, Scott Taylor From mailing_lists at railsnewbie.com Sat Mar 24 05:11:04 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sat, 24 Mar 2007 05:11:04 -0400 Subject: [rspec-users] spec'ing metaprograming & rails CRUD Message-ID: <6CB12C20-54B1-4043-8C07-D1E3E9C92BC2@railsnewbie.com> For edge rails there is a Crud generator. There is also a CRUD controller that is out there from which you can inherit your other controllers (see http://geekonomics.blogspot.com/2006/07/crud-and- shared-controllers.html) This got me thinking about Crud controllers in general. As far as I know, the generator can't produce crud classes which are nested (i.e. /posts/1/comments/7). So I thought about creating my own Crud class from which to inherit from, with some private methods, like so: class CrudController < ActiveRecord::Base class << self private def model # get a default name based on the controller name # or specify a name end def belongs_to # the model's "belongs_to"/foreign key relationship # this could also be found dynamically end end end class CommentsController < CrudController model :comments belongs_to :post end And then this would generate the typical nested crud, with before_filter and all of that jazz Anyway, here goes my question. The CrudController's specs should set a bunch of instance variables (such as @comments = @post.comments) and a bunch of instance methods in the Comments controller. How would I spec out such a thing? I would have to use reflection in The CRUD controller - do a bunch of no-no's, like use private_instance_methods, send, etc. to get to the private class methods So It looks like I should just create a CommentsController instance, and spec that. But now how do I practice test-first development on the CrudController? I have also been thinking a little bit about the specs of Rubinius. I have no idea how it is implemented, but I'm sure each class will have a symbol table, etc. etc. The high level spec's will look something like the following: specify "+ should concatenate two arrays" do example do [ 1, 2, 3 ] + [ 4, 5 ] end.should == [1, 2, 3, 4, 5] end How Rubininus creates the Arrays, sets them up in the symbol table/ creates an object id, etc. - All of this, the spec will never touch. How is one to do test first development on this sort of thing? If the methods involved get too big, they will probably be refactored into private methods. So how does one practice BDD on private methods? Or should one just assume that they will work? These sorts of things are the things I was thinking about in my last email. As I see it, spec'ing/testing is used for the following: 1. Verification of Code Working the way you expect it to. This is more fine grained, and better suited to Test::Unit, although the code can easily break after refactoring. 2. Documentation 3. Test-First development. What small piece do I implement next? (Think of the Rubinus/private methods example) 4. Defining Behaviour, which of course, is simply high level verification on exposed methods. Thoughts on these matters? Scott From dchelimsky at gmail.com Sat Mar 24 08:19:20 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 24 Mar 2007 07:19:20 -0500 Subject: [rspec-users] State Based vs. Behaviour Based Spec/Testing In-Reply-To: <3AB63458-C244-43C6-92F5-24061534B606@railsnewbie.com> References: <3AB63458-C244-43C6-92F5-24061534B606@railsnewbie.com> Message-ID: <57c63afe0703240519q40ae8a62v34672b71874fc383@mail.gmail.com> On 3/24/07, Scott Taylor wrote: > > I've notice that a project like Rubinius has both a spec & a test > directory. Rspec has only a spec directory. Obviously I support > BDD, but isn't there also a place for state based/verification > testing? BDD is not a tool. BDD is a way of thinking about TDD. BDD *is* TDD, with focus (not exclusivity) on behaviour. This is what I believe to be the initial intent of TDD. This doesn't mean that all state testing is bad. In fact, most of the expectations in rspec are state-based: actual.should == value, etc. I think you're confusing Interaction testing with BDD. Interaction testing is a very important part of BDD, but it is not the sole purview of BDD. Mocks have been around for a long time. I can't really think of anything that you can do with rspec that you can't do w/ test/unit and mocha. RSpec just tries to make it easier to focus on behaviour by using less "testy" words. > I sometimes sense that I *do* want to practice Test Driven > Development. That is, I want some assurance that my production code > will run as intended. But I also want some verification of a bug > right after I have implemented it. Many people fix bugs using TDD. When the bug is reported, just start by writing a failing test that exposes the bug. Keep in mind that when doing TDD, the nature of the tests change very quickly. When you write the failing test, your goal is expose a missing or incorrect behaviour, and use the resulting test to drive your design. As soon as that test is passing, it changes in nature, becoming both documentation and a regression test. > > How can one truly get away from state based testing to some degree? You can't. At least not in my experience. > Spec's often seem too "high level" to assure the "testing" of the code. Again, this has to do w/ approach. You can write low level specs just as you can write high-level tests. The trick is balance, keeping the focus on behaviour rather than the internal structure of code. > I know that Test::Unit code will always be brittle. What happens > when the code is refactored? It is sure to break. > Does this suggest that Test::Unit code should be written right after > development is done, covering the internals of the project? Again, this is a matter of approach, not tooling. Assuming that you *must* test something internal, there's no reason that you can't do it with rspec. But if you are testing internals, I'd reflect on that and ask yourself why it is important to do so. Ask yourself how the behaviour is going to be different if the internals change. I'll bet that most (not all) of the time, you'll be able to find ways to express your "testing" concerns in terms of behaviour. If you can do that without having to get too far away from the code to do so, you're better off because you'll have better documentation and less brittle tests. We should really be talking about specific examples, because there are some principles here that are either not being recognized or dying to get out. Feel free to post some. > Maybe > BDD specs should be written first, using TDD with Test::Unit for > verification (as throw-away code)? Or do mock objects solve all of > these problems? > > The real question is, do you spec'ers think there is any place for a > testing framework next to a spec'ing framework? Heretical though this may seem: RSPEC IS A TESTING FRAMEWORK. There, I said it. Scott - I don't mean to pick on you here. In fact, I thank you for posting this because a lot has been said during the early phases of BDD's evolution that is confusing and obviously misleading. And, in fact, much of this has been said by me as I've been exploring what the meaning of BDD is ... to me. I hope that you'll keep posting questions like this as they can only help us all to clarify things. Cheers, David > > Best, > > Scott Taylor > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Sat Mar 24 09:08:57 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 24 Mar 2007 08:08:57 -0500 Subject: [rspec-users] State Based vs. Behaviour Based Spec/Testing In-Reply-To: <57c63afe0703240519q40ae8a62v34672b71874fc383@mail.gmail.com> References: <3AB63458-C244-43C6-92F5-24061534B606@railsnewbie.com> <57c63afe0703240519q40ae8a62v34672b71874fc383@mail.gmail.com> Message-ID: <57c63afe0703240608m1021ac3dx52812572a014d82f@mail.gmail.com> On 3/24/07, David Chelimsky wrote: > On 3/24/07, Scott Taylor wrote: > > > > I've notice that a project like Rubinius has both a spec & a test > > directory. Rspec has only a spec directory. Obviously I support > > BDD, but isn't there also a place for state based/verification > > testing? > > BDD is not a tool. BDD is a way of thinking about TDD. BDD *is* TDD, > with focus (not exclusivity) on behaviour. This is what I believe to > be the initial intent of TDD. This doesn't mean that all state testing > is bad. In fact, most of the expectations in rspec are state-based: > actual.should == value, etc. > > I think you're confusing Interaction testing with BDD. Interaction > testing is a very important part of BDD, but it is not the sole > purview of BDD. Mocks have been around for a long time. I can't really > think of anything that you can do with rspec that you can't do w/ > test/unit and mocha. RSpec just tries to make it easier to focus on > behaviour by using less "testy" words. > > > I sometimes sense that I *do* want to practice Test Driven > > Development. That is, I want some assurance that my production code > > will run as intended. But I also want some verification of a bug > > right after I have implemented it. > > Many people fix bugs using TDD. When the bug is reported, just start > by writing a failing test that exposes the bug. > > Keep in mind that when doing TDD, the nature of the tests change very > quickly. When you write the failing test, your goal is expose a > missing or incorrect behaviour, and use the resulting test to drive > your design. As soon as that test is passing, it changes in nature, > becoming both documentation and a regression test. > > > > > How can one truly get away from state based testing to some degree? > > You can't. At least not in my experience. > > > Spec's often seem too "high level" to assure the "testing" of the code. > > Again, this has to do w/ approach. You can write low level specs just > as you can write high-level tests. The trick is balance, keeping the > focus on behaviour rather than the internal structure of code. > > > I know that Test::Unit code will always be brittle. What happens > > when the code is refactored? It is sure to break. > > Does this suggest that Test::Unit code should be written right after > > development is done, covering the internals of the project? > > Again, this is a matter of approach, not tooling. Assuming that you > *must* test something internal, there's no reason that you can't do it > with rspec. But if you are testing internals, I'd reflect on that and > ask yourself why it is important to do so. Ask yourself how the > behaviour is going to be different if the internals change. I'll bet > that most (not all) of the time, you'll be able to find ways to > express your "testing" concerns in terms of behaviour. If you can do > that without having to get too far away from the code to do so, you're > better off because you'll have better documentation and less brittle > tests. > > We should really be talking about specific examples, because there are > some principles here that are either not being recognized or dying to > get out. Feel free to post some. > > > Maybe > > BDD specs should be written first, using TDD with Test::Unit for > > verification (as throw-away code)? Or do mock objects solve all of > > these problems? > > > > The real question is, do you spec'ers think there is any place for a > > testing framework next to a spec'ing framework? > > Heretical though this may seem: RSPEC IS A TESTING FRAMEWORK. There, I said it. > > Scott - I don't mean to pick on you here. In fact, I thank you for > posting this because a lot has been said during the early phases of > BDD's evolution that is confusing and obviously misleading. And, in > fact, much of this has been said by me as I've been exploring what the > meaning of BDD is ... to me. > > I hope that you'll keep posting questions like this as they can only > help us all to clarify things. I should also add that I'm talking about BDD as applied to isolation testing (what many call unit testing :) ). BDD has really evolved into an agile practice that comprises TDD, Acceptance Test Driven Planning and other concepts that are geared towards increasing communication and understanding within the context of a software project. If this is new to you, check out http://dannorth.net/introducing-bdd/. > > Cheers, > David > > > > > 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 Sat Mar 24 09:11:12 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Sat, 24 Mar 2007 14:11:12 +0100 Subject: [rspec-users] State Based vs. Behaviour Based Spec/Testing In-Reply-To: <3AB63458-C244-43C6-92F5-24061534B606@railsnewbie.com> References: <3AB63458-C244-43C6-92F5-24061534B606@railsnewbie.com> Message-ID: <8d961d900703240611u3e79baa0w5c795d72dae5697e@mail.gmail.com> On 3/24/07, Scott Taylor wrote: > > I've notice that a project like Rubinius has both a spec & a test > directory. Rspec has only a spec directory. Obviously I support > BDD, but isn't there also a place for state based/verification Anyone is free to write their code who they want. RSpec doesn't mandate any particular style, it just encourages it. > testing? I sometimes sense that I *do* want to practice Test Driven > Development. Ok. BDD is just a kind of TDD with a stronger focus on "tell don't ask", mocking and intent. > That is, I want some assurance that my production code > will run as intended. But I also want some verification of a bug > right after I have implemented it. > > How can one truly get away from state based testing to some degree? Use mocking to drive out interaction between objects. Strive for a "tell don't ask" design (look it up). > Spec's often seem too "high level" to assure the "testing" of the code. > What do you mean? > I know that Test::Unit code will always be brittle. What happens > when the code is refactored? It is sure to break. > Huh? What is it about Test::Unit that makes it inherently brittle? I have no idea what you are talking about here. > Does this suggest that Test::Unit code should be written right after > development is done, covering the internals of the project? If you're doing TDD, no - you write tests before the code. If you're "just using Test::Unit" you can write it when you want. > Maybe > BDD specs should be written first, using TDD with Test::Unit for BDD *is* TDD, with some extra philosophical baggage. You write specs before the code in both BDD and TDD. > verification (as throw-away code)? Or do mock objects solve all of > these problems? > What problems? > The real question is, do you spec'ers think there is any place for a > testing framework next to a spec'ing framework? > To solve what problem? Aslak > Best, > > Scott Taylor > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mtrier at eminentconsultinggroup.com Sat Mar 24 09:32:06 2007 From: mtrier at eminentconsultinggroup.com (Michael Trier) Date: Sat, 24 Mar 2007 09:32:06 -0400 Subject: [rspec-users] spec'ing metaprograming & rails CRUD In-Reply-To: <6CB12C20-54B1-4043-8C07-D1E3E9C92BC2@railsnewbie.com> References: <6CB12C20-54B1-4043-8C07-D1E3E9C92BC2@railsnewbie.com> Message-ID: <6F1FD75F-2451-48A3-98AE-1F806963AE2F@eminentconsultinggroup.com> On Mar 24, 2007, at 5:11 AM, Scott Taylor wrote: > > For edge rails there is a Crud generator. There is also a CRUD > controller that is out there from which you can inherit your other > controllers (see http://geekonomics.blogspot.com/2006/07/crud-and- > shared-controllers.html) > > This got me thinking about Crud controllers in general. As far as I > know, the generator can't produce crud classes which are nested > (i.e. /posts/1/comments/7). So I thought about creating my own Crud > class from which to inherit from, with some private methods, like so: > > class CrudController < ActiveRecord::Base > class << self > private > def model > # get a default name based on the controller name > # or specify a name > end > > def belongs_to > # the model's "belongs_to"/foreign key relationship > # this could also be found dynamically > end > end > end > > class CommentsController < CrudController > model :comments > belongs_to :post > end You might want to look into the resource_controller plugin: (http:// svn.ardes.com/rails_plugins/resources_controller/ It does what you're describing in a very nice way and supports nested as well as acts_as_tree situations. Michael -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070324/47027130/attachment-0001.html From keith at dancingtext.com Sat Mar 24 10:45:57 2007 From: keith at dancingtext.com (Keith McDonnell) Date: Sat, 24 Mar 2007 14:45:57 +0000 Subject: [rspec-users] Using spec fixtures with integration tests In-Reply-To: References: Message-ID: <460539A5.7080005@dancingtext.com> Hi all, How can I use spec fixtures with rails integration tests ? I've tried adding {{ fixtures "../../spec/fixtures/myfixture" }} to the integration test but the fixtures are not loaded when I run the rake task. Rails doesn't load symlinked fixtures either so I copied the files from spec/fixtures for the time being. Not very DRY. Any ideas ? Keith rspec-users-request at rubyforge.org wrote: > Send rspec-users mailing list submissions to > rspec-users at rubyforge.org > > To subscribe or unsubscribe via the World Wide Web, visit > http://rubyforge.org/mailman/listinfo/rspec-users > or, via email, send a message with subject or body 'help' to > rspec-users-request at rubyforge.org > > You can reach the person managing the list at > rspec-users-owner at rubyforge.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of rspec-users digest..." > > > Today's Topics: > > 1. spec'ing metaprograming & rails CRUD (Scott Taylor) > 2. Re: State Based vs. Behaviour Based Spec/Testing (David Chelimsky) > 3. Re: State Based vs. Behaviour Based Spec/Testing (David Chelimsky) > 4. Re: State Based vs. Behaviour Based Spec/Testing (aslak hellesoy) > 5. Re: spec'ing metaprograming & rails CRUD (Michael Trier) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Sat, 24 Mar 2007 05:11:04 -0400 > From: Scott Taylor > Subject: [rspec-users] spec'ing metaprograming & rails CRUD > To: rspec-users > Message-ID: <6CB12C20-54B1-4043-8C07-D1E3E9C92BC2 at railsnewbie.com> > Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed > > > For edge rails there is a Crud generator. There is also a CRUD > controller that is out there from which you can inherit your other > controllers (see http://geekonomics.blogspot.com/2006/07/crud-and- > shared-controllers.html) > > This got me thinking about Crud controllers in general. As far as I > know, the generator can't produce crud classes which are nested > (i.e. /posts/1/comments/7). So I thought about creating my own Crud > class from which to inherit from, with some private methods, like so: > > class CrudController < ActiveRecord::Base > class << self > private > def model > # get a default name based on the controller name > # or specify a name > end > > def belongs_to > # the model's "belongs_to"/foreign key relationship > # this could also be found dynamically > end > end > end > > class CommentsController < CrudController > model :comments > belongs_to :post > end > > And then this would generate the typical nested crud, with > before_filter and all of that jazz > > Anyway, here goes my question. The CrudController's specs should set > a bunch of instance variables (such as @comments = @post.comments) > and a bunch of instance methods in the Comments controller. How > would I spec out such a thing? I would have to use reflection in The > CRUD controller - do a bunch of no-no's, like use > private_instance_methods, send, etc. to get to the private class methods > > So It looks like I should just create a CommentsController instance, > and spec that. But now how do I practice test-first development on > the CrudController? > > I have also been thinking a little bit about the specs of Rubinius. > I have no idea how it is implemented, but I'm sure each class will > have a symbol table, etc. etc. The high level spec's will look > something like the following: > > specify "+ should concatenate two arrays" do > example do > [ 1, 2, 3 ] + [ 4, 5 ] > end.should == [1, 2, 3, 4, 5] > end > > How Rubininus creates the Arrays, sets them up in the symbol table/ > creates an object id, etc. - All of this, the spec will never touch. > How is one to do test first development on this sort of thing? If > the methods involved get too big, they will probably be refactored > into private methods. So how does one practice BDD on private > methods? Or should one just assume that they will work? > > These sorts of things are the things I was thinking about in my last > email. As I see it, spec'ing/testing is used for the following: > 1. Verification of Code Working the way you expect it to. This is > more fine grained, and better suited to Test::Unit, although the code > can easily break after refactoring. > 2. Documentation > 3. Test-First development. What small piece do I implement next? > (Think of the Rubinus/private methods example) > 4. Defining Behaviour, which of course, is simply high level > verification on exposed methods. > > > Thoughts on these matters? > > Scott > > > > > ------------------------------ > > Message: 2 > Date: Sat, 24 Mar 2007 07:19:20 -0500 > From: "David Chelimsky" > Subject: Re: [rspec-users] State Based vs. Behaviour Based > Spec/Testing > To: rspec-users > Message-ID: > <57c63afe0703240519q40ae8a62v34672b71874fc383 at mail.gmail.com> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed > > On 3/24/07, Scott Taylor wrote: >> I've notice that a project like Rubinius has both a spec & a test >> directory. Rspec has only a spec directory. Obviously I support >> BDD, but isn't there also a place for state based/verification >> testing? > > BDD is not a tool. BDD is a way of thinking about TDD. BDD *is* TDD, > with focus (not exclusivity) on behaviour. This is what I believe to > be the initial intent of TDD. This doesn't mean that all state testing > is bad. In fact, most of the expectations in rspec are state-based: > actual.should == value, etc. > > I think you're confusing Interaction testing with BDD. Interaction > testing is a very important part of BDD, but it is not the sole > purview of BDD. Mocks have been around for a long time. I can't really > think of anything that you can do with rspec that you can't do w/ > test/unit and mocha. RSpec just tries to make it easier to focus on > behaviour by using less "testy" words. > >> I sometimes sense that I *do* want to practice Test Driven >> Development. That is, I want some assurance that my production code >> will run as intended. But I also want some verification of a bug >> right after I have implemented it. > > Many people fix bugs using TDD. When the bug is reported, just start > by writing a failing test that exposes the bug. > > Keep in mind that when doing TDD, the nature of the tests change very > quickly. When you write the failing test, your goal is expose a > missing or incorrect behaviour, and use the resulting test to drive > your design. As soon as that test is passing, it changes in nature, > becoming both documentation and a regression test. > >> How can one truly get away from state based testing to some degree? > > You can't. At least not in my experience. > >> Spec's often seem too "high level" to assure the "testing" of the code. > > Again, this has to do w/ approach. You can write low level specs just > as you can write high-level tests. The trick is balance, keeping the > focus on behaviour rather than the internal structure of code. > >> I know that Test::Unit code will always be brittle. What happens >> when the code is refactored? It is sure to break. >> Does this suggest that Test::Unit code should be written right after >> development is done, covering the internals of the project? > > Again, this is a matter of approach, not tooling. Assuming that you > *must* test something internal, there's no reason that you can't do it > with rspec. But if you are testing internals, I'd reflect on that and > ask yourself why it is important to do so. Ask yourself how the > behaviour is going to be different if the internals change. I'll bet > that most (not all) of the time, you'll be able to find ways to > express your "testing" concerns in terms of behaviour. If you can do > that without having to get too far away from the code to do so, you're > better off because you'll have better documentation and less brittle > tests. > > We should really be talking about specific examples, because there are > some principles here that are either not being recognized or dying to > get out. Feel free to post some. > >> Maybe >> BDD specs should be written first, using TDD with Test::Unit for >> verification (as throw-away code)? Or do mock objects solve all of >> these problems? >> >> The real question is, do you spec'ers think there is any place for a >> testing framework next to a spec'ing framework? > > Heretical though this may seem: RSPEC IS A TESTING FRAMEWORK. There, I said it. > > Scott - I don't mean to pick on you here. In fact, I thank you for > posting this because a lot has been said during the early phases of > BDD's evolution that is confusing and obviously misleading. And, in > fact, much of this has been said by me as I've been exploring what the > meaning of BDD is ... to me. > > I hope that you'll keep posting questions like this as they can only > help us all to clarify things. > > Cheers, > David > >> Best, >> >> Scott Taylor >> >> >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > ------------------------------ > > Message: 3 > Date: Sat, 24 Mar 2007 08:08:57 -0500 > From: "David Chelimsky" > Subject: Re: [rspec-users] State Based vs. Behaviour Based > Spec/Testing > To: rspec-users > Message-ID: > <57c63afe0703240608m1021ac3dx52812572a014d82f at mail.gmail.com> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed > > On 3/24/07, David Chelimsky wrote: >> On 3/24/07, Scott Taylor wrote: >>> I've notice that a project like Rubinius has both a spec & a test >>> directory. Rspec has only a spec directory. Obviously I support >>> BDD, but isn't there also a place for state based/verification >>> testing? >> BDD is not a tool. BDD is a way of thinking about TDD. BDD *is* TDD, >> with focus (not exclusivity) on behaviour. This is what I believe to >> be the initial intent of TDD. This doesn't mean that all state testing >> is bad. In fact, most of the expectations in rspec are state-based: >> actual.should == value, etc. >> >> I think you're confusing Interaction testing with BDD. Interaction >> testing is a very important part of BDD, but it is not the sole >> purview of BDD. Mocks have been around for a long time. I can't really >> think of anything that you can do with rspec that you can't do w/ >> test/unit and mocha. RSpec just tries to make it easier to focus on >> behaviour by using less "testy" words. >> >>> I sometimes sense that I *do* want to practice Test Driven >>> Development. That is, I want some assurance that my production code >>> will run as intended. But I also want some verification of a bug >>> right after I have implemented it. >> Many people fix bugs using TDD. When the bug is reported, just start >> by writing a failing test that exposes the bug. >> >> Keep in mind that when doing TDD, the nature of the tests change very >> quickly. When you write the failing test, your goal is expose a >> missing or incorrect behaviour, and use the resulting test to drive >> your design. As soon as that test is passing, it changes in nature, >> becoming both documentation and a regression test. >> >>> How can one truly get away from state based testing to some degree? >> You can't. At least not in my experience. >> >>> Spec's often seem too "high level" to assure the "testing" of the code. >> Again, this has to do w/ approach. You can write low level specs just >> as you can write high-level tests. The trick is balance, keeping the >> focus on behaviour rather than the internal structure of code. >> >>> I know that Test::Unit code will always be brittle. What happens >>> when the code is refactored? It is sure to break. >>> Does this suggest that Test::Unit code should be written right after >>> development is done, covering the internals of the project? >> Again, this is a matter of approach, not tooling. Assuming that you >> *must* test something internal, there's no reason that you can't do it >> with rspec. But if you are testing internals, I'd reflect on that and >> ask yourself why it is important to do so. Ask yourself how the >> behaviour is going to be different if the internals change. I'll bet >> that most (not all) of the time, you'll be able to find ways to >> express your "testing" concerns in terms of behaviour. If you can do >> that without having to get too far away from the code to do so, you're >> better off because you'll have better documentation and less brittle >> tests. >> >> We should really be talking about specific examples, because there are >> some principles here that are either not being recognized or dying to >> get out. Feel free to post some. >> >>> Maybe >>> BDD specs should be written first, using TDD with Test::Unit for >>> verification (as throw-away code)? Or do mock objects solve all of >>> these problems? >>> >>> The real question is, do you spec'ers think there is any place for a >>> testing framework next to a spec'ing framework? >> Heretical though this may seem: RSPEC IS A TESTING FRAMEWORK. There, I said it. >> >> Scott - I don't mean to pick on you here. In fact, I thank you for >> posting this because a lot has been said during the early phases of >> BDD's evolution that is confusing and obviously misleading. And, in >> fact, much of this has been said by me as I've been exploring what the >> meaning of BDD is ... to me. >> >> I hope that you'll keep posting questions like this as they can only >> help us all to clarify things. > > I should also add that I'm talking about BDD as applied to isolation > testing (what many call unit testing :) ). BDD has really evolved into > an agile practice that comprises TDD, Acceptance Test Driven Planning > and other concepts that are geared towards increasing communication > and understanding within the context of a software project. If this is > new to you, check out http://dannorth.net/introducing-bdd/. > >> Cheers, >> David >> >>> Best, >>> >>> Scott Taylor >>> >>> >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> > > > ------------------------------ > > Message: 4 > Date: Sat, 24 Mar 2007 14:11:12 +0100 > From: "aslak hellesoy" > Subject: Re: [rspec-users] State Based vs. Behaviour Based > Spec/Testing > To: rspec-users > Message-ID: > <8d961d900703240611u3e79baa0w5c795d72dae5697e at mail.gmail.com> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed > > On 3/24/07, Scott Taylor wrote: >> I've notice that a project like Rubinius has both a spec & a test >> directory. Rspec has only a spec directory. Obviously I support >> BDD, but isn't there also a place for state based/verification > > Anyone is free to write their code who they want. RSpec doesn't > mandate any particular style, it just encourages it. > >> testing? I sometimes sense that I *do* want to practice Test Driven >> Development. > > Ok. BDD is just a kind of TDD with a stronger focus on "tell don't > ask", mocking and intent. > >> That is, I want some assurance that my production code >> will run as intended. But I also want some verification of a bug >> right after I have implemented it. >> >> How can one truly get away from state based testing to some degree? > > Use mocking to drive out interaction between objects. Strive for a > "tell don't ask" design (look it up). > >> Spec's often seem too "high level" to assure the "testing" of the code. >> > > What do you mean? > >> I know that Test::Unit code will always be brittle. What happens >> when the code is refactored? It is sure to break. >> > > Huh? What is it about Test::Unit that makes it inherently brittle? > I have no idea what you are talking about here. > >> Does this suggest that Test::Unit code should be written right after >> development is done, covering the internals of the project? > > If you're doing TDD, no - you write tests before the code. If you're > "just using Test::Unit" you can write it when you want. > >> Maybe >> BDD specs should be written first, using TDD with Test::Unit for > > BDD *is* TDD, with some extra philosophical baggage. You write specs > before the code in both BDD and TDD. > >> verification (as throw-away code)? Or do mock objects solve all of >> these problems? >> > > What problems? > >> The real question is, do you spec'ers think there is any place for a >> testing framework next to a spec'ing framework? >> > > To solve what problem? > > Aslak > >> Best, >> >> Scott Taylor >> >> >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > ------------------------------ > > Message: 5 > Date: Sat, 24 Mar 2007 09:32:06 -0400 > From: Michael Trier > Subject: Re: [rspec-users] spec'ing metaprograming & rails CRUD > To: rspec-users > Message-ID: > <6F1FD75F-2451-48A3-98AE-1F806963AE2F at eminentconsultinggroup.com> > Content-Type: text/plain; charset="us-ascii" > > > On Mar 24, 2007, at 5:11 AM, Scott Taylor wrote: > >> For edge rails there is a Crud generator. There is also a CRUD >> controller that is out there from which you can inherit your other >> controllers (see http://geekonomics.blogspot.com/2006/07/crud-and- >> shared-controllers.html) >> >> This got me thinking about Crud controllers in general. As far as I >> know, the generator can't produce crud classes which are nested >> (i.e. /posts/1/comments/7). So I thought about creating my own Crud >> class from which to inherit from, with some private methods, like so: >> >> class CrudController < ActiveRecord::Base >> class << self >> private >> def model >> # get a default name based on the controller name >> # or specify a name >> end >> >> def belongs_to >> # the model's "belongs_to"/foreign key relationship >> # this could also be found dynamically >> end >> end >> end >> >> class CommentsController < CrudController >> model :comments >> belongs_to :post >> end > > You might want to look into the resource_controller plugin: (http:// > svn.ardes.com/rails_plugins/resources_controller/ > > It does what you're describing in a very nice way and supports nested > as well as acts_as_tree situations. > > Michael > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070324/47027130/attachment.html > > ------------------------------ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > End of rspec-users Digest, Vol 9, Issue 16 > ****************************************** > > From gerardovr at gmail.com Sat Mar 24 13:45:49 2007 From: gerardovr at gmail.com (=?ISO-8859-1?Q?Gerardo_V=E1zquez?=) Date: Sat, 24 Mar 2007 18:45:49 +0100 Subject: [rspec-users] Testing Single Table Inheritance Message-ID: <460563CD.8070208@gmail.com> Hi all, I have just started using Rspec in rails and trying to test the following models: >>node.rb class Node < ActiveRecord::Base acts_as_tree end >>project.rb class Project < Node end >>task.rb class Task < Project end >>milestone.rb class Milestone < Node end Fixtures for table nodes is set global in spec_helper.rb, with the types set manually in the fixtures file. one: id: 1 type: Node name: Node1 .. etc, 2 fixtures for each class (8 in total) When i run the default test (check 2 records loaded from fixtures) it fails. It founds 8 nodes(Failed), 4 project(Failed), 2 task(OK) and 2 milestones(OK). From the rails test server: [4;35;1mSQL(0.000000)[0m[0mBEGIN[0m [4;36;1mNode Load(0.000000)[0m[0;1mSELECT * FROM nodes[0m [4;35;1mNode Columns(0.000000)[0m[0mSHOW FIELDS FROM nodes[0m [4;36;1mSQL (0.000000)[0m[0;1mROLLBACK[0m [4;35;1mSQL (0.000000)[0m[0mBEGIN[0m [4;36;1mProject Columns(0.000000)[0m[0;1mSHOW FIELDS FROM nodes[0m [4;35;1mProject Load(0.000000)[0m[0mSELECT * FROM nodes WHERE ((nodes.`type` = 'Project' OR nodes.`type` = 'Task'))[0m It does not specify type for node and adds "Task" type for project. Running the test with no fixtures set it does not add the "Task" type for project. [4;35;1mProject Columns(0.000000)[0m[0mSHOW FIELDS FROM nodes[0m [4;36;1mProject Load(0.000000)[0m[0;1mSELECT * FROM nodes WHERE ((nodes.`type` = 'Project'))[0m Here goes the _spec files: >>node_spec.rb require File.dirname(__FILE__) + '/../spec_helper' context "Given a generated node_spec.rb with fixtures loaded" do setup do @Nodes = Node.find(:all) end specify "fixtures should load 2 Nodes" do @Nodes.should have(2).records end end >>project_spec.rb require File.dirname(__FILE__) + '/../spec_helper' context "Given a generated project_spec.rb with fixtures loaded" do setup do @Projects = Project.find(:all) end specify "fixtures should load two Projects" do @Projects.should have(2).records end end Should I test all the class in node_spec? I suppose I`m missing something, any tip? Thanks in advance Gerardo From bruno.bornsztein at gmail.com Sat Mar 24 15:15:51 2007 From: bruno.bornsztein at gmail.com (Bruno Bornsztein) Date: Sat, 24 Mar 2007 14:15:51 -0500 Subject: [rspec-users] RSpec and namespaced controllers Message-ID: I'm running into a problem with RSpec/Rails and namespaced controllers. I've got a controller called 'TenantsController' in app/controllers and another called 'Admin::TenantsController' in app/controllers/admin In spec/controllers/, I have a tenants_controller_spec.rb. In spec/controllers/admin/ I have another tenants_controller_spec.rb. Both specs run correctly when I run them individually from ruby (ie ruby spec/controllers/admin/tenants_controller.rb), but the namespaced tenants_controller.rb (inside /admin) fails when I run the tests from rake. I think there's a collision between the two controller name, or else RSpec/Rails isn't parsing the second controller's name correctly. For reference, in /admin/tenants_controller_spec.rb, I'm setting the controller_name as: controller_name 'admin/tenants' Any thoughts on what might be going wrong? Thanks, Bruno Bornsztein www.missingmethod.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070324/e31bb651/attachment.html From dchelimsky at gmail.com Sat Mar 24 15:37:01 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 24 Mar 2007 14:37:01 -0500 Subject: [rspec-users] RSpec and namespaced controllers In-Reply-To: References: Message-ID: <57c63afe0703241237s1b556f93u24c566405421daab@mail.gmail.com> On 3/24/07, Bruno Bornsztein wrote: > I'm running into a problem with RSpec/Rails and namespaced controllers. > I've got a controller called 'TenantsController' in app/controllers > and another called 'Admin::TenantsController' in app/controllers/admin > > In spec/controllers/, I have a tenants_controller_spec.rb. In > spec/controllers/admin/ I have another tenants_controller_spec.rb. > Both specs run correctly when I run them individually from ruby (ie ruby > spec/controllers/admin/tenants_controller.rb), but the > namespaced tenants_controller.rb (inside /admin) fails when I run the tests > from rake. > > I think there's a collision between the two controller name, or else > RSpec/Rails isn't parsing the second controller's name correctly. > For reference, in /admin/tenants_controller_spec.rb, I'm > setting the controller_name as: > > controller_name 'admin/tenants' > > Any thoughts on what might be going wrong? Does this work in rails built-in testing? > Thanks, > Bruno Bornsztein > www.missingmethod.com > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Sun Mar 25 01:44:26 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sun, 25 Mar 2007 01:44:26 -0400 Subject: [rspec-users] State Based vs. Behaviour Based Spec/Testing In-Reply-To: <8d961d900703240611u3e79baa0w5c795d72dae5697e@mail.gmail.com> References: <3AB63458-C244-43C6-92F5-24061534B606@railsnewbie.com> <8d961d900703240611u3e79baa0w5c795d72dae5697e@mail.gmail.com> Message-ID: <6A48C69F-A1B5-4AF2-9336-7B91B329AC4F@railsnewbie.com> Sorry if this was rather incoherent. I guess the simplest questions that I have are these: 1. Should you test protected and private methods in your specs? 2. Should you ever test that a certain instance variable gets set in a method, or only that methods return their correct values? This question can be generalized to: Should you ever test/spec *parts* of a method? 3. If you already have a code base (with no specs/tests) is there any advantage over using Rspec to Test::Unit for verification testing? Some of these questions may be seemingly off topic from the original post, but I'm sure they are connected somehow subconsciously for me. I'd be interested in hearing your answers. Just another point to make: >>> I know that Test::Unit code will always be brittle. What happens >>> when the code is refactored? It is sure to break. >>> >> >> Huh? What is it about Test::Unit that makes it inherently brittle? >> I have no idea what you are talking about here. I was watching Dave Astel's Google Tech Talk, and one of the main problems he saw with testing was that classes had a one to one correspondence with tests, removing the ability to refactor. Best, Scott From pergesu at gmail.com Sun Mar 25 02:25:13 2007 From: pergesu at gmail.com (Pat Maddox) Date: Sun, 25 Mar 2007 00:25:13 -0600 Subject: [rspec-users] State Based vs. Behaviour Based Spec/Testing In-Reply-To: <6A48C69F-A1B5-4AF2-9336-7B91B329AC4F@railsnewbie.com> References: <3AB63458-C244-43C6-92F5-24061534B606@railsnewbie.com> <8d961d900703240611u3e79baa0w5c795d72dae5697e@mail.gmail.com> <6A48C69F-A1B5-4AF2-9336-7B91B329AC4F@railsnewbie.com> Message-ID: <810a540e0703242325l474e8fefx67cc7c4e20c89af6@mail.gmail.com> On 3/24/07, Scott Taylor wrote: > 1. Should you test protected and private methods in your specs? No. You're specifying the behavior of an object as seen by the outside world. Of course protected and private methods aren't available to the world, so why would you need to test them? When you're doing state-based testing, just call a method and then verify that it returns the expected value or leaves your object in an expected state. > 2. Should you ever test that a certain instance variable gets set in > a method, or only that methods return their correct values? This > question can be generalized to: Should you ever test/spec *parts* of > a method? Same thinking behind my answer to (1) applies here. > 3. If you already have a code base (with no specs/tests) is there > any advantage over using Rspec to Test::Unit for verification testing? Sure. my_object.foo.should == 3 vs assert_equal 3, my_object.foo my_object.should_not be_nil vs assert !my_object.nil? my_object.should have(2).errors vs assert_equal 2, my_object.errors.size Ultimately it comes down to personal preference. If you're doing things the right way, you're going to do basically the same thing in RSpec or Test::Unit, just with a different syntax. However if you're like me, RSpec makes it easier to do things the right way (or at least get close :) Pat From mailing_lists at railsnewbie.com Sun Mar 25 02:37:15 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sun, 25 Mar 2007 02:37:15 -0400 Subject: [rspec-users] State Based vs. Behaviour Based Spec/Testing In-Reply-To: <810a540e0703242325l474e8fefx67cc7c4e20c89af6@mail.gmail.com> References: <3AB63458-C244-43C6-92F5-24061534B606@railsnewbie.com> <8d961d900703240611u3e79baa0w5c795d72dae5697e@mail.gmail.com> <6A48C69F-A1B5-4AF2-9336-7B91B329AC4F@railsnewbie.com> <810a540e0703242325l474e8fefx67cc7c4e20c89af6@mail.gmail.com> Message-ID: <7DF22A00-FE3E-45E7-A0AF-C81DEDAA8CEA@railsnewbie.com> On Mar 25, 2007, at 2:25 AM, Pat Maddox wrote: > On 3/24/07, Scott Taylor wrote: >> 1. Should you test protected and private methods in your specs? > > No. You're specifying the behavior of an object as seen by the > outside world. Of course protected and private methods aren't > available to the world, so why would you need to test them? When > you're doing state-based testing, just call a method and then verify > that it returns the expected value or leaves your object in an > expected state. > How about if your writing code that is *only* meant to be reused? E.g., you are writing some class which is only meant to be derived from (ruby metaprogramming - Spec'ing rails would be a good example)? Best, Scott From pergesu at gmail.com Sun Mar 25 02:39:38 2007 From: pergesu at gmail.com (Pat Maddox) Date: Sun, 25 Mar 2007 00:39:38 -0600 Subject: [rspec-users] State Based vs. Behaviour Based Spec/Testing In-Reply-To: <3AB63458-C244-43C6-92F5-24061534B606@railsnewbie.com> References: <3AB63458-C244-43C6-92F5-24061534B606@railsnewbie.com> Message-ID: <810a540e0703242339n57334766m8e239a26a4ac2964@mail.gmail.com> I actually wrote something in our company wiki tonight that touches on this. I'm going to be lazy and just copy and paste it here (it's late). Anyway to summarize my thinking on the state-based vs interaction-based testing, it's... Some of your code's job is to tell a story some of your code's job is to get stuff done The first part is pretty easy. You just write your mock expecations and go. There's not a whole lot of state-based testing. The second part is more of a mix of the two, depending on what an object or method should do. When a method has to interact with other objects, obviously interaction-based testing is looking like a good option. If you're interested in a method's return value, or whether it changes the object's state, you have to do some state-based testing. Here's the wiki excerpt I wrote up. Hope you find it helpful. Pat =========================================== We should have good enough domain model code that our controllers tell an easy to read story. (PM: yes I'm aware I sorta suck at that). They really shouldn't have any business logic, that's all done in the models. The controller just coordinates it all and exposes data to the user. With that in mind, the vast majority of your controller specs should be behavioral expectations. We just want to know that the right method was called on the right object. Really the only state-based verification you'd do is to ensure that certain instance variables are correctly set for the view. I'll show an example for requesting /video_formats/1.xml, which is the XML representation of the VideoFormat with ID=1. We are interested in verifying three things: * The proper video format is selected from the db * We call that video format's #to_xml method * The result of #to_xml is rendered as the page output context "Requesting /video_formats/1.xml using GET" do controller_name :video_formats setup do @mock_format = mock("format") @mock_format.stub!(:to_xml).and_return "XML" VideoFormat.stub!(:find).and_return @mock_format end def do_get @request.env["HTTP_ACCEPT"] = "application/xml" get :show, :id => "1" end specify "should be successful" do do_get response.should_be_success end specify "should find the VideoFormat" do VideoFormat.should_receive(:find).with("1").and_return @mock_format do_get end specify "should render the format as XML" do @mock_format.should_receive(:to_xml).and_return "XML" do_get response.body.should_eql "XML" end end The specification clearly communicates what should happen when we request /video_formats/1.xml. In general I like to keep only one expectation per specification, but in the last one ("should render the format as XML") it makes sense to combine the two expectations since they're closely related. Now I'm going to show an example of a spec that is a good idea and an important spec, but probably in the wrong place. context "Requesting real /video_formats/1.xml using GET" do controller_name :video_formats setup do @format = VideoFormat.new @format.save VideoFormat.stub!(:find).and_return @format end def do_get @request.env["HTTP_ACCEPT"] = "application/xml" get :show, :id => "1" end specify "use real video format xml and make sure id is set" do response = do_get response.should_be_success data = response.body # check the feed to make sure the format id is in there, we need it for the databurst addAsset call h = Hash.from_xml data format = h['video_format'] assert format.has_key?('id') end end The problem with this spec is that it's not verifying the behavior of the VideoFormatsController#show action, but rather verifying the behavior of a VideoFormat object itself. Because we know from the previous spec that #show renders the VideoFormat's XML representation as a response, by finding the property in the XML we implicitly know that a VideoFormat renders its id attribute. A better approach would be to move this into the VideoFormat model spec. That way the knowledge of a VideoFormat's behavior is located in one place, and our controller specification can drop its dependence on the database and go back to simply telling the action's story. context "A saved VideoFormat in general" do setup do @format = VideoFormat.create end specify "should include the ID in its XML" do Hash.from_xml(@format.to_xml)["video_format"]["id"].should_not be_nil end end Now we've explicitly stated that a VideoFormat should include when it renders itself as XML. We can remove the second controller specification, because we've now verified that (a) /video_formats/1.xml calls the VideoFormat's #to_xml method, and (b) calling #to_xml on a VideoFormat includes the id property. From pergesu at gmail.com Sun Mar 25 02:40:58 2007 From: pergesu at gmail.com (Pat Maddox) Date: Sun, 25 Mar 2007 00:40:58 -0600 Subject: [rspec-users] State Based vs. Behaviour Based Spec/Testing In-Reply-To: <7DF22A00-FE3E-45E7-A0AF-C81DEDAA8CEA@railsnewbie.com> References: <3AB63458-C244-43C6-92F5-24061534B606@railsnewbie.com> <8d961d900703240611u3e79baa0w5c795d72dae5697e@mail.gmail.com> <6A48C69F-A1B5-4AF2-9336-7B91B329AC4F@railsnewbie.com> <810a540e0703242325l474e8fefx67cc7c4e20c89af6@mail.gmail.com> <7DF22A00-FE3E-45E7-A0AF-C81DEDAA8CEA@railsnewbie.com> Message-ID: <810a540e0703242340u243d0a8em8e7b65365f974003@mail.gmail.com> On 3/25/07, Scott Taylor wrote: > > On Mar 25, 2007, at 2:25 AM, Pat Maddox wrote: > > > On 3/24/07, Scott Taylor wrote: > >> 1. Should you test protected and private methods in your specs? > > > > No. You're specifying the behavior of an object as seen by the > > outside world. Of course protected and private methods aren't > > available to the world, so why would you need to test them? When > > you're doing state-based testing, just call a method and then verify > > that it returns the expected value or leaves your object in an > > expected state. > > > > > How about if your writing code that is *only* meant to be reused? > E.g., you are writing some class which is only meant to be derived > from (ruby metaprogramming - Spec'ing rails would be a good example)? > > Best, > > Scott > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > I'm not sure what you mean, to tell you the truth. Would you mind showing an example of some code that you want to spec but aren't sure how? Pat From mailing_lists at railsnewbie.com Sun Mar 25 03:08:04 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sun, 25 Mar 2007 03:08:04 -0400 Subject: [rspec-users] State Based vs. Behaviour Based Spec/Testing In-Reply-To: <810a540e0703242340u243d0a8em8e7b65365f974003@mail.gmail.com> References: <3AB63458-C244-43C6-92F5-24061534B606@railsnewbie.com> <8d961d900703240611u3e79baa0w5c795d72dae5697e@mail.gmail.com> <6A48C69F-A1B5-4AF2-9336-7B91B329AC4F@railsnewbie.com> <810a540e0703242325l474e8fefx67cc7c4e20c89af6@mail.gmail.com> <7DF22A00-FE3E-45E7-A0AF-C81DEDAA8CEA@railsnewbie.com> <810a540e0703242340u243d0a8em8e7b65365f974003@mail.gmail.com> Message-ID: <1F6D020A-110D-4008-983A-71BAB16E59E6@railsnewbie.com> On Mar 25, 2007, at 2:40 AM, Pat Maddox wrote: > On 3/25/07, Scott Taylor wrote: >> >> On Mar 25, 2007, at 2:25 AM, Pat Maddox wrote: >> >>> On 3/24/07, Scott Taylor wrote: >>>> 1. Should you test protected and private methods in your specs? >>> >>> No. You're specifying the behavior of an object as seen by the >>> outside world. Of course protected and private methods aren't >>> available to the world, so why would you need to test them? When >>> you're doing state-based testing, just call a method and then verify >>> that it returns the expected value or leaves your object in an >>> expected state. >>> >> >> >> How about if your writing code that is *only* meant to be reused? >> E.g., you are writing some class which is only meant to be derived >> from (ruby metaprogramming - Spec'ing rails would be a good example)? >> > > I'm not sure what you mean, to tell you the truth. Would you mind > showing an example of some code that you want to spec but aren't sure > how? I had in mind a rails generic crud controller. The basic gist of it is would be one class which had a series of private class methods. These methods could be called in any class which derived from this class, which would then set certain instance variables and instance methods for use in the class. A good example is a typical rails controller, or class: class Person < ActiveRecord::Base has_many :posts end If you say something like: @person = Person.find(:first_name => "Scott", :last_name => "Taylor) @person.posts The first line will find the first person in the database that matches "Scott Taylor." The second will find all posts associated with Scott Taylor. What do you think the ActiveRecord::Base class is going to look like? It's going to have a private class method named "has_many" which excepts a string or symbol as a parameter. This will then create an instance method in the derived class. In this example, that instance method would "posts". (For simplicity sake I've left out or changed some details of all the other things rails does). ActiveRecord::Base will never be used on its own, only as a class which is derived from. So how would ActiveRecord::Base be spec'ed out for this example? I haven't posted my code example because what I was trying to achieve was implemented by someone else already, and I decided to abandon the attempt. I've noticed that they have a spec directory in their project, so I'll have to check out how they've spec'ed out their class. Regards, Scott From pergesu at gmail.com Sun Mar 25 03:17:29 2007 From: pergesu at gmail.com (Pat Maddox) Date: Sun, 25 Mar 2007 01:17:29 -0600 Subject: [rspec-users] State Based vs. Behaviour Based Spec/Testing In-Reply-To: <1F6D020A-110D-4008-983A-71BAB16E59E6@railsnewbie.com> References: <3AB63458-C244-43C6-92F5-24061534B606@railsnewbie.com> <8d961d900703240611u3e79baa0w5c795d72dae5697e@mail.gmail.com> <6A48C69F-A1B5-4AF2-9336-7B91B329AC4F@railsnewbie.com> <810a540e0703242325l474e8fefx67cc7c4e20c89af6@mail.gmail.com> <7DF22A00-FE3E-45E7-A0AF-C81DEDAA8CEA@railsnewbie.com> <810a540e0703242340u243d0a8em8e7b65365f974003@mail.gmail.com> <1F6D020A-110D-4008-983A-71BAB16E59E6@railsnewbie.com> Message-ID: <810a540e0703250017m4208e4d7y95a2ec48fdb0bcef@mail.gmail.com> On 3/25/07, Scott Taylor wrote: > > On Mar 25, 2007, at 2:40 AM, Pat Maddox wrote: > > > On 3/25/07, Scott Taylor wrote: > >> > >> On Mar 25, 2007, at 2:25 AM, Pat Maddox wrote: > >> > >>> On 3/24/07, Scott Taylor wrote: > >>>> 1. Should you test protected and private methods in your specs? > >>> > >>> No. You're specifying the behavior of an object as seen by the > >>> outside world. Of course protected and private methods aren't > >>> available to the world, so why would you need to test them? When > >>> you're doing state-based testing, just call a method and then verify > >>> that it returns the expected value or leaves your object in an > >>> expected state. > >>> > >> > >> > >> How about if your writing code that is *only* meant to be reused? > >> E.g., you are writing some class which is only meant to be derived > >> from (ruby metaprogramming - Spec'ing rails would be a good example)? > >> > > > > I'm not sure what you mean, to tell you the truth. Would you mind > > showing an example of some code that you want to spec but aren't sure > > how? > > I had in mind a rails generic crud controller. The basic gist of it > is would be one class which had a series of private class methods. > These methods could be called in any class which derived from this > class, which would then set certain instance variables and instance > methods for use in the class. > > A good example is a typical rails controller, or class: > > class Person < ActiveRecord::Base > has_many :posts > end > > If you say something like: > > @person = Person.find(:first_name => "Scott", :last_name => "Taylor) > > @person.posts > > The first line will find the first person in the database that > matches "Scott Taylor." The second will find all posts associated > with Scott Taylor. > > What do you think the ActiveRecord::Base class is going to look > like? It's going to have a private class method named "has_many" > which excepts a string or symbol as a parameter. This will then > create an instance method in the derived class. In this example, > that instance method would "posts". (For simplicity sake I've left > out or changed some details of all the other things rails does). > > ActiveRecord::Base will never be used on its own, only as a class > which is derived from. > > So how would ActiveRecord::Base be spec'ed out for this example? I'm not sure how the Rails codebase is tested, but I think I'd do base = ActiveRecord::Base.new base.send :has_many, :posts and verify from there. I'm interested to see what David and Aslak think. Pat From aslak.hellesoy at gmail.com Sun Mar 25 06:06:19 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Sun, 25 Mar 2007 12:06:19 +0200 Subject: [rspec-users] State Based vs. Behaviour Based Spec/Testing In-Reply-To: <810a540e0703250017m4208e4d7y95a2ec48fdb0bcef@mail.gmail.com> References: <3AB63458-C244-43C6-92F5-24061534B606@railsnewbie.com> <8d961d900703240611u3e79baa0w5c795d72dae5697e@mail.gmail.com> <6A48C69F-A1B5-4AF2-9336-7B91B329AC4F@railsnewbie.com> <810a540e0703242325l474e8fefx67cc7c4e20c89af6@mail.gmail.com> <7DF22A00-FE3E-45E7-A0AF-C81DEDAA8CEA@railsnewbie.com> <810a540e0703242340u243d0a8em8e7b65365f974003@mail.gmail.com> <1F6D020A-110D-4008-983A-71BAB16E59E6@railsnewbie.com> <810a540e0703250017m4208e4d7y95a2ec48fdb0bcef@mail.gmail.com> Message-ID: <8d961d900703250306t251fb63aj84b0b54178933e8c@mail.gmail.com> On 3/25/07, Pat Maddox wrote: > On 3/25/07, Scott Taylor wrote: > > > > On Mar 25, 2007, at 2:40 AM, Pat Maddox wrote: > > > > > On 3/25/07, Scott Taylor wrote: > > >> > > >> On Mar 25, 2007, at 2:25 AM, Pat Maddox wrote: > > >> > > >>> On 3/24/07, Scott Taylor wrote: > > >>>> 1. Should you test protected and private methods in your specs? > > >>> > > >>> No. You're specifying the behavior of an object as seen by the > > >>> outside world. Of course protected and private methods aren't > > >>> available to the world, so why would you need to test them? When > > >>> you're doing state-based testing, just call a method and then verify > > >>> that it returns the expected value or leaves your object in an > > >>> expected state. > > >>> > > >> > > >> > > >> How about if your writing code that is *only* meant to be reused? > > >> E.g., you are writing some class which is only meant to be derived > > >> from (ruby metaprogramming - Spec'ing rails would be a good example)? > > >> > > > > > > I'm not sure what you mean, to tell you the truth. Would you mind > > > showing an example of some code that you want to spec but aren't sure > > > how? > > > > I had in mind a rails generic crud controller. The basic gist of it > > is would be one class which had a series of private class methods. > > These methods could be called in any class which derived from this > > class, which would then set certain instance variables and instance > > methods for use in the class. > > > > A good example is a typical rails controller, or class: > > > > class Person < ActiveRecord::Base > > has_many :posts > > end > > > > If you say something like: > > > > @person = Person.find(:first_name => "Scott", :last_name => "Taylor) > > > > @person.posts > > > > The first line will find the first person in the database that > > matches "Scott Taylor." The second will find all posts associated > > with Scott Taylor. > > > > What do you think the ActiveRecord::Base class is going to look > > like? It's going to have a private class method named "has_many" > > which excepts a string or symbol as a parameter. This will then > > create an instance method in the derived class. In this example, > > that instance method would "posts". (For simplicity sake I've left > > out or changed some details of all the other things rails does). > > > > ActiveRecord::Base will never be used on its own, only as a class > > which is derived from. > > > > So how would ActiveRecord::Base be spec'ed out for this example? > > I'm not sure how the Rails codebase is tested, but I think I'd do > > base = ActiveRecord::Base.new > base.send :has_many, :posts > > and verify from there. I'm interested to see what David and Aslak think. > The (controller) specs generated by the rspec_resource generator are good examples on how to test a controller. I would just use them as-is. Aslak > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From pergesu at gmail.com Sun Mar 25 06:18:45 2007 From: pergesu at gmail.com (Pat Maddox) Date: Sun, 25 Mar 2007 04:18:45 -0600 Subject: [rspec-users] State Based vs. Behaviour Based Spec/Testing In-Reply-To: <8d961d900703250306t251fb63aj84b0b54178933e8c@mail.gmail.com> References: <3AB63458-C244-43C6-92F5-24061534B606@railsnewbie.com> <8d961d900703240611u3e79baa0w5c795d72dae5697e@mail.gmail.com> <6A48C69F-A1B5-4AF2-9336-7B91B329AC4F@railsnewbie.com> <810a540e0703242325l474e8fefx67cc7c4e20c89af6@mail.gmail.com> <7DF22A00-FE3E-45E7-A0AF-C81DEDAA8CEA@railsnewbie.com> <810a540e0703242340u243d0a8em8e7b65365f974003@mail.gmail.com> <1F6D020A-110D-4008-983A-71BAB16E59E6@railsnewbie.com> <810a540e0703250017m4208e4d7y95a2ec48fdb0bcef@mail.gmail.com> <8d961d900703250306t251fb63aj84b0b54178933e8c@mail.gmail.com> Message-ID: <810a540e0703250318i10f01032k2d3497a992399e98@mail.gmail.com> On 3/25/07, aslak hellesoy wrote: > On 3/25/07, Pat Maddox wrote: > > On 3/25/07, Scott Taylor wrote: > > > > > > On Mar 25, 2007, at 2:40 AM, Pat Maddox wrote: > > > > > > > On 3/25/07, Scott Taylor wrote: > > > >> > > > >> On Mar 25, 2007, at 2:25 AM, Pat Maddox wrote: > > > >> > > > >>> On 3/24/07, Scott Taylor wrote: > > > >>>> 1. Should you test protected and private methods in your specs? > > > >>> > > > >>> No. You're specifying the behavior of an object as seen by the > > > >>> outside world. Of course protected and private methods aren't > > > >>> available to the world, so why would you need to test them? When > > > >>> you're doing state-based testing, just call a method and then verify > > > >>> that it returns the expected value or leaves your object in an > > > >>> expected state. > > > >>> > > > >> > > > >> > > > >> How about if your writing code that is *only* meant to be reused? > > > >> E.g., you are writing some class which is only meant to be derived > > > >> from (ruby metaprogramming - Spec'ing rails would be a good example)? > > > >> > > > > > > > > I'm not sure what you mean, to tell you the truth. Would you mind > > > > showing an example of some code that you want to spec but aren't sure > > > > how? > > > > > > I had in mind a rails generic crud controller. The basic gist of it > > > is would be one class which had a series of private class methods. > > > These methods could be called in any class which derived from this > > > class, which would then set certain instance variables and instance > > > methods for use in the class. > > > > > > A good example is a typical rails controller, or class: > > > > > > class Person < ActiveRecord::Base > > > has_many :posts > > > end > > > > > > If you say something like: > > > > > > @person = Person.find(:first_name => "Scott", :last_name => "Taylor) > > > > > > @person.posts > > > > > > The first line will find the first person in the database that > > > matches "Scott Taylor." The second will find all posts associated > > > with Scott Taylor. > > > > > > What do you think the ActiveRecord::Base class is going to look > > > like? It's going to have a private class method named "has_many" > > > which excepts a string or symbol as a parameter. This will then > > > create an instance method in the derived class. In this example, > > > that instance method would "posts". (For simplicity sake I've left > > > out or changed some details of all the other things rails does). > > > > > > ActiveRecord::Base will never be used on its own, only as a class > > > which is derived from. > > > > > > So how would ActiveRecord::Base be spec'ed out for this example? > > > > I'm not sure how the Rails codebase is tested, but I think I'd do > > > > base = ActiveRecord::Base.new > > base.send :has_many, :posts > > > > and verify from there. I'm interested to see what David and Aslak think. > > > > The (controller) specs generated by the rspec_resource generator are > good examples on how to test a controller. I would just use them > as-is. That's not what he means, if I understand correctly. Assume Rails doesn't exist, and you're building it from the ground up. How would you spec ActiveRecord::Base? At least that's what I thought the question is. Pat From dchelimsky at gmail.com Sun Mar 25 06:42:53 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 25 Mar 2007 05:42:53 -0500 Subject: [rspec-users] State Based vs. Behaviour Based Spec/Testing In-Reply-To: <810a540e0703250318i10f01032k2d3497a992399e98@mail.gmail.com> References: <3AB63458-C244-43C6-92F5-24061534B606@railsnewbie.com> <8d961d900703240611u3e79baa0w5c795d72dae5697e@mail.gmail.com> <6A48C69F-A1B5-4AF2-9336-7B91B329AC4F@railsnewbie.com> <810a540e0703242325l474e8fefx67cc7c4e20c89af6@mail.gmail.com> <7DF22A00-FE3E-45E7-A0AF-C81DEDAA8CEA@railsnewbie.com> <810a540e0703242340u243d0a8em8e7b65365f974003@mail.gmail.com> <1F6D020A-110D-4008-983A-71BAB16E59E6@railsnewbie.com> <810a540e0703250017m4208e4d7y95a2ec48fdb0bcef@mail.gmail.com> <8d961d900703250306t251fb63aj84b0b54178933e8c@mail.gmail.com> <810a540e0703250318i10f01032k2d3497a992399e98@mail.gmail.com> Message-ID: <57c63afe0703250342n571f5785ia81a183c59a7505b@mail.gmail.com> On 3/25/07, Pat Maddox wrote: > On 3/25/07, aslak hellesoy wrote: > > On 3/25/07, Pat Maddox wrote: > > > On 3/25/07, Scott Taylor wrote: > > > > >> How about if your writing code that is *only* meant to be reused? > > > > >> E.g., you are writing some class which is only meant to be derived > > > > >> from (ruby metaprogramming - Spec'ing rails would be a good example)? > > > > >> > > > > > > > > > > I'm not sure what you mean, to tell you the truth. Would you mind > > > > > showing an example of some code that you want to spec but aren't sure > > > > > how? > > > > > > > > I had in mind a rails generic crud controller. The basic gist of it > > > > is would be one class which had a series of private class methods. > > > > These methods could be called in any class which derived from this > > > > class, which would then set certain instance variables and instance > > > > methods for use in the class. > > > > > > > > A good example is a typical rails controller, or class: > > > > > > > > class Person < ActiveRecord::Base > > > > has_many :posts > > > > end > > > > > > > > If you say something like: > > > > > > > > @person = Person.find(:first_name => "Scott", :last_name => "Taylor) > > > > > > > > @person.posts > > > > > > > > The first line will find the first person in the database that > > > > matches "Scott Taylor." The second will find all posts associated > > > > with Scott Taylor. > > > > > > > > What do you think the ActiveRecord::Base class is going to look > > > > like? It's going to have a private class method named "has_many" > > > > which excepts a string or symbol as a parameter. This will then > > > > create an instance method in the derived class. In this example, > > > > that instance method would "posts". (For simplicity sake I've left > > > > out or changed some details of all the other things rails does). > > > > > > > > ActiveRecord::Base will never be used on its own, only as a class > > > > which is derived from. > > > > > > > > So how would ActiveRecord::Base be spec'ed out for this example? > > > > > > I'm not sure how the Rails codebase is tested, but I think I'd do > > > > > > base = ActiveRecord::Base.new > > > base.send :has_many, :posts > > > > > > and verify from there. I'm interested to see what David and Aslak think. > > > > > > > The (controller) specs generated by the rspec_resource generator are > > good examples on how to test a controller. I would just use them > > as-is. > > That's not what he means, if I understand correctly. > > Assume Rails doesn't exist, and you're building it from the ground up. > How would you spec ActiveRecord::Base? > > At least that's what I thought the question is. I think you're right. Typically I'd do something like this: describe FooSubclass do setup {@foo_sub = FooSubclass.new) it "should do bar" do ... end end class FooSubclass < Foo .. end To me, this is a little better than just describing the Foo class because the Foo class is never intended to be instantiated directly. If there are any interactions between the two (like initialization of the sub setting values in super, or super implementing #inherited(klass) ), they get well documented in the resulting descriptions. David From dchelimsky at gmail.com Sun Mar 25 06:59:12 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 25 Mar 2007 05:59:12 -0500 Subject: [rspec-users] State Based vs. Behaviour Based Spec/Testing In-Reply-To: <810a540e0703242325l474e8fefx67cc7c4e20c89af6@mail.gmail.com> References: <3AB63458-C244-43C6-92F5-24061534B606@railsnewbie.com> <8d961d900703240611u3e79baa0w5c795d72dae5697e@mail.gmail.com> <6A48C69F-A1B5-4AF2-9336-7B91B329AC4F@railsnewbie.com> <810a540e0703242325l474e8fefx67cc7c4e20c89af6@mail.gmail.com> Message-ID: <57c63afe0703250359h49e363et7fc073d12f8d057f@mail.gmail.com> On 3/25/07, Pat Maddox wrote: > On 3/24/07, Scott Taylor wrote: > > 1. Should you test protected and private methods in your specs? > > No. You're specifying the behavior of an object as seen by the > outside world. Of course protected and private methods aren't > available to the world, so why would you need to test them? When > you're doing state-based testing, just call a method and then verify > that it returns the expected value or leaves your object in an > expected state. +1. Well said. > > > 2. Should you ever test that a certain instance variable gets set in > > a method, or only that methods return their correct values? This > > question can be generalized to: Should you ever test/spec *parts* of > > a method? > > Same thinking behind my answer to (1) applies here. +1 again. > > > 3. If you already have a code base (with no specs/tests) is there > > any advantage over using Rspec to Test::Unit for verification testing? > > Sure. > > my_object.foo.should == 3 > vs > assert_equal 3, my_object.foo > > my_object.should_not be_nil > vs > assert !my_object.nil? > > my_object.should have(2).errors > vs > assert_equal 2, my_object.errors.size I think Scott's question was the reverse of what you're answering - I read "does Test::Unit hold any advantage over RSpec for post-code verification testing" Even when I'm doing TDD, once I'm convinced that I've satisfied the behavioural requirements (typically by passing Acceptance Tests), I'll review the tests from the perspective of documentation. Can another developer read these tests and understand how to use the objects being described? If not, I'll refactor the tests, which may mean adding new ones. Perhaps there's even a corner case that I haven't covered that I perceive covering would add some value. In this case, I'll often add a new test method to cover that, just for the documentation value. If it passes right away, I'll usually go into the code and tweak something to make it fail, and then tweak it back. This provides a sanity check that the test is actually interacting with the parts of the system it claims to, which is the main reason for starting with failing tests when you are in TDD mode. > > Ultimately it comes down to personal preference. If you're doing > things the right way, you're going to do basically the same thing in > RSpec or Test::Unit, just with a different syntax. However if you're > like me, RSpec makes it easier to do things the right way (or at least > get close :) I'm really glad to see that you're having that experience. This is the whole point of BDD. If you look at the things that Dave Astels and Dan North have written about since the earliest days of BDD, it is about making it easier to learn and then practice TDD as we believe it to be intended by evolving language and frameworks that focus on observable behaviour. Cheers, David > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From pergesu at gmail.com Sun Mar 25 07:34:42 2007 From: pergesu at gmail.com (Pat Maddox) Date: Sun, 25 Mar 2007 05:34:42 -0600 Subject: [rspec-users] State Based vs. Behaviour Based Spec/Testing In-Reply-To: <57c63afe0703250342n571f5785ia81a183c59a7505b@mail.gmail.com> References: <3AB63458-C244-43C6-92F5-24061534B606@railsnewbie.com> <6A48C69F-A1B5-4AF2-9336-7B91B329AC4F@railsnewbie.com> <810a540e0703242325l474e8fefx67cc7c4e20c89af6@mail.gmail.com> <7DF22A00-FE3E-45E7-A0AF-C81DEDAA8CEA@railsnewbie.com> <810a540e0703242340u243d0a8em8e7b65365f974003@mail.gmail.com> <1F6D020A-110D-4008-983A-71BAB16E59E6@railsnewbie.com> <810a540e0703250017m4208e4d7y95a2ec48fdb0bcef@mail.gmail.com> <8d961d900703250306t251fb63aj84b0b54178933e8c@mail.gmail.com> <810a540e0703250318i10f01032k2d3497a992399e98@mail.gmail.com> <57c63afe0703250342n571f5785ia81a183c59a7505b@mail.gmail.com> Message-ID: <810a540e0703250434i6a4fa876h45bd99dfe37bc256@mail.gmail.com> On 3/25/07, David Chelimsky wrote: > On 3/25/07, Pat Maddox wrote: > > On 3/25/07, aslak hellesoy wrote: > > > On 3/25/07, Pat Maddox wrote: > > > > On 3/25/07, Scott Taylor wrote: > > > > > >> How about if your writing code that is *only* meant to be reused? > > > > > >> E.g., you are writing some class which is only meant to be derived > > > > > >> from (ruby metaprogramming - Spec'ing rails would be a good example)? > > > > > >> > > > > > > > > > > > > I'm not sure what you mean, to tell you the truth. Would you mind > > > > > > showing an example of some code that you want to spec but aren't sure > > > > > > how? > > > > > > > > > > I had in mind a rails generic crud controller. The basic gist of it > > > > > is would be one class which had a series of private class methods. > > > > > These methods could be called in any class which derived from this > > > > > class, which would then set certain instance variables and instance > > > > > methods for use in the class. > > > > > > > > > > A good example is a typical rails controller, or class: > > > > > > > > > > class Person < ActiveRecord::Base > > > > > has_many :posts > > > > > end > > > > > > > > > > If you say something like: > > > > > > > > > > @person = Person.find(:first_name => "Scott", :last_name => "Taylor) > > > > > > > > > > @person.posts > > > > > > > > > > The first line will find the first person in the database that > > > > > matches "Scott Taylor." The second will find all posts associated > > > > > with Scott Taylor. > > > > > > > > > > What do you think the ActiveRecord::Base class is going to look > > > > > like? It's going to have a private class method named "has_many" > > > > > which excepts a string or symbol as a parameter. This will then > > > > > create an instance method in the derived class. In this example, > > > > > that instance method would "posts". (For simplicity sake I've left > > > > > out or changed some details of all the other things rails does). > > > > > > > > > > ActiveRecord::Base will never be used on its own, only as a class > > > > > which is derived from. > > > > > > > > > > So how would ActiveRecord::Base be spec'ed out for this example? > > > > > > > > I'm not sure how the Rails codebase is tested, but I think I'd do > > > > > > > > base = ActiveRecord::Base.new > > > > base.send :has_many, :posts > > > > > > > > and verify from there. I'm interested to see what David and Aslak think. > > > > > > > > > > The (controller) specs generated by the rspec_resource generator are > > > good examples on how to test a controller. I would just use them > > > as-is. > > > > That's not what he means, if I understand correctly. > > > > Assume Rails doesn't exist, and you're building it from the ground up. > > How would you spec ActiveRecord::Base? > > > > At least that's what I thought the question is. > > I think you're right. > > Typically I'd do something like this: > > describe FooSubclass do > setup {@foo_sub = FooSubclass.new) > it "should do bar" do > ... > end > end > > class FooSubclass < Foo > .. > end > > To me, this is a little better than just describing the Foo class > because the Foo class is never intended to be instantiated directly. > If there are any interactions between the two (like initialization of > the sub setting values in super, or super implementing > #inherited(klass) ), they get well documented in the resulting > descriptions. > > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > Yeah I was thinking that as well. I think it has the added benefit of clearly expressing the intent and usage of the class under test. It's only meant to be subclassed, and should be spec'ed that way. Pat From hussein at morsy.de Sun Mar 25 16:04:12 2007 From: hussein at morsy.de (Hussein Morsy) Date: Sun, 25 Mar 2007 22:04:12 +0200 Subject: [rspec-users] New Style: describe-it instead of context-specify Message-ID: Hello, in the tunk, i found a new style for spec: describe Foo do it "should do bar" do ... end end instead of context "Foo" context "should do bar" ... end end The Rails-Textmate-bundle in trunk use only the new "describe-it" style, What are the reasons for the new style ? Shall i use the new style from now on ? Hussein From aslak.hellesoy at gmail.com Sun Mar 25 16:46:42 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Sun, 25 Mar 2007 22:46:42 +0200 Subject: [rspec-users] New Style: describe-it instead of context-specify In-Reply-To: References: Message-ID: <8d961d900703251346s76512e57j43aad1ea3f729e08@mail.gmail.com> On 3/25/07, Hussein Morsy wrote: > Hello, > > in the tunk, i found a new style for spec: > > describe Foo do > it "should do bar" do > ... > end > end > > instead of > > context "Foo" > context "should do bar" > ... > end > end > > The Rails-Textmate-bundle in trunk use only the new "describe-it" > style, > > What are the reasons for the new style ? We believe it will lead spec writers to subconsciously write more behavioural specs. > Shall i use the new style from now on ? > Yes, but we will still support the old style for a good while. Aslak > > > Hussein > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From bhelmkamp at gmail.com Sun Mar 25 17:20:07 2007 From: bhelmkamp at gmail.com (Bryan Helmkamp) Date: Sun, 25 Mar 2007 17:20:07 -0400 Subject: [rspec-users] New Style: describe-it instead of context-specify In-Reply-To: <8d961d900703251346s76512e57j43aad1ea3f729e08@mail.gmail.com> References: <8d961d900703251346s76512e57j43aad1ea3f729e08@mail.gmail.com> Message-ID: I'm a bit uncomfortable with the new describe/it syntax, and I'm hoping someone can help me put aside my reservations... Basically, using the context/specify syntax, there is room to include additional information about the context of the set specs without duplicating it in each spec. For example, the context would be "An invalid credit card", and the specify blocks would be "should be reject by the payment processor", etc. In the describe/it syntax, it seems like I'd have to do: describe CreditCard it "should be rejected by the payment processor when invalid" it "should not be chargeable when invalid" it "should contain validation errors when invalid" end I'm concerned about the duplication of "when invalid" in the "it" blocks. I totally understand the argument of clarity over DRY in specs, but the new syntax seems like it requires spec writers to take this too far to the extreme. Does the describe syntax take an extra string param? That would provide a solution as follows: describe CreditCard, "when invalid" do ... end WDYT? -Bryan From dchelimsky at gmail.com Sun Mar 25 17:33:01 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 25 Mar 2007 16:33:01 -0500 Subject: [rspec-users] New Style: describe-it instead of context-specify In-Reply-To: References: <8d961d900703251346s76512e57j43aad1ea3f729e08@mail.gmail.com> Message-ID: <57c63afe0703251433g256f4850s5e71856fe13a2d03@mail.gmail.com> On 3/25/07, Bryan Helmkamp wrote: > I'm a bit uncomfortable with the new describe/it syntax, and I'm > hoping someone can help me put aside my reservations... > > Basically, using the context/specify syntax, there is room to include > additional information about the context of the set specs without > duplicating it in each spec. For example, the context would be "An > invalid credit card", and the specify blocks would be "should be > reject by the payment processor", etc. In the describe/it syntax, it > seems like I'd have to do: > > describe CreditCard > it "should be rejected by the payment processor when invalid" > it "should not be chargeable when invalid" > it "should contain validation errors when invalid" > end > > I'm concerned about the duplication of "when invalid" in the "it" > blocks. I totally understand the argument of clarity over DRY in > specs, but the new syntax seems like it requires spec writers to take > this too far to the extreme. > > Does the describe syntax take an extra string param? That would > provide a solution as follows: > > describe CreditCard, "when invalid" do YES!!!! It does. The signature now looks like this: def describe(type_or_description, additional_description=nil, &block) (actually, it still says "def context" and describe is an alias" in trunk - need to reverse that) This will be completely backwards compatible, and context/specify will live indefinitely as aliases to describe/it. David > ... > end > > WDYT? > > -Bryan > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From work at ashleymoran.me.uk Mon Mar 26 09:59:42 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Mon, 26 Mar 2007 14:59:42 +0100 Subject: [rspec-users] Failure creating model in spec setup not reported? Message-ID: Hi I've just tracked down a wierd error that AFAICT is caused by an error not being raised in the setup: context "An Asset" do setup do @provider = Provider.create(:name => "Provider1") @product = Product.new(:name => "Product1", :provider => @provider) @applicant = Applicant.new(:first_name => "Fred", :last_name => "Flinstone", :email => "fred at flinstone.com") @asset = Asset.new(:value => BigDecimal("250")) end specify "should have many quote parameters" do @asset.applicant = @applicant quote_parameters_1 = QuoteParameters.new(:term => 36, :applicant => @applicant, :product => @product) quote_parameters_2 = QuoteParameters.new(:term => 48, :applicant => @applicant, :product => @product) @asset.should respond_to(:quote_parameters) @asset.quote_parameters.should respond_to(:<<) @asset.quote_parameters << quote_parameters_1 @asset.quote_parameters << quote_parameters_2 @asset.save.should == true asset_reloaded = Asset.find(@asset.id) asset_reloaded.quote_parameters.map { |p| p.term }.sort.should == [ 36, 48 ] end end Regardless of whether this is a good way to spec the association or (probably) not, it fails on "@asset.save.should == true" with this error: should have many quote parameters PGError: ERROR: null value in column "provider_id" violates not-null constraint : INSERT INTO products ("name", "provider_id", "default_term", "maximum_resolicitation_period", "type", "gap_cover_type_id", "created_at") VALUES('Product1', NULL, NULL, NULL, NULL, NULL, '2007-03-26 14:42:29.872399') However the probably is actually caused by the first line of the setup, which is missing a mandatory parameter (using validations): @provider = Provider.create(:name => "Provider1", :external_identifier => "external-id") (I was using "new" but changed it to "create" to highlight the issue) Why would this not fail sooner? Thanks Ashley From aslak.hellesoy at gmail.com Mon Mar 26 10:48:22 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Mon, 26 Mar 2007 16:48:22 +0200 Subject: [rspec-users] Failure creating model in spec setup not reported? In-Reply-To: References: Message-ID: <8d961d900703260748o4f09e54dr780c7aae3afda836@mail.gmail.com> On 3/26/07, Ashley Moran wrote: > Hi > > I've just tracked down a wierd error that AFAICT is caused by an > error not being raised in the setup: > > context "An Asset" do > setup do > @provider = Provider.create(:name => "Provider1") > @product = Product.new(:name => "Product1", :provider => > @provider) > @applicant = Applicant.new(:first_name => "Fred", :last_name > => "Flinstone", :email => "fred at flinstone.com") > > @asset = Asset.new(:value => BigDecimal("250")) > end > > specify "should have many quote parameters" do > @asset.applicant = @applicant > > quote_parameters_1 = QuoteParameters.new(:term => > 36, :applicant => @applicant, :product => @product) > quote_parameters_2 = QuoteParameters.new(:term => > 48, :applicant => @applicant, :product => @product) > > @asset.should respond_to(:quote_parameters) > @asset.quote_parameters.should respond_to(:<<) > @asset.quote_parameters << quote_parameters_1 > @asset.quote_parameters << quote_parameters_2 > > @asset.save.should == true > > asset_reloaded = Asset.find(@asset.id) > asset_reloaded.quote_parameters.map { |p| > p.term }.sort.should == [ 36, 48 ] > end > end > > Regardless of whether this is a good way to spec the association or > (probably) not, it fails on "@asset.save.should == true" with this > error: > should have many quote parameters > PGError: ERROR: null value in column "provider_id" violates not-null > constraint > : INSERT INTO products ("name", "provider_id", "default_term", > "maximum_resolicitation_period", "type", "gap_cover_type_id", > "created_at") VALUES('Product1', NULL, NULL, NULL, NULL, NULL, > '2007-03-26 14:42:29.872399') > > > However the probably is actually caused by the first line of the > setup, which is missing a mandatory parameter (using validations): > > @provider = Provider.create(:name => > "Provider1", :external_identifier => "external-id") > > (I was using "new" but changed it to "create" to highlight the issue) > > Why would this not fail sooner? > Sounds like a Rails question. Can you (by running an equivalent Test::Unit test) confirm that this is really RSpec related and not Rails related? Aslak > > Thanks > Ashley > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From work at ashleymoran.me.uk Mon Mar 26 11:11:40 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Mon, 26 Mar 2007 16:11:40 +0100 Subject: [rspec-users] Failure creating model in spec setup not reported? In-Reply-To: <8d961d900703260748o4f09e54dr780c7aae3afda836@mail.gmail.com> References: <8d961d900703260748o4f09e54dr780c7aae3afda836@mail.gmail.com> Message-ID: <019C4E02-EAE4-49EA-BE74-6C5501A538B1@ashleymoran.me.uk> On 26 Mar 2007, at 15:48, aslak hellesoy wrote: > Sounds like a Rails question. > > Can you (by running an equivalent Test::Unit test) confirm that this > is really RSpec related and not Rails related? > > Aslak It's ok, me being an idiot. AR::Base.create fails silently. I'd need to use create! to see that error... sorry for the noise From mailing_lists at railsnewbie.com Tue Mar 27 03:54:10 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Tue, 27 Mar 2007 03:54:10 -0400 Subject: [rspec-users] REST rspec_generator Message-ID: <2E7AA9A8-94E1-4C6E-937E-9DF5F08B1EF3@railsnewbie.com> Is there some reason that the rspec resource generator produces code like this: context "Routes for the AnimalsController should map" do controller_name :animals specify "{ :controller => 'animals', :action => 'index' } to / animals" do route_for(:controller => "animals", :action => "index").should == "/animals" end ... end and not like this: describe "The AnimalsController" do it "should have an index route" do route_for(hash_for_animals_url).should == "/animals" end end Scott From david.smalley.lists at googlemail.com Tue Mar 27 05:12:15 2007 From: david.smalley.lists at googlemail.com (David Smalley) Date: Tue, 27 Mar 2007 10:12:15 +0100 Subject: [rspec-users] Stubbing out method for all instances Message-ID: I am using the acts_as_state_machine plugin to control state of an object in my app, however when testing this I need to be able to stub out the guard conditions so that state will change when I fire off an event without depending on other models. Guard conditions simply return true or false so I have an instance method: def encoded? return true or false end However I cannot find a way to stub out this method properly. Ideally I wish to do something that I expect I could do with Test::Unit mocks and just replace the encoded? instance method for all objects that might use it to just return true. Any ideas? David From mailing_lists at railsnewbie.com Tue Mar 27 05:21:34 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Tue, 27 Mar 2007 05:21:34 -0400 Subject: [rspec-users] sqlite3 and rspec_on_rails tests Message-ID: <89322292-DCBF-4589-B4BC-AFFE49E7596C@railsnewbie.com> As I think I previously mentioned, there is an incompatibility with rails 1.2.1 and sqlite3 3.3.8. see: http://weblog.rubyonrails.org/2007/1/29/using-sqlite3-with-rails and: http://weblog.rubyonrails.org/2007/2/6/rails-1-2-2-sqlite3-gems- singular-resources Sqlite is now at 3.3.13. Because of this, if a developer is trying to create a patch for rspec_on_rails, he will have one of the following two problems (if he is using sqlite): 1. the rails 1.2.1 specs will fail, if sqlite > 3.3.7 2. the rails 1.2.2 and greater will fail if sqlite is < 3.3.8. This renders running all of the specs as impossible with sqlite, doesn't it? Either way, there should be *something* in the docs about it. Let me know what you guys think. Scott From aslak.hellesoy at gmail.com Tue Mar 27 06:19:44 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 27 Mar 2007 12:19:44 +0200 Subject: [rspec-users] Stubbing out method for all instances In-Reply-To: References: Message-ID: <8d961d900703270319l3d1bb418k8d4aa4539a81725a@mail.gmail.com> On 3/27/07, David Smalley wrote: > I am using the acts_as_state_machine plugin to control state of an > object in my app, however when testing this I need to be able to stub > out the guard conditions so that state will change when I fire off an > event without depending on other models. > > Guard conditions simply return true or false so I have an instance > method: > > def encoded? > > return true or false > end > > However I cannot find a way to stub out this method properly. Ideally > I wish to do something that I expect I could do with Test::Unit mocks What's Test::Unit mocks? > and just replace the encoded? instance method for all objects that > might use it to just return true. > > Any ideas? > You can submit a feature request - ideally with a failing spec to illustrate what you want. > David > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From work at ashleymoran.me.uk Tue Mar 27 06:20:01 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Tue, 27 Mar 2007 11:20:01 +0100 Subject: [rspec-users] Aspects Message-ID: <6F0A54C5-B480-44D6-84EF-27EA050B0031@ashleymoran.me.uk> I've become very fond of Yurii Rashkovskii's "aspects". For such a simple change they make it a LOT easier to navigate, read and verify specs. Are there any plans to include something like this in RSpec? Ashley From aslak.hellesoy at gmail.com Tue Mar 27 06:21:22 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 27 Mar 2007 12:21:22 +0200 Subject: [rspec-users] sqlite3 and rspec_on_rails tests In-Reply-To: <89322292-DCBF-4589-B4BC-AFFE49E7596C@railsnewbie.com> References: <89322292-DCBF-4589-B4BC-AFFE49E7596C@railsnewbie.com> Message-ID: <8d961d900703270321h4025b226x8dda0f6c0f96b8d0@mail.gmail.com> On 3/27/07, Scott Taylor wrote: > > As I think I previously mentioned, there is an incompatibility with > rails 1.2.1 and sqlite3 3.3.8. > > see: http://weblog.rubyonrails.org/2007/1/29/using-sqlite3-with-rails > and: http://weblog.rubyonrails.org/2007/2/6/rails-1-2-2-sqlite3-gems- > singular-resources > > Sqlite is now at 3.3.13. > > Because of this, if a developer is trying to create a patch for > rspec_on_rails, he will have one of the following two problems (if he > is using sqlite): > > 1. the rails 1.2.1 specs will fail, if sqlite > 3.3.7 > 2. the rails 1.2.2 and greater will fail if sqlite is < 3.3.8. > > This renders running all of the specs as impossible with sqlite, > doesn't it? > Maybe it's time to retire RSpec's support for Rails pre 1.2.2? WDYT? > Either way, there should be *something* in the docs about it. Let > me know what you guys think. > > Scott > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Tue Mar 27 06:34:47 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Tue, 27 Mar 2007 06:34:47 -0400 Subject: [rspec-users] sqlite3 and rspec_on_rails tests In-Reply-To: <8d961d900703270321h4025b226x8dda0f6c0f96b8d0@mail.gmail.com> References: <89322292-DCBF-4589-B4BC-AFFE49E7596C@railsnewbie.com> <8d961d900703270321h4025b226x8dda0f6c0f96b8d0@mail.gmail.com> Message-ID: > > Maybe it's time to retire RSpec's support for Rails pre 1.2.2? > > WDYT? It doesn't sound crazy to me. I've been running edge rails for a while now, and 1.2.2 + are just bug fixes to 1.2.1...so, I'm in favour of it. Anyone with any strong opinions on the other end? Scott From david.smalley.lists at googlemail.com Tue Mar 27 06:34:55 2007 From: david.smalley.lists at googlemail.com (David Smalley) Date: Tue, 27 Mar 2007 11:34:55 +0100 Subject: [rspec-users] Stubbing out method for all instances In-Reply-To: <8d961d900703270319l3d1bb418k8d4aa4539a81725a@mail.gmail.com> References: <8d961d900703270319l3d1bb418k8d4aa4539a81725a@mail.gmail.com> Message-ID: <9B4445F1-CC72-4B23-A1C6-23E9880095DE@googlemail.com> On 27 Mar 2007, at 11:19, aslak hellesoy wrote: > > What's Test::Unit mocks? Ah sorry, by which I mean the /test/mocks//mocked_code.rb setup in a default Rails skeleton - it lets you drop a replacement for a method that appears higher up in the search path and allows you to completely over-ride a method. > >> and just replace the encoded? instance method for all objects that >> might use it to just return true. >> >> Any ideas? >> > > You can submit a feature request - ideally with a failing spec to > illustrate what you want. After a bit of digging around it looks like David (Chelimsky) has already submitted such a feature request https://rubyforge.org/tracker/index.php? func=detail&aid=6791&group_id=797&atid=3152 - looks a lot like what I want. Consider it similar to the syntax offered by mocha e.g. Order.any_instance.stubs(:shipped_on).returns(nil) I think it would be a very helpful addition to Rspec stub/mock framework - I'd be interested in helping to implement it but I fear I don't know enough about how mocking works. I'll dig into mocha and rspec code but if any of the Rspec developers want to take the lead that would be great! Cheers, David -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070327/9cb16f49/attachment-0001.html From dchelimsky at gmail.com Tue Mar 27 06:57:07 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 27 Mar 2007 06:57:07 -0400 Subject: [rspec-users] Aspects In-Reply-To: <6F0A54C5-B480-44D6-84EF-27EA050B0031@ashleymoran.me.uk> References: <6F0A54C5-B480-44D6-84EF-27EA050B0031@ashleymoran.me.uk> Message-ID: <57c63afe0703270357p25041695s28b257f7147281ca@mail.gmail.com> On 3/27/07, Ashley Moran wrote: > I've become very fond of Yurii Rashkovskii's "aspects". For such a > simple change they make it a LOT easier to navigate, read and verify > specs. Are there any plans to include something like this in RSpec? Something like this, yes. Exactly this, no. Search for "Aspects" in the tracker and you'll see some of the conversation. Whatever we come up w/ probably won't make it before 0.9.1. > > Ashley > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From aslak.hellesoy at gmail.com Tue Mar 27 07:55:13 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 27 Mar 2007 13:55:13 +0200 Subject: [rspec-users] Stubbing out method for all instances In-Reply-To: <9B4445F1-CC72-4B23-A1C6-23E9880095DE@googlemail.com> References: <8d961d900703270319l3d1bb418k8d4aa4539a81725a@mail.gmail.com> <9B4445F1-CC72-4B23-A1C6-23E9880095DE@googlemail.com> Message-ID: <8d961d900703270455j86badd6i6e3aff9e51955acb@mail.gmail.com> On 3/27/07, David Smalley wrote: > > > On 27 Mar 2007, at 11:19, aslak hellesoy wrote: > > > > > > What's Test::Unit mocks? > > Ah sorry, by which I mean the > /test/mocks//mocked_code.rb setup in a default > Rails skeleton - it lets you drop a replacement for a method that appears > higher up in the search path and allows you to completely over-ride a > method. > I see. Strictly speaking these are not mocks, but stubs. http://www.martinfowler.com/articles/mocksArentStubs.html Aslak > > > > > > and just replace the encoded? instance method for all objects that > > might use it to just return true. > > > > > Any ideas? > > > > > > > > You can submit a feature request - ideally with a failing spec to > > illustrate what you want. > After a bit of digging around it looks like David (Chelimsky) has already > submitted such a feature request > > https://rubyforge.org/tracker/index.php?func=detail&aid=6791&group_id=797&atid=3152 > - looks a lot like what I want. > > Consider it similar to the syntax offered by mocha > > e.g. > Order.any_instance.stubs(:shipped_on).returns(nil) > > I think it would be a very helpful addition to Rspec stub/mock framework - > I'd be interested in helping to implement it but I fear I don't know enough > about how mocking works. I'll dig into mocha and rspec code but if any of > the Rspec developers want to take the lead that would be great! > > Cheers, > > David > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Tue Mar 27 08:05:50 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Tue, 27 Mar 2007 08:05:50 -0400 Subject: [rspec-users] sqlite3 and rspec_on_rails tests In-Reply-To: References: <89322292-DCBF-4589-B4BC-AFFE49E7596C@railsnewbie.com> <8d961d900703270321h4025b226x8dda0f6c0f96b8d0@mail.gmail.com> Message-ID: On Mar 27, 2007, at 6:34 AM, Scott Taylor wrote: >> >> Maybe it's time to retire RSpec's support for Rails pre 1.2.2? >> >> WDYT? Is there much pre-1.2.2 code scattered around rspec? Scott From scotttaylor at bigfoot.com Tue Mar 27 09:55:06 2007 From: scotttaylor at bigfoot.com (Scott Taylor) Date: Tue, 27 Mar 2007 09:55:06 -0400 Subject: [rspec-users] mocking/stubbing newbie questions Message-ID: I'm new to mocking and stubbing. Can someone help me out with the following? I don't exactly know why this spec is failing: describe "GET /users/1/terms" do controller_name :terms setup do @user = mock_model(User) User.stub!(:find).and_return(@user) end def do_get get :index, :user_id => 1 end it "should find all terms associated with the user" do User.should_receive(:find).with("1") end end the controller code: class TermsController < ApplicationController def index User.find(1) end end the spec results: 1) Spec::Mocks::MockExpectationError in 'GET /users/1/terms should find all terms associated with the user' User expected :find with ("1") once, but received it 0 times ./spec/controllers/terms_controller_spec.rb:43: ./script/rails_spec_server:21:in `run' ./script/rails_spec_server:42: Thanks for any help in advance, Scott From t.lucas at toolmantim.com Tue Mar 27 10:01:51 2007 From: t.lucas at toolmantim.com (Tim Lucas) Date: Wed, 28 Mar 2007 00:01:51 +1000 Subject: [rspec-users] mocking/stubbing newbie questions In-Reply-To: References: Message-ID: <433E07F0-3441-4AF1-8010-C5DB582DCF45@toolmantim.com> On 27/03/2007, at 11:55 PM, Scott Taylor wrote: > it "should find all terms associated with the user" do > User.should_receive(:find).with("1") > end > end ... > Spec::Mocks::MockExpectationError in 'GET /users/1/terms should find > all terms associated with the user' > User expected :find with ("1") once, but received it 0 times > ./spec/controllers/terms_controller_spec.rb:43: you forgot to actually call your do_get method: it "should find all terms associated with the user" do User.should_receive(:find).with("1") do_get end -- tim From aslak.hellesoy at gmail.com Tue Mar 27 10:12:16 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 27 Mar 2007 16:12:16 +0200 Subject: [rspec-users] sqlite3 and rspec_on_rails tests In-Reply-To: References: <89322292-DCBF-4589-B4BC-AFFE49E7596C@railsnewbie.com> <8d961d900703270321h4025b226x8dda0f6c0f96b8d0@mail.gmail.com> Message-ID: <8d961d900703270712w60b088berb6c74110f92d6c0a@mail.gmail.com> On 3/27/07, Scott Taylor wrote: > > On Mar 27, 2007, at 6:34 AM, Scott Taylor wrote: > > >> > >> Maybe it's time to retire RSpec's support for Rails pre 1.2.2? > >> > >> WDYT? > > Is there much pre-1.2.2 code scattered around rspec? > Not much, but we run the spec suite for Spec::Rails against 1.1.6, 1.2.1, 1.2.2, 1.2.3 and edge. Aslak > Scott > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From znmeb at cesmail.net Tue Mar 27 10:04:05 2007 From: znmeb at cesmail.net (M. Edward (Ed) Borasky) Date: Tue, 27 Mar 2007 07:04:05 -0700 Subject: [rspec-users] sqlite3 and rspec_on_rails tests In-Reply-To: <8d961d900703270321h4025b226x8dda0f6c0f96b8d0@mail.gmail.com> References: <89322292-DCBF-4589-B4BC-AFFE49E7596C@railsnewbie.com> <8d961d900703270321h4025b226x8dda0f6c0f96b8d0@mail.gmail.com> Message-ID: <46092455.8000107@cesmail.net> aslak hellesoy wrote: > On 3/27/07, Scott Taylor wrote: > >> As I think I previously mentioned, there is an incompatibility with >> rails 1.2.1 and sqlite3 3.3.8. >> >> see: http://weblog.rubyonrails.org/2007/1/29/using-sqlite3-with-rails >> and: http://weblog.rubyonrails.org/2007/2/6/rails-1-2-2-sqlite3-gems- >> singular-resources >> >> Sqlite is now at 3.3.13. >> >> Because of this, if a developer is trying to create a patch for >> rspec_on_rails, he will have one of the following two problems (if he >> is using sqlite): >> >> 1. the rails 1.2.1 specs will fail, if sqlite > 3.3.7 >> 2. the rails 1.2.2 and greater will fail if sqlite is < 3.3.8. >> >> This renders running all of the specs as impossible with sqlite, >> doesn't it? >> >> > > Maybe it's time to retire RSpec's support for Rails pre 1.2.2? > > WDYT? > Well, in the case of commercial projects, there's usually strong pressure from the vendor to minimize vendor support costs by only supporting the latest general release version and only one older one. However, since their stuff costs money, a lot of customers will attempt to keep more ancient technology alive as long as possible. But in a "free" world, there hardly seems to be any reason to support versions older than general release. Maybe you'd want to support general release minus one. So my vote is to do what makes life easier for RSpec, and if that means support only 1.2.2, do it. Then again, I run testing systems anyhow -- I don't think I have much "general release" level code on my boxes. :) -- M. Edward (Ed) Borasky, FBG, AB, PTA, PGS, MS, MNLP, NST, ACMC(P) http://borasky-research.blogspot.com/ If God had meant for carrots to be eaten cooked, He would have given rabbits fire. From mlangenberg at gmail.com Tue Mar 27 14:00:24 2007 From: mlangenberg at gmail.com (Matthijs Langenberg) Date: Tue, 27 Mar 2007 20:00:24 +0200 Subject: [rspec-users] REST rspec_generator In-Reply-To: <2E7AA9A8-94E1-4C6E-937E-9DF5F08B1EF3@railsnewbie.com> References: <2E7AA9A8-94E1-4C6E-937E-9DF5F08B1EF3@railsnewbie.com> Message-ID: <27c0ac6d0703271100j274b2977y95820fd6c7d6f555@mail.gmail.com> I guess the resource generator isn't updated yet. On 3/27/07, Scott Taylor wrote: > > Is there some reason that the rspec resource generator produces code > like this: > > context "Routes for the AnimalsController should map" do > controller_name :animals > > specify "{ :controller => 'animals', :action => 'index' } to / > animals" do > route_for(:controller => "animals", :action => "index").should > == "/animals" > end > ... > end > > and not like this: > > describe "The AnimalsController" do > it "should have an index route" do > route_for(hash_for_animals_url).should == "/animals" > end > end > > Scott > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Tue Mar 27 15:24:03 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Tue, 27 Mar 2007 15:24:03 -0400 Subject: [rspec-users] mocking/stubbing newbie questions In-Reply-To: <433E07F0-3441-4AF1-8010-C5DB582DCF45@toolmantim.com> References: <433E07F0-3441-4AF1-8010-C5DB582DCF45@toolmantim.com> Message-ID: <7AF17BD9-D3A3-42C3-AA66-40C808D07011@railsnewbie.com> What a dumb move. I need to sleep more. Thanks for your help. Scott On Mar 27, 2007, at 10:01 AM, Tim Lucas wrote: > On 27/03/2007, at 11:55 PM, Scott Taylor wrote: > >> it "should find all terms associated with the user" do >> User.should_receive(:find).with("1") >> end >> end > > ... > >> Spec::Mocks::MockExpectationError in 'GET /users/1/terms should find >> all terms associated with the user' >> User expected :find with ("1") once, but received it 0 times >> ./spec/controllers/terms_controller_spec.rb:43: > > you forgot to actually call your do_get method: > > it "should find all terms associated with the user" do > User.should_receive(:find).with("1") > do_get > end > > -- tim > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From mailing_lists at railsnewbie.com Tue Mar 27 22:42:25 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Tue, 27 Mar 2007 22:42:25 -0400 Subject: [rspec-users] extracting common methods out of specs Message-ID: I have several specs which do more or less the same thing: describe "GET /users/1/terms" do controller_name :terms def do_get get :index, :user_id => 1 end it "should be successful" do controller.should_render :index do_get end ... end How could I extract this functionality from each spec? Scott From t.lucas at toolmantim.com Tue Mar 27 23:05:01 2007 From: t.lucas at toolmantim.com (Tim Lucas) Date: Wed, 28 Mar 2007 13:05:01 +1000 Subject: [rspec-users] extracting common methods out of specs In-Reply-To: References: Message-ID: <514A74F6-781C-4093-B248-29D4438C6462@toolmantim.com> On 28/03/2007, at 12:42 PM, Scott Taylor wrote: > > I have several specs which do more or less the same thing: > > describe "GET /users/1/terms" do > controller_name :terms > > def do_get > get :index, :user_id => 1 > end > > it "should be successful" do > controller.should_render :index > do_get > end > ... > end > > > How could I extract this functionality from each spec? but *should* you extract this functionality from each spec? Actions change in complexity so often, and so what might look common and repetitive now might end up differing quite significantly in a month's time. -- tim From mailing_lists at railsnewbie.com Tue Mar 27 23:44:06 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Tue, 27 Mar 2007 23:44:06 -0400 Subject: [rspec-users] respond.should be_successful Message-ID: <1F38305D-53C2-464C-A692-15EADD12208C@railsnewbie.com> I'm wondering: Does it make more sense to add on successful? as an alias for success? in ActionController:TestRequest? I keep getting these two mixed up in my specs and was wondering if it would be helpful to anyone as a small patch to rspec. Best, Scott From mailing_lists at railsnewbie.com Wed Mar 28 02:46:35 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Wed, 28 Mar 2007 02:46:35 -0400 Subject: [rspec-users] Autotest Message-ID: Is anyone using rspec with autotest? Scott From graeme.nelson at gmail.com Wed Mar 28 02:58:54 2007 From: graeme.nelson at gmail.com (Graeme Nelson) Date: Tue, 27 Mar 2007 23:58:54 -0700 Subject: [rspec-users] Autotest In-Reply-To: References: Message-ID: <699D1E13-30C7-4F8B-A905-62E8D9033A12@gmail.com> Hi Scott - I haven't used autotest with rspec, but a friend has... http://www.robbyonrails.com/articles/tag/autotest Thanks, graeme On Mar 27, 2007, at 11:46 PM, Scott Taylor wrote: > > Is anyone using rspec with autotest? > > Scott > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From aslak.hellesoy at gmail.com Wed Mar 28 03:04:18 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Wed, 28 Mar 2007 09:04:18 +0200 Subject: [rspec-users] respond.should be_successful In-Reply-To: <1F38305D-53C2-464C-A692-15EADD12208C@railsnewbie.com> References: <1F38305D-53C2-464C-A692-15EADD12208C@railsnewbie.com> Message-ID: <8d961d900703280004m25a728f8n5f3036cacb25a962@mail.gmail.com> On 3/28/07, Scott Taylor wrote: > > I'm wondering: Does it make more sense to add on successful? as an > alias for success? in ActionController:TestRequest? > > I keep getting these two mixed up in my specs and was wondering if it > would be helpful to anyone as a small patch to rspec. > Why don't you just alias successful yourself? I don't want to add this to RSpec. Aslak > Best, > > Scott > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Wed Mar 28 06:48:56 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 28 Mar 2007 06:48:56 -0400 Subject: [rspec-users] Autotest In-Reply-To: References: Message-ID: <57c63afe0703280348y476ecb2dr414edf7bb521369a@mail.gmail.com> On 3/28/07, Scott Taylor wrote: > > Is anyone using rspec with autotest? I've been using http://svn.caldersphere.net/svn/main/plugins/rspec_autotest with great success. > > Scott > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mtrier at eminentconsultinggroup.com Wed Mar 28 09:17:26 2007 From: mtrier at eminentconsultinggroup.com (Michael Trier) Date: Wed, 28 Mar 2007 09:17:26 -0400 Subject: [rspec-users] Autotest In-Reply-To: <57c63afe0703280348y476ecb2dr414edf7bb521369a@mail.gmail.com> References: <57c63afe0703280348y476ecb2dr414edf7bb521369a@mail.gmail.com> Message-ID: <2C305509-621E-4F3C-AD22-66CC10F3831D@eminentconsultinggroup.com> On Mar 28, 2007, at 6:48 AM, David Chelimsky wrote: > On 3/28/07, Scott Taylor wrote: >> >> Is anyone using rspec with autotest? > > I've been using > http://svn.caldersphere.net/svn/main/plugins/rspec_autotest with great > success. > Same here. Works well. The task will not show in your rake -T listing because of a missing desc line. Just add something like the following: desc "Autotest that works with RSpec" to the rake file in the tasks directory for the plugin. Michael railsconsulting.com From nick at ekenosen.net Wed Mar 28 13:40:06 2007 From: nick at ekenosen.net (nicholas a. evans) Date: Wed, 28 Mar 2007 13:40:06 -0400 Subject: [rspec-users] sqlite3 and rspec_on_rails tests In-Reply-To: <46092455.8000107@cesmail.net> References: <89322292-DCBF-4589-B4BC-AFFE49E7596C@railsnewbie.com> <8d961d900703270321h4025b226x8dda0f6c0f96b8d0@mail.gmail.com> <46092455.8000107@cesmail.net> Message-ID: <276ff9870703281040s4de74166jd809dcde8f843909@mail.gmail.com> On 3/27/07, M. Edward (Ed) Borasky wrote: > aslak hellesoy wrote: ... > > Maybe it's time to retire RSpec's support for Rails pre 1.2.2? > > > > WDYT? ... > But in a "free" world, there hardly seems to be any reason to support > versions older than general release. Maybe you'd want to support general > release minus one. Well, even in the free software world, although the costs of buying upgrades are mitigated, there are still issues of stability and QA, as well as changing APIs and environments. Notice how Ubuntu Dapper will be supported for up to 5 years, even though 10 more editions of Ubuntu will have been released by it's end of support (and most of them will only be supported for 18 months). Granted, having good test/spec coverage and a good quality process and developers who keep their code clean and keep abreast of current "best practices" should enable one to upgrade quickly... but it might still take some time. And there are the strategic concerns to worry about: when my company upgrades all of our apps to Rails 1.2, we *will* need to change some code that currently works in order to make it work under 1.2. This is not impossible, or even particularly difficult, but it will take a little bit of time (there is an opportunity cost), and it might not be wise to do right before a major release. (In fact, one of our apps just had a major release and won't have another for a little while, and I'm working on cleaning up the trunk to work under 1.2 right now.) All of that said... I think it would be best to claim support for only the latest release, one previous minor release, and one previous major release: currently 1.1.6, 1.2.2, and 1.2.3. But if the cost of supporting the older releases is too high, then I would understand if you dropped support for 1.1.6 in newer releases of Spec::Rails. My company will eventually catch up. -- Nick From jchris at mfdz.com Wed Mar 28 17:53:05 2007 From: jchris at mfdz.com (Chris Anderson) Date: Wed, 28 Mar 2007 14:53:05 -0700 Subject: [rspec-users] Autotest In-Reply-To: <2C305509-621E-4F3C-AD22-66CC10F3831D@eminentconsultinggroup.com> References: <57c63afe0703280348y476ecb2dr414edf7bb521369a@mail.gmail.com> <2C305509-621E-4F3C-AD22-66CC10F3831D@eminentconsultinggroup.com> Message-ID: I added this to my rakefile, to handle clearing out the test database / getting it up to date migrations in the dev. database. namespace :spec do task :server => 'db:test:prepare' do system('script/rails_spec_server') end end Autotest is the bomb. I blogged a shortcut that I didn't come up with myself. But it is certainly useful to be able to scope your autotest runs to a subset of your project. http://jchris.mfdz.com/code/2007/2/scope_autotest_by_filename Chris On 3/28/07, Michael Trier wrote: > > On Mar 28, 2007, at 6:48 AM, David Chelimsky wrote: > > > On 3/28/07, Scott Taylor wrote: > >> > >> Is anyone using rspec with autotest? > > > > I've been using > > http://svn.caldersphere.net/svn/main/plugins/rspec_autotest with great > > success. > > > > Same here. Works well. The task will not show in your rake -T > listing because of a missing desc line. Just add something like the > following: > > desc "Autotest that works with RSpec" > > to the rake file in the tasks directory for the plugin. > > Michael > railsconsulting.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Chris Anderson http://jchris.mfdz.com From mailing_lists at railsnewbie.com Wed Mar 28 15:45:03 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Wed, 28 Mar 2007 15:45:03 -0400 Subject: [rspec-users] respond.should be_successful In-Reply-To: <8d961d900703280004m25a728f8n5f3036cacb25a962@mail.gmail.com> References: <1F38305D-53C2-464C-A692-15EADD12208C@railsnewbie.com> <8d961d900703280004m25a728f8n5f3036cacb25a962@mail.gmail.com> Message-ID: Does be_a still work? This would make the spec more readable: request.should be_a_sucess Scott On Mar 28, 2007, at 3:04 AM, aslak hellesoy wrote: > On 3/28/07, Scott Taylor wrote: >> >> I'm wondering: Does it make more sense to add on successful? as an >> alias for success? in ActionController:TestRequest? >> >> I keep getting these two mixed up in my specs and was wondering if it >> would be helpful to anyone as a small patch to rspec. >> > > Why don't you just alias successful yourself? I don't want to add > this to RSpec. > > Aslak > >> Best, >> >> 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 mailing_lists at railsnewbie.com Wed Mar 28 20:50:27 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Wed, 28 Mar 2007 20:50:27 -0400 Subject: [rspec-users] respond.should be_successful In-Reply-To: References: <1F38305D-53C2-464C-A692-15EADD12208C@railsnewbie.com> <8d961d900703280004m25a728f8n5f3036cacb25a962@mail.gmail.com> Message-ID: <4C65F443-5C8B-4CC9-86D2-525420D08446@railsnewbie.com> Disregard the question. It does work. Scott On Mar 28, 2007, at 3:45 PM, Scott Taylor wrote: > > Does be_a still work? This would make the spec more readable: > > request.should be_a_sucess > > Scott > > > On Mar 28, 2007, at 3:04 AM, aslak hellesoy wrote: > >> On 3/28/07, Scott Taylor wrote: >>> >>> I'm wondering: Does it make more sense to add on successful? as an >>> alias for success? in ActionController:TestRequest? >>> >>> I keep getting these two mixed up in my specs and was wondering >>> if it >>> would be helpful to anyone as a small patch to rspec. >>> >> >> Why don't you just alias successful yourself? I don't want to add >> this to RSpec. >> >> Aslak >> >>> Best, >>> >>> 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 mailing_lists at railsnewbie.com Wed Mar 28 20:54:24 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Wed, 28 Mar 2007 20:54:24 -0400 Subject: [rspec-users] Autotest In-Reply-To: <2C305509-621E-4F3C-AD22-66CC10F3831D@eminentconsultinggroup.com> References: <57c63afe0703280348y476ecb2dr414edf7bb521369a@mail.gmail.com> <2C305509-621E-4F3C-AD22-66CC10F3831D@eminentconsultinggroup.com> Message-ID: <8213E026-2769-4D37-AF2F-9EA518724904@railsnewbie.com> What do you think about adding this code to rspec? Or does it more properly belong with autotest or as a plugin? I've noticed that it won't work with a) color and b) with a checked out rspec directory w/ rails. That means all of my describe it spec's won't work, and the spec's won't even run. I've patched part b) for my own use. Would this be helpful to anyone? Scott On Mar 28, 2007, at 9:17 AM, Michael Trier wrote: > > On Mar 28, 2007, at 6:48 AM, David Chelimsky wrote: > >> On 3/28/07, Scott Taylor wrote: >>> >>> Is anyone using rspec with autotest? >> >> I've been using >> http://svn.caldersphere.net/svn/main/plugins/rspec_autotest with >> great >> success. >> > > Same here. Works well. The task will not show in your rake -T > listing because of a missing desc line. Just add something like the > following: > > desc "Autotest that works with RSpec" > > to the rake file in the tasks directory for the plugin. > > Michael > railsconsulting.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From mtrier at eminentconsultinggroup.com Wed Mar 28 21:26:48 2007 From: mtrier at eminentconsultinggroup.com (Michael Trier) Date: Wed, 28 Mar 2007 21:26:48 -0400 Subject: [rspec-users] Autotest In-Reply-To: <8213E026-2769-4D37-AF2F-9EA518724904@railsnewbie.com> References: <57c63afe0703280348y476ecb2dr414edf7bb521369a@mail.gmail.com> <2C305509-621E-4F3C-AD22-66CC10F3831D@eminentconsultinggroup.com> <8213E026-2769-4D37-AF2F-9EA518724904@railsnewbie.com> Message-ID: On Mar 28, 2007, at 8:54 PM, Scott Taylor wrote: > > What do you think about adding this code to rspec? Or does it more > properly belong with autotest or as a plugin? > > I've noticed that it won't work with a) color and b) with a checked > out rspec directory w/ rails. That means all of my describe it > spec's won't work, and the spec's won't even run. > > I've patched part b) for my own use. Would this be helpful to anyone? I don't really follow you but if you want color just add: --colour to your spec.opts file. Michael railsconsulting.com From mailing_lists at railsnewbie.com Wed Mar 28 21:51:51 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Wed, 28 Mar 2007 21:51:51 -0400 Subject: [rspec-users] Autotest In-Reply-To: References: <57c63afe0703280348y476ecb2dr414edf7bb521369a@mail.gmail.com> <2C305509-621E-4F3C-AD22-66CC10F3831D@eminentconsultinggroup.com> <8213E026-2769-4D37-AF2F-9EA518724904@railsnewbie.com> Message-ID: <07A0E438-910E-4393-9778-3A7A2D779BAE@railsnewbie.com> On Mar 28, 2007, at 9:26 PM, Michael Trier wrote: > > On Mar 28, 2007, at 8:54 PM, Scott Taylor wrote: > >> >> What do you think about adding this code to rspec? Or does it more >> properly belong with autotest or as a plugin? >> >> I've noticed that it won't work with a) color and b) with a checked >> out rspec directory w/ rails. That means all of my describe it >> spec's won't work, and the spec's won't even run. >> >> I've patched part b) for my own use. Would this be helpful to >> anyone? > > I don't really follow you but if you want color just add: > > --colour > > to your spec.opts file. Does that work for you? I'm running rspec's trunk, so I have that checked out in vendor/rails. One of the new features in trunk, which isn't present in the 0.8.2 gem is using describe/it instead of context/specify. I don't think the rspec_autotest even reads the options files. Look at it's code: class RspecAutotest < Autotest attr_accessor :spec_command def initialize # :nodoc: @spec_command = "spec --diff unified" super @exceptions = %r%^\./(?:coverage|doc)% end .... end That means that unless you override the spec_command, it's not going to read from your spec.opts file. This is what I get when I try to run the rake task: euclid% rake spec:autotest (in /Users/smtlaissezfaire/Sites/rails/dictionary) spec --diff unified spec/models/definition_category_spec.rb spec/ helpers/terms_helper_spec.rb spec/models/definition_spec.rb spec/ models/user_term_spec.rb spec/models/user_spec.rb spec/controllers/ terms_controller_spec.rb spec/models/term_spec.rb spec/models/ category_spec.rb /Users/smtlaissezfaire/Sites/rails/dictionary/vendor/plugins/ rspec_on_rails/lib/spec/rails/version.rb:14: (RuntimeError) ######################################################################## #### Your RSpec on Rails plugin is incompatible with your installed RSpec. RSpec : 0.8.2 (r1560) RSpec on Rails : r1652 Make sure your RSpec on Rails plugin is compatible with your RSpec gem. See http://rspec.rubyforge.org/documentation/rails/install.html for details. ######################################################################## #### Notice that the command is "spec --diff ..." - without --options. That means the spec.opts isn't being used. The version of rspec_on_rails I have checked out is the trunk version. But the command is running against rspec gem which is older than trunk. This is what I meant when I said "the specs won't even run" Scott > > Michael > railsconsulting.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From joshknowles at gmail.com Wed Mar 28 22:15:59 2007 From: joshknowles at gmail.com (Josh Knowles) Date: Wed, 28 Mar 2007 19:15:59 -0700 Subject: [rspec-users] Autotest In-Reply-To: <07A0E438-910E-4393-9778-3A7A2D779BAE@railsnewbie.com> References: <57c63afe0703280348y476ecb2dr414edf7bb521369a@mail.gmail.com> <2C305509-621E-4F3C-AD22-66CC10F3831D@eminentconsultinggroup.com> <8213E026-2769-4D37-AF2F-9EA518724904@railsnewbie.com> <07A0E438-910E-4393-9778-3A7A2D779BAE@railsnewbie.com> Message-ID: On 3/28/07, Scott Taylor wrote: > I don't think the rspec_autotest even reads the options files. Look > at it's code: > > class RspecAutotest < Autotest > attr_accessor :spec_command > def initialize # :nodoc: > @spec_command = "spec --diff unified" > super > @exceptions = %r%^\./(?:coverage|doc)% > end > .... > end I replaced the default @spec_command with the following: @spec_command = "#{RAILS_ROOT}/vendor/plugins/rspec/bin/spec --diff unified --options #{RAILS_ROOT}/spec/spec.opts" This allows me to run edge-rspec as well as use the options defined in my spec.opts file. Josh -- Josh Knowles joshknowles at gmail.com http://joshknowles.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070328/854243dc/attachment.html From mailing_lists at railsnewbie.com Wed Mar 28 22:27:05 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Wed, 28 Mar 2007 22:27:05 -0400 Subject: [rspec-users] Autotest In-Reply-To: References: <57c63afe0703280348y476ecb2dr414edf7bb521369a@mail.gmail.com> <2C305509-621E-4F3C-AD22-66CC10F3831D@eminentconsultinggroup.com> <8213E026-2769-4D37-AF2F-9EA518724904@railsnewbie.com> <07A0E438-910E-4393-9778-3A7A2D779BAE@railsnewbie.com> Message-ID: On Mar 28, 2007, at 10:15 PM, Josh Knowles wrote: > > > On 3/28/07, Scott Taylor wrote: > I don't think the rspec_autotest even reads the options files. Look > at it's code: > > class RspecAutotest < Autotest > attr_accessor :spec_command > def initialize # :nodoc: > @spec_command = "spec --diff unified" > super > @exceptions = %r%^\./(?:coverage|doc)% > end > .... > end > > > I replaced the default @spec_command with the following: > > @spec_command = "#{RAILS_ROOT}/vendor/plugins/rspec/bin/spec --diff > unified --options #{RAILS_ROOT}/spec/spec.opts" > > This allows me to run edge-rspec as well as use the options defined > in my spec.opts file. > Yeah, I did something similar. If you use --color in spec.opts, does it work? Scott From mtrier at eminentconsultinggroup.com Wed Mar 28 22:34:23 2007 From: mtrier at eminentconsultinggroup.com (Michael Trier) Date: Wed, 28 Mar 2007 22:34:23 -0400 Subject: [rspec-users] Autotest In-Reply-To: <07A0E438-910E-4393-9778-3A7A2D779BAE@railsnewbie.com> References: <57c63afe0703280348y476ecb2dr414edf7bb521369a@mail.gmail.com> <2C305509-621E-4F3C-AD22-66CC10F3831D@eminentconsultinggroup.com> <8213E026-2769-4D37-AF2F-9EA518724904@railsnewbie.com> <07A0E438-910E-4393-9778-3A7A2D779BAE@railsnewbie.com> Message-ID: <420BA8F9-886F-4BBB-87B3-8660521D2DF9@eminentconsultinggroup.com> > > That means that unless you override the spec_command, it's not going > to read from your spec.opts file. > Ah, you're right. Sometimes I code in my sleep or at the very least quite inebriated. Sorry for the confusion. My spec line looks like this: spec --colour --diff unified I'm not running edge though. Michael railsconsulting.com From mailing_lists at railsnewbie.com Wed Mar 28 23:17:39 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Wed, 28 Mar 2007 23:17:39 -0400 Subject: [rspec-users] sqlite3 and rspec_on_rails tests In-Reply-To: <276ff9870703281040s4de74166jd809dcde8f843909@mail.gmail.com> References: <89322292-DCBF-4589-B4BC-AFFE49E7596C@railsnewbie.com> <8d961d900703270321h4025b226x8dda0f6c0f96b8d0@mail.gmail.com> <46092455.8000107@cesmail.net> <276ff9870703281040s4de74166jd809dcde8f843909@mail.gmail.com> Message-ID: Since this is really a problem with rails + sqlite, maybe we should make rspec's build depend on mysql and remove support for running the tests through sqlite ? Scott On Mar 28, 2007, at 1:40 PM, nicholas a. evans wrote: > On 3/27/07, M. Edward (Ed) Borasky wrote: >> aslak hellesoy wrote: > ... >>> Maybe it's time to retire RSpec's support for Rails pre 1.2.2? >>> >>> WDYT? > ... >> But in a "free" world, there hardly seems to be any reason to support >> versions older than general release. Maybe you'd want to support >> general >> release minus one. > > Well, even in the free software world, although the costs of buying > upgrades are mitigated, there are still issues of stability and QA, as > well as changing APIs and environments. Notice how Ubuntu Dapper will > be supported for up to 5 years, even though 10 more editions of Ubuntu > will have been released by it's end of support (and most of them will > only be supported for 18 months). > > Granted, having good test/spec coverage and a good quality process and > developers who keep their code clean and keep abreast of current "best > practices" should enable one to upgrade quickly... but it might still > take some time. And there are the strategic concerns to worry about: > when my company upgrades all of our apps to Rails 1.2, we *will* need > to change some code that currently works in order to make it work > under 1.2. This is not impossible, or even particularly difficult, > but it will take a little bit of time (there is an opportunity cost), > and it might not be wise to do right before a major release. (In > fact, one of our apps just had a major release and won't have another > for a little while, and I'm working on cleaning up the trunk to work > under 1.2 right now.) > > All of that said... I think it would be best to claim support for only > the latest release, one previous minor release, and one previous major > release: currently 1.1.6, 1.2.2, and 1.2.3. But if the cost of > supporting the older releases is too high, then I would understand if > you dropped support for 1.1.6 in newer releases of Spec::Rails. My > company will eventually catch up. > > -- > Nick > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From joshknowles at gmail.com Wed Mar 28 23:58:15 2007 From: joshknowles at gmail.com (Josh Knowles) Date: Wed, 28 Mar 2007 20:58:15 -0700 Subject: [rspec-users] Autotest In-Reply-To: References: <57c63afe0703280348y476ecb2dr414edf7bb521369a@mail.gmail.com> <2C305509-621E-4F3C-AD22-66CC10F3831D@eminentconsultinggroup.com> <8213E026-2769-4D37-AF2F-9EA518724904@railsnewbie.com> <07A0E438-910E-4393-9778-3A7A2D779BAE@railsnewbie.com> Message-ID: On 3/28/07, Scott Taylor wrote: > > > > Yeah, I did something similar. > > If you use --color in spec.opts, does it work? Yes -- Josh Knowles joshknowles at gmail.com http://joshknowles.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070328/786265a8/attachment.html From joshknowles at gmail.com Thu Mar 29 01:37:42 2007 From: joshknowles at gmail.com (Josh Knowles) Date: Wed, 28 Mar 2007 22:37:42 -0700 Subject: [rspec-users] sqlite3 and rspec_on_rails tests In-Reply-To: References: <89322292-DCBF-4589-B4BC-AFFE49E7596C@railsnewbie.com> <8d961d900703270321h4025b226x8dda0f6c0f96b8d0@mail.gmail.com> <46092455.8000107@cesmail.net> <276ff9870703281040s4de74166jd809dcde8f843909@mail.gmail.com> Message-ID: On 3/28/07, Scott Taylor wrote: > > > Since this is really a problem with rails + sqlite, maybe we should > make rspec's build depend on mysql and remove support for running the > tests through sqlite ? -1 SQLite is the only thing I bother to install on my development boxes these days. I shouldn't have to go install another database system to be able to contribute to the project. Setup a cruisecontrol box with all of the databases if you're worried about code being applied to trunk that isn't backwards compatible. Supporting 1.2.2 would be fine with me. -- Josh Knowles joshknowles at gmail.com http://joshknowles.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070328/f6d51c32/attachment.html From mailing_lists at railsnewbie.com Thu Mar 29 01:59:48 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Thu, 29 Mar 2007 01:59:48 -0400 Subject: [rspec-users] sqlite3 and rspec_on_rails tests In-Reply-To: References: <89322292-DCBF-4589-B4BC-AFFE49E7596C@railsnewbie.com> <8d961d900703270321h4025b226x8dda0f6c0f96b8d0@mail.gmail.com> <46092455.8000107@cesmail.net> <276ff9870703281040s4de74166jd809dcde8f843909@mail.gmail.com> Message-ID: <7CF413AF-C823-4A8C-9729-0E4A03150974@railsnewbie.com> On Mar 29, 2007, at 1:37 AM, Josh Knowles wrote: > > > On 3/28/07, Scott Taylor wrote: > Since this is really a problem with rails + sqlite, maybe we should > make rspec's build depend on mysql and remove support for running the > tests through sqlite ? > > > -1 > > SQLite is the only thing I bother to install on my development > boxes these days. I shouldn't have to go install another database > system to be able to contribute to the project. Setup a > cruisecontrol box with all of the databases if you're worried about > code being applied to trunk that isn't backwards compatible. > > Supporting 1.2.2 would be fine with me. Well, as it stands now you can't even use sqlite! So, something must be done, eventually. Maybe for now we should just add a note to the docs about this, and maybe when edge rails becomes a version release it will be time to drop support for rails < 1.2.2 Scott From mailing_lists at railsnewbie.com Thu Mar 29 03:28:04 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Thu, 29 Mar 2007 03:28:04 -0400 Subject: [rspec-users] Autotest In-Reply-To: References: <57c63afe0703280348y476ecb2dr414edf7bb521369a@mail.gmail.com> <2C305509-621E-4F3C-AD22-66CC10F3831D@eminentconsultinggroup.com> <8213E026-2769-4D37-AF2F-9EA518724904@railsnewbie.com> <07A0E438-910E-4393-9778-3A7A2D779BAE@railsnewbie.com> Message-ID: On Mar 28, 2007, at 11:58 PM, Josh Knowles wrote: > > > On 3/28/07, Scott Taylor wrote: > > Yeah, I did something similar. > > If you use --color in spec.opts, does it work? > > Yes > So what did you set the spec command to in the rake task? Scott From court3nay at gmail.com Thu Mar 29 04:18:27 2007 From: court3nay at gmail.com (Courtenay) Date: Thu, 29 Mar 2007 01:18:27 -0700 Subject: [rspec-users] a better "should have valid associations" Message-ID: <4b430c8f0703290118t49bf8c45vc8fcab2670108f97@mail.gmail.com> This is pretty much the same as last time around, if you recall. Thanks to Wilson for converting to the new form. I've added a few lines. Basically, it iterates over your model associations and does two things. - First, just try to call the association. Usually fixes speeling erors or other such silliness. - Second, try to find a record with an :include on the association. This actually hits the DB and will tell you if you have lingering associations on deleted models. Page.find(:first, :include => :user) (Note: I usually feel that testing associations is really testing the framework, and such code belongs in the framework itself. Also, this won't check if you removed some associations. And it won't check for polymorphs either.) Put this somewhere handy and require it into spec_helper. ======================================== module ActiveRecordMatchers class HaveValidAssociations def matches?(model) @failed_association = nil @model_class = model.class model.class.reflect_on_all_associations.each do |assoc| begin model.send(assoc.name, true) model.class.send('find', :first, :include => assoc.name) rescue ActiveRecord::EagerLoadPolymorphicError # nothing. Can't find :include a polymorph. This requires a better test. rescue => err @failed_association = "#{assoc.name} // #{err}" end end !@failed_association end def failure_message "invalid association \"#{@failed_association}\" on #{@model_class}" end end def have_valid_associations HaveValidAssociations.new end end ======================================== Put this in your model spec. context "A new Page" do include ActiveRecordMatchers specify "should have valid associations" do object = Page.new object.should have_valid_associations end end ======================================== court3nay http://blog.caboo.se From aslak.hellesoy at gmail.com Thu Mar 29 05:18:29 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Thu, 29 Mar 2007 11:18:29 +0200 Subject: [rspec-users] a better "should have valid associations" In-Reply-To: <4b430c8f0703290118t49bf8c45vc8fcab2670108f97@mail.gmail.com> References: <4b430c8f0703290118t49bf8c45vc8fcab2670108f97@mail.gmail.com> Message-ID: <8d961d900703290218h36c3a9f3rfc3db72daf8e8ce7@mail.gmail.com> I really like it. Good to see custom matchers for RSpec are being put to use too. Does anyone think it would be a good idea to add this to spec:rails? Aslak On 3/29/07, Courtenay wrote: > This is pretty much the same as last time around, if you recall. > > Thanks to Wilson for converting to the new form. I've added a few > lines. Basically, it iterates over your model associations and does > two things. > > - First, just try to call the association. Usually fixes speeling > erors or other such silliness. > > - Second, try to find a record with an :include on the association. > This actually hits the DB and will tell you if you have lingering > associations on deleted models. Page.find(:first, :include => :user) > > (Note: I usually feel that testing associations is really testing the > framework, and such code belongs in the framework itself. Also, this > won't check if you removed some associations. And it won't check for > polymorphs either.) > > Put this somewhere handy and require it into spec_helper. > > ======================================== > > module ActiveRecordMatchers > class HaveValidAssociations > def matches?(model) > @failed_association = nil > @model_class = model.class > > model.class.reflect_on_all_associations.each do |assoc| > begin > model.send(assoc.name, true) > model.class.send('find', :first, :include => assoc.name) > rescue ActiveRecord::EagerLoadPolymorphicError > # nothing. Can't find :include a polymorph. This requires a > better test. > rescue => err > @failed_association = "#{assoc.name} // #{err}" > end > end > !@failed_association > end > > def failure_message > "invalid association \"#{@failed_association}\" on #{@model_class}" > end > end > > def have_valid_associations > HaveValidAssociations.new > end > end > > ======================================== > > Put this in your model spec. > > context "A new Page" do > include ActiveRecordMatchers > > specify "should have valid associations" do > object = Page.new > object.should have_valid_associations > end > end > > ======================================== > > > court3nay > http://blog.caboo.se > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From work at ashleymoran.me.uk Thu Mar 29 05:38:29 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Thu, 29 Mar 2007 10:38:29 +0100 Subject: [rspec-users] a better "should have valid associations" In-Reply-To: <4b430c8f0703290118t49bf8c45vc8fcab2670108f97@mail.gmail.com> References: <4b430c8f0703290118t49bf8c45vc8fcab2670108f97@mail.gmail.com> Message-ID: <27D89235-9882-4C06-9ADB-15970FEDC57A@ashleymoran.me.uk> On 29 Mar 2007, at 09:18, Courtenay wrote: > Note: I usually feel that testing associations is really testing the > framework, and such code belongs in the framework itself. All the fancy details that load and save are part of the framework, but you still have to write has_whatever in your model class. My test-code ratio for models is 3.8:1, almost entirely due to copy-and- past coding to verify the associations. I'd love a really expressive way of testing associations like "Car.should have_many(:wheels)" or "Bull.should have_one(:udder)" or whatever. But looking at my own code it would be hard to factor out a one-size-fits-all expectation, especially through associations. Ashley From cdemyanovich at gmail.com Thu Mar 29 09:03:25 2007 From: cdemyanovich at gmail.com (Craig Demyanovich) Date: Thu, 29 Mar 2007 09:03:25 -0400 Subject: [rspec-users] a better "should have valid associations" In-Reply-To: <27D89235-9882-4C06-9ADB-15970FEDC57A@ashleymoran.me.uk> References: <4b430c8f0703290118t49bf8c45vc8fcab2670108f97@mail.gmail.com> <27D89235-9882-4C06-9ADB-15970FEDC57A@ashleymoran.me.uk> Message-ID: <5670D770-3160-42B6-AFCD-27B4404D15AF@gmail.com> On Mar 29, 2007, at 5:38 AM, Ashley Moran wrote: > > On 29 Mar 2007, at 09:18, Courtenay wrote: > >> Note: I usually feel that testing associations is really testing the >> framework, and such code belongs in the framework itself. > > All the fancy details that load and save are part of the framework, > but you still have to write has_whatever in your model class. My > test-code ratio for models is 3.8:1, almost entirely due to copy-and- > past coding to verify the associations. I'd love a really expressive > way of testing associations like "Car.should have_many(:wheels)" or > "Bull.should have_one(:udder)" or whatever. But looking at my own > code it would be hard to factor out a one-size-fits-all expectation, > especially through associations. Here's how I'm currently specifying my associations: context "All campaigns" do specify "may have many funds" do association = Campaign.reflect_on_association(:funds) association.macro.should == :has_many association.class_name.should == 'Fund' association.options.should == { :foreign_key => 'FK_Campaign' } end end context "All funds" do specify "may belong to a campaign" do association = Fund.reflect_on_association(:campaign) association.macro.should == :belongs_to association.class_name.should == 'Campaign' association.options.should == { :foreign_key => 'FK_Campaign' } end end Doing more than this feels like doing too much. However, I'm still a bit of a beginner when it comes to Rails. Am I specifying too little? Am I missing something? Regards, Craig From work at ashleymoran.me.uk Thu Mar 29 09:37:21 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Thu, 29 Mar 2007 14:37:21 +0100 Subject: [rspec-users] a better "should have valid associations" In-Reply-To: <5670D770-3160-42B6-AFCD-27B4404D15AF@gmail.com> References: <4b430c8f0703290118t49bf8c45vc8fcab2670108f97@mail.gmail.com> <27D89235-9882-4C06-9ADB-15970FEDC57A@ashleymoran.me.uk> <5670D770-3160-42B6-AFCD-27B4404D15AF@gmail.com> Message-ID: On 29 Mar 2007, at 14:03, Craig Demyanovich wrote: > Doing more than this feels like doing too much. However, I'm still a > bit of a beginner when it comes to Rails. Am I specifying too little? > Am I missing something? That's a lot more concise than my version! I'm sure there are people with more informed opinions, but to me your solution looks like it depends a lot on the Rails implementation, so the specs would be useless if you wanted to switch (or could switch) to Og, say. My specs look like this: context "A SiteVariable (associations)" do setup do # fixtures here, then make a variable... @variable = SiteVariable.new(:name => "variable") end specify "should belong to SiteVariableCategory" do @variable.site_variable_type = @type @variable.should respond_to(:site_variable_category) @variable.should respond_to(:site_variable_category=) @variable.site_variable_category = @category @variable.save! variable = SiteVariable.find(@variable.id) variable.site_variable_category.should == @category end specify "should have many SiteValues" do @variable.site_variable_category = @category @variable.site_variable_type = @type site_value_1 = SiteStringValue.new(:string_value => "value_1", :site => @site) site_value_2 = SiteStringValue.new(:string_value => "value_2", :site => @site) @variable.should respond_to(:site_values) @variable.site_values.should respond_to(:<<) @variable.site_values << site_value_1 @variable.site_values << site_value_2 @variable.save.should == true variable_reloaded = SiteVariable.find(@variable.id) variable_reloaded.site_values.sort { |a, b| a.string_value <=> b.string_value }.should == [ site_value_1, site_value_2 ] end end It's ugly and long winded, but it tests the actual behaviour. I'm sure somewhere between the two approaches there's an ideal solution. Ashley From bhelmkamp at gmail.com Thu Mar 29 10:22:42 2007 From: bhelmkamp at gmail.com (Bryan Helmkamp) Date: Thu, 29 Mar 2007 10:22:42 -0400 Subject: [rspec-users] a better "should have valid associations" In-Reply-To: <4b430c8f0703290118t49bf8c45vc8fcab2670108f97@mail.gmail.com> References: <4b430c8f0703290118t49bf8c45vc8fcab2670108f97@mail.gmail.com> Message-ID: On 3/29/07, Courtenay wrote: > Thanks to Wilson for converting to the new form. I've added a few > lines. Actually, I converted this to the matcher syntax. Wilson and I are using it on a project we are working on together. While have_valid_associations is useful as a safety net in places where you are otherwise uncovered, I now strongly prefer enumerating the associations that should exist in the spec. To do that, we use the following code: ========================================== class HaveAssociation def initialize(association_name) @association_name = association_name end def matches?(model) @model_class = model.class success = true model.send(@association_name.to_sym, true) rescue success = false success end def failure_message "invalid or nonexistent association \"#{@association_name}\" on #{@model_class}" end end def have_association(association_name) HaveAssociation.new(association_name) end ========================================== And then in the model spec (we include ActiveRecordMatchers in the context for all model specs): context "A car" do setup do @car = Car.new end specify "should have valid associations" do @car.should have_association(:owner) @car.should have_association(:insurance) end end Now we're covered in the case that an association is accidentally removed. The "should have valid associations" specification can get a big long and ugly on more complex classes, so we often use this syntax: context "A car" do setup do @car = Car.new end %w[owner insurance driver passengers engine].each do |assoc| specify "should have valid #{assoc} association" do @car.should have_association(assoc) end end This has the added bonus of producing much better specdoc: A car - should have valid owner association - should have valid insurance association - should have valid driver association - should have valid passengers association - should have valid engine association -Bryan From cdemyanovich at gmail.com Thu Mar 29 10:45:25 2007 From: cdemyanovich at gmail.com (Craig Demyanovich) Date: Thu, 29 Mar 2007 10:45:25 -0400 Subject: [rspec-users] a better "should have valid associations" In-Reply-To: References: <4b430c8f0703290118t49bf8c45vc8fcab2670108f97@mail.gmail.com> Message-ID: On Mar 29, 2007, at 10:22 AM, Bryan Helmkamp wrote: > On 3/29/07, Courtenay wrote: >> Thanks to Wilson for converting to the new form. I've added a few >> lines. > > Actually, I converted this to the matcher syntax. Wilson and I are > using it on a project we are working on together. > > While have_valid_associations is useful as a safety net in places > where you are otherwise uncovered, I now strongly prefer enumerating > the associations that should exist in the spec. To do that, we use the > following code: > > ========================================== > > class HaveAssociation > def initialize(association_name) > @association_name = association_name > end > > def matches?(model) > @model_class = model.class > success = true > model.send(@association_name.to_sym, true) rescue success = > false > success > end > > def failure_message > "invalid or nonexistent association \"#{@association_name}\" on > #{@model_class}" > end > end > > def have_association(association_name) > HaveAssociation.new(association_name) > end > > ========================================== > > And then in the model spec (we include ActiveRecordMatchers in the > context for all model specs): > > context "A car" do > setup do > @car = Car.new > end > > specify "should have valid associations" do > @car.should have_association(:owner) > @car.should have_association(:insurance) > end > end > > Now we're covered in the case that an association is accidentally > removed. The "should have valid associations" specification can get a > big long and ugly on more complex classes, so we often use this > syntax: > > context "A car" do > setup do > @car = Car.new > end > > %w[owner insurance driver passengers engine].each do |assoc| > specify "should have valid #{assoc} association" do > @car.should have_association(assoc) > end > end > > This has the added bonus of producing much better specdoc: > > A car > - should have valid owner association > - should have valid insurance association > - should have valid driver association > - should have valid passengers association > - should have valid engine association > > -Bryan Nice idea, Bryan. It doesn't go far enough for me, though: it verifies only the name of the association. I want to verify that I've specified the correct macro (e.g., :has_many instead of :has_one), class and foreign key. Part of why I want this is because I'm working with a legacy database that doesn't follow the Rails conventions at all. In addition, though, checking all of the association attributes increases my confidence that I'll notice if something about the association changes or if I make a mistake defining it, such as using :has_one instead of :has_many. For these reasons, I'm doing what I posted earlier in this thread. Thoughts? Craig From dchelimsky at gmail.com Thu Mar 29 11:05:00 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 29 Mar 2007 10:05:00 -0500 Subject: [rspec-users] a better "should have valid associations" In-Reply-To: References: <4b430c8f0703290118t49bf8c45vc8fcab2670108f97@mail.gmail.com> Message-ID: <57c63afe0703290805n44d830arb49b93215cf572ee@mail.gmail.com> On 3/29/07, Craig Demyanovich wrote: > On Mar 29, 2007, at 10:22 AM, Bryan Helmkamp wrote: > > > On 3/29/07, Courtenay wrote: > >> Thanks to Wilson for converting to the new form. I've added a few > >> lines. > > > > Actually, I converted this to the matcher syntax. Wilson and I are > > using it on a project we are working on together. > > > > While have_valid_associations is useful as a safety net in places > > where you are otherwise uncovered, I now strongly prefer enumerating > > the associations that should exist in the spec. To do that, we use the > > following code: > > > > ========================================== > > > > class HaveAssociation > > def initialize(association_name) > > @association_name = association_name > > end > > > > def matches?(model) > > @model_class = model.class > > success = true > > model.send(@association_name.to_sym, true) rescue success = > > false > > success > > end > > > > def failure_message > > "invalid or nonexistent association \"#{@association_name}\" on > > #{@model_class}" > > end > > end > > > > def have_association(association_name) > > HaveAssociation.new(association_name) > > end > > > > ========================================== > > > > And then in the model spec (we include ActiveRecordMatchers in the > > context for all model specs): > > > > context "A car" do > > setup do > > @car = Car.new > > end > > > > specify "should have valid associations" do > > @car.should have_association(:owner) > > @car.should have_association(:insurance) > > end > > end > > > > Now we're covered in the case that an association is accidentally > > removed. The "should have valid associations" specification can get a > > big long and ugly on more complex classes, so we often use this > > syntax: > > > > context "A car" do > > setup do > > @car = Car.new > > end > > > > %w[owner insurance driver passengers engine].each do |assoc| > > specify "should have valid #{assoc} association" do > > @car.should have_association(assoc) > > end > > end > > > > This has the added bonus of producing much better specdoc: > > > > A car > > - should have valid owner association > > - should have valid insurance association > > - should have valid driver association > > - should have valid passengers association > > - should have valid engine association > > > > -Bryan > > Nice idea, Bryan. It doesn't go far enough for me, though: it > verifies only the name of the association. I want to verify that I've > specified the correct macro (e.g., :has_many instead of :has_one), > class and foreign key. Part of why I want this is because I'm working > with a legacy database that doesn't follow the Rails conventions at > all. In addition, though, checking all of the association attributes > increases my confidence that I'll notice if something about the > association changes or if I make a mistake defining it, such as > using :has_one instead of :has_many. For these reasons, I'm doing > what I posted earlier in this thread. Thoughts? How about this? project.should belong_to(:manager) manager.should have_many(:projects) etc This would involve more matchers, but could be implemented in the same fashion as have_association is above. David > > Craig > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mlangenberg at gmail.com Thu Mar 29 11:09:58 2007 From: mlangenberg at gmail.com (Matthijs Langenberg) Date: Thu, 29 Mar 2007 17:09:58 +0200 Subject: [rspec-users] a better "should have valid associations" In-Reply-To: <57c63afe0703290805n44d830arb49b93215cf572ee@mail.gmail.com> References: <4b430c8f0703290118t49bf8c45vc8fcab2670108f97@mail.gmail.com> <57c63afe0703290805n44d830arb49b93215cf572ee@mail.gmail.com> Message-ID: <27c0ac6d0703290809y5cb71adeha130652a99da51c8@mail.gmail.com> Would that be possible to implement? Looks much cleaner then solutions I've been using in RSpec or Test::Unit. On 3/29/07, David Chelimsky wrote: > On 3/29/07, Craig Demyanovich wrote: > > On Mar 29, 2007, at 10:22 AM, Bryan Helmkamp wrote: > > > > > On 3/29/07, Courtenay wrote: > > >> Thanks to Wilson for converting to the new form. I've added a few > > >> lines. > > > > > > Actually, I converted this to the matcher syntax. Wilson and I are > > > using it on a project we are working on together. > > > > > > While have_valid_associations is useful as a safety net in places > > > where you are otherwise uncovered, I now strongly prefer enumerating > > > the associations that should exist in the spec. To do that, we use the > > > following code: > > > > > > ========================================== > > > > > > class HaveAssociation > > > def initialize(association_name) > > > @association_name = association_name > > > end > > > > > > def matches?(model) > > > @model_class = model.class > > > success = true > > > model.send(@association_name.to_sym, true) rescue success = > > > false > > > success > > > end > > > > > > def failure_message > > > "invalid or nonexistent association \"#{@association_name}\" on > > > #{@model_class}" > > > end > > > end > > > > > > def have_association(association_name) > > > HaveAssociation.new(association_name) > > > end > > > > > > ========================================== > > > > > > And then in the model spec (we include ActiveRecordMatchers in the > > > context for all model specs): > > > > > > context "A car" do > > > setup do > > > @car = Car.new > > > end > > > > > > specify "should have valid associations" do > > > @car.should have_association(:owner) > > > @car.should have_association(:insurance) > > > end > > > end > > > > > > Now we're covered in the case that an association is accidentally > > > removed. The "should have valid associations" specification can get a > > > big long and ugly on more complex classes, so we often use this > > > syntax: > > > > > > context "A car" do > > > setup do > > > @car = Car.new > > > end > > > > > > %w[owner insurance driver passengers engine].each do |assoc| > > > specify "should have valid #{assoc} association" do > > > @car.should have_association(assoc) > > > end > > > end > > > > > > This has the added bonus of producing much better specdoc: > > > > > > A car > > > - should have valid owner association > > > - should have valid insurance association > > > - should have valid driver association > > > - should have valid passengers association > > > - should have valid engine association > > > > > > -Bryan > > > > Nice idea, Bryan. It doesn't go far enough for me, though: it > > verifies only the name of the association. I want to verify that I've > > specified the correct macro (e.g., :has_many instead of :has_one), > > class and foreign key. Part of why I want this is because I'm working > > with a legacy database that doesn't follow the Rails conventions at > > all. In addition, though, checking all of the association attributes > > increases my confidence that I'll notice if something about the > > association changes or if I make a mistake defining it, such as > > using :has_one instead of :has_many. For these reasons, I'm doing > > what I posted earlier in this thread. Thoughts? > > How about this? > > project.should belong_to(:manager) > manager.should have_many(:projects) > > etc > > This would involve more matchers, but could be implemented in the same > fashion as have_association is above. > > David > > > > 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 joshknowles at gmail.com Thu Mar 29 11:28:53 2007 From: joshknowles at gmail.com (Josh Knowles) Date: Thu, 29 Mar 2007 08:28:53 -0700 Subject: [rspec-users] Autotest In-Reply-To: References: <57c63afe0703280348y476ecb2dr414edf7bb521369a@mail.gmail.com> <2C305509-621E-4F3C-AD22-66CC10F3831D@eminentconsultinggroup.com> <8213E026-2769-4D37-AF2F-9EA518724904@railsnewbie.com> <07A0E438-910E-4393-9778-3A7A2D779BAE@railsnewbie.com> Message-ID: On 3/29/07, Scott Taylor wrote: > > So what did you set the spec command to in the rake task? @spec_command = "#{RAILS_ROOT}/vendor/plugins/rspec/bin/spec --diff unified --options #{RAILS_ROOT}/spec/spec.opts" -- Josh Knowles joshknowles at gmail.com http://joshknowles.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070329/b181fc42/attachment.html From cdemyanovich at gmail.com Thu Mar 29 11:30:59 2007 From: cdemyanovich at gmail.com (Craig Demyanovich) Date: Thu, 29 Mar 2007 11:30:59 -0400 Subject: [rspec-users] a better "should have valid associations" In-Reply-To: <57c63afe0703290805n44d830arb49b93215cf572ee@mail.gmail.com> References: <4b430c8f0703290118t49bf8c45vc8fcab2670108f97@mail.gmail.com> <57c63afe0703290805n44d830arb49b93215cf572ee@mail.gmail.com> Message-ID: <6C6C89FA-B7D9-4650-B82B-FD839ADE965B@gmail.com> On Mar 29, 2007, at 11:05 AM, David Chelimsky wrote: > On 3/29/07, Craig Demyanovich wrote: >> On Mar 29, 2007, at 10:22 AM, Bryan Helmkamp wrote: >> >>> On 3/29/07, Courtenay wrote: >>>> Thanks to Wilson for converting to the new form. I've added a few >>>> lines. >>> >>> Actually, I converted this to the matcher syntax. Wilson and I are >>> using it on a project we are working on together. >>> >>> While have_valid_associations is useful as a safety net in places >>> where you are otherwise uncovered, I now strongly prefer enumerating >>> the associations that should exist in the spec. To do that, we >>> use the >>> following code: >>> >>> ========================================== >>> >>> class HaveAssociation >>> def initialize(association_name) >>> @association_name = association_name >>> end >>> >>> def matches?(model) >>> @model_class = model.class >>> success = true >>> model.send(@association_name.to_sym, true) rescue success = >>> false >>> success >>> end >>> >>> def failure_message >>> "invalid or nonexistent association \"#{@association_name} >>> \" on >>> #{@model_class}" >>> end >>> end >>> >>> def have_association(association_name) >>> HaveAssociation.new(association_name) >>> end >>> >>> ========================================== >>> >>> And then in the model spec (we include ActiveRecordMatchers in the >>> context for all model specs): >>> >>> context "A car" do >>> setup do >>> @car = Car.new >>> end >>> >>> specify "should have valid associations" do >>> @car.should have_association(:owner) >>> @car.should have_association(:insurance) >>> end >>> end >>> >>> Now we're covered in the case that an association is accidentally >>> removed. The "should have valid associations" specification can >>> get a >>> big long and ugly on more complex classes, so we often use this >>> syntax: >>> >>> context "A car" do >>> setup do >>> @car = Car.new >>> end >>> >>> %w[owner insurance driver passengers engine].each do |assoc| >>> specify "should have valid #{assoc} association" do >>> @car.should have_association(assoc) >>> end >>> end >>> >>> This has the added bonus of producing much better specdoc: >>> >>> A car >>> - should have valid owner association >>> - should have valid insurance association >>> - should have valid driver association >>> - should have valid passengers association >>> - should have valid engine association >>> >>> -Bryan >> >> Nice idea, Bryan. It doesn't go far enough for me, though: it >> verifies only the name of the association. I want to verify that I've >> specified the correct macro (e.g., :has_many instead of :has_one), >> class and foreign key. Part of why I want this is because I'm working >> with a legacy database that doesn't follow the Rails conventions at >> all. In addition, though, checking all of the association attributes >> increases my confidence that I'll notice if something about the >> association changes or if I make a mistake defining it, such as >> using :has_one instead of :has_many. For these reasons, I'm doing >> what I posted earlier in this thread. Thoughts? > > How about this? > > project.should belong_to(:manager) > manager.should have_many(:projects) > > etc > > This would involve more matchers, but could be implemented in the same > fashion as have_association is above. That looks pretty good, David. In fact, it's probably just right for apps that use a database that follows the Rails conventions. However, does anyone have any ideas for how we could specify the class and foreign key? I feel that I need to specify those as well since my database is quite unconventional according to Rails. Change may be in its future, but it's not safe just yet. Thanks, Craig From joshknowles at gmail.com Thu Mar 29 11:35:12 2007 From: joshknowles at gmail.com (Josh Knowles) Date: Thu, 29 Mar 2007 08:35:12 -0700 Subject: [rspec-users] a better "should have valid associations" In-Reply-To: <57c63afe0703290805n44d830arb49b93215cf572ee@mail.gmail.com> References: <4b430c8f0703290118t49bf8c45vc8fcab2670108f97@mail.gmail.com> <57c63afe0703290805n44d830arb49b93215cf572ee@mail.gmail.com> Message-ID: On 3/29/07, David Chelimsky wrote: > > > > How about this? > > project.should belong_to(:manager) > manager.should have_many(:projects) > > etc > > This would involve more matchers, but could be implemented in the same > fashion as have_association is above. I've implenented the first pass at the following rails matchers: should belong_to(association) should have_many(association) should validate_confirmation_of(attribute) should validate_format_of(attribute, valid => [], invalid => []) should validate_lendth_of(attribute, range) should validate_presence_of(attribute) should validate_uniqueness_of(attribute) Plugin available here: http://svn.integrumtech.com/public/plugins/rspec_on_rails_matchers/ I haven't had a chance to get the README done, or any rdoc, but there are specs for the majority of the matchers. Comments / Suggestions Welcome! Josh -- Josh Knowles joshknowles at gmail.com http://joshknowles.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070329/3da6ea13/attachment.html From dchelimsky at gmail.com Thu Mar 29 11:44:58 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 29 Mar 2007 10:44:58 -0500 Subject: [rspec-users] a better "should have valid associations" In-Reply-To: References: <4b430c8f0703290118t49bf8c45vc8fcab2670108f97@mail.gmail.com> <57c63afe0703290805n44d830arb49b93215cf572ee@mail.gmail.com> Message-ID: <57c63afe0703290844m20421d03q8e54ef0a4810c5e3@mail.gmail.com> On 3/29/07, Josh Knowles wrote: > > > On 3/29/07, David Chelimsky wrote: > > > > > > How about this? > > > > project.should belong_to(:manager) > > manager.should have_many(:projects) > > > > etc > > > > This would involve more matchers, but could be implemented in the same > > fashion as have_association is above. > > > I've implenented the first pass at the following rails matchers: > > should belong_to(association) > should have_many(association) > should validate_confirmation_of(attribute) > should validate_format_of(attribute, valid => [], invalid => []) > should validate_lendth_of(attribute, range) > should validate_presence_of(attribute) > should validate_uniqueness_of(attribute) > > Plugin available here: > http://svn.integrumtech.com/public/plugins/rspec_on_rails_matchers/ > > I haven't had a chance to get the README done, or any rdoc, but there are > specs for the majority of the matchers. > > Comments / Suggestions Welcome! AWESOME! I'm so psyched to see a plugin emerging for this. Looks like have_many and belong_to don't really specify the specific type of association, so you could get false positives. Also, it probably needs a have_one and have_and_belong_to_many matchers is well to round it out, no? Cheers, David > > Josh > > > > > -- > Josh Knowles > joshknowles at gmail.com > http://joshknowles.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From joshknowles at gmail.com Thu Mar 29 11:49:26 2007 From: joshknowles at gmail.com (Josh Knowles) Date: Thu, 29 Mar 2007 08:49:26 -0700 Subject: [rspec-users] a better "should have valid associations" In-Reply-To: <57c63afe0703290844m20421d03q8e54ef0a4810c5e3@mail.gmail.com> References: <4b430c8f0703290118t49bf8c45vc8fcab2670108f97@mail.gmail.com> <57c63afe0703290805n44d830arb49b93215cf572ee@mail.gmail.com> <57c63afe0703290844m20421d03q8e54ef0a4810c5e3@mail.gmail.com> Message-ID: On 3/29/07, David Chelimsky wrote: > AWESOME! I'm so psyched to see a plugin emerging for this. > > Looks like have_many and belong_to don't really specify the specific > type of association, so you could get false positives. Also, it > probably needs a have_one and have_and_belong_to_many matchers is well > to round it out, no? Yes this is definitely still a work in progress, and I wasn't quite ready to release, but figured since folks were talking about this now I'd throw it out there and get feedback earlier rather then later. Josh -- Josh Knowles joshknowles at gmail.com http://joshknowles.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070329/933c7801/attachment.html From aslak.hellesoy at gmail.com Thu Mar 29 12:02:59 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Thu, 29 Mar 2007 18:02:59 +0200 Subject: [rspec-users] a better "should have valid associations" In-Reply-To: References: <4b430c8f0703290118t49bf8c45vc8fcab2670108f97@mail.gmail.com> <57c63afe0703290805n44d830arb49b93215cf572ee@mail.gmail.com> <57c63afe0703290844m20421d03q8e54ef0a4810c5e3@mail.gmail.com> Message-ID: <8d961d900703290902n5ef951b5k2045564a92e41d90@mail.gmail.com> On 3/29/07, Josh Knowles wrote: > > > On 3/29/07, David Chelimsky wrote: > > AWESOME! I'm so psyched to see a plugin emerging for this. > > I second that. > > Looks like have_many and belong_to don't really specify the specific > > type of association, so you could get false positives. Also, it > > probably needs a have_one and have_and_belong_to_many matchers is well > > to round it out, no? > > > Yes this is definitely still a work in progress, and I wasn't quite ready to > release, but figured since folks were talking about this now I'd throw it > out there and get feedback earlier rather then later. > Now that the rspec plugin mechanism seems to be working nicely, we don't have to include lots of stuff in the Spec::Rails codebase. However, we should make sure the RSpec website includes a link to valuable plugins like this one. Aslak > Josh > > > > > -- > Josh Knowles > joshknowles at gmail.com > http://joshknowles.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From bkeepers at gmail.com Fri Mar 30 14:09:18 2007 From: bkeepers at gmail.com (Brandon Keepers) Date: Fri, 30 Mar 2007 14:09:18 -0400 Subject: [rspec-users] a better "should have valid associations" In-Reply-To: References: <4b430c8f0703290118t49bf8c45vc8fcab2670108f97@mail.gmail.com> <57c63afe0703290805n44d830arb49b93215cf572ee@mail.gmail.com> Message-ID: <079B323C-6CE8-460E-9FBB-B11AB9CC9CF4@gmail.com> I need to keep up with this list more. I hadn't read the posts from yesterday and implemented a matcher this morning based off of Craig's post to the Grand Rapids Ruby group list[1]. module Spec module Rails module Matchers class HaveAssociation #:nodoc: def initialize(type, name, options = {}) @type = type @name = name @options = options @class_name = options[:class_name] || @name.to_s.singularize.camelize end def matches?(model) @model = model @association = model.reflect_on_association(@name) @association && @association.macro == @type && @association.class_name == @class_name && @association.options == @options end def failure_message "expected #{model.inspect} to have a #{type} association called '#{name}', but got #{association.inspect}" end def description "have a #{type} association called :#{name}" end private attr_reader :type, :name, :model, :association end def have_association(type, name, options = {}) HaveAssociation.new(type, name, options) end end end end and in my spec: context "A comment" do specify "should belong to a message" do Comment.should have_association (:belongs_to, :message, :class_name => 'Post', :foreign_key => 'custom_foreign_key') end end The only thing I don't like about this approach (and ones similar) is that it only checks the declaration. While that is important, I also think specs need to check that the declaration actually works (foreign key exists in database, model exists, etc.). Brandon [1] http://lists.gr-ruby.org/pipermail/discuss-gr-ruby.org/2007-March/ 000568.html On Mar 29, 2007, at 11:35 AM, Josh Knowles wrote: > > > On 3/29/07, David Chelimsky wrote: > > How about this? > > project.should belong_to(:manager) > manager.should have_many(:projects) > > etc > > This would involve more matchers, but could be implemented in the same > fashion as have_association is above. > > > I've implenented the first pass at the following rails matchers: > > should belong_to(association) > should have_many(association) > should validate_confirmation_of(attribute) > should validate_format_of(attribute, valid => [], invalid => []) > should validate_lendth_of(attribute, range) > should validate_presence_of(attribute) > should validate_uniqueness_of(attribute) > > Plugin available here: http://svn.integrumtech.com/public/plugins/ > rspec_on_rails_matchers/ > > I haven't had a chance to get the README done, or any rdoc, but > there are specs for the majority of the matchers. > > Comments / Suggestions Welcome! > > Josh > > > > > -- > Josh Knowles > joshknowles at gmail.com > http://joshknowles.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From court3nay at gmail.com Fri Mar 30 18:22:07 2007 From: court3nay at gmail.com (Courtenay) Date: Fri, 30 Mar 2007 15:22:07 -0700 Subject: [rspec-users] a better "should have valid associations" In-Reply-To: <079B323C-6CE8-460E-9FBB-B11AB9CC9CF4@gmail.com> References: <4b430c8f0703290118t49bf8c45vc8fcab2670108f97@mail.gmail.com> <57c63afe0703290805n44d830arb49b93215cf572ee@mail.gmail.com> <079B323C-6CE8-460E-9FBB-B11AB9CC9CF4@gmail.com> Message-ID: <4b430c8f0703301522pc30ea1et31b1c4dbe9afdd05@mail.gmail.com> On 3/30/07, Brandon Keepers wrote: > > The only thing I don't like about this approach (and ones similar) is > that it only checks the declaration. While that is important, I also > think specs need to check that the declaration actually works > (foreign key exists in database, model exists, etc.). > That's what my original post does. Court3nay From chad at spicycode.com Fri Mar 30 20:18:41 2007 From: chad at spicycode.com (Chad Humphries) Date: Fri, 30 Mar 2007 20:18:41 -0400 Subject: [rspec-users] a better "should have valid associations" In-Reply-To: <4b430c8f0703301522pc30ea1et31b1c4dbe9afdd05@mail.gmail.com> References: <4b430c8f0703290118t49bf8c45vc8fcab2670108f97@mail.gmail.com> <57c63afe0703290805n44d830arb49b93215cf572ee@mail.gmail.com> <079B323C-6CE8-460E-9FBB-B11AB9CC9CF4@gmail.com> <4b430c8f0703301522pc30ea1et31b1c4dbe9afdd05@mail.gmail.com> Message-ID: <16f722280703301718t2345edfftfeae5e47f7c7750d@mail.gmail.com> I've been working on building out standard expectation matchers for all the built-in validations in rails ala: setup do @user = User.new(valid_user_attributes) end specify do @user.should require_presence_of :first_name end specify do @user.should require_confirmation_of :password end The first version has a few of the validators, the next release coming shortly will finish out all the rest. -chad On 3/30/07, Courtenay wrote: > On 3/30/07, Brandon Keepers wrote: > > > > The only thing I don't like about this approach (and ones similar) is > > that it only checks the declaration. While that is important, I also > > think specs need to check that the declaration actually works > > (foreign key exists in database, model exists, etc.). > > > > That's what my original post does. > > > Court3nay > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From chad at spicycode.com Fri Mar 30 20:21:06 2007 From: chad at spicycode.com (Chad Humphries) Date: Fri, 30 Mar 2007 20:21:06 -0400 Subject: [rspec-users] a better "should have valid associations" In-Reply-To: References: <4b430c8f0703290118t49bf8c45vc8fcab2670108f97@mail.gmail.com> <57c63afe0703290805n44d830arb49b93215cf572ee@mail.gmail.com> Message-ID: <16f722280703301721m7b5629bcl89872b0c9936c371@mail.gmail.com> josh, sweet, missed your earlier post, looks like we've both finished these out :) -chad On 3/29/07, Josh Knowles wrote: > > > On 3/29/07, David Chelimsky wrote: > > > > > > How about this? > > > > project.should belong_to(:manager) > > manager.should have_many(:projects) > > > > etc > > > > This would involve more matchers, but could be implemented in the same > > fashion as have_association is above. > > > I've implenented the first pass at the following rails matchers: > > should belong_to(association) > should have_many(association) > should validate_confirmation_of(attribute) > should validate_format_of(attribute, valid => [], invalid => []) > should validate_lendth_of(attribute, range) > should validate_presence_of(attribute) > should validate_uniqueness_of(attribute) > > Plugin available here: > http://svn.integrumtech.com/public/plugins/rspec_on_rails_matchers/ > > I haven't had a chance to get the README done, or any rdoc, but there are > specs for the majority of the matchers. > > Comments / Suggestions Welcome! > > Josh > > > > > -- > Josh Knowles > joshknowles at gmail.com > http://joshknowles.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Fri Mar 30 23:19:30 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Fri, 30 Mar 2007 23:19:30 -0400 Subject: [rspec-users] Autotest In-Reply-To: References: <57c63afe0703280348y476ecb2dr414edf7bb521369a@mail.gmail.com> <2C305509-621E-4F3C-AD22-66CC10F3831D@eminentconsultinggroup.com> <8213E026-2769-4D37-AF2F-9EA518724904@railsnewbie.com> <07A0E438-910E-4393-9778-3A7A2D779BAE@railsnewbie.com> Message-ID: <7F52434B-5EBE-4F6A-BE41-ACC879589CF0@railsnewbie.com> Does it work for you if you use the DRB server specified in your opts file? What version of rspec are you using? Thanks, Scott On Mar 29, 2007, at 11:28 AM, Josh Knowles wrote: > > > On 3/29/07, Scott Taylor wrote: > > So what did you set the spec command to in the rake task? > > > @spec_command = "#{RAILS_ROOT}/vendor/plugins > /rspec/bin/spec --diff unified --options #{RAILS_ROOT}/spec/spec.opts" > > > > > > -- > Josh Knowles > joshknowles at gmail.com > http://joshknowles.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dastels at daveastels.com Sat Mar 31 11:12:44 2007 From: dastels at daveastels.com (Dave Astels) Date: Sat, 31 Mar 2007 12:12:44 -0300 Subject: [rspec-users] a better "should have valid associations" In-Reply-To: <8d961d900703290902n5ef951b5k2045564a92e41d90@mail.gmail.com> References: <4b430c8f0703290118t49bf8c45vc8fcab2670108f97@mail.gmail.com> <57c63afe0703290805n44d830arb49b93215cf572ee@mail.gmail.com> <57c63afe0703290844m20421d03q8e54ef0a4810c5e3@mail.gmail.com> <8d961d900703290902n5ef951b5k2045564a92e41d90@mail.gmail.com> Message-ID: <6079631A-7C8D-4BC6-AA80-973F22E684EC@daveastels.com> On 29-Mar-07, at 1:02 PM, aslak hellesoy wrote: > On 3/29/07, Josh Knowles wrote: >> >> >> On 3/29/07, David Chelimsky wrote: >>> AWESOME! I'm so psyched to see a plugin emerging for this. >>> > > I second that. I'll play devils-advocate.. what does all this have to do with specifying behaviour? From a specification point of view, do I care that there's a valiadtor for a field? I don't think so... I'm more concerned with what happens when I try to use a bad value for that field. That there's a validator for it in the model is an implementation detail. That said, it's great stuff for a plugin. Dave -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070331/7bf1c9a8/attachment.html From aslak.hellesoy at gmail.com Sat Mar 31 14:09:15 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Sat, 31 Mar 2007 20:09:15 +0200 Subject: [rspec-users] a better "should have valid associations" In-Reply-To: <6079631A-7C8D-4BC6-AA80-973F22E684EC@daveastels.com> References: <4b430c8f0703290118t49bf8c45vc8fcab2670108f97@mail.gmail.com> <57c63afe0703290805n44d830arb49b93215cf572ee@mail.gmail.com> <57c63afe0703290844m20421d03q8e54ef0a4810c5e3@mail.gmail.com> <8d961d900703290902n5ef951b5k2045564a92e41d90@mail.gmail.com> <6079631A-7C8D-4BC6-AA80-973F22E684EC@daveastels.com> Message-ID: <8d961d900703311109j1a05dc09w34e4b35e33ab6633@mail.gmail.com> On 3/31/07, Dave Astels wrote: > > > On 29-Mar-07, at 1:02 PM, aslak hellesoy wrote: > > > On 3/29/07, Josh Knowles wrote: > > > > > > > > > On 3/29/07, David Chelimsky wrote: > > > AWESOME! I'm so psyched to see a plugin emerging for this. > > > > > > > > I second that. > I'll play devils-advocate.. what does all this have to do with specifying > behaviour? > Probably not much, but can't we say that about most of RSpec's built-in matchers? Like for example: foo.should match(/bar/) What does that have to do with behaviour? > From a specification point of view, do I care that there's a valiadtor for a > field? I don't think so... I'm more concerned with what happens when I try > to use a bad value for that field. That there's a validator for it in the > model is an implementation detail. > > That said, it's great stuff for a plugin. > I've been thinking - would it make sense to modify the rspec_resource generator to generate specs that use the matchers provided by Josh's plugin? It would be possible to infer from foreign key fields passed as arguments to the generator (name:string project_id:integer) etc. Aslak > Dave > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Sat Mar 31 16:44:13 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 31 Mar 2007 15:44:13 -0500 Subject: [rspec-users] a better "should have valid associations" In-Reply-To: <8d961d900703311109j1a05dc09w34e4b35e33ab6633@mail.gmail.com> References: <4b430c8f0703290118t49bf8c45vc8fcab2670108f97@mail.gmail.com> <57c63afe0703290805n44d830arb49b93215cf572ee@mail.gmail.com> <57c63afe0703290844m20421d03q8e54ef0a4810c5e3@mail.gmail.com> <8d961d900703290902n5ef951b5k2045564a92e41d90@mail.gmail.com> <6079631A-7C8D-4BC6-AA80-973F22E684EC@daveastels.com> <8d961d900703311109j1a05dc09w34e4b35e33ab6633@mail.gmail.com> Message-ID: <57c63afe0703311344h5298c7c2wef0c71aa2a6daeda@mail.gmail.com> On 3/31/07, aslak hellesoy wrote: > On 3/31/07, Dave Astels wrote: > > I'll play devils-advocate.. what does all this have to do with specifying > > behaviour? > > Probably not much, but can't we say that about most of RSpec's > built-in matchers? Like for example: > > foo.should match(/bar/) > > What does that have to do with behaviour? I think it gets too easy to say "if we're checking state it's not about behaviour" but I think that's wrong. Some objects answer questions - and that IS their behaviour. If an object answers the same question in two different ways based on what you've done (or not done) before you ask the question, then that is behaviour. I think the distinction here is that we're really describing an object's structure, not its behaviour, when we say: pet_shop.should have_many(:pets) This is an interesting dilemma that were forced to negotiate our way through because Rails breaks what have long been considered good Object Oriented principles like "favor delegation over inheritance". It is adherence to that principle, in my view, that makes Spring the hands down winner over Struts in the java space. Well, there are other reasons as well. But there's a counter argument to all this, which is pragmatism. I can express a lot of implied behaviour by saying: describe User do it "should require email" do User.new.should validate_presence_of(:email) end end I think that has some value. The risk, of course, is that we're now married to Rails and it would be hard to use a different framework without changing all of our examples. If that's the fear, then you really shouldn't be using Rails to begin with. > > > From a specification point of view, do I care that there's a valiadtor for a > > field? I don't think so... I'm more concerned with what happens when I try > > to use a bad value for that field. That there's a validator for it in the > > model is an implementation detail. > > > > That said, it's great stuff for a plugin. > > I've been thinking - would it make sense to modify the rspec_resource > generator to generate specs that use the matchers provided by Josh's > plugin? It would be possible to infer from foreign key fields passed > as arguments to the generator (name:string project_id:integer) etc. My instinct is that I wouldn't want the dependency from Spec::Rails to another plugin. If that's the goal we should either ship the rspec_resource generator as a separate plugin or move Josh's plugin into RSpec (w/ his permission, of course). Thoughts on that (especially from Josh)? David > > Aslak > > > Dave > > > > > > _______________________________________________ > > 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 >