From osahyoun at gmail.com Sat Dec 1 11:42:50 2007 From: osahyoun at gmail.com (Sahyoun) Date: Sat, 1 Dec 2007 17:42:50 +0100 Subject: [rspec-users] mock feed Message-ID: Hello generous coders, I'm having difficulty getting a couple of tests to pass. I have an address model which takes an address and with a callback on save and update passes the address to google's geocoding service. The returned XML is parsed and saved to the address object: protected def geocode_address key = "mykey" url = "http://maps.google.com/maps/geo?q=#{self.address_1.gsub(' ', '+')},+#{self.postcode},+FRANCE&output=xml&key=#{key}" doc = Hpricot.XML(Iconv.iconv("UTF-8", "ISO-8859-2", open(URI.escape (url)).read).to_s) section = (doc/"Placemark").first self.lat, self.lng = (section/"coordinates").text.split(',') self.town = (section/"LocalityName").text self.address_1 = (section/"ThoroughfareName").text end In my spec for the address model I have as a helper: def mock_feed directions = "q=71+av+Parmentier,+75011,+FRANCE&output=xml&key=mykey" xml = File.read(RAILS_ROOT + "/spec/fixtures/feeds/75001.xml") @address.should_receive(:open).exactly(1).times. with("http://maps.google.com/maps/geo?#{directions}"). and_return(xml) end ....................... describe Address, "fetch and geocode" do include AddressSpecHelper before do @address = Address.new mock_feed @address.attributes = valid_address_attributes @address.save end it "should populate town and address 1" do @address.town.should eql("Paris") @address.address_1.should eql("71, Avenue Parmentier") end it "should populate lat and lng as BigDecimals" do @address.lat.should eql(BigDecimal("2.375258")) @address.lng.should eql(BigDecimal("48.864315")) end end My two errors: 2) NoMethodError in 'Address fetch and geocode should populate town and address 1' undefined method `read' for # 1) NoMethodError in 'Address fetch and geocode should populate lat and lng as BigDecimals' undefined method `read' for # These tests passed fine with a previous version of the geocode_address method: protected def geocode_address key = "mykey" url = "http://maps.google.com/maps/geo?q=#{self.address_1.gsub(' ', '+')},+#{self.postcode},+FRANCE&output=xml&key=#{key}" doc = Hpricot.XML(open(url)) self.lat, self.lng = (doc/"coordinates").text.split(',') self.town = (doc/"LocalityName").text self.address_1 = (doc/"ThoroughfareName").text end I'm new to rspec and the ideas behind mocks and stubs. I don't understand why rspec is paying any notice to 'read'. Do I also need to inform the mock of the 'read' method? If so, how and why? Any pointers would be gratefully received. Many thanks O -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071201/40018e75/attachment-0001.html From sera at fhwang.net Sat Dec 1 15:45:16 2007 From: sera at fhwang.net (Francis Hwang) Date: Sat, 1 Dec 2007 15:45:16 -0500 Subject: [rspec-users] specifying an HTTP status code Message-ID: Hi all, I'm just starting to work w/ RSpec, so I hope this question isn't too obvious or missing the point somehow: Is there a way in RSpec to specify that a controller action should use a specific HTTP status code? Specifically I want to test for the usage of 301 as opposed to 302, for a permanent redirection. response.should be_redirect looks like it calls ActionController::TestRequest#redirect?, which is only testing for a status code from 300..399. In an old-fashioned Test::Unit Rails test I could do assert_response, but I can't see anything matching that in RSpec. Is there a less-documented feature I'm missing? Thanks, Francis Hwang http://fhwang.net/ From mailing_lists at railsnewbie.com Sat Dec 1 16:27:53 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sat, 1 Dec 2007 16:27:53 -0500 Subject: [rspec-users] specifying an HTTP status code In-Reply-To: References: Message-ID: <810787FC-7AD1-4638-8943-CBA5DED11D2A@railsnewbie.com> On Dec 1, 2007, at 3:45 PM, Francis Hwang wrote: > Hi all, > > I'm just starting to work w/ RSpec, so I hope this question isn't too > obvious or missing the point somehow: Is there a way in RSpec to > specify that a controller action should use a specific HTTP status > code? Specifically I want to test for the usage of 301 as opposed to > 302, for a permanent redirection. > > response.should be_redirect > > looks like it calls ActionController::TestRequest#redirect?, which is > only testing for a status code from 300..399. In an old-fashioned > Test::Unit Rails test I could do assert_response, but I can't see > anything matching that in RSpec. Is there a less-documented feature > I'm missing? > > Thanks, > > Francis Hwang > http://fhwang.net/ > Hey Francis - Great to see you've finally come over from the dark side (Test::Unit)! How is rspec treating you? Anyway - here's how I've done it with a 404: describe ErrorController, "view" do it "should render the 404 page in public/" do get :view response.should render_template("#{RAILS_ROOT}/public/404.html") end it "should return an HTTP status code of 404" do get :view response.headers["Status"].should == "404 Not Found" end end I would imagine you could do something similar for 301. I don't think there are currently any matchers for these status codes like: should_be_not_found or should_not_be_a_404, although they could certainly be written. (Method missing seems to be screaming at me here...) Regards, Scott Taylor From dchelimsky at gmail.com Sat Dec 1 17:08:47 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 1 Dec 2007 17:08:47 -0500 Subject: [rspec-users] specifying an HTTP status code In-Reply-To: <810787FC-7AD1-4638-8943-CBA5DED11D2A@railsnewbie.com> References: <810787FC-7AD1-4638-8943-CBA5DED11D2A@railsnewbie.com> Message-ID: <57c63afe0712011408q268be4dsb56738ef25010822@mail.gmail.com> On Dec 1, 2007 4:27 PM, Scott Taylor wrote: > > On Dec 1, 2007, at 3:45 PM, Francis Hwang wrote: > > > Hi all, > > > > I'm just starting to work w/ RSpec, so I hope this question isn't too > > obvious or missing the point somehow: Is there a way in RSpec to > > specify that a controller action should use a specific HTTP status > > code? Specifically I want to test for the usage of 301 as opposed to > > 302, for a permanent redirection. > > > > response.should be_redirect > > > > looks like it calls ActionController::TestRequest#redirect?, which is > > only testing for a status code from 300..399. In an old-fashioned > > Test::Unit Rails test I could do assert_response, but I can't see > > anything matching that in RSpec. Is there a less-documented feature > > I'm missing? > > > > Thanks, > > > > Francis Hwang > > http://fhwang.net/ > > > > Hey Francis - Great to see you've finally come over from the dark > side (Test::Unit)! How is rspec treating you? > > Anyway - here's how I've done it with a 404: > > describe ErrorController, "view" do > > it "should render the 404 page in public/" do > get :view > response.should render_template("#{RAILS_ROOT}/public/404.html") > end > > it "should return an HTTP status code of 404" do > get :view > response.headers["Status"].should == "404 Not Found" > end > > end You can also just go right for the response_code: response.response_code.should == 301 > > > I would imagine you could do something similar for 301. I don't > think there are currently any matchers for these status codes like: > should_be_not_found or should_not_be_a_404, although they could > certainly be written. (Method missing seems to be screaming at me > here...) > > Regards, > > Scott Taylor > > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jarkko at jlaine.net Sat Dec 1 17:10:36 2007 From: jarkko at jlaine.net (Jarkko Laine) Date: Sun, 2 Dec 2007 00:10:36 +0200 Subject: [rspec-users] specifying an HTTP status code In-Reply-To: <810787FC-7AD1-4638-8943-CBA5DED11D2A@railsnewbie.com> References: <810787FC-7AD1-4638-8943-CBA5DED11D2A@railsnewbie.com> Message-ID: <368DA940-A278-42B1-ADF1-14411C233BA7@jlaine.net> On 1.12.2007, at 23.27, Scott Taylor wrote: > it "should return an HTTP status code of 404" do > get :view > response.headers["Status"].should == "404 Not Found" or response.response_code.should == 404 -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http://odesign.fi From mailing_lists at railsnewbie.com Sat Dec 1 17:19:20 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sat, 1 Dec 2007 17:19:20 -0500 Subject: [rspec-users] specifying an HTTP status code In-Reply-To: <368DA940-A278-42B1-ADF1-14411C233BA7@jlaine.net> References: <810787FC-7AD1-4638-8943-CBA5DED11D2A@railsnewbie.com> <368DA940-A278-42B1-ADF1-14411C233BA7@jlaine.net> Message-ID: <27B6BA7F-96B2-480B-8F7D-8892F35F8B3A@railsnewbie.com> On Dec 1, 2007, at 5:10 PM, Jarkko Laine wrote: > On 1.12.2007, at 23.27, Scott Taylor wrote: >> it "should return an HTTP status code of 404" do >> get :view >> response.headers["Status"].should == "404 Not Found" > > or > > response.response_code.should == 404 > Nice. I find out something new every day from this list. From cdemyanovich at gmail.com Sun Dec 2 08:12:14 2007 From: cdemyanovich at gmail.com (Craig Demyanovich) Date: Sun, 2 Dec 2007 08:12:14 -0500 Subject: [rspec-users] specifying an HTTP status code In-Reply-To: <27B6BA7F-96B2-480B-8F7D-8892F35F8B3A@railsnewbie.com> References: <810787FC-7AD1-4638-8943-CBA5DED11D2A@railsnewbie.com> <368DA940-A278-42B1-ADF1-14411C233BA7@jlaine.net> <27B6BA7F-96B2-480B-8F7D-8892F35F8B3A@railsnewbie.com> Message-ID: <61c885db0712020512m59805edla196d99ed212670d@mail.gmail.com> On Dec 1, 2007 5:19 PM, Scott Taylor wrote: > > On Dec 1, 2007, at 5:10 PM, Jarkko Laine wrote: > > > On 1.12.2007, at 23.27, Scott Taylor wrote: > >> it "should return an HTTP status code of 404" do > >> get :view > >> response.headers["Status"].should == "404 Not Found" > > > > or > > > > response.response_code.should == 404 > > > > Nice. I find out something new every day from this list. You might also look at status_codes.rb. For example, if you have rails in vendor/rails, it's path is vendor/rails/actionpack/lib/action_controller/status_codes.rb For any status in that file, you should be able to do this in your examples: assert_response :not_found Yes, that's a Test::Unit assertion. Here's why I use it: * I'm not sure if there is a way to do it in RSpec (haven't yet investigated) * I can use Test::Unit assertions in RSpec (really cool) * I like the way it reads compared to using the codes, such as 404 Regards, Craig -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071202/bd0a0834/attachment.html From daniel at helpmebuyacar.org Mon Dec 3 04:57:35 2007 From: daniel at helpmebuyacar.org (Fischer, Daniel) Date: Mon, 3 Dec 2007 01:57:35 -0800 Subject: [rspec-users] Need help mocking this out Message-ID: <7e565b5c0712030157s4e56b280l1bcf4621c8c8c7a4@mail.gmail.com> Let's say you're using the restful_authentication plugin. You have a model called articles. On the index action of the articlescontroller you simply want to spec out that it'll scope the results to the ownership of the current_user. It should NOT include any articles other than the articles that user owns. How would you properly spec this out? Thanks for the help! -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071203/1d33f697/attachment.html From daniel at danielfischer.com Mon Dec 3 04:58:16 2007 From: daniel at danielfischer.com (Fischer, Daniel) Date: Mon, 3 Dec 2007 01:58:16 -0800 Subject: [rspec-users] Need help mocking this out In-Reply-To: <7e565b5c0712030157s4e56b280l1bcf4621c8c8c7a4@mail.gmail.com> References: <7e565b5c0712030157s4e56b280l1bcf4621c8c8c7a4@mail.gmail.com> Message-ID: <7e565b5c0712030158m64d0a3fr4c7218508ecec201@mail.gmail.com> Let's say you're using the restful_authentication plugin. You have a model called articles. On the index action of the articlescontroller you simply want to spec out that it'll scope the results to the ownership of the current_user. It should NOT include any articles other than the articles that user owns. How would you properly spec this out? Thanks for the help! -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071203/362a4bab/attachment.html From stefan.landro at gmail.com Mon Dec 3 05:07:51 2007 From: stefan.landro at gmail.com (=?ISO-8859-1?Q?Stefan_Magnus_Landr=F8?=) Date: Mon, 3 Dec 2007 11:07:51 +0100 Subject: [rspec-users] Need help mocking this out In-Reply-To: <7e565b5c0712030157s4e56b280l1bcf4621c8c8c7a4@mail.gmail.com> References: <7e565b5c0712030157s4e56b280l1bcf4621c8c8c7a4@mail.gmail.com> Message-ID: <921ca2f80712030207o7f45771dk15006c3ab5b17ab8@mail.gmail.com> Typically, I'd write a method in your user model that returns the user's articles: class User do def find_articles_for_user Article.find(:all, :conditions => ['userid = ?', id) end end Then you'd use a mock in your controller spec, and make sure you test that your method is being called. On the other hand, the user model should be tested directly against the db. HTH, Stefan 2007/12/3, Fischer, Daniel : > > Let's say you're using the restful_authentication plugin. > You have a model called articles. On the index action of the > articlescontroller you simply want to spec out that it'll scope the results > to the ownership of the current_user. > > It should NOT include any articles other than the articles that user owns. > > How would you properly spec this out? > > Thanks for the help! > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Bekk Open Source http://boss.bekk.no -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071203/ca3fda82/attachment.html From me at danielfischer.com Mon Dec 3 05:33:44 2007 From: me at danielfischer.com (Fischer, Daniel) Date: Mon, 3 Dec 2007 02:33:44 -0800 Subject: [rspec-users] Need help mocking this out In-Reply-To: <921ca2f80712030207o7f45771dk15006c3ab5b17ab8@mail.gmail.com> References: <7e565b5c0712030157s4e56b280l1bcf4621c8c8c7a4@mail.gmail.com> <921ca2f80712030207o7f45771dk15006c3ab5b17ab8@mail.gmail.com> Message-ID: <7e565b5c0712030233h9554c98h57fd1f90d4bcf023@mail.gmail.com> yuck, that seems kind of nasty, no? user.articles is already scoped... There has to be a different solution! On Dec 3, 2007 2:07 AM, Stefan Magnus Landr? wrote: > Typically, I'd write a method in your user model that returns the user's > articles: > > class User do > > def find_articles_for_user > Article.find(:all, :conditions => ['userid = ?', id) > end > > end > > Then you'd use a mock in your controller spec, and make sure you test that > your method is being called. > > On the other hand, the user model should be tested directly against the > db. > > HTH, > > Stefan > > 2007/12/3, Fischer, Daniel : > > > > Let's say you're using the restful_authentication plugin. > > You have a model called articles. On the index action of the > > articlescontroller you simply want to spec out that it'll scope the results > > to the ownership of the current_user. > > > > It should NOT include any articles other than the articles that user > > owns. > > > > How would you properly spec this out? > > > > Thanks for the help! > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > -- > Bekk Open Source > http://boss.bekk.no > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071203/78dbb660/attachment-0001.html From jarkko at jlaine.net Mon Dec 3 05:42:46 2007 From: jarkko at jlaine.net (Jarkko Laine) Date: Mon, 3 Dec 2007 12:42:46 +0200 Subject: [rspec-users] Need help mocking this out In-Reply-To: <7e565b5c0712030157s4e56b280l1bcf4621c8c8c7a4@mail.gmail.com> References: <7e565b5c0712030157s4e56b280l1bcf4621c8c8c7a4@mail.gmail.com> Message-ID: <5A47E0E4-9A00-47D2-8FF1-BDA4F3849637@jlaine.net> On 3.12.2007, at 11.57, Fischer, Daniel wrote: > Let's say you're using the restful_authentication plugin. > > You have a model called articles. On the index action of the > articlescontroller you simply want to spec out that it'll scope the > results to the ownership of the current_user. > > It should NOT include any articles other than the articles that user > owns. Given that you have user has_many :articles You want to use current_user.articles (or current_user.articles.find(*additional options*)). In the spec, you want to make sure that the articles are scoped through the correct user: before(:each) do @user = mock_model(User) User.stub!(:find).and_return(@user) # to make sure current_user is the mock model @articles = [mock_model(Article)] end it "should find articles for the current user" do @user.should_receive(:articles).and_return(@articles) get :index end It is then the responsibility of the articles association to scope the results. In the controller specs you just trust that it works. -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http://odesign.fi From has.sox at gmail.com Mon Dec 3 05:44:06 2007 From: has.sox at gmail.com (Daniel N) Date: Mon, 3 Dec 2007 21:44:06 +1100 Subject: [rspec-users] Need help mocking this out In-Reply-To: <921ca2f80712030207o7f45771dk15006c3ab5b17ab8@mail.gmail.com> References: <7e565b5c0712030157s4e56b280l1bcf4621c8c8c7a4@mail.gmail.com> <921ca2f80712030207o7f45771dk15006c3ab5b17ab8@mail.gmail.com> Message-ID: <2fff50390712030244t25e59b74y176a4876ba8b011e@mail.gmail.com> Assuming that there is a call like this in your controller @articles = current_user.articles One way to do this is to stub out the controller.current_user to return a mock object of the current_user Then put an expectation on the current user that it's articles method gets called. (return a mocked collection of articles) Then check that @articles is set to the returned mocked collection of articles from current_user.articles phew... Ok So one way you might write this could be (This is untested...) it "should scope the articles to the currrent_user" do user = mock_model(User) articles = [mock_model(Article)] controller.stub!(:current_user).and_return(user) user.should_receive(:articles).and_return(articles) get :index assigns[:articles].should == articles end Like I said though, that's not tested itself. If that's not exactly right... it's along the right track of an option that can work. HTH Daniel On Dec 3, 2007 9:07 PM, Stefan Magnus Landr? wrote: > Typically, I'd write a method in your user model that returns the user's > articles: > > class User do > > def find_articles_for_user > Article.find(:all, :conditions => ['userid = ?', id) > end > > end > > Then you'd use a mock in your controller spec, and make sure you test that > your method is being called. > > On the other hand, the user model should be tested directly against the > db. > > HTH, > > Stefan > > 2007/12/3, Fischer, Daniel : > > > > Let's say you're using the restful_authentication plugin. > > You have a model called articles. On the index action of the > > articlescontroller you simply want to spec out that it'll scope the results > > to the ownership of the current_user. > > > > It should NOT include any articles other than the articles that user > > owns. > > > > How would you properly spec this out? > > > > Thanks for the help! > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > -- > Bekk Open Source > http://boss.bekk.no > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071203/cffdf875/attachment.html From daniel.ruby at tenner.org Mon Dec 3 05:48:16 2007 From: daniel.ruby at tenner.org (Daniel Tenner) Date: Mon, 3 Dec 2007 10:48:16 +0000 Subject: [rspec-users] Need help mocking this out In-Reply-To: <7e565b5c0712030233h9554c98h57fd1f90d4bcf023@mail.gmail.com> References: <7e565b5c0712030157s4e56b280l1bcf4621c8c8c7a4@mail.gmail.com> <921ca2f80712030207o7f45771dk15006c3ab5b17ab8@mail.gmail.com> <7e565b5c0712030233h9554c98h57fd1f90d4bcf023@mail.gmail.com> Message-ID: Hi Daniel, You're trying to do too much in the controller. It's not the controller's responsibility to ensure that the user is capable of returning its own article without including anyone else's - that's the user's (or the Article model's, perhaps) responsibility. Your controller should be thin and simple, delegating all business logic onto the model objects. See this article: http://www.pragprog.com/ articles/tell-dont-ask Once thinned down like this, speccing the controller becomes trivial - just mock the current_user method and ensure that it receives a call to "available_articles" or whatever the method name is. Then, spec that method in the User model. At that point, don't mock anything you don't have to, and test the behaviour of the User model (e.g. "it should not return anyone else's article within its available articles" or something like that). Hope this helps, Daniel On 3 Dec 2007, at 10:33 3 Dec 2007, Fischer, Daniel wrote: > yuck, that seems kind of nasty, no? > > user.articles is already scoped... > > There has to be a different solution! > > On Dec 3, 2007 2:07 AM, Stefan Magnus Landr? > wrote: > Typically, I'd write a method in your user model that returns the > user's articles: > > class User do > > def find_articles_for_user > Article.find(:all, :conditions => ['userid = ?', id) > end > > end > > Then you'd use a mock in your controller spec, and make sure you > test that your method is being called. > > On the other hand, the user model should be tested directly against > the db. > > HTH, > > Stefan > > 2007/12/3, Fischer, Daniel : > Let's say you're using the restful_authentication plugin. > > You have a model called articles. On the index action of the > articlescontroller you simply want to spec out that it'll scope the > results to the ownership of the current_user. > > It should NOT include any articles other than the articles that > user owns. > > How would you properly spec this out? > > Thanks for the help! > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > > > -- > Bekk Open Source > http://boss.bekk.no > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.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/20071203/8555842d/attachment.html From stefan.landro at gmail.com Mon Dec 3 06:50:15 2007 From: stefan.landro at gmail.com (=?ISO-8859-1?Q?Stefan_Magnus_Landr=F8?=) Date: Mon, 3 Dec 2007 12:50:15 +0100 Subject: [rspec-users] Need help mocking this out In-Reply-To: <7e565b5c0712030233h9554c98h57fd1f90d4bcf023@mail.gmail.com> References: <7e565b5c0712030157s4e56b280l1bcf4621c8c8c7a4@mail.gmail.com> <921ca2f80712030207o7f45771dk15006c3ab5b17ab8@mail.gmail.com> <7e565b5c0712030233h9554c98h57fd1f90d4bcf023@mail.gmail.com> Message-ID: <921ca2f80712030350p6f6b374aoc2afb7322c63e1a3@mail.gmail.com> Well, if articles is already scoped, you just say: user.should_receive('articles').and_return(some_articles) To make sure your articles method is scoped, write a model test that hits the database, and verify that only the user's articles are returned. As Daniel Tenner says, you should try to keep your controllers as thin as possible. In addition you should try to keep your tests as fast as possible - and you typically do that by not hitting the DB. Stefan 2007/12/3, Fischer, Daniel : > > yuck, that seems kind of nasty, no? > user.articles is already scoped... > > There has to be a different solution! > > On Dec 3, 2007 2:07 AM, Stefan Magnus Landr? > wrote: > > > Typically, I'd write a method in your user model that returns the user's > > articles: > > > > class User do > > > > def find_articles_for_user > > Article.find(:all, :conditions => ['userid = ?', id) > > end > > > > end > > > > Then you'd use a mock in your controller spec, and make sure you test > > that your method is being called. > > > > On the other hand, the user model should be tested directly against the > > db. > > > > HTH, > > > > Stefan > > > > 2007/12/3, Fischer, Daniel : > > > > > > Let's say you're using the restful_authentication plugin. > > > You have a model called articles. On the index action of the > > > articlescontroller you simply want to spec out that it'll scope the results > > > to the ownership of the current_user. > > > > > > It should NOT include any articles other than the articles that user > > > owns. > > > > > > How would you properly spec this out? > > > > > > Thanks for the help! > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > -- > > Bekk Open Source > > http://boss.bekk.no > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Bekk Open Source http://boss.bekk.no -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071203/9cb5dd5a/attachment-0001.html From bryan at osesm.com Mon Dec 3 08:32:13 2007 From: bryan at osesm.com (Bryan Liles) Date: Mon, 3 Dec 2007 08:32:13 -0500 Subject: [rspec-users] Stylistic preferences In-Reply-To: References: Message-ID: <9C6B87F4-C473-4B23-8176-19A9A5165AB0@osesm.com> On Nov 29, 2007, at 5:54 AM, Daniel Tenner wrote: > What are people's opinions on which of these two styles is better to > use? > > > it "should be possible to disable the number" do > given(valid_sms_user) do |user| > user.save > user.disable_number > user.should be_disabled > end > end > it "should be possible to disable the number" do lambda { user.save user.disable_number }.should change(user, :disabled?).from(true).to(false) end If this doesn't work, the solution is very close to this. From daniel.ruby at tenner.org Mon Dec 3 08:42:42 2007 From: daniel.ruby at tenner.org (Daniel Tenner) Date: Mon, 3 Dec 2007 13:42:42 +0000 Subject: [rspec-users] Stylistic preferences In-Reply-To: <9C6B87F4-C473-4B23-8176-19A9A5165AB0@osesm.com> References: <9C6B87F4-C473-4B23-8176-19A9A5165AB0@osesm.com> Message-ID: <096B6EDB-E5A4-41D1-B619-B4B63DC48ABE@tenner.org> The code works fine. I was asking about the "given" thing. Daniel On 3 Dec 2007, at 13:32 3 Dec 2007, Bryan Liles wrote: > > On Nov 29, 2007, at 5:54 AM, Daniel Tenner wrote: > >> What are people's opinions on which of these two styles is better to >> use? >> >> >> it "should be possible to disable the number" do >> given(valid_sms_user) do |user| >> user.save >> user.disable_number >> user.should be_disabled >> end >> end >> > > > it "should be possible to disable the number" do > lambda { > user.save > user.disable_number > }.should change(user, :disabled?).from(true).to(false) > end > > If this doesn't work, the solution is very close to this. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From stefan.landro at gmail.com Mon Dec 3 10:31:03 2007 From: stefan.landro at gmail.com (=?ISO-8859-1?Q?Stefan_Magnus_Landr=F8?=) Date: Mon, 3 Dec 2007 16:31:03 +0100 Subject: [rspec-users] Stylistic preferences In-Reply-To: References: Message-ID: <921ca2f80712030731w35d88e95p6cdc957c240e32f8@mail.gmail.com> Well, I kinda like the word given, however I feel it's competing with the Context in describe Class, "Context" do Maybe before should be replaced with some givens and expectations, like so: describe Class, "Context" do given do end always_expect do end it "should ..." do end end Stefan 2007/11/29, Daniel Tenner : > > What are people's opinions on which of these two styles is better to > use? > > 1) before > --------------------------- > module UserSpecHelper > include GenericSpecHelper > > def valid_sms_attributes(phone_number="12345") > { :phone_number => phone_number } > end > end > > describe User, "with phone number" do > include UserSpecHelper > > before(:each) do > @user = User.new(valid_sms_attributes) > end > > it "should be valid" do > @user.should be_valid > end > > it "should reject duplicate phone number" do > @user.save > @user_2 = User.new(valid_sms_attributes) > @user_2.should_not be_valid > end > > it "should be possible to disable the number" do > @user.save > @user.disable_number > @user.should be_disabled > end > end > > > ------------------------ > 2) given/yield > --------------------------- > module GenericSpecHelper > def given(thing) > yield thing if block_given? > thing > end > > end > > > module UserSpecHelper > include GenericSpecHelper > def valid_sms_attributes(phone_number="12345") > { :phone_number => phone_number } > end > > def valid_sms_user(phone_number="12345") > User.new(valid_sms_attributes(phone_number)) > end > end > > > describe User, "unconfirmed" do > include UserSpecHelper > > it "should be valid" do > valid_sms_user.should be_valid > end > > it "should reject duplicate phone number" do > valid_sms_user("1").save > valid_sms_user("1").should_not be_valid > end > > it "should be possible to disable the number" do > given(valid_sms_user) do |user| > user.save > user.disable_number > user.should be_disabled > end > end > > > end > ------------------- > > My thoughts: the second style is more readable sometimes, less other > times. More importantly, with the first style, my specs tend to be > split alongside the lines of whether they can use the same before > (:each), rather than whether they belong together, whereas with the > second one, one "description" can have several different "starting > points", and I group them by whether I feel they belong together > logically. So at the moment I'm more comfortable with the second style. > > What do you think? > > Daniel > > PS: I know these specs themselves are trivial... I've used both > approaches in less trivial specs, I hope these illustrate the idea > though > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Bekk Open Source http://boss.bekk.no -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071203/8f82b69b/attachment.html From osahyoun at gmail.com Mon Dec 3 13:33:56 2007 From: osahyoun at gmail.com (Sahyoun) Date: Mon, 3 Dec 2007 19:33:56 +0100 Subject: [rspec-users] spec for model_id should eql Message-ID: Hello, I'm confused why the spec described below is failing. Other simple comparison specs are passing fine for the same model. The code is working accordingly when I test it through the console, I'm just having difficulty getting this spec to work. Any pointers would be appreciated. Failure message: 'Address fetch and geocode should extract department and write to address object' FAILED expected 3, got nil (using .eql?) This spec that is failing: @address.department_id.should eql(3) before: before do @address = Address.new @address.attributes = valid_address_attributes @address.save @department = mock_model(Department) @department.stub!(:find_by_code).with("75").and_return("3") end The line of code I am writing the spec for: self.department = Department.find_by_code(self.postcode[0..1]) Many thanks, Omar -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071203/0b8e5734/attachment.html From nathan.sutton at gmail.com Mon Dec 3 14:05:28 2007 From: nathan.sutton at gmail.com (Nathan Sutton) Date: Mon, 3 Dec 2007 13:05:28 -0600 Subject: [rspec-users] spec for model_id should eql In-Reply-To: References: Message-ID: <307B2AF4-E9C4-427C-BBCD-DD51EC6D6023@gmail.com> Department.stub!(:find_by_code).with("75").and_return("3") Nathan Sutton fowlduck at gmail.com rspec edge revision 3014 rspec_on_rails edge revision 3014 rails edge revision 8238 On Dec 3, 2007, at 12:33 PM, Sahyoun wrote: > Hello, > > I'm confused why the spec described below is failing. Other simple > comparison specs are passing fine for the same model. The code is > working accordingly when I test it through the console, I'm just > having difficulty getting this spec to work. Any pointers would be > appreciated. > > Failure message: > 'Address fetch and geocode should extract department and write to > address object' FAILED > expected 3, got nil (using .eql?) > > This spec that is failing: > @address.department_id.should eql(3) > > before: > before do > @address = Address.new > @address.attributes = valid_address_attributes > @address.save > @department = mock_model(Department) > @department.stub! (:find_by_code).with("75").and_return("3") > end > > > The line of code I am writing the spec for: > self.department = Department.find_by_code(self.postcode[0..1]) > > > > Many thanks, > Omar > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From jarkko at jlaine.net Mon Dec 3 14:18:35 2007 From: jarkko at jlaine.net (Jarkko Laine) Date: Mon, 3 Dec 2007 21:18:35 +0200 Subject: [rspec-users] spec for model_id should eql In-Reply-To: <307B2AF4-E9C4-427C-BBCD-DD51EC6D6023@gmail.com> References: <307B2AF4-E9C4-427C-BBCD-DD51EC6D6023@gmail.com> Message-ID: <1533E5F7-ADF1-44B1-8B51-13977627E3C2@jlaine.net> On 3.12.2007, at 21.05, Nathan Sutton wrote: > Department.stub!(:find_by_code).with("75").and_return("3") You can't use with() with stub! (only with should_receive), so just leave it away: Department.stub!(:find_by_code).and_return("3") //jarkko -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http://odesign.fi From dchelimsky at gmail.com Mon Dec 3 14:23:01 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 3 Dec 2007 13:23:01 -0600 Subject: [rspec-users] spec for model_id should eql In-Reply-To: <1533E5F7-ADF1-44B1-8B51-13977627E3C2@jlaine.net> References: <307B2AF4-E9C4-427C-BBCD-DD51EC6D6023@gmail.com> <1533E5F7-ADF1-44B1-8B51-13977627E3C2@jlaine.net> Message-ID: <57c63afe0712031123r72adc566i5b131966c423e2a2@mail.gmail.com> On Dec 3, 2007 1:18 PM, Jarkko Laine wrote: > > On 3.12.2007, at 21.05, Nathan Sutton wrote: > > > Department.stub!(:find_by_code).with("75").and_return("3") > > You can't use with() with stub! (only with should_receive), so just > leave it away: > > Department.stub!(:find_by_code).and_return("3") Actually, you can now, but it's not really documented. > > //jarkko > > -- > Jarkko Laine > http://jlaine.net > http://dotherightthing.com > http://www.railsecommerce.com > http://odesign.fi > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From nathan.sutton at gmail.com Mon Dec 3 14:28:06 2007 From: nathan.sutton at gmail.com (Nathan Sutton) Date: Mon, 3 Dec 2007 13:28:06 -0600 Subject: [rspec-users] spec for model_id should eql In-Reply-To: <57c63afe0712031123r72adc566i5b131966c423e2a2@mail.gmail.com> References: <307B2AF4-E9C4-427C-BBCD-DD51EC6D6023@gmail.com> <1533E5F7-ADF1-44B1-8B51-13977627E3C2@jlaine.net> <57c63afe0712031123r72adc566i5b131966c423e2a2@mail.gmail.com> Message-ID: <7A34AA27-981A-4E19-B8E0-F8968CA3E2CF@gmail.com> It's worked since I started using rspec, but I started relatively recently, and only on edge. Nathan Sutton fowlduck at gmail.com rspec edge revision 3014 rspec_on_rails edge revision 3014 rails edge revision 8238 On Dec 3, 2007, at 1:23 PM, David Chelimsky wrote: > On Dec 3, 2007 1:18 PM, Jarkko Laine wrote: >> >> On 3.12.2007, at 21.05, Nathan Sutton wrote: >> >>> Department.stub!(:find_by_code).with("75").and_return("3") >> >> You can't use with() with stub! (only with should_receive), so just >> leave it away: >> >> Department.stub!(:find_by_code).and_return("3") > > Actually, you can now, but it's not really documented. > >> >> //jarkko >> >> -- >> Jarkko Laine >> http://jlaine.net >> http://dotherightthing.com >> http://www.railsecommerce.com >> http://odesign.fi >> >> >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From jarkko at jlaine.net Mon Dec 3 15:34:04 2007 From: jarkko at jlaine.net (Jarkko Laine) Date: Mon, 3 Dec 2007 22:34:04 +0200 Subject: [rspec-users] spec for model_id should eql In-Reply-To: <57c63afe0712031123r72adc566i5b131966c423e2a2@mail.gmail.com> References: <307B2AF4-E9C4-427C-BBCD-DD51EC6D6023@gmail.com> <1533E5F7-ADF1-44B1-8B51-13977627E3C2@jlaine.net> <57c63afe0712031123r72adc566i5b131966c423e2a2@mail.gmail.com> Message-ID: <8DC76CCC-3E88-473B-891F-5EF46AD9E26E@jlaine.net> On 3.12.2007, at 21.23, David Chelimsky wrote: > On Dec 3, 2007 1:18 PM, Jarkko Laine wrote: >> >> On 3.12.2007, at 21.05, Nathan Sutton wrote: >> >>> Department.stub!(:find_by_code).with("75").and_return("3") >> >> You can't use with() with stub! (only with should_receive), so just >> leave it away: >> >> Department.stub!(:find_by_code).and_return("3") > > Actually, you can now, but it's not really documented. Oh, cool. I take it back, then :-) //jarkko -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http://odesign.fi From me at danielfischer.com Mon Dec 3 23:26:28 2007 From: me at danielfischer.com (Fischer, Daniel) Date: Mon, 3 Dec 2007 20:26:28 -0800 Subject: [rspec-users] Need help mocking this out In-Reply-To: <2fff50390712030244t25e59b74y176a4876ba8b011e@mail.gmail.com> References: <7e565b5c0712030157s4e56b280l1bcf4621c8c8c7a4@mail.gmail.com> <921ca2f80712030207o7f45771dk15006c3ab5b17ab8@mail.gmail.com> <2fff50390712030244t25e59b74y176a4876ba8b011e@mail.gmail.com> Message-ID: <7e565b5c0712032026s7da64526q2faf6758f2d1a6dd@mail.gmail.com> Hey cool, thanks for the help guys. One problem though, when I take this approach I can't decouple the specs anymore. They all "User_xxx receive unexpected message :articles". It seems silly to include all behaviors in one spec, or put that expectation in each test. Is there a way around this? Thanks for all the help, Daniel Fischer http://www.danielfischer.com On Dec 3, 2007 2:44 AM, Daniel N wrote: > Assuming that there is a call like this in your controller > @articles = current_user.articles > > One way to do this is to stub out the controller.current_user to return a > mock object of the current_user > > Then put an expectation on the current user that it's articles method gets > called. (return a mocked collection of articles) > > Then check that @articles is set to the returned mocked collection of > articles from current_user.articles > > phew... > > Ok So one way you might write this could be (This is untested...) > > it "should scope the articles to the currrent_user" do > > user = mock_model(User) > articles = [mock_model(Article)] > > controller.stub!(:current_user).and_return(user) > user.should_receive (:articles).and_return(articles) > > get :index > > assigns[:articles].should == articles > > end > > Like I said though, that's not tested itself. If that's not exactly > right... it's along the right track of an option that can work. > > HTH > Daniel > > On Dec 3, 2007 9:07 PM, Stefan Magnus Landr? > wrote: > > > Typically, I'd write a method in your user model that returns the user's > > articles: > > > > class User do > > > > def find_articles_for_user > > Article.find(:all, :conditions => ['userid = ?', id) > > end > > > > end > > > > Then you'd use a mock in your controller spec, and make sure you test > > that your method is being called. > > > > On the other hand, the user model should be tested directly against the > > db. > > > > HTH, > > > > Stefan > > > > 2007/12/3, Fischer, Daniel : > > > > > > Let's say you're using the restful_authentication plugin. > > > You have a model called articles. On the index action of the > > > articlescontroller you simply want to spec out that it'll scope the results > > > to the ownership of the current_user. > > > > > > It should NOT include any articles other than the articles that user > > > owns. > > > > > > How would you properly spec this out? > > > > > > Thanks for the help! > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > -- > > Bekk Open Source > > http://boss.bekk.no > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.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/20071203/06371128/attachment.html From me at danielfischer.com Tue Dec 4 00:25:07 2007 From: me at danielfischer.com (Fischer, Daniel) Date: Mon, 3 Dec 2007 21:25:07 -0800 Subject: [rspec-users] Need help mocking this out In-Reply-To: <7e565b5c0712032026s7da64526q2faf6758f2d1a6dd@mail.gmail.com> References: <7e565b5c0712030157s4e56b280l1bcf4621c8c8c7a4@mail.gmail.com> <921ca2f80712030207o7f45771dk15006c3ab5b17ab8@mail.gmail.com> <2fff50390712030244t25e59b74y176a4876ba8b011e@mail.gmail.com> <7e565b5c0712032026s7da64526q2faf6758f2d1a6dd@mail.gmail.com> Message-ID: <7e565b5c0712032125n20aba5f2x81a72898dadd227a@mail.gmail.com> I also have another problem, when I am trying to do the similar strategy for XML based speccing it fails on saying nil.to_xml Arg.. And all it is, is the following => (with a before_filter on login required) but still, it's just current_user. def show @writing = current_user.writings.find(params[:id]) respond_to do |format| format.html format.xml { render :xml => @writing.to_xml } end end http://pastie.textmate.org/private/99vq9ipqb6u8cu5bfirlaa here is the pastie. On Dec 3, 2007 8:26 PM, Fischer, Daniel wrote: > Hey cool, thanks for the help guys. One problem though, when I take this > approach I can't decouple the specs anymore. They all "User_xxx receive > unexpected message :articles". It seems silly to include all behaviors in > one spec, or put that expectation in each test. Is there a way around this? > Thanks for all the help, > Daniel Fischer > http://www.danielfischer.com > > > On Dec 3, 2007 2:44 AM, Daniel N < has.sox at gmail.com> wrote: > > > Assuming that there is a call like this in your controller > > @articles = current_user.articles > > > > One way to do this is to stub out the controller.current_user to return > > a mock object of the current_user > > > > Then put an expectation on the current user that it's articles method > > gets called. (return a mocked collection of articles) > > > > Then check that @articles is set to the returned mocked collection of > > articles from current_user.articles > > > > phew... > > > > Ok So one way you might write this could be (This is untested...) > > > > it "should scope the articles to the currrent_user" do > > > > user = mock_model(User) > > articles = [mock_model(Article)] > > > > controller.stub!(:current_user).and_return(user) > > user.should_receive (:articles).and_return(articles) > > > > get :index > > > > assigns[:articles].should == articles > > > > end > > > > Like I said though, that's not tested itself. If that's not exactly > > right... it's along the right track of an option that can work. > > > > HTH > > Daniel > > > > On Dec 3, 2007 9:07 PM, Stefan Magnus Landr? > > wrote: > > > > > Typically, I'd write a method in your user model that returns the > > > user's articles: > > > > > > class User do > > > > > > def find_articles_for_user > > > Article.find(:all, :conditions => ['userid = ?', id) > > > end > > > > > > end > > > > > > Then you'd use a mock in your controller spec, and make sure you test > > > that your method is being called. > > > > > > On the other hand, the user model should be tested directly against > > > the db. > > > > > > HTH, > > > > > > Stefan > > > > > > 2007/12/3, Fischer, Daniel : > > > > > > > > Let's say you're using the restful_authentication plugin. > > > > You have a model called articles. On the index action of the > > > > articlescontroller you simply want to spec out that it'll scope the results > > > > to the ownership of the current_user. > > > > > > > > It should NOT include any articles other than the articles that user > > > > owns. > > > > > > > > How would you properly spec this out? > > > > > > > > Thanks for the help! > > > > > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > -- > > > Bekk Open Source > > > http://boss.bekk.no > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.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/20071203/85856ef7/attachment.html From dchelimsky at gmail.com Tue Dec 4 00:33:58 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 3 Dec 2007 23:33:58 -0600 Subject: [rspec-users] Need help mocking this out In-Reply-To: <7e565b5c0712032026s7da64526q2faf6758f2d1a6dd@mail.gmail.com> References: <7e565b5c0712030157s4e56b280l1bcf4621c8c8c7a4@mail.gmail.com> <921ca2f80712030207o7f45771dk15006c3ab5b17ab8@mail.gmail.com> <2fff50390712030244t25e59b74y176a4876ba8b011e@mail.gmail.com> <7e565b5c0712032026s7da64526q2faf6758f2d1a6dd@mail.gmail.com> Message-ID: <57c63afe0712032133j2fd73555t235b126c0679eb77@mail.gmail.com> On Dec 3, 2007 10:26 PM, Fischer, Daniel wrote: > Hey cool, thanks for the help guys. One problem though, when I take this > approach I can't decouple the specs anymore. They all "User_xxx receive > unexpected message :articles". It seems silly to include all behaviors in > one spec, or put that expectation in each test. Is there a way around this? Sure. Create a method somewhere that generates a baseline stub for you. module UserControllerSpecHelper def create_stub_user mock_model(User, :articles => []) end end describe UserController, "..." do include UserControllerSpecHelper before(:each) do @user = create_stub_user end end If there are other methods you need to stub on all instances of user, do it in the helper. Then you can use message expectations (mocks) where you need them to describe specific behaviour. HTH, David > > Thanks for all the help, > Daniel Fischer > http://www.danielfischer.com > > > > On Dec 3, 2007 2:44 AM, Daniel N < has.sox at gmail.com> wrote: > > Assuming that there is a call like this in your controller > > > > > > @articles = current_user.articles > > > > > > One way to do this is to stub out the controller.current_user to return a > mock object of the current_user > > > > > > Then put an expectation on the current user that it's articles method gets > called. (return a mocked collection of articles) > > > > > > Then check that @articles is set to the returned mocked collection of > articles from current_user.articles > > > > > > phew... > > > > > > Ok So one way you might write this could be (This is untested...) > > > > > > it "should scope the articles to the currrent_user" do > > > > > > user = mock_model(User) > > articles = [mock_model(Article)] > > > > > > controller.stub!(:current_user).and_return(user) > > > > user.should_receive (:articles).and_return(articles) > > > > get :index > > > > assigns[:articles].should == articles > > > > > > end > > > > > > Like I said though, that's not tested itself. If that's not exactly > right... it's along the right track of an option that can work. > > > > > > HTH > > Daniel > > > > > > > > On Dec 3, 2007 9:07 PM, Stefan Magnus Landr? > wrote: > > > > > > > > > > > Typically, I'd write a method in your user model that returns the user's > articles: > > > > > > class User do > > > > > > def find_articles_for_user > > > Article.find(:all, :conditions => ['userid = ?', id) > > > end > > > > > > end > > > > > > Then you'd use a mock in your controller spec, and make sure you test > that your method is being called. > > > > > > On the other hand, the user model should be tested directly against the > db. > > > > > > HTH, > > > > > > Stefan > > > > > > > > > 2007/12/3, Fischer, Daniel : > > > > > > > > > > > > > > > > Let's say you're using the restful_authentication plugin. > > > > > > > > > > > > You have a model called articles. On the index action of the > articlescontroller you simply want to spec out that it'll scope the results > to the ownership of the current_user. > > > > > > > > > > > > It should NOT include any articles other than the articles that user > owns. > > > > > > > > > > > > How would you properly spec this out? > > > > > > > > > > > > Thanks for the help! > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > -- > > > Bekk Open Source > > > http://boss.bekk.no > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.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 jonathan at parkerhill.com Tue Dec 4 00:41:26 2007 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Tue, 4 Dec 2007 00:41:26 -0500 Subject: [rspec-users] spec'ing shared controller methods Message-ID: <50DA2DB3-5898-4A7F-A8DD-62FC0E93A2F4@parkerhill.com> I want to isolate and spec methods that are shared by controllers, and live in application.rb. Whereas I usually also provide examples in individual controllers that use these methods, not necessarily all the edge cases and I'd like to isolate the examples. This is the approach I'm taking (thanks to bryanl for suggestions and http://pastie.caboo.se/123626). WDYT? This example is a before_filter that finds the Account specified in params[:account_id], which may be used by any number of other controllers in my app. As you can see, the filter is still getting spec'd and has pending examples. ## application.rb class ApplicationController < ActionController::Base ... def find_account @account = Account.find_by_id( params[:account_id]) # TODO: check account status is suspended, closed, different flash message? return( error_redirect_gracefully( "Account not found")) unless @account end ... end ## application_controller_spec.rb require File.dirname(__FILE__) + '/../spec_helper' ActionController::Routing::Routes.draw do |map| map.connect 'foos/:action', :controller => 'foos' end class FoosController < ApplicationController end describe FoosController, "account authorization" do before do FoosController.class_eval do define_method(:foo) { find_account # this is the method being tested } end end it "should find_account from params" do acnt = mock_model(Account) Account.should_receive(:find_by_id).with('99').and_return(acnt) get :foo, :account_id => "99" assigns[:account].should == acnt end it "should redirect gracefully if no account specified" do controller.stub!(:error_redirect_gracefully) controller.should_receive(:error_redirect_gracefully).with ( "Account not found") acnt = mock_model(Account) Account.should_receive(:find_by_id).with(nil).and_return(nil) get :foo end it "should not find accounts that are suspended" it "should flash different message for accounts that are suspended" it "should not find accounts that are closed" end From jonathan at parkerhill.com Tue Dec 4 01:12:57 2007 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Tue, 4 Dec 2007 01:12:57 -0500 Subject: [rspec-users] spec'ing shared controller methods In-Reply-To: <50DA2DB3-5898-4A7F-A8DD-62FC0E93A2F4@parkerhill.com> References: <50DA2DB3-5898-4A7F-A8DD-62FC0E93A2F4@parkerhill.com> Message-ID: <51A484BE-E9B5-43F4-8984-C55A43204C88@parkerhill.com> didnt mean to confuse, i'm asking about the code in the body of the email. The pastie was just for background reference. --J On Dec 4, 2007, at 12:41 AM, Jonathan Linowes wrote: > I want to isolate and spec methods that are shared by controllers, > and live in application.rb. > > Whereas I usually also provide examples in individual controllers > that use these methods, not necessarily all the edge cases and I'd > like to isolate the examples. > > This is the approach I'm taking (thanks to bryanl for suggestions and > http://pastie.caboo.se/123626). WDYT? > > This example is a before_filter that finds the Account specified in > params[:account_id], which may be used by any number of other > controllers in my app. As you can see, the filter is still getting > spec'd and has pending examples. > > ## application.rb > > class ApplicationController < ActionController::Base > ... > def find_account > @account = Account.find_by_id( params[:account_id]) > # TODO: check account status is suspended, closed, different > flash message? > return( error_redirect_gracefully( "Account not found")) unless > @account > end > > ... > end > > ## application_controller_spec.rb > > require File.dirname(__FILE__) + '/../spec_helper' > > ActionController::Routing::Routes.draw do |map| > map.connect 'foos/:action', :controller => 'foos' > end > > class FoosController < ApplicationController > end > > describe FoosController, "account authorization" do > > before do > FoosController.class_eval do > define_method(:foo) { > find_account # this is the method being tested > } > end > end > > it "should find_account from params" do > acnt = mock_model(Account) > Account.should_receive(:find_by_id).with('99').and_return(acnt) > get :foo, :account_id => "99" > assigns[:account].should == acnt > end > > it "should redirect gracefully if no account specified" do > controller.stub!(:error_redirect_gracefully) > controller.should_receive(:error_redirect_gracefully).with > ( "Account not found") > acnt = mock_model(Account) > Account.should_receive(:find_by_id).with(nil).and_return(nil) > get :foo > end > > it "should not find accounts that are suspended" > it "should flash different message for accounts that are suspended" > it "should not find accounts that are closed" > > end > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From me at danielfischer.com Tue Dec 4 01:33:18 2007 From: me at danielfischer.com (Fischer, Daniel) Date: Mon, 3 Dec 2007 22:33:18 -0800 Subject: [rspec-users] Need help mocking this out In-Reply-To: <57c63afe0712032133j2fd73555t235b126c0679eb77@mail.gmail.com> References: <7e565b5c0712030157s4e56b280l1bcf4621c8c8c7a4@mail.gmail.com> <921ca2f80712030207o7f45771dk15006c3ab5b17ab8@mail.gmail.com> <2fff50390712030244t25e59b74y176a4876ba8b011e@mail.gmail.com> <7e565b5c0712032026s7da64526q2faf6758f2d1a6dd@mail.gmail.com> <57c63afe0712032133j2fd73555t235b126c0679eb77@mail.gmail.com> Message-ID: <7e565b5c0712032233q6802e613ma823fc6422b39e3a@mail.gmail.com> Alright, thanks, I'm getting more progress in this. As soon as I figure this out I won't have too many problems.. hopefully. Anyone know what "undefined method `call' for "1":String" means? I'm trying to do this: http://pastie.textmate.org/private/17jjjmbave0ph2mkcgp6w On Dec 3, 2007 9:33 PM, David Chelimsky wrote: > On Dec 3, 2007 10:26 PM, Fischer, Daniel wrote: > > Hey cool, thanks for the help guys. One problem though, when I take this > > approach I can't decouple the specs anymore. They all "User_xxx receive > > unexpected message :articles". It seems silly to include all behaviors > in > > one spec, or put that expectation in each test. Is there a way around > this? > > Sure. Create a method somewhere that generates a baseline stub for you. > > module UserControllerSpecHelper > def create_stub_user > mock_model(User, :articles => []) > end > end > > describe UserController, "..." do > include UserControllerSpecHelper > before(:each) do > @user = create_stub_user > end > end > > If there are other methods you need to stub on all instances of user, > do it in the helper. Then you can use message expectations (mocks) > where you need them to describe specific behaviour. > > HTH, > David > > > > > Thanks for all the help, > > Daniel Fischer > > http://www.danielfischer.com > > > > > > > > On Dec 3, 2007 2:44 AM, Daniel N < has.sox at gmail.com> wrote: > > > Assuming that there is a call like this in your controller > > > > > > > > > @articles = current_user.articles > > > > > > > > > One way to do this is to stub out the controller.current_user to > return a > > mock object of the current_user > > > > > > > > > Then put an expectation on the current user that it's articles method > gets > > called. (return a mocked collection of articles) > > > > > > > > > Then check that @articles is set to the returned mocked collection of > > articles from current_user.articles > > > > > > > > > phew... > > > > > > > > > Ok So one way you might write this could be (This is untested...) > > > > > > > > > it "should scope the articles to the currrent_user" do > > > > > > > > > user = mock_model(User) > > > articles = [mock_model(Article)] > > > > > > > > > controller.stub!(:current_user).and_return(user) > > > > > > user.should_receive (:articles).and_return(articles) > > > > > > get :index > > > > > > assigns[:articles].should == articles > > > > > > > > > end > > > > > > > > > Like I said though, that's not tested itself. If that's not exactly > > right... it's along the right track of an option that can work. > > > > > > > > > HTH > > > Daniel > > > > > > > > > > > > On Dec 3, 2007 9:07 PM, Stefan Magnus Landr? > > wrote: > > > > > > > > > > > > > > > > Typically, I'd write a method in your user model that returns the > user's > > articles: > > > > > > > > class User do > > > > > > > > def find_articles_for_user > > > > Article.find(:all, :conditions => ['userid = ?', id) > > > > end > > > > > > > > end > > > > > > > > Then you'd use a mock in your controller spec, and make sure you > test > > that your method is being called. > > > > > > > > On the other hand, the user model should be tested directly against > the > > db. > > > > > > > > HTH, > > > > > > > > Stefan > > > > > > > > > > > > 2007/12/3, Fischer, Daniel : > > > > > > > > > > > > > > > > > > > > Let's say you're using the restful_authentication plugin. > > > > > > > > > > > > > > > You have a model called articles. On the index action of the > > articlescontroller you simply want to spec out that it'll scope the > results > > to the ownership of the current_user. > > > > > > > > > > > > > > > It should NOT include any articles other than the articles that > user > > owns. > > > > > > > > > > > > > > > How would you properly spec this out? > > > > > > > > > > > > > > > Thanks for the help! > > > > > _______________________________________________ > > > > > rspec-users mailing list > > > > > rspec-users at rubyforge.org > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > > > > > > -- > > > > Bekk Open Source > > > > http://boss.bekk.no > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.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/20071203/ced91e2a/attachment.html From me at danielfischer.com Tue Dec 4 01:40:55 2007 From: me at danielfischer.com (Fischer, Daniel) Date: Mon, 3 Dec 2007 22:40:55 -0800 Subject: [rspec-users] Need help mocking this out In-Reply-To: <7e565b5c0712032233q6802e613ma823fc6422b39e3a@mail.gmail.com> References: <7e565b5c0712030157s4e56b280l1bcf4621c8c8c7a4@mail.gmail.com> <921ca2f80712030207o7f45771dk15006c3ab5b17ab8@mail.gmail.com> <2fff50390712030244t25e59b74y176a4876ba8b011e@mail.gmail.com> <7e565b5c0712032026s7da64526q2faf6758f2d1a6dd@mail.gmail.com> <57c63afe0712032133j2fd73555t235b126c0679eb77@mail.gmail.com> <7e565b5c0712032233q6802e613ma823fc6422b39e3a@mail.gmail.com> Message-ID: <7e565b5c0712032240i45ea4e8ck63cb6b0f74e32051@mail.gmail.com> Sorry for so many messages, I hope I don't get in trouble for this. Maybe IRC would be better if there was a RSpec one. Anyway, the previous problem was solved with the following http://pastie.textmate.org/private/m6qqfd7tzeanw2yar8rua The problem was caused by : @user = mock_model(User, :writings => [] ) I'm not sure if that is a bug or what, but that's what caused it. It'd also say "no block given" if I put something there other than a "mock". On Dec 3, 2007 10:33 PM, Fischer, Daniel wrote: > Alright, thanks, I'm getting more progress in this. As soon as I figure > this out I won't have too many problems.. hopefully. > Anyone know what "undefined method `call' for "1":String" means? > > I'm trying to do this: > > http://pastie.textmate.org/private/17jjjmbave0ph2mkcgp6w > > > On Dec 3, 2007 9:33 PM, David Chelimsky wrote: > > > On Dec 3, 2007 10:26 PM, Fischer, Daniel wrote: > > > Hey cool, thanks for the help guys. One problem though, when I take > > this > > > approach I can't decouple the specs anymore. They all "User_xxx > > receive > > > unexpected message :articles". It seems silly to include all behaviors > > in > > > one spec, or put that expectation in each test. Is there a way around > > this? > > > > Sure. Create a method somewhere that generates a baseline stub for you. > > > > module UserControllerSpecHelper > > def create_stub_user > > mock_model(User, :articles => []) > > end > > end > > > > describe UserController, "..." do > > include UserControllerSpecHelper > > before(:each) do > > @user = create_stub_user > > end > > end > > > > If there are other methods you need to stub on all instances of user, > > do it in the helper. Then you can use message expectations (mocks) > > where you need them to describe specific behaviour. > > > > HTH, > > David > > > > > > > > Thanks for all the help, > > > Daniel Fischer > > > http://www.danielfischer.com > > > > > > > > > > > > On Dec 3, 2007 2:44 AM, Daniel N < has.sox at gmail.com> wrote: > > > > Assuming that there is a call like this in your controller > > > > > > > > > > > > @articles = current_user.articles > > > > > > > > > > > > One way to do this is to stub out the controller.current_user to > > return a > > > mock object of the current_user > > > > > > > > > > > > Then put an expectation on the current user that it's articles > > method gets > > > called. (return a mocked collection of articles) > > > > > > > > > > > > Then check that @articles is set to the returned mocked collection > > of > > > articles from current_user.articles > > > > > > > > > > > > phew... > > > > > > > > > > > > Ok So one way you might write this could be (This is untested...) > > > > > > > > > > > > it "should scope the articles to the currrent_user" do > > > > > > > > > > > > user = mock_model(User) > > > > articles = [mock_model(Article)] > > > > > > > > > > > > controller.stub!(:current_user).and_return(user) > > > > > > > > user.should_receive (:articles).and_return(articles) > > > > > > > > get :index > > > > > > > > assigns[:articles].should == articles > > > > > > > > > > > > end > > > > > > > > > > > > Like I said though, that's not tested itself. If that's not exactly > > > right... it's along the right track of an option that can work. > > > > > > > > > > > > HTH > > > > Daniel > > > > > > > > > > > > > > > > On Dec 3, 2007 9:07 PM, Stefan Magnus Landr? > > > > > wrote: > > > > > > > > > > > > > > > > > > > > > Typically, I'd write a method in your user model that returns the > > user's > > > articles: > > > > > > > > > > class User do > > > > > > > > > > def find_articles_for_user > > > > > Article.find(:all, :conditions => ['userid = ?', id) > > > > > end > > > > > > > > > > end > > > > > > > > > > Then you'd use a mock in your controller spec, and make sure you > > test > > > that your method is being called. > > > > > > > > > > On the other hand, the user model should be tested directly > > against the > > > db. > > > > > > > > > > HTH, > > > > > > > > > > Stefan > > > > > > > > > > > > > > > 2007/12/3, Fischer, Daniel < daniel at helpmebuyacar.org>: > > > > > > > > > > > > > > > > > > > > > > > > Let's say you're using the restful_authentication plugin. > > > > > > > > > > > > > > > > > > You have a model called articles. On the index action of the > > > articlescontroller you simply want to spec out that it'll scope the > > results > > > to the ownership of the current_user. > > > > > > > > > > > > > > > > > > It should NOT include any articles other than the articles that > > user > > > owns. > > > > > > > > > > > > > > > > > > How would you properly spec this out? > > > > > > > > > > > > > > > > > > Thanks for the help! > > > > > > _______________________________________________ > > > > > > rspec-users mailing list > > > > > > rspec-users at rubyforge.org > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > > > > > > > > > > > -- > > > > > Bekk Open Source > > > > > http://boss.bekk.no > > > > > _______________________________________________ > > > > > rspec-users mailing list > > > > > rspec-users at rubyforge.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/20071203/83b97e7b/attachment-0001.html From jarkko at jlaine.net Tue Dec 4 02:40:23 2007 From: jarkko at jlaine.net (Jarkko Laine) Date: Tue, 4 Dec 2007 09:40:23 +0200 Subject: [rspec-users] Need help mocking this out In-Reply-To: <7e565b5c0712032240i45ea4e8ck63cb6b0f74e32051@mail.gmail.com> References: <7e565b5c0712030157s4e56b280l1bcf4621c8c8c7a4@mail.gmail.com> <921ca2f80712030207o7f45771dk15006c3ab5b17ab8@mail.gmail.com> <2fff50390712030244t25e59b74y176a4876ba8b011e@mail.gmail.com> <7e565b5c0712032026s7da64526q2faf6758f2d1a6dd@mail.gmail.com> <57c63afe0712032133j2fd73555t235b126c0679eb77@mail.gmail.com> <7e565b5c0712032233q6802e613ma823fc6422b39e3a@mail.gmail.com> <7e565b5c0712032240i45ea4e8ck63cb6b0f74e32051@mail.gmail.com> Message-ID: On 4.12.2007, at 8.40, Fischer, Daniel wrote: > Sorry for so many messages, I hope I don't get in trouble for this. > Maybe IRC would be better if there was a RSpec one. #rspec @freenode //jarkko -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http://odesign.fi From hotfusionman at yahoo.com Tue Dec 4 03:17:40 2007 From: hotfusionman at yahoo.com (Al Chou) Date: Tue, 4 Dec 2007 00:17:40 -0800 (PST) Subject: [rspec-users] params not available for controller specs? Message-ID: <493757.46829.qm@web58713.mail.re1.yahoo.com> Hi, all, I'm trying to write a spec for a controller method that starts out: def download @orders = Order.find( params[:ids] ) ... and started writing a spec that set params[:ids] to a mock. I was surprised to discover that controller specs (at least in RSpec 1.0.8) don't offer the use of the params object (per http://rspec.rubyforge.org/documentation/rails/writing/controllers.html), though assigns, flash, and session are available. Maybe I'm missing something, but it seems to me that it would be helpful if controller specs could use params also.... Al ____________________________________________________________________________________ Looking for last minute shopping deals? Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071204/027571ab/attachment.html From jarkko at jlaine.net Tue Dec 4 03:33:11 2007 From: jarkko at jlaine.net (Jarkko Laine) Date: Tue, 4 Dec 2007 10:33:11 +0200 Subject: [rspec-users] params not available for controller specs? In-Reply-To: <493757.46829.qm@web58713.mail.re1.yahoo.com> References: <493757.46829.qm@web58713.mail.re1.yahoo.com> Message-ID: On 4.12.2007, at 10.17, Al Chou wrote: > Hi, all, > > I'm trying to write a spec for a controller method that starts out: > > > def download > @orders = Order.find( params[:ids] ) > ... > > and started writing a spec that set params[:ids] to a mock. Why would you want to set params[:ids] to a mock? params values are always basically strings (or hashes/arrays of strings) and you can set them in the actual action call: get :foo, :ids => [1,2,3] Moreover, in your case Order.find should be the thing you want to stub. You don't want the finder call to go to the database, since you're speccing the controller behaviour here, not business logic. //jarkko -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http://odesign.fi From hotfusionman at yahoo.com Tue Dec 4 04:28:40 2007 From: hotfusionman at yahoo.com (Al Chou) Date: Tue, 4 Dec 2007 01:28:40 -0800 (PST) Subject: [rspec-users] params not available for controller specs? Message-ID: <723651.16277.qm@web58704.mail.re1.yahoo.com> I actually did stub Order.find() but was getting a nil object error because params[:ids] was nil. I can't write controller.download :ids => '1/2/3' in the controller spec, and get download, :ids => ids_string results in the following error message: NameError in 'Admin::OrdersController should split the params[:ids] string to create an array of id's to find for downloading' undefined local variable or method `download' for [RSpec example]:# ./spec/controllers/admin/orders_controller_spec.rb:14: Al ----- Original Message ---- From: Jarkko Laine To: rspec-users Sent: Tuesday, December 4, 2007 12:33:11 AM Subject: Re: [rspec-users] params not available for controller specs? On 4.12.2007, at 10.17, Al Chou wrote: > Hi, all, > > I'm trying to write a spec for a controller method that starts out: > > > def download > @orders = Order.find( params[:ids] ) > ... > > and started writing a spec that set params[:ids] to a mock. Why would you want to set params[:ids] to a mock? params values are always basically strings (or hashes/arrays of strings) and you can set them in the actual action call: get :foo, :ids => [1,2,3] Moreover, in your case Order.find should be the thing you want to stub. You don't want the finder call to go to the database, since you're speccing the controller behaviour here, not business logic. //jarkko -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http://odesign.fi _______________________________________________ rspec-users mailing list rspec-users at rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users ____________________________________________________________________________________ Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071204/4ad4f71a/attachment.html From daniel.ruby at tenner.org Tue Dec 4 04:56:25 2007 From: daniel.ruby at tenner.org (Daniel Tenner) Date: Tue, 4 Dec 2007 09:56:25 +0000 Subject: [rspec-users] params not available for controller specs? In-Reply-To: <723651.16277.qm@web58704.mail.re1.yahoo.com> References: <723651.16277.qm@web58704.mail.re1.yahoo.com> Message-ID: <8F81CD13-EA40-48D7-9766-E0FC880D090D@tenner.org> Try: get :download, :ids => ids_string You need the ":" in front of the action name. Daniel On 4 Dec 2007, at 09:28 4 Dec 2007, Al Chou wrote: > I actually did stub Order.find() but was getting a nil object error > because params[:ids] was nil. I can't write > > controller.download :ids => '1/2/3' > > in the controller spec, and > > get download, :ids => ids_string > > results in the following error message: > > NameError in 'Admin::OrdersController should split the params[:ids] > string to create an array of id's to find for downloading' > undefined local variable or method `download' for [RSpec > example]:# > ./spec/controllers/admin/orders_controller_spec.rb:14: > > > Al > > ----- Original Message ---- > From: Jarkko Laine > To: rspec-users > Sent: Tuesday, December 4, 2007 12:33:11 AM > Subject: Re: [rspec-users] params not available for controller specs? > > > On 4.12.2007, at 10.17, Al Chou wrote: > > > Hi, all, > > > > I'm trying to write a spec for a controller method that starts out: > > > > > > def download > > @orders = Order.find( params[:ids] ) > > ... > > > > and started writing a spec that set params[:ids] to a mock. > > Why would you want to set params[:ids] to a mock? params values are > always basically strings (or hashes/arrays of strings) and you can set > them in the actual action call: > > get :foo, :ids => [1,2,3] > > Moreover, in your case Order.find should be the thing you want to > stub. You don't want the finder call to go to the database, since > you're speccing the controller behaviour here, not business logic. > > //jarkko > > -- > Jarkko Laine > http://jlaine.net > http://dotherightthing.com > http://www.railsecommerce.com > http://odesign.fi > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > Never miss a thing. Make Yahoo your homepage. > _______________________________________________ > 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/20071204/49a1610a/attachment.html From hotfusionman at yahoo.com Tue Dec 4 10:13:14 2007 From: hotfusionman at yahoo.com (Al Chou) Date: Tue, 4 Dec 2007 07:13:14 -0800 (PST) Subject: [rspec-users] params not available for controller specs? Message-ID: <168417.96403.qm@web58715.mail.re1.yahoo.com> Ah, thanks! That was a breakthrough. My mock object "ids_string" isn't receiving the method calls I expect (even though the code under test actually does what I want it to do and works correctly), but at least I'm past the params issue. Al ----- Original Message ---- From: Daniel Tenner To: rspec-users Sent: Tuesday, December 4, 2007 1:56:25 AM Subject: Re: [rspec-users] params not available for controller specs? Try: get :download, :ids => ids_string You need the ":" in front of the action name. Daniel On 4 Dec 2007, at 09:28 4 Dec 2007, Al Chou wrote: I actually did stub Order.find() but was getting a nil object error because params[:ids] was nil. I can't write controller.download :ids => '1/2/3' in the controller spec, and get download, :ids => ids_string results in the following error message: NameError in 'Admin::OrdersController should split the params[:ids] string to create an array of id's to find for downloading' undefined local variable or method `download' for [RSpec example]:# ./spec/controllers/admin/orders_controller_spec.rb:14: Al ----- Original Message ---- From: Jarkko Laine To: rspec-users Sent: Tuesday, December 4, 2007 12:33:11 AM Subject: Re: [rspec-users] params not available for controller specs? On 4.12.2007, at 10.17, Al Chou wrote: > Hi, all, > > I'm trying to write a spec for a controller method that starts out: > > > def download > @orders = Order.find( params[:ids] ) > ... > > and started writing a spec that set params[:ids] to a mock. Why would you want to set params[:ids] to a mock? params values are always basically strings (or hashes/arrays of strings) and you can set them in the actual action call: get :foo, :ids => [1,2,3] Moreover, in your case Order.find should be the thing you want to stub. You don't want the finder call to go to the database, since you're speccing the controller behaviour here, not business logic. //jarkko -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http://odesign.fi _______________________________________________ rspec-users mailing list rspec-users at rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users ____________________________________________________________________________________ Looking for last minute shopping deals? Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071204/68c50619/attachment-0001.html From jarkko at jlaine.net Tue Dec 4 10:31:11 2007 From: jarkko at jlaine.net (Jarkko Laine) Date: Tue, 4 Dec 2007 17:31:11 +0200 Subject: [rspec-users] params not available for controller specs? In-Reply-To: <168417.96403.qm@web58715.mail.re1.yahoo.com> References: <168417.96403.qm@web58715.mail.re1.yahoo.com> Message-ID: On 4.12.2007, at 17.13, Al Chou wrote: > Ah, thanks! That was a breakthrough. My mock object "ids_string" > isn't receiving the method calls I expect (even though the code > under test actually does what I want it to do and works correctly), > but at least I'm past the params issue. You don't get the same object through the action queue, which is another reason for not mocking something there. "string 1" is not necessarily the same object as "string 1" and Rails will do a lot of processing to the parameters before they end up in the params hash. Just assume that a similar string will get passed through and spec that the behaviour is what you expect. What kind of method calls are you expecting/stubbing for a string? //jarkko -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http://odesign.fi From andy at adveho.net Tue Dec 4 10:41:40 2007 From: andy at adveho.net (Andy Goundry) Date: Tue, 4 Dec 2007 15:41:40 +0000 Subject: [rspec-users] Newbie question Message-ID: <139c56460712040741rce7a10eic06704bf71543351@mail.gmail.com> Good day all :-) I am getting into RSpec and am a little confused by an aspect of mocks / mock_models in controller tests. I've gone through the online docs and the PeepCode movies and have them slightly contradictory on this matter. I hope you can clarify. Many thanks in advance :-) I'm writing a system that uses the restful authentication plugin and am writing a test for the following controller create method: class AccountsController < ApplicationController def create @account = Account.new(params[:account]) if @account.save! self.current_account = @account redirect_back_or_default('/') flash[:notice] = "Thanks for signing up!" end rescue ActiveRecord::RecordInvalid render :action => 'new' end ... end I've created the following spec test to simply ensure that the Account model receives a call to :new, but the spec is failing as it also receives a call to :save! and it isn't expecting it. I am using "@account = mock_model(Account)". If i replace this with "@account = mock('account', :null_object => true)" the test passes, but i'm not sure that's really what i want. I'm pretty sure i need to us mock_model in this instance. The code is below. Also, are my use of comment blocks within the spec against the RSpec *way*. I appreciate that this isn't using fixtures and i might use them later. I also appreciate that i can write modules to contain these methods, but i can't quite see the point in muddying things. Comments most welcome. Thanks describe AccountsController, "allows users to create only valid accounts" do ####### ### Reusable methods ####### def do_post(params = nil) post :create, :account => params end def valid_account_form_details { :password => "password", :password_confirmation => "password", :login => "new_login", :email => "test at test.com" } end ####### ### Before block ####### before do @account = mock_model(Account) Account.stub!(:new).and_return(@account) end ####### ### It Statements ####### it "should display the new account template when the user visits /accounts/new" do get 'new' response.should render_template(:new) end it "should tell the Account model to create a new account on form POST" do Account.should_receive(:new).with(:anything).and_return(@account) do_post end -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071204/151ae095/attachment.html From tom at experthuman.com Tue Dec 4 10:58:03 2007 From: tom at experthuman.com (Tom Stuart) Date: Tue, 4 Dec 2007 15:58:03 +0000 Subject: [rspec-users] Newbie question In-Reply-To: <139c56460712040741rce7a10eic06704bf71543351@mail.gmail.com> References: <139c56460712040741rce7a10eic06704bf71543351@mail.gmail.com> Message-ID: On 4 Dec 2007, at 15:41, Andy Goundry wrote: > I've created the following spec test to simply ensure that the > Account model receives a call to :new, but the spec is failing as it > also receives a call to :save! and it isn't expecting it. I am using > "@account = mock_model(Account)". If i replace this with "@account = > mock('account', :null_object => true)" the test passes, but i'm not > sure that's really what i want. I'm pretty sure i need to us > mock_model in this instance. mock_model doesn't do anything magic -- it just creates a mock (with a conveniently-chosen name) and stubs out a few useful methods for you. In your case you need to stub out #save! too, so that you don't get the failure: @account = mock_model(Account, :save! => true). Cheers, -Tom From andy at adveho.net Tue Dec 4 11:06:23 2007 From: andy at adveho.net (Andy Goundry) Date: Tue, 4 Dec 2007 16:06:23 +0000 Subject: [rspec-users] Newbie question In-Reply-To: References: <139c56460712040741rce7a10eic06704bf71543351@mail.gmail.com> Message-ID: <139c56460712040806v18475da9p42ab6de278feefcb@mail.gmail.com> cheers Tom. That worked. I'll go dig in the rspec source... On 04/12/2007, Tom Stuart wrote: > > On 4 Dec 2007, at 15:41, Andy Goundry wrote: > > I've created the following spec test to simply ensure that the > > Account model receives a call to :new, but the spec is failing as it > > also receives a call to :save! and it isn't expecting it. I am using > > "@account = mock_model(Account)". If i replace this with "@account = > > mock('account', :null_object => true)" the test passes, but i'm not > > sure that's really what i want. I'm pretty sure i need to us > > mock_model in this instance. > > mock_model doesn't do anything magic -- it just creates a mock (with a > conveniently-chosen name) and stubs out a few useful methods for you. > In your case you need to stub out #save! too, so that you don't get > the failure: @account = mock_model(Account, :save! => true). > > Cheers, > -Tom > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071204/2e0862a9/attachment.html From hotfusionman at yahoo.com Tue Dec 4 11:19:04 2007 From: hotfusionman at yahoo.com (Al Chou) Date: Tue, 4 Dec 2007 08:19:04 -0800 (PST) Subject: [rspec-users] params not available for controller specs? Message-ID: <472037.76178.qm@web58711.mail.re1.yahoo.com> Going back to my original message, I have the following at the beginning of the download method: def download @orders = Order.find( params[:ids] ) ... The problem is that params[:ids], although built as an Array object by the view that calls the download method on the controller, is passed as a /-delimited string of id values. Order.find() will not do the desired thing with that string, which was intended to be an array by the view, but Rails passed it in a string representation. So the method really should be def download @orders = Order.find( params[:ids].split( '/' ) ) and what I'm trying to spec is the addition of the call to split(). Al ----- Original Message ---- From: Jarkko Laine To: rspec-users Sent: Tuesday, December 4, 2007 7:31:11 AM Subject: Re: [rspec-users] params not available for controller specs? On 4.12.2007, at 17.13, Al Chou wrote: > Ah, thanks! That was a breakthrough. My mock object "ids_string" > isn't receiving the method calls I expect (even though the code > under test actually does what I want it to do and works correctly), > but at least I'm past the params issue. You don't get the same object through the action queue, which is another reason for not mocking something there. "string 1" is not necessarily the same object as "string 1" and Rails will do a lot of processing to the parameters before they end up in the params hash. Just assume that a similar string will get passed through and spec that the behaviour is what you expect. What kind of method calls are you expecting/stubbing for a string? //jarkko -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http://odesign.fi _______________________________________________ rspec-users mailing list rspec-users at rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users ____________________________________________________________________________________ Never miss a thing. Make Yahoo your home page. http://www.yahoo.com/r/hs -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071204/dab6cd6b/attachment.html From jarkko at jlaine.net Tue Dec 4 13:09:01 2007 From: jarkko at jlaine.net (Jarkko Laine) Date: Tue, 4 Dec 2007 20:09:01 +0200 Subject: [rspec-users] params not available for controller specs? In-Reply-To: <472037.76178.qm@web58711.mail.re1.yahoo.com> References: <472037.76178.qm@web58711.mail.re1.yahoo.com> Message-ID: <9A7C4BDD-2788-4F18-946D-7247BE306C13@jlaine.net> On 4.12.2007, at 18.19, Al Chou wrote: > Going back to my original message, I have the following at the > beginning of the download method: > > def download > @orders = Order.find( params[:ids] ) > ... > > The problem is that params[:ids], although built as an Array object > by the view that calls the download method on the controller, is > passed as a /-delimited string of id values. If I set <%= link_to "Test", :controller => "clients", :foo => [1, 2, 3, 4, 5] %> I get this as the url: http://localhost:3000/en/clients?foo%5B%5D=1&foo%5B%5D=2&foo%5B%5D=3&foo%5B%5D=4&foo%5B%5D=5 That will get correctly parsed back to an array in the receiving action: Parameters: {"action"=>"index", "foo"=>["1", "2", "3", "4", "5"], "controller"=>"clients", "locale"=>"en"} This is Edge Rails, though, so YMMV. > Order.find() will not do the desired thing with that string, which > was intended to be an array by the view, but Rails passed it in a > string representation. So the method really should be > > def download > @orders = Order.find( params[:ids].split( '/' ) ) > > and what I'm trying to spec is the addition of the call to split(). IMHO there's no need to stub string methods like that. Just do something like this: Order.should_receive(:find).with(%w(1 2 3)).and_return(@some_order_objects) If params[:ids] is "1/2/3", you can be pretty certain that split("/") will work correctly so you're more interested in that the find method gets called with correct set of attributes, an array. It's not really interesting how that array got to be. In this case, you might notice that somehow params[:ids] is an array after all and you can take the split call away, and the spec will still pass. I guess what I'm trying to say is that the split call is part of the controller action's internal implementation, and you should be spec'ing how it behaves related to its surrounding world: fetches stuff from the business model, assigns objects for the view etc. //jarkko -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http://odesign.fi From schleg at gmail.com Tue Dec 4 12:49:55 2007 From: schleg at gmail.com (schleg) Date: Tue, 4 Dec 2007 09:49:55 -0800 (PST) Subject: [rspec-users] Unexpected message on :attr_accessor Message-ID: <14155614.post@talk.nabble.com> This may be a dumb noob issue, but I haven't found any answers while seaching the forum-- I have a controller method def edit @user = User.find params[:id] @user.password_confirmation = @user.password end The User class has an "attr_accessor :password_confirmation" definition (so "password_confirmation" doesn't exist in the users table). My spec has the following it "should find User on GET to users/edit/:id" do User.should_receive(:find).and_return(@user) @user.should_receive(:password_confirmation) get 'edit', :id => @user.id end I am asking it to expect that I will be assigning something to that attribute in the "edit" method. Unfortunately, the spec fails with Spec::Mocks::MockExpectationError in 'UsersController should find User on GET to users/edit/:id' Mock 'user' received unexpected message :password_confirmation= with ("password") Initially I thought that my "should_receive" expectation was incorrectly written, but if I comment out the attribute assignment in the controller method ... @user = User.find params[:id] #@user.password_confirmation = @user.password ... then the test fails with Spec::Mocks::MockExpectationError in 'UsersController should find User on GET to users/edit/:id' Mock 'user' expected :password_confirmation with (any args) once, but received it 0 times So, it seems to me that the expectation is written correctly, but something about using the attr_accessor via the mock object is causing a failure. BTW, I am doing the following in a before(:each) block @user = mock("user") @user.stub!(:new_record?).and_return(false) @user.stub!(:update_attributes).and_return(true) @user.stub!(:password_confirmation).and_return('password') @user.stub!(:password).and_return('password') User.stub!(:new).and_return(@user) Does anyone know what I'm missing here? Thanks! -- View this message in context: http://www.nabble.com/Unexpected-message-on-%3Aattr_accessor-tf4944588.html#a14155614 Sent from the rspec-users mailing list archive at Nabble.com. From dchelimsky at gmail.com Tue Dec 4 14:02:46 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 4 Dec 2007 13:02:46 -0600 Subject: [rspec-users] Unexpected message on :attr_accessor In-Reply-To: <14155614.post@talk.nabble.com> References: <14155614.post@talk.nabble.com> Message-ID: <57c63afe0712041102n1c2a4554y1bf13308b8924a78@mail.gmail.com> On Dec 4, 2007 11:49 AM, schleg wrote: > > This may be a dumb noob issue, but I haven't found any answers while seaching > the forum-- > > I have a controller method > > def edit > @user = User.find params[:id] > @user.password_confirmation = @user.password > end > > The User class has an "attr_accessor :password_confirmation" definition (so > "password_confirmation" doesn't exist in the users table). My spec has the > following > > it "should find User on GET to users/edit/:id" do > User.should_receive(:find).and_return(@user) > @user.should_receive(:password_confirmation) This should be: @user.should_receive(:password_confirmation=) Cheers, David > get 'edit', :id => @user.id > end > > I am asking it to expect that I will be assigning something to that > attribute in the "edit" method. Unfortunately, the spec fails with > > Spec::Mocks::MockExpectationError in 'UsersController should find User on > GET to users/edit/:id' > Mock 'user' received unexpected message :password_confirmation= with > ("password") > > Initially I thought that my "should_receive" expectation was incorrectly > written, but if I comment out the attribute assignment in the controller > method > > ... > @user = User.find params[:id] > #@user.password_confirmation = @user.password > ... > > then the test fails with > > Spec::Mocks::MockExpectationError in 'UsersController should find User on > GET to users/edit/:id' > Mock 'user' expected :password_confirmation with (any args) once, but > received it 0 times > > So, it seems to me that the expectation is written correctly, but something > about using the attr_accessor via the mock object is causing a failure. > > BTW, I am doing the following in a before(:each) block > > @user = mock("user") > @user.stub!(:new_record?).and_return(false) > @user.stub!(:update_attributes).and_return(true) > @user.stub!(:password_confirmation).and_return('password') > @user.stub!(:password).and_return('password') > User.stub!(:new).and_return(@user) > > Does anyone know what I'm missing here? > > Thanks! > -- > View this message in context: http://www.nabble.com/Unexpected-message-on-%3Aattr_accessor-tf4944588.html#a14155614 > 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 aslak.hellesoy at gmail.com Tue Dec 4 14:27:39 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 4 Dec 2007 20:27:39 +0100 Subject: [rspec-users] Unexpected message on :attr_accessor In-Reply-To: <57c63afe0712041102n1c2a4554y1bf13308b8924a78@mail.gmail.com> References: <14155614.post@talk.nabble.com> <57c63afe0712041102n1c2a4554y1bf13308b8924a78@mail.gmail.com> Message-ID: <8d961d900712041127jb60e417w558daf867fc5a87f@mail.gmail.com> On Dec 4, 2007 8:02 PM, David Chelimsky wrote: > On Dec 4, 2007 11:49 AM, schleg wrote: > > > > This may be a dumb noob issue, but I haven't found any answers while seaching > > the forum-- > > > > I have a controller method > > > > def edit > > @user = User.find params[:id] > > @user.password_confirmation = @user.password > > end > > > > The User class has an "attr_accessor :password_confirmation" definition (so > > "password_confirmation" doesn't exist in the users table). My spec has the > > following > > > > it "should find User on GET to users/edit/:id" do > > User.should_receive(:find).and_return(@user) > > @user.should_receive(:password_confirmation) > > This should be: > > @user.should_receive(:password_confirmation=) > Lots of beginners make this mistake. Maybe RSpec's mock framework should be smart enough to suggest this fix by itself. Patch anyone? Aslak > Cheers, > David > > > > get 'edit', :id => @user.id > > end > > > > I am asking it to expect that I will be assigning something to that > > attribute in the "edit" method. Unfortunately, the spec fails with > > > > Spec::Mocks::MockExpectationError in 'UsersController should find User on > > GET to users/edit/:id' > > Mock 'user' received unexpected message :password_confirmation= with > > ("password") > > > > Initially I thought that my "should_receive" expectation was incorrectly > > written, but if I comment out the attribute assignment in the controller > > method > > > > ... > > @user = User.find params[:id] > > #@user.password_confirmation = @user.password > > ... > > > > then the test fails with > > > > Spec::Mocks::MockExpectationError in 'UsersController should find User on > > GET to users/edit/:id' > > Mock 'user' expected :password_confirmation with (any args) once, but > > received it 0 times > > > > So, it seems to me that the expectation is written correctly, but something > > about using the attr_accessor via the mock object is causing a failure. > > > > BTW, I am doing the following in a before(:each) block > > > > @user = mock("user") > > @user.stub!(:new_record?).and_return(false) > > @user.stub!(:update_attributes).and_return(true) > > @user.stub!(:password_confirmation).and_return('password') > > @user.stub!(:password).and_return('password') > > User.stub!(:new).and_return(@user) > > > > Does anyone know what I'm missing here? > > > > Thanks! > > -- > > View this message in context: http://www.nabble.com/Unexpected-message-on-%3Aattr_accessor-tf4944588.html#a14155614 > > 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 hotfusionman at yahoo.com Tue Dec 4 15:09:42 2007 From: hotfusionman at yahoo.com (Al Chou) Date: Tue, 4 Dec 2007 12:09:42 -0800 (PST) Subject: [rspec-users] params not available for controller specs? Message-ID: <606252.81870.qm@web58704.mail.re1.yahoo.com> I get what you're saying, but I was trying to fix a bug in existing code in Substruct (that I did not write) that was caused by Rails passing the array as a /-delimited string and then not automatically decoding that string. As Substruct does not say that Edge Rails is a requirement, I felt it was worth documenting what I had to change to run it on Rails 1.2.x. Every code change should be driven by a test or example; perhaps in this situation I should've gone over to Test::Unit instead of staying in RSpec? An interesting philosophical thought.... Al ----- Original Message ---- From: Jarkko Laine To: rspec-users Sent: Tuesday, December 4, 2007 10:09:01 AM Subject: Re: [rspec-users] params not available for controller specs? On 4.12.2007, at 18.19, Al Chou wrote: > Going back to my original message, I have the following at the > beginning of the download method: > > def download > @orders = Order.find( params[:ids] ) > ... > > The problem is that params[:ids], although built as an Array object > by the view that calls the download method on the controller, is > passed as a /-delimited string of id values. If I set <%= link_to "Test", :controller => "clients", :foo => [1, 2, 3, 4, 5] %> I get this as the url: http://localhost:3000/en/clients?foo%5B%5D=1&foo%5B%5D=2&foo%5B%5D=3&foo%5B%5D=4&foo%5B%5D=5 That will get correctly parsed back to an array in the receiving action: Parameters: {"action"=>"index", "foo"=>["1", "2", "3", "4", "5"], "controller"=>"clients", "locale"=>"en"} This is Edge Rails, though, so YMMV. > Order.find() will not do the desired thing with that string, which > was intended to be an array by the view, but Rails passed it in a > string representation. So the method really should be > > def download > @orders = Order.find( params[:ids].split( '/' ) ) > > and what I'm trying to spec is the addition of the call to split(). IMHO there's no need to stub string methods like that. Just do something like this: Order.should_receive(:find).with(%w(1 2 3)).and_return(@some_order_objects) If params[:ids] is "1/2/3", you can be pretty certain that split("/") will work correctly so you're more interested in that the find method gets called with correct set of attributes, an array. It's not really interesting how that array got to be. In this case, you might notice that somehow params[:ids] is an array after all and you can take the split call away, and the spec will still pass. I guess what I'm trying to say is that the split call is part of the controller action's internal implementation, and you should be spec'ing how it behaves related to its surrounding world: fetches stuff from the business model, assigns objects for the view etc. //jarkko -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http://odesign.fi _______________________________________________ rspec-users mailing list rspec-users at rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users ____________________________________________________________________________________ Be a better sports nut! Let your teams follow you with Yahoo Mobile. Try it now. http://mobile.yahoo.com/sports;_ylt=At9_qDKvtAbMuh1G1SQtBI7ntAcJ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071204/ee360c0a/attachment.html From lists at ruby-forum.com Tue Dec 4 15:13:44 2007 From: lists at ruby-forum.com (Chris Olsen) Date: Tue, 4 Dec 2007 21:13:44 +0100 Subject: [rspec-users] svn: Connection closed unexpectedly when getting trunk Message-ID: <7c520447b45ff3af42c30b16d62f5825@ruby-forum.com> Is anyone else getting this message? With rails 2.0 pre-releases it looks like you also have to be working with the latest version of rpsec. $ ruby script/plugin install svn://rubyforge.org/var/svn/rspec/trunk/rspec svn: Connection closed unexpectedly The above is what I get when I try to install the trunk version. Is there something that I am missing? Thanks -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Tue Dec 4 15:18:58 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 4 Dec 2007 14:18:58 -0600 Subject: [rspec-users] params not available for controller specs? In-Reply-To: <606252.81870.qm@web58704.mail.re1.yahoo.com> References: <606252.81870.qm@web58704.mail.re1.yahoo.com> Message-ID: <57c63afe0712041218k781b47dgf41766a0c5c4bbb3@mail.gmail.com> On Dec 4, 2007 2:09 PM, Al Chou wrote: > > I get what you're saying, but I was trying to fix a bug in existing code in > Substruct (that I did not write) that was caused by Rails passing the array > as a /-delimited string and then not automatically decoding that string. As > Substruct does not say that Edge Rails is a requirement, I felt it was worth > documenting what I had to change to run it on Rails 1.2.x. Every code > change should be driven by a test or example; perhaps in this situation I > should've gone over to Test::Unit instead of staying in RSpec? An > interesting philosophical thought.... Seems to me this thread has been about how to deal with rails. I don't see what that has to do w/ a T::U vs rspec decision. > > Al > > > > ----- Original Message ---- > From: Jarkko Laine > To: rspec-users > Sent: Tuesday, December 4, 2007 10:09:01 AM > Subject: Re: [rspec-users] params not available for controller specs? > > > On 4.12.2007, at 18.19, Al Chou wrote: > > > Going back to my original message, I have the following at the > > beginning of the download method: > > > > def download > > @orders = Order.find( params[:ids] ) > > ... > > > > The problem is that params[:ids], although built as an Array object > > by the view that calls the download method on the controller, is > > passed as a /-delimited string of id values. > > If I set > > <%= link_to "Test", :controller => "clients", :foo => [1, 2, 3, 4, > 5] %> > > I get this as the url: > > http://localhost:3000/en/clients?foo%5B%5D=1&foo%5B%5D=2&foo%5B%5D=3&foo%5B%5D=4&foo%5B%5D=5 > > That will get correctly parsed back to an array in the receiving action: > > Parameters: {"action"=>"index", "foo"=>["1", "2", "3", "4", "5"], > "controller"=>"clients", "locale"=>"en"} > > This is Edge Rails, though, so YMMV. > > > Order.find() will not do the desired thing with that string, which > > was intended to be an array by the view, but Rails passed it in a > > string representation. So the method really should be > > > > def download > > @orders = Order.find( params[:ids].split( '/' ) ) > > > > and what I'm trying to spec is the addition of the call to split(). > > IMHO there's no need to stub string methods like that. Just do > something like this: > > Order.should_receive(:find).with(%w(1 2 > 3)).and_return(@some_order_objects) > > If params[:ids] is "1/2/3", you can be pretty certain that split("/") > will work correctly so you're more interested in that the find method > gets called with correct set of attributes, an array. It's not really > interesting how that array got to be. In this case, you might notice > that somehow params[:ids] is an array after all and you can take the > split call away, and the spec will still pass. > > I guess what I'm trying to say is that the split call is part of the > controller action's internal implementation, and you should be > spec'ing how it behaves related to its surrounding world: fetches > stuff from the business model, assigns objects for the view etc. > > //jarkko > > -- > Jarkko Laine > http://jlaine.net > http://dotherightthing.com > http://www.railsecommerce.com > http://odesign.fi > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > ________________________________ > Never miss a thing. Make Yahoo your homepage. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Tue Dec 4 15:20:02 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 4 Dec 2007 14:20:02 -0600 Subject: [rspec-users] svn: Connection closed unexpectedly when getting trunk In-Reply-To: <7c520447b45ff3af42c30b16d62f5825@ruby-forum.com> References: <7c520447b45ff3af42c30b16d62f5825@ruby-forum.com> Message-ID: <57c63afe0712041220hb5282e3i44e844b583c4d434@mail.gmail.com> On Dec 4, 2007 2:13 PM, Chris Olsen wrote: > Is anyone else getting this message? > > With rails 2.0 pre-releases it looks like you also have to be working > with the latest version of rpsec. > > $ ruby script/plugin install > svn://rubyforge.org/var/svn/rspec/trunk/rspec > svn: Connection closed unexpectedly > > The above is what I get when I try to install the trunk version. Try: http://rspec.rubyforge.org/svn/trunk/rspec http://rspec.rubyforge.org/svn/trunk/rspec_on_rails > > Is there something that I am missing? > > Thanks > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Tue Dec 4 15:20:47 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 4 Dec 2007 14:20:47 -0600 Subject: [rspec-users] [ANN] Webrat 0.1.0 released - Ruby Acceptance Testing for Web applications In-Reply-To: References: Message-ID: <57c63afe0712041220o2671e394v193abc8a0b7998bd@mail.gmail.com> On Nov 30, 2007 3:28 PM, Jens-Christian Fischer wrote: > > > > Code is available at: http://svn.eastmedia.net/public/plugins/webrat/ > > > * Rails integration tests in Test::Unit _or_ > > * RSpec stories (using an RSpec version >= revision 2997) > > I had to add: > > require 'cgi' > require "cgi/session" > require 'cgi/session/pstore' > require 'action_controller/cgi_ext/cgi_methods' You could also apply this patch instead: diff -r 80ee2d7fc95d -r 617747be70b6 vendor/plugins/webrat/lib/webrat/session.rb --- a/vendor/plugins/webrat/lib/webrat/session.rb Tue Dec 04 13:53:46 2007 -0600 +++ b/vendor/plugins/webrat/lib/webrat/session.rb Tue Dec 04 14:04:50 2007 -0600 @@ -102,7 +102,12 @@ module ActionController def add_form_data(input_element, value) # :nodoc: form = form_for_node(input_element) - data = CGIMethods::parse_query_parameters("#{input_element.attributes["name"]}=#{value}") + if defined?(CGIMethods) + parser = CGIMethods + else + parser = request.class + end + data = parser.parse_query_parameters("#{input_element.attributes["name"]}=#{value}") merge_form_data(form_number(form), data) end > > in the beginning of lib/webrat/session.rb to get rid of the following > error: > > NameError: uninitialized constant > ActionController::Integration::Session::CGIMethods > /Users/jcf/dev/work/quevita/vendor/rails/activerecord/lib/../../ > activesupport/lib/active_support/dependencies.rb:478:in `const_missing' > /Users/jcf/dev/work/quevita/vendor/plugins/webrat/lib/webrat/ > session.rb:107:in `add_form_data' > /Users/jcf/dev/work/quevita/vendor/plugins/webrat/lib/webrat/ > session.rb:175:in `add_default_params_for' > > > nice work! > > Jens-Christian > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Tue Dec 4 15:37:38 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Tue, 4 Dec 2007 15:37:38 -0500 Subject: [rspec-users] svn: Connection closed unexpectedly when getting trunk In-Reply-To: <57c63afe0712041220hb5282e3i44e844b583c4d434@mail.gmail.com> References: <7c520447b45ff3af42c30b16d62f5825@ruby-forum.com> <57c63afe0712041220hb5282e3i44e844b583c4d434@mail.gmail.com> Message-ID: On Dec 4, 2007, at 3:20 PM, David Chelimsky wrote: > On Dec 4, 2007 2:13 PM, Chris Olsen wrote: >> Is anyone else getting this message? >> >> With rails 2.0 pre-releases it looks like you also have to be working >> with the latest version of rpsec. >> >> $ ruby script/plugin install >> svn://rubyforge.org/var/svn/rspec/trunk/rspec >> svn: Connection closed unexpectedly >> >> The above is what I get when I try to install the trunk version. > > Try: > > http://rspec.rubyforge.org/svn/trunk/rspec > http://rspec.rubyforge.org/svn/trunk/rspec_on_rails Yeah - the http connection is a lot more reliable than the svn one. Scott From mlins at webinforem.com Tue Dec 4 15:43:46 2007 From: mlins at webinforem.com (Matthew Lins) Date: Tue, 04 Dec 2007 14:43:46 -0600 Subject: [rspec-users] AutoTest / Rspec - "stack level too deep" Message-ID: Hello, I'm running AutoTest with Rspec on a Rails application. Every 20 or so runs I get "stack level too deep" on one particular controller stub. Ex. controller.stub!(:login).and_return(true) This particular line is in a before block of a certain describe block. The strange thing is, every single spec in this file fails on that one line, even the specs in other describe blocks! Just for the hell of it, I commented it out. Then it fails on another controller stub in another describe block. Same behavior, every spec fails on this one line. I continue commenting the lines that are causing problems. I noticed it only happens with controller stubs and mocks. Once I finally get all controller mocks and stubs commented out, then my spec fails for legitimate reasons (because of the missing stubs). The only way I can fix this, is to reset AutoTest. Any ideas? Thanks, Matt P.S. If you really need to see this 750 line spec file, I'd be glad to pastie it, but I don't think it'll reveal anything. From jonathan at parkerhill.com Tue Dec 4 15:54:43 2007 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Tue, 4 Dec 2007 15:54:43 -0500 Subject: [rspec-users] Unexpected message on :attr_accessor In-Reply-To: <8d961d900712041127jb60e417w558daf867fc5a87f@mail.gmail.com> References: <14155614.post@talk.nabble.com> <57c63afe0712041102n1c2a4554y1bf13308b8924a78@mail.gmail.com> <8d961d900712041127jb60e417w558daf867fc5a87f@mail.gmail.com> Message-ID: <4E57E9BE-2214-4444-9FAB-68667B29052F@parkerhill.com> >> >> This should be: >> >> @user.should_receive(:password_confirmation=) >> > > Lots of beginners make this mistake. Maybe RSpec's mock framework > should be smart enough to suggest this fix by itself. > > Patch anyone? > > Aslak >> perhaps be even more explicit that it's an accessor, like User.should_set(:password_confirmation) User.should_get(:password_confirmation) From smingins at elctech.com Tue Dec 4 15:53:32 2007 From: smingins at elctech.com (Shane Mingins) Date: Wed, 5 Dec 2007 09:53:32 +1300 Subject: [rspec-users] AutoTest / Rspec - "stack level too deep" In-Reply-To: References: Message-ID: <9566E5AF-7791-42DD-9682-8F809FC74764@elctech.com> On 5/12/2007, at 9:43 AM, Matthew Lins wrote: > Hello, > > I'm running AutoTest with Rspec on a Rails application. > > Every 20 or so runs I get "stack level too deep" on one particular > controller stub. > > So this spec fails when you just run it?? I was a little unsure if you are having a problem with autotest or with your spec ... it seemed the later? Cheers Shane From dchelimsky at gmail.com Tue Dec 4 16:00:28 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 4 Dec 2007 15:00:28 -0600 Subject: [rspec-users] Unexpected message on :attr_accessor In-Reply-To: <4E57E9BE-2214-4444-9FAB-68667B29052F@parkerhill.com> References: <14155614.post@talk.nabble.com> <57c63afe0712041102n1c2a4554y1bf13308b8924a78@mail.gmail.com> <8d961d900712041127jb60e417w558daf867fc5a87f@mail.gmail.com> <4E57E9BE-2214-4444-9FAB-68667B29052F@parkerhill.com> Message-ID: <57c63afe0712041300m33b6c0a8jea01407e605fe928@mail.gmail.com> On Dec 4, 2007 2:54 PM, Jonathan Linowes wrote: > > >> > >> This should be: > >> > >> @user.should_receive(:password_confirmation=) > >> > > > > Lots of beginners make this mistake. Maybe RSpec's mock framework > > should be smart enough to suggest this fix by itself. > > > > Patch anyone? > > > > Aslak > >> > > perhaps be even more explicit that it's an accessor, like > > User.should_set(:password_confirmation) > User.should_get(:password_confirmation) This is silly. Mock frameworks are not there to help you learn the language. Adding getter/setter knowledge into a framework is completely backwards. -1000 > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jonathan at parkerhill.com Tue Dec 4 16:09:34 2007 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Tue, 4 Dec 2007 16:09:34 -0500 Subject: [rspec-users] Unexpected message on :attr_accessor In-Reply-To: <4E57E9BE-2214-4444-9FAB-68667B29052F@parkerhill.com> References: <14155614.post@talk.nabble.com> <57c63afe0712041102n1c2a4554y1bf13308b8924a78@mail.gmail.com> <8d961d900712041127jb60e417w558daf867fc5a87f@mail.gmail.com> <4E57E9BE-2214-4444-9FAB-68667B29052F@parkerhill.com> Message-ID: err, that suggestion was supposed to read @user.should_set... etc On Dec 4, 2007, at 3:54 PM, Jonathan Linowes wrote: > >>> >>> This should be: >>> >>> @user.should_receive(:password_confirmation=) >>> >> >> Lots of beginners make this mistake. Maybe RSpec's mock framework >> should be smart enough to suggest this fix by itself. >> >> Patch anyone? >> >> Aslak >>> > > perhaps be even more explicit that it's an accessor, like > > User.should_set(:password_confirmation) > User.should_get(:password_confirmation) > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From hotfusionman at yahoo.com Tue Dec 4 16:11:43 2007 From: hotfusionman at yahoo.com (Al Chou) Date: Tue, 4 Dec 2007 13:11:43 -0800 (PST) Subject: [rspec-users] params not available for controller specs? Message-ID: <127355.80851.qm@web58701.mail.re1.yahoo.com> I think Jarkko is saying that no spec should have been written for the code I was trying to fix/change. I'm not sure I would agree that BDD/RSpec is an inappropriate tool for documenting what I was trying to change, but I think he would argue that.... Al ----- Original Message ---- From: David Chelimsky To: rspec-users Sent: Tuesday, December 4, 2007 12:18:58 PM Subject: Re: [rspec-users] params not available for controller specs? On Dec 4, 2007 2:09 PM, Al Chou wrote: > > I get what you're saying, but I was trying to fix a bug in existing code in > Substruct (that I did not write) that was caused by Rails passing the array > as a /-delimited string and then not automatically decoding that string. As > Substruct does not say that Edge Rails is a requirement, I felt it was worth > documenting what I had to change to run it on Rails 1.2.x. Every code > change should be driven by a test or example; perhaps in this situation I > should've gone over to Test::Unit instead of staying in RSpec? An > interesting philosophical thought.... Seems to me this thread has been about how to deal with rails. I don't see what that has to do w/ a T::U vs rspec decision. > > Al > > > > ----- Original Message ---- > From: Jarkko Laine > To: rspec-users > Sent: Tuesday, December 4, 2007 10:09:01 AM > Subject: Re: [rspec-users] params not available for controller specs? > > > On 4.12.2007, at 18.19, Al Chou wrote: > > > Going back to my original message, I have the following at the > > beginning of the download method: > > > > def download > > @orders = Order.find( params[:ids] ) > > ... > > > > The problem is that params[:ids], although built as an Array object > > by the view that calls the download method on the controller, is > > passed as a /-delimited string of id values. > > If I set > > <%= link_to "Test", :controller => "clients", :foo => [1, 2, 3, 4, > 5] %> > > I get this as the url: > > http://localhost:3000/en/clients?foo%5B%5D=1&foo%5B%5D=2&foo%5B%5D=3&foo%5B%5D=4&foo%5B%5D=5 > > That will get correctly parsed back to an array in the receiving action: > > Parameters: {"action"=>"index", "foo"=>["1", "2", "3", "4", "5"], > "controller"=>"clients", "locale"=>"en"} > > This is Edge Rails, though, so YMMV. > > > Order.find() will not do the desired thing with that string, which > > was intended to be an array by the view, but Rails passed it in a > > string representation. So the method really should be > > > > def download > > @orders = Order.find( params[:ids].split( '/' ) ) > > > > and what I'm trying to spec is the addition of the call to split(). > > IMHO there's no need to stub string methods like that. Just do > something like this: > > Order.should_receive(:find).with(%w(1 2 > 3)).and_return(@some_order_objects) > > If params[:ids] is "1/2/3", you can be pretty certain that split("/") > will work correctly so you're more interested in that the find method > gets called with correct set of attributes, an array. It's not really > interesting how that array got to be. In this case, you might notice > that somehow params[:ids] is an array after all and you can take the > split call away, and the spec will still pass. > > I guess what I'm trying to say is that the split call is part of the > controller action's internal implementation, and you should be > spec'ing how it behaves related to its surrounding world: fetches > stuff from the business model, assigns objects for the view etc. > > //jarkko > > -- > Jarkko Laine > http://jlaine.net > http://dotherightthing.com > http://www.railsecommerce.com > http://odesign.fi > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users ____________________________________________________________________________________ Be a better pen pal. Text or chat with friends inside Yahoo! Mail. See how. http://overview.mail.yahoo.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071204/6ebf9704/attachment.html From dchelimsky at gmail.com Tue Dec 4 16:18:23 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 4 Dec 2007 15:18:23 -0600 Subject: [rspec-users] Unexpected message on :attr_accessor In-Reply-To: <57c63afe0712041300m33b6c0a8jea01407e605fe928@mail.gmail.com> References: <14155614.post@talk.nabble.com> <57c63afe0712041102n1c2a4554y1bf13308b8924a78@mail.gmail.com> <8d961d900712041127jb60e417w558daf867fc5a87f@mail.gmail.com> <4E57E9BE-2214-4444-9FAB-68667B29052F@parkerhill.com> <57c63afe0712041300m33b6c0a8jea01407e605fe928@mail.gmail.com> Message-ID: <57c63afe0712041318s7dc813f6occed19000bc4ce89@mail.gmail.com> On Dec 4, 2007 3:00 PM, David Chelimsky wrote: > On Dec 4, 2007 2:54 PM, Jonathan Linowes wrote: > > > > >> > > >> This should be: > > >> > > >> @user.should_receive(:password_confirmation=) > > >> > > > > > > Lots of beginners make this mistake. Maybe RSpec's mock framework > > > should be smart enough to suggest this fix by itself. > > > > > > Patch anyone? > > > > > > Aslak > > >> > > > > perhaps be even more explicit that it's an accessor, like > > > > User.should_set(:password_confirmation) > > User.should_get(:password_confirmation) > > This is silly. Mock frameworks are not there to help you learn the > language. That was a knee-jerk reaction. Let me explain. We already have should_receive(:message). :password_confirmation and password_confirmation= are two completely different messages. So saying should_set(:password_confirmation) hides what the message is that you're looking for. RSpec does aim to make things readable and consequently pleasing, but it's not here to protect you from having to learn the language. This is the same issue we had in rspec core w/ should equal(value). There are 4 versions of equal in Ruby and they all have different meanings, so we set up rspec to expose them, which means you have to understand Ruby to understand what "should equal" means. > Adding getter/setter knowledge into a framework is > completely backwards. Just following up on that thought - even though duplication is the root of all evil in OO, so are getters and setters. They act like they are encapsulating something, but really they encourage objects to interact with the state of other objects instead of interacting with the objects themselves and letting them manage their own state - THATS's what encapsulation means - not hiding data behind a getter/setter method. So having a first class construct in a mock framework that encourages thinking in terms of getters and setters seems like a step in the wrong direction. FWIW, David > > -1000 > > > > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > From jarkko at jlaine.net Tue Dec 4 16:49:17 2007 From: jarkko at jlaine.net (Jarkko Laine) Date: Tue, 4 Dec 2007 23:49:17 +0200 Subject: [rspec-users] params not available for controller specs? In-Reply-To: <127355.80851.qm@web58701.mail.re1.yahoo.com> References: <127355.80851.qm@web58701.mail.re1.yahoo.com> Message-ID: <964AD16F-263A-4A71-8D6C-90B23C76D250@jlaine.net> On 4.12.2007, at 23.11, Al Chou wrote: > I think Jarkko is saying that no spec should have been written for > the code I was trying to fix/change. I'm not sure I would agree > that BDD/RSpec is an inappropriate tool for documenting what I was > trying to change, but I think he would argue that.... What I was saying was that I think it's important that Order.find gets called with an array of ids. That's what you want to happen and to have in your spec, right? So in your spec, you'd have it "should find orders with an array of ids" do Order.should_receive(:find).with(["1", "2", "3"]) get :download, :ids => "1/2/3" end (or whatever ids you pass to the action). Now, if the current, buggy behaviour just passes the string as "1/2/3" to Order.find, the spec above will break, because it will not receive an array but a string. After you add the split("/") call to the actual code, your broken spec is fixed, and the code works as expected. Tada! No need to stub String#split anywhere. //jarkko -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http://odesign.fi From lists at ruby-forum.com Tue Dec 4 16:52:10 2007 From: lists at ruby-forum.com (Chris Olsen) Date: Tue, 4 Dec 2007 22:52:10 +0100 Subject: [rspec-users] svn: Connection closed unexpectedly when getting trunk In-Reply-To: <57c63afe0712041220hb5282e3i44e844b583c4d434@mail.gmail.com> References: <7c520447b45ff3af42c30b16d62f5825@ruby-forum.com> <57c63afe0712041220hb5282e3i44e844b583c4d434@mail.gmail.com> Message-ID: David Chelimsky wrote: > > Try: > > http://rspec.rubyforge.org/svn/trunk/rspec > http://rspec.rubyforge.org/svn/trunk/rspec_on_rails That worked much better. Thanks -- Posted via http://www.ruby-forum.com/. From edward.og at gmail.com Tue Dec 4 16:53:01 2007 From: edward.og at gmail.com (Edward Ocampo-Gooding) Date: Tue, 04 Dec 2007 16:53:01 -0500 Subject: [rspec-users] shared behaviour for all views Message-ID: <4755CC3D.2080401@gmail.com> Is there a way I can write something like a shared behaviour for all views that just checks the page responds with a 200 status and has a title, meta tags, and an h1? Here's an idea for a shared behaviour (that only applies if I set views to use it manually with it_should_behave_like "a standard layout"): describe "a standard layout", :shared => true do it "should have meta tags" do do_render response.should have_tag("meta") end it "should have an h1 tag" do do_render response.should have_tag("h1") end end Note that this also sucks because I currently have to define a do_render that calls render with a stringified name of the view I'm spec-ing. I also get the feeling that I might want to split this out into a shared behaviour for controllers that checks if all of its pages respond with a 200 (like a spider-crawling thing) and the rest should be in a view spec. I've got a feeling this would go in spec_helper.rb, but I'm not sure how to set it up for all views and controllers. What's the simplest way? Thanks, Edward From schleg at gmail.com Tue Dec 4 18:11:02 2007 From: schleg at gmail.com (schleg) Date: Tue, 4 Dec 2007 15:11:02 -0800 (PST) Subject: [rspec-users] Unexpected message on :attr_accessor In-Reply-To: <57c63afe0712041102n1c2a4554y1bf13308b8924a78@mail.gmail.com> References: <14155614.post@talk.nabble.com> <57c63afe0712041102n1c2a4554y1bf13308b8924a78@mail.gmail.com> Message-ID: <14161456.post@talk.nabble.com> Thanks, David! Glad I'm unstuck on this :) David Chelimsky-2 wrote: > > On Dec 4, 2007 11:49 AM, schleg wrote: >> >> This may be a dumb noob issue, but I haven't found any answers while >> seaching >> the forum-- >> >> I have a controller method >> >> def edit >> @user = User.find params[:id] >> @user.password_confirmation = @user.password >> end >> >> The User class has an "attr_accessor :password_confirmation" definition >> (so >> "password_confirmation" doesn't exist in the users table). My spec has >> the >> following >> >> it "should find User on GET to users/edit/:id" do >> User.should_receive(:find).and_return(@user) >> @user.should_receive(:password_confirmation) > > This should be: > > @user.should_receive(:password_confirmation=) > > Cheers, > David > >> get 'edit', :id => @user.id >> end >> >> I am asking it to expect that I will be assigning something to that >> attribute in the "edit" method. Unfortunately, the spec fails with >> >> Spec::Mocks::MockExpectationError in 'UsersController should find User on >> GET to users/edit/:id' >> Mock 'user' received unexpected message :password_confirmation= with >> ("password") >> >> Initially I thought that my "should_receive" expectation was incorrectly >> written, but if I comment out the attribute assignment in the controller >> method >> >> ... >> @user = User.find params[:id] >> #@user.password_confirmation = @user.password >> ... >> >> then the test fails with >> >> Spec::Mocks::MockExpectationError in 'UsersController should find User on >> GET to users/edit/:id' >> Mock 'user' expected :password_confirmation with (any args) once, but >> received it 0 times >> >> So, it seems to me that the expectation is written correctly, but >> something >> about using the attr_accessor via the mock object is causing a failure. >> >> BTW, I am doing the following in a before(:each) block >> >> @user = mock("user") >> @user.stub!(:new_record?).and_return(false) >> @user.stub!(:update_attributes).and_return(true) >> @user.stub!(:password_confirmation).and_return('password') >> @user.stub!(:password).and_return('password') >> User.stub!(:new).and_return(@user) >> >> Does anyone know what I'm missing here? >> >> Thanks! >> -- >> View this message in context: >> http://www.nabble.com/Unexpected-message-on-%3Aattr_accessor-tf4944588.html#a14155614 >> 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/Unexpected-message-on-%3Aattr_accessor-tf4944588.html#a14161456 Sent from the rspec-users mailing list archive at Nabble.com. From hotfusionman at yahoo.com Tue Dec 4 21:21:07 2007 From: hotfusionman at yahoo.com (Al Chou) Date: Tue, 4 Dec 2007 18:21:07 -0800 (PST) Subject: [rspec-users] params not available for controller specs? Message-ID: <99115.576.qm@web58715.mail.re1.yahoo.com> OK, I see your strategy now. Rather than mock the String argument, mock Order to confirm that it gets called with an array. Nice! Al ----- Original Message ---- From: Jarkko Laine To: rspec-users Sent: Tuesday, December 4, 2007 1:49:17 PM Subject: Re: [rspec-users] params not available for controller specs? On 4.12.2007, at 23.11, Al Chou wrote: > I think Jarkko is saying that no spec should have been written for > the code I was trying to fix/change. I'm not sure I would agree > that BDD/RSpec is an inappropriate tool for documenting what I was > trying to change, but I think he would argue that.... What I was saying was that I think it's important that Order.find gets called with an array of ids. That's what you want to happen and to have in your spec, right? So in your spec, you'd have it "should find orders with an array of ids" do Order.should_receive(:find).with(["1", "2", "3"]) get :download, :ids => "1/2/3" end (or whatever ids you pass to the action). Now, if the current, buggy behaviour just passes the string as "1/2/3" to Order.find, the spec above will break, because it will not receive an array but a string. After you add the split("/") call to the actual code, your broken spec is fixed, and the code works as expected. Tada! No need to stub String#split anywhere. //jarkko -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http://odesign.fi _______________________________________________ rspec-users mailing list rspec-users at rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users ____________________________________________________________________________________ Never miss a thing. Make Yahoo your home page. http://www.yahoo.com/r/hs -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071204/b0971fe6/attachment.html From jonathan at parkerhill.com Tue Dec 4 22:49:51 2007 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Tue, 4 Dec 2007 22:49:51 -0500 Subject: [rspec-users] Unexpected message on :attr_accessor In-Reply-To: <57c63afe0712041318s7dc813f6occed19000bc4ce89@mail.gmail.com> References: <14155614.post@talk.nabble.com> <57c63afe0712041102n1c2a4554y1bf13308b8924a78@mail.gmail.com> <8d961d900712041127jb60e417w558daf867fc5a87f@mail.gmail.com> <4E57E9BE-2214-4444-9FAB-68667B29052F@parkerhill.com> <57c63afe0712041300m33b6c0a8jea01407e605fe928@mail.gmail.com> <57c63afe0712041318s7dc813f6occed19000bc4ce89@mail.gmail.com> Message-ID: damn, looks like I'm going to have to come up with 997 more good ideas just to break even :) On Dec 4, 2007, at 4:18 PM, David Chelimsky wrote: >> >> -1000 >> From dchelimsky at gmail.com Tue Dec 4 22:56:55 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 4 Dec 2007 21:56:55 -0600 Subject: [rspec-users] Unexpected message on :attr_accessor In-Reply-To: References: <14155614.post@talk.nabble.com> <57c63afe0712041102n1c2a4554y1bf13308b8924a78@mail.gmail.com> <8d961d900712041127jb60e417w558daf867fc5a87f@mail.gmail.com> <4E57E9BE-2214-4444-9FAB-68667B29052F@parkerhill.com> <57c63afe0712041300m33b6c0a8jea01407e605fe928@mail.gmail.com> <57c63afe0712041318s7dc813f6occed19000bc4ce89@mail.gmail.com> Message-ID: <57c63afe0712041956y7d934727xd84bd63437f20c6f@mail.gmail.com> On Dec 4, 2007 9:49 PM, Jonathan Linowes wrote: > damn, looks like I'm going to have to come up with 997 more good > ideas just to break even > :) Tell you what, I'll withdraw 999 and leave it as a -1. That leaves you at +2 I believe. > On Dec 4, 2007, at 4:18 PM, David Chelimsky wrote: > > >> > >> -1000 > >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Tue Dec 4 22:57:21 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 4 Dec 2007 21:57:21 -0600 Subject: [rspec-users] Unexpected message on :attr_accessor In-Reply-To: <57c63afe0712041956y7d934727xd84bd63437f20c6f@mail.gmail.com> References: <14155614.post@talk.nabble.com> <57c63afe0712041102n1c2a4554y1bf13308b8924a78@mail.gmail.com> <8d961d900712041127jb60e417w558daf867fc5a87f@mail.gmail.com> <4E57E9BE-2214-4444-9FAB-68667B29052F@parkerhill.com> <57c63afe0712041300m33b6c0a8jea01407e605fe928@mail.gmail.com> <57c63afe0712041318s7dc813f6occed19000bc4ce89@mail.gmail.com> <57c63afe0712041956y7d934727xd84bd63437f20c6f@mail.gmail.com> Message-ID: <57c63afe0712041957y39ae7152lb0cb0a92a92376e0@mail.gmail.com> On Dec 4, 2007 9:56 PM, David Chelimsky wrote: > On Dec 4, 2007 9:49 PM, Jonathan Linowes wrote: > > damn, looks like I'm going to have to come up with 997 more good > > ideas just to break even > > :) > > Tell you what, I'll withdraw 999 and leave it as a -1. That leaves you > at +2 I believe. Although the 997 good ideas would be welcome. > > > > On Dec 4, 2007, at 4:18 PM, David Chelimsky wrote: > > > > >> > > >> -1000 > > >> > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > From hotfusionman at yahoo.com Wed Dec 5 09:52:49 2007 From: hotfusionman at yahoo.com (Al Chou) Date: Wed, 5 Dec 2007 06:52:49 -0800 (PST) Subject: [rspec-users] Does mock_model's :null_object option work? Message-ID: <66851.59921.qm@web58710.mail.re1.yahoo.com> Please understand in the following that I am making relatively minor changes to legacy (non-TDD/BDD) code in Substruct and don't have the time to refactor nicely right now. I'm just trying to get past the untested/un-speced cruft quickly to write the spec for my new code, so I'm looking for expediency over prettiness. I'm specifying before( :each ) do @order_address = mock_model( OrderAddress, :null_object => TRUE ) end but finding that unstubbed/unmocked method calls on @order_address still throw error messages like: Mock 'OrderAddress_1026' received unexpected message :first_name with (no args) so I'm starting to wonder whether the :null_object option is doing anything at all.... Al ____________________________________________________________________________________ Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071205/02ca5dc7/attachment-0001.html From dchelimsky at gmail.com Wed Dec 5 10:02:13 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 5 Dec 2007 09:02:13 -0600 Subject: [rspec-users] Does mock_model's :null_object option work? In-Reply-To: <66851.59921.qm@web58710.mail.re1.yahoo.com> References: <66851.59921.qm@web58710.mail.re1.yahoo.com> Message-ID: <57c63afe0712050702y5efef9cax436c26aa9be6718@mail.gmail.com> On Dec 5, 2007 8:52 AM, Al Chou wrote: > > Please understand in the following that I am making relatively minor changes > to legacy (non-TDD/BDD) code in Substruct and don't have the time to > refactor nicely right now. I'm just trying to get past the > untested/un-speced cruft quickly to write the spec for my new code, so I'm > looking for expediency over prettiness. > > I'm specifying > > before( :each ) do > @order_address = mock_model( OrderAddress, :null_object => TRUE ) :null_object => true (lower case) should work. > end > > but finding that unstubbed/unmocked method calls on @order_address still > throw error messages like: > > Mock 'OrderAddress_1026' received unexpected message :first_name with (no > args) > > so I'm starting to wonder whether the :null_object option is doing anything > at all.... > > > Al > > ________________________________ > Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it > now. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From tom at experthuman.com Wed Dec 5 10:07:55 2007 From: tom at experthuman.com (Tom Stuart) Date: Wed, 5 Dec 2007 15:07:55 +0000 Subject: [rspec-users] Does mock_model's :null_object option work? In-Reply-To: <66851.59921.qm@web58710.mail.re1.yahoo.com> References: <66851.59921.qm@web58710.mail.re1.yahoo.com> Message-ID: On 5 Dec 2007, at 14:52, Al Chou wrote: > @order_address = mock_model( OrderAddress, :null_object => TRUE ) > Mock 'OrderAddress_1026' received unexpected message :first_name > with (no args) > so I'm starting to wonder whether the :null_object option is doing > anything at all.... :null_object is an option to #mock, not #mock_model, which does call down to #mock but doesn't pass any arguments through to it. The optional hash argument to #mock_model allows you to stub specific methods (in addition to #id, #to_param etc which #mock_model already does for you), e.g. mock_model(OrderAddress, :first_name => 'Al', :last_name => 'Chou'). If you've got so many methods to stub that it's not worth doing it explicitly, your best bet is probably to use #mock directly and pass :null_object. Cheers, -Tom From dchelimsky at gmail.com Wed Dec 5 10:16:50 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 5 Dec 2007 09:16:50 -0600 Subject: [rspec-users] Does mock_model's :null_object option work? In-Reply-To: References: <66851.59921.qm@web58710.mail.re1.yahoo.com> Message-ID: <57c63afe0712050716i2fb84dddi6a83794dd38cde25@mail.gmail.com> On Dec 5, 2007 9:07 AM, Tom Stuart wrote: > On 5 Dec 2007, at 14:52, Al Chou wrote: > > @order_address = mock_model( OrderAddress, :null_object => TRUE ) > > Mock 'OrderAddress_1026' received unexpected message :first_name > > with (no args) > > so I'm starting to wonder whether the :null_object option is doing > > anything at all.... > > :null_object is an option to #mock, not #mock_model, which does call > down to #mock but doesn't pass any arguments through to it. This is true of the 1.0.8 release, but the current trunk does push :null_object down to the mock. > > The optional hash argument to #mock_model allows you to stub specific > methods (in addition to #id, #to_param etc which #mock_model already > does for you), e.g. mock_model(OrderAddress, :first_name => > 'Al', :last_name => 'Chou'). > > If you've got so many methods to stub that it's not worth doing it > explicitly, your best bet is probably to use #mock directly and > pass :null_object. > > Cheers, > -Tom > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From tom at experthuman.com Wed Dec 5 10:17:06 2007 From: tom at experthuman.com (Tom Stuart) Date: Wed, 5 Dec 2007 15:17:06 +0000 Subject: [rspec-users] Does mock_model's :null_object option work? In-Reply-To: <57c63afe0712050702y5efef9cax436c26aa9be6718@mail.gmail.com> References: <66851.59921.qm@web58710.mail.re1.yahoo.com> <57c63afe0712050702y5efef9cax436c26aa9be6718@mail.gmail.com> Message-ID: On 5 Dec 2007, at 15:02, David Chelimsky wrote: >> @order_address = mock_model( OrderAddress, :null_object => TRUE ) > :null_object => true (lower case) should work. Well, I'm talking bollocks then, aren't I? From hotfusionman at yahoo.com Wed Dec 5 10:25:04 2007 From: hotfusionman at yahoo.com (Al Chou) Date: Wed, 5 Dec 2007 07:25:04 -0800 (PST) Subject: [rspec-users] Does mock_model's :null_object option work? Message-ID: <643893.26541.qm@web58715.mail.re1.yahoo.com> Cool, I'll use mock for this purpose in the future! Al ----- Original Message ---- From: Tom Stuart To: rspec-users Sent: Wednesday, December 5, 2007 7:07:55 AM Subject: Re: [rspec-users] Does mock_model's :null_object option work? On 5 Dec 2007, at 14:52, Al Chou wrote: > @order_address = mock_model( OrderAddress, :null_object => TRUE ) > Mock 'OrderAddress_1026' received unexpected message :first_name > with (no args) > so I'm starting to wonder whether the :null_object option is doing > anything at all.... :null_object is an option to #mock, not #mock_model, which does call down to #mock but doesn't pass any arguments through to it. The optional hash argument to #mock_model allows you to stub specific methods (in addition to #id, #to_param etc which #mock_model already does for you), e.g. mock_model(OrderAddress, :first_name => 'Al', :last_name => 'Chou'). If you've got so many methods to stub that it's not worth doing it explicitly, your best bet is probably to use #mock directly and pass :null_object. Cheers, -Tom _______________________________________________ rspec-users mailing list rspec-users at rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users ____________________________________________________________________________________ Never miss a thing. Make Yahoo your home page. http://www.yahoo.com/r/hs -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071205/c0f74491/attachment.html From dchelimsky at gmail.com Wed Dec 5 10:30:12 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 5 Dec 2007 09:30:12 -0600 Subject: [rspec-users] Does mock_model's :null_object option work? In-Reply-To: References: <66851.59921.qm@web58710.mail.re1.yahoo.com> <57c63afe0712050702y5efef9cax436c26aa9be6718@mail.gmail.com> Message-ID: <57c63afe0712050730g486c4dafs53c8abb09af3fab7@mail.gmail.com> On Dec 5, 2007 9:17 AM, Tom Stuart wrote: > On 5 Dec 2007, at 15:02, David Chelimsky wrote: > >> @order_address = mock_model( OrderAddress, :null_object => TRUE ) > > :null_object => true (lower case) should work. > > Well, I'm talking bollocks then, aren't I? Actually, it turns out that TRUE and true resolve to the same issue. I'm guessing Al is using 1.0.8. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From hotfusionman at yahoo.com Wed Dec 5 10:36:04 2007 From: hotfusionman at yahoo.com (Al Chou) Date: Wed, 5 Dec 2007 07:36:04 -0800 (PST) Subject: [rspec-users] Does mock_model's :null_object option work? Message-ID: <622530.38648.qm@web58715.mail.re1.yahoo.com> Uh, shouldn't they both work? I use TRUE (and FALSE) because I like the facts that a) they stand out typographically and b) they are Ruby constants. I can't believe the case of the letters matters, unless you are doing something meta-programmingy rather than just passing the value through to whatever is receiving it.... Al ----- Original Message ---- From: Tom Stuart To: rspec-users Sent: Wednesday, December 5, 2007 7:17:06 AM Subject: Re: [rspec-users] Does mock_model's :null_object option work? On 5 Dec 2007, at 15:02, David Chelimsky wrote: >> @order_address = mock_model( OrderAddress, :null_object => TRUE ) > :null_object => true (lower case) should work. Well, I'm talking bollocks then, aren't I? _______________________________________________ rspec-users mailing list rspec-users at rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users ____________________________________________________________________________________ Never miss a thing. Make Yahoo your home page. http://www.yahoo.com/r/hs -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071205/69d23402/attachment.html From mlins at webinforem.com Wed Dec 5 10:37:50 2007 From: mlins at webinforem.com (Matthew Lins) Date: Wed, 05 Dec 2007 09:37:50 -0600 Subject: [rspec-users] AutoTest / Rspec - "stack level too deep" In-Reply-To: <9566E5AF-7791-42DD-9682-8F809FC74764@elctech.com> Message-ID: On 12/4/07 2:53 PM, "Shane Mingins" wrote: > On 5/12/2007, at 9:43 AM, Matthew Lins wrote: > >> Hello, >> >> I'm running AutoTest with Rspec on a Rails application. >> >> Every 20 or so runs I get "stack level too deep" on one particular >> controller stub. >> >> > > > > So this spec fails when you just run it?? I was a little unsure if > you are having a problem with autotest or with your spec ... it > seemed the later? No I think its a combination of Autotest and Rspec. Let me summarize: - I have Autotest running constantly with Rspec on a Rails app - When I start Autotest it'll run all my tests, ALL PASS - After making changes to code, Autotest detects such and runs the tests again for the specific file I'm editing ( a controller in this case) - After about 10-20 changes(Autotest runs the specs each time), I get a bunch of errors ("stack level too deep") on my controller mocks and stubs. The only way I can cure this, is by restarting AutoTest. Then in 10-20 more changes it'll happen again. It's very frustrating. If anyone can even give me a clue, I'd be very grateful. Let me know if I can provide any more information, sorry if I'm doing a poor job of explaining the problem. Thanks, Matt > > Cheers > Shane > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From mailing_lists at railsnewbie.com Wed Dec 5 10:48:03 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Wed, 5 Dec 2007 10:48:03 -0500 Subject: [rspec-users] AutoTest / Rspec - "stack level too deep" In-Reply-To: References: Message-ID: <3BE356AE-FF56-4823-B868-457A95FA8589@railsnewbie.com> On Dec 5, 2007, at 10:37 AM, Matthew Lins wrote: > On 12/4/07 2:53 PM, "Shane Mingins" wrote: > >> On 5/12/2007, at 9:43 AM, Matthew Lins wrote: >> >>> Hello, >>> >>> I'm running AutoTest with Rspec on a Rails application. >>> >>> Every 20 or so runs I get "stack level too deep" on one particular >>> controller stub. >>> >>> >> >> >> >> So this spec fails when you just run it?? I was a little unsure if >> you are having a problem with autotest or with your spec ... it >> seemed the later? > > No I think its a combination of Autotest and Rspec. > > Let me summarize: > > - I have Autotest running constantly with Rspec on a Rails app > > - When I start Autotest it'll run all my tests, ALL PASS > > - After making changes to code, Autotest detects such and runs the > tests > again for the specific file I'm editing ( a controller in this case) > > - After about 10-20 changes(Autotest runs the specs each time), I > get a > bunch of errors ("stack level too deep") on my controller mocks > and stubs. > > The only way I can cure this, is by restarting AutoTest. Then in > 10-20 more > changes it'll happen again. > > It's very frustrating. > > If anyone can even give me a clue, I'd be very grateful. > > Let me know if I can provide any more information, sorry if I'm > doing a poor > job of explaining the problem. > > Thanks, > > Matt It would probably be helpful to see the stack trace. Scott From dchelimsky at gmail.com Wed Dec 5 10:53:40 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 5 Dec 2007 09:53:40 -0600 Subject: [rspec-users] Does mock_model's :null_object option work? In-Reply-To: <622530.38648.qm@web58715.mail.re1.yahoo.com> References: <622530.38648.qm@web58715.mail.re1.yahoo.com> Message-ID: <57c63afe0712050753wf4e6fadn5541d1c9c488ded4@mail.gmail.com> On Dec 5, 2007 9:36 AM, Al Chou wrote: > > Uh, shouldn't they both work? I use TRUE (and FALSE) because I like the > facts that a) they stand out typographically and b) they are Ruby constants. > I can't believe the case of the letters matters, unless you are doing > something meta-programmingy rather than just passing the value through to > whatever is receiving it.... Did you see my earlier email acknowledging that the problem was not true/TRUE, but was likely the version of the plugin you are using? 1.0.8 does not support :null_object. Trunk does. > > Al > > > > ----- Original Message ---- > From: Tom Stuart > To: rspec-users > Sent: Wednesday, December 5, 2007 7:17:06 AM > Subject: Re: [rspec-users] Does mock_model's :null_object option work? > > On 5 Dec 2007, at 15:02, David Chelimsky wrote: > >> @order_address = mock_model( OrderAddress, :null_object => TRUE ) > > :null_object => true (lower case) should work. > > Well, I'm talking bollocks then, aren't I? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > ________________________________ > Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it > now. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lancecarlson at gmail.com Wed Dec 5 10:54:49 2007 From: lancecarlson at gmail.com (Lance Carlson) Date: Wed, 5 Dec 2007 10:54:49 -0500 Subject: [rspec-users] AutoTest / Rspec - "stack level too deep" In-Reply-To: References: <9566E5AF-7791-42DD-9682-8F809FC74764@elctech.com> Message-ID: <49f64a900712050754o67ec92b8h4e268ab0965153e8@mail.gmail.com> Pasting more of your code would help. I get this error when infinite recursion creeps into the application, or in my specs.. like when you run .save! on a model that has an after_filter calling save! On Dec 5, 2007 10:37 AM, Matthew Lins wrote: > On 12/4/07 2:53 PM, "Shane Mingins" wrote: > > > On 5/12/2007, at 9:43 AM, Matthew Lins wrote: > > > >> Hello, > >> > >> I'm running AutoTest with Rspec on a Rails application. > >> > >> Every 20 or so runs I get "stack level too deep" on one particular > >> controller stub. > >> > >> > > > > > > > > So this spec fails when you just run it?? I was a little unsure if > > you are having a problem with autotest or with your spec ... it > > seemed the later? > > No I think its a combination of Autotest and Rspec. > > Let me summarize: > > - I have Autotest running constantly with Rspec on a Rails app > > - When I start Autotest it'll run all my tests, ALL PASS > > - After making changes to code, Autotest detects such and runs the tests > again for the specific file I'm editing ( a controller in this case) > > - After about 10-20 changes(Autotest runs the specs each time), I get a > bunch of errors ("stack level too deep") on my controller mocks and stubs. > > The only way I can cure this, is by restarting AutoTest. Then in 10-20 more > changes it'll happen again. > > It's very frustrating. > > If anyone can even give me a clue, I'd be very grateful. > > Let me know if I can provide any more information, sorry if I'm doing a poor > job of explaining the problem. > > Thanks, > > Matt > > > > > > Cheers > > Shane > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.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 hotfusionman at yahoo.com Wed Dec 5 12:21:35 2007 From: hotfusionman at yahoo.com (Al Chou) Date: Wed, 5 Dec 2007 09:21:35 -0800 (PST) Subject: [rspec-users] Does mock_model's :null_object option work? Message-ID: <323232.30711.qm@web58710.mail.re1.yahoo.com> That's correct, I'm still on 1.0.8. Sorry for forgetting to mention that. I'm trying to keep some semblance of sanity as to knowing what versions of code I'm using, given how scattered I am about a subset of it (viz., Substruct). Al ----- Original Message ---- From: David Chelimsky To: rspec-users Sent: Wednesday, December 5, 2007 7:30:12 AM Subject: Re: [rspec-users] Does mock_model's :null_object option work? On Dec 5, 2007 9:17 AM, Tom Stuart wrote: > On 5 Dec 2007, at 15:02, David Chelimsky wrote: > >> @order_address = mock_model( OrderAddress, :null_object => TRUE ) > > :null_object => true (lower case) should work. > > Well, I'm talking bollocks then, aren't I? Actually, it turns out that TRUE and true resolve to the same issue. I'm guessing Al is using 1.0.8. _______________________________________________ rspec-users mailing list rspec-users at rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users ____________________________________________________________________________________ Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071205/38ce146c/attachment.html From andy at adveho.net Thu Dec 6 11:56:31 2007 From: andy at adveho.net (Andy Goundry) Date: Thu, 6 Dec 2007 16:56:31 +0000 Subject: [rspec-users] Mocks? Really? Message-ID: <139c56460712060856i6bb410fcl23def3b16c0388b4@mail.gmail.com> OK, so i've played a bit with mocks and mock_models in controller and view tests and i have a question. Is this statement really correct: "We highly recommend that you exploit the mock framework here rather than providing real model objects in order to keep the view specs isolated from changes to your models." (http://rspec.rubyforge.org/documentation/rails/writing/views.html in section 'assigns') I ask because this wonderful declaration passes in my view test even though the model Project doesn't have the field 'synopsis' yet: @project1 = mock_model(Project) @project1.stub!(:id).and_return(1) @project1.stub!(:name).and_return("My first project") @project1.stub!(:synopsis).and_return("This is a fantastic new project") assigns[:projects] = [@project1] it "should show the list of projects with name and synopsis" do render "/projects/index.rhtml" response.should have_tag('div#project_1_name', 'My first project') response.should have_tag('div#project_1_synopsis', 'This is a fantastic new project') response.should have_tag('div#project_2_name', 'My second project') response.should have_tag('div#project_2_synopsis', 'This is another fantastic project') response.should have_tag('a', 'This is another fantastic project') end This is handy and keeps the view test isolated from changes to your models, but is that really the point? What if someone later changes the model and updates the model tests so that they pass but do not realize that they've then broken the view? I'm sure i am simply missing the point here or not taking into account integration testing that would i expect aim to catch such changes, but somehow i want my view tests to tell me that the views are no longer going to behave as expected Thanks Andy From dchelimsky at gmail.com Thu Dec 6 12:04:42 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 6 Dec 2007 11:04:42 -0600 Subject: [rspec-users] Mocks? Really? In-Reply-To: <139c56460712060856i6bb410fcl23def3b16c0388b4@mail.gmail.com> References: <139c56460712060856i6bb410fcl23def3b16c0388b4@mail.gmail.com> Message-ID: <57c63afe0712060904hf965f98jf94511e9ef357c11@mail.gmail.com> On Dec 6, 2007 10:56 AM, Andy Goundry wrote: > OK, so i've played a bit with mocks and mock_models in controller and > view tests and i have a question. Is this statement really correct: > > "We highly recommend that you exploit the mock framework here rather > than providing real model objects in order to keep the view specs > isolated from changes to your models." > (http://rspec.rubyforge.org/documentation/rails/writing/views.html in > section 'assigns') > > I ask because this wonderful declaration passes in my view test even > though the model Project doesn't have the field 'synopsis' yet: > > @project1 = mock_model(Project) > @project1.stub!(:id).and_return(1) > @project1.stub!(:name).and_return("My first project") > @project1.stub!(:synopsis).and_return("This is a fantastic new project") > assigns[:projects] = [@project1] > > it "should show the list of projects with name and synopsis" do > render "/projects/index.rhtml" > response.should have_tag('div#project_1_name', 'My first project') > response.should have_tag('div#project_1_synopsis', 'This is a > fantastic new project') > response.should have_tag('div#project_2_name', 'My second project') > response.should have_tag('div#project_2_synopsis', 'This is > another fantastic project') > response.should have_tag('a', 'This is another fantastic project') > end > > This is handy and keeps the view test isolated from changes to your > models, but is that really the point? It depends on what you value. If you are doing BDD, then you are running all of your examples between every change. If you are doing that, you value fast-running examples. >What if someone later changes > the model and updates the model tests so that they pass but do not > realize that they've then broken the view? > > I'm sure i am simply missing the point here or not taking into account > integration testing that would i expect aim to catch such changes, but > somehow i want my view tests to tell me that the views are no longer > going to behave as expected This is matter of mindset. In my view, the view is still behaving as expected, it's just that the expectation is wrong. What's not behaving correctly is the application, which, as you point out, we would learn from stories (integration tests). HTH, David > > Thanks > > Andy > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From tom at experthuman.com Thu Dec 6 12:11:26 2007 From: tom at experthuman.com (Tom Stuart) Date: Thu, 6 Dec 2007 17:11:26 +0000 Subject: [rspec-users] Mocks? Really? In-Reply-To: <139c56460712060856i6bb410fcl23def3b16c0388b4@mail.gmail.com> References: <139c56460712060856i6bb410fcl23def3b16c0388b4@mail.gmail.com> Message-ID: On 6 Dec 2007, at 16:56, Andy Goundry wrote: > This is handy and keeps the view test isolated from changes to your > models, but is that really the point? Yes, that's part of the whole idea of using mocks. (Similarly, two interacting models will be isolated from each other's implementation.) > What if someone later changes > the model and updates the model tests so that they pass but do not > realize that they've then broken the view? This is an engineering problem. For example, perhaps you could have one helper that's used to manufacture mock Projects, and use it in the view specs and the model specs; changes to the attributes of Project (and the corresponding changes to its spec) will then require that helper to be updated so that the model specs still pass, and the view spec will fail accordingly. > somehow i want my view tests to tell me that the views are no longer > going to behave as expected Your view specs tell you that your views will behave as expected _under the assumption that_ your model objects behave as expected. That assumption needs to be checked elsewhere (in the model spec). Cheers, -Tom From mailing_lists at railsnewbie.com Thu Dec 6 16:37:24 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Thu, 6 Dec 2007 16:37:24 -0500 Subject: [rspec-users] mock libraries, Object#send, and Object#__send__ Message-ID: What is the appropriate way to stub out (and put an expectation on Object#__send__), without getting warnings from the Rspec mock library? Scott From dchelimsky at gmail.com Thu Dec 6 16:41:45 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 6 Dec 2007 15:41:45 -0600 Subject: [rspec-users] mock libraries, Object#send, and Object#__send__ In-Reply-To: References: Message-ID: <57c63afe0712061341h4bb925a9je04730e30db0fbb6@mail.gmail.com> On Dec 6, 2007 3:37 PM, Scott Taylor wrote: > > > What is the appropriate way to stub out (and put an expectation on > Object#__send__), without getting warnings from the Rspec mock library? Come on Scott - you know better than that :) Error please? > > Scott > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Thu Dec 6 17:08:21 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Thu, 6 Dec 2007 17:08:21 -0500 Subject: [rspec-users] mock libraries, Object#send, and Object#__send__ In-Reply-To: <57c63afe0712061341h4bb925a9je04730e30db0fbb6@mail.gmail.com> References: <57c63afe0712061341h4bb925a9je04730e30db0fbb6@mail.gmail.com> Message-ID: <7D9EEF10-3B1B-49F8-BFC1-408696D04B11@railsnewbie.com> On Dec 6, 2007, at 4:41 PM, David Chelimsky wrote: > On Dec 6, 2007 3:37 PM, Scott Taylor > wrote: >> >> >> What is the appropriate way to stub out (and put an expectation on >> Object#__send__), without getting warnings from the Rspec mock >> library? > > Come on Scott - you know better than that :) > > Error please? Not an error, just a warning. And I should have written my description better. Basically, I wanted to make sure that my library didn't call send, but instead __send__. I tried something like this: before :each do @caller = Object.new @caller.stub!(:send).and_raise @caller.stub!(:__send__) end it "should be able to send the message with __send__" do @caller.should_not_receive(:send) @caller.should_receive(:__send__) @attributes.to_new_class_instance({}, @caller) end The @caller object is a sort of mock object. I would have used a real mock object, except that stubbing send on a mock object didn't seem to do anything. The warning was this: ./usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.8/lib/spec/mocks/ proxy.rb:99: warning: redefining `__send__' may cause serious problem Just wondering about what you would recommend for this. Let me know if you need more context. Scott From dchelimsky at gmail.com Thu Dec 6 17:12:32 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 6 Dec 2007 16:12:32 -0600 Subject: [rspec-users] mock libraries, Object#send, and Object#__send__ In-Reply-To: <7D9EEF10-3B1B-49F8-BFC1-408696D04B11@railsnewbie.com> References: <57c63afe0712061341h4bb925a9je04730e30db0fbb6@mail.gmail.com> <7D9EEF10-3B1B-49F8-BFC1-408696D04B11@railsnewbie.com> Message-ID: <57c63afe0712061412s7423d365h93e1e6da88a3ebbf@mail.gmail.com> On Dec 6, 2007 4:08 PM, Scott Taylor wrote: > > On Dec 6, 2007, at 4:41 PM, David Chelimsky wrote: > > > On Dec 6, 2007 3:37 PM, Scott Taylor > > wrote: > >> > >> > >> What is the appropriate way to stub out (and put an expectation on > >> Object#__send__), without getting warnings from the Rspec mock > >> library? > > > > Come on Scott - you know better than that :) > > > > Error please? > > Not an error, just a warning. And I should have written my > description better. Basically, I wanted to make sure that my library > didn't call send, but instead __send__. I tried something like this: > > before :each do > @caller = Object.new > @caller.stub!(:send).and_raise > @caller.stub!(:__send__) > > end > > it "should be able to send the message with __send__" do > @caller.should_not_receive(:send) > @caller.should_receive(:__send__) > > @attributes.to_new_class_instance({}, @caller) > end > > > The @caller object is a sort of mock object. I would have used a > real mock object, except that stubbing send on a mock object didn't > seem to do anything. > > The warning was this: > > ./usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.8/lib/spec/mocks/ > proxy.rb:99: warning: redefining `__send__' may cause serious problem I LOVE that it says "may cause serious problem" - not "problems" Anyhow - I'm not sure what we can do about that. RSpec's stubs work by redefining existing methods. Ruby doesn't want you to do that with __send__. For the moment, there's no way around it, but I'm not even sure what we could change in RSpec to make it work. Any ideas? > > Just wondering about what you would recommend for this. Let me know > if you need more context. > > > Scott > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Thu Dec 6 17:22:14 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Thu, 6 Dec 2007 17:22:14 -0500 Subject: [rspec-users] mock libraries, Object#send, and Object#__send__ In-Reply-To: <57c63afe0712061412s7423d365h93e1e6da88a3ebbf@mail.gmail.com> References: <57c63afe0712061341h4bb925a9je04730e30db0fbb6@mail.gmail.com> <7D9EEF10-3B1B-49F8-BFC1-408696D04B11@railsnewbie.com> <57c63afe0712061412s7423d365h93e1e6da88a3ebbf@mail.gmail.com> Message-ID: <2C982131-7CCC-44CE-B15A-B53B486D824F@railsnewbie.com> On Dec 6, 2007, at 5:12 PM, David Chelimsky wrote: > On Dec 6, 2007 4:08 PM, Scott Taylor > wrote: >> >> On Dec 6, 2007, at 4:41 PM, David Chelimsky wrote: >> >>> On Dec 6, 2007 3:37 PM, Scott Taylor >>> wrote: >>>> >>>> >>>> What is the appropriate way to stub out (and put an expectation on >>>> Object#__send__), without getting warnings from the Rspec mock >>>> library? >>> >>> Come on Scott - you know better than that :) >>> >>> Error please? >> >> Not an error, just a warning. And I should have written my >> description better. Basically, I wanted to make sure that my library >> didn't call send, but instead __send__. I tried something like this: >> >> before :each do >> @caller = Object.new >> @caller.stub!(:send).and_raise >> @caller.stub!(:__send__) >> >> end >> >> it "should be able to send the message with __send__" do >> @caller.should_not_receive(:send) >> @caller.should_receive(:__send__) >> >> @attributes.to_new_class_instance({}, @caller) >> end >> >> >> The @caller object is a sort of mock object. I would have used a >> real mock object, except that stubbing send on a mock object didn't >> seem to do anything. >> >> The warning was this: >> >> ./usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.8/lib/spec/mocks/ >> proxy.rb:99: warning: redefining `__send__' may cause serious problem > > I LOVE that it says "may cause serious problem" - not "problems" > > Anyhow - I'm not sure what we can do about that. RSpec's stubs work by > redefining existing methods. Ruby doesn't want you to do that with > __send__. For the moment, there's no way around it, but I'm not even > sure what we could change in RSpec to make it work. Any ideas? Ah - so it's actually something ruby does, and not the mock library. I hadn't realized that. I'm not sure this is the best idea, but we could actually remove the warning: def execute_silently(&blk) old_warning_level = $VERBOSE $VERBOSE = nil yield $VERBOSE = old_warning_level end (or I could do this myself, in my own specs) Scott From dchelimsky at gmail.com Thu Dec 6 17:25:48 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 6 Dec 2007 16:25:48 -0600 Subject: [rspec-users] mock libraries, Object#send, and Object#__send__ In-Reply-To: <2C982131-7CCC-44CE-B15A-B53B486D824F@railsnewbie.com> References: <57c63afe0712061341h4bb925a9je04730e30db0fbb6@mail.gmail.com> <7D9EEF10-3B1B-49F8-BFC1-408696D04B11@railsnewbie.com> <57c63afe0712061412s7423d365h93e1e6da88a3ebbf@mail.gmail.com> <2C982131-7CCC-44CE-B15A-B53B486D824F@railsnewbie.com> Message-ID: <57c63afe0712061425n348bcc7fn718f6de02a1700f3@mail.gmail.com> On Dec 6, 2007 4:22 PM, Scott Taylor wrote: > > > On Dec 6, 2007, at 5:12 PM, David Chelimsky wrote: > > > On Dec 6, 2007 4:08 PM, Scott Taylor > > wrote: > >> > >> On Dec 6, 2007, at 4:41 PM, David Chelimsky wrote: > >> > >>> On Dec 6, 2007 3:37 PM, Scott Taylor > >>> wrote: > >>>> > >>>> > >>>> What is the appropriate way to stub out (and put an expectation on > >>>> Object#__send__), without getting warnings from the Rspec mock > >>>> library? > >>> > >>> Come on Scott - you know better than that :) > >>> > >>> Error please? > >> > >> Not an error, just a warning. And I should have written my > >> description better. Basically, I wanted to make sure that my library > >> didn't call send, but instead __send__. I tried something like this: > >> > >> before :each do > >> @caller = Object.new > >> @caller.stub!(:send).and_raise > >> @caller.stub!(:__send__) > >> > >> end > >> > >> it "should be able to send the message with __send__" do > >> @caller.should_not_receive(:send) > >> @caller.should_receive(:__send__) > >> > >> @attributes.to_new_class_instance({}, @caller) > >> end > >> > >> > >> The @caller object is a sort of mock object. I would have used a > >> real mock object, except that stubbing send on a mock object didn't > >> seem to do anything. > >> > >> The warning was this: > >> > >> ./usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.8/lib/spec/mocks/ > >> proxy.rb:99: warning: redefining `__send__' may cause serious problem > > > > I LOVE that it says "may cause serious problem" - not "problems" > > > > Anyhow - I'm not sure what we can do about that. RSpec's stubs work by > > redefining existing methods. Ruby doesn't want you to do that with > > __send__. For the moment, there's no way around it, but I'm not even > > sure what we could change in RSpec to make it work. Any ideas? > > Ah - so it's actually something ruby does, and not the mock library. > I hadn't realized that. > > I'm not sure this is the best idea, but we could actually remove the > warning: > > def execute_silently(&blk) > old_warning_level = $VERBOSE > $VERBOSE = nil > yield > $VERBOSE = old_warning_level > end > > > (or I could do this myself, in my own specs) I'd be happier if you did that yourself. I don't want RSpec to be in the habit of hiding warnings. > > > Scott > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Thu Dec 6 17:33:34 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Thu, 6 Dec 2007 17:33:34 -0500 Subject: [rspec-users] mock libraries, Object#send, and Object#__send__ In-Reply-To: <57c63afe0712061425n348bcc7fn718f6de02a1700f3@mail.gmail.com> References: <57c63afe0712061341h4bb925a9je04730e30db0fbb6@mail.gmail.com> <7D9EEF10-3B1B-49F8-BFC1-408696D04B11@railsnewbie.com> <57c63afe0712061412s7423d365h93e1e6da88a3ebbf@mail.gmail.com> <2C982131-7CCC-44CE-B15A-B53B486D824F@railsnewbie.com> <57c63afe0712061425n348bcc7fn718f6de02a1700f3@mail.gmail.com> Message-ID: On Dec 6, 2007, at 5:25 PM, David Chelimsky wrote: > On Dec 6, 2007 4:22 PM, Scott Taylor > wrote: >> >> >> On Dec 6, 2007, at 5:12 PM, David Chelimsky wrote: >> >>> On Dec 6, 2007 4:08 PM, Scott Taylor >>> wrote: >>>> >>>> On Dec 6, 2007, at 4:41 PM, David Chelimsky wrote: >>>> >>>>> On Dec 6, 2007 3:37 PM, Scott Taylor >>>>> wrote: >>>>>> >>>>>> >>>>>> What is the appropriate way to stub out (and put an >>>>>> expectation on >>>>>> Object#__send__), without getting warnings from the Rspec mock >>>>>> library? >>>>> ... >> I'm not sure this is the best idea, but we could actually remove the >> warning: >> >> def execute_silently(&blk) >> old_warning_level = $VERBOSE >> $VERBOSE = nil >> yield >> $VERBOSE = old_warning_level >> end >> >> >> (or I could do this myself, in my own specs) > > I'd be happier if you did that yourself. I don't want RSpec to be in > the habit of hiding warnings. > Yep. I don't disagree with you (especially now that I know that the warning comes from ruby itself). Originally I thought that maybe the mock library used __send__, and issued a warning if you tried to stub it. Scott From flyeminent at hotmail.com Thu Dec 6 21:51:21 2007 From: flyeminent at hotmail.com (Shaker) Date: Thu, 6 Dec 2007 18:51:21 -0800 (PST) Subject: [rspec-users] weird behavior of mocking ruby class methods Message-ID: <14205880.post@talk.nabble.com> Hello everyone: After I played with Rspec for three months, I realized a weird behavior of mocking ruby classes (e.g. File). Please let me post a sample code before I point out the problems: #file_reader.rb (to be tested) class FileReader def do_read File.read('asd.txt') end end #file_reader_spec.rb describe FileReader, "do_read" do it "should throw File Not Found on non-existent file" do reader = FileReader.new() lambda { reader.do_read }.should raise_error(Errno::ENOENT) end end describe FileReader, "do_read" do it "should read the mock contents" do reader = FileReader.new() File.should_receive(:read).and_return('file contents') reader.do_read.should == 'file contents' end end In the test cases shown above, I wanted to mock the "read" method in ruby "File" class. The first case passed while the second one failed. I suspected that the mocking was not working in the second case. (Please see the output in "Scenario 1" in the attached file) Then I switched the running order of the test cases, another interesting result came out. The mocking worked well this time but "read" method in "File" class became undefined in the second test case. It seemed that the mocking erased the "read" method. (Please see the output in "Scenario 2" in the attached file) http://www.nabble.com/file/p14205880/result.txt result.txt I am wondering what is going on out there when I mocked a method of ruby class? Do I use mocking in a proper way as the sample code shown above? What is the correct way of mocking methods of ruby classes? -- View this message in context: http://www.nabble.com/weird-behavior-of-mocking-ruby-class-methods-tf4959949.html#a14205880 Sent from the rspec-users mailing list archive at Nabble.com. From jed.hurt at gmail.com Fri Dec 7 02:25:55 2007 From: jed.hurt at gmail.com (Jed Hurt) Date: Fri, 7 Dec 2007 00:25:55 -0700 Subject: [rspec-users] TextMate Sidebar Message-ID: Hey David, I just watched the RubyConf recording of your RSpec session and noticed that you're using a modified version of TextMate that uses a sidebar instead of a project drawer. Where did you find that mod? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071207/c900e1bc/attachment.html From dchelimsky at gmail.com Fri Dec 7 08:06:03 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 7 Dec 2007 07:06:03 -0600 Subject: [rspec-users] TextMate Sidebar In-Reply-To: References: Message-ID: <57c63afe0712070506o1f5e3f72n25c93d3ee7d046fc@mail.gmail.com> On Dec 7, 2007 1:25 AM, Jed Hurt wrote: > Hey David, > > I just watched the RubyConf recording of your RSpec session Cool - I didn't know those were up. > and noticed that > you're using a modified version of TextMate that uses a sidebar instead of a > project drawer. Where did you find that mod? MissingDrawer.tmplugin: http://hetima.com/textmate/index-e.html It was a little buggy in Tiger, but works great now in Leopard. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Fri Dec 7 09:58:13 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 7 Dec 2007 08:58:13 -0600 Subject: [rspec-users] help please Message-ID: <57c63afe0712070658y5f240572rb1fe0c6ac77e110a@mail.gmail.com> Hey all, Rails just got tagged 2.0.0, and then 2.0.1. Unfortunately, it includes a changeset from yesterday that breaks rspec's pre_commit task. I do not have cycles to address this until tonight, and I suspect that everyone is going to be grabbing the 2.0.1 release and become sad when RSpec won't work with it. If any of you (especially Josh Knowles, who added the feature to rails that is breaking rspec :), care to come up w/ a patch I can take the few minutes necessary to get it in to trunk. http://rspec.lighthouseapp.com/projects/5645/tickets/171 http://dev.rubyonrails.org/changeset/8324 http://dev.rubyonrails.org/ticket/10377 Cheers, David From brandon at collectiveidea.com Fri Dec 7 11:42:12 2007 From: brandon at collectiveidea.com (Brandon Keepers) Date: Fri, 7 Dec 2007 11:42:12 -0500 Subject: [rspec-users] strange error on mock proxy Message-ID: <3700D3A0-A110-468F-888D-9DBFDCFB4D14@collectiveidea.com> I'm banging my head over this really strange error in a view test when I run "rake spec". The weird thing is that I don't get the error when I run the spec file by itself. Here is the spec (I know, fixtures are the devil): describe "/units/new.html.erb here" do fixtures :units, :accounts, :groups it_should_behave_like '/units/_form' before do login_as :cathy assigns[:unit] = @unit = Unit.new @groups = accounts(:dawson).groups render "/units/new.html" end it "should render new form" do response.should have_tag("form[action=?][method=post]", units_path) end end And the error: 4) ActionView::TemplateError in 'Spec::Rails::Example::ViewExampleGroup/ units/new.html.erb should render new form' You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.include? On line #13 of units/_form.html.erb 10: <% unless @unit.root? -%> 11:
  • 12: 13: <%= f.select :parent_id, [1,2,3] %> 14: <%#= f.select :parent_id, 15: nested_set_options_for_select(current_account.units.root) {|u| "#{'?' * u.level} #{u.name}"} %> 16:
  • vendor/plugins/rspec/lib/spec/mocks/proxy.rb:71:in `send' vendor/plugins/rspec/lib/spec/mocks/proxy.rb:71:in `message_received' vendor/plugins/rspec/lib/spec/mocks/proxy.rb:100:in `include?' vendor/rails/actionpack/lib/action_view/helpers/ form_options_helper.rb:304:in `option_value_selected?' vendor/rails/actionpack/lib/action_view/helpers/ form_options_helper.rb:163:in `options_for_select' vendor/rails/actionpack/lib/action_view/helpers/text_helper.rb: 29:in `inject' vendor/rails/actionpack/lib/action_view/helpers/ form_options_helper.rb:161:in `each' vendor/rails/actionpack/lib/action_view/helpers/ form_options_helper.rb:161:in `inject' vendor/rails/actionpack/lib/action_view/helpers/ form_options_helper.rb:161:in `options_for_select' vendor/rails/actionpack/lib/action_view/helpers/ form_options_helper.rb:358:in `to_select_tag' vendor/rails/actionpack/lib/action_view/helpers/ form_options_helper.rb:84:in `select' vendor/rails/actionpack/lib/action_view/helpers/ form_options_helper.rb:409:in `select' app/views//units/_form.html.erb:13:in `_run_47app47views47units47_form46html46erb' vendor/rails/actionpack/lib/action_view/base.rb:390:in `send' vendor/rails/actionpack/lib/action_view/base.rb:390:in `compile_and_render_template' vendor/rails/actionpack/lib/action_view/base.rb:366:in `render_template' vendor/rails/actionpack/lib/action_view/base.rb:316:in `globalize_old_render_file' vendor/plugins/globalize/lib/globalize/rails/action_view.rb:18:in `render_file' vendor/rails/actionpack/lib/action_view/base.rb:331:in `orig_render' vendor/plugins/rspec_on_rails/lib/spec/rails/extensions/ action_view/base.rb:22:in `render' vendor/rails/actionpack/lib/action_view/partials.rb:117:in `render_partial' vendor/rails/actionpack/lib/action_controller/benchmarking.rb: 26:in `benchmark' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ ruby/1.8/benchmark.rb:293:in `measure' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ ruby/1.8/benchmark.rb:307:in `realtime' vendor/rails/actionpack/lib/action_controller/benchmarking.rb: 26:in `benchmark' vendor/rails/actionpack/lib/action_view/partials.rb:116:in `render_partial' vendor/plugins/rspec_on_rails/lib/spec/rails/extensions/ action_view/base.rb:13:in `render_partial' vendor/rails/actionpack/lib/action_view/base.rb:352:in `orig_render' vendor/plugins/rspec_on_rails/lib/spec/rails/extensions/ action_view/base.rb:22:in `render' app/views//units/new.html.erb:6:in `_run_47app47views47units47new46html46erb' vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb: 248:in `fields_for' vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb: 184:in `form_for' app/views//units/new.html.erb:5:in `_run_47app47views47units47new46html46erb' vendor/rails/actionpack/lib/action_view/base.rb:390:in `send' vendor/rails/actionpack/lib/action_view/base.rb:390:in `compile_and_render_template' vendor/rails/actionpack/lib/action_view/base.rb:366:in `render_template' vendor/rails/actionpack/lib/action_view/base.rb:316:in `globalize_old_render_file' vendor/plugins/globalize/lib/globalize/rails/action_view.rb:18:in `render_file' vendor/rails/actionpack/lib/action_controller/base.rb:1109:in `render_for_file' vendor/rails/actionpack/lib/action_controller/base.rb:861:in `render_with_no_layout' vendor/rails/actionpack/lib/action_controller/layout.rb:269:in `render_without_benchmark' vendor/rails/actionpack/lib/action_controller/benchmarking.rb: 51:in `render' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ ruby/1.8/benchmark.rb:293:in `measure' vendor/rails/actionpack/lib/action_controller/benchmarking.rb: 51:in `render' vendor/plugins/rspec_on_rails/lib/spec/rails/example/ view_example_group.rb:129:in `send' vendor/plugins/rspec_on_rails/lib/spec/rails/example/ view_example_group.rb:129:in `render' spec/views/units/new.html.erb_spec.rb:11 vendor/plugins/rspec/lib/spec/example/example_methods.rb:42:in `instance_eval' vendor/plugins/rspec/lib/spec/example/example_methods.rb:42:in `eval_each_fail_fast' vendor/plugins/rspec/lib/spec/example/example_methods.rb:41:in `each' vendor/plugins/rspec/lib/spec/example/example_methods.rb:41:in `eval_each_fail_fast' vendor/plugins/rspec/lib/spec/example/example_group_methods.rb: 216:in `run_before_each' vendor/plugins/rspec/lib/spec/example/example_group_methods.rb: 316:in `execute_in_class_hierarchy' vendor/plugins/rspec/lib/spec/example/example_group_methods.rb: 315:in `each' vendor/plugins/rspec/lib/spec/example/example_group_methods.rb: 315:in `execute_in_class_hierarchy' vendor/plugins/rspec/lib/spec/example/example_group_methods.rb: 215:in `run_before_each' vendor/plugins/rspec/lib/spec/example/example_methods.rb:65:in `before_example' vendor/plugins/rspec/lib/spec/example/example_methods.rb:13:in `execute' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ ruby/1.8/timeout.rb:48:in `timeout' vendor/plugins/rspec/lib/spec/example/example_methods.rb:11:in `execute' vendor/plugins/rspec/lib/spec/example/example_group_methods.rb: 256:in `execute_examples' vendor/plugins/rspec/lib/spec/example/example_group_methods.rb: 254:in `each' vendor/plugins/rspec/lib/spec/example/example_group_methods.rb: 254:in `execute_examples' vendor/plugins/rspec/lib/spec/example/example_group_methods.rb: 115:in `run' vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb: 22:in `run' vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb: 21:in `each' vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb: 21:in `run' vendor/plugins/rspec/lib/spec/runner/options.rb:85:in `run_examples' vendor/plugins/rspec/lib/spec/runner/command_line.rb:19:in `run' vendor/plugins/rspec/bin/spec:3 I'm not sure why the error is in the mock proxy because this spec isn't using mocking at all. Any ideas? Brandon -------------- next part -------------- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 186 bytes Desc: This is a digitally signed message part Url : http://rubyforge.org/pipermail/rspec-users/attachments/20071207/1810c78e/attachment-0001.bin From dchelimsky at gmail.com Fri Dec 7 12:54:17 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 7 Dec 2007 11:54:17 -0600 Subject: [rspec-users] strange error on mock proxy In-Reply-To: <3700D3A0-A110-468F-888D-9DBFDCFB4D14@collectiveidea.com> References: <3700D3A0-A110-468F-888D-9DBFDCFB4D14@collectiveidea.com> Message-ID: <57c63afe0712070954x42fd519avae1641c952bcb532@mail.gmail.com> I'm away from my computer right now so I can't give you details, but I know that view examples use mocks under the hood for some things. On 12/7/07, Brandon Keepers wrote: > I'm banging my head over this really strange error in a view test when > I run "rake spec". The weird thing is that I don't get the error when > I run the spec file by itself. > > Here is the spec (I know, fixtures are the devil): > > describe "/units/new.html.erb here" do > fixtures :units, :accounts, :groups > it_should_behave_like '/units/_form' > > before do > login_as :cathy > assigns[:unit] = @unit = Unit.new > @groups = accounts(:dawson).groups > render "/units/new.html" > end > > it "should render new form" do > response.should have_tag("form[action=?][method=post]", units_path) > end > > end > > And the error: > > 4) > ActionView::TemplateError in 'Spec::Rails::Example::ViewExampleGroup/ > units/new.html.erb should render new form' > You have a nil object when you didn't expect it! > You might have expected an instance of Array. > The error occurred while evaluating nil.include? > On line #13 of units/_form.html.erb > > 10: <% unless @unit.root? -%> > 11:
  • > 12: > 13: <%= f.select :parent_id, [1,2,3] %> > 14: <%#= f.select :parent_id, > 15: nested_set_options_for_select(current_account.units.root) > {|u| "#{'?' * u.level} #{u.name}"} %> > 16:
  • > > vendor/plugins/rspec/lib/spec/mocks/proxy.rb:71:in `send' > vendor/plugins/rspec/lib/spec/mocks/proxy.rb:71:in > `message_received' > vendor/plugins/rspec/lib/spec/mocks/proxy.rb:100:in `include?' > vendor/rails/actionpack/lib/action_view/helpers/ > form_options_helper.rb:304:in `option_value_selected?' > vendor/rails/actionpack/lib/action_view/helpers/ > form_options_helper.rb:163:in `options_for_select' > vendor/rails/actionpack/lib/action_view/helpers/text_helper.rb: > 29:in `inject' > vendor/rails/actionpack/lib/action_view/helpers/ > form_options_helper.rb:161:in `each' > vendor/rails/actionpack/lib/action_view/helpers/ > form_options_helper.rb:161:in `inject' > vendor/rails/actionpack/lib/action_view/helpers/ > form_options_helper.rb:161:in `options_for_select' > vendor/rails/actionpack/lib/action_view/helpers/ > form_options_helper.rb:358:in `to_select_tag' > vendor/rails/actionpack/lib/action_view/helpers/ > form_options_helper.rb:84:in `select' > vendor/rails/actionpack/lib/action_view/helpers/ > form_options_helper.rb:409:in `select' > app/views//units/_form.html.erb:13:in > `_run_47app47views47units47_form46html46erb' > vendor/rails/actionpack/lib/action_view/base.rb:390:in `send' > vendor/rails/actionpack/lib/action_view/base.rb:390:in > `compile_and_render_template' > vendor/rails/actionpack/lib/action_view/base.rb:366:in > `render_template' > vendor/rails/actionpack/lib/action_view/base.rb:316:in > `globalize_old_render_file' > vendor/plugins/globalize/lib/globalize/rails/action_view.rb:18:in > `render_file' > vendor/rails/actionpack/lib/action_view/base.rb:331:in > `orig_render' > vendor/plugins/rspec_on_rails/lib/spec/rails/extensions/ > action_view/base.rb:22:in `render' > vendor/rails/actionpack/lib/action_view/partials.rb:117:in > `render_partial' > vendor/rails/actionpack/lib/action_controller/benchmarking.rb: > 26:in `benchmark' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ > ruby/1.8/benchmark.rb:293:in `measure' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ > ruby/1.8/benchmark.rb:307:in `realtime' > vendor/rails/actionpack/lib/action_controller/benchmarking.rb: > 26:in `benchmark' > vendor/rails/actionpack/lib/action_view/partials.rb:116:in > `render_partial' > vendor/plugins/rspec_on_rails/lib/spec/rails/extensions/ > action_view/base.rb:13:in `render_partial' > vendor/rails/actionpack/lib/action_view/base.rb:352:in > `orig_render' > vendor/plugins/rspec_on_rails/lib/spec/rails/extensions/ > action_view/base.rb:22:in `render' > app/views//units/new.html.erb:6:in > `_run_47app47views47units47new46html46erb' > vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb: > 248:in `fields_for' > vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb: > 184:in `form_for' > app/views//units/new.html.erb:5:in > `_run_47app47views47units47new46html46erb' > vendor/rails/actionpack/lib/action_view/base.rb:390:in `send' > vendor/rails/actionpack/lib/action_view/base.rb:390:in > `compile_and_render_template' > vendor/rails/actionpack/lib/action_view/base.rb:366:in > `render_template' > vendor/rails/actionpack/lib/action_view/base.rb:316:in > `globalize_old_render_file' > vendor/plugins/globalize/lib/globalize/rails/action_view.rb:18:in > `render_file' > vendor/rails/actionpack/lib/action_controller/base.rb:1109:in > `render_for_file' > vendor/rails/actionpack/lib/action_controller/base.rb:861:in > `render_with_no_layout' > vendor/rails/actionpack/lib/action_controller/layout.rb:269:in > `render_without_benchmark' > vendor/rails/actionpack/lib/action_controller/benchmarking.rb: > 51:in `render' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ > ruby/1.8/benchmark.rb:293:in `measure' > vendor/rails/actionpack/lib/action_controller/benchmarking.rb: > 51:in `render' > vendor/plugins/rspec_on_rails/lib/spec/rails/example/ > view_example_group.rb:129:in `send' > vendor/plugins/rspec_on_rails/lib/spec/rails/example/ > view_example_group.rb:129:in `render' > spec/views/units/new.html.erb_spec.rb:11 > vendor/plugins/rspec/lib/spec/example/example_methods.rb:42:in > `instance_eval' > vendor/plugins/rspec/lib/spec/example/example_methods.rb:42:in > `eval_each_fail_fast' > vendor/plugins/rspec/lib/spec/example/example_methods.rb:41:in > `each' > vendor/plugins/rspec/lib/spec/example/example_methods.rb:41:in > `eval_each_fail_fast' > vendor/plugins/rspec/lib/spec/example/example_group_methods.rb: > 216:in `run_before_each' > vendor/plugins/rspec/lib/spec/example/example_group_methods.rb: > 316:in `execute_in_class_hierarchy' > vendor/plugins/rspec/lib/spec/example/example_group_methods.rb: > 315:in `each' > vendor/plugins/rspec/lib/spec/example/example_group_methods.rb: > 315:in `execute_in_class_hierarchy' > vendor/plugins/rspec/lib/spec/example/example_group_methods.rb: > 215:in `run_before_each' > vendor/plugins/rspec/lib/spec/example/example_methods.rb:65:in > `before_example' > vendor/plugins/rspec/lib/spec/example/example_methods.rb:13:in > `execute' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ > ruby/1.8/timeout.rb:48:in `timeout' > vendor/plugins/rspec/lib/spec/example/example_methods.rb:11:in > `execute' > vendor/plugins/rspec/lib/spec/example/example_group_methods.rb: > 256:in `execute_examples' > vendor/plugins/rspec/lib/spec/example/example_group_methods.rb: > 254:in `each' > vendor/plugins/rspec/lib/spec/example/example_group_methods.rb: > 254:in `execute_examples' > vendor/plugins/rspec/lib/spec/example/example_group_methods.rb: > 115:in `run' > vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb: > 22:in `run' > vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb: > 21:in `each' > vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb: > 21:in `run' > vendor/plugins/rspec/lib/spec/runner/options.rb:85:in > `run_examples' > vendor/plugins/rspec/lib/spec/runner/command_line.rb:19:in `run' > vendor/plugins/rspec/bin/spec:3 > > > I'm not sure why the error is in the mock proxy because this spec > isn't using mocking at all. > > Any ideas? > > Brandon From dchelimsky at gmail.com Fri Dec 7 14:32:49 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 7 Dec 2007 13:32:49 -0600 Subject: [rspec-users] rspec_on_rails (trunk - r3070) works with Rails 2.0.1 Message-ID: <57c63afe0712071132w2dbb6f4aqb6fc01ddd1a9c904@mail.gmail.com> After a couple of quick fixes this morning, rspec_on_rails (in trunk as of rev 3070) now works correctly with Rails 2.0.1 Now that Rails 2.0 is out, we'll try to get an RSpec 1.1 release candidate out the door in the next few days. Cheers, David From rspec.user at gmail.com Fri Dec 7 15:57:57 2007 From: rspec.user at gmail.com (sinclair bain) Date: Fri, 7 Dec 2007 15:57:57 -0500 Subject: [rspec-users] TextMate Sidebar In-Reply-To: References: Message-ID: <2ca660dd0712071257h636e58e6y96c78a7cefa6798a@mail.gmail.com> Hey Jed, Can you please provide a link to the recording you mentioned ? That would be great! Cheers! sinclair On Dec 7, 2007 2:25 AM, Jed Hurt wrote: > Hey David, > I just watched the RubyConf recording of your RSpec session and noticed > that you're using a modified version of TextMate that uses a sidebar instead > of a project drawer. Where did you find that mod? > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Cheers! sinclair -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071207/7ddef751/attachment.html From mailing_lists at railsnewbie.com Fri Dec 7 16:19:53 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Fri, 7 Dec 2007 16:19:53 -0500 Subject: [rspec-users] TextMate Sidebar In-Reply-To: <2ca660dd0712071257h636e58e6y96c78a7cefa6798a@mail.gmail.com> References: <2ca660dd0712071257h636e58e6y96c78a7cefa6798a@mail.gmail.com> Message-ID: <20F77C68-EA19-4780-9968-6B70A382A946@railsnewbie.com> On Dec 7, 2007, at 3:57 PM, sinclair bain wrote: > Hey Jed, > > Can you please provide a link to the recording you mentioned ? > > That would be great! I would imagine he's talking about this: http://rubyconf2007.confreaks.com/ Scott -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071207/a316cd9b/attachment.html From priit at mx.ee Fri Dec 7 21:30:35 2007 From: priit at mx.ee (Priit Tamboom) Date: Sat, 8 Dec 2007 10:30:35 +0800 Subject: [rspec-users] Mocks? Really? In-Reply-To: References: <139c56460712060856i6bb410fcl23def3b16c0388b4@mail.gmail.com> Message-ID: Hi! > > This is handy and keeps the view test isolated from changes to your > > models, but is that really the point? I was very confused first as well. It didn't make any point to me and I'm not using it at all. As far as I know, I take it as an optional tool to go nuts with views when needed. I will use it when some stuff in view becomes super important to be there. However as an one-band project I haven't feel this need yet. Second thing is about how you like to develop your stuff. As far as I know David start with Story -> Views -> controller -> model. I prefer to go this way: Story -> model/controller -> views. So now you might guess why specing views are nice thing when you go David's way up-to-down. Anyhow, mocking in controllers (and in views) makes much more sense now with story runner in the big picture. General stuff 'does it work at all' goes to story runner and specific low level stuff goes to spec. So it's up to you if you care about low level stuff in views. One thing what I still don't like so much is that rspec "force" you to develop things super vertically or otherwise your mocks will be out of sync very quickly. Correct me if I'm wrong !!! Oki, Priit PS. somehow autotest does not pick up stories to run. I haven't yet investigate it why. From dchelimsky at gmail.com Fri Dec 7 21:40:15 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 7 Dec 2007 20:40:15 -0600 Subject: [rspec-users] Mocks? Really? In-Reply-To: References: <139c56460712060856i6bb410fcl23def3b16c0388b4@mail.gmail.com> Message-ID: <57c63afe0712071840w13e8d2co85a60c00f3caefa9@mail.gmail.com> On Dec 7, 2007 8:30 PM, Priit Tamboom wrote: > Hi! > > > > This is handy and keeps the view test isolated from changes to your > > > models, but is that really the point? > > I was very confused first as well. It didn't make any point to me and > I'm not using it at all. As far as I know, I take it as an optional > tool to go nuts with views when needed. I will use it when some stuff > in view becomes super important to be there. However as an one-band > project I haven't feel this need yet. > > Second thing is about how you like to develop your stuff. As far as I > know David start with Story -> Views -> controller -> model. I prefer > to go this way: Story -> model/controller -> views. So now you might > guess why specing views are nice thing when you go David's way > up-to-down. > > Anyhow, mocking in controllers (and in views) makes much more sense > now with story runner in the big picture. General stuff 'does it work > at all' goes to story runner and specific low level stuff goes to > spec. So it's up to you if you care about low level stuff in views. > > One thing what I still don't like so much is that rspec "force" you to > develop things super vertically or otherwise your mocks will be out of > sync very quickly. Correct me if I'm wrong !!! RSpec doesn't force you to anything at all. However, the agile approach tends to be vertical slices in short iterations. Working outside-in, using mocks, etc all ties in with that thinking. But rspec is certainly not going to throw errors at you if you decide to write your entire model layer first. > > Oki, > Priit > > PS. somehow autotest does not pick up stories to run. I haven't yet > investigate it why. This is by design. Autotest supports the TDD process - rapid iterations of red/green/refactor. Having them run your stories too would slow things down considerably. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From andy at adveho.net Sat Dec 8 04:20:02 2007 From: andy at adveho.net (Andy Goundry) Date: Sat, 8 Dec 2007 09:20:02 +0000 Subject: [rspec-users] Mocks? Really? In-Reply-To: <57c63afe0712071840w13e8d2co85a60c00f3caefa9@mail.gmail.com> References: <139c56460712060856i6bb410fcl23def3b16c0388b4@mail.gmail.com> <57c63afe0712071840w13e8d2co85a60c00f3caefa9@mail.gmail.com> Message-ID: Thanks for all the feedback. Personally, i am working outside in, from views to models, so mocking does have its place. After lots of trialing, I am confident now that a Factory class can satisfy my need for using mocks and real models in different places. I define the characteristics of an intended model in the factory and ask it to return either a mock_model or a real one depending on my specific need. Once I've used in anger, I'll mail details of my implementation and experiences. Although I have played with story runner, I have yet to decide how I'll fit that into my development process. In fact, I love story runner, it's just I am not sure how much time I can afford to assign to tests on client work whilst I am still getting up to speed. As a note, I recently wrote a functional spec document for a client using the Given, When, Then approach for each use case, and the client loved it! It is a very clear way if writing specs. Andy On 8 Dec 2007, at 02:40, "David Chelimsky" wrote: > On Dec 7, 2007 8:30 PM, Priit Tamboom wrote: >> Hi! >> >>>> This is handy and keeps the view test isolated from changes to your >>>> models, but is that really the point? >> >> I was very confused first as well. It didn't make any point to me and >> I'm not using it at all. As far as I know, I take it as an optional >> tool to go nuts with views when needed. I will use it when some stuff >> in view becomes super important to be there. However as an one-band >> project I haven't feel this need yet. >> >> Second thing is about how you like to develop your stuff. As far as I >> know David start with Story -> Views -> controller -> model. I prefer >> to go this way: Story -> model/controller -> views. So now you might >> guess why specing views are nice thing when you go David's way >> up-to-down. >> >> Anyhow, mocking in controllers (and in views) makes much more sense >> now with story runner in the big picture. General stuff 'does it work >> at all' goes to story runner and specific low level stuff goes to >> spec. So it's up to you if you care about low level stuff in views. >> >> One thing what I still don't like so much is that rspec "force" you >> to >> develop things super vertically or otherwise your mocks will be out >> of >> sync very quickly. Correct me if I'm wrong !!! > > RSpec doesn't force you to anything at all. However, the agile > approach tends to be vertical slices in short iterations. Working > outside-in, using mocks, etc all ties in with that thinking. > > But rspec is certainly not going to throw errors at you if you decide > to write your entire model layer first. > >> >> Oki, >> Priit >> >> PS. somehow autotest does not pick up stories to run. I haven't yet >> investigate it why. > > This is by design. Autotest supports the TDD process - rapid > iterations of red/green/refactor. Having them run your stories too > would slow things down considerably. > >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.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 tastapod at gmail.com Sat Dec 8 07:06:49 2007 From: tastapod at gmail.com (Dan North) Date: Sat, 8 Dec 2007 12:06:49 +0000 Subject: [rspec-users] Mocks? Really? In-Reply-To: References: <139c56460712060856i6bb410fcl23def3b16c0388b4@mail.gmail.com> <57c63afe0712071840w13e8d2co85a60c00f3caefa9@mail.gmail.com> Message-ID: I prefer the mantra "mock roles, not objects", in other words, mock things that have behaviour (services, components, resources, whatever your preferred term is) rather than stubbing out domain objects themselves. If you have to mock domain objects it's usually a smell that your domain implementation is too tightly coupled to some infrastructure. The rails community is the first place I've encountered stubbing domain objects as a norm (and in fact as an encouraged "best practice"). It seems to be a consequence of how tightly coupled the model classes are to the database. I don't use rails in anger, and in the other technologies and frameworks I use (in Java, .Net or Ruby) I never mock the domain model. It seems unwieldy and overly verbose to me to have to stub properties on a model class. I usually use a builder pattern: cheese = CheeseBuilder.to_cheese # with suitable default values for testing The builder has lots of methods that start "with_" and return the builder instance, so you can train-wreck the properties: another_cheese = CheeseBuilder.with_type (:edam).with_flavour(:mild).to_cheese toastie = ToastieBuilder.with_cheese(cheese).to_toastie # composing domain objects In applications with a database, I then have a very thin suite of low level integration tests that use "real" domain objects, wired up to a real database to verify the behaviour at that level. Of course this is both slow and highly dependent on infrastructure, so I am careful to keep the integration examples separate from the interaction-based ones that I can isolate. Maybe it's the way rails encourages you to write apps - where it's mostly about getting data from a screen to a database and back again - that people are more tolerant of such highly-coupled tests. For myself, I use builders for domain objects and mocks for service dependencies whenever I can, and have a minimal suite of integration tests that require everything to be wired together. Using fixtures and database setup for regular behavioural examples smacks of data-oriented programming to me, and stubbing domain objects feels like solving the wrong problem. Cheers, Dan On Dec 8, 2007 9:20 AM, Andy Goundry wrote: > Thanks for all the feedback. Personally, i am working outside in, from > views to models, so mocking does have its place. After lots of > trialing, I am confident now that a Factory class can satisfy my need > for using mocks and real models in different places. I define the > characteristics of an intended model in the factory and ask it to > return either a mock_model or a real one depending on my specific > need. Once I've used in anger, I'll mail details of my implementation > and experiences. > > Although I have played with story runner, I have yet to decide how > I'll fit that into my development process. In fact, I love story > runner, it's just I am not sure how much time I can afford to assign > to tests on client work whilst I am still getting up to speed. > > As a note, I recently wrote a functional spec document for a client > using the Given, When, Then approach for each use case, and the client > loved it! It is a very clear way if writing specs. > > Andy > > On 8 Dec 2007, at 02:40, "David Chelimsky" wrote: > > > On Dec 7, 2007 8:30 PM, Priit Tamboom wrote: > >> Hi! > >> > >>>> This is handy and keeps the view test isolated from changes to your > >>>> models, but is that really the point? > >> > >> I was very confused first as well. It didn't make any point to me and > >> I'm not using it at all. As far as I know, I take it as an optional > >> tool to go nuts with views when needed. I will use it when some stuff > >> in view becomes super important to be there. However as an one-band > >> project I haven't feel this need yet. > >> > >> Second thing is about how you like to develop your stuff. As far as I > >> know David start with Story -> Views -> controller -> model. I prefer > >> to go this way: Story -> model/controller -> views. So now you might > >> guess why specing views are nice thing when you go David's way > >> up-to-down. > >> > >> Anyhow, mocking in controllers (and in views) makes much more sense > >> now with story runner in the big picture. General stuff 'does it work > >> at all' goes to story runner and specific low level stuff goes to > >> spec. So it's up to you if you care about low level stuff in views. > >> > >> One thing what I still don't like so much is that rspec "force" you > >> to > >> develop things super vertically or otherwise your mocks will be out > >> of > >> sync very quickly. Correct me if I'm wrong !!! > > > > RSpec doesn't force you to anything at all. However, the agile > > approach tends to be vertical slices in short iterations. Working > > outside-in, using mocks, etc all ties in with that thinking. > > > > But rspec is certainly not going to throw errors at you if you decide > > to write your entire model layer first. > > > >> > >> Oki, > >> Priit > >> > >> PS. somehow autotest does not pick up stories to run. I haven't yet > >> investigate it why. > > > > This is by design. Autotest supports the TDD process - rapid > > iterations of red/green/refactor. Having them run your stories too > > would slow things down considerably. > > > >> > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-users at rubyforge.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/20071208/1fc89c90/attachment.html From james.deville at gmail.com Sat Dec 8 23:47:24 2007 From: james.deville at gmail.com (James Deville) Date: Sat, 8 Dec 2007 20:47:24 -0800 Subject: [rspec-users] [rspec-devel] rspec_on_rails (trunk - r3070) works with Rails 2.0.1 In-Reply-To: References: <1865E5DA-99AF-4778-AEAA-868C45B184F3@gmail.com> Message-ID: I figured most of it out. The Spec::Rails stuff was something in the code which has been fixed by revision 3099. The test methods partially make sense. Since the test/unit code has been integrated, methods with test in them are automatically turned into specs. However, the test? method is in a lib file that isn't directly loaded into the specs. It is a convenience method: def test?; RAILS_ENV=="test";end I don't know why this method is being included in my tests, every context has it as an example. Any ideas? Jim D On Dec 8, 2007, at 8:42 PM, James Deville wrote: > > > Begin forwarded message: > >> From: James Deville >> Date: December 7, 2007 5:00:30 PM PST >> To: James Deville >> Subject: Re: [rspec-devel] rspec_on_rails (trunk - r3070) works >> with Rails 2.0.1 >> >> Nope, i'm now getting a test? spec before every group, it seems >> related to the rspec_on_rails plugin. I'll take a look more at >> home, but I would appreciate any help. >> >> Person with account >> - test? >> - should obviously show last login >> ... >> >> Person model: A new Person >> - test? >> - should have an empty dna_contacts collection >> ... >> >> >> - test? >> >> >> - test? >> >> >> - test? (FAILED - 5) >> >> Spec::Rails::Example::FunctionalExampleGroup >> - test? (ERROR - 6) >> >> >> - test? >> >> Spec::Rails::Example::RailsExampleGroup >> - test? >> >> Pending: >> >> >> JD >> >> >> >> On Dec 7, 2007, at 4:39 PM, James Deville wrote: >> >>> I think I just found it. I had rspec 1.0.8 unpacked as a gem in >>> vendor/gems >>> >>> However, now I am getting a test? spec before every group. I'll >>> try going to 3070 to see if it fixes the problem >>> >>> JD >>> On Dec 7, 2007, at 4:18 PM, James Deville wrote: >>> >>>> No change. >>>> >>>> Jim >>>> >>>> On Dec 7, 2007, at 4:06 PM, David Chelimsky wrote: >>>> >>>>> On Dec 7, 2007 6:01 PM, James Deville >>>>> wrote: >>>>>> I'm getting an error with this fix. My versions: rspec:3072 >>>>>> rspec_on_rails:3073 >>>>> >>>>> You've got 2 different revisions of rspec, 3072 and 3073. Can you >>>>> align those and try again? >>>>> >>>>>> rails:2.0.1. Formatter in this case is Specdoc >>>>>> >>>>>> The odd part is that debugger is telling me that BaseFormatter, >>>>>> BaseTextFormatter and SpecdocFormatter all take one argument. I >>>>>> don't >>>>>> have the gem installed, so I'm not sure where Ruby is getting >>>>>> that >>>>>> from, as the code shows 2, options and where. >>>>>> >>>>>> Any advice on where to look, or what other information I can >>>>>> give you? >>>>>> >>>>>> Jim D >>>>>> >>>>>> >>>>>> Aragorn:mydna james$ rake spec >>>>>> (in /Users/james/projects/mydna) >>>>>> /Users/james/projects/mydna/app/models/asset.rb:23: warning: >>>>>> Object#id >>>>>> will be deprecated; use Object#object_id >>>>>> ./spec/models/mailers/person_notifier_spec.rb:41: warning: >>>>>> already >>>>>> initialized constant FIXTURES_PATH >>>>>> ./spec/models/mailers/person_notifier_spec.rb:42: warning: >>>>>> already >>>>>> initialized constant CHARSET >>>>>> ./spec/models/mailers/feedback_notifier_spec.rb:4: warning: >>>>>> already >>>>>> initialized constant FIXTURES_PATH >>>>>> ./spec/models/mailers/feedback_notifier_spec.rb:5: warning: >>>>>> already >>>>>> initialized constant CHARSET >>>>>> /Users/james/projects/mydna/vendor/plugins/rspec/lib/spec/runner/ >>>>>> options.rb:151:in `initialize': wrong number of arguments (2 >>>>>> for 1) >>>>>> (ArgumentError) >>>>>> from /Users/james/projects/mydna/vendor/plugins/rspec/lib/ >>>>>> spec/runner/ >>>>>> options.rb:151:in `new' >>>>>> from /Users/james/projects/mydna/vendor/plugins/rspec/lib/ >>>>>> spec/runner/ >>>>>> options.rb:151:in `formatters' >>>>>> from /Users/james/projects/mydna/vendor/plugins/rspec/lib/ >>>>>> spec/runner/ >>>>>> options.rb:144:in `map' >>>>>> from /Users/james/projects/mydna/vendor/plugins/rspec/lib/ >>>>>> spec/runner/ >>>>>> options.rb:144:in `formatters' >>>>>> from /Users/james/projects/mydna/vendor/plugins/rspec/lib/ >>>>>> spec/runner/ >>>>>> reporter.rb:71:in `formatters' >>>>>> from /Users/james/projects/mydna/vendor/plugins/rspec/lib/ >>>>>> spec/runner/ >>>>>> reporter.rb:58:in `dump' >>>>>> from /Users/james/projects/mydna/vendor/plugins/rspec/lib/ >>>>>> spec/runner/ >>>>>> example_group_runner.rb:37:in `finish' >>>>>> from /Users/james/projects/mydna/vendor/plugins/rspec/lib/ >>>>>> spec/runner/ >>>>>> example_group_runner.rb:26:in `run' >>>>>> from /Users/james/projects/mydna/vendor/plugins/rspec/lib/ >>>>>> spec/runner/ >>>>>> options.rb:85:in `run_examples' >>>>>> from /Users/james/projects/mydna/vendor/plugins/rspec/lib/ >>>>>> spec/runner/ >>>>>> command_line.rb:19:in `run' >>>>>> from /Users/james/projects/mydna/vendor/plugins/rspec/bin/ >>>>>> spec:3 >>>>>> rake aborted! >>>>>> >>>>>> >>>>>> On Dec 7, 2007, at 11:32 AM, David Chelimsky wrote: >>>>>> >>>>>>> After a couple of quick fixes this morning, rspec_on_rails (in >>>>>>> trunk >>>>>>> as of rev 3070) now works correctly with Rails 2.0.1 >>>>>>> >>>>>>> Now that Rails 2.0 is out, we'll try to get an RSpec 1.1 release >>>>>>> candidate out the door in the next few days. >>>>>>> >>>>>>> Cheers, >>>>>>> David >>>>>>> _______________________________________________ >>>>>>> rspec-devel mailing list >>>>>>> rspec-devel at rubyforge.org >>>>>>> http://rubyforge.org/mailman/listinfo/rspec-devel >>>>>> >>>>>> _______________________________________________ >>>>>> rspec-devel mailing list >>>>>> rspec-devel at rubyforge.org >>>>>> http://rubyforge.org/mailman/listinfo/rspec-devel >>>>>> >>>>> _______________________________________________ >>>>> rspec-devel mailing list >>>>> rspec-devel at rubyforge.org >>>>> http://rubyforge.org/mailman/listinfo/rspec-devel >>>> >>> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071208/1bff0065/attachment-0001.html From philodespotos at gmail.com Sun Dec 9 07:06:06 2007 From: philodespotos at gmail.com (Kyle Hargraves) Date: Sun, 9 Dec 2007 06:06:06 -0600 Subject: [rspec-users] Story HTML Formatter Message-ID: <60f3810c0712090406y57524353u7a6c7664b205d99a@mail.gmail.com> I recently noticed the HTML formatter for the story runner, but I'm unable to figure out how to make it function. 'ruby stories/all.rb --format html' seems like it should work, in that --help works as expected, but I still get only plain text output. Maybe it's not been wired up yet and/or this is a bug. Maybe I'm just being dumb. I have no clue at this time of night/morning. Thanks Kyle From cdemyanovich at gmail.com Sun Dec 9 10:09:03 2007 From: cdemyanovich at gmail.com (Craig Demyanovich) Date: Sun, 9 Dec 2007 10:09:03 -0500 Subject: [rspec-users] [rspec-devel] rspec_on_rails (trunk - r3070) works with Rails 2.0.1 In-Reply-To: References: <1865E5DA-99AF-4778-AEAA-868C45B184F3@gmail.com> Message-ID: <61c885db0712090709u3dd6e26an5b7aa0e7ddd9c316@mail.gmail.com> On Dec 8, 2007 11:47 PM, James Deville wrote: > I figured most of it out. The Spec::Rails stuff was something in the code > which has been fixed by revision 3099. The test methods partially make > sense. Since the test/unit code has been integrated, methods with test in > them are automatically turned into specs. However, the test? method is in a > lib file that isn't directly loaded into the specs. It is a convenience > method: def test?; RAILS_ENV=="test";end > I don't know why this method is being included in my tests, every context > has it as an example. Any ideas? > I have a couple ideas. If the lib file is on the load path, then maybe rspec is searching it. Also, re: the name, maybe rspec and/or test::unit is recognizing the method as a test because it begins with "test." Try renaming the method. Regards, Craig -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071209/0da05940/attachment.html From dchelimsky at gmail.com Sun Dec 9 11:30:03 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 9 Dec 2007 10:30:03 -0600 Subject: [rspec-users] Story HTML Formatter In-Reply-To: <60f3810c0712090406y57524353u7a6c7664b205d99a@mail.gmail.com> References: <60f3810c0712090406y57524353u7a6c7664b205d99a@mail.gmail.com> Message-ID: <57c63afe0712090830p4b948af8s657a571a214ff15c@mail.gmail.com> On Dec 9, 2007 6:06 AM, Kyle Hargraves wrote: > I recently noticed the HTML formatter for the story runner, but I'm > unable to figure out how to make it function. > > 'ruby stories/all.rb --format html' seems like it should work, in that > --help works as expected, but I still get only plain text output. > > Maybe it's not been wired up yet and/or this is a bug. Maybe I'm just > being dumb. I have no clue at this time of night/morning. It is wired up but there is a bug when using it w/ rails that makes it ... less wired up :) Don't know if we'll get that fixed pre-release, but we will soon. > > Thanks > > Kyle > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From andypearson at criticalwebdesign.co.uk Sun Dec 9 14:54:59 2007 From: andypearson at criticalwebdesign.co.uk (Andy Pearson) Date: Sun, 9 Dec 2007 19:54:59 +0000 Subject: [rspec-users] Writing Specifications for Custom Form Builders (and Helpers) Message-ID: Hello all, Long time reader, first time poster! I am a relative newcomer (no idea what on earth I am doing) to Ruby, Rails and Rspec and have a feeling I am probably trying to run before I know how to walk. I had imagined a cool way of outputting a div around some form stuff which would have a class on it if the related field had errors, something a bit like: <% f.div_with_errors_for :login do %> <%= f.text_field :login %> <% end %> It will output a regular div if there are no errors on the field or
    ... if there is an error. So, I began trying to get this working. Searching about I discovered that I could create a custom form builder so i created lib/ extended_form_builder.rb along with spec/lib/ extended_form_builder_spec.rb so I could start writing my specifications. So far, so good. An hour or so later, after searching, reading Rails source code and abandoning specs completely I have ended up with the very basic: class ExtendedFormBuilder < ActionView::Helpers::FormBuilder def div_with_errors_for(object_name, &block) @template.concat(@template.content_tag(:div, @template.capture(&block)), block.binding) end end Which only wraps the block I pass to it with a
    and outputs it correctly using erb. The problem is, I have NO specs for it, and I don't want to continue writing the rest of the method until I know how to spec it correctly. Any tips on how I should be speccing this, I guess I need to stub out @template correctly (?!) as at the moment, the extended_form_builder_spec.rb is not running like a view spec where I assume @template would be set up. Which brings me onto my second question, what sort of tone of voice should I be using to describe Helpers, at the moment I am using stuff like: describe ApplicationHelper, 'error_message_for method' do it 'should not return the error message if the instance doesnt exist yet' it 'should return the error message if there are errors on the object' it 'should not return the error message if there are no errors on the object' end But it doesn't feel right, I guess it isn't "real" enough, too much talk of methods and objects I suppose. Thanks for taking the time to read this, and thanks in advance for any advice you can offer! Andy From lists at ruby-forum.com Sun Dec 9 15:58:05 2007 From: lists at ruby-forum.com (Chris Olsen) Date: Sun, 9 Dec 2007 21:58:05 +0100 Subject: [rspec-users] What to test for views? Message-ID: When you guys test views, what are you testing? Do you just test that all the form fields exist in a new.rhtml, that all form fields are filled in an edit.rhtml, and that all the proper columns are are shown in a index.rhtml page, or is there something more that should be tested? Thanks. -- Posted via http://www.ruby-forum.com/. From omen.king at gmail.com Sun Dec 9 23:58:34 2007 From: omen.king at gmail.com (Andrew WC Brown) Date: Sun, 9 Dec 2007 23:58:34 -0500 Subject: [rspec-users] What to test for views? In-Reply-To: References: Message-ID: I think what David said before about spec views is take it with a grain of salt. If you think you need to check the presence of every field go ahead. When I spec out my views I only spec what needs to be there: I won't check for the presence of a form fields new.rhtml_spec.rb I would place my fields in a partial called fields and I spec their presence in _fields.html_spec.rb I would spec in my new.rhtml_spec.rb if the partial fields was rendered. It may satisfy you just to have a spec that says: it "should show form" do response.shouldhave_tag("form[action=#{projects_path(@game)}][method=post]") end Its all up to you how granular you want to get. On Dec 9, 2007 3:58 PM, Chris Olsen wrote: > When you guys test views, what are you testing? Do you just test that > all the form fields exist in a new.rhtml, that all form fields are > filled in an edit.rhtml, and that all the proper columns are are shown > in a index.rhtml page, or is there something more that should be tested? > > Thanks. > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071209/0755b276/attachment.html From michael.s.klishin.lists at gmail.com Mon Dec 10 01:07:16 2007 From: michael.s.klishin.lists at gmail.com (Michael Klishin) Date: Mon, 10 Dec 2007 08:07:16 +0200 Subject: [rspec-users] What to test for views? In-Reply-To: References: Message-ID: I first started to check things existence in the resulting page but quickly decided to only check for permission-affected links, forms, etc. Though if your applications are RESTful it would be good idea to check http method form uses and hidden fields that Rails uses to piggyback PUT and DELETE on top of POST. On 9 ???. 2007, at 22:58, Chris Olsen wrote: > When you guys test views, what are you testing? Do you just test that > all the form fields exist in a new.rhtml, that all form fields are > filled in an edit.rhtml, and that all the proper columns are are shown > in a index.rhtml page, or is there something more that should be > tested? MK From lists at ruby-forum.com Mon Dec 10 08:40:55 2007 From: lists at ruby-forum.com (Richard Manyanza) Date: Mon, 10 Dec 2007 14:40:55 +0100 Subject: [rspec-users] Duplicate error messages Message-ID: I am running rails 1.2.3 and rspec 1.0.8 on os X 10.4 and I am having a problem with one of my model specs (User class). For some reason rspec is throwing repeating errors. If the error I expect is "email is required", I end up getting it several times. What's even more confusing, my spec passes without DRB, but with DRB is when all the multiple errors show up. At the moment I have stripped away all but one spec in the file, one that checks for errors when you validate a new object but the problem still persists even with this very basic spec. Any ideas would be greatly appreciated! Thanks -- Posted via http://www.ruby-forum.com/. From rspec.user at gmail.com Mon Dec 10 09:04:22 2007 From: rspec.user at gmail.com (sinclair bain) Date: Mon, 10 Dec 2007 09:04:22 -0500 Subject: [rspec-users] TextMate Sidebar In-Reply-To: <20F77C68-EA19-4780-9968-6B70A382A946@railsnewbie.com> References: <2ca660dd0712071257h636e58e6y96c78a7cefa6798a@mail.gmail.com> <20F77C68-EA19-4780-9968-6B70A382A946@railsnewbie.com> Message-ID: <2ca660dd0712100604y4de3ae2aye1e4941174927e04@mail.gmail.com> Great ! Thanks Scott! On Dec 7, 2007 4:19 PM, Scott Taylor wrote: > > On Dec 7, 2007, at 3:57 PM, sinclair bain wrote: > > Hey Jed, > Can you please provide a link to the recording you mentioned ? > > That would be great! > > > > I would imagine he's talking about this: > > http://rubyconf2007.confreaks.com/ > > Scott > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Cheers! sinclair -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071210/ad53c69c/attachment.html From aslak.hellesoy at gmail.com Mon Dec 10 09:32:50 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Mon, 10 Dec 2007 15:32:50 +0100 Subject: [rspec-users] Duplicate error messages In-Reply-To: References: Message-ID: <8d961d900712100632l1d398b14iabafabd6569f77b6@mail.gmail.com> On Dec 10, 2007 2:40 PM, Richard Manyanza wrote: > I am running rails 1.2.3 and rspec 1.0.8 on os X 10.4 and I am having a > problem with one of my model specs (User class). For some reason rspec > is throwing repeating errors. If the error I expect is "email is > required", I end up getting it several times. What's even more > confusing, my spec passes without DRB, but with DRB is when all the > multiple errors show up. At the moment I have stripped away all but one > spec in the file, one that checks for errors when you validate a new > object but the problem still persists even with this very basic spec. > Any ideas would be greatly appreciated! > how about some code and error messages aslak > Thanks > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Mon Dec 10 10:08:26 2007 From: lists at ruby-forum.com (Richard Manyanza) Date: Mon, 10 Dec 2007 16:08:26 +0100 Subject: [rspec-users] Duplicate error messages In-Reply-To: <8d961d900712100632l1d398b14iabafabd6569f77b6@mail.gmail.com> References: <8d961d900712100632l1d398b14iabafabd6569f77b6@mail.gmail.com> Message-ID: <93f81801838330bd2451df53088a0ca5@ruby-forum.com> > > how about some code and error messages > > aslak Sorry, I should have done that earlier. At the moment I'm running a very basic spec file, I've stripped out the rest as I figure this out. user_spec.rb ------------ require File.dirname(__FILE__) + '/../spec_helper' describe User, "when first created" do before(:each) do @user = User.new end it "should be invalid with 7 errors" do @user.should_not be_valid @user.errors.count.should == 7 end end In user.rb I have --------------- validates_presence_of :first_name, :surname, :login, :email, :mobile, :message => "is required" With DRB I get --------------- ruby script/spec -X spec/models/user_spec.rb F 1) 'User when first created should be invalid with 7 errors' FAILED expected: 7, got: 32 (using ==) ./spec/models/user_spec.rb:10: Finished in 0.026632 seconds 1 example, 1 failure And without DRB I get ----------------------- ruby script/spec spec/models/user_spec.rb . Finished in 0.190591 seconds 1 example, 0 failures When I check the 32 errors above, I find repeating messages of email required, first name required etc. I'm using svn and the whole spec was actually working before (I really should have started using autotest earlier). So something along the way got broke. I have 9 other models and their specs work just fine. And in the web browser I only get the expected 7 errors. -- Posted via http://www.ruby-forum.com/. From brandon at collectiveidea.com Mon Dec 10 12:42:35 2007 From: brandon at collectiveidea.com (Brandon Keepers) Date: Mon, 10 Dec 2007 12:42:35 -0500 Subject: [rspec-users] strange error on mock proxy In-Reply-To: <3700D3A0-A110-468F-888D-9DBFDCFB4D14@collectiveidea.com> References: <3700D3A0-A110-468F-888D-9DBFDCFB4D14@collectiveidea.com> Message-ID: David, Did you ever get a chance to look at this to see if I am missing something obvious. I'm getting these errors randomly. Brandon On Dec 7, 2007, at 11:42 AM, Brandon Keepers wrote: > I'm banging my head over this really strange error in a view test > when I run "rake spec". The weird thing is that I don't get the > error when I run the spec file by itself. > > Here is the spec (I know, fixtures are the devil): > > describe "/units/new.html.erb here" do > fixtures :units, :accounts, :groups > it_should_behave_like '/units/_form' > > before do > login_as :cathy > assigns[:unit] = @unit = Unit.new > @groups = accounts(:dawson).groups > render "/units/new.html" > end > > it "should render new form" do > response.should have_tag("form[action=?][method=post]", units_path) > end > > end > > And the error: > > 4) > ActionView::TemplateError in 'Spec::Rails::Example::ViewExampleGroup/ > units/new.html.erb should render new form' > You have a nil object when you didn't expect it! > You might have expected an instance of Array. > The error occurred while evaluating nil.include? > On line #13 of units/_form.html.erb > > 10: <% unless @unit.root? -%> > 11:
  • > 12: > 13: <%= f.select :parent_id, [1,2,3] %> > 14: <%#= f.select :parent_id, > 15: nested_set_options_for_select(current_account.units.root) > {|u| "#{'?' * u.level} #{u.name}"} %> > 16:
  • > > vendor/plugins/rspec/lib/spec/mocks/proxy.rb:71:in `send' > vendor/plugins/rspec/lib/spec/mocks/proxy.rb:71:in > `message_received' > vendor/plugins/rspec/lib/spec/mocks/proxy.rb:100:in `include?' > vendor/rails/actionpack/lib/action_view/helpers/ > form_options_helper.rb:304:in `option_value_selected?' > vendor/rails/actionpack/lib/action_view/helpers/ > form_options_helper.rb:163:in `options_for_select' > vendor/rails/actionpack/lib/action_view/helpers/text_helper.rb: > 29:in `inject' > vendor/rails/actionpack/lib/action_view/helpers/ > form_options_helper.rb:161:in `each' > vendor/rails/actionpack/lib/action_view/helpers/ > form_options_helper.rb:161:in `inject' > vendor/rails/actionpack/lib/action_view/helpers/ > form_options_helper.rb:161:in `options_for_select' > vendor/rails/actionpack/lib/action_view/helpers/ > form_options_helper.rb:358:in `to_select_tag' > vendor/rails/actionpack/lib/action_view/helpers/ > form_options_helper.rb:84:in `select' > vendor/rails/actionpack/lib/action_view/helpers/ > form_options_helper.rb:409:in `select' > app/views//units/_form.html.erb:13:in > `_run_47app47views47units47_form46html46erb' > vendor/rails/actionpack/lib/action_view/base.rb:390:in `send' > vendor/rails/actionpack/lib/action_view/base.rb:390:in > `compile_and_render_template' > vendor/rails/actionpack/lib/action_view/base.rb:366:in > `render_template' > vendor/rails/actionpack/lib/action_view/base.rb:316:in > `globalize_old_render_file' > vendor/plugins/globalize/lib/globalize/rails/action_view.rb:18:in > `render_file' > vendor/rails/actionpack/lib/action_view/base.rb:331:in > `orig_render' > vendor/plugins/rspec_on_rails/lib/spec/rails/extensions/ > action_view/base.rb:22:in `render' > vendor/rails/actionpack/lib/action_view/partials.rb:117:in > `render_partial' > vendor/rails/actionpack/lib/action_controller/benchmarking.rb: > 26:in `benchmark' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ > ruby/1.8/benchmark.rb:293:in `measure' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ > ruby/1.8/benchmark.rb:307:in `realtime' > vendor/rails/actionpack/lib/action_controller/benchmarking.rb: > 26:in `benchmark' > vendor/rails/actionpack/lib/action_view/partials.rb:116:in > `render_partial' > vendor/plugins/rspec_on_rails/lib/spec/rails/extensions/ > action_view/base.rb:13:in `render_partial' > vendor/rails/actionpack/lib/action_view/base.rb:352:in > `orig_render' > vendor/plugins/rspec_on_rails/lib/spec/rails/extensions/ > action_view/base.rb:22:in `render' > app/views//units/new.html.erb:6:in > `_run_47app47views47units47new46html46erb' > vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb: > 248:in `fields_for' > vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb: > 184:in `form_for' > app/views//units/new.html.erb:5:in > `_run_47app47views47units47new46html46erb' > vendor/rails/actionpack/lib/action_view/base.rb:390:in `send' > vendor/rails/actionpack/lib/action_view/base.rb:390:in > `compile_and_render_template' > vendor/rails/actionpack/lib/action_view/base.rb:366:in > `render_template' > vendor/rails/actionpack/lib/action_view/base.rb:316:in > `globalize_old_render_file' > vendor/plugins/globalize/lib/globalize/rails/action_view.rb:18:in > `render_file' > vendor/rails/actionpack/lib/action_controller/base.rb:1109:in > `render_for_file' > vendor/rails/actionpack/lib/action_controller/base.rb:861:in > `render_with_no_layout' > vendor/rails/actionpack/lib/action_controller/layout.rb:269:in > `render_without_benchmark' > vendor/rails/actionpack/lib/action_controller/benchmarking.rb: > 51:in `render' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ > ruby/1.8/benchmark.rb:293:in `measure' > vendor/rails/actionpack/lib/action_controller/benchmarking.rb: > 51:in `render' > vendor/plugins/rspec_on_rails/lib/spec/rails/example/ > view_example_group.rb:129:in `send' > vendor/plugins/rspec_on_rails/lib/spec/rails/example/ > view_example_group.rb:129:in `render' > spec/views/units/new.html.erb_spec.rb:11 > vendor/plugins/rspec/lib/spec/example/example_methods.rb:42:in > `instance_eval' > vendor/plugins/rspec/lib/spec/example/example_methods.rb:42:in > `eval_each_fail_fast' > vendor/plugins/rspec/lib/spec/example/example_methods.rb:41:in > `each' > vendor/plugins/rspec/lib/spec/example/example_methods.rb:41:in > `eval_each_fail_fast' > vendor/plugins/rspec/lib/spec/example/example_group_methods.rb: > 216:in `run_before_each' > vendor/plugins/rspec/lib/spec/example/example_group_methods.rb: > 316:in `execute_in_class_hierarchy' > vendor/plugins/rspec/lib/spec/example/example_group_methods.rb: > 315:in `each' > vendor/plugins/rspec/lib/spec/example/example_group_methods.rb: > 315:in `execute_in_class_hierarchy' > vendor/plugins/rspec/lib/spec/example/example_group_methods.rb: > 215:in `run_before_each' > vendor/plugins/rspec/lib/spec/example/example_methods.rb:65:in > `before_example' > vendor/plugins/rspec/lib/spec/example/example_methods.rb:13:in > `execute' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ > ruby/1.8/timeout.rb:48:in `timeout' > vendor/plugins/rspec/lib/spec/example/example_methods.rb:11:in > `execute' > vendor/plugins/rspec/lib/spec/example/example_group_methods.rb: > 256:in `execute_examples' > vendor/plugins/rspec/lib/spec/example/example_group_methods.rb: > 254:in `each' > vendor/plugins/rspec/lib/spec/example/example_group_methods.rb: > 254:in `execute_examples' > vendor/plugins/rspec/lib/spec/example/example_group_methods.rb: > 115:in `run' > vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb: > 22:in `run' > vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb: > 21:in `each' > vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb: > 21:in `run' > vendor/plugins/rspec/lib/spec/runner/options.rb:85:in > `run_examples' > vendor/plugins/rspec/lib/spec/runner/command_line.rb:19:in `run' > vendor/plugins/rspec/bin/spec:3 > > > I'm not sure why the error is in the mock proxy because this spec > isn't using mocking at all. > > Any ideas? > > Brandon -------------- next part -------------- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 186 bytes Desc: This is a digitally signed message part Url : http://rubyforge.org/pipermail/rspec-users/attachments/20071210/9f83d4bc/attachment.bin From dchelimsky at gmail.com Mon Dec 10 12:55:52 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 10 Dec 2007 11:55:52 -0600 Subject: [rspec-users] strange error on mock proxy In-Reply-To: References: <3700D3A0-A110-468F-888D-9DBFDCFB4D14@collectiveidea.com> Message-ID: <57c63afe0712100955y217c5aa4m2edf0690da318089@mail.gmail.com> On Dec 10, 2007 11:42 AM, Brandon Keepers wrote: > David, > > Did you ever get a chance to look at this to see if I am missing > something obvious. I'm getting these errors randomly. Haven't yet. Anybody else on this list having a similar experience? > > Brandon > > > On Dec 7, 2007, at 11:42 AM, Brandon Keepers wrote: > > > I'm banging my head over this really strange error in a view test > > when I run "rake spec". The weird thing is that I don't get the > > error when I run the spec file by itself. > > > > Here is the spec (I know, fixtures are the devil): > > > > describe "/units/new.html.erb here" do > > fixtures :units, :accounts, :groups > > it_should_behave_like '/units/_form' > > > > before do > > login_as :cathy > > assigns[:unit] = @unit = Unit.new > > @groups = accounts(:dawson).groups > > render "/units/new.html" > > end > > > > it "should render new form" do > > response.should have_tag("form[action=?][method=post]", units_path) > > end > > > > end > > > > And the error: > > > > 4) > > ActionView::TemplateError in 'Spec::Rails::Example::ViewExampleGroup/ > > units/new.html.erb should render new form' > > You have a nil object when you didn't expect it! > > You might have expected an instance of Array. > > The error occurred while evaluating nil.include? > > On line #13 of units/_form.html.erb > > > > 10: <% unless @unit.root? -%> > > 11:
  • > > 12: > > 13: <%= f.select :parent_id, [1,2,3] %> > > 14: <%#= f.select :parent_id, > > 15: nested_set_options_for_select(current_account.units.root) > > {|u| "#{'?' * u.level} #{u.name}"} %> > > 16:
  • > > > > vendor/plugins/rspec/lib/spec/mocks/proxy.rb:71:in `send' > > vendor/plugins/rspec/lib/spec/mocks/proxy.rb:71:in > > `message_received' > > vendor/plugins/rspec/lib/spec/mocks/proxy.rb:100:in `include?' > > vendor/rails/actionpack/lib/action_view/helpers/ > > form_options_helper.rb:304:in `option_value_selected?' > > vendor/rails/actionpack/lib/action_view/helpers/ > > form_options_helper.rb:163:in `options_for_select' > > vendor/rails/actionpack/lib/action_view/helpers/text_helper.rb: > > 29:in `inject' > > vendor/rails/actionpack/lib/action_view/helpers/ > > form_options_helper.rb:161:in `each' > > vendor/rails/actionpack/lib/action_view/helpers/ > > form_options_helper.rb:161:in `inject' > > vendor/rails/actionpack/lib/action_view/helpers/ > > form_options_helper.rb:161:in `options_for_select' > > vendor/rails/actionpack/lib/action_view/helpers/ > > form_options_helper.rb:358:in `to_select_tag' > > vendor/rails/actionpack/lib/action_view/helpers/ > > form_options_helper.rb:84:in `select' > > vendor/rails/actionpack/lib/action_view/helpers/ > > form_options_helper.rb:409:in `select' > > app/views//units/_form.html.erb:13:in > > `_run_47app47views47units47_form46html46erb' > > vendor/rails/actionpack/lib/action_view/base.rb:390:in `send' > > vendor/rails/actionpack/lib/action_view/base.rb:390:in > > `compile_and_render_template' > > vendor/rails/actionpack/lib/action_view/base.rb:366:in > > `render_template' > > vendor/rails/actionpack/lib/action_view/base.rb:316:in > > `globalize_old_render_file' > > vendor/plugins/globalize/lib/globalize/rails/action_view.rb:18:in > > `render_file' > > vendor/rails/actionpack/lib/action_view/base.rb:331:in > > `orig_render' > > vendor/plugins/rspec_on_rails/lib/spec/rails/extensions/ > > action_view/base.rb:22:in `render' > > vendor/rails/actionpack/lib/action_view/partials.rb:117:in > > `render_partial' > > vendor/rails/actionpack/lib/action_controller/benchmarking.rb: > > 26:in `benchmark' > > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ > > ruby/1.8/benchmark.rb:293:in `measure' > > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ > > ruby/1.8/benchmark.rb:307:in `realtime' > > vendor/rails/actionpack/lib/action_controller/benchmarking.rb: > > 26:in `benchmark' > > vendor/rails/actionpack/lib/action_view/partials.rb:116:in > > `render_partial' > > vendor/plugins/rspec_on_rails/lib/spec/rails/extensions/ > > action_view/base.rb:13:in `render_partial' > > vendor/rails/actionpack/lib/action_view/base.rb:352:in > > `orig_render' > > vendor/plugins/rspec_on_rails/lib/spec/rails/extensions/ > > action_view/base.rb:22:in `render' > > app/views//units/new.html.erb:6:in > > `_run_47app47views47units47new46html46erb' > > vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb: > > 248:in `fields_for' > > vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb: > > 184:in `form_for' > > app/views//units/new.html.erb:5:in > > `_run_47app47views47units47new46html46erb' > > vendor/rails/actionpack/lib/action_view/base.rb:390:in `send' > > vendor/rails/actionpack/lib/action_view/base.rb:390:in > > `compile_and_render_template' > > vendor/rails/actionpack/lib/action_view/base.rb:366:in > > `render_template' > > vendor/rails/actionpack/lib/action_view/base.rb:316:in > > `globalize_old_render_file' > > vendor/plugins/globalize/lib/globalize/rails/action_view.rb:18:in > > `render_file' > > vendor/rails/actionpack/lib/action_controller/base.rb:1109:in > > `render_for_file' > > vendor/rails/actionpack/lib/action_controller/base.rb:861:in > > `render_with_no_layout' > > vendor/rails/actionpack/lib/action_controller/layout.rb:269:in > > `render_without_benchmark' > > vendor/rails/actionpack/lib/action_controller/benchmarking.rb: > > 51:in `render' > > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ > > ruby/1.8/benchmark.rb:293:in `measure' > > vendor/rails/actionpack/lib/action_controller/benchmarking.rb: > > 51:in `render' > > vendor/plugins/rspec_on_rails/lib/spec/rails/example/ > > view_example_group.rb:129:in `send' > > vendor/plugins/rspec_on_rails/lib/spec/rails/example/ > > view_example_group.rb:129:in `render' > > spec/views/units/new.html.erb_spec.rb:11 > > vendor/plugins/rspec/lib/spec/example/example_methods.rb:42:in > > `instance_eval' > > vendor/plugins/rspec/lib/spec/example/example_methods.rb:42:in > > `eval_each_fail_fast' > > vendor/plugins/rspec/lib/spec/example/example_methods.rb:41:in > > `each' > > vendor/plugins/rspec/lib/spec/example/example_methods.rb:41:in > > `eval_each_fail_fast' > > vendor/plugins/rspec/lib/spec/example/example_group_methods.rb: > > 216:in `run_before_each' > > vendor/plugins/rspec/lib/spec/example/example_group_methods.rb: > > 316:in `execute_in_class_hierarchy' > > vendor/plugins/rspec/lib/spec/example/example_group_methods.rb: > > 315:in `each' > > vendor/plugins/rspec/lib/spec/example/example_group_methods.rb: > > 315:in `execute_in_class_hierarchy' > > vendor/plugins/rspec/lib/spec/example/example_group_methods.rb: > > 215:in `run_before_each' > > vendor/plugins/rspec/lib/spec/example/example_methods.rb:65:in > > `before_example' > > vendor/plugins/rspec/lib/spec/example/example_methods.rb:13:in > > `execute' > > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ > > ruby/1.8/timeout.rb:48:in `timeout' > > vendor/plugins/rspec/lib/spec/example/example_methods.rb:11:in > > `execute' > > vendor/plugins/rspec/lib/spec/example/example_group_methods.rb: > > 256:in `execute_examples' > > vendor/plugins/rspec/lib/spec/example/example_group_methods.rb: > > 254:in `each' > > vendor/plugins/rspec/lib/spec/example/example_group_methods.rb: > > 254:in `execute_examples' > > vendor/plugins/rspec/lib/spec/example/example_group_methods.rb: > > 115:in `run' > > vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb: > > 22:in `run' > > vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb: > > 21:in `each' > > vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb: > > 21:in `run' > > vendor/plugins/rspec/lib/spec/runner/options.rb:85:in > > `run_examples' > > vendor/plugins/rspec/lib/spec/runner/command_line.rb:19:in `run' > > vendor/plugins/rspec/bin/spec:3 > > > > > > I'm not sure why the error is in the mock proxy because this spec > > isn't using mocking at all. > > > > Any ideas? > > > > Brandon > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jeroen.houben at lostboys.nl Mon Dec 10 13:25:09 2007 From: jeroen.houben at lostboys.nl (Jeroen Houben) Date: Mon, 10 Dec 2007 19:25:09 +0100 Subject: [rspec-users] strange error on mock proxy In-Reply-To: <57c63afe0712100955y217c5aa4m2edf0690da318089@mail.gmail.com> Message-ID: On 12/10/07 6:55 PM, "David Chelimsky" wrote: > On Dec 10, 2007 11:42 AM, Brandon Keepers wrote: >> David, >> >> Did you ever get a chance to look at this to see if I am missing >> something obvious. I'm getting these errors randomly. > > Haven't yet. Anybody else on this list having a similar experience? I've also been getting very confused with specs failing with rake:spec but passing when running focused examples (e.g.from textmate). This is without fixtures but using mocks. It's as if the mocks were somehow remembering the should_receive declarations between specs. They didn't seem to get updated. Turned out I made a mistake a using partial mocks namely trying to set should_receive on the real object instead of the mock. This mistakes somehow only became apparent when running with rake:spec. I'm using flexmock 0.8, rspec plugin 1.08 with rails 1.2.6 I'm pretty sure I still get some failures in a rake:spec but not in isolation, I'll post examples when I run into them again Jeroen P.s. I had to read this bit a few times before understanding partial mocking with flexmock: "If you you give flexmock a real object in the argument list, it will treat that real object as a base for a partial mock object. The return value m may be used to set expectations. The real_object should be used in the reference portion of the test." http://onestepback.org/software/flexmock/ From james.deville at gmail.com Mon Dec 10 14:34:20 2007 From: james.deville at gmail.com (James Deville) Date: Mon, 10 Dec 2007 11:34:20 -0800 Subject: [rspec-users] Selenium on Rspec Message-ID: http://www.kerrybuckley.com/2007/11/07/driving-selenium-from-the-rspec-story-runner-rbehave found via Bunk and Rambling ? Readable Selenium tests with rspec -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071210/f4ab9dc4/attachment-0001.html From daniel.ruby at tenner.org Tue Dec 11 07:18:15 2007 From: daniel.ruby at tenner.org (Daniel Tenner) Date: Tue, 11 Dec 2007 12:18:15 +0000 Subject: [rspec-users] Attachment-fu + Story Runner Message-ID: Hi all, I'm trying to run a Story Runner integration test that uploads a file through Attachment-fu. I've tried various ways of specifying the file data, from custom mocks: class MockFile < Struct.new (:original_filename, :read, :content_type); end fdata = MockFile.new "test_upload.txt", "Test Upload", "text/plain" to 'proper' railsy stubs like: fdata = ActionController::TestUploadedFile.new("../spec/fixtures/ test_upload.txt", "text/plain") The actual params are specified as: { :uploaded_data => fdata, :filename => file_reference_name(identifier) } Now, this is being passed successfully into attachment-fu, where it is processed. Well, almost successfully. Somehow, along the way, the TestUploadedFile, struct, mock, whatever you want, gets turned into a String. Then it blows up when attachment-fu tries to retrieve the content type: #":String> Somehow, I can't seem to pass anything but a String down into the controller. Even in the action, the TestUploadedFile is already transmogrified into a String (which, of course, has no content_type property). I put a logging statement in the ActionController too, and it seems that the entire params hash is turned into a string somewhere in there - which would explain why the object has literally no chance of going through. I'm a bit stumped by this. I guess it makes sense that params are turned into strings - but then what sort of string should i specify for a file upload? Thanks for any help. Daniel From dchelimsky at gmail.com Tue Dec 11 08:28:33 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 11 Dec 2007 07:28:33 -0600 Subject: [rspec-users] Attachment-fu + Story Runner In-Reply-To: References: Message-ID: <57c63afe0712110528l7551f346r86adf8ca71790e91@mail.gmail.com> On Dec 11, 2007 6:18 AM, Daniel Tenner wrote: > Hi all, > > I'm trying to run a Story Runner integration test that uploads a file > through Attachment-fu. > > I've tried various ways of specifying the file data, from custom mocks: > class MockFile < Struct.new > (:original_filename, :read, :content_type); end > fdata = MockFile.new "test_upload.txt", "Test Upload", "text/plain" > > to 'proper' railsy stubs like: > > fdata = ActionController::TestUploadedFile.new("../spec/fixtures/ > test_upload.txt", "text/plain") > > The actual params are specified as: > { :uploaded_data => fdata, > :filename => file_reference_name(identifier) > } > > Now, this is being passed successfully into attachment-fu, where it > is processed. Well, almost successfully. Somehow, along the way, the > TestUploadedFile, struct, mock, whatever you want, gets turned into a > String. Then it blows up when attachment-fu tries to retrieve the > content type: > > # "#":String> > > Somehow, I can't seem to pass anything but a String down into the > controller. Even in the action, the TestUploadedFile is already > transmogrified into a String (which, of course, has no content_type > property). I put a logging statement in the ActionController too, and > it seems that the entire params hash is turned into a string > somewhere in there - which would explain why the object has literally > no chance of going through. > > I'm a bit stumped by this. I guess it makes sense that params are > turned into strings - but then what sort of string should i specify > for a file upload? > > Thanks for any help. Code please. From daniel.ruby at tenner.org Tue Dec 11 08:57:35 2007 From: daniel.ruby at tenner.org (Daniel Tenner) Date: Tue, 11 Dec 2007 13:57:35 +0000 Subject: [rspec-users] Attachment-fu + Story Runner In-Reply-To: <57c63afe0712110528l7551f346r86adf8ca71790e91@mail.gmail.com> References: <57c63afe0712110528l7551f346r86adf8ca71790e91@mail.gmail.com> Message-ID: <8D52CE6F-5E7A-47E7-A436-7098186978E3@tenner.org> I've pasted up the code at: http://pastie.caboo.se/126925 Since there are quite a few files involved. Thanks for your time, Daniel On 11 Dec 2007, at 13:28 11 Dec 2007, David Chelimsky wrote: > On Dec 11, 2007 6:18 AM, Daniel Tenner wrote: >> Hi all, >> >> I'm trying to run a Story Runner integration test that uploads a file >> through Attachment-fu. >> >> I've tried various ways of specifying the file data, from custom >> mocks: >> class MockFile < Struct.new >> (:original_filename, :read, :content_type); end >> fdata = MockFile.new "test_upload.txt", "Test Upload", "text/plain" >> >> to 'proper' railsy stubs like: >> >> fdata = ActionController::TestUploadedFile.new("../spec/fixtures/ >> test_upload.txt", "text/plain") >> >> The actual params are specified as: >> { :uploaded_data => fdata, >> :filename => file_reference_name(identifier) >> } >> >> Now, this is being passed successfully into attachment-fu, where it >> is processed. Well, almost successfully. Somehow, along the way, the >> TestUploadedFile, struct, mock, whatever you want, gets turned into a >> String. Then it blows up when attachment-fu tries to retrieve the >> content type: >> >> #> "#":String> >> >> Somehow, I can't seem to pass anything but a String down into the >> controller. Even in the action, the TestUploadedFile is already >> transmogrified into a String (which, of course, has no content_type >> property). I put a logging statement in the ActionController too, and >> it seems that the entire params hash is turned into a string >> somewhere in there - which would explain why the object has literally >> no chance of going through. >> >> I'm a bit stumped by this. I guess it makes sense that params are >> turned into strings - but then what sort of string should i specify >> for a file upload? >> >> Thanks for any help. > > Code please. > _______________________________________________ > 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/20071211/53542cf6/attachment.html From luislavena at gmail.com Tue Dec 11 09:39:22 2007 From: luislavena at gmail.com (Luis Lavena) Date: Tue, 11 Dec 2007 11:39:22 -0300 Subject: [rspec-users] Attachment-fu + Story Runner In-Reply-To: <8D52CE6F-5E7A-47E7-A436-7098186978E3@tenner.org> References: <57c63afe0712110528l7551f346r86adf8ca71790e91@mail.gmail.com> <8D52CE6F-5E7A-47E7-A436-7098186978E3@tenner.org> Message-ID: <71166b3b0712110639p3acb5c3am16cddc67a9cb619d@mail.gmail.com> On Dec 11, 2007 10:57 AM, Daniel Tenner wrote: > > I've pasted up the code at: > > http://pastie.caboo.se/126925 > > Since there are quite a few files involved. > > Thanks for your time, > A similar discussion was raised back in november (about fixture_file_upload): http://rubyforge.org/pipermail/rspec-users/2007-November/004378.html Instead of mocking the FileUpload, why not provide a real one? After all, the StoryRunner is aimed to fully exercise your code :-D Also, adjust the path of your TestFileUpload file location, instead of a relative one (../spec/fixtures) provide one related to RAILS_ROOT, which will work no matter where you put your helper or what is your current directory (Dir.chdir). HTH, -- Luis Lavena Multimedia systems - A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools. Douglas Adams From daniel.ruby at tenner.org Tue Dec 11 09:54:56 2007 From: daniel.ruby at tenner.org (Daniel Tenner) Date: Tue, 11 Dec 2007 14:54:56 +0000 Subject: [rspec-users] Attachment-fu + Story Runner In-Reply-To: <71166b3b0712110639p3acb5c3am16cddc67a9cb619d@mail.gmail.com> References: <57c63afe0712110528l7551f346r86adf8ca71790e91@mail.gmail.com> <8D52CE6F-5E7A-47E7-A436-7098186978E3@tenner.org> <71166b3b0712110639p3acb5c3am16cddc67a9cb619d@mail.gmail.com> Message-ID: Hi Luis, I read through that thread, but unfortunately it wasn't much help. fixture_file_upload also creates an ActionController::TestUploadedFile. It's is just a shortcut to ActionController::TestUploadedFile.new. There's no problem with the path - it creates the fixture and loads the file, and has the right values inside if I inspect the params directly before posting them: {:filename=>"file- TFile.txt", :uploaded_data=>#, @tempfile=#, @original_filename="test_upload.txt">} It's only once this is passed into the controller that it all gets to_s'ed. I like the idea of 'providing a real file upload', but I'm not sure how to do that in a Story... if anyone has any suggestions or pointers, they would be welcome! Thanks, Daniel On 11 Dec 2007, at 14:39 11 Dec 2007, Luis Lavena wrote: > On Dec 11, 2007 10:57 AM, Daniel Tenner > wrote: >> >> I've pasted up the code at: >> >> http://pastie.caboo.se/126925 >> >> Since there are quite a few files involved. >> >> Thanks for your time, >> > > A similar discussion was raised back in november (about > fixture_file_upload): > > http://rubyforge.org/pipermail/rspec-users/2007-November/004378.html > > Instead of mocking the FileUpload, why not provide a real one? > > After all, the StoryRunner is aimed to fully exercise your code :-D > > Also, adjust the path of your TestFileUpload file location, instead of > a relative one (../spec/fixtures) provide one related to RAILS_ROOT, > which will work no matter where you put your helper or what is your > current directory (Dir.chdir). > > HTH, > > -- > Luis Lavena > Multimedia systems > - > A common mistake that people make when trying to design > something completely foolproof is to underestimate > the ingenuity of complete fools. > Douglas Adams > _______________________________________________ > 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/20071211/b140ad3e/attachment-0001.html From keith at dancingtext.com Tue Dec 11 10:49:05 2007 From: keith at dancingtext.com (Keith McDonnell) Date: Tue, 11 Dec 2007 15:49:05 +0000 Subject: [rspec-users] Fresh rspec on rails install blows up Message-ID: <475EB171.1060105@dancingtext.com> Hi there, I installed the rspec on rails plugin for a new project today and guess what -- it blows up! All by other rspec on rails projects are working fine. I updated all gems & still no joy. Any ideas how I can troubleshoot this one ? Here's my setup: - ruby 1.8.4 (2005-12-24) [powerpc-darwin8.7.0] - Rails 1.2.5 Installed with svn: ruby script/plugin install svn://rubyforge.org/var/svn/rspec/tags/CURRENT/rspec ruby script/plugin install svn://rubyforge.org/var/svn/rspec/tags/CURRENT/rspec_on_rails ruby script/generate rspec [Created a model] Here's the error: /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:404:in `to_constant_name': Anonymous modules have no name to be referenced by (ArgumentError) from /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:214:in `qualified_name_for' from /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:476:in `const_missing' from /Users/kmcd/work/banknote/vendor/plugins/rspec/lib/spec/example/example_group_factory.rb:7:in `reset' from /Users/kmcd/work/banknote/vendor/plugins/rspec/lib/spec/example/example_group_factory.rb:59 from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require' from /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:495:in `require' from /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:342:in `new_constants_in' from /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:495:in `require' ... 47 levels... from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.8/lib/spec/runner/behaviour_runner.rb:19:in `run' from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.8/lib/spec/runner/command_line.rb:17:in `run' from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.8/bin/spec:3 from /usr/local/bin/spec:16 Regards, Keith From dchelimsky at gmail.com Tue Dec 11 11:55:33 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 11 Dec 2007 10:55:33 -0600 Subject: [rspec-users] Fresh rspec on rails install blows up In-Reply-To: <475EB171.1060105@dancingtext.com> References: <475EB171.1060105@dancingtext.com> Message-ID: <57c63afe0712110855s5f608e67pdf3e06b845510fcd@mail.gmail.com> On Dec 11, 2007 9:49 AM, Keith McDonnell wrote: > Hi there, > > I installed the rspec on rails plugin for a new project today and guess > what -- it blows up! > > All by other rspec on rails projects are working fine. > > I updated all gems & still no joy. Any ideas how I can troubleshoot this > one ? > > Here's my setup: > > - ruby 1.8.4 (2005-12-24) [powerpc-darwin8.7.0] > - Rails 1.2.5 > > Installed with svn: > ruby script/plugin install > svn://rubyforge.org/var/svn/rspec/tags/CURRENT/rspec > > ruby script/plugin install > svn://rubyforge.org/var/svn/rspec/tags/CURRENT/rspec_on_rails > > ruby script/generate rspec > > [Created a model] > > Here's the error: > > /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:404:in > `to_constant_name': Anonymous modules have no name to be referenced by > (ArgumentError) > from > /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:214:in > `qualified_name_for' > from > /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:476:in > `const_missing' > from > /Users/kmcd/work/banknote/vendor/plugins/rspec/lib/spec/example/example_group_factory.rb:7:in > `reset' > from > /Users/kmcd/work/banknote/vendor/plugins/rspec/lib/spec/example/example_group_factory.rb:59 > from > /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require' > from > /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:495:in > `require' > from > /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:342:in > `new_constants_in' > from > /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:495:in > `require' > ... 47 levels... > from > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.8/lib/spec/runner/behaviour_runner.rb:19:in > `run' > from > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.8/lib/spec/runner/command_line.rb:17:in > `run' > from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.8/bin/spec:3 > from /usr/local/bin/spec:16 Looks like it's using your installed gem instead of the rspec installed in your plugins directory. Don't know why that is (it should check to see if the plugin is there first). Try uninstalling the gem and see if you still have the problem. > > Regards, > > Keith > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Tue Dec 11 12:28:14 2007 From: lists at ruby-forum.com (Chris Olsen) Date: Tue, 11 Dec 2007 18:28:14 +0100 Subject: [rspec-users] can't access helper methods for model testing Message-ID: I would like to have some valid mock models readily available in the helper module, but when I try to access the helper I get the error saying that the method is not found. ======= describe MembersHelper do # Helper methods can be called directly in the examples (it blocks) def valid_member_mock member = mock_model(Member) member.stub!(:first_name).and_return("Joe") member.stub!(:last_name).and_return("Smith") member.stub!(:email).and_return("joe at smith.com") member.stub!(:city).and_return("LA") member.stub!(:region).and_return("CA") member.stub!(:region_code).and_return("234234") return member end end ======= require File.dirname(__FILE__) + '/../spec_helper' describe Member do before(:each) do @member = valid_member_mock end it "should be valid" do @member.should be_valid end end ======= NameError in 'Spec::Rails::Example::ModelExampleGroup Member should be valid' undefined local variable or method `valid_member_mock' for # ======= I would assume that rails is including the helper module behind the scenes, although I have explicitly made the require with no luck. What am I missing? Are these helpers only for controller tests? Thanks -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Tue Dec 11 12:33:34 2007 From: lists at ruby-forum.com (Chris Olsen) Date: Tue, 11 Dec 2007 18:33:34 +0100 Subject: [rspec-users] can't access helper methods for model testing In-Reply-To: References: Message-ID: <65a2e3f4fcafeb9be90668b20cbf5f85@ruby-forum.com> This isn't the best example, as I normally wouldn't validate a mock model, it was more for demonstration, although a bad one. -- Posted via http://www.ruby-forum.com/. From aslak.hellesoy at gmail.com Tue Dec 11 12:06:08 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 11 Dec 2007 18:06:08 +0100 Subject: [rspec-users] Fresh rspec on rails install blows up In-Reply-To: <475EB171.1060105@dancingtext.com> References: <475EB171.1060105@dancingtext.com> Message-ID: <8d961d900712110906r2198e6c8x16e30ee817ecbdbb@mail.gmail.com> On Dec 11, 2007 4:49 PM, Keith McDonnell wrote: > Hi there, > > I installed the rspec on rails plugin for a new project today and guess > what -- it blows up! > Guess what - when RSpec 1.0.8 was released (August 12 2007), the latest release of RoR was 1.2.3 (March 13 2007). Can you try one of these: * Downgrade to RoR 1.2.3 * Upgrade to RSpec trunk Aslak > All by other rspec on rails projects are working fine. > > I updated all gems & still no joy. Any ideas how I can troubleshoot this > one ? > > Here's my setup: > > - ruby 1.8.4 (2005-12-24) [powerpc-darwin8.7.0] > - Rails 1.2.5 > > Installed with svn: > ruby script/plugin install > svn://rubyforge.org/var/svn/rspec/tags/CURRENT/rspec > > ruby script/plugin install > svn://rubyforge.org/var/svn/rspec/tags/CURRENT/rspec_on_rails > > ruby script/generate rspec > > [Created a model] > > Here's the error: > > /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:404:in > `to_constant_name': Anonymous modules have no name to be referenced by > (ArgumentError) > from > /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:214:in > `qualified_name_for' > from > /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:476:in > `const_missing' > from > /Users/kmcd/work/banknote/vendor/plugins/rspec/lib/spec/example/example_group_factory.rb:7:in > `reset' > from > /Users/kmcd/work/banknote/vendor/plugins/rspec/lib/spec/example/example_group_factory.rb:59 > from > /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require' > from > /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:495:in > `require' > from > /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:342:in > `new_constants_in' > from > /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:495:in > `require' > ... 47 levels... > from > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.8/lib/spec/runner/behaviour_runner.rb:19:in > `run' > from > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.8/lib/spec/runner/command_line.rb:17:in > `run' > from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.8/bin/spec:3 > from /usr/local/bin/spec:16 > > Regards, > > Keith > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From nathan.sutton at gmail.com Tue Dec 11 13:18:43 2007 From: nathan.sutton at gmail.com (Nathan Sutton) Date: Tue, 11 Dec 2007 12:18:43 -0600 Subject: [rspec-users] RSpec TMbundle Message-ID: <0784629A-B126-46EE-96E5-EC429BACCFED@gmail.com> I tried checking it out today using instructions here: http://rspec.rubyforge.org/tools/extensions/editors/textmate.html I get a 'svn: Connection closed unexpectedly'. Did it move or is it down? Nathan Sutton fowlduck at gmail.com rspec edge revision 3052 rspec_on_rails edge revision 3049 rails edge revision 8269 From daniel.ruby at tenner.org Tue Dec 11 12:30:58 2007 From: daniel.ruby at tenner.org (Daniel Tenner) Date: Tue, 11 Dec 2007 17:30:58 +0000 Subject: [rspec-users] Attachment-fu + Story Runner In-Reply-To: References: <57c63afe0712110528l7551f346r86adf8ca71790e91@mail.gmail.com> <8D52CE6F-5E7A-47E7-A436-7098186978E3@tenner.org> <71166b3b0712110639p3acb5c3am16cddc67a9cb619d@mail.gmail.com> Message-ID: I've now located where this is going wrong, though I am not yet sure how to fix it. In rails' integration.rb, there is a method called 'process'. around line 226. It mangles the parameters by calling: data = requestify(parameters) doing: puts "\n1----===#{parameters.inspect}" puts "\n2----===#{data.inspect}" a bit later reveals the problem: 1----==={:quick_file=>{:filename=>"file- TFile.txt", :uploaded_data=>#, @original_filename="test_upload.txt">}, :quick_folder=> {:id=>1330}, :request_type=>"xml"} 2----==="quick_file%5Bfilename%5D=file-TFile.txt&quick_file% 5Buploaded_data%5D=%23%3CActionController%3A%3ATestUploadedFile% 3A0x3434150%3E&quick_folder%5Bid%5D=1330&request_type=xml" Obviously that's not going to work. I wonder how Test::Unit does it, then, though... Daniel On 11 Dec 2007, at 14:54 11 Dec 2007, Daniel Tenner wrote: > Hi Luis, > > I read through that thread, but unfortunately it wasn't much help. > > fixture_file_upload also creates an > ActionController::TestUploadedFile. It's is just a shortcut to > ActionController::TestUploadedFile.new. > > There's no problem with the path - it creates the fixture and loads > the file, and has the right values inside if I inspect the params > directly before posting them: > > {:filename=>"file- > TFile.txt", :uploaded_data=># 0x33f83bc @content_type=# @synonyms=[], @string="text/plain">, @tempfile=# test_upload29049-0.txt>, @original_filename="test_upload.txt">} > > It's only once this is passed into the controller that it all gets > to_s'ed. > > I like the idea of 'providing a real file upload', but I'm not sure > how to do that in a Story... if anyone has any suggestions or > pointers, they would be welcome! > > Thanks, > > Daniel > > On 11 Dec 2007, at 14:39 11 Dec 2007, Luis Lavena wrote: > >> On Dec 11, 2007 10:57 AM, Daniel Tenner >> wrote: >>> >>> I've pasted up the code at: >>> >>> http://pastie.caboo.se/126925 >>> >>> Since there are quite a few files involved. >>> >>> Thanks for your time, >>> >> >> A similar discussion was raised back in november (about >> fixture_file_upload): >> >> http://rubyforge.org/pipermail/rspec-users/2007-November/004378.html >> >> Instead of mocking the FileUpload, why not provide a real one? >> >> After all, the StoryRunner is aimed to fully exercise your code :-D >> >> Also, adjust the path of your TestFileUpload file location, >> instead of >> a relative one (../spec/fixtures) provide one related to RAILS_ROOT, >> which will work no matter where you put your helper or what is your >> current directory (Dir.chdir). >> >> HTH, >> >> -- >> Luis Lavena >> Multimedia systems >> - >> A common mistake that people make when trying to design >> something completely foolproof is to underestimate >> the ingenuity of complete fools. >> Douglas Adams >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.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/20071211/317c3a75/attachment-0001.html From ben at benmabey.com Tue Dec 11 13:28:30 2007 From: ben at benmabey.com (Ben Mabey) Date: Tue, 11 Dec 2007 11:28:30 -0700 Subject: [rspec-users] RSpec TMbundle In-Reply-To: <0784629A-B126-46EE-96E5-EC429BACCFED@gmail.com> References: <0784629A-B126-46EE-96E5-EC429BACCFED@gmail.com> Message-ID: <475ED6CE.1060102@benmabey.com> Nathan Sutton wrote: > I tried checking it out today using instructions here: > http://rspec.rubyforge.org/tools/extensions/editors/textmate.html > > I get a 'svn: Connection closed unexpectedly'. Did it move or is it > down? > > Nathan Sutton > fowlduck at gmail.com > rspec edge revision 3052 > rspec_on_rails edge revision 3049 > rails edge revision 8269 > > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > Last I heard it was officially moved into the Textmate bundle repo. I may be wrong, but check that out. -Ben From nathan.sutton at gmail.com Tue Dec 11 13:37:41 2007 From: nathan.sutton at gmail.com (Nathan Sutton) Date: Tue, 11 Dec 2007 12:37:41 -0600 Subject: [rspec-users] RSpec TMbundle In-Reply-To: <475ED6CE.1060102@benmabey.com> References: <0784629A-B126-46EE-96E5-EC429BACCFED@gmail.com> <475ED6CE.1060102@benmabey.com> Message-ID: I wouldn't even know what to check to determine whether it had been moved. Nathan Sutton fowlduck at gmail.com rspec edge revision 3052 rspec_on_rails edge revision 3049 rails edge revision 8269 On Dec 11, 2007, at 12:28 PM, Ben Mabey wrote: > Nathan Sutton wrote: >> I tried checking it out today using instructions here: >> http://rspec.rubyforge.org/tools/extensions/editors/textmate.html >> >> I get a 'svn: Connection closed unexpectedly'. Did it move or is it >> down? >> >> Nathan Sutton >> fowlduck at gmail.com >> rspec edge revision 3052 >> rspec_on_rails edge revision 3049 >> rails edge revision 8269 >> >> >> >> >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > Last I heard it was officially moved into the Textmate bundle repo. I > may be wrong, but check that out. > > -Ben > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Tue Dec 11 13:40:02 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 11 Dec 2007 12:40:02 -0600 Subject: [rspec-users] RSpec TMbundle In-Reply-To: <475ED6CE.1060102@benmabey.com> References: <0784629A-B126-46EE-96E5-EC429BACCFED@gmail.com> <475ED6CE.1060102@benmabey.com> Message-ID: <57c63afe0712111040s3216735br7eab23a0a15019a3@mail.gmail.com> On Dec 11, 2007 12:28 PM, Ben Mabey wrote: > > Nathan Sutton wrote: > > I tried checking it out today using instructions here: > > http://rspec.rubyforge.org/tools/extensions/editors/textmate.html > > > > I get a 'svn: Connection closed unexpectedly'. Did it move or is it > > down? > > > > Nathan Sutton > > fowlduck at gmail.com > > rspec edge revision 3052 > > rspec_on_rails edge revision 3049 > > rails edge revision 8269 > > > > > > > > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > Last I heard it was officially moved into the Textmate bundle repo. I > may be wrong, but check that out. The one in the Textmate repo is aligned w/ 1.0.8. If you want one that works w/ trunk, try http://rspec.rubyforge.org/svn/trunk/RSpec.tmbundle. From nathan.sutton at gmail.com Tue Dec 11 13:47:43 2007 From: nathan.sutton at gmail.com (Nathan Sutton) Date: Tue, 11 Dec 2007 12:47:43 -0600 Subject: [rspec-users] RSpec TMbundle In-Reply-To: <57c63afe0712111040s3216735br7eab23a0a15019a3@mail.gmail.com> References: <0784629A-B126-46EE-96E5-EC429BACCFED@gmail.com> <475ED6CE.1060102@benmabey.com> <57c63afe0712111040s3216735br7eab23a0a15019a3@mail.gmail.com> Message-ID: <869CFD3B-7891-4426-BBBA-B61570E23633@gmail.com> As usual, David to the rescue. Thanks, Nathan Sutton fowlduck at gmail.com rspec edge revision 3052 rspec_on_rails edge revision 3049 rails edge revision 8269 On Dec 11, 2007, at 12:40 PM, David Chelimsky wrote: > On Dec 11, 2007 12:28 PM, Ben Mabey wrote: >> >> Nathan Sutton wrote: >>> I tried checking it out today using instructions here: >>> http://rspec.rubyforge.org/tools/extensions/editors/textmate.html >>> >>> I get a 'svn: Connection closed unexpectedly'. Did it move or is it >>> down? >>> >>> Nathan Sutton >>> fowlduck at gmail.com >>> rspec edge revision 3052 >>> rspec_on_rails edge revision 3049 >>> rails edge revision 8269 >>> >>> >>> >>> >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> Last I heard it was officially moved into the Textmate bundle >> repo. I >> may be wrong, but check that out. > > The one in the Textmate repo is aligned w/ 1.0.8. If you want one that > works w/ trunk, try > http://rspec.rubyforge.org/svn/trunk/RSpec.tmbundle. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From jeroen.houben at lostboys.nl Tue Dec 11 14:13:30 2007 From: jeroen.houben at lostboys.nl (Jeroen Houben) Date: Tue, 11 Dec 2007 20:13:30 +0100 Subject: [rspec-users] RSpec TMbundle In-Reply-To: <57c63afe0712111040s3216735br7eab23a0a15019a3@mail.gmail.com> Message-ID: Which versions (rspec and tmbundle) should we use with rails 2 (stable)? Can we just keep using rspec 1.08 with rails2? I noticed running specs from textmate with rails2 throws some errors. /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.1/lib/active_support/dep endencies.rb:263:in `load_missing_constant': uninitialized constant ActionView::Helpers::JavaScriptMacrosHelper (NameError) from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.1/lib/active_support/dep endencies.rb:453:in `const_missing' from /Users/jeroen/rails2-lostboysnl/vendor/plugins/rspec_on_rails/lib/spec/rails /dsl/behaviour/helper.rb:31 from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require' from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.1/lib/active_support/dep endencies.rb:496:in `require' from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.1/lib/active_support/dep endencies.rb:342:in `new_constants_in' from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.1/lib/active_support/dep endencies.rb:496:in `require' from /Users/jeroen/rails2-lostboysnl/vendor/plugins/rspec_on_rails/lib/spec/rails /dsl/behaviour.rb:8 ... 29 levels... from /Users/jeroen/Library/Application Support/TextMate/Pristine Copy/Bundles/RSpec.tmbundle/Support/lib/spec_mate.rb:46:in `chdir' from /Users/jeroen/Library/Application Support/TextMate/Pristine Copy/Bundles/RSpec.tmbundle/Support/lib/spec_mate.rb:46:in `run' from /Users/jeroen/Library/Application Support/TextMate/Pristine Copy/Bundles/RSpec.tmbundle/Support/lib/spec_mate.rb:25:in `run_file' from /tmp/temp_textmate.UgXRgh:4 Thanks, Jeroen On 12/11/07 7:40 PM, "David Chelimsky" wrote: > On Dec 11, 2007 12:28 PM, Ben Mabey wrote: >> >> Nathan Sutton wrote: >>> I tried checking it out today using instructions here: >>> http://rspec.rubyforge.org/tools/extensions/editors/textmate.html >>> >>> I get a 'svn: Connection closed unexpectedly'. Did it move or is it >>> down? >>> >>> Nathan Sutton >>> fowlduck at gmail.com >>> rspec edge revision 3052 >>> rspec_on_rails edge revision 3049 >>> rails edge revision 8269 >>> >>> >>> >>> >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> Last I heard it was officially moved into the Textmate bundle repo. I >> may be wrong, but check that out. > > The one in the Textmate repo is aligned w/ 1.0.8. If you want one that > works w/ trunk, try > http://rspec.rubyforge.org/svn/trunk/RSpec.tmbundle. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From mailing_lists at railsnewbie.com Tue Dec 11 15:06:39 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Tue, 11 Dec 2007 15:06:39 -0500 Subject: [rspec-users] Transactional/Rollback problems Message-ID: <09998514-6707-4E3B-AC43-165B1078A331@railsnewbie.com> I'm having a rollback problem with rspec trunk. It doesn't seem like rollbacks are happening quite as often as they should be. It appears as though the rollbacks are *NOT* occurring on the first description block in a file, but are for the rest. Here is a set of specs that are failing: require File.dirname(__FILE__) + "/../spec_helper" describe "Rollback issue 1" do before :each do create_user end it "should have 1 user" do User.count.should == 1 end end describe "Rollback issue 2" do before :each do create_user end it "should have one user" do User.count.should == 1 end end end escher: rake db:test:prepare (in /Users/smt/src/web/urbis/trunk) escher: ./script/spec spec/models/no_rollback_issue_spec.rb .F 1) 'Rollback issue 2 should have one user (Spec::Rails::Example::ModelExampleGroup::Subclass_2)' FAILED expected: 1, got: 2 (using ==) ./spec/models/no_rollback_issue_spec.rb:19: ./script/spec:4: Finished in 0.343708 seconds 2 examples, 1 failure But, commenting out the user creation if the first description block allows the test to pass: escher: rake db:test:prepare; ./script/spec spec/models/ no_rollback_issue_spec.rb (in /Users/smt/src/web/urbis/trunk) .. Finished in 0.236502 seconds 2 examples, 0 failures I've noticed that at the start of the test log, these two lines are seen: Dec 11 14:56:20 urbis[2166]: Spec::Rails::Example::HelperBehaviourController: missing default helper path spec/rails/example/helper_behaviour_helper Dec 11 14:56:20 urbis[2166]: Spec::Rails::Example::ViewExampleGroupController: missing default helper path spec/rails/example/view_example_group_helper Don't know if these are related or not. Any feedback or help would be much appreciated, Scott (At trunk /rev. 3135 of rspec, rspec_on_rails, rails v. 1.2.3, Mac OS X.4.11) From mailing_lists at railsnewbie.com Tue Dec 11 15:56:22 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Tue, 11 Dec 2007 15:56:22 -0500 Subject: [rspec-users] Transactional/Rollback problems In-Reply-To: <09998514-6707-4E3B-AC43-165B1078A331@railsnewbie.com> References: <09998514-6707-4E3B-AC43-165B1078A331@railsnewbie.com> Message-ID: <99AB1E6B-205B-4604-9FD0-7AD2A3990E7C@railsnewbie.com> Rolling back to revision 3131 seems to have fixed the problem. I see that 3132 has the following commit message: "Tighter integration with Test::Unit for ActiveRecord fixtures. Speed up fixtures." Scott On Dec 11, 2007, at 3:06 PM, Scott Taylor wrote: > > I'm having a rollback problem with rspec trunk. It doesn't seem like > rollbacks are happening quite as often as they should be. It > appears as though the rollbacks are *NOT* occurring on the first > description block in a file, but are for the rest. Here is a set of > specs that are failing: > > require File.dirname(__FILE__) + "/../spec_helper" > > describe "Rollback issue 1" do > before :each do > create_user > end > > it "should have 1 user" do > User.count.should == 1 > end > end > > describe "Rollback issue 2" do > before :each do > create_user > end > > it "should have one user" do > User.count.should == 1 > end > end > end > > escher: rake db:test:prepare > (in /Users/smt/src/web/urbis/trunk) > escher: ./script/spec spec/models/no_rollback_issue_spec.rb > .F > > 1) > 'Rollback issue 2 should have one user > (Spec::Rails::Example::ModelExampleGroup::Subclass_2)' FAILED > expected: 1, > got: 2 (using ==) > ./spec/models/no_rollback_issue_spec.rb:19: > ./script/spec:4: > > Finished in 0.343708 seconds > > 2 examples, 1 failure > > > But, commenting out the user creation if the first description block > allows the test to pass: > > escher: rake db:test:prepare; ./script/spec spec/models/ > no_rollback_issue_spec.rb > (in /Users/smt/src/web/urbis/trunk) > .. > > Finished in 0.236502 seconds > > 2 examples, 0 failures > > > I've noticed that at the start of the test log, these two lines are > seen: > > Dec 11 14:56:20 urbis[2166]: > Spec::Rails::Example::HelperBehaviourController: missing default > helper path spec/rails/example/helper_behaviour_helper > Dec 11 14:56:20 urbis[2166]: > Spec::Rails::Example::ViewExampleGroupController: missing default > helper path spec/rails/example/view_example_group_helper > > Don't know if these are related or not. > > Any feedback or help would be much appreciated, > > Scott > > (At trunk /rev. 3135 of rspec, rspec_on_rails, rails v. 1.2.3, Mac > OS X.4.11) > > _______________________________________________ > 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/20071211/bd03ea47/attachment-0001.html From dchelimsky at gmail.com Tue Dec 11 16:16:27 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 11 Dec 2007 15:16:27 -0600 Subject: [rspec-users] Transactional/Rollback problems In-Reply-To: <99AB1E6B-205B-4604-9FD0-7AD2A3990E7C@railsnewbie.com> References: <09998514-6707-4E3B-AC43-165B1078A331@railsnewbie.com> <99AB1E6B-205B-4604-9FD0-7AD2A3990E7C@railsnewbie.com> Message-ID: <57c63afe0712111316i63673571i5a15b69f687ec813@mail.gmail.com> On Dec 11, 2007 2:56 PM, Scott Taylor wrote: > > > Rolling back to revision 3131 seems to have fixed the problem. I see that > 3132 has the following commit message: > > "Tighter integration with Test::Unit for ActiveRecord fixtures. Speed up > fixtures." You mind filing that in the lighthouse? > > Scott > > > > > > > On Dec 11, 2007, at 3:06 PM, Scott Taylor wrote: > > > I'm having a rollback problem with rspec trunk. It doesn't seem like > rollbacks are happening quite as often as they should be. It > appears as though the rollbacks are *NOT* occurring on the first > description block in a file, but are for the rest. Here is a set of > specs that are failing: > > require File.dirname(__FILE__) + "/../spec_helper" > > describe "Rollback issue 1" do > before :each do > create_user > end > > it "should have 1 user" do > User.count.should == 1 > end > end > > describe "Rollback issue 2" do > before :each do > create_user > end > > it "should have one user" do > User.count.should == 1 > end > end > end > > escher: rake db:test:prepare > (in /Users/smt/src/web/urbis/trunk) > escher: ./script/spec spec/models/no_rollback_issue_spec.rb > .F > > 1) > 'Rollback issue 2 should have one user > (Spec::Rails::Example::ModelExampleGroup::Subclass_2)' FAILED > expected: 1, > got: 2 (using ==) > ./spec/models/no_rollback_issue_spec.rb:19: > ./script/spec:4: > > Finished in 0.343708 seconds > > 2 examples, 1 failure > > > But, commenting out the user creation if the first description block > allows the test to pass: > > escher: rake db:test:prepare; ./script/spec spec/models/ > no_rollback_issue_spec.rb > (in /Users/smt/src/web/urbis/trunk) > .. > > Finished in 0.236502 seconds > > 2 examples, 0 failures > > > I've noticed that at the start of the test log, these two lines are > seen: > > Dec 11 14:56:20 urbis[2166]: > Spec::Rails::Example::HelperBehaviourController: missing default > helper path spec/rails/example/helper_behaviour_helper > Dec 11 14:56:20 urbis[2166]: > Spec::Rails::Example::ViewExampleGroupController: missing default > helper path spec/rails/example/view_example_group_helper > > Don't know if these are related or not. > > Any feedback or help would be much appreciated, > > Scott > > (At trunk /rev. 3135 of rspec, rspec_on_rails, rails v. 1.2.3, Mac > OS X.4.11) > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.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 Dec 11 16:27:54 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Tue, 11 Dec 2007 16:27:54 -0500 Subject: [rspec-users] Transactional/Rollback problems In-Reply-To: <57c63afe0712111316i63673571i5a15b69f687ec813@mail.gmail.com> References: <09998514-6707-4E3B-AC43-165B1078A331@railsnewbie.com> <99AB1E6B-205B-4604-9FD0-7AD2A3990E7C@railsnewbie.com> <57c63afe0712111316i63673571i5a15b69f687ec813@mail.gmail.com> Message-ID: <064C0D84-5F73-484D-B282-E969542A27CE@railsnewbie.com> On Dec 11, 2007, at 4:16 PM, David Chelimsky wrote: > On Dec 11, 2007 2:56 PM, Scott Taylor > wrote: >> >> >> Rolling back to revision 3131 seems to have fixed the problem. I >> see that >> 3132 has the following commit message: >> >> "Tighter integration with Test::Unit for ActiveRecord fixtures. >> Speed up >> fixtures." > > You mind filing that in the lighthouse? > will do it right now. Scott >> >> Scott >> >> >> >> >> >> >> On Dec 11, 2007, at 3:06 PM, Scott Taylor wrote: >> >> >> I'm having a rollback problem with rspec trunk. It doesn't seem like >> rollbacks are happening quite as often as they should be. It >> appears as though the rollbacks are *NOT* occurring on the first >> description block in a file, but are for the rest. Here is a set of >> specs that are failing: >> >> require File.dirname(__FILE__) + "/../spec_helper" >> >> describe "Rollback issue 1" do >> before :each do >> create_user >> end >> >> it "should have 1 user" do >> User.count.should == 1 >> end >> end >> >> describe "Rollback issue 2" do >> before :each do >> create_user >> end >> >> it "should have one user" do >> User.count.should == 1 >> end >> end >> end >> >> escher: rake db:test:prepare >> (in /Users/smt/src/web/urbis/trunk) >> escher: ./script/spec spec/models/no_rollback_issue_spec.rb >> .F >> >> 1) >> 'Rollback issue 2 should have one user >> (Spec::Rails::Example::ModelExampleGroup::Subclass_2)' FAILED >> expected: 1, >> got: 2 (using ==) >> ./spec/models/no_rollback_issue_spec.rb:19: >> ./script/spec:4: >> >> Finished in 0.343708 seconds >> >> 2 examples, 1 failure >> >> >> But, commenting out the user creation if the first description block >> allows the test to pass: >> >> escher: rake db:test:prepare; ./script/spec spec/models/ >> no_rollback_issue_spec.rb >> (in /Users/smt/src/web/urbis/trunk) >> .. >> >> Finished in 0.236502 seconds >> >> 2 examples, 0 failures >> >> >> I've noticed that at the start of the test log, these two lines are >> seen: >> >> Dec 11 14:56:20 urbis[2166]: >> Spec::Rails::Example::HelperBehaviourController: missing default >> helper path spec/rails/example/helper_behaviour_helper >> Dec 11 14:56:20 urbis[2166]: >> Spec::Rails::Example::ViewExampleGroupController: missing default >> helper path spec/rails/example/view_example_group_helper >> >> Don't know if these are related or not. >> >> Any feedback or help would be much appreciated, >> >> Scott >> >> (At trunk /rev. 3135 of rspec, rspec_on_rails, rails v. 1.2.3, Mac >> OS X.4.11) >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.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 timcharper at gmail.com Tue Dec 11 16:40:50 2007 From: timcharper at gmail.com (Tim Harper) Date: Tue, 11 Dec 2007 14:40:50 -0700 Subject: [rspec-users] rspec and rad-rails Message-ID: Quick announcement: I wrote a small enhancement to TestUnitRunner.rb to allow RadRails to run both Test::Unit cases and RSpec examples in the fancy pants GUI runner. Chris will be merging it in with future releases of RadRails, and we're going to work on getting the integration better (some limitations with the Java GUI component are preventing fuller integration). More info at the project's home page here, with a screen-shot so you know what I'm talking about: http://code.google.com/p/rad-rails-rspec-runner/ Tim -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071211/16a650e0/attachment.html From yitzhakbg at gmail.com Tue Dec 11 18:48:17 2007 From: yitzhakbg at gmail.com (Yitzhak Bar Geva) Date: Wed, 12 Dec 2007 01:48:17 +0200 Subject: [rspec-users] Rspec 1.0.8 with Rails 2.0 Message-ID: <3c0677320712111548i5c6e0a90ua9a1d4d8286c81e5@mail.gmail.com> Is it OK to go ahead and generate a Rails 2.0 project with RSpec 1.0.8? Am I likely to run into problems? Would it be best advised to wait or can I go ahead now? Thanks, Yitzhak -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071212/c6fcea0f/attachment.html From dchelimsky at gmail.com Wed Dec 12 00:09:17 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 11 Dec 2007 23:09:17 -0600 Subject: [rspec-users] can't access helper methods for model testing In-Reply-To: References: Message-ID: <57c63afe0712112109i5b1ae5cam870c2027381e2863@mail.gmail.com> On Dec 11, 2007 11:28 AM, Chris Olsen wrote: > I would like to have some valid mock models readily available in the > helper module, but when I try to access the helper I get the error > saying that the method is not found. > ======= > describe MembersHelper do # Helper methods can be called directly in the > examples (it blocks) > def valid_member_mock > member = mock_model(Member) > member.stub!(:first_name).and_return("Joe") > member.stub!(:last_name).and_return("Smith") > member.stub!(:email).and_return("joe at smith.com") > member.stub!(:city).and_return("LA") > member.stub!(:region).and_return("CA") > member.stub!(:region_code).and_return("234234") > > return member > end > end > ======= > require File.dirname(__FILE__) + '/../spec_helper' > > describe Member do > before(:each) do > @member = valid_member_mock > end > > it "should be valid" do > @member.should be_valid > end > end > ======= > NameError in 'Spec::Rails::Example::ModelExampleGroup Member should be > valid' > undefined local variable or method `valid_member_mock' for > # > ======= > > I would assume that rails is including the helper module behind the > scenes, although I have explicitly made the require with no luck. You know the old saying about assuming. When you assume ... you should write an example! > > What am I missing? Are these helpers only for controller tests? Rails helpers are there for views and controllers, not for models. If you want an RSpec helper, something you use to set up state for your examples, you can write a module and include it in the example groups - but that is a horse of a different color. HTH, David > > Thanks > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From raasdnil at gmail.com Wed Dec 12 00:10:18 2007 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Wed, 12 Dec 2007 16:10:18 +1100 Subject: [rspec-users] Alternate file jump in Textmate Message-ID: <57a815bf0712112110u4ba3635cl331b1dd5ca83bbf5@mail.gmail.com> Hello all, Using RSpec 1.1 RC from the SVN source. Running in Textmate with the bundle, all working good. Got a problem with the Alternate File jump (Ctl Shift DownArrow) because it works fine in Rails with the html.erb templates, but I can not figure out how to get it working with HAML templates that I am using. For ref, my specs are called: spec/views/users/edit.html.haml_spec.rb For the corresponding view: app/views/users/edit.html.haml When I try the jump it wants to create: app/views/users/edit.html.haml.rb Any pointers on how to fix this? Looking inside the bundle sort of left me dry and stranded... Mikel From nathan.sutton at gmail.com Wed Dec 12 00:18:32 2007 From: nathan.sutton at gmail.com (Nathan Sutton) Date: Tue, 11 Dec 2007 23:18:32 -0600 Subject: [rspec-users] Rspec 1.0.8 with Rails 2.0 In-Reply-To: <3c0677320712111548i5c6e0a90ua9a1d4d8286c81e5@mail.gmail.com> References: <3c0677320712111548i5c6e0a90ua9a1d4d8286c81e5@mail.gmail.com> Message-ID: <5A6F191A-CB40-4FE6-A999-033B5FDAF69B@gmail.com> It's likely to fall completely on its face in a horrific manner, you'll enjoy life much more if you use edge rspec. Nathan Sutton fowlduck at gmail.com rspec edge revision 3052 rspec_on_rails edge revision 3049 rails edge revision 8269 On Dec 11, 2007, at 5:48 PM, Yitzhak Bar Geva wrote: > Is it OK to go ahead and generate a Rails 2.0 project with RSpec > 1.0.8? Am I likely to run into problems? > Would it be best advised to wait or can I go ahead now? > Thanks, > Yitzhak > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From jonathan at parkerhill.com Wed Dec 12 00:19:09 2007 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Wed, 12 Dec 2007 00:19:09 -0500 Subject: [rspec-users] default_url_options Message-ID: <868B4D40-494C-49A8-A9BC-2049B3B61668@parkerhill.com> Hi, i recently added a def default_url_options to application.rb (used by url_for , *_path etc). My method references request (eg request.domain) . But when I spec a controller, its dies in default_url_options with nil.domain, Is there a way for it to see "request"? I prefer to not have to stub it on every example. linoj From stefan.landro at gmail.com Wed Dec 12 03:34:01 2007 From: stefan.landro at gmail.com (=?ISO-8859-1?Q?Stefan_Magnus_Landr=F8?=) Date: Wed, 12 Dec 2007 09:34:01 +0100 Subject: [rspec-users] Fresh rspec on rails install blows up In-Reply-To: <475EB171.1060105@dancingtext.com> References: <475EB171.1060105@dancingtext.com> Message-ID: <921ca2f80712120034t2efcc4afv1ca287c58d83d95b@mail.gmail.com> For your info, CURRENT means RSpec version 1.0.8. Try one of Aslak's solution for fixing this. HTH, Stefan 2007/12/11, Keith McDonnell : > > Hi there, > > I installed the rspec on rails plugin for a new project today and guess > what -- it blows up! > > All by other rspec on rails projects are working fine. > > I updated all gems & still no joy. Any ideas how I can troubleshoot this > one ? > > Here's my setup: > > - ruby 1.8.4 (2005-12-24) [powerpc-darwin8.7.0] > - Rails 1.2.5 > > Installed with svn: > ruby script/plugin install > svn://rubyforge.org/var/svn/rspec/tags/CURRENT/rspec > > ruby script/plugin install > svn://rubyforge.org/var/svn/rspec/tags/CURRENT/rspec_on_rails > > ruby script/generate rspec > > [Created a model] > > Here's the error: > > /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.4 > /lib/active_support/dependencies.rb:404:in > `to_constant_name': Anonymous modules have no name to be referenced by > (ArgumentError) > from > /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.4 > /lib/active_support/dependencies.rb:214:in > `qualified_name_for' > from > /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.4 > /lib/active_support/dependencies.rb:476:in > `const_missing' > from > > /Users/kmcd/work/banknote/vendor/plugins/rspec/lib/spec/example/example_group_factory.rb:7:in > `reset' > from > > /Users/kmcd/work/banknote/vendor/plugins/rspec/lib/spec/example/example_group_factory.rb:59 > from > /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in > `require' > from > /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.4 > /lib/active_support/dependencies.rb:495:in > `require' > from > /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.4 > /lib/active_support/dependencies.rb:342:in > `new_constants_in' > from > /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.4 > /lib/active_support/dependencies.rb:495:in > `require' > ... 47 levels... > from > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.8 > /lib/spec/runner/behaviour_runner.rb:19:in > `run' > from > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.8 > /lib/spec/runner/command_line.rb:17:in > `run' > from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.8/bin/spec:3 > from /usr/local/bin/spec:16 > > Regards, > > Keith > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Bekk Open Source http://boss.bekk.no -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071212/dac8811c/attachment-0001.html From stefan.landro at gmail.com Wed Dec 12 03:37:57 2007 From: stefan.landro at gmail.com (=?ISO-8859-1?Q?Stefan_Magnus_Landr=F8?=) Date: Wed, 12 Dec 2007 09:37:57 +0100 Subject: [rspec-users] Rspec 1.0.8 with Rails 2.0 In-Reply-To: <5A6F191A-CB40-4FE6-A999-033B5FDAF69B@gmail.com> References: <3c0677320712111548i5c6e0a90ua9a1d4d8286c81e5@mail.gmail.com> <5A6F191A-CB40-4FE6-A999-033B5FDAF69B@gmail.com> Message-ID: <921ca2f80712120037r7ea688bfj2281833aeafaa5fc@mail.gmail.com> I highly recommend using piston for this. Works like a breeze here. Stefan 2007/12/12, Nathan Sutton : > > It's likely to fall completely on its face in a horrific manner, > you'll enjoy life much more if you use edge rspec. > > Nathan Sutton > fowlduck at gmail.com > rspec edge revision 3052 > rspec_on_rails edge revision 3049 > rails edge revision 8269 > > On Dec 11, 2007, at 5:48 PM, Yitzhak Bar Geva wrote: > > > Is it OK to go ahead and generate a Rails 2.0 project with RSpec > > 1.0.8? Am I likely to run into problems? > > Would it be best advised to wait or can I go ahead now? > > Thanks, > > Yitzhak > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Bekk Open Source http://boss.bekk.no -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071212/25c93a5b/attachment.html From voodoorai2000 at gmail.com Wed Dec 12 04:38:49 2007 From: voodoorai2000 at gmail.com (voodoorai2000) Date: Wed, 12 Dec 2007 01:38:49 -0800 (PST) Subject: [rspec-users] Attachment-fu + Story Runner In-Reply-To: References: <57c63afe0712110528l7551f346r86adf8ca71790e91@mail.gmail.com> <8D52CE6F-5E7A-47E7-A436-7098186978E3@tenner.org> <71166b3b0712110639p3acb5c3am16cddc67a9cb619d@mail.gmail.com> Message-ID: <14291797.post@talk.nabble.com> Hi, I had the same problem, couldn't get it to run with Stories thought... Had to test file uploads using controller specs, which works but is not as clear as a Story. I'm guessing the bug where it changes the TempFile to a String will be fixed soon by the core team, but if someone has a patch it would be awesome! Rai Daniel Tenner wrote: > > I've now located where this is going wrong, though I am not yet sure > how to fix it. > > In rails' integration.rb, there is a method called 'process'. around > line 226. It mangles the parameters by calling: > data = requestify(parameters) > > doing: > puts "\n1----===#{parameters.inspect}" > puts "\n2----===#{data.inspect}" > > a bit later reveals the problem: > 1----==={:quick_file=>{:filename=>"file- > TFile.txt", :uploaded_data=># 0x3434150 @content_type="text/plain", @tempfile=# test_upload29259-0.txt>, > @original_filename="test_upload.txt">}, :quick_folder=> > {:id=>1330}, :request_type=>"xml"} > > 2----==="quick_file%5Bfilename%5D=file-TFile.txt&quick_file% > 5Buploaded_data%5D=%23%3CActionController%3A%3ATestUploadedFile% > 3A0x3434150%3E&quick_folder%5Bid%5D=1330&request_type=xml" > > Obviously that's not going to work. I wonder how Test::Unit does it, > then, though... > > Daniel > > On 11 Dec 2007, at 14:54 11 Dec 2007, Daniel Tenner wrote: > >> Hi Luis, >> >> I read through that thread, but unfortunately it wasn't much help. >> >> fixture_file_upload also creates an >> ActionController::TestUploadedFile. It's is just a shortcut to >> ActionController::TestUploadedFile.new. >> >> There's no problem with the path - it creates the fixture and loads >> the file, and has the right values inside if I inspect the params >> directly before posting them: >> >> {:filename=>"file- >> TFile.txt", :uploaded_data=>#> 0x33f83bc @content_type=#> @synonyms=[], @string="text/plain">, @tempfile=#> test_upload29049-0.txt>, @original_filename="test_upload.txt">} >> >> It's only once this is passed into the controller that it all gets >> to_s'ed. >> >> I like the idea of 'providing a real file upload', but I'm not sure >> how to do that in a Story... if anyone has any suggestions or >> pointers, they would be welcome! >> >> Thanks, >> >> Daniel >> >> On 11 Dec 2007, at 14:39 11 Dec 2007, Luis Lavena wrote: >> >>> On Dec 11, 2007 10:57 AM, Daniel Tenner >>> wrote: >>>> >>>> I've pasted up the code at: >>>> >>>> http://pastie.caboo.se/126925 >>>> >>>> Since there are quite a few files involved. >>>> >>>> Thanks for your time, >>>> >>> >>> A similar discussion was raised back in november (about >>> fixture_file_upload): >>> >>> http://rubyforge.org/pipermail/rspec-users/2007-November/004378.html >>> >>> Instead of mocking the FileUpload, why not provide a real one? >>> >>> After all, the StoryRunner is aimed to fully exercise your code :-D >>> >>> Also, adjust the path of your TestFileUpload file location, >>> instead of >>> a relative one (../spec/fixtures) provide one related to RAILS_ROOT, >>> which will work no matter where you put your helper or what is your >>> current directory (Dir.chdir). >>> >>> HTH, >>> >>> -- >>> Luis Lavena >>> Multimedia systems >>> - >>> A common mistake that people make when trying to design >>> something completely foolproof is to underestimate >>> the ingenuity of complete fools. >>> Douglas Adams >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- View this message in context: http://www.nabble.com/Attachment-fu-%2B-Story-Runner-tp14272891p14291797.html Sent from the rspec-users mailing list archive at Nabble.com. From daniel.ruby at tenner.org Wed Dec 12 06:41:11 2007 From: daniel.ruby at tenner.org (Daniel Tenner) Date: Wed, 12 Dec 2007 11:41:11 +0000 Subject: [rspec-users] Attachment-fu + Story Runner In-Reply-To: <14291797.post@talk.nabble.com> References: <57c63afe0712110528l7551f346r86adf8ca71790e91@mail.gmail.com> <8D52CE6F-5E7A-47E7-A436-7098186978E3@tenner.org> <71166b3b0712110639p3acb5c3am16cddc67a9cb619d@mail.gmail.com> <14291797.post@talk.nabble.com> Message-ID: Ok, a bit more digging and I found this is a Rails issue, that is logged here: http://dev.rubyonrails.org/ticket/4635 File uploads don't work in Rails integration tests either, only in functional tests. This is not specific to Attachment-Fu. There is, however, a monkey patch that you can download to enable a multipart_post method which will not mangle the params anymore. Hope this helps others too! Daniel On 12 Dec 2007, at 09:38 12 Dec 2007, voodoorai2000 wrote: > > Hi, > > I had the same problem, couldn't get it to run with Stories thought... > Had to test file uploads using controller specs, which works but is > not as > clear as a Story. > > I'm guessing the bug where it changes the TempFile to a String will > be fixed > soon by the core team, but if someone has a patch it would be awesome! > > > Rai > > > > Daniel Tenner wrote: >> >> I've now located where this is going wrong, though I am not yet sure >> how to fix it. >> >> In rails' integration.rb, there is a method called 'process'. around >> line 226. It mangles the parameters by calling: >> data = requestify(parameters) >> >> doing: >> puts "\n1----===#{parameters.inspect}" >> puts "\n2----===#{data.inspect}" >> >> a bit later reveals the problem: >> 1----==={:quick_file=>{:filename=>"file- >> TFile.txt", :uploaded_data=>#> 0x3434150 @content_type="text/plain", @tempfile=#> test_upload29259-0.txt>, >> @original_filename="test_upload.txt">}, :quick_folder=> >> {:id=>1330}, :request_type=>"xml"} >> >> 2----==="quick_file%5Bfilename%5D=file-TFile.txt&quick_file% >> 5Buploaded_data%5D=%23%3CActionController%3A%3ATestUploadedFile% >> 3A0x3434150%3E&quick_folder%5Bid%5D=1330&request_type=xml" >> >> Obviously that's not going to work. I wonder how Test::Unit does it, >> then, though... >> >> Daniel >> >> On 11 Dec 2007, at 14:54 11 Dec 2007, Daniel Tenner wrote: >> >>> Hi Luis, >>> >>> I read through that thread, but unfortunately it wasn't much help. >>> >>> fixture_file_upload also creates an >>> ActionController::TestUploadedFile. It's is just a shortcut to >>> ActionController::TestUploadedFile.new. >>> >>> There's no problem with the path - it creates the fixture and loads >>> the file, and has the right values inside if I inspect the params >>> directly before posting them: >>> >>> {:filename=>"file- >>> TFile.txt", :uploaded_data=>#>> 0x33f83bc @content_type=#>> @synonyms=[], @string="text/plain">, @tempfile=#>> test_upload29049-0.txt>, @original_filename="test_upload.txt">} >>> >>> It's only once this is passed into the controller that it all gets >>> to_s'ed. >>> >>> I like the idea of 'providing a real file upload', but I'm not sure >>> how to do that in a Story... if anyone has any suggestions or >>> pointers, they would be welcome! >>> >>> Thanks, >>> >>> Daniel >>> >>> On 11 Dec 2007, at 14:39 11 Dec 2007, Luis Lavena wrote: >>> >>>> On Dec 11, 2007 10:57 AM, Daniel Tenner >>>> wrote: >>>>> >>>>> I've pasted up the code at: >>>>> >>>>> http://pastie.caboo.se/126925 >>>>> >>>>> Since there are quite a few files involved. >>>>> >>>>> Thanks for your time, >>>>> >>>> >>>> A similar discussion was raised back in november (about >>>> fixture_file_upload): >>>> >>>> http://rubyforge.org/pipermail/rspec-users/2007-November/ >>>> 004378.html >>>> >>>> Instead of mocking the FileUpload, why not provide a real one? >>>> >>>> After all, the StoryRunner is aimed to fully exercise your code :-D >>>> >>>> Also, adjust the path of your TestFileUpload file location, >>>> instead of >>>> a relative one (../spec/fixtures) provide one related to >>>> RAILS_ROOT, >>>> which will work no matter where you put your helper or what is your >>>> current directory (Dir.chdir). >>>> >>>> HTH, >>>> >>>> -- >>>> Luis Lavena >>>> Multimedia systems >>>> - >>>> A common mistake that people make when trying to design >>>> something completely foolproof is to underestimate >>>> the ingenuity of complete fools. >>>> Douglas Adams >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-users at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > -- > View this message in context: http://www.nabble.com/Attachment-fu-% > 2B-Story-Runner-tp14272891p14291797.html > Sent from the rspec-users mailing list archive at Nabble.com. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071212/7b201c56/attachment-0001.html From aslak.hellesoy at gmail.com Wed Dec 12 07:01:51 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Wed, 12 Dec 2007 13:01:51 +0100 Subject: [rspec-users] Rspec 1.0.8 with Rails 2.0 In-Reply-To: <3c0677320712111548i5c6e0a90ua9a1d4d8286c81e5@mail.gmail.com> References: <3c0677320712111548i5c6e0a90ua9a1d4d8286c81e5@mail.gmail.com> Message-ID: <8d961d900712120401r4b186477wa93fc62e089b3efa@mail.gmail.com> On Dec 12, 2007 12:48 AM, Yitzhak Bar Geva wrote: > > Is it OK to go ahead and generate a Rails 2.0 project with RSpec 1.0.8? Am I > likely to run into problems? When we released RSpec 1.0.8 there was no Rails 2.0. We always have to do a fair amount of tweaks to keep up with Rails, so the versions you're talking about are incompatible. As a general rule: Each RSpec release will work with the latest Rails at the time of release. If you want to use a newer Rails, use RSpec trunk. Aslak > Would it be best advised to wait or can I go ahead now? > Thanks, > Yitzhak > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Wed Dec 12 08:54:12 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 12 Dec 2007 07:54:12 -0600 Subject: [rspec-users] Attachment-fu + Story Runner In-Reply-To: References: <57c63afe0712110528l7551f346r86adf8ca71790e91@mail.gmail.com> <8D52CE6F-5E7A-47E7-A436-7098186978E3@tenner.org> <71166b3b0712110639p3acb5c3am16cddc67a9cb619d@mail.gmail.com> <14291797.post@talk.nabble.com> Message-ID: <57c63afe0712120554j147ffbe6lcff9faf8d5af743f@mail.gmail.com> On Dec 12, 2007 5:41 AM, Daniel Tenner wrote: > > Ok, a bit more digging and I found this is a Rails issue, that is logged > here: > > http://dev.rubyonrails.org/ticket/4635 > > File uploads don't work in Rails integration tests either, only in > functional tests. This is not specific to Attachment-Fu. > > There is, however, a monkey patch that you can download to enable a > multipart_post method which will not mangle the params anymore. > > Hope this helps others too! Daniel - thanks for doing the research on this. There are no tests for the rails patch. If you're willing to add rspec examples and contribute it to the rspec tracker, I'll add it to rspec as a temporary fix until that ticket is resolved. > > Daniel > > > > On 12 Dec 2007, at 09:38 12 Dec 2007, voodoorai2000 wrote: > > > Hi, > > I had the same problem, couldn't get it to run with Stories thought... > Had to test file uploads using controller specs, which works but is not as > clear as a Story. > > I'm guessing the bug where it changes the TempFile to a String will be fixed > soon by the core team, but if someone has a patch it would be awesome! > > > Rai > > > > Daniel Tenner wrote: > > I've now located where this is going wrong, though I am not yet sure > how to fix it. > > In rails' integration.rb, there is a method called 'process'. around > line 226. It mangles the parameters by calling: > data = requestify(parameters) > > doing: > puts "\n1----===#{parameters.inspect}" > puts "\n2----===#{data.inspect}" > > a bit later reveals the problem: > 1----==={:quick_file=>{:filename=>"file- > TFile.txt", :uploaded_data=># 0x3434150 @content_type="text/plain", @tempfile=# test_upload29259-0.txt>, > @original_filename="test_upload.txt">}, :quick_folder=> > {:id=>1330}, :request_type=>"xml"} > > 2----==="quick_file%5Bfilename%5D=file-TFile.txt&quick_file% > 5Buploaded_data%5D=%23%3CActionController%3A%3ATestUploadedFile% > 3A0x3434150%3E&quick_folder%5Bid%5D=1330&request_type=xml" > > Obviously that's not going to work. I wonder how Test::Unit does it, > then, though... > > Daniel > > On 11 Dec 2007, at 14:54 11 Dec 2007, Daniel Tenner wrote: > > > Hi Luis, > > I read through that thread, but unfortunately it wasn't much help. > > fixture_file_upload also creates an > ActionController::TestUploadedFile. It's is just a shortcut to > ActionController::TestUploadedFile.new. > > There's no problem with the path - it creates the fixture and loads > the file, and has the right values inside if I inspect the params > directly before posting them: > > {:filename=>"file- > TFile.txt", :uploaded_data=># 0x33f83bc @content_type=# @synonyms=[], @string="text/plain">, @tempfile=# test_upload29049-0.txt>, @original_filename="test_upload.txt">} > > It's only once this is passed into the controller that it all gets > to_s'ed. > > I like the idea of 'providing a real file upload', but I'm not sure > how to do that in a Story... if anyone has any suggestions or > pointers, they would be welcome! > > Thanks, > > Daniel > > On 11 Dec 2007, at 14:39 11 Dec 2007, Luis Lavena wrote: > > > On Dec 11, 2007 10:57 AM, Daniel Tenner > wrote: > > I've pasted up the code at: > > http://pastie.caboo.se/126925 > > Since there are quite a few files involved. > > Thanks for your time, > > > > A similar discussion was raised back in november (about > fixture_file_upload): > > http://rubyforge.org/pipermail/rspec-users/2007-November/004378.html > > Instead of mocking the FileUpload, why not provide a real one? > > After all, the StoryRunner is aimed to fully exercise your code :-D > > Also, adjust the path of your TestFileUpload file location, > instead of > a relative one (../spec/fixtures) provide one related to RAILS_ROOT, > which will work no matter where you put your helper or what is your > current directory (Dir.chdir). > > HTH, > > -- > Luis Lavena > Multimedia systems > - > A common mistake that people make when trying to design > something completely foolproof is to underestimate > the ingenuity of complete fools. > Douglas Adams > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > > > -- > View this message in context: > http://www.nabble.com/Attachment-fu-%2B-Story-Runner-tp14272891p14291797.html > Sent from the rspec-users mailing list archive at Nabble.com. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From a.schur at nucleus.com Wed Dec 12 10:50:52 2007 From: a.schur at nucleus.com (Alvin Schur) Date: Wed, 12 Dec 2007 08:50:52 -0700 Subject: [rspec-users] undefined method: controller_name In-Reply-To: References: Message-ID: <4760035C.6080907@nucleus.com> With rspec 1.0.8 I have a spec in the directory: spec/units/controllers/application_controller_spec.rb require File.dirname(__FILE__) + '/../../spec_helper' class DummyController < ApplicationController def index raise "Prevent index from rendering" end end describe ApplicationController, "Handling errors in production", :behaviour_type => :controller do controller_name :dummy before(:each) do # set up request and response lambda { get :index }.should raise_error end it "should display 'file not found' when a routing error occurs" do controller.rescue_action_in_public(ActionController::RoutingError.new("this page does not exist")) response.should render_template("error/404") end end and it works. After updating to rspec revision 3136 and running script/generate rspec, I get the following error: kwigger:~/workspace/eTriever-spec-tmp alvin$ script/spec --backtrace spec/unit/controllers/application_controller_spec2.rb ./spec/unit/controllers/application_controller_spec2.rb:10: undefined method `controller_name' for Spec::Rails::Example::RailsExampleGroup::Subclass_1:Class (NoMethodError) from /Users/alvin/workspace/eTriever-spec-tmp/vendor/plugins/rspec/lib/spec/example/example_group_methods.rb:39:in `module_eval' from /Users/alvin/workspace/eTriever-spec-tmp/vendor/plugins/rspec/lib/spec/example/example_group_methods.rb:39:in `describe' from /Users/alvin/workspace/eTriever-spec-tmp/vendor/plugins/rspec/lib/spec/extensions/class.rb:14:in `instance_eval' from /Users/alvin/workspace/eTriever-spec-tmp/vendor/plugins/rspec/lib/spec/extensions/class.rb:14:in `subclass' from /Users/alvin/workspace/eTriever-spec-tmp/vendor/plugins/rspec/lib/spec/example/example_group_methods.rb:37:in `describe' from /Users/alvin/workspace/eTriever-spec-tmp/vendor/plugins/rspec/lib/spec/example/example_group_factory.rb:43:in `create_example_group' from /Users/alvin/workspace/eTriever-spec-tmp/vendor/plugins/rspec/lib/spec/extensions/main.rb:27:in `describe' from ./spec/unit/controllers/application_controller_spec2.rb:9 from /Users/alvin/workspace/eTriever-spec-tmp/vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb:14:in `load' from /Users/alvin/workspace/eTriever-spec-tmp/vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb:14:in `load_files' from /Users/alvin/workspace/eTriever-spec-tmp/vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb:13:in `each' from /Users/alvin/workspace/eTriever-spec-tmp/vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb:13:in `load_files' from /Users/alvin/workspace/eTriever-spec-tmp/vendor/plugins/rspec/lib/spec/runner/options.rb:83:in `run_examples' from /Users/alvin/workspace/eTriever-spec-tmp/vendor/plugins/rspec/lib/spec/runner/command_line.rb:19:in `run' from script/spec:4 Is there a better way to write this spec in 3136? Thanks, Alvin. From dchelimsky at gmail.com Wed Dec 12 10:56:22 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 12 Dec 2007 09:56:22 -0600 Subject: [rspec-users] undefined method: controller_name In-Reply-To: <4760035C.6080907@nucleus.com> References: <4760035C.6080907@nucleus.com> Message-ID: <57c63afe0712120756t2cd2b204uaa2c46edbfb28097@mail.gmail.com> On Dec 12, 2007 9:50 AM, Alvin Schur wrote: > With rspec 1.0.8 I have a spec in the directory: > spec/units/controllers/application_controller_spec.rb > > require File.dirname(__FILE__) + '/../../spec_helper' > > class DummyController < ApplicationController > def index > raise "Prevent index from rendering" > end > end > > describe ApplicationController, "Handling errors in production", > :behaviour_type => :controller do Try :type instead and see if that works. > controller_name :dummy > > before(:each) do > # set up request and response > lambda { get :index }.should raise_error > end > > it "should display 'file not found' when a routing error occurs" do > > controller.rescue_action_in_public(ActionController::RoutingError.new("this > page does not exist")) > response.should render_template("error/404") > end > end > > and it works. > > > After updating to rspec revision 3136 and running script/generate rspec, > I get the following error: > > kwigger:~/workspace/eTriever-spec-tmp alvin$ script/spec --backtrace > spec/unit/controllers/application_controller_spec2.rb > ./spec/unit/controllers/application_controller_spec2.rb:10: undefined > method `controller_name' for > Spec::Rails::Example::RailsExampleGroup::Subclass_1:Class (NoMethodError) > from > /Users/alvin/workspace/eTriever-spec-tmp/vendor/plugins/rspec/lib/spec/example/example_group_methods.rb:39:in > `module_eval' > from > /Users/alvin/workspace/eTriever-spec-tmp/vendor/plugins/rspec/lib/spec/example/example_group_methods.rb:39:in > `describe' > from > /Users/alvin/workspace/eTriever-spec-tmp/vendor/plugins/rspec/lib/spec/extensions/class.rb:14:in > `instance_eval' > from > /Users/alvin/workspace/eTriever-spec-tmp/vendor/plugins/rspec/lib/spec/extensions/class.rb:14:in > `subclass' > from > /Users/alvin/workspace/eTriever-spec-tmp/vendor/plugins/rspec/lib/spec/example/example_group_methods.rb:37:in > `describe' > from > /Users/alvin/workspace/eTriever-spec-tmp/vendor/plugins/rspec/lib/spec/example/example_group_factory.rb:43:in > `create_example_group' > from > /Users/alvin/workspace/eTriever-spec-tmp/vendor/plugins/rspec/lib/spec/extensions/main.rb:27:in > `describe' > from ./spec/unit/controllers/application_controller_spec2.rb:9 > from > /Users/alvin/workspace/eTriever-spec-tmp/vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb:14:in > `load' > from > /Users/alvin/workspace/eTriever-spec-tmp/vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb:14:in > `load_files' > from > /Users/alvin/workspace/eTriever-spec-tmp/vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb:13:in > `each' > from > /Users/alvin/workspace/eTriever-spec-tmp/vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb:13:in > `load_files' > from > /Users/alvin/workspace/eTriever-spec-tmp/vendor/plugins/rspec/lib/spec/runner/options.rb:83:in > `run_examples' > from > /Users/alvin/workspace/eTriever-spec-tmp/vendor/plugins/rspec/lib/spec/runner/command_line.rb:19:in > `run' > from script/spec:4 > > > > Is there a better way to write this spec in 3136? > > Thanks, > Alvin. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dpdnolan at gmail.com Wed Dec 12 12:39:36 2007 From: dpdnolan at gmail.com (David Nolan) Date: Wed, 12 Dec 2007 17:39:36 +0000 Subject: [rspec-users] Problem running examples with spec_server Message-ID: Hello, Running RSpec without DRB works fine. However, "spec -X" runs without error but provides no output at all, even though the DRB spec_server seems to be fine. Has anyone got some suggestions as to why and how to fix? RSpec: 1-1-0RC1 build time 20071212145122 RSpec on Rails: Build time 20071212145122 Ruby: 1.8.6 Rails: 2-0-1 Win XP SP 2 Thanks very much, Dave -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071212/08a8cf7b/attachment.html From mailing_lists at railsnewbie.com Wed Dec 12 12:14:21 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Wed, 12 Dec 2007 12:14:21 -0500 Subject: [rspec-users] undefined method: controller_name In-Reply-To: <57c63afe0712120756t2cd2b204uaa2c46edbfb28097@mail.gmail.com> References: <4760035C.6080907@nucleus.com> <57c63afe0712120756t2cd2b204uaa2c46edbfb28097@mail.gmail.com> Message-ID: <2302E1F7-F77E-4C35-986C-98128AD114BE@railsnewbie.com> On Dec 12, 2007, at 10:56 AM, David Chelimsky wrote: > On Dec 12, 2007 9:50 AM, Alvin Schur wrote: >> With rspec 1.0.8 I have a spec in the directory: >> spec/units/controllers/application_controller_spec.rb >> >> require File.dirname(__FILE__) + '/../../spec_helper' >> >> class DummyController < ApplicationController >> def index >> raise "Prevent index from rendering" >> end >> end >> >> describe ApplicationController, "Handling errors in production", >> :behaviour_type => :controller do > > Try :type instead and see if that works. Yep. I had a bunch of regressions with :behaviour_type => ..., which started to fail a few weeks ago. Changing it to :type seemed to fix it up. Scott From a.schur at nucleus.com Wed Dec 12 13:11:48 2007 From: a.schur at nucleus.com (Alvin Schur) Date: Wed, 12 Dec 2007 11:11:48 -0700 Subject: [rspec-users] undefined method: controller_name In-Reply-To: References: Message-ID: <47602464.6080004@nucleus.com> David Chelimsky wrote: > On Dec 12, 2007 9:50 AM, Alvin Schur > wrote: > >/ With rspec 1.0.8 I have a spec in the directory: /> >/ spec/units/controllers/application_controller_spec.rb /> >/ /> >/ require File.dirname(__FILE__) + '/../../spec_helper' /> >/ /> >/ class DummyController < ApplicationController /> >/ def index /> >/ raise "Prevent index from rendering" /> >/ end /> >/ end /> >/ /> >/ describe ApplicationController, "Handling errors in production", /> >/ :behaviour_type => :controller do /> > Try :type instead and see if that works. This did work, thanks. From thijs at 80beans.com Wed Dec 12 06:03:51 2007 From: thijs at 80beans.com (Thijs Cadier) Date: Wed, 12 Dec 2007 03:03:51 -0800 (PST) Subject: [rspec-users] namespaced controllers In-Reply-To: <2BC42D14-A430-4C78-8A0E-2CAD4A8CAED4@railsnewbie.com> References: <60f3810c0711231427w1c6804b2v5e1575012c885431@mail.gmail.com> <60f3810c0711250723l114cc668rffa93396f8ace9c3@mail.gmail.com> <60f3810c0711250848wc4afd59v18f6d0c1a8657de5@mail.gmail.com> <2BC42D14-A430-4C78-8A0E-2CAD4A8CAED4@railsnewbie.com> Message-ID: <14292651.post@talk.nabble.com> Has anybody been taking a look at this issue? I'm getting a little annoyed touching the namespaced controllers before running the specs all the time :-). Scott Taylor-6 wrote: > >> >> Figured out how to reproduce it. It depends on load order, I guess. >> >> Given the files: >> spec/controllers/foo_controller_spec.rb >> spec/controllers/admin/foo_controller_spec.rb >> >> The specs do nothing but hit the FooController#show and >> Admin::FooController#index actions and expect the right render. >> >> If I touch admin/foo_controller_spec.rb, the specs pass. >> >> If I touch foo_controller_spec.rb, the specs for Admin::FooController >> fail with UnknownAction exceptions, since ::FooController has no index >> action defined. >> >> Problem occurs with autotest and rake spec, but not with ./script/ >> spec spec. >> >> This is happening with the current latest trunk versions, rails r8200 >> and rspec r2980. > > Can you put this in the tracker? I'm likely to forget about it > otherwise. > > Scott > > _______________________________________________ > 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/namespaced-controllers-tp13919259p14292651.html Sent from the rspec-users mailing list archive at Nabble.com. From dchelimsky at gmail.com Wed Dec 12 17:37:22 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 12 Dec 2007 16:37:22 -0600 Subject: [rspec-users] namespaced controllers In-Reply-To: <14292651.post@talk.nabble.com> References: <60f3810c0711231427w1c6804b2v5e1575012c885431@mail.gmail.com> <60f3810c0711250723l114cc668rffa93396f8ace9c3@mail.gmail.com> <60f3810c0711250848wc4afd59v18f6d0c1a8657de5@mail.gmail.com> <2BC42D14-A430-4C78-8A0E-2CAD4A8CAED4@railsnewbie.com> <14292651.post@talk.nabble.com> Message-ID: <57c63afe0712121437r21f89adbj89ab70ab18cbd230@mail.gmail.com> On Dec 12, 2007 5:03 AM, Thijs Cadier wrote: > > Has anybody been taking a look at this issue? I'm getting a little annoyed > touching the namespaced controllers before running the specs all the time > :-). What annoys me is the relative inverse ratio of level of whining to level of contribution. If you want it done quick, stop whining and contribute a patch. > > > > > Scott Taylor-6 wrote: > > > >> > >> Figured out how to reproduce it. It depends on load order, I guess. > >> > >> Given the files: > >> spec/controllers/foo_controller_spec.rb > >> spec/controllers/admin/foo_controller_spec.rb > >> > >> The specs do nothing but hit the FooController#show and > >> Admin::FooController#index actions and expect the right render. > >> > >> If I touch admin/foo_controller_spec.rb, the specs pass. > >> > >> If I touch foo_controller_spec.rb, the specs for Admin::FooController > >> fail with UnknownAction exceptions, since ::FooController has no index > >> action defined. > >> > >> Problem occurs with autotest and rake spec, but not with ./script/ > >> spec spec. > >> > >> This is happening with the current latest trunk versions, rails r8200 > >> and rspec r2980. > > > > Can you put this in the tracker? I'm likely to forget about it > > otherwise. > > > > Scott > > > > _______________________________________________ > > 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/namespaced-controllers-tp13919259p14292651.html > Sent from the rspec-users mailing list archive at Nabble.com. > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From thijs at 80beans.com Wed Dec 12 18:57:17 2007 From: thijs at 80beans.com (Thijs Cadier) Date: Wed, 12 Dec 2007 15:57:17 -0800 (PST) Subject: [rspec-users] namespaced controllers In-Reply-To: <57c63afe0712121437r21f89adbj89ab70ab18cbd230@mail.gmail.com> References: <60f3810c0711231427w1c6804b2v5e1575012c885431@mail.gmail.com> <60f3810c0711250723l114cc668rffa93396f8ace9c3@mail.gmail.com> <60f3810c0711250848wc4afd59v18f6d0c1a8657de5@mail.gmail.com> <2BC42D14-A430-4C78-8A0E-2CAD4A8CAED4@railsnewbie.com> <14292651.post@talk.nabble.com> <57c63afe0712121437r21f89adbj89ab70ab18cbd230@mail.gmail.com> Message-ID: <14306960.post@talk.nabble.com> Hi David, You might have taken my message the wrong way. I didn't mean to say I was annoyed because the Rspec team hasn't delivered a solution for my problem. I was trying to say that I'm annoyed by the consequences of this problem, in a friendly way. I actually had a look at the Rspec code, but I quickly saw that I'm not able to fix a problem like this with my level of understanding of the Rspec internals. Anyway, I hope this issue stays on the radar and I'll do a bit more research myself to see if I can find the cause. Thijs David Chelimsky-2 wrote: > > What annoys me is the relative inverse ratio of level of whining to > level of contribution. > > If you want it done quick, stop whining and contribute a patch. > -- View this message in context: http://www.nabble.com/namespaced-controllers-tp13919259p14306960.html Sent from the rspec-users mailing list archive at Nabble.com. From nathan.sutton at gmail.com Wed Dec 12 18:59:10 2007 From: nathan.sutton at gmail.com (Nathan Sutton) Date: Wed, 12 Dec 2007 17:59:10 -0600 Subject: [rspec-users] namespaced controllers In-Reply-To: <57c63afe0712121437r21f89adbj89ab70ab18cbd230@mail.gmail.com> References: <60f3810c0711231427w1c6804b2v5e1575012c885431@mail.gmail.com> <60f3810c0711250723l114cc668rffa93396f8ace9c3@mail.gmail.com> <60f3810c0711250848wc4afd59v18f6d0c1a8657de5@mail.gmail.com> <2BC42D14-A430-4C78-8A0E-2CAD4A8CAED4@railsnewbie.com> <14292651.post@talk.nabble.com> <57c63afe0712121437r21f89adbj89ab70ab18cbd230@mail.gmail.com> Message-ID: Well put. Nathan Sutton fowlduck at gmail.com rspec edge revision 3052 rspec_on_rails edge revision 3049 rails 2.0.1 On Dec 12, 2007, at 4:37 PM, David Chelimsky wrote: > On Dec 12, 2007 5:03 AM, Thijs Cadier wrote: >> >> Has anybody been taking a look at this issue? I'm getting a little >> annoyed >> touching the namespaced controllers before running the specs all >> the time >> :-). > > What annoys me is the relative inverse ratio of level of whining to > level of contribution. > > If you want it done quick, stop whining and contribute a patch. > >> >> >> >> >> Scott Taylor-6 wrote: >>> >>>> >>>> Figured out how to reproduce it. It depends on load order, I guess. >>>> >>>> Given the files: >>>> spec/controllers/foo_controller_spec.rb >>>> spec/controllers/admin/foo_controller_spec.rb >>>> >>>> The specs do nothing but hit the FooController#show and >>>> Admin::FooController#index actions and expect the right render. >>>> >>>> If I touch admin/foo_controller_spec.rb, the specs pass. >>>> >>>> If I touch foo_controller_spec.rb, the specs for >>>> Admin::FooController >>>> fail with UnknownAction exceptions, since ::FooController has no >>>> index >>>> action defined. >>>> >>>> Problem occurs with autotest and rake spec, but not with ./script/ >>>> spec spec. >>>> >>>> This is happening with the current latest trunk versions, rails >>>> r8200 >>>> and rspec r2980. >>> >>> Can you put this in the tracker? I'm likely to forget about it >>> otherwise. >>> >>> Scott >>> >>> _______________________________________________ >>> 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/namespaced-controllers-tp13919259p14292651.html >> Sent from the rspec-users mailing list archive at Nabble.com. >> >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From philodespotos at gmail.com Wed Dec 12 20:07:18 2007 From: philodespotos at gmail.com (Kyle Hargraves) Date: Wed, 12 Dec 2007 19:07:18 -0600 Subject: [rspec-users] namespaced controllers In-Reply-To: <57c63afe0712121437r21f89adbj89ab70ab18cbd230@mail.gmail.com> References: <60f3810c0711231427w1c6804b2v5e1575012c885431@mail.gmail.com> <60f3810c0711250723l114cc668rffa93396f8ace9c3@mail.gmail.com> <60f3810c0711250848wc4afd59v18f6d0c1a8657de5@mail.gmail.com> <2BC42D14-A430-4C78-8A0E-2CAD4A8CAED4@railsnewbie.com> <14292651.post@talk.nabble.com> <57c63afe0712121437r21f89adbj89ab70ab18cbd230@mail.gmail.com> Message-ID: <60f3810c0712121707t55ed202as32f3ae11f4668fcf@mail.gmail.com> On Dec 12, 2007 4:37 PM, David Chelimsky wrote: > On Dec 12, 2007 5:03 AM, Thijs Cadier wrote: > > > > Has anybody been taking a look at this issue? I'm getting a little annoyed > > touching the namespaced controllers before running the specs all the time > > :-). > > What annoys me is the relative inverse ratio of level of whining to > level of contribution. > > If you want it done quick, stop whining and contribute a patch. I ended up coming to the conclusion that this is probably not rspec's bug, but never bothered to reply here or update the ticket I filed. Just did: http://rspec.lighthouseapp.com/projects/5645/tickets/145-namespaced-controller-load-order Kyle From philodespotos at gmail.com Wed Dec 12 20:33:17 2007 From: philodespotos at gmail.com (Kyle Hargraves) Date: Wed, 12 Dec 2007 19:33:17 -0600 Subject: [rspec-users] namespaced controllers In-Reply-To: <14292651.post@talk.nabble.com> References: <60f3810c0711231427w1c6804b2v5e1575012c885431@mail.gmail.com> <60f3810c0711250723l114cc668rffa93396f8ace9c3@mail.gmail.com> <60f3810c0711250848wc4afd59v18f6d0c1a8657de5@mail.gmail.com> <2BC42D14-A430-4C78-8A0E-2CAD4A8CAED4@railsnewbie.com> <14292651.post@talk.nabble.com> Message-ID: <60f3810c0712121733s43d04110v5e98930084d94a5f@mail.gmail.com> On Dec 12, 2007 5:03 AM, Thijs Cadier wrote: > > Has anybody been taking a look at this issue? I'm getting a little annoyed > touching the namespaced controllers before running the specs all the time > :-). As a workaround, do what the rest of us have done and just be explicit about the module. describe Admin::FooController Problem goes away. I probably shouldn't even call it a workaround -- it's a solution. The only change is a minor difference in style. Kyle From dchelimsky at gmail.com Wed Dec 12 20:44:47 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 12 Dec 2007 19:44:47 -0600 Subject: [rspec-users] namespaced controllers In-Reply-To: <14306960.post@talk.nabble.com> References: <60f3810c0711231427w1c6804b2v5e1575012c885431@mail.gmail.com> <60f3810c0711250723l114cc668rffa93396f8ace9c3@mail.gmail.com> <60f3810c0711250848wc4afd59v18f6d0c1a8657de5@mail.gmail.com> <2BC42D14-A430-4C78-8A0E-2CAD4A8CAED4@railsnewbie.com> <14292651.post@talk.nabble.com> <57c63afe0712121437r21f89adbj89ab70ab18cbd230@mail.gmail.com> <14306960.post@talk.nabble.com> Message-ID: <57c63afe0712121744t1c1e8b23hbece6ec7b7d28fc0@mail.gmail.com> On Dec 12, 2007 5:57 PM, Thijs Cadier wrote: > > Hi David, > > You might have taken my message the wrong way. I didn't mean to say I was > annoyed because the Rspec team hasn't delivered a solution for my problem. I > was trying to say that I'm annoyed by the consequences of this problem, in a > friendly way. I did misread it. Thanks for being less reactionary than me :) > I actually had a look at the Rspec code, but I quickly saw that I'm not able > to fix a problem like this with my level of understanding of the Rspec > internals. They are confusing - especially in the rails plugin. We're slowly working on improving that. > Anyway, I hope this issue stays on the radar and I'll do a bit more research > myself to see if I can find the cause. > > > Thijs > > > David Chelimsky-2 wrote: > > > > What annoys me is the relative inverse ratio of level of whining to > > level of contribution. > > > > If you want it done quick, stop whining and contribute a patch. > > > -- > View this message in context: http://www.nabble.com/namespaced-controllers-tp13919259p14306960.html > > Sent from the rspec-users mailing list archive at Nabble.com. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From rick.denatale at gmail.com Wed Dec 12 22:09:06 2007 From: rick.denatale at gmail.com (Rick DeNatale) Date: Wed, 12 Dec 2007 22:09:06 -0500 Subject: [rspec-users] "Tricks" for testing after_create callback??? Message-ID: I've got a model Message, which needs to send an email using action mailer after it's first saved in the database. I want to pass the model to the mailer which then uses methods on the message model to render the email. So the natural way to do this is in an after_create callback on the Message model. But I can't see an easy way to test this. Here's my spec describe Message, "from anyone" do it "should be sent on save" do msg_creation_parms = { :subject => "Subj", :body => "hi", :sender => people(:rick), :recipient => people(:john) } SantasMailbox.should_receive(:deliver_secret_santa).with(Message.new(msg_creation_parms)) Message.create(msg_creation_parms) end end This fails, but only because the model object has an id and time stamps assigned as it's saved. Spec::Mocks::MockExpectationError in 'Message from anyone should be sent on save' Mock 'Class' expected :deliver_secret_santa with (#) but received it with (#) I figured I'd through this out to the list for ideas on how best to approach this before I go to bed and sleep on it. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From philodespotos at gmail.com Wed Dec 12 22:48:21 2007 From: philodespotos at gmail.com (Kyle Hargraves) Date: Wed, 12 Dec 2007 21:48:21 -0600 Subject: [rspec-users] "Tricks" for testing after_create callback??? In-Reply-To: References: Message-ID: <60f3810c0712121948gaea9aeej30f86fe6f0bc0264@mail.gmail.com> On Dec 12, 2007 9:09 PM, Rick DeNatale wrote: > I've got a model Message, which needs to send an email using action > mailer after it's first saved in the database. > > I want to pass the model to the mailer which then uses methods on the > message model to render the email. > > So the natural way to do this is in an after_create callback on the > Message model. > > But I can't see an easy way to test this. Here's my spec > > describe Message, "from anyone" do > > it "should be sent on save" do > msg_creation_parms = { > :subject => "Subj", > :body => "hi", > :sender => people(:rick), > :recipient => people(:john) > } > SantasMailbox.should_receive(:deliver_secret_santa).with(Message.new(msg_creation_parms)) > Message.create(msg_creation_parms) > end > > end > > This fails, but only because the model object has an id and time > stamps assigned as it's saved. > > Spec::Mocks::MockExpectationError in 'Message from anyone should be > sent on save' > Mock 'Class' expected :deliver_secret_santa with (# subject: "Subj", body: "hi", sender_id: 343839476, recipient_id: > 21341157, message_type: nil, created_at: nil, updated_at: nil>) but > received it with (# sender_id: 343839476, recipient_id: 21341157, message_type: nil, > created_at: "2007-12-12 21:53:16", updated_at: "2007-12-12 21:53:16">) > > I figured I'd through this out to the list for ideas on how best to > approach this before I go to bed and sleep on it. Someone else may have a more elegant approach, but the block syntax to should_receive() could allow something like: expected_message = Message.new(msg_creation_params) SantasMailbox.should_receive(:deliver_secret_santa) do |msg| msg.body.should == expected_message.body msg.subject.should == expected_message.subject # etc. if it's necessary end Message.create(msg_creation_params) Feels clunky, though. Kyle From pergesu at gmail.com Wed Dec 12 23:11:59 2007 From: pergesu at gmail.com (Pat Maddox) Date: Wed, 12 Dec 2007 20:11:59 -0800 Subject: [rspec-users] "Tricks" for testing after_create callback??? In-Reply-To: References: Message-ID: <810a540e0712122011h2b657beo50f88489f843dc71@mail.gmail.com> On Dec 12, 2007 7:09 PM, Rick DeNatale wrote: > I've got a model Message, which needs to send an email using action > mailer after it's first saved in the database. > > I want to pass the model to the mailer which then uses methods on the > message model to render the email. > > So the natural way to do this is in an after_create callback on the > Message model. > > But I can't see an easy way to test this. Here's my spec > > describe Message, "from anyone" do > > it "should be sent on save" do > msg_creation_parms = { > :subject => "Subj", > :body => "hi", > :sender => people(:rick), > :recipient => people(:john) > } > SantasMailbox.should_receive(:deliver_secret_santa).with(Message.new(msg_creation_parms)) > Message.create(msg_creation_parms) > end > > end > > This fails, but only because the model object has an id and time > stamps assigned as it's saved. > > Spec::Mocks::MockExpectationError in 'Message from anyone should be > sent on save' > Mock 'Class' expected :deliver_secret_santa with (# subject: "Subj", body: "hi", sender_id: 343839476, recipient_id: > 21341157, message_type: nil, created_at: nil, updated_at: nil>) but > received it with (# sender_id: 343839476, recipient_id: 21341157, message_type: nil, > created_at: "2007-12-12 21:53:16", updated_at: "2007-12-12 21:53:16">) > > I figured I'd through this out to the list for ideas on how best to > approach this before I go to bed and sleep on it. > > -- > Rick DeNatale > > My blog on Ruby > http://talklikeaduck.denhaven2.com/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > I would not mock the call, and would instead just let the mailer do its thing. You can verify that a message was sent, match the subject/content, etc. It's very lightweight so there's no reason not to use it. Pat From pergesu at gmail.com Wed Dec 12 23:17:34 2007 From: pergesu at gmail.com (Pat Maddox) Date: Wed, 12 Dec 2007 20:17:34 -0800 Subject: [rspec-users] Rspec 1.0.8 with Rails 2.0 In-Reply-To: <8d961d900712120401r4b186477wa93fc62e089b3efa@mail.gmail.com> References: <3c0677320712111548i5c6e0a90ua9a1d4d8286c81e5@mail.gmail.com> <8d961d900712120401r4b186477wa93fc62e089b3efa@mail.gmail.com> Message-ID: <810a540e0712122017i66be5a28n5d417ae45f43c6bc@mail.gmail.com> On Dec 12, 2007 4:01 AM, aslak hellesoy wrote: > On Dec 12, 2007 12:48 AM, Yitzhak Bar Geva wrote: > > > > Is it OK to go ahead and generate a Rails 2.0 project with RSpec 1.0.8? Am I > > likely to run into problems? > > When we released RSpec 1.0.8 there was no Rails 2.0. We always have to > do a fair amount of tweaks to keep up with Rails, so the versions > you're talking about are incompatible. > > As a general rule: Each RSpec release will work with the latest Rails > at the time of release. If you want to use a newer Rails, use RSpec > trunk. Do you think it would make sense to do an interim release of RSpec whenever a new Rails version gets released? It (probably) shouldn't be based off of trunk, but rather the last stable release, with whatever little bug fixes may be required to work with Rails. That way there's no question...for any Rails version, people have the choice of using a stable version of RSpec trunk. Pat From dchelimsky at gmail.com Thu Dec 13 00:16:36 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 12 Dec 2007 23:16:36 -0600 Subject: [rspec-users] "Tricks" for testing after_create callback??? In-Reply-To: <60f3810c0712121948gaea9aeej30f86fe6f0bc0264@mail.gmail.com> References: <60f3810c0712121948gaea9aeej30f86fe6f0bc0264@mail.gmail.com> Message-ID: <57c63afe0712122116q58deac00wf80e46b7a79434a@mail.gmail.com> On Dec 12, 2007 9:48 PM, Kyle Hargraves wrote: > > On Dec 12, 2007 9:09 PM, Rick DeNatale wrote: > > I've got a model Message, which needs to send an email using action > > mailer after it's first saved in the database. > > > > I want to pass the model to the mailer which then uses methods on the > > message model to render the email. > > > > So the natural way to do this is in an after_create callback on the > > Message model. > > > > But I can't see an easy way to test this. Here's my spec > > > > describe Message, "from anyone" do > > > > it "should be sent on save" do > > msg_creation_parms = { > > :subject => "Subj", > > :body => "hi", > > :sender => people(:rick), > > :recipient => people(:john) > > } > > SantasMailbox.should_receive(:deliver_secret_santa).with(Message.new(msg_creation_parms)) > > Message.create(msg_creation_parms) > > end > > > > end > > > > This fails, but only because the model object has an id and time > > stamps assigned as it's saved. > > > > Spec::Mocks::MockExpectationError in 'Message from anyone should be > > sent on save' > > Mock 'Class' expected :deliver_secret_santa with (# > subject: "Subj", body: "hi", sender_id: 343839476, recipient_id: > > 21341157, message_type: nil, created_at: nil, updated_at: nil>) but > > received it with (# > sender_id: 343839476, recipient_id: 21341157, message_type: nil, > > created_at: "2007-12-12 21:53:16", updated_at: "2007-12-12 21:53:16">) > > > > I figured I'd through this out to the list for ideas on how best to > > approach this before I go to bed and sleep on it. > > Someone else may have a more elegant approach, but the block syntax to > should_receive() could allow something like: > > expected_message = Message.new(msg_creation_params) > SantasMailbox.should_receive(:deliver_secret_santa) do |msg| > msg.body.should == expected_message.body > msg.subject.should == expected_message.subject > # etc. if it's necessary > end > Message.create(msg_creation_params) Not only could it support this, it DOES. That said, I'd go for a lesser known feature: custom mock argument matchers. Something like this (completely off the top of my head and not tested or guaranteed bug-free - but this will give you the idea): class EquivalentMessage def initialize(message) @message = message end def ==(other) other.subject == @message.subject && other.body == @message.body && other.sender == @message.sender && other.recipient == @message.recipient end end def message_equivalent_to(message) EquivalentMessage.new(message) end it "should be sent on save" do msg_creation_parms = { :subject => "Subj", :body => "hi", :sender => people(:rick), :recipient => people(:john) } SantasMailbox.should_receive(:deliver_secret_santa). with(message_equivalent_to(Message.new(msg_creation_parms))) Message.create(msg_creation_parms) end Try that out and see what you think. Cheers, David > > Feels clunky, though. > > Kyle > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Thu Dec 13 00:17:39 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 12 Dec 2007 23:17:39 -0600 Subject: [rspec-users] Rspec 1.0.8 with Rails 2.0 In-Reply-To: <810a540e0712122017i66be5a28n5d417ae45f43c6bc@mail.gmail.com> References: <3c0677320712111548i5c6e0a90ua9a1d4d8286c81e5@mail.gmail.com> <8d961d900712120401r4b186477wa93fc62e089b3efa@mail.gmail.com> <810a540e0712122017i66be5a28n5d417ae45f43c6bc@mail.gmail.com> Message-ID: <57c63afe0712122117p3624d0a3nf2c0e610175bf094@mail.gmail.com> On Dec 12, 2007 10:17 PM, Pat Maddox wrote: > On Dec 12, 2007 4:01 AM, aslak hellesoy wrote: > > On Dec 12, 2007 12:48 AM, Yitzhak Bar Geva wrote: > > > > > > Is it OK to go ahead and generate a Rails 2.0 project with RSpec 1.0.8? Am I > > > likely to run into problems? > > > > When we released RSpec 1.0.8 there was no Rails 2.0. We always have to > > do a fair amount of tweaks to keep up with Rails, so the versions > > you're talking about are incompatible. > > > > As a general rule: Each RSpec release will work with the latest Rails > > at the time of release. If you want to use a newer Rails, use RSpec > > trunk. > > Do you think it would make sense to do an interim release of RSpec > whenever a new Rails version gets released? We try to do releases right after rails releases - that's why we're working hard to get 1.1 out the door now. > It (probably) shouldn't > be based off of trunk, but rather the last stable release, with > whatever little bug fixes may be required to work with Rails. That > way there's no question...for any Rails version, people have the > choice of using a stable version of RSpec trunk. > > Pat > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jonathan at parkerhill.com Thu Dec 13 02:00:12 2007 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Thu, 13 Dec 2007 02:00:12 -0500 Subject: [rspec-users] stub with assigns? Message-ID: <3BB9A0F8-5034-4244-AEDC-10CAE25C8728@parkerhill.com> is there a way to stub a method that sets an instance variable, so the stub sets it too? def find_foo @foo = Foo.find(params[:id] end ... controller.stub!(:find_foo).and_assigns(:foo, "123") -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071213/2042719f/attachment.html From jarkko at jlaine.net Thu Dec 13 02:06:08 2007 From: jarkko at jlaine.net (Jarkko Laine) Date: Thu, 13 Dec 2007 09:06:08 +0200 Subject: [rspec-users] stub with assigns? In-Reply-To: <3BB9A0F8-5034-4244-AEDC-10CAE25C8728@parkerhill.com> References: <3BB9A0F8-5034-4244-AEDC-10CAE25C8728@parkerhill.com> Message-ID: On 13.12.2007, at 9.00, Jonathan Linowes wrote: > is there a way to stub a method that sets an instance variable, so > the stub sets it too? > > def find_foo > @foo = Foo.find(params[:id] > end > > > ... > controller.stub!(:find_foo).and_assigns(:foo, "123") Why don't you just stub Foo.find? That way the instance var gets assigned automatically. //jarkko -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http://odesign.fi From pergesu at gmail.com Thu Dec 13 02:12:29 2007 From: pergesu at gmail.com (Pat Maddox) Date: Wed, 12 Dec 2007 23:12:29 -0800 Subject: [rspec-users] stub with assigns? In-Reply-To: <3BB9A0F8-5034-4244-AEDC-10CAE25C8728@parkerhill.com> References: <3BB9A0F8-5034-4244-AEDC-10CAE25C8728@parkerhill.com> Message-ID: <810a540e0712122312i32151416lc2184568c6782b9a@mail.gmail.com> On Dec 12, 2007 11:00 PM, Jonathan Linowes wrote: > > is there a way to stub a method that sets an instance variable, so the stub > sets it too? > > def find_foo > @foo = Foo.find(params[:id] > end > > > ... > controller.stub!(:find_foo).and_assigns(:foo, "123") huh? I think what you want to be doing is Foo.stub!(:find_foo).and_return @mock_foo and then assigns[:foo] will of course be set to @mock_foo. Pat From mailing_lists at railsnewbie.com Thu Dec 13 02:17:24 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Thu, 13 Dec 2007 02:17:24 -0500 Subject: [rspec-users] stub with assigns? In-Reply-To: <3BB9A0F8-5034-4244-AEDC-10CAE25C8728@parkerhill.com> References: <3BB9A0F8-5034-4244-AEDC-10CAE25C8728@parkerhill.com> Message-ID: <3ACC48DC-CB52-46CE-A55A-4E9C7C4D2CB9@railsnewbie.com> On Dec 13, 2007, at 2:00 AM, Jonathan Linowes wrote: > is there a way to stub a method that sets an instance variable, so > the stub sets it too? > Nope. The idea behind this is that instance variables are supposed to be the inner representation of some data inside a class, while an attr_accessor/reader is the public interface to other objects. Obviously, this idea breaks down in rails. If you wanted something like that, why not write some shared specs like this: it "should find ..." do do_action @class_name.constantize.should_receive(:find).with (params).and_return @instance_var_contents end it "should assign the instance variable to the template" do do_action assigns[@class_name.underscore].should == @instance_var_contents end where @class_name would be a string like "Foo" Scott > def find_foo > @foo = Foo.find(params[:id] > end > > > ... > controller.stub!(:find_foo).and_assigns(:foo, "123") > > > _______________________________________________ > 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/20071213/36c31800/attachment.html From jonathan at parkerhill.com Thu Dec 13 02:47:30 2007 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Thu, 13 Dec 2007 02:47:30 -0500 Subject: [rspec-users] stub with assigns? In-Reply-To: References: <3BB9A0F8-5034-4244-AEDC-10CAE25C8728@parkerhill.com> Message-ID: <4BC12E58-692B-419D-9C8D-4A7B08D8B740@parkerhill.com> On Dec 13, 2007, at 2:06 AM, Jarkko Laine wrote: > > On 13.12.2007, at 9.00, Jonathan Linowes wrote: > >> is there a way to stub a method that sets an instance variable, so >> the stub sets it too? >> >> def find_foo >> @foo = Foo.find(params[:id] >> end >> >> >> ... >> controller.stub!(:find_foo).and_assigns(:foo, "123") > > Why don't you just stub Foo.find? That way the instance var gets > assigned automatically. > > //jarkko > Sorry, perhaps I gave too simplistic an example. My question is what if I want to stub the whole find_foo method but one of its side effects is it sets @foo (rather than stub the internals of find_foo) From jonathan at parkerhill.com Thu Dec 13 02:55:40 2007 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Thu, 13 Dec 2007 02:55:40 -0500 Subject: [rspec-users] stub with assigns? In-Reply-To: <4BC12E58-692B-419D-9C8D-4A7B08D8B740@parkerhill.com> References: <3BB9A0F8-5034-4244-AEDC-10CAE25C8728@parkerhill.com> <4BC12E58-692B-419D-9C8D-4A7B08D8B740@parkerhill.com> Message-ID: On Dec 13, 2007, at 2:47 AM, Jonathan Linowes wrote: > > On Dec 13, 2007, at 2:06 AM, Jarkko Laine wrote: > >> >> On 13.12.2007, at 9.00, Jonathan Linowes wrote: >> >>> is there a way to stub a method that sets an instance variable, so >>> the stub sets it too? >>> >>> def find_foo >>> @foo = Foo.find(params[:id] >>> end >>> >>> >>> ... >>> controller.stub!(:find_foo).and_assigns(:foo, "123") >> >> Why don't you just stub Foo.find? That way the instance var gets >> assigned automatically. >> >> //jarkko >> > > Sorry, perhaps I gave too simplistic an example. > My question is what if I want to stub the whole find_foo method > but one of its side effects is it sets @foo > (rather than stub the internals of find_foo) > > ... and @foo is used by the method that i am testing From stefan.landro at gmail.com Thu Dec 13 03:11:46 2007 From: stefan.landro at gmail.com (=?ISO-8859-1?Q?Stefan_Magnus_Landr=F8?=) Date: Thu, 13 Dec 2007 09:11:46 +0100 Subject: [rspec-users] Rspec 1.0.8 with Rails 2.0 In-Reply-To: <57c63afe0712122117p3624d0a3nf2c0e610175bf094@mail.gmail.com> References: <3c0677320712111548i5c6e0a90ua9a1d4d8286c81e5@mail.gmail.com> <8d961d900712120401r4b186477wa93fc62e089b3efa@mail.gmail.com> <810a540e0712122017i66be5a28n5d417ae45f43c6bc@mail.gmail.com> <57c63afe0712122117p3624d0a3nf2c0e610175bf094@mail.gmail.com> Message-ID: <921ca2f80712130011r6e0223e0wdf2cd30c3f2517be@mail.gmail.com> Hi there, Would it make sense to put up a page on an RSpec wiki where a table of good combinations (versions of rails and rspec) would be maintained? Anyway, I think a wiki would be a good idea. Stefan 2007/12/13, David Chelimsky : > > On Dec 12, 2007 10:17 PM, Pat Maddox wrote: > > On Dec 12, 2007 4:01 AM, aslak hellesoy > wrote: > > > On Dec 12, 2007 12:48 AM, Yitzhak Bar Geva > wrote: > > > > > > > > Is it OK to go ahead and generate a Rails 2.0 project with RSpec > 1.0.8? Am I > > > > likely to run into problems? > > > > > > When we released RSpec 1.0.8 there was no Rails 2.0. We always have to > > > do a fair amount of tweaks to keep up with Rails, so the versions > > > you're talking about are incompatible. > > > > > > As a general rule: Each RSpec release will work with the latest Rails > > > at the time of release. If you want to use a newer Rails, use RSpec > > > trunk. > > > > Do you think it would make sense to do an interim release of RSpec > > whenever a new Rails version gets released? > > We try to do releases right after rails releases - that's why we're > working hard to get 1.1 out the door now. > > > It (probably) shouldn't > > be based off of trunk, but rather the last stable release, with > > whatever little bug fixes may be required to work with Rails. That > > way there's no question...for any Rails version, people have the > > choice of using a stable version of RSpec trunk. > > > > Pat > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Bekk Open Source http://boss.bekk.no -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071213/78fa69bb/attachment.html From stefan.landro at gmail.com Thu Dec 13 03:19:07 2007 From: stefan.landro at gmail.com (=?ISO-8859-1?Q?Stefan_Magnus_Landr=F8?=) Date: Thu, 13 Dec 2007 09:19:07 +0100 Subject: [rspec-users] stub with assigns? In-Reply-To: References: <3BB9A0F8-5034-4244-AEDC-10CAE25C8728@parkerhill.com> <4BC12E58-692B-419D-9C8D-4A7B08D8B740@parkerhill.com> Message-ID: <921ca2f80712130019i4436e394scf571a4ac88c070a@mail.gmail.com> I wouldn't try doing this. You risk getting highly coupled test code. I'd rather use a little helper method that does this for you. Stefan 2007/12/13, Jonathan Linowes : > > > On Dec 13, 2007, at 2:47 AM, Jonathan Linowes wrote: > > > > > On Dec 13, 2007, at 2:06 AM, Jarkko Laine wrote: > > > >> > >> On 13.12.2007, at 9.00, Jonathan Linowes wrote: > >> > >>> is there a way to stub a method that sets an instance variable, so > >>> the stub sets it too? > >>> > >>> def find_foo > >>> @foo = Foo.find(params[:id] > >>> end > >>> > >>> > >>> ... > >>> controller.stub!(:find_foo).and_assigns(:foo, "123") > >> > >> Why don't you just stub Foo.find? That way the instance var gets > >> assigned automatically. > >> > >> //jarkko > >> > > > > Sorry, perhaps I gave too simplistic an example. > > My question is what if I want to stub the whole find_foo method > > but one of its side effects is it sets @foo > > (rather than stub the internals of find_foo) > > > > > ... and @foo is used by the method that i am testing > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Bekk Open Source http://boss.bekk.no -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071213/06c5d38e/attachment.html From michael.s.klishin.lists at gmail.com Thu Dec 13 05:22:12 2007 From: michael.s.klishin.lists at gmail.com (Michael Klishin) Date: Thu, 13 Dec 2007 12:22:12 +0200 Subject: [rspec-users] Problem running examples with spec_server In-Reply-To: References: Message-ID: <52F70C79-5DE0-4F93-86E7-4D15E2676DAE@gmail.com> What error do you get? On 12 ???. 2007, at 19:39, David Nolan wrote: > Hello, > Running RSpec without DRB works fine. > However, "spec -X" runs without error but provides no output at all, > even though the DRB spec_server seems to be fine. > Has anyone got some suggestions as to why and how to fix? MK From rick.denatale at gmail.com Thu Dec 13 07:57:02 2007 From: rick.denatale at gmail.com (Rick DeNatale) Date: Thu, 13 Dec 2007 07:57:02 -0500 Subject: [rspec-users] "Tricks" for testing after_create callback??? In-Reply-To: <810a540e0712122011h2b657beo50f88489f843dc71@mail.gmail.com> References: <810a540e0712122011h2b657beo50f88489f843dc71@mail.gmail.com> Message-ID: On 12/12/07, Pat Maddox wrote: > I would not mock the call, and would instead just let the mailer do > its thing. You can verify that a message was sent, match the > subject/content, etc. It's very lightweight so there's no reason not > to use it. The problem with this is that it combines testing the sending of the message with testing how it's rendered. I prefer to do the latter in the context of testing the mailer. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From daniel.ruby at tenner.org Thu Dec 13 08:35:03 2007 From: daniel.ruby at tenner.org (Daniel Tenner) Date: Thu, 13 Dec 2007 13:35:03 +0000 Subject: [rspec-users] "Tricks" for testing after_create callback??? In-Reply-To: References: <810a540e0712122011h2b657beo50f88489f843dc71@mail.gmail.com> Message-ID: <89BBAF90-5084-4A3B-BDF5-C44F61D156F3@tenner.org> Hi Rick, I'm probably a heretic on this point, but I would test that :deliver_xyz is being called but not specify what parameters it's called with. What's my reasoning? - What I'm really testing in the Message spec is not the validity of the email that's being sent, but the fact that an email is being sent. Basically, I think the Mailer is a different tier. - I have integration tests that ensure that the system is working as a whole. If the params are wrong in a business-meaningful way, those should tell me what's wrong Possibly most important point: - How is this piece of code likely to break? The most likely way that this code would break would be if I change the mailer method so that it requires different parameters. Will the spec the way you're attempting to write it catch that? Nope. Only the integration test will catch that. What will you catch by specifying the exact parameters that the mailer is called with, then? Not much - typos in the after_create callback, perhaps. As it happens, that would also be caught by the integration test. I like to focus my speccing effort on where the errors are likely to occur. As such, my approach would be to simplify the spec to: describe Message, "from anyone" do it "should send an email on save" do msg_creation_parms = { :subject => "Subj", :body => "hi", :sender => people(:rick), :recipient => people(:john) } SantasMailbox.should_receive(:deliver_secret_santa) Message.create(msg_creation_parms) end end But, as I said, I'm probably a heretic :-) Others will probably disagree violently (and they'll probably be right). I hope this helps, Daniel PS: If I decided that the mailer is actually the same tier as the model that's calling it, then I would not mock any of it, and do what Pat suggested. However, at the moment, I tend to see mailing as a separate tier from BL/CRUD. On 13 Dec 2007, at 12:57 13 Dec 2007, Rick DeNatale wrote: > On 12/12/07, Pat Maddox wrote: > >> I would not mock the call, and would instead just let the mailer do >> its thing. You can verify that a message was sent, match the >> subject/content, etc. It's very lightweight so there's no reason not >> to use it. > > The problem with this is that it combines testing the sending of the > message with testing how it's rendered. > > I prefer to do the latter in the context of testing the mailer. > > -- > Rick DeNatale > > My blog on Ruby > http://talklikeaduck.denhaven2.com/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From rick.denatale at gmail.com Thu Dec 13 08:38:31 2007 From: rick.denatale at gmail.com (Rick DeNatale) Date: Thu, 13 Dec 2007 08:38:31 -0500 Subject: [rspec-users] "Tricks" for testing after_create callback??? In-Reply-To: <57c63afe0712122116q58deac00wf80e46b7a79434a@mail.gmail.com> References: <60f3810c0712121948gaea9aeej30f86fe6f0bc0264@mail.gmail.com> <57c63afe0712122116q58deac00wf80e46b7a79434a@mail.gmail.com> Message-ID: On 12/13/07, David Chelimsky wrote: > That said, I'd go for a lesser known feature: custom mock argument > matchers. Something like this (completely off the top of my head and > not tested or guaranteed bug-free - but this will give you the idea): > > class EquivalentMessage > def initialize(message) > @message = message > end > > def ==(other) > other.subject == @message.subject && > other.body == @message.body && > other.sender == @message.sender && > other.recipient == @message.recipient > end > end > > def message_equivalent_to(message) > EquivalentMessage.new(message) > end > > it "should be sent on save" do > msg_creation_parms = { > :subject => "Subj", > :body => "hi", > :sender => people(:rick), > :recipient => people(:john) > } > SantasMailbox.should_receive(:deliver_secret_santa). > with(message_equivalent_to(Message.new(msg_creation_parms))) > Message.create(msg_creation_parms) > end > > Try that out and see what you think. I like this but, I'm running into a snag or two. When I tried this as-is I'm getting a no method exception in EquivalentMessage#== because it's running into a case where other is :no_args. I put in some tracing and determined that it was also getting other with the right message. So (biting my lip because I don't like class tests I changed this to: def ==(other) Message === other && other.subject == @message.subject && other.body == @message.body && other.sender == @message.sender && other.recipient == @message.recipient end Now it fails with: Spec::Mocks::MockExpectationError in 'Message from anyone should be sent on save' Mock 'Class' expected :deliver_secret_santa with (#>) once, but received it twice Now I'm interpreting this to mean that 1) the deliver_secret_santa message actually got called at least once with no arguments, hence the :no_args and 2) It got called twice with matching args. As to the second, there's only one call to that method, in the after_create call-back, and it passes the message as an argument. So I put some tracing into the callback to print out a back trace, and it does seem to be called twice, BUT it also seems that the Message.create call IN THE SPEC, is being called twice?!? **** after_create # /Users/rick/ssanta/vendor/rails/activerecord/lib/active_record/callbacks.rb:311:in `call' /Users/rick/ssanta/vendor/rails/activerecord/lib/active_record/callbacks.rb:311:in `callback' /Users/rick/ssanta/vendor/rails/activerecord/lib/active_record/callbacks.rb:304:in `each' /Users/rick/ssanta/vendor/rails/activerecord/lib/active_record/callbacks.rb:304:in `callback' /Users/rick/ssanta/vendor/rails/activerecord/lib/active_record/callbacks.rb:227:in `create_without_timestamps' /Users/rick/ssanta/vendor/rails/activerecord/lib/active_record/timestamp.rb:29:in `create' /Users/rick/ssanta/vendor/rails/activerecord/lib/active_record/base.rb:2165:in `create_or_update_without_callbacks' /Users/rick/ssanta/vendor/rails/activerecord/lib/active_record/callbacks.rb:213:in `create_or_update' /Users/rick/ssanta/vendor/rails/activerecord/lib/active_record/base.rb:1899:in `save_without_validation' /Users/rick/ssanta/vendor/rails/activerecord/lib/active_record/validations.rb:901:in `save_without_transactions' /Users/rick/ssanta/vendor/rails/activerecord/lib/active_record/transactions.rb:108:in `save' /Users/rick/ssanta/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:66:in `transaction' /Users/rick/ssanta/vendor/rails/activerecord/lib/active_record/transactions.rb:80:in `transaction' /Users/rick/ssanta/vendor/rails/activerecord/lib/active_record/transactions.rb:100:in `transaction' /Users/rick/ssanta/vendor/rails/activerecord/lib/active_record/transactions.rb:108:in `save' /Users/rick/ssanta/vendor/rails/activerecord/lib/active_record/transactions.rb:120:in `rollback_active_record_state!' /Users/rick/ssanta/vendor/rails/activerecord/lib/active_record/transactions.rb:108:in `save' /Users/rick/ssanta/vendor/rails/activerecord/lib/active_record/base.rb:522:in `create' ./spec/models/message_spec.rb:177 /Users/rick/ssanta/vendor/plugins/rspec/lib/spec/example/example.rb:18:in `instance_eval' /Users/rick/ssanta/vendor/plugins/rspec/lib/spec/example/example.rb:18:in `run_in' /Users/rick/ssanta/vendor/plugins/rspec/lib/spec/matchers.rb:143:in `capture_generated_description' /Users/rick/ssanta/vendor/plugins/rspec/lib/spec/example/example.rb:17:in `run_in' /Users/rick/ssanta/vendor/plugins/rspec/lib/spec/example/example_methods.rb:14:in `execute' /opt/local/lib/ruby/1.8/timeout.rb:48:in `timeout' /Users/rick/ssanta/vendor/plugins/rspec/lib/spec/example/example_methods.rb:11:in `execute' /Users/rick/ssanta/vendor/plugins/rspec/lib/spec/example/example_group_methods.rb:260:in `execute_examples' /Users/rick/ssanta/vendor/plugins/rspec/lib/spec/example/example_group_methods.rb:258:in `each' /Users/rick/ssanta/vendor/plugins/rspec/lib/spec/example/example_group_methods.rb:258:in `execute_examples' /Users/rick/ssanta/vendor/plugins/rspec/lib/spec/example/example_group_methods.rb:115:in `run' /Users/rick/ssanta/vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb:22:in `run' /Users/rick/ssanta/vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb:21:in `each' /Users/rick/ssanta/vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb:21:in `run' /Users/rick/ssanta/vendor/plugins/rspec/lib/spec/runner/options.rb:86:in `run_examples' /Users/rick/ssanta/vendor/plugins/rspec/lib/spec/runner/command_line.rb:19:in `run' /Users/rick/ssanta/vendor/plugins/rspec/bin/spec:3 **** after_create # /Users/rick/ssanta/vendor/rails/activerecord/lib/active_record/callbacks.rb:311:in `call' /Users/rick/ssanta/vendor/rails/activerecord/lib/active_record/callbacks.rb:311:in `callback' /Users/rick/ssanta/vendor/rails/activerecord/lib/active_record/callbacks.rb:304:in `each' /Users/rick/ssanta/vendor/rails/activerecord/lib/active_record/callbacks.rb:304:in `callback' /Users/rick/ssanta/vendor/rails/activerecord/lib/active_record/callbacks.rb:227:in `create_without_timestamps' /Users/rick/ssanta/vendor/rails/activerecord/lib/active_record/timestamp.rb:29:in `create' /Users/rick/ssanta/vendor/rails/activerecord/lib/active_record/base.rb:2165:in `create_or_update_without_callbacks' /Users/rick/ssanta/vendor/rails/activerecord/lib/active_record/callbacks.rb:213:in `create_or_update' /Users/rick/ssanta/vendor/rails/activerecord/lib/active_record/base.rb:1899:in `save_without_validation' /Users/rick/ssanta/vendor/rails/activerecord/lib/active_record/validations.rb:901:in `save_without_transactions' /Users/rick/ssanta/vendor/rails/activerecord/lib/active_record/transactions.rb:108:in `save' /Users/rick/ssanta/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:66:in `transaction' /Users/rick/ssanta/vendor/rails/activerecord/lib/active_record/transactions.rb:80:in `transaction' /Users/rick/ssanta/vendor/rails/activerecord/lib/active_record/transactions.rb:100:in `transaction' /Users/rick/ssanta/vendor/rails/activerecord/lib/active_record/transactions.rb:108:in `save' /Users/rick/ssanta/vendor/rails/activerecord/lib/active_record/transactions.rb:120:in `rollback_active_record_state!' /Users/rick/ssanta/vendor/rails/activerecord/lib/active_record/transactions.rb:108:in `save' /Users/rick/ssanta/vendor/rails/activerecord/lib/active_record/base.rb:522:in `create' ./spec/models/message_spec.rb:177 /Users/rick/ssanta/vendor/plugins/rspec/lib/spec/example/example.rb:18:in `instance_eval' /Users/rick/ssanta/vendor/plugins/rspec/lib/spec/example/example.rb:18:in `run_in' /Users/rick/ssanta/vendor/plugins/rspec/lib/spec/matchers.rb:143:in `capture_generated_description' /Users/rick/ssanta/vendor/plugins/rspec/lib/spec/example/example.rb:17:in `run_in' /Users/rick/ssanta/vendor/plugins/rspec/lib/spec/example/example_methods.rb:14:in `execute' /opt/local/lib/ruby/1.8/timeout.rb:48:in `timeout' /Users/rick/ssanta/vendor/plugins/rspec/lib/spec/example/example_methods.rb:11:in `execute' /Users/rick/ssanta/vendor/plugins/rspec/lib/spec/example/example_group_methods.rb:260:in `execute_examples' /Users/rick/ssanta/vendor/plugins/rspec/lib/spec/example/example_group_methods.rb:258:in `each' /Users/rick/ssanta/vendor/plugins/rspec/lib/spec/example/example_group_methods.rb:258:in `execute_examples' /Users/rick/ssanta/vendor/plugins/rspec/lib/spec/example/example_group_methods.rb:115:in `run' /Users/rick/ssanta/vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb:22:in `run' /Users/rick/ssanta/vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb:21:in `each' /Users/rick/ssanta/vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb:21:in `run' /Users/rick/ssanta/vendor/plugins/rspec/lib/spec/runner/options.rb:86:in `run_examples' /Users/rick/ssanta/vendor/plugins/rspec/lib/spec/runner/command_line.rb:19:in `run' /Users/rick/ssanta/vendor/plugins/rspec/bin/spec:3 Not sure why this is happening, but it seems to be the rspec machinery that's doing it unless I'm missing something. Here's the complete description from the spec: class EquivalentMessage def initialize(msg) @message = msg end def ==(other) Message === other && other.subject == @message.subject && other.body == @message.body && other.sender == @message.sender && other.recipient == @message.recipient end end def message_equivalent_to(message) EquivalentMessage.new(message) end describe Message, "from anyone" do # t.string :subject # t.text :body # t.integer :from_id # t.integer :to_id # t.integer :type # Normal, FromSecretSanta, ToSecretSanta fixtures :people before(:each) do end it "should be sent on save" do msg_creation_parms = { :subject => "Subj", :body => "hi", :sender => people(:rick), :recipient => people(:john), :message_type => Message::FromSecretSanta } SantasMailbox.should_receive(:deliver_secret_santa).with(message_equivalent_to(Message.new(msg_creation_parms))) Message.create(msg_creation_parms) end end -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From rick.denatale at gmail.com Thu Dec 13 08:43:59 2007 From: rick.denatale at gmail.com (Rick DeNatale) Date: Thu, 13 Dec 2007 08:43:59 -0500 Subject: [rspec-users] "Tricks" for testing after_create callback??? In-Reply-To: <89BBAF90-5084-4A3B-BDF5-C44F61D156F3@tenner.org> References: <810a540e0712122011h2b657beo50f88489f843dc71@mail.gmail.com> <89BBAF90-5084-4A3B-BDF5-C44F61D156F3@tenner.org> Message-ID: On 12/13/07, Daniel Tenner wrote: > Hi Rick, > > I'm probably a heretic on this point, but I would test > that :deliver_xyz is being called but not specify what parameters > it's called with. > > What's my reasoning? > > - What I'm really testing in the Message spec is not the validity of > the email that's being sent, but the fact that an email is being > sent. Basically, I think the Mailer is a different tier. I'm not testing the validity of the email, but. In this case the email which gets send depends largely on what's in the message object. The mailer extracts attributes from the object to create the email, so it's crucial that the correct message is passed and that's what I'm trying to spec. The actual contents of the message are specified in tests against the mailer as I indicated in my earlier reply to Pat. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From daniel.ruby at tenner.org Thu Dec 13 08:57:05 2007 From: daniel.ruby at tenner.org (Daniel Tenner) Date: Thu, 13 Dec 2007 13:57:05 +0000 Subject: [rspec-users] "Tricks" for testing after_create callback??? In-Reply-To: References: <810a540e0712122011h2b657beo50f88489f843dc71@mail.gmail.com> <89BBAF90-5084-4A3B-BDF5-C44F61D156F3@tenner.org> Message-ID: Hi Rick, Could you paste us what your after_save and your deliver_xyz methods look like? I think it would be helpful to make the discussion more concrete. I've found that whenever my code is hard to spec, it's usually poorly designed in the first place, and a better split of responsibilities helps make the code both clearer and easily spec'ed. In this specific case, I'm a bit perplexed that you're sending a pre- generated body/subject/sender/etc to the Mailer. Shouldn't that code be in the Mailer's deliver_xyz method? E.g., from my own code: ## password_change_observer.rb class PasswordChangeObserver < ActiveRecord::Observer observe User def after_update(user) if user.password_modified? UserMailer.deliver_new_password(user) end end end ## user_mailer.rb class UserMailer < ActionMailer::Base def new_password(user) @subject = 'Your new password' @body = {"user" => user} @recipients = user.email @sent_on = Time.now @from = MAIL_FROM end end ##new_password.erb Dear user, You have just updated your password. This is a reminder, so that you don't forget it. Your username (email) is: <%= @user.email %> Your password is: <%= @user.password %> If you lose this email and forget your password, don't worry - you can get a new password generated by going to http://<%= SERVER_NAME %>/forgot_password/<%= @user.id %>"> and entering your email. Thanks, The Team #### I'm a bit confused because your code seems to say: msg_creation_parms = { :subject => "Subj", :body => "hi", :sender => people(:rick), :recipient => people(:john) } SantasMailbox.should_receive(:deliver_secret_santa).with(Message.new (msg_creation_parms)) Which would imply you're building the subject, body, sender and recipient before passing things on to the mailer? Maybe I got this all wrong though... Daniel On 13 Dec 2007, at 13:43 13 Dec 2007, Rick DeNatale wrote: > On 12/13/07, Daniel Tenner wrote: >> Hi Rick, >> >> I'm probably a heretic on this point, but I would test >> that :deliver_xyz is being called but not specify what parameters >> it's called with. >> >> What's my reasoning? >> >> - What I'm really testing in the Message spec is not the validity of >> the email that's being sent, but the fact that an email is being >> sent. Basically, I think the Mailer is a different tier. > > I'm not testing the validity of the email, but. > > In this case the email which gets send depends largely on what's in > the message object. The mailer extracts attributes from the object to > create the email, so it's crucial that the correct message is passed > and that's what I'm trying to spec. > > The actual contents of the message are specified in tests against the > mailer as I indicated in my earlier reply to Pat. > > -- > Rick DeNatale > > My blog on Ruby > http://talklikeaduck.denhaven2.com/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From daniel.ruby at tenner.org Thu Dec 13 09:06:41 2007 From: daniel.ruby at tenner.org (Daniel Tenner) Date: Thu, 13 Dec 2007 14:06:41 +0000 Subject: [rspec-users] stub with assigns? In-Reply-To: References: <3BB9A0F8-5034-4244-AEDC-10CAE25C8728@parkerhill.com> <4BC12E58-692B-419D-9C8D-4A7B08D8B740@parkerhill.com> Message-ID: <3775E681-4243-4A25-95EC-4F9FD8B31219@tenner.org> >> Sorry, perhaps I gave too simplistic an example. >> Real code, please? :-) Simplified examples only ever result in simplistic suggestions. Daniel On 13 Dec 2007, at 07:55 13 Dec 2007, Jonathan Linowes wrote: > > On Dec 13, 2007, at 2:47 AM, Jonathan Linowes wrote: > >> >> On Dec 13, 2007, at 2:06 AM, Jarkko Laine wrote: >> >>> >>> On 13.12.2007, at 9.00, Jonathan Linowes wrote: >>> >>>> is there a way to stub a method that sets an instance variable, so >>>> the stub sets it too? >>>> >>>> def find_foo >>>> @foo = Foo.find(params[:id] >>>> end >>>> >>>> >>>> ... >>>> controller.stub!(:find_foo).and_assigns(:foo, "123") >>> >>> Why don't you just stub Foo.find? That way the instance var gets >>> assigned automatically. >>> >>> //jarkko >>> >> >> Sorry, perhaps I gave too simplistic an example. >> My question is what if I want to stub the whole find_foo method >> but one of its side effects is it sets @foo >> (rather than stub the internals of find_foo) >> >> > ... and @foo is used by the method that i am testing > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From rick.denatale at gmail.com Thu Dec 13 09:44:37 2007 From: rick.denatale at gmail.com (Rick DeNatale) Date: Thu, 13 Dec 2007 09:44:37 -0500 Subject: [rspec-users] "Tricks" for testing after_create callback??? In-Reply-To: References: <810a540e0712122011h2b657beo50f88489f843dc71@mail.gmail.com> <89BBAF90-5084-4A3B-BDF5-C44F61D156F3@tenner.org> Message-ID: On 12/13/07, Daniel Tenner wrote: > Hi Rick, > > Could you paste us what your after_save and your deliver_xyz methods > look like? I think it would be helpful to make the discussion more > concrete. > > I've found that whenever my code is hard to spec, it's usually poorly > designed in the first place, and a better split of responsibilities > helps make the code both clearer and easily spec'ed. > > In this specific case, I'm a bit perplexed that you're sending a pre- > generated body/subject/sender/etc to the Mailer. Shouldn't that code > be in the Mailer's deliver_xyz method? In this case the bulk of the message is coming from, surprise, the message object. This is a secret santa site, the idea is to allow folks to communicate without giving away who is who. class Message < ActiveRecord::Base belongs_to :sender, :class_name => "Person", :foreign_key => :sender_id belongs_to :recipient, :class_name => "Person", :foreign_key => :recipient_id after_create do |msg| puts "\n**** after_create #{msg}\n#{caller.join("\n")}\n" SantasMailbox.deliver_secret_santa(msg) end ... end class SantasMailbox < ActionMailer::Base ... def secret_santa(message) subject message.subject body( {:sender => message.sender_name, :recipient => message.recipient_first_name, :text => body}) recipients "#{recipient.full_name} <#{recipient.email}>" from "#{message.sender_full_name} <#{message.sender_name}@denhaven2.com" sent_on message.created_at content_type 'text/html' headers {} end ... end Where methods like sender_name etc. on the Message object produce appropriate clear or obfuscated (e.g. 'Your Secret Santa' depending on the message state. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From rick.denatale at gmail.com Thu Dec 13 09:46:03 2007 From: rick.denatale at gmail.com (Rick DeNatale) Date: Thu, 13 Dec 2007 09:46:03 -0500 Subject: [rspec-users] "Tricks" for testing after_create callback??? In-Reply-To: References: <810a540e0712122011h2b657beo50f88489f843dc71@mail.gmail.com> <89BBAF90-5084-4A3B-BDF5-C44F61D156F3@tenner.org> Message-ID: On 12/13/07, Rick DeNatale wrote: > class Message < ActiveRecord::Base > > belongs_to :sender, :class_name => "Person", :foreign_key => :sender_id > belongs_to :recipient, :class_name => "Person", :foreign_key => :recipient_id > > after_create do |msg| > puts "\n**** after_create #{msg}\n#{caller.join("\n")}\n" Of course that puts isn't really there, it's a remnant of my attempts to debug David's suggestion. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From daniel.ruby at tenner.org Thu Dec 13 09:52:28 2007 From: daniel.ruby at tenner.org (Daniel Tenner) Date: Thu, 13 Dec 2007 14:52:28 +0000 Subject: [rspec-users] "Tricks" for testing after_create callback??? In-Reply-To: References: <810a540e0712122011h2b657beo50f88489f843dc71@mail.gmail.com> <89BBAF90-5084-4A3B-BDF5-C44F61D156F3@tenner.org> Message-ID: Then I definitely think there's little point in specifying what "deliver_secret_santa" is called with. The chances that you'll get that wrong are extremely small, and even if you do it will be picked up instantly by your integration tests, and be very easy to fix. What's much more likely to break is SantasMailbox - so focus the time, the effort, and the lines of code on speccing that quite thoroughly, so you know it can take every likely Message that you might throw at it. (/opinion) Daniel On 13 Dec 2007, at 14:44 13 Dec 2007, Rick DeNatale wrote: > On 12/13/07, Daniel Tenner wrote: >> Hi Rick, >> >> Could you paste us what your after_save and your deliver_xyz methods >> look like? I think it would be helpful to make the discussion more >> concrete. >> >> I've found that whenever my code is hard to spec, it's usually poorly >> designed in the first place, and a better split of responsibilities >> helps make the code both clearer and easily spec'ed. >> >> In this specific case, I'm a bit perplexed that you're sending a pre- >> generated body/subject/sender/etc to the Mailer. Shouldn't that code >> be in the Mailer's deliver_xyz method? > > In this case the bulk of the message is coming from, surprise, the > message object. > > This is a secret santa site, the idea is to allow folks to communicate > without giving away who is who. > > class Message < ActiveRecord::Base > > belongs_to :sender, :class_name => "Person", :foreign_key > => :sender_id > belongs_to :recipient, :class_name => "Person", :foreign_key > => :recipient_id > > after_create do |msg| > puts "\n**** after_create #{msg}\n#{caller.join("\n")}\n" > > SantasMailbox.deliver_secret_santa(msg) > end > ... > end > > class SantasMailbox < ActionMailer::Base > ... > def secret_santa(message) > subject message.subject > body( {:sender => message.sender_name, > :recipient => > message.recipient_first_name, :text => body}) > recipients "#{recipient.full_name} <#{recipient.email}>" > from "#{message.sender_full_name} > <#{message.sender_name}@denhaven2.com" > sent_on message.created_at > content_type 'text/html' > headers {} > end > ... > end > > Where methods like sender_name etc. on the Message object produce > appropriate clear or obfuscated (e.g. 'Your Secret Santa' depending > on the message state. > > -- > Rick DeNatale > > My blog on Ruby > http://talklikeaduck.denhaven2.com/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From rick.denatale at gmail.com Thu Dec 13 09:59:18 2007 From: rick.denatale at gmail.com (Rick DeNatale) Date: Thu, 13 Dec 2007 09:59:18 -0500 Subject: [rspec-users] "Tricks" for testing after_create callback??? In-Reply-To: References: <810a540e0712122011h2b657beo50f88489f843dc71@mail.gmail.com> <89BBAF90-5084-4A3B-BDF5-C44F61D156F3@tenner.org> Message-ID: On 12/13/07, Daniel Tenner wrote: > Then I definitely think there's little point in specifying what > "deliver_secret_santa" is called with. The chances that you'll get > that wrong are extremely small, and even if you do it will be picked > up instantly by your integration tests, and be very easy to fix. > > What's much more likely to break is SantasMailbox - so focus the > time, the effort, and the lines of code on speccing that quite > thoroughly, so you know it can take every likely Message that you > might throw at it. > > (/opinion) Well IMHO, I think that it's important to spec both. Even though the callback is simple, it's a crucial design point, and I'm not unknown to break such assumptions as code progresses. It shouldn't be so hard to do either, I just can't figure out now, why rspec seems to be calling the create in my spec twice. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From pergesu at gmail.com Thu Dec 13 10:06:28 2007 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 13 Dec 2007 07:06:28 -0800 Subject: [rspec-users] "Tricks" for testing after_create callback??? In-Reply-To: References: <810a540e0712122011h2b657beo50f88489f843dc71@mail.gmail.com> Message-ID: <810a540e0712130706p53fab798ybef92b0fb94c3317@mail.gmail.com> On Dec 13, 2007 4:57 AM, Rick DeNatale wrote: > On 12/12/07, Pat Maddox wrote: > > > I would not mock the call, and would instead just let the mailer do > > its thing. You can verify that a message was sent, match the > > subject/content, etc. It's very lightweight so there's no reason not > > to use it. > > The problem with this is that it combines testing the sending of the > message with testing how it's rendered. > > I prefer to do the latter in the context of testing the mailer. So then I would write two specs. One verifies that it was sent, and one verifies the content. You're combining them here as well, albeit in a less flexible (and apparently painful :) way. Pat From dchelimsky at gmail.com Thu Dec 13 10:07:10 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 13 Dec 2007 09:07:10 -0600 Subject: [rspec-users] "Tricks" for testing after_create callback??? In-Reply-To: References: <810a540e0712122011h2b657beo50f88489f843dc71@mail.gmail.com> <89BBAF90-5084-4A3B-BDF5-C44F61D156F3@tenner.org> Message-ID: <57c63afe0712130707o74542fc1ie1e369a7d3e29c33@mail.gmail.com> On Dec 13, 2007 8:59 AM, Rick DeNatale wrote: > On 12/13/07, Daniel Tenner wrote: > > Then I definitely think there's little point in specifying what > > "deliver_secret_santa" is called with. The chances that you'll get > > that wrong are extremely small, and even if you do it will be picked > > up instantly by your integration tests, and be very easy to fix. > > > > What's much more likely to break is SantasMailbox - so focus the > > time, the effort, and the lines of code on speccing that quite > > thoroughly, so you know it can take every likely Message that you > > might throw at it. > > > > (/opinion) > > Well IMHO, I think that it's important to spec both. Even though the > callback is simple, it's a crucial design point, and I'm not unknown > to break such assumptions as code progresses. > > > It shouldn't be so hard to do either, I just can't figure out now, > why rspec seems to be calling the create in my spec twice. This is a bit scary :( Rick - would you mind sticking this information, a bit filtered, into the tracker? > > > -- > Rick DeNatale > > My blog on Ruby > http://talklikeaduck.denhaven2.com/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dpdnolan at gmail.com Thu Dec 13 10:15:02 2007 From: dpdnolan at gmail.com (David Nolan) Date: Thu, 13 Dec 2007 15:15:02 +0000 Subject: [rspec-users] Problem running examples with spec_server In-Reply-To: <52F70C79-5DE0-4F93-86E7-4D15E2676DAE@gmail.com> References: <52F70C79-5DE0-4F93-86E7-4D15E2676DAE@gmail.com> Message-ID: Hello, It doesn't output any error messages. It doesn't output anything, not a sausage, and just returns the prompt after a brief pause. Thanks, Dave On 13/12/2007, Michael Klishin wrote: > > What error do you get? > > On 12 ???. 2007, at 19:39, David Nolan wrote: > > > Hello, > > Running RSpec without DRB works fine. > > However, "spec -X" runs without error but provides no output at all, > > even though the DRB spec_server seems to be fine. > > Has anyone got some suggestions as to why and how to fix? > > MK > _______________________________________________ > 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/20071213/fae46c75/attachment.html From rick.denatale at gmail.com Thu Dec 13 10:54:11 2007 From: rick.denatale at gmail.com (Rick DeNatale) Date: Thu, 13 Dec 2007 10:54:11 -0500 Subject: [rspec-users] "Tricks" for testing after_create callback??? In-Reply-To: <57c63afe0712130707o74542fc1ie1e369a7d3e29c33@mail.gmail.com> References: <810a540e0712122011h2b657beo50f88489f843dc71@mail.gmail.com> <89BBAF90-5084-4A3B-BDF5-C44F61D156F3@tenner.org> <57c63afe0712130707o74542fc1ie1e369a7d3e29c33@mail.gmail.com> Message-ID: On 12/13/07, David Chelimsky wrote: > On Dec 13, 2007 8:59 AM, Rick DeNatale wrote: > > On 12/13/07, Daniel Tenner wrote: > > > Then I definitely think there's little point in specifying what > > > "deliver_secret_santa" is called with. The chances that you'll get > > > that wrong are extremely small, and even if you do it will be picked > > > up instantly by your integration tests, and be very easy to fix. > > Well IMHO, I think that it's important to spec both. Even though the > > callback is simple, it's a crucial design point, and I'm not unknown > > to break such assumptions as code progresses. > > > > > > It shouldn't be so hard to do either, I just can't figure out now, > > why rspec seems to be calling the create in my spec twice. > > This is a bit scary :( > > Rick - would you mind sticking this information, a bit filtered, into > the tracker? Well, as I was doing just that, I looked a bit closer at those walkbacks, and it occurred to me that I was assuming that rspec was calling the method twice. As it turns out, it was actually ActiveRecord calling the callback twice, and it went away when I changed from after_create do |msg| ... end to def after_create ... end So I guess I need to follow up on Rails core! Although that change fixed things for this case. And it just goes to show that it was important to spec this, since it would be a bad thing (tm) if the email got sent twice. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From rick.denatale at gmail.com Thu Dec 13 11:39:16 2007 From: rick.denatale at gmail.com (Rick DeNatale) Date: Thu, 13 Dec 2007 11:39:16 -0500 Subject: [rspec-users] "Tricks" for testing after_create callback??? In-Reply-To: References: <89BBAF90-5084-4A3B-BDF5-C44F61D156F3@tenner.org> <57c63afe0712130707o74542fc1ie1e369a7d3e29c33@mail.gmail.com> Message-ID: On 12/13/07, Rick DeNatale wrote: > On 12/13/07, David Chelimsky wrote: > > This is a bit scary :( > > > > Rick - would you mind sticking this information, a bit filtered, into > > the tracker? > > Well, as I was doing just that, I looked a bit closer at those > walkbacks, and it occurred to me that I was assuming that rspec was > calling the method twice. > > As it turns out, it was actually ActiveRecord calling the callback > twice, and it went away when I changed from > > after_create do |msg| > ... > end > > to > > def after_create > ... > end > > So I guess I need to follow up on Rails core! Although that change > fixed things for this case. Okay, more info. As I was investigating this for a possible ticket for Rails Trac, it dawned on me that maybe, just maybe, the after_create do...end was being executed twice. So I added a puts "**** loading Message" in the class definition for the Message AR class, and sure enough it was being loaded twice! It turns out that I had require 'message' at the top of the spec file. and a few other descriptions in the same file which were using the messages fixture. When I remove the require 'message' from my spec file, it seems to work with either form of the callback definition. So I'm not sure if this is an Rspec bug, an AR fixtures bug, both or neither. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From jonathan at parkerhill.com Thu Dec 13 12:15:40 2007 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Thu, 13 Dec 2007 12:15:40 -0500 Subject: [rspec-users] stub with assigns? In-Reply-To: <3775E681-4243-4A25-95EC-4F9FD8B31219@tenner.org> References: <3BB9A0F8-5034-4244-AEDC-10CAE25C8728@parkerhill.com> <4BC12E58-692B-419D-9C8D-4A7B08D8B740@parkerhill.com> <3775E681-4243-4A25-95EC-4F9FD8B31219@tenner.org> Message-ID: thx I ended up wrapping the instance variable in a method, which I can then stub also Its cleaner that way anyhow def current_foo @foo end On Dec 13, 2007, at 9:06 AM, Daniel Tenner wrote: >>> Sorry, perhaps I gave too simplistic an example. >>> > Real code, please? :-) > > Simplified examples only ever result in simplistic suggestions. > > Daniel > > On 13 Dec 2007, at 07:55 13 Dec 2007, Jonathan Linowes wrote: > >> >> On Dec 13, 2007, at 2:47 AM, Jonathan Linowes wrote: >> >>> >>> On Dec 13, 2007, at 2:06 AM, Jarkko Laine wrote: >>> >>>> >>>> On 13.12.2007, at 9.00, Jonathan Linowes wrote: >>>> >>>>> is there a way to stub a method that sets an instance variable, so >>>>> the stub sets it too? >>>>> >>>>> def find_foo >>>>> @foo = Foo.find(params[:id] >>>>> end >>>>> >>>>> >>>>> ... >>>>> controller.stub!(:find_foo).and_assigns(:foo, "123") >>>> >>>> Why don't you just stub Foo.find? That way the instance var gets >>>> assigned automatically. >>>> >>>> //jarkko >>>> >>> >>> Sorry, perhaps I gave too simplistic an example. >>> My question is what if I want to stub the whole find_foo method >>> but one of its side effects is it sets @foo >>> (rather than stub the internals of find_foo) >>> >>> >> ... and @foo is used by the method that i am testing >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.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 rspec at showcase60.com Thu Dec 13 12:36:05 2007 From: rspec at showcase60.com (rspec at showcase60.com) Date: Thu, 13 Dec 2007 10:36:05 -0700 Subject: [rspec-users] RSpec and Mock Tutorial/Cheatsheet Message-ID: I wrote a simple summary of Mocks with RSpec as an answer to a discussion on our local Ruby users group. I was wondering if people here could review it, adding comments for any corrections or other important ideas regarding mocks and RSpec. You can find the article here: http://blog.showcase60.com/2007/12/13/rspec-mocks Thanks From mailing_lists at railsnewbie.com Thu Dec 13 13:30:17 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Thu, 13 Dec 2007 13:30:17 -0500 Subject: [rspec-users] RSpec and Mock Tutorial/Cheatsheet In-Reply-To: References: Message-ID: On Dec 13, 2007, at 12:36 PM, rspec at showcase60.com wrote: > I wrote a simple summary of Mocks with RSpec as an answer to a > discussion on our local Ruby users group. I was wondering if people > here could review it, adding comments for any corrections or other > important ideas regarding mocks and RSpec. You can find the article > here: http://blog.showcase60.com/2007/12/13/rspec-mocks > > Thanks hey - Thanks for the mention! Just wanted to clarify this point: "Mocha is one of those alternatives ...The benefit of Mocha is that you can mock and stub methods on real classes and instances (not just your mock models). So, if you?re specing class Foo, and you want to assume that the method bar is working, you can just stub that out, and focus on the part of the class that you?re creating at the moment." Just to let you know, there is nothing stopping you from doing this with rspec's mock/stub framework. Scott From dchelimsky at gmail.com Fri Dec 14 00:58:22 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 13 Dec 2007 23:58:22 -0600 Subject: [rspec-users] [ANN] RSpec-1.1.0 is released Message-ID: <57c63afe0712132158p5ccc906v9a90c90c227be3e1@mail.gmail.com> The RSpec Development Team is pleased as glug (that's kind of like punch, but more festive) to announce RSpec-1.1.0. Thanks to all who have contributed patches over the last few months. Big thanks to Dan North and Brian Takita for their important work on this release. Dan contributed his rbehave framework which is now the Story Runner. Brian patiently did a TON of refactoring around interoperability with Test::Unit, and the result is a much cleaner RSpec core, and a clean adapter model that gets loaded when Test::Unit is on the path. == RSpec 1.1 brings four significant changes for RSpec users: * The RSpec Story Runner * Nested Example Groups * Support for Rails 2.0.1 * Test::Unit interoperability == Story Runner The RSpec Story Runner is Dan North's rbehave framework merged into RSpec. The Story Runner is a framework for expressing high level requirements in the form of executable User Stories with Scenarios that represent Customer Acceptance Tests. RSpec 1.1 also ships with a Ruby on Rails extension called RailsStory, which lets you write executable user stories for your rails apps as well. == Nested Example Groups Now you can nest groups to organize things a bit better: describe RubyDeveloper do before(:each) do @ruby_developer = RubyDeveloper.new end describe "using RSpec 1.1.0" do before(:each) do @ruby_developer.use_rspec('1.1.0') end it "should be able to nest example groups" do @ruby_developer.should be_able_to_nest_example_groups end end describe "using RSpec 1.0.1" do before(:each) do @ruby_developer.use_rspec('1.0.8') end it "should not be able to nest example groups" do @ruby_developer.should_not be_able_to_nest_example_groups end end end Running this outputs: RubyDeveloper using RSpec 1.1.0 - should be able to nest example groups RubyDeveloper using RSpec 1.0.8 - should not be able to nest example groups == Support for Rails 2.0.1 gem install rails rails myapp ruby script/install http://rspec.rubyforge.org/svn/tags/REL_1_1_0/rspec ruby script/install http://rspec.rubyforge.org/svn/tags/REL_1_1_0/rspec_on_rails script/generate rspec == Test::Unit Interoperability Contrary to popular belief, Spec::Rails, RSpec's Ruby on Rails plugin, has been a Test::Unit wrapper since the the 0.7 release in November of 2006. RSpec 1.1 ups the ante though, offering a smooth transition from Test::Unit to RSpec with or without Rails: 1. Start with a TestCase: require 'test/unit' class TransitionTest < Test::Unit::TestCase def test_should_be_smooth transition = Transition.new( :from => "Test::Unit::TestCase", :to => "Spec::ExampleGroup" ) assert_equal "really smooth", transition.in_practice end end 2. Require 'spec' require 'test/unit' require 'spec' class TransitionTest < Test::Unit::TestCase def test_should_be_smooth transition = Transition.new( :from => "Test::Unit::TestCase", :to => "Spec::ExampleGroup" ) assert_equal "really smooth", transition.in_practice end end 3. Convert TestCase to ExampleGroup require 'test/unit' require 'spec' describe "transitioning from TestCase to ExampleGroup" do def test_should_be_smooth transition = Transition.new( :from => "Test::Unit::TestCase", :to => "Spec::ExampleGroup" ) assert_equal "really smooth", transition.in_practice end end 4. Convert test methods to examples require 'test/unit' require 'spec' describe "transitioning from TestCase to ExampleGroup" do it "should be smooth" do transition = Transition.new( :from => "Test::Unit::TestCase", :to => "Spec::ExampleGroup" ) assert_equal "really smooth", transition.in_practice end end 5. Convert assertions to expectations require 'test/unit' require 'spec' describe "transitioning from TestCase to ExampleGroup" do it "should be smooth" do transition = Transition.new( :from => "Test::Unit::TestCase", :to => "Spec::ExampleGroup") transition.in_practice.should == "really smooth" end end 6. Un-require test/unit require 'spec' describe "transitioning from TestCase to ExampleGroup" do it "should be smooth" do transition = Transition.new( :from => "Test::Unit::TestCase", :to => "Spec::ExampleGroup" ) transition.in_practice.should == "really smooth" end end At every one of these steps after step 2, you can run the file with the ruby command and you'll be getting RSpec's developer friendly output. This means that you can transition things as gradually as you like: no wholesale changes. That's the story. Thanks again to all who contributed and to all who continue do so. From lists at ruby-forum.com Fri Dec 14 01:36:56 2007 From: lists at ruby-forum.com (Chris Olsen) Date: Fri, 14 Dec 2007 07:36:56 +0100 Subject: [rspec-users] How do I mock params? Message-ID: <408fb8d24db6dbcec6e30f8542f0ea22@ruby-forum.com> Here is the code within the controller: Line 69: @photo = @member.build_photo(params[:photo]) unless params[:photo][:uploaded_data].blank? I got a little ahead of myself and wrote the code, and now have a bunch of errors telling me that: ------- 6) NoMethodError in 'Spec::Rails::Example::ControllerExampleGroup MembersController handling PUT /members/1 should find the member requested' You have a nil object when you didn't expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.[] /Users/chris/Documents/Projects/Rails/CommunityCMS/trunk/app/controllers/members_controller.rb:69:in `update' /Users/chris/Documents/Projects/Rails/CommunityCMS/trunk/vendor/rails/actionpack/lib/action_controller/base.rb:1168:in `send' ------- I have read how to set the flash and session vars, but I haven't found anything on the params. Thanks for the help BTW. Has anyone heard if the pragmatic rspec book is still planned to be released this month? -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Fri Dec 14 01:43:46 2007 From: lists at ruby-forum.com (Chris Olsen) Date: Fri, 14 Dec 2007 07:43:46 +0100 Subject: [rspec-users] can't access helper methods for model testing In-Reply-To: <57c63afe0712112109i5b1ae5cam870c2027381e2863@mail.gmail.com> References: <57c63afe0712112109i5b1ae5cam870c2027381e2863@mail.gmail.com> Message-ID: <657246ebe8318bf4d5d902b2f4e2d121@ruby-forum.com> >> What am I missing? Are these helpers only for controller tests? > > Rails helpers are there for views and controllers, not for models. > > If you want an RSpec helper, something you use to set up state for > your examples, you can write a module and include it in the example > groups - but that is a horse of a different color. > > HTH, > David That makes sense. Thanks for the help. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Fri Dec 14 01:51:11 2007 From: lists at ruby-forum.com (Chris Olsen) Date: Fri, 14 Dec 2007 07:51:11 +0100 Subject: [rspec-users] How do I mock params? In-Reply-To: <408fb8d24db6dbcec6e30f8542f0ea22@ruby-forum.com> References: <408fb8d24db6dbcec6e30f8542f0ea22@ruby-forum.com> Message-ID: Ya, just ignore this post, except for the question regarding the rpsec book. I really do wish there was a way to delete your own posts :) -- Posted via http://www.ruby-forum.com/. From pergesu at gmail.com Fri Dec 14 02:01:32 2007 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 13 Dec 2007 23:01:32 -0800 Subject: [rspec-users] [ANN] RSpec-1.1.0 is released In-Reply-To: <57c63afe0712132158p5ccc906v9a90c90c227be3e1@mail.gmail.com> References: <57c63afe0712132158p5ccc906v9a90c90c227be3e1@mail.gmail.com> Message-ID: <810a540e0712132301l7f001ec4o2d2432f6ab121bc2@mail.gmail.com> On Dec 13, 2007 9:58 PM, David Chelimsky wrote: > > The RSpec Development Team is pleased as glug (that's kind of like > punch, but more festive) to announce RSpec-1.1.0. > > Thanks to all who have contributed patches over the last few months. > Big thanks to Dan North and Brian Takita for their important work on > this release. Dan contributed his rbehave framework which is now the > Story Runner. Brian patiently did a TON of refactoring around > interoperability with Test::Unit, and the result is a much cleaner > RSpec core, and a clean adapter model that gets loaded when Test::Unit > is on the path. > > == RSpec 1.1 brings four significant changes for RSpec users: > > * The RSpec Story Runner > * Nested Example Groups > * Support for Rails 2.0.1 > * Test::Unit interoperability > > == Story Runner > > The RSpec Story Runner is Dan North's rbehave framework merged into > RSpec. The Story Runner is a framework for expressing high level > requirements in the form of executable User Stories with Scenarios > that represent Customer Acceptance Tests. > > RSpec 1.1 also ships with a Ruby on Rails extension called RailsStory, > which lets you write executable user stories for your rails apps as > well. > > == Nested Example Groups > > Now you can nest groups to organize things a bit better: > > describe RubyDeveloper do > > before(:each) do > @ruby_developer = RubyDeveloper.new > end > > describe "using RSpec 1.1.0" do > > before(:each) do > @ruby_developer.use_rspec('1.1.0') > end > > it "should be able to nest example groups" do > @ruby_developer.should be_able_to_nest_example_groups > end > > end > > describe "using RSpec 1.0.1" do > > before(:each) do > @ruby_developer.use_rspec('1.0.8') > end > > it "should not be able to nest example groups" do > @ruby_developer.should_not be_able_to_nest_example_groups > end > > end > > end > > Running this outputs: > > RubyDeveloper using RSpec 1.1.0 > - should be able to nest example groups > > RubyDeveloper using RSpec 1.0.8 > - should not be able to nest example groups > > == Support for Rails 2.0.1 > > gem install rails > rails myapp > ruby script/install http://rspec.rubyforge.org/svn/tags/REL_1_1_0/rspec > ruby script/install http://rspec.rubyforge.org/svn/tags/REL_1_1_0/rspec_on_rails > script/generate rspec > > == Test::Unit Interoperability > > Contrary to popular belief, Spec::Rails, RSpec's Ruby on Rails plugin, > has been a Test::Unit wrapper since the the 0.7 release in November of > 2006. RSpec 1.1 ups the ante though, offering a smooth transition from > Test::Unit to RSpec with or without Rails: > > 1. Start with a TestCase: > > require 'test/unit' > > class TransitionTest < Test::Unit::TestCase > def test_should_be_smooth > transition = Transition.new( > :from => "Test::Unit::TestCase", > :to => "Spec::ExampleGroup" > ) > assert_equal "really smooth", transition.in_practice > end > end > 2. Require 'spec' > > require 'test/unit' > require 'spec' > > class TransitionTest < Test::Unit::TestCase > def test_should_be_smooth > transition = Transition.new( > :from => "Test::Unit::TestCase", > :to => "Spec::ExampleGroup" > ) > assert_equal "really smooth", transition.in_practice > end > end > 3. Convert TestCase to ExampleGroup > > require 'test/unit' > require 'spec' > > describe "transitioning from TestCase to ExampleGroup" do > def test_should_be_smooth > transition = Transition.new( > :from => "Test::Unit::TestCase", > :to => "Spec::ExampleGroup" > ) > assert_equal "really smooth", transition.in_practice > end > end > 4. Convert test methods to examples > > require 'test/unit' > require 'spec' > > describe "transitioning from TestCase to ExampleGroup" do > it "should be smooth" do > transition = Transition.new( > :from => "Test::Unit::TestCase", > :to => "Spec::ExampleGroup" > ) > assert_equal "really smooth", transition.in_practice > end > end > 5. Convert assertions to expectations > > require 'test/unit' > require 'spec' > > describe "transitioning from TestCase to ExampleGroup" do > it "should be smooth" do > transition = Transition.new( > :from => "Test::Unit::TestCase", > :to => "Spec::ExampleGroup") > transition.in_practice.should == "really smooth" > end > end > 6. Un-require test/unit > > require 'spec' > > describe "transitioning from TestCase to ExampleGroup" do > it "should be smooth" do > transition = Transition.new( > :from => "Test::Unit::TestCase", > :to => "Spec::ExampleGroup" > ) > transition.in_practice.should == "really smooth" > end > end > At every one of these steps after step 2, you can run the file with > the ruby command and you'll be getting RSpec's developer friendly > output. This means that you can transition things as gradually as you > like: no wholesale changes. > > That's the story. Thanks again to all who contributed and to all who > continue do so. > > Congratulations!! Very cool. Pat From tom at experthuman.com Fri Dec 14 03:35:25 2007 From: tom at experthuman.com (Tom Stuart) Date: Fri, 14 Dec 2007 08:35:25 +0000 Subject: [rspec-users] RSpec book In-Reply-To: <408fb8d24db6dbcec6e30f8542f0ea22@ruby-forum.com> References: <408fb8d24db6dbcec6e30f8542f0ea22@ruby-forum.com> Message-ID: <9AA06BB1-7E31-4C92-85DA-BE9FF5CA1207@experthuman.com> On 14 Dec 2007, at 06:36, Chris Olsen wrote: > BTW. Has anyone heard if the pragmatic rspec book is still planned to > be released this month? I second this -- O'Reilly owe me a book for the November hackfest and I'm wondering whether I should ask for a rain check until the RSpec tome arrives. Come on guys, it's Christmas! :-) Cheers, -Tom From dchelimsky at gmail.com Fri Dec 14 06:42:32 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 14 Dec 2007 05:42:32 -0600 Subject: [rspec-users] RSpec book In-Reply-To: <9AA06BB1-7E31-4C92-85DA-BE9FF5CA1207@experthuman.com> References: <408fb8d24db6dbcec6e30f8542f0ea22@ruby-forum.com> <9AA06BB1-7E31-4C92-85DA-BE9FF5CA1207@experthuman.com> Message-ID: <57c63afe0712140342m4022db1bi87ab7ed8df7437ae@mail.gmail.com> On Dec 14, 2007 2:35 AM, Tom Stuart wrote: > On 14 Dec 2007, at 06:36, Chris Olsen wrote: > > BTW. Has anyone heard if the pragmatic rspec book is still planned to > > be released this month? > > I second this -- O'Reilly owe me a book for the November hackfest and > I'm wondering whether I should ask for a rain check until the RSpec > tome arrives. > > Come on guys, it's Christmas! :-) We're aiming for beta in January. So far our aim hasn't been that great :). But we're making good progress now. Expect to see some bloggage soon. Cheers, David > > Cheers, > -Tom > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dpdnolan at gmail.com Fri Dec 14 07:51:54 2007 From: dpdnolan at gmail.com (David Nolan) Date: Fri, 14 Dec 2007 12:51:54 +0000 Subject: [rspec-users] Problem running examples with spec_server In-Reply-To: References: <52F70C79-5DE0-4F93-86E7-4D15E2676DAE@gmail.com> Message-ID: OK I am studip. The reason "spec -X" does not output anything is because it does not specify a directory with any examples in it. "spec ./spec -X" works as expected. Cheers, Dave On 13/12/2007, David Nolan wrote: > > Hello, > It doesn't output any error messages. It doesn't output anything, not a > sausage, and just returns the prompt after a brief pause. > Thanks, > Dave > > > On 13/12/2007, Michael Klishin wrote: > > > > What error do you get? > > > > On 12 ???. 2007, at 19:39, David Nolan wrote: > > > > > Hello, > > > Running RSpec without DRB works fine. > > > However, "spec -X" runs without error but provides no output at all, > > > even though the DRB spec_server seems to be fine. > > > Has anyone got some suggestions as to why and how to fix? > > > > MK > > _______________________________________________ > > 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/20071214/d9fddcd2/attachment.html From rick.denatale at gmail.com Fri Dec 14 08:15:25 2007 From: rick.denatale at gmail.com (Rick DeNatale) Date: Fri, 14 Dec 2007 08:15:25 -0500 Subject: [rspec-users] [ANN] RSpec-1.1.0 is released In-Reply-To: <57c63afe0712132158p5ccc906v9a90c90c227be3e1@mail.gmail.com> References: <57c63afe0712132158p5ccc906v9a90c90c227be3e1@mail.gmail.com> Message-ID: On 12/14/07, David Chelimsky wrote: > The RSpec Development Team is pleased as glug (that's kind of like > punch, but more festive) to announce RSpec-1.1.0. Now I'm hoping that for those of us who have the two rspec plugins installed as svn externals in a Rails 2.0.1 project the upgrade path is just svn up. Unfortunately when I try this right now I get: $ svn up Fetching external item into 'vendor/plugins/rspec' svn: Connection closed unexpectedly I am pretty up to date (I think 10 revisions back, yesterday morning.) $ svn info vendor/plugins/rspec Path: vendor/plugins/rspec URL: svn://rubyforge.org/var/svn/rspec/trunk/rspec Repository Root: svn://rubyforge.org/var/svn/rspec Repository UUID: 410327ef-2207-0410-a325-f78bbcb22a5a Revision: 3146 Node Kind: directory Schedule: normal Last Changed Author: dchelimsky Last Changed Rev: 3146 Last Changed Date: 2007-12-13 09:24:54 -0500 (Thu, 13 Dec 2007) $ svn info vendor/plugins/rspec rspec rspec_on_rails shadowfax:~/ssanta rick$ svn info vendor/plugins/rspec_on_rails/ Path: vendor/plugins/rspec_on_rails URL: svn://rubyforge.org/var/svn/rspec/trunk/rspec_on_rails Repository Root: svn://rubyforge.org/var/svn/rspec Repository UUID: 410327ef-2207-0410-a325-f78bbcb22a5a Revision: 3146 Node Kind: directory Schedule: normal Last Changed Author: dchelimsky Last Changed Rev: 3146 Last Changed Date: 2007-12-13 09:24:54 -0500 (Thu, 13 Dec 2007) -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From rick.denatale at gmail.com Fri Dec 14 08:18:38 2007 From: rick.denatale at gmail.com (Rick DeNatale) Date: Fri, 14 Dec 2007 08:18:38 -0500 Subject: [rspec-users] [ANN] RSpec-1.1.0 is released In-Reply-To: <57c63afe0712132158p5ccc906v9a90c90c227be3e1@mail.gmail.com> References: <57c63afe0712132158p5ccc906v9a90c90c227be3e1@mail.gmail.com> Message-ID: Another question. Will http://rspec.rubyforge.org/ be updated or is there already an official source for updated docs? -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From dchelimsky at gmail.com Fri Dec 14 08:20:15 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 14 Dec 2007 07:20:15 -0600 Subject: [rspec-users] [ANN] RSpec-1.1.0 is released In-Reply-To: References: <57c63afe0712132158p5ccc906v9a90c90c227be3e1@mail.gmail.com> Message-ID: <57c63afe0712140520r61e432f0qafdee4a004349d6e@mail.gmail.com> On Dec 14, 2007 7:18 AM, Rick DeNatale wrote: > Another question. > > Will http://rspec.rubyforge.org/ be updated or is there already an > official source for updated docs? We've had numerous permissions problems uploading the new docs over the last couple of years. It's been a while since it's been a problem, but something changed and I was once again unable to update the docs. I'm working on it and will follow up when they are posted. > > > -- > Rick DeNatale > > My blog on Ruby > http://talklikeaduck.denhaven2.com/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From erik at ruby-lang.nl Fri Dec 14 07:52:51 2007 From: erik at ruby-lang.nl (Erik Terpstra) Date: Fri, 14 Dec 2007 13:52:51 +0100 Subject: [rspec-users] Vim integration. Message-ID: <47627CA3.5010804@ruby-lang.nl> Hi, Does anybody have a vim script that enables me to run specs from within vim and have the cursor positioned on the right line in case of a backtrace? TIA, Erik. From dchelimsky at gmail.com Fri Dec 14 08:23:43 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 14 Dec 2007 07:23:43 -0600 Subject: [rspec-users] [ANN] RSpec-1.1.0 is released In-Reply-To: References: <57c63afe0712132158p5ccc906v9a90c90c227be3e1@mail.gmail.com> Message-ID: <57c63afe0712140523x772972c3g2d864eea6364923c@mail.gmail.com> On Dec 14, 2007 7:15 AM, Rick DeNatale wrote: > On 12/14/07, David Chelimsky wrote: > > The RSpec Development Team is pleased as glug (that's kind of like > > punch, but more festive) to announce RSpec-1.1.0. > > Now I'm hoping that for those of us who have the two rspec plugins > installed as svn externals in a Rails 2.0.1 project the upgrade path > is just svn up. > > Unfortunately when I try this right now I get: > > $ svn up > > Fetching external item into 'vendor/plugins/rspec' > svn: Connection closed unexpectedly > > I am pretty up to date (I think 10 revisions back, yesterday morning.) > > $ svn info vendor/plugins/rspec > Path: vendor/plugins/rspec > URL: svn://rubyforge.org/var/svn/rspec/trunk/rspec I'd switch this to http: Trunk: http://rspec.rubyforge.org/svn/trunk/rspec http://rspec.rubyforge.org/svn/trunk/rspec_on_rails 1.1.0: http://rspec.rubyforge.org/svn/tags/REL_1_1_0/rspec http://rspec.rubyforge.org/svn/tags/REL_1_1_0/rspec_on_rails It's a bit more reliable in my experience. > Repository Root: svn://rubyforge.org/var/svn/rspec > Repository UUID: 410327ef-2207-0410-a325-f78bbcb22a5a > Revision: 3146 > Node Kind: directory > Schedule: normal > Last Changed Author: dchelimsky > Last Changed Rev: 3146 > Last Changed Date: 2007-12-13 09:24:54 -0500 (Thu, 13 Dec 2007) > > $ svn info vendor/plugins/rspec > rspec rspec_on_rails > shadowfax:~/ssanta rick$ svn info vendor/plugins/rspec_on_rails/ > Path: vendor/plugins/rspec_on_rails > URL: svn://rubyforge.org/var/svn/rspec/trunk/rspec_on_rails > Repository Root: svn://rubyforge.org/var/svn/rspec > Repository UUID: 410327ef-2207-0410-a325-f78bbcb22a5a > Revision: 3146 > Node Kind: directory > Schedule: normal > Last Changed Author: dchelimsky > Last Changed Rev: 3146 > Last Changed Date: 2007-12-13 09:24:54 -0500 (Thu, 13 Dec 2007) > -- > Rick DeNatale > > My blog on Ruby > http://talklikeaduck.denhaven2.com/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From rick.denatale at gmail.com Fri Dec 14 08:24:37 2007 From: rick.denatale at gmail.com (Rick DeNatale) Date: Fri, 14 Dec 2007 08:24:37 -0500 Subject: [rspec-users] [ANN] RSpec-1.1.0 is released In-Reply-To: <57c63afe0712140520r61e432f0qafdee4a004349d6e@mail.gmail.com> References: <57c63afe0712132158p5ccc906v9a90c90c227be3e1@mail.gmail.com> <57c63afe0712140520r61e432f0qafdee4a004349d6e@mail.gmail.com> Message-ID: On 12/14/07, David Chelimsky wrote: > On Dec 14, 2007 7:18 AM, Rick DeNatale wrote: > > Another question. > > > > Will http://rspec.rubyforge.org/ be updated or is there already an > > official source for updated docs? > > We've had numerous permissions problems uploading the new docs over > the last couple of years. It's been a while since it's been a problem, > but something changed and I was once again unable to update the docs. > > I'm working on it and will follow up when they are posted. Thanks, Any insight on why on svn up the connection to svn://rubyforge.org/var/svn/rspec is being dropped unexpectedely? -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From rick.denatale at gmail.com Fri Dec 14 08:29:09 2007 From: rick.denatale at gmail.com (Rick DeNatale) Date: Fri, 14 Dec 2007 08:29:09 -0500 Subject: [rspec-users] [ANN] RSpec-1.1.0 is released In-Reply-To: <57c63afe0712140523x772972c3g2d864eea6364923c@mail.gmail.com> References: <57c63afe0712132158p5ccc906v9a90c90c227be3e1@mail.gmail.com> <57c63afe0712140523x772972c3g2d864eea6364923c@mail.gmail.com> Message-ID: On 12/14/07, David Chelimsky wrote: > > I'd switch this to http: > > Trunk: > http://rspec.rubyforge.org/svn/trunk/rspec > http://rspec.rubyforge.org/svn/trunk/rspec_on_rails Hmmmm shadowfax:~/ssanta/vendor/plugins/rspec rick$ svn switch http://rspec.rubyforge.org/svn/trunk/rspec svn: Connection closed unexpectedly k$ svn switch http://rspec.rubyforge.org/svn/trunk/rspec . svn: 'http://rspec.rubyforge.org/svn/trunk/rspec' is not the same repository as 'svn://rubyforge.org/var/svn/rspec' -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From dchelimsky at gmail.com Fri Dec 14 08:36:38 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 14 Dec 2007 07:36:38 -0600 Subject: [rspec-users] [ANN] RSpec-1.1.0 is released In-Reply-To: References: <57c63afe0712132158p5ccc906v9a90c90c227be3e1@mail.gmail.com> <57c63afe0712140523x772972c3g2d864eea6364923c@mail.gmail.com> Message-ID: <57c63afe0712140536t285af593i34c1ccd94717471e@mail.gmail.com> On Dec 14, 2007 7:29 AM, Rick DeNatale wrote: > On 12/14/07, David Chelimsky wrote: > > > > > I'd switch this to http: > > > > Trunk: > > http://rspec.rubyforge.org/svn/trunk/rspec > > http://rspec.rubyforge.org/svn/trunk/rspec_on_rails > > Hmmmm > > shadowfax:~/ssanta/vendor/plugins/rspec rick$ svn switch > http://rspec.rubyforge.org/svn/trunk/rspec > svn: Connection closed unexpectedly > > k$ svn switch http://rspec.rubyforge.org/svn/trunk/rspec . > svn: 'http://rspec.rubyforge.org/svn/trunk/rspec' > is not the same repository as > 'svn://rubyforge.org/var/svn/rspec' Rick - you're going to need to take this to rubyforge. There's not much we can do about it. > > -- > > Rick DeNatale > > My blog on Ruby > http://talklikeaduck.denhaven2.com/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Fri Dec 14 09:12:23 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Fri, 14 Dec 2007 09:12:23 -0500 Subject: [rspec-users] [ANN] RSpec-1.1.0 is released In-Reply-To: References: <57c63afe0712132158p5ccc906v9a90c90c227be3e1@mail.gmail.com> <57c63afe0712140523x772972c3g2d864eea6364923c@mail.gmail.com> Message-ID: <16C9CAC4-C8A1-4ABB-9B3E-BBB96002C2DD@railsnewbie.com> On Dec 14, 2007, at 8:29 AM, Rick DeNatale wrote: > On 12/14/07, David Chelimsky wrote: > >> >> I'd switch this to http: >> >> Trunk: >> http://rspec.rubyforge.org/svn/trunk/rspec >> http://rspec.rubyforge.org/svn/trunk/rspec_on_rails > > Hmmmm > > shadowfax:~/ssanta/vendor/plugins/rspec rick$ svn switch > http://rspec.rubyforge.org/svn/trunk/rspec > svn: Connection closed unexpectedly > > k$ svn switch http://rspec.rubyforge.org/svn/trunk/rspec . > svn: 'http://rspec.rubyforge.org/svn/trunk/rspec' > is not the same repository as > 'svn://rubyforge.org/var/svn/rspec' > Yeah, I used to have this problem all the time. At one point I even set up an SVK mirror for the rspec repository because of this problem. The admins at rubyforge advise using the http repos - and so far, it has caused me no problems. Scott From rick.denatale at gmail.com Fri Dec 14 09:16:09 2007 From: rick.denatale at gmail.com (Rick DeNatale) Date: Fri, 14 Dec 2007 09:16:09 -0500 Subject: [rspec-users] [ANN] RSpec-1.1.0 is released In-Reply-To: <16C9CAC4-C8A1-4ABB-9B3E-BBB96002C2DD@railsnewbie.com> References: <57c63afe0712132158p5ccc906v9a90c90c227be3e1@mail.gmail.com> <57c63afe0712140523x772972c3g2d864eea6364923c@mail.gmail.com> <16C9CAC4-C8A1-4ABB-9B3E-BBB96002C2DD@railsnewbie.com> Message-ID: On 12/14/07, Scott Taylor wrote: > > On Dec 14, 2007, at 8:29 AM, Rick DeNatale wrote: > > shadowfax:~/ssanta/vendor/plugins/rspec rick$ svn switch > > http://rspec.rubyforge.org/svn/trunk/rspec > > svn: Connection closed unexpectedly > > > > k$ svn switch http://rspec.rubyforge.org/svn/trunk/rspec . > > svn: 'http://rspec.rubyforge.org/svn/trunk/rspec' > > is not the same repository as > > 'svn://rubyforge.org/var/svn/rspec' > > > > Yeah, I used to have this problem all the time. At one point I even > set up an SVK mirror for the rspec repository because of this problem. > > The admins at rubyforge advise using the http repos - and so far, it > has caused me no problems. Well all I need to do is figure out how to get the switch to work. In the meantime, I opened a ticket on the Rubyforge support project. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From dchelimsky at gmail.com Fri Dec 14 10:05:01 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 14 Dec 2007 09:05:01 -0600 Subject: [rspec-users] new home for the rspec website Message-ID: <57c63afe0712140705g308b2c64sfa2633a1c54dc5ec@mail.gmail.com> Hi all, We've moved the rspec website to http://rspec.info. We want http://rspec.org, of course, but someone is squatting on and has yet to respond to my email :( The 1.1.0 docs are there. The 1.0.8 docs are still at http://rspec.rubyforge.org for the time being. We'll be archiving them at the new site soon. This new site is hosted on our shiny new sponsored slice at Engine Yard, which will soon be the host for our source repository as well. Speaking of the new source repo, we got a lot of feedback pushing towards using git over hg, but we have some reasons that we might prefer hg. So here's what we're going to do. We're going to work in one for a month, and then the other, and then make a decision. I'll follow up as to which we're using first and how to access the repo. Either way, we'll continue to push changes over to the svn repo at rubyforge, so if you don't want to participate in our experiment you don't have to - though we will be asking patch contributors to so that we can really get a feel for what it's like to deal with patches, updates, etc with both tools. Cheers, David From rick.denatale at gmail.com Fri Dec 14 10:12:17 2007 From: rick.denatale at gmail.com (Rick DeNatale) Date: Fri, 14 Dec 2007 10:12:17 -0500 Subject: [rspec-users] new home for the rspec website In-Reply-To: <57c63afe0712140705g308b2c64sfa2633a1c54dc5ec@mail.gmail.com> References: <57c63afe0712140705g308b2c64sfa2633a1c54dc5ec@mail.gmail.com> Message-ID: On 12/14/07, David Chelimsky wrote: > Hi all, > > We've moved the rspec website to http://rspec.info. We want > http://rspec.org, of course, but someone is squatting on and has yet > to respond to my email :( > > The 1.1.0 docs are there. Cool. You might want to change the upgrade instructions page to use the http instead of svn urls. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From cody at skidmore.us Fri Dec 14 10:16:15 2007 From: cody at skidmore.us (Cody P. Skidmore) Date: Fri, 14 Dec 2007 07:16:15 -0800 (PST) Subject: [rspec-users] new home for the rspec website In-Reply-To: <57c63afe0712140705g308b2c64sfa2633a1c54dc5ec@mail.gmail.com> References: <57c63afe0712140705g308b2c64sfa2633a1c54dc5ec@mail.gmail.com> Message-ID: <53859.216.167.174.66.1197645375.squirrel@webmail.skidmore.us> David Chelimsky wrote: > We've moved the rspec website to http://rspec.info. We want > http://rspec.org, of course, but someone is squatting on and has yet > to respond to my email :( Squatters make getting a decent domain name nearly impossible these days. When searching for a .com, I'm almost excited to violence. Sorry for the digression. With Regards, // Signed // Cody P. Skidmore From dchelimsky at gmail.com Fri Dec 14 10:26:09 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 14 Dec 2007 09:26:09 -0600 Subject: [rspec-users] new home for the rspec website In-Reply-To: References: <57c63afe0712140705g308b2c64sfa2633a1c54dc5ec@mail.gmail.com> Message-ID: <57c63afe0712140726u4499497je14929a05e2f991a@mail.gmail.com> On Dec 14, 2007 9:12 AM, Rick DeNatale wrote: > On 12/14/07, David Chelimsky wrote: > > Hi all, > > > > We've moved the rspec website to http://rspec.info. We want > > http://rspec.org, of course, but someone is squatting on and has yet > > to respond to my email :( > > > > The 1.1.0 docs are there. > > Cool. > > You might want to change the upgrade instructions page to use the http > instead of svn urls. Done. Thanks. > > -- > Rick DeNatale > > My blog on Ruby > http://talklikeaduck.denhaven2.com/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From loop at superinfinite.com Fri Dec 14 10:28:37 2007 From: loop at superinfinite.com (Bart Zonneveld) Date: Fri, 14 Dec 2007 16:28:37 +0100 Subject: [rspec-users] new home for the rspec website In-Reply-To: <57c63afe0712140705g308b2c64sfa2633a1c54dc5ec@mail.gmail.com> References: <57c63afe0712140705g308b2c64sfa2633a1c54dc5ec@mail.gmail.com> Message-ID: <4C34A987-14BE-4E2B-BB59-22F7D88F2306@superinfinite.com> On 14 dec 2007, at 16:05, David Chelimsky wrote: > Hi all, > > The 1.1.0 docs are there. The 1.0.8 docs are still at > http://rspec.rubyforge.org for the time being. We'll be archiving them > at the new site soon. Sweet! Any idea when the docs for the plain text Stories are online? I'm struggling with something like When I POST to /posts with :name => "Post Title", :body => "Body" at the moment. cheers, bartz From mailing_lists at railsnewbie.com Fri Dec 14 10:55:32 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Fri, 14 Dec 2007 10:55:32 -0500 Subject: [rspec-users] new home for the rspec website In-Reply-To: <57c63afe0712140705g308b2c64sfa2633a1c54dc5ec@mail.gmail.com> References: <57c63afe0712140705g308b2c64sfa2633a1c54dc5ec@mail.gmail.com> Message-ID: On Dec 14, 2007, at 10:05 AM, David Chelimsky wrote: > Hi all, > > We've moved the rspec website to http://rspec.info. We want > http://rspec.org, of course, but someone is squatting on and has yet > to respond to my email :( > So now will you update the site more frequently than before? I remember you had some problems with rubyforge, and would only update the site after every release. Scott From dchelimsky at gmail.com Fri Dec 14 10:58:18 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 14 Dec 2007 09:58:18 -0600 Subject: [rspec-users] new home for the rspec website In-Reply-To: References: <57c63afe0712140705g308b2c64sfa2633a1c54dc5ec@mail.gmail.com> Message-ID: <57c63afe0712140758w516d91ecg6099fdebaa2dae3c@mail.gmail.com> On Dec 14, 2007 9:55 AM, Scott Taylor wrote: > > On Dec 14, 2007, at 10:05 AM, David Chelimsky wrote: > > > Hi all, > > > > We've moved the rspec website to http://rspec.info. We want > > http://rspec.org, of course, but someone is squatting on and has yet > > to respond to my email :( > > > > So now will you update the site more frequently than before? I > remember you had some problems with rubyforge, and would only update > the site after every release. We'll update clarifications and bug fixes, yes. We're also going to be setting up CI, and once we do we'll include a build of the docs so there will be a place where you can see the docs updated trunk too. But all this in time :) > > Scott > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Fri Dec 14 10:59:47 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 14 Dec 2007 09:59:47 -0600 Subject: [rspec-users] new home for the rspec website In-Reply-To: <4C34A987-14BE-4E2B-BB59-22F7D88F2306@superinfinite.com> References: <57c63afe0712140705g308b2c64sfa2633a1c54dc5ec@mail.gmail.com> <4C34A987-14BE-4E2B-BB59-22F7D88F2306@superinfinite.com> Message-ID: <57c63afe0712140759u4c975eeet1827113e3af1a44a@mail.gmail.com> On Dec 14, 2007 9:28 AM, Bart Zonneveld wrote: > > On 14 dec 2007, at 16:05, David Chelimsky wrote: > > > Hi all, > > > > The 1.1.0 docs are there. The 1.0.8 docs are still at > > http://rspec.rubyforge.org for the time being. We'll be archiving them > > at the new site soon. > > Sweet! > Any idea when the docs for the plain text Stories are online? > I'm struggling with something like When I POST to /posts with :name => > "Post Title", :body => "Body" at the moment. No idea right now. Priorities :) If anyone wants to start contributing them, however, I'll push 'em to the site. > > cheers, > bartz > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From rick.denatale at gmail.com Fri Dec 14 12:14:54 2007 From: rick.denatale at gmail.com (Rick DeNatale) Date: Fri, 14 Dec 2007 12:14:54 -0500 Subject: [rspec-users] new home for the rspec website In-Reply-To: <57c63afe0712140726u4499497je14929a05e2f991a@mail.gmail.com> References: <57c63afe0712140705g308b2c64sfa2633a1c54dc5ec@mail.gmail.com> <57c63afe0712140726u4499497je14929a05e2f991a@mail.gmail.com> Message-ID: On 12/14/07, David Chelimsky wrote: > On Dec 14, 2007 9:12 AM, Rick DeNatale wrote: > > On 12/14/07, David Chelimsky wrote: > > > Hi all, > > > > > > We've moved the rspec website to http://rspec.info. We want > > > http://rspec.org, of course, but someone is squatting on and has yet > > > to respond to my email :( > > > > > > The 1.1.0 docs are there. > > > > Cool. > > > > You might want to change the upgrade instructions page to use the http > > instead of svn urls. > > Done. Thanks. > I'm having trouble finding any documentation on nested from the description on your blog they look like an alternate/hierarchical way to do what shared groups did before. Am I thinking about them the right way? Also, I know that it might be competition for your upcoming book, but the doc wouldn't be available in a form which was more amenable to producing nice hardcopy, would it? I'd manually massaged the old 1.0.8 version on rubyforge into a pages document, but that was a pain. If not, I'd volunteer to help, if I can scrape up the bandwidth. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From pat.eyler at gmail.com Fri Dec 14 13:14:18 2007 From: pat.eyler at gmail.com (pat eyler) Date: Fri, 14 Dec 2007 11:14:18 -0700 Subject: [rspec-users] RSpec poll Message-ID: <6fd0654b0712141014n1415ccf6of6b6d8617a17b6a7@mail.gmail.com> If anyone's interested in voting, I'm in the last couple of days of a poll about RSpec. If you'd like to toss in your vote (or a comment), I'd appreciate it: http://on-ruby.blogspot.com/2007/12/ruby-dev-tools-survey-results.html -- thanks, -pate ------------------------- Duty makes us do things, Love make us do things well. http://on-ruby.blogspot.com http://on-erlang.blogspot.com http://on-soccer.blogspot.com From pergesu at gmail.com Sat Dec 15 02:17:12 2007 From: pergesu at gmail.com (Pat Maddox) Date: Fri, 14 Dec 2007 23:17:12 -0800 Subject: [rspec-users] Mocks? Really? In-Reply-To: References: <139c56460712060856i6bb410fcl23def3b16c0388b4@mail.gmail.com> <57c63afe0712071840w13e8d2co85a60c00f3caefa9@mail.gmail.com> Message-ID: <810a540e0712142317t5e13f84dt2952986cd0a58a95@mail.gmail.com> On Dec 8, 2007 4:06 AM, Dan North wrote: > I prefer the mantra "mock roles, not objects", in other words, mock things > that have behaviour (services, components, resources, whatever your > preferred term is) rather than stubbing out domain objects themselves. If > you have to mock domain objects it's usually a smell that your domain > implementation is too tightly coupled to some infrastructure. Assuming you could easily write Rails specs using the real domain objects, but not hit the database, would you "never" mock domain objects (where "never" means you deviate only in extraordinary circumstances)? I'm mostly curious in the interaction between controller and model...if you use real models, then changes to the model code could very well lead to failing controller specs, even though the controller's logic is still correct. What is your opinion on isolating tests? Do you try to test each class in complete isolation, mocking its collaborators? When you use interaction-based tests, do you always leave those in place, or do you substitute real objects as you implement them (and if so, do your changes move to a more state-based style)? How do you approach specifying different layers within an app? Do you use real implementations if there are lightweight ones available, or do you mock everything out? I realize that's a ton of questions...I'd be very grateful (and impressed!) if you took the time to answer any of them. Also I'd love to hear input from other people as well. Pat From wdperson at hotmail.com Sun Dec 16 11:15:29 2007 From: wdperson at hotmail.com (Michael Riley) Date: Sun, 16 Dec 2007 11:15:29 -0500 Subject: [rspec-users] rSpec troubles Message-ID: Hello All, I am hoping someone can help me. I am having a nightmare of a time trying to get rSpec to work. It was working at one time, but I tried installing Zentest to get autotest to work with rSpec and it's been downhill ever since. Here are the gems I have installed in my rails app: ZenTest 3.6.1 if it matters (technically this is in my Ruby gems list and not in my vendor directory of my rails app). Rails - version 2.0.1 rSpec on Rails (revision 3166). Fixed one error by finding that you must use the latest version with edge rails. The current error I am getting is: custom_require.rb:27 in 'gem_original_require': no such file to load -- spec/example/configuration (MissingSourceFile) Wouldn't rSpec install all the necessary files or am I missing another gem? thanks for any assistance. Mike Riley _________________________________________________________________ Don't get caught with egg on your face. Play Chicktionary! http://club.live.com/chicktionary.aspx?icid=chick_wlhmtextlink1_dec -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071216/63b8eaf6/attachment.html From dchelimsky at gmail.com Sun Dec 16 11:22:22 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 16 Dec 2007 10:22:22 -0600 Subject: [rspec-users] rSpec troubles In-Reply-To: References: Message-ID: <57c63afe0712160822m32eb2a00i663ee854c00077b9@mail.gmail.com> On Dec 16, 2007 10:15 AM, Michael Riley wrote: > > Hello All, > > I am hoping someone can help me. I am having a nightmare of a time > trying to get rSpec to work. It was working at one time, but I tried > installing Zentest to get autotest to work with rSpec and it's been downhill > ever since. Here are the gems I have installed in my rails app: > > ZenTest 3.6.1 if it matters (technically this is in my Ruby gems list and > not in my vendor directory of my rails app). > Rails - version 2.0.1 > rSpec on Rails (revision 3166). Fixed one error by finding that you must > use the latest version with edge rails. > > The current error I am getting is: > custom_require.rb:27 in 'gem_original_require': no such file to load -- > spec/example/configuration (MissingSourceFile) > > Wouldn't rSpec install all the necessary files or am I missing another gem? Did you follow these installation instructions? http://rspec.info/documentation/rails/install.html You should have the same revision of rspec and rspec_on_rails installed as gems. > > thanks for any assistance. > Mike Riley > > ________________________________ > Don't get caught with egg on your face. Play Chicktionary! Check it out! > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From coreyhaines at gmail.com Sun Dec 16 11:22:43 2007 From: coreyhaines at gmail.com (Corey Haines) Date: Sun, 16 Dec 2007 11:22:43 -0500 Subject: [rspec-users] rSpec troubles In-Reply-To: References: Message-ID: <6bdacb70712160822le230b3hd8cd4e8d1789e78c@mail.gmail.com> Did you install with dependencies? On Dec 16, 2007 11:15 AM, Michael Riley wrote: > > Hello All, > > I am hoping someone can help me. I am having a nightmare of a time > trying to get rSpec to work. It was working at one time, but I tried > installing Zentest to get autotest to work with rSpec and it's been downhill > ever since. Here are the gems I have installed in my rails app: > > ZenTest 3.6.1 if it matters (technically this is in my Ruby gems list and > not in my vendor directory of my rails app). > Rails - version 2.0.1 > rSpec on Rails (revision 3166). Fixed one error by finding that you must > use the latest version with edge rails. > > The current error I am getting is: > custom_require.rb:27 in 'gem_original_require': no such file to load -- > spec/example/configuration (MissingSourceFile) > > Wouldn't rSpec install all the necessary files or am I missing another gem? > > thanks for any assistance. > Mike Riley > > ________________________________ > Don't get caught with egg on your face. Play Chicktionary! Check it out! > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- http://www.coreyhaines.com From sera at fhwang.net Sun Dec 16 11:32:28 2007 From: sera at fhwang.net (Francis Hwang) Date: Sun, 16 Dec 2007 11:32:28 -0500 Subject: [rspec-users] how do I spec my Rails routes? Message-ID: <8FAD3F24-8F4E-4025-B8D0-D5C28AF96833@fhwang.net> Once again, here's something I haven't figured out. Apologies if this is too newb-ish, but, how do I spec my routes using RSpec-Rails? In particular, I've got a catch-all route that needs to catch a wide variety of URLs: map.document '*url', :controller => 'documents', :action => 'show' Is there a way to have a controller spec test site-wide routing? It seems to me that the get and post methods are just controller- specific routing. If I can't do it in a controller spec, where else should I do it? Thanks, Francis Hwang http://fhwang.net/ From dchelimsky at gmail.com Sun Dec 16 11:43:37 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 16 Dec 2007 10:43:37 -0600 Subject: [rspec-users] how do I spec my Rails routes? In-Reply-To: <8FAD3F24-8F4E-4025-B8D0-D5C28AF96833@fhwang.net> References: <8FAD3F24-8F4E-4025-B8D0-D5C28AF96833@fhwang.net> Message-ID: <57c63afe0712160843i7a141544u8d8a93f61a9903e2@mail.gmail.com> On Dec 16, 2007 10:32 AM, Francis Hwang wrote: > Once again, here's something I haven't figured out. Apologies if this > is too newb-ish, but, how do I spec my routes using RSpec-Rails? > > In particular, I've got a catch-all route that needs to catch a wide > variety of URLs: > > map.document '*url', :controller => 'documents', :action => 'show' > > Is there a way to have a controller spec test site-wide routing? It > seems to me that the get and post methods are just controller- > specific routing. If I can't do it in a controller spec, where else > should I do it? Check out route_for and params_from at http://rspec.info/rdoc-rails/. There are examples of their use in the controller examples generated by 'script/generate rspec_scaffold ...'. Here are a couple of examples: http://pastie.caboo.se/129301 Cheers, David > > Thanks, > > Francis Hwang > http://fhwang.net/ > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From wdperson at hotmail.com Sun Dec 16 11:47:13 2007 From: wdperson at hotmail.com (Michael Riley) Date: Sun, 16 Dec 2007 11:47:13 -0500 Subject: [rspec-users] rSpec troubles In-Reply-To: <57c63afe0712160822m32eb2a00i663ee854c00077b9@mail.gmail.com> References: <57c63afe0712160822m32eb2a00i663ee854c00077b9@mail.gmail.com> Message-ID: David, Thanks for the reply. I really appreciate it. You must be updating the site as I was looking at it earlier the title said 1.0.8 and now the title says 1.1.0. I have it running now. So, I am back to my first step which is getting rSpec to work. I ruined it yesterday trying to get autotest to work. I must have had incompatible versions of rSpec and rSpec on Rails. I was under the assumption that the 2 were different. In other words rSpec works for any type of ruby app and rSpec on Rails works is specific to rails (fine tuned to Rails). I see now that they are dependent. What I did was removed the spec directory, the rSpec on Rails and rSpec directories in my vendor folder in my application. Then installed both versions using the instructions under "Living on the edge." Then ran the ruby script/generate rspec command. Then created a rspec_model and ran the ruby script/spec spec command and everything worked great. I appreciate the push in the right direction. I'm going to try and get autotest to work now. thanks. Mike Riley > Date: Sun, 16 Dec 2007 10:22:22 -0600 > From: dchelimsky at gmail.com > To: rspec-users at rubyforge.org > Subject: Re: [rspec-users] rSpec troubles > > On Dec 16, 2007 10:15 AM, Michael Riley wrote: > > > > Hello All, > > > > I am hoping someone can help me. I am having a nightmare of a time > > trying to get rSpec to work. It was working at one time, but I tried > > installing Zentest to get autotest to work with rSpec and it's been downhill > > ever since. Here are the gems I have installed in my rails app: > > > > ZenTest 3.6.1 if it matters (technically this is in my Ruby gems list and > > not in my vendor directory of my rails app). > > Rails - version 2.0.1 > > rSpec on Rails (revision 3166). Fixed one error by finding that you must > > use the latest version with edge rails. > > > > The current error I am getting is: > > custom_require.rb:27 in 'gem_original_require': no such file to load -- > > spec/example/configuration (MissingSourceFile) > > > > Wouldn't rSpec install all the necessary files or am I missing another gem? > > Did you follow these installation instructions? > > http://rspec.info/documentation/rails/install.html > > You should have the same revision of rspec and rspec_on_rails installed as gems. > > > > > thanks for any assistance. > > Mike Riley > > > > ________________________________ > > Don't get caught with egg on your face. Play Chicktionary! Check it out! > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users _________________________________________________________________ i?m is proud to present Cause Effect, a series about real people making a difference. http://im.live.com/Messenger/IM/MTV/?source=text_Cause_Effect -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071216/e8571524/attachment.html From philodespotos at gmail.com Sun Dec 16 15:50:59 2007 From: philodespotos at gmail.com (Kyle Hargraves) Date: Sun, 16 Dec 2007 14:50:59 -0600 Subject: [rspec-users] Fwd: Vim integration. In-Reply-To: <47627CA3.5010804@ruby-lang.nl> References: <47627CA3.5010804@ruby-lang.nl> Message-ID: <60f3810c0712161250w3a6789e7ja35a47a22674e667@mail.gmail.com> On Dec 14, 2007 6:52 AM, Erik Terpstra wrote: > Hi, > > Does anybody have a vim script that enables me to run specs from within > vim and have the cursor positioned on the right line in case of a backtrace? > > TIA, > > Erik. Having finally gone back to vim from textmate (after finding http://code.google.com/p/macvim/), I picked up tpope's rails.vim again, which now has lots of rspec goodness, too. From inside a spec, :Rake will run the spec, and jumps to the proper line in case of failure. :A will move from spec to the implementation (or the reverse), :AS will do it in a new split window, etc. It's very, very nice. Rails.vim only works, of course, within rails projects. And vim internals terrify me, so I don't know how easily his magics could be extracted. But if you're doing rails dev, rails.vim is definitely worth checking out. Refs: http://www.vim.org/scripts/script.php?script_id=1567 - rails.vim http://biodegradablegeek.com/2007/12/13/using-vim-as-a-complete-ruby-on-rails-ide/ - found this when googling for rails.vim, looks useful Kyle From jonathan at parkerhill.com Sun Dec 16 16:23:06 2007 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Sun, 16 Dec 2007 16:23:06 -0500 Subject: [rspec-users] how do I spec my Rails routes? In-Reply-To: <57c63afe0712160843i7a141544u8d8a93f61a9903e2@mail.gmail.com> References: <8FAD3F24-8F4E-4025-B8D0-D5C28AF96833@fhwang.net> <57c63afe0712160843i7a141544u8d8a93f61a9903e2@mail.gmail.com> Message-ID: <91118B9A-4519-47C3-B656-3B4E6A1A5614@parkerhill.com> personally I've broken with convention and put all my route specs into a routes_spec.rb file in part because they're in one file in rails, and when i edit that file I want to make sure other routes didn't break. Your question about a catchall is another reason. I also like to spec named routes, not all the time but especially those outside the rails resources conventions. Although not strictly a "behavior", I'm more comfortable knowing that the named routes work (e.g. logout_path => /logout ) before using them in my code. Unfortunately I found (via trial and error) that you need a response first. This is what I have working (although its hackish): class RoutesController < ApplicationController def foo end end describe FoosController, "named routes" do before do get :foo end it "should route /logout " do logout_path.should == "/logout" route_for(:controller => "sessions", :action => "destroy").should == "/logout" params_from(:get, "/logout").should == {:controller => "sessions", :action => "destroy"} end end --linoj On Dec 16, 2007, at 11:43 AM, David Chelimsky wrote: > On Dec 16, 2007 10:32 AM, Francis Hwang wrote: >> Once again, here's something I haven't figured out. Apologies if this >> is too newb-ish, but, how do I spec my routes using RSpec-Rails? >> >> In particular, I've got a catch-all route that needs to catch a wide >> variety of URLs: >> >> map.document '*url', :controller => 'documents', :action => 'show' >> >> Is there a way to have a controller spec test site-wide routing? It >> seems to me that the get and post methods are just controller- >> specific routing. If I can't do it in a controller spec, where else >> should I do it? > > Check out route_for and params_from at http://rspec.info/rdoc-rails/. > There are examples of their use in the controller examples generated > by 'script/generate rspec_scaffold ...'. Here are a couple of > examples: > > http://pastie.caboo.se/129301 > > Cheers, > David > >> >> Thanks, >> >> Francis Hwang >> http://fhwang.net/ >> >> >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.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 jonathan at parkerhill.com Sun Dec 16 12:03:28 2007 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Sun, 16 Dec 2007 12:03:28 -0500 Subject: [rspec-users] Need help mocking this out In-Reply-To: <2fff50390712030244t25e59b74y176a4876ba8b011e@mail.gmail.com> References: <7e565b5c0712030157s4e56b280l1bcf4621c8c8c7a4@mail.gmail.com> <921ca2f80712030207o7f45771dk15006c3ab5b17ab8@mail.gmail.com> <2fff50390712030244t25e59b74y176a4876ba8b011e@mail.gmail.com> Message-ID: <09A63FFF-BC89-4503-AF02-9C751D929192@parkerhill.com> btw, to answer the same question for member actions (such as show), you can stub or assert the association proxy class @article = current_user.articles.find(params[:id]) then, it "should find article scoped by current_user" do article = mock_model(Article) current_user.should_receive(:articles).and_return(Article) Article.should_receive(:find).and_return(article) get :show, :id => article.id end this will ensure that your controller is not calling Article.find unscoped linoj On Dec 3, 2007, at 5:44 AM, Daniel N wrote: > Assuming that there is a call like this in your controller > > @articles = current_user.articles > > One way to do this is to stub out the controller.current_user to > return a mock object of the current_user > > Then put an expectation on the current user that it's articles > method gets called. (return a mocked collection of articles) > > Then check that @articles is set to the returned mocked collection > of articles from current_user.articles > > phew... > > Ok So one way you might write this could be (This is untested...) > > it "should scope the articles to the currrent_user" do > > user = mock_model(User) > articles = [mock_model(Article)] > > controller.stub!(:current_user).and_return(user) > user.should_receive (:articles).and_return(articles) > > get :index > > assigns[:articles].should == articles > > end > > Like I said though, that's not tested itself. If that's not > exactly right... it's along the right track of an option that can > work. > > HTH > Daniel > > On Dec 3, 2007 9:07 PM, Stefan Magnus Landr? > wrote: > Typically, I'd write a method in your user model that returns the > user's articles: > > class User do > > def find_articles_for_user > Article.find(:all, :conditions => ['userid = ?', id) > end > > end > > Then you'd use a mock in your controller spec, and make sure you > test that your method is being called. > > On the other hand, the user model should be tested directly against > the db. > > HTH, > > Stefan > > 2007/12/3, Fischer, Daniel : > Let's say you're using the restful_authentication plugin. > > You have a model called articles. On the index action of the > articlescontroller you simply want to spec out that it'll scope the > results to the ownership of the current_user. > > It should NOT include any articles other than the articles that > user owns. > > How would you properly spec this out? > > Thanks for the help! > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > > > -- > Bekk Open Source > http://boss.bekk.no > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.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/20071216/157a15e3/attachment.html From dchelimsky at gmail.com Sun Dec 16 16:29:53 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 16 Dec 2007 15:29:53 -0600 Subject: [rspec-users] how do I spec my Rails routes? In-Reply-To: <91118B9A-4519-47C3-B656-3B4E6A1A5614@parkerhill.com> References: <8FAD3F24-8F4E-4025-B8D0-D5C28AF96833@fhwang.net> <57c63afe0712160843i7a141544u8d8a93f61a9903e2@mail.gmail.com> <91118B9A-4519-47C3-B656-3B4E6A1A5614@parkerhill.com> Message-ID: <57c63afe0712161329o4e7888b1ue07c76918f82a1f4@mail.gmail.com> On Dec 16, 2007 3:23 PM, Jonathan Linowes wrote: > personally I've broken with convention and put all my route specs > into a routes_spec.rb file 1.1 broke with that same convention! But slightly differently. The rspec_scaffold generator generates a controller spec and a routing spec for each controller you create. > in part because they're in one file in rails, and when i edit that > file I want to make sure other routes didn't break. > Your question about a catchall is another reason. > > I also like to spec named routes, not all the time but especially > those outside the rails resources conventions. Although not strictly > a "behavior", I'm more comfortable knowing that the named routes work > (e.g. logout_path => /logout ) before using them in my code. > Unfortunately I found (via trial and error) that you need a response > first. This is what I have working (although its hackish): > > class RoutesController < ApplicationController > def foo > end > end > > describe FoosController, "named routes" do > before do > get :foo > end > > it "should route /logout " do > logout_path.should == "/logout" > route_for(:controller => "sessions", :action => > "destroy").should == "/logout" > params_from(:get, "/logout").should == {:controller => > "sessions", :action => "destroy"} > end > > end What would you like to see in rspec to manage this for you? How about a feature request in the tracker? > > > --linoj > > > > On Dec 16, 2007, at 11:43 AM, David Chelimsky wrote: > > > On Dec 16, 2007 10:32 AM, Francis Hwang wrote: > >> Once again, here's something I haven't figured out. Apologies if this > >> is too newb-ish, but, how do I spec my routes using RSpec-Rails? > >> > >> In particular, I've got a catch-all route that needs to catch a wide > >> variety of URLs: > >> > >> map.document '*url', :controller => 'documents', :action => 'show' > >> > >> Is there a way to have a controller spec test site-wide routing? It > >> seems to me that the get and post methods are just controller- > >> specific routing. If I can't do it in a controller spec, where else > >> should I do it? > > > > Check out route_for and params_from at http://rspec.info/rdoc-rails/. > > There are examples of their use in the controller examples generated > > by 'script/generate rspec_scaffold ...'. Here are a couple of > > examples: > > > > http://pastie.caboo.se/129301 > > > > Cheers, > > David > > > >> > >> Thanks, > >> > >> Francis Hwang > >> http://fhwang.net/ > >> > >> > >> > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-users at rubyforge.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 omen.king at gmail.com Sun Dec 16 16:37:35 2007 From: omen.king at gmail.com (Andrew WC Brown) Date: Sun, 16 Dec 2007 16:37:35 -0500 Subject: [rspec-users] RSpec book In-Reply-To: <57c63afe0712140342m4022db1bi87ab7ed8df7437ae@mail.gmail.com> References: <408fb8d24db6dbcec6e30f8542f0ea22@ruby-forum.com> <9AA06BB1-7E31-4C92-85DA-BE9FF5CA1207@experthuman.com> <57c63afe0712140342m4022db1bi87ab7ed8df7437ae@mail.gmail.com> Message-ID: I want to see a TOC. On Dec 14, 2007 6:42 AM, David Chelimsky wrote: > On Dec 14, 2007 2:35 AM, Tom Stuart wrote: > > On 14 Dec 2007, at 06:36, Chris Olsen wrote: > > > BTW. Has anyone heard if the pragmatic rspec book is still planned to > > > be released this month? > > > > I second this -- O'Reilly owe me a book for the November hackfest and > > I'm wondering whether I should ask for a rain check until the RSpec > > tome arrives. > > > > Come on guys, it's Christmas! :-) > > We're aiming for beta in January. So far our aim hasn't been that > great :). But we're making good progress now. Expect to see some > bloggage soon. > > Cheers, > David > > > > > > Cheers, > > -Tom > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071216/6a8ec97c/attachment.html From dchelimsky at gmail.com Sun Dec 16 16:43:42 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 16 Dec 2007 15:43:42 -0600 Subject: [rspec-users] Need help mocking this out In-Reply-To: <09A63FFF-BC89-4503-AF02-9C751D929192@parkerhill.com> References: <7e565b5c0712030157s4e56b280l1bcf4621c8c8c7a4@mail.gmail.com> <921ca2f80712030207o7f45771dk15006c3ab5b17ab8@mail.gmail.com> <2fff50390712030244t25e59b74y176a4876ba8b011e@mail.gmail.com> <09A63FFF-BC89-4503-AF02-9C751D929192@parkerhill.com> Message-ID: <57c63afe0712161343x42c05b4ex4344f8dcb44415f4@mail.gmail.com> On Dec 16, 2007 11:03 AM, Jonathan Linowes wrote: > > btw, to answer the same question for member actions (such as show), you can > stub or assert the association proxy class > > @article = current_user.articles.find(params[:id]) > > then, > > it "should find article scoped by current_user" do > article = mock_model(Article) > current_user.should_receive(:articles).and_return(Article) > Article.should_receive(:find).and_return(article) > get :show, :id => article.id > end > > this will ensure that your controller is not calling Article.find unscoped I tend to take this one more step. I'm a bit of a demeter zealot, and I'm also usually writing the examples from the code first. So I'd do something like: it "should find the current users articles" do article = mock_model(Article) current_user.should_receive(:find_article).with("1").and_return(Article) get :show, :id => "1" end This would lead me to add a find_article method to User: describe User do it "should find it's own articles" do user = User.new user.articles.should_receive(:find).with("1") user.find_article("1) end end This has two benefits: - each example is simpler and focuses on one object and how it behaves - I can change the relationship between a User and it's Articles without changing the controller code. FWIW, David > > linoj > > > > > On Dec 3, 2007, at 5:44 AM, Daniel N wrote: > Assuming that there is a call like this in your controller > > @articles = current_user.articles > > One way to do this is to stub out the controller.current_user to return a > mock object of the current_user > > Then put an expectation on the current user that it's articles method gets > called. (return a mocked collection of articles) > > Then check that @articles is set to the returned mocked collection of > articles from current_user.articles > > phew... > > Ok So one way you might write this could be (This is untested...) > > it "should scope the articles to the currrent_user" do > > user = mock_model(User) > articles = [mock_model(Article)] > > controller.stub!(:current_user).and_return(user) > user.should_receive (:articles).and_return(articles) > > get :index > > assigns[:articles].should == articles > > end > > > Like I said though, that's not tested itself. If that's not exactly > right... it's along the right track of an option that can work. > > HTH > Daniel > > On Dec 3, 2007 9:07 PM, Stefan Magnus Landr? > wrote: > > Typically, I'd write a method in your user model that returns the user's > articles: > > > > class User do > > > > def find_articles_for_user > > Article.find(:all, :conditions => ['userid = ?', id) > > end > > > > end > > > > Then you'd use a mock in your controller spec, and make sure you test that > your method is being called. > > > > On the other hand, the user model should be tested directly against the > db. > > > > HTH, > > > > Stefan > > > > > > 2007/12/3, Fischer, Daniel : > > > > > > > > > > > > Let's say you're using the restful_authentication plugin. > > > > > > > > > You have a model called articles. On the index action of the > articlescontroller you simply want to spec out that it'll scope the results > to the ownership of the current_user. > > > > > > > > > It should NOT include any articles other than the articles that user > owns. > > > > > > > > > How would you properly spec this out? > > > > > > > > > Thanks for the help! > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > -- > > Bekk Open Source > > http://boss.bekk.no > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.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 Sun Dec 16 16:44:11 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 16 Dec 2007 15:44:11 -0600 Subject: [rspec-users] RSpec book In-Reply-To: References: <408fb8d24db6dbcec6e30f8542f0ea22@ruby-forum.com> <9AA06BB1-7E31-4C92-85DA-BE9FF5CA1207@experthuman.com> <57c63afe0712140342m4022db1bi87ab7ed8df7437ae@mail.gmail.com> Message-ID: <57c63afe0712161344o4586bb5bu81281132b9543887@mail.gmail.com> On Dec 16, 2007 3:37 PM, Andrew WC Brown wrote: > I want to see a TOC. Me too :) > > > > On Dec 14, 2007 6:42 AM, David Chelimsky wrote: > > > > On Dec 14, 2007 2:35 AM, Tom Stuart wrote: > > > On 14 Dec 2007, at 06:36, Chris Olsen wrote: > > > > BTW. Has anyone heard if the pragmatic rspec book is still planned to > > > > be released this month? > > > > > > I second this -- O'Reilly owe me a book for the November hackfest and > > > I'm wondering whether I should ask for a rain check until the RSpec > > > tome arrives. > > > > > > Come on guys, it's Christmas! :-) > > > > We're aiming for beta in January. So far our aim hasn't been that > > great :). But we're making good progress now. Expect to see some > > bloggage soon. > > > > Cheers, > > David > > > > > > > > > > > > > > > > Cheers, > > > -Tom > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From has.sox at gmail.com Sun Dec 16 17:01:44 2007 From: has.sox at gmail.com (Daniel N) Date: Mon, 17 Dec 2007 09:01:44 +1100 Subject: [rspec-users] Need help mocking this out In-Reply-To: <57c63afe0712161343x42c05b4ex4344f8dcb44415f4@mail.gmail.com> References: <7e565b5c0712030157s4e56b280l1bcf4621c8c8c7a4@mail.gmail.com> <921ca2f80712030207o7f45771dk15006c3ab5b17ab8@mail.gmail.com> <2fff50390712030244t25e59b74y176a4876ba8b011e@mail.gmail.com> <09A63FFF-BC89-4503-AF02-9C751D929192@parkerhill.com> <57c63afe0712161343x42c05b4ex4344f8dcb44415f4@mail.gmail.com> Message-ID: <2fff50390712161401l76aee54asf4e391ae44e3c2cb@mail.gmail.com> On Dec 17, 2007 8:43 AM, David Chelimsky wrote: > On Dec 16, 2007 11:03 AM, Jonathan Linowes > wrote: > > > > btw, to answer the same question for member actions (such as show), you > can > > stub or assert the association proxy class > > > > @article = current_user.articles.find(params[:id]) > > > > then, > > > > it "should find article scoped by current_user" do > > article = mock_model(Article) > > current_user.should_receive(:articles).and_return(Article) > > Article.should_receive(:find).and_return(article) > > get :show, :id => article.id > > end > > > > this will ensure that your controller is not calling Article.findunscoped > > I tend to take this one more step. I'm a bit of a demeter zealot, and > I'm also usually writing the examples from the code first. So I'd do > something like: > > it "should find the current users articles" do > article = mock_model(Article) > current_user.should_receive(:find_article).with("1").and_return(Article) > get :show, :id => "1" > end Where is current_user defined here? I've always stubbed current_user on the controller object. How are you doing this one? > > > This would lead me to add a find_article method to User: > > describe User do > it "should find it's own articles" do > user = User.new > user.articles.should_receive(:find).with("1") > user.find_article("1) > end > end > > This has two benefits: > - each example is simpler and focuses on one object and how it behaves > - I can change the relationship between a User and it's Articles > without changing the controller code. > > FWIW, > David > > > > > > linoj > > > > > > > > > > On Dec 3, 2007, at 5:44 AM, Daniel N wrote: > > Assuming that there is a call like this in your controller > > > > @articles = current_user.articles > > > > One way to do this is to stub out the controller.current_user to return > a > > mock object of the current_user > > > > Then put an expectation on the current user that it's articles method > gets > > called. (return a mocked collection of articles) > > > > Then check that @articles is set to the returned mocked collection of > > articles from current_user.articles > > > > phew... > > > > Ok So one way you might write this could be (This is untested...) > > > > it "should scope the articles to the currrent_user" do > > > > user = mock_model(User) > > articles = [mock_model(Article)] > > > > controller.stub!(:current_user).and_return(user) > > user.should_receive (:articles).and_return(articles) > > > > get :index > > > > assigns[:articles].should == articles > > > > end > > > > > > Like I said though, that's not tested itself. If that's not exactly > > right... it's along the right track of an option that can work. > > > > HTH > > Daniel > > > > On Dec 3, 2007 9:07 PM, Stefan Magnus Landr? > > wrote: > > > Typically, I'd write a method in your user model that returns the > user's > > articles: > > > > > > class User do > > > > > > def find_articles_for_user > > > Article.find(:all, :conditions => ['userid = ?', id) > > > end > > > > > > end > > > > > > Then you'd use a mock in your controller spec, and make sure you test > that > > your method is being called. > > > > > > On the other hand, the user model should be tested directly against > the > > db. > > > > > > HTH, > > > > > > Stefan > > > > > > > > > 2007/12/3, Fischer, Daniel : > > > > > > > > > > > > > > > > Let's say you're using the restful_authentication plugin. > > > > > > > > > > > > You have a model called articles. On the index action of the > > articlescontroller you simply want to spec out that it'll scope the > results > > to the ownership of the current_user. > > > > > > > > > > > > It should NOT include any articles other than the articles that user > > owns. > > > > > > > > > > > > How would you properly spec this out? > > > > > > > > > > > > Thanks for the help! > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > -- > > > Bekk Open Source > > > http://boss.bekk.no > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.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/20071217/0b590545/attachment.html From dchelimsky at gmail.com Sun Dec 16 17:06:02 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 16 Dec 2007 16:06:02 -0600 Subject: [rspec-users] Need help mocking this out In-Reply-To: <2fff50390712161401l76aee54asf4e391ae44e3c2cb@mail.gmail.com> References: <7e565b5c0712030157s4e56b280l1bcf4621c8c8c7a4@mail.gmail.com> <921ca2f80712030207o7f45771dk15006c3ab5b17ab8@mail.gmail.com> <2fff50390712030244t25e59b74y176a4876ba8b011e@mail.gmail.com> <09A63FFF-BC89-4503-AF02-9C751D929192@parkerhill.com> <57c63afe0712161343x42c05b4ex4344f8dcb44415f4@mail.gmail.com> <2fff50390712161401l76aee54asf4e391ae44e3c2cb@mail.gmail.com> Message-ID: <57c63afe0712161406t49c4d875te5784947ec9390eb@mail.gmail.com> On Dec 16, 2007 4:01 PM, Daniel N wrote: > > > > On Dec 17, 2007 8:43 AM, David Chelimsky wrote: > > > > On Dec 16, 2007 11:03 AM, Jonathan Linowes > wrote: > > > > > > btw, to answer the same question for member actions (such as show), you > can > > > stub or assert the association proxy class > > > > > > @article = current_user.articles.find(params[:id]) > > > > > > then, > > > > > > it "should find article scoped by current_user" do > > > article = mock_model(Article) > > > current_user.should_receive(:articles).and_return(Article) > > > Article.should_receive(:find).and_return(article) > > > get :show, :id => article.id > > > end > > > > > > this will ensure that your controller is not calling Article.find > unscoped > > > > I tend to take this one more step. I'm a bit of a demeter zealot, and > > I'm also usually writing the examples from the code first. So I'd do > > something like: > > > > it "should find the current users articles" do > > article = mock_model(Article) > > current_user.should_receive(:find_article).with("1").and_return(Article) > > get :show, :id => "1" > > end > > Where is current_user defined here? I've always stubbed current_user on the > controller object. How are you doing this one? Well that was just an example, not taken from any real code. You could either get it from the controller in the example: controller.current_user.should_receive(:find_article) or create a helper method to get at it. > > > > > > > > > This would lead me to add a find_article method to User: > > > > describe User do > > it "should find it's own articles" do > > user = User.new > > user.articles.should_receive(:find).with("1") > > user.find_article("1) > > end > > end > > > > This has two benefits: > > - each example is simpler and focuses on one object and how it behaves > > - I can change the relationship between a User and it's Articles > > without changing the controller code. > > > > FWIW, > > David > > > > > > > > > > > > > > > > linoj > > > > > > > > > > > > > > > On Dec 3, 2007, at 5:44 AM, Daniel N wrote: > > > Assuming that there is a call like this in your controller > > > > > > @articles = current_user.articles > > > > > > One way to do this is to stub out the controller.current_user to return > a > > > mock object of the current_user > > > > > > Then put an expectation on the current user that it's articles method > gets > > > called. (return a mocked collection of articles) > > > > > > Then check that @articles is set to the returned mocked collection of > > > articles from current_user.articles > > > > > > phew... > > > > > > Ok So one way you might write this could be (This is untested...) > > > > > > it "should scope the articles to the currrent_user" do > > > > > > user = mock_model(User) > > > articles = [mock_model(Article)] > > > > > > controller.stub!(:current_user).and_return(user) > > > user.should_receive (:articles).and_return(articles) > > > > > > get :index > > > > > > assigns[:articles].should == articles > > > > > > end > > > > > > > > > Like I said though, that's not tested itself. If that's not exactly > > > right... it's along the right track of an option that can work. > > > > > > HTH > > > Daniel > > > > > > On Dec 3, 2007 9:07 PM, Stefan Magnus Landr? > > > wrote: > > > > Typically, I'd write a method in your user model that returns the > user's > > > articles: > > > > > > > > class User do > > > > > > > > def find_articles_for_user > > > > Article.find(:all, :conditions => ['userid = ?', id) > > > > end > > > > > > > > end > > > > > > > > Then you'd use a mock in your controller spec, and make sure you test > that > > > your method is being called. > > > > > > > > On the other hand, the user model should be tested directly against > the > > > db. > > > > > > > > HTH, > > > > > > > > Stefan > > > > > > > > > > > > 2007/12/3, Fischer, Daniel : > > > > > > > > > > > > > > > > > > > > Let's say you're using the restful_authentication plugin. > > > > > > > > > > > > > > > You have a model called articles. On the index action of the > > > articlescontroller you simply want to spec out that it'll scope the > results > > > to the ownership of the current_user. > > > > > > > > > > > > > > > It should NOT include any articles other than the articles that user > > > owns. > > > > > > > > > > > > > > > How would you properly spec this out? > > > > > > > > > > > > > > > Thanks for the help! > > > > > _______________________________________________ > > > > > rspec-users mailing list > > > > > rspec-users at rubyforge.org > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > > > > > > -- > > > > Bekk Open Source > > > > http://boss.bekk.no > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.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 tastapod at gmail.com Sun Dec 16 17:59:04 2007 From: tastapod at gmail.com (Dan North) Date: Sun, 16 Dec 2007 22:59:04 +0000 Subject: [rspec-users] Mocks? Really? In-Reply-To: <810a540e0712142317t5e13f84dt2952986cd0a58a95@mail.gmail.com> References: <139c56460712060856i6bb410fcl23def3b16c0388b4@mail.gmail.com> <57c63afe0712071840w13e8d2co85a60c00f3caefa9@mail.gmail.com> <810a540e0712142317t5e13f84dt2952986cd0a58a95@mail.gmail.com> Message-ID: Pat. I'm going to reply by promising to reply. You've asked a ton of really useful and insightful questions. I can't do them justice without sitting down and spending a bunch of time thinking about them. I'm going to be off the radar for a bit over Christmas - I've had an insane year and I've promised myself (and my wife) some quiet time. Your questions have a little star next to them in my gmail inbox, which means at the very least they'll be ignored less than the other mail I have to respond to :) The one sentence response, though, is that I honestly don't know (which is why I need to think about it). I can tell you I *think* I isolate services from their dependencies using mocks, I *think* I never stub domain objects (I definitely never mock them, but stubbing them is different), I can't say how I test layers because I think we have a different definition of layers. The reason I'm being being so vague is that I usually specify behaviour from the outside in, starting with the "outermost" objects (the ones that appear in the scenario steps) and working inwards as I implement each bit of behaviour. That way I discover service dependencies that I introduce as mocks, and other domain objects that become, well, domain objects. Then there are other little classes that fall out of the mix that seem to make sense as I go along. I don't usually start out with much more of a strategy than that. I can't speak as a tester because I'm not one, so I can't really give you a sensible answer for how isolated my tests are. I simply don't have tests at that level. At an acceptance level my scenarios only ever use real objects wired together doing full end-to-end testing. Sometimes I'll swap in a lighter-weight implementation (say using an in-memory database rather than a remote one, or an in-thread Java web container like Jetty rather than firing up Tomcat), but all the wiring is still the same (say JDBC or HTTP-over-the-wire). I'm still not entirely sure how this maps to Rails, but in Java MVC web apps I would *want* the controller examples failing if the model's behaviour changed in a particular way, so I can't think of a reason why I would want fake domain objects. Like I said, I'll have a proper think and get back to you. Cheers, Dan On Dec 15, 2007 7:17 AM, Pat Maddox wrote: > On Dec 8, 2007 4:06 AM, Dan North wrote: > > I prefer the mantra "mock roles, not objects", in other words, mock > things > > that have behaviour (services, components, resources, whatever your > > preferred term is) rather than stubbing out domain objects themselves. > If > > you have to mock domain objects it's usually a smell that your domain > > implementation is too tightly coupled to some infrastructure. > > Assuming you could easily write Rails specs using the real domain > objects, but not hit the database, would you "never" mock domain > objects (where "never" means you deviate only in extraordinary > circumstances)? I'm mostly curious in the interaction between > controller and model...if you use real models, then changes to the > model code could very well lead to failing controller specs, even > though the controller's logic is still correct. > > What is your opinion on isolating tests? Do you try to test each > class in complete isolation, mocking its collaborators? When you use > interaction-based tests, do you always leave those in place, or do you > substitute real objects as you implement them (and if so, do your > changes move to a more state-based style)? How do you approach > specifying different layers within an app? Do you use real > implementations if there are lightweight ones available, or do you > mock everything out? > > I realize that's a ton of questions...I'd be very grateful (and > impressed!) if you took the time to answer any of them. Also I'd love > to hear input from other people as well. > > Pat > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071216/38a83a5f/attachment.html From sera at fhwang.net Sun Dec 16 18:22:42 2007 From: sera at fhwang.net (Francis Hwang) Date: Sun, 16 Dec 2007 18:22:42 -0500 Subject: [rspec-users] Mocks? Really? In-Reply-To: References: <139c56460712060856i6bb410fcl23def3b16c0388b4@mail.gmail.com> <57c63afe0712071840w13e8d2co85a60c00f3caefa9@mail.gmail.com> <810a540e0712142317t5e13f84dt2952986cd0a58a95@mail.gmail.com> Message-ID: Coming to this thread a bit late: I think I'm pretty close to Dan, in practice: I'm not a big fan of fine-grained isolation in writing your tests. The practice seems to me like it would just bug you down. When I'm writing a behavior for a particular thing, such as a controller, I don't want to have to worry about the precise messages that are passed to its collaborators. I try to think in a fairly "black box" manner about it: Presupposing that there's a given document in a database table, when I make an HTTP request that's looking for that document, I should get that document in such-and-such a format. Ideally I wouldn't specify too much whether the controller hits Document.find or Document.find_by_sql or gets it out of some disk cache or gets the data by doing a magical little dance in a faerie circle off in the forest. It's really not my test's problem. On the other hand, I do think mocking is extremely useful when you're dealing with very externalized services with narrow, rigid interfaces that you can't implicitly test all the time. At work I have to write lots of complex tests around a specific web service, but I don't have a lot of control over it, so I wrote a fairly complex mock for that service. But even then it's a different sort of mock: It's more state- aware than surface-aware, which is part of the point as I see it. Of course, writing those sorts of mocks is much more time-consuming. If you haven't seen it before, Martin Fowler has a pretty good article about the differences in styles: http://martinfowler.com/ articles/mocksArentStubs.html Francis Hwang http://fhwang.net/ On Dec 16, 2007, at 5:59 PM, Dan North wrote: > Pat. > > I'm going to reply by promising to reply. You've asked a ton of > really useful and insightful questions. I can't do them justice > without sitting down and spending a bunch of time thinking about them. > > I'm going to be off the radar for a bit over Christmas - I've had > an insane year and I've promised myself (and my wife) some quiet > time. Your questions have a little star next to them in my gmail > inbox, which means at the very least they'll be ignored less than > the other mail I have to respond to :) > > The one sentence response, though, is that I honestly don't know > (which is why I need to think about it). I can tell you I think I > isolate services from their dependencies using mocks, I think I > never stub domain objects (I definitely never mock them, but > stubbing them is different), I can't say how I test layers because > I think we have a different definition of layers. > > The reason I'm being being so vague is that I usually specify > behaviour from the outside in, starting with the "outermost" > objects (the ones that appear in the scenario steps) and working > inwards as I implement each bit of behaviour. That way I discover > service dependencies that I introduce as mocks, and other domain > objects that become, well, domain objects. Then there are other > little classes that fall out of the mix that seem to make sense as > I go along. I don't usually start out with much more of a strategy > than that. I can't speak as a tester because I'm not one, so I > can't really give you a sensible answer for how isolated my tests > are. I simply don't have tests at that level. At an acceptance > level my scenarios only ever use real objects wired together doing > full end-to-end testing. Sometimes I'll swap in a lighter-weight > implementation (say using an in-memory database rather than a > remote one, or an in-thread Java web container like Jetty rather > than firing up Tomcat), but all the wiring is still the same (say > JDBC or HTTP-over-the-wire). I'm still not entirely sure how this > maps to Rails, but in Java MVC web apps I would want the controller > examples failing if the model's behaviour changed in a particular > way, so I can't think of a reason why I would want fake domain > objects. > > Like I said, I'll have a proper think and get back to you. > > Cheers, > Dan > > On Dec 15, 2007 7:17 AM, Pat Maddox < pergesu at gmail.com> wrote: > On Dec 8, 2007 4:06 AM, Dan North < tastapod at gmail.com> wrote: > > I prefer the mantra "mock roles, not objects", in other words, > mock things > > that have behaviour (services, components, resources, whatever your > > preferred term is) rather than stubbing out domain objects > themselves. If > > you have to mock domain objects it's usually a smell that your > domain > > implementation is too tightly coupled to some infrastructure. > > Assuming you could easily write Rails specs using the real domain > objects, but not hit the database, would you "never" mock domain > objects (where "never" means you deviate only in extraordinary > circumstances)? I'm mostly curious in the interaction between > controller and model...if you use real models, then changes to the > model code could very well lead to failing controller specs, even > though the controller's logic is still correct. > > What is your opinion on isolating tests? Do you try to test each > class in complete isolation, mocking its collaborators? When you use > interaction-based tests, do you always leave those in place, or do you > substitute real objects as you implement them (and if so, do your > changes move to a more state-based style)? How do you approach > specifying different layers within an app? Do you use real > implementations if there are lightweight ones available, or do you > mock everything out? > > I realize that's a ton of questions...I'd be very grateful (and > impressed!) if you took the time to answer any of them. Also I'd love > to hear input from other people as well. > > Pat > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From pergesu at gmail.com Sun Dec 16 22:00:46 2007 From: pergesu at gmail.com (Pat Maddox) Date: Sun, 16 Dec 2007 19:00:46 -0800 Subject: [rspec-users] Need help mocking this out In-Reply-To: <57c63afe0712161343x42c05b4ex4344f8dcb44415f4@mail.gmail.com> References: <7e565b5c0712030157s4e56b280l1bcf4621c8c8c7a4@mail.gmail.com> <921ca2f80712030207o7f45771dk15006c3ab5b17ab8@mail.gmail.com> <2fff50390712030244t25e59b74y176a4876ba8b011e@mail.gmail.com> <09A63FFF-BC89-4503-AF02-9C751D929192@parkerhill.com> <57c63afe0712161343x42c05b4ex4344f8dcb44415f4@mail.gmail.com> Message-ID: <810a540e0712161900j27f073bdw3311f2a85a44a2e7@mail.gmail.com> On Dec 16, 2007 1:43 PM, David Chelimsky wrote: > I tend to take this one more step. I'm a bit of a demeter zealot, and > I'm also usually writing the examples from the code first. So I'd do > something like: > > it "should find the current users articles" do > article = mock_model(Article) > current_user.should_receive(:find_article).with("1").and_return(Article) > get :show, :id => "1" > end I find that there are two problems with this approach: - since proxies provide so much behavior, wrapping the proxy's methods like this can quickly lead to a bloated API on User - The Rails Way seems to care a lot less about demeter than you do. Even though the method name is obvious, you still get people going, "huh? why doesn't he just do user.articles.find?" I'm right there with you in theory, but in practice I've found that people simply don't like it. So I've just had to bite my tongue and write slightly uglier specs (I won't give in on add_article, however. articles.should_receive(:<<) gives me sharp stomach pains) It has provided me a nice opportunity to express intent, though. Whenever I want a default finder that does slightly more than articles.find(1), I can write a find_article method to encapsulate it. Then when someone asks me, "well why don't use you juse articles.find" I can reply that there's a little more than meets the eye. But how great is it that they don't have to know what it is in order to use it! Maybe there's something to this approach after all. So like I said, in general I prefer your approach, but I've opted for the principle of least surprise with my coworkers. I think I make the best of it by communicating those times when I depart from the standard Rails chaining style. Pat From mailing_lists at railsnewbie.com Sun Dec 16 22:43:58 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sun, 16 Dec 2007 22:43:58 -0500 Subject: [rspec-users] Mocks? Really? In-Reply-To: References: <139c56460712060856i6bb410fcl23def3b16c0388b4@mail.gmail.com> <57c63afe0712071840w13e8d2co85a60c00f3caefa9@mail.gmail.com> <810a540e0712142317t5e13f84dt2952986cd0a58a95@mail.gmail.com> Message-ID: Francis and Pat probably know my thoughts on this, already, but as far as I can see it, mocks (at least the message based ones) are popular for one reason in the rails / active-record world: Speed. Mocks are extremely fast. I don't think it's uncommon for those who write specs for rails projects to have a full test suite running in under 20 seconds if they are mocking all dependencies. Primarily, this means using mocks for all associations on a Rails model, and using only mocks for controller specs. The issue of speed seems secondary, but I can already tell how costly a long build cycle is. At work our test suite has about 1800 specs, and takes around 3 minutes to run (and hits the database in all model specs). My coworker actually released something into production on Friday before he left which failed the build. Obviously - this has a serious effect on the end user, who is currently receiving errors. If the test suite took 20 seconds to run, he would be running it all the time, and this error would have never occurred. The fact that they don't run quickly means that he isn't going to run them all the time, and will need to rely on a CI server to beep or do something obnoxious like that (which isn't an option in the shared office space in which we are currently working). Plus - let's be honest: We use tests as our feedback loop. The tighter we can get this, the closer we can stay to the code. When the specs take over a few minutes to run, we no longer have the luxury of running the whole suite every time we make a little one line change. We are forced to run specs from one file, or a subset of the specs from one file, and we loose a certain amount of feedback on how our code is integrating. Yes - there are other reasons for using mocks - like defining interfaces that don't exist (or may not exist for a long time); So far the main reason I've seen them used is for speed. I think this is a major problem with activerecord - and one which only be solved only by moving to an ORM with a different design pattern (like a true DataMapper). Lafcadio would probably be in the running for this sort of thing - a library which can isolate the database and the API with a middle layer, which can easily be mocked either by a mock library which could be a drop in replacement for the database, or a middle layer which could easily be stubbed out with message based stubs. As always, it's good to hear this sort of discussion going on. (Francis: It was exactly this sort of discussion that got me involved with RSpec in the first place) Regards, Scott On Dec 16, 2007, at 6:22 PM, Francis Hwang wrote: > Coming to this thread a bit late: > > I think I'm pretty close to Dan, in practice: I'm not a big fan of > fine-grained isolation in writing your tests. The practice seems to > me like it would just bug you down. When I'm writing a behavior for a > particular thing, such as a controller, I don't want to have to worry > about the precise messages that are passed to its collaborators. I > try to think in a fairly "black box" manner about it: Presupposing > that there's a given document in a database table, when I make an > HTTP request that's looking for that document, I should get that > document in such-and-such a format. Ideally I wouldn't specify too > much whether the controller hits Document.find or > Document.find_by_sql or gets it out of some disk cache or gets the > data by doing a magical little dance in a faerie circle off in the > forest. It's really not my test's problem. > On the other hand, I do think mocking is extremely useful when you're > dealing with very externalized services with narrow, rigid interfaces > that you can't implicitly test all the time. At work I have to write > lots of complex tests around a specific web service, but I don't have > a lot of control over it, so I wrote a fairly complex mock for that > service. But even then it's a different sort of mock: It's more state- > aware than surface-aware, which is part of the point as I see it. Of > course, writing those sorts of mocks is much more time-consuming. > > If you haven't seen it before, Martin Fowler has a pretty good > article about the differences in styles: http://martinfowler.com/ > articles/mocksArentStubs.html > > Francis Hwang > http://fhwang.net/ > > > > On Dec 16, 2007, at 5:59 PM, Dan North wrote: > >> Pat. >> >> I'm going to reply by promising to reply. You've asked a ton of >> really useful and insightful questions. I can't do them justice >> without sitting down and spending a bunch of time thinking about >> them. >> >> I'm going to be off the radar for a bit over Christmas - I've had >> an insane year and I've promised myself (and my wife) some quiet >> time. Your questions have a little star next to them in my gmail >> inbox, which means at the very least they'll be ignored less than >> the other mail I have to respond to :) >> >> The one sentence response, though, is that I honestly don't know >> (which is why I need to think about it). I can tell you I think I >> isolate services from their dependencies using mocks, I think I >> never stub domain objects (I definitely never mock them, but >> stubbing them is different), I can't say how I test layers because >> I think we have a different definition of layers. >> >> The reason I'm being being so vague is that I usually specify >> behaviour from the outside in, starting with the "outermost" >> objects (the ones that appear in the scenario steps) and working >> inwards as I implement each bit of behaviour. That way I discover >> service dependencies that I introduce as mocks, and other domain >> objects that become, well, domain objects. Then there are other >> little classes that fall out of the mix that seem to make sense as >> I go along. I don't usually start out with much more of a strategy >> than that. I can't speak as a tester because I'm not one, so I >> can't really give you a sensible answer for how isolated my tests >> are. I simply don't have tests at that level. At an acceptance >> level my scenarios only ever use real objects wired together doing >> full end-to-end testing. Sometimes I'll swap in a lighter-weight >> implementation (say using an in-memory database rather than a >> remote one, or an in-thread Java web container like Jetty rather >> than firing up Tomcat), but all the wiring is still the same (say >> JDBC or HTTP-over-the-wire). I'm still not entirely sure how this >> maps to Rails, but in Java MVC web apps I would want the controller >> examples failing if the model's behaviour changed in a particular >> way, so I can't think of a reason why I would want fake domain >> objects. >> >> Like I said, I'll have a proper think and get back to you. >> >> Cheers, >> Dan >> >> On Dec 15, 2007 7:17 AM, Pat Maddox < pergesu at gmail.com> wrote: >> On Dec 8, 2007 4:06 AM, Dan North < tastapod at gmail.com> wrote: >>> I prefer the mantra "mock roles, not objects", in other words, >> mock things >>> that have behaviour (services, components, resources, whatever your >>> preferred term is) rather than stubbing out domain objects >> themselves. If >>> you have to mock domain objects it's usually a smell that your >> domain >>> implementation is too tightly coupled to some infrastructure. >> >> Assuming you could easily write Rails specs using the real domain >> objects, but not hit the database, would you "never" mock domain >> objects (where "never" means you deviate only in extraordinary >> circumstances)? I'm mostly curious in the interaction between >> controller and model...if you use real models, then changes to the >> model code could very well lead to failing controller specs, even >> though the controller's logic is still correct. >> >> What is your opinion on isolating tests? Do you try to test each >> class in complete isolation, mocking its collaborators? When you use >> interaction-based tests, do you always leave those in place, or do >> you >> substitute real objects as you implement them (and if so, do your >> changes move to a more state-based style)? How do you approach >> specifying different layers within an app? Do you use real >> implementations if there are lightweight ones available, or do you >> mock everything out? >> >> I realize that's a ton of questions...I'd be very grateful (and >> impressed!) if you took the time to answer any of them. Also I'd >> love >> to hear input from other people as well. >> >> Pat >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From brian.takita at gmail.com Mon Dec 17 03:25:42 2007 From: brian.takita at gmail.com (Brian Takita) Date: Mon, 17 Dec 2007 00:25:42 -0800 Subject: [rspec-users] Mocks? Really? In-Reply-To: References: <139c56460712060856i6bb410fcl23def3b16c0388b4@mail.gmail.com> <57c63afe0712071840w13e8d2co85a60c00f3caefa9@mail.gmail.com> <810a540e0712142317t5e13f84dt2952986cd0a58a95@mail.gmail.com> Message-ID: <1d7ddd110712170025n2bcbff61l969d60d7b852a495@mail.gmail.com> On Dec 16, 2007 7:43 PM, Scott Taylor wrote: > > Francis and Pat probably know my thoughts on this, already, but as > far as I can see it, mocks (at least the message based ones) are > popular for one reason in the rails / active-record world: > > Speed. Mocks are extremely fast. I don't think it's uncommon for > those who write specs for rails projects to have a full test suite > running in under 20 seconds if they are mocking all dependencies. > Primarily, this means using mocks for all associations on a Rails > model, and using only mocks for controller specs. My experience with AR is that AR itself (mainly object instantiation) is slow, not the queries. Mocking the queries did not result in a worthwhile test run time savings. Rails creates lots of objects, which causes lots of slowness. Its death by a thousand cuts. I guess one could mock out the entire AR object, but I'm not convinced that it would result in large performance benefits in many cases. I've tried doing this a couple of times and did not save much time at all. Of course, this was done in view examples on a project that uses Markaby (which is slow). Whatever you do, I recommend taking performance metrics of your suite as you try to diagnose the slowness. The results will probably be surprising. > > The issue of speed seems secondary, but I can already tell how costly > a long build cycle is. At work our test suite has about 1800 specs, > and takes around 3 minutes to run (and hits the database in all model > specs). My coworker actually released something into production on > Friday before he left which failed the build. Obviously - this has a > serious effect on the end user, who is currently receiving errors. > If the test suite took 20 seconds to run, he would be running it all > the time, and this error would have never occurred. The fact that > they don't run quickly means that he isn't going to run them all the > time, and will need to rely on a CI server to beep or do something > obnoxious like that (which isn't an option in the shared office space > in which we are currently working). > > Plus - let's be honest: We use tests as our feedback loop. The > tighter we can get this, the closer we can stay to the code. When the > specs take over a few minutes to run, we no longer have the luxury of > running the whole suite every time we make a little one line change. > We are forced to run specs from one file, or a subset of the specs > from one file, and we loose a certain amount of feedback on how our > code is integrating. > > Yes - there are other reasons for using mocks - like defining > interfaces that don't exist (or may not exist for a long time); So > far the main reason I've seen them used is for speed. I think this > is a major problem with activerecord - and one which only be solved > only by moving to an ORM with a different design pattern (like a true > DataMapper). Lafcadio would probably be in the running for this sort > of thing - a library which can isolate the database and the API with > a middle layer, which can easily be mocked either by a mock library > which could be a drop in replacement for the database, or a middle > layer which could easily be stubbed out with message based stubs. One thing about AR that hurts is all of the copies of the same record. It would be really nice if there was only one instance of each record in the thread. This would help performance and significantly reduce the need to reload the object. > > As always, it's good to hear this sort of discussion going on. > (Francis: It was exactly this sort of discussion that got me > involved with RSpec in the first place) > > Regards, > > Scott > > > > > > On Dec 16, 2007, at 6:22 PM, Francis Hwang wrote: > > > Coming to this thread a bit late: > > > > I think I'm pretty close to Dan, in practice: I'm not a big fan of > > fine-grained isolation in writing your tests. The practice seems to > > me like it would just bug you down. When I'm writing a behavior for a > > particular thing, such as a controller, I don't want to have to worry > > about the precise messages that are passed to its collaborators. I > > try to think in a fairly "black box" manner about it: Presupposing > > that there's a given document in a database table, when I make an > > HTTP request that's looking for that document, I should get that > > document in such-and-such a format. Ideally I wouldn't specify too > > much whether the controller hits Document.find or > > Document.find_by_sql or gets it out of some disk cache or gets the > > data by doing a magical little dance in a faerie circle off in the > > forest. It's really not my test's problem. > > On the other hand, I do think mocking is extremely useful when you're > > dealing with very externalized services with narrow, rigid interfaces > > that you can't implicitly test all the time. At work I have to write > > lots of complex tests around a specific web service, but I don't have > > a lot of control over it, so I wrote a fairly complex mock for that > > service. But even then it's a different sort of mock: It's more state- > > aware than surface-aware, which is part of the point as I see it. Of > > course, writing those sorts of mocks is much more time-consuming. > > > > If you haven't seen it before, Martin Fowler has a pretty good > > article about the differences in styles: http://martinfowler.com/ > > articles/mocksArentStubs.html > > > > Francis Hwang > > http://fhwang.net/ > > > > > > > > On Dec 16, 2007, at 5:59 PM, Dan North wrote: > > > >> Pat. > >> > >> I'm going to reply by promising to reply. You've asked a ton of > >> really useful and insightful questions. I can't do them justice > >> without sitting down and spending a bunch of time thinking about > >> them. > >> > >> I'm going to be off the radar for a bit over Christmas - I've had > >> an insane year and I've promised myself (and my wife) some quiet > >> time. Your questions have a little star next to them in my gmail > >> inbox, which means at the very least they'll be ignored less than > >> the other mail I have to respond to :) > >> > >> The one sentence response, though, is that I honestly don't know > >> (which is why I need to think about it). I can tell you I think I > >> isolate services from their dependencies using mocks, I think I > >> never stub domain objects (I definitely never mock them, but > >> stubbing them is different), I can't say how I test layers because > >> I think we have a different definition of layers. > >> > >> The reason I'm being being so vague is that I usually specify > >> behaviour from the outside in, starting with the "outermost" > >> objects (the ones that appear in the scenario steps) and working > >> inwards as I implement each bit of behaviour. That way I discover > >> service dependencies that I introduce as mocks, and other domain > >> objects that become, well, domain objects. Then there are other > >> little classes that fall out of the mix that seem to make sense as > >> I go along. I don't usually start out with much more of a strategy > >> than that. I can't speak as a tester because I'm not one, so I > >> can't really give you a sensible answer for how isolated my tests > >> are. I simply don't have tests at that level. At an acceptance > >> level my scenarios only ever use real objects wired together doing > >> full end-to-end testing. Sometimes I'll swap in a lighter-weight > >> implementation (say using an in-memory database rather than a > >> remote one, or an in-thread Java web container like Jetty rather > >> than firing up Tomcat), but all the wiring is still the same (say > >> JDBC or HTTP-over-the-wire). I'm still not entirely sure how this > >> maps to Rails, but in Java MVC web apps I would want the controller > >> examples failing if the model's behaviour changed in a particular > >> way, so I can't think of a reason why I would want fake domain > >> objects. > >> > >> Like I said, I'll have a proper think and get back to you. > >> > >> Cheers, > >> Dan > >> > >> On Dec 15, 2007 7:17 AM, Pat Maddox < pergesu at gmail.com> wrote: > >> On Dec 8, 2007 4:06 AM, Dan North < tastapod at gmail.com> wrote: > >>> I prefer the mantra "mock roles, not objects", in other words, > >> mock things > >>> that have behaviour (services, components, resources, whatever your > >>> preferred term is) rather than stubbing out domain objects > >> themselves. If > >>> you have to mock domain objects it's usually a smell that your > >> domain > >>> implementation is too tightly coupled to some infrastructure. > >> > >> Assuming you could easily write Rails specs using the real domain > >> objects, but not hit the database, would you "never" mock domain > >> objects (where "never" means you deviate only in extraordinary > >> circumstances)? I'm mostly curious in the interaction between > >> controller and model...if you use real models, then changes to the > >> model code could very well lead to failing controller specs, even > >> though the controller's logic is still correct. > >> > >> What is your opinion on isolating tests? Do you try to test each > >> class in complete isolation, mocking its collaborators? When you use > >> interaction-based tests, do you always leave those in place, or do > >> you > >> substitute real objects as you implement them (and if so, do your > >> changes move to a more state-based style)? How do you approach > >> specifying different layers within an app? Do you use real > >> implementations if there are lightweight ones available, or do you > >> mock everything out? > >> > >> I realize that's a ton of questions...I'd be very grateful (and > >> impressed!) if you took the time to answer any of them. Also I'd > >> love > >> to hear input from other people as well. > >> > >> Pat > >> > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-users at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/rspec-users > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From andy at adveho.net Mon Dec 17 06:10:50 2007 From: andy at adveho.net (Andy Goundry) Date: Mon, 17 Dec 2007 11:10:50 +0000 Subject: [rspec-users] Mocks? Really? In-Reply-To: <810a540e0712142317t5e13f84dt2952986cd0a58a95@mail.gmail.com> References: <139c56460712060856i6bb410fcl23def3b16c0388b4@mail.gmail.com> <57c63afe0712071840w13e8d2co85a60c00f3caefa9@mail.gmail.com> <810a540e0712142317t5e13f84dt2952986cd0a58a95@mail.gmail.com> Message-ID: <139c56460712170310y437b505bwc21dc1ebc56c22a8@mail.gmail.com> For me, this has certainly been the most enjoyable and interesting part of using RSpec - finding answers to these questions in a context that suits the project. Of course, i am new to this, but have found an approach that works well for my current project. However, my approach is wide open to review and improvement and will no doubt evolve well beyond its current scope in future. I am still reading and re-reading Dan's previous mail regarding the Builder pattern as it is very elegant, although i am not using now as i feel that it could introduce a little too much overhead to maintain the Builders. I am also considering Dan's mantra and with more RSpec experience i'll gain a better insight into how this can work in rails. Here's what i'm doing that works well for our project: Mocking * In views and controllers I always use mocks and stub out any responses that i spot or are flagged up by autotest (yep, autotest is ace for highlighting those methods that need stubbing) * In models, i only use real models for the model specific to the test. I always mock all other interacting models - so in a test for a project with many tasks, the tasks model is mocked and then stubbed. * I only define the expectation for any mock or real model in one place. So, in our app, the expected definition of a Project is defined once and that definition is used by all tests that use that object, from views to models. It's default values can be overwritten, but the expectation is set for all uses. More info below: Factories So far, I am finding that a factory class is offering a useful *glue* between the intentionally separated unit tests. So, even though all tests are isolated from each other with mocks, they still share an expectation of what any used mock should look like. This enables me to be aware of the system wide impact of a change to a small component of the system. I fully accept that this should be covered by integration testing and not unit testing, but on a quick project, i am not sure i can justify (not yet at least) the time to write unit tests and then integration tests, especially as the test team will go at the app with Scellenium. As i say, mine is an evolving platform :-) Here's how we are using a factory. I hope it helps and that i don't get too grilled for the design and implementation :-) ### # The factory class houses the expected # definition of each object and returns # mocks or real models depending on the request # It's attribute values (but not keys) can be overwritten # See 'validate_attributes' method below ### module Factory def self.create_project(attributes = {}, mock = false) @default_attributes = { :name => "Mock Project", :synopsis => "Mock Project Synopsis" } create_object(attributes,mock,Project) end private def self.create_object(custom_attributes,mock,object_type) validate_attributes(custom_attributes) attributes = @default_attributes.merge(custom_attributes) if mock attributes.each_pair do |key, value| mock.stub!(key).and_return(value) end mock else mock = object_type.create attributes end end ### # The following method validates that any received # custom attribute's key is in the expected attribute # list for the object. If not, the test fails, forcing # the developer to keep the factory defaults up to # date with any changes ### def self.validate_attributes(attributes) attributes.each_key {|a| raise "Unrecognised attribute '#{a}' was passed into the Factory" if !@default_attributes.has_key?(a)} true end end ### # Projects controller test interacts # with the Factory and receives mocks ### describe ProjectsController do include Factory before(:each) do @project1 = Factory.create_project({}, mock_model(Project)), @project2 = Factory.create_project({:name => "My second project", :synopsis => "This is another fantastic project"}, mock_model(Project)) @projects = [@project1, at project2] end end ### # The Project model test interacts with # the Factory and receives real models ### describe Project do include Factory before(:each) do Project.destroy_all #Real project @project = Factory.create_project #Stub Role @role = Factory.create_role({},mock_model(Role)) @role.stub!(:quoted_id).and_return(true) @role.stub!(:[]=).and_return(true) @role.stub!(:save).and_return(true) end end From dchelimsky at gmail.com Mon Dec 17 06:56:59 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 17 Dec 2007 05:56:59 -0600 Subject: [rspec-users] Mocks? Really? In-Reply-To: <139c56460712170310y437b505bwc21dc1ebc56c22a8@mail.gmail.com> References: <139c56460712060856i6bb410fcl23def3b16c0388b4@mail.gmail.com> <57c63afe0712071840w13e8d2co85a60c00f3caefa9@mail.gmail.com> <810a540e0712142317t5e13f84dt2952986cd0a58a95@mail.gmail.com> <139c56460712170310y437b505bwc21dc1ebc56c22a8@mail.gmail.com> Message-ID: <57c63afe0712170356ha778a48t306f0ed267ea5039@mail.gmail.com> On Dec 17, 2007 5:10 AM, Andy Goundry wrote: > I am also considering Dan's mantra Dan's mantra of "mock roles, not objects" comes from http://www.jmock.org/oopsla2004.pdf, a paper of the same name. My read on this differs from Dan's a bit. I'll follow up on that later, but you might want to give it a read and form your own opinion before I poison you with mine :) From andy at adveho.net Mon Dec 17 07:08:13 2007 From: andy at adveho.net (Andy Goundry) Date: Mon, 17 Dec 2007 12:08:13 +0000 Subject: [rspec-users] :-) Message-ID: <139c56460712170408x311339eya611e1187a01602a@mail.gmail.com> A quick post unrelated to anything other than to say THANKS TO EVERYONE for such a vibrant, established and supportive email list. Fantastic work and i will of course be supporting more and more as i gain ground. Merry Christmas :-) Andy From jeroen.houben at lostboys.nl Mon Dec 17 08:13:05 2007 From: jeroen.houben at lostboys.nl (Jeroen Houben) Date: Mon, 17 Dec 2007 14:13:05 +0100 Subject: [rspec-users] Change in isolation behaviour 1.08 - 1.10 ? Message-ID: Hi, I just moved from 1.08 to 1.10 and now have one example failing, which, under 1.08, passed. Is the due to a change in behaviour? Here's my spec (removed some passing examples) require File.dirname(__FILE__) + '/../spec_helper' describe "A user" do before(:each) do @user = User.new @valid_user = User.new( :email => 'bert.valid at lostboys.nl', :fname => 'bert', :lname => 'valid', :jobtitle => "programmer" ) end it "should have a unique email address" do @valid_user.save.should == true @user.email = @valid_user.email @user.should have(1).error_on(:email) end it "should allow two users with the same name" do @valid_user.save.should == true @user.fname = @valid_user.fname @user.lname = @valid_user.lname @user.should have(:no).error_on(:fname) @user.should have(:no).error_on(:lname) end end The second example now fails, as the inserted record from the first example is not rolled back. I can just put a User.delete_all in an after(:each) block but I think it would be nicer if Rspec wrapped each example in a db transaction. Wasn't this they way things worked in 1.08 ? Jeroen From aslak.hellesoy at gmail.com Mon Dec 17 09:17:10 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Mon, 17 Dec 2007 15:17:10 +0100 Subject: [rspec-users] Change in isolation behaviour 1.08 - 1.10 ? In-Reply-To: References: Message-ID: <8d961d900712170617o56d88550l403ef5a8013ef68f@mail.gmail.com> On Dec 17, 2007 2:13 PM, Jeroen Houben wrote: > Hi, > > I just moved from 1.08 to 1.10 and now have one example failing, which, > under 1.08, passed. Is the due to a change in behaviour? > > Here's my spec (removed some passing examples) > > require File.dirname(__FILE__) + '/../spec_helper' > > describe "A user" do > > before(:each) do > @user = User.new > @valid_user = User.new( > :email => 'bert.valid at lostboys.nl', > :fname => 'bert', > :lname => 'valid', > :jobtitle => "programmer" > ) > end > > it "should have a unique email address" do > @valid_user.save.should == true > @user.email = @valid_user.email > @user.should have(1).error_on(:email) > end > > it "should allow two users with the same name" do > @valid_user.save.should == true > @user.fname = @valid_user.fname > @user.lname = @valid_user.lname > @user.should have(:no).error_on(:fname) > @user.should have(:no).error_on(:lname) > end > > end > > The second example now fails, as the inserted record from the first example > is not rolled back. > stack trace please > I can just put a User.delete_all in an after(:each) block but I think it > would be nicer if Rspec wrapped each example in a db transaction. Wasn't > this they way things worked in 1.08 ? > > Jeroen > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jeroen.houben at lostboys.nl Mon Dec 17 09:23:54 2007 From: jeroen.houben at lostboys.nl (Jeroen Houben) Date: Mon, 17 Dec 2007 15:23:54 +0100 Subject: [rspec-users] Change in isolation behaviour 1.08 - 1.10 ? In-Reply-To: <8d961d900712170617o56d88550l403ef5a8013ef68f@mail.gmail.com> Message-ID: jeroen$ ./script/spec spec/models/user_spec.rb -b ...F..................P.. Pending: A valid user should add the correct error on dob when using an bogus dob assignment (with only a month) (met max dob is beetje lastig op win32 lijkt het :-s) 1) 'A user should allow two users with the same name' FAILED expected: true, got: false (using ==) /Users/jeroen/lostboys.nl/vendor/plugins/rspec/lib/spec/expectations.rb:52:i n `fail_with' /Users/jeroen/lostboys.nl/vendor/plugins/rspec/lib/spec/matchers/operator_ma tcher.rb:46:in `fail_with_message' /Users/jeroen/lostboys.nl/vendor/plugins/rspec/lib/spec/matchers/operator_ma tcher.rb:56:in `__delegate_method_missing_to_target' /Users/jeroen/lostboys.nl/vendor/plugins/rspec/lib/spec/matchers/operator_ma tcher.rb:12:in `==' ./spec/models/user_spec.rb:36: /Users/jeroen/lostboys.nl/vendor/plugins/rspec/lib/spec/example/example_meth ods.rb:79:in `instance_eval' /Users/jeroen/lostboys.nl/vendor/plugins/rspec/lib/spec/example/example_meth ods.rb:79:in `run_with_description_capturing' /Users/jeroen/lostboys.nl/vendor/plugins/rspec/lib/spec/matchers.rb:144:in `capture_generated_description' /Users/jeroen/lostboys.nl/vendor/plugins/rspec/lib/spec/example/example_meth ods.rb:78:in `run_with_description_capturing' /Users/jeroen/lostboys.nl/vendor/plugins/rspec/lib/spec/example/example_meth ods.rb:19:in `execute' /usr/local/lib/ruby/1.8/timeout.rb:48:in `timeout' /Users/jeroen/lostboys.nl/vendor/plugins/rspec/lib/spec/example/example_meth ods.rb:16:in `execute' /Users/jeroen/lostboys.nl/vendor/plugins/rspec/lib/spec/example/example_grou p_methods.rb:280:in `execute_examples' /Users/jeroen/lostboys.nl/vendor/plugins/rspec/lib/spec/example/example_grou p_methods.rb:279:in `each' /Users/jeroen/lostboys.nl/vendor/plugins/rspec/lib/spec/example/example_grou p_methods.rb:279:in `execute_examples' /Users/jeroen/lostboys.nl/vendor/plugins/rspec/lib/spec/example/example_grou p_methods.rb:120:in `run' /Users/jeroen/lostboys.nl/vendor/plugins/rspec/lib/spec/runner/example_group _runner.rb:22:in `run' /Users/jeroen/lostboys.nl/vendor/plugins/rspec/lib/spec/runner/example_group _runner.rb:21:in `each' /Users/jeroen/lostboys.nl/vendor/plugins/rspec/lib/spec/runner/example_group _runner.rb:21:in `run' /Users/jeroen/lostboys.nl/vendor/plugins/rspec/lib/spec/runner/options.rb:87 :in `run_examples' /Users/jeroen/lostboys.nl/vendor/plugins/rspec/lib/spec/runner/command_line. rb:19:in `run' ./script/spec:4: Finished in 0.391897 seconds 25 examples, 1 failure, 1 pending On 12/17/07 3:17 PM, "aslak hellesoy" wrote: > On Dec 17, 2007 2:13 PM, Jeroen Houben wrote: >> Hi, >> >> I just moved from 1.08 to 1.10 and now have one example failing, which, >> under 1.08, passed. Is the due to a change in behaviour? >> >> Here's my spec (removed some passing examples) >> >> require File.dirname(__FILE__) + '/../spec_helper' >> >> describe "A user" do >> >> before(:each) do >> @user = User.new >> @valid_user = User.new( >> :email => 'bert.valid at lostboys.nl', >> :fname => 'bert', >> :lname => 'valid', >> :jobtitle => "programmer" >> ) >> end >> >> it "should have a unique email address" do >> @valid_user.save.should == true >> @user.email = @valid_user.email >> @user.should have(1).error_on(:email) >> end >> >> it "should allow two users with the same name" do >> @valid_user.save.should == true >> @user.fname = @valid_user.fname >> @user.lname = @valid_user.lname >> @user.should have(:no).error_on(:fname) >> @user.should have(:no).error_on(:lname) >> end >> >> end >> >> The second example now fails, as the inserted record from the first example >> is not rolled back. >> > > stack trace please > >> I can just put a User.delete_all in an after(:each) block but I think it >> would be nicer if Rspec wrapped each example in a db transaction. Wasn't >> this they way things worked in 1.08 ? >> >> Jeroen >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.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 Dec 17 09:47:23 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Mon, 17 Dec 2007 15:47:23 +0100 Subject: [rspec-users] Change in isolation behaviour 1.08 - 1.10 ? In-Reply-To: References: Message-ID: <8d961d900712170647k77e1ede2x1b3cf197582184bc@mail.gmail.com> On Dec 17, 2007 2:13 PM, Jeroen Houben wrote: > Hi, > > I just moved from 1.08 to 1.10 and now have one example failing, which, > under 1.08, passed. Is the due to a change in behaviour? > > Here's my spec (removed some passing examples) > > require File.dirname(__FILE__) + '/../spec_helper' > > describe "A user" do > > before(:each) do > @user = User.new > @valid_user = User.new( > :email => 'bert.valid at lostboys.nl', > :fname => 'bert', > :lname => 'valid', > :jobtitle => "programmer" > ) > end > > it "should have a unique email address" do > @valid_user.save.should == true > @user.email = @valid_user.email > @user.should have(1).error_on(:email) > end > > it "should allow two users with the same name" do > @valid_user.save.should == true > @user.fname = @valid_user.fname > @user.lname = @valid_user.lname > @user.should have(:no).error_on(:fname) > @user.should have(:no).error_on(:lname) > end > > end > > The second example now fails, as the inserted record from the first example > is not rolled back. > I don't see a fixtures :users in your spec. Do you have this in your spec_helper? Have you rerun script/generate rspec after you upgraded? There are some changes in the spec_helper.rb file between the two releases. Aslak > I can just put a User.delete_all in an after(:each) block but I think it > would be nicer if Rspec wrapped each example in a db transaction. Wasn't > this they way things worked in 1.08 ? > > Jeroen > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Mon Dec 17 09:50:33 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 17 Dec 2007 08:50:33 -0600 Subject: [rspec-users] Change in isolation behaviour 1.08 - 1.10 ? In-Reply-To: <8d961d900712170647k77e1ede2x1b3cf197582184bc@mail.gmail.com> References: <8d961d900712170647k77e1ede2x1b3cf197582184bc@mail.gmail.com> Message-ID: <57c63afe0712170650p1c0740ecw9f1325818af314fe@mail.gmail.com> On Dec 17, 2007 8:47 AM, aslak hellesoy wrote: > On Dec 17, 2007 2:13 PM, Jeroen Houben wrote: > > > Hi, > > > > I just moved from 1.08 to 1.10 and now have one example failing, which, > > under 1.08, passed. Is the due to a change in behaviour? > > > > Here's my spec (removed some passing examples) > > > > require File.dirname(__FILE__) + '/../spec_helper' > > > > describe "A user" do > > > > before(:each) do > > @user = User.new > > @valid_user = User.new( > > :email => 'bert.valid at lostboys.nl', > > :fname => 'bert', > > :lname => 'valid', > > :jobtitle => "programmer" > > ) > > end > > > > it "should have a unique email address" do > > @valid_user.save.should == true > > @user.email = @valid_user.email > > @user.should have(1).error_on(:email) > > end > > > > it "should allow two users with the same name" do > > @valid_user.save.should == true > > @user.fname = @valid_user.fname > > @user.lname = @valid_user.lname > > @user.should have(:no).error_on(:fname) > > @user.should have(:no).error_on(:lname) > > end > > > > end > > > > The second example now fails, as the inserted record from the first example > > is not rolled back. > > > > I don't see a fixtures :users in your spec. Do you have this in your > spec_helper? > Have you rerun script/generate rspec after you upgraded? There are > some changes in the spec_helper.rb file between the two releases. This is actually a regression in 1.1.0 that has been fixed in trunk. We'll do a 1.1.1 release later today, but go ahead and update to trunk for the time being and you should be good. Cheers, David > > Aslak > > > > I can just put a User.delete_all in an after(:each) block but I think it > > would be nicer if Rspec wrapped each example in a db transaction. Wasn't > > this they way things worked in 1.08 ? > > > > Jeroen > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.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 jeroen.houben at lostboys.nl Mon Dec 17 09:52:55 2007 From: jeroen.houben at lostboys.nl (Jeroen Houben) Date: Mon, 17 Dec 2007 15:52:55 +0100 Subject: [rspec-users] Change in isolation behaviour 1.08 - 1.10 ? In-Reply-To: <57c63afe0712170650p1c0740ecw9f1325818af314fe@mail.gmail.com> Message-ID: > > This is actually a regression in 1.1.0 that has been fixed in trunk. > We'll do a 1.1.1 release later today, but go ahead and update to trunk > for the time being and you should be good. > Great, thanks. Will I get 1.1.1 automatically if I'm using svn:externals and the CURRENT tag? jeroen From dchelimsky at gmail.com Mon Dec 17 09:53:34 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 17 Dec 2007 08:53:34 -0600 Subject: [rspec-users] Change in isolation behaviour 1.08 - 1.10 ? In-Reply-To: References: <57c63afe0712170650p1c0740ecw9f1325818af314fe@mail.gmail.com> Message-ID: <57c63afe0712170653x1af756bdod23a8959d1c966ee@mail.gmail.com> On Dec 17, 2007 8:52 AM, Jeroen Houben wrote: > > > > This is actually a regression in 1.1.0 that has been fixed in trunk. > > We'll do a 1.1.1 release later today, but go ahead and update to trunk > > for the time being and you should be good. > > > > Great, thanks. Will I get 1.1.1 automatically if I'm using svn:externals and > the CURRENT tag? When we do the release, yes, but not until then. > > > jeroen > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jeroen.houben at lostboys.nl Mon Dec 17 09:55:42 2007 From: jeroen.houben at lostboys.nl (Jeroen Houben) Date: Mon, 17 Dec 2007 15:55:42 +0100 Subject: [rspec-users] Change in isolation behaviour 1.08 - 1.10 ? In-Reply-To: <8d961d900712170647k77e1ede2x1b3cf197582184bc@mail.gmail.com> Message-ID: > > I don't see a fixtures :users in your spec. Do you have this in your > spec_helper? Not using fixtures in this particular spec > Have you rerun script/generate rspec after you upgraded? Yes, but manually copied over the changes in spec_helper.rb > There are some changes in the spec_helper.rb file between the two releases. ... Just received the message by David. This will be fixed in 1.1.1 Thanks for your help! Jeroen From dchelimsky at gmail.com Mon Dec 17 09:58:33 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 17 Dec 2007 08:58:33 -0600 Subject: [rspec-users] Change in isolation behaviour 1.08 - 1.10 ? In-Reply-To: References: <8d961d900712170647k77e1ede2x1b3cf197582184bc@mail.gmail.com> Message-ID: <57c63afe0712170658t6a331290k10ca69f3c06b8819@mail.gmail.com> On Dec 17, 2007 8:55 AM, Jeroen Houben wrote: > > > > > I don't see a fixtures :users in your spec. Do you have this in your > > spec_helper? > > Not using fixtures in this particular spec > > > Have you rerun script/generate rspec after you upgraded? > > Yes, but manually copied over the changes in spec_helper.rb > > > There are some changes in the spec_helper.rb file between the two releases. > > ... Just received the message by David. This will be fixed in 1.1.1 Jeroen - just for good measure, would you kindly update from trunk and verify that it does in fact fix your issue? > > Thanks for your help! > > > Jeroen > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jeroen.houben at lostboys.nl Mon Dec 17 10:06:34 2007 From: jeroen.houben at lostboys.nl (Jeroen Houben) Date: Mon, 17 Dec 2007 16:06:34 +0100 Subject: [rspec-users] Change in isolation behaviour 1.08 - 1.10 ? In-Reply-To: <57c63afe0712170658t6a331290k10ca69f3c06b8819@mail.gmail.com> Message-ID: >> >> ... Just received the message by David. This will be fixed in 1.1.1 > > Jeroen - just for good measure, would you kindly update from trunk and > verify that it does in fact fix your issue? Finished in 3.42683 seconds 176 examples, 0 failures, 3 pending :) From dchelimsky at gmail.com Mon Dec 17 10:12:06 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 17 Dec 2007 09:12:06 -0600 Subject: [rspec-users] Change in isolation behaviour 1.08 - 1.10 ? In-Reply-To: References: <57c63afe0712170658t6a331290k10ca69f3c06b8819@mail.gmail.com> Message-ID: <57c63afe0712170712p6234c966v80ba5c6b06c151b0@mail.gmail.com> On Dec 17, 2007 9:06 AM, Jeroen Houben wrote: > >> > >> ... Just received the message by David. This will be fixed in 1.1.1 > > > > Jeroen - just for good measure, would you kindly update from trunk and > > verify that it does in fact fix your issue? > > Finished in 3.42683 seconds > > 176 examples, 0 failures, 3 pending Thanks. I'll get the release out by tonight. Cheers, David > > :) > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From aslak.hellesoy at gmail.com Mon Dec 17 11:55:55 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Mon, 17 Dec 2007 17:55:55 +0100 Subject: [rspec-users] Change in isolation behaviour 1.08 - 1.10 ? In-Reply-To: <57c63afe0712170712p6234c966v80ba5c6b06c151b0@mail.gmail.com> References: <57c63afe0712170658t6a331290k10ca69f3c06b8819@mail.gmail.com> <57c63afe0712170712p6234c966v80ba5c6b06c151b0@mail.gmail.com> Message-ID: <8d961d900712170855j42d825c0h4417e9733187f915@mail.gmail.com> On Dec 17, 2007 4:12 PM, David Chelimsky wrote: > On Dec 17, 2007 9:06 AM, Jeroen Houben wrote: > > >> > > >> ... Just received the message by David. This will be fixed in 1.1.1 > > > > > > Jeroen - just for good measure, would you kindly update from trunk and > > > verify that it does in fact fix your issue? > > > > Finished in 3.42683 seconds > > > > 176 examples, 0 failures, 3 pending > > Thanks. I'll get the release out by tonight. > Awesome David. Do we have any specs that will catch this regression if it's reintroduced? Aslak > Cheers, > David > > > > > > :) > > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Mon Dec 17 11:58:34 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 17 Dec 2007 10:58:34 -0600 Subject: [rspec-users] Change in isolation behaviour 1.08 - 1.10 ? In-Reply-To: <8d961d900712170855j42d825c0h4417e9733187f915@mail.gmail.com> References: <57c63afe0712170658t6a331290k10ca69f3c06b8819@mail.gmail.com> <57c63afe0712170712p6234c966v80ba5c6b06c151b0@mail.gmail.com> <8d961d900712170855j42d825c0h4417e9733187f915@mail.gmail.com> Message-ID: <57c63afe0712170858u5b07440o215a734cb52005aa@mail.gmail.com> On Dec 17, 2007 10:55 AM, aslak hellesoy wrote: > On Dec 17, 2007 4:12 PM, David Chelimsky wrote: > > On Dec 17, 2007 9:06 AM, Jeroen Houben wrote: > > > >> > > > >> ... Just received the message by David. This will be fixed in 1.1.1 > > > > > > > > Jeroen - just for good measure, would you kindly update from trunk and > > > > verify that it does in fact fix your issue? > > > > > > Finished in 3.42683 seconds > > > > > > 176 examples, 0 failures, 3 pending > > > > Thanks. I'll get the release out by tonight. > > > > Awesome David. > > Do we have any specs that will catch this regression if it's reintroduced? I didn't look and don't have time right now. The fix was committed in r3158. Can you check the diff? > > Aslak > > > > Cheers, > > David > > > > > > > > > > :) > > > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From aslak.hellesoy at gmail.com Mon Dec 17 13:14:27 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Mon, 17 Dec 2007 19:14:27 +0100 Subject: [rspec-users] Change in isolation behaviour 1.08 - 1.10 ? In-Reply-To: <57c63afe0712170858u5b07440o215a734cb52005aa@mail.gmail.com> References: <57c63afe0712170658t6a331290k10ca69f3c06b8819@mail.gmail.com> <57c63afe0712170712p6234c966v80ba5c6b06c151b0@mail.gmail.com> <8d961d900712170855j42d825c0h4417e9733187f915@mail.gmail.com> <57c63afe0712170858u5b07440o215a734cb52005aa@mail.gmail.com> Message-ID: <8d961d900712171014q249f15efgbf59649762a85f11@mail.gmail.com> On Dec 17, 2007 5:58 PM, David Chelimsky wrote: > On Dec 17, 2007 10:55 AM, aslak hellesoy wrote: > > On Dec 17, 2007 4:12 PM, David Chelimsky wrote: > > > On Dec 17, 2007 9:06 AM, Jeroen Houben wrote: > > > > >> > > > > >> ... Just received the message by David. This will be fixed in 1.1.1 > > > > > > > > > > Jeroen - just for good measure, would you kindly update from trunk and > > > > > verify that it does in fact fix your issue? > > > > > > > > Finished in 3.42683 seconds > > > > > > > > 176 examples, 0 failures, 3 pending > > > > > > Thanks. I'll get the release out by tonight. > > > > > > > Awesome David. > > > > Do we have any specs that will catch this regression if it's reintroduced? > > I didn't look and don't have time right now. The fix was committed in > r3158. Can you check the diff? > I've added some more functional specs (r3172) that should prevent any transaction related bugs from coming back in. Jeroen - if you find more bugs, please report what Rails and Ruby versions you are using - it took me a while to realise that you were on Rails 1.2.3 (David told me) > > > > > Aslak > > > > > > > Cheers, > > > David > > > > > > > > > > > > > > :) > > > > > > > > > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Mon Dec 17 14:02:33 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Mon, 17 Dec 2007 14:02:33 -0500 Subject: [rspec-users] Mocks? Really? In-Reply-To: <1d7ddd110712170025n2bcbff61l969d60d7b852a495@mail.gmail.com> References: <139c56460712060856i6bb410fcl23def3b16c0388b4@mail.gmail.com> <57c63afe0712071840w13e8d2co85a60c00f3caefa9@mail.gmail.com> <810a540e0712142317t5e13f84dt2952986cd0a58a95@mail.gmail.com> <1d7ddd110712170025n2bcbff61l969d60d7b852a495@mail.gmail.com> Message-ID: <4488AB72-8E16-412D-82BD-3614A4A892F9@railsnewbie.com> On Dec 17, 2007, at 3:25 AM, Brian Takita wrote: > On Dec 16, 2007 7:43 PM, Scott Taylor > wrote: >> >> Francis and Pat probably know my thoughts on this, already, but as >> far as I can see it, mocks (at least the message based ones) are >> popular for one reason in the rails / active-record world: >> >> Speed. Mocks are extremely fast. I don't think it's uncommon for >> those who write specs for rails projects to have a full test suite >> running in under 20 seconds if they are mocking all dependencies. >> Primarily, this means using mocks for all associations on a Rails >> model, and using only mocks for controller specs. > My experience with AR is that AR itself (mainly object instantiation) > is slow, not the queries. > Mocking the queries did not result in a worthwhile test run time > savings. > Rails creates lots of objects, which causes lots of slowness. Its > death by a thousand cuts. > > I guess one could mock out the entire AR object, but I'm not convinced > that it would result in large performance benefits in many cases. > I've tried doing this a couple of times and did not save much time at > all. Of course, this was done in view examples on a project that uses > Markaby (which is slow). > > Whatever you do, I recommend taking performance metrics of your suite > as you try to diagnose the slowness. The results will probably be > surprising. Certainly. A lesson in premature optimization. Although, I did notice that my test suite took about half the time with an in-memory sqllite3 database, so I would find it hard to believe that most of the time is spent in object creation - but...off to do some benchmarking. Scott From smingins at elctech.com Mon Dec 17 15:55:26 2007 From: smingins at elctech.com (Shane Mingins) Date: Tue, 18 Dec 2007 09:55:26 +1300 Subject: [rspec-users] RSpec 1.1.0 (Rails) --- Supported Rails Versions? Message-ID: <9719FDC4-4901-4D61-BE59-98C005B45C6A@elctech.com> Hi Just a quick question .... what backward versions of Rails will the 1.1.0 versions of RSpec and Spec::Rails support? I think I maybe under the (incorrect) impression that I had to go to Rails 2.0 for 1.1.0 Cheers Shane Shane Mingins ELC Technologies (TM) 1921 State Street Santa Barbara, CA 93101 Phone: +64 4 568 6684 Mobile: +64 21 435 586 Email: smingins at elctech.com AIM: ShaneMingins Skype: shane.mingins (866) 863-7365 Tel - Santa Barbara Office (866) 893-1902 Fax - Santa Barbara Office +44 020 7504 1346 Tel - London Office +44 020 7504 1347 Fax - London Office http://www.elctech.com -------------------------------------------------------------------- Privacy and Confidentiality Notice: The information contained in this electronic mail message is intended for the named recipient(s) only. It may contain privileged and confidential information. If you are not an intended recipient, you must not copy, forward, distribute or take any action in reliance on it. If you have received this electronic mail message in error, please notify the sender immediately. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071218/3b9768a5/attachment.html From brian.takita at gmail.com Mon Dec 17 16:02:19 2007 From: brian.takita at gmail.com (Brian Takita) Date: Mon, 17 Dec 2007 13:02:19 -0800 Subject: [rspec-users] Mocks? Really? In-Reply-To: <4488AB72-8E16-412D-82BD-3614A4A892F9@railsnewbie.com> References: <139c56460712060856i6bb410fcl23def3b16c0388b4@mail.gmail.com> <57c63afe0712071840w13e8d2co85a60c00f3caefa9@mail.gmail.com> <810a540e0712142317t5e13f84dt2952986cd0a58a95@mail.gmail.com> <1d7ddd110712170025n2bcbff61l969d60d7b852a495@mail.gmail.com> <4488AB72-8E16-412D-82BD-3614A4A892F9@railsnewbie.com> Message-ID: <1d7ddd110712171302ub38abd7s30898f5a436053d5@mail.gmail.com> On Dec 17, 2007 11:02 AM, Scott Taylor wrote: > > > On Dec 17, 2007, at 3:25 AM, Brian Takita wrote: > > > On Dec 16, 2007 7:43 PM, Scott Taylor > > wrote: > >> > >> Francis and Pat probably know my thoughts on this, already, but as > >> far as I can see it, mocks (at least the message based ones) are > >> popular for one reason in the rails / active-record world: > >> > >> Speed. Mocks are extremely fast. I don't think it's uncommon for > >> those who write specs for rails projects to have a full test suite > >> running in under 20 seconds if they are mocking all dependencies. > >> Primarily, this means using mocks for all associations on a Rails > >> model, and using only mocks for controller specs. > > My experience with AR is that AR itself (mainly object instantiation) > > is slow, not the queries. > > Mocking the queries did not result in a worthwhile test run time > > savings. > > Rails creates lots of objects, which causes lots of slowness. Its > > death by a thousand cuts. > > > > I guess one could mock out the entire AR object, but I'm not convinced > > that it would result in large performance benefits in many cases. > > I've tried doing this a couple of times and did not save much time at > > all. Of course, this was done in view examples on a project that uses > > Markaby (which is slow). > > > > Whatever you do, I recommend taking performance metrics of your suite > > as you try to diagnose the slowness. The results will probably be > > surprising. > > Certainly. A lesson in premature optimization. Although, I did > notice that > my test suite took about half the time with an in-memory sqllite3 > database, > so I would find it hard to believe that most of the time is spent in > object > creation - but...off to do some benchmarking. True. I also did some custom fixture optimizations. For some reason, instantiating a Fixture object instance is very slow. I've rigged it so there is only one instance of a Fixture object for each table for the entire process. Of course this would break fixture scenarios. I've had around 20-30% increases using in memory sqllite, about 1 year ago. I havn't tried it since. > > Scott > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Mon Dec 17 16:08:32 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 17 Dec 2007 15:08:32 -0600 Subject: [rspec-users] Mocks? Really? In-Reply-To: <1d7ddd110712171302ub38abd7s30898f5a436053d5@mail.gmail.com> References: <139c56460712060856i6bb410fcl23def3b16c0388b4@mail.gmail.com> <810a540e0712142317t5e13f84dt2952986cd0a58a95@mail.gmail.com> <1d7ddd110712170025n2bcbff61l969d60d7b852a495@mail.gmail.com> <4488AB72-8E16-412D-82BD-3614A4A892F9@railsnewbie.com> <1d7ddd110712171302ub38abd7s30898f5a436053d5@mail.gmail.com> Message-ID: <57c63afe0712171308kcb89d36g8082093a53bdf310@mail.gmail.com> On Dec 17, 2007 3:02 PM, Brian Takita wrote: > > On Dec 17, 2007 11:02 AM, Scott Taylor wrote: > > > > > > On Dec 17, 2007, at 3:25 AM, Brian Takita wrote: > > > > > On Dec 16, 2007 7:43 PM, Scott Taylor > > > wrote: > > >> > > >> Francis and Pat probably know my thoughts on this, already, but as > > >> far as I can see it, mocks (at least the message based ones) are > > >> popular for one reason in the rails / active-record world: > > >> > > >> Speed. Mocks are extremely fast. I don't think it's uncommon for > > >> those who write specs for rails projects to have a full test suite > > >> running in under 20 seconds if they are mocking all dependencies. > > >> Primarily, this means using mocks for all associations on a Rails > > >> model, and using only mocks for controller specs. > > > My experience with AR is that AR itself (mainly object instantiation) > > > is slow, not the queries. > > > Mocking the queries did not result in a worthwhile test run time > > > savings. > > > Rails creates lots of objects, which causes lots of slowness. Its > > > death by a thousand cuts. > > > > > > I guess one could mock out the entire AR object, but I'm not convinced > > > that it would result in large performance benefits in many cases. > > > I've tried doing this a couple of times and did not save much time at > > > all. Of course, this was done in view examples on a project that uses > > > Markaby (which is slow). > > > > > > Whatever you do, I recommend taking performance metrics of your suite > > > as you try to diagnose the slowness. The results will probably be > > > surprising. > > > > Certainly. A lesson in premature optimization. Although, I did > > notice that > > my test suite took about half the time with an in-memory sqllite3 > > database, > > so I would find it hard to believe that most of the time is spent in > > object > > creation - but...off to do some benchmarking. > True. I also did some custom fixture optimizations. For some reason, > instantiating a Fixture object instance is very slow. I've rigged it > so there is only one instance of a Fixture object for each table for > the entire process. > Of course this would break fixture scenarios. Did you do that in rspec? Or in your own project? > > I've had around 20-30% increases using in memory sqllite, about 1 year > ago. I havn't tried it since. > > > > > 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 aslak.hellesoy at gmail.com Mon Dec 17 16:10:45 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Mon, 17 Dec 2007 22:10:45 +0100 Subject: [rspec-users] RSpec 1.1.0 (Rails) --- Supported Rails Versions? In-Reply-To: <9719FDC4-4901-4D61-BE59-98C005B45C6A@elctech.com> References: <9719FDC4-4901-4D61-BE59-98C005B45C6A@elctech.com> Message-ID: <8d961d900712171310pfa26ad8x27737d067011f490@mail.gmail.com> On Dec 17, 2007 9:55 PM, Shane Mingins wrote: > Hi > > > Just a quick question .... what backward versions of Rails will the 1.1.0 > versions of RSpec and Spec::Rails support? > RSpec 1.1.0 is tested against Rails 1.2.3, 1.2.5, 1.2.6 and 2.0.1 It might also work with 1.2.4 It worked with edge Rails when we released it, but since that's a moving target it might break at any time. Aslak > I think I maybe under the (incorrect) impression that I had to go to Rails > 2.0 for 1.1.0 > > Cheers > Shane > > > Shane Mingins > ELC Technologies (TM) > 1921 State Street > Santa Barbara, CA 93101 > > > Phone: +64 4 568 6684 > Mobile: +64 21 435 586 > Email: smingins at elctech.com > AIM: ShaneMingins > Skype: shane.mingins > > (866) 863-7365 Tel - Santa Barbara Office > (866) 893-1902 Fax - Santa Barbara Office > > +44 020 7504 1346 Tel - London Office > +44 020 7504 1347 Fax - London Office > > http://www.elctech.com > > -------------------------------------------------------------------- > Privacy and Confidentiality Notice: > The information contained in this electronic mail message is intended for > the named recipient(s) only. It may contain privileged and confidential > information. If you are not an intended recipient, you > must not copy, forward, distribute or take any action in reliance on it. If > you have received this electronic mail message in error, please notify the > sender immediately. > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From brian.takita at gmail.com Mon Dec 17 16:10:53 2007 From: brian.takita at gmail.com (Brian Takita) Date: Mon, 17 Dec 2007 13:10:53 -0800 Subject: [rspec-users] Mocks? Really? In-Reply-To: <57c63afe0712171308kcb89d36g8082093a53bdf310@mail.gmail.com> References: <139c56460712060856i6bb410fcl23def3b16c0388b4@mail.gmail.com> <810a540e0712142317t5e13f84dt2952986cd0a58a95@mail.gmail.com> <1d7ddd110712170025n2bcbff61l969d60d7b852a495@mail.gmail.com> <4488AB72-8E16-412D-82BD-3614A4A892F9@railsnewbie.com> <1d7ddd110712171302ub38abd7s30898f5a436053d5@mail.gmail.com> <57c63afe0712171308kcb89d36g8082093a53bdf310@mail.gmail.com> Message-ID: <1d7ddd110712171310r63a1b95i1de7c0e10396439f@mail.gmail.com> On Dec 17, 2007 1:08 PM, David Chelimsky wrote: > > On Dec 17, 2007 3:02 PM, Brian Takita wrote: > > > > On Dec 17, 2007 11:02 AM, Scott Taylor wrote: > > > > > > > > > On Dec 17, 2007, at 3:25 AM, Brian Takita wrote: > > > > > > > On Dec 16, 2007 7:43 PM, Scott Taylor > > > > wrote: > > > >> > > > >> Francis and Pat probably know my thoughts on this, already, but as > > > >> far as I can see it, mocks (at least the message based ones) are > > > >> popular for one reason in the rails / active-record world: > > > >> > > > >> Speed. Mocks are extremely fast. I don't think it's uncommon for > > > >> those who write specs for rails projects to have a full test suite > > > >> running in under 20 seconds if they are mocking all dependencies. > > > >> Primarily, this means using mocks for all associations on a Rails > > > >> model, and using only mocks for controller specs. > > > > My experience with AR is that AR itself (mainly object instantiation) > > > > is slow, not the queries. > > > > Mocking the queries did not result in a worthwhile test run time > > > > savings. > > > > Rails creates lots of objects, which causes lots of slowness. Its > > > > death by a thousand cuts. > > > > > > > > I guess one could mock out the entire AR object, but I'm not convinced > > > > that it would result in large performance benefits in many cases. > > > > I've tried doing this a couple of times and did not save much time at > > > > all. Of course, this was done in view examples on a project that uses > > > > Markaby (which is slow). > > > > > > > > Whatever you do, I recommend taking performance metrics of your suite > > > > as you try to diagnose the slowness. The results will probably be > > > > surprising. > > > > > > Certainly. A lesson in premature optimization. Although, I did > > > notice that > > > my test suite took about half the time with an in-memory sqllite3 > > > database, > > > so I would find it hard to believe that most of the time is spent in > > > object > > > creation - but...off to do some benchmarking. > > True. I also did some custom fixture optimizations. For some reason, > > instantiating a Fixture object instance is very slow. I've rigged it > > so there is only one instance of a Fixture object for each table for > > the entire process. > > Of course this would break fixture scenarios. > > Did you do that in rspec? Or in your own project? My own project. I overrode Test::Unit::TestCase @@already_loaded_fixtures with a shim. > > > > > > I've had around 20-30% increases using in memory sqllite, about 1 year > > ago. I havn't tried it since. > > > > > > > > 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 smingins at elctech.com Mon Dec 17 16:15:58 2007 From: smingins at elctech.com (Shane Mingins) Date: Tue, 18 Dec 2007 10:15:58 +1300 Subject: [rspec-users] RSpec 1.1.0 (Rails) --- Supported Rails Versions? In-Reply-To: <8d961d900712171310pfa26ad8x27737d067011f490@mail.gmail.com> References: <9719FDC4-4901-4D61-BE59-98C005B45C6A@elctech.com> <8d961d900712171310pfa26ad8x27737d067011f490@mail.gmail.com> Message-ID: <7570EFF1-9748-4451-8AA4-EF6909840C76@elctech.com> On 18/12/2007, at 10:10 AM, aslak hellesoy wrote: > RSpec 1.1.0 is tested against Rails 1.2.3, 1.2.5, 1.2.6 and 2.0.1 Thanks Aslak for the confirm :-) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071218/2cbf4193/attachment.html From mailing_lists at railsnewbie.com Mon Dec 17 16:29:50 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Mon, 17 Dec 2007 16:29:50 -0500 Subject: [rspec-users] Mocks? Really? In-Reply-To: <1d7ddd110712171302ub38abd7s30898f5a436053d5@mail.gmail.com> References: <139c56460712060856i6bb410fcl23def3b16c0388b4@mail.gmail.com> <57c63afe0712071840w13e8d2co85a60c00f3caefa9@mail.gmail.com> <810a540e0712142317t5e13f84dt2952986cd0a58a95@mail.gmail.com> <1d7ddd110712170025n2bcbff61l969d60d7b852a495@mail.gmail.com> <4488AB72-8E16-412D-82BD-3614A4A892F9@railsnewbie.com> <1d7ddd110712171302ub38abd7s30898f5a436053d5@mail.gmail.com> Message-ID: > True. I also did some custom fixture optimizations. For some reason, > instantiating a Fixture object instance is very slow. I've rigged it > so there is only one instance of a Fixture object for each table for > the entire process. > Of course this would break fixture scenarios. > > I've had around 20-30% increases using in memory sqllite, about 1 year > ago. I havn't tried it since. Interesting. I'm not using Fixtures, so I guess this isn't an option for me. (I need to figure out a way to speed up FixtureReplacement). What was so slow in the fixture instantiation? Scott From brian.takita at gmail.com Mon Dec 17 16:42:26 2007 From: brian.takita at gmail.com (Brian Takita) Date: Mon, 17 Dec 2007 13:42:26 -0800 Subject: [rspec-users] Mocks? Really? In-Reply-To: References: <139c56460712060856i6bb410fcl23def3b16c0388b4@mail.gmail.com> <810a540e0712142317t5e13f84dt2952986cd0a58a95@mail.gmail.com> <1d7ddd110712170025n2bcbff61l969d60d7b852a495@mail.gmail.com> <4488AB72-8E16-412D-82BD-3614A4A892F9@railsnewbie.com> <1d7ddd110712171302ub38abd7s30898f5a436053d5@mail.gmail.com> Message-ID: <1d7ddd110712171342w560e6fe8offe010d88042e997@mail.gmail.com> On Dec 17, 2007 1:29 PM, Scott Taylor wrote: > > > > True. I also did some custom fixture optimizations. For some reason, > > instantiating a Fixture object instance is very slow. I've rigged it > > so there is only one instance of a Fixture object for each table for > > the entire process. > > Of course this would break fixture scenarios. > > > > I've had around 20-30% increases using in memory sqllite, about 1 year > > ago. I havn't tried it since. > > Interesting. I'm not using Fixtures, so I guess this isn't an option > for me. (I need to figure out a way to speed up FixtureReplacement). > > What was so slow in the fixture instantiation? I didn't isolate what about fixture instantiation was slow. It reads the yaml files and converts the hash into objects. All I know is when I did the optimization, I got around a 30% performance increase when loading all fixtures in all Examples. > > > Scott > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Mon Dec 17 17:08:56 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Mon, 17 Dec 2007 17:08:56 -0500 Subject: [rspec-users] Mocks? Really? In-Reply-To: <1d7ddd110712171342w560e6fe8offe010d88042e997@mail.gmail.com> References: <139c56460712060856i6bb410fcl23def3b16c0388b4@mail.gmail.com> <810a540e0712142317t5e13f84dt2952986cd0a58a95@mail.gmail.com> <1d7ddd110712170025n2bcbff61l969d60d7b852a495@mail.gmail.com> <4488AB72-8E16-412D-82BD-3614A4A892F9@railsnewbie.com> <1d7ddd110712171302ub38abd7s30898f5a436053d5@mail.gmail.com> <1d7ddd110712171342w560e6fe8offe010d88042e997@mail.gmail.com> Message-ID: <960F4937-E325-44F1-AA90-CA365190F3F1@railsnewbie.com> On Dec 17, 2007, at 4:42 PM, Brian Takita wrote: > On Dec 17, 2007 1:29 PM, Scott Taylor > wrote: >> >> >>> True. I also did some custom fixture optimizations. For some reason, >>> instantiating a Fixture object instance is very slow. I've rigged it >>> so there is only one instance of a Fixture object for each table for >>> the entire process. >>> Of course this would break fixture scenarios. >>> >>> I've had around 20-30% increases using in memory sqllite, about 1 >>> year >>> ago. I havn't tried it since. >> >> Interesting. I'm not using Fixtures, so I guess this isn't an option >> for me. (I need to figure out a way to speed up FixtureReplacement). >> >> What was so slow in the fixture instantiation? > I didn't isolate what about fixture instantiation was slow. It reads > the yaml files and converts the hash into objects. > All I know is when I did the optimization, I got around a 30% > performance increase when loading all fixtures in all Examples. I assume you were using instantiated fixtures, and not transactional fixtures? Scott From brian.takita at gmail.com Mon Dec 17 19:59:20 2007 From: brian.takita at gmail.com (Brian Takita) Date: Mon, 17 Dec 2007 16:59:20 -0800 Subject: [rspec-users] Mocks? Really? In-Reply-To: <960F4937-E325-44F1-AA90-CA365190F3F1@railsnewbie.com> References: <139c56460712060856i6bb410fcl23def3b16c0388b4@mail.gmail.com> <1d7ddd110712170025n2bcbff61l969d60d7b852a495@mail.gmail.com> <4488AB72-8E16-412D-82BD-3614A4A892F9@railsnewbie.com> <1d7ddd110712171302ub38abd7s30898f5a436053d5@mail.gmail.com> <1d7ddd110712171342w560e6fe8offe010d88042e997@mail.gmail.com> <960F4937-E325-44F1-AA90-CA365190F3F1@railsnewbie.com> Message-ID: <1d7ddd110712171659l323a44e4we5a97772ce84fd26@mail.gmail.com> On Dec 17, 2007 2:08 PM, Scott Taylor wrote: > > On Dec 17, 2007, at 4:42 PM, Brian Takita wrote: > > > On Dec 17, 2007 1:29 PM, Scott Taylor > > wrote: > >> > >> > >>> True. I also did some custom fixture optimizations. For some reason, > >>> instantiating a Fixture object instance is very slow. I've rigged it > >>> so there is only one instance of a Fixture object for each table for > >>> the entire process. > >>> Of course this would break fixture scenarios. > >>> > >>> I've had around 20-30% increases using in memory sqllite, about 1 > >>> year > >>> ago. I havn't tried it since. > >> > >> Interesting. I'm not using Fixtures, so I guess this isn't an option > >> for me. (I need to figure out a way to speed up FixtureReplacement). > >> > >> What was so slow in the fixture instantiation? > > I didn't isolate what about fixture instantiation was slow. It reads > > the yaml files and converts the hash into objects. > > All I know is when I did the optimization, I got around a 30% > > performance increase when loading all fixtures in all Examples. > > I assume you were using instantiated fixtures, and not transactional > fixtures? I was using transactional fixtures. This was before Rails 2.0 fixture optimizations, so I'm not sure if the same applies today. > > > Scott > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From JONATHAN at LINOWES.COM Tue Dec 18 12:39:33 2007 From: JONATHAN at LINOWES.COM (Jonathan Linowes) Date: Tue, 18 Dec 2007 12:39:33 -0500 Subject: [rspec-users] shared behav Message-ID: <505B52E3-039A-4AD6-A897-7B72AAA3DC89@LINOWES.COM> hi, i want to make a behavior shared between models, the examples need to create new instances etc. Is there a way to pass the model class to the shared behavior? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071218/5b400cc5/attachment-0001.html From erik at solidcode.net Fri Dec 14 07:20:48 2007 From: erik at solidcode.net (Erik Terpstra) Date: Fri, 14 Dec 2007 13:20:48 +0100 Subject: [rspec-users] Vim integration. Message-ID: <47627520.2070904@solidcode.net> Hi, Does anybody have a vim script that enables me to run specs from within vim and have the cursor positioned on the right line in case of a backtrace? TIA, Erik. From dchelimsky at gmail.com Tue Dec 18 16:36:40 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 18 Dec 2007 15:36:40 -0600 Subject: [rspec-users] shared behav In-Reply-To: <505B52E3-039A-4AD6-A897-7B72AAA3DC89@LINOWES.COM> References: <505B52E3-039A-4AD6-A897-7B72AAA3DC89@LINOWES.COM> Message-ID: <57c63afe0712181336s3038deb4v1c0194f8bf6a0926@mail.gmail.com> On Dec 18, 2007 11:39 AM, Jonathan Linowes wrote: > > hi, i want to make a behavior shared between models, the examples need to > create new instances etc. Is there a way to pass the model class to the > shared behavior? We're calling these shared example groups now. The way to affect the state within a shared example group is to use before(:each) to set an instance variable: shared_examples_for "models that do stuff" do before(:each) do @instance = @class.new end it "should do something" do @instance.should do_something end end describe Foo do before(:each) do @class = Foo end it_should_behave_like "models that do stuff" end Cheers, David > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Tue Dec 18 16:37:39 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Tue, 18 Dec 2007 16:37:39 -0500 Subject: [rspec-users] shared behav In-Reply-To: <505B52E3-039A-4AD6-A897-7B72AAA3DC89@LINOWES.COM> References: <505B52E3-039A-4AD6-A897-7B72AAA3DC89@LINOWES.COM> Message-ID: <25B2FCA2-6BA4-40BD-A8F0-0FBC3E69DEC5@railsnewbie.com> On Dec 18, 2007, at 12:39 PM, Jonathan Linowes wrote: > hi, i want to make a behavior shared between models, the examples > need to create new instances etc. Is there a way to pass the model > class to the shared behavior? Nope. The only way to do it right now is with an instance variable. The shared behaviours can be thought of modules which are included into the current behaviour - so it should also have access to any methods defined in the example (group) in which it is shared. Scott -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071218/55e1b41b/attachment.html From dchelimsky at gmail.com Tue Dec 18 16:42:36 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 18 Dec 2007 15:42:36 -0600 Subject: [rspec-users] shared behav In-Reply-To: <25B2FCA2-6BA4-40BD-A8F0-0FBC3E69DEC5@railsnewbie.com> References: <505B52E3-039A-4AD6-A897-7B72AAA3DC89@LINOWES.COM> <25B2FCA2-6BA4-40BD-A8F0-0FBC3E69DEC5@railsnewbie.com> Message-ID: <57c63afe0712181342p697529c6i45dfeab2d6901225@mail.gmail.com> On Dec 18, 2007 3:37 PM, Scott Taylor wrote: > The > shared behaviours can be thought of modules which are included into the > current behaviour - so it should also have access to any methods defined in > the example (group) in which it is shared. You don't even have to think of it that way - that's actually what they are - modules that get included. You can actually assign them to a constant and just use Ruby include. From mailing_lists at railsnewbie.com Tue Dec 18 16:53:49 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Tue, 18 Dec 2007 16:53:49 -0500 Subject: [rspec-users] shared behav In-Reply-To: <57c63afe0712181342p697529c6i45dfeab2d6901225@mail.gmail.com> References: <505B52E3-039A-4AD6-A897-7B72AAA3DC89@LINOWES.COM> <25B2FCA2-6BA4-40BD-A8F0-0FBC3E69DEC5@railsnewbie.com> <57c63afe0712181342p697529c6i45dfeab2d6901225@mail.gmail.com> Message-ID: <2F10E44D-CBCB-48D4-BF6D-3F5C600614DD@railsnewbie.com> On Dec 18, 2007, at 4:42 PM, David Chelimsky wrote: > On Dec 18, 2007 3:37 PM, Scott Taylor > wrote: >> The >> shared behaviours can be thought of modules which are included >> into the >> current behaviour - so it should also have access to any methods >> defined in >> the example (group) in which it is shared. > > You don't even have to think of it that way - that's actually what > they are - modules that get included. You can actually assign them to > a constant and just use Ruby include. Although we've talked about the implementation changing, which would cause those who use them as modules to have broken specs. Scott From dchelimsky at gmail.com Tue Dec 18 17:12:14 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 18 Dec 2007 16:12:14 -0600 Subject: [rspec-users] shared behav In-Reply-To: <2F10E44D-CBCB-48D4-BF6D-3F5C600614DD@railsnewbie.com> References: <505B52E3-039A-4AD6-A897-7B72AAA3DC89@LINOWES.COM> <25B2FCA2-6BA4-40BD-A8F0-0FBC3E69DEC5@railsnewbie.com> <57c63afe0712181342p697529c6i45dfeab2d6901225@mail.gmail.com> <2F10E44D-CBCB-48D4-BF6D-3F5C600614DD@railsnewbie.com> Message-ID: <57c63afe0712181412l28bae885rb80ddcd078a697fb@mail.gmail.com> On Dec 18, 2007 3:53 PM, Scott Taylor wrote: > > > On Dec 18, 2007, at 4:42 PM, David Chelimsky wrote: > > > On Dec 18, 2007 3:37 PM, Scott Taylor > > wrote: > >> The > >> shared behaviours can be thought of modules which are included > >> into the > >> current behaviour - so it should also have access to any methods > >> defined in > >> the example (group) in which it is shared. > > > > You don't even have to think of it that way - that's actually what > > they are - modules that get included. You can actually assign them to > > a constant and just use Ruby include. > > Although we've talked about the implementation changing, which would > cause those who use them as modules to have broken specs. It would, but we stopped talking about it :) It actually works quite well this way. The change came up, iirc, in the conversation about parameterizing it_should_behave_like, right? I've got a solution for that worked out, but I haven't applied it yet because I want to discuss it a bit: You'd use it like this: shared_examples_for "anything" do it "should do stuff" do @thing.should do_stuff end end describe SpecificThing do it_should_behave_like "anything", :thing => SpecificThing.new end Now comes the tricky part. This can work one of two ways. In either case it turns :thing into an instance variable @thing. The question is whether that instance variable is assigned in the scope of the SpecificThing example group or in a scope created especially to run the shared examples. Each choice presents usability confusion in my view. Imagine this scenario: shared_examples_for "anything" do it "should do stuff" do @thing.should do_stuff end it "should be like another thing" do @thing.should be_like(@other_thing) end end describe SpecificThing do before(:each) do @thing = SpecificThing.new end it_should_behave_like "anything", :other_thing => SpecificThing.new it "should not be unlike other thing" do @thing.should_not be_unlike(@other_thing) end end If @other_thing is defined in the context of a separate scope just to run the shared examples, the shared examples won't know about @thing. If @other_thing in the scope of the example group created by "describe SpecificThing," then it's just confusing to look at - both before(:each) and it_should_behave_like are creating instance variables in the current scope, and it is NOT clear that is what is happening. If we go w/ the separate scope, then the metaphor of it_should_behave_like is wrong, because we're not talking about something in the current scope that should behave like something else anymore. We'd probably want a different construct to create these, even though the underlying mechanism would be the same. Thoughts? David From mailing_lists at railsnewbie.com Tue Dec 18 17:22:46 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Tue, 18 Dec 2007 17:22:46 -0500 Subject: [rspec-users] shared behav In-Reply-To: <57c63afe0712181412l28bae885rb80ddcd078a697fb@mail.gmail.com> References: <505B52E3-039A-4AD6-A897-7B72AAA3DC89@LINOWES.COM> <25B2FCA2-6BA4-40BD-A8F0-0FBC3E69DEC5@railsnewbie.com> <57c63afe0712181342p697529c6i45dfeab2d6901225@mail.gmail.com> <2F10E44D-CBCB-48D4-BF6D-3F5C600614DD@railsnewbie.com> <57c63afe0712181412l28bae885rb80ddcd078a697fb@mail.gmail.com> Message-ID: <05E0DF41-A55B-4024-8E24-EF8430EBE513@railsnewbie.com> On Dec 18, 2007, at 5:12 PM, David Chelimsky wrote: > On Dec 18, 2007 3:53 PM, Scott Taylor > wrote: >> >> >> On Dec 18, 2007, at 4:42 PM, David Chelimsky wrote: >> >>> On Dec 18, 2007 3:37 PM, Scott Taylor >>> wrote: >>>> The >>>> shared behaviours can be thought of modules which are included >>>> into the >>>> current behaviour - so it should also have access to any methods >>>> defined in >>>> the example (group) in which it is shared. >>> >>> You don't even have to think of it that way - that's actually what >>> they are - modules that get included. You can actually assign >>> them to >>> a constant and just use Ruby include. >> >> Although we've talked about the implementation changing, which would >> cause those who use them as modules to have broken specs. > > It would, but we stopped talking about it :) > > It actually works quite well this way. The change came up, iirc, in > the conversation about parameterizing it_should_behave_like, right? > I've got a solution for that worked out, but I haven't applied it yet > because I want to discuss it a bit: > > You'd use it like this: > > shared_examples_for "anything" do > it "should do stuff" do > @thing.should do_stuff > end > end > > describe SpecificThing do > it_should_behave_like "anything", :thing => SpecificThing.new > end > > Now comes the tricky part. This can work one of two ways. In either > case it turns :thing into an instance variable @thing. The question is > whether that instance variable is assigned in the scope of the > SpecificThing example group or in a scope created especially to run > the shared examples. Each choice presents usability confusion in my > view. > > Imagine this scenario: > > shared_examples_for "anything" do > it "should do stuff" do > @thing.should do_stuff > end > it "should be like another thing" do > @thing.should be_like(@other_thing) > end > end > > describe SpecificThing do > before(:each) do > @thing = SpecificThing.new > end > it_should_behave_like "anything", :other_thing => SpecificThing.new > > it "should not be unlike other thing" do > @thing.should_not be_unlike(@other_thing) > end > end > > If @other_thing is defined in the context of a separate scope just to > run the shared examples, the shared examples won't know about @thing. > > If @other_thing in the scope of the example group created by "describe > SpecificThing," then it's just confusing to look at - both > before(:each) and it_should_behave_like are creating instance > variables in the current scope, and it is NOT clear that is what is > happening. > > If we go w/ the separate scope, then the metaphor of > it_should_behave_like is wrong, because we're not talking about > something in the current scope that should behave like something else > anymore. We'd probably want a different construct to create these, > even though the underlying mechanism would be the same. > > Thoughts? How about this: Use a separate scope, but copy the instance variables from the calling example group. Any parameters passed into the shared example group will be methods which wrap the values given. This way we don't have instance variable naming conflicts (like @other_thing, in the example above). On the other hand, this would also mean that shared example groups wouldn't have the ability to call methods in the calling example group. Thoughts? Scott From dchelimsky at gmail.com Tue Dec 18 17:25:29 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 18 Dec 2007 16:25:29 -0600 Subject: [rspec-users] shared behav In-Reply-To: <05E0DF41-A55B-4024-8E24-EF8430EBE513@railsnewbie.com> References: <505B52E3-039A-4AD6-A897-7B72AAA3DC89@LINOWES.COM> <25B2FCA2-6BA4-40BD-A8F0-0FBC3E69DEC5@railsnewbie.com> <57c63afe0712181342p697529c6i45dfeab2d6901225@mail.gmail.com> <2F10E44D-CBCB-48D4-BF6D-3F5C600614DD@railsnewbie.com> <57c63afe0712181412l28bae885rb80ddcd078a697fb@mail.gmail.com> <05E0DF41-A55B-4024-8E24-EF8430EBE513@railsnewbie.com> Message-ID: <57c63afe0712181425y3946922bl18e68d461d9082ad@mail.gmail.com> On Dec 18, 2007 4:22 PM, Scott Taylor wrote: > > > On Dec 18, 2007, at 5:12 PM, David Chelimsky wrote: > > > On Dec 18, 2007 3:53 PM, Scott Taylor > > wrote: > >> > >> > >> On Dec 18, 2007, at 4:42 PM, David Chelimsky wrote: > >> > >>> On Dec 18, 2007 3:37 PM, Scott Taylor > >>> wrote: > >>>> The > >>>> shared behaviours can be thought of modules which are included > >>>> into the > >>>> current behaviour - so it should also have access to any methods > >>>> defined in > >>>> the example (group) in which it is shared. > >>> > >>> You don't even have to think of it that way - that's actually what > >>> they are - modules that get included. You can actually assign > >>> them to > >>> a constant and just use Ruby include. > >> > >> Although we've talked about the implementation changing, which would > >> cause those who use them as modules to have broken specs. > > > > It would, but we stopped talking about it :) > > > > It actually works quite well this way. The change came up, iirc, in > > the conversation about parameterizing it_should_behave_like, right? > > I've got a solution for that worked out, but I haven't applied it yet > > because I want to discuss it a bit: > > > > You'd use it like this: > > > > shared_examples_for "anything" do > > it "should do stuff" do > > @thing.should do_stuff > > end > > end > > > > describe SpecificThing do > > it_should_behave_like "anything", :thing => SpecificThing.new > > end > > > > Now comes the tricky part. This can work one of two ways. In either > > case it turns :thing into an instance variable @thing. The question is > > whether that instance variable is assigned in the scope of the > > SpecificThing example group or in a scope created especially to run > > the shared examples. Each choice presents usability confusion in my > > view. > > > > Imagine this scenario: > > > > shared_examples_for "anything" do > > it "should do stuff" do > > @thing.should do_stuff > > end > > it "should be like another thing" do > > @thing.should be_like(@other_thing) > > end > > end > > > > describe SpecificThing do > > before(:each) do > > @thing = SpecificThing.new > > end > > it_should_behave_like "anything", :other_thing => SpecificThing.new > > > > it "should not be unlike other thing" do > > @thing.should_not be_unlike(@other_thing) > > end > > end > > > > If @other_thing is defined in the context of a separate scope just to > > run the shared examples, the shared examples won't know about @thing. > > > > If @other_thing in the scope of the example group created by "describe > > SpecificThing," then it's just confusing to look at - both > > before(:each) and it_should_behave_like are creating instance > > variables in the current scope, and it is NOT clear that is what is > > happening. > > > > If we go w/ the separate scope, then the metaphor of > > it_should_behave_like is wrong, because we're not talking about > > something in the current scope that should behave like something else > > anymore. We'd probably want a different construct to create these, > > even though the underlying mechanism would be the same. > > > > Thoughts? > > > How about this: > > Use a separate scope, but copy the instance variables from the > calling example group. Any parameters passed into the shared example > group will be methods which wrap the values given. This way we > don't have instance variable naming conflicts (like @other_thing, in > the example above). > > On the other hand, this would also mean that shared example groups > wouldn't have the ability to call methods in the calling example group. > > Thoughts? Copying instance variables around is nasty business. In fact, we eliminated that from shared behaviours by making them modules that get included! So I would view that as a step backwards from an implementation standpoint, and it still feels like voodoo from a usability standpoint. > > > Scott > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From rick.denatale at gmail.com Tue Dec 18 17:30:54 2007 From: rick.denatale at gmail.com (Rick DeNatale) Date: Tue, 18 Dec 2007 17:30:54 -0500 Subject: [rspec-users] shared behav In-Reply-To: <57c63afe0712181336s3038deb4v1c0194f8bf6a0926@mail.gmail.com> References: <505B52E3-039A-4AD6-A897-7B72AAA3DC89@LINOWES.COM> <57c63afe0712181336s3038deb4v1c0194f8bf6a0926@mail.gmail.com> Message-ID: On 12/18/07, David Chelimsky wrote: > On Dec 18, 2007 11:39 AM, Jonathan Linowes wrote: > > > > hi, i want to make a behavior shared between models, the examples need to > > create new instances etc. Is there a way to pass the model class to the > > shared behavior? > > We're calling these shared example groups now. > > The way to affect the state within a shared example group is to use > before(:each) to set an instance variable: > > shared_examples_for "models that do stuff" do > before(:each) do > @instance = @class.new > end > it "should do something" do > @instance.should do_something > end > end > > describe Foo do > before(:each) do > @class = Foo > end > it_should_behave_like "models that do stuff" > end So I guess this means that the before block for the shared example group gets executed after the example group using it. I don't recall seeing this documented, although I'm sure that it is. This helps me a lot. Can you do something similar with the new nested example groups? It doesn't seem so. describe "Shared", :shared => true do before(:each) do @outer = @inner end it "should set @outer to @inner" do @outer.should == @inner end end describe "Sharer" do it_should_behave_like "Shared" it "should set @outer to 1" do @inner = 1 end end describe "Outer" do before(:each) do @outer = @inner end describe "inner one" do before(:each) do @inner = 1 end it "should be set outer to 1" do @outer.should == 1 end end describe "inner two" do before(:each) do @inner = 2 end it "should be set outer to 1" do @outer.should == 2 end end end k$ spec ~/nestedspec.rb FF.. 1) 'inner one should be set outer to 1' FAILED expected: 1, got: nil (using ==) /Users/rick/nestedspec.rb:16: 2) 'inner two should be set outer to 1' FAILED expected: 2, got: nil (using ==) /Users/rick/nestedspec.rb:26: Finished in 0.00627 seconds 4 examples, 2 failures -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From dchelimsky at gmail.com Tue Dec 18 17:31:01 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 18 Dec 2007 16:31:01 -0600 Subject: [rspec-users] shared behav In-Reply-To: <57c63afe0712181425y3946922bl18e68d461d9082ad@mail.gmail.com> References: <505B52E3-039A-4AD6-A897-7B72AAA3DC89@LINOWES.COM> <25B2FCA2-6BA4-40BD-A8F0-0FBC3E69DEC5@railsnewbie.com> <57c63afe0712181342p697529c6i45dfeab2d6901225@mail.gmail.com> <2F10E44D-CBCB-48D4-BF6D-3F5C600614DD@railsnewbie.com> <57c63afe0712181412l28bae885rb80ddcd078a697fb@mail.gmail.com> <05E0DF41-A55B-4024-8E24-EF8430EBE513@railsnewbie.com> <57c63afe0712181425y3946922bl18e68d461d9082ad@mail.gmail.com> Message-ID: <57c63afe0712181431y74632537r66c69f80cafc5efb@mail.gmail.com> On Dec 18, 2007 4:25 PM, David Chelimsky wrote: > > On Dec 18, 2007 4:22 PM, Scott Taylor wrote: > > > > > > On Dec 18, 2007, at 5:12 PM, David Chelimsky wrote: > > > > > On Dec 18, 2007 3:53 PM, Scott Taylor > > > wrote: > > >> > > >> > > >> On Dec 18, 2007, at 4:42 PM, David Chelimsky wrote: > > >> > > >>> On Dec 18, 2007 3:37 PM, Scott Taylor > > >>> wrote: > > >>>> The > > >>>> shared behaviours can be thought of modules which are included > > >>>> into the > > >>>> current behaviour - so it should also have access to any methods > > >>>> defined in > > >>>> the example (group) in which it is shared. > > >>> > > >>> You don't even have to think of it that way - that's actually what > > >>> they are - modules that get included. You can actually assign > > >>> them to > > >>> a constant and just use Ruby include. > > >> > > >> Although we've talked about the implementation changing, which would > > >> cause those who use them as modules to have broken specs. > > > > > > It would, but we stopped talking about it :) > > > > > > It actually works quite well this way. The change came up, iirc, in > > > the conversation about parameterizing it_should_behave_like, right? > > > I've got a solution for that worked out, but I haven't applied it yet > > > because I want to discuss it a bit: > > > > > > You'd use it like this: > > > > > > shared_examples_for "anything" do > > > it "should do stuff" do > > > @thing.should do_stuff > > > end > > > end > > > > > > describe SpecificThing do > > > it_should_behave_like "anything", :thing => SpecificThing.new > > > end > > > > > > Now comes the tricky part. This can work one of two ways. In either > > > case it turns :thing into an instance variable @thing. The question is > > > whether that instance variable is assigned in the scope of the > > > SpecificThing example group or in a scope created especially to run > > > the shared examples. Each choice presents usability confusion in my > > > view. > > > > > > Imagine this scenario: > > > > > > shared_examples_for "anything" do > > > it "should do stuff" do > > > @thing.should do_stuff > > > end > > > it "should be like another thing" do > > > @thing.should be_like(@other_thing) > > > end > > > end > > > > > > describe SpecificThing do > > > before(:each) do > > > @thing = SpecificThing.new > > > end > > > it_should_behave_like "anything", :other_thing => SpecificThing.new > > > > > > it "should not be unlike other thing" do > > > @thing.should_not be_unlike(@other_thing) > > > end > > > end > > > > > > If @other_thing is defined in the context of a separate scope just to > > > run the shared examples, the shared examples won't know about @thing. > > > > > > If @other_thing in the scope of the example group created by "describe > > > SpecificThing," then it's just confusing to look at - both > > > before(:each) and it_should_behave_like are creating instance > > > variables in the current scope, and it is NOT clear that is what is > > > happening. > > > > > > If we go w/ the separate scope, then the metaphor of > > > it_should_behave_like is wrong, because we're not talking about > > > something in the current scope that should behave like something else > > > anymore. We'd probably want a different construct to create these, > > > even though the underlying mechanism would be the same. > > > > > > Thoughts? > > > > > > How about this: > > > > Use a separate scope, but copy the instance variables from the > > calling example group. Any parameters passed into the shared example > > group will be methods which wrap the values given. This way we > > don't have instance variable naming conflicts (like @other_thing, in > > the example above). > > > > On the other hand, this would also mean that shared example groups > > wouldn't have the ability to call methods in the calling example group. > > > > Thoughts? > > Copying instance variables around is nasty business. In fact, we > eliminated that from shared behaviours by making them modules that get > included! So I would view that as a step backwards from an > implementation standpoint, and it still feels like voodoo from a > usability standpoint. Well - THAT was nothing but negative. Let me add some positive to balance things: As I think about it, I'm more inclined to make this a completely different method, as I suggested as an option earlier. Something that says "run in another scope with these variables." That way there's no magic and consequently no confusion. Suggestions? From dchelimsky at gmail.com Tue Dec 18 17:37:53 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 18 Dec 2007 16:37:53 -0600 Subject: [rspec-users] shared behav In-Reply-To: References: <505B52E3-039A-4AD6-A897-7B72AAA3DC89@LINOWES.COM> <57c63afe0712181336s3038deb4v1c0194f8bf6a0926@mail.gmail.com> Message-ID: <57c63afe0712181437i3a7d9cccx1591639b3b19021b@mail.gmail.com> On Dec 18, 2007 4:30 PM, Rick DeNatale wrote: > On 12/18/07, David Chelimsky wrote: > > On Dec 18, 2007 11:39 AM, Jonathan Linowes wrote: > > > > > > hi, i want to make a behavior shared between models, the examples need to > > > create new instances etc. Is there a way to pass the model class to the > > > shared behavior? > > > > We're calling these shared example groups now. > > > > The way to affect the state within a shared example group is to use > > before(:each) to set an instance variable: > > > > shared_examples_for "models that do stuff" do > > before(:each) do > > @instance = @class.new > > end > > it "should do something" do > > @instance.should do_something > > end > > end > > > > describe Foo do > > before(:each) do > > @class = Foo > > end > > it_should_behave_like "models that do stuff" > > end > > So I guess this means that the before block for the shared example > group gets executed after the example group using it. I don't recall > seeing this documented, although I'm sure that it is. > > This helps me a lot. > > Can you do something similar with the new nested example groups? It > doesn't seem so. > > describe "Shared", :shared => true do > > before(:each) do > @outer = @inner > end > > it "should set @outer to @inner" do > @outer.should == @inner > end > end > > describe "Sharer" do > it_should_behave_like "Shared" > > it "should set @outer to 1" do > @inner = 1 > end > end > > describe "Outer" do > before(:each) do > @outer = @inner > end > > describe "inner one" do > before(:each) do > @inner = 1 > end > > it "should be set outer to 1" do > @outer.should == 1 > end > end > > describe "inner two" do > before(:each) do > @inner = 2 > end > > it "should be set outer to 1" do > @outer.should == 2 > end > end > end > > k$ spec ~/nestedspec.rb > FF.. > > 1) > 'inner one should be set outer to 1' FAILED > expected: 1, > got: nil (using ==) > /Users/rick/nestedspec.rb:16: > > 2) > 'inner two should be set outer to 1' FAILED > expected: 2, > got: nil (using ==) > /Users/rick/nestedspec.rb:26: > > Finished in 0.00627 seconds > > 4 examples, 2 failures That's actually as it should be. The common use case for nested is that you create something in the outer group and expand its definition in the inner group. describe Thing do before(:each) { @thing = Thing.new } describe "with special magic powers" do before(:each) { @thing.grant_special_magic_powers } it "should be able to conjure up world peace" do @thing.should be_able_to_conjure_up_world_peace end end end This requires running the befores in the outer groups first, which is the opposite of what your example would require. Make sense? David From rick.denatale at gmail.com Tue Dec 18 17:38:09 2007 From: rick.denatale at gmail.com (Rick DeNatale) Date: Tue, 18 Dec 2007 17:38:09 -0500 Subject: [rspec-users] shared behav In-Reply-To: <57c63afe0712181412l28bae885rb80ddcd078a697fb@mail.gmail.com> References: <505B52E3-039A-4AD6-A897-7B72AAA3DC89@LINOWES.COM> <25B2FCA2-6BA4-40BD-A8F0-0FBC3E69DEC5@railsnewbie.com> <57c63afe0712181342p697529c6i45dfeab2d6901225@mail.gmail.com> <2F10E44D-CBCB-48D4-BF6D-3F5C600614DD@railsnewbie.com> <57c63afe0712181412l28bae885rb80ddcd078a697fb@mail.gmail.com> Message-ID: On 12/18/07, David Chelimsky wrote: > You'd use it like this: > > shared_examples_for "anything" do > it "should do stuff" do > @thing.should do_stuff > end > end > > describe SpecificThing do > it_should_behave_like "anything", :thing => SpecificThing.new > end > > Now comes the tricky part. This can work one of two ways. In either > case it turns :thing into an instance variable @thing. The question is > whether that instance variable is assigned in the scope of the > SpecificThing example group or in a scope created especially to run > the shared examples. Each choice presents usability confusion in my > view. > > Imagine this scenario: > > shared_examples_for "anything" do > it "should do stuff" do > @thing.should do_stuff > end > it "should be like another thing" do > @thing.should be_like(@other_thing) > end > end > > describe SpecificThing do > before(:each) do > @thing = SpecificThing.new > end > it_should_behave_like "anything", :other_thing => SpecificThing.new > > it "should not be unlike other thing" do > @thing.should_not be_unlike(@other_thing) > end > end > > If @other_thing is defined in the context of a separate scope just to > run the shared examples, the shared examples won't know about @thing. > > If @other_thing in the scope of the example group created by "describe > SpecificThing," then it's just confusing to look at - both > before(:each) and it_should_behave_like are creating instance > variables in the current scope, and it is NOT clear that is what is > happening. > > If we go w/ the separate scope, then the metaphor of > it_should_behave_like is wrong, because we're not talking about > something in the current scope that should behave like something else > anymore. We'd probably want a different construct to create these, > even though the underlying mechanism would be the same. > > Thoughts? How about something like (following the example of things like the :include option in ActiveRecord::Base#find: it_should_behave_like "anything", :except_that => { :thing => SpecificThing.new} -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From dchelimsky at gmail.com Tue Dec 18 17:41:39 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 18 Dec 2007 16:41:39 -0600 Subject: [rspec-users] shared behav In-Reply-To: References: <505B52E3-039A-4AD6-A897-7B72AAA3DC89@LINOWES.COM> <25B2FCA2-6BA4-40BD-A8F0-0FBC3E69DEC5@railsnewbie.com> <57c63afe0712181342p697529c6i45dfeab2d6901225@mail.gmail.com> <2F10E44D-CBCB-48D4-BF6D-3F5C600614DD@railsnewbie.com> <57c63afe0712181412l28bae885rb80ddcd078a697fb@mail.gmail.com> Message-ID: <57c63afe0712181441n5dba3c95sfb4a155d9cc0944@mail.gmail.com> On Dec 18, 2007 4:38 PM, Rick DeNatale wrote: > How about something like (following the example of things like the > :include option in ActiveRecord::Base#find: > > it_should_behave_like "anything", :except_that => { :thing => > SpecificThing.new} That's a little better, but I'm really leaning towards a different method name. Don't know what it is yet. Awaiting suggestions :) From mailing_lists at railsnewbie.com Tue Dec 18 17:45:11 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Tue, 18 Dec 2007 17:45:11 -0500 Subject: [rspec-users] shared behav In-Reply-To: <57c63afe0712181431y74632537r66c69f80cafc5efb@mail.gmail.com> References: <505B52E3-039A-4AD6-A897-7B72AAA3DC89@LINOWES.COM> <25B2FCA2-6BA4-40BD-A8F0-0FBC3E69DEC5@railsnewbie.com> <57c63afe0712181342p697529c6i45dfeab2d6901225@mail.gmail.com> <2F10E44D-CBCB-48D4-BF6D-3F5C600614DD@railsnewbie.com> <57c63afe0712181412l28bae885rb80ddcd078a697fb@mail.gmail.com> <05E0DF41-A55B-4024-8E24-EF8430EBE513@railsnewbie.com> <57c63afe0712181425y3946922bl18e68d461d9082ad@mail.gmail.com> <57c63afe0712181431y74632537r66c69f80cafc5efb@mail.gmail.com> Message-ID: <551A9FE6-133E-459A-A55F-2B03FEE71424@railsnewbie.com> On Dec 18, 2007, at 5:31 PM, David Chelimsky wrote: > On Dec 18, 2007 4:25 PM, David Chelimsky wrote: >> >> On Dec 18, 2007 4:22 PM, Scott Taylor >> wrote: >>> >>> >>> On Dec 18, 2007, at 5:12 PM, David Chelimsky wrote: >>> >>>> On Dec 18, 2007 3:53 PM, Scott Taylor >>>> wrote: >>>>> >>>>> >>>>> On Dec 18, 2007, at 4:42 PM, David Chelimsky wrote: >>>>> >>>>>> On Dec 18, 2007 3:37 PM, Scott Taylor >>>>>> wrote: >>>>>>> The >>>>>>> shared behaviours can be thought of modules which are included >>>>>>> into the >>>>>>> current behaviour - so it should also have access to any methods >>>>>>> defined in >>>>>>> the example (group) in which it is shared. >>>>>> >>>>>> You don't even have to think of it that way - that's actually >>>>>> what >>>>>> they are - modules that get included. You can actually assign >>>>>> them to >>>>>> a constant and just use Ruby include. >>>>> >>>>> Although we've talked about the implementation changing, which >>>>> would >>>>> cause those who use them as modules to have broken specs. >>>> >>>> It would, but we stopped talking about it :) >>>> >>>> It actually works quite well this way. The change came up, iirc, in >>>> the conversation about parameterizing it_should_behave_like, right? >>>> I've got a solution for that worked out, but I haven't applied >>>> it yet >>>> because I want to discuss it a bit: >>>> >>>> You'd use it like this: >>>> >>>> shared_examples_for "anything" do >>>> it "should do stuff" do >>>> @thing.should do_stuff >>>> end >>>> end >>>> >>>> describe SpecificThing do >>>> it_should_behave_like "anything", :thing => SpecificThing.new >>>> end >>>> >>>> Now comes the tricky part. This can work one of two ways. In either >>>> case it turns :thing into an instance variable @thing. The >>>> question is >>>> whether that instance variable is assigned in the scope of the >>>> SpecificThing example group or in a scope created especially to run >>>> the shared examples. Each choice presents usability confusion in my >>>> view. >>>> >>>> Imagine this scenario: >>>> >>>> shared_examples_for "anything" do >>>> it "should do stuff" do >>>> @thing.should do_stuff >>>> end >>>> it "should be like another thing" do >>>> @thing.should be_like(@other_thing) >>>> end >>>> end >>>> >>>> describe SpecificThing do >>>> before(:each) do >>>> @thing = SpecificThing.new >>>> end >>>> it_should_behave_like "anything", :other_thing => >>>> SpecificThing.new >>>> >>>> it "should not be unlike other thing" do >>>> @thing.should_not be_unlike(@other_thing) >>>> end >>>> end >>>> >>>> If @other_thing is defined in the context of a separate scope >>>> just to >>>> run the shared examples, the shared examples won't know about >>>> @thing. >>>> >>>> If @other_thing in the scope of the example group created by >>>> "describe >>>> SpecificThing," then it's just confusing to look at - both >>>> before(:each) and it_should_behave_like are creating instance >>>> variables in the current scope, and it is NOT clear that is what is >>>> happening. >>>> >>>> If we go w/ the separate scope, then the metaphor of >>>> it_should_behave_like is wrong, because we're not talking about >>>> something in the current scope that should behave like something >>>> else >>>> anymore. We'd probably want a different construct to create these, >>>> even though the underlying mechanism would be the same. >>>> >>>> Thoughts? >>> >>> >>> How about this: >>> >>> Use a separate scope, but copy the instance variables from the >>> calling example group. Any parameters passed into the shared >>> example >>> group will be methods which wrap the values given. This way we >>> don't have instance variable naming conflicts (like @other_thing, in >>> the example above). >>> >>> On the other hand, this would also mean that shared example groups >>> wouldn't have the ability to call methods in the calling example >>> group. >>> >>> Thoughts? >> >> Copying instance variables around is nasty business. In fact, we >> eliminated that from shared behaviours by making them modules that >> get >> included! So I would view that as a step backwards from an >> implementation standpoint, and it still feels like voodoo from a >> usability standpoint. > > Well - THAT was nothing but negative. > > Let me add some positive to balance things: > > As I think about it, I'm more inclined to make this a completely > different method, as I suggested as an option earlier. Something that > says "run in another scope with these variables." That way there's no > magic and consequently no confusion. I'm with you on that one. I don't like "it_should_behave_like" much anyway - I end up aliasing it in a few different forms: it_should_behave_like_a it_should_behave_like_the and so on. Anyway - how do the nested behaviours work right now? Are instance variables being copied? Methods? Scott From rick.denatale at gmail.com Tue Dec 18 17:46:54 2007 From: rick.denatale at gmail.com (Rick DeNatale) Date: Tue, 18 Dec 2007 17:46:54 -0500 Subject: [rspec-users] shared behav In-Reply-To: <57c63afe0712181437i3a7d9cccx1591639b3b19021b@mail.gmail.com> References: <505B52E3-039A-4AD6-A897-7B72AAA3DC89@LINOWES.COM> <57c63afe0712181336s3038deb4v1c0194f8bf6a0926@mail.gmail.com> <57c63afe0712181437i3a7d9cccx1591639b3b19021b@mail.gmail.com> Message-ID: On 12/18/07, David Chelimsky wrote: > That's actually as it should be. The common use case for nested is > that you create something in the outer group and expand its definition > in the inner group. > > describe Thing do > before(:each) { @thing = Thing.new } > > describe "with special magic powers" do > before(:each) { @thing.grant_special_magic_powers } > it "should be able to conjure up world peace" do > @thing.should be_able_to_conjure_up_world_peace > end > end > end > > This requires running the befores in the outer groups first, which is > the opposite of what your example would require. > > Make sense? Yes and it helps clarify my questions about how nested groups were different, if at all, from shared groups. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From dchelimsky at gmail.com Tue Dec 18 17:47:15 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 18 Dec 2007 16:47:15 -0600 Subject: [rspec-users] shared behav In-Reply-To: <551A9FE6-133E-459A-A55F-2B03FEE71424@railsnewbie.com> References: <505B52E3-039A-4AD6-A897-7B72AAA3DC89@LINOWES.COM> <25B2FCA2-6BA4-40BD-A8F0-0FBC3E69DEC5@railsnewbie.com> <57c63afe0712181342p697529c6i45dfeab2d6901225@mail.gmail.com> <2F10E44D-CBCB-48D4-BF6D-3F5C600614DD@railsnewbie.com> <57c63afe0712181412l28bae885rb80ddcd078a697fb@mail.gmail.com> <05E0DF41-A55B-4024-8E24-EF8430EBE513@railsnewbie.com> <57c63afe0712181425y3946922bl18e68d461d9082ad@mail.gmail.com> <57c63afe0712181431y74632537r66c69f80cafc5efb@mail.gmail.com> <551A9FE6-133E-459A-A55F-2B03FEE71424@railsnewbie.com> Message-ID: <57c63afe0712181447n496e3fc2p4525065c113f4e@mail.gmail.com> On Dec 18, 2007 4:45 PM, Scott Taylor wrote: > > > On Dec 18, 2007, at 5:31 PM, David Chelimsky wrote: > > > On Dec 18, 2007 4:25 PM, David Chelimsky wrote: > >> > >> On Dec 18, 2007 4:22 PM, Scott Taylor > >> wrote: > >>> > >>> > >>> On Dec 18, 2007, at 5:12 PM, David Chelimsky wrote: > >>> > >>>> On Dec 18, 2007 3:53 PM, Scott Taylor > >>>> wrote: > >>>>> > >>>>> > >>>>> On Dec 18, 2007, at 4:42 PM, David Chelimsky wrote: > >>>>> > >>>>>> On Dec 18, 2007 3:37 PM, Scott Taylor > >>>>>> wrote: > >>>>>>> The > >>>>>>> shared behaviours can be thought of modules which are included > >>>>>>> into the > >>>>>>> current behaviour - so it should also have access to any methods > >>>>>>> defined in > >>>>>>> the example (group) in which it is shared. > >>>>>> > >>>>>> You don't even have to think of it that way - that's actually > >>>>>> what > >>>>>> they are - modules that get included. You can actually assign > >>>>>> them to > >>>>>> a constant and just use Ruby include. > >>>>> > >>>>> Although we've talked about the implementation changing, which > >>>>> would > >>>>> cause those who use them as modules to have broken specs. > >>>> > >>>> It would, but we stopped talking about it :) > >>>> > >>>> It actually works quite well this way. The change came up, iirc, in > >>>> the conversation about parameterizing it_should_behave_like, right? > >>>> I've got a solution for that worked out, but I haven't applied > >>>> it yet > >>>> because I want to discuss it a bit: > >>>> > >>>> You'd use it like this: > >>>> > >>>> shared_examples_for "anything" do > >>>> it "should do stuff" do > >>>> @thing.should do_stuff > >>>> end > >>>> end > >>>> > >>>> describe SpecificThing do > >>>> it_should_behave_like "anything", :thing => SpecificThing.new > >>>> end > >>>> > >>>> Now comes the tricky part. This can work one of two ways. In either > >>>> case it turns :thing into an instance variable @thing. The > >>>> question is > >>>> whether that instance variable is assigned in the scope of the > >>>> SpecificThing example group or in a scope created especially to run > >>>> the shared examples. Each choice presents usability confusion in my > >>>> view. > >>>> > >>>> Imagine this scenario: > >>>> > >>>> shared_examples_for "anything" do > >>>> it "should do stuff" do > >>>> @thing.should do_stuff > >>>> end > >>>> it "should be like another thing" do > >>>> @thing.should be_like(@other_thing) > >>>> end > >>>> end > >>>> > >>>> describe SpecificThing do > >>>> before(:each) do > >>>> @thing = SpecificThing.new > >>>> end > >>>> it_should_behave_like "anything", :other_thing => > >>>> SpecificThing.new > >>>> > >>>> it "should not be unlike other thing" do > >>>> @thing.should_not be_unlike(@other_thing) > >>>> end > >>>> end > >>>> > >>>> If @other_thing is defined in the context of a separate scope > >>>> just to > >>>> run the shared examples, the shared examples won't know about > >>>> @thing. > >>>> > >>>> If @other_thing in the scope of the example group created by > >>>> "describe > >>>> SpecificThing," then it's just confusing to look at - both > >>>> before(:each) and it_should_behave_like are creating instance > >>>> variables in the current scope, and it is NOT clear that is what is > >>>> happening. > >>>> > >>>> If we go w/ the separate scope, then the metaphor of > >>>> it_should_behave_like is wrong, because we're not talking about > >>>> something in the current scope that should behave like something > >>>> else > >>>> anymore. We'd probably want a different construct to create these, > >>>> even though the underlying mechanism would be the same. > >>>> > >>>> Thoughts? > >>> > >>> > >>> How about this: > >>> > >>> Use a separate scope, but copy the instance variables from the > >>> calling example group. Any parameters passed into the shared > >>> example > >>> group will be methods which wrap the values given. This way we > >>> don't have instance variable naming conflicts (like @other_thing, in > >>> the example above). > >>> > >>> On the other hand, this would also mean that shared example groups > >>> wouldn't have the ability to call methods in the calling example > >>> group. > >>> > >>> Thoughts? > >> > >> Copying instance variables around is nasty business. In fact, we > >> eliminated that from shared behaviours by making them modules that > >> get > >> included! So I would view that as a step backwards from an > >> implementation standpoint, and it still feels like voodoo from a > >> usability standpoint. > > > > Well - THAT was nothing but negative. > > > > Let me add some positive to balance things: > > > > As I think about it, I'm more inclined to make this a completely > > different method, as I suggested as an option earlier. Something that > > says "run in another scope with these variables." That way there's no > > magic and consequently no confusion. > > I'm with you on that one. I don't like "it_should_behave_like" much > anyway - I end up aliasing it in a few different forms: > > it_should_behave_like_a > it_should_behave_like_the > > and so on. > > Anyway - how do the nested behaviours work right now? Are instance > variables being copied? Methods? They are subclasses!!!! It's pretty sweet. We can thank Brian (and Aslak, too) for getting us there. Basically there is no copying, just inheriting or, in the case of shared, mixing in. Ruby does the rest for free. > > > Scott > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Tue Dec 18 17:48:20 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 18 Dec 2007 16:48:20 -0600 Subject: [rspec-users] shared behav In-Reply-To: References: <505B52E3-039A-4AD6-A897-7B72AAA3DC89@LINOWES.COM> <57c63afe0712181336s3038deb4v1c0194f8bf6a0926@mail.gmail.com> <57c63afe0712181437i3a7d9cccx1591639b3b19021b@mail.gmail.com> Message-ID: <57c63afe0712181448s23b75b2esa843fb5b31960219@mail.gmail.com> On Dec 18, 2007 4:46 PM, Rick DeNatale wrote: > On 12/18/07, David Chelimsky wrote: > > > That's actually as it should be. The common use case for nested is > > that you create something in the outer group and expand its definition > > in the inner group. > > > > describe Thing do > > before(:each) { @thing = Thing.new } > > > > describe "with special magic powers" do > > before(:each) { @thing.grant_special_magic_powers } > > it "should be able to conjure up world peace" do > > @thing.should be_able_to_conjure_up_world_peace > > end > > end > > end > > > > This requires running the befores in the outer groups first, which is > > the opposite of what your example would require. > > > > Make sense? > > Yes and it helps clarify my questions about how nested groups were > different, if at all, from shared groups. My response to scott's mail should enlighten that a bit as well. Nested groups are subclasses of the outer groups. Shared groups get mixed in. > > > -- > Rick DeNatale > > My blog on Ruby > http://talklikeaduck.denhaven2.com/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From rick.denatale at gmail.com Tue Dec 18 17:58:31 2007 From: rick.denatale at gmail.com (Rick DeNatale) Date: Tue, 18 Dec 2007 17:58:31 -0500 Subject: [rspec-users] rpec_scaffold and nested resources Message-ID: I've got a love-hate relationship with script/generate rspec_scaffold If you are using non-nested controllers/resources it's great. I love the spec skeletons it generates. But I find myself doing this, where Y is and existing set of model/controller ... representing a resource: 1) script/generate rspec_scaffold x .... At this point rake spec passes. 2) edit config/routes.rb and change it from: map.resources :ys map.resources :xs to: map.resources :ys do | y | y.resources :xs end At this point rake spec fails on the routes and controller specs for x, no big surprise. The controller needs to change as well. This is followed by a manual editing session of BOTH the controller and the specs, with lots of fairly tedious changes. Of course most of this might be laid to the rails scaffold generator not being able to generate nested resource controllers directly as a prerequisite to rspec_scaffold, unless there's something y'all know that I don't. (Well I'm sure that y'all know lots that I don't but I don't know if it's relevant to this). But the changes to the controller are much easier than the changes to the specs. I was starting to think about writing a plugin/tool to address this, but I was wondering if anyone had any insight or had already started down this path. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From dchelimsky at gmail.com Tue Dec 18 18:04:30 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 18 Dec 2007 17:04:30 -0600 Subject: [rspec-users] rpec_scaffold and nested resources In-Reply-To: References: Message-ID: <57c63afe0712181504p55189546n277d089f08e84180@mail.gmail.com> On Dec 18, 2007 4:58 PM, Rick DeNatale wrote: > I was starting to think about writing a plugin/tool to address this, > but I was wondering if anyone had any insight or had already started > down this path. This is definitely something I'd like to see addressed, so if you come up w/something that works I'll commit it. I don't know if anyone is already working on it. From mailing_lists at bengreenberg.net Wed Dec 19 08:31:48 2007 From: mailing_lists at bengreenberg.net (Ben Greenberg) Date: Wed, 19 Dec 2007 08:31:48 -0500 Subject: [rspec-users] Installation Trouble Message-ID: <47691D44.9000500@bengreenberg.net> Hey all, I'm new to BDD and rspec, but I am very intrigued. I tried installing rspec and rspec_on_rails into my Rails app, but I am having some trouble. I chose to install both as plugins, as the documentation suggests. I checked out the CURRENT tag from svn, and copied the rspec and rspec_on_rails directories into my app's vendor/plugins directory. Then I ran script/generate rspec, which created its files. Everything seemed ok, so I wrote up a little model spec, put it in spec/models, and ran rake spec. I did put require "File.dirname(__FILE__) + '/../spec_helper.rb'" at the top of my spec file. The message and call stack I get back is: == c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:266:in `load_missing_constant': uninitialized constant Spec::Rails (NameError) from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:452:in `const_missing' from C:/src/Aptana/ir/vendor/plugins/rspec_on_rails/lib/spec/rails/extensions/spec/example/configuration.rb:14 from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require' from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require' from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:495:in `require' from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:342:in `new_constants_in' from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:495:in `require' from C:/src/Aptana/ir/vendor/plugins/rspec_on_rails/lib/spec/rails/extensions.rb:5 ... 18 levels... from C:/src/Aptana/ir/vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb:13:in `load_files' from C:/src/Aptana/ir/vendor/plugins/rspec/lib/spec/runner/options.rb:83:in `run_examples' from C:/src/Aptana/ir/vendor/plugins/rspec/lib/spec/runner/command_line.rb:19:in `run' from C:/src/Aptana/ir/vendor/plugins/rspec/bin/spec:3 rake aborted! Command ruby -I"C:/src/Aptana/ir/vendor/plugins/rspec/lib" "C:/src/Aptana/ir/ven dor/plugins/rspec/bin/spec" "spec/models/image_spec.rb" --options "C:/src/Aptana /ir/config/../spec/spec.opts" failed == As you can see, I am running Windows. Does anyone have any idea what I am doing wrong? Thanks, Ben -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071219/67815598/attachment.html From dchelimsky at gmail.com Wed Dec 19 09:44:15 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 19 Dec 2007 08:44:15 -0600 Subject: [rspec-users] Installation Trouble In-Reply-To: <47691D44.9000500@bengreenberg.net> References: <47691D44.9000500@bengreenberg.net> Message-ID: <57c63afe0712190644m4440a012n9136b87095e5eb89@mail.gmail.com> On Dec 19, 2007 7:31 AM, Ben Greenberg wrote: > > > Hey all, > > I'm new to BDD and rspec, but I am very intrigued. > > I tried installing rspec and rspec_on_rails into my Rails app, but I am > having some trouble. > > I chose to install both as plugins, as the documentation suggests. I > checked out the CURRENT tag from svn, and copied the rspec and > rspec_on_rails directories into my app's vendor/plugins directory. Then I > ran script/generate rspec, which created its files. Everything seemed ok, so > I wrote up a little model spec, put it in spec/models, and ran rake spec. I > did put require "File.dirname(__FILE__) + '/../spec_helper.rb'" at the top > of my spec file. > > The message and call stack I get back is: > > == > > c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:266:in > `load_missing_constant': uninitialized constant Spec::Rails (NameError) > from > c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:452:in > `const_missing' > from > C:/src/Aptana/ir/vendor/plugins/rspec_on_rails/lib/spec/rails/extensions/spec/example/configuration.rb:14 > from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in > `gem_original_require' > from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in > `require' > from > c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:495:in > `require' > from > c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:342:in > `new_constants_in' > from > c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:495:in > `require' > from > C:/src/Aptana/ir/vendor/plugins/rspec_on_rails/lib/spec/rails/extensions.rb:5 > ... 18 levels... > from > C:/src/Aptana/ir/vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb:13:in > `load_files' > from > C:/src/Aptana/ir/vendor/plugins/rspec/lib/spec/runner/options.rb:83:in > `run_examples' > from > C:/src/Aptana/ir/vendor/plugins/rspec/lib/spec/runner/command_line.rb:19:in > `run' > from C:/src/Aptana/ir/vendor/plugins/rspec/bin/spec:3 > rake aborted! > Command ruby -I"C:/src/Aptana/ir/vendor/plugins/rspec/lib" > "C:/src/Aptana/ir/ven > dor/plugins/rspec/bin/spec" "spec/models/image_spec.rb" --options > "C:/src/Aptana > /ir/config/../spec/spec.opts" failed > == > > As you can see, I am running Windows. > > Does anyone have any idea what I am doing wrong? Are you running this from Aptana or from the command line? > > Thanks, > Ben > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at bengreenberg.net Wed Dec 19 09:46:52 2007 From: mailing_lists at bengreenberg.net (Ben Greenberg) Date: Wed, 19 Dec 2007 09:46:52 -0500 Subject: [rspec-users] Installation Trouble In-Reply-To: <57c63afe0712190644m4440a012n9136b87095e5eb89@mail.gmail.com> References: <47691D44.9000500@bengreenberg.net> <57c63afe0712190644m4440a012n9136b87095e5eb89@mail.gmail.com> Message-ID: <47692EDC.3000804@bengreenberg.net> David Chelimsky wrote: > On Dec 19, 2007 7:31 AM, Ben Greenberg wrote: > >> Hey all, >> >> I'm new to BDD and rspec, but I am very intrigued. >> >> I tried installing rspec and rspec_on_rails into my Rails app, but I am >> having some trouble. >> >> I chose to install both as plugins, as the documentation suggests. I >> checked out the CURRENT tag from svn, and copied the rspec and >> rspec_on_rails directories into my app's vendor/plugins directory. Then I >> ran script/generate rspec, which created its files. Everything seemed ok, so >> I wrote up a little model spec, put it in spec/models, and ran rake spec. I >> did put require "File.dirname(__FILE__) + '/../spec_helper.rb'" at the top >> of my spec file. >> >> The message and call stack I get back is: >> >> == >> >> c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:266:in >> `load_missing_constant': uninitialized constant Spec::Rails (NameError) >> from >> c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:452:in >> `const_missing' >> from >> C:/src/Aptana/ir/vendor/plugins/rspec_on_rails/lib/spec/rails/extensions/spec/example/configuration.rb:14 >> from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in >> `gem_original_require' >> from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in >> `require' >> from >> c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:495:in >> `require' >> from >> c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:342:in >> `new_constants_in' >> from >> c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:495:in >> `require' >> from >> C:/src/Aptana/ir/vendor/plugins/rspec_on_rails/lib/spec/rails/extensions.rb:5 >> ... 18 levels... >> from >> C:/src/Aptana/ir/vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb:13:in >> `load_files' >> from >> C:/src/Aptana/ir/vendor/plugins/rspec/lib/spec/runner/options.rb:83:in >> `run_examples' >> from >> C:/src/Aptana/ir/vendor/plugins/rspec/lib/spec/runner/command_line.rb:19:in >> `run' >> from C:/src/Aptana/ir/vendor/plugins/rspec/bin/spec:3 >> rake aborted! >> Command ruby -I"C:/src/Aptana/ir/vendor/plugins/rspec/lib" >> "C:/src/Aptana/ir/ven >> dor/plugins/rspec/bin/spec" "spec/models/image_spec.rb" --options >> "C:/src/Aptana >> /ir/config/../spec/spec.opts" failed >> == >> >> As you can see, I am running Windows. >> >> Does anyone have any idea what I am doing wrong? >> > > Are you running this from Aptana or from the command line? > > Thanks for the quick reply. I am running from the command line, in my RAILS_ROOT. >> Thanks, >> Ben >> >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071219/f0685930/attachment-0001.html From dchelimsky at gmail.com Wed Dec 19 10:11:30 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 19 Dec 2007 09:11:30 -0600 Subject: [rspec-users] Installation Trouble In-Reply-To: <47692EDC.3000804@bengreenberg.net> References: <47691D44.9000500@bengreenberg.net> <57c63afe0712190644m4440a012n9136b87095e5eb89@mail.gmail.com> <47692EDC.3000804@bengreenberg.net> Message-ID: <57c63afe0712190711p2cba3f9blcb27c54dbfc953f9@mail.gmail.com> On Dec 19, 2007 8:46 AM, Ben Greenberg wrote: > > David Chelimsky wrote: > > On Dec 19, 2007 7:31 AM, Ben Greenberg > wrote: > > > Hey all, > > I'm new to BDD and rspec, but I am very intrigued. > > I tried installing rspec and rspec_on_rails into my Rails app, but I am > having some trouble. > > I chose to install both as plugins, as the documentation suggests. I > checked out the CURRENT tag from svn, and copied the rspec and > rspec_on_rails directories into my app's vendor/plugins directory. Then I > ran script/generate rspec, which created its files. Everything seemed ok, so > I wrote up a little model spec, put it in spec/models, and ran rake spec. I > did put require "File.dirname(__FILE__) + '/../spec_helper.rb'" at the top > of my spec file. > > The message and call stack I get back is: > > == > > c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:266:in > `load_missing_constant': uninitialized constant Spec::Rails (NameError) > from > c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:452:in > `const_missing' > from > C:/src/Aptana/ir/vendor/plugins/rspec_on_rails/lib/spec/rails/extensions/spec/example/configuration.rb:14 > from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in > `gem_original_require' > from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in > `require' > from > c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:495:in > `require' > from > c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:342:in > `new_constants_in' > from > c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:495:in > `require' > from > C:/src/Aptana/ir/vendor/plugins/rspec_on_rails/lib/spec/rails/extensions.rb:5 > ... 18 levels... > from > C:/src/Aptana/ir/vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb:13:in > `load_files' > from > C:/src/Aptana/ir/vendor/plugins/rspec/lib/spec/runner/options.rb:83:in > `run_examples' > from > C:/src/Aptana/ir/vendor/plugins/rspec/lib/spec/runner/command_line.rb:19:in > `run' > from C:/src/Aptana/ir/vendor/plugins/rspec/bin/spec:3 > rake aborted! > Command ruby -I"C:/src/Aptana/ir/vendor/plugins/rspec/lib" > "C:/src/Aptana/ir/ven > dor/plugins/rspec/bin/spec" "spec/models/image_spec.rb" --options > "C:/src/Aptana > /ir/config/../spec/spec.opts" failed > == > > As you can see, I am running Windows. > > Does anyone have any idea what I am doing wrong? > > Are you running this from Aptana or from the command line? > > > > Thanks for the quick reply. > > I am running from the command line, in my RAILS_ROOT. And you've got the following near the top of spec/spec_helper.rb? require 'spec' require 'spec/rails' From chad at spicycode.com Wed Dec 19 10:13:58 2007 From: chad at spicycode.com (Chad Humphries) Date: Wed, 19 Dec 2007 10:13:58 -0500 Subject: [rspec-users] Installation Trouble In-Reply-To: <57c63afe0712190711p2cba3f9blcb27c54dbfc953f9@mail.gmail.com> References: <47691D44.9000500@bengreenberg.net> <57c63afe0712190644m4440a012n9136b87095e5eb89@mail.gmail.com> <47692EDC.3000804@bengreenberg.net> <57c63afe0712190711p2cba3f9blcb27c54dbfc953f9@mail.gmail.com> Message-ID: <348F34C7-D00C-4500-98BA-E3F7D0486748@spicycode.com> Also, could you post the spec if possible? - Chad On Dec 19, 2007, at 10:11 AM, David Chelimsky wrote: > On Dec 19, 2007 8:46 AM, Ben Greenberg > wrote: >> >> David Chelimsky wrote: >> >> On Dec 19, 2007 7:31 AM, Ben Greenberg > > >> wrote: >> >> >> Hey all, >> >> I'm new to BDD and rspec, but I am very intrigued. >> >> I tried installing rspec and rspec_on_rails into my Rails app, but >> I am >> having some trouble. >> >> I chose to install both as plugins, as the documentation suggests. I >> checked out the CURRENT tag from svn, and copied the rspec and >> rspec_on_rails directories into my app's vendor/plugins directory. >> Then I >> ran script/generate rspec, which created its files. Everything >> seemed ok, so >> I wrote up a little model spec, put it in spec/models, and ran rake >> spec. I >> did put require "File.dirname(__FILE__) + '/../spec_helper.rb'" at >> the top >> of my spec file. >> >> The message and call stack I get back is: >> >> == >> >> c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/ >> active_support/dependencies.rb:266:in >> `load_missing_constant': uninitialized constant Spec::Rails >> (NameError) >> from >> c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/ >> active_support/dependencies.rb:452:in >> `const_missing' >> from >> C:/src/Aptana/ir/vendor/plugins/rspec_on_rails/lib/spec/rails/ >> extensions/spec/example/configuration.rb:14 >> from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in >> `gem_original_require' >> from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in >> `require' >> from >> c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/ >> active_support/dependencies.rb:495:in >> `require' >> from >> c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/ >> active_support/dependencies.rb:342:in >> `new_constants_in' >> from >> c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/ >> active_support/dependencies.rb:495:in >> `require' >> from >> C:/src/Aptana/ir/vendor/plugins/rspec_on_rails/lib/spec/rails/ >> extensions.rb:5 >> ... 18 levels... >> from >> C:/src/Aptana/ir/vendor/plugins/rspec/lib/spec/runner/ >> example_group_runner.rb:13:in >> `load_files' >> from >> C:/src/Aptana/ir/vendor/plugins/rspec/lib/spec/runner/options.rb: >> 83:in >> `run_examples' >> from >> C:/src/Aptana/ir/vendor/plugins/rspec/lib/spec/runner/ >> command_line.rb:19:in >> `run' >> from C:/src/Aptana/ir/vendor/plugins/rspec/bin/spec:3 >> rake aborted! >> Command ruby -I"C:/src/Aptana/ir/vendor/plugins/rspec/lib" >> "C:/src/Aptana/ir/ven >> dor/plugins/rspec/bin/spec" "spec/models/image_spec.rb" --options >> "C:/src/Aptana >> /ir/config/../spec/spec.opts" failed >> == >> >> As you can see, I am running Windows. >> >> Does anyone have any idea what I am doing wrong? >> >> Are you running this from Aptana or from the command line? >> >> >> >> Thanks for the quick reply. >> >> I am running from the command line, in my RAILS_ROOT. > > And you've got the following near the top of spec/spec_helper.rb? > > require 'spec' > require 'spec/rails' > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From jeroen.houben at lostboys.nl Wed Dec 19 10:15:27 2007 From: jeroen.houben at lostboys.nl (Jeroen Houben) Date: Wed, 19 Dec 2007 16:15:27 +0100 Subject: [rspec-users] Change in isolation behaviour 1.08 - 1.10 ? In-Reply-To: <8d961d900712171014q249f15efgbf59649762a85f11@mail.gmail.com> Message-ID: On 12/17/07 7:14 PM, "aslak hellesoy" wrote: > On Dec 17, 2007 5:58 PM, David Chelimsky wrote: >> On Dec 17, 2007 10:55 AM, aslak hellesoy wrote: >>> On Dec 17, 2007 4:12 PM, David Chelimsky wrote: >>>> On Dec 17, 2007 9:06 AM, Jeroen Houben wrote: >>>>>>> >>>>>>> ... Just received the message by David. This will be fixed in 1.1.1 >>>>>> >>>>>> Jeroen - just for good measure, would you kindly update from trunk and >>>>>> verify that it does in fact fix your issue? >>>>> >>>>> Finished in 3.42683 seconds >>>>> >>>>> 176 examples, 0 failures, 3 pending >>>> >>>> Thanks. I'll get the release out by tonight. >>>> >>> >>> Awesome David. >>> >>> Do we have any specs that will catch this regression if it's reintroduced? >> >> I didn't look and don't have time right now. The fix was committed in >> r3158. Can you check the diff? >> > > I've added some more functional specs (r3172) that should prevent any > transaction related bugs from coming back in. > > Jeroen - if you find more bugs, please report what Rails and Ruby > versions you are using - it took me a while to realise that you were > on Rails 1.2.3 (David told me) Don't know if it makes a difference, but I was on 1.2.6 Cheers, Jeroen From michel at demazure.com Wed Dec 19 09:27:13 2007 From: michel at demazure.com (Michel Demazure) Date: Wed, 19 Dec 2007 15:27:13 +0100 Subject: [rspec-users] Using autotest + rspec for plain ruby (not rails) Message-ID: <570717C0AF0B483E9B674C9C4E61DC0E@MSI> autotest (zentest 3.5.0) + rspec 1.1.1 ask for "spec_autotest.rb", nowhere to be found... -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071219/d560dfed/attachment.html From dchelimsky at gmail.com Wed Dec 19 10:29:03 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 19 Dec 2007 09:29:03 -0600 Subject: [rspec-users] Using autotest + rspec for plain ruby (not rails) In-Reply-To: <570717C0AF0B483E9B674C9C4E61DC0E@MSI> References: <570717C0AF0B483E9B674C9C4E61DC0E@MSI> Message-ID: <57c63afe0712190729t43c0cefcr22b82073bfb863c4@mail.gmail.com> On Dec 19, 2007 8:27 AM, Michel Demazure wrote: > autotest (zentest 3.5.0) + rspec 1.1.1 ask for "spec_autotest.rb", nowhere > to be found... Gotta update ZenTest. The integration w/ rspec didn't get added until 3.6. From mailing_lists at railsnewbie.com Wed Dec 19 10:30:30 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Wed, 19 Dec 2007 10:30:30 -0500 Subject: [rspec-users] Using autotest + rspec for plain ruby (not rails) In-Reply-To: <570717C0AF0B483E9B674C9C4E61DC0E@MSI> References: <570717C0AF0B483E9B674C9C4E61DC0E@MSI> Message-ID: <40C39D7D-86D3-455E-9572-C346DB872328@railsnewbie.com> On Dec 19, 2007, at 9:27 AM, Michel Demazure wrote: > autotest (zentest 3.5.0) + rspec 1.1.1 ask for ?spec_autotest.rb?, > nowhere to be found... > Also - I'd stay away from doing a gem update --system. Scott -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071219/a9db1e53/attachment.html From michel at demazure.com Wed Dec 19 11:00:12 2007 From: michel at demazure.com (Michel Demazure) Date: Wed, 19 Dec 2007 17:00:12 +0100 Subject: [rspec-users] RE : Using autotest + rspec for plain ruby (not rails) In-Reply-To: <57c63afe0712190729t43c0cefcr22b82073bfb863c4@mail.gmail.com> Message-ID: Thanks. I found the bug : zentest 3.6 has got capitals : it is now ZenTest ! Michel Demazure michel at demazure.com -----Message d'origine----- De?: rspec-users-bounces at rubyforge.org [mailto:rspec-users-bounces at rubyforge.org] De la part de David Chelimsky Envoy??: mercredi 19 d?cembre 2007 16:29 ??: rspec-users Objet?: Re: [rspec-users] Using autotest + rspec for plain ruby (not rails) On Dec 19, 2007 8:27 AM, Michel Demazure wrote: > autotest (zentest 3.5.0) + rspec 1.1.1 ask for "spec_autotest.rb", nowhere > to be found... Gotta update ZenTest. The integration w/ rspec didn't get added until 3.6. _______________________________________________ rspec-users mailing list rspec-users at rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users From ed.howland at gmail.com Wed Dec 19 14:37:29 2007 From: ed.howland at gmail.com (Ed Howland) Date: Wed, 19 Dec 2007 13:37:29 -0600 Subject: [rspec-users] new home for the rspec website In-Reply-To: <57c63afe0712140759u4c975eeet1827113e3af1a44a@mail.gmail.com> References: <57c63afe0712140705g308b2c64sfa2633a1c54dc5ec@mail.gmail.com> <4C34A987-14BE-4E2B-BB59-22F7D88F2306@superinfinite.com> <57c63afe0712140759u4c975eeet1827113e3af1a44a@mail.gmail.com> Message-ID: <3df642dd0712191137qfdccdf9l3d1644bfa9a7cadf@mail.gmail.com> On Dec 14, 2007 9:59 AM, David Chelimsky wrote: > On Dec 14, 2007 9:28 AM, Bart Zonneveld wrote: > > > > On 14 dec 2007, at 16:05, David Chelimsky wrote: > > > > > Hi all, > > > > > > The 1.1.0 docs are there. The 1.0.8 docs are still at > > > http://rspec.rubyforge.org for the time being. We'll be archiving them > > > at the new site soon. > > > > Sweet! > > Any idea when the docs for the plain text Stories are online? > > I'm struggling with something like When I POST to /posts with :name => > > "Post Title", :body => "Body" at the moment. > +1 If I might suggest a simple addition to the site. Just fill out the part "(detail left out for brevity)" on the story on the front page. IOW, put the detail back in somewhere for clarity. That would get a a lot of folks jump-started on Stories. At least have the require statements and list the needed helpers. Thanks Ed From james.deville at gmail.com Wed Dec 19 20:01:57 2007 From: james.deville at gmail.com (James Deville) Date: Wed, 19 Dec 2007 17:01:57 -0800 Subject: [rspec-users] Story runner rake task Message-ID: What's the status on a rake task for the story runner. If nothing is in progress, where could I start to try and build one? JD From ben at benmabey.com Wed Dec 19 20:05:27 2007 From: ben at benmabey.com (Ben Mabey) Date: Wed, 19 Dec 2007 18:05:27 -0700 Subject: [rspec-users] Story runner rake task In-Reply-To: References: Message-ID: <4769BFD7.30904@benmabey.com> James Deville wrote: > What's the status on a rake task for the story runner. If nothing is > in progress, where could I start to try and build one? > > JD > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > If you check out rspec trunk you can see that they have created one for the rspec project. It just runs the all.rb file in the stories directory. -Ben From philodespotos at gmail.com Wed Dec 19 20:07:04 2007 From: philodespotos at gmail.com (Kyle Hargraves) Date: Wed, 19 Dec 2007 19:07:04 -0600 Subject: [rspec-users] Story runner rake task In-Reply-To: References: Message-ID: <60f3810c0712191707qa23e9d3y8bc2fcb51afde8f7@mail.gmail.com> On Dec 19, 2007 7:01 PM, James Deville wrote: > What's the status on a rake task for the story runner. If nothing is > in progress, where could I start to try and build one? > > JD I've been using: task 'stories' do sh "ruby stories/all.rb" end task 'stories:rcov' do sh "rcov -o story_coverage --exclude stories stories/all.rb" end Kyle From ben at benmabey.com Wed Dec 19 20:07:10 2007 From: ben at benmabey.com (Ben Mabey) Date: Wed, 19 Dec 2007 18:07:10 -0700 Subject: [rspec-users] Story runner rake task In-Reply-To: <4769BFD7.30904@benmabey.com> References: <4769BFD7.30904@benmabey.com> Message-ID: <4769C03E.5060507@benmabey.com> Ben Mabey wrote: > James Deville wrote: > >> What's the status on a rake task for the story runner. If nothing is >> in progress, where could I start to try and build one? >> >> JD >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> >> > > If you check out rspec trunk you can see that they have created one for > the rspec project. It just runs the all.rb file in the stories directory. > > -Ben > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > This is the actual task they are using: desc "Run all stories" task :stories do html = 'story_server/prototype/rspec_stories.html' ruby "stories/all.rb --colour --format plain --format html:#{html}" unless IO.read(html) =~ //m raise 'highlighted parameters are broken in story HTML' end end From joshknowles at gmail.com Wed Dec 19 21:28:39 2007 From: joshknowles at gmail.com (Josh Knowles) Date: Wed, 19 Dec 2007 21:28:39 -0500 Subject: [rspec-users] Story runner rake task In-Reply-To: References: Message-ID: On 12/19/07, James Deville wrote: > What's the status on a rake task for the story runner. If nothing is > in progress, where could I start to try and build one? Until step/scenario directories are standardized you're not going to see a rake task committed. Feel free to roll your own, I wrote a simple one that just calls all.rb. -- Josh Knowles phone: 509-979-1593 email: joshknowles at gmail.com web: http://joshknowles.com From mailing_lists at bengreenberg.net Wed Dec 19 22:29:49 2007 From: mailing_lists at bengreenberg.net (Ben Greenberg) Date: Wed, 19 Dec 2007 22:29:49 -0500 Subject: [rspec-users] Installation Trouble In-Reply-To: <348F34C7-D00C-4500-98BA-E3F7D0486748@spicycode.com> References: <47691D44.9000500@bengreenberg.net> <57c63afe0712190644m4440a012n9136b87095e5eb89@mail.gmail.com> <47692EDC.3000804@bengreenberg.net> <57c63afe0712190711p2cba3f9blcb27c54dbfc953f9@mail.gmail.com> <348F34C7-D00C-4500-98BA-E3F7D0486748@spicycode.com> Message-ID: <4769E1AD.9070504@bengreenberg.net> Chad Humphries wrote: > Also, could you post the spec if possible? > > - Chad > > On Dec 19, 2007, at 10:11 AM, David Chelimsky wrote: > > >> And you've got the following near the top of spec/spec_helper.rb? >> >> require 'spec' >> require 'spec/rails' >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> My spec/spec_helper.rb does contain those lines. I did not modify it after it was generated. The one spec I have is spec/models/image_spec.rb. The contents are: require File.dirname(__FILE__) + '/../spec_helper.rb' describe Image, "brand new" do before(:each) do @image = Image.new end it "should be in the review bucket" do @image.bucket.should equal(Bucket.review) end end Thanks, Ben -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071219/3f2c1e8e/attachment.html From james.deville at gmail.com Thu Dec 20 00:34:12 2007 From: james.deville at gmail.com (James Deville) Date: Wed, 19 Dec 2007 21:34:12 -0800 Subject: [rspec-users] Story runner rake task In-Reply-To: References: Message-ID: <75D18260-5D95-4B1F-BCC6-9D0A8C98CB47@gmail.com> Yeah, had a slight email conversation with David C about that in regards to bug #188. I am wondering why we don't standardize it, ya know convention over configuration and all. JD On Dec 19, 2007, at 6:28 PM, Josh Knowles wrote: > On 12/19/07, James Deville wrote: >> What's the status on a rake task for the story runner. If nothing is >> in progress, where could I start to try and build one? > > Until step/scenario directories are standardized you're not going to > see a rake task committed. > > Feel free to roll your own, I wrote a simple one that just calls > all.rb. > > > -- > Josh Knowles > phone: 509-979-1593 > email: joshknowles at gmail.com > web: http://joshknowles.com > _______________________________________________ > rspec-users mailing list > rspec-use From james.deville at gmail.com Thu Dec 20 00:34:52 2007 From: james.deville at gmail.com (James Deville) Date: Wed, 19 Dec 2007 21:34:52 -0800 Subject: [rspec-users] Story runner rake task In-Reply-To: <4769C03E.5060507@benmabey.com> References: <4769BFD7.30904@benmabey.com> <4769C03E.5060507@benmabey.com> Message-ID: What file is that in? I was looking for one in trunk earlier. JD On Dec 19, 2007, at 5:07 PM, Ben Mabey wrote: > Ben Mabey wrote: >> James Deville wrote: >> >>> What's the status on a rake task for the story runner. If nothing is >>> in progress, where could I start to try and build one? >>> >>> JD >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >>> >> >> If you check out rspec trunk you can see that they have created one >> for >> the rspec project. It just runs the all.rb file in the stories >> directory. >> >> -Ben >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > This is the actual task they are using: > > desc "Run all stories" > task :stories do > html = 'story_server/prototype/rspec_stories.html' > ruby "stories/all.rb --colour --format plain --format html:#{html}" > unless IO.read(html) =~ //m > raise 'highlighted parameters are broken in story HTML' > end > end > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Thu Dec 20 00:38:39 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 19 Dec 2007 23:38:39 -0600 Subject: [rspec-users] Story runner rake task In-Reply-To: <75D18260-5D95-4B1F-BCC6-9D0A8C98CB47@gmail.com> References: <75D18260-5D95-4B1F-BCC6-9D0A8C98CB47@gmail.com> Message-ID: <57c63afe0712192138v6ae83c3aiaad7adbd09a4fce5@mail.gmail.com> On Dec 19, 2007 11:34 PM, James Deville wrote: > Yeah, had a slight email conversation with David C about that in > regards to bug #188. I am wondering why we don't standardize it, ya > know convention over configuration and all. Because I think it's premature to call anything related to story runner a convention. I actually organize them differently from what many are calling convention, and my way is not necessarily "right" or "better." Let's wait a while on this. We'll get there. From james.deville at gmail.com Thu Dec 20 00:40:33 2007 From: james.deville at gmail.com (James Deville) Date: Wed, 19 Dec 2007 21:40:33 -0800 Subject: [rspec-users] Story runner rake task In-Reply-To: <57c63afe0712192138v6ae83c3aiaad7adbd09a4fce5@mail.gmail.com> References: <75D18260-5D95-4B1F-BCC6-9D0A8C98CB47@gmail.com> <57c63afe0712192138v6ae83c3aiaad7adbd09a4fce5@mail.gmail.com> Message-ID: <6A09754D-7C3E-4125-8DA9-80089F8B525C@gmail.com> On Dec 19, 2007, at 9:38 PM, David Chelimsky wrote: > On Dec 19, 2007 11:34 PM, James Deville > wrote: >> Yeah, had a slight email conversation with David C about that in >> regards to bug #188. I am wondering why we don't standardize it, ya >> know convention over configuration and all. > > Because I think it's premature to call anything related to story > runner a convention. I actually organize them differently from what > many are calling convention, and my way is not necessarily "right" or > "better." Let's wait a while on this. We'll get there. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Good enough for me. I just wanted a reason. May I ask how you set them up? James Deville From dchelimsky at gmail.com Thu Dec 20 00:44:13 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 19 Dec 2007 23:44:13 -0600 Subject: [rspec-users] Story runner rake task In-Reply-To: <6A09754D-7C3E-4125-8DA9-80089F8B525C@gmail.com> References: <75D18260-5D95-4B1F-BCC6-9D0A8C98CB47@gmail.com> <57c63afe0712192138v6ae83c3aiaad7adbd09a4fce5@mail.gmail.com> <6A09754D-7C3E-4125-8DA9-80089F8B525C@gmail.com> Message-ID: <57c63afe0712192144p644d3d2fkeda2979c85d3aac@mail.gmail.com> On Dec 19, 2007 11:40 PM, James Deville wrote: > > > On Dec 19, 2007, at 9:38 PM, David Chelimsky wrote: > > > On Dec 19, 2007 11:34 PM, James Deville > > wrote: > >> Yeah, had a slight email conversation with David C about that in > >> regards to bug #188. I am wondering why we don't standardize it, ya > >> know convention over configuration and all. > > > > Because I think it's premature to call anything related to story > > runner a convention. I actually organize them differently from what > > many are calling convention, and my way is not necessarily "right" or > > "better." Let's wait a while on this. We'll get there. > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > Good enough for me. I just wanted a reason. May I ask how you set them > up? Sure. stories/ stories/helper.rb stories/steps/ (steps go in here - that seems to be the "convention") stories/stuff_related_to_one_feature stories/stuff_related_to_another_feature stories/stuff_related_to_yet_another_feature So in this case, the only thing that would be consistent across projects would be helper.rb and the steps directory. Even that should probably be called step_definitions or something. I'm not sure. Anyhow - that's where I'm at. How about you? From james.deville at gmail.com Thu Dec 20 00:50:33 2007 From: james.deville at gmail.com (James Deville) Date: Wed, 19 Dec 2007 21:50:33 -0800 Subject: [rspec-users] Story runner rake task In-Reply-To: <57c63afe0712192144p644d3d2fkeda2979c85d3aac@mail.gmail.com> References: <75D18260-5D95-4B1F-BCC6-9D0A8C98CB47@gmail.com> <57c63afe0712192138v6ae83c3aiaad7adbd09a4fce5@mail.gmail.com> <6A09754D-7C3E-4125-8DA9-80089F8B525C@gmail.com> <57c63afe0712192144p644d3d2fkeda2979c85d3aac@mail.gmail.com> Message-ID: On Dec 19, 2007, at 9:44 PM, David Chelimsky wrote: > On Dec 19, 2007 11:40 PM, James Deville > wrote: >> >> >> On Dec 19, 2007, at 9:38 PM, David Chelimsky wrote: >> >>> On Dec 19, 2007 11:34 PM, James Deville >>> wrote: >>>> Yeah, had a slight email conversation with David C about that in >>>> regards to bug #188. I am wondering why we don't standardize it, ya >>>> know convention over configuration and all. >>> >>> Because I think it's premature to call anything related to story >>> runner a convention. I actually organize them differently from what >>> many are calling convention, and my way is not necessarily "right" >>> or >>> "better." Let's wait a while on this. We'll get there. >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> >> Good enough for me. I just wanted a reason. May I ask how you set >> them >> up? > > Sure. > > stories/ > stories/helper.rb > stories/steps/ (steps go in here - that seems to be the "convention") > stories/stuff_related_to_one_feature > stories/stuff_related_to_another_feature > stories/stuff_related_to_yet_another_feature > > So in this case, the only thing that would be consistent across > projects would be helper.rb and the steps directory. Even that should > probably be called step_definitions or something. I'm not sure. > > Anyhow - that's where I'm at. How about you? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users I've been doing a feature per file. So I have: stories/ stories/helper.rb stories/steps/ stories/stories/ So in stories/stories I have my stories with multiple scenarios per story. I'm definitely seeing your point, and the reason for leaving it as is. Do you use selenium or anything like that via the stories? If not, what kinds of things do you test with stories? JD From dchelimsky at gmail.com Thu Dec 20 01:16:00 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 20 Dec 2007 00:16:00 -0600 Subject: [rspec-users] Story runner rake task In-Reply-To: References: <75D18260-5D95-4B1F-BCC6-9D0A8C98CB47@gmail.com> <57c63afe0712192138v6ae83c3aiaad7adbd09a4fce5@mail.gmail.com> <6A09754D-7C3E-4125-8DA9-80089F8B525C@gmail.com> <57c63afe0712192144p644d3d2fkeda2979c85d3aac@mail.gmail.com> Message-ID: <57c63afe0712192216w3e981456qd9d04d7012990f99@mail.gmail.com> On Dec 19, 2007 11:50 PM, James Deville wrote: > > > On Dec 19, 2007, at 9:44 PM, David Chelimsky wrote: > > > On Dec 19, 2007 11:40 PM, James Deville > > wrote: > >> > >> > >> On Dec 19, 2007, at 9:38 PM, David Chelimsky wrote: > >> > >>> On Dec 19, 2007 11:34 PM, James Deville > >>> wrote: > >>>> Yeah, had a slight email conversation with David C about that in > >>>> regards to bug #188. I am wondering why we don't standardize it, ya > >>>> know convention over configuration and all. > >>> > >>> Because I think it's premature to call anything related to story > >>> runner a convention. I actually organize them differently from what > >>> many are calling convention, and my way is not necessarily "right" > >>> or > >>> "better." Let's wait a while on this. We'll get there. > >>> _______________________________________________ > >>> rspec-users mailing list > >>> rspec-users at rubyforge.org > >>> http://rubyforge.org/mailman/listinfo/rspec-users > >> > >> > >> Good enough for me. I just wanted a reason. May I ask how you set > >> them > >> up? > > > > Sure. > > > > stories/ > > stories/helper.rb > > stories/steps/ (steps go in here - that seems to be the "convention") > > stories/stuff_related_to_one_feature > > stories/stuff_related_to_another_feature > > stories/stuff_related_to_yet_another_feature > > > > So in this case, the only thing that would be consistent across > > projects would be helper.rb and the steps directory. Even that should > > probably be called step_definitions or something. I'm not sure. > > > > Anyhow - that's where I'm at. How about you? > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > I've been doing a feature per file. So I have: > > stories/ > stories/helper.rb > stories/steps/ > stories/stories/ > > So in stories/stories I have my stories with multiple scenarios per > story. > > I'm definitely seeing your point, and the reason for leaving it as is. > > Do you use selenium or anything like that via the stories? If not, > what kinds of things do you test with stories? I've got a bunch of selenium tests being driven by spec/ui. I haven't converted them to stories yet. Mostly I've been using webrat, Bryan Helmkamp's awesome Hpricot-wrapping goodness. It doesn't cover javascript, but the apps I've been working on have been very vanilla with respect to ajax, so I've been satisfied with have_rjs. Anyhow, webrat does something really cool - it ties your form submissions to the html of the rendered form. So you make steps like this: ===================== When "I go to log in" do visits "/session/new" end When "I enter $label: $value" do |label, value| fills_in label, :with => value end When "I submit my credentials" do clicks_button end Then "I should see $message" do |message| response.should have_text(/#{message}/) end ===================== And a scenario like this: ===================== When I go to log in And I enter Username: david And I enter Password: webrat rules And I submit my credentials Then I should see Welcome david ===================== And what webrat does is grabs the html from the response in the visits method, modifies that html with your data in the fills_in method, and then yanks the data from the html and submits it with the clicks_button method. What this means is that if the form isn't aligned with the fields you're submitting, you'll get a failure. How clean is that? From james.deville at gmail.com Thu Dec 20 01:25:42 2007 From: james.deville at gmail.com (James Deville) Date: Wed, 19 Dec 2007 22:25:42 -0800 Subject: [rspec-users] Story runner rake task In-Reply-To: <57c63afe0712192216w3e981456qd9d04d7012990f99@mail.gmail.com> References: <75D18260-5D95-4B1F-BCC6-9D0A8C98CB47@gmail.com> <57c63afe0712192138v6ae83c3aiaad7adbd09a4fce5@mail.gmail.com> <6A09754D-7C3E-4125-8DA9-80089F8B525C@gmail.com> <57c63afe0712192144p644d3d2fkeda2979c85d3aac@mail.gmail.com> <57c63afe0712192216w3e981456qd9d04d7012990f99@mail.gmail.com> Message-ID: On Dec 19, 2007, at 10:16 PM, David Chelimsky wrote: > On Dec 19, 2007 11:50 PM, James Deville > wrote: >> >> >> On Dec 19, 2007, at 9:44 PM, David Chelimsky wrote: >> >>> On Dec 19, 2007 11:40 PM, James Deville >>> wrote: >>>> >>>> >>>> On Dec 19, 2007, at 9:38 PM, David Chelimsky wrote: >>>> >>>>> On Dec 19, 2007 11:34 PM, James Deville >>>>> wrote: >>>>>> Yeah, had a slight email conversation with David C about that in >>>>>> regards to bug #188. I am wondering why we don't standardize >>>>>> it, ya >>>>>> know convention over configuration and all. >>>>> >>>>> Because I think it's premature to call anything related to story >>>>> runner a convention. I actually organize them differently from >>>>> what >>>>> many are calling convention, and my way is not necessarily "right" >>>>> or >>>>> "better." Let's wait a while on this. We'll get there. >>>>> _______________________________________________ >>>>> rspec-users mailing list >>>>> rspec-users at rubyforge.org >>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>> >>>> >>>> Good enough for me. I just wanted a reason. May I ask how you set >>>> them >>>> up? >>> >>> Sure. >>> >>> stories/ >>> stories/helper.rb >>> stories/steps/ (steps go in here - that seems to be the >>> "convention") >>> stories/stuff_related_to_one_feature >>> stories/stuff_related_to_another_feature >>> stories/stuff_related_to_yet_another_feature >>> >>> So in this case, the only thing that would be consistent across >>> projects would be helper.rb and the steps directory. Even that >>> should >>> probably be called step_definitions or something. I'm not sure. >>> >>> Anyhow - that's where I'm at. How about you? >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> I've been doing a feature per file. So I have: >> >> stories/ >> stories/helper.rb >> stories/steps/ >> stories/stories/ >> >> So in stories/stories I have my stories with multiple scenarios per >> story. >> >> I'm definitely seeing your point, and the reason for leaving it as >> is. >> >> Do you use selenium or anything like that via the stories? If not, >> what kinds of things do you test with stories? > > I've got a bunch of selenium tests being driven by spec/ui. I haven't > converted them to stories yet. > > Mostly I've been using webrat, Bryan Helmkamp's awesome > Hpricot-wrapping goodness. It doesn't cover javascript, but the apps > I've been working on have been very vanilla with respect to ajax, so > I've been satisfied with have_rjs. > > Anyhow, webrat does something really cool - it ties your form > submissions to the html of the rendered form. So you make steps like > this: > > ===================== > When "I go to log in" do > visits "/session/new" > end > > When "I enter $label: $value" do |label, value| > fills_in label, :with => value > end > > When "I submit my credentials" do > clicks_button > end > > Then "I should see $message" do |message| > response.should have_text(/#{message}/) > end > ===================== > > And a scenario like this: > > ===================== > When I go to log in > And I enter Username: david > And I enter Password: webrat rules > And I submit my credentials > Then I should see Welcome david > ===================== > > And what webrat does is grabs the html from the response in the visits > method, modifies that html with your data in the fills_in method, and > then yanks the data from the html and submits it with the > clicks_button method. What this means is that if the form isn't > aligned with the fields you're submitting, you'll get a failure. > > How clean is that? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Um... Sweetness!!! How is it for speed? There is a ton of stuff we would love to move out of Selenium due to issues with sessions, flash, and database persistance. JD From dchelimsky at gmail.com Thu Dec 20 01:42:09 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 20 Dec 2007 00:42:09 -0600 Subject: [rspec-users] Story runner rake task In-Reply-To: References: <75D18260-5D95-4B1F-BCC6-9D0A8C98CB47@gmail.com> <57c63afe0712192138v6ae83c3aiaad7adbd09a4fce5@mail.gmail.com> <6A09754D-7C3E-4125-8DA9-80089F8B525C@gmail.com> <57c63afe0712192144p644d3d2fkeda2979c85d3aac@mail.gmail.com> <57c63afe0712192216w3e981456qd9d04d7012990f99@mail.gmail.com> Message-ID: <57c63afe0712192242g5bcfecabk5225146ff84dba3f@mail.gmail.com> On Dec 20, 2007 12:25 AM, James Deville wrote: > > > On Dec 19, 2007, at 10:16 PM, David Chelimsky wrote: > > > On Dec 19, 2007 11:50 PM, James Deville > > wrote: > >> > >> > >> On Dec 19, 2007, at 9:44 PM, David Chelimsky wrote: > >> > >>> On Dec 19, 2007 11:40 PM, James Deville > >>> wrote: > >>>> > >>>> > >>>> On Dec 19, 2007, at 9:38 PM, David Chelimsky wrote: > >>>> > >>>>> On Dec 19, 2007 11:34 PM, James Deville > >>>>> wrote: > >>>>>> Yeah, had a slight email conversation with David C about that in > >>>>>> regards to bug #188. I am wondering why we don't standardize > >>>>>> it, ya > >>>>>> know convention over configuration and all. > >>>>> > >>>>> Because I think it's premature to call anything related to story > >>>>> runner a convention. I actually organize them differently from > >>>>> what > >>>>> many are calling convention, and my way is not necessarily "right" > >>>>> or > >>>>> "better." Let's wait a while on this. We'll get there. > >>>>> _______________________________________________ > >>>>> rspec-users mailing list > >>>>> rspec-users at rubyforge.org > >>>>> http://rubyforge.org/mailman/listinfo/rspec-users > >>>> > >>>> > >>>> Good enough for me. I just wanted a reason. May I ask how you set > >>>> them > >>>> up? > >>> > >>> Sure. > >>> > >>> stories/ > >>> stories/helper.rb > >>> stories/steps/ (steps go in here - that seems to be the > >>> "convention") > >>> stories/stuff_related_to_one_feature > >>> stories/stuff_related_to_another_feature > >>> stories/stuff_related_to_yet_another_feature > >>> > >>> So in this case, the only thing that would be consistent across > >>> projects would be helper.rb and the steps directory. Even that > >>> should > >>> probably be called step_definitions or something. I'm not sure. > >>> > >>> Anyhow - that's where I'm at. How about you? > >>> _______________________________________________ > >>> rspec-users mailing list > >>> rspec-users at rubyforge.org > >>> http://rubyforge.org/mailman/listinfo/rspec-users > >> > >> I've been doing a feature per file. So I have: > >> > >> stories/ > >> stories/helper.rb > >> stories/steps/ > >> stories/stories/ > >> > >> So in stories/stories I have my stories with multiple scenarios per > >> story. > >> > >> I'm definitely seeing your point, and the reason for leaving it as > >> is. > >> > >> Do you use selenium or anything like that via the stories? If not, > >> what kinds of things do you test with stories? > > > > I've got a bunch of selenium tests being driven by spec/ui. I haven't > > converted them to stories yet. > > > > Mostly I've been using webrat, Bryan Helmkamp's awesome > > Hpricot-wrapping goodness. It doesn't cover javascript, but the apps > > I've been working on have been very vanilla with respect to ajax, so > > I've been satisfied with have_rjs. > > > > Anyhow, webrat does something really cool - it ties your form > > submissions to the html of the rendered form. So you make steps like > > this: > > > > ===================== > > When "I go to log in" do > > visits "/session/new" > > end > > > > When "I enter $label: $value" do |label, value| > > fills_in label, :with => value > > end > > > > When "I submit my credentials" do > > clicks_button > > end > > > > Then "I should see $message" do |message| > > response.should have_text(/#{message}/) > > end > > ===================== > > > > And a scenario like this: > > > > ===================== > > When I go to log in > > And I enter Username: david > > And I enter Password: webrat rules > > And I submit my credentials > > Then I should see Welcome david > > ===================== > > > > And what webrat does is grabs the html from the response in the visits > > method, modifies that html with your data in the fills_in method, and > > then yanks the data from the html and submits it with the > > clicks_button method. What this means is that if the form isn't > > aligned with the fields you're submitting, you'll get a failure. > > > > How clean is that? > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > Um... Sweetness!!! How is it for speed? There is a ton of stuff we > would love to move out of Selenium due to issues with sessions, flash, > and database persistance. Obviously it's much faster than running stuff in a browser. I have nothing else to measure it against and haven't done any real benchmarking, but it is perceivably much faster than running selenium. What I'd recommend - where I'm headed as the opportunity presents itself - is to have in-memory and in-browser implementations of the same steps. Then you can run them in-memory most of the time and skip the javascript, but run them in-browser once in a while - like before commits - to make sure the javascript is all working too. There's also an interesting javascript testing framework that I think shows a lot of promise called crosscheck (http://www.thefrontside.net/crosscheck). It's basically got it's own browser-less javascript engines and runs in-memory. Last I heard it was mostly dead-on, but that it missed some things. The guy who told me that said he was running selenium for a few things that crosscheck didn't do right, but I don't know what those are :) I did toy with it for a minute, and it's blazingly fast. I just haven't made a commitment to use it in anger yet - but I'm looking forward to the opportunity to. Cheers, David From ben at benmabey.com Thu Dec 20 01:42:44 2007 From: ben at benmabey.com (Ben Mabey) Date: Wed, 19 Dec 2007 23:42:44 -0700 Subject: [rspec-users] Story runner rake task In-Reply-To: References: <75D18260-5D95-4B1F-BCC6-9D0A8C98CB47@gmail.com> <57c63afe0712192138v6ae83c3aiaad7adbd09a4fce5@mail.gmail.com> <6A09754D-7C3E-4125-8DA9-80089F8B525C@gmail.com> <57c63afe0712192144p644d3d2fkeda2979c85d3aac@mail.gmail.com> <57c63afe0712192216w3e981456qd9d04d7012990f99@mail.gmail.com> Message-ID: <476A0EE4.7090402@benmabey.com> James Deville wrote: > On Dec 19, 2007, at 10:16 PM, David Chelimsky wrote: > > >> On Dec 19, 2007 11:50 PM, James Deville >> wrote: >> >>> On Dec 19, 2007, at 9:44 PM, David Chelimsky wrote: >>> >>> >>>> On Dec 19, 2007 11:40 PM, James Deville >>>> wrote: >>>> >>>>> On Dec 19, 2007, at 9:38 PM, David Chelimsky wrote: >>>>> >>>>> >>>>>> On Dec 19, 2007 11:34 PM, James Deville >>>>>> wrote: >>>>>> >>>>>>> Yeah, had a slight email conversation with David C about that in >>>>>>> regards to bug #188. I am wondering why we don't standardize >>>>>>> it, ya >>>>>>> know convention over configuration and all. >>>>>>> >>>>>> Because I think it's premature to call anything related to story >>>>>> runner a convention. I actually organize them differently from >>>>>> what >>>>>> many are calling convention, and my way is not necessarily "right" >>>>>> or >>>>>> "better." Let's wait a while on this. We'll get there. >>>>>> _______________________________________________ >>>>>> rspec-users mailing list >>>>>> rspec-users at rubyforge.org >>>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>>> >>>>> Good enough for me. I just wanted a reason. May I ask how you set >>>>> them >>>>> up? >>>>> >>>> Sure. >>>> >>>> stories/ >>>> stories/helper.rb >>>> stories/steps/ (steps go in here - that seems to be the >>>> "convention") >>>> stories/stuff_related_to_one_feature >>>> stories/stuff_related_to_another_feature >>>> stories/stuff_related_to_yet_another_feature >>>> >>>> So in this case, the only thing that would be consistent across >>>> projects would be helper.rb and the steps directory. Even that >>>> should >>>> probably be called step_definitions or something. I'm not sure. >>>> >>>> Anyhow - that's where I'm at. How about you? >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-users at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>> >>> I've been doing a feature per file. So I have: >>> >>> stories/ >>> stories/helper.rb >>> stories/steps/ >>> stories/stories/ >>> >>> So in stories/stories I have my stories with multiple scenarios per >>> story. >>> >>> I'm definitely seeing your point, and the reason for leaving it as >>> is. >>> >>> Do you use selenium or anything like that via the stories? If not, >>> what kinds of things do you test with stories? >>> >> I've got a bunch of selenium tests being driven by spec/ui. I haven't >> converted them to stories yet. >> >> Mostly I've been using webrat, Bryan Helmkamp's awesome >> Hpricot-wrapping goodness. It doesn't cover javascript, but the apps >> I've been working on have been very vanilla with respect to ajax, so >> I've been satisfied with have_rjs. >> >> Anyhow, webrat does something really cool - it ties your form >> submissions to the html of the rendered form. So you make steps like >> this: >> >> ===================== >> When "I go to log in" do >> visits "/session/new" >> end >> >> When "I enter $label: $value" do |label, value| >> fills_in label, :with => value >> end >> >> When "I submit my credentials" do >> clicks_button >> end >> >> Then "I should see $message" do |message| >> response.should have_text(/#{message}/) >> end >> ===================== >> >> And a scenario like this: >> >> ===================== >> When I go to log in >> And I enter Username: david >> And I enter Password: webrat rules >> And I submit my credentials >> Then I should see Welcome david >> ===================== >> >> And what webrat does is grabs the html from the response in the visits >> method, modifies that html with your data in the fills_in method, and >> then yanks the data from the html and submits it with the >> clicks_button method. What this means is that if the form isn't >> aligned with the fields you're submitting, you'll get a failure. >> >> How clean is that? >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > Um... Sweetness!!! How is it for speed? There is a ton of stuff we > would love to move out of Selenium due to issues with sessions, flash, > and database persistance. > > JD > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > Yeah, I'm curious about speed as well. We decided not to switch over to webrat because we thought that using hpricot on all of the tests would slow things down compared to the regular assert_select and other integration helpers. Is there much of a speed difference? -Ben From jonathan at parkerhill.com Thu Dec 20 01:43:52 2007 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Thu, 20 Dec 2007 01:43:52 -0500 Subject: [rspec-users] link to lighthouse? Message-ID: fyi, there doesnt seem to be a link to rspec.lighthouse.com from the new web site (unless I missed it). I guess I expected it under "Community" linoj From dchelimsky at gmail.com Thu Dec 20 01:48:19 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 20 Dec 2007 00:48:19 -0600 Subject: [rspec-users] Story runner rake task In-Reply-To: <476A0EE4.7090402@benmabey.com> References: <75D18260-5D95-4B1F-BCC6-9D0A8C98CB47@gmail.com> <57c63afe0712192138v6ae83c3aiaad7adbd09a4fce5@mail.gmail.com> <6A09754D-7C3E-4125-8DA9-80089F8B525C@gmail.com> <57c63afe0712192144p644d3d2fkeda2979c85d3aac@mail.gmail.com> <57c63afe0712192216w3e981456qd9d04d7012990f99@mail.gmail.com> <476A0EE4.7090402@benmabey.com> Message-ID: <57c63afe0712192248w1a027381sc2e71b4be48c9d06@mail.gmail.com> On Dec 20, 2007 12:42 AM, Ben Mabey wrote: > > James Deville wrote: > > On Dec 19, 2007, at 10:16 PM, David Chelimsky wrote: > > > > > >> On Dec 19, 2007 11:50 PM, James Deville > >> wrote: > >> > >>> On Dec 19, 2007, at 9:44 PM, David Chelimsky wrote: > >>> > >>> > >>>> On Dec 19, 2007 11:40 PM, James Deville > >>>> wrote: > >>>> > >>>>> On Dec 19, 2007, at 9:38 PM, David Chelimsky wrote: > >>>>> > >>>>> > >>>>>> On Dec 19, 2007 11:34 PM, James Deville > >>>>>> wrote: > >>>>>> > >>>>>>> Yeah, had a slight email conversation with David C about that in > >>>>>>> regards to bug #188. I am wondering why we don't standardize > >>>>>>> it, ya > >>>>>>> know convention over configuration and all. > >>>>>>> > >>>>>> Because I think it's premature to call anything related to story > >>>>>> runner a convention. I actually organize them differently from > >>>>>> what > >>>>>> many are calling convention, and my way is not necessarily "right" > >>>>>> or > >>>>>> "better." Let's wait a while on this. We'll get there. > >>>>>> _______________________________________________ > >>>>>> rspec-users mailing list > >>>>>> rspec-users at rubyforge.org > >>>>>> http://rubyforge.org/mailman/listinfo/rspec-users > >>>>>> > >>>>> Good enough for me. I just wanted a reason. May I ask how you set > >>>>> them > >>>>> up? > >>>>> > >>>> Sure. > >>>> > >>>> stories/ > >>>> stories/helper.rb > >>>> stories/steps/ (steps go in here - that seems to be the > >>>> "convention") > >>>> stories/stuff_related_to_one_feature > >>>> stories/stuff_related_to_another_feature > >>>> stories/stuff_related_to_yet_another_feature > >>>> > >>>> So in this case, the only thing that would be consistent across > >>>> projects would be helper.rb and the steps directory. Even that > >>>> should > >>>> probably be called step_definitions or something. I'm not sure. > >>>> > >>>> Anyhow - that's where I'm at. How about you? > >>>> _______________________________________________ > >>>> rspec-users mailing list > >>>> rspec-users at rubyforge.org > >>>> http://rubyforge.org/mailman/listinfo/rspec-users > >>>> > >>> I've been doing a feature per file. So I have: > >>> > >>> stories/ > >>> stories/helper.rb > >>> stories/steps/ > >>> stories/stories/ > >>> > >>> So in stories/stories I have my stories with multiple scenarios per > >>> story. > >>> > >>> I'm definitely seeing your point, and the reason for leaving it as > >>> is. > >>> > >>> Do you use selenium or anything like that via the stories? If not, > >>> what kinds of things do you test with stories? > >>> > >> I've got a bunch of selenium tests being driven by spec/ui. I haven't > >> converted them to stories yet. > >> > >> Mostly I've been using webrat, Bryan Helmkamp's awesome > >> Hpricot-wrapping goodness. It doesn't cover javascript, but the apps > >> I've been working on have been very vanilla with respect to ajax, so > >> I've been satisfied with have_rjs. > >> > >> Anyhow, webrat does something really cool - it ties your form > >> submissions to the html of the rendered form. So you make steps like > >> this: > >> > >> ===================== > >> When "I go to log in" do > >> visits "/session/new" > >> end > >> > >> When "I enter $label: $value" do |label, value| > >> fills_in label, :with => value > >> end > >> > >> When "I submit my credentials" do > >> clicks_button > >> end > >> > >> Then "I should see $message" do |message| > >> response.should have_text(/#{message}/) > >> end > >> ===================== > >> > >> And a scenario like this: > >> > >> ===================== > >> When I go to log in > >> And I enter Username: david > >> And I enter Password: webrat rules > >> And I submit my credentials > >> Then I should see Welcome david > >> ===================== > >> > >> And what webrat does is grabs the html from the response in the visits > >> method, modifies that html with your data in the fills_in method, and > >> then yanks the data from the html and submits it with the > >> clicks_button method. What this means is that if the form isn't > >> aligned with the fields you're submitting, you'll get a failure. > >> > >> How clean is that? > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-users at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/rspec-users > >> > > > > > > Um... Sweetness!!! How is it for speed? There is a ton of stuff we > > would love to move out of Selenium due to issues with sessions, flash, > > and database persistance. > > > > JD > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > Yeah, I'm curious about speed as well. We decided not to switch over to > webrat because we thought that using hpricot on all of the tests would > slow things down compared to the regular assert_select and other > integration helpers. Is there much of a speed difference? I haven't compared directly - I would have to assume it's slower not necessarily because of hpricot, but because of the strategy of tying the inputs to the form and building the post from the html. But that is very, very comforting - especially in integration tests. Without that, assert_select leaves you with the same problems that mocks do - you could get all your isolation tests to pass, but integration fails. From dchelimsky at gmail.com Thu Dec 20 01:49:20 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 20 Dec 2007 00:49:20 -0600 Subject: [rspec-users] link to lighthouse? In-Reply-To: References: Message-ID: <57c63afe0712192249i1ba12782y2d0d2026a944c0df@mail.gmail.com> On Dec 20, 2007 12:43 AM, Jonathan Linowes wrote: > fyi, there doesnt seem to be a link to rspec.lighthouse.com from the > new web site (unless I missed it). I guess I expected it under > "Community" http://rspec.info/community/contribute.html > > linoj > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From james.deville at gmail.com Thu Dec 20 01:55:00 2007 From: james.deville at gmail.com (James Deville) Date: Wed, 19 Dec 2007 22:55:00 -0800 Subject: [rspec-users] Story runner rake task In-Reply-To: <57c63afe0712192242g5bcfecabk5225146ff84dba3f@mail.gmail.com> References: <75D18260-5D95-4B1F-BCC6-9D0A8C98CB47@gmail.com> <57c63afe0712192138v6ae83c3aiaad7adbd09a4fce5@mail.gmail.com> <6A09754D-7C3E-4125-8DA9-80089F8B525C@gmail.com> <57c63afe0712192144p644d3d2fkeda2979c85d3aac@mail.gmail.com> <57c63afe0712192216w3e981456qd9d04d7012990f99@mail.gmail.com> <57c63afe0712192242g5bcfecabk5225146ff84dba3f@mail.gmail.com> Message-ID: <26B603F8-8907-48DD-ACC0-CAACBF738274@gmail.com> On Dec 19, 2007, at 10:42 PM, David Chelimsky wrote: > On Dec 20, 2007 12:25 AM, James Deville > wrote: >> >> >> On Dec 19, 2007, at 10:16 PM, David Chelimsky wrote: >> >>> On Dec 19, 2007 11:50 PM, James Deville >>> wrote: >>>> >>>> >>>> On Dec 19, 2007, at 9:44 PM, David Chelimsky wrote: >>>> >>>>> On Dec 19, 2007 11:40 PM, James Deville >>>>> wrote: >>>>>> >>>>>> >>>>>> On Dec 19, 2007, at 9:38 PM, David Chelimsky wrote: >>>>>> >>>>>>> On Dec 19, 2007 11:34 PM, James Deville >>>>>>> >>>>>>> wrote: >>>>>>>> Yeah, had a slight email conversation with David C about that >>>>>>>> in >>>>>>>> regards to bug #188. I am wondering why we don't standardize >>>>>>>> it, ya >>>>>>>> know convention over configuration and all. >>>>>>> >>>>>>> Because I think it's premature to call anything related to story >>>>>>> runner a convention. I actually organize them differently from >>>>>>> what >>>>>>> many are calling convention, and my way is not necessarily >>>>>>> "right" >>>>>>> or >>>>>>> "better." Let's wait a while on this. We'll get there. >>>>>>> _______________________________________________ >>>>>>> rspec-users mailing list >>>>>>> rspec-users at rubyforge.org >>>>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>>> >>>>>> >>>>>> Good enough for me. I just wanted a reason. May I ask how you set >>>>>> them >>>>>> up? >>>>> >>>>> Sure. >>>>> >>>>> stories/ >>>>> stories/helper.rb >>>>> stories/steps/ (steps go in here - that seems to be the >>>>> "convention") >>>>> stories/stuff_related_to_one_feature >>>>> stories/stuff_related_to_another_feature >>>>> stories/stuff_related_to_yet_another_feature >>>>> >>>>> So in this case, the only thing that would be consistent across >>>>> projects would be helper.rb and the steps directory. Even that >>>>> should >>>>> probably be called step_definitions or something. I'm not sure. >>>>> >>>>> Anyhow - that's where I'm at. How about you? >>>>> _______________________________________________ >>>>> rspec-users mailing list >>>>> rspec-users at rubyforge.org >>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>> >>>> I've been doing a feature per file. So I have: >>>> >>>> stories/ >>>> stories/helper.rb >>>> stories/steps/ >>>> stories/stories/ >>>> >>>> So in stories/stories I have my stories with multiple scenarios per >>>> story. >>>> >>>> I'm definitely seeing your point, and the reason for leaving it as >>>> is. >>>> >>>> Do you use selenium or anything like that via the stories? If not, >>>> what kinds of things do you test with stories? >>> >>> I've got a bunch of selenium tests being driven by spec/ui. I >>> haven't >>> converted them to stories yet. >>> >>> Mostly I've been using webrat, Bryan Helmkamp's awesome >>> Hpricot-wrapping goodness. It doesn't cover javascript, but the apps >>> I've been working on have been very vanilla with respect to ajax, so >>> I've been satisfied with have_rjs. >>> >>> Anyhow, webrat does something really cool - it ties your form >>> submissions to the html of the rendered form. So you make steps like >>> this: >>> >>> ===================== >>> When "I go to log in" do >>> visits "/session/new" >>> end >>> >>> When "I enter $label: $value" do |label, value| >>> fills_in label, :with => value >>> end >>> >>> When "I submit my credentials" do >>> clicks_button >>> end >>> >>> Then "I should see $message" do |message| >>> response.should have_text(/#{message}/) >>> end >>> ===================== >>> >>> And a scenario like this: >>> >>> ===================== >>> When I go to log in >>> And I enter Username: david >>> And I enter Password: webrat rules >>> And I submit my credentials >>> Then I should see Welcome david >>> ===================== >>> >>> And what webrat does is grabs the html from the response in the >>> visits >>> method, modifies that html with your data in the fills_in method, >>> and >>> then yanks the data from the html and submits it with the >>> clicks_button method. What this means is that if the form isn't >>> aligned with the fields you're submitting, you'll get a failure. >>> >>> How clean is that? >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> >> Um... Sweetness!!! How is it for speed? There is a ton of stuff we >> would love to move out of Selenium due to issues with sessions, >> flash, >> and database persistance. > > Obviously it's much faster than running stuff in a browser. I have > nothing else to measure it against and haven't done any real > benchmarking, but it is perceivably much faster than running selenium. > > What I'd recommend - where I'm headed as the opportunity presents > itself - is to have in-memory and in-browser implementations of the > same steps. Then you can run them in-memory most of the time and skip > the javascript, but run them in-browser once in a while - like before > commits - to make sure the javascript is all working too. > Not a bad idea. Our tests are in terrible condition due to the length of time it takes to run selenium. > There's also an interesting javascript testing framework that I think > shows a lot of promise called crosscheck > (http://www.thefrontside.net/crosscheck). It's basically got it's own > browser-less javascript engines and runs in-memory. Last I heard it > was mostly dead-on, but that it missed some things. The guy who told > me that said he was running selenium for a few things that crosscheck > didn't do right, but I don't know what those are :) > > I did toy with it for a minute, and it's blazingly fast. I just > haven't made a commitment to use it in anger yet - but I'm looking > forward to the opportunity to. > I'll look into it. Thanks for the pointer! > Cheers, > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From loop at superinfinite.com Thu Dec 20 05:31:43 2007 From: loop at superinfinite.com (Bart Zonneveld) Date: Thu, 20 Dec 2007 11:31:43 +0100 Subject: [rspec-users] How-to spec this helper method?... Message-ID: <227C6FA4-5E6A-4715-8C80-523D11ECE754@superinfinite.com> Hey gang, I have this dead-simple method defined in a helper: def add_category_link(name) link_to_function name do |page| page.insert_html :bottom, :categories, :partial => 'category', :object => Category.new end end Where, and mostly how, would I spec this? I haven't been able to find how to stub the rjs in a helper spec, so I'd appreciate any pointers whatsoever.. thanks! bartz From jimmy.zimmerman at gmail.com Fri Dec 21 13:30:49 2007 From: jimmy.zimmerman at gmail.com (jimmy zimmerman) Date: Fri, 21 Dec 2007 11:30:49 -0700 Subject: [rspec-users] I need some guidance Message-ID: I'm building an http communicator class for a web service API wrapper and I'm trying to go through the BDD process in doing so. I'm having a bit of a struggle figuring out how to set up the tests in relation to isolating things appropriately as well as testing behavior vs testing implementation. Specifically, I'm trying to set up a post method on my HttpCommunicator so I have the following: describe FamilyTreeApi::HttpCommunicator, "post" do it "should accept an endpoint and an xml string to post" # I'm okay with this one it "should perform post content to given endpoint" it "should return a response object" end I have written/passed the tests for the first spec, but I'm having troubles figuring out how to verify behavior for the second and third, and how to mock/stub it up. I'll be using the 'net/https' standard libraries to implement the POST action, and I know that it requires the use of a URI instance, a Net::HTTP instance, and a Net::HTTP::Post request instance. I don't want to hit the actual web service each time I run the test, so I'd like to stub or mock this in some way. I think I just need some guidance on how to approach something like this. Do I just ignore the implementation details? Do I push the actual posting of data to a private method and mock that method so that I can verify that it is being called? Would you recommend I actually hit the web service? Any help is greatly appreciated. -- Jimmy Zimmerman http://jimmyzimmerman.com/blog/ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071221/4610b75e/attachment.html From pergesu at gmail.com Fri Dec 21 13:56:13 2007 From: pergesu at gmail.com (Pat Maddox) Date: Fri, 21 Dec 2007 10:56:13 -0800 Subject: [rspec-users] I need some guidance In-Reply-To: References: Message-ID: <810a540e0712211056m2af5adfbnce358ff90c920538@mail.gmail.com> On Dec 21, 2007 10:30 AM, jimmy zimmerman wrote: > I'm building an http communicator class for a web service API wrapper and > I'm trying to go through the BDD process in doing so. I'm having a bit of a > struggle figuring out how to set up the tests in relation to isolating > things appropriately as well as testing behavior vs testing implementation. > > Specifically, I'm trying to set up a post method on my HttpCommunicator so I > have the following: > > describe FamilyTreeApi::HttpCommunicator, "post" do > it "should accept an endpoint and an xml string to post" # I'm okay with > this one > it "should perform post content to given endpoint" > it "should return a response object" > end > > I have written/passed the tests for the first spec, but I'm having troubles > figuring out how to verify behavior for the second and third, and how to > mock/stub it up. I'll be using the 'net/https' standard libraries to > implement the POST action, and I know that it requires the use of a URI > instance, a Net::HTTP instance, and a Net::HTTP::Post request instance. > > I don't want to hit the actual web service each time I run the test, so I'd > like to stub or mock this in some way. I think I just need some guidance on > how to approach something like this. > > Do I just ignore the implementation details? > Do I push the actual posting of data to a private method and mock that > method so that I can verify that it is being called? > Would you recommend I actually hit the web service? > > Any help is greatly appreciated. > -- > Jimmy Zimmerman > http://jimmyzimmerman.com/blog/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > There's a PeepCode screencast where he shows how to do something like this I think...in the past, I've always used mocks to drive an internal API that I like. Then when that's more or less locked down, I write a spec to implement that API. I pull response pages from the external service, and stub Net::HTTP to return those. It's a tad bit brittle, because if the service changes then your specs will be invalid. However by writing the client code and driving the API first, you can at least guarantee that you keep a clean API that you want, that remains decoupled from the external service. Pat From mailing_lists at railsnewbie.com Fri Dec 21 14:41:30 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Fri, 21 Dec 2007 14:41:30 -0500 Subject: [rspec-users] I need some guidance In-Reply-To: References: Message-ID: On Dec 21, 2007, at 1:30 PM, jimmy zimmerman wrote: > I'm building an http communicator class for a web service API > wrapper and I'm trying to go through the BDD process in doing so. > I'm having a bit of a struggle figuring out how to set up the tests > in relation to isolating things appropriately as well as testing > behavior vs testing implementation. > > Specifically, I'm trying to set up a post method on my > HttpCommunicator so I have the following: > > describe FamilyTreeApi::HttpCommunicator, "post" do > it "should accept an endpoint and an xml string to post" # I'm okay > with this one > it "should perform post content to given endpoint" > it "should return a response object" > end > > I have written/passed the tests for the first spec, but I'm having > troubles figuring out how to verify behavior for the second and > third, and how to mock/stub it up. I'll be using the 'net/https' > standard libraries to implement the POST action, and I know that it > requires the use of a URI instance, a Net::HTTP instance, and a > Net::HTTP::Post request instance. > Yep - I was doing something like that just yesterday, excepting fetching a feed with the URI and Net:HTTP classes. The way I got around it was to write one method which encapsulated the behaviour of the URI.parse (stubbing a class method which returned a mock). The second method would wrap the first - so something like this: def get_parsed_url URI.parse(url) end def get_feed Net::HTTP.get_response(get_parsed_url) end This allows me to stub out get_parsed_url when I'm testing the get_feed method, and ignore the URI class altogether. Another way to get around this sort of thing is by passing mock objects into constructors, a la "Dependency Injection". That would go something like this: class Foo def initialize(http_class = Net::HTTP, uri_class = URI) @http_class, @uri_class = http_class, uri_class end def get_parsed_url @uri_class.parse(url) end def get_feed @http_class.get_response(get_parsed_url) end end This allows you to pass in mock objects (mock classes) for your tests, but it still allows the production code to default to what you really want (the Net::HTTP and URI classes). It's also going to make your code more flexible, in the case that you ever wanted to swap out Net::HTTP or URI for an alternative implementation. Hope that helps, Scott From jimmy.zimmerman at gmail.com Fri Dec 21 14:44:05 2007 From: jimmy.zimmerman at gmail.com (jimmy zimmerman) Date: Fri, 21 Dec 2007 12:44:05 -0700 Subject: [rspec-users] I need some guidance In-Reply-To: <810a540e0712211056m2af5adfbnce358ff90c920538@mail.gmail.com> References: <810a540e0712211056m2af5adfbnce358ff90c920538@mail.gmail.com> Message-ID: Thanks Pat, When I wrote my first message, I think I was missing a big part of the Mock/Stub capabilities. I thought you could only stub or mock methods of a particular instance that had been set up already in the spec. However, I realize now that you can also stub/mock class methods. I think my approach will be to create a mock object that would give results for method calls that I expect for Net::HTTP. I would then stub the new call on Net::HTTP to return that mock object. I would then set up should_receive verifications on that object to make sure that it's being called appropriately. That way, I'm not hitting the web service, but I can verify that things are happening correctly in my method. Does this approach sound right? By the way, I have watched the Peepcode screencasts, and they have helped tremendously. I had just missed this (big) part of mocking/stubbing when I watched the Mocks video. -- Jimmy On Dec 21, 2007 11:56 AM, Pat Maddox wrote: > On Dec 21, 2007 10:30 AM, jimmy zimmerman > wrote: > > I'm building an http communicator class for a web service API wrapper > and > > I'm trying to go through the BDD process in doing so. I'm having a bit > of a > > struggle figuring out how to set up the tests in relation to isolating > > things appropriately as well as testing behavior vs testing > implementation. > > > > Specifically, I'm trying to set up a post method on my HttpCommunicator > so I > > have the following: > > > > describe FamilyTreeApi::HttpCommunicator, "post" do > > it "should accept an endpoint and an xml string to post" # I'm okay with > > this one > > it "should perform post content to given endpoint" > > it "should return a response object" > > end > > > > I have written/passed the tests for the first spec, but I'm having > troubles > > figuring out how to verify behavior for the second and third, and how to > > mock/stub it up. I'll be using the 'net/https' standard libraries to > > implement the POST action, and I know that it requires the use of a URI > > instance, a Net::HTTP instance, and a Net::HTTP::Post request instance. > > > > I don't want to hit the actual web service each time I run the test, so > I'd > > like to stub or mock this in some way. I think I just need some guidance > on > > how to approach something like this. > > > > Do I just ignore the implementation details? > > Do I push the actual posting of data to a private method and mock that > > method so that I can verify that it is being called? > > Would you recommend I actually hit the web service? > > > > Any help is greatly appreciated. > > -- > > Jimmy Zimmerman > > http://jimmyzimmerman.com/blog/ > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > There's a PeepCode screencast where he shows how to do something like > this I think...in the past, I've always used mocks to drive an > internal API that I like. Then when that's more or less locked down, > I write a spec to implement that API. I pull response pages from the > external service, and stub Net::HTTP to return those. It's a tad bit > brittle, because if the service changes then your specs will be > invalid. However by writing the client code and driving the API > first, you can at least guarantee that you keep a clean API that you > want, that remains decoupled from the external service. > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Jimmy Zimmerman http://jimmyzimmerman.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071221/f13d7d36/attachment-0001.html From mailing_lists at railsnewbie.com Fri Dec 21 14:45:28 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Fri, 21 Dec 2007 14:45:28 -0500 Subject: [rspec-users] I need some guidance In-Reply-To: References: Message-ID: > to stub or mock this in some way. I think I just need some > guidance on how to approach something like this. > > Do I just ignore the implementation details? > Do I push the actual posting of data to a private method and mock > that method so that I can verify that it is being called? > Would you recommend I actually hit the web service? Oh yeah - and also, you probably will want an integration test which actually hits the web service at least once just to check that the API hasn't changed (and so on, if you can actually do it). But that's what the story runner is for (and not mock objects). Scott From j at jonathanleighton.com Fri Dec 21 14:59:39 2007 From: j at jonathanleighton.com (Jonathan Leighton) Date: Fri, 21 Dec 2007 19:59:39 +0000 Subject: [rspec-users] StoryRunner docs/guidance Message-ID: <1198267179.16946.2.camel@tybalt> Hi all, Are there any plans for better documentation for the new StoryRunner feature? I tried to use it today (with Rails), and had a hard time getting my head around whether I was doing it "right" and exactly what things are appropriate to test at that level (this might be exacerbated by the fact that I've never really used integration testing that much). A full example of testing a Rails controller would be extremely useful to me. Thanks, Jon -- Jonathan Leighton, Web Developer http://jonathanleighton.com/ From nathan.sutton at gmail.com Fri Dec 21 15:20:52 2007 From: nathan.sutton at gmail.com (Nathan Sutton) Date: Fri, 21 Dec 2007 14:20:52 -0600 Subject: [rspec-users] StoryRunner docs/guidance In-Reply-To: <1198267179.16946.2.camel@tybalt> References: <1198267179.16946.2.camel@tybalt> Message-ID: <2ECCFFEC-C7BE-4BFD-9BA8-F9D68575C8AF@gmail.com> Yeah, this is truly needed, you have a second from me. Nathan Sutton fowlduck at gmail.com rspec 1.1 rspec_on_rails 1.1 rails 2.0.1 On Dec 21, 2007, at 1:59 PM, Jonathan Leighton wrote: > Hi all, > > Are there any plans for better documentation for the new StoryRunner > feature? I tried to use it today (with Rails), and had a hard time > getting my head around whether I was doing it "right" and exactly what > things are appropriate to test at that level (this might be > exacerbated > by the fact that I've never really used integration testing that > much). > A full example of testing a Rails controller would be extremely useful > to me. > > Thanks, > > Jon > > -- > Jonathan Leighton, Web Developer > http://jonathanleighton.com/ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From kerry at kerrybuckley.com Fri Dec 21 17:40:32 2007 From: kerry at kerrybuckley.com (Kerry Buckley) Date: Fri, 21 Dec 2007 22:40:32 +0000 Subject: [rspec-users] StoryRunner docs/guidance In-Reply-To: <1198267179.16946.2.camel@tybalt> References: <1198267179.16946.2.camel@tybalt> Message-ID: <0D9ADD31-58C9-4B32-8EDE-B4E9A00A6FD5@kerrybuckley.com> On 21 Dec 2007, at 19:59, Jonathan Leighton wrote: > Hi all, > > Are there any plans for better documentation for the new StoryRunner > feature? I tried to use it today (with Rails), and had a hard time > getting my head around whether I was doing it "right" and exactly what > things are appropriate to test at that level (this might be > exacerbated > by the fact that I've never really used integration testing that > much). > A full example of testing a Rails controller would be extremely useful > to me. No idea whether I'm doing it right either, but I've posted my experiences, with some sample code, here: http://www.kerrybuckley.com/2007/11/07/driving-selenium-from-the-rspec-story-runner-rbehave/ Obviously the bits that force it to use rspec trunk from an odd directory aren't needed any more. Hope it helps, Kerry From james.deville at gmail.com Fri Dec 21 18:16:54 2007 From: james.deville at gmail.com (James Deville) Date: Fri, 21 Dec 2007 15:16:54 -0800 Subject: [rspec-users] Story runner rake task In-Reply-To: <57c63afe0712192242g5bcfecabk5225146ff84dba3f@mail.gmail.com> References: <75D18260-5D95-4B1F-BCC6-9D0A8C98CB47@gmail.com> <57c63afe0712192138v6ae83c3aiaad7adbd09a4fce5@mail.gmail.com> <6A09754D-7C3E-4125-8DA9-80089F8B525C@gmail.com> <57c63afe0712192144p644d3d2fkeda2979c85d3aac@mail.gmail.com> <57c63afe0712192216w3e981456qd9d04d7012990f99@mail.gmail.com> <57c63afe0712192242g5bcfecabk5225146ff84dba3f@mail.gmail.com> Message-ID: On Dec 19, 2007, at 10:42 PM, David Chelimsky wrote: > On Dec 20, 2007 12:25 AM, James Deville > wrote: >> >> >> On Dec 19, 2007, at 10:16 PM, David Chelimsky wrote: >> >>> On Dec 19, 2007 11:50 PM, James Deville >>> wrote: >>>> >>>> >>>> On Dec 19, 2007, at 9:44 PM, David Chelimsky wrote: >>>> >>>>> On Dec 19, 2007 11:40 PM, James Deville >>>>> wrote: >>>>>> >>>>>> >>>>>> On Dec 19, 2007, at 9:38 PM, David Chelimsky wrote: >>>>>> >>>>>>> On Dec 19, 2007 11:34 PM, James Deville >>>>>>> >>>>>>> wrote: >>>>>>>> Yeah, had a slight email conversation with David C about that >>>>>>>> in >>>>>>>> regards to bug #188. I am wondering why we don't standardize >>>>>>>> it, ya >>>>>>>> know convention over configuration and all. >>>>>>> >>>>>>> Because I think it's premature to call anything related to story >>>>>>> runner a convention. I actually organize them differently from >>>>>>> what >>>>>>> many are calling convention, and my way is not necessarily >>>>>>> "right" >>>>>>> or >>>>>>> "better." Let's wait a while on this. We'll get there. >>>>>>> _______________________________________________ >>>>>>> rspec-users mailing list >>>>>>> rspec-users at rubyforge.org >>>>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>>> >>>>>> >>>>>> Good enough for me. I just wanted a reason. May I ask how you set >>>>>> them >>>>>> up? >>>>> >>>>> Sure. >>>>> >>>>> stories/ >>>>> stories/helper.rb >>>>> stories/steps/ (steps go in here - that seems to be the >>>>> "convention") >>>>> stories/stuff_related_to_one_feature >>>>> stories/stuff_related_to_another_feature >>>>> stories/stuff_related_to_yet_another_feature >>>>> >>>>> So in this case, the only thing that would be consistent across >>>>> projects would be helper.rb and the steps directory. Even that >>>>> should >>>>> probably be called step_definitions or something. I'm not sure. >>>>> >>>>> Anyhow - that's where I'm at. How about you? >>>>> _______________________________________________ >>>>> rspec-users mailing list >>>>> rspec-users at rubyforge.org >>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>> >>>> I've been doing a feature per file. So I have: >>>> >>>> stories/ >>>> stories/helper.rb >>>> stories/steps/ >>>> stories/stories/ >>>> >>>> So in stories/stories I have my stories with multiple scenarios per >>>> story. >>>> >>>> I'm definitely seeing your point, and the reason for leaving it as >>>> is. >>>> >>>> Do you use selenium or anything like that via the stories? If not, >>>> what kinds of things do you test with stories? >>> >>> I've got a bunch of selenium tests being driven by spec/ui. I >>> haven't >>> converted them to stories yet. >>> >>> Mostly I've been using webrat, Bryan Helmkamp's awesome >>> Hpricot-wrapping goodness. It doesn't cover javascript, but the apps >>> I've been working on have been very vanilla with respect to ajax, so >>> I've been satisfied with have_rjs. >>> >>> Anyhow, webrat does something really cool - it ties your form >>> submissions to the html of the rendered form. So you make steps like >>> this: >>> >>> ===================== >>> When "I go to log in" do >>> visits "/session/new" >>> end >>> >>> When "I enter $label: $value" do |label, value| >>> fills_in label, :with => value >>> end >>> >>> When "I submit my credentials" do >>> clicks_button >>> end >>> >>> Then "I should see $message" do |message| >>> response.should have_text(/#{message}/) >>> end >>> ===================== >>> >>> And a scenario like this: >>> >>> ===================== >>> When I go to log in >>> And I enter Username: david >>> And I enter Password: webrat rules >>> And I submit my credentials >>> Then I should see Welcome david >>> ===================== >>> >>> And what webrat does is grabs the html from the response in the >>> visits >>> method, modifies that html with your data in the fills_in method, >>> and >>> then yanks the data from the html and submits it with the >>> clicks_button method. What this means is that if the form isn't >>> aligned with the fields you're submitting, you'll get a failure. >>> >>> How clean is that? >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> >> Um... Sweetness!!! How is it for speed? There is a ton of stuff we >> would love to move out of Selenium due to issues with sessions, >> flash, >> and database persistance. > > Obviously it's much faster than running stuff in a browser. I have > nothing else to measure it against and haven't done any real > benchmarking, but it is perceivably much faster than running selenium. > > What I'd recommend - where I'm headed as the opportunity presents > itself - is to have in-memory and in-browser implementations of the > same steps. Then you can run them in-memory most of the time and skip > the javascript, but run them in-browser once in a while - like before > commits - to make sure the javascript is all working too. > > There's also an interesting javascript testing framework that I think > shows a lot of promise called crosscheck > (http://www.thefrontside.net/crosscheck). It's basically got it's own > browser-less javascript engines and runs in-memory. Last I heard it > was mostly dead-on, but that it missed some things. The guy who told > me that said he was running selenium for a few things that crosscheck > didn't do right, but I don't know what those are :) > > I did toy with it for a minute, and it's blazingly fast. I just > haven't made a commitment to use it in anger yet - but I'm looking > forward to the opportunity to. > > Cheers, > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Can you show me how you set up for webrat? I can't get the story runner to recognize webrat. I have require 'webrat' in helper.rb, and then I'm trying to use visits, and it fails! JD From jonathan at parkerhill.com Fri Dec 21 18:40:07 2007 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Fri, 21 Dec 2007 18:40:07 -0500 Subject: [rspec-users] StoryRunner docs/guidance In-Reply-To: <1198267179.16946.2.camel@tybalt> References: <1198267179.16946.2.camel@tybalt> Message-ID: <2DA31023-DACF-4CFE-8F23-70A52DC240BC@parkerhill.com> I just went through this myself yesterday, and was considering posting an article on my blog, but figured it'd be too short lived, once the doc page is up on the rspec site. So I'll post here what I've cobbled together from various other articles, emails, and generous help on #rspec. 1. DECIDE A DIRECTORY STRUCTURE AND FILL OUT helper.rb Directory structure: stories/ stories/steps/ stories/stories/ stories/stories/foo stories/stories/foo/a_foo_story stories/stories/foo/a_foo_story.rb stories/stories/foo/another_foo_story stories/stories/foo/another_foo_story.rb stories/all.rb stories/helper.rb File: stories/helper.rb: ENV["RAILS_ENV"] = "test" require File.expand_path(File.dirname(__FILE__) + "/../config/ environment") require 'spec/rails/story_adapter' Dir['stories/steps/**/*.rb'].each do |steps_file| require steps_file end # add extra include's and helper methods here include FixtureReplacement 2. WRITE A SHORT TEXT STORY File: stories/stories/admin/admin_accounts Story: admin user manages accounts As an admin user I want site-wide access to accounts, projects, and users So I can create and modify items Scenario: admin user logs in Given an admin user and account And a bunch of accounts setup When user logs in with email: admin at example.com and password: secret Then browser should show the Admin page And browser should show the Accounts table 3. WRITE A rb SCRIPT FOR THE STORY File: stories/stories/admin/admin_accounts.rb require File.join(File.dirname(__FILE__), "../../helper") with_steps_for :misc do run File.expand_path(__FILE__).gsub(".rb",""), :type => RailsStory end For other stories, just copy this file, and add/change the steps groups as required. The rest of the file is unchanged (it gets the text story filename from its own name.) 3.A And Run It: $ ruby stories/stories/admin/admin_accounts.rb should show 1 scenarios: 0 succeeded, 0 failed, 1 pending 4. CODE THE STEPS To start, I put all my steps into a "miscellaneous" steps file until patterns emerge when I'll separate them out into different steps files File: stores/steps/misc_steps.rb steps_for(:misc) do Given "an admin user and account" do @user = create_user( :email => "admin at example.com", :password => 'secret', :site_admin => true) end Given "a bunch of accounts setup" do 4.times do create_account end end When "user logs in with email: $email and password: $password" do | email, password| post_via_redirect "/sessions", :email => email, :password => password, :account => account response.should be_success session[:user].should == @user.id # should_be_logged_in(@user) end Then "browser should show the $h1_contents page" do |h1_contents| response.should have_tag("h1", h1_contents) end Then "browser should show the $table_name table" do |table_name| response.should have_tag("div h2", table_name) end end 4.A And Run It $ ruby stories/stories/admin/admin_accounts.rb or $ ruby stories/all.rb --linoj On Dec 21, 2007, at 2:59 PM, Jonathan Leighton wrote: > Hi all, > > Are there any plans for better documentation for the new StoryRunner > feature? I tried to use it today (with Rails), and had a hard time > getting my head around whether I was doing it "right" and exactly what > things are appropriate to test at that level (this might be > exacerbated > by the fact that I've never really used integration testing that > much). > A full example of testing a Rails controller would be extremely useful > to me. > > Thanks, > > Jon > > -- > Jonathan Leighton, Web Developer > http://jonathanleighton.com/ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From jonathan at linowes.com Sat Dec 22 02:51:04 2007 From: jonathan at linowes.com (Jonathan Linowes) Date: Sat, 22 Dec 2007 02:51:04 -0500 Subject: [rspec-users] StepGroup ? Message-ID: <1F3CF791-CA7C-4366-BA77-6BCBB3883D74@linowes.com> Hi, I have a need for the StepGroup feature in stories but not clear what's the current api. Could you provide an example? In my case I have several scenarios which vary in the Givens, but not the results. Ideally I'm hoping to achieve something like: (but anything will do for now :) Scenario: one Given something When he does foo Then good things should happen Scenario: two Given something different When he does foo Group Of good things should happen Group: good things should happen Then good thing one And good thing two And good thing three From bryan at brynary.com Sat Dec 22 10:39:25 2007 From: bryan at brynary.com (Bryan Helmkamp) Date: Sat, 22 Dec 2007 10:39:25 -0500 Subject: [rspec-users] Story runner rake task In-Reply-To: References: <75D18260-5D95-4B1F-BCC6-9D0A8C98CB47@gmail.com> <57c63afe0712192138v6ae83c3aiaad7adbd09a4fce5@mail.gmail.com> <6A09754D-7C3E-4125-8DA9-80089F8B525C@gmail.com> <57c63afe0712192144p644d3d2fkeda2979c85d3aac@mail.gmail.com> <57c63afe0712192216w3e981456qd9d04d7012990f99@mail.gmail.com> <57c63afe0712192242g5bcfecabk5225146ff84dba3f@mail.gmail.com> Message-ID: On Dec 21, 2007 6:16 PM, James Deville wrote: > Can you show me how you set up for webrat? I can't get the story > runner to recognize webrat. I have require 'webrat' in helper.rb, and > then I'm trying to use visits, and it fails! Actually, you shouldn't need to add an include to helper.rb because Webrat's init.rb loads it automatically when in the test environment. Can you email me off-list with a stacktrace? Thanks, -- Bryan Helmkamp http://brynary.com -- My blog From caleb.land at gmail.com Sat Dec 22 13:17:15 2007 From: caleb.land at gmail.com (Caleb Land) Date: Sat, 22 Dec 2007 13:17:15 -0500 Subject: [rspec-users] Rails: Specing libraries Message-ID: I was reading the documentation on using rails with rspec and I didn't see anything about how to spec libraries in the rails /lib directory so that they're integrated into the whole spec::rails system. Where should I put specs for my libraries, and what's the best way to require the files that I'm testing in my spec? I've never used rspec before, and I'm new to rails, so I'm huge newb. -- Caleb Land -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071222/80f1b979/attachment.html From chad at spicycode.com Sat Dec 22 14:20:37 2007 From: chad at spicycode.com (Chad Humphries) Date: Sat, 22 Dec 2007 14:20:37 -0500 Subject: [rspec-users] Rails: Specing libraries In-Reply-To: References: Message-ID: <28FF73F1-5694-46C8-9ABE-082E610D644A@spicycode.com> Caleb, In most cases you could just create a lib folder under spec with your new file in it. For example if you have: lib/my_extension.rb You would have: spec/lib/my_extension_spec.rb That starts out something like: require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') describe MyExtension do ... end And that should about do it. -- Chad Humphries http://spicycode.com/ On Dec 22, 2007, at 1:17 PM, Caleb Land wrote: > I was reading the documentation on using rails with rspec and I > didn't see anything about how to spec libraries in the rails /lib > directory so that they're integrated into the whole spec::rails > system. > > Where should I put specs for my libraries, and what's the best way > to require the files that I'm testing in my spec? > > I've never used rspec before, and I'm new to rails, so I'm huge newb. > > -- > Caleb Land > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From jonathan at parkerhill.com Sat Dec 22 18:24:21 2007 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Sat, 22 Dec 2007 18:24:21 -0500 Subject: [rspec-users] StepGroup ? In-Reply-To: <1F3CF791-CA7C-4366-BA77-6BCBB3883D74@linowes.com> References: <1F3CF791-CA7C-4366-BA77-6BCBB3883D74@linowes.com> Message-ID: <5E0601AB-2D54-428A-9B88-CC9109EA7EEB@parkerhill.com> Sorry, I guess stepgroup is the steps_for framework, and not what I'm asking about. Is there a way to hierarchically combine steps under a single step to achieve? On Dec 22, 2007, at 2:51 AM, Jonathan Linowes wrote: > Hi, > I have a need for the StepGroup feature in stories but not clear > what's the current api. Could you provide an example? > > In my case I have several scenarios which vary in the Givens, but not > the results. Ideally I'm hoping to achieve something like: (but > anything will do for now :) > > Scenario: one > Given something > When he does foo > Then good things should happen > > Scenario: two > Given something different > When he does foo > Then good things should happen > > > Group: good things should happen > Then good thing one > And good thing two > And good thing three > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From bryan at osesm.com Sat Dec 22 18:36:56 2007 From: bryan at osesm.com (Bryan Liles) Date: Sat, 22 Dec 2007 18:36:56 -0500 Subject: [rspec-users] rspec story directory structure Message-ID: <2985F48D-7930-4FAA-95AA-D0900456BC36@osesm.com> I've been thinking about the structure of the rspec story stuff, and I've come up with this for my first post: stories/ # top level to contain all of our story related stuff stories/helper.rb # top level helper stories/helpers/ # other helpers like custom matchers and other libs stories/steps/ # steps go here stories/features/ # top level for features stories/features/feature/ # stories for a feature stories/features/feature/ # stories for another feature I've posted a blog entry with a rake task and the stories/helper.rb at http://smartic.us/2007/12/22/smarticus-rspec-stories-on-rails -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071222/32147ce3/attachment.html From omen.king at gmail.com Sat Dec 22 19:25:55 2007 From: omen.king at gmail.com (Andrew WC Brown) Date: Sat, 22 Dec 2007 19:25:55 -0500 Subject: [rspec-users] StoryRunner docs/guidance In-Reply-To: <2DA31023-DACF-4CFE-8F23-70A52DC240BC@parkerhill.com> References: <1198267179.16946.2.camel@tybalt> <2DA31023-DACF-4CFE-8F23-70A52DC240BC@parkerhill.com> Message-ID: I never really thought of placing subdirectories in the stories directory. I guess that would be useful for separating your administrative stories for the back end of your app. I named my stories in the following convention: #role#_#action#_story.rb eg: user_creates_project_story.rb user_edits_project_story.rb user_deletes_project_story.rb user_views_project_story.rb On Dec 21, 2007 6:40 PM, Jonathan Linowes wrote: > I just went through this myself yesterday, and was considering > posting an article on my blog, but figured it'd be too short lived, > once the doc page is up on the rspec site. So I'll post here what > I've cobbled together from various other articles, emails, and > generous help on #rspec. > > 1. DECIDE A DIRECTORY STRUCTURE AND FILL OUT helper.rb > Directory structure: > stories/ > stories/steps/ > stories/stories/ > stories/stories/foo > stories/stories/foo/a_foo_story > stories/stories/foo/a_foo_story.rb > stories/stories/foo/another_foo_story > stories/stories/foo/another_foo_story.rb > stories/all.rb > stories/helper.rb > > File: stories/helper.rb: > > ENV["RAILS_ENV"] = "test" > require File.expand_path(File.dirname(__FILE__) + "/../config/ > environment") > require 'spec/rails/story_adapter' > > Dir['stories/steps/**/*.rb'].each do |steps_file| > require steps_file > end > > # add extra include's and helper methods here > include FixtureReplacement > > > 2. WRITE A SHORT TEXT STORY > > File: stories/stories/admin/admin_accounts > > Story: admin user manages accounts > As an admin user > I want site-wide access to accounts, projects, and users > So I can create and modify items > > Scenario: admin user logs in > Given an admin user and account > And a bunch of accounts setup > When user logs in with email: admin at example.com and password: > secret > Then browser should show the Admin page > And browser should show the Accounts table > > > 3. WRITE A rb SCRIPT FOR THE STORY > > File: stories/stories/admin/admin_accounts.rb > > require File.join(File.dirname(__FILE__), "../../helper") > > with_steps_for :misc do > run File.expand_path(__FILE__).gsub(".rb",""), :type => RailsStory > end > > For other stories, just copy this file, and add/change the steps > groups as required. The rest of the file is unchanged (it gets the > text story filename from its own name.) > > > 3.A And Run It: > > $ ruby stories/stories/admin/admin_accounts.rb > > should show 1 scenarios: 0 succeeded, 0 failed, 1 pending > > > 4. CODE THE STEPS > To start, I put all my steps into a "miscellaneous" steps file until > patterns emerge when I'll separate them out into different steps files > > File: stores/steps/misc_steps.rb > > steps_for(:misc) do > Given "an admin user and account" do > @user = create_user( :email => "admin at example.com", :password => > 'secret', :site_admin => true) > end > > Given "a bunch of accounts setup" do > 4.times do > create_account > end > end > > When "user logs in with email: $email and password: $password" do | > email, password| > post_via_redirect "/sessions", :email => email, :password => > password, :account => account > response.should be_success > session[:user].should == @user.id # should_be_logged_in(@user) > end > > Then "browser should show the $h1_contents page" do |h1_contents| > response.should have_tag("h1", h1_contents) > end > > Then "browser should show the $table_name table" do |table_name| > response.should have_tag("div h2", table_name) > end > end > > 4.A And Run It > > $ ruby stories/stories/admin/admin_accounts.rb > or > $ ruby stories/all.rb > > > > > --linoj > > > > > > On Dec 21, 2007, at 2:59 PM, Jonathan Leighton wrote: > > > Hi all, > > > > Are there any plans for better documentation for the new StoryRunner > > feature? I tried to use it today (with Rails), and had a hard time > > getting my head around whether I was doing it "right" and exactly what > > things are appropriate to test at that level (this might be > > exacerbated > > by the fact that I've never really used integration testing that > > much). > > A full example of testing a Rails controller would be extremely useful > > to me. > > > > Thanks, > > > > Jon > > > > -- > > Jonathan Leighton, Web Developer > > http://jonathanleighton.com/ > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071222/807d5f9b/attachment.html From dchelimsky at gmail.com Sat Dec 22 21:46:21 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 22 Dec 2007 20:46:21 -0600 Subject: [rspec-users] StepGroup ? In-Reply-To: <1F3CF791-CA7C-4366-BA77-6BCBB3883D74@linowes.com> References: <1F3CF791-CA7C-4366-BA77-6BCBB3883D74@linowes.com> Message-ID: <57c63afe0712221846y5af4306x7d09323392119a49@mail.gmail.com> On Dec 22, 2007 1:51 AM, Jonathan Linowes wrote: > Hi, > I have a need for the StepGroup feature in stories but not clear > what's the current api. Could you provide an example? > > In my case I have several scenarios which vary in the Givens, but not > the results. Ideally I'm hoping to achieve something like: (but > anything will do for now :) > > Scenario: one > Given something > When he does foo > Then good things should happen > > Scenario: two > Given something different > When he does foo > Group Of good things should happen > > > Group: good things should happen > Then good thing one > And good thing two > And good thing three There is "Given Scenario", but that only lets you call up scenarios defined earlier in the same story. So you could use that but the semantics don't seem right for what you're wanting - which seems to be a collection of verifications that should be the same for different pretexts, as opposed to a collection of givens that diverge at some point. Regardless - take a look at examples/stories/game-of-life. It uses Given Scenario as intended. > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jonathan at parkerhill.com Sun Dec 23 02:15:57 2007 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Sun, 23 Dec 2007 02:15:57 -0500 Subject: [rspec-users] StepGroup ? In-Reply-To: <57c63afe0712221846y5af4306x7d09323392119a49@mail.gmail.com> References: <1F3CF791-CA7C-4366-BA77-6BCBB3883D74@linowes.com> <57c63afe0712221846y5af4306x7d09323392119a49@mail.gmail.com> Message-ID: <5AC0CEE2-963A-4A9B-9E39-D0B14A83520A@parkerhill.com> On Dec 22, 2007, at 9:46 PM, David Chelimsky wrote: > On Dec 22, 2007 1:51 AM, Jonathan Linowes > wrote: >> Hi, >> I have a need for the StepGroup feature in stories but not clear >> what's the current api. Could you provide an example? >> >> In my case I have several scenarios which vary in the Givens, but not >> the results. Ideally I'm hoping to achieve something like: (but >> anything will do for now :) >> >> Scenario: one >> Given something >> When he does foo >> Then good things should happen >> >> Scenario: two >> Given something different >> When he does foo >> Group Of good things should happen >> >> >> Group: good things should happen >> Then good thing one >> And good thing two >> And good thing three > > There is "Given Scenario", but that only lets you call up scenarios > defined earlier in the same story. So you could use that but the > semantics don't seem right for what you're wanting - which seems to be > a collection of verifications that should be the same for different > pretexts, as opposed to a collection of givens that diverge at some > point. > > Regardless - take a look at examples/stories/game-of-life. It uses > Given Scenario as intended. Thanks. That might be feasible if there were a way to tell a scenario not to run unless its called from GivenScenario How about something like "Scenario Segment" and a corresponding "Follow Scenario" ? From ivo.dancet at gmail.com Sun Dec 23 07:49:06 2007 From: ivo.dancet at gmail.com (Ivo Dancet) Date: Sun, 23 Dec 2007 13:49:06 +0100 Subject: [rspec-users] basic authentication Message-ID: <89D33F86-545A-4BA1-A4C9-2B470CBF247C@gmail.com> When I try to get a page via post_via_redirect on a project that uses the new rails 2 http authentication, for example: post_via_redirect path, {:name_of_object => { :att => "test" }}, :authorization => authorize then the post works, but then I'm being redirected to the show action where I'm unauthorized again. A browser doesn't suffer from this but all the tests are. After searching for a long time I just put a session in my authorization method, but this can't be the best solution (as it is only there to satisfy tests...). Any recommendations on this? Regards Ivo Dancet From ivo.dancet at gmail.com Sun Dec 23 07:38:03 2007 From: ivo.dancet at gmail.com (Ivo Dancet) Date: Sun, 23 Dec 2007 13:38:03 +0100 Subject: [rspec-users] multiple scenarios problem Message-ID: <37F0CBD0-6369-4D37-A046-1E8B4AC71682@gmail.com> Hi all I just recently started to use rspec and I'm having a problem using multple scenarios in one story. These are the two scenarios, trying to test my implemenation of the new http authentication in rails 2: Scenario "user has to authenticate" do Given "an anonymous user" do end When "visiting", "working_page" do |page| get page end Then "it should return 401 Unauthorized on each request" do response.headers["Status"].should == "401 Unauthorized" end end Scenario "user authenticates so the page should return 200" do Given "a user"; end When "visiting", "working_page" do |page| get page, nil, :authorization => ActionController::HttpAuthentication::Basic.encode_credentials("name", "pass") end Then "I'm logged in" do response.should be_success end end What happens is that the second scenario's response is also returning 401 and if I switch the order of the two scenarios, the second scenario (now the one that should return 401) returns 200. Each scenario works if I remove the other one. thanks for any help! Ivo Dancet From sera at fhwang.net Sun Dec 23 12:23:52 2007 From: sera at fhwang.net (Francis Hwang) Date: Sun, 23 Dec 2007 09:23:52 -0800 Subject: [rspec-users] Rails: possible routing discrepancy Message-ID: <695E67EF-27A6-46E9-99DC-9D55CCEF2E8A@fhwang.net> Hey all, I'm seeing a strange behavior in my spec that I can't account for. I've got a route that looks like this: map.writing \ '/writing', :controller => 'abstracts', :action => 'index', :index => { :select => 'all' } and I have template code that looks like this:
    <%= link_to_unless_current 'Writing', writing_path %> and I have a spec which calls this page, and checks to see that 'Writing' is not a link: describe "'/writing/'" do controller_name :abstracts integrate_views it "should not link 'Writing'" do get 'index', :index => { :select => 'new' } response.body.should_not have_tag( 'a', 'Writing' ) end end ... and it fails. Normally, I'd assume I just messed up writing my routes, which is an easy enough mistake for me to make. But when I actually open up my browser and go to /writing, I see that the text is not being linked. And the params hash that's visible in my application log shows the same params I think I'm generating in my spec: Parameters: {"action"=>"index", "controller"=>"abstracts", "index"=> {"select"=>"all"}} but there seems to be a discrepancy nonetheless. Then I started poking around in action_view/helpers/url_helper.rb, in current_page?, which is used by link_to_unless_current. Here's that method: def current_page?(options) url_string = CGI.escapeHTML(url_for(options)) request = @controller.request if url_string =~ /^\w+:\/\// url_string == "#{request.protocol}#{request.host_with_port}# {request.request_uri}" else url_string == request.request_uri end end So here's the rub: When I'm running current_page? with script/server, I get "/writing" for url_string and "/writing" for @controller.request.request_uri -- meaning current_page? works correctly, and link_to_unless_current works correctly. But, when I'm running current_page? from my spec, I get "/writing" for url_string and "/abstracts?index%5Bselect%5D=new" for @controller.request.request_uri -- so current_page? works incorrectly and so does link_to_unless_current. Looks like that @controller.request is an RSpec request of some kind. Is it possible the RSpec request isn't handling route generation correctly? Or should I be writing my spec differently? Thanks, Francis Hwang http://fhwang.net/ From sera at fhwang.net Sun Dec 23 13:35:42 2007 From: sera at fhwang.net (Francis Hwang) Date: Sun, 23 Dec 2007 10:35:42 -0800 Subject: [rspec-users] Rails: possible routing discrepancy In-Reply-To: <695E67EF-27A6-46E9-99DC-9D55CCEF2E8A@fhwang.net> References: <695E67EF-27A6-46E9-99DC-9D55CCEF2E8A@fhwang.net> Message-ID: Arg, please disregard that last email. My route and my request are just different; I had to actually write that crazy long email, send it out, and then read it again to see the mistake. Francis Hwang http://fhwang.net/ On Dec 23, 2007, at 9:23 AM, Francis Hwang wrote: > Hey all, I'm seeing a strange behavior in my spec that I can't > account for. I've got a route that looks like this: > > map.writing \ > '/writing', > :controller => 'abstracts', :action => 'index', > :index => { :select => 'all' } > > and I have template code that looks like this: > >
    <%= link_to_unless_current 'Writing', writing_path %> > > and I have a spec which calls this page, and checks to see that > 'Writing' is not a link: > > describe "'/writing/'" do > controller_name :abstracts > integrate_views > > it "should not link 'Writing'" do > get 'index', :index => { :select => 'new' } > response.body.should_not have_tag( 'a', 'Writing' ) > end > end > > ... and it fails. > > Normally, I'd assume I just messed up writing my routes, which is an > easy enough mistake for me to make. But when I actually open up my > browser and go to /writing, I see that the text is not being linked. > And the params hash that's visible in my application log shows the > same params I think I'm generating in my spec: > > Parameters: {"action"=>"index", "controller"=>"abstracts", "index"=> > {"select"=>"all"}} > > but there seems to be a discrepancy nonetheless. > > Then I started poking around in action_view/helpers/url_helper.rb, in > current_page?, which is used by link_to_unless_current. Here's that > method: > > def current_page?(options) > url_string = CGI.escapeHTML(url_for(options)) > request = @controller.request > if url_string =~ /^\w+:\/\// > url_string == "#{request.protocol}#{request.host_with_port}# > {request.request_uri}" > else > url_string == request.request_uri > end > end > > So here's the rub: When I'm running current_page? with script/server, > I get "/writing" for url_string and "/writing" for > @controller.request.request_uri -- meaning current_page? works > correctly, and link_to_unless_current works correctly. > > But, when I'm running current_page? from my spec, I get "/writing" > for url_string and "/abstracts?index%5Bselect%5D=new" for > @controller.request.request_uri -- so current_page? works incorrectly > and so does link_to_unless_current. > > Looks like that @controller.request is an RSpec request of some kind. > Is it possible the RSpec request isn't handling route generation > correctly? Or should I be writing my spec differently? > > Thanks, > > Francis Hwang > http://fhwang.net/ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Sun Dec 23 13:58:49 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 23 Dec 2007 13:58:49 -0500 Subject: [rspec-users] multiple scenarios problem In-Reply-To: <37F0CBD0-6369-4D37-A046-1E8B4AC71682@gmail.com> References: <37F0CBD0-6369-4D37-A046-1E8B4AC71682@gmail.com> Message-ID: <57c63afe0712231058q50e55dbegf0c6b85c25ae2944@mail.gmail.com> On Dec 23, 2007 7:38 AM, Ivo Dancet wrote: > Hi all > > I just recently started to use rspec and I'm having a problem using > multple scenarios in one story. These are the two scenarios, trying to > test my implemenation of the new http authentication in rails 2: > > Scenario "user has to authenticate" do > Given "an anonymous user" do > end > When "visiting", "working_page" do |page| > get page > end > Then "it should return 401 Unauthorized on each request" do > response.headers["Status"].should == "401 Unauthorized" > end > end > > Scenario "user authenticates so the page should return 200" do > Given "a user"; end > When "visiting", "working_page" do |page| > get page, nil, :authorization => > ActionController::HttpAuthentication::Basic.encode_credentials("name", > "pass") > end > Then "I'm logged in" do > response.should be_success > end > end > > What happens is that the second scenario's response is also returning > 401 and if I switch the order of the two scenarios, the second > scenario (now the one that should return 401) returns 200. Each > scenario works if I remove the other one. Within a single story, each step can only get defined once. The second definition is bypassed. There is a discussion about this in a ticket about this at the lighthouse (http://rspec.lighthouseapp.com/projects/5645/tickets/167) and we'll probably add a warning when you try to do this, but know that it is not supported and will not be supported - so you'll want to restructure these scenarios. On another note, an important factor of stories/scenarios is that the doc-strings tell the story, so to speak. What you've got there would not really do that very clearly. I'd probably try to do something more like: Scenario "user has to authenticate" do Given "an anonymous user" do @authorization => nil end When "visiting", "working_page" do |page| get page, :authorization => @authorization end Then "it should return 401 Unauthorized on each request" do response.headers["Status"].should == "401 Unauthorized" end end Scenario "user authenticates so the page should return 200" do Given "an authorized user" do @authorization = ActionController::HttpAuthentication::Basic.encode_credentials("name", "pass") end When "visiting", "working_page" Then "I'm logged in" do response.should be_success end end Now the notion of the anonymous or authorized user is tied to the correct step in each scenario. I haven't run that myself, so it might not work as/is, but it is the direction I'd try to go. Cheers, David > > thanks for any help! > Ivo Dancet > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Sun Dec 23 14:01:35 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 23 Dec 2007 14:01:35 -0500 Subject: [rspec-users] StepGroup ? In-Reply-To: <5AC0CEE2-963A-4A9B-9E39-D0B14A83520A@parkerhill.com> References: <1F3CF791-CA7C-4366-BA77-6BCBB3883D74@linowes.com> <57c63afe0712221846y5af4306x7d09323392119a49@mail.gmail.com> <5AC0CEE2-963A-4A9B-9E39-D0B14A83520A@parkerhill.com> Message-ID: <57c63afe0712231101k2bdd0fd2l5d240d2842da9e7a@mail.gmail.com> On Dec 23, 2007 2:15 AM, Jonathan Linowes wrote: > > > On Dec 22, 2007, at 9:46 PM, David Chelimsky wrote: > > > On Dec 22, 2007 1:51 AM, Jonathan Linowes > > wrote: > >> Hi, > >> I have a need for the StepGroup feature in stories but not clear > >> what's the current api. Could you provide an example? > >> > >> In my case I have several scenarios which vary in the Givens, but not > >> the results. Ideally I'm hoping to achieve something like: (but > >> anything will do for now :) > >> > >> Scenario: one > >> Given something > >> When he does foo > >> Then good things should happen > >> > >> Scenario: two > >> Given something different > >> When he does foo > >> Group Of good things should happen > >> > >> > >> Group: good things should happen > >> Then good thing one > >> And good thing two > >> And good thing three > > > > There is "Given Scenario", but that only lets you call up scenarios > > defined earlier in the same story. So you could use that but the > > semantics don't seem right for what you're wanting - which seems to be > > a collection of verifications that should be the same for different > > pretexts, as opposed to a collection of givens that diverge at some > > point. > > > > Regardless - take a look at examples/stories/game-of-life. It uses > > Given Scenario as intended. > > Thanks. > That might be feasible if there were a way to tell a scenario not to > run unless its called from GivenScenario > How about something like "Scenario Segment" and a corresponding > "Follow Scenario" ? Please submit a ticket for this: http://rspec.lighthouseapp.com/. Can't say whether or not we'll do it, but if you want this to get on/stay on the radar, that's your best bet. Thanks, David > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From zach.dennis at gmail.com Sun Dec 23 17:27:05 2007 From: zach.dennis at gmail.com (Zach Dennis) Date: Sun, 23 Dec 2007 17:27:05 -0500 Subject: [rspec-users] Mocks? Really? In-Reply-To: <810a540e0712142317t5e13f84dt2952986cd0a58a95@mail.gmail.com> References: <139c56460712060856i6bb410fcl23def3b16c0388b4@mail.gmail.com> <57c63afe0712071840w13e8d2co85a60c00f3caefa9@mail.gmail.com> <810a540e0712142317t5e13f84dt2952986cd0a58a95@mail.gmail.com> Message-ID: <85d99afe0712231427k55bb3ed1x12e4dccf65cae2c6@mail.gmail.com> I know the questioned are directed towards Dan so I hope you don't me chiming in. My comments are inline. On Dec 15, 2007 2:17 AM, Pat Maddox wrote: > > On Dec 8, 2007 4:06 AM, Dan North wrote: > > I prefer the mantra "mock roles, not objects", in other words, mock things > > that have behaviour (services, components, resources, whatever your > > preferred term is) rather than stubbing out domain objects themselves. If > > you have to mock domain objects it's usually a smell that your domain > > implementation is too tightly coupled to some infrastructure. > > Assuming you could easily write Rails specs using the real domain > objects, but not hit the database, would you "never" mock domain > objects (where "never" means you deviate only in extraordinary > circumstances)? I'm mostly curious in the interaction between > controller and model...if you use real models, then changes to the > model code could very well lead to failing controller specs, even > though the controller's logic is still correct. In Java you don't mock domain objects because you want to program toward an interface rather then a single concrete implementation. Conceptually this still applies in Ruby, but because of differences between the languages it isn't a 1 to 1 mapping in practice. With regard to controllers and models in Rails, I don't want my controller spec to use real model objects. The requirement of a model existing can be found as part of the discovery process for what a controller needs to do its job. If the implementation of a model is wrong it isn't the job of the controller spec to report the failure. It's the job of the model spec or an integration test (if its an integration related issue) to report the failure. When you make it a job of the controller spec to ensure that the real model objects work correctly within a controller it is usually because there is a lack of integration tests and controller specs are being used to fill in the void. Also, controllers can achieve a better level of programming toward the "interface" rather then a concrete class by using dependency injection. For example consider using lighight DI using the injection plugin (http://atomicobjectrb.rubyforge.org/injection/): class PhotosController < ApplicationController inject :project_repository def index @projects = @project_repository.find_projects end end There is a config/objects.yml file which exists to define what project_repository is: --- project_repository: use_class_directly: true class: Project This removes any unneeded coupling between the controller and the model. Although the most common thing I've seen in Rails is to partial mock the Project class in your spec. Although this works there is unnecessary coupling between your controller a concrete model class. > > > What is your opinion on isolating tests? Tests should be responsible for ensuring an object works as expected. So it's usually a good thing to isolate objects under test to ensure that they are working as expected. If you don't isolate then you end up with a lot of little integration tests. Now when one implementation is wrong you get 100 test failures rather then 1 or 2, which can be a headache when you're trying to find out why something failed. > Do you try to test each > class in complete isolation, mocking its collaborators? Yes. The pattern I find I follow in testing is that objects whose job it is to coordinate or manage other objects (like controllers, presenters, managers, etc) are always tested in isolation. Interaction-based testing is the key here. These objects can be considered branch objects. They connect to other branches or to leaf node objects. Leaf node objects are the end of the line and they do the actual work. Here is where I use state based testing. I consider ActiveRecord models leaf nodes. A practice that I've been following that was inspired from a coworker has been that an object should be a branch or a leaf, but not both. Most Rails applications don't follow anything like this and it's common to find bloated controllers and bloated models (most people IMO do not understand the Skinny Controller, Fat Model post, bloated models are now becoming an up and coming trend unfortunately). Objects and methods built-in the language, standard library or framework are exempt from my above statements. If a manager coordinates return values from methods being called other objects and pushes them onto an array, I don't mock a call to Array.new. > When you use > interaction-based tests, do you always leave those in place, or do you > substitute real objects as you implement them (and if so, do your > changes move to a more state-based style)? Leave the mocked out collaborators in place. An interaction based test verifies that the correct interaction takes place. As soon as you remove the mock and substitute it with a real object your test has become compromised. It's no longer verifying the correct interaction occurs, it now only makes sure your test doesn't die with a real object. If you do substitute in a real object, the only way you would be able to maintain the integrity of the test is to partial mock your real object to expect the right methods to be called. This will ensure that the interaction continues to take place. But what happens is that the test gets muddied up with things that don't need to be there. > How do you approach > specifying different layers within an app? One way to think about this is is terms of composition and inheritance. When layers interact using composition you treat it and test it differently then if you use inheritance. For example a ProjectsController using a @project_repository (see injection example above) or a Project model subclassing ActiveRecord::Base. I need to think about them some more though. > Do you use real > implementations if there are lightweight ones available, or do you > mock everything out? For me it depends. With most Rails projects I've worked on there has been one suite of integration tests against the application as a whole and then a bunch of unit tests. The times this has differed are when the application relied on third-party services. These services would be replaced with dummy or lightweight implementations for my integration tests (for example geocoding). Although there would be another set of integration tests to specifically test our app against the actual service. An integration test should test that real objects are working together correctly produce the intended system behavior. You should never mock objects out at this level, but you may need to provide stub implementations for third party services. > > I realize that's a ton of questions...I'd be very grateful (and > impressed!) if you took the time to answer any of them. Also I'd love > to hear input from other people as well. > It's too bad we can't just stand at a whiteboard and talk this out. The answers to these questions could fill a book and email hardly does it justice to provide clear, coherent and complete answers. Not that my response are "answers" to your questions, but it's how I think about testing and TDD. -- Zach Dennis http://www.continuousthinking.com http://www.atomicobject.com From dchelimsky at gmail.com Sun Dec 23 23:09:30 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 23 Dec 2007 22:09:30 -0600 Subject: [rspec-users] How-to spec this helper method?... In-Reply-To: <227C6FA4-5E6A-4715-8C80-523D11ECE754@superinfinite.com> References: <227C6FA4-5E6A-4715-8C80-523D11ECE754@superinfinite.com> Message-ID: <57c63afe0712232009l65fae7ccg48cfeb3fd7d9441f@mail.gmail.com> On Dec 20, 2007 4:31 AM, Bart Zonneveld wrote: > Hey gang, > > I have this dead-simple method defined in a helper: > > def add_category_link(name) > link_to_function name do |page| > page.insert_html :bottom, :categories, :partial => > 'category', :object => Category.new > end > end > > Where, and mostly how, would I spec this? I haven't been able to find > how to stub the rjs in a helper spec, so I'd appreciate any pointers > whatsoever.. If you can spec it in a template using rjs, you can do it in a helper: describe FooHelper do it "should build a category link" do add_category_link(:foo).should have_rjs(...) end end "should have_rjs" is a wrapper for assert_select_rjs in rails. HTH, David From loop at superinfinite.com Mon Dec 24 08:48:12 2007 From: loop at superinfinite.com (Bart Zonneveld) Date: Mon, 24 Dec 2007 14:48:12 +0100 Subject: [rspec-users] How-to spec this helper method?... In-Reply-To: <57c63afe0712232009l65fae7ccg48cfeb3fd7d9441f@mail.gmail.com> References: <227C6FA4-5E6A-4715-8C80-523D11ECE754@superinfinite.com> <57c63afe0712232009l65fae7ccg48cfeb3fd7d9441f@mail.gmail.com> Message-ID: On 24 dec 2007, at 05:09, David Chelimsky wrote: > On Dec 20, 2007 4:31 AM, Bart Zonneveld > wrote: >> Hey gang, >> >> I have this dead-simple method defined in a helper: >> >> def add_category_link(name) >> link_to_function name do |page| >> page.insert_html :bottom, :categories, :partial => >> 'category', :object => Category.new >> end >> end >> >> Where, and mostly how, would I spec this? I haven't been able to find >> how to stub the rjs in a helper spec, so I'd appreciate any pointers >> whatsoever.. > > If you can spec it in a template using rjs, you can do it in a helper: > > describe FooHelper do > it "should build a category link" do > add_category_link(:foo).should have_rjs(...) > end > end Thanks! However, I am getting an error about 'nil.render' now, with this backtrace: You have a nil object when you didn't expect it! The error occurred while evaluating nil.render /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.0.1/lib/action_view/ helpers/prototype_helper.rb:956:in `render' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.0.1/lib/action_view/ helpers/prototype_helper.rb:727:in `insert_html' /Users/bartz/Documents/workspace/blog/app/helpers/admin/ admin_helper.rb:34:in `__instance_exec0' /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.0.1/lib/ active_support/core_ext/object/extending.rb:52:in `send' /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.0.1/lib/ active_support/core_ext/object/extending.rb:52:in `instance_exec' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.0.1/lib/action_view/ helpers/prototype_helper.rb:581:in `initialize' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.0.1/lib/action_view/ helpers/prototype_helper.rb:992:in `new' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.0.1/lib/action_view/ helpers/prototype_helper.rb:992:in `update_page' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.0.1/lib/action_view/ helpers/javascript_helper.rb:87:in `link_to_function' No idea how to fix this :(... thanks in advance, and happy Christmas and all! bartz From dchelimsky at gmail.com Mon Dec 24 10:24:59 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 24 Dec 2007 09:24:59 -0600 Subject: [rspec-users] How-to spec this helper method?... In-Reply-To: References: <227C6FA4-5E6A-4715-8C80-523D11ECE754@superinfinite.com> <57c63afe0712232009l65fae7ccg48cfeb3fd7d9441f@mail.gmail.com> Message-ID: <57c63afe0712240724l6991289ax4d4f09d8ff8d5bc5@mail.gmail.com> On Dec 24, 2007 7:48 AM, Bart Zonneveld wrote: > > > On 24 dec 2007, at 05:09, David Chelimsky wrote: > > > On Dec 20, 2007 4:31 AM, Bart Zonneveld > > wrote: > >> Hey gang, > >> > >> I have this dead-simple method defined in a helper: > >> > >> def add_category_link(name) > >> link_to_function name do |page| > >> page.insert_html :bottom, :categories, :partial => > >> 'category', :object => Category.new > >> end > >> end > >> > >> Where, and mostly how, would I spec this? I haven't been able to find > >> how to stub the rjs in a helper spec, so I'd appreciate any pointers > >> whatsoever.. > > > > If you can spec it in a template using rjs, you can do it in a helper: > > > > describe FooHelper do > > it "should build a category link" do > > add_category_link(:foo).should have_rjs(...) > > end > > end > > Thanks! However, I am getting an error about 'nil.render' now, with > this backtrace: Just for fun - try putting it in a view specs instead and include the helper: describe "FooHelper", :type => :view do include FooHelper # etc end It might be that view specs have services you need for this example that don't exist in helper specs. If it works, then you can use that as a workaround for now and we know where the deficiency lies. If so, please submit a ticket at http://rspec.lighthouseapp.com/. Cheers, David > > You have a nil object when you didn't expect it! > The error occurred while evaluating nil.render > /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.0.1/lib/action_view/ > helpers/prototype_helper.rb:956:in `render' > /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.0.1/lib/action_view/ > helpers/prototype_helper.rb:727:in `insert_html' > /Users/bartz/Documents/workspace/blog/app/helpers/admin/ > admin_helper.rb:34:in `__instance_exec0' > /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.0.1/lib/ > active_support/core_ext/object/extending.rb:52:in `send' > /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.0.1/lib/ > active_support/core_ext/object/extending.rb:52:in `instance_exec' > /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.0.1/lib/action_view/ > helpers/prototype_helper.rb:581:in `initialize' > /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.0.1/lib/action_view/ > helpers/prototype_helper.rb:992:in `new' > /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.0.1/lib/action_view/ > helpers/prototype_helper.rb:992:in `update_page' > /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.0.1/lib/action_view/ > helpers/javascript_helper.rb:87:in `link_to_function' > > No idea how to fix this :(... > > thanks in advance, and happy Christmas and all! > > bartz > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jaydonnell at yahoo.com Wed Dec 26 01:26:07 2007 From: jaydonnell at yahoo.com (Jay Donnell) Date: Tue, 25 Dec 2007 22:26:07 -0800 (PST) Subject: [rspec-users] Mocks? Really? In-Reply-To: <85d99afe0712231427k55bb3ed1x12e4dccf65cae2c6@mail.gmail.com> Message-ID: <230114.83164.qm@web56002.mail.re3.yahoo.com> > If the > implementation of a model is > wrong it isn't the job of the controller spec to > report the failure. > It's the job of the model spec or an integration > test (if its an > integration related issue) to report the failure. It seems that it would be very easy to change a model, thereby breaking the controller, and not realize it. Let's say that we decide to change the implementation of a model, how do you then go about finding the controllers that need to be updated? I know this is the classic argument between classicists and mockists, but I don't see the benefit of this type of strict mocking. If the integration test is required then what benefit are we getting from the mock and is it worth the cost? > > Also, controllers can achieve a better level of > programming toward the > "interface" rather then a concrete class by using > dependency > injection. I don't see any reason to use DI in a dynamic language like ruby. I also see no reason in this specific case. Let's assume we're working on a rails social networking site. If we have a Blog controller and a Blog model class there is no reason to use DI to inject the blog model in the blog controller. It isn't removing unneeded coupling, it's adding unneeded complexity. In java this injection is necessary to make things like testing easier, but it is wholly unnecessary in a language like ruby. > If you don't > isolate then you end > up with a lot of little integration tests. Now when > one implementation > is wrong you get 100 test failures rather then 1 or > 2, which can be a > headache when you're trying to find out why > something failed. This has never been a headache for me. If you run your tests often you'll know what was changed recently and it's trivial to find the problem. Also, if you run localized tests frequently you'll see the error without seeing the failures that it causes through out the test suite and you still get the benefit of mini integration tests ;) In all honesty I'm trying to ____________________________________________________________________________________ Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ From loop at superinfinite.com Wed Dec 26 06:17:24 2007 From: loop at superinfinite.com (Bart Zonneveld) Date: Wed, 26 Dec 2007 12:17:24 +0100 Subject: [rspec-users] Mocks? Really? In-Reply-To: <230114.83164.qm@web56002.mail.re3.yahoo.com> References: <230114.83164.qm@web56002.mail.re3.yahoo.com> Message-ID: On 26 dec 2007, at 07:26, Jay Donnell wrote: > In all honesty I'm trying to > > ____________________________________________________________________________________ > Be a better friend, newshound, and > know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ You're trying what? :) gr, bartz From zach.dennis at gmail.com Wed Dec 26 09:19:29 2007 From: zach.dennis at gmail.com (Zach Dennis) Date: Wed, 26 Dec 2007 09:19:29 -0500 Subject: [rspec-users] Mocks? Really? In-Reply-To: <230114.83164.qm@web56002.mail.re3.yahoo.com> References: <85d99afe0712231427k55bb3ed1x12e4dccf65cae2c6@mail.gmail.com> <230114.83164.qm@web56002.mail.re3.yahoo.com> Message-ID: <85d99afe0712260619p35c7088cj197116c21af1d4d4@mail.gmail.com> On Dec 26, 2007 1:26 AM, Jay Donnell wrote: > > If the > > implementation of a model is > > wrong it isn't the job of the controller spec to > > report the failure. > > It's the job of the model spec or an integration > > test (if its an > > integration related issue) to report the failure. > > It seems that it would be very easy to change a model, > thereby breaking the controller, and not realize it. > Let's say that we decide to change the implementation > of a model, how do you then go about finding the > controllers that need to be updated? The integration test will die if you broke functionality. > I know this is > the classic argument between classicists and mockists, > but I don't see the benefit of this type of strict > mocking. If the integration test is required then what > benefit are we getting from the mock and is it worth > the cost? > At either level an integration is required. I prefer extracting it out into its own test so I can simplify (by which I mean isolate) my controller. The other option is to give the test of the controller the dual responsibility of testing the controller works correctly by itself and also that it works correctly with real models. By isolating the controller and doing interaction-based testing I find that I end up with simpler controllers and more simple objects. I think this is because my tests become increasingly painful to write with the more crap I try to shove on my controller. I have learned to listen to them and start extracting out other objects when my tests become painful because it's usually a sign. I also prefer acceptance test driven development, which is TDD on top down development so interaction-based testing is important since the model is usually one of the last things I create. > > > > > Also, controllers can achieve a better level of > > programming toward the > > "interface" rather then a concrete class by using > > dependency > > injection. > > I don't see any reason to use DI in a dynamic language > like ruby. I also see no reason in this specific case. > Let's assume we're working on a rails social > networking site. If we have a Blog controller and a > Blog model class there is no reason to use DI to > inject the blog model in the blog controller. It isn't > removing unneeded coupling, it's adding unneeded > complexity. In java this injection is necessary to > make things like testing easier, but it is wholly > unnecessary in a language like ruby. This is the Jamis Buck argument. DI is unneeded in Ruby as it is implemented in Java. Needle and Copland are Java implementations in Ruby and they should be avoided. I do not agree that DI is wholly unneeded. In my experience the Injection library has been very lightweight and it has worked well in my controllers for Rails apps. The only way to get around DI is to have every class/module know about every other class/module it deals with OR to reopen classes and override methods which would supply an object. Both of these have their shortcomings. I am not advocating using DI for the sake of DI, but it can be useful. For example, I often extract out date, authentication, etc. helpers and managers. So in my BlogsController there may be a reference to the Blog model because as you say it is not unneeded coupling, however my BlogsController requires authentication and rather then dealing with a LoginManager directly it deals with a @login_manager. Having my BlogsController know about the LoginManager implementation is unneeded coupling. It needs to be able to authenticate, it doesn't need to know which implementation it uses to authenticate. >From a development perspective you end up with a declarative list of objects your implementation will rely on. It's highly readable what your controller depends to do its job. This is a supporting +1 in my opinion. > > > > If you don't > > isolate then you end > > up with a lot of little integration tests. Now when > > one implementation > > is wrong you get 100 test failures rather then 1 or > > 2, which can be a > > headache when you're trying to find out why > > something failed. > > This has never been a headache for me. If you run your > tests often you'll know what was changed recently and > it's trivial to find the problem. Also, if you run > localized tests frequently you'll see the error > without seeing the failures that it causes through out > the test suite and you still get the benefit of mini > integration tests ;) I agree we should be running tests frequently. One of the things you didn't hit up is how you test objects which coordinate interactions vs those that do the work? Those branch/leaf object scenarios. How do you see testing those? Do see the separation of testing concerns as non-existent because only doing state-based testing will cause every failure (even when an object is working correctly, but the objects its coordinating are broken)? I guess if the LoginManager is working correctly it seems wrong in principle and practice to have it be red if the User object is working is broken. -- Zach Dennis http://www.continuousthinking.com From jaydonnell at yahoo.com Wed Dec 26 13:44:53 2007 From: jaydonnell at yahoo.com (Jay Donnell) Date: Wed, 26 Dec 2007 10:44:53 -0800 (PST) Subject: [rspec-users] Mocks? Really? Message-ID: <195622.52178.qm@web56006.mail.re3.yahoo.com> My first email sounded more certain that I intended. I'm trying to work out my own views by throwing out ideas in a peer review fashion. > The integration test will die if you broke > functionality. I'm curious what you mean by 'integration test'. With regards to rails, are your integration tests always testing the full stack and verifying against the returned html/xml, i.e the verifying against the UI. If so, I find it exceptionally harder testing against the UI than testing against the controller directly and for many of my apps I don't do comprehensive UI tests because they've bitten me too many times in the past and I haven't figured out a better way to do them. This is one of the reasons that I like having my controller tests also be mini integration tests. > By isolating the controller and doing > interaction-based testing I find > that I end up with simpler controllers and more > simple objects. Yeah, I've had this experience as well, but this begs the question, are these interaction based tests really tests? I mean, they aren't really testing anything except assumptions that could easily be false. To me it feels like a great design tool that isn't really testing anything. > I also prefer acceptance test driven development, > which is TDD on top > down development so interaction-based testing is > important since the > model is usually one of the last things I create. I'm trying out this approach with a flex application I'm making that has a rails backend. So far so good, and the flex UI only talks to the rails portion via restful calls. You can do top down by mocking the backend with simple flat xml files which you then implement after the UI is completed against the mocks. > I am not advocating using DI for the sake of DI, but > it can be useful. I agree, what I was trying to say is that it's the exception rather than the rule for me personally. > One of the things you didn't hit up is how you test > objects which > coordinate interactions vs those that do the work? > Those branch/leaf > object scenarios. How do you see testing those? Do > see the separation > of testing concerns as non-existent because only > doing state-based > testing will cause every failure (even when an > object is working > correctly, but the objects its coordinating are > broken)? This may be a matter of scale. The largest rails app I've written is under 10k lines of production code with a bit over 10k lines of test code. This is relatively small, and at this level causing "every failure" hasn't posed a real problem. One of the lessons from the java world is that techniques which are needed for large scale applications are often a hinderance to small teams working on a much smaller scale. Back to your question, how would a coordinated object get broken? I can see this happening in a large team, but with small teams it's rare. And, when it does happen it's nice getting notified from the controllers test. Basically, my controller tests are my integration tests which gets back to my earlier question about how you do integration tests. Jay ____________________________________________________________________________________ Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ From pergesu at gmail.com Wed Dec 26 15:23:44 2007 From: pergesu at gmail.com (Pat Maddox) Date: Wed, 26 Dec 2007 12:23:44 -0800 Subject: [rspec-users] Mocks? Really? In-Reply-To: <85d99afe0712231427k55bb3ed1x12e4dccf65cae2c6@mail.gmail.com> References: <139c56460712060856i6bb410fcl23def3b16c0388b4@mail.gmail.com> <57c63afe0712071840w13e8d2co85a60c00f3caefa9@mail.gmail.com> <810a540e0712142317t5e13f84dt2952986cd0a58a95@mail.gmail.com> <85d99afe0712231427k55bb3ed1x12e4dccf65cae2c6@mail.gmail.com> Message-ID: <810a540e0712261223u4a0f375bqa3f63f6a4711cb60@mail.gmail.com> On Dec 23, 2007 2:27 PM, Zach Dennis wrote: > I know the questioned are directed towards Dan so I hope you don't me > chiming in. My comments are inline. Thanks a lot for your comments, I really appreciate them. I've been dying to respond to this for the past several days, but haven't had internet access. > On Dec 15, 2007 2:17 AM, Pat Maddox wrote: > > > > On Dec 8, 2007 4:06 AM, Dan North wrote: > > > I prefer the mantra "mock roles, not objects", in other words, mock things > > > that have behaviour (services, components, resources, whatever your > > > preferred term is) rather than stubbing out domain objects themselves. If > > > you have to mock domain objects it's usually a smell that your domain > > > implementation is too tightly coupled to some infrastructure. > > > > Assuming you could easily write Rails specs using the real domain > > objects, but not hit the database, would you "never" mock domain > > objects (where "never" means you deviate only in extraordinary > > circumstances)? I'm mostly curious in the interaction between > > controller and model...if you use real models, then changes to the > > model code could very well lead to failing controller specs, even > > though the controller's logic is still correct. > > In Java you don't mock domain objects because you want to program > toward an interface rather then a single concrete implementation. > Conceptually this still applies in Ruby, but because of differences > between the languages it isn't a 1 to 1 mapping in practice. I must be misunderstanding you here, because you say you "don't mock domain objects," and the rest of your email suggests that you mock basically everything. > > Do you try to test each > > class in complete isolation, mocking its collaborators? > > Yes. The pattern I find I follow in testing is that objects whose job > it is to coordinate or manage other objects (like controllers, > presenters, managers, etc) are always tested in isolation. > Interaction-based testing is the key here. These objects can be > considered branch objects. They connect to other branches or to leaf > node objects. > > Leaf node objects are the end of the line and they do the actual work. > Here is where I use state based testing. I consider ActiveRecord > models leaf nodes. What about interactions between ActiveRecord objects. If a User has_many Subscriptions, do you mock out those interactions? Would you still mock them out if User and Subscription were PROs (plain Ruby objects) and persistence were handled separately? > > When you use > > interaction-based tests, do you always leave those in place, or do you > > substitute real objects as you implement them (and if so, do your > > changes move to a more state-based style)? > > Leave the mocked out collaborators in place. An interaction based test > verifies that the correct interaction takes place. As soon as you > remove the mock and substitute it with a real object your test has > become compromised. It's no longer verifying the correct interaction > occurs, it now only makes sure your test doesn't die with a real > object. This leads to perhaps a more subtle case of my previous question...ActiveRecord relies pretty heavily on the real classes of objects. To me, this means that it would make more sense to use mocks if you didn't use AR, but use the real objects when you are using AR. Again, this is only between model objects. I agree that controller specs should mock them all out. > > I realize that's a ton of questions...I'd be very grateful (and > > impressed!) if you took the time to answer any of them. Also I'd love > > to hear input from other people as well. > > > > It's too bad we can't just stand at a whiteboard and talk this out. > The answers to these questions could fill a book and email hardly does > it justice to provide clear, coherent and complete answers. Not that > my response are "answers" to your questions, but it's how I think > about testing and TDD. Thanks again for your thoughtful reply. Looking forward to hearing a little bit more. Pat From zach.dennis at gmail.com Wed Dec 26 15:44:38 2007 From: zach.dennis at gmail.com (Zach Dennis) Date: Wed, 26 Dec 2007 15:44:38 -0500 Subject: [rspec-users] Mocks? Really? In-Reply-To: <810a540e0712261223u4a0f375bqa3f63f6a4711cb60@mail.gmail.com> References: <139c56460712060856i6bb410fcl23def3b16c0388b4@mail.gmail.com> <57c63afe0712071840w13e8d2co85a60c00f3caefa9@mail.gmail.com> <810a540e0712142317t5e13f84dt2952986cd0a58a95@mail.gmail.com> <85d99afe0712231427k55bb3ed1x12e4dccf65cae2c6@mail.gmail.com> <810a540e0712261223u4a0f375bqa3f63f6a4711cb60@mail.gmail.com> Message-ID: <85d99afe0712261244r62c1134dwf25674b59bc617aa@mail.gmail.com> On Dec 26, 2007 3:23 PM, Pat Maddox wrote: > On Dec 23, 2007 2:27 PM, Zach Dennis wrote: > > I know the questioned are directed towards Dan so I hope you don't me > > chiming in. My comments are inline. > > Thanks a lot for your comments, I really appreciate them. I've been > dying to respond to this for the past several days, but haven't had > internet access. > > > > On Dec 15, 2007 2:17 AM, Pat Maddox wrote: > > > > > > On Dec 8, 2007 4:06 AM, Dan North wrote: > > > > I prefer the mantra "mock roles, not objects", in other words, mock things > > > > that have behaviour (services, components, resources, whatever your > > > > preferred term is) rather than stubbing out domain objects themselves. If > > > > you have to mock domain objects it's usually a smell that your domain > > > > implementation is too tightly coupled to some infrastructure. > > > > > > Assuming you could easily write Rails specs using the real domain > > > objects, but not hit the database, would you "never" mock domain > > > objects (where "never" means you deviate only in extraordinary > > > circumstances)? I'm mostly curious in the interaction between > > > controller and model...if you use real models, then changes to the > > > model code could very well lead to failing controller specs, even > > > though the controller's logic is still correct. > > > > In Java you don't mock domain objects because you want to program > > toward an interface rather then a single concrete implementation. > > Conceptually this still applies in Ruby, but because of differences > > between the languages it isn't a 1 to 1 mapping in practice. > > I must be misunderstanding you here, because you say you "don't mock > domain objects," and the rest of your email suggests that you mock > basically everything. > I'll respond more later, but wanted to point out that that should be "In Java you mock domain objects because you want to ...". I don't know how the "n't" got in there. ;) Zach Dennis http://www.continuousthinking.com From armin.joellenbeck at googlemail.com Wed Dec 26 16:38:22 2007 From: armin.joellenbeck at googlemail.com (Armin Joellenbeck) Date: Wed, 26 Dec 2007 22:38:22 +0100 Subject: [rspec-users] executing code after each step of a story Message-ID: <4a117bfc0712261338y789f13a4p35f6b9546d3a7905@mail.gmail.com> Hello, how can I execute some code after each step of a story. Is there some kind of listener documentated. Thank you in advance, Armin From dchelimsky at gmail.com Wed Dec 26 16:48:41 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 26 Dec 2007 16:48:41 -0500 Subject: [rspec-users] executing code after each step of a story In-Reply-To: <4a117bfc0712261338y789f13a4p35f6b9546d3a7905@mail.gmail.com> References: <4a117bfc0712261338y789f13a4p35f6b9546d3a7905@mail.gmail.com> Message-ID: <57c63afe0712261348l31537bd2m96eb343b9ed1a14f@mail.gmail.com> On Dec 26, 2007 4:38 PM, Armin Joellenbeck wrote: > Hello, > > how can I execute some code after each step of a story. Is there some > kind of listener documentated. Very little is documented, and Story Runner is still considered experimental (i.e. API's subject to change), but here is what you can do with the 1.1.1 release: World.add_listener(mylistener) The listener needs to respond to a variety of messages related to steps and scenarios, so you'll probably want to implement method_missing to ignore the messages you're not interested in. HTH, David > > Thank you in advance, > > Armin > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From brynarylists at gmail.com Thu Dec 20 13:07:41 2007 From: brynarylists at gmail.com (Bryan Helmkamp) Date: Thu, 20 Dec 2007 13:07:41 -0500 Subject: [rspec-users] Story runner rake task In-Reply-To: <26B603F8-8907-48DD-ACC0-CAACBF738274@gmail.com> References: <75D18260-5D95-4B1F-BCC6-9D0A8C98CB47@gmail.com> <57c63afe0712192138v6ae83c3aiaad7adbd09a4fce5@mail.gmail.com> <6A09754D-7C3E-4125-8DA9-80089F8B525C@gmail.com> <57c63afe0712192144p644d3d2fkeda2979c85d3aac@mail.gmail.com> <57c63afe0712192216w3e981456qd9d04d7012990f99@mail.gmail.com> <57c63afe0712192242g5bcfecabk5225146ff84dba3f@mail.gmail.com> <26B603F8-8907-48DD-ACC0-CAACBF738274@gmail.com> Message-ID: Thanks for the endorsement, David. Just wanted to mention that I'd be very interested in optimizing the internals of Webrat for performance down the road if necessary. We're not tied to Hpricot by the API, so swapping it out for a faster parser would be fine if it produces a speed gain. My first goal was to nail the approach and get a good API. In the mean time, in my experience it is quite fast, and I'm personally quite picky about test speed. When I've got more concrete benchmarks on a larger test suite, I'll post them. -- Bryan Helmkamp http://brynary.com -- My blog From zach.dennis at gmail.com Thu Dec 27 09:13:55 2007 From: zach.dennis at gmail.com (Zach Dennis) Date: Thu, 27 Dec 2007 09:13:55 -0500 Subject: [rspec-users] Mocks? Really? In-Reply-To: <810a540e0712261223u4a0f375bqa3f63f6a4711cb60@mail.gmail.com> References: <139c56460712060856i6bb410fcl23def3b16c0388b4@mail.gmail.com> <57c63afe0712071840w13e8d2co85a60c00f3caefa9@mail.gmail.com> <810a540e0712142317t5e13f84dt2952986cd0a58a95@mail.gmail.com> <85d99afe0712231427k55bb3ed1x12e4dccf65cae2c6@mail.gmail.com> <810a540e0712261223u4a0f375bqa3f63f6a4711cb60@mail.gmail.com> Message-ID: <85d99afe0712270613i2d221e35m6f9a34b8c7de4f04@mail.gmail.com> On Dec 26, 2007 3:23 PM, Pat Maddox wrote: > On Dec 23, 2007 2:27 PM, Zach Dennis wrote: > > I know the questioned are directed towards Dan so I hope you don't me > > chiming in. My comments are inline. > > Thanks a lot for your comments, I really appreciate them. I've been > dying to respond to this for the past several days, but haven't had > internet access. > > > > On Dec 15, 2007 2:17 AM, Pat Maddox wrote: > > > > > > On Dec 8, 2007 4:06 AM, Dan North wrote: > > > > I prefer the mantra "mock roles, not objects", in other words, mock things > > > > that have behaviour (services, components, resources, whatever your > > > > preferred term is) rather than stubbing out domain objects themselves. If > > > > you have to mock domain objects it's usually a smell that your domain > > > > implementation is too tightly coupled to some infrastructure. > > > > > > Assuming you could easily write Rails specs using the real domain > > > objects, but not hit the database, would you "never" mock domain > > > objects (where "never" means you deviate only in extraordinary > > > circumstances)? I'm mostly curious in the interaction between > > > controller and model...if you use real models, then changes to the > > > model code could very well lead to failing controller specs, even > > > though the controller's logic is still correct. > > > > In Java you don't mock domain objects because you want to program > > toward an interface rather then a single concrete implementation. > > Conceptually this still applies in Ruby, but because of differences > > between the languages it isn't a 1 to 1 mapping in practice. > > I must be misunderstanding you here, because you say you "don't mock > domain objects," and the rest of your email suggests that you mock > basically everything. > > > > > > Do you try to test each > > > class in complete isolation, mocking its collaborators? > > > > Yes. The pattern I find I follow in testing is that objects whose job > > it is to coordinate or manage other objects (like controllers, > > presenters, managers, etc) are always tested in isolation. > > Interaction-based testing is the key here. These objects can be > > considered branch objects. They connect to other branches or to leaf > > node objects. > > > > Leaf node objects are the end of the line and they do the actual work. > > Here is where I use state based testing. I consider ActiveRecord > > models leaf nodes. > > What about interactions between ActiveRecord objects. If a User > has_many Subscriptions, do you mock out those interactions? For me it depends. If I am testing my User object and it has a custom method called find_subscriptions_which_have_not_expired_but_which _has_not_been_read_in_over_n_days. I will not mock out any interactions with the subscriptions at that point. This is for two reasons. One, when I first get this to work I may do it in pure ruby code (no SQL help) just to get it working. At some later date/time this is going to move to SQL. I want my test to not have to change in order to do this. If I was interaction-based testing this custom find method then it wouldn't really help me ensure I didn't break something. Secondly, I view my model has a leaf node object. Most of everything my model does I want to state based test the thing to ensure the results are what I want (and not the interactions). Some times I find there is a method where I will mock an association because I truly don't care about the result, and I really only care about the interaction. For example if User delegates something to the Subscription class either via a delegate declaration or a simple method which delegates. For example: delegate :zip_code, :to => :address OR def zip_code address.zip_code end > Would you > still mock them out if User and Subscription were PROs (plain Ruby > objects) and persistence were handled separately? Possibly. I think it depends on how the objects used each other, what kind of mini-frameworks or modules were in place to give functionality, etc. Since models get most of their functionality through inheritance of ActiveRecord::Base it would be difficult to compare w/o knowing how my PROs were hooked up. Composition or inheritance makes a difference in my head right now. Do you have any specific concrete examples in mind? > > > > > When you use > > > interaction-based tests, do you always leave those in place, or do you > > > substitute real objects as you implement them (and if so, do your > > > changes move to a more state-based style)? > > > > Leave the mocked out collaborators in place. An interaction based test > > verifies that the correct interaction takes place. As soon as you > > remove the mock and substitute it with a real object your test has > > become compromised. It's no longer verifying the correct interaction > > occurs, it now only makes sure your test doesn't die with a real > > object. > > This leads to perhaps a more subtle case of my previous > question...ActiveRecord relies pretty heavily on the real classes of > objects. To me, this means that it would make more sense to use mocks > if you didn't use AR, but use the real objects when you are using AR. > Again, this is only between model objects. I agree that controller > specs should mock them all out. I agree with this. This is largely how I work now as described above. > > > > > I realize that's a ton of questions...I'd be very grateful (and > > > impressed!) if you took the time to answer any of them. Also I'd love > > > to hear input from other people as well. > > > > > > > It's too bad we can't just stand at a whiteboard and talk this out. > > The answers to these questions could fill a book and email hardly does > > it justice to provide clear, coherent and complete answers. Not that > > my response are "answers" to your questions, but it's how I think > > about testing and TDD. > > Thanks again for your thoughtful reply. Looking forward to hearing a > little bit more. > ditto, -- Zach Dennis http://www.continuousthinking.com From coreyhaines at gmail.com Thu Dec 27 11:30:35 2007 From: coreyhaines at gmail.com (Corey Haines) Date: Thu, 27 Dec 2007 11:30:35 -0500 Subject: [rspec-users] ExampleGroup and SharedExampleGroup relationship(?) Message-ID: <6bdacb70712270830h18cc05a9s9c52aa69c5eb7b1@mail.gmail.com> I'm working on a series going over the source code for rspec, and I ran into something interesting with ExampleGroup and SharedExampleGroup. I was wondering if anyone could shed light on it. [NOTE: I'm working through the code for my own edification in learning Ruby. Ruby has some features that I think are incredibly cool, so I'm using a concrete implementation (RSpec) as a learning tool to see them implemented. Along the way, I figured I would ask questions that were confusing to me. So, please bear with me and please please please do not take this as criticisms/attacks] I expected to see SharedExampleGroup < ExampleGroup, but, instead, I saw SharedExampleGroup < Module. This is incredibly confusing to me. I realize that they don't even need to have any relationship to each other since they get their shared functionality through the module ExampleGroupMethods, but it still seems a bit odd to me that they don't have a hierarchical relationship. If there is some hidden meaning, I'd love to hear it. I'll post it as an update to the blog entry, too. Oh, and here are the links to the first few parts of the series if anyone is interested: It looks like I'll be able to get about a post a week on it. part 1: http://www.coreyhaines.com/coreysramblings/2007/12/15/ARubyNewbieLooksThroughRSpecPartIWhatIsThis.aspx part 2: http://www.coreyhaines.com/coreysramblings/2007/12/15/ARubyNewbieLooksThroughRSpecPartIIDescribe.aspx part 3: http://www.coreyhaines.com/coreysramblings/2007/12/22/ARubyNewbieLooksThroughRSpecPartIIIDescribeRedux.aspx part 4: I'm working on this, which is where I noticed the ExampleGroup/SharedExampleGroup thing. -Corey -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071227/1820a1ba/attachment.html From mailing_lists at railsnewbie.com Thu Dec 27 12:12:56 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Thu, 27 Dec 2007 12:12:56 -0500 Subject: [rspec-users] ExampleGroup and SharedExampleGroup relationship(?) In-Reply-To: <6bdacb70712270830h18cc05a9s9c52aa69c5eb7b1@mail.gmail.com> References: <6bdacb70712270830h18cc05a9s9c52aa69c5eb7b1@mail.gmail.com> Message-ID: <92F99ABF-D596-4BCE-828F-D809462942FB@railsnewbie.com> On Dec 27, 2007, at 11:30 AM, Corey Haines wrote: > I'm working on a series going over the source code for rspec, and I > ran into something interesting with ExampleGroup and > SharedExampleGroup. I was wondering if anyone could shed light on it. > [NOTE: I'm working through the code for my own edification in > learning Ruby. Ruby has some features that I think are incredibly > cool, so I'm using a concrete implementation (RSpec) as a learning > tool to see them implemented. Along the way, I figured I would ask > questions that were confusing to me. So, please bear with me and > please please please do not take this as criticisms/attacks] > > I expected to see SharedExampleGroup < ExampleGroup, but, instead, > I saw SharedExampleGroup < Module. This is incredibly confusing to > me. I realize that they don't even need to have any relationship to > each other since they get their shared functionality through the > module ExampleGroupMethods, but it still seems a bit odd to me that > they don't Yep - it certainly was surprising to me too. Here's some explanation (although not on the design decision front - just on the Ruby, how it works front): When you use the keyword module, you are actually creating a new instance of the Module class. So these two are equivalent: MyMod = Module.new() module MyMod; end So - Module is a class, but a module is a module (i.e., an instance of the class Module). The SharedExampleGroup is a class, which decends from the Module class. This, in effect, makes a new SharedExampleGroup instance act like a typical module (it is a kind_of?(Module)) - just as if you had declared it with Module.new or the keyword. The advantage of using the approach of instantiating over using the keyword is that the keyword always requires a constant to be defined - on the other hand, Module.new doesn't need a constant, and can be passed around as a regular object without needing to define these constants on the fly. Since the SharedExampleGroup is a subclass of Module, the instances of SharedExampleGroup can be included just as a regular module can be, into the regular old ExampleGroup (this is what happens when you say it_should_behave_like "..." - the instances methods of the SharedExampleGroup are copied directly. Now - for why it was implemented this way, and not another way, David or Aslak could tell you much better than I. Also - it's likely this implementation will change in the near future. Hope that helps. Scott > have a hierarchical relationship. > > If there is some hidden meaning, I'd love to hear it. I'll post it > as an update to the blog entry, too. > > Oh, and here are the links to the first few parts of the series if > anyone is interested: It looks like I'll be able to get about a > post a week on it. > > part 1: http://www.coreyhaines.com/coreysramblings/2007/12/15/ > ARubyNewbieLooksThroughRSpecPartIWhatIsThis.aspx > > part 2: http://www.coreyhaines.com/coreysramblings/2007/12/15/ > ARubyNewbieLooksThroughRSpecPartIIDescribe.aspx > > part 3: http://www.coreyhaines.com/coreysramblings/2007/12/22/ > ARubyNewbieLooksThroughRSpecPartIIIDescribeRedux.aspx > > part 4: I'm working on this, which is where I noticed the > ExampleGroup/SharedExampleGroup thing. > > > -Corey > > -- > http://www.coreyhaines.com > The Internet's Premiere source of information about Corey Haines > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071227/222f9e51/attachment-0001.html From pergesu at gmail.com Thu Dec 27 12:21:05 2007 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 27 Dec 2007 09:21:05 -0800 Subject: [rspec-users] ExampleGroup and SharedExampleGroup relationship(?) In-Reply-To: <6bdacb70712270830h18cc05a9s9c52aa69c5eb7b1@mail.gmail.com> References: <6bdacb70712270830h18cc05a9s9c52aa69c5eb7b1@mail.gmail.com> Message-ID: <810a540e0712270921y4ebab945y68610982e26eb5e1@mail.gmail.com> On Dec 27, 2007 8:30 AM, Corey Haines wrote: > I expected to see SharedExampleGroup < ExampleGroup, but, instead, I saw > SharedExampleGroup < Module. This is incredibly confusing to me. I realize > that they don't even need to have any relationship to each other since they > get their shared functionality through the module ExampleGroupMethods, but > it still seems a bit odd to me that they don't have a hierarchical > relationship. Whenever you write an example, RSpec defines a method. Shared example groups are basically sugary modules. They define examples - methods - that get included into your "real" example groups. I can't say for sure if there's any deeper meaning to it other than it's the simplest implementation. It would be possible to make SharedExampleGroup be a class, but then when an ExampleGroup uses it_should_behave_like, it would have to list all the examples in the SharedExampleGroup, define methods on itself that delegate to the SEG...as opposed to just mixing in a module :) I admit I'm pulling all of this out of my ass, btw, but I think it's right. I'm sure David will clarify soon. Pat From coreyhaines at gmail.com Thu Dec 27 12:36:25 2007 From: coreyhaines at gmail.com (Corey Haines) Date: Thu, 27 Dec 2007 12:36:25 -0500 Subject: [rspec-users] ExampleGroup and SharedExampleGroup relationship(?) In-Reply-To: <810a540e0712270921y4ebab945y68610982e26eb5e1@mail.gmail.com> References: <6bdacb70712270830h18cc05a9s9c52aa69c5eb7b1@mail.gmail.com> <810a540e0712270921y4ebab945y68610982e26eb5e1@mail.gmail.com> Message-ID: <6bdacb70712270936t5c28c884y4a7a1afae077b164@mail.gmail.com> Thanks to both Pat and Scott for the first two comments. I'm digesting what you are saying. I'll take these ideas (and any others that come) and try to summarize them in and upcoming post. Thanks. -Corey On Dec 27, 2007 12:21 PM, Pat Maddox wrote: > On Dec 27, 2007 8:30 AM, Corey Haines wrote: > > I expected to see SharedExampleGroup < ExampleGroup, but, instead, I saw > > SharedExampleGroup < Module. This is incredibly confusing to me. I > realize > > that they don't even need to have any relationship to each other since > they > > get their shared functionality through the module ExampleGroupMethods, > but > > it still seems a bit odd to me that they don't have a hierarchical > > relationship. > > Whenever you write an example, RSpec defines a method. Shared example > groups are basically sugary modules. They define examples - methods - > that get included into your "real" example groups. > > I can't say for sure if there's any deeper meaning to it other than > it's the simplest implementation. It would be possible to make > SharedExampleGroup be a class, but then when an ExampleGroup uses > it_should_behave_like, it would have to list all the examples in the > SharedExampleGroup, define methods on itself that delegate to the > SEG...as opposed to just mixing in a module :) > > I admit I'm pulling all of this out of my ass, btw, but I think it's > right. I'm sure David will clarify soon. > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071227/9c020bf8/attachment.html From dchelimsky at gmail.com Thu Dec 27 12:41:23 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 27 Dec 2007 11:41:23 -0600 Subject: [rspec-users] ExampleGroup and SharedExampleGroup relationship(?) In-Reply-To: <92F99ABF-D596-4BCE-828F-D809462942FB@railsnewbie.com> References: <6bdacb70712270830h18cc05a9s9c52aa69c5eb7b1@mail.gmail.com> <92F99ABF-D596-4BCE-828F-D809462942FB@railsnewbie.com> Message-ID: <57c63afe0712270941p2554cf3cye9cd419595c5d557@mail.gmail.com> On Dec 27, 2007 11:12 AM, Scott Taylor wrote: >> On Dec 27, 2007, at 11:30 AM, Corey Haines wrote: >> I'm working on a series going over the source code for rspec, and I ran into >> something interesting with ExampleGroup and SharedExampleGroup. I was >> wondering if anyone could shed light on it. > Now - for why it was implemented this way, and not another way, David or > Aslak could tell you much better than I. > > Also - it's likely this implementation will change in the near future. I had said it might change a while back, but at this point we are quite happy with the way this works and don't expect it to change. The reason we like it is as you described: to use a shared group you just include the module and you get everything for free. The alternative is slinging around a bunch of Method objects. This would be fine if it added some value, but the way things have landed it really doesn't. Cheers, David From dchelimsky at gmail.com Thu Dec 27 12:42:14 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 27 Dec 2007 11:42:14 -0600 Subject: [rspec-users] ExampleGroup and SharedExampleGroup relationship(?) In-Reply-To: <810a540e0712270921y4ebab945y68610982e26eb5e1@mail.gmail.com> References: <6bdacb70712270830h18cc05a9s9c52aa69c5eb7b1@mail.gmail.com> <810a540e0712270921y4ebab945y68610982e26eb5e1@mail.gmail.com> Message-ID: <57c63afe0712270942n1329c658oa58f0cf0d97b8c60@mail.gmail.com> On Dec 27, 2007 11:21 AM, Pat Maddox wrote: > On Dec 27, 2007 8:30 AM, Corey Haines wrote: > > I expected to see SharedExampleGroup < ExampleGroup, but, instead, I saw > > SharedExampleGroup < Module. This is incredibly confusing to me. I realize > > that they don't even need to have any relationship to each other since they > > get their shared functionality through the module ExampleGroupMethods, but > > it still seems a bit odd to me that they don't have a hierarchical > > relationship. > > Whenever you write an example, RSpec defines a method. Shared example > groups are basically sugary modules. They define examples - methods - > that get included into your "real" example groups. > > I can't say for sure if there's any deeper meaning to it other than > it's the simplest implementation. That's about right. Cheers, David From rick.denatale at gmail.com Thu Dec 27 16:22:13 2007 From: rick.denatale at gmail.com (Rick DeNatale) Date: Thu, 27 Dec 2007 16:22:13 -0500 Subject: [rspec-users] RSpec on Ruby 1.9: before(:all) (Not Yet Implemented) pending messages instead of tests In-Reply-To: <20071227201926.GJ1277@durance.shot.pl> References: <20071227181607.GI1277@durance.shot.pl> <20071227201926.GJ1277@durance.shot.pl> Message-ID: On Dec 27, 2007 3:18 PM, Shot (Piotr Szotkowski) wrote: > Shot (Piotr Szotkowski): > > > I happily hand-compiled Ruby 1.9.0-0 into /home/shot/opt/ruby today > > and I'm running into a strange error with RSpec ? all my examples work > > perfectly with Ruby 1.8 but are considered peding on Ruby 1.9. > > FWIW, I get the same result with this simplest spec: > > describe Array do > it 'should work' do > a = [1, 2] > a.first.should == 1 > end > end > > RSpec 1.1.1 on Ruby 1.8 ? 1 example, 0 failures. > RSpec 1.1.1 on Ruby 1.9 ? 1 example, 0 failures, 1 pending. > You should probably bring this up on the rspec-users list (I'm copying this reply there). This is most likely either: 1) A bug in Ruby 1.9 - At least one bug was reported just before the 1.9.0 release which related to using module_eval inside a method. I've looked at the RSpec code and it's using instance_eval inside a method, so there might be a related bug. I tried to come up with a simplified program which evidenced a failure, but couldn't, but I didn't try all that hard. 2) RSpec running into a subtle 1.9 incompatible language change. I didn't see anything obvious, but that's not to say it's not there. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From raecoo at gmail.com Fri Dec 28 11:20:15 2007 From: raecoo at gmail.com (Raecoo) Date: Sat, 29 Dec 2007 00:20:15 +0800 Subject: [rspec-users] rspec_autotest testing with the use of the controller Namespaces Message-ID: <76ab035e0712280820v7735ed50p799afc5ee3b0fd6d@mail.gmail.com> Rails2.0 the official support of namespace, making it easier for people with the usual habit of definition Controller For example,We define the following Controller admin/hacks_controller this class namespace is Admin::HackController When we use rspec_autotest for testing,Will be following error no such file to load -- ./spec/views/hacks/../../spec_helper (LoadError) The wrong reason is very simple. By default, rspec_autotest the loading path and does not take into account the issue of naming space, so it is necessary to be loaded their own. There are two ways: First, edit documents in the corresponding Spec loading path require File.dirname(__FILE__) + '/../../spec_helper' ### here Another, add the overall load require File.expand_path(File.dirname(__FILE__) + "/../spec/spec_helper") Two methods are very useful, but first some trouble.Choose your own ways to use it -- Best Wish For You Raecoo GTalk/Gmail: raecoo at gmail.com MSN: caol at live.com From ola.bini at gmail.com Fri Dec 28 16:46:11 2007 From: ola.bini at gmail.com (Ola Bini) Date: Fri, 28 Dec 2007 21:46:11 +0000 Subject: [rspec-users] JtestR 0.1 released Message-ID: <47756EA3.3010607@gmail.com> JtestR allows you to test your Java code with Ruby frameworks. Homepage: http://jtestr.codehaus.org Download: http://dist.codehaus.org/jtestr JtestR 0.1 is the first public release of the JtestR testing tool. JtestR integrates JRuby with several Ruby frameworks to allow painless testing of Java code, using RSpec, Test/Unit, dust and Mocha. Features: - Integrates with Ant and Maven - Includes JRuby 1.1, Test/Unit, RSpec, dust, Mocha and ActiveSupport - Customizes Mocha so that mocking of any Java class is possible - Background testing server for quick startup of tests - Automatically runs your JUnit codebase as part of the build Getting started: http://jtestr.codehaus.org/Getting+Started Team: Ola Bini - ola.bini at gmail.com Anda Abramovici - anda.abramovici at gmail.com -- Ola Bini (http://ola-bini.blogspot.com) JRuby Core Developer Developer, ThoughtWorks Studios (http://studios.thoughtworks.com) Practical JRuby on Rails (http://apress.com/book/view/9781590598818) "Yields falsehood when quined" yields falsehood when quined. From cwdinfo at gmail.com Fri Dec 28 17:56:11 2007 From: cwdinfo at gmail.com (s.ross) Date: Fri, 28 Dec 2007 14:56:11 -0800 Subject: [rspec-users] Converting to Rails 2.0.2 Message-ID: I'm moving an older project to Rails 2.0.2 and ran into a roadblock on the version matching. Here's script/console session: >> Spec::VERSION::REV => "1785" >> Spec::Rails::VERSION::REV NoMethodError: undefined method `run=' for Test::Unit:Module from /Users/sxross/rails/tastie_work/vendor/plugins/rspec_on_rails/ lib/spec/rails.rb:16 from /Users/sxross/rails/tastie_work/vendor/rails/activerecord/ lib/../../activesupport/lib/active_support/dependencies.rb:203:in `load_without_new_constant_marking' from /Users/sxross/rails/tastie_work/vendor/rails/activerecord/ lib/../../activesupport/lib/active_support/dependencies.rb:203:in `load_file' from /Users/sxross/rails/tastie_work/vendor/rails/activerecord/ lib/../../activesupport/lib/active_support/dependencies.rb:342:in `new_constants_in' from /Users/sxross/rails/tastie_work/vendor/rails/activerecord/ lib/../../activesupport/lib/active_support/dependencies.rb:202:in `load_file' from /Users/sxross/rails/tastie_work/vendor/rails/activerecord/ lib/../../activesupport/lib/active_support/dependencies.rb:94:in `require_or_load' from /Users/sxross/rails/tastie_work/vendor/rails/activerecord/ lib/../../activesupport/lib/active_support/dependencies.rb:248:in `load_missing_constant' from /Users/sxross/rails/tastie_work/vendor/rails/activerecord/ lib/../../activesupport/lib/active_support/dependencies.rb:453:in `const_missing' The project uses trunk versions of rspec and rspec_on_rails, along with current Rails edge (at this point, 8506). After upgrading Rails and some of the normal monkeying around, I did a script/generate rspec (nothing of note there and replaced all just to be sure). Then: rake spec does this: Users/sxross/rails/tastie_work/vendor/rails/activerecord/lib/../../ activesupport/lib/active_support/dependencies.rb:263:in `load_missing_constant': uninitialized constant Spec::VERSION::REV (NameError) from /Users/sxross/rails/tastie_work/vendor/rails/activerecord/ lib/../../activesupport/lib/active_support/dependencies.rb:453:in `const_missing' from /Users/sxross/rails/tastie_work/vendor/plugins/rspec_on_rails/ lib/spec/rails/version.rb:13 from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:27:in `gem_original_require' from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:27:in `require' from /Users/sxross/rails/tastie_work/vendor/rails/activerecord/ lib/../../activesupport/lib/active_support/dependencies.rb:496:in `require' from /Users/sxross/rails/tastie_work/vendor/rails/activerecord/ lib/../../activesupport/lib/active_support/dependencies.rb:342:in `new_constants_in' from /Users/sxross/rails/tastie_work/vendor/rails/activerecord/ lib/../../activesupport/lib/active_support/dependencies.rb:496:in `require' from /Users/sxross/rails/tastie_work/vendor/plugins/rspec_on_rails/ lib/spec/rails.rb:11 ... 11 levels... from /Library/Ruby/Gems/1.8/gems/rspec-1.1.1/lib/spec/runner/ example_group_runner.rb:13:in `load_files' from /Library/Ruby/Gems/1.8/gems/rspec-1.1.1/lib/spec/runner/ options.rb:83:in `run_examples' from /Library/Ruby/Gems/1.8/gems/rspec-1.1.1/lib/spec/runner/ command_line.rb:19:in `run' from /Library/Ruby/Gems/1.8/gems/rspec-1.1.1/bin/spec:3 Anyone know what's up here? Thx --s From aslak.hellesoy at gmail.com Fri Dec 28 19:28:09 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Sat, 29 Dec 2007 01:28:09 +0100 Subject: [rspec-users] JtestR 0.1 released In-Reply-To: <47756EA3.3010607@gmail.com> References: <47756EA3.3010607@gmail.com> Message-ID: <8d961d900712281628t62a24026pe2aad539fd86b87b@mail.gmail.com> On Dec 28, 2007 10:46 PM, Ola Bini wrote: > JtestR allows you to test your Java code with Ruby frameworks. > > Homepage: http://jtestr.codehaus.org > Download: http://dist.codehaus.org/jtestr > Thanks for the pointer and the code Ola - this is REALLY cool. I'll definitely take a close look at this - I'm over my "java is boring" period ;-) Aslak > JtestR 0.1 is the first public release of the JtestR testing tool. > JtestR integrates JRuby with several Ruby frameworks to allow painless > testing of Java code, using RSpec, Test/Unit, dust and Mocha. > > Features: > - Integrates with Ant and Maven > - Includes JRuby 1.1, Test/Unit, RSpec, dust, Mocha and ActiveSupport > - Customizes Mocha so that mocking of any Java class is possible > - Background testing server for quick startup of tests > - Automatically runs your JUnit codebase as part of the build > > Getting started: http://jtestr.codehaus.org/Getting+Started > > Team: > Ola Bini - ola.bini at gmail.com > Anda Abramovici - anda.abramovici at gmail.com > > -- > Ola Bini (http://ola-bini.blogspot.com) > JRuby Core Developer > Developer, ThoughtWorks Studios (http://studios.thoughtworks.com) > Practical JRuby on Rails (http://apress.com/book/view/9781590598818) > > "Yields falsehood when quined" yields falsehood when quined. > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From philodespotos at gmail.com Fri Dec 28 20:08:08 2007 From: philodespotos at gmail.com (Kyle Hargraves) Date: Fri, 28 Dec 2007 20:08:08 -0500 Subject: [rspec-users] Converting to Rails 2.0.2 In-Reply-To: References: Message-ID: <60f3810c0712281708v6074e92aw51b7094191d4dbde@mail.gmail.com> The REV constants no longer exist in trunk (and haven't for a while), yet somehow your rspec_on_rails in vendor is still expecting it. Meaning you don't actually have a copy of trunk in plugins/rspec_on_rails, I guess. HTH Kyle On 12/28/07, s.ross wrote: > I'm moving an older project to Rails 2.0.2 and ran into a roadblock on > the version matching. Here's script/console session: > > >> Spec::VERSION::REV > => "1785" > >> Spec::Rails::VERSION::REV > NoMethodError: undefined method `run=' for Test::Unit:Module > from /Users/sxross/rails/tastie_work/vendor/plugins/rspec_on_rails/ > lib/spec/rails.rb:16 > from /Users/sxross/rails/tastie_work/vendor/rails/activerecord/ > lib/../../activesupport/lib/active_support/dependencies.rb:203:in > `load_without_new_constant_marking' > from /Users/sxross/rails/tastie_work/vendor/rails/activerecord/ > lib/../../activesupport/lib/active_support/dependencies.rb:203:in > `load_file' > from /Users/sxross/rails/tastie_work/vendor/rails/activerecord/ > lib/../../activesupport/lib/active_support/dependencies.rb:342:in > `new_constants_in' > from /Users/sxross/rails/tastie_work/vendor/rails/activerecord/ > lib/../../activesupport/lib/active_support/dependencies.rb:202:in > `load_file' > from /Users/sxross/rails/tastie_work/vendor/rails/activerecord/ > lib/../../activesupport/lib/active_support/dependencies.rb:94:in > `require_or_load' > from /Users/sxross/rails/tastie_work/vendor/rails/activerecord/ > lib/../../activesupport/lib/active_support/dependencies.rb:248:in > `load_missing_constant' > from /Users/sxross/rails/tastie_work/vendor/rails/activerecord/ > lib/../../activesupport/lib/active_support/dependencies.rb:453:in > `const_missing' > > The project uses trunk versions of rspec and rspec_on_rails, along > with current Rails edge (at this point, 8506). After upgrading Rails > and some of the normal monkeying around, I did a script/generate rspec > (nothing of note there and replaced all just to be sure). Then: > > rake spec does this: > > Users/sxross/rails/tastie_work/vendor/rails/activerecord/lib/../../ > activesupport/lib/active_support/dependencies.rb:263:in > `load_missing_constant': uninitialized constant Spec::VERSION::REV > (NameError) > from /Users/sxross/rails/tastie_work/vendor/rails/activerecord/ > lib/../../activesupport/lib/active_support/dependencies.rb:453:in > `const_missing' > from /Users/sxross/rails/tastie_work/vendor/plugins/rspec_on_rails/ > lib/spec/rails/version.rb:13 > from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:27:in > `gem_original_require' > from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:27:in `require' > from /Users/sxross/rails/tastie_work/vendor/rails/activerecord/ > lib/../../activesupport/lib/active_support/dependencies.rb:496:in > `require' > from /Users/sxross/rails/tastie_work/vendor/rails/activerecord/ > lib/../../activesupport/lib/active_support/dependencies.rb:342:in > `new_constants_in' > from /Users/sxross/rails/tastie_work/vendor/rails/activerecord/ > lib/../../activesupport/lib/active_support/dependencies.rb:496:in > `require' > from /Users/sxross/rails/tastie_work/vendor/plugins/rspec_on_rails/ > lib/spec/rails.rb:11 > ... 11 levels... > from /Library/Ruby/Gems/1.8/gems/rspec-1.1.1/lib/spec/runner/ > example_group_runner.rb:13:in `load_files' > from /Library/Ruby/Gems/1.8/gems/rspec-1.1.1/lib/spec/runner/ > options.rb:83:in `run_examples' > from /Library/Ruby/Gems/1.8/gems/rspec-1.1.1/lib/spec/runner/ > command_line.rb:19:in `run' > from /Library/Ruby/Gems/1.8/gems/rspec-1.1.1/bin/spec:3 > > Anyone know what's up here? > > Thx > > --s > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From cwdinfo at gmail.com Fri Dec 28 22:02:59 2007 From: cwdinfo at gmail.com (s.ross) Date: Fri, 28 Dec 2007 19:02:59 -0800 Subject: [rspec-users] Converting to Rails 2.0.2 In-Reply-To: <60f3810c0712281708v6074e92aw51b7094191d4dbde@mail.gmail.com> References: <60f3810c0712281708v6074e92aw51b7094191d4dbde@mail.gmail.com> Message-ID: <693C133F-FCDE-4669-8218-1433A779B32E@gmail.com> How strange... I've been having some svn misbehavior so I decided to clone the tree and not do any plugin installations -- simply external references to the correct repos. So this is a today project and these are the externals from svn propedit: vendor/plugins/rspec http://rspec.rubyforge.org/svn/trunk/rspec vendor/plugins/rspec_on_rails http://rspec.rubyforge.org/svn/trunk/rspec_on_rails I'll keep looking into this to see why my installation would have gone so wrong. Thanks for the info... --s On Dec 28, 2007, at 5:08 PM, Kyle Hargraves wrote: > The REV constants no longer exist in trunk (and haven't for a while), > yet somehow your rspec_on_rails in vendor is still expecting it. > Meaning you don't actually have a copy of trunk in > plugins/rspec_on_rails, I guess. > > HTH > > Kyle > > On 12/28/07, s.ross wrote: >> I'm moving an older project to Rails 2.0.2 and ran into a roadblock >> on >> the version matching. Here's script/console session: >> >>>> Spec::VERSION::REV >> => "1785" >>>> Spec::Rails::VERSION::REV >> NoMethodError: undefined method `run=' for Test::Unit:Module >> from /Users/sxross/rails/tastie_work/vendor/plugins/rspec_on_rails/ >> lib/spec/rails.rb:16 >> from /Users/sxross/rails/tastie_work/vendor/rails/activerecord/ >> lib/../../activesupport/lib/active_support/dependencies.rb:203:in >> `load_without_new_constant_marking' >> from /Users/sxross/rails/tastie_work/vendor/rails/activerecord/ >> lib/../../activesupport/lib/active_support/dependencies.rb:203:in >> `load_file' >> from /Users/sxross/rails/tastie_work/vendor/rails/activerecord/ >> lib/../../activesupport/lib/active_support/dependencies.rb:342:in >> `new_constants_in' >> from /Users/sxross/rails/tastie_work/vendor/rails/activerecord/ >> lib/../../activesupport/lib/active_support/dependencies.rb:202:in >> `load_file' >> from /Users/sxross/rails/tastie_work/vendor/rails/activerecord/ >> lib/../../activesupport/lib/active_support/dependencies.rb:94:in >> `require_or_load' >> from /Users/sxross/rails/tastie_work/vendor/rails/activerecord/ >> lib/../../activesupport/lib/active_support/dependencies.rb:248:in >> `load_missing_constant' >> from /Users/sxross/rails/tastie_work/vendor/rails/activerecord/ >> lib/../../activesupport/lib/active_support/dependencies.rb:453:in >> `const_missing' >> >> The project uses trunk versions of rspec and rspec_on_rails, along >> with current Rails edge (at this point, 8506). After upgrading Rails >> and some of the normal monkeying around, I did a script/generate >> rspec >> (nothing of note there and replaced all just to be sure). Then: >> >> rake spec does this: >> >> Users/sxross/rails/tastie_work/vendor/rails/activerecord/lib/../../ >> activesupport/lib/active_support/dependencies.rb:263:in >> `load_missing_constant': uninitialized constant Spec::VERSION::REV >> (NameError) >> from /Users/sxross/rails/tastie_work/vendor/rails/activerecord/ >> lib/../../activesupport/lib/active_support/dependencies.rb:453:in >> `const_missing' >> from /Users/sxross/rails/tastie_work/vendor/plugins/rspec_on_rails/ >> lib/spec/rails/version.rb:13 >> from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:27:in >> `gem_original_require' >> from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:27:in >> `require' >> from /Users/sxross/rails/tastie_work/vendor/rails/activerecord/ >> lib/../../activesupport/lib/active_support/dependencies.rb:496:in >> `require' >> from /Users/sxross/rails/tastie_work/vendor/rails/activerecord/ >> lib/../../activesupport/lib/active_support/dependencies.rb:342:in >> `new_constants_in' >> from /Users/sxross/rails/tastie_work/vendor/rails/activerecord/ >> lib/../../activesupport/lib/active_support/dependencies.rb:496:in >> `require' >> from /Users/sxross/rails/tastie_work/vendor/plugins/rspec_on_rails/ >> lib/spec/rails.rb:11 >> ... 11 levels... >> from /Library/Ruby/Gems/1.8/gems/rspec-1.1.1/lib/spec/runner/ >> example_group_runner.rb:13:in `load_files' >> from /Library/Ruby/Gems/1.8/gems/rspec-1.1.1/lib/spec/runner/ >> options.rb:83:in `run_examples' >> from /Library/Ruby/Gems/1.8/gems/rspec-1.1.1/lib/spec/runner/ >> command_line.rb:19:in `run' >> from /Library/Ruby/Gems/1.8/gems/rspec-1.1.1/bin/spec:3 >> >> Anyone know what's up here? >> >> Thx >> >> --s >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.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 omen.king at gmail.com Sat Dec 29 02:00:25 2007 From: omen.king at gmail.com (Andrew WC Brown) Date: Sat, 29 Dec 2007 02:00:25 -0500 Subject: [rspec-users] Do you think it would look cleaner? Message-ID: I was looking over some of my specs. I was thinking that the following: @game.should_receive(:name).and_return('The Battle for Blaze') @game.should_receive(:people).and_return(5000000) @game.should_receive(:activated).and_return(true) Would it look cleaner if I could do this instead? @game.should_recieve_and_return( :name => 'The Battle for Blaze' :people => 5000000 :activated => true) Opinions? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071229/9ee68a8a/attachment.html From aslak.hellesoy at gmail.com Sat Dec 29 05:10:49 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Sat, 29 Dec 2007 11:10:49 +0100 Subject: [rspec-users] Converting to Rails 2.0.2 In-Reply-To: References: Message-ID: <8d961d900712290210q3e83c9ach8e1067bce8f89d2d@mail.gmail.com> On Dec 28, 2007 11:56 PM, s.ross wrote: > I'm moving an older project to Rails 2.0.2 and ran into a roadblock on > the version matching. Here's script/console session: > > >> Spec::VERSION::REV > => "1785" > >> Spec::Rails::VERSION::REV > NoMethodError: undefined method `run=' for Test::Unit:Module > from /Users/sxross/rails/tastie_work/vendor/plugins/rspec_on_rails/ > lib/spec/rails.rb:16 > from /Users/sxross/rails/tastie_work/vendor/rails/activerecord/ > lib/../../activesupport/lib/active_support/dependencies.rb:203:in > `load_without_new_constant_marking' > from /Users/sxross/rails/tastie_work/vendor/rails/activerecord/ > lib/../../activesupport/lib/active_support/dependencies.rb:203:in > `load_file' > from /Users/sxross/rails/tastie_work/vendor/rails/activerecord/ > lib/../../activesupport/lib/active_support/dependencies.rb:342:in > `new_constants_in' > from /Users/sxross/rails/tastie_work/vendor/rails/activerecord/ > lib/../../activesupport/lib/active_support/dependencies.rb:202:in > `load_file' > from /Users/sxross/rails/tastie_work/vendor/rails/activerecord/ > lib/../../activesupport/lib/active_support/dependencies.rb:94:in > `require_or_load' > from /Users/sxross/rails/tastie_work/vendor/rails/activerecord/ > lib/../../activesupport/lib/active_support/dependencies.rb:248:in > `load_missing_constant' > from /Users/sxross/rails/tastie_work/vendor/rails/activerecord/ > lib/../../activesupport/lib/active_support/dependencies.rb:453:in > `const_missing' > > The project uses trunk versions of rspec and rspec_on_rails, along > with current Rails edge (at this point, 8506). After upgrading Rails > and some of the normal monkeying around, I did a script/generate rspec > (nothing of note there and replaced all just to be sure). Then: > > rake spec does this: > > Users/sxross/rails/tastie_work/vendor/rails/activerecord/lib/../../ > activesupport/lib/active_support/dependencies.rb:263:in > `load_missing_constant': uninitialized constant Spec::VERSION::REV > (NameError) > from /Users/sxross/rails/tastie_work/vendor/rails/activerecord/ > lib/../../activesupport/lib/active_support/dependencies.rb:453:in > `const_missing' > from /Users/sxross/rails/tastie_work/vendor/plugins/rspec_on_rails/ > lib/spec/rails/version.rb:13 > from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:27:in > `gem_original_require' > from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:27:in `require' > from /Users/sxross/rails/tastie_work/vendor/rails/activerecord/ > lib/../../activesupport/lib/active_support/dependencies.rb:496:in > `require' > from /Users/sxross/rails/tastie_work/vendor/rails/activerecord/ > lib/../../activesupport/lib/active_support/dependencies.rb:342:in > `new_constants_in' > from /Users/sxross/rails/tastie_work/vendor/rails/activerecord/ > lib/../../activesupport/lib/active_support/dependencies.rb:496:in > `require' > from /Users/sxross/rails/tastie_work/vendor/plugins/rspec_on_rails/ > lib/spec/rails.rb:11 > ... 11 levels... > from /Library/Ruby/Gems/1.8/gems/rspec-1.1.1/lib/spec/runner/ > example_group_runner.rb:13:in `load_files' > from /Library/Ruby/Gems/1.8/gems/rspec-1.1.1/lib/spec/runner/ > options.rb:83:in `run_examples' > from /Library/Ruby/Gems/1.8/gems/rspec-1.1.1/lib/spec/runner/ > command_line.rb:19:in `run' > from /Library/Ruby/Gems/1.8/gems/rspec-1.1.1/bin/spec:3 The culprit is right here in your stack trace. You're running with a pre-trunk gem version of RSpec that isn't compatible with Spec::Rails trunk. Uninstall your existing RSpec gem. A more long term solution would be to make sure plugged-in rspec is always on $LOAD_PATH before the gemmed one, but that might be a little tricky. Aslak > > Anyone know what's up here? > > Thx > > --s > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Sat Dec 29 05:44:15 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 29 Dec 2007 08:44:15 -0200 Subject: [rspec-users] RSpec on Ruby 1.9: before(:all) (Not Yet Implemented) pending messages instead of tests In-Reply-To: <20071227181607.GI1277@durance.shot.pl> References: <20071227181607.GI1277@durance.shot.pl> Message-ID: <57c63afe0712290244p13fb9febp8e2e3fb1015edc9b@mail.gmail.com> On Dec 27, 2007 4:28 PM, Shot (Piotr Szotkowski) wrote: > Hi. > > I happily hand-compiled Ruby 1.9.0-0 into /home/shot/opt/ruby today > and I'm running into a strange error with RSpec ? all my examples work > perfectly with Ruby 1.8 but are considered peding on Ruby 1.9. > Pending: > ArtDecomp::Architecture before(:all) (Not Yet Implemented) > ArtDecomp::Architecture before(:all) (Not Yet Implemented) > ArtDecomp::Architecture before(:all) (Not Yet Implemented) > > Finished in 0.012114249 seconds > > 3 examples, 0 failures, 3 pending > > How can I bugtrack/fix this? RSpec's tracker can be found at http://rspec.lighthouseapp.com. The "Not Yet Implemented" issue you had is fixed in trunk now. > I had to patch RSpec in the below manner to get it running > on Ruby 1.9, but I doubt these fixes can be the culprit. > > --- lib/spec/runner/options.rb.orig 2007-12-27 16:36:03.000000000 +0100 > +++ lib/spec/runner/options.rb 2007-12-27 16:36:28.000000000 +0100 > @@ -102,7 +102,7 @@ > def colour=(colour) > @colour = colour > begin; \ > - require 'Win32/Console/ANSI' if @colour && PLATFORM =~ /win32/; \ > +# require 'Win32/Console/ANSI' if @colour && PLATFORM =~ /win32/; \ > rescue LoadError ; \ > raise "You must gem install win32console to use colour on Windows" ; \ > end > --- lib/spec/matchers/be.rb.orig 2007-12-27 16:30:51.000000000 +0100 > +++ lib/spec/matchers/be.rb 2007-12-27 16:32:14.000000000 +0100 > @@ -124,7 +124,8 @@ > def parse_expected(expected) > if Symbol === expected > @handling_predicate = true > - ["be_an_","be_a_","be_"].each do |@prefix| > + ["be_an_","be_a_","be_"].each do |at_prefix| > + @prefix = at_prefix > if expected.starts_with?(@prefix) > return "#{expected.to_s.sub(@prefix,"")}".to_sym > end > The change to be.rb has already been applied, but not the change to options.rb. I'm not sure I see any relationship between that and problems you might be experiencing with 1.9 (unless win32console does not yet support 1.9). Feel free to submit a ticket to the tracker on this one. Cheers, David From luislavena at gmail.com Sat Dec 29 10:49:28 2007 From: luislavena at gmail.com (Luis Lavena) Date: Sat, 29 Dec 2007 12:49:28 -0300 Subject: [rspec-users] RSpec on Ruby 1.9: before(:all) (Not Yet Implemented) pending messages instead of tests In-Reply-To: <57c63afe0712290244p13fb9febp8e2e3fb1015edc9b@mail.gmail.com> References: <20071227181607.GI1277@durance.shot.pl> <57c63afe0712290244p13fb9febp8e2e3fb1015edc9b@mail.gmail.com> Message-ID: <71166b3b0712290749p67595becx7f162fe6b8ce31c8@mail.gmail.com> On Dec 29, 2007 7:44 AM, David Chelimsky wrote: > On Dec 27, 2007 4:28 PM, Shot (Piotr Szotkowski) wrote: > > > I had to patch RSpec in the below manner to get it running > > on Ruby 1.9, but I doubt these fixes can be the culprit. > > > > --- lib/spec/runner/options.rb.orig 2007-12-27 16:36:03.000000000 +0100 > > +++ lib/spec/runner/options.rb 2007-12-27 16:36:28.000000000 +0100 > > @@ -102,7 +102,7 @@ > > def colour=(colour) > > @colour = colour > > begin; \ > > - require 'Win32/Console/ANSI' if @colour && PLATFORM =~ /win32/; \ > > +# require 'Win32/Console/ANSI' if @colour && PLATFORM =~ /win32/; \ > > rescue LoadError ; \ > > raise "You must gem install win32console to use colour on Windows" ; \ > > end > > --- lib/spec/matchers/be.rb.orig 2007-12-27 16:30:51.000000000 +0100 > > +++ lib/spec/matchers/be.rb 2007-12-27 16:32:14.000000000 +0100 > > @@ -124,7 +124,8 @@ > > def parse_expected(expected) > > if Symbol === expected > > @handling_predicate = true > > - ["be_an_","be_a_","be_"].each do |@prefix| > > + ["be_an_","be_a_","be_"].each do |at_prefix| > > + @prefix = at_prefix > > if expected.starts_with?(@prefix) > > return "#{expected.to_s.sub(@prefix,"")}".to_sym > > end > > > > The change to be.rb has already been applied, but not the change to > options.rb. I'm not sure I see any relationship between that and > problems you might be experiencing with 1.9 (unless win32console does > not yet support 1.9). Feel free to submit a ticket to the tracker on > this one. David, will not be better set @colour back to false if the require failed, instead of raising the exception? In that way, colour is automatically disabled, the user warned and when win32console gets updated for 1.9, all users will be happy :-D -- Luis Lavena Multimedia systems - A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools. Douglas Adams From lists at brynary.com Sat Dec 29 11:47:10 2007 From: lists at brynary.com (Bryan Helmkamp) Date: Sat, 29 Dec 2007 11:47:10 -0500 Subject: [rspec-users] ./script/story command Message-ID: Below I've pasted a ./script/story command I've been using for about a week. It has three modes of operation: 1. ./script/story with no arguments will run all *.story files in the story path 2. ./script/story with a path or glob will run the specified stories 3. If input is passed in via STDIN, it runs that text as a story. This opens up story running via a simple interface (Unix pipes) for integration with other tools. This deals with plain text stories only, and does NOT require an associated .rb runner file for them. Without Ruby runner code for the stories, the problem becomes figuring out what steps to use with a given plain text story file. The solution I put together is quite simple. I declare groups of step matchers in a separate directory, taking care to match the step group name to the file name. When a story file is run, if any steps match a part of the path, they are included. For example, my story in RAILS_ROOT/stories/scenarios/schedule_formatting/weekly.story will attempt to use the step groups "schedule_formatting" and "weekly" if they exist. For cases where that convention is not flexible enough, I added support for including a comment line in the .story file with instructions for which steps it should be run with. I think about this kind of like a she-bang line. So the first line of a .story file could be: # steps: navigations, more_steps And that will override the default behavior. I'm posting this because I hope it might be of immediate use to others using plain text stories right now, and also because I would like to consider possibilities for getting this functionality into RSpec core. WDYT? -- Bryan Helmkamp http://brynary.com -- My blog ----------------------------------------------- #!/usr/bin/env ruby class StoryCommand ROOT_PATH = File.expand_path(File.dirname(__FILE__) + "/..") STORIES_PATH = "#{ROOT_PATH}/stories/scenarios" STEP_MATCHERS_PATH = "#{ROOT_PATH}/stories/steps" HELPER_PATH = "#{ROOT_PATH}/stories/helper" def self.run self.new.run end def run if ARGV.empty? && first_char = using_stdin? setup_and_run_story((first_char + STDIN.read).split("\n")) elsif ARGV.empty? run_story_files(all_story_files) else run_story_files(ARGV) end end def all_story_files Dir["#{STORIES_PATH}/**/*.story"].uniq end def using_stdin? char = nil begin char = STDIN.read_nonblock(1) rescue Errno::EAGAIN return false end return char end def clean_story_paths(paths) paths.map! { |path| File.expand_path(path) } paths.map! { |path| path.gsub(/\.story$/, "") } paths.map! { |path| path.gsub(/#{STORIES_PATH}\//, "") } end def run_story_files(stories) clean_story_paths(stories).each do |story| setup_and_run_story(File.readlines("#{STORIES_PATH}/#{story}.story"), story) end end def setup_and_run_story(lines, story_name = nil) require HELPER_PATH steps = steps_for_story(lines, story_name) steps.reject! { |step| !File.exist?("#{STEP_MATCHERS_PATH}/#{step}.rb") } steps.each { |step| require "#{STEP_MATCHERS_PATH}/#{step}" } run_story(lines, steps) end def steps_for_story(lines, story_name) if lines.first =~ /^# steps: / lines.first.gsub(/^# steps: /, "").split(",").map(&:strip) else story_name.to_s.split("/") end end def run_story(lines, steps) tempfile = Tempfile.new("story") lines.each do |line| tempfile.puts line end tempfile.close with_steps_for(*steps.map(&:to_sym)) do run tempfile.path, :type => RailsStory end end end StoryCommand.run From pergesu at gmail.com Sat Dec 29 13:29:57 2007 From: pergesu at gmail.com (Pat Maddox) Date: Sat, 29 Dec 2007 10:29:57 -0800 Subject: [rspec-users] Do you think it would look cleaner? In-Reply-To: References: Message-ID: <810a540e0712291029u2d65aeb4va644764f6814715e@mail.gmail.com> On Dec 28, 2007 11:00 PM, Andrew WC Brown wrote: > I was looking over some of my specs. > I was thinking that the following: > > @game.should_receive(:name).and_return('The Battle for Blaze') > @game.should_receive(:people).and_return(5000000) > @game.should_receive (:activated).and_return(true) > > Would it look cleaner if I could do this instead? > > @game.should_recieve_and_return( > :name => 'The Battle for Blaze' > :people => 5000000 > :activated => true) > > Opinions? > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > Two thoughts as to why I wouldn't use this... 1. One expectation per example 2. Stub queries, expect commands Your way is clean though. How do you handle arguments? Pat From omen.king at gmail.com Sat Dec 29 15:00:09 2007 From: omen.king at gmail.com (Andrew WC Brown) Date: Sat, 29 Dec 2007 15:00:09 -0500 Subject: [rspec-users] Do you think it would look cleaner? In-Reply-To: <810a540e0712291029u2d65aeb4va644764f6814715e@mail.gmail.com> References: <810a540e0712291029u2d65aeb4va644764f6814715e@mail.gmail.com> Message-ID: eg. I'm going to the store to buy one milk I'm going to the store to buy one bagel I'm going to the store to buy one coffee @shopping_list.should_receive(:milk).once.and_return('milk') @shopping_list.should_receive(:bagel).once.and_return('bagel') @shopping_list.should_receive(:coffee).once.and_return('coffee') I going to the store to buy one: * milk * bagel * coffee @shopping_list.should_receive_the_following( :milk => 'milk' :bagel => 'bagel' :coffee => 'coffee' ).once For the shopping list I describe its expected that they all have the same expectations. I'm still reading the rspec source. I would think of creating a new method called: should_receive_the_following but seeing how the message_expectations work not sure how plausible it would be to implement. You wouldn't expect to return something: @shopping_list.should_receive_the_following( :milk => 'milk' :bagel => 'bagel' :coffee => 'coffee' ).once.and_return(@list) It boggles my mind. I haven't done too much meta programming. I just see these large blocks of: @shopping_list.should_receive(:milk)..and_return('milk') @shopping_list.should_receive(:bagel).and_return('bagel') @shopping_list.should_receive(:coffee).and_return('coffee') and it would be much clearer if I could list them in a hash instead. On Dec 29, 2007 1:29 PM, Pat Maddox wrote: > On Dec 28, 2007 11:00 PM, Andrew WC Brown wrote: > > I was looking over some of my specs. > > I was thinking that the following: > > > > @game.should_receive(:name).and_return('The Battle for Blaze') > > @game.should_receive(:people).and_return(5000000) > > @game.should_receive (:activated).and_return(true) > > > > Would it look cleaner if I could do this instead? > > > > @game.should_recieve_and_return( > > :name => 'The Battle for Blaze' > > :people => 5000000 > > :activated => true) > > > > Opinions? > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > Two thoughts as to why I wouldn't use this... > > 1. One expectation per example > 2. Stub queries, expect commands > > Your way is clean though. How do you handle arguments? > > Pat > _______________________________________________ > 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/20071229/71190359/attachment.html From gramos at rectorado.unl.edu.ar Sat Dec 29 10:44:31 2007 From: gramos at rectorado.unl.edu.ar (Gaston Ramos) Date: Sat, 29 Dec 2007 12:44:31 -0300 Subject: [rspec-users] Do you think it would look cleaner? In-Reply-To: References: Message-ID: <20071229154431.GA14970@marlasina> El s?b, 29 de dic de 2007, a las 02:00:25 -0500, Andrew WC Brown dijo: > I was looking over some of my specs. > I was thinking that the following: > > @game.should_receive(:name).and_return('The Battle for Blaze') > @game.should_receive(:people).and_return(5000000) > @game.should_receive(:activated).and_return(true) > > Would it look cleaner if I could do this instead? > > @game.should_recieve_and_return( > :name => 'The Battle for Blaze' > :people => 5000000 > :activated => true) > > Opinions? Hi Andrew, I think the first option is more clearer and more expresive than then 2nd. one. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -- Gast?n Ramos "I always thought Smalltalk would beat Java, I just didn't know it would be called 'Ruby' when it did." -- Kent Beck GNU/Linux Counter user #450312 http://gastonramos.wordpress.com/ No a la Matricula Obligatoria http://noalamatricula.wordpress.com/about/ From dchelimsky at gmail.com Sat Dec 29 16:14:12 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 29 Dec 2007 19:14:12 -0200 Subject: [rspec-users] Do you think it would look cleaner? In-Reply-To: References: <810a540e0712291029u2d65aeb4va644764f6814715e@mail.gmail.com> Message-ID: <57c63afe0712291314t9c2c796t9f02d2df10b6c5ca@mail.gmail.com> On Dec 29, 2007 6:00 PM, Andrew WC Brown wrote: > I just see these large blocks of: > > @shopping_list.should_receive(:milk)..and_return('milk') > @shopping_list.should_receive(:bagel).and_return('bagel') > @shopping_list.should_receive(:coffee).and_return('coffee') > > and it would be much clearer if I could list them in a hash instead. It would definitely be less typing, but I don't think it would be as clear in terms of intent. We do have a similar syntax to what you're looking for for stubs: list = stub("list", :milk => 'milk' ) This makes sense to me for stubs for a couple of reasons. One is that it is similar to the syntax for creating an OpenStruct, which should be familiar to any ruby developer. If we were to do the same with expectations we lose two things. Most importantly is the line number of the failure when one occurs. Also, and_return is already problematic for me after should_receive because it implies an expectation - it should receive this and it should return that, as opposed to it should receive this and when it does go ahead and return that so that the example can keep moving :) Combining these two concepts into one method name would make this even more confusing in my perception. There are other mock frameworks that might come closer to the terseness you desire. You should check out mocha and RR (http://rubypub.com/gem/rr-0.3.11/) if that's what you're looking for. They both offer a different "feel" from rspec's framework and some different features as well. HTH, David From dchelimsky at gmail.com Sat Dec 29 17:07:37 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 29 Dec 2007 20:07:37 -0200 Subject: [rspec-users] Mocks? Really? In-Reply-To: <85d99afe0712270613i2d221e35m6f9a34b8c7de4f04@mail.gmail.com> References: <139c56460712060856i6bb410fcl23def3b16c0388b4@mail.gmail.com> <57c63afe0712071840w13e8d2co85a60c00f3caefa9@mail.gmail.com> <810a540e0712142317t5e13f84dt2952986cd0a58a95@mail.gmail.com> <85d99afe0712231427k55bb3ed1x12e4dccf65cae2c6@mail.gmail.com> <810a540e0712261223u4a0f375bqa3f63f6a4711cb60@mail.gmail.com> <85d99afe0712270613i2d221e35m6f9a34b8c7de4f04@mail.gmail.com> Message-ID: <57c63afe0712291407h5eec4eajabb50f7b3c763e09@mail.gmail.com> Hi all - I've been keeping an eye on this thread and I've just been too busy with holiday travel and book writing to participate as I would like. I'm just going to lay out some thoughts in one fell swoop rather than going back through and finding all the quotes. Hope that works for you. First - "mock roles, not objects" - that comes from a paper of the same name written by Steve Freeman, Nat Pryce, Tim Mackinnon, Joe Walnes who I believe were all working for ThoughtWorks, London in 2004. They describe using mocks as part of a process to stay focused on one object at a time and let mock objects help you to discover the interfaces of the current object's collaborators. My read is that they do not make a distinction between domain objects and service objects, though they do make a distinction between "your" objects (which you should mock) and "everyone else's" (which you should not). My own approach is largely derived from this document, and I'd recommend that everyone participating in this thread give it a read: http://www.jmock.org/oopsla2004.pdf. I think one place that we tend to get stuck on, and this is true of TDD in general, not just mocks, is that mocks need not be a permanent part of any example. Before I encountered Rails it was common for me to use mocks in a test and then replace them with the mocked object later. This decision would depend on many factors, and I can't say that I sought to eliminate mocks when I could, but there were times when it just made more sense to use a real object once it came to be. Rails is a different beast because we don't really have a sense of 3 layers with lots of little objects in each. Instead we have what amount to 3 giant objects with lots of behavior in each and even shared state across layers. For me, this rationalizes isolating things with mocks and stubs (which is counter to the recommendation in the oopsla paper referenced above). Because the framework itself provides virtually no isolation, the spec suite must if you want isolation. Zach's idea of branch nodes and leaf nodes really speaks to me. I don't remember where I read this, but I long ago learned that an ideal OO operation consists of a chain of messages over any number of objects, culminating at a boundary object (what Zach is calling a leaf node). It should also favor commands over queries (Tell Don't Ask), so while all of the getters we get for free on our AR model objects is convenient, from an OO perspective it's a giant encapsulation-sieve (again, more reason to isolate things w/ stubs/mocks in tests). You might find http://www.holub.com/publications/notes_and_slides/Everything.You.Know.is.Wrong.pdf in regards to this. In this paper, Holub suggests that getters are evil and we should use importers and exporters instead of exposing getters/setters. If we were to re-engineer rails to satisfy this, instead of this in a controller: def index @model = Model.find(params[:id]) render :template => "some_template" end you might see something more like this: def index Model.export(params[:id]).to(some_template) end Here Model would still do a query, but it becomes internal to the Model (class) object. Then it passes some_template to the model and says "export yourself", at which point the model starts calling methods like name=self.name. The fact that the recipient of the export is a view is unknown to the model, so there is no conceptual binding between model and view. Ah, just think of how easy THAT would be to mock, and when things are easy to mock, it means that it is easy to swap out components in the chain of events, thus using run-time conditions to alter the path of a given operation through different objects. There is much, much more to say, but this is all I have time to contribute right now. Cheers, and Happy New Year to all! David From sera at fhwang.net Sat Dec 29 17:46:51 2007 From: sera at fhwang.net (Francis Hwang) Date: Sat, 29 Dec 2007 17:46:51 -0500 Subject: [rspec-users] Mocks? Really? In-Reply-To: <57c63afe0712291407h5eec4eajabb50f7b3c763e09@mail.gmail.com> References: <139c56460712060856i6bb410fcl23def3b16c0388b4@mail.gmail.com> <57c63afe0712071840w13e8d2co85a60c00f3caefa9@mail.gmail.com> <810a540e0712142317t5e13f84dt2952986cd0a58a95@mail.gmail.com> <85d99afe0712231427k55bb3ed1x12e4dccf65cae2c6@mail.gmail.com> <810a540e0712261223u4a0f375bqa3f63f6a4711cb60@mail.gmail.com> <85d99afe0712270613i2d221e35m6f9a34b8c7de4f04@mail.gmail.com> <57c63afe0712291407h5eec4eajabb50f7b3c763e09@mail.gmail.com> Message-ID: <8DD055F8-AFDD-4AC5-8258-C21F452C861D@fhwang.net> I don't know if anyone else will find this thought useful, but: I think different programmers have different situations, and they often force different sorts of priorities. I feel like a lot of the talk about mocking -- particularly as it hedges into discussions of modeling, design as part of the spec-writing process, LoD, etc -- implicitly assumes you want to spend a certain percentage of your work-week delineating a sensible class design for your application, and embedding those design ideas into your specs. At the risk of sounding like a cowboy coder I'd like to suggest that some situations actually call for more tolerance of chaos than others. I can think of a few forces that might imply this: - Team size. A bigger team means the code's design has to be more explicit, because of the limits of implicity knowledge team members can get from one another through everyday conversation, etc. - How quickly the business needs change. Designs for medical imaging software are likely to change less quickly than those of a consumer- facing website, which means you might have more or less time to tease out the forces that would lead you to an optimal design. In my case: I work in an small team (4 Rails programmers) making consumer-facing websites, so the team is small and the business needs can turn on a dime. From having been in such an environment for years, I feel like I've learned to write code that is just chaotic enough and yet still works. When I say "just chaotic enough", I mean not prematurely modeling problems I don't have the time to fully understand, but still giving the code enough structure and tests that 1) stupid bugs don't happen and 2) I can easily restructure the code when the time seems right. In such environment, mocking simply gets in my way. If I'm writing, say, a complex sequence of steps involving the posting of a form, various validations, an email getting sent, a link getting clicked, and changes being made in the database, I really don't want to also have to write a series of mocks delineating every underlying call those various controllers are making. At the time I'm writing the spec, I simply don't understand the problem well enough to write good lines about what should be mocked where. In a matter of hours or days I'll probably end up rewriting all of that stuff, and I'd rather not have it in my way. We talk about production code having a maintenance cost: Spec code has a maintenance cost as well. If I can get the same level of logical testing with specs and half the code, by leaving out mocking definitions, then that's what I'm going to do. As an analogy: I live in New York, and I've learned to have semi- compulsive cleaning habits from living in such small places. When you have a tiny room, you notice clutter much more. Then, a few years ago, I moved to a much bigger apartment (though "much bigger" is relative to NYC, of course). At first, I was cleaning just as much, but then I realized that I simply didn't need to. Now sometimes I just leave clutter around, on my bedside table or my kitchen counter. I don't need to spend all my life neatening up. And if I do lose something, I may not find it instantly, but I can spend a little while and look for it. It's got to be somewhere in my apartment, and the whole thing's not even that big. Francis Hwang http://fhwang.net/ From cwdinfo at gmail.com Sat Dec 29 17:55:49 2007 From: cwdinfo at gmail.com (s.ross) Date: Sat, 29 Dec 2007 14:55:49 -0800 Subject: [rspec-users] should send_email always succeeds? Message-ID: I wrote the following in my spec: emails = ActionMailer::Base.deliveries emails.length.should eql(2) response.should send_email { with_tag('tr', @contact_info[:full_name]) } knowing that 1) an email is being sent; and 2) the contact info is in a 'p' tag and only in a 'p' tag. The length expectation is met -- there are two emails. The send_email expectation is met, but should not be, as the correct tag would be a 'p' and not a 'tr'. Any thoughts as to why? Thx --s From zach.dennis at gmail.com Sun Dec 30 01:42:03 2007 From: zach.dennis at gmail.com (Zach Dennis) Date: Sun, 30 Dec 2007 01:42:03 -0500 Subject: [rspec-users] Mocks? Really? In-Reply-To: <8DD055F8-AFDD-4AC5-8258-C21F452C861D@fhwang.net> References: <139c56460712060856i6bb410fcl23def3b16c0388b4@mail.gmail.com> <57c63afe0712071840w13e8d2co85a60c00f3caefa9@mail.gmail.com> <810a540e0712142317t5e13f84dt2952986cd0a58a95@mail.gmail.com> <85d99afe0712231427k55bb3ed1x12e4dccf65cae2c6@mail.gmail.com> <810a540e0712261223u4a0f375bqa3f63f6a4711cb60@mail.gmail.com> <85d99afe0712270613i2d221e35m6f9a34b8c7de4f04@mail.gmail.com> <57c63afe0712291407h5eec4eajabb50f7b3c763e09@mail.gmail.com> <8DD055F8-AFDD-4AC5-8258-C21F452C861D@fhwang.net> Message-ID: <85d99afe0712292242mb85b02ata8df7087d5ad2ff3@mail.gmail.com> On Dec 29, 2007 5:46 PM, Francis Hwang wrote: > I don't know if anyone else will find this thought useful, but: > > > I think different programmers have different situations, and they > often force different sorts of priorities. I feel like a lot of the > talk about mocking -- particularly as it hedges into discussions of > modeling, design as part of the spec-writing process, LoD, etc -- > implicitly assumes you want to spend a certain percentage of your > work-week delineating a sensible class design for your application, > and embedding those design ideas into your specs. The fact is that you are going to spend time on designing, testing and implementing anyways. It is a natural part of software development. You cannot develop software without doing these things. The challenge is to do it in a way that better supports the initial development of a project as well as maintenance and continued development. > > At the risk of > sounding like a cowboy coder I'd like to suggest that some situations > actually call for more tolerance of chaos than others. > > > I can think of a few forces that might imply this: > > - Team size. A bigger team means the code's design has to be more > explicit, because of the limits of implicity knowledge team members > can get from one another through everyday conversation, etc. This argument doesn't pan out. First, it's highly unlikely that the same developers are on a project for the full lifetime of the project. Second, this fails to account for the negative impact of bad code and design. The negative impact includes the time it takes to understand the bad design, find/fix obscure bugs and to extend with new features or changing to existing ones. > - How quickly the business needs change. Designs for medical imaging > software are likely to change less quickly than those of a consumer- > facing website, which means you might have more or less time to tease > out the forces that would lead you to an optimal design. This doesn't pan out either. Business needs also change at infrequent intervals. Company mergers, new or updated policies, new or updated laws, the new CEO wanting something, etc are things that don't happen every day, but when they do happen it can have a big impact. The goal of good program design isn't to add unnecessary complexity which accounts for these. The goal of good program design is to develop a system that is simple, coherent and able to change to support the initial development of a project as well as maintenance and continued development. The ability to "change" is relative -- every program design can be changed. There are certain practices and disciplines that can allow for easier change though, change that reinforces the goal of good program design. The Law of Demeter is one of them. Simple objects with a single responsibility is another which reinforces the separation of concerns concept. Testing is another. The concept of an "optimal" design implies there is one magical design that will solve all potential issues. This puts people in the "design, then build" mindset -- the idea that if the design is perfect then all you have to do is build it. We know this is not correct. > In my case: I work in an small team (4 Rails programmers) making > consumer-facing websites, so the team is small and the business needs > can turn on a dime. From having been in such an environment for > years, I feel like I've learned to write code that is just chaotic > enough and yet still works. When I say "just chaotic enough", I mean > not prematurely modeling problems I don't have the time to fully > understand, but still giving the code enough structure and tests that > 1) stupid bugs don't happen and 2) I can easily restructure the code > when the time seems right. The challenge is to write code that is not chaotic, and to learn to do it in a way that allows the code to be more meaningful and that enhances your ability to develop software rather then hinder it. > In such environment, mocking simply gets in my way. If I'm writing, > say, a complex sequence of steps involving the posting of a form, > various validations, an email getting sent, a link getting clicked, > and changes being made in the database, I really don't want to also > have to write a series of mocks delineating every underlying call > those various controllers are making. At the time I'm writing the > spec, I simply don't understand the problem well enough to write good > lines about what should be mocked where. In a matter of hours or days > I'll probably end up rewriting all of that stuff, and I'd rather not > have it in my way. We talk about production code having a maintenance > cost: Spec code has a maintenance cost as well. If I can get the same > level of logical testing with specs and half the code, by leaving out > mocking definitions, then that's what I'm going to do. I think we should make a distinction. In my head when you need to write code and explore so you can understand what is needed in order to solve a problem I call that a "spike". I don't test spikes. They are an exploratory task which help me understand what I need to do. When I understand what I need to do I test drive my development. Now different rules apply for when you use mocks. In previous posts in this thread I pointed out that I tend to use a branch/leaf node object guideline to determine where I use mocks and when I don't. > As an analogy: I live in New York, and I've learned to have semi- > compulsive cleaning habits from living in such small places. When you > have a tiny room, you notice clutter much more. Then, a few years > ago, I moved to a much bigger apartment (though "much bigger" is > relative to NYC, of course). At first, I was cleaning just as much, > but then I realized that I simply didn't need to. Now sometimes I > just leave clutter around, on my bedside table or my kitchen counter. > I don't need to spend all my life neatening up. And if I do lose > something, I may not find it instantly, but I can spend a little > while and look for it. It's got to be somewhere in my apartment, and > the whole thing's not even that big. Two things about this bothers me. One, this implies that from the get-go it is ok to leave crap around an application code base. Two, this builds on the concept of a "optimal" design; by way of spending your life neatening up. I am going to rewrite your analogy in a way that changes the meaning as I read it, but hopefully conveys what you wanted to get across: " I do not want to spend the life of a project refactoring a code base to perfection for the sake of idealogical views on what code should be. I want to develop a running program for my customer. And where I find the ideals clashing with that goal I will abandon the ideals. Knowing this, parts of my application may be clutter or imperfect, but I am ok with this and so is my customer -- he/she has a running application. " If this is what you meant then I agree with you. The question is, are there things you can learn or discover which better support the goal of developing software for your customer, for the initial launch, as well as maintenance and ongoing development. If so, what are the ones that can be learned and how-to they apply? And for the times you discover be sure to share with the rest of us. =) Finally IMO mocking and interaction-based testing has a place in software development and when used properly it adds value to the software development process. -- Zach Dennis http://www.continuousthinking.com From zach.dennis at gmail.com Sun Dec 30 01:49:05 2007 From: zach.dennis at gmail.com (Zach Dennis) Date: Sun, 30 Dec 2007 01:49:05 -0500 Subject: [rspec-users] Do you think it would look cleaner? In-Reply-To: <810a540e0712291029u2d65aeb4va644764f6814715e@mail.gmail.com> References: <810a540e0712291029u2d65aeb4va644764f6814715e@mail.gmail.com> Message-ID: <85d99afe0712292249q1b28f68bh846c9ebc96505c64@mail.gmail.com> On Dec 29, 2007 1:29 PM, Pat Maddox wrote: > > On Dec 28, 2007 11:00 PM, Andrew WC Brown wrote: > > I was looking over some of my specs. > > I was thinking that the following: > > > > @game.should_receive(:name).and_return('The Battle for Blaze') > > @game.should_receive(:people).and_return(5000000) > > @game.should_receive (:activated).and_return(true) > > > > Would it look cleaner if I could do this instead? > > > > @game.should_recieve_and_return( > > :name => 'The Battle for Blaze' > > :people => 5000000 > > :activated => true) > > > > Opinions? I find this more confusing. When I first read it I thought it was going to receive the hash as arguments and return the hash. I think the expressiveness of "should_receive(...).and_return(...)" wins in this case, -- Zach Dennis http://www.continuousthinking.com From jftran at rubyfrance.org Sun Dec 30 03:52:04 2007 From: jftran at rubyfrance.org (=?ISO-8859-1?Q?Jean-Fran=E7ois_Tr=E2n?=) Date: Sun, 30 Dec 2007 09:52:04 +0100 Subject: [rspec-users] Do you think it would look cleaner? In-Reply-To: References: <810a540e0712291029u2d65aeb4va644764f6814715e@mail.gmail.com> Message-ID: <7f3720950712300052m4eadc21bx490e82f0224bc9f6@mail.gmail.com> 2007/12/29, Andrew WC Brown : > I just see these large blocks of: > > @shopping_list.should_receive(:milk)..and_return('milk') > @shopping_list.should_receive(:bagel).and_return('bagel') > @shopping_list.should_receive(:coffee).and_return('coffee') > > and it would be much clearer if I could list them in a hash instead. What about : { :milk => 'milk', :bagel => 'bagel', :coffee => 'coffee' }.each do |method, value| @shopping_list.should_receive(method).and_return(value) end So it doesn't need a #should_receive_the_following method. -- Jean-Fran?ois. From dchelimsky at gmail.com Sun Dec 30 07:04:39 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 30 Dec 2007 10:04:39 -0200 Subject: [rspec-users] Do you think it would look cleaner? In-Reply-To: <7f3720950712300052m4eadc21bx490e82f0224bc9f6@mail.gmail.com> References: <810a540e0712291029u2d65aeb4va644764f6814715e@mail.gmail.com> <7f3720950712300052m4eadc21bx490e82f0224bc9f6@mail.gmail.com> Message-ID: <57c63afe0712300404m3ab82bcclb2dd1d3e33271a4a@mail.gmail.com> On Dec 30, 2007 6:52 AM, Jean-Fran?ois Tr?n wrote: > 2007/12/29, Andrew WC Brown : > > > I just see these large blocks of: > > > > @shopping_list.should_receive(:milk)..and_return('milk') > > @shopping_list.should_receive(:bagel).and_return('bagel') > > @shopping_list.should_receive(:coffee).and_return('coffee') > > > > and it would be much clearer if I could list them in a hash instead. > > What about : > > { > :milk => 'milk', > :bagel => 'bagel', > :coffee => 'coffee' > }.each do |method, value| > @shopping_list.should_receive(method).and_return(value) > end > > So it doesn't need a #should_receive_the_following method. You can certainly do that (and I have), but again, you'd lose the benefit of a unique line number in the failure message. This is something that is often lost under the banner of DRY. DRY doesn't mean "type as few characters as you can." It means don't repeat functionality or knowledge within a system. IMO, multiple calls to the same methods, but with different data, are NOT duplication in this sense. From dchelimsky at gmail.com Sun Dec 30 07:12:26 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 30 Dec 2007 10:12:26 -0200 Subject: [rspec-users] Do you think it would look cleaner? In-Reply-To: <57c63afe0712300404m3ab82bcclb2dd1d3e33271a4a@mail.gmail.com> References: <810a540e0712291029u2d65aeb4va644764f6814715e@mail.gmail.com> <7f3720950712300052m4eadc21bx490e82f0224bc9f6@mail.gmail.com> <57c63afe0712300404m3ab82bcclb2dd1d3e33271a4a@mail.gmail.com> Message-ID: <57c63afe0712300412v2ceade81ncf7163635c959996@mail.gmail.com> On Dec 30, 2007 10:04 AM, David Chelimsky wrote: > On Dec 30, 2007 6:52 AM, Jean-Fran?ois Tr?n wrote: > > 2007/12/29, Andrew WC Brown : > > > > > I just see these large blocks of: > > > > > > @shopping_list.should_receive(:milk)..and_return('milk') > > > @shopping_list.should_receive(:bagel).and_return('bagel') > > > @shopping_list.should_receive(:coffee).and_return('coffee') > > > > > > and it would be much clearer if I could list them in a hash instead. > > > > What about : > > > > { > > :milk => 'milk', > > :bagel => 'bagel', > > :coffee => 'coffee' > > }.each do |method, value| > > @shopping_list.should_receive(method).and_return(value) > > end > > > > So it doesn't need a #should_receive_the_following method. > > You can certainly do that (and I have), but again, you'd lose the > benefit of a unique line number in the failure message. > > This is something that is often lost under the banner of DRY. DRY > doesn't mean "type as few characters as you can." It means don't > repeat functionality or knowledge within a system. IMO, multiple calls > to the same methods, but with different data, are NOT duplication in > this sense. (I hit send too soon) In the end, DRY exists to serve a higher master: maintainability. And it is not terribly rare that the illusion of DRY (as explored in this case) flies in the face of maintainability. In this case, the clarity of the line number in the event of a failure wins for me. Also, this is going to have to change when you decide that the shopping list should raise an error when it receives "bagel." Change is fine, but to make that change is going to be more work and likely leave things lopsided: { :milk => 'milk', :coffee => 'coffee' }.each do |method, value| @shopping_list.should_receive(method).and_return(value) end @shopping_list.should_receive(:bagel).and_raise(WeAreOutOfBagelsError) To me, that is simply not as clear as this: @shopping_list.should_receive(:milk).and_return('milk') @shopping_list.should_receive(:coffee).and_return('coffee') @shopping_list.should_receive(:bagel).and_raise(WeAreOutOfBagelsError) FWIW, David From lists-rspec at shopwatch.org Sun Dec 30 13:52:05 2007 From: lists-rspec at shopwatch.org (Jay Levitt) Date: Sun, 30 Dec 2007 13:52:05 -0500 Subject: [rspec-users] Mocks? Really? In-Reply-To: <8DD055F8-AFDD-4AC5-8258-C21F452C861D@fhwang.net> References: <139c56460712060856i6bb410fcl23def3b16c0388b4@mail.gmail.com> <57c63afe0712071840w13e8d2co85a60c00f3caefa9@mail.gmail.com> <810a540e0712142317t5e13f84dt2952986cd0a58a95@mail.gmail.com> <85d99afe0712231427k55bb3ed1x12e4dccf65cae2c6@mail.gmail.com> <810a540e0712261223u4a0f375bqa3f63f6a4711cb60@mail.gmail.com> <85d99afe0712270613i2d221e35m6f9a34b8c7de4f04@mail.gmail.com> <57c63afe0712291407h5eec4eajabb50f7b3c763e09@mail.gmail.com> <8DD055F8-AFDD-4AC5-8258-C21F452C861D@fhwang.net> Message-ID: <4777E8D5.4030907@shopwatch.org> On 12/29/2007 5:46 PM, Francis Hwang wrote: > - How quickly the business needs change. Designs for medical imaging > software are likely to change less quickly than those of a consumer- > facing website, which means you might have more or less time to tease > out the forces that would lead you to an optimal design. A few weeks ago, I ran across the following comment, explaining away 200 lines of copied-and-pasted internal structures in lieu of encapsulation, in what was once the world's largest consumer-facing web site: /* Yes, normally this would be */ /* incredibly dangerous ? but MainLoop is */ /* very unlikely to change now (spring '00) */ Careful about those assumptions. Jay Levitt From sera at fhwang.net Sun Dec 30 15:24:10 2007 From: sera at fhwang.net (Francis Hwang) Date: Sun, 30 Dec 2007 15:24:10 -0500 Subject: [rspec-users] Mocks? Really? In-Reply-To: <85d99afe0712292242mb85b02ata8df7087d5ad2ff3@mail.gmail.com> References: <139c56460712060856i6bb410fcl23def3b16c0388b4@mail.gmail.com> <57c63afe0712071840w13e8d2co85a60c00f3caefa9@mail.gmail.com> <810a540e0712142317t5e13f84dt2952986cd0a58a95@mail.gmail.com> <85d99afe0712231427k55bb3ed1x12e4dccf65cae2c6@mail.gmail.com> <810a540e0712261223u4a0f375bqa3f63f6a4711cb60@mail.gmail.com> <85d99afe0712270613i2d221e35m6f9a34b8c7de4f04@mail.gmail.com> <57c63afe0712291407h5eec4eajabb50f7b3c763e09@mail.gmail.com> <8DD055F8-AFDD-4AC5-8258-C21F452C861D@fhwang.net> <85d99afe0712292242mb85b02ata8df7087d5ad2ff3@mail.gmail.com> Message-ID: <2BD8093B-665B-46C9-961D-3378E6C3AC16@fhwang.net> On Dec 30, 2007, at 1:42 AM, Zach Dennis wrote: > On Dec 29, 2007 5:46 PM, Francis Hwang wrote: >> I don't know if anyone else will find this thought useful, but: >> >> >> I think different programmers have different situations, and they >> often force different sorts of priorities. I feel like a lot of the >> talk about mocking -- particularly as it hedges into discussions of >> modeling, design as part of the spec-writing process, LoD, etc -- >> implicitly assumes you want to spend a certain percentage of your >> work-week delineating a sensible class design for your application, >> and embedding those design ideas into your specs. > > The fact is that you are going to spend time on designing, testing and > implementing anyways. It is a natural part of software > development. You cannot develop software without doing these > things. The challenge is to do it in a way that better supports the > initial development of a project as well as maintenance and continued > development. I certainly didn't mean to imply that you shouldn't do any design or testing. If I had to guess at my coding style versus the average RSpec user, based on what's been said in this thread, I'd guess that I do about as much writing of tests/specs, and probably spend less time designing. But there is certainly such a thing as overdesigning, as well, right? I'm always trying to find the right amount, and I suspect that "the right amount" can vary somewhat in context. > >> >> At the risk of >> sounding like a cowboy coder I'd like to suggest that some situations >> actually call for more tolerance of chaos than others. >> >> >> I can think of a few forces that might imply this: >> >> - Team size. A bigger team means the code's design has to be more >> explicit, because of the limits of implicity knowledge team members >> can get from one another through everyday conversation, etc. > > This argument doesn't pan out. First, it's highly unlikely that > the same developers are on a project for the full lifetime of the > project. Second, this fails to account for the negative impact of bad > code and design. The negative impact includes the time it takes to > understand the bad design, find/fix obscure bugs and to extend with > new features or changing to existing ones. Again, I did not say "if you have a small team you don't have to do any design at all." I said that perhaps if you have a much smaller team you can spend a little less time on design, because implicit knowledge is much more effectively communicated. Are you disagreeing with this point? Are you saying that two software projects, one with four developers and the other with forty, will ideally spend the exact same percentage of time thinking about modeling, designing, etc.? >> - How quickly the business needs change. Designs for medical imaging >> software are likely to change less quickly than those of a consumer- >> facing website, which means you might have more or less time to tease >> out the forces that would lead you to an optimal design. > > This doesn't pan out either. Business needs also change at infrequent > intervals. Company mergers, new or updated policies, new or updated > laws, the new CEO wanting something, etc are things that don't happen > every day, but when they do happen it can have a big impact. The goal > of good program design isn't to add unnecessary complexity which > accounts for these. I wasn't saying that some businesses needs never change. The point I was trying to make is in that some sorts of businesses and companies, change happens more often, and can be expected to happen more often based on past experience. >> In my case: I work in an small team (4 Rails programmers) making >> consumer-facing websites, so the team is small and the business needs >> can turn on a dime. From having been in such an environment for >> years, I feel like I've learned to write code that is just chaotic >> enough and yet still works. When I say "just chaotic enough", I mean >> not prematurely modeling problems I don't have the time to fully >> understand, but still giving the code enough structure and tests that >> 1) stupid bugs don't happen and 2) I can easily restructure the code >> when the time seems right. > > The challenge is to write code that is not chaotic, and to learn to do > it in a way that allows the code to be more meaningful and that > enhances > your ability to develop software rather then hinder it. I wonder if part of the disconnect here depends on terminology. Some might see "chaos" as a negative term; I don't. There are plenty of highly chaotic, functional systems, both man-made and natural. Ecosystems, for example, are chaotic: They have an order that is implicit through the collective actions of all their agents. But that order is difficult to understand, since it's not really written down. I guess that's what I'm trying to express when applying the word "chaos" to code: It functions for now, but perhaps the way it works isn't as expressive as it could be for a newcomer coming to the code. Another thing I'd express is that I find a codebase to assymetrical, in terms of how much specification each individual piece needs. I find it surprising, for example, when people want to test their Rails views in isolation. I write plenty of tests when I'm working, but I try to have a sense of which pieces of code require a more full treatment. I'll extensively test code when the cost/benefit ratio makes sense to me, trying to think about factors such as: - how hard is it to write the test? - how hard is the code, and how many varied edge cases are there that I should write down? - are there unusual cases that I can think of now, that should be embodied in a test? >> In such environment, mocking simply gets in my way. If I'm writing, >> say, a complex sequence of steps involving the posting of a form, >> various validations, an email getting sent, a link getting clicked, >> and changes being made in the database, I really don't want to also >> have to write a series of mocks delineating every underlying call >> those various controllers are making. At the time I'm writing the >> spec, I simply don't understand the problem well enough to write good >> lines about what should be mocked where. In a matter of hours or days >> I'll probably end up rewriting all of that stuff, and I'd rather not >> have it in my way. We talk about production code having a maintenance >> cost: Spec code has a maintenance cost as well. If I can get the same >> level of logical testing with specs and half the code, by leaving out >> mocking definitions, then that's what I'm going to do. > > I think we should make a distinction. In my head when you need to > write code > and explore so you can understand what is needed in order to solve > a problem I > call that a "spike". > > I don't test spikes. They are an exploratory task which help me > understand what I need to do. When I understand what I need to do I > test drive my development. Now different rules apply for when you use > mocks. In previous posts in this thread I pointed out that I tend to > use a branch/leaf node object guideline to determine where I use mocks > and when I don't. My understanding of a spike is to write code that explores a problem that you aren't certain is solvable at all, given a certain set of constraints. That's not the lack of understanding I'm talking about: I'm more addressing code that I know is easily writeable, but there are a number of issues regarding application design that I haven't worked out yet. I'd rather write a test that encapsulates only the external touchpoints -- submit a form, receive an email, click on the link in the email -- and leave any deeper design decisions to a few minutes later, when I actually begin implementing that interaction. There's another kind of "not understanding" that's also relevant here: A "not understanding" due to the fact that you don't have all the relevant information, and you can't get it all now. For example: You release the very first iteration of a website feature on Monday, knowing full well that the feature's not completed. But the reason you release it is because on Wednesday you want to collect user data regarding this feature, which will help you and the company make business decisions about where the feature should go next. > >> As an analogy: I live in New York, and I've learned to have semi- >> compulsive cleaning habits from living in such small places. When you >> have a tiny room, you notice clutter much more. Then, a few years >> ago, I moved to a much bigger apartment (though "much bigger" is >> relative to NYC, of course). At first, I was cleaning just as much, >> but then I realized that I simply didn't need to. Now sometimes I >> just leave clutter around, on my bedside table or my kitchen counter. >> I don't need to spend all my life neatening up. And if I do lose >> something, I may not find it instantly, but I can spend a little >> while and look for it. It's got to be somewhere in my apartment, and >> the whole thing's not even that big. > > Two things about this bothers me. One, this implies that from the > get-go it is ok to leave crap around an application code base. Well, not to belabor the analogy, but: It's not "crap". If it's in my apartment, I own it for a reason. I may not use it all the time, it may not be the most important thing in my life, but apparently I need it once in a while or else I'd throw it away. I may not spend all my time trying to find the optimal place to put it, but that doesn't mean I don't value it. I just might value it less than other things in my apartment. > Two, > this builds on the concept of a "optimal" design; by way of > spending your life neatening up. > > I am going to rewrite your analogy in a way that changes the meaning > as I read it, but hopefully conveys what you wanted to get across: > " > I do not want to spend the life of a project refactoring a code base > to perfection for the sake of idealogical views on what code should > be. I want to develop a running > program for my customer. And where I find the ideals clashing with > that goal I will abandon the ideals. Knowing this, parts of my > application may be clutter or imperfect, but I am ok with this and so > is my customer -- he/she has a running application. > " That's probably close to what I'm trying to say. But in a broader, philosophical sense, I'm okay with the fact that my code is never going to be perfect. Not at this job, not at any other job. In fact I don't know if I've ever met anybody who gets to write perfect code. We write code in the real world, and the real world's far from perfect. I suppose Wabi Sabi comes into play here. To bring it back to mocks: It seems to that mocks might play a role in your specs if you were highly focused on the design and interaction of classes in isolation from all other classes, but understanding that isolation involves having done a decent amount of design work -- though more in some cases than in others. But if you were living with code that was more chaotic/amorphous/what-have-you, prematurely embedded such design assumptions into your specs might do more harm than good. I do, incidentally, use mocks extensively in a lot of code, but only in highly focused cases where simulating state of an external resource (filesystem, external login service) seems extremely important. Of course, that usage of mocks is very different from what's recommended as the default w/ RSpec. Francis Hwang http://fhwang.net/ From sera at fhwang.net Sun Dec 30 15:29:54 2007 From: sera at fhwang.net (Francis Hwang) Date: Sun, 30 Dec 2007 15:29:54 -0500 Subject: [rspec-users] Mocks? Really? In-Reply-To: <4777E8D5.4030907@shopwatch.org> References: <139c56460712060856i6bb410fcl23def3b16c0388b4@mail.gmail.com> <57c63afe0712071840w13e8d2co85a60c00f3caefa9@mail.gmail.com> <810a540e0712142317t5e13f84dt2952986cd0a58a95@mail.gmail.com> <85d99afe0712231427k55bb3ed1x12e4dccf65cae2c6@mail.gmail.com> <810a540e0712261223u4a0f375bqa3f63f6a4711cb60@mail.gmail.com> <85d99afe0712270613i2d221e35m6f9a34b8c7de4f04@mail.gmail.com> <57c63afe0712291407h5eec4eajabb50f7b3c763e09@mail.gmail.com> <8DD055F8-AFDD-4AC5-8258-C21F452C861D@fhwang.net> <4777E8D5.4030907@shopwatch.org> Message-ID: <66AFA127-0223-444F-A4CA-7E31253182CC@fhwang.net> On Dec 30, 2007, at 1:52 PM, Jay Levitt wrote: > On 12/29/2007 5:46 PM, Francis Hwang wrote: > >> - How quickly the business needs change. Designs for medical imaging >> software are likely to change less quickly than those of a consumer- >> facing website, which means you might have more or less time to tease >> out the forces that would lead you to an optimal design. > > A few weeks ago, I ran across the following comment, explaining > away 200 > lines of copied-and-pasted internal structures in lieu of > encapsulation, > in what was once the world's largest consumer-facing web site: > > /* Yes, normally this would be */ > /* incredibly dangerous ? but MainLoop is */ > /* very unlikely to change now (spring '00) */ > > Careful about those assumptions. Yeah, well, there's a difference between chaotic code and foolish code. Regardless of what company I was working at, pretty much any code that would probably break a few years out would be a problem. Of course, you can't predict with 100% accuracy which parts of the code are likely to change and which are likely to go untouched for years. I think you can make educated guesses, though. Incidentally, how well-tested was that code base? 200 lines of copy- and-paste smells like untested code to me. Francis Hwang http://fhwang.net/ From lists-rspec at shopwatch.org Sun Dec 30 21:38:20 2007 From: lists-rspec at shopwatch.org (Jay Levitt) Date: Sun, 30 Dec 2007 21:38:20 -0500 Subject: [rspec-users] Mocks? Really? In-Reply-To: <66AFA127-0223-444F-A4CA-7E31253182CC@fhwang.net> References: <139c56460712060856i6bb410fcl23def3b16c0388b4@mail.gmail.com> <57c63afe0712071840w13e8d2co85a60c00f3caefa9@mail.gmail.com> <810a540e0712142317t5e13f84dt2952986cd0a58a95@mail.gmail.com> <85d99afe0712231427k55bb3ed1x12e4dccf65cae2c6@mail.gmail.com> <810a540e0712261223u4a0f375bqa3f63f6a4711cb60@mail.gmail.com> <85d99afe0712270613i2d221e35m6f9a34b8c7de4f04@mail.gmail.com> <57c63afe0712291407h5eec4eajabb50f7b3c763e09@mail.gmail.com> <8DD055F8-AFDD-4AC5-8258-C21F452C861D@fhwang.net> <4777E8D5.4030907@shopwatch.org> <66AFA127-0223-444F-A4CA-7E31253182CC@fhwang.net> Message-ID: <4778561C.7030608@shopwatch.org> On 12/30/2007 3:29 PM, Francis Hwang wrote: > On Dec 30, 2007, at 1:52 PM, Jay Levitt wrote: > >> On 12/29/2007 5:46 PM, Francis Hwang wrote: >> >>> - How quickly the business needs change. Designs for medical imaging >>> software are likely to change less quickly than those of a consumer- >>> facing website, which means you might have more or less time to tease >>> out the forces that would lead you to an optimal design. >> A few weeks ago, I ran across the following comment, explaining >> away 200 >> lines of copied-and-pasted internal structures in lieu of >> encapsulation, >> in what was once the world's largest consumer-facing web site: >> >> /* Yes, normally this would be */ >> /* incredibly dangerous ? but MainLoop is */ >> /* very unlikely to change now (spring '00) */ >> >> Careful about those assumptions. > > Yeah, well, there's a difference between chaotic code and foolish > code. Regardless of what company I was working at, pretty much any > code that would probably break a few years out would be a problem. > > Of course, you can't predict with 100% accuracy which parts of the > code are likely to change and which are likely to go untouched for > years. I think you can make educated guesses, though. You can, and we did... turns out they weren't. (OK, I'm exaggerating. Most of them were, and the only guesses I'm finding now are the wrong guesses, by definition. And the world's changed a lot, and we know more and can do more.) > Incidentally, how well-tested was that code base? 200 lines of copy- > and-paste smells like untested code to me. 15-20 years ago, unit tests were not a widespread industry practice :) This code's in a procedural language that really, really doesn't do unit tests well. I've been trying, too. Almost wrote a pre-processor, till I thought about the maintenance nightmare that'd cause. Jay Levitt From lists-rspec at shopwatch.org Sun Dec 30 21:43:08 2007 From: lists-rspec at shopwatch.org (Jay Levitt) Date: Sun, 30 Dec 2007 21:43:08 -0500 Subject: [rspec-users] Mocks? Really? In-Reply-To: <85d99afe0712292242mb85b02ata8df7087d5ad2ff3@mail.gmail.com> References: <139c56460712060856i6bb410fcl23def3b16c0388b4@mail.gmail.com> <57c63afe0712071840w13e8d2co85a60c00f3caefa9@mail.gmail.com> <810a540e0712142317t5e13f84dt2952986cd0a58a95@mail.gmail.com> <85d99afe0712231427k55bb3ed1x12e4dccf65cae2c6@mail.gmail.com> <810a540e0712261223u4a0f375bqa3f63f6a4711cb60@mail.gmail.com> <85d99afe0712270613i2d221e35m6f9a34b8c7de4f04@mail.gmail.com> <57c63afe0712291407h5eec4eajabb50f7b3c763e09@mail.gmail.com> <8DD055F8-AFDD-4AC5-8258-C21F452C861D@fhwang.net> <85d99afe0712292242mb85b02ata8df7087d5ad2ff3@mail.gmail.com> Message-ID: <4778573C.1040108@shopwatch.org> On 12/30/2007 1:42 AM, Zach Dennis wrote: > I think we should make a distinction. In my head when you need to write code > and explore so you can understand what is needed in order to solve a problem I > call that a "spike". That's great; I've been needing a term for exactly that and never saw this word used. > On Dec 29, 2007 5:46 PM, Francis Hwang wrote: >> At first, I was cleaning just as much, >> but then I realized that I simply didn't need to. Now sometimes I >> just leave clutter around, on my bedside table or my kitchen counter. I'm having the opposite problem. I moved from a huge house (that I specifically designed to always look clean) to a good-sized apartment, and discovered I'm a disgusting, unsanitary slob. (I have no idea how this relates to RSpec. I just wanted to share.) Jay Levitt From sera at fhwang.net Sun Dec 30 22:09:31 2007 From: sera at fhwang.net (Francis Hwang) Date: Sun, 30 Dec 2007 22:09:31 -0500 Subject: [rspec-users] Mocks? Really? In-Reply-To: <4778561C.7030608@shopwatch.org> References: <139c56460712060856i6bb410fcl23def3b16c0388b4@mail.gmail.com> <57c63afe0712071840w13e8d2co85a60c00f3caefa9@mail.gmail.com> <810a540e0712142317t5e13f84dt2952986cd0a58a95@mail.gmail.com> <85d99afe0712231427k55bb3ed1x12e4dccf65cae2c6@mail.gmail.com> <810a540e0712261223u4a0f375bqa3f63f6a4711cb60@mail.gmail.com> <85d99afe0712270613i2d221e35m6f9a34b8c7de4f04@mail.gmail.com> <57c63afe0712291407h5eec4eajabb50f7b3c763e09@mail.gmail.com> <8DD055F8-AFDD-4AC5-8258-C21F452C861D@fhwang.net> <4777E8D5.4030907@shopwatch.org> <66AFA127-0223-444F-A4CA-7E31253182CC@fhwang.net> <4778561C.7030608@shopwatch.org> Message-ID: <02ED17FC-3B18-4DBF-A9E9-A063AC49024C@fhwang.net> On Dec 30, 2007, at 9:38 PM, Jay Levitt wrote: >>> Incidentally, how well-tested was that code base? 200 lines of copy- >> and-paste smells like untested code to me. > > 15-20 years ago, unit tests were not a widespread industry practice :) > This code's in a procedural language that really, really doesn't do > unit tests well. I've been trying, too. Almost wrote a pre- > processor, > till I thought about the maintenance nightmare that'd cause. Right, that's why I ask. I think working with languages, tools, and frameworks that are easier to test is a great advantage to how we all worked 10 or more years ago ... I suspect part of that luxury translates in being able to actually design _less_, since the cost of fixing our design mistakes in the future goes down significantly. Francis Hwang http://fhwang.net/ From pluskid at gmail.com Mon Dec 31 05:55:56 2007 From: pluskid at gmail.com (Chiyuan Zhang) Date: Mon, 31 Dec 2007 18:55:56 +0800 Subject: [rspec-users] How to run stories with `spec' command? Message-ID: Hi, all! I have a story steps array.rb and the story array.story. I can run it with ruby array.rb But when I execute spec array.rb nothing happened. I'm wondering how can I use spec command to execute stories? (executing examples is OK) Or maybe another question. If I have to run stories with `ruby' command, how can I choose the output format? (I think there's only plain text and HTML for stories currently) Any idea? Thanks. ps: Here's my stories ============ array.rb ============ require 'spec/story' steps_for(:array) do Given("my state initialized") do @array = Array.new end When("$elem added to me") do |elem| @array << elem end Then("my size should be $size") do |size| @array.size.should == size.to_i end end # if __FILE__ == $0 with_steps_for :array do run __FILE__.gsub(/\.rb$/, '.story') end # end =========== array.story =========== Story: array for holding objects As an array for holding objects I can hold a bunch of objects So that they can be retrieved later Scenario: an empty array Given my state initialized Then my size should be 0 Scenario: an array with only 1 element Given my state initialized When 1 added to me Then my size should be 1 From aslak.hellesoy at gmail.com Mon Dec 31 08:19:46 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Mon, 31 Dec 2007 14:19:46 +0100 Subject: [rspec-users] How to run stories with `spec' command? In-Reply-To: References: Message-ID: <8d961d900712310519p46b898f7pcfd81f35e1719347@mail.gmail.com> On Dec 31, 2007 11:55 AM, Chiyuan Zhang wrote: > Hi, all! > > I have a story steps array.rb and the story array.story. I > can run it with > > ruby array.rb > > But when I execute > > spec array.rb > > nothing happened. I'm wondering how can I use spec command to > execute stories? You can't. The spec command is only for examples. Aslak > (executing examples is OK) Or maybe another > question. If I have to run stories with `ruby' command, how > can I choose the output format? (I think there's only plain text > and HTML for stories currently) Any idea? Thanks. > > ps: Here's my stories > > ============ > array.rb > ============ > require 'spec/story' > > steps_for(:array) do > Given("my state initialized") do > @array = Array.new > end > When("$elem added to me") do |elem| > @array << elem > end > Then("my size should be $size") do |size| > @array.size.should == size.to_i > end > end > > # if __FILE__ == $0 > with_steps_for :array do > run __FILE__.gsub(/\.rb$/, '.story') > end > # end > > =========== > array.story > =========== > Story: array for holding objects > As an array for holding objects > I can hold a bunch of objects > So that they can be retrieved later > > Scenario: an empty array > Given my state initialized > Then my size should be 0 > > Scenario: an array with only 1 element > Given my state initialized > When 1 added to me > Then my size should be 1 > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Mon Dec 31 11:49:34 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Mon, 31 Dec 2007 11:49:34 -0500 Subject: [rspec-users] Mocks? Really? In-Reply-To: <8DD055F8-AFDD-4AC5-8258-C21F452C861D@fhwang.net> References: <139c56460712060856i6bb410fcl23def3b16c0388b4@mail.gmail.com> <57c63afe0712071840w13e8d2co85a60c00f3caefa9@mail.gmail.com> <810a540e0712142317t5e13f84dt2952986cd0a58a95@mail.gmail.com> <85d99afe0712231427k55bb3ed1x12e4dccf65cae2c6@mail.gmail.com> <810a540e0712261223u4a0f375bqa3f63f6a4711cb60@mail.gmail.com> <85d99afe0712270613i2d221e35m6f9a34b8c7de4f04@mail.gmail.com> <57c63afe0712291407h5eec4eajabb50f7b3c763e09@mail.gmail.com> <8DD055F8-AFDD-4AC5-8258-C21F452C861D@fhwang.net> Message-ID: <9D93C3A3-2742-477E-9239-CCD9279FE552@railsnewbie.com> On Dec 29, 2007, at 5:46 PM, Francis Hwang wrote: > I don't know if anyone else will find this thought useful, but: > > I think different programmers have different situations, and they > often force different sorts of priorities. I feel like a lot of the > talk about mocking -- particularly as it hedges into discussions of > modeling, design as part of the spec-writing process, LoD, etc -- > implicitly assumes you want to spend a certain percentage of your > work-week delineating a sensible class design for your application, > and embedding those design ideas into your specs. At the risk of > sounding like a cowboy coder I'd like to suggest that some situations > actually call for more tolerance of chaos than others. > > I can think of a few forces that might imply this: > > - Team size. A bigger team means the code's design has to be more > explicit, because of the limits of implicity knowledge team members > can get from one another through everyday conversation, etc. > - How quickly the business needs change. Designs for medical imaging > software are likely to change less quickly than those of a consumer- > facing website, which means you might have more or less time to tease > out the forces that would lead you to an optimal design. +1 - This helps my thought out a lot. Thanks for the contributions, as always (this has been a great thread - from everyone involved). Scott From rick.denatale at gmail.com Mon Dec 31 12:53:21 2007 From: rick.denatale at gmail.com (Rick DeNatale) Date: Mon, 31 Dec 2007 12:53:21 -0500 Subject: [rspec-users] Mocks? Really? In-Reply-To: <02ED17FC-3B18-4DBF-A9E9-A063AC49024C@fhwang.net> References: <139c56460712060856i6bb410fcl23def3b16c0388b4@mail.gmail.com> <85d99afe0712231427k55bb3ed1x12e4dccf65cae2c6@mail.gmail.com> <810a540e0712261223u4a0f375bqa3f63f6a4711cb60@mail.gmail.com> <85d99afe0712270613i2d221e35m6f9a34b8c7de4f04@mail.gmail.com> <57c63afe0712291407h5eec4eajabb50f7b3c763e09@mail.gmail.com> <8DD055F8-AFDD-4AC5-8258-C21F452C861D@fhwang.net> <4777E8D5.4030907@shopwatch.org> <66AFA127-0223-444F-A4CA-7E31253182CC@fhwang.net> <4778561C.7030608@shopwatch.org> <02ED17FC-3B18-4DBF-A9E9-A063AC49024C@fhwang.net> Message-ID: On Dec 30, 2007 10:09 PM, Francis Hwang wrote: > On Dec 30, 2007, at 9:38 PM, Jay Levitt wrote: > > >>> Incidentally, how well-tested was that code base? 200 lines of copy- > >> and-paste smells like untested code to me. > > > > 15-20 years ago, unit tests were not a widespread industry practice :) > > This code's in a procedural language that really, really doesn't do > > unit tests well. I've been trying, too. Almost wrote a pre- > > processor, > > till I thought about the maintenance nightmare that'd cause. > > Right, that's why I ask. I think working with languages, tools, and > frameworks that are easier to test is a great advantage to how we all > worked 10 or more years ago ... I suspect part of that luxury > translates in being able to actually design _less_, since the cost of > fixing our design mistakes in the future goes down significantly. I don't think of it as designing less. (B/T)DD means designing incrementally. I read recently something where someone made a distinction between invention and discovery. Rather than sitting down 'ahead of time' and inventing a design, you can discover the design as you go. The tests/specs become the design documentation themselves, and can evolve as requirements change or are refined as the process continues. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From rspec-users at kero.tmfweb.nl Mon Dec 31 12:54:00 2007 From: rspec-users at kero.tmfweb.nl (Kero van Gelder) Date: Mon, 31 Dec 2007 17:54:00 +0000 Subject: [rspec-users] executing code after each step of a story In-Reply-To: <57c63afe0712261348l31537bd2m96eb343b9ed1a14f@mail.gmail.com> References: <4a117bfc0712261338y789f13a4p35f6b9546d3a7905@mail.gmail.com> <57c63afe0712261348l31537bd2m96eb343b9ed1a14f@mail.gmail.com> Message-ID: <20071231175359.GB24657@chello.nl> Hi! After a bit of digging in runners, I found that I need a formatter, really. now --format FORMAT:WHERE is explained properly by --help. --runner otoh, is not; see below. For the purpose of recording a user story (demo, webdemo), I run espeak for each step and then some. It seems to me, a formatter is the correct thing to use for this, but it demands a WHERE parameter that I am not going to use, as such (I need to store audio snippets and combine with screenshots into video; grabbing screens is not formatting anymore; a listener would be better, see below). Would it be an idea to not stop executing when I specify "-f Speaker:" which indicates I know I would need the WHERE, but actually don't? But worse, when I specify -f p -c -f Speaker, I get my speaker to speak *before* the coloured text is printed. This is not nice for a live demo, since the customer can not read along. When I specify -f Speaker -f p -c, I get my speaker to get one step ahead of the normal formatter (it speaks, it speaks, the prints, speaks, prints and prints). I am confused as to why that happens. > > how can I execute some code after each step of a story. Is there some > > kind of listener documentated. > > Very little is documented, and Story Runner is still considered > experimental (i.e. API's subject to change), but here is what you can > do with the 1.1.1 release: > > World.add_listener(mylistener) Found that before. Together with - Spec::Story::Runner::ScenarioRunner#add_listener - Spec::Story::Runner::StoryRunner#add_listener This is at least inconsistent; where is the StepRunner? "World" really seems too generic a name. Also, a formatter, though it hooks into similar things, is not a listener. What's the relation? If I do not know the relation, I can never decide what the appropriate time is to make a screenshot. And why, when I specify --runner Spec::Story::Runner::StoryRunner or --runner Spec::Story::Runner::ScenarioRunner do things break? (or, perhaps, what is a custom runner supposed to run?) I need to mess with my own runner when I want to see gtk things happening on screen (which would be even cooler for demoes). This is the reason I started messing with runners and only noticed the formatters much later... I succeeded in that, though it is not pretty (have to call exit myself), is there any way to disable the at_exit registered stuff? to be clear, I have Ruby code like require 'spec' Story { Scenario { When {} Then {} } } and run it with `ruby that_code.rb` (whereas `spec that_code.rb` is very silent; a warning would be nice) I'll post some videos and code when I'm really done :) Bye, Kero. From zach.dennis at gmail.com Mon Dec 31 13:10:29 2007 From: zach.dennis at gmail.com (Zach Dennis) Date: Mon, 31 Dec 2007 13:10:29 -0500 Subject: [rspec-users] Mocks? Really? In-Reply-To: References: <139c56460712060856i6bb410fcl23def3b16c0388b4@mail.gmail.com> <810a540e0712261223u4a0f375bqa3f63f6a4711cb60@mail.gmail.com> <85d99afe0712270613i2d221e35m6f9a34b8c7de4f04@mail.gmail.com> <57c63afe0712291407h5eec4eajabb50f7b3c763e09@mail.gmail.com> <8DD055F8-AFDD-4AC5-8258-C21F452C861D@fhwang.net> <4777E8D5.4030907@shopwatch.org> <66AFA127-0223-444F-A4CA-7E31253182CC@fhwang.net> <4778561C.7030608@shopwatch.org> <02ED17FC-3B18-4DBF-A9E9-A063AC49024C@fhwang.net> Message-ID: <85d99afe0712311010h5f95a862oa82789b4df59ae5c@mail.gmail.com> On Dec 31, 2007 12:53 PM, Rick DeNatale wrote: > On Dec 30, 2007 10:09 PM, Francis Hwang wrote: > > On Dec 30, 2007, at 9:38 PM, Jay Levitt wrote: > > > > >>> Incidentally, how well-tested was that code base? 200 lines of copy- > > >> and-paste smells like untested code to me. > > > > > > 15-20 years ago, unit tests were not a widespread industry practice :) > > > This code's in a procedural language that really, really doesn't do > > > unit tests well. I've been trying, too. Almost wrote a pre- > > > processor, > > > till I thought about the maintenance nightmare that'd cause. > > > > Right, that's why I ask. I think working with languages, tools, and > > frameworks that are easier to test is a great advantage to how we all > > worked 10 or more years ago ... I suspect part of that luxury > > translates in being able to actually design _less_, since the cost of > > fixing our design mistakes in the future goes down significantly. > > I don't think of it as designing less. (B/T)DD means designing > incrementally. I read recently something where someone made a > distinction between invention and discovery. Rather than sitting down > 'ahead of time' and inventing a design, you can discover the design as > you go. I don't think it is "designing less" either. It's designing better and doing it smarter, knowing that you'll never fully comprehend the domain of your problem upfront, so you discover it, iteratively. As you discover more about the domain the design of your program changes (during refactoring) to support a domain model to which it is representing. This is a concept from Domain Driven Design. It Francis is referring to doing less upfront design to try to master it all from the outset, then I agree that less of that is better. But that is entirely different then just doing less design. -- Zach Dennis http://www.continuousthinking.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071231/bde7b0d9/attachment.html From bryan at osesm.com Mon Dec 31 18:44:15 2007 From: bryan at osesm.com (Bryan Liles) Date: Mon, 31 Dec 2007 18:44:15 -0500 Subject: [rspec-users] How to run stories with `spec' command? In-Reply-To: References: Message-ID: <00360231-66F2-4DB7-A944-EF7612AA0A87@osesm.com> On Dec 31, 2007, at 5:55 AM, Chiyuan Zhang wrote: > Hi, all! > > I have a story steps array.rb and the story array.story. I > can run it with > > ruby array.rb > > But when I execute > > spec array.rb > > nothing happened. I'm wondering how can I use spec command to > execute stories? (executing examples is OK) Or maybe another > question. If I have to run stories with `ruby' command, how > can I choose the output format? (I think there's only plain text > and HTML for stories currently) Any idea? Thanks. > Here is something I'm playing around with: http://smartic.us/2007/12/22/smarticus-rspec-stories-on-rails Plus Bryan Helkamp mentioned something as well a couple of days ago. Good luck! From pluskid at gmail.com Mon Dec 31 21:22:51 2007 From: pluskid at gmail.com (Chiyuan Zhang) Date: Tue, 1 Jan 2008 10:22:51 +0800 Subject: [rspec-users] How to run stories with `spec' command? In-Reply-To: <00360231-66F2-4DB7-A944-EF7612AA0A87@osesm.com> References: <00360231-66F2-4DB7-A944-EF7612AA0A87@osesm.com> Message-ID: Hmm, Thanks for your suggestion. I suppose the document of stories for rspec is not complete yet? Maybe the file layout suggestion could be included in the document. ps: Happy New Year to all! 2008/1/1, Bryan Liles : > > On Dec 31, 2007, at 5:55 AM, Chiyuan Zhang wrote: > > > Hi, all! > > > > I have a story steps array.rb and the story array.story. I > > can run it with > > > > ruby array.rb > > > > But when I execute > > > > spec array.rb > > > > nothing happened. I'm wondering how can I use spec command to > > execute stories? (executing examples is OK) Or maybe another > > question. If I have to run stories with `ruby' command, how > > can I choose the output format? (I think there's only plain text > > and HTML for stories currently) Any idea? Thanks. > > > > Here is something I'm playing around with: > > http://smartic.us/2007/12/22/smarticus-rspec-stories-on-rails > > Plus Bryan Helkamp mentioned something as well a couple of days ago. > > Good luck! > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From kero at chello.nl Sun Dec 30 04:47:26 2007 From: kero at chello.nl (Kero van Gelder) Date: Sun, 30 Dec 2007 09:47:26 +0000 Subject: [rspec-users] Do you think it would look cleaner? In-Reply-To: References: Message-ID: <20071230094725.GA24657@chello.nl> > I was looking over some of my specs. > I was thinking that the following: > > @game.should_receive(:name).and_return('The Battle for Blaze') > @game.should_receive(:people).and_return(5000000) > @game.should_receive(:activated).and_return(true) > > Would it look cleaner if I could do this instead? > > @game.should_recieve_and_return( > :name => 'The Battle for Blaze' > :people => 5000000 > :activated => true) > > Opinions? A Hash is not ordered. (but the 1st set of statements is) Bye, Kero.