From dbatshaw at gmail.com Mon Mar 1 15:32:35 2010 From: dbatshaw at gmail.com (drewB) Date: Mon, 1 Mar 2010 12:32:35 -0800 (PST) Subject: [rspec-users] Integration testing without cucumber Message-ID: <968ea143-57a0-4c04-bc52-5f67e8504b8d@q16g2000yqq.googlegroups.com> I need to create some integration tests without cucumber. Can anyone point me in the right direction for how to do that in rails? I tried creating specs under 'spec/integration/' but no matchers are being included. I also tried rspec_integration plugin (http://github.com/ tricycle/rspec-integration) but that only defines a few matchers and response.should be_success doesn't work properly. Any help you can provide would be much appreciated! From joe at josephwilk.net Mon Mar 1 16:27:39 2010 From: joe at josephwilk.net (Joseph Wilk) Date: Mon, 01 Mar 2010 21:27:39 +0000 Subject: [rspec-users] Integration testing without cucumber In-Reply-To: <968ea143-57a0-4c04-bc52-5f67e8504b8d@q16g2000yqq.googlegroups.com> References: <968ea143-57a0-4c04-bc52-5f67e8504b8d@q16g2000yqq.googlegroups.com> Message-ID: <4B8C314B.6070604@josephwilk.net> drewB wrote: > I need to create some integration tests without cucumber. Can anyone > point me in the right direction for how to do that in rails? I tried > creating specs under 'spec/integration/' but no matchers are being > included. I also tried rspec_integration plugin (http://github.com/ > tricycle/rspec-integration) but that only defines a few matchers and > response.should be_success doesn't work properly. > > Any help you can provide would be much appreciated! > You should not need any magic to get rspec working. In order to run integration specs I've been using a very simple spec_helper.rb. Maybe this can be some help to you; http://gist.github.com/318821 -- Joseph Wilk http://blog.josephwilk.net http://www.songkick.com mob: +44(0)7812816431 > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > From win at wincent.com Mon Mar 1 16:54:02 2010 From: win at wincent.com (Wincent Colaiuta) Date: Mon, 1 Mar 2010 22:54:02 +0100 Subject: [rspec-users] Integration testing without cucumber In-Reply-To: <968ea143-57a0-4c04-bc52-5f67e8504b8d@q16g2000yqq.googlegroups.com> References: <968ea143-57a0-4c04-bc52-5f67e8504b8d@q16g2000yqq.googlegroups.com> Message-ID: <0ECC405F-73FA-4CC0-AC26-3B002BC81BF0@wincent.com> El 01/03/2010, a las 21:32, drewB escribi?: > I need to create some integration tests without cucumber. Can anyone > point me in the right direction for how to do that in rails? I tried > creating specs under 'spec/integration/' but no matchers are being > included. I also tried rspec_integration plugin (http://github.com/ > tricycle/rspec-integration) but that only defines a few matchers and > response.should be_success doesn't work properly. > > Any help you can provide would be much appreciated! You could try Steak: http://github.com/cavalle/steak Cheers, Wincent From dansteinicke at gmail.com Mon Mar 1 17:24:53 2010 From: dansteinicke at gmail.com (DanS) Date: Mon, 1 Mar 2010 14:24:53 -0800 (PST) Subject: [rspec-users] Can have_selector Match Only Part of an Elements Class String? Message-ID: <41173af8-9d63-4f05-9eb0-8da38e3a6ffe@l12g2000prg.googlegroups.com> I would like to find a way to check for the existence of a class on a element in a calendar. The s are the days of the calendar and can have various classes assigned. I want to test if a day has the 'past' class and don't care (in this test) if other classes (weekend, today, etc) are present. So far I've only been able to use have_selector('td', :class=>'some class') if the class string matches exactly. Is there an easy way to match if the class 'past' is just present in the string? (wildcards, regex, whatever) Making the test match the string exactly feels like it makes the test too complicated and loose its focus on the single thing I want to test. Thanks to anyone who can offer advice on this. Dan Steinicke From dchelimsky at gmail.com Mon Mar 1 17:26:39 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 1 Mar 2010 16:26:39 -0600 Subject: [rspec-users] Can have_selector Match Only Part of an Elements Class String? In-Reply-To: <41173af8-9d63-4f05-9eb0-8da38e3a6ffe@l12g2000prg.googlegroups.com> References: <41173af8-9d63-4f05-9eb0-8da38e3a6ffe@l12g2000prg.googlegroups.com> Message-ID: <57c63afe1003011426m405b6275tfa45dd3dacec6715@mail.gmail.com> On Mon, Mar 1, 2010 at 4:24 PM, DanS wrote: > I would like to find a way to check for the existence of a class on a > element in a calendar. ?The s are the days of the calendar > and can have various classes assigned. ?I want to test if a day has > the 'past' class and don't care (in this test) if other classes > (weekend, today, etc) are present. ?So far I've only been able to use > have_selector('td', :class=>'some class') if the class string matches > exactly. ?Is there an easy way to match if the class 'past' is just > present in the string? (wildcards, regex, whatever) > > Making the test match the string exactly feels like it makes the test > too complicated and loose its focus on the single thing I want to > test. > > Thanks to anyone who can offer advice on this. This is a webrat question. If nobody answers you here, check the webrat group: http://groups.google.com/group/webrat. HTH, David From dbatshaw at gmail.com Mon Mar 1 17:59:56 2010 From: dbatshaw at gmail.com (drewB) Date: Mon, 1 Mar 2010 14:59:56 -0800 (PST) Subject: [rspec-users] Integration testing without cucumber In-Reply-To: <0ECC405F-73FA-4CC0-AC26-3B002BC81BF0@wincent.com> References: <968ea143-57a0-4c04-bc52-5f67e8504b8d@q16g2000yqq.googlegroups.com> <0ECC405F-73FA-4CC0-AC26-3B002BC81BF0@wincent.com> Message-ID: <28d51163-d2af-41f9-b98a-d989dfb0621f@c16g2000yqd.googlegroups.com> Belwo is a spec that when used with the default spec_helper fails with: NoMethodError in 'test matchers should be able to find be_success' undefined method `be_success' for # ---------- require 'spec_helper' describe "test matchers" do it "should be able to find be_success" do get '/' response.should be_success end end ------------- From dchelimsky at gmail.com Mon Mar 1 18:04:06 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 1 Mar 2010 17:04:06 -0600 Subject: [rspec-users] Integration testing without cucumber In-Reply-To: <28d51163-d2af-41f9-b98a-d989dfb0621f@c16g2000yqd.googlegroups.com> References: <968ea143-57a0-4c04-bc52-5f67e8504b8d@q16g2000yqq.googlegroups.com> <0ECC405F-73FA-4CC0-AC26-3B002BC81BF0@wincent.com> <28d51163-d2af-41f9-b98a-d989dfb0621f@c16g2000yqd.googlegroups.com> Message-ID: <57c63afe1003011504n443328e5k1fb2f9f1ad944951@mail.gmail.com> On Mon, Mar 1, 2010 at 4:59 PM, drewB wrote: > Belwo is a spec that when used with the default spec_helper fails > with: > > NoMethodError in 'test matchers should be able to find be_success' > undefined method `be_success' for > # > > ---------- > > require 'spec_helper' > > describe "test matchers" do > ?it "should be able to find be_success" do > ? ?get '/' > ? ?response.should be_success > ?end > > end Try adding this to spec/spec_helper.rb Spec::Runner.configure {|c| c.include Spec::Matchers} From dbatshaw at gmail.com Mon Mar 1 19:06:29 2010 From: dbatshaw at gmail.com (drewB) Date: Mon, 1 Mar 2010 16:06:29 -0800 (PST) Subject: [rspec-users] Integration testing without cucumber In-Reply-To: <57c63afe1003011504n443328e5k1fb2f9f1ad944951@mail.gmail.com> References: <968ea143-57a0-4c04-bc52-5f67e8504b8d@q16g2000yqq.googlegroups.com> <0ECC405F-73FA-4CC0-AC26-3B002BC81BF0@wincent.com> <28d51163-d2af-41f9-b98a-d989dfb0621f@c16g2000yqd.googlegroups.com> <57c63afe1003011504n443328e5k1fb2f9f1ad944951@mail.gmail.com> Message-ID: <8e285398-3c55-4223-aeae-b0e12b914c8c@e1g2000yqh.googlegroups.com> That fixed it! Thanks! Any idea why that was needed for integration specs and not MVCs? On Mar 1, 3:04?pm, David Chelimsky wrote: > On Mon, Mar 1, 2010 at 4:59 PM, drewB wrote: > > Belwo is a spec that when used with the default spec_helper fails > > with: > > > NoMethodError in 'test matchers should be able to find be_success' > > undefined method `be_success' for > > # > > > ---------- > > > require 'spec_helper' > > > describe "test matchers" do > > ?it "should be able to find be_success" do > > ? ?get '/' > > ? ?response.should be_success > > ?end > > > end > > Try adding this to spec/spec_helper.rb > > Spec::Runner.configure {|c| c.include Spec::Matchers} > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From dansteinicke at gmail.com Tue Mar 2 00:15:12 2010 From: dansteinicke at gmail.com (DanS) Date: Mon, 1 Mar 2010 21:15:12 -0800 (PST) Subject: [rspec-users] Can have_selector Match Only Part of an Elements Class String? In-Reply-To: <57c63afe1003011426m405b6275tfa45dd3dacec6715@mail.gmail.com> References: <41173af8-9d63-4f05-9eb0-8da38e3a6ffe@l12g2000prg.googlegroups.com> <57c63afe1003011426m405b6275tfa45dd3dacec6715@mail.gmail.com> Message-ID: <4b2944ff-962c-4845-ba69-2006e4c35fee@b9g2000pri.googlegroups.com> On Mar 1, 2:26?pm, David Chelimsky wrote: > On Mon, Mar 1, 2010 at 4:24 PM, DanS wrote: > > I would like to find a way to check for the existence of a class on a > > element in a calendar. ?The s are the days of the calendar > > and can have various classes assigned. ?I want to test if a day has > > the 'past' class and don't care (in this test) if other classes > > (weekend, today, etc) are present. ?So far I've only been able to use > > have_selector('td', :class=>'some class') if the class string matches > > exactly. ?Is there an easy way to match if the class 'past' is just > > present in the string? (wildcards, regex, whatever) > > > Making the test match the string exactly feels like it makes the test > > too complicated and loose its focus on the single thing I want to > > test. > > > Thanks to anyone who can offer advice on this. > > This is a webrat question. If nobody answers you here, check the > webrat group:http://groups.google.com/group/webrat. > > HTH, > David > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users Thanks David. Sorry for posting to wrong place. Posted on webrat group here: http://groups.google.com/group/webrat/browse_thread/thread/ac30dec93f842316 From lists at ruby-forum.com Tue Mar 2 03:39:03 2010 From: lists at ruby-forum.com (Zhenning Guan) Date: Tue, 2 Mar 2010 09:39:03 +0100 Subject: [rspec-users] how to mock a Net::Http object? Message-ID: one_data = Net::HTTP.post_form(URI.parse(country_site), {'country' => "american"}) two_data = Net::HTTP.post_form(URI.parse(visit_site), {'country' => "english"}) I have a code similar like above code in my application, so how to mock a a object like above? if only post_from once, I just need to stub post_form, but now, it has different parameter, how to do it? Net::HTTP.stub!(:post_form).and_return('my_data') -- Posted via http://www.ruby-forum.com/. From aslak.hellesoy at gmail.com Tue Mar 2 03:49:36 2010 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 2 Mar 2010 09:49:36 +0100 Subject: [rspec-users] how to mock a Net::Http object? In-Reply-To: References: Message-ID: <8d961d901003020049s1a2eaad9m17ea31eab981473e@mail.gmail.com> On Tue, Mar 2, 2010 at 9:39 AM, Zhenning Guan wrote: > one_data = Net::HTTP.post_form(URI.parse(country_site), {'country' => > "american"}) > two_data = Net::HTTP.post_form(URI.parse(visit_site), {'country' => > "english"}) > > I have a code similar like above code in my application, so how to mock > a a object like above? if only post_from once, I just need to stub > post_form, but now, it has different parameter, how to do it? > > http://github.com/blaine/fakeweb Aslak > Net::HTTP.stub!(:post_form).and_return('my_data') > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kmandrup at gmail.com Tue Mar 2 08:42:28 2010 From: kmandrup at gmail.com (Kristian Mandrup) Date: Tue, 2 Mar 2010 05:42:28 -0800 (PST) Subject: [rspec-users] Configuring RSpec 2 Message-ID: <6674f783-a431-4acb-8cca-30777246c817@z11g2000yqz.googlegroups.com> # spec_helper.rb $LOAD_PATH.unshift(File.dirname(__FILE__)) $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) require '... require 'rspec' require 'rspec/autorun' # doesn't work: just remove it and it works. # But how would you configure the RSpec Runner in RSpec 2 then? Rspec::Runner.configure do |config| # config here end Then I found this: Rspec::Core.configure do |c| # config here end Which works :) From dchelimsky at gmail.com Tue Mar 2 08:59:25 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 2 Mar 2010 07:59:25 -0600 Subject: [rspec-users] Configuring RSpec 2 In-Reply-To: <6674f783-a431-4acb-8cca-30777246c817@z11g2000yqz.googlegroups.com> References: <6674f783-a431-4acb-8cca-30777246c817@z11g2000yqz.googlegroups.com> Message-ID: <57c63afe1003020559n127802odc743b30bddc8c3c@mail.gmail.com> On Tue, Mar 2, 2010 at 7:42 AM, Kristian Mandrup wrote: > # spec_helper.rb > > $LOAD_PATH.unshift(File.dirname(__FILE__)) > $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) > require '... > require 'rspec' > require 'rspec/autorun' > > # doesn't work: just remove it and it works. > # But how would you configure the RSpec Runner in RSpec 2 then? > Rspec::Runner.configure do |config| > ?# config here > end > > Then I found this: > > Rspec::Core.configure do |c| > ?# config here > end > > Which works :) And is deprecated :) Use this: Rspec.configure do |c| # config here end From dchelimsky at gmail.com Tue Mar 2 09:51:22 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 2 Mar 2010 08:51:22 -0600 Subject: [rspec-users] RSpec-2 and The RSpec Book Message-ID: <57c63afe1003020651t5ad96e01g49e672ae651f4628@mail.gmail.com> Hey all, I'm happy to announce that The RSpec Book will be updated for RSpec-2 and Rails-3 before its final release. This, of course, means that the print schedule will get pushed back, but we'll have a couple of more beta releases of the book before we go to print. I don't know the exact schedule right now, but I'll follow up as it shapes up. Cheers, David From tom at experthuman.com Tue Mar 2 10:37:39 2010 From: tom at experthuman.com (Tom Stuart) Date: Tue, 2 Mar 2010 15:37:39 +0000 Subject: [rspec-users] RSpec-2 and The RSpec Book In-Reply-To: <57c63afe1003020651t5ad96e01g49e672ae651f4628@mail.gmail.com> References: <57c63afe1003020651t5ad96e01g49e672ae651f4628@mail.gmail.com> Message-ID: <8EB26CE1-ECCA-44D8-9E2A-B6055D71E6C1@experthuman.com> On 2 Mar 2010, at 14:51, David Chelimsky wrote: > I'm happy to announce that The RSpec Book will be updated for RSpec-2 > and Rails-3 before its final release. Wow, this is great news. Thanks, David! I'm sure it'll be well worth the wait; having the beta book available in the meantime gives RSpec users the best of both worlds. Cheers, -Tom From rick.denatale at gmail.com Tue Mar 2 10:51:48 2010 From: rick.denatale at gmail.com (Rick DeNatale) Date: Tue, 2 Mar 2010 10:51:48 -0500 Subject: [rspec-users] RSpec-2 and The RSpec Book In-Reply-To: <57c63afe1003020651t5ad96e01g49e672ae651f4628@mail.gmail.com> References: <57c63afe1003020651t5ad96e01g49e672ae651f4628@mail.gmail.com> Message-ID: On Tue, Mar 2, 2010 at 9:51 AM, David Chelimsky wrote: > Hey all, > > I'm happy to announce that The RSpec Book will be updated for RSpec-2 > and Rails-3 before its final release. This, of course, means that the > print schedule will get pushed back, but we'll have a couple of more > beta releases of the book before we go to print. I don't know the > exact schedule right now, but I'll follow up as it shapes up. Good news. It's hard for a dead-tree book authors to keep up with changing software, even when he/she/they are the folks changing the software. I guess that the current beta PDF will serve as the best checkpoint for RSpec 1 and Rails 2.x. I guess it's time to print a personal hard-copy. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale From dchelimsky at gmail.com Tue Mar 2 11:38:33 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 2 Mar 2010 10:38:33 -0600 Subject: [rspec-users] RSpec-2 and The RSpec Book In-Reply-To: References: <57c63afe1003020651t5ad96e01g49e672ae651f4628@mail.gmail.com> Message-ID: <57c63afe1003020838m359beeb5sba55ccfd539bbe93@mail.gmail.com> On Tue, Mar 2, 2010 at 9:51 AM, Rick DeNatale wrote: > On Tue, Mar 2, 2010 at 9:51 AM, David Chelimsky wrote: >> Hey all, >> >> I'm happy to announce that The RSpec Book will be updated for RSpec-2 >> and Rails-3 before its final release. This, of course, means that the >> print schedule will get pushed back, but we'll have a couple of more >> beta releases of the book before we go to print. I don't know the >> exact schedule right now, but I'll follow up as it shapes up. > > Good news. ?It's hard for a dead-tree book authors to keep up with > changing software, even when he/she/they are the folks changing the > software. > > I guess that the current beta PDF will serve as the best checkpoint > for RSpec 1 and Rails 2.x. ?I guess it's time to print a personal > hard-copy. That is probably a good idea, but we'll be including notes in the book about differences w/ the previous versions. From dbatshaw at gmail.com Tue Mar 2 12:53:05 2010 From: dbatshaw at gmail.com (drewB) Date: Tue, 2 Mar 2010 09:53:05 -0800 (PST) Subject: [rspec-users] Integration testing without cucumber In-Reply-To: <8e285398-3c55-4223-aeae-b0e12b914c8c@e1g2000yqh.googlegroups.com> References: <968ea143-57a0-4c04-bc52-5f67e8504b8d@q16g2000yqq.googlegroups.com> <0ECC405F-73FA-4CC0-AC26-3B002BC81BF0@wincent.com> <28d51163-d2af-41f9-b98a-d989dfb0621f@c16g2000yqd.googlegroups.com> <57c63afe1003011504n443328e5k1fb2f9f1ad944951@mail.gmail.com> <8e285398-3c55-4223-aeae-b0e12b914c8c@e1g2000yqh.googlegroups.com> Message-ID: <3f3dcb43-7bdd-4c0a-8145-2ad434b470cc@33g2000yqj.googlegroups.com> Looks like I spoke too soon. I made a mistake when testing your suggest. When I add that I still get the same failure. On Mar 1, 4:06?pm, drewB wrote: > That fixed it! Thanks! > > Any idea why that was needed for integration specs and not MVCs? > > On Mar 1, 3:04?pm, David Chelimsky wrote: > > > On Mon, Mar 1, 2010 at 4:59 PM, drewB wrote: > > > Belwo is a spec that when used with the default spec_helper fails > > > with: > > > > NoMethodError in 'test matchers should be able to find be_success' > > > undefined method `be_success' for > > > # > > > > ---------- > > > > require 'spec_helper' > > > > describe "test matchers" do > > > ?it "should be able to find be_success" do > > > ? ?get '/' > > > ? ?response.should be_success > > > ?end > > > > end > > > Try adding this to spec/spec_helper.rb > > > Spec::Runner.configure {|c| c.include Spec::Matchers} > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From reed.adam at gmail.com Tue Mar 2 12:24:10 2010 From: reed.adam at gmail.com (Adam R) Date: Tue, 2 Mar 2010 09:24:10 -0800 (PST) Subject: [rspec-users] RSpec and Watir, easy script structure question Message-ID: <27758607.post@talk.nabble.com> Howdy! I'm relatively new to RSpec, but I've worked with Watir and Ruby for about 5 years now. My company is redesigning a web app from the ground up, so I'm taking the opportunity to leverage RSpec instead of Test/Unit. I've run into a problem with RSpec organization that I just can't sort out on my own, so I'm hoping it's straightforward enough that someone can help me out. Basically I have a single HTML page with an organized list of links. Each link points to a new page with a single verifiable item on it. The script collects all the links into an array, then iterates over the array, loading each link and verifying a single piece of text. That's the easy part. Here's the relevant code for what I believe to be the closest attempt right now: @links = Array.new @browser = Watir::Browser.new @browser.goto(page) @browser.link.each do |link| @links << [link.name, link.href] end @links.each do |name, link| describe name do it "should contain the word #{name}" do @browser.goto link @browser.div(:id, /example/).text.should include(name) end #it end #desc end #@links I've tried a combination of methods -- putting all of this code inside a describe block, etc, but I end up with the variables being unknown because they're not inside the same describe or it block (even when set to $global), or the describe/it blocks being layered incorrectly. I'm sure there's a simple solution to the format, but unfortunately I haven't been able to Google or RDoc my way to an answer. I appreciate any advice you can offer! Thanks, Adam -- View this message in context: http://old.nabble.com/RSpec-and-Watir%2C-easy-script-structure-question-tp27758607p27758607.html Sent from the rspec-users mailing list archive at Nabble.com. From dbatshaw at gmail.com Tue Mar 2 14:22:55 2010 From: dbatshaw at gmail.com (drewB) Date: Tue, 2 Mar 2010 11:22:55 -0800 (PST) Subject: [rspec-users] requiring "test_notifier/rspec" in spec,opts Message-ID: <6673165f-29d4-4a9e-8bb8-ec94f0b1b3e5@t41g2000yqt.googlegroups.com> There is a nice little gem that gives you desktop notifications of your spec commands called test_noitifer (http://github.com/fnando/ test_notifier). I can get it to work by including require "test_notifier/rspec" toward the top of my spec_helper, or by manually including it in the command line like: spec --require "test_notifier/rspec" However, if I add it to the top of my spec.opts file, I get the following error: /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- "test_notifier/ rspec" (LoadError) Any ideas on how to make it work? I don't want to add it to spec_helper because then others on my team would need to use the gem as well (which they might not want to). From dchelimsky at gmail.com Tue Mar 2 14:33:22 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 2 Mar 2010 13:33:22 -0600 Subject: [rspec-users] requiring "test_notifier/rspec" in spec,opts In-Reply-To: <6673165f-29d4-4a9e-8bb8-ec94f0b1b3e5@t41g2000yqt.googlegroups.com> References: <6673165f-29d4-4a9e-8bb8-ec94f0b1b3e5@t41g2000yqt.googlegroups.com> Message-ID: <57c63afe1003021133w3b32bea3j2970251f0bc59b57@mail.gmail.com> On Tue, Mar 2, 2010 at 1:22 PM, drewB wrote: > There is a nice little gem that gives you desktop notifications of > your spec commands called test_noitifer (http://github.com/fnando/ > test_notifier). ?I can get it to work by including require > "test_notifier/rspec" toward the top of my spec_helper, or by manually > including it in the command line like: > > spec --require "test_notifier/rspec" > > However, if I add it to the top of my spec.opts file, I get the > following error: > > /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in > `gem_original_require': no such file to load -- "test_notifier/ > rspec" (LoadError) > > Any ideas on how to make it work? ?I don't want to add it to > spec_helper because then others on my team would need to use the gem > as well (which they might not want to). spec.opts is not a ruby file, so you can't put it there. Why not add it to a ruby file in spec/support/ that you don't keep in source control? From phillipkoebbe at gmail.com Tue Mar 2 14:38:08 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Tue, 02 Mar 2010 13:38:08 -0600 Subject: [rspec-users] stub and should_receive In-Reply-To: <4B8D67E0.2000606@gmail.com> References: <4B8D67E0.2000606@gmail.com> Message-ID: <4B8D6920.9090002@gmail.com> Nevermind. If I would have waited five more minutes before clicking "Send", I would have seen my error. Blech. Phillip Koebbe wrote: > What is the expected behavior when a model has both stub and > should_receive defined for the same method? > > I have a helper method which creates an admin "logged in": > > def stub_user(is_administrator) > user = stub_model(User) > user.stub(:is_administrator).and_return(is_administrator) > User.stub(:find_by_id).and_return(user) > user > end > > def setup_admin > @admin = stub_user(true) > session[:user_id] = @admin.id > end > > In an admin controller spec, I have to setup_admin so the specs can > get to the controllers, but then later in particular contexts, I do > > @some_user = stub_model(User) > User.should_receive(:find_by_id).and_return(@some_user) > > This is to simulate selecting a user from a list and either showing or > editing details. Based on what I'm seeing, it appears that the the > find_by_id return values are getting mixed up. Am I wrong to attempt > to use both of these or should this work as I expect? If the latter, > then I have more digging to do to determine what's going wrong. > > Thanks, > Phillip From phillipkoebbe at gmail.com Tue Mar 2 14:32:48 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Tue, 02 Mar 2010 13:32:48 -0600 Subject: [rspec-users] stub and should_receive Message-ID: <4B8D67E0.2000606@gmail.com> What is the expected behavior when a model has both stub and should_receive defined for the same method? I have a helper method which creates an admin "logged in": def stub_user(is_administrator) user = stub_model(User) user.stub(:is_administrator).and_return(is_administrator) User.stub(:find_by_id).and_return(user) user end def setup_admin @admin = stub_user(true) session[:user_id] = @admin.id end In an admin controller spec, I have to setup_admin so the specs can get to the controllers, but then later in particular contexts, I do @some_user = stub_model(User) User.should_receive(:find_by_id).and_return(@some_user) This is to simulate selecting a user from a list and either showing or editing details. Based on what I'm seeing, it appears that the the find_by_id return values are getting mixed up. Am I wrong to attempt to use both of these or should this work as I expect? If the latter, then I have more digging to do to determine what's going wrong. Thanks, Phillip From reed.adam at gmail.com Tue Mar 2 16:05:41 2010 From: reed.adam at gmail.com (Adam R) Date: Tue, 2 Mar 2010 13:05:41 -0800 (PST) Subject: [rspec-users] RSpec framework question In-Reply-To: <27758607.post@talk.nabble.com> References: <27758607.post@talk.nabble.com> Message-ID: <27761159.post@talk.nabble.com> An update for this issue. This script works, but only if I explicitly define the array that I'm iterating over (][countryname, url]].each do, rather than @countries.each do). Can someone help me understand why my array here (@countries) is not recognized? I tried to instantiate it as a global variable ($countries) and it still was not recognized. If I explicitly describe an array in place of the variable, the script works. Is it an issue with my organization format, or something else? global_page_spec.rb $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') if $0 == __FILE__ require 'helpers/example_helper' describe "The country page for" do include ExHelper before(:all) do setup collect_global_countries end @countries.each do |name, link| describe name do it "should contain the word #{name} in the title" do @browser.goto link @browser.div(:id, /content-content/).text.should include(name) end #it end #desc end #countries after(:all) do teardown end #after end #spec example_helper.rb $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') if $0 == __FILE__ require 'helpers/global_helper' module ExHelper include GlobalHelper def setup @browser = Watir::Browser.new @browser.add_checker lambda {|b| b.text.should_not include('The requested page could not be found.')} end # setup def collect_global_countries @countries = Array.new @countries.should be_empty @browser.goto "http://www.#{$env}.com/global" @browser.table(:class, /global-list/).links.each do |link| @countries << [link.text, link.href] end #links @countries.should_not be_empty def teardown @browser.close end # teardown end #module -- View this message in context: http://old.nabble.com/RSpec-and-Watir%2C-easy-script-structure-question-tp27758607p27761159.html Sent from the rspec-users mailing list archive at Nabble.com. From dbatshaw at gmail.com Tue Mar 2 16:13:40 2010 From: dbatshaw at gmail.com (drewB) Date: Tue, 2 Mar 2010 13:13:40 -0800 (PST) Subject: [rspec-users] requiring "test_notifier/rspec" in spec,opts In-Reply-To: <57c63afe1003021133w3b32bea3j2970251f0bc59b57@mail.gmail.com> References: <6673165f-29d4-4a9e-8bb8-ec94f0b1b3e5@t41g2000yqt.googlegroups.com> <57c63afe1003021133w3b32bea3j2970251f0bc59b57@mail.gmail.com> Message-ID: I may not have been clear. When I said if I add it to the top of my spec.opts file, I meant adding, '--require "test_notifier/rspec"'. Nevertheless, I tried you suggestion (a very good one). Unfortunately, it seems that it must be required before "require File.expand_path(File.join(File.dirname(__FILE__),'..','config','environment'))" or the following error appears: /usr/local/lib/site_ruby/1.8/rubygems.rb:270:in `activate': You have a nil object when you didn't expect it! (NoMethodError) You might have expected an instance of Array. The error occurred while evaluating nil.map On Mar 2, 11:33?am, David Chelimsky wrote: > On Tue, Mar 2, 2010 at 1:22 PM, drewB wrote: > > There is a nice little gem that gives you desktop notifications of > > your spec commands called test_noitifer (http://github.com/fnando/ > > test_notifier). ?I can get it to work by including require > > "test_notifier/rspec" toward the top of my spec_helper, or by manually > > including it in the command line like: > > > spec --require "test_notifier/rspec" > > > However, if I add it to the top of my spec.opts file, I get the > > following error: > > > /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in > > `gem_original_require': no such file to load -- "test_notifier/ > > rspec" (LoadError) > > > Any ideas on how to make it work? ?I don't want to add it to > > spec_helper because then others on my team would need to use the gem > > as well (which they might not want to). > > spec.opts is not a ruby file, so you can't put it there. Why not add > it to a ruby file in spec/support/ that you don't keep in source > control? > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From dbatshaw at gmail.com Tue Mar 2 17:56:21 2010 From: dbatshaw at gmail.com (drewB) Date: Tue, 2 Mar 2010 14:56:21 -0800 (PST) Subject: [rspec-users] requiring "test_notifier/rspec" in spec,opts In-Reply-To: References: <6673165f-29d4-4a9e-8bb8-ec94f0b1b3e5@t41g2000yqt.googlegroups.com> <57c63afe1003021133w3b32bea3j2970251f0bc59b57@mail.gmail.com> Message-ID: If I add to spec.opts '--require test_notifier/rspec' (quotes are removed) it is finding it but I am encountering the same error as if I didn't require the file early enough in spec_helper: /usr/local/lib/site_ruby/1.8/rubygems.rb:270:in `activate': You have a nil object when you didn't expect it! (NoMethodError) You might have expected an instance of Array. The error occurred while evaluating nil.map No sure they same problem won't occur when using the option on the command line. On Mar 2, 1:13?pm, drewB wrote: > I may not have been clear. ?When I said if I add it to the top of my > spec.opts file, I meant adding, '--require "test_notifier/rspec"'. > > Nevertheless, I tried you suggestion (a very good one). > Unfortunately, it seems that it must be required before "require > File.expand_path(File.join(File.dirname(__FILE__),'..','config','environment'))" > or the following error appears: > > /usr/local/lib/site_ruby/1.8/rubygems.rb:270:in `activate': You have a > nil object when you didn't expect it! (NoMethodError) > You might have expected an instance of Array. > The error occurred while evaluating nil.map > > On Mar 2, 11:33?am, David Chelimsky wrote: > > > On Tue, Mar 2, 2010 at 1:22 PM, drewB wrote: > > > There is a nice little gem that gives you desktop notifications of > > > your spec commands called test_noitifer (http://github.com/fnando/ > > > test_notifier). ?I can get it to work by including require > > > "test_notifier/rspec" toward the top of my spec_helper, or by manually > > > including it in the command line like: > > > > spec --require "test_notifier/rspec" > > > > However, if I add it to the top of my spec.opts file, I get the > > > following error: > > > > /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in > > > `gem_original_require': no such file to load -- "test_notifier/ > > > rspec" (LoadError) > > > > Any ideas on how to make it work? ?I don't want to add it to > > > spec_helper because then others on my team would need to use the gem > > > as well (which they might not want to). > > > spec.opts is not a ruby file, so you can't put it there. Why not add > > it to a ruby file in spec/support/ that you don't keep in source > > control? > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From matt at mattwynne.net Tue Mar 2 18:16:26 2010 From: matt at mattwynne.net (Matt Wynne) Date: Tue, 2 Mar 2010 23:16:26 +0000 Subject: [rspec-users] RSpec framework question In-Reply-To: <27761159.post@talk.nabble.com> References: <27758607.post@talk.nabble.com> <27761159.post@talk.nabble.com> Message-ID: <6D4244AA-51CD-409E-9F8B-02EC7CB72623@mattwynne.net> On 2 Mar 2010, at 21:05, Adam R wrote: > > An update for this issue. This script works, but only if I > explicitly define > the array that I'm iterating over (][countryname, url]].each do, > rather than > @countries.each do). > > Can someone help me understand why my array here (@countries) is not > recognized? I tried to instantiate it as a global variable > ($countries) and > it still was not recognized. If I explicitly describe an array in > place of > the variable, the script works. > > Is it an issue with my organization format, or something else? > > global_page_spec.rb > $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') if $0 == > __FILE__ > require 'helpers/example_helper' > > describe "The country page for" do > include ExHelper > > before(:all) do > setup > collect_global_countries > end > > @countries.each do |name, link| > describe name do > it "should contain the word #{name} in the title" do > @browser.goto link > @browser.div(:id, /content-content/).text.should include(name) > end #it > end #desc > end #countries > > after(:all) do > teardown > end #after > end #spec > > example_helper.rb > $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') if $0 == > __FILE__ > require 'helpers/global_helper' > > module ExHelper > include GlobalHelper > > def setup > @browser = Watir::Browser.new > @browser.add_checker lambda {|b| b.text.should_not include('The > requested page could not be found.')} > end # setup > > def collect_global_countries > @countries = Array.new > @countries.should be_empty > > @browser.goto "http://www.#{$env}.com/global" > @browser.table(:class, /global-list/).links.each do |link| > @countries << [link.text, link.href] > end #links > > @countries.should_not be_empty > > def teardown > @browser.close > end # teardown > end #module > -- > View this message in context: http://old.nabble.com/RSpec-and-Watir%2C-easy-script-structure-question-tp27758607p27761159.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 Briefly, think of two passes over this file: the first 'parse' pass, and the second 'execution' pass. The #before and #it blocks run during the 'execution' pass, but the code in the #describe blocks runs in the initial 'parse' pass. Because @countries is not created until the before blocks run, there's no way for the 'parse' pass to know what value it has. That's the basic essence of your issue. I'd recommend paring this back to a much simpler example, getting that working, then building up from there. I'm also not sure why you're using the SUT to generate the tests, but that's for another thread... cheers, Matt http://mattwynne.net +447974 430184 From dchelimsky at gmail.com Tue Mar 2 18:54:00 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 2 Mar 2010 17:54:00 -0600 Subject: [rspec-users] Integration testing without cucumber In-Reply-To: <3f3dcb43-7bdd-4c0a-8145-2ad434b470cc@33g2000yqj.googlegroups.com> References: <968ea143-57a0-4c04-bc52-5f67e8504b8d@q16g2000yqq.googlegroups.com> <0ECC405F-73FA-4CC0-AC26-3B002BC81BF0@wincent.com> <28d51163-d2af-41f9-b98a-d989dfb0621f@c16g2000yqd.googlegroups.com> <57c63afe1003011504n443328e5k1fb2f9f1ad944951@mail.gmail.com> <8e285398-3c55-4223-aeae-b0e12b914c8c@e1g2000yqh.googlegroups.com> <3f3dcb43-7bdd-4c0a-8145-2ad434b470cc@33g2000yqj.googlegroups.com> Message-ID: <57c63afe1003021554m7b0e90bs3b86847ac97f2691@mail.gmail.com> On Tue, Mar 2, 2010 at 11:53 AM, drewB wrote: > Looks like I spoke too soon. ?I made a mistake when testing your > suggest. ?When I add that I still get the same failure. I just did the following using rails 2.3.5, rspec 1.3.2 and rspec-rails 1.3.0: $ rails foo $ cd foo $ script/generate rspec $ mkdir spec/integration $ script/generate integration_spec widgets $ rake db:migrate && db:test:prepare Then I modified spec/integration/widgets_spec.rb as follows: require 'spec_helper' describe "Widgets" do it "shows me the list" do get "/widgets" response.should be_success end end Then I ran this: $ script/spec spec/integration/ And here's the output I saw: F 1) 'Widgets ..' FAILED expected success? to return true, got false /Users/dchelimsky/tmp/foo/spec/integration/widgets_spec.rb:6: So everything is working as it should on a fresh app. Did you update spec/spec_helper.rb the last time you upgraded the app? Are you using an earlier version of rspec-rails or rspec? > > On Mar 1, 4:06?pm, drewB wrote: >> That fixed it! Thanks! >> >> Any idea why that was needed for integration specs and not MVCs? >> >> On Mar 1, 3:04?pm, David Chelimsky wrote: >> >> > On Mon, Mar 1, 2010 at 4:59 PM, drewB wrote: >> > > Belwo is a spec that when used with the default spec_helper fails >> > > with: >> >> > > NoMethodError in 'test matchers should be able to find be_success' >> > > undefined method `be_success' for >> > > # >> >> > > ---------- >> >> > > require 'spec_helper' >> >> > > describe "test matchers" do >> > > ?it "should be able to find be_success" do >> > > ? ?get '/' >> > > ? ?response.should be_success >> > > ?end >> >> > > end >> >> > Try adding this to spec/spec_helper.rb >> >> > Spec::Runner.configure {|c| c.include Spec::Matchers} From dchelimsky at gmail.com Tue Mar 2 19:11:09 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 2 Mar 2010 18:11:09 -0600 Subject: [rspec-users] RSpec and Watir, easy script structure question In-Reply-To: <27758607.post@talk.nabble.com> References: <27758607.post@talk.nabble.com> Message-ID: <57c63afe1003021611r4602b831ha4307d917721fa15@mail.gmail.com> On Tue, Mar 2, 2010 at 11:24 AM, Adam R wrote: > > Howdy! ?I'm relatively new to RSpec, but I've worked with Watir and Ruby for > about 5 years now. ?My company is redesigning a web app from the ground up, > so I'm taking the opportunity to leverage RSpec instead of Test/Unit. > > I've run into a problem with RSpec organization that I just can't sort out > on my own, so I'm hoping it's straightforward enough that someone can help > me out. > > Basically I have a single HTML page with an organized list of links. ?Each > link points to a new page with a single verifiable item on it. ?The script > collects all the links into an array, then iterates over the array, loading > each link and verifying a single piece of text. ?That's the easy part. > > Here's the relevant code for what I believe to be the closest attempt right > now: > > @links = Array.new > @browser = Watir::Browser.new > @browser.goto(page) > > @browser.link.each do |link| > ? ?@links << [link.name, link.href] > end > > ? ?@links.each do |name, link| > ? ? ? ? describe name do > ? ? ? ? ? ? ?it "should contain the word #{name}" do > ? ? ? ? ? ? ? ? ? ?@browser.goto link > ? ? ? ? ? ? ? ? ? ?@browser.div(:id, /example/).text.should include(name) > ? ? ? ? ? ? ?end #it > ? ? ? ? end #desc > ? ?end #@links > > I've tried a combination of methods -- putting all of this code inside a > describe block, etc, but I end up with the variables being unknown because > they're not inside the same describe or it block (even when set to $global), > or the describe/it blocks being layered incorrectly. > > I'm sure there's a simple solution to the format, but unfortunately I > haven't been able to Google or RDoc my way to an answer. ?I appreciate any > advice you can offer! describe "something" do it "does something" do end end That's the simplest format - everything should go in the example (it block), not directly inside the describe block. HTH, David > > Thanks, > Adam > -- > View this message in context: http://old.nabble.com/RSpec-and-Watir%2C-easy-script-structure-question-tp27758607p27758607.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 reed.adam at gmail.com Tue Mar 2 20:40:15 2010 From: reed.adam at gmail.com (Adam Reed) Date: Tue, 2 Mar 2010 19:40:15 -0600 Subject: [rspec-users] RSpec and Watir, easy script structure question In-Reply-To: <57c63afe1003021611r4602b831ha4307d917721fa15@mail.gmail.com> References: <27758607.post@talk.nabble.com> <57c63afe1003021611r4602b831ha4307d917721fa15@mail.gmail.com> Message-ID: <1f87a1c1003021740p553b181ak586df8458d7cd0e5@mail.gmail.com> Thanks David. I have the basic format working in other scripts, so that's a good sign. Another user pointed me to this example, which is why I was exploring a different format: > ["Los Angeles", "Austin"].each do |location| > it "should show #{location}" do > @browser.div(:id, /example/).text.should include(location) > end > end > Is this not correct/usable? Thanks again, Adam On Tue, Mar 2, 2010 at 6:11 PM, David Chelimsky wrote: > On Tue, Mar 2, 2010 at 11:24 AM, Adam R wrote: > > > > Howdy! I'm relatively new to RSpec, but I've worked with Watir and Ruby > for > > about 5 years now. My company is redesigning a web app from the ground > up, > > so I'm taking the opportunity to leverage RSpec instead of Test/Unit. > > > > I've run into a problem with RSpec organization that I just can't sort > out > > on my own, so I'm hoping it's straightforward enough that someone can > help > > me out. > > > > Basically I have a single HTML page with an organized list of links. > Each > > link points to a new page with a single verifiable item on it. The > script > > collects all the links into an array, then iterates over the array, > loading > > each link and verifying a single piece of text. That's the easy part. > > > > Here's the relevant code for what I believe to be the closest attempt > right > > now: > > > > @links = Array.new > > @browser = Watir::Browser.new > > @browser.goto(page) > > > > @browser.link.each do |link| > > @links << [link.name, link.href] > > end > > > > @links.each do |name, link| > > describe name do > > it "should contain the word #{name}" do > > @browser.goto link > > @browser.div(:id, /example/).text.should include(name) > > end #it > > end #desc > > end #@links > > > > I've tried a combination of methods -- putting all of this code inside a > > describe block, etc, but I end up with the variables being unknown > because > > they're not inside the same describe or it block (even when set to > $global), > > or the describe/it blocks being layered incorrectly. > > > > I'm sure there's a simple solution to the format, but unfortunately I > > haven't been able to Google or RDoc my way to an answer. I appreciate > any > > advice you can offer! > > describe "something" do > it "does something" do > end > end > > That's the simplest format - everything should go in the example (it > block), not directly inside the describe block. > > HTH, > David > > > > > Thanks, > > Adam > > -- > > View this message in context: > http://old.nabble.com/RSpec-and-Watir%2C-easy-script-structure-question-tp27758607p27758607.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 > -------------- next part -------------- An HTML attachment was scrubbed... URL: From thiyagarajannv at gmail.com Wed Mar 3 03:16:59 2010 From: thiyagarajannv at gmail.com (vtr) Date: Wed, 3 Mar 2010 00:16:59 -0800 (PST) Subject: [rspec-users] Hi All Message-ID: Hi All, This is Thiyagarajan Veluchamy from India, i am new to rspec. gI need to learn rspec. Can anyone guide me, how to start properly. Advance Thanks, Thanks, Thiyagarajan Veluchamy From dchelimsky at gmail.com Wed Mar 3 08:15:09 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 3 Mar 2010 07:15:09 -0600 Subject: [rspec-users] RSpec and Watir, easy script structure question In-Reply-To: <1f87a1c1003021740p553b181ak586df8458d7cd0e5@mail.gmail.com> References: <27758607.post@talk.nabble.com> <57c63afe1003021611r4602b831ha4307d917721fa15@mail.gmail.com> <1f87a1c1003021740p553b181ak586df8458d7cd0e5@mail.gmail.com> Message-ID: <57c63afe1003030515h1f24292dqe778adf746667767@mail.gmail.com> On Tue, Mar 2, 2010 at 7:40 PM, Adam Reed wrote: > On Tue, Mar 2, 2010 at 6:11 PM, David Chelimsky > wrote: >> >> On Tue, Mar 2, 2010 at 11:24 AM, Adam R wrote: >> > >> > Howdy! ?I'm relatively new to RSpec, but I've worked with Watir and Ruby >> > for >> > about 5 years now. ?My company is redesigning a web app from the ground >> > up, >> > so I'm taking the opportunity to leverage RSpec instead of Test/Unit. >> > >> > I've run into a problem with RSpec organization that I just can't sort >> > out >> > on my own, so I'm hoping it's straightforward enough that someone can >> > help >> > me out. >> > >> > Basically I have a single HTML page with an organized list of links. >> > ?Each >> > link points to a new page with a single verifiable item on it. ?The >> > script >> > collects all the links into an array, then iterates over the array, >> > loading >> > each link and verifying a single piece of text. ?That's the easy part. >> > >> > Here's the relevant code for what I believe to be the closest attempt >> > right >> > now: >> > >> > @links = Array.new >> > @browser = Watir::Browser.new >> > @browser.goto(page) >> > >> > @browser.link.each do |link| >> > ? ?@links << [link.name, link.href] >> > end >> > >> > ? ?@links.each do |name, link| >> > ? ? ? ? describe name do >> > ? ? ? ? ? ? ?it "should contain the word #{name}" do >> > ? ? ? ? ? ? ? ? ? ?@browser.goto link >> > ? ? ? ? ? ? ? ? ? ?@browser.div(:id, /example/).text.should >> > include(name) >> > ? ? ? ? ? ? ?end #it >> > ? ? ? ? end #desc >> > ? ?end #@links >> > >> > I've tried a combination of methods -- putting all of this code inside a >> > describe block, etc, but I end up with the variables being unknown >> > because >> > they're not inside the same describe or it block (even when set to >> > $global), >> > or the describe/it blocks being layered incorrectly. >> > >> > I'm sure there's a simple solution to the format, but unfortunately I >> > haven't been able to Google or RDoc my way to an answer. ?I appreciate >> > any >> > advice you can offer! >> >> describe "something" do >> ?it "does something" do >> ?end >> end >> >> That's the simplest format - everything should go in the example (it >> block), not directly inside the describe block. > Thanks David.? I have the basic format working in other scripts, so that's a > good sign.? Another user pointed me to this example, which is why I was > exploring a different format: > >> >> ["Los Angeles", "Austin"].each do |location| >> ? ? it "should show #{location}" do >> ? ? ? @browser.div(:id, /example/).text.should include(location) >> ? ? end >> end > > Is this not correct/usable? Correct is subjective. What you have here is somewhat harmless, but I've seen simple lists like that grow into nested lists with conditional logic where members of one list impact what is done with the values in the other. That makes it very difficult to understand failures and difficult to change as requirements change. HTH, David From dchelimsky at gmail.com Wed Mar 3 08:26:12 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 3 Mar 2010 07:26:12 -0600 Subject: [rspec-users] Hi All In-Reply-To: References: Message-ID: <57c63afe1003030526jc7a2107k27d90e41f0815384@mail.gmail.com> On Wed, Mar 3, 2010 at 2:16 AM, vtr wrote: > Hi All, > > This is Thiyagarajan Veluchamy from India, i am new to rspec. gI need > to learn rspec. Can anyone guide me, how to start properly. > Advance Thanks, Hi Thiyagarajan. Welcome to Rspec and this mailing list. If you're interested in participating, please read http://wiki.github.com/dchelimsky/rspec/get-in-touch. We're here to answer specific questions, but vague questions like "how do I start properly" are much better suited for google than this list: http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=getting+started+with+rspec Looking forward to your specific questions. Cheers, David From dchelimsky at gmail.com Wed Mar 3 08:38:43 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 3 Mar 2010 07:38:43 -0600 Subject: [rspec-users] requiring "test_notifier/rspec" in spec,opts In-Reply-To: References: <6673165f-29d4-4a9e-8bb8-ec94f0b1b3e5@t41g2000yqt.googlegroups.com> <57c63afe1003021133w3b32bea3j2970251f0bc59b57@mail.gmail.com> Message-ID: <57c63afe1003030538t3e635f26ja3e2137c640bde26@mail.gmail.com> On Tue, Mar 2, 2010 at 3:13 PM, drewB wrote: > I may not have been clear. ?When I said if I add it to the top of my > spec.opts file, I meant adding, '--require "test_notifier/rspec"'. > > Nevertheless, I tried you suggestion (a very good one). > Unfortunately, it seems that it must be required before "require > File.expand_path(File.join(File.dirname(__FILE__),'..','config','environment'))" > or the following error appears: > > /usr/local/lib/site_ruby/1.8/rubygems.rb:270:in `activate': You have a > nil object when you didn't expect it! (NoMethodError) > You might have expected an instance of Array. > The error occurred while evaluating nil.map If you know where it works in the spec_helper file, then you can do what I suggested before, but in a new directory. So right now in spec_helper you've got something like: Dir['spec/support/*_.rb'].each {|f| require f} Do the same thing, but put your helpers in a separate directory, and include that _before_ the line that requires 'config/environment' Dir['spec/before_rails_loads/*_.rb'].each {|f| require f} require File.expand_path(File.join(File.dirname(__FILE__),'..','config','environment')) HTH, David > > On Mar 2, 11:33?am, David Chelimsky wrote: >> On Tue, Mar 2, 2010 at 1:22 PM, drewB wrote: >> > There is a nice little gem that gives you desktop notifications of >> > your spec commands called test_noitifer (http://github.com/fnando/ >> > test_notifier). ?I can get it to work by including require >> > "test_notifier/rspec" toward the top of my spec_helper, or by manually >> > including it in the command line like: >> >> > spec --require "test_notifier/rspec" >> >> > However, if I add it to the top of my spec.opts file, I get the >> > following error: >> >> > /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in >> > `gem_original_require': no such file to load -- "test_notifier/ >> > rspec" (LoadError) >> >> > Any ideas on how to make it work? ?I don't want to add it to >> > spec_helper because then others on my team would need to use the gem >> > as well (which they might not want to). >> >> spec.opts is not a ruby file, so you can't put it there. Why not add >> it to a ruby file in spec/support/ that you don't keep in source >> control? >> _______________________________________________ >> rspec-users mailing list >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailinglists at patmaddox.com Wed Mar 3 10:30:58 2010 From: mailinglists at patmaddox.com (Pat Maddox) Date: Wed, 3 Mar 2010 07:30:58 -0800 Subject: [rspec-users] Hi All In-Reply-To: <57c63afe1003030526jc7a2107k27d90e41f0815384@mail.gmail.com> References: <57c63afe1003030526jc7a2107k27d90e41f0815384@mail.gmail.com> Message-ID: <423E4759-C34A-4E45-9965-CEB6F0DB51A9@patmaddox.com> On Mar 3, 2010, at 5:26 AM, David Chelimsky wrote: > On Wed, Mar 3, 2010 at 2:16 AM, vtr wrote: >> Hi All, >> >> This is Thiyagarajan Veluchamy from India, i am new to rspec. gI need >> to learn rspec. Can anyone guide me, how to start properly. >> Advance Thanks, > > Hi Thiyagarajan. Welcome to Rspec and this mailing list. If you're > interested in participating, please read > http://wiki.github.com/dchelimsky/rspec/get-in-touch. We're here to > answer specific questions, but vague questions like "how do I start > properly" are much better suited for google than this list: > > http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=getting+started+with+rspec > > Looking forward to your specific questions. > > Cheers, > David Also, buy and study http://www.pragprog.com/titles/achbd/the-rspec-book :) From reed.adam at gmail.com Wed Mar 3 11:08:15 2010 From: reed.adam at gmail.com (Adam R) Date: Wed, 3 Mar 2010 08:08:15 -0800 (PST) Subject: [rspec-users] RSpec and Watir, easy script structure question In-Reply-To: <27758607.post@talk.nabble.com> References: <27758607.post@talk.nabble.com> Message-ID: <27770149.post@talk.nabble.com> Thanks again for the parse/execute perspective Matt, that really sorted me out. Solution: Hey dummy, collect the data and create the array before starting the describe function. Moral of the story: I was trying to make collecting the data that I wanted to verify part of the test/spec, partially because I had it stuck in my head that 'everything' had to be inside a describe block, and partially because I was treating RSpec like some new alien technology instead of a Ruby library. Code: @Array = [...] or Method to collect array data @array.each do |name, stuff| describe name do it "should put the lotion in the basket" do end end end -- View this message in context: http://old.nabble.com/RSpec-and-Watir%2C-easy-script-structure-question-tp27758607p27770149.html Sent from the rspec-users mailing list archive at Nabble.com. From dbatshaw at gmail.com Wed Mar 3 13:24:45 2010 From: dbatshaw at gmail.com (drewB) Date: Wed, 3 Mar 2010 10:24:45 -0800 (PST) Subject: [rspec-users] Integration testing without cucumber In-Reply-To: <57c63afe1003021554m7b0e90bs3b86847ac97f2691@mail.gmail.com> References: <968ea143-57a0-4c04-bc52-5f67e8504b8d@q16g2000yqq.googlegroups.com> <0ECC405F-73FA-4CC0-AC26-3B002BC81BF0@wincent.com> <28d51163-d2af-41f9-b98a-d989dfb0621f@c16g2000yqd.googlegroups.com> <57c63afe1003011504n443328e5k1fb2f9f1ad944951@mail.gmail.com> <8e285398-3c55-4223-aeae-b0e12b914c8c@e1g2000yqh.googlegroups.com> <3f3dcb43-7bdd-4c0a-8145-2ad434b470cc@33g2000yqj.googlegroups.com> <57c63afe1003021554m7b0e90bs3b86847ac97f2691@mail.gmail.com> Message-ID: <48fa2440-24cd-46d9-90e1-2a2e7191e5f6@q16g2000yqq.googlegroups.com> Let me start by saying thank you for the time you are spending helping me. It appears to be a rails version issue. I ran though the same steps you outlined on my machine and continued to get the same error message, "undefined method `be_success'". I am running rspec 1.3.0, rspec-rails 1.3.2, rails 2.3.4. When I upgraded to rails 2.3.5 and tried again, everything worked. The project I am working on is frozen at rails 2.1.2 so am still looking for a way to get this to work with rails 2.1.2. Should I downgrade to an earlier version of RSpec or spec-rails? If so, which one? On Mar 2, 3:54?pm, David Chelimsky wrote: > On Tue, Mar 2, 2010 at 11:53 AM, drewB wrote: > > Looks like I spoke too soon. ?I made a mistake when testing your > > suggest. ?When I add that I still get the same failure. > > I just did the following using rails 2.3.5, rspec 1.3.2 and rspec-rails 1.3.0: > > $ rails foo > $ cd foo > $ script/generate rspec > $ mkdir spec/integration > $ script/generate integration_spec widgets > $ rake db:migrate && db:test:prepare > > Then I modified spec/integration/widgets_spec.rb as follows: > > require 'spec_helper' > > describe "Widgets" do > ? it "shows me the list" do > ? ? get "/widgets" > ? ? response.should be_success > ? end > end > > Then I ran this: > > $ script/spec spec/integration/ > > And here's the output I saw: > > F > > 1) > 'Widgets ..' FAILED > expected success? to return true, got false > /Users/dchelimsky/tmp/foo/spec/integration/widgets_spec.rb:6: > > So everything is working as it should on a fresh app. Did you update > spec/spec_helper.rb the last time you upgraded the app? Are you using > an earlier version of rspec-rails or rspec? > > > > > > > On Mar 1, 4:06?pm, drewB wrote: > >> That fixed it! Thanks! > > >> Any idea why that was needed for integration specs and not MVCs? > > >> On Mar 1, 3:04?pm, David Chelimsky wrote: > > >> > On Mon, Mar 1, 2010 at 4:59 PM, drewB wrote: > >> > > Belwo is a spec that when used with the default spec_helper fails > >> > > with: > > >> > > NoMethodError in 'test matchers should be able to find be_success' > >> > > undefined method `be_success' for > >> > > # > > >> > > ---------- > > >> > > require 'spec_helper' > > >> > > describe "test matchers" do > >> > > ?it "should be able to find be_success" do > >> > > ? ?get '/' > >> > > ? ?response.should be_success > >> > > ?end > > >> > > end > > >> > Try adding this to spec/spec_helper.rb > > >> > Spec::Runner.configure {|c| c.include Spec::Matchers} > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Wed Mar 3 13:38:21 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 3 Mar 2010 12:38:21 -0600 Subject: [rspec-users] Integration testing without cucumber In-Reply-To: <48fa2440-24cd-46d9-90e1-2a2e7191e5f6@q16g2000yqq.googlegroups.com> References: <968ea143-57a0-4c04-bc52-5f67e8504b8d@q16g2000yqq.googlegroups.com> <0ECC405F-73FA-4CC0-AC26-3B002BC81BF0@wincent.com> <28d51163-d2af-41f9-b98a-d989dfb0621f@c16g2000yqd.googlegroups.com> <57c63afe1003011504n443328e5k1fb2f9f1ad944951@mail.gmail.com> <8e285398-3c55-4223-aeae-b0e12b914c8c@e1g2000yqh.googlegroups.com> <3f3dcb43-7bdd-4c0a-8145-2ad434b470cc@33g2000yqj.googlegroups.com> <57c63afe1003021554m7b0e90bs3b86847ac97f2691@mail.gmail.com> <48fa2440-24cd-46d9-90e1-2a2e7191e5f6@q16g2000yqq.googlegroups.com> Message-ID: <57c63afe1003031038x1f3e2759p1a59a0668581e708@mail.gmail.com> On Wed, Mar 3, 2010 at 12:24 PM, drewB wrote: > Let me start by saying thank you for the time you are spending helping > me. You're welcome. > It appears to be a rails version issue. ?I ran though the same steps > you outlined on my machine and continued to get the same error > message, "undefined method `be_success'". ?I am running rspec 1.3.0, > rspec-rails 1.3.2, rails 2.3.4. ?When I upgraded to rails 2.3.5 and > tried again, everything worked. > > The project I am working on is frozen at rails 2.1.2 so am still > looking for a way to get this to work with rails 2.1.2. ?Should I > downgrade to an earlier version of RSpec or spec-rails? ?If so, which > one? 1.3.2 is tested against the last fix release of each series: 2.3.5, 2.2.2, 2.1.2, 2.0.5. So it should work with 2.1.2. If not, it's a bug, so go ahead and file a bug report at http://rspec.lighthouseapp.com - feel free to reference this thread. Cheers, David > > On Mar 2, 3:54?pm, David Chelimsky wrote: >> On Tue, Mar 2, 2010 at 11:53 AM, drewB wrote: >> > Looks like I spoke too soon. ?I made a mistake when testing your >> > suggest. ?When I add that I still get the same failure. >> >> I just did the following using rails 2.3.5, rspec 1.3.2 and rspec-rails 1.3.0: >> >> $ rails foo >> $ cd foo >> $ script/generate rspec >> $ mkdir spec/integration >> $ script/generate integration_spec widgets >> $ rake db:migrate && db:test:prepare >> >> Then I modified spec/integration/widgets_spec.rb as follows: >> >> require 'spec_helper' >> >> describe "Widgets" do >> ? it "shows me the list" do >> ? ? get "/widgets" >> ? ? response.should be_success >> ? end >> end >> >> Then I ran this: >> >> $ script/spec spec/integration/ >> >> And here's the output I saw: >> >> F >> >> 1) >> 'Widgets ..' FAILED >> expected success? to return true, got false >> /Users/dchelimsky/tmp/foo/spec/integration/widgets_spec.rb:6: >> >> So everything is working as it should on a fresh app. Did you update >> spec/spec_helper.rb the last time you upgraded the app? Are you using >> an earlier version of rspec-rails or rspec? >> >> >> >> >> >> > On Mar 1, 4:06?pm, drewB wrote: >> >> That fixed it! Thanks! >> >> >> Any idea why that was needed for integration specs and not MVCs? >> >> >> On Mar 1, 3:04?pm, David Chelimsky wrote: >> >> >> > On Mon, Mar 1, 2010 at 4:59 PM, drewB wrote: >> >> > > Belwo is a spec that when used with the default spec_helper fails >> >> > > with: >> >> >> > > NoMethodError in 'test matchers should be able to find be_success' >> >> > > undefined method `be_success' for >> >> > > # >> >> >> > > ---------- >> >> >> > > require 'spec_helper' >> >> >> > > describe "test matchers" do >> >> > > ?it "should be able to find be_success" do >> >> > > ? ?get '/' >> >> > > ? ?response.should be_success >> >> > > ?end >> >> >> > > end >> >> >> > Try adding this to spec/spec_helper.rb >> >> >> > Spec::Runner.configure {|c| c.include Spec::Matchers} >> >> _______________________________________________ >> rspec-users mailing list >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dbatshaw at gmail.com Wed Mar 3 14:33:15 2010 From: dbatshaw at gmail.com (drewB) Date: Wed, 3 Mar 2010 11:33:15 -0800 (PST) Subject: [rspec-users] requiring "test_notifier/rspec" in spec,opts In-Reply-To: <57c63afe1003030538t3e635f26ja3e2137c640bde26@mail.gmail.com> References: <6673165f-29d4-4a9e-8bb8-ec94f0b1b3e5@t41g2000yqt.googlegroups.com> <57c63afe1003021133w3b32bea3j2970251f0bc59b57@mail.gmail.com> <57c63afe1003030538t3e635f26ja3e2137c640bde26@mail.gmail.com> Message-ID: Thank you. That makes perfect sense. Just in case anyone else comes across this, for me to include spec/ before_rails_loads/test_notifer.rb I needed to remove the underscore so: Dir['spec/before_rails_loads/*.rb'].each {|f| require f} On Mar 3, 5:38?am, David Chelimsky wrote: > On Tue, Mar 2, 2010 at 3:13 PM, drewB wrote: > > I may not have been clear. ?When I said if I add it to the top of my > > spec.opts file, I meant adding, '--require "test_notifier/rspec"'. > > > Nevertheless, I tried you suggestion (a very good one). > > Unfortunately, it seems that it must be required before "require > > File.expand_path(File.join(File.dirname(__FILE__),'..','config','environment'))" > > or the following error appears: > > > /usr/local/lib/site_ruby/1.8/rubygems.rb:270:in `activate': You have a > > nil object when you didn't expect it! (NoMethodError) > > You might have expected an instance of Array. > > The error occurred while evaluating nil.map > > If you know where it works in the spec_helper file, then you can do > what I suggested before, but in a new directory. So right now in > spec_helper you've got something like: > > ? Dir['spec/support/*_.rb'].each {|f| require f} > > Do the same thing, but put your helpers in a separate directory, and > include that _before_ the line that requires 'config/environment' > > ? Dir['spec/before_rails_loads/*_.rb'].each {|f| require f} > ? require File.expand_path(File.join(File.dirname(__FILE__),'..','config','environment')) > > HTH, > David > > > > > > > On Mar 2, 11:33?am, David Chelimsky wrote: > >> On Tue, Mar 2, 2010 at 1:22 PM, drewB wrote: > >> > There is a nice little gem that gives you desktop notifications of > >> > your spec commands called test_noitifer (http://github.com/fnando/ > >> > test_notifier). ?I can get it to work by including require > >> > "test_notifier/rspec" toward the top of my spec_helper, or by manually > >> > including it in the command line like: > > >> > spec --require "test_notifier/rspec" > > >> > However, if I add it to the top of my spec.opts file, I get the > >> > following error: > > >> > /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in > >> > `gem_original_require': no such file to load -- "test_notifier/ > >> > rspec" (LoadError) > > >> > Any ideas on how to make it work? ?I don't want to add it to > >> > spec_helper because then others on my team would need to use the gem > >> > as well (which they might not want to). > > >> spec.opts is not a ruby file, so you can't put it there. Why not add > >> it to a ruby file in spec/support/ that you don't keep in source > >> control? > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From stefan.kanev at gmail.com Wed Mar 3 15:43:53 2010 From: stefan.kanev at gmail.com (Stefan Kanev) Date: Wed, 3 Mar 2010 21:43:53 +0100 Subject: [rspec-users] Disabling database access in controller specs Message-ID: <285b75bb1003031243x316a2830sa947bb5bdf52b2fe@mail.gmail.com> It took a while, but now I an totally convinced that controller specs should not access the database and stub as much as possible. I'm committed to that style of writing, yet from time to time I incidentally allow it to happen. Is there a way to err on the safe side and have RSpec throw an error every time a controller spec attempts to access the database? And does it sound like a good idea? Thanks, Stefan -------------- next part -------------- An HTML attachment was scrubbed... URL: From matt at mattwynne.net Wed Mar 3 17:54:34 2010 From: matt at mattwynne.net (Matt Wynne) Date: Wed, 3 Mar 2010 22:54:34 +0000 Subject: [rspec-users] Disabling database access in controller specs In-Reply-To: <285b75bb1003031243x316a2830sa947bb5bdf52b2fe@mail.gmail.com> References: <285b75bb1003031243x316a2830sa947bb5bdf52b2fe@mail.gmail.com> Message-ID: You could use something like NullDb to achieve this, I think: http://www.slideshare.net/bmabey/disconnecting-the-database-with-activerecord On 3 Mar 2010, at 20:43, Stefan Kanev wrote: > It took a while, but now I an totally convinced that controller > specs should not access the database and stub as much as possible. > I'm committed to that style of writing, yet from time to time I > incidentally allow it to happen. > > Is there a way to err on the safe side and have RSpec throw an error > every time a controller spec attempts to access the database? > > And does it sound like a good idea? > > Thanks, > Stefan > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users cheers, Matt http://mattwynne.net +447974 430184 From dchelimsky at gmail.com Wed Mar 3 21:29:08 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 3 Mar 2010 20:29:08 -0600 Subject: [rspec-users] rspec-2 update In-Reply-To: <57c63afe1003031743j4356cae4o80f166f77a4f158c@mail.gmail.com> References: <57c63afe1003031743j4356cae4o80f166f77a4f158c@mail.gmail.com> Message-ID: <57c63afe1003031829u24cdbe24p8f97ae64812efe50@mail.gmail.com> Hey all, rspec-2 is moving along nicely and we're at the point now where we'd love to see more people starting to use it, provide feedback, and hopefully start contributing as well. You can find the rspec-2 repositories under the rspec user on github: http://github.com/rspec. There are currently 6 repos: http://github.com/rspec http://github.com/rspec-core http://github.com/rspec-dev http://github.com/rspec-expectations http://github.com/rspec-mocks http://github.com/rspec-rails Here's a brief explanation of each: rspec is just a meta-gem, that depends on rspec-core, rspec-expectations, rspec-mocks. For users, you only need to "gem install rspec" (with --pre for now) and the rest is taken care of for you. rspec-core provides rspec's new runner, which comes from Chad Humphries' Micronaut, the describe and it methods (and their aliases), and the rspec command (which replaces the spec command). rspec-expectations provides "should" and "should_not" and matchers. rspec-mocks provides test double behaviour (stubbing and mocking) rspec-rails provides specialized example groups and matchers for rails-3 rspec-dev is for people like me who work on all of these libraries. You don't really need rspec-dev if you want to patch any one library, but it's useful if you plan to contribute to more than one. Each has a wiki and most have issues configured. Please feel free to start updating the wikis, entering issues, forking the repos and submitting pull requests. Our near term goal is to identify and document rspec-1 features that are missing from rspec-2. We'll want to get most of them working like rspec-1, but there will likely be some that we decide to stop supporting. In the latter case, we want to be sure that they are well documented so users don't get too surprised when they upgrade. There are cucumber features in the rspec-core, rspec-expectations, and rspec-mocks libraries. Please have a look at those as well. By the time we release 2.0 final, I'd like to be able to point to them as the definitive resource as to how to use rspec's features. As we identify missing features that we want to support in rspec 2.0, I want to be sure to add cukes for them. Let me know if you have any questions. Looking forward to your feedback and contributions! Cheers, David From dchelimsky at gmail.com Wed Mar 3 21:36:28 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 3 Mar 2010 20:36:28 -0600 Subject: [rspec-users] rspec-2 for rails-2???? Message-ID: <57c63afe1003031836ma07b191sc1118d8b7dd11cb9@mail.gmail.com> Hey all, rspec-rails-2 will only work with rails-3 (not rails-2). My suspicion is that once rspec-2 is out, folks are going to want to start using it with their existing rails-2 projects (because it offers some sweet new goodness that you won't want to live without). Would anybody be interested in writing and maintaining and rspec-2-rails-2 gem? This would be a separate code-base from rspec-rails, but we could keep the repo under the new rspec github user (http://github.com/rspec) provided that it is generally accepted and used by the community. Let me know if you're interested, or if you have any concerns about this approach. Cheers, David From me at franklakatos.com Thu Mar 4 01:03:57 2010 From: me at franklakatos.com (Frank Lakatos) Date: Thu, 4 Mar 2010 01:03:57 -0500 Subject: [rspec-users] Verify Order Message-ID: I may be missing something obvious, but how do I verify sort order? I have class Project < ActiveRecord::Base has_many :tasks, :order => "position" end I create a project, and 2 tasks: one with position = 1 and the other with position = 2. I want to verify that Project.tasks orders the tasks so that the task with position = 1 comes before the task with position = 2. Little push would be great, thanks Frank From godfoca at gmail.com Thu Mar 4 01:15:34 2010 From: godfoca at gmail.com (=?ISO-8859-1?Q?Nicol=E1s_Sanguinetti?=) Date: Thu, 4 Mar 2010 04:15:34 -0200 Subject: [rspec-users] Verify Order In-Reply-To: References: Message-ID: Assuming Project.tasks has :order => 'position ASC' then: describe Project do before do @project = Project.create @first_task = @project.tasks.create(:position => 1) @last_task = @project.tasks.create(:position => 2) end it "returns its tasks in order" do @project.tasks.should == [@first_task, @last_task] end end Will check that they are ordered. Cheers, -foca On Thu, Mar 4, 2010 at 4:03 AM, Frank Lakatos wrote: > I may be missing something obvious, but how do I verify sort order? > > I have > > class Project < ActiveRecord::Base > ?has_many :tasks, :order => "position" > end > > > I create a project, and 2 tasks: one with position = 1 and the other with > position = 2. I want to verify that Project.tasks orders the tasks so that > the task with position = 1 comes before the task with position = 2. > > Little push would be great, thanks > > Frank > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From aslak.hellesoy at gmail.com Thu Mar 4 02:58:53 2010 From: aslak.hellesoy at gmail.com (=?utf-8?Q?Aslak_Helles=C3=B8y?=) Date: Thu, 4 Mar 2010 08:58:53 +0100 Subject: [rspec-users] rspec-2 for rails-2???? In-Reply-To: <57c63afe1003031836ma07b191sc1118d8b7dd11cb9@mail.gmail.com> References: <57c63afe1003031836ma07b191sc1118d8b7dd11cb9@mail.gmail.com> Message-ID: <8D5E5421-8353-462E-9F20-77567988038E@gmail.com> > Hey all, > > rspec-rails-2 will only work with rails-3 (not rails-2). My suspicion > is that once rspec-2 is out, folks are going to want to start using it > with their existing rails-2 projects (because it offers some sweet new > goodness that you won't want to live without). > > Would anybody be interested in writing and maintaining and > rspec-2-rails-2 gem? This would be a separate code-base from > rspec-rails, but we could keep the repo under the new rspec github > user (http://github.com/rspec) provided that it is generally accepted > and used by the community. > FWIW, cucumber-rails supports both Rails2 and Rails3. If someone picks up the challenge it might be worthwhile to study the codebase. It uses some smart tricks to support both in the same codebase, without too much duplication. Maybe supporting both Rails2 and Rails3 in rspec-rails is a smaller effort than maintaining 2 gems? Aslak > Let me know if you're interested, or if you have any concerns about > this approach. > > Cheers, > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From rick.denatale at gmail.com Thu Mar 4 08:32:55 2010 From: rick.denatale at gmail.com (Rick DeNatale) Date: Thu, 4 Mar 2010 08:32:55 -0500 Subject: [rspec-users] rspec-2 update In-Reply-To: <57c63afe1003031829u24cdbe24p8f97ae64812efe50@mail.gmail.com> References: <57c63afe1003031743j4356cae4o80f166f77a4f158c@mail.gmail.com> <57c63afe1003031829u24cdbe24p8f97ae64812efe50@mail.gmail.com> Message-ID: On Wed, Mar 3, 2010 at 9:29 PM, David Chelimsky wrote: > Hey all, > > rspec-2 is moving along nicely and we're at the point now where we'd > love to see more people starting to use it, provide feedback, and > hopefully start contributing as well. > > You can find the rspec-2 repositories under the rspec user on github: > http://github.com/rspec. > > There are currently 6 repos: > > http://github.com/rspec > http://github.com/rspec-core > http://github.com/rspec-dev > http://github.com/rspec-expectations > http://github.com/rspec-mocks > http://github.com/rspec-rails I think those should be: http://github.com/rspec/rspec http://github.com/rspec/rspec-core http://github.com/rspec/rspec-dev http://github.com/rspec/rspec-expectations http://github.com/rspec/rspec-mocks http://github.com/rspec/rspec-rails -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale From dchelimsky at gmail.com Thu Mar 4 08:37:36 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 4 Mar 2010 07:37:36 -0600 Subject: [rspec-users] rspec-2 for rails-2???? In-Reply-To: <8D5E5421-8353-462E-9F20-77567988038E@gmail.com> References: <57c63afe1003031836ma07b191sc1118d8b7dd11cb9@mail.gmail.com> <8D5E5421-8353-462E-9F20-77567988038E@gmail.com> Message-ID: <57c63afe1003040537s70fb7369v2e9377c253fc942d@mail.gmail.com> On Thu, Mar 4, 2010 at 1:58 AM, Aslak Helles?y wrote: > > >> Hey all, >> >> rspec-rails-2 will only work with rails-3 (not rails-2). My suspicion >> is that once rspec-2 is out, folks are going to want to start using it >> with their existing rails-2 projects (because it offers some sweet new >> goodness that you won't want to live without). >> >> Would anybody be interested in writing and maintaining and >> rspec-2-rails-2 gem? This would be a separate code-base from >> rspec-rails, but we could keep the repo under the new rspec github >> user (http://github.com/rspec) provided that it is generally accepted >> and used by the community. >> > FWIW, cucumber-rails supports both Rails2 and Rails3. If someone picks up > the challenge it might be worthwhile to study the codebase. It uses some > smart tricks to support both in the same codebase, without too much > duplication. > > Maybe supporting both Rails2 and Rails3 in rspec-rails is a smaller effort > than maintaining 2 gems? I'm certainly open to the idea, but don't have cycles to investigate it myself. I'd welcome someone taking on this cause and submitting patches. Anyone interested? > > Aslak >> >> Let me know if you're interested, or if you have any concerns about >> this approach. >> >> 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 Thu Mar 4 08:47:10 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 4 Mar 2010 07:47:10 -0600 Subject: [rspec-users] rspec-2 update In-Reply-To: References: <57c63afe1003031743j4356cae4o80f166f77a4f158c@mail.gmail.com> <57c63afe1003031829u24cdbe24p8f97ae64812efe50@mail.gmail.com> Message-ID: <57c63afe1003040547r69f762edjdf06531e6f8532e4@mail.gmail.com> On Thu, Mar 4, 2010 at 7:32 AM, Rick DeNatale wrote: > On Wed, Mar 3, 2010 at 9:29 PM, David Chelimsky wrote: >> Hey all, >> >> rspec-2 is moving along nicely and we're at the point now where we'd >> love to see more people starting to use it, provide feedback, and >> hopefully start contributing as well. >> >> You can find the rspec-2 repositories under the rspec user on github: >> http://github.com/rspec. >> >> There are currently 6 repos: >> >> http://github.com/rspec >> http://github.com/rspec-core >> http://github.com/rspec-dev >> http://github.com/rspec-expectations >> http://github.com/rspec-mocks >> http://github.com/rspec-rails > > I think those should be: > > > http://github.com/rspec/rspec > http://github.com/rspec/rspec-core > http://github.com/rspec/rspec-dev > http://github.com/rspec/rspec-expectations > http://github.com/rspec/rspec-mocks > http://github.com/rspec/rspec-rails Yes, indeed. Thank you, Rick :) Cheers, David > > -- > Rick DeNatale > > Blog: http://talklikeaduck.denhaven2.com/ > Twitter: http://twitter.com/RickDeNatale > WWR: http://www.workingwithrails.com/person/9021-rick-denatale > LinkedIn: http://www.linkedin.com/in/rickdenatale > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Thu Mar 4 10:08:10 2010 From: lists at ruby-forum.com (Amit Kulkarni) Date: Thu, 4 Mar 2010 16:08:10 +0100 Subject: [rspec-users] Undefined method 'post' Message-ID: <9434c45a13a1e769df7e8e1bb834fd3f@ruby-forum.com> Hello all, I am facing a strange problem. I have generated rspec for a particular project.Similarly created a spec controller.Under that controller i have written post :create action When i run my spec i get an error as "undefined method `post' for #" Strangely my models are working fine.My rails version is 2.3.5 and rspec version is 1.1.12 I tried in some other project,in that i am getting error as "Undefined method controller for nil class" Earlier it was working fine,but dont know what is the problem. Please suggest. -- Posted via http://www.ruby-forum.com/. From dbatshaw at gmail.com Thu Mar 4 12:26:30 2010 From: dbatshaw at gmail.com (drewB) Date: Thu, 4 Mar 2010 09:26:30 -0800 (PST) Subject: [rspec-users] Integration testing without cucumber In-Reply-To: <57c63afe1003031038x1f3e2759p1a59a0668581e708@mail.gmail.com> References: <968ea143-57a0-4c04-bc52-5f67e8504b8d@q16g2000yqq.googlegroups.com> <0ECC405F-73FA-4CC0-AC26-3B002BC81BF0@wincent.com> <28d51163-d2af-41f9-b98a-d989dfb0621f@c16g2000yqd.googlegroups.com> <57c63afe1003011504n443328e5k1fb2f9f1ad944951@mail.gmail.com> <8e285398-3c55-4223-aeae-b0e12b914c8c@e1g2000yqh.googlegroups.com> <3f3dcb43-7bdd-4c0a-8145-2ad434b470cc@33g2000yqj.googlegroups.com> <57c63afe1003021554m7b0e90bs3b86847ac97f2691@mail.gmail.com> <48fa2440-24cd-46d9-90e1-2a2e7191e5f6@q16g2000yqq.googlegroups.com> <57c63afe1003031038x1f3e2759p1a59a0668581e708@mail.gmail.com> Message-ID: <83110f94-b06b-445a-95c0-26526158b928@y17g2000yqd.googlegroups.com> Bug filed. Any idea about an earlier version that I might try? On Mar 3, 10:38?am, David Chelimsky wrote: > On Wed, Mar 3, 2010 at 12:24 PM, drewB wrote: > > Let me start by saying thank you for the time you are spending helping > > me. > > You're welcome. > > > It appears to be a rails version issue. ?I ran though the same steps > > you outlined on my machine and continued to get the same error > > message, "undefined method `be_success'". ?I am running rspec 1.3.0, > > rspec-rails 1.3.2, rails 2.3.4. ?When I upgraded to rails 2.3.5 and > > tried again, everything worked. > > > The project I am working on is frozen at rails 2.1.2 so am still > > looking for a way to get this to work with rails 2.1.2. ?Should I > > downgrade to an earlier version of RSpec or spec-rails? ?If so, which > > one? > > 1.3.2 is tested against the last fix release of each series: 2.3.5, > 2.2.2, 2.1.2, 2.0.5. So it should work with 2.1.2. If not, it's a bug, > so go ahead and file a bug report athttp://rspec.lighthouseapp.com- > feel free to reference this thread. > > Cheers, > David > > > > > > > On Mar 2, 3:54?pm, David Chelimsky wrote: > >> On Tue, Mar 2, 2010 at 11:53 AM, drewB wrote: > >> > Looks like I spoke too soon. ?I made a mistake when testing your > >> > suggest. ?When I add that I still get the same failure. > > >> I just did the following using rails 2.3.5, rspec 1.3.2 and rspec-rails 1.3.0: > > >> $ rails foo > >> $ cd foo > >> $ script/generate rspec > >> $ mkdir spec/integration > >> $ script/generate integration_spec widgets > >> $ rake db:migrate && db:test:prepare > > >> Then I modified spec/integration/widgets_spec.rb as follows: > > >> require 'spec_helper' > > >> describe "Widgets" do > >> ? it "shows me the list" do > >> ? ? get "/widgets" > >> ? ? response.should be_success > >> ? end > >> end > > >> Then I ran this: > > >> $ script/spec spec/integration/ > > >> And here's the output I saw: > > >> F > > >> 1) > >> 'Widgets ..' FAILED > >> expected success? to return true, got false > >> /Users/dchelimsky/tmp/foo/spec/integration/widgets_spec.rb:6: > > >> So everything is working as it should on a fresh app. Did you update > >> spec/spec_helper.rb the last time you upgraded the app? Are you using > >> an earlier version of rspec-rails or rspec? > > >> > On Mar 1, 4:06?pm, drewB wrote: > >> >> That fixed it! Thanks! > > >> >> Any idea why that was needed for integration specs and not MVCs? > > >> >> On Mar 1, 3:04?pm, David Chelimsky wrote: > > >> >> > On Mon, Mar 1, 2010 at 4:59 PM, drewB wrote: > >> >> > > Belwo is a spec that when used with the default spec_helper fails > >> >> > > with: > > >> >> > > NoMethodError in 'test matchers should be able to find be_success' > >> >> > > undefined method `be_success' for > >> >> > > # > > >> >> > > ---------- > > >> >> > > require 'spec_helper' > > >> >> > > describe "test matchers" do > >> >> > > ?it "should be able to find be_success" do > >> >> > > ? ?get '/' > >> >> > > ? ?response.should be_success > >> >> > > ?end > > >> >> > > end > > >> >> > Try adding this to spec/spec_helper.rb > > >> >> > Spec::Runner.configure {|c| c.include Spec::Matchers} > > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Fri Mar 5 08:03:59 2010 From: lists at ruby-forum.com (Amit Kulkarni) Date: Fri, 5 Mar 2010 14:03:59 +0100 Subject: [rspec-users] Undefined method 'post' In-Reply-To: <9434c45a13a1e769df7e8e1bb834fd3f@ruby-forum.com> References: <9434c45a13a1e769df7e8e1bb834fd3f@ruby-forum.com> Message-ID: <5170faf6cf63695dedad0c38d342660b@ruby-forum.com> Amit Kulkarni wrote: > Hello all, > I am facing a strange problem. > I have generated rspec for a particular project.Similarly created a spec > controller.Under that controller i have written post :create action > When i run my spec i get an error as > "undefined method `post' for > #" > > Strangely my models are working fine.My rails version is 2.3.5 and rspec > version is 1.1.12 > I tried in some other project,in that i am getting error as "Undefined > method controller for nil class" > Earlier it was working fine,but dont know what is the problem. > Please suggest. I created a fresh application and tried to write simple user signup controller. But when i tried to run then it is showing the same error as undefined method "post" Please suggest -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Fri Mar 5 08:48:17 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 5 Mar 2010 07:48:17 -0600 Subject: [rspec-users] Undefined method 'post' In-Reply-To: <5170faf6cf63695dedad0c38d342660b@ruby-forum.com> References: <9434c45a13a1e769df7e8e1bb834fd3f@ruby-forum.com> <5170faf6cf63695dedad0c38d342660b@ruby-forum.com> Message-ID: <57c63afe1003050548k1c2a931bv2efc73886a9c1f58@mail.gmail.com> On Fri, Mar 5, 2010 at 7:03 AM, Amit Kulkarni wrote: > Amit Kulkarni wrote: >> Hello all, >> I am facing a strange problem. >> I have generated rspec for a particular project.Similarly created a spec >> controller.Under that controller i have written post :create action >> When i run my spec i get an error as >> "undefined method `post' for >> #" >> >> Strangely my models are working fine.My rails version is 2.3.5 and rspec >> version is 1.1.12 >> I tried in some other project,in that i am getting error as "Undefined >> method controller for nil class" >> Earlier it was working fine,but dont know what is the problem. >> Please suggest. > I created a fresh application and tried to write simple user signup > controller. > But when i tried to run then it is showing the same error as undefined > method "post" > Please suggest Take a look at these two pages: http://rubygems.org/gems/rspec-rails/versions http://rubygems.org/gems/rails/versions rspec-rails-1.1.12 was released in January of 2009 rails-2.3.5 was released in November of 2009 You've got to use a version of rspec-rails that was released _after_ the version of rails you're working with. Cheers, David From ashley.moran at patchspace.co.uk Sat Mar 6 11:34:57 2010 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Sat, 6 Mar 2010 16:34:57 +0000 Subject: [rspec-users] RSpec 2 / Rails 3 autoload Message-ID: Hi For the last 18 months I've been used to writing specs like this, which was written with Merb 1.1.0.pre and RSpec 1.3: module LanguageRepository describe DataMapperAdapter do it_should_behave_like "Contract: LanguageRepository" def language_repository DataMapperAdapter.new end end end This will happily find and instantiate ::LanguageRepository::DataMapperAdapter from the models/language_repository folder. However, using Rails 3.0.0.beta from master and Rspec 2.0.0.beta.2, I get the following error: 1) LanguageRepository::DataMapperAdapter storage and retrieval can store a Language and retrieve it by code Failure/Error: DataMapperAdapter.new uninitialized constant Rspec::Core::ExampleGroup::NestedLevel_8::DataMapperAdapter I have to change it to this to make it work: def language_repository LanguageRepository::DataMapperAdapter.new end Now, having just changed two moving parts (RSpec and web framework) I'm not sure what correct behaviour is on anything. I don't know how Rails code auto-loading works, or how RSpec interacts with it. Is the above behaviour a bug or a misunderstanding on my part? Cheers Ashley -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashleymoran From jarmo.p at gmail.com Sat Mar 6 12:09:32 2010 From: jarmo.p at gmail.com (Jarmo Pertman) Date: Sat, 6 Mar 2010 09:09:32 -0800 (PST) Subject: [rspec-users] how to pass objects from spec to formatter from before :all block? Message-ID: <3df161de-0154-4c0f-a3f4-711927f1243c@q21g2000yqm.googlegroups.com> Hello. I need to pass something from before :all to formatter. I know that i could use options hash from spec and then get the value back in formatter, but it doesn't work when i'm doing it from before :all. So, this work: # in spec before :each do options[:something] = 1 end # in formatter def example_failed(example, counter, failure) puts example.options[:something] # outputs 1 super end But if i try to do the same thing from before :all, then it doesn't work. So i looked into the source of RSpec and in example/example_methods.rb in method set_instance_variables_from_hash there is a line which ignores some instance variables among with others @_proxy, which has this option hash initialized in before :all and that's why it's not getting into the formatter - in other words it is just dropped. Is this a bug or expected behaviour? If it's expected then what's the reason and how could i get the desired results of passing something to formatter from before :all? Can't we just pass this options hash along? Jarmo From dchelimsky at gmail.com Sat Mar 6 12:28:59 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 6 Mar 2010 11:28:59 -0600 Subject: [rspec-users] how to pass objects from spec to formatter from before :all block? In-Reply-To: <3df161de-0154-4c0f-a3f4-711927f1243c@q21g2000yqm.googlegroups.com> References: <3df161de-0154-4c0f-a3f4-711927f1243c@q21g2000yqm.googlegroups.com> Message-ID: <57c63afe1003060928k59a489d2o37f4106d92c5c8fb@mail.gmail.com> On Sat, Mar 6, 2010 at 11:09 AM, Jarmo Pertman wrote: > Hello. > > I need to pass something from before :all to formatter. I know that i > could use options hash from spec and then get the value back in > formatter, but it doesn't work when i'm doing it from before :all. > > So, this work: > > # in spec > before :each do > ?options[:something] = 1 > end > > # in formatter > def example_failed(example, counter, failure) > ?puts example.options[:something] # outputs 1 > ?super > end > > But if i try to do the same thing from before :all, then it doesn't > work. > > So i looked into the source of RSpec and in example/example_methods.rb > in method set_instance_variables_from_hash there is a line which > ignores some instance variables among with others @_proxy, which has > this option hash initialized in before :all and that's why it's not > getting into the formatter - in other words it is just dropped. > > Is this a bug or expected behaviour? If it's expected then what's the > reason and how could i get the desired results of passing something to > formatter from before :all? > > Can't we just pass this options hash along? It was never intended that you would set values on options from inside an example and access them in a formatter. You've happened on something that just happens to work because we're using a standard Ruby data structure. The reason it won't work for before(:all) is that before(:all) gets run before any of the examples are run - so it doesn't have access to the options hash, which is created per example in rspec-1. What sort of information are you trying to get to your formatter? Maybe there is a different way to do it. From jarmo.p at gmail.com Sat Mar 6 13:33:20 2010 From: jarmo.p at gmail.com (Jarmo Pertman) Date: Sat, 6 Mar 2010 10:33:20 -0800 (PST) Subject: [rspec-users] how to pass objects from spec to formatter from before :all block? In-Reply-To: <57c63afe1003060928k59a489d2o37f4106d92c5c8fb@mail.gmail.com> References: <3df161de-0154-4c0f-a3f4-711927f1243c@q21g2000yqm.googlegroups.com> <57c63afe1003060928k59a489d2o37f4106d92c5c8fb@mail.gmail.com> Message-ID: <54f97986-2774-4e66-8e36-54240be7390a@g7g2000yqe.googlegroups.com> Since i'm using Watir then i usually open up the browser in before :all block like this: before :all do @browser = Watir::Browser.new end and then in the formatter I'm saving html of the browser - thus needing to access the browser object. I could solve it currently by using before :each block as shown in my first post or a global variable (not nice at all), but i thought that it would be more logical to set it into options in before :all once. Also, if using before :each solution and something fails in before :all, then formatter doesn't know currently anything about the browser object and cannot save the html or anything. It's little bit bad, since let's say if i do also some "setup actions" in before :all before the actual tests and what if something fails there? But what would happen if example_group options would be merged with example options? Any other solutions? Jarmo On Mar 6, 7:28?pm, David Chelimsky wrote: > On Sat, Mar 6, 2010 at 11:09 AM, Jarmo Pertman wrote: > > Hello. > > > I need to pass something from before :all to formatter. I know that i > > could use options hash from spec and then get the value back in > > formatter, but it doesn't work when i'm doing it from before :all. > > > So, this work: > > > # in spec > > before :each do > > ?options[:something] = 1 > > end > > > # in formatter > > def example_failed(example, counter, failure) > > ?puts example.options[:something] # outputs 1 > > ?super > > end > > > But if i try to do the same thing from before :all, then it doesn't > > work. > > > So i looked into the source of RSpec and in example/example_methods.rb > > in method set_instance_variables_from_hash there is a line which > > ignores some instance variables among with others @_proxy, which has > > this option hash initialized in before :all and that's why it's not > > getting into the formatter - in other words it is just dropped. > > > Is this a bug or expected behaviour? If it's expected then what's the > > reason and how could i get the desired results of passing something to > > formatter from before :all? > > > Can't we just pass this options hash along? > > It was never intended that you would set values on options from inside > an example and access them in a formatter. You've happened on > something that just happens to work because we're using a standard > Ruby data structure. > > The reason it won't work for before(:all) is that before(:all) gets > run before any of the examples are run - so it doesn't have access to > the options hash, which is created per example in rspec-1. > > What sort of information are you trying to get to your formatter? > Maybe there is a different way to do it. > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From ed.howland at gmail.com Sat Mar 6 14:21:21 2010 From: ed.howland at gmail.com (Ed Howland) Date: Sat, 6 Mar 2010 14:21:21 -0500 Subject: [rspec-users] Newlines in step arguments Was How can I pass an XML block... Message-ID: <3df642dd1003061121s63e65d66y143977644dbdb039@mail.gmail.com> On Tue, Apr 14, 2009 at 10:03 PM, Stephen Eley wrote: > On Tue, Apr 14, 2009 at 10:37 PM, Stephen Eley wrote: >> > All right, never mind. ?Having been given enough clues that the > feature exists and what it generally might look like, I prowled > through Cucumber's specs and examples until I got a clearer picture. > Then, to keep my 'There ain't no documentation!' whining privileges, I > went and added what I learned to the wiki: > > http://wiki.github.com/aslakhellesoy/cucumber/multiline-step-arguments > This is fantastic! I admit that I must gave skimmed over the that in the book, but your wiki page made it very clear. I wrote some steps that call a command and capture the output with IO at popen. In my code I was testing, I used puts everywhere and could not figure out how to match the newlines in Cuke, E.g. Then the output should be """ """ Scenarios: |command|args|output| |option|:dummy|-d, --[no]-dummy| ---- Thanks for the wiki page! > I'd call it my minor good deed for the day, but really I was using it > to procrastinate on my podcasting work for another half hour, so > overall it was morally neutral. > > > -- > Have Fun, > ? Steve Eley (sfeley at gmail.com) > ? ESCAPE POD - The Science Fiction Podcast Magazine > ? http://www.escapepod.org > Cheers, Ed Ed Howland http://greenprogrammer.wordpress.com http://twitter.com/ed_howland From lists at ruby-forum.com Sat Mar 6 17:31:50 2010 From: lists at ruby-forum.com (Nick Hoffman) Date: Sat, 6 Mar 2010 23:31:50 +0100 Subject: [rspec-users] Is share_examples_for deprecated? Message-ID: API Dock says that "share_examples_for" is deprecated. If that's correct, what should we be using instead? http://apidock.com/rspec/Spec/Extensions/Main/share_examples_for Thanks, Nick -- Posted via http://www.ruby-forum.com/. From mailinglists at patmaddox.com Sat Mar 6 18:34:07 2010 From: mailinglists at patmaddox.com (Pat Maddox) Date: Sat, 6 Mar 2010 15:34:07 -0800 Subject: [rspec-users] Is share_examples_for deprecated? In-Reply-To: References: Message-ID: describe "something something", :shared => true do ... end describe "chunky bacon" do it_should_behave_like "something something" end On Mar 6, 2010, at 2:31 PM, Nick Hoffman wrote: > API Dock says that "share_examples_for" is deprecated. If that's > correct, what should we be using instead? > > http://apidock.com/rspec/Spec/Extensions/Main/share_examples_for > > Thanks, > Nick > -- > 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 Sat Mar 6 18:45:24 2010 From: lists at ruby-forum.com (Nick Hoffman) Date: Sun, 7 Mar 2010 00:45:24 +0100 Subject: [rspec-users] Is share_examples_for deprecated? In-Reply-To: References: Message-ID: <5cb1ee409ead22ae990410a4b831dec8@ruby-forum.com> Pat Maddox wrote: > describe "something something", :shared => true do > ... > end > > describe "chunky bacon" do > it_should_behave_like "something something" > end Thanks, mate. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Sat Mar 6 23:21:34 2010 From: lists at ruby-forum.com (Nick Hoffman) Date: Sun, 7 Mar 2010 05:21:34 +0100 Subject: [rspec-users] Is share_examples_for deprecated? In-Reply-To: References: Message-ID: Pat Maddox wrote: > describe "something something", :shared => true do > ... > end > > describe "chunky bacon" do > it_should_behave_like "something something" > end BTW, is rspec.info supposed to be up-to-date? It still recommends using "shared_examples_for". http://rspec.info/documentation/ -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Sun Mar 7 07:43:47 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 7 Mar 2010 06:43:47 -0600 Subject: [rspec-users] Is share_examples_for deprecated? In-Reply-To: References: Message-ID: <57c63afe1003070443k3473f61ay69426feb7765f99f@mail.gmail.com> On Sat, Mar 6, 2010 at 10:21 PM, Nick Hoffman wrote: > Pat Maddox wrote: >> describe "something something", :shared => true do >> ? ... >> end >> >> describe "chunky bacon" do >> ? it_should_behave_like "something something" >> end > > BTW, is rspec.info supposed to be up-to-date? It still recommends using > "shared_examples_for". > > http://rspec.info/documentation/ So this presents an interesting problem :) My intent some time back was to deprecate :shared => true, not share_examples_for (which is aliased with shared_examples_for). Based on that, the rspec.info site is correct and Pat is incorrect. However, Pat didn't know that because I never communicated it in any other way besides documenting the method on the site. Now as we're introducing rspec-2 to the mix, option hashes passed to describe and it will become much more common. On the grounds that it would simplify the API, it seems to me it might make more sense in rspec-2 to use :shared => true and get rid of these methods. Thoughts? David From dchelimsky at gmail.com Sun Mar 7 08:12:09 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 7 Mar 2010 07:12:09 -0600 Subject: [rspec-users] how to pass objects from spec to formatter from before :all block? In-Reply-To: <54f97986-2774-4e66-8e36-54240be7390a@g7g2000yqe.googlegroups.com> References: <3df161de-0154-4c0f-a3f4-711927f1243c@q21g2000yqm.googlegroups.com> <57c63afe1003060928k59a489d2o37f4106d92c5c8fb@mail.gmail.com> <54f97986-2774-4e66-8e36-54240be7390a@g7g2000yqe.googlegroups.com> Message-ID: <57c63afe1003070512h2d92e57au808342d46079984@mail.gmail.com> On Sat, Mar 6, 2010 at 12:33 PM, Jarmo Pertman wrote: > Since i'm using Watir > then i usually open up the browser in > before :all block like this: > before :all do > ?@browser = Watir::Browser.new > end > > and then in the formatter I'm saving html of the browser - thus > needing to access the browser object. You should have access to it from within each example. This would be a bit noisier, but you could do this: before(:all) do @browser = Watir::Browser.new end before(:each) do options[:browser] = @browser end Even though that's noisier, you could easily encapsulate that in a method: def with_new_browser before(:all) do @browser = Watir::Browser.new end before(:each) do options[:browser] = @browser end yield end describe "the home page" do with_new_browser do it "looks awesome" do # .... end it "takes you where you want to go" do # ... end end end > I could solve it currently by using before :each block as shown in my > first post or a global variable (not nice at all), but i thought that > it would be more logical to set it into options in before :all once. > > Also, if using before :each solution and something fails in > before :all, then formatter doesn't know currently anything about the > browser object and cannot save the html or anything. It's little bit > bad, since let's say if i do also some "setup actions" in before :all > before the actual tests and what if something fails there? after(:each) and after(:all) are guaranteed to run regardless of what happens in before(:each), before(:all), and the examples themselves. So you could deliver the browser there: def with_new_browser before(:all) do @browser = Watir::Browser.new end yield after(:each) do options[:browser] = @browser end end > But what would happen if example_group options would be merged with > example options? In rspec-1 that would be problematic, but this is already supported in rspec-2 out of the box, so you may want to give rspec-2 a try. > > Any other solutions? > > Jarmo > > On Mar 6, 7:28?pm, David Chelimsky wrote: >> On Sat, Mar 6, 2010 at 11:09 AM, Jarmo Pertman wrote: >> > Hello. >> >> > I need to pass something from before :all to formatter. I know that i >> > could use options hash from spec and then get the value back in >> > formatter, but it doesn't work when i'm doing it from before :all. >> >> > So, this work: >> >> > # in spec >> > before :each do >> > ?options[:something] = 1 >> > end >> >> > # in formatter >> > def example_failed(example, counter, failure) >> > ?puts example.options[:something] # outputs 1 >> > ?super >> > end >> >> > But if i try to do the same thing from before :all, then it doesn't >> > work. >> >> > So i looked into the source of RSpec and in example/example_methods.rb >> > in method set_instance_variables_from_hash there is a line which >> > ignores some instance variables among with others @_proxy, which has >> > this option hash initialized in before :all and that's why it's not >> > getting into the formatter - in other words it is just dropped. >> >> > Is this a bug or expected behaviour? If it's expected then what's the >> > reason and how could i get the desired results of passing something to >> > formatter from before :all? >> >> > Can't we just pass this options hash along? >> >> It was never intended that you would set values on options from inside >> an example and access them in a formatter. You've happened on >> something that just happens to work because we're using a standard >> Ruby data structure. >> >> The reason it won't work for before(:all) is that before(:all) gets >> run before any of the examples are run - so it doesn't have access to >> the options hash, which is created per example in rspec-1. >> >> What sort of information are you trying to get to your formatter? >> Maybe there is a different way to do it. >> _______________________________________________ >> rspec-users mailing list >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jarmo.p at gmail.com Sun Mar 7 08:47:48 2010 From: jarmo.p at gmail.com (Jarmo Pertman) Date: Sun, 7 Mar 2010 05:47:48 -0800 (PST) Subject: [rspec-users] how to pass objects from spec to formatter from before :all block? In-Reply-To: <57c63afe1003070512h2d92e57au808342d46079984@mail.gmail.com> References: <3df161de-0154-4c0f-a3f4-711927f1243c@q21g2000yqm.googlegroups.com> <57c63afe1003060928k59a489d2o37f4106d92c5c8fb@mail.gmail.com> <54f97986-2774-4e66-8e36-54240be7390a@g7g2000yqe.googlegroups.com> <57c63afe1003070512h2d92e57au808342d46079984@mail.gmail.com> Message-ID: <673df843-f5bd-4df3-ba5c-f3837149526c@x22g2000yqx.googlegroups.com> Thank you for your thoughts. Unfortunately it seems that after :each is not run if before :all fails... And after :all is ran after example_failed in formatter. Consider spec like this: describe "something" do before :all do p "before" raise end it "does" do p "it" end after :each do p "each" end after :all do p "all" end end Output of it will be: "before" F"all" In other words, I'd have to put @browser into options in before :all AND in after :each. After :each is actually a good place, because then if @browser object is changed within the it block, then formatter gets correct browser object nevertheless. It will be messier of course, but I thought that I'd use Spec::Runner.configure in spec_helper or somewhere: Spec::Runner.configure do |config| config.before(:all) {@browser = options[:browser] = Watir::Browser.new} config.after(:each) {options[:browser] = @browser} end Does it make sense? In that way i wouldn't have to write my specs by using any custom way (like you demonstrated with your method with_new_browser. It would be great of course if i wouldn't have to fill options two times. Jarmo On Mar 7, 3:12?pm, David Chelimsky wrote: > On Sat, Mar 6, 2010 at 12:33 PM, Jarmo Pertman wrote: > > Since i'm using Watir > > then i usually open up the browser in > > before :all block like this: > > before :all do > > ?@browser = Watir::Browser.new > > end > > > and then in the formatter I'm saving html of the browser - thus > > needing to access the browser object. > > You should have access to it from within each example. This would be a > bit noisier, but you could do this: > > before(:all) do > ? @browser = Watir::Browser.new > end > before(:each) do > ? options[:browser] = @browser > end > > Even though that's noisier, you could easily encapsulate that in a method: > > def with_new_browser > ? before(:all) do > ? ? @browser = Watir::Browser.new > ? end > ? before(:each) do > ? ? options[:browser] = @browser > ? end > ? yield > end > > describe "the home page" do > ? with_new_browser do > ? ? it "looks awesome" do > ? ? ? # .... > ? ? end > ? ? it "takes you where you want to go" do > ? ? ? # ... > ? ? end > ? end > end > > > I could solve it currently by using before :each block as shown in my > > first post or a global variable (not nice at all), but i thought that > > it would be more logical to set it into options in before :all once. > > > Also, if using before :each solution and something fails in > > before :all, then formatter doesn't know currently anything about the > > browser object and cannot save the html or anything. It's little bit > > bad, since let's say if i do also some "setup actions" in before :all > > before the actual tests and what if something fails there? > > after(:each) and after(:all) are guaranteed to run regardless of what > happens in before(:each), before(:all), and the examples > themselves. So you could deliver the browser there: > > def with_new_browser > ? before(:all) do > ? ? @browser = Watir::Browser.new > ? end > ? yield > ? after(:each) do > ? ? options[:browser] = @browser > ? end > end > > > But what would happen if example_group options would be merged with > > example options? > > In rspec-1 that would be problematic, but this is already supported in > rspec-2 out of the box, so you may want to give rspec-2 a try. > > > > > > > > > Any other solutions? > > > Jarmo > > > On Mar 6, 7:28?pm, David Chelimsky wrote: > >> On Sat, Mar 6, 2010 at 11:09 AM, Jarmo Pertman wrote: > >> > Hello. > > >> > I need to pass something from before :all to formatter. I know that i > >> > could use options hash from spec and then get the value back in > >> > formatter, but it doesn't work when i'm doing it from before :all. > > >> > So, this work: > > >> > # in spec > >> > before :each do > >> > ?options[:something] = 1 > >> > end > > >> > # in formatter > >> > def example_failed(example, counter, failure) > >> > ?puts example.options[:something] # outputs 1 > >> > ?super > >> > end > > >> > But if i try to do the same thing from before :all, then it doesn't > >> > work. > > >> > So i looked into the source of RSpec and in example/example_methods.rb > >> > in method set_instance_variables_from_hash there is a line which > >> > ignores some instance variables among with others @_proxy, which has > >> > this option hash initialized in before :all and that's why it's not > >> > getting into the formatter - in other words it is just dropped. > > >> > Is this a bug or expected behaviour? If it's expected then what's the > >> > reason and how could i get the desired results of passing something to > >> > formatter from before :all? > > >> > Can't we just pass this options hash along? > > >> It was never intended that you would set values on options from inside > >> an example and access them in a formatter. You've happened on > >> something that just happens to work because we're using a standard > >> Ruby data structure. > > >> The reason it won't work for before(:all) is that before(:all) gets > >> run before any of the examples are run - so it doesn't have access to > >> the options hash, which is created per example in rspec-1. > > >> What sort of information are you trying to get to your formatter? > >> Maybe there is a different way to do it. > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Sun Mar 7 09:59:25 2010 From: lists at ruby-forum.com (Nick Hoffman) Date: Sun, 7 Mar 2010 15:59:25 +0100 Subject: [rspec-users] Is share_examples_for deprecated? In-Reply-To: <57c63afe1003070443k3473f61ay69426feb7765f99f@mail.gmail.com> References: <57c63afe1003070443k3473f61ay69426feb7765f99f@mail.gmail.com> Message-ID: <55efe2143b828abfd8ee9b107dea854c@ruby-forum.com> David Chelimsky wrote: > So this presents an interesting problem :) > > My intent some time back was to deprecate :shared => true, not > share_examples_for (which is aliased with shared_examples_for). Based > on that, the rspec.info site is correct and Pat is incorrect. However, > Pat didn't know that because I never communicated it in any other way > besides documenting the method on the site. > > Now as we're introducing rspec-2 to the mix, option hashes passed to > describe and it will become much more common. On the grounds that it > would simplify the API, it seems to me it might make more sense in > rspec-2 to use :shared => true and get rid of these methods. > > Thoughts? > > David I'm a fan of "shared_examples_for", because it's beautifully descriptive of what the purpose of its block is: sharing its examples with other example groups. Passing ":shared => true" to a "describe" is less obvious to me, simply because it doesn't stand out. This is especially true when ":shared => true" is at the end of a long string. Eg: http://pastie.org/858196 Cheers, Nick -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Sun Mar 7 10:45:55 2010 From: lists at ruby-forum.com (Russell Fine) Date: Sun, 7 Mar 2010 16:45:55 +0100 Subject: [rspec-users] How to test an app with multiple databases? Message-ID: Our app connects to two databases. The main database (through ActiveRecord::Base) is automatically cleared before each test. How do I force the clear of the secondary database as well ? Thanks in advance... Russell -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Sun Mar 7 10:50:13 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 7 Mar 2010 09:50:13 -0600 Subject: [rspec-users] How to test an app with multiple databases? In-Reply-To: References: Message-ID: <57c63afe1003070750i50f27b31l267ce6966f087ea5@mail.gmail.com> On Sun, Mar 7, 2010 at 9:45 AM, Russell Fine wrote: > Our app connects to two databases. ?The main database (through > ActiveRecord::Base) is automatically cleared before each test. ?How do I > force the clear of the secondary database as well ? There's no implicit support for this, so you'd have to do something manually in a before(:each) block. You can do that in the configuration (usually in spec_helper): Spec::Runner.configure do |c| c.before(:each) do # clear out 2ndary db end end HTH, David From lists at ruby-forum.com Sun Mar 7 11:11:15 2010 From: lists at ruby-forum.com (Russell Fine) Date: Sun, 7 Mar 2010 17:11:15 +0100 Subject: [rspec-users] How to test an app with multiple databases? In-Reply-To: <57c63afe1003070750i50f27b31l267ce6966f087ea5@mail.gmail.com> References: <57c63afe1003070750i50f27b31l267ce6966f087ea5@mail.gmail.com> Message-ID: <21ea442916c5378441b867140b8c891c@ruby-forum.com> David Chelimsky wrote: > On Sun, Mar 7, 2010 at 9:45 AM, Russell Fine > wrote: >> Our app connects to two databases. ?The main database (through >> ActiveRecord::Base) is automatically cleared before each test. ?How do I >> force the clear of the secondary database as well ? > > There's no implicit support for this, so you'd have to do something > manually in a before(:each) block. You can do that in the > configuration (usually in spec_helper): > > Spec::Runner.configure do |c| > c.before(:each) do > # clear out 2ndary db > end > end > > HTH, > David Thanks for the quick reply. Do you happen to know where in the framework I would call to clear out the db? I can obviously do it myself by hand by just deleting all elements, but I'm worried that the testing framework may perform some unique actions that differ from what I would do. Russell -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Sun Mar 7 11:42:19 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 7 Mar 2010 10:42:19 -0600 Subject: [rspec-users] How to test an app with multiple databases? In-Reply-To: <21ea442916c5378441b867140b8c891c@ruby-forum.com> References: <57c63afe1003070750i50f27b31l267ce6966f087ea5@mail.gmail.com> <21ea442916c5378441b867140b8c891c@ruby-forum.com> Message-ID: <57c63afe1003070842l2a4fcd31k3ab6276800f1bb5@mail.gmail.com> On Sun, Mar 7, 2010 at 10:11 AM, Russell Fine wrote: > David Chelimsky wrote: >> On Sun, Mar 7, 2010 at 9:45 AM, Russell Fine >> wrote: >>> Our app connects to two databases. ?The main database (through >>> ActiveRecord::Base) is automatically cleared before each test. ?How do I >>> force the clear of the secondary database as well ? >> >> There's no implicit support for this, so you'd have to do something >> manually in a before(:each) block. You can do that in the >> configuration (usually in spec_helper): >> >> Spec::Runner.configure do |c| >> ? c.before(:each) do >> ? ? # clear out 2ndary db >> ? end >> end >> >> HTH, >> David > > Thanks for the quick reply. ?Do you happen to know where in the > framework I would call to clear out the db? ?I can obviously do it > myself by hand by just deleting all elements, but I'm worried that the > testing framework may perform some unique actions that differ from what > I would do. rspec-rails just wraps the rails testing framework facilities, so whatever you're looking for is going to be found in the rails code. I'm not sure how the database_cleaner gem handles multiple databases, but you might find your answer there. Can anybody else point Russell in the right direction? From dchelimsky at gmail.com Sun Mar 7 13:10:30 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 7 Mar 2010 12:10:30 -0600 Subject: [rspec-users] how to pass objects from spec to formatter from before :all block? In-Reply-To: <673df843-f5bd-4df3-ba5c-f3837149526c@x22g2000yqx.googlegroups.com> References: <3df161de-0154-4c0f-a3f4-711927f1243c@q21g2000yqm.googlegroups.com> <57c63afe1003060928k59a489d2o37f4106d92c5c8fb@mail.gmail.com> <54f97986-2774-4e66-8e36-54240be7390a@g7g2000yqe.googlegroups.com> <57c63afe1003070512h2d92e57au808342d46079984@mail.gmail.com> <673df843-f5bd-4df3-ba5c-f3837149526c@x22g2000yqx.googlegroups.com> Message-ID: <57c63afe1003071010i5c81b7a9r94f2b0c693d84bd2@mail.gmail.com> On Sun, Mar 7, 2010 at 7:47 AM, Jarmo Pertman wrote: > Thank you for your thoughts. Unfortunately it seems that after :each > is not run if before :all fails... > > And after :all is ran after example_failed in formatter. Consider spec > like this: > > describe "something" do > ?before :all do > ? ?p "before" > ? ?raise > ?end > > ?it "does" do > ? ?p "it" > ?end > > ?after :each do > ? ?p "each" > ?end > > ?after :all do > ? ?p "all" > ?end > end > > Output of it will be: > "before" > F"all" > > In other words, I'd have to put @browser into options in before :all > AND in after :each. After :each is actually a good place, because then > if @browser object is changed within the it block, then formatter gets > correct browser object nevertheless. It will be messier of course, but > I thought that I'd use Spec::Runner.configure in spec_helper or > somewhere: > Spec::Runner.configure do |config| > ?config.before(:all) {@browser = options[:browser] = > Watir::Browser.new} > ?config.after(:each) {options[:browser] = @browser} > end > > Does it make sense? In that way i wouldn't have to write my specs by > using any custom way (like you demonstrated with your method > with_new_browser. > > It would be great of course if i wouldn't have to fill options two > times. Again, there was never an intent to be able to modify the options hash at all from within an example. The fact that you can in before/after(:each) is an unintended by-product of the implementation, and making it available in before(:all) would require some re-architecting that is simply not going to happen in the context of rspec-1 now that we're actively working on rspec-2. Rspec-2 does give you access to a metadata hash, which you can access through a formal API from an example, before(:each) or after(:each): describe "something" do it "does something" do running_example.metadata[:description].should eq("does something") end end At the moment you can't access it in before(:all) because there is no running_example yet, but we should be able to provide access to it through a new API. I'll look into that in rspec-2. I've added an issue for it: http://github.com/rspec/rspec-core/issues/issue/6 In the mean time, for better or worse, I'd stick with a global because it works right now. That's how I always did this sort of thing when I was using rspec to drive WATIR or Selenium. HTH, David > > Jarmo > > On Mar 7, 3:12?pm, David Chelimsky wrote: >> On Sat, Mar 6, 2010 at 12:33 PM, Jarmo Pertman wrote: >> > Since i'm using Watir >> > then i usually open up the browser in >> > before :all block like this: >> > before :all do >> > ?@browser = Watir::Browser.new >> > end >> >> > and then in the formatter I'm saving html of the browser - thus >> > needing to access the browser object. >> >> You should have access to it from within each example. This would be a >> bit noisier, but you could do this: >> >> before(:all) do >> ? @browser = Watir::Browser.new >> end >> before(:each) do >> ? options[:browser] = @browser >> end >> >> Even though that's noisier, you could easily encapsulate that in a method: >> >> def with_new_browser >> ? before(:all) do >> ? ? @browser = Watir::Browser.new >> ? end >> ? before(:each) do >> ? ? options[:browser] = @browser >> ? end >> ? yield >> end >> >> describe "the home page" do >> ? with_new_browser do >> ? ? it "looks awesome" do >> ? ? ? # .... >> ? ? end >> ? ? it "takes you where you want to go" do >> ? ? ? # ... >> ? ? end >> ? end >> end >> >> > I could solve it currently by using before :each block as shown in my >> > first post or a global variable (not nice at all), but i thought that >> > it would be more logical to set it into options in before :all once. >> >> > Also, if using before :each solution and something fails in >> > before :all, then formatter doesn't know currently anything about the >> > browser object and cannot save the html or anything. It's little bit >> > bad, since let's say if i do also some "setup actions" in before :all >> > before the actual tests and what if something fails there? >> >> after(:each) and after(:all) are guaranteed to run regardless of what >> happens in before(:each), before(:all), and the examples >> themselves. So you could deliver the browser there: >> >> def with_new_browser >> ? before(:all) do >> ? ? @browser = Watir::Browser.new >> ? end >> ? yield >> ? after(:each) do >> ? ? options[:browser] = @browser >> ? end >> end >> >> > But what would happen if example_group options would be merged with >> > example options? >> >> In rspec-1 that would be problematic, but this is already supported in >> rspec-2 out of the box, so you may want to give rspec-2 a try. >> >> >> >> >> >> >> >> > Any other solutions? >> >> > Jarmo >> >> > On Mar 6, 7:28?pm, David Chelimsky wrote: >> >> On Sat, Mar 6, 2010 at 11:09 AM, Jarmo Pertman wrote: >> >> > Hello. >> >> >> > I need to pass something from before :all to formatter. I know that i >> >> > could use options hash from spec and then get the value back in >> >> > formatter, but it doesn't work when i'm doing it from before :all. >> >> >> > So, this work: >> >> >> > # in spec >> >> > before :each do >> >> > ?options[:something] = 1 >> >> > end >> >> >> > # in formatter >> >> > def example_failed(example, counter, failure) >> >> > ?puts example.options[:something] # outputs 1 >> >> > ?super >> >> > end >> >> >> > But if i try to do the same thing from before :all, then it doesn't >> >> > work. >> >> >> > So i looked into the source of RSpec and in example/example_methods.rb >> >> > in method set_instance_variables_from_hash there is a line which >> >> > ignores some instance variables among with others @_proxy, which has >> >> > this option hash initialized in before :all and that's why it's not >> >> > getting into the formatter - in other words it is just dropped. >> >> >> > Is this a bug or expected behaviour? If it's expected then what's the >> >> > reason and how could i get the desired results of passing something to >> >> > formatter from before :all? >> >> >> > Can't we just pass this options hash along? >> >> >> It was never intended that you would set values on options from inside >> >> an example and access them in a formatter. You've happened on >> >> something that just happens to work because we're using a standard >> >> Ruby data structure. >> >> >> The reason it won't work for before(:all) is that before(:all) gets >> >> run before any of the examples are run - so it doesn't have access to >> >> the options hash, which is created per example in rspec-1. >> >> >> What sort of information are you trying to get to your formatter? >> >> Maybe there is a different way to do it. >> >> _______________________________________________ >> >> rspec-users mailing list >> >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ >> > rspec-users mailing list >> > rspec-us... at rubyforge.org >> >http://rubyforge.org/mailman/listinfo/rspec-users >> >> _______________________________________________ >> rspec-users mailing list >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Mon Mar 8 02:13:42 2010 From: lists at ruby-forum.com (Amit Kulkarni) Date: Mon, 8 Mar 2010 08:13:42 +0100 Subject: [rspec-users] Undefined method 'post' In-Reply-To: <57c63afe1003050548k1c2a931bv2efc73886a9c1f58@mail.gmail.com> References: <9434c45a13a1e769df7e8e1bb834fd3f@ruby-forum.com> <5170faf6cf63695dedad0c38d342660b@ruby-forum.com> <57c63afe1003050548k1c2a931bv2efc73886a9c1f58@mail.gmail.com> Message-ID: <945b5211cd42766eddd5c9dfe9ef9e3b@ruby-forum.com> As per the list there are 3 versions of rspec released in Jan 2010 i.e. 1.3.0,1.3.1 and 1.3.2 Also there are various versions starting from 2. So from all above version which one is a stable one so that i can install it. -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Mon Mar 8 02:16:49 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 8 Mar 2010 01:16:49 -0600 Subject: [rspec-users] Undefined method 'post' In-Reply-To: <945b5211cd42766eddd5c9dfe9ef9e3b@ruby-forum.com> References: <9434c45a13a1e769df7e8e1bb834fd3f@ruby-forum.com> <5170faf6cf63695dedad0c38d342660b@ruby-forum.com> <57c63afe1003050548k1c2a931bv2efc73886a9c1f58@mail.gmail.com> <945b5211cd42766eddd5c9dfe9ef9e3b@ruby-forum.com> Message-ID: <57c63afe1003072316q6dcd9c6fg4f48e37a214b8ade@mail.gmail.com> On Mon, Mar 8, 2010 at 1:13 AM, Amit Kulkarni wrote: > As per the list there are 3 versions of rspec released in Jan 2010 i.e. > 1.3.0,1.3.1 and 1.3.2 > Also there are various versions starting from 2. > So from all above version which one is a stable one so that i can > install it. Why would you want anything but the latest? I'd go with that: 1.3.2. Cheers, David From ben at benmabey.com Sun Mar 7 22:53:06 2010 From: ben at benmabey.com (Ben Mabey) Date: Sun, 07 Mar 2010 20:53:06 -0700 Subject: [rspec-users] How to test an app with multiple databases? In-Reply-To: <57c63afe1003070842l2a4fcd31k3ab6276800f1bb5@mail.gmail.com> References: <57c63afe1003070750i50f27b31l267ce6966f087ea5@mail.gmail.com> <21ea442916c5378441b867140b8c891c@ruby-forum.com> <57c63afe1003070842l2a4fcd31k3ab6276800f1bb5@mail.gmail.com> Message-ID: <4B9474A2.8030800@benmabey.com> David Chelimsky wrote: > On Sun, Mar 7, 2010 at 10:11 AM, Russell Fine wrote: > >> David Chelimsky wrote: >> >>> On Sun, Mar 7, 2010 at 9:45 AM, Russell Fine >>> wrote: >>> >>>> Our app connects to two databases. ?The main database (through >>>> ActiveRecord::Base) is automatically cleared before each test. ?How do I >>>> force the clear of the secondary database as well ? >>>> >>> There's no implicit support for this, so you'd have to do something >>> manually in a before(:each) block. You can do that in the >>> configuration (usually in spec_helper): >>> >>> Spec::Runner.configure do |c| >>> c.before(:each) do >>> # clear out 2ndary db >>> end >>> end >>> >>> HTH, >>> David >>> >> Thanks for the quick reply. Do you happen to know where in the >> framework I would call to clear out the db? I can obviously do it >> myself by hand by just deleting all elements, but I'm worried that the >> testing framework may perform some unique actions that differ from what >> I would do. >> > > rspec-rails just wraps the rails testing framework facilities, so > whatever you're looking for is going to be found in the rails code. > > I'm not sure how the database_cleaner gem handles multiple databases, > but you might find your answer there. > > Can anybody else point Russell in the right direction? > DatabaseCleaner doesn't support multiple databases ATM. I have had some discussions with people about adding support for multiple database types (i.e. AR and MongoMapper in the same app) but haven't thought about multiple DB connections for the same adapter. Off the top of my head I don't think it should be too difficult to do for AR. It sounds like you are using the standard rails transactional rollbacks for your tests right now. In order to clear out your second database in a similar fashion (with transactions) I would try something like this in your spec_helper: require 'database_cleaner' DatabaseCleaner.strategy = :transaction Spec::Runner.configure do |c| c.before(:each) do ActiveRecord::Base::establish_connection :secondary_db DatabaseCleaner.start ActiveRecord::Base::establish_connection :primary_db end c.after(:each) do ActiveRecord::Base::establish_connection :secondary_db DatabaseCleaner.clean ActiveRecord::Base::establish_connection :primary_db end end I haven't tried the above code but it seems correct. Give it a try and let me know if it works. If it does I could add support to DatabaseCleaner so you can select which AR DB connections you want to clean. HTH, Ben From lists at ruby-forum.com Mon Mar 8 04:12:25 2010 From: lists at ruby-forum.com (Amit Kulkarni) Date: Mon, 8 Mar 2010 10:12:25 +0100 Subject: [rspec-users] Undefined method 'post' In-Reply-To: <57c63afe1003072316q6dcd9c6fg4f48e37a214b8ade@mail.gmail.com> References: <9434c45a13a1e769df7e8e1bb834fd3f@ruby-forum.com> <5170faf6cf63695dedad0c38d342660b@ruby-forum.com> <57c63afe1003050548k1c2a931bv2efc73886a9c1f58@mail.gmail.com> <945b5211cd42766eddd5c9dfe9ef9e3b@ruby-forum.com> <57c63afe1003072316q6dcd9c6fg4f48e37a214b8ade@mail.gmail.com> Message-ID: <6f4a36c127565ead73ee2a133951f79c@ruby-forum.com> David Chelimsky wrote: > On Mon, Mar 8, 2010 at 1:13 AM, Amit Kulkarni > wrote: >> As per the list there are 3 versions of rspec released in Jan 2010 i.e. >> 1.3.0,1.3.1 and 1.3.2 >> Also there are various versions starting from 2. >> So from all above version which one is a stable one so that i can >> install it. > > Why would you want anything but the latest? I'd go with that: 1.3.2. > > Cheers, > David Hi David, I updated the rspec-rails with 1.3.2 and it update rspec with 1.3.0 Also i read the doc which stated that spec server is no longer used.Instead they are using spork. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Mon Mar 8 04:17:12 2010 From: lists at ruby-forum.com (Amit Kulkarni) Date: Mon, 8 Mar 2010 10:17:12 +0100 Subject: [rspec-users] Undefined method 'post' In-Reply-To: <6f4a36c127565ead73ee2a133951f79c@ruby-forum.com> References: <9434c45a13a1e769df7e8e1bb834fd3f@ruby-forum.com> <5170faf6cf63695dedad0c38d342660b@ruby-forum.com> <57c63afe1003050548k1c2a931bv2efc73886a9c1f58@mail.gmail.com> <945b5211cd42766eddd5c9dfe9ef9e3b@ruby-forum.com> <57c63afe1003072316q6dcd9c6fg4f48e37a214b8ade@mail.gmail.com> <6f4a36c127565ead73ee2a133951f79c@ruby-forum.com> Message-ID: Amit Kulkarni wrote: > David Chelimsky wrote: >> On Mon, Mar 8, 2010 at 1:13 AM, Amit Kulkarni >> wrote: >>> As per the list there are 3 versions of rspec released in Jan 2010 i.e. >>> 1.3.0,1.3.1 and 1.3.2 >>> Also there are various versions starting from 2. >>> So from all above version which one is a stable one so that i can >>> install it. >> >> Why would you want anything but the latest? I'd go with that: 1.3.2. >> >> Cheers, >> David > > Hi David, > I updated the rspec-rails with 1.3.2 and it update rspec with 1.3.0 > Also i read the doc which stated that spec server is no longer > used.Instead they are using spork. Since when i try to run with spec command it gives me above error Now when i run with "spec --drb" then that spec is properly executed. Also i want to know that when i run "spork" command from the project root then it says "Spork is ready and listening on 8989!" but when i try to run this port in browser then nothing is displayed. Can you please tell me the difference between running spork command and running spec locally using spec -drb -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Mon Mar 8 06:12:52 2010 From: lists at ruby-forum.com (Amit Kulkarni) Date: Mon, 8 Mar 2010 12:12:52 +0100 Subject: [rspec-users] Undefined method 'post' In-Reply-To: References: <9434c45a13a1e769df7e8e1bb834fd3f@ruby-forum.com> <5170faf6cf63695dedad0c38d342660b@ruby-forum.com> <57c63afe1003050548k1c2a931bv2efc73886a9c1f58@mail.gmail.com> <945b5211cd42766eddd5c9dfe9ef9e3b@ruby-forum.com> <57c63afe1003072316q6dcd9c6fg4f48e37a214b8ade@mail.gmail.com> <6f4a36c127565ead73ee2a133951f79c@ruby-forum.com> Message-ID: <3661b6fcf2f71bd39dc1ffa67fe8ff83@ruby-forum.com> Hello, I am having some problem with the controllers after i updated my specs. Following are the details: I am trying to call create action as post :create :user => {:name => "abc", :login => "abcd", :phone => 11111} After this i am searching this for confirmation i.e. user = User.find_by_name("abc") user.name.should == "abc" Now when i run this i am getting an error as You have a nil object when you didn't expect it!The error occurred while evaluating nil.title Similarly for update.I am getting that particular user from the fixtures and just updating the name and searching as above.But i am getting same error I am using fixtures as fixtures :users So my guess is whatever params i am passing it may be getting updated but again fixtures are getting uploaded. Please suggest -- Posted via http://www.ruby-forum.com/. From apremdas at gmail.com Tue Mar 9 13:23:20 2010 From: apremdas at gmail.com (Andrew Premdas) Date: Tue, 9 Mar 2010 18:23:20 +0000 Subject: [rspec-users] Best practices to managing RSpec code for very large projects? In-Reply-To: References: Message-ID: <88fd8ddc1003091023w266ed2efi9e6435990527f0e7@mail.gmail.com> On 4 February 2010 05:12, David Mitchell wrote: > Hello group, > > I've searched through several months messages in the archive, but haven't > found an answer to this... > > What is the 'best practice' way to structure RSpec code and documentation > when testing a very large project, where the RSpec code base has to be > maintained and extended over a long period? > > A bit of background: I've just be brought onto a (non-Ruby) project that > has unit- and functional-test suites written using RSpec. It's a large > project, and growing; there's currently >20,000 distinct unit-test cases in > RSpec, and a smaller (but still considerable) number of functional-test > cases. The quantity of these test cases is still growing quickly, but > they've hit a bottleneck in creating new test cases without breaking > existing test cases. > > Over the life of the project, there's been a number of people writing RSpec > tests without any overriding guidance on things like: > - appropriate naming of helper functions > - use of private vs. protected vs. public methods to only expose > functionality as required > - ensuring the scope of code is managed correctly (e.g. code for testing > databases should probably be held in a module named 'Database') > - documentation, in any form e.g. what a helper function does, what its > side effects are, coverage of modules & how to extend them, ... > - use of 'raise' and 'warn' to highlight problems > - etc., etc. > > As a result, what exists now is basically a huge mess. For example, we've > got multiple helper functions named identically, that serve very different > purposes e.g. 'it_should_be_nil', with one doing a string comparison, > another covering the number of records returned in a database cursor, and so > on. The scope of these functions is such that they're accessible from all > the 'wrong' places, so it's quite possible that the wrong helper function > could accidentally be referenced at any point and quite difficult to > identify which one of several identically-named helper functions is going to > be executed at any given point. > > Aside from some serious therapy, what I'm looking for is some sort of 'best > practices' documentation covering how to use RSpec to create *and maintain* > a very large population of test cases over an extended period of time. If I > can get that, then I can at least start working in the right direction to > ensure the problem doesn't get any worse, and then start fixing what exists > now. Issues that are biting me right now include: > - how to structure a hierarchy of RSpec modules to cover both unit- and > functional-test requirements. For unit-testing, it seems to make sense to > create a hierarchy along infrastructure lines, so there might be a module > named 'Database' that includes all the generic database test functions (e.g. > check table names, field names, field definitions, constraints, triggers, > ... are all defined correctly), that is subclassed into distinct modules for > each database instance being tested. However, for functional-testing, it > seems to make more sense to create a hierarchy along business process lines, > so that helper functions covering a particular set of business functionality > are bundled together. Given you'll probably want to use a lot of the same > methods in both your functional- and unit-test code, what's the best way to > structure this hierarchy? > - use of modules/namespaces to achieve sensible isolation of functionality > (e.g. the 'it_should_be_nil' problem described above), while still having > the code referencing functions in modules being readable > - documentation requirements when building/maintaining a large RSpec test > suite over an extended period of time, so that you don't wind up relying > exclusively on knowledge held in the heads of key people, and new people can > be brought up to date on "how it all hangs together" relatively quickly > > If anyone can point me to useful reference material along these lines, I'd > greatly appreciate it. > > Thanks in advance > > David Mitchell > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > Rails is quite good in organising RSpec tests, so looking at a big Rails project could give you some pointers. Key ideas I would take from Rails are 1. Separation of unit specs from other sorts of specs 2. 1 to 1 match between a class and its spec 3. Applying convention with rigour to naming of specs My no.1 tip for any spec is to read its output when you run it. I do this in texmate but you can do it with an html report or at the command prompt. Basically my opinion is that if a spec viewed in this manner doesn't make absolute sense then its not worth having. If you can't understand what you're specifying you certainly can't know how your application is behaving. One thing this kind of viewing will do is reveal specs that are doing to many things. HTH Andrew -------------- next part -------------- An HTML attachment was scrubbed... URL: From ashley.moran at patchspace.co.uk Wed Mar 10 08:31:19 2010 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Wed, 10 Mar 2010 13:31:19 +0000 Subject: [rspec-users] Spork in RSpec 2 Message-ID: <5856EB55-AE0E-4A46-AD3A-0477AC518916@patchspace.co.uk> Hi I've just started using RSpec 2 in Rails 3 and I'm incredibly frustrated by the time it takes to boot Rails, it's a real TDD bottleneck. The obvious solution is Spork, which is currently not possible with RSpec 2 because it lacks DRb support[1]. I've cloned RSpec and I'm about to start working on DRb in RSpec 2, but I thought I'd fire this off to ask... * is anyone else also working on it? I don't want to duplicate effort. * are there any potential issues that people with RSpec 2 knowledge can forsee? I don't want to lose time on known gotchas. If the answer to both is no I'll dive in :) Cheers Ashley [1] http://github.com/rspec/rspec-core/issues#issue/2 -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashleymoran From dchelimsky at gmail.com Wed Mar 10 08:46:09 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 10 Mar 2010 07:46:09 -0600 Subject: [rspec-users] Spork in RSpec 2 In-Reply-To: <5856EB55-AE0E-4A46-AD3A-0477AC518916@patchspace.co.uk> References: <5856EB55-AE0E-4A46-AD3A-0477AC518916@patchspace.co.uk> Message-ID: <57c63afe1003100546l45ec2a6at5cd31d5b01f7d864@mail.gmail.com> On Wed, Mar 10, 2010 at 7:31 AM, Ashley Moran wrote: > Hi > > I've just started using RSpec 2 in Rails 3 and I'm incredibly frustrated by the time it takes to boot Rails, it's a real TDD bottleneck. ?The obvious solution is Spork, which is currently not possible with RSpec 2 because it lacks DRb support[1]. > > I've cloned RSpec and I'm about to start working on DRb in RSpec 2, but I thought I'd fire this off to ask... > > * is anyone else also working on it? ?I don't want to duplicate effort. AFAIK, no. Please add a comment to the issue saying you're working on it. > * are there any potential issues that people with RSpec 2 knowledge can forsee? ?I don't want to lose time on known gotchas. * You will need the other gems installed in order to work on rspec-2. There is no concept of a CommandLineRunner yet, nor does there necessarily need to be. i.e. don't add one just because that's how rspec-1 dealt with Drb, but if that seems like an easy direction and it solves the problem cleanly, go for it. Thanks for taking up the cause! Cheers, David > > If the answer to both is no I'll dive in :) > > Cheers > Ashley > > [1] http://github.com/rspec/rspec-core/issues#issue/2 > > -- > http://www.patchspace.co.uk/ > http://www.linkedin.com/in/ashleymoran > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ashley.moran at patchspace.co.uk Wed Mar 10 09:05:29 2010 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Wed, 10 Mar 2010 14:05:29 +0000 Subject: [rspec-users] Spork in RSpec 2 In-Reply-To: <57c63afe1003100546l45ec2a6at5cd31d5b01f7d864@mail.gmail.com> References: <5856EB55-AE0E-4A46-AD3A-0477AC518916@patchspace.co.uk> <57c63afe1003100546l45ec2a6at5cd31d5b01f7d864@mail.gmail.com> Message-ID: On Mar 10, 2010, at 1:46 pm, David Chelimsky wrote: > AFAIK, no. Please add a comment to the issue saying you're working on it. Done. >> * are there any potential issues that people with RSpec 2 knowledge can forsee? I don't want to lose time on known gotchas. > > * You will need the other gems installed in order to work on rspec-2. Think I have that all sorted. BTW when did you start using "watchr"? It's new to me. I notice it runs specs blindingly fast, which I like :-) Why that over (the new ZenTest-free) autotest? > There is no concept of a CommandLineRunner yet, nor does there > necessarily need to be. i.e. don't add one just because that's how > rspec-1 dealt with Drb, but if that seems like an easy direction and > it solves the problem cleanly, go for it. I'll see what seems to fit. Don't expect me to come up with a good design first time though. > Thanks for taking up the cause! No probs - I'll end up stabbing myself in the eye with a real spork if I have to watch Rails boot one more time =) Ashley -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashleymoran From lists at ruby-forum.com Wed Mar 10 09:06:17 2010 From: lists at ruby-forum.com (Amit Kulkarni) Date: Wed, 10 Mar 2010 15:06:17 +0100 Subject: [rspec-users] webrat methods are undefined In-Reply-To: <57c63afe0901280753g45607037nafff0ea84ae67858@mail.gmail.com> References: <897488b954d8536cb88314d26c128d13@ruby-forum.com> <57c63afe0901280753g45607037nafff0ea84ae67858@mail.gmail.com> Message-ID: Hello, I recently updated rspec-rails from 1.1.12 to 1.3.0 and rspec from 1.1.12 to 1.3.0 Now while running cucumber i am facing a problem. It says as 'undefined method 'visit'' my cucumber version is 0.3.99 and webrat version is 0.7.0. Before upgrading the gem it ran well but now above error is displayed. My env.rb file is as follows: ENV["RAILS_ENV"] ||= "test" require File.expand_path(File.dirname(__FILE__) + '/../../config/environment') require 'cucumber/rails/world' # Comment out the next line if you don't want Cucumber Unicode support require 'cucumber/formatter/unicode' # Comment out the next line if you don't want transactions to # open/roll back around each scenario Cucumber::Rails.use_transactional_fixtures Before do Fixtures.reset_cache fixtures_folder = File.join(RAILS_ROOT, 'spec', 'fixtures') fixtures = Dir[File.join(fixtures_folder, '*.yml')].map {|f| File.basename(f, '.yml') } Fixtures.create_fixtures(fixtures_folder, fixtures) end # Comment out the next line if you want Rails' own error handling # (e.g. rescue_action_in_public / rescue_responses / rescue_from) Cucumber::Rails.bypass_rescue require 'webrat' require 'cucumber/webrat/element_locator' # Lets you do table.diff!(element_at('#my_table_or_dl_or_ul_or_ol').to_table) Webrat.configure do |config| config.mode = :rails end require 'cucumber/rails/rspec' require 'webrat/core/matchers' Also my config/environments/cucumber.rb contains config.cache_classes = true # This must be true for Cucumber to operate correctly! # Log error messages when you accidentally call methods on nil. config.whiny_nils = true # Show full error reports and disable caching config.action_controller.consider_all_requests_local = true config.action_controller.perform_caching = false # Disable request forgery protection in test environment config.action_controller.allow_forgery_protection = false # Tell Action Mailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test config.gem 'cucumber', :lib => false, :version => '>=0.3.99' unless File.directory?(File.join(Rails.root, 'vendor/plugins/cucumber')) config.gem 'webrat', :lib => false, :version => '>=0.7.0' unless File.directory?(File.join(Rails.root, 'vendor/plugins/webrat')) config.gem 'rspec', :lib => false, :version => '>=1.3.0' unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec')) config.gem 'rspec-rails', :lib => 'spec/rails', :version => '>=1.3.2' unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec-rails')) Please suggest -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Wed Mar 10 12:03:00 2010 From: lists at ruby-forum.com (Chris Gunnels) Date: Wed, 10 Mar 2010 18:03:00 +0100 Subject: [rspec-users] How to test helpers in a Sinatra app? Message-ID: <38faffbc72ae94f4cc2977b38bc3e8e5@ruby-forum.com> I am using rspec and trying to test some helpers, but for some reason can't get rspec to read my methods in my helpers.rb file. I include the helpers file in the helpers spec...in the spec I run a test with a method from my helpers file and I get an error saying: undefined method for my_method Any ideas suggestions, that'd be great. -- Posted via http://www.ruby-forum.com/. From godfoca at gmail.com Thu Mar 11 01:26:44 2010 From: godfoca at gmail.com (=?ISO-8859-1?Q?Nicol=E1s_Sanguinetti?=) Date: Thu, 11 Mar 2010 04:26:44 -0200 Subject: [rspec-users] Testing a rails controller *outside* of spec/controllers Message-ID: We have an app that has "extensions" that are built as rails engines. Each engine needs some code in the controllers, which we solved as "include this module, call a method". In order to test it, though, we don't want to "copy" the test for how that works into each engine, so the idea is to write the tests once, in 'spec/lib/extensions_spec.rb', where we are testing the other stuff that's common for all the extensions (which are defined on lib/extensions.rb, thus the spec's location) In order to do it, I'm declaring a 'sample' controller in the specs (just include the module, call the method), and then writing a couple specs for what we are doing. Problem is, I can't get rspec to understand that that example group is a controller example groups. I have class MyExampleController < ApplicationController include Extensions::ControllerHelpers call_awesome_method # this, among other things, defines an instance method on the controller that I want to test end inside my spec, and after that I tried: 1) describe("controller helpers", :type => :controller) { controller_name "my_example"; ... } It complains about controller_name not being a method of this dynamic subclass of ActiveSupport::TestCase. After some time reading the source I figured that :type => :controller pretty much just works for config.include/config.extend. So on to the next thing: 2) describe MyExampleController do...end # aka, duh, the obvious one. It complained about @controller being nil. Ended up reading most of action_controller/test_case, and rspec-rails, with no success. 3) move that *outside* the big top-level describe(Extensions). That at least got the specs running, but they failed because @controller is nil. Again. So "Ok, it's not setting the controller class at any point, let's force it", and I added the 'controller_name ...' call (also tried going low-level to calling ActiveSupport::TestCase.tests(klass), but that didn't work either.) 4) move all that into it's own file (maybe, for some reason which wouldn't make much sense, two different types of specs can't live together in the same file) Nope, same errors. 5) move the file into spec/controllers Bang! It works. But it's ugly that it's there, because I'm just testing something "related" to controllers. (Granted, writing a controller spec isn't the best idea ever for this, but it's the straightest way to get a controller instanced and that responds to all the routing helpers -- which is, in the end, what I need to call.) Basically, I read a lot of source code for both rspec-rails and rails' own testing code, trying to figure out a way around of this, and I'm running out of options. An alternative would be to include the module and call the method on a mock instead of a real controller -- but 'call_awesome_method' actually does some stuff with the rails router, and I really don't want to start writing all those huge mocks for just testing a simple method (since the 2.3.x router is definitely not something that I would characterize as 'overly testable') So the question is: is there a way I force rspec into saying *this is a controller spec, treat it as such* when the describe block is not defined on spec/controllers? And (Or) where does the relevant code to decide if it's a controller spec (i.e., it should subclass ControllerExampleGroup) or otherwise live? I can manage to work my way around from there :) Sorry for the rant, it's past 4am here and I'm not sure I can think straight at this anymore (or that all of this makes much sense) Cheers, -foca From scott at railsnewbie.com Thu Mar 11 01:41:42 2010 From: scott at railsnewbie.com (Scott Taylor) Date: Thu, 11 Mar 2010 01:41:42 -0500 Subject: [rspec-users] Testing a rails controller *outside* of spec/controllers In-Reply-To: References: Message-ID: <77823280-3C91-488A-8416-368D73EFD756@railsnewbie.com> On Mar 11, 2010, at 1:26 AM, Nicol?s Sanguinetti wrote: > We have an app that has "extensions" that are built as rails engines. > Each engine needs some code in the controllers, which we solved as > "include this module, call a method". In order to test it, though, we > don't want to "copy" the test for how that works into each engine, so > the idea is to write the tests once, in 'spec/lib/extensions_spec.rb', > where we are testing the other stuff that's common for all the > extensions (which are defined on lib/extensions.rb, thus the spec's > location) > > In order to do it, I'm declaring a 'sample' controller in the specs > (just include the module, call the method), and then writing a couple > specs for what we are doing. Problem is, I can't get rspec to > understand that that example group is a controller example groups. > > I have > > class MyExampleController < ApplicationController > include Extensions::ControllerHelpers > call_awesome_method # this, among other things, defines an > instance method on the controller that I want to test > end > > inside my spec, and after that I tried: > > 1) describe("controller helpers", :type => :controller) { > controller_name "my_example"; ... } > > It complains about controller_name not being a method of this dynamic > subclass of ActiveSupport::TestCase. > After some time reading the source I figured that :type => :controller > pretty much just works for config.include/config.extend. So on to the > next thing: > > 2) describe MyExampleController do...end # aka, duh, the obvious one. > > It complained about @controller being nil. Ended up reading most of > action_controller/test_case, and rspec-rails, with no success. > > 3) move that *outside* the big top-level describe(Extensions). That at > least got the specs running, but they failed because @controller is > nil. Again. So "Ok, it's not setting the controller class at any > point, let's force it", and I added the 'controller_name ...' call > (also tried going low-level to calling > ActiveSupport::TestCase.tests(klass), but that didn't work either.) > > 4) move all that into it's own file (maybe, for some reason which > wouldn't make much sense, two different types of specs can't live > together in the same file) > > Nope, same errors. > > 5) move the file into spec/controllers > > Bang! It works. But it's ugly that it's there, because I'm just > testing something "related" to controllers. (Granted, writing a > controller spec isn't the best idea ever for this, but it's the > straightest way to get a controller instanced and that responds to all > the routing helpers -- which is, in the end, what I need to call.) > > Basically, I read a lot of source code for both rspec-rails and rails' > own testing code, trying to figure out a way around of this, and I'm > running out of options. An alternative would be to include the module > and call the method on a mock instead of a real controller -- but > 'call_awesome_method' actually does some stuff with the rails router, > and I really don't want to start writing all those huge mocks for just > testing a simple method (since the 2.3.x router is definitely not > something that I would characterize as 'overly testable') > > So the question is: is there a way I force rspec into saying *this is > a controller spec, treat it as such* when the describe block is not > defined on spec/controllers? And (Or) where does the relevant code to > decide if it's a controller spec (i.e., it should subclass > ControllerExampleGroup) or otherwise live? I can manage to work my way > around from there :) > > Sorry for the rant, it's past 4am here and I'm not sure I can think > straight at this anymore (or that all of this makes much sense) What version of rspec are you using? Scott > > Cheers, > -foca > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From scott at railsnewbie.com Thu Mar 11 02:10:51 2010 From: scott at railsnewbie.com (Scott Taylor) Date: Thu, 11 Mar 2010 02:10:51 -0500 Subject: [rspec-users] Testing a rails controller *outside* of spec/controllers In-Reply-To: References: Message-ID: On Mar 11, 2010, at 1:26 AM, Nicol?s Sanguinetti wrote: > We have an app that has "extensions" that are built as rails engines. > Each engine needs some code in the controllers, which we solved as > "include this module, call a method". In order to test it, though, we > don't want to "copy" the test for how that works into each engine, so > the idea is to write the tests once, in 'spec/lib/extensions_spec.rb', > where we are testing the other stuff that's common for all the > extensions (which are defined on lib/extensions.rb, thus the spec's > location) > > In order to do it, I'm declaring a 'sample' controller in the specs > (just include the module, call the method), and then writing a couple > specs for what we are doing. Problem is, I can't get rspec to > understand that that example group is a controller example groups. > > I have > > class MyExampleController < ApplicationController > include Extensions::ControllerHelpers > call_awesome_method # this, among other things, defines an > instance method on the controller that I want to test > end > > inside my spec, and after that I tried: > > 1) describe("controller helpers", :type => :controller) { > controller_name "my_example"; ... } > > It complains about controller_name not being a method of this dynamic > subclass of ActiveSupport::TestCase. That seems like a really strange error. What is the actual stack trace? What versions of the test-unit gem do you have installed? What version of rails? rspec? If you uninstall the test-unit gem, will it work with the :type => :controller hash given to describe? (I've noticed *very* strange things with the test-unit gem installed in the past - such as a test suite which was 100% green, using a hybrid of mocha + rspec mocks/stubs. When the gem was uninstalled, half the test suite failed!) > After some time reading the source I figured that :type => :controller > pretty much just works for config.include/config.extend. So on to the > next thing: Have you taken a look at Spec::Example::ExampleGroupFactory? Not sure if this will help, but here's a patch that brynary and I banged out way back in rspec 1.1.9 to support spec/unit & spec/integration: (the usual disclaimer applies - all the good parts are his, all the bad parts are mine) http://gist.github.com/328919 That piece of the code might at least take you to a place where you can debug what's going on. Best, Scott From godfoca at gmail.com Thu Mar 11 05:09:47 2010 From: godfoca at gmail.com (=?ISO-8859-1?Q?Nicol=E1s_Sanguinetti?=) Date: Thu, 11 Mar 2010 08:09:47 -0200 Subject: [rspec-users] Testing a rails controller *outside* of spec/controllers In-Reply-To: References: Message-ID: Interesting: describe SomeModule do describe "Bar", :type => :controller do controller_name "blah" end end Doesn't work, while describe SomeModule do end describe "Bar", :type => :controller do controller_name "blah" end does. 2010/3/11 Nicol?s Sanguinetti : > On Thu, Mar 11, 2010 at 5:10 AM, Scott Taylor wrote: >> >> On Mar 11, 2010, at 1:26 AM, Nicol?s Sanguinetti wrote: >> >>> We have an app that has "extensions" that are built as rails engines. >>> Each engine needs some code in the controllers, which we solved as >>> "include this module, call a method". In order to test it, though, we >>> don't want to "copy" the test for how that works into each engine, so >>> the idea is to write the tests once, in 'spec/lib/extensions_spec.rb', >>> where we are testing the other stuff that's common for all the >>> extensions (which are defined on lib/extensions.rb, thus the spec's >>> location) >>> >>> In order to do it, I'm declaring a 'sample' controller in the specs >>> (just include the module, call the method), and then writing a couple >>> specs for what we are doing. Problem is, I can't get rspec to >>> understand that that example group is a controller example groups. >>> >>> I have >>> >>> ? ?class MyExampleController < ApplicationController >>> ? ? ?include Extensions::ControllerHelpers >>> ? ? ?call_awesome_method # this, among other things, defines an >>> instance method on the controller that I want to test >>> ? ?end >>> >>> inside my spec, and after that I tried: >>> >>> 1) describe("controller helpers", :type => :controller) { >>> controller_name "my_example"; ... } >>> >>> It complains about controller_name not being a method of this dynamic >>> subclass of ActiveSupport::TestCase. >> >> That seems like a really strange error. ?What is the actual stack trace? > > ./spec/lib/extensions_spec.rb:20: undefined method `controller_name' > for ActiveSupport::TestCase::Subclass_1:Class (NoMethodError) > ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/example/example_group_methods.rb:183:in > `module_eval' > ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/example/example_group_methods.rb:183:in > `subclass' > ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/example/example_group_methods.rb:55:in > `describe' > ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/example/example_group_factory.rb:31:in > `create_example_group' > ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/dsl/main.rb:28:in `describe' > ? ? ? ?from ./spec/lib/extensions_spec.rb:19 > ? ? ? ?from $gem_path/activesupport-2.3.5/lib/active_support/dependencies.rb:147:in > `load_without_new_constant_marking' > ? ? ? ?from $gem_path/activesupport-2.3.5/lib/active_support/dependencies.rb:147:in > `load' > ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:15:in > `load_files' > ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:14:in `each' > ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:14:in > `load_files' > ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/runner/options.rb:133:in `run_examples' > ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/runner/command_line.rb:9:in `run' > ? ? ? ?from script/spec:10 > > (sanitized it a bit) > >> What versions of the test-unit gem do you have installed? ?What version of rails? ?rspec? ?If you uninstall the test-unit gem, will it work with the :type => :controller hash given to describe? > > This is using rails 2.3.5, rspec 1.3.0, and rspec-rails 1.3.2. I do > not have test-unit on this system, I have mocha 0.9.8 (though it > shouldn't be required in the environment by anyone here) > >> (I've noticed *very* strange things with the test-unit gem installed in the past - such as a test suite which was 100% green, using a hybrid of mocha + rspec mocks/stubs. ?When the gem was uninstalled, half the test suite failed!) >> >>> After some time reading the source I figured that :type => :controller >>> pretty much just works for config.include/config.extend. So on to the >>> next thing: >> >> Have you taken a look at Spec::Example::ExampleGroupFactory? > > Ah, darn, I hadn't gotten that far into rspec's rabbit hole, and > missed the reference in rspec-rails. That's what you get for trying to > debug stuff at 4am :) So, :type => :controller should be enough, then. > > Still, doing: > > describe MyExampleController, :type => :controller do > ?it "should do stuff" do > ? ?controller.should_receive(:foo) > ? ?controller.extension.bar > ?end > end > > Fails with 'undefined local variable or method `controller' for > #' > > And replacing controller with @controller gives me 'undefined method > `bar' for nil:NilClass'. Which is pretty much the same results I got a > few hours ago before going to sleep :( > > ?So :type => :controller is apparently not enough for rspec to pick up on this. > >> Not sure if this will help, but here's a patch that brynary and I banged out way back in rspec 1.1.9 to support spec/unit & spec/integration: (the usual disclaimer applies - all the good parts are his, all the bad parts are mine) >> >> http://gist.github.com/328919 > > Thanks :) > >> That piece of the code might at least take you to a place where you can debug what's going on. >> >> Best, >> >> Scott >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > From godfoca at gmail.com Thu Mar 11 05:04:12 2010 From: godfoca at gmail.com (=?ISO-8859-1?Q?Nicol=E1s_Sanguinetti?=) Date: Thu, 11 Mar 2010 08:04:12 -0200 Subject: [rspec-users] Testing a rails controller *outside* of spec/controllers In-Reply-To: References: Message-ID: On Thu, Mar 11, 2010 at 5:10 AM, Scott Taylor wrote: > > On Mar 11, 2010, at 1:26 AM, Nicol?s Sanguinetti wrote: > >> We have an app that has "extensions" that are built as rails engines. >> Each engine needs some code in the controllers, which we solved as >> "include this module, call a method". In order to test it, though, we >> don't want to "copy" the test for how that works into each engine, so >> the idea is to write the tests once, in 'spec/lib/extensions_spec.rb', >> where we are testing the other stuff that's common for all the >> extensions (which are defined on lib/extensions.rb, thus the spec's >> location) >> >> In order to do it, I'm declaring a 'sample' controller in the specs >> (just include the module, call the method), and then writing a couple >> specs for what we are doing. Problem is, I can't get rspec to >> understand that that example group is a controller example groups. >> >> I have >> >> ? ?class MyExampleController < ApplicationController >> ? ? ?include Extensions::ControllerHelpers >> ? ? ?call_awesome_method # this, among other things, defines an >> instance method on the controller that I want to test >> ? ?end >> >> inside my spec, and after that I tried: >> >> 1) describe("controller helpers", :type => :controller) { >> controller_name "my_example"; ... } >> >> It complains about controller_name not being a method of this dynamic >> subclass of ActiveSupport::TestCase. > > That seems like a really strange error. ?What is the actual stack trace? ./spec/lib/extensions_spec.rb:20: undefined method `controller_name' for ActiveSupport::TestCase::Subclass_1:Class (NoMethodError) from $gem_path/rspec-1.3.0/lib/spec/example/example_group_methods.rb:183:in `module_eval' from $gem_path/rspec-1.3.0/lib/spec/example/example_group_methods.rb:183:in `subclass' from $gem_path/rspec-1.3.0/lib/spec/example/example_group_methods.rb:55:in `describe' from $gem_path/rspec-1.3.0/lib/spec/example/example_group_factory.rb:31:in `create_example_group' from $gem_path/rspec-1.3.0/lib/spec/dsl/main.rb:28:in `describe' from ./spec/lib/extensions_spec.rb:19 from $gem_path/activesupport-2.3.5/lib/active_support/dependencies.rb:147:in `load_without_new_constant_marking' from $gem_path/activesupport-2.3.5/lib/active_support/dependencies.rb:147:in `load' from $gem_path/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:15:in `load_files' from $gem_path/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:14:in `each' from $gem_path/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:14:in `load_files' from $gem_path/rspec-1.3.0/lib/spec/runner/options.rb:133:in `run_examples' from $gem_path/rspec-1.3.0/lib/spec/runner/command_line.rb:9:in `run' from script/spec:10 (sanitized it a bit) > What versions of the test-unit gem do you have installed? ?What version of rails? ?rspec? ?If you uninstall the test-unit gem, will it work with the :type => :controller hash given to describe? This is using rails 2.3.5, rspec 1.3.0, and rspec-rails 1.3.2. I do not have test-unit on this system, I have mocha 0.9.8 (though it shouldn't be required in the environment by anyone here) > (I've noticed *very* strange things with the test-unit gem installed in the past - such as a test suite which was 100% green, using a hybrid of mocha + rspec mocks/stubs. ?When the gem was uninstalled, half the test suite failed!) > >> After some time reading the source I figured that :type => :controller >> pretty much just works for config.include/config.extend. So on to the >> next thing: > > Have you taken a look at Spec::Example::ExampleGroupFactory? Ah, darn, I hadn't gotten that far into rspec's rabbit hole, and missed the reference in rspec-rails. That's what you get for trying to debug stuff at 4am :) So, :type => :controller should be enough, then. Still, doing: describe MyExampleController, :type => :controller do it "should do stuff" do controller.should_receive(:foo) controller.extension.bar end end Fails with 'undefined local variable or method `controller' for #' And replacing controller with @controller gives me 'undefined method `bar' for nil:NilClass'. Which is pretty much the same results I got a few hours ago before going to sleep :( ?So :type => :controller is apparently not enough for rspec to pick up on this. > Not sure if this will help, but here's a patch that brynary and I banged out way back in rspec 1.1.9 to support spec/unit & spec/integration: (the usual disclaimer applies - all the good parts are his, all the bad parts are mine) > > http://gist.github.com/328919 Thanks :) > That piece of the code might at least take you to a place where you can debug what's going on. > > Best, > > Scott > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From godfoca at gmail.com Thu Mar 11 05:12:14 2010 From: godfoca at gmail.com (=?ISO-8859-1?Q?Nicol=E1s_Sanguinetti?=) Date: Thu, 11 Mar 2010 08:12:14 -0200 Subject: [rspec-users] Testing a rails controller *outside* of spec/controllers In-Reply-To: References: Message-ID: Scratch that, it works if you run just that file, if you run the whole suite it doesn't. WTH. 2010/3/11 Nicol?s Sanguinetti : > Interesting: > > describe SomeModule do > ?describe "Bar", :type => :controller do > ? ?controller_name "blah" > ?end > end > > Doesn't work, while > > describe SomeModule do > end > > describe "Bar", :type => :controller do > ?controller_name "blah" > end > > does. > > 2010/3/11 Nicol?s Sanguinetti : >> On Thu, Mar 11, 2010 at 5:10 AM, Scott Taylor wrote: >>> >>> On Mar 11, 2010, at 1:26 AM, Nicol?s Sanguinetti wrote: >>> >>>> We have an app that has "extensions" that are built as rails engines. >>>> Each engine needs some code in the controllers, which we solved as >>>> "include this module, call a method". In order to test it, though, we >>>> don't want to "copy" the test for how that works into each engine, so >>>> the idea is to write the tests once, in 'spec/lib/extensions_spec.rb', >>>> where we are testing the other stuff that's common for all the >>>> extensions (which are defined on lib/extensions.rb, thus the spec's >>>> location) >>>> >>>> In order to do it, I'm declaring a 'sample' controller in the specs >>>> (just include the module, call the method), and then writing a couple >>>> specs for what we are doing. Problem is, I can't get rspec to >>>> understand that that example group is a controller example groups. >>>> >>>> I have >>>> >>>> ? ?class MyExampleController < ApplicationController >>>> ? ? ?include Extensions::ControllerHelpers >>>> ? ? ?call_awesome_method # this, among other things, defines an >>>> instance method on the controller that I want to test >>>> ? ?end >>>> >>>> inside my spec, and after that I tried: >>>> >>>> 1) describe("controller helpers", :type => :controller) { >>>> controller_name "my_example"; ... } >>>> >>>> It complains about controller_name not being a method of this dynamic >>>> subclass of ActiveSupport::TestCase. >>> >>> That seems like a really strange error. ?What is the actual stack trace? >> >> ./spec/lib/extensions_spec.rb:20: undefined method `controller_name' >> for ActiveSupport::TestCase::Subclass_1:Class (NoMethodError) >> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/example/example_group_methods.rb:183:in >> `module_eval' >> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/example/example_group_methods.rb:183:in >> `subclass' >> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/example/example_group_methods.rb:55:in >> `describe' >> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/example/example_group_factory.rb:31:in >> `create_example_group' >> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/dsl/main.rb:28:in `describe' >> ? ? ? ?from ./spec/lib/extensions_spec.rb:19 >> ? ? ? ?from $gem_path/activesupport-2.3.5/lib/active_support/dependencies.rb:147:in >> `load_without_new_constant_marking' >> ? ? ? ?from $gem_path/activesupport-2.3.5/lib/active_support/dependencies.rb:147:in >> `load' >> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:15:in >> `load_files' >> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:14:in `each' >> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:14:in >> `load_files' >> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/runner/options.rb:133:in `run_examples' >> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/runner/command_line.rb:9:in `run' >> ? ? ? ?from script/spec:10 >> >> (sanitized it a bit) >> >>> What versions of the test-unit gem do you have installed? ?What version of rails? ?rspec? ?If you uninstall the test-unit gem, will it work with the :type => :controller hash given to describe? >> >> This is using rails 2.3.5, rspec 1.3.0, and rspec-rails 1.3.2. I do >> not have test-unit on this system, I have mocha 0.9.8 (though it >> shouldn't be required in the environment by anyone here) >> >>> (I've noticed *very* strange things with the test-unit gem installed in the past - such as a test suite which was 100% green, using a hybrid of mocha + rspec mocks/stubs. ?When the gem was uninstalled, half the test suite failed!) >>> >>>> After some time reading the source I figured that :type => :controller >>>> pretty much just works for config.include/config.extend. So on to the >>>> next thing: >>> >>> Have you taken a look at Spec::Example::ExampleGroupFactory? >> >> Ah, darn, I hadn't gotten that far into rspec's rabbit hole, and >> missed the reference in rspec-rails. That's what you get for trying to >> debug stuff at 4am :) So, :type => :controller should be enough, then. >> >> Still, doing: >> >> describe MyExampleController, :type => :controller do >> ?it "should do stuff" do >> ? ?controller.should_receive(:foo) >> ? ?controller.extension.bar >> ?end >> end >> >> Fails with 'undefined local variable or method `controller' for >> #' >> >> And replacing controller with @controller gives me 'undefined method >> `bar' for nil:NilClass'. Which is pretty much the same results I got a >> few hours ago before going to sleep :( >> >> ?So :type => :controller is apparently not enough for rspec to pick up on this. >> >>> Not sure if this will help, but here's a patch that brynary and I banged out way back in rspec 1.1.9 to support spec/unit & spec/integration: (the usual disclaimer applies - all the good parts are his, all the bad parts are mine) >>> >>> http://gist.github.com/328919 >> >> Thanks :) >> >>> That piece of the code might at least take you to a place where you can debug what's going on. >>> >>> Best, >>> >>> Scott >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> > From dchelimsky at gmail.com Thu Mar 11 08:12:04 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 11 Mar 2010 07:12:04 -0600 Subject: [rspec-users] Testing a rails controller *outside* of spec/controllers In-Reply-To: References: Message-ID: <57c63afe1003110512p6106f057pe0e8901b036e53d7@mail.gmail.com> 2010/3/11 Nicol?s Sanguinetti : > Scratch that, it works if you run just that file, if you run the whole > suite it doesn't. WTH. The fact that it works at all is an accident :) > > 2010/3/11 Nicol?s Sanguinetti : >> Interesting: >> >> describe SomeModule do >> ?describe "Bar", :type => :controller do >> ? ?controller_name "blah" >> ?end >> end >> >> Doesn't work, while >> >> describe SomeModule do >> end >> >> describe "Bar", :type => :controller do >> ?controller_name "blah" >> end >> >> does. >> >> 2010/3/11 Nicol?s Sanguinetti : >>> On Thu, Mar 11, 2010 at 5:10 AM, Scott Taylor wrote: >>>> >>>> On Mar 11, 2010, at 1:26 AM, Nicol?s Sanguinetti wrote: >>>> >>>>> We have an app that has "extensions" that are built as rails engines. >>>>> Each engine needs some code in the controllers, which we solved as >>>>> "include this module, call a method". In order to test it, though, we >>>>> don't want to "copy" the test for how that works into each engine, so >>>>> the idea is to write the tests once, in 'spec/lib/extensions_spec.rb', >>>>> where we are testing the other stuff that's common for all the >>>>> extensions (which are defined on lib/extensions.rb, thus the spec's >>>>> location) >>>>> >>>>> In order to do it, I'm declaring a 'sample' controller in the specs >>>>> (just include the module, call the method), and then writing a couple >>>>> specs for what we are doing. Problem is, I can't get rspec to >>>>> understand that that example group is a controller example groups. >>>>> >>>>> I have >>>>> >>>>> ? ?class MyExampleController < ApplicationController >>>>> ? ? ?include Extensions::ControllerHelpers >>>>> ? ? ?call_awesome_method # this, among other things, defines an >>>>> instance method on the controller that I want to test >>>>> ? ?end >>>>> >>>>> inside my spec, and after that I tried: >>>>> >>>>> 1) describe("controller helpers", :type => :controller) { >>>>> controller_name "my_example"; ... } >>>>> >>>>> It complains about controller_name not being a method of this dynamic >>>>> subclass of ActiveSupport::TestCase. >>>> >>>> That seems like a really strange error. ?What is the actual stack trace? >>> >>> ./spec/lib/extensions_spec.rb:20: undefined method `controller_name' >>> for ActiveSupport::TestCase::Subclass_1:Class (NoMethodError) >>> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/example/example_group_methods.rb:183:in >>> `module_eval' >>> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/example/example_group_methods.rb:183:in >>> `subclass' >>> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/example/example_group_methods.rb:55:in >>> `describe' >>> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/example/example_group_factory.rb:31:in >>> `create_example_group' >>> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/dsl/main.rb:28:in `describe' >>> ? ? ? ?from ./spec/lib/extensions_spec.rb:19 >>> ? ? ? ?from $gem_path/activesupport-2.3.5/lib/active_support/dependencies.rb:147:in >>> `load_without_new_constant_marking' >>> ? ? ? ?from $gem_path/activesupport-2.3.5/lib/active_support/dependencies.rb:147:in >>> `load' >>> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:15:in >>> `load_files' >>> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:14:in `each' >>> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:14:in >>> `load_files' >>> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/runner/options.rb:133:in `run_examples' >>> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/runner/command_line.rb:9:in `run' >>> ? ? ? ?from script/spec:10 >>> >>> (sanitized it a bit) >>> >>>> What versions of the test-unit gem do you have installed? ?What version of rails? ?rspec? ?If you uninstall the test-unit gem, will it work with the :type => :controller hash given to describe? >>> >>> This is using rails 2.3.5, rspec 1.3.0, and rspec-rails 1.3.2. I do >>> not have test-unit on this system, I have mocha 0.9.8 (though it >>> shouldn't be required in the environment by anyone here) >>> >>>> (I've noticed *very* strange things with the test-unit gem installed in the past - such as a test suite which was 100% green, using a hybrid of mocha + rspec mocks/stubs. ?When the gem was uninstalled, half the test suite failed!) >>>> >>>>> After some time reading the source I figured that :type => :controller >>>>> pretty much just works for config.include/config.extend. So on to the >>>>> next thing: >>>> >>>> Have you taken a look at Spec::Example::ExampleGroupFactory? >>> >>> Ah, darn, I hadn't gotten that far into rspec's rabbit hole, and >>> missed the reference in rspec-rails. That's what you get for trying to >>> debug stuff at 4am :) So, :type => :controller should be enough, then. >>> >>> Still, doing: >>> >>> describe MyExampleController, :type => :controller do >>> ?it "should do stuff" do >>> ? ?controller.should_receive(:foo) >>> ? ?controller.extension.bar >>> ?end >>> end >>> >>> Fails with 'undefined local variable or method `controller' for >>> #' >>> >>> And replacing controller with @controller gives me 'undefined method >>> `bar' for nil:NilClass'. Which is pretty much the same results I got a >>> few hours ago before going to sleep :( >>> >>> ?So :type => :controller is apparently not enough for rspec to pick up on this. >>> >>>> Not sure if this will help, but here's a patch that brynary and I banged out way back in rspec 1.1.9 to support spec/unit & spec/integration: (the usual disclaimer applies - all the good parts are his, all the bad parts are mine) >>>> >>>> http://gist.github.com/328919 >>> >>> Thanks :) >>> >>>> That piece of the code might at least take you to a place where you can debug what's going on. >>>> >>>> Best, >>>> >>>> Scott >>>> >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-users at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>> >>> >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Thu Mar 11 08:11:02 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 11 Mar 2010 07:11:02 -0600 Subject: [rspec-users] Testing a rails controller *outside* of spec/controllers In-Reply-To: References: Message-ID: <57c63afe1003110511t4e0f6416jbb380c0b752a68c0@mail.gmail.com> 2010/3/11 Nicol?s Sanguinetti : > Interesting: > > describe SomeModule do > ?describe "Bar", :type => :controller do > ? ?controller_name "blah" > ?end > end You can only set the type in the outermost-nested group. The reason for this is that the nested groups are subclasses of the outer group. So you could do this: describe SomeModule, :type => :controller do describe "Bar" do controller_name "blah" end end and it should work. HTH, David > > Doesn't work, while > > describe SomeModule do > end > > describe "Bar", :type => :controller do > ?controller_name "blah" > end > > does. > > 2010/3/11 Nicol?s Sanguinetti : >> On Thu, Mar 11, 2010 at 5:10 AM, Scott Taylor wrote: >>> >>> On Mar 11, 2010, at 1:26 AM, Nicol?s Sanguinetti wrote: >>> >>>> We have an app that has "extensions" that are built as rails engines. >>>> Each engine needs some code in the controllers, which we solved as >>>> "include this module, call a method". In order to test it, though, we >>>> don't want to "copy" the test for how that works into each engine, so >>>> the idea is to write the tests once, in 'spec/lib/extensions_spec.rb', >>>> where we are testing the other stuff that's common for all the >>>> extensions (which are defined on lib/extensions.rb, thus the spec's >>>> location) >>>> >>>> In order to do it, I'm declaring a 'sample' controller in the specs >>>> (just include the module, call the method), and then writing a couple >>>> specs for what we are doing. Problem is, I can't get rspec to >>>> understand that that example group is a controller example groups. >>>> >>>> I have >>>> >>>> ? ?class MyExampleController < ApplicationController >>>> ? ? ?include Extensions::ControllerHelpers >>>> ? ? ?call_awesome_method # this, among other things, defines an >>>> instance method on the controller that I want to test >>>> ? ?end >>>> >>>> inside my spec, and after that I tried: >>>> >>>> 1) describe("controller helpers", :type => :controller) { >>>> controller_name "my_example"; ... } >>>> >>>> It complains about controller_name not being a method of this dynamic >>>> subclass of ActiveSupport::TestCase. >>> >>> That seems like a really strange error. ?What is the actual stack trace? >> >> ./spec/lib/extensions_spec.rb:20: undefined method `controller_name' >> for ActiveSupport::TestCase::Subclass_1:Class (NoMethodError) >> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/example/example_group_methods.rb:183:in >> `module_eval' >> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/example/example_group_methods.rb:183:in >> `subclass' >> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/example/example_group_methods.rb:55:in >> `describe' >> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/example/example_group_factory.rb:31:in >> `create_example_group' >> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/dsl/main.rb:28:in `describe' >> ? ? ? ?from ./spec/lib/extensions_spec.rb:19 >> ? ? ? ?from $gem_path/activesupport-2.3.5/lib/active_support/dependencies.rb:147:in >> `load_without_new_constant_marking' >> ? ? ? ?from $gem_path/activesupport-2.3.5/lib/active_support/dependencies.rb:147:in >> `load' >> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:15:in >> `load_files' >> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:14:in `each' >> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:14:in >> `load_files' >> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/runner/options.rb:133:in `run_examples' >> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/runner/command_line.rb:9:in `run' >> ? ? ? ?from script/spec:10 >> >> (sanitized it a bit) >> >>> What versions of the test-unit gem do you have installed? ?What version of rails? ?rspec? ?If you uninstall the test-unit gem, will it work with the :type => :controller hash given to describe? >> >> This is using rails 2.3.5, rspec 1.3.0, and rspec-rails 1.3.2. I do >> not have test-unit on this system, I have mocha 0.9.8 (though it >> shouldn't be required in the environment by anyone here) >> >>> (I've noticed *very* strange things with the test-unit gem installed in the past - such as a test suite which was 100% green, using a hybrid of mocha + rspec mocks/stubs. ?When the gem was uninstalled, half the test suite failed!) >>> >>>> After some time reading the source I figured that :type => :controller >>>> pretty much just works for config.include/config.extend. So on to the >>>> next thing: >>> >>> Have you taken a look at Spec::Example::ExampleGroupFactory? >> >> Ah, darn, I hadn't gotten that far into rspec's rabbit hole, and >> missed the reference in rspec-rails. That's what you get for trying to >> debug stuff at 4am :) So, :type => :controller should be enough, then. >> >> Still, doing: >> >> describe MyExampleController, :type => :controller do >> ?it "should do stuff" do >> ? ?controller.should_receive(:foo) >> ? ?controller.extension.bar >> ?end >> end >> >> Fails with 'undefined local variable or method `controller' for >> #' >> >> And replacing controller with @controller gives me 'undefined method >> `bar' for nil:NilClass'. Which is pretty much the same results I got a >> few hours ago before going to sleep :( >> >> ?So :type => :controller is apparently not enough for rspec to pick up on this. >> >>> Not sure if this will help, but here's a patch that brynary and I banged out way back in rspec 1.1.9 to support spec/unit & spec/integration: (the usual disclaimer applies - all the good parts are his, all the bad parts are mine) >>> >>> http://gist.github.com/328919 >> >> Thanks :) >> >>> That piece of the code might at least take you to a place where you can debug what's going on. >>> >>> Best, >>> >>> Scott >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From godfoca at gmail.com Thu Mar 11 08:26:44 2010 From: godfoca at gmail.com (=?ISO-8859-1?Q?Nicol=E1s_Sanguinetti?=) Date: Thu, 11 Mar 2010 11:26:44 -0200 Subject: [rspec-users] Testing a rails controller *outside* of spec/controllers In-Reply-To: <57c63afe1003110512p6106f057pe0e8901b036e53d7@mail.gmail.com> References: <57c63afe1003110512p6106f057pe0e8901b036e53d7@mail.gmail.com> Message-ID: On Thu, Mar 11, 2010 at 11:12 AM, David Chelimsky wrote: > 2010/3/11 Nicol?s Sanguinetti : >> Scratch that, it works if you run just that file, if you run the whole >> suite it doesn't. WTH. > > The fact that it works at all is an accident :) Hah, ok :) Why shouldn't two different types of specs work off the same file? (if you care for a technical explanation :)) Since it works by moving it to another file, so I'm just doing that (describe MyController, :type => :controller), so it's just more idle curiosity than anything else, at this point :) >> >> 2010/3/11 Nicol?s Sanguinetti : >>> Interesting: >>> >>> describe SomeModule do >>> ?describe "Bar", :type => :controller do >>> ? ?controller_name "blah" >>> ?end >>> end >>> >>> Doesn't work, while >>> >>> describe SomeModule do >>> end >>> >>> describe "Bar", :type => :controller do >>> ?controller_name "blah" >>> end >>> >>> does. >>> >>> 2010/3/11 Nicol?s Sanguinetti : >>>> On Thu, Mar 11, 2010 at 5:10 AM, Scott Taylor wrote: >>>>> >>>>> On Mar 11, 2010, at 1:26 AM, Nicol?s Sanguinetti wrote: >>>>> >>>>>> We have an app that has "extensions" that are built as rails engines. >>>>>> Each engine needs some code in the controllers, which we solved as >>>>>> "include this module, call a method". In order to test it, though, we >>>>>> don't want to "copy" the test for how that works into each engine, so >>>>>> the idea is to write the tests once, in 'spec/lib/extensions_spec.rb', >>>>>> where we are testing the other stuff that's common for all the >>>>>> extensions (which are defined on lib/extensions.rb, thus the spec's >>>>>> location) >>>>>> >>>>>> In order to do it, I'm declaring a 'sample' controller in the specs >>>>>> (just include the module, call the method), and then writing a couple >>>>>> specs for what we are doing. Problem is, I can't get rspec to >>>>>> understand that that example group is a controller example groups. >>>>>> >>>>>> I have >>>>>> >>>>>> ? ?class MyExampleController < ApplicationController >>>>>> ? ? ?include Extensions::ControllerHelpers >>>>>> ? ? ?call_awesome_method # this, among other things, defines an >>>>>> instance method on the controller that I want to test >>>>>> ? ?end >>>>>> >>>>>> inside my spec, and after that I tried: >>>>>> >>>>>> 1) describe("controller helpers", :type => :controller) { >>>>>> controller_name "my_example"; ... } >>>>>> >>>>>> It complains about controller_name not being a method of this dynamic >>>>>> subclass of ActiveSupport::TestCase. >>>>> >>>>> That seems like a really strange error. ?What is the actual stack trace? >>>> >>>> ./spec/lib/extensions_spec.rb:20: undefined method `controller_name' >>>> for ActiveSupport::TestCase::Subclass_1:Class (NoMethodError) >>>> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/example/example_group_methods.rb:183:in >>>> `module_eval' >>>> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/example/example_group_methods.rb:183:in >>>> `subclass' >>>> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/example/example_group_methods.rb:55:in >>>> `describe' >>>> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/example/example_group_factory.rb:31:in >>>> `create_example_group' >>>> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/dsl/main.rb:28:in `describe' >>>> ? ? ? ?from ./spec/lib/extensions_spec.rb:19 >>>> ? ? ? ?from $gem_path/activesupport-2.3.5/lib/active_support/dependencies.rb:147:in >>>> `load_without_new_constant_marking' >>>> ? ? ? ?from $gem_path/activesupport-2.3.5/lib/active_support/dependencies.rb:147:in >>>> `load' >>>> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:15:in >>>> `load_files' >>>> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:14:in `each' >>>> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:14:in >>>> `load_files' >>>> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/runner/options.rb:133:in `run_examples' >>>> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/runner/command_line.rb:9:in `run' >>>> ? ? ? ?from script/spec:10 >>>> >>>> (sanitized it a bit) >>>> >>>>> What versions of the test-unit gem do you have installed? ?What version of rails? ?rspec? ?If you uninstall the test-unit gem, will it work with the :type => :controller hash given to describe? >>>> >>>> This is using rails 2.3.5, rspec 1.3.0, and rspec-rails 1.3.2. I do >>>> not have test-unit on this system, I have mocha 0.9.8 (though it >>>> shouldn't be required in the environment by anyone here) >>>> >>>>> (I've noticed *very* strange things with the test-unit gem installed in the past - such as a test suite which was 100% green, using a hybrid of mocha + rspec mocks/stubs. ?When the gem was uninstalled, half the test suite failed!) >>>>> >>>>>> After some time reading the source I figured that :type => :controller >>>>>> pretty much just works for config.include/config.extend. So on to the >>>>>> next thing: >>>>> >>>>> Have you taken a look at Spec::Example::ExampleGroupFactory? >>>> >>>> Ah, darn, I hadn't gotten that far into rspec's rabbit hole, and >>>> missed the reference in rspec-rails. That's what you get for trying to >>>> debug stuff at 4am :) So, :type => :controller should be enough, then. >>>> >>>> Still, doing: >>>> >>>> describe MyExampleController, :type => :controller do >>>> ?it "should do stuff" do >>>> ? ?controller.should_receive(:foo) >>>> ? ?controller.extension.bar >>>> ?end >>>> end >>>> >>>> Fails with 'undefined local variable or method `controller' for >>>> #' >>>> >>>> And replacing controller with @controller gives me 'undefined method >>>> `bar' for nil:NilClass'. Which is pretty much the same results I got a >>>> few hours ago before going to sleep :( >>>> >>>> ?So :type => :controller is apparently not enough for rspec to pick up on this. >>>> >>>>> Not sure if this will help, but here's a patch that brynary and I banged out way back in rspec 1.1.9 to support spec/unit & spec/integration: (the usual disclaimer applies - all the good parts are his, all the bad parts are mine) >>>>> >>>>> http://gist.github.com/328919 >>>> >>>> Thanks :) >>>> >>>>> That piece of the code might at least take you to a place where you can debug what's going on. >>>>> >>>>> Best, >>>>> >>>>> Scott >>>>> >>>>> _______________________________________________ >>>>> rspec-users mailing list >>>>> rspec-users at rubyforge.org >>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>> >>>> >>> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Thu Mar 11 08:37:08 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 11 Mar 2010 07:37:08 -0600 Subject: [rspec-users] Testing a rails controller *outside* of spec/controllers In-Reply-To: References: <57c63afe1003110512p6106f057pe0e8901b036e53d7@mail.gmail.com> Message-ID: <57c63afe1003110537m768d792fje69d38dcbc51587a@mail.gmail.com> 2010/3/11 Nicol?s Sanguinetti : > On Thu, Mar 11, 2010 at 11:12 AM, David Chelimsky wrote: >> 2010/3/11 Nicol?s Sanguinetti : >>> Scratch that, it works if you run just that file, if you run the whole >>> suite it doesn't. WTH. >> >> The fact that it works at all is an accident :) > > Hah, ok :) > > Why shouldn't two different types of specs work off the same file? (if > you care for a technical explanation :)) I explained that in another email this thread that I sent about a minute before this one. Maybe google delivered them to you out of order? You can have different types in one file, but not in one nesting construct. Nested example groups are subclasses of the outer group, so it's sort of like this: class Outer < Spec::Example::ExampleGroup; end class Inner < Outer Obviously, things are going to get messy if you try to introduce a new type to the mix on the way down the hierarchy. Make sense? > Since it works by moving it to another file, so I'm just doing that > (describe MyController, :type => :controller), so it's just more idle > curiosity than anything else, at this point :) > >>> >>> 2010/3/11 Nicol?s Sanguinetti : >>>> Interesting: >>>> >>>> describe SomeModule do >>>> ?describe "Bar", :type => :controller do >>>> ? ?controller_name "blah" >>>> ?end >>>> end >>>> >>>> Doesn't work, while >>>> >>>> describe SomeModule do >>>> end >>>> >>>> describe "Bar", :type => :controller do >>>> ?controller_name "blah" >>>> end >>>> >>>> does. >>>> >>>> 2010/3/11 Nicol?s Sanguinetti : >>>>> On Thu, Mar 11, 2010 at 5:10 AM, Scott Taylor wrote: >>>>>> >>>>>> On Mar 11, 2010, at 1:26 AM, Nicol?s Sanguinetti wrote: >>>>>> >>>>>>> We have an app that has "extensions" that are built as rails engines. >>>>>>> Each engine needs some code in the controllers, which we solved as >>>>>>> "include this module, call a method". In order to test it, though, we >>>>>>> don't want to "copy" the test for how that works into each engine, so >>>>>>> the idea is to write the tests once, in 'spec/lib/extensions_spec.rb', >>>>>>> where we are testing the other stuff that's common for all the >>>>>>> extensions (which are defined on lib/extensions.rb, thus the spec's >>>>>>> location) >>>>>>> >>>>>>> In order to do it, I'm declaring a 'sample' controller in the specs >>>>>>> (just include the module, call the method), and then writing a couple >>>>>>> specs for what we are doing. Problem is, I can't get rspec to >>>>>>> understand that that example group is a controller example groups. >>>>>>> >>>>>>> I have >>>>>>> >>>>>>> ? ?class MyExampleController < ApplicationController >>>>>>> ? ? ?include Extensions::ControllerHelpers >>>>>>> ? ? ?call_awesome_method # this, among other things, defines an >>>>>>> instance method on the controller that I want to test >>>>>>> ? ?end >>>>>>> >>>>>>> inside my spec, and after that I tried: >>>>>>> >>>>>>> 1) describe("controller helpers", :type => :controller) { >>>>>>> controller_name "my_example"; ... } >>>>>>> >>>>>>> It complains about controller_name not being a method of this dynamic >>>>>>> subclass of ActiveSupport::TestCase. >>>>>> >>>>>> That seems like a really strange error. ?What is the actual stack trace? >>>>> >>>>> ./spec/lib/extensions_spec.rb:20: undefined method `controller_name' >>>>> for ActiveSupport::TestCase::Subclass_1:Class (NoMethodError) >>>>> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/example/example_group_methods.rb:183:in >>>>> `module_eval' >>>>> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/example/example_group_methods.rb:183:in >>>>> `subclass' >>>>> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/example/example_group_methods.rb:55:in >>>>> `describe' >>>>> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/example/example_group_factory.rb:31:in >>>>> `create_example_group' >>>>> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/dsl/main.rb:28:in `describe' >>>>> ? ? ? ?from ./spec/lib/extensions_spec.rb:19 >>>>> ? ? ? ?from $gem_path/activesupport-2.3.5/lib/active_support/dependencies.rb:147:in >>>>> `load_without_new_constant_marking' >>>>> ? ? ? ?from $gem_path/activesupport-2.3.5/lib/active_support/dependencies.rb:147:in >>>>> `load' >>>>> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:15:in >>>>> `load_files' >>>>> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:14:in `each' >>>>> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:14:in >>>>> `load_files' >>>>> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/runner/options.rb:133:in `run_examples' >>>>> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/runner/command_line.rb:9:in `run' >>>>> ? ? ? ?from script/spec:10 >>>>> >>>>> (sanitized it a bit) >>>>> >>>>>> What versions of the test-unit gem do you have installed? ?What version of rails? ?rspec? ?If you uninstall the test-unit gem, will it work with the :type => :controller hash given to describe? >>>>> >>>>> This is using rails 2.3.5, rspec 1.3.0, and rspec-rails 1.3.2. I do >>>>> not have test-unit on this system, I have mocha 0.9.8 (though it >>>>> shouldn't be required in the environment by anyone here) >>>>> >>>>>> (I've noticed *very* strange things with the test-unit gem installed in the past - such as a test suite which was 100% green, using a hybrid of mocha + rspec mocks/stubs. ?When the gem was uninstalled, half the test suite failed!) >>>>>> >>>>>>> After some time reading the source I figured that :type => :controller >>>>>>> pretty much just works for config.include/config.extend. So on to the >>>>>>> next thing: >>>>>> >>>>>> Have you taken a look at Spec::Example::ExampleGroupFactory? >>>>> >>>>> Ah, darn, I hadn't gotten that far into rspec's rabbit hole, and >>>>> missed the reference in rspec-rails. That's what you get for trying to >>>>> debug stuff at 4am :) So, :type => :controller should be enough, then. >>>>> >>>>> Still, doing: >>>>> >>>>> describe MyExampleController, :type => :controller do >>>>> ?it "should do stuff" do >>>>> ? ?controller.should_receive(:foo) >>>>> ? ?controller.extension.bar >>>>> ?end >>>>> end >>>>> >>>>> Fails with 'undefined local variable or method `controller' for >>>>> #' >>>>> >>>>> And replacing controller with @controller gives me 'undefined method >>>>> `bar' for nil:NilClass'. Which is pretty much the same results I got a >>>>> few hours ago before going to sleep :( >>>>> >>>>> ?So :type => :controller is apparently not enough for rspec to pick up on this. >>>>> >>>>>> Not sure if this will help, but here's a patch that brynary and I banged out way back in rspec 1.1.9 to support spec/unit & spec/integration: (the usual disclaimer applies - all the good parts are his, all the bad parts are mine) >>>>>> >>>>>> http://gist.github.com/328919 >>>>> >>>>> Thanks :) >>>>> >>>>>> That piece of the code might at least take you to a place where you can debug what's going on. >>>>>> >>>>>> Best, >>>>>> >>>>>> Scott >>>>>> >>>>>> _______________________________________________ >>>>>> rspec-users mailing list >>>>>> rspec-users at rubyforge.org >>>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>>> >>>>> >>>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From godfoca at gmail.com Thu Mar 11 08:46:50 2010 From: godfoca at gmail.com (=?ISO-8859-1?Q?Nicol=E1s_Sanguinetti?=) Date: Thu, 11 Mar 2010 11:46:50 -0200 Subject: [rspec-users] Testing a rails controller *outside* of spec/controllers In-Reply-To: <57c63afe1003110537m768d792fje69d38dcbc51587a@mail.gmail.com> References: <57c63afe1003110512p6106f057pe0e8901b036e53d7@mail.gmail.com> <57c63afe1003110537m768d792fje69d38dcbc51587a@mail.gmail.com> Message-ID: On Thu, Mar 11, 2010 at 11:37 AM, David Chelimsky wrote: > 2010/3/11 Nicol?s Sanguinetti : >> On Thu, Mar 11, 2010 at 11:12 AM, David Chelimsky wrote: >>> 2010/3/11 Nicol?s Sanguinetti : >>>> Scratch that, it works if you run just that file, if you run the whole >>>> suite it doesn't. WTH. >>> >>> The fact that it works at all is an accident :) >> >> Hah, ok :) >> >> Why shouldn't two different types of specs work off the same file? (if >> you care for a technical explanation :)) > > I explained that in another email this thread that I sent about a > minute before this one. Maybe google delivered them to you out of > order? > > You can have different types in one file, but not in one nesting > construct. Nested example groups are subclasses of the outer group, so > it's sort of like this: > > class Outer < Spec::Example::ExampleGroup; end > class Inner < Outer > > Obviously, things are going to get messy if you try to introduce a new > type to the mix on the way down the hierarchy. Ah, I thought that you were surprised at having the different types at top-level on the same file passing with script/spec and failing with rake spec -- as in "it should always fail" -- which is why I wanted an explanation, since I didn't see why. I guess it's some random setup thing in another part of the specs. In any case, putting it in a different file makes it always pass (well, as long as the code works :P) Thanks for your time, both you and Scott ^^ > Make sense? > >> Since it works by moving it to another file, so I'm just doing that >> (describe MyController, :type => :controller), so it's just more idle >> curiosity than anything else, at this point :) >> >>>> >>>> 2010/3/11 Nicol?s Sanguinetti : >>>>> Interesting: >>>>> >>>>> describe SomeModule do >>>>> ?describe "Bar", :type => :controller do >>>>> ? ?controller_name "blah" >>>>> ?end >>>>> end >>>>> >>>>> Doesn't work, while >>>>> >>>>> describe SomeModule do >>>>> end >>>>> >>>>> describe "Bar", :type => :controller do >>>>> ?controller_name "blah" >>>>> end >>>>> >>>>> does. >>>>> >>>>> 2010/3/11 Nicol?s Sanguinetti : >>>>>> On Thu, Mar 11, 2010 at 5:10 AM, Scott Taylor wrote: >>>>>>> >>>>>>> On Mar 11, 2010, at 1:26 AM, Nicol?s Sanguinetti wrote: >>>>>>> >>>>>>>> We have an app that has "extensions" that are built as rails engines. >>>>>>>> Each engine needs some code in the controllers, which we solved as >>>>>>>> "include this module, call a method". In order to test it, though, we >>>>>>>> don't want to "copy" the test for how that works into each engine, so >>>>>>>> the idea is to write the tests once, in 'spec/lib/extensions_spec.rb', >>>>>>>> where we are testing the other stuff that's common for all the >>>>>>>> extensions (which are defined on lib/extensions.rb, thus the spec's >>>>>>>> location) >>>>>>>> >>>>>>>> In order to do it, I'm declaring a 'sample' controller in the specs >>>>>>>> (just include the module, call the method), and then writing a couple >>>>>>>> specs for what we are doing. Problem is, I can't get rspec to >>>>>>>> understand that that example group is a controller example groups. >>>>>>>> >>>>>>>> I have >>>>>>>> >>>>>>>> ? ?class MyExampleController < ApplicationController >>>>>>>> ? ? ?include Extensions::ControllerHelpers >>>>>>>> ? ? ?call_awesome_method # this, among other things, defines an >>>>>>>> instance method on the controller that I want to test >>>>>>>> ? ?end >>>>>>>> >>>>>>>> inside my spec, and after that I tried: >>>>>>>> >>>>>>>> 1) describe("controller helpers", :type => :controller) { >>>>>>>> controller_name "my_example"; ... } >>>>>>>> >>>>>>>> It complains about controller_name not being a method of this dynamic >>>>>>>> subclass of ActiveSupport::TestCase. >>>>>>> >>>>>>> That seems like a really strange error. ?What is the actual stack trace? >>>>>> >>>>>> ./spec/lib/extensions_spec.rb:20: undefined method `controller_name' >>>>>> for ActiveSupport::TestCase::Subclass_1:Class (NoMethodError) >>>>>> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/example/example_group_methods.rb:183:in >>>>>> `module_eval' >>>>>> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/example/example_group_methods.rb:183:in >>>>>> `subclass' >>>>>> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/example/example_group_methods.rb:55:in >>>>>> `describe' >>>>>> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/example/example_group_factory.rb:31:in >>>>>> `create_example_group' >>>>>> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/dsl/main.rb:28:in `describe' >>>>>> ? ? ? ?from ./spec/lib/extensions_spec.rb:19 >>>>>> ? ? ? ?from $gem_path/activesupport-2.3.5/lib/active_support/dependencies.rb:147:in >>>>>> `load_without_new_constant_marking' >>>>>> ? ? ? ?from $gem_path/activesupport-2.3.5/lib/active_support/dependencies.rb:147:in >>>>>> `load' >>>>>> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:15:in >>>>>> `load_files' >>>>>> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:14:in `each' >>>>>> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:14:in >>>>>> `load_files' >>>>>> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/runner/options.rb:133:in `run_examples' >>>>>> ? ? ? ?from $gem_path/rspec-1.3.0/lib/spec/runner/command_line.rb:9:in `run' >>>>>> ? ? ? ?from script/spec:10 >>>>>> >>>>>> (sanitized it a bit) >>>>>> >>>>>>> What versions of the test-unit gem do you have installed? ?What version of rails? ?rspec? ?If you uninstall the test-unit gem, will it work with the :type => :controller hash given to describe? >>>>>> >>>>>> This is using rails 2.3.5, rspec 1.3.0, and rspec-rails 1.3.2. I do >>>>>> not have test-unit on this system, I have mocha 0.9.8 (though it >>>>>> shouldn't be required in the environment by anyone here) >>>>>> >>>>>>> (I've noticed *very* strange things with the test-unit gem installed in the past - such as a test suite which was 100% green, using a hybrid of mocha + rspec mocks/stubs. ?When the gem was uninstalled, half the test suite failed!) >>>>>>> >>>>>>>> After some time reading the source I figured that :type => :controller >>>>>>>> pretty much just works for config.include/config.extend. So on to the >>>>>>>> next thing: >>>>>>> >>>>>>> Have you taken a look at Spec::Example::ExampleGroupFactory? >>>>>> >>>>>> Ah, darn, I hadn't gotten that far into rspec's rabbit hole, and >>>>>> missed the reference in rspec-rails. That's what you get for trying to >>>>>> debug stuff at 4am :) So, :type => :controller should be enough, then. >>>>>> >>>>>> Still, doing: >>>>>> >>>>>> describe MyExampleController, :type => :controller do >>>>>> ?it "should do stuff" do >>>>>> ? ?controller.should_receive(:foo) >>>>>> ? ?controller.extension.bar >>>>>> ?end >>>>>> end >>>>>> >>>>>> Fails with 'undefined local variable or method `controller' for >>>>>> #' >>>>>> >>>>>> And replacing controller with @controller gives me 'undefined method >>>>>> `bar' for nil:NilClass'. Which is pretty much the same results I got a >>>>>> few hours ago before going to sleep :( >>>>>> >>>>>> ?So :type => :controller is apparently not enough for rspec to pick up on this. >>>>>> >>>>>>> Not sure if this will help, but here's a patch that brynary and I banged out way back in rspec 1.1.9 to support spec/unit & spec/integration: (the usual disclaimer applies - all the good parts are his, all the bad parts are mine) >>>>>>> >>>>>>> http://gist.github.com/328919 >>>>>> >>>>>> Thanks :) >>>>>> >>>>>>> That piece of the code might at least take you to a place where you can debug what's going on. >>>>>>> >>>>>>> Best, >>>>>>> >>>>>>> Scott >>>>>>> >>>>>>> _______________________________________________ >>>>>>> rspec-users mailing list >>>>>>> rspec-users at rubyforge.org >>>>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>>>> >>>>>> >>>>> >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-users at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> _______________________________________________ >> 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 joahking at gmail.com Fri Mar 12 07:45:42 2010 From: joahking at gmail.com (Joaquin Rivera Padron) Date: Fri, 12 Mar 2010 13:45:42 +0100 Subject: [rspec-users] spec-ing a nested object is saved on the specs of the object it is nested into Message-ID: <8277b7f41003120445xc4931bck30a832da3a78f0dc@mail.gmail.com> hi there, I have a Rails model A, that has_one model B, model A have a method called save_nested_b that: * context 'invalid B params' ** context 'no nested B exists' => do nothing ** context 'nested B exists' => remove it * context 'valid B params' ** context 'no nested B exists' => create it ** context 'nested B exists' => remove it and create new one (or edit attributes linking to A) the save_nested_b method implementation should not be problematic. My question is: on A specs I want to make sure all above on the list happens but not having to repeat all B validations on making 'invalid B params' examples, because B have its own specs, and also the A specs for save_nested_b will be brittle when B validations change (not to mention the combinations of invalid fields can be long) how would you do this? would you do a loose thing like: context 'invalid B params' do .. a.save_nested_b nil a.should have_no_b .. end giving it a more thought after writing this email I guess I would go for this approach, what do you think? greetings, joaquin -- www.least-significant-bit.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Sat Mar 13 13:40:32 2010 From: lists at ruby-forum.com (P. A.) Date: Sat, 13 Mar 2010 19:40:32 +0100 Subject: [rspec-users] Testing file upload (Sinatra, RSpec, Rack-Test) Message-ID: <90dcce9de6f1a69755a798bffa9bcea2@ruby-forum.com> Hi. I have a simple application and I want to add a file upload functionality. How can I write a spec? Here's my try. # directory structure app: - controller.rb - controller.spec.rb - files: [] - fixtures: [test_file.png] # controller.spec.rb require 'rack/test' require 'controller' module MyHelpers def app Sinatra::Application end end Spec::Runner.configure do |conf| conf.include Rack::Test::Methods conf.include MyHelpers end describe 'Application' do it 'should accept uploaded files and save them into the `files` directory' post '/', 'file' => Rack::Test::UploadedFile.new('fixtures/test_file.png', 'image/png') Dir['files/*'].should include('files/test_file.png') end end # controller.rb require 'sinatra' require 'fileutils' post '/' do tempfile = params['file'][:tempfile] FileUtils.copy_file(tempfile.path, 'files') end But when I ran... $ spec -f specdoc controller.rb ...I get the following output. Application - should accept uploaded files and save them into the `files` directory (FAILED - 1) 1) 'Application should accept uploaded files and save them into the `files` directory' FAILED expected [] to include "files/test_file.png" /controller.spec.rb::in `block (2 levels) in ' Finished in 0.132799038 seconds 1 example, 1 failure What I do wrong? Thanks. Debian GNU/Linux 5.0.4; Ruby 1.9.2; Sinatra 0.9.6; RSpec 1.3.0; Rack-Test 0.5.3. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Sat Mar 13 14:21:24 2010 From: lists at ruby-forum.com (P. A.) Date: Sat, 13 Mar 2010 20:21:24 +0100 Subject: [rspec-users] Testing file upload (Sinatra, RSpec, Rack-Test) In-Reply-To: <90dcce9de6f1a69755a798bffa9bcea2@ruby-forum.com> References: <90dcce9de6f1a69755a798bffa9bcea2@ruby-forum.com> Message-ID: <804256dc220c0d0ef18c4dde65fa3f83@ruby-forum.com> P. A. wrote: > Hi. > > I have a simple application and I want to add a file upload > functionality. How can I write a spec? > > Here's my try. > > # directory structure > app: > - controller.rb > - controller.spec.rb > - files: [] > - fixtures: [test_file.png] > > # controller.spec.rb > require 'rack/test' > require 'controller' > > module MyHelpers > def app > Sinatra::Application > end > end > > Spec::Runner.configure do |conf| > conf.include Rack::Test::Methods > conf.include MyHelpers > end > > describe 'Application' do > it 'should accept uploaded files and save them into the `files` > directory' > post '/', 'file' => > Rack::Test::UploadedFile.new('fixtures/test_file.png', 'image/png') > Dir['files/*'].should include('files/test_file.png') > end > end > > # controller.rb > require 'sinatra' > require 'fileutils' > > post '/' do > tempfile = params['file'][:tempfile] > FileUtils.copy_file(tempfile.path, 'files') > end > > But when I ran... > > $ spec -f specdoc controller.rb > > ...I get the following output. > > Application > - should accept uploaded files and save them into the `files` directory > (FAILED - 1) > > 1) > 'Application should accept uploaded files and save them into the `files` > directory' FAILED > expected [] to include "files/test_file.png" > /controller.spec.rb::in `block (2 levels) in > ' > > Finished in 0.132799038 seconds > > 1 example, 1 failure > > What I do wrong? > > Thanks. > > Debian GNU/Linux 5.0.4; > Ruby 1.9.2; > Sinatra 0.9.6; > RSpec 1.3.0; > Rack-Test 0.5.3. I found out the source of the problem by myself. It was in the FileUtils.copy_file method. As it turned out this method doesn't accept a directory name as the second argument. It needs both the first argument and the second argument to be a file names. So, the updated code looks like the following. # controller.rb post '/' do tempfile = params['file'][:tempfile] FileUtils.copy_file(tempfile.path, "files/#{params['file'][:filename]}") # the problem was here end All works now (and that's enough for man to be happy). Thank you for your attention. -- Posted via http://www.ruby-forum.com/. From jeroen.zwartepoorte at gmail.com Sun Mar 14 06:12:44 2010 From: jeroen.zwartepoorte at gmail.com (Jeroen) Date: Sun, 14 Mar 2010 03:12:44 -0700 (PDT) Subject: [rspec-users] autotest & rspec2 Message-ID: <4919f442-3e8c-43e7-bc9c-592f347de1ce@x12g2000yqx.googlegroups.com> Hi guys, I'm trying to find some information on how to get autotest to run the rspec2 tests. I have my project setup so "rake spec" runs the specs properly, but autotest seems to ignore/don't know that there are specs to test. I read on the rspec2 wiki that autotest integration is o be added eventually. Any ideas on how to achieve this? Thanks, Jeroen From steve at hodgkiss.me.uk Fri Mar 12 10:44:24 2010 From: steve at hodgkiss.me.uk (stevehodgkiss) Date: Fri, 12 Mar 2010 07:44:24 -0800 (PST) Subject: [rspec-users] Access to controller and request objects in controller specs (rails 3) Message-ID: <08769ff3-0723-4070-87f5-c4829a9ac66d@t23g2000yqt.googlegroups.com> Hi Rails 3 provides @controller and @request as instance variables in controller tests, whats the equivalent in rspec controller tests? I'm using warden for authentication and need to be able to stub @request.env['warden'] with something so that controllers can be tested. Currently @request is nil (error: undefined method `env' for nil:NilClass). If I remember correctly the default controller specs in rails 2/rspec 1 contained this assertion: controller.should be_an_instance_of(MyController) This fails with rails 3/rspec 2 beta 3 because controller is nil. Any ideas? Thanks Steve From dchelimsky at gmail.com Sun Mar 14 11:11:34 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 14 Mar 2010 10:11:34 -0500 Subject: [rspec-users] autotest & rspec2 In-Reply-To: <4919f442-3e8c-43e7-bc9c-592f347de1ce@x12g2000yqx.googlegroups.com> References: <4919f442-3e8c-43e7-bc9c-592f347de1ce@x12g2000yqx.googlegroups.com> Message-ID: On Mar 14, 2010, at 5:12 AM, Jeroen wrote: > Hi guys, > > I'm trying to find some information on how to get autotest to run the > rspec2 tests. I have my project setup so "rake spec" runs the specs > properly, but autotest seems to ignore/don't know that there are specs > to test. > > I read on the rspec2 wiki that autotest integration is o be added > eventually. Any ideas on how to achieve this? I just pushed preliminary autotest support to github: http://github.com/rspec/rspec-core/commit/c1d600cd4367fb24a333c3f27f3b27693745ad14 I'll release beta.4 today or tomorrow with this support. Note that there will not be an autospec command for rspec-2. All that autospec does is sets an environment variable and creates confusion :) Per the commit message, you just need to add an autotest/discover.rb file in your project with: Autotest.add_discovery { "rspec2" } This may change to just { "rspec" } before rspec-2 goes final, but "rspec2" will work for now. Cheers, David From dchelimsky at gmail.com Sun Mar 14 11:15:22 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 14 Mar 2010 10:15:22 -0500 Subject: [rspec-users] Access to controller and request objects in controller specs (rails 3) In-Reply-To: <08769ff3-0723-4070-87f5-c4829a9ac66d@t23g2000yqt.googlegroups.com> References: <08769ff3-0723-4070-87f5-c4829a9ac66d@t23g2000yqt.googlegroups.com> Message-ID: <8EBDF398-7757-48B8-B248-F7A43C5728D2@gmail.com> On Mar 12, 2010, at 9:44 AM, stevehodgkiss wrote: > Hi > > Rails 3 provides @controller and @request as instance variables in > controller tests, whats the equivalent in rspec controller tests? > > I'm using warden for authentication and need to be able to stub > @request.env['warden'] with something so that controllers can be > tested. Currently @request is nil (error: undefined method `env' for > nil:NilClass). > > If I remember correctly the default controller specs in rails 2/rspec > 1 contained this assertion: > > controller.should be_an_instance_of(MyController) > > This fails with rails 3/rspec 2 beta 3 because controller is nil. > > Any ideas? Right now, rspec-2 controller specs include rails integration test behaviour, not rails controller test behaviour. Before rails-3 and rspec-rails-2 go final, we'll figure out a way to provide access to a controller object, but things are a bit fluid right now on both fronts, so it might not be available for a bit. There is a ticket about this on lighthouse: https://rspec.lighthouseapp.com/projects/5645/tickets/963 Please feel free to follow that ticket and/or weigh in on it. Cheers, David From jeroen.zwartepoorte at gmail.com Sun Mar 14 14:40:33 2010 From: jeroen.zwartepoorte at gmail.com (Jeroen) Date: Sun, 14 Mar 2010 11:40:33 -0700 (PDT) Subject: [rspec-users] autotest & rspec2 In-Reply-To: References: <4919f442-3e8c-43e7-bc9c-592f347de1ce@x12g2000yqx.googlegroups.com> Message-ID: <01b7f4f2-20dc-49c7-957a-6331c5252e4a@t41g2000yqt.googlegroups.com> Cool, thanks! Regards, Jeroen On Mar 14, 4:11?pm, David Chelimsky wrote: > On Mar 14, 2010, at 5:12 AM, Jeroen wrote: > > > Hi guys, > > > I'm trying to find some information on how to get autotest to run the > > rspec2 tests. I have my project setup so "rake spec" runs the specs > > properly, but autotest seems to ignore/don't know that there are specs > > to test. > > > I read on the rspec2 wiki that autotest integration is o be added > > eventually. Any ideas on how to achieve this? > > I just pushed preliminary autotest support to github: > > http://github.com/rspec/rspec-core/commit/c1d600cd4367fb24a333c3f27f3... > > I'll release beta.4 today or tomorrow with this support. > > Note that there will not be an autospec command for rspec-2. All that autospec does is sets an environment variable and creates confusion :) Per the commit message, you just need to add an autotest/discover.rb file in your project with: > > Autotest.add_discovery { "rspec2" } > > This may change to just { "rspec" } before rspec-2 goes final, but "rspec2" will work for now. > > Cheers, > David > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From barunio at gmail.com Sun Mar 14 15:20:31 2010 From: barunio at gmail.com (barunio) Date: Sun, 14 Mar 2010 12:20:31 -0700 (PDT) Subject: [rspec-users] AmbiguousReturnError Message-ID: <61bd69ac-b8df-44ef-b34e-9d9ab9dd8ab9@r1g2000yqj.googlegroups.com> I'm trying to use RSpec to test some screen-scraping code. Because I don't want to hit external websites for my tests, I'm stubbing out the html I expect to receive, and trying to focus my tests on making sure the code is parsing the html correctly, and submitting the correct values when requesting external pages. However, I'm running into a problem. The following code causes RSpec to raise a "Spec::Mocks::AmbiguousReturnError" exception: @agent.should_receive(:submit) do |form, form_button| form.class.should == Mechanize::Form form.username.should == 'username' form.password.should == 'password' end.and_return(@bad_login_page) Am I doing something incorrectly here, or is the problem just that RSpec doesn't like for explicit return values to be specified when a block is supplied to the message expectation? If it is the latter, what would be the recommendation for how to appropriately write this spec? Thanks. From dchelimsky at gmail.com Sun Mar 14 16:11:30 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 14 Mar 2010 15:11:30 -0500 Subject: [rspec-users] AmbiguousReturnError In-Reply-To: <61bd69ac-b8df-44ef-b34e-9d9ab9dd8ab9@r1g2000yqj.googlegroups.com> References: <61bd69ac-b8df-44ef-b34e-9d9ab9dd8ab9@r1g2000yqj.googlegroups.com> Message-ID: <5086CE04-F61C-4AEE-9977-EAE6BAB4B9A7@gmail.com> On Mar 14, 2010, at 2:20 PM, barunio wrote: > I'm trying to use RSpec to test some screen-scraping code. Because I > don't want to hit external websites for my tests, I'm stubbing out the > html I expect to receive, and trying to focus my tests on making sure > the code is parsing the html correctly, and submitting the correct > values when requesting external pages. > > However, I'm running into a problem. The following code causes RSpec > to raise a "Spec::Mocks::AmbiguousReturnError" exception: > > @agent.should_receive(:submit) do |form, form_button| > form.class.should == Mechanize::Form > form.username.should == 'username' > form.password.should == 'password' > end.and_return(@bad_login_page) When you pass a block to should_receive or stub, rspec wants to return the value returned by the block: @agent.should_receive(:submit) do |form, form_button| form.class.should == Mechanize::Form form.username.should == 'username' form.password.should == 'password' @bad_login_page end HTH, David > > Am I doing something incorrectly here, or is the problem just that > RSpec doesn't like for explicit return values to be specified when a > block is supplied to the message expectation? If it is the latter, > what would be the recommendation for how to appropriately write this > spec? > > Thanks. From barunio at gmail.com Sun Mar 14 18:45:59 2010 From: barunio at gmail.com (barunio) Date: Sun, 14 Mar 2010 15:45:59 -0700 (PDT) Subject: [rspec-users] AmbiguousReturnError In-Reply-To: <5086CE04-F61C-4AEE-9977-EAE6BAB4B9A7@gmail.com> References: <61bd69ac-b8df-44ef-b34e-9d9ab9dd8ab9@r1g2000yqj.googlegroups.com> <5086CE04-F61C-4AEE-9977-EAE6BAB4B9A7@gmail.com> Message-ID: <90eefd13-6ced-4575-a6fa-f1555017534a@x12g2000yqx.googlegroups.com> Ah, of course. Thanks, David, this works. On Mar 14, 4:11?pm, David Chelimsky wrote: > On Mar 14, 2010, at 2:20 PM, barunio wrote: > > > I'm trying to use RSpec to test some screen-scraping code. ?Because I > > don't want to hit external websites for my tests, I'm stubbing out the > > html I expect to receive, and trying to focus my tests on making sure > > the code is parsing the html correctly, and submitting the correct > > values when requesting external pages. > > > However, I'm running into a problem. ?The following code causes RSpec > > to raise a "Spec::Mocks::AmbiguousReturnError" exception: > > > @agent.should_receive(:submit) do |form, form_button| > > ?form.class.should == Mechanize::Form > > ?form.username.should == 'username' > > ?form.password.should == 'password' > > end.and_return(@bad_login_page) > > When you pass a block to should_receive or stub, rspec wants to return the value returned by the block: > > @agent.should_receive(:submit) do |form, form_button| > ? form.class.should == Mechanize::Form > ? form.username.should == 'username' > ? form.password.should == 'password' > ? @bad_login_page > end > > HTH, > David > > > > > Am I doing something incorrectly here, or is the problem just that > > RSpec doesn't like for explicit return values to be specified when a > > block is supplied to the message expectation? ?If it is the latter, > > what would be the recommendation for how to appropriately write this > > spec? > > > Thanks. > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From timo.roessner at googlemail.com Mon Mar 15 07:54:22 2010 From: timo.roessner at googlemail.com (jollyroger) Date: Mon, 15 Mar 2010 04:54:22 -0700 (PDT) Subject: [rspec-users] Strange validation errors Message-ID: Hey guys, I'm having a serious rspec-problem at the moment: I keep getting strange, empty validation errors when I run the whole spec-suite: ################################################################# 1) ActiveRecord::RecordInvalid in 'LikesController DELETE destroy' should change like-count' Validation failed: my_project/vendor/bundled_gems/gems/activerecord-2.3.5/lib/ active_record/validations.rb:1090:in `save_without_dirty!' my_project/vendor/bundled_gems/gems/activerecord-2.3.5/lib/ active_record/dirty.rb:87:in `save_without_transactions!' my_project/vendor/bundled_gems/gems/activerecord-2.3.5/lib/ active_record/transactions.rb:200:in `save!' my_project/vendor/bundled_gems/gems/activerecord-2.3.5/lib/ active_record/connection_adapters/abstract/database_statements.rb: 136:in `transaction' my_project/vendor/bundled_gems/gems/activerecord-2.3.5/lib/ active_record/transactions.rb:182:in `transaction' my_project/vendor/bundled_gems/gems/activerecord-2.3.5/lib/ active_record/transactions.rb:200:in `save!' my_project/vendor/bundled_gems/gems/activerecord-2.3.5/lib/ active_record/transactions.rb:208:in `rollback_active_record_state!' my_project/vendor/bundled_gems/gems/activerecord-2.3.5/lib/ active_record/transactions.rb:200:in `save!' my_project/vendor/bundled_gems/gems/factory_girl-1.2.3/lib/ factory_girl/proxy/create.rb:6:in `result' my_project/vendor/bundled_gems/gems/factory_girl-1.2.3/lib/ factory_girl/factory.rb:316:in `run' my_project/vendor/bundled_gems/gems/factory_girl-1.2.3/lib/ factory_girl/factory.rb:260:in `create' my_project/vendor/bundled_gems/gems/factory_girl-1.2.3/lib/ factory_girl/proxy/build.rb:17:in `associate' my_project/vendor/bundled_gems/gems/factory_girl-1.2.3/lib/ factory_girl/attribute/association.rb:15:in `add_to' my_project/vendor/bundled_gems/gems/factory_girl-1.2.3/lib/ factory_girl/factory.rb:313:in `run' my_project/vendor/bundled_gems/gems/factory_girl-1.2.3/lib/ factory_girl/factory.rb:311:in `each' my_project/vendor/bundled_gems/gems/factory_girl-1.2.3/lib/ factory_girl/factory.rb:311:in `run' my_project/vendor/bundled_gems/gems/factory_girl-1.2.3/lib/ factory_girl/factory.rb:260:in `create' my_project/vendor/bundled_gems/gems/factory_girl-1.2.3/lib/ factory_girl/factory.rb:291:in `send' my_project/vendor/bundled_gems/gems/factory_girl-1.2.3/lib/ factory_girl/factory.rb:291:in `default_strategy' my_project/vendor/bundled_gems/gems/factory_girl-1.2.3/lib/ factory_girl.rb:21:in `Factory' ./spec/controllers/likes_controller_spec.rb:46: ################################################################# Here is the corresponding spec: ################################################################# it "should change like-count" do we_are_logged_in_as(get_member_user) entry = Factory(:entry) Factory(:like, :user => get_member_user, :entry => entry) lambda do post 'destroy', :entry_id => entry.id end.should change(Like, :count).by(-1) response.should be_success end ################################################################# Trouble-Shooting turns out to be difficult: The spec itself seems to be correct, when running the spec-file alone I don't get any errors. I only get this error when running the whole spec-suite - running the single spec file is fine: ################################################################# spec spec/controllers/likes_controller_spec.rb Example disabled: should change like-count on success ... Finished in 0.756284 seconds 3 examples, 0 failures ################################################################# I have a lot of other specs failing in the very same way. The errors itself are confusing - empty validation error messages are utterly meaningless. I suspect that there is something going wrong with all the stubbing / mocking within in my specs. To be concrete: I suspect that something like: Foo.any_instance.stubs(:bar).returns.... within a spec isn't properly isolated from the other specs, thus causing strange validation errors. What do you guys think? How could I narrow down this error further? Sys-Info: OS: Ubuntu 9.10 spec -v rspec 1.3.0 Mocking / Stubbing: Mocha 0.9.8 From timo.roessner at googlemail.com Mon Mar 15 08:24:52 2010 From: timo.roessner at googlemail.com (jollyroger) Date: Mon, 15 Mar 2010 05:24:52 -0700 (PDT) Subject: [rspec-users] Insufficient database clean-up between specs Message-ID: <8f3fc0ea-02c0-46ec-a6fa-dbb58b0c9b9e@d2g2000yqa.googlegroups.com> Hey guys, unfortunately I've got one more issue with rspec right now. It seems like rspec isnt properly cleaning up the database after each spec. I have the following spec: ################################################################### describe ProfilesController do describe "GET 'index'" do it 'should render active profiles' do active_user = Factory(:user, :active => 1) active_user.profile = Factory.build(:profile) inactive_user = Factory(:user, :active => 0) inactive_user.profile = Factory.build(:profile) get 'index' assigns[:profiles].should == [active_user.profile] end end # ...... end ################################################################### This spec fails with: ################################################################### 'ProfilesController GET 'index' should render active profiles' FAILED expected: [#], got: [#, #, #, #] (using ==) ################################################################### As you can see, the problem is that there are more profiles than actually expected. Running this exact spec alone is ok: ################################################################### spec spec/controllers/profiles_controller_spec.rb -l 17 . Finished in 7.743924 seconds 1 example, 0 failures ################################################################### The same goes for the whole spec-file itself: ################################################################### spec spec/controllers/profiles_controller_spec.rb ............ Finished in 6.108002 seconds 12 examples, 0 failures ################################################################### A quick debugging via: ################################################################### it 'should render active profiles' do custom_log("Profile-count before: #{Profile.count.to_s}") # ........ see code from before get 'index' custom_log("Profile-count after: #{Profile.count.to_s}") assigns[:profiles].should == [active_user.profile] end ################################################################### shows: ################################################################### Profile-count before: 3 Profile-count after: 5 ################################################################### Apparently the problem is, that there are still previously created profiles around. As far as I've understood rspec, shouldn't the database be properly cleaned up after each spec? In other words, shouldn't there be zero profiles before running the spec from above? Sys-Info: OS: Ubuntu 9.10 spec -v rspec 1.3.0 Mocking / Stubbing: Mocha 0.9.8 From dchelimsky at gmail.com Mon Mar 15 08:34:13 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 15 Mar 2010 07:34:13 -0500 Subject: [rspec-users] Insufficient database clean-up between specs In-Reply-To: <8f3fc0ea-02c0-46ec-a6fa-dbb58b0c9b9e@d2g2000yqa.googlegroups.com> References: <8f3fc0ea-02c0-46ec-a6fa-dbb58b0c9b9e@d2g2000yqa.googlegroups.com> Message-ID: <57c63afe1003150534v1f669136r26cd004430cfabb7@mail.gmail.com> On Mon, Mar 15, 2010 at 7:24 AM, jollyroger wrote: > Hey guys, > > unfortunately I've got one more issue with rspec right now. > > It seems like rspec isnt properly cleaning up the database after each > spec. > > I have the following spec: > > ################################################################### > describe ProfilesController do > ?describe "GET 'index'" do > ? ?it 'should render active profiles' do > ? ? ?active_user = Factory(:user, :active => 1) > ? ? ?active_user.profile = Factory.build(:profile) > ? ? ?inactive_user = Factory(:user, :active => 0) > ? ? ?inactive_user.profile = Factory.build(:profile) > ? ? ?get 'index' > ? ? ?assigns[:profiles].should == [active_user.profile] > ? ?end > ?end > ?# ...... > end > ################################################################### > > This spec fails with: > > ################################################################### > 'ProfilesController GET 'index' should render active profiles' FAILED > expected: [# country: "Yemen, Rep.", icon_file_name: nil, icon_content_type: nil, > icon_file_size: nil, icon_updated_at: nil, description: "I've gotten > burned over Cheryl Tiegs and blown up f...", personal_website_url: > "www.google.com", social_network_of_choice: nil, twitter_name: > "Sarah", created_at: "2010-03-15 11:41:56", updated_at: "2010-03-15 > 11:41:56">], > ? ? got: [# country: "Yemen, Rep.", icon_file_name: nil, icon_content_type: nil, > icon_file_size: nil, icon_updated_at: nil, description: "I've gotten > burned over Cheryl Tiegs and blown up f...", personal_website_url: > "www.google.com", social_network_of_choice: nil, twitter_name: > "Sarah", created_at: "2010-03-15 11:41:56", updated_at: "2010-03-15 > 11:41:56">, # nil, icon_file_name: nil, icon_content_type: nil, icon_file_size: nil, > icon_updated_at: nil, description: nil, personal_website_url: nil, > social_network_of_choice: nil, twitter_name: nil, created_at: > "2010-03-15 11:21:15", updated_at: "2010-03-15 11:21:15">, # id: 40, user_id: 40, real_name: nil, country: nil, icon_file_name: > nil, icon_content_type: nil, icon_file_size: nil, icon_updated_at: > nil, description: nil, personal_website_url: nil, > social_network_of_choice: nil, twitter_name: nil, created_at: > "2010-03-15 11:21:15", updated_at: "2010-03-15 11:21:15">, # id: 52, user_id: 52, real_name: nil, country: nil, icon_file_name: > nil, icon_content_type: nil, icon_file_size: nil, icon_updated_at: > nil, description: nil, personal_website_url: nil, > social_network_of_choice: nil, twitter_name: nil, created_at: > "2010-03-15 11:21:15", updated_at: "2010-03-15 11:21:15">] (using ==) > ################################################################### > > As you can see, the problem is that there are more profiles than > actually expected. > > Running this exact spec alone is ok: > > ################################################################### > spec spec/controllers/profiles_controller_spec.rb -l 17 > . > > Finished in 7.743924 seconds > > 1 example, 0 failures > ################################################################### > > The same goes for the whole spec-file itself: > > ################################################################### > spec spec/controllers/profiles_controller_spec.rb > ............ > > Finished in 6.108002 seconds > > 12 examples, 0 failures > ################################################################### > > A quick debugging via: > > ################################################################### > ? ?it 'should render active profiles' do > ? ? ?custom_log("Profile-count before: #{Profile.count.to_s}") > ? ? ?# ........ see code from before > ? ? ?get 'index' > ? ? ?custom_log("Profile-count after: #{Profile.count.to_s}") > ? ? ?assigns[:profiles].should == [active_user.profile] > ? ?end > ################################################################### > > shows: > > ################################################################### > Profile-count before: 3 > Profile-count after: 5 > ################################################################### > > Apparently the problem is, that there are still previously created > profiles around. > > As far as I've understood rspec, shouldn't the database be properly > cleaned up after each spec? > In other words, shouldn't there be zero profiles before running the > spec from above? rspec-rails hooks into rails' transaction management, rolling back transactions after every example. It does not guarantee that your database is empty - just that it is in the same state after each example that it was in before. Now there are a couple of caveats here: 1 - you have to have "config.use_transactional_fixtures = true" in spec/spec_helper.rb This is rails' nomenclature and really means "run each example in a transaction" 2 - if you use before(:all) anywhere in your suite, that code is _not_ run in a transaction and it is up to you to destroy any data you create. HTH, David > Sys-Info: > OS: Ubuntu 9.10 > spec -v > rspec 1.3.0 > Mocking / Stubbing: Mocha 0.9.8 From giorgian at gmail.com Mon Mar 15 04:48:19 2010 From: giorgian at gmail.com (giorgian) Date: Mon, 15 Mar 2010 01:48:19 -0700 (PDT) Subject: [rspec-users] [rails] mock controllers, different behaviour between ruby 1.8.7 and ruby 1.9.1 Message-ID: <2f5eddb0-53d5-455d-8efb-a36ba4b67631@x12g2000yqx.googlegroups.com> Hi, I wanted to test something like this: # /lib/rest_verification.rb module RestVerification def self.included(base) # :nodoc: base.extend(ClassMethods) end module ClassMethods def verify_rest_actions verify :method => :post, :only => [:create], :redirect_to => { :action => :new } ... end end end (just send some verify to controller). My attempt: describe RestVerification do class FooController < ActionController::Base include RestVerification verify_rest_actions def new ; end def index ; end def create ; end def edit ; end def update ; end def destroy ; end end # controller_name 'foo' # this only works with ruby 1.8.7 : 1.9.1 says "uninitialized constant FooController" tests FooController # this works with both before(:each) do ActionController::Routing::Routes.draw do |map| map.resources :foo end end after(:each) do ActionController::Routing::Routes.reload! end it ':create should redirect to :new if invoked with wrong verb' do [:get, :put, :delete].each do |verb| send verb, :create response.should redirect_to(new_foo_url) end end ... end Using ruby 1.8.7 it works: $ ruby -v ruby 1.8.7 (2010-01-10 patchlevel 249) [i486-linux] $ rake RestVerification :create should redirect to :new if invoked with wrong verb Finished in 0.175586 seconds Using ruby 1.9.1 it fails: $ rvm use 1.9.1 Using ruby 1.9.1 p378 $ rake RestVerification :create should redirect to :new if invoked with wrong verb (FAILED - 1) 1) 'RestVerification :create should redirect to :new if invoked with wrong verb' FAILED expected redirect to "http://test.host/foo/new", got redirect to "http://test.host/spec/rails/example/controller_example_group/ subclass_1/foo/new" What can I do to make it work under ruby 1.9.1? thanks pietro From dchelimsky at gmail.com Mon Mar 15 08:40:53 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 15 Mar 2010 07:40:53 -0500 Subject: [rspec-users] Strange validation errors In-Reply-To: References: Message-ID: <57c63afe1003150540i26199d3cy4f49e4081cc93f6d@mail.gmail.com> On Mon, Mar 15, 2010 at 6:54 AM, jollyroger wrote: > Hey guys, > > I'm having a serious rspec-problem at the moment: > > I keep getting strange, empty validation errors when I run the whole > spec-suite: > > ################################################################# > 1) > ActiveRecord::RecordInvalid in 'LikesController DELETE destroy' should > change like-count' > Validation failed: > my_project/vendor/bundled_gems/gems/activerecord-2.3.5/lib/ > active_record/validations.rb:1090:in `save_without_dirty!' > my_project/vendor/bundled_gems/gems/activerecord-2.3.5/lib/ > active_record/dirty.rb:87:in `save_without_transactions!' > my_project/vendor/bundled_gems/gems/activerecord-2.3.5/lib/ > active_record/transactions.rb:200:in `save!' > my_project/vendor/bundled_gems/gems/activerecord-2.3.5/lib/ > active_record/connection_adapters/abstract/database_statements.rb: > 136:in `transaction' > my_project/vendor/bundled_gems/gems/activerecord-2.3.5/lib/ > active_record/transactions.rb:182:in `transaction' > my_project/vendor/bundled_gems/gems/activerecord-2.3.5/lib/ > active_record/transactions.rb:200:in `save!' > my_project/vendor/bundled_gems/gems/activerecord-2.3.5/lib/ > active_record/transactions.rb:208:in `rollback_active_record_state!' > my_project/vendor/bundled_gems/gems/activerecord-2.3.5/lib/ > active_record/transactions.rb:200:in `save!' > my_project/vendor/bundled_gems/gems/factory_girl-1.2.3/lib/ > factory_girl/proxy/create.rb:6:in `result' > my_project/vendor/bundled_gems/gems/factory_girl-1.2.3/lib/ > factory_girl/factory.rb:316:in `run' > my_project/vendor/bundled_gems/gems/factory_girl-1.2.3/lib/ > factory_girl/factory.rb:260:in `create' > my_project/vendor/bundled_gems/gems/factory_girl-1.2.3/lib/ > factory_girl/proxy/build.rb:17:in `associate' > my_project/vendor/bundled_gems/gems/factory_girl-1.2.3/lib/ > factory_girl/attribute/association.rb:15:in `add_to' > my_project/vendor/bundled_gems/gems/factory_girl-1.2.3/lib/ > factory_girl/factory.rb:313:in `run' > my_project/vendor/bundled_gems/gems/factory_girl-1.2.3/lib/ > factory_girl/factory.rb:311:in `each' > my_project/vendor/bundled_gems/gems/factory_girl-1.2.3/lib/ > factory_girl/factory.rb:311:in `run' > my_project/vendor/bundled_gems/gems/factory_girl-1.2.3/lib/ > factory_girl/factory.rb:260:in `create' > my_project/vendor/bundled_gems/gems/factory_girl-1.2.3/lib/ > factory_girl/factory.rb:291:in `send' > my_project/vendor/bundled_gems/gems/factory_girl-1.2.3/lib/ > factory_girl/factory.rb:291:in `default_strategy' > my_project/vendor/bundled_gems/gems/factory_girl-1.2.3/lib/ > factory_girl.rb:21:in `Factory' > ./spec/controllers/likes_controller_spec.rb:46: > ################################################################# > > Here is the corresponding spec: > > ################################################################# > ? ?it "should change like-count" do > ? ? ?we_are_logged_in_as(get_member_user) > ? ? ?entry = Factory(:entry) > ? ? ?Factory(:like, :user => get_member_user, :entry => entry) > ? ? ?lambda do > ? ? ? ?post 'destroy', :entry_id => entry.id > ? ? ?end.should change(Like, :count).by(-1) > ? ? ?response.should be_success > ? ?end > ################################################################# > > Trouble-Shooting turns out to be difficult: > > The spec itself seems to be correct, when running the spec-file alone > I don't get any errors. > I only get this error when running the whole spec-suite - running the > single spec file is fine: > > ################################################################# > spec spec/controllers/likes_controller_spec.rb > Example disabled: should change like-count on success > ... > > Finished in 0.756284 seconds > > 3 examples, 0 failures > ################################################################# > > I have a lot of other specs failing in the very same way. > The errors itself are confusing - empty validation error messages are > utterly meaningless. > > I suspect that there is something going wrong with all the stubbing / > mocking within in my specs. > > To be concrete: > > I suspect that something like: > > Foo.any_instance.stubs(:bar).returns.... > > within a spec isn't properly isolated from the other specs, thus > causing strange validation errors. > > What do you guys think? > How could I narrow down this error further? > > Sys-Info: > OS: Ubuntu 9.10 > spec -v > rspec 1.3.0 > Mocking / Stubbing: Mocha 0.9.8 Take a look at this thread and see if it helps: http://groups.google.com/group/mocha-developer/browse_thread/thread/5c2b8b28f700bb17?hl=en From dchelimsky at gmail.com Mon Mar 15 08:44:05 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 15 Mar 2010 07:44:05 -0500 Subject: [rspec-users] [rails] mock controllers, different behaviour between ruby 1.8.7 and ruby 1.9.1 In-Reply-To: <2f5eddb0-53d5-455d-8efb-a36ba4b67631@x12g2000yqx.googlegroups.com> References: <2f5eddb0-53d5-455d-8efb-a36ba4b67631@x12g2000yqx.googlegroups.com> Message-ID: <57c63afe1003150544y717798fcueb0b2b6917e340d2@mail.gmail.com> On Mon, Mar 15, 2010 at 3:48 AM, giorgian wrote: > Hi, > > I wanted to test something like this: > > # /lib/rest_verification.rb > module RestVerification > ?def self.included(base) # :nodoc: > ? ?base.extend(ClassMethods) > ?end > > ?module ClassMethods > ? ?def verify_rest_actions > ? ? ?verify :method => :post, :only => [:create], :redirect_to ?=> > { :action => :new } > ? ? ?... > ? ?end > ?end > end > > (just send some verify to controller). > > My attempt: > > describe RestVerification do > > ?class FooController < ActionController::Base > ? ?include RestVerification > ? ?verify_rest_actions > > ? ?def new ; end > ? ?def index ; end > ? ?def create ; end > ? ?def edit ; end > ? ?def update ; end > ? ?def destroy ; end > ?end > > ?# controller_name 'foo' # this only works with ruby 1.8.7 : 1.9.1 > says "uninitialized constant FooController" > ?tests FooController # this works with both > > ?before(:each) do > ? ?ActionController::Routing::Routes.draw do |map| > ? ? ?map.resources :foo > ? ?end > ?end > > ?after(:each) do > ? ?ActionController::Routing::Routes.reload! > ?end > > ?it ':create should redirect to :new if invoked with wrong verb' do > ? ?[:get, :put, :delete].each do |verb| > ? ? ?send verb, :create > ? ? ?response.should redirect_to(new_foo_url) > ? ?end > ?end > > ?... > end > > > Using ruby 1.8.7 it works: > > $ ruby -v > ruby 1.8.7 (2010-01-10 patchlevel 249) [i486-linux] > $ rake > RestVerification > ?:create should redirect to :new if invoked with wrong verb > > Finished in 0.175586 seconds > > Using ruby 1.9.1 it fails: > > $ rvm use 1.9.1 > Using ruby 1.9.1 p378 > $ rake > RestVerification > ?:create should redirect to :new if invoked with wrong verb (FAILED - > 1) > 1) > 'RestVerification :create should redirect to :new if invoked with > wrong verb' FAILED > expected redirect to "http://test.host/foo/new", got redirect to > "http://test.host/spec/rails/example/controller_example_group/ > subclass_1/foo/new" > > > What can I do to make it work under ruby 1.9.1? This has to do with scoping changes in ruby 1.9.1, which I hear are going to be changed back in 1.9.2, but that's only hearsay. Try defining FooController outside the describe block. Either that or prefixing it with :: like this: class ::FooController < ::ActionController::Base Either should solve the problem. HTH, David From dchelimsky at gmail.com Mon Mar 15 09:15:55 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 15 Mar 2010 08:15:55 -0500 Subject: [rspec-users] spec-ing a nested object is saved on the specs of the object it is nested into In-Reply-To: <8277b7f41003120445xc4931bck30a832da3a78f0dc@mail.gmail.com> References: <8277b7f41003120445xc4931bck30a832da3a78f0dc@mail.gmail.com> Message-ID: <57c63afe1003150615i1b46c561u13f8c516e0990a45@mail.gmail.com> On Fri, Mar 12, 2010 at 7:45 AM, Joaquin Rivera Padron wrote: > hi there, > I have a Rails model A, that has_one model B, model A have a method called > save_nested_b that: > * context 'invalid B params' > ?** context 'no nested B exists' => do nothing > ?** context 'nested B exists' => remove it > > * context 'valid B params' > ?** context 'no nested B exists' => create it > ?** context 'nested B exists' => remove it and create new one (or edit > attributes linking to A) > > the save_nested_b method implementation should not be problematic. My > question is: > > on A specs I want to make sure all above on the list happens but not having > to repeat all B validations on making 'invalid B params' examples, because B > have its own specs, and also the A specs for save_nested_b will be brittle > when B validations change (not to mention the combinations of invalid fields > can be long) > > how would you do this? would you do a loose thing like: > > context 'invalid B params' do > .. > a.save_nested_b nil > a.should have_no_b > .. > end > > giving it a more thought after writing this email I guess I would go for this approach, what do you think? Depends on who is calling save_nested_b. I usually save associations via callbacks as part of the save operation, and wouldn't call save_nested_b from outside the A object. In that case, I'd treat save_nested_b as a private method and likely not spec it directly. i.e. a = A.create!(valid_a_attributes, :b => valid_b_attributes) a.should have_a_b a = A.create!(valid_a_attributes, :b => invalid_b_attributes) a.should have_no_b etc WDYT? David From joahking at gmail.com Mon Mar 15 09:35:33 2010 From: joahking at gmail.com (Joaquin Rivera Padron) Date: Mon, 15 Mar 2010 14:35:33 +0100 Subject: [rspec-users] spec-ing a nested object is saved on the specs of the object it is nested into In-Reply-To: <57c63afe1003150615i1b46c561u13f8c516e0990a45@mail.gmail.com> References: <8277b7f41003120445xc4931bck30a832da3a78f0dc@mail.gmail.com> <57c63afe1003150615i1b46c561u13f8c516e0990a45@mail.gmail.com> Message-ID: <8277b7f41003150635k12089b74v79377d69ecb35e98@mail.gmail.com> thanks for your reply David, what worried me (well, got me thinking) was having to put on A's specs too much knowledge about when B's attributes were valid or not. I ended up doing more or less what you expose, but only: * using nil as the invalid input * using one valid combination for the valid ones greetings, joaquin 2010/3/15 David Chelimsky > On Fri, Mar 12, 2010 at 7:45 AM, Joaquin Rivera Padron > wrote: > > hi there, > > I have a Rails model A, that has_one model B, model A have a method > called > > save_nested_b that: > > * context 'invalid B params' > > ** context 'no nested B exists' => do nothing > > ** context 'nested B exists' => remove it > > > > * context 'valid B params' > > ** context 'no nested B exists' => create it > > ** context 'nested B exists' => remove it and create new one (or edit > > attributes linking to A) > > > > the save_nested_b method implementation should not be problematic. My > > question is: > > > > on A specs I want to make sure all above on the list happens but not > having > > to repeat all B validations on making 'invalid B params' examples, > because B > > have its own specs, and also the A specs for save_nested_b will be > brittle > > when B validations change (not to mention the combinations of invalid > fields > > can be long) > > > > how would you do this? would you do a loose thing like: > > > > context 'invalid B params' do > > .. > > a.save_nested_b nil > > a.should have_no_b > > .. > > end > > > > giving it a more thought after writing this email I guess I would go for > this approach, what do you think? > > Depends on who is calling save_nested_b. I usually save associations > via callbacks as part of the save operation, and wouldn't call > save_nested_b from outside the A object. In that case, I'd treat > save_nested_b as a private method and likely not spec it directly. > i.e. > > a = A.create!(valid_a_attributes, :b => valid_b_attributes) > a.should have_a_b > > a = A.create!(valid_a_attributes, :b => invalid_b_attributes) > a.should have_no_b > > etc > > WDYT? > > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- www.least-significant-bit.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Mon Mar 15 10:54:53 2010 From: lists at ruby-forum.com (Rails Learner) Date: Mon, 15 Mar 2010 15:54:53 +0100 Subject: [rspec-users] Problwm with Webrat and Selenium Message-ID: <2dd21b4106627748ac8ad1b218df44ea@ruby-forum.com> Hello Everyone, I am having problem running Webrat steps through Firefox using Selenium. I doesn't give me any error, but it never does anything. Well, I am using Windows XP (I know....) Here are the gems I am using: cucumber (0.6.2) cucumber-rails (0.3.0, 0.2.4) database_cleaner (0.5.0, 0.4.3) mongrel (1.1.5) rspec (1.3.0) rspec-rails (1.3.2) selenium-client (1.2.18) Here is what I get: ==> Waiting for Selenium RC server on port 4444... Ready! ** WARNING: Win32 does not support daemon mode. ** Daemonized, any open files are closed. Look at H:/Workspace/Rails/ Test/showt ime/tmp/pids/mongrel_selenium.pid and log/mongrel.log for info. ** Starting Mongrel listening at 0.0.0.0:3001 ** Starting Rails with test environment... C:/Ruby/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/rails/gem_dependency.rb: 119:Warni ng: Gem::Dependency#version_requirements is deprecated and will be removed on or after August 2010. Use #requirement ** Rails loaded. ** Loading any Rails specific GemPlugins ** Signals ready. INT => stop (no restart). ** Mongrel 1.1.5 available at 0.0.0.0:3001 It just sits there and does nothing. I have done a lot of things to fix this but nothing works. Any help is much appreciated. Thank a lot!!!!!!!! -- Posted via http://www.ruby-forum.com/. From eddanger at gmail.com Mon Mar 15 13:50:03 2010 From: eddanger at gmail.com (emdub) Date: Mon, 15 Mar 2010 10:50:03 -0700 (PDT) Subject: [rspec-users] Is share_examples_for deprecated? In-Reply-To: <57c63afe1003070443k3473f61ay69426feb7765f99f@mail.gmail.com> References: <57c63afe1003070443k3473f61ay69426feb7765f99f@mail.gmail.com> Message-ID: <153fe851-3ab2-4f89-b1b0-6ded330f108d@u19g2000prh.googlegroups.com> I think what is easiest/cleanest in the code should prevail :) I personally like "shared_examples_for", but can easily adapt to whatever decision is made. On a semi-related note. Where do I require my shared specs so it_should_behave_like can find my shared example groups? Is there any convention for this? Cheers, Mike. On Mar 7, 5:43?am, David Chelimsky wrote: > On Sat, Mar 6, 2010 at 10:21 PM, Nick Hoffman wrote: > > Pat Maddox wrote: > >> describe "something something", :shared => true do > >> ? ... > >> end > > >> describe "chunky bacon" do > >> ? it_should_behave_like "something something" > >> end > > > BTW, is rspec.info supposed to be up-to-date? It still recommends using > > "shared_examples_for". > > >http://rspec.info/documentation/ > > So this presents an interesting problem :) > > My intent some time back was to deprecate :shared => true, not > share_examples_for (which is aliased with shared_examples_for). Based > on that, the rspec.info site is correct and Pat is incorrect. However, > Pat didn't know that because I never communicated it in any other way > besides documenting the method on the site. > > Now as we're introducing rspec-2 to the mix, option hashes passed to > describe and it will become much more common. On the grounds that it > would simplify the API, it seems to me it might make more sense in > rspec-2 to use :shared => true and get rid of these methods. > > Thoughts? > > David > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Mon Mar 15 16:40:35 2010 From: lists at ruby-forum.com (Nick Hoffman) Date: Mon, 15 Mar 2010 21:40:35 +0100 Subject: [rspec-users] Is share_examples_for deprecated? In-Reply-To: <153fe851-3ab2-4f89-b1b0-6ded330f108d@u19g2000prh.googlegroups.com> References: <57c63afe1003070443k3473f61ay69426feb7765f99f@mail.gmail.com> <153fe851-3ab2-4f89-b1b0-6ded330f108d@u19g2000prh.googlegroups.com> Message-ID: emdub wrote: > I think what is easiest/cleanest in the code should prevail :) I > personally like "shared_examples_for", but can easily adapt to > whatever decision is made. > > On a semi-related note. Where do I require my shared specs so > it_should_behave_like can find my shared example groups? Is there any > convention for this? > > Cheers, > > Mike. Here you go, mate: http://pastie.org/870928 -- Posted via http://www.ruby-forum.com/. From chris.dimartino at gmail.com Tue Mar 16 00:16:19 2010 From: chris.dimartino at gmail.com (Chris DiMartino) Date: Tue, 16 Mar 2010 00:16:19 -0400 Subject: [rspec-users] Testing the <=> operator Message-ID: <85372ae71003152116h5675ab44w979f1ad537d6a733@mail.gmail.com> I'm having trouble getting rspec to allow me to test my Comparable class. I would like to test the <=> method, but rspec is giving me unexpected results: @hand = Hand.new('R') @other_hand = Hand.new('S') @hand.should be > @other_hand expected > #, got # Shouldn't that test be checking for the comparison operator? chris -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Tue Mar 16 00:55:38 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 15 Mar 2010 23:55:38 -0500 Subject: [rspec-users] Testing the <=> operator In-Reply-To: <85372ae71003152116h5675ab44w979f1ad537d6a733@mail.gmail.com> References: <85372ae71003152116h5675ab44w979f1ad537d6a733@mail.gmail.com> Message-ID: <37C87CC4-F098-4C8C-8D55-9C0B32ABB264@gmail.com> On Mar 15, 2010, at 11:16 PM, Chris DiMartino wrote: > I'm having trouble getting rspec to allow me to test my Comparable class. I would like to test the <=> method, but rspec is giving me unexpected results: > > @hand = Hand.new('R') > @other_hand = Hand.new('S') > @hand.should be > @other_hand > > expected > #, got # > > Shouldn't that test be checking for the comparison operator? Nope. Keep in mind that most operators in ruby are actually methods. When the example says: @hand.should be > @other_hand Ruby evaluates that as this: @hand.should(be.>(@other_hand)) Which rspec then translates to this (more or less): @hand.>(@other_hand) ? pass : fail That make sense? From matt at mattwynne.net Tue Mar 16 06:10:35 2010 From: matt at mattwynne.net (Matt Wynne) Date: Tue, 16 Mar 2010 10:10:35 +0000 Subject: [rspec-users] Insufficient database clean-up between specs In-Reply-To: <57c63afe1003150534v1f669136r26cd004430cfabb7@mail.gmail.com> References: <8f3fc0ea-02c0-46ec-a6fa-dbb58b0c9b9e@d2g2000yqa.googlegroups.com> <57c63afe1003150534v1f669136r26cd004430cfabb7@mail.gmail.com> Message-ID: <367FFA25-A694-452A-84F9-AB2AA07DB26B@mattwynne.net> On 15 Mar 2010, at 12:34, David Chelimsky wrote: > On Mon, Mar 15, 2010 at 7:24 AM, jollyroger > wrote: >> Hey guys, >> >> unfortunately I've got one more issue with rspec right now. >> >> It seems like rspec isnt properly cleaning up the database after each >> spec. >> >> I have the following spec: >> >> ################################################################### >> describe ProfilesController do >> describe "GET 'index'" do >> it 'should render active profiles' do >> active_user = Factory(:user, :active => 1) >> active_user.profile = Factory.build(:profile) >> inactive_user = Factory(:user, :active => 0) >> inactive_user.profile = Factory.build(:profile) >> get 'index' >> assigns[:profiles].should == [active_user.profile] >> end >> end >> # ...... >> end >> ################################################################### >> >> This spec fails with: >> >> ################################################################### >> 'ProfilesController GET 'index' should render active profiles' FAILED >> expected: [#> country: "Yemen, Rep.", icon_file_name: nil, icon_content_type: nil, >> icon_file_size: nil, icon_updated_at: nil, description: "I've gotten >> burned over Cheryl Tiegs and blown up f...", personal_website_url: >> "www.google.com", social_network_of_choice: nil, twitter_name: >> "Sarah", created_at: "2010-03-15 11:41:56", updated_at: "2010-03-15 >> 11:41:56">], >> got: [#> country: "Yemen, Rep.", icon_file_name: nil, icon_content_type: nil, >> icon_file_size: nil, icon_updated_at: nil, description: "I've gotten >> burned over Cheryl Tiegs and blown up f...", personal_website_url: >> "www.google.com", social_network_of_choice: nil, twitter_name: >> "Sarah", created_at: "2010-03-15 11:41:56", updated_at: "2010-03-15 >> 11:41:56">, #> nil, icon_file_name: nil, icon_content_type: nil, icon_file_size: >> nil, >> icon_updated_at: nil, description: nil, personal_website_url: nil, >> social_network_of_choice: nil, twitter_name: nil, created_at: >> "2010-03-15 11:21:15", updated_at: "2010-03-15 11:21:15">, #> id: 40, user_id: 40, real_name: nil, country: nil, icon_file_name: >> nil, icon_content_type: nil, icon_file_size: nil, icon_updated_at: >> nil, description: nil, personal_website_url: nil, >> social_network_of_choice: nil, twitter_name: nil, created_at: >> "2010-03-15 11:21:15", updated_at: "2010-03-15 11:21:15">, #> id: 52, user_id: 52, real_name: nil, country: nil, icon_file_name: >> nil, icon_content_type: nil, icon_file_size: nil, icon_updated_at: >> nil, description: nil, personal_website_url: nil, >> social_network_of_choice: nil, twitter_name: nil, created_at: >> "2010-03-15 11:21:15", updated_at: "2010-03-15 11:21:15">] (using ==) >> ################################################################### >> >> As you can see, the problem is that there are more profiles than >> actually expected. >> >> Running this exact spec alone is ok: >> >> ################################################################### >> spec spec/controllers/profiles_controller_spec.rb -l 17 >> . >> >> Finished in 7.743924 seconds >> >> 1 example, 0 failures >> ################################################################### >> >> The same goes for the whole spec-file itself: >> >> ################################################################### >> spec spec/controllers/profiles_controller_spec.rb >> ............ >> >> Finished in 6.108002 seconds >> >> 12 examples, 0 failures >> ################################################################### >> >> A quick debugging via: >> >> ################################################################### >> it 'should render active profiles' do >> custom_log("Profile-count before: #{Profile.count.to_s}") >> # ........ see code from before >> get 'index' >> custom_log("Profile-count after: #{Profile.count.to_s}") >> assigns[:profiles].should == [active_user.profile] >> end >> ################################################################### >> >> shows: >> >> ################################################################### >> Profile-count before: 3 >> Profile-count after: 5 >> ################################################################### >> >> Apparently the problem is, that there are still previously created >> profiles around. >> >> As far as I've understood rspec, shouldn't the database be properly >> cleaned up after each spec? >> In other words, shouldn't there be zero profiles before running the >> spec from above? > > rspec-rails hooks into rails' transaction management, rolling back > transactions after every example. It does not guarantee that your > database is empty - just that it is in the same state after each > example that it was in before. Now there are a couple of caveats here: > > 1 - you have to have "config.use_transactional_fixtures = true" in > spec/spec_helper.rb > > This is rails' nomenclature and really means "run each example in a > transaction" > > 2 - if you use before(:all) anywhere in your suite, that code is _not_ > run in a transaction and it is up to you to destroy any data you > create. 3. If you make any dirty little direct SQL calls (using ActiveRecord::Base.connection.execute) while the example runs, that will commit the transaction so it's won't be rolled back. cheers, Matt http://mattwynne.net +447974 430184 From david.spurr at gmail.com Wed Mar 17 09:34:58 2010 From: david.spurr at gmail.com (DEfusion) Date: Wed, 17 Mar 2010 06:34:58 -0700 (PDT) Subject: [rspec-users] Autospec with RSpec 2 beta for Rails 3 Message-ID: <89bf11da-c6f3-4d03-907b-56aaeafd95ba@z3g2000yqz.googlegroups.com> I can't seem to find autospec installed anywhere after installing the latest Rails 3 beta. I've tried copying the contents of a script/ autospec from a Rails 2 application but that includes all the test/ file none of the spec files. Am I missing something as I miss not having autospec to run. From dchelimsky at gmail.com Wed Mar 17 10:05:46 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 17 Mar 2010 09:05:46 -0500 Subject: [rspec-users] Autospec with RSpec 2 beta for Rails 3 In-Reply-To: <89bf11da-c6f3-4d03-907b-56aaeafd95ba@z3g2000yqz.googlegroups.com> References: <89bf11da-c6f3-4d03-907b-56aaeafd95ba@z3g2000yqz.googlegroups.com> Message-ID: <19367494-5D39-4679-9F87-E730C2F8F7E3@gmail.com> On Mar 17, 2010, at 8:34 AM, DEfusion wrote: > I can't seem to find autospec installed anywhere after installing the > latest Rails 3 beta. I've tried copying the contents of a script/ > autospec from a Rails 2 application but that includes all the test/ > file none of the spec files. > > Am I missing something as I miss not having autospec to run. http://blog.davidchelimsky.net/2010/03/15/rspec-2-and-autotest/ Cheers, David From david.spurr at gmail.com Wed Mar 17 10:16:16 2010 From: david.spurr at gmail.com (DEfusion) Date: Wed, 17 Mar 2010 07:16:16 -0700 (PDT) Subject: [rspec-users] Autospec with RSpec 2 beta for Rails 3 In-Reply-To: <19367494-5D39-4679-9F87-E730C2F8F7E3@gmail.com> References: <89bf11da-c6f3-4d03-907b-56aaeafd95ba@z3g2000yqz.googlegroups.com> <19367494-5D39-4679-9F87-E730C2F8F7E3@gmail.com> Message-ID: <3a0baf59-bc3d-4fa8-81b1-bd399c49a902@g10g2000yqh.googlegroups.com> If I add that into an autospec/discover.rb file autotest fails with this: loading autotest/rspec2 ... /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.4/bin/rspec:2:in `require': no such file to load -- rspec/autorun (LoadError) from /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.4/bin/ rspec:2 > http://blog.davidchelimsky.net/2010/03/15/rspec-2-and-autotest/ > > Cheers, > David From dchelimsky at gmail.com Wed Mar 17 10:33:06 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 17 Mar 2010 09:33:06 -0500 Subject: [rspec-users] Autospec with RSpec 2 beta for Rails 3 In-Reply-To: <3a0baf59-bc3d-4fa8-81b1-bd399c49a902@g10g2000yqh.googlegroups.com> References: <89bf11da-c6f3-4d03-907b-56aaeafd95ba@z3g2000yqz.googlegroups.com> <19367494-5D39-4679-9F87-E730C2F8F7E3@gmail.com> <3a0baf59-bc3d-4fa8-81b1-bd399c49a902@g10g2000yqh.googlegroups.com> Message-ID: <09FF6FFE-F1C8-46C0-9120-291EF3D84CA4@gmail.com> On Mar 17, 2010, at 9:16 AM, DEfusion wrote: > If I add that into an autospec/discover.rb file autotest fails with > this: > > loading autotest/rspec2 > ... > /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.4/bin/rspec:2:in > `require': no such file to load -- rspec/autorun (LoadError) > from /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.4/bin/ > rspec:2 Do you have RUBYOPT=rubygems in your environment? >> http://blog.davidchelimsky.net/2010/03/15/rspec-2-and-autotest/ >> >> Cheers, >> David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From david.spurr at gmail.com Wed Mar 17 12:20:33 2010 From: david.spurr at gmail.com (DEfusion) Date: Wed, 17 Mar 2010 09:20:33 -0700 (PDT) Subject: [rspec-users] Autospec with RSpec 2 beta for Rails 3 In-Reply-To: <09FF6FFE-F1C8-46C0-9120-291EF3D84CA4@gmail.com> References: <89bf11da-c6f3-4d03-907b-56aaeafd95ba@z3g2000yqz.googlegroups.com> <19367494-5D39-4679-9F87-E730C2F8F7E3@gmail.com> <3a0baf59-bc3d-4fa8-81b1-bd399c49a902@g10g2000yqh.googlegroups.com> <09FF6FFE-F1C8-46C0-9120-291EF3D84CA4@gmail.com> Message-ID: On Mar 17, 2:33?pm, David Chelimsky wrote: > On Mar 17, 2010, at 9:16 AM, DEfusion wrote: > > > If I add that into an autospec/discover.rb file autotest fails with > > this: > > > loading autotest/rspec2 > > ... > > /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.4/bin/rspec:2:in > > `require': no such file to load -- rspec/autorun (LoadError) > > ? ? ? ?from /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.4/bin/ > > rspec:2 > > Do you have RUBYOPT=rubygems in your environment? > No, should I or shouldn't I? From david.spurr at gmail.com Wed Mar 17 12:30:57 2010 From: david.spurr at gmail.com (DEfusion) Date: Wed, 17 Mar 2010 09:30:57 -0700 (PDT) Subject: [rspec-users] Autospec with RSpec 2 beta for Rails 3 In-Reply-To: References: <89bf11da-c6f3-4d03-907b-56aaeafd95ba@z3g2000yqz.googlegroups.com> <19367494-5D39-4679-9F87-E730C2F8F7E3@gmail.com> <3a0baf59-bc3d-4fa8-81b1-bd399c49a902@g10g2000yqh.googlegroups.com> <09FF6FFE-F1C8-46C0-9120-291EF3D84CA4@gmail.com> Message-ID: <80b422fd-2518-4564-8fdf-ca8f41d453c0@v20g2000yqv.googlegroups.com> > > Do you have RUBYOPT=rubygems in your environment? > > No, should I or shouldn't I? Okay I added that, should have done that before my last post, now I get a different issue, the same one Gabriel posted in the comments on the blog post : /usr/lib/ruby/1.8/optparse.rb:1445:in `complete': invalid option: -O (OptionParser::InvalidOption) from /usr/lib/ruby/1.8/optparse.rb:1443:in `catch' from /usr/lib/ruby/1.8/optparse.rb:1443:in `complete' from /usr/lib/ruby/1.8/optparse.rb:1282:in `parse_in_order' from /usr/lib/ruby/1.8/optparse.rb:1249:in `catch' from /usr/lib/ruby/1.8/optparse.rb:1249:in `parse_in_order' from /usr/lib/ruby/1.8/optparse.rb:1243:in `order!' from /usr/lib/ruby/1.8/optparse.rb:1334:in `permute!' from /usr/lib/ruby/1.8/optparse.rb:1355:in `parse!' from /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.4/lib/ rspec/core/command_line_options.rb:22:in `parse' from /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.4/lib/ rspec/core/command_line_options.rb:13:in `parse' from /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.4/lib/ rspec/core/runner.rb:29:in `run' from /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.4/lib/ rspec/core/runner.rb:13:in `autorun' from /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.4/bin/ rspec:2 From dchelimsky at gmail.com Wed Mar 17 12:49:52 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 17 Mar 2010 11:49:52 -0500 Subject: [rspec-users] Autospec with RSpec 2 beta for Rails 3 In-Reply-To: <80b422fd-2518-4564-8fdf-ca8f41d453c0@v20g2000yqv.googlegroups.com> References: <89bf11da-c6f3-4d03-907b-56aaeafd95ba@z3g2000yqz.googlegroups.com> <19367494-5D39-4679-9F87-E730C2F8F7E3@gmail.com> <3a0baf59-bc3d-4fa8-81b1-bd399c49a902@g10g2000yqh.googlegroups.com> <09FF6FFE-F1C8-46C0-9120-291EF3D84CA4@gmail.com> <80b422fd-2518-4564-8fdf-ca8f41d453c0@v20g2000yqv.googlegroups.com> Message-ID: <7C6D025B-12A1-40BA-BA86-F99613E69AD7@gmail.com> On Mar 17, 2010, at 11:30 AM, DEfusion wrote: > >>> Do you have RUBYOPT=rubygems in your environment? >> >> No, should I or shouldn't I? > > Okay I added that, should have done that before my last post, now I > get a different issue, the same one Gabriel posted in the comments on > the blog post : > > /usr/lib/ruby/1.8/optparse.rb:1445:in `complete': invalid option: -O You read Gabriel's comment, but not my response to him :) From timo.roessner at googlemail.com Thu Mar 18 06:15:40 2010 From: timo.roessner at googlemail.com (jollyroger) Date: Thu, 18 Mar 2010 03:15:40 -0700 (PDT) Subject: [rspec-users] Strange validation errors In-Reply-To: <57c63afe1003150540i26199d3cy4f49e4081cc93f6d@mail.gmail.com> References: <57c63afe1003150540i26199d3cy4f49e4081cc93f6d@mail.gmail.com> Message-ID: <5cd27df2-333b-4d93-813b-65f659afe674@c16g2000yqd.googlegroups.com> Hey David, I experienced similar problems as depicted above in other projects now as well. E.g. a wrong-used stub in an it-block overwrote stubs established in helper functions for the whole spec-file etc. This was a mocha-related problem, I know that for sure cause when I swapped out mocha for rspec-stubbing everything behaved as expected. I now switched from mocha to rspec-stubbing / mocking, and so far, works like a charm - thanks for your time and help. On Mar 15, 1:40?pm, David Chelimsky wrote: > On Mon, Mar 15, 2010 at 6:54 AM, jollyroger > > > > wrote: > > Hey guys, > > > I'm having a serious rspec-problem at the moment: > > > I keep getting strange, empty validation errors when I run the whole > > spec-suite: > > > ################################################################# > > 1) > > ActiveRecord::RecordInvalid in 'LikesController DELETE destroy' should > > change like-count' > > Validation failed: > > my_project/vendor/bundled_gems/gems/activerecord-2.3.5/lib/ > > active_record/validations.rb:1090:in `save_without_dirty!' > > my_project/vendor/bundled_gems/gems/activerecord-2.3.5/lib/ > > active_record/dirty.rb:87:in `save_without_transactions!' > > my_project/vendor/bundled_gems/gems/activerecord-2.3.5/lib/ > > active_record/transactions.rb:200:in `save!' > > my_project/vendor/bundled_gems/gems/activerecord-2.3.5/lib/ > > active_record/connection_adapters/abstract/database_statements.rb: > > 136:in `transaction' > > my_project/vendor/bundled_gems/gems/activerecord-2.3.5/lib/ > > active_record/transactions.rb:182:in `transaction' > > my_project/vendor/bundled_gems/gems/activerecord-2.3.5/lib/ > > active_record/transactions.rb:200:in `save!' > > my_project/vendor/bundled_gems/gems/activerecord-2.3.5/lib/ > > active_record/transactions.rb:208:in `rollback_active_record_state!' > > my_project/vendor/bundled_gems/gems/activerecord-2.3.5/lib/ > > active_record/transactions.rb:200:in `save!' > > my_project/vendor/bundled_gems/gems/factory_girl-1.2.3/lib/ > > factory_girl/proxy/create.rb:6:in `result' > > my_project/vendor/bundled_gems/gems/factory_girl-1.2.3/lib/ > > factory_girl/factory.rb:316:in `run' > > my_project/vendor/bundled_gems/gems/factory_girl-1.2.3/lib/ > > factory_girl/factory.rb:260:in `create' > > my_project/vendor/bundled_gems/gems/factory_girl-1.2.3/lib/ > > factory_girl/proxy/build.rb:17:in `associate' > > my_project/vendor/bundled_gems/gems/factory_girl-1.2.3/lib/ > > factory_girl/attribute/association.rb:15:in `add_to' > > my_project/vendor/bundled_gems/gems/factory_girl-1.2.3/lib/ > > factory_girl/factory.rb:313:in `run' > > my_project/vendor/bundled_gems/gems/factory_girl-1.2.3/lib/ > > factory_girl/factory.rb:311:in `each' > > my_project/vendor/bundled_gems/gems/factory_girl-1.2.3/lib/ > > factory_girl/factory.rb:311:in `run' > > my_project/vendor/bundled_gems/gems/factory_girl-1.2.3/lib/ > > factory_girl/factory.rb:260:in `create' > > my_project/vendor/bundled_gems/gems/factory_girl-1.2.3/lib/ > > factory_girl/factory.rb:291:in `send' > > my_project/vendor/bundled_gems/gems/factory_girl-1.2.3/lib/ > > factory_girl/factory.rb:291:in `default_strategy' > > my_project/vendor/bundled_gems/gems/factory_girl-1.2.3/lib/ > > factory_girl.rb:21:in `Factory' > > ./spec/controllers/likes_controller_spec.rb:46: > > ################################################################# > > > Here is the corresponding spec: > > > ################################################################# > > ? ?it "should change like-count" do > > ? ? ?we_are_logged_in_as(get_member_user) > > ? ? ?entry = Factory(:entry) > > ? ? ?Factory(:like, :user => get_member_user, :entry => entry) > > ? ? ?lambda do > > ? ? ? ?post 'destroy', :entry_id => entry.id > > ? ? ?end.should change(Like, :count).by(-1) > > ? ? ?response.should be_success > > ? ?end > > ################################################################# > > > Trouble-Shooting turns out to be difficult: > > > The spec itself seems to be correct, when running the spec-file alone > > I don't get any errors. > > I only get this error when running the whole spec-suite - running the > > single spec file is fine: > > > ################################################################# > > spec spec/controllers/likes_controller_spec.rb > > Example disabled: should change like-count on success > > ... > > > Finished in 0.756284 seconds > > > 3 examples, 0 failures > > ################################################################# > > > I have a lot of other specs failing in the very same way. > > The errors itself are confusing - empty validation error messages are > > utterly meaningless. > > > I suspect that there is something going wrong with all the stubbing / > > mocking within in my specs. > > > To be concrete: > > > I suspect that something like: > > > Foo.any_instance.stubs(:bar).returns.... > > > within a spec isn't properly isolated from the other specs, thus > > causing strange validation errors. > > > What do you guys think? > > How could I narrow down this error further? > > > Sys-Info: > > OS: Ubuntu 9.10 > > spec -v > > rspec 1.3.0 > > Mocking / Stubbing: Mocha 0.9.8 > > Take a look at this thread and see if it helps: > > http://groups.google.com/group/mocha-developer/browse_thread/thread/5... > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From nash at kabbara.us Wed Mar 17 19:05:16 2010 From: nash at kabbara.us (Nash) Date: Wed, 17 Mar 2010 16:05:16 -0700 (PDT) Subject: [rspec-users] Rspec doubles & rails metal Message-ID: <1f12f541-b4ef-4d80-b827-eb1b5fc1fd31@g4g2000yqa.googlegroups.com> Hi, I've created a cucumber test to test a metal I've created that connects to a third party. I'm using rspec mocks to create a stub for the 3 party. It seems that stubbing/mocking isn't extending all the way to the metal. It calls the read object and not the stub. Any idea of how I can make stubbing/mocking extend to the rails metal? Thanks. -Nash From harini.rails at gmail.com Wed Mar 17 19:25:51 2010 From: harini.rails at gmail.com (harinionrails) Date: Wed, 17 Mar 2010 16:25:51 -0700 (PDT) Subject: [rspec-users] rspec with out Active Record Message-ID: I want to use rspec with my application where we don't have database. I want to know how to use fixtures with out ORM layer. From dchelimsky at gmail.com Thu Mar 18 08:22:56 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 18 Mar 2010 07:22:56 -0500 Subject: [rspec-users] rspec with out Active Record In-Reply-To: References: Message-ID: On Mar 17, 2010, at 6:25 PM, harinionrails wrote: > I want to use rspec with my application where we don't have database. The answer to this is in spec/spec_helper.rb (lines 16 - 21), which is generated when you run "script/generate rspec" in the root of your rails app: http://github.com/dchelimsky/rspec-rails/blob/master/generators/rspec/templates/spec_helper.rb > I want to know how to use fixtures with out ORM layer. Rails fixtures are specifically intended for use with an ORM layer. Without one, you'll have to roll your own test data. HTH, David From dchelimsky at gmail.com Thu Mar 18 08:28:56 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 18 Mar 2010 07:28:56 -0500 Subject: [rspec-users] Rspec doubles & rails metal In-Reply-To: <1f12f541-b4ef-4d80-b827-eb1b5fc1fd31@g4g2000yqa.googlegroups.com> References: <1f12f541-b4ef-4d80-b827-eb1b5fc1fd31@g4g2000yqa.googlegroups.com> Message-ID: On Mar 17, 2010, at 6:05 PM, Nash wrote: > Hi, > > I've created a cucumber test to test a metal I've created that > connects to a third party. > > I'm using rspec mocks to create a stub for the 3 party. It seems > that stubbing/mocking isn't extending all the way to the metal. It > calls the read object and not the stub. > > Any idea of how I can make stubbing/mocking extend to the rails > metal? I responded on the cukes list: http://groups.google.com/group/cukes/browse_thread/thread/1cebf781c6073eb3?hl=en From freakguard at gmail.com Thu Mar 18 08:31:04 2010 From: freakguard at gmail.com (Freak) Date: Thu, 18 Mar 2010 13:31:04 +0100 Subject: [rspec-users] rspec with out Active Record In-Reply-To: References: Message-ID: <201003181331.05256.freakguard@gmail.com> On Thursday 18 March 2010 00.25:51 harinionrails wrote: > I want to use rspec with my application where we don't have database. > I want to know how to use fixtures with out ORM layer. Probably those fixtures are now called 'stubs'. From dbatshaw at gmail.com Thu Mar 18 17:18:50 2010 From: dbatshaw at gmail.com (drewB) Date: Thu, 18 Mar 2010 14:18:50 -0700 (PDT) Subject: [rspec-users] shared_example can't have the same name even if defined it different specs Message-ID: I am writing some specs related to permissions for different kinds of users. Every user has some common examples to test in many different specs. For example, all users can view, and edit their profile. Also, all users can view their own "history." So I have two spec files, say profile_controller_spec and history_controller_spec. They might look like http://gist.github.com/336898 Using these files RSpec will give an error that 'User' is already registered as a shared group, even though they are defined in separate files and example groups. Is it suppose to behave that way? Seems like a hassle to have to prepend the controller name to each shared_example_for. From dchelimsky at gmail.com Thu Mar 18 17:40:05 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 18 Mar 2010 16:40:05 -0500 Subject: [rspec-users] shared_example can't have the same name even if defined it different specs In-Reply-To: References: Message-ID: <1E0AF5F5-9D64-4385-9054-7339B969B256@gmail.com> On Mar 18, 2010, at 4:18 PM, drewB wrote: > I am writing some specs related to permissions for different kinds of > users. Every user has some common examples to test in many different > specs. For example, all users can view, and edit their profile. > Also, all users can view their own "history." So I have two spec > files, say profile_controller_spec and history_controller_spec. > > They might look like http://gist.github.com/336898 > > Using these files RSpec will give an error that 'User' is already > registered as a shared group, even though they are defined in separate > files and example groups. Shared examples are not scoped to groups they are defined in. They are global. > Is it suppose to behave that way? Yes > Seems like a hassle to have to prepend the controller name to each shared_example_for. It's not really behaving like a User so this: it_should_behave_like "User" doesn't tell me anything I need to know. It's actually behaving like a profile controller handling any user, so I'd probably write this: it_should_behave_like "the profile controller handling any user" In terms of being able to scope shared examples, I think that's a good idea and something we should consider for rspec-2. If you're interested, feel free to create an issue at http://github.com/rspec/rspec-core/issues and, even better, fork the repo and submit a patch. Cheers, David From lists at ruby-forum.com Thu Mar 18 19:02:45 2010 From: lists at ruby-forum.com (Bartosz Blimke) Date: Fri, 19 Mar 2010 00:02:45 +0100 Subject: [rspec-users] how to mock a Net::Http object? In-Reply-To: References: Message-ID: <0c6f0d60872fcb21b524c13e9989cc41@ruby-forum.com> You can also use WebMock http://github.com/bblimke/webmock -- Posted via http://www.ruby-forum.com/. From joshuawallis at gmail.com Thu Mar 18 13:12:51 2010 From: joshuawallis at gmail.com (jw) Date: Thu, 18 Mar 2010 10:12:51 -0700 (PDT) Subject: [rspec-users] how does one define dependencies on a specTask? Message-ID: <1f62c2e7-2ee8-40af-a94f-72a724563827@e7g2000yqf.googlegroups.com> I get that you create dependencies on a normal rake task like this: task :codeGen do # do the code generation end task :compile => :codeGen do # do the compilation end but what is the syntax for a specTask? Spec::Rake::SpecTask.new('task1a') do |t| # t.spec_files = ... end You can create a (redundant) standard rake task: task :task1b => 'task1a' do # just runs task1a end but that sure seems unnecessary. There's got to be a way to do this, right? From dchelimsky at gmail.com Thu Mar 18 19:50:24 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 18 Mar 2010 18:50:24 -0500 Subject: [rspec-users] how does one define dependencies on a specTask? In-Reply-To: <1f62c2e7-2ee8-40af-a94f-72a724563827@e7g2000yqf.googlegroups.com> References: <1f62c2e7-2ee8-40af-a94f-72a724563827@e7g2000yqf.googlegroups.com> Message-ID: <585C5C8E-A9FA-414C-8E0A-7BA13D080F93@gmail.com> On Mar 18, 2010, at 12:12 PM, jw wrote: > I get that you create dependencies on a normal rake task like this: > > task :codeGen do > # do the code generation > end > > task :compile => :codeGen do > # do the compilation > end > > > but what is the syntax for a specTask? > > Spec::Rake::SpecTask.new('task1a') do |t| > # t.spec_files = ... > end > > You can create a (redundant) standard rake task: > > task :task1b => 'task1a' do > # just runs task1a > end > > but that sure seems unnecessary. There's got to be a way to do this, right? Just call "task1a" directly. From lists at ruby-forum.com Fri Mar 19 13:00:51 2010 From: lists at ruby-forum.com (Nick Hoffman) Date: Fri, 19 Mar 2010 18:00:51 +0100 Subject: [rspec-users] stub vs stub! Message-ID: <79bb04c3cf82c84e722e90dc92bc0dcd@ruby-forum.com> RSpec's changelog says that in version 1.2.5: "also alias_method :stub, :stub!, so you can stub with less bang" which I've been taking advantage of a lot. However, I just ran into a situation where using #stub caused an error to occur, and changing to #stub! caused the error the disappear. Any idea what's going on? http://codepad.org/P2uIlJVj Thanks, Nick -- Posted via http://www.ruby-forum.com/. From mailinglists at patmaddox.com Fri Mar 19 13:07:24 2010 From: mailinglists at patmaddox.com (Pat Maddox) Date: Fri, 19 Mar 2010 10:07:24 -0700 Subject: [rspec-users] stub vs stub! In-Reply-To: <79bb04c3cf82c84e722e90dc92bc0dcd@ruby-forum.com> References: <79bb04c3cf82c84e722e90dc92bc0dcd@ruby-forum.com> Message-ID: <925FF50B-83AB-4A03-AF49-93FAA50643E6@patmaddox.com> I've never heard of CurbFu, but according to http://github.com/gdi/curb-fu/blob/master/lib/curb-fu.rb#L43 it defines a stub method already. So you're hitting that one, which expects two arguments. stub! goes to RSpec's mocking framework. Pat On Mar 19, 2010, at 10:00 AM, Nick Hoffman wrote: > RSpec's changelog says that in version 1.2.5: > > "also alias_method :stub, :stub!, so you can stub with less bang" > > which I've been taking advantage of a lot. > > However, I just ran into a situation where using #stub caused an error > to occur, and changing to #stub! caused the error the disappear. > > Any idea what's going on? > > http://codepad.org/P2uIlJVj > > Thanks, > Nick > -- > 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 Fri Mar 19 14:27:37 2010 From: lists at ruby-forum.com (Nick Hoffman) Date: Fri, 19 Mar 2010 19:27:37 +0100 Subject: [rspec-users] stub vs stub! In-Reply-To: <925FF50B-83AB-4A03-AF49-93FAA50643E6@patmaddox.com> References: <79bb04c3cf82c84e722e90dc92bc0dcd@ruby-forum.com> <925FF50B-83AB-4A03-AF49-93FAA50643E6@patmaddox.com> Message-ID: Pat Maddox wrote: > I've never heard of CurbFu, but according to > http://github.com/gdi/curb-fu/blob/master/lib/curb-fu.rb#L43 it defines > a stub method already. So you're hitting that one, which expects two > arguments. stub! goes to RSpec's mocking framework. > > Pat Good catch! Thanks, Pat. -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Fri Mar 19 14:39:50 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 19 Mar 2010 13:39:50 -0500 Subject: [rspec-users] stub vs stub! In-Reply-To: References: <79bb04c3cf82c84e722e90dc92bc0dcd@ruby-forum.com> <925FF50B-83AB-4A03-AF49-93FAA50643E6@patmaddox.com> Message-ID: On Mar 19, 2010, at 1:27 PM, Nick Hoffman wrote: > Pat Maddox wrote: >> I've never heard of CurbFu, but according to >> http://github.com/gdi/curb-fu/blob/master/lib/curb-fu.rb#L43 it defines >> a stub method already. So you're hitting that one, which expects two >> arguments. stub! goes to RSpec's mocking framework. >> >> Pat > > Good catch! Thanks, Pat. This presents an interesting dilemma, in that I (now not so) secretly plan to deprecate and remove stub(). I also plan to offer up a mode in which you don't get stub and should_receive added to every object, but instead have to wrap each object you want to set stubs/message expectations on. i.e. double(Foo).stub(:bar) { return value } This is how flexmock works, and it helps to avoid problems exactly like the one you've uncovered. I guess these two changes will need to ship together :) Cheers, David From patrick at collinatorstudios.com Fri Mar 19 17:35:54 2010 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Fri, 19 Mar 2010 14:35:54 -0700 (PDT) Subject: [rspec-users] lots of nil problems! In-Reply-To: References: <79bb04c3cf82c84e722e90dc92bc0dcd@ruby-forum.com> <925FF50B-83AB-4A03-AF49-93FAA50643E6@patmaddox.com> Message-ID: Hi, I have this in my controller action: from_address = Setting.find_by_name("shipping_from_address").address and my spec fails: NoMethodError in 'Admin::ShippingLabelsController should render a pdf file' undefined method `address' for nil:NilClass yet in the console I can do: >> Setting.find_by_name("shipping_from_address").address => #
and I get the address-- so I don't understand why it's failing in the spec.. ? ... Also, if I want to test that I am getting a pdf back, how is the best way to do that? I was doing: controller: respond_to do |format| format.pdf do render :template => 'admin/contacts/shipping_label' end spec: def do_get get :create, :format => :pdf end it "should render a pdf file" do do_get response.should render_template("admin/contacts/shipping_label") end -- but that gives me: 'Admin::ShippingLabelsController should render a pdf file' FAILED expected "admin/contacts/shipping_label", got nil /Users/patrick/coding/rails/matthew/spec/controllers/admin/shipping_labels_controller_spec.rb:11: thanks... Patrick J. Collins http://collinatorstudios.com From lists at ruby-forum.com Fri Mar 19 22:53:48 2010 From: lists at ruby-forum.com (Nick Hoffman) Date: Sat, 20 Mar 2010 03:53:48 +0100 Subject: [rspec-users] lots of nil problems! In-Reply-To: References: <79bb04c3cf82c84e722e90dc92bc0dcd@ruby-forum.com> <925FF50B-83AB-4A03-AF49-93FAA50643E6@patmaddox.com> Message-ID: Patrick Collins wrote: > Hi, > > I have this in my controller action: > > from_address = Setting.find_by_name("shipping_from_address").address > > and my spec fails: > > NoMethodError in 'Admin::ShippingLabelsController should render a pdf > file' > undefined method `address' for nil:NilClass > > ...snip... Patrick, please create a new thread for this, since it doesn't have anything to do with the current topic. -- Posted via http://www.ruby-forum.com/. From patrick99e99 at gmail.com Sat Mar 20 00:22:06 2010 From: patrick99e99 at gmail.com (patrick99e99) Date: Fri, 19 Mar 2010 21:22:06 -0700 (PDT) Subject: [rspec-users] lots of nil problems! In-Reply-To: References: <79bb04c3cf82c84e722e90dc92bc0dcd@ruby-forum.com> <925FF50B-83AB-4A03-AF49-93FAA50643E6@patmaddox.com> Message-ID: <5ba3acb2-647f-466f-901b-33bf779116cd@t9g2000prh.googlegroups.com> > Patrick, please create a new thread for this, since it doesn't have > anything to do with the current topic. Wow that is weird.. I replied to the previous thread in my email client but removed the subject-- as I assumed that was what kept things associated with threads; there was no other text in the email pertaining to this thread, and the address was the generic rspec- users at rubyforge.org... So I don't quite understand why my post was thrown under this topic.. Oh well, sorry about that and I will repost. -patrick From patrick99e99 at gmail.com Sat Mar 20 00:22:58 2010 From: patrick99e99 at gmail.com (patrick99e99) Date: Fri, 19 Mar 2010 21:22:58 -0700 (PDT) Subject: [rspec-users] lots of nil problems! Message-ID: <37f5aff8-a571-43d9-b60e-468c35ad4438@g1g2000pre.googlegroups.com> Hi, I have this in my controller action: from_address = Setting.find_by_name("shipping_from_address").address and my spec fails: NoMethodError in 'Admin::ShippingLabelsController should render a pdf file' undefined method `address' for nil:NilClass yet in the console I can do: >> Setting.find_by_name("shipping_from_address").address => #
and I get the address-- so I don't understand why it's failing in the spec.. ? ... Also, if I want to test that I am getting a pdf back, how is the best way to do that? I was doing: controller: respond_to do |format| format.pdf do render :template => 'admin/contacts/shipping_label' end spec: def do_get get :create, :format => :pdf end it "should render a pdf file" do do_get response.should render_template("admin/contacts/shipping_label") end -- but that gives me: 'Admin::ShippingLabelsController should render a pdf file' FAILED expected "admin/contacts/shipping_label", got nil /Users/patrick/coding/rails/matthew/spec/controllers/admin/ shipping_labels_controller_spec.rb:11: thanks... -patrick From lists at ruby-forum.com Sat Mar 20 00:34:17 2010 From: lists at ruby-forum.com (Nick Hoffman) Date: Sat, 20 Mar 2010 05:34:17 +0100 Subject: [rspec-users] lots of nil problems! In-Reply-To: <5ba3acb2-647f-466f-901b-33bf779116cd@t9g2000prh.googlegroups.com> References: <79bb04c3cf82c84e722e90dc92bc0dcd@ruby-forum.com> <925FF50B-83AB-4A03-AF49-93FAA50643E6@patmaddox.com> <5ba3acb2-647f-466f-901b-33bf779116cd@t9g2000prh.googlegroups.com> Message-ID: patrick99e99 wrote: >> Patrick, please create a new thread for this, since it doesn't have >> anything to do with the current topic. > > Wow that is weird.. I replied to the previous thread in my email > client but removed the subject-- as I assumed that was what kept > things associated with threads; there was no other text in the email > pertaining to this thread, and the address was the generic rspec- > users at rubyforge.org... So I don't quite understand why my post was > thrown under this topic.. > > Oh well, sorry about that and I will repost. > > -patrick No worries, mate. There's an email header that identifies which thread a given post belongs to. If you reply to a post, your reply will inherit that header, and thus be associated with the thread. Cheers, Nick -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Sat Mar 20 00:55:39 2010 From: lists at ruby-forum.com (Nick Hoffman) Date: Sat, 20 Mar 2010 05:55:39 +0100 Subject: [rspec-users] lots of nil problems! In-Reply-To: <37f5aff8-a571-43d9-b60e-468c35ad4438@g1g2000pre.googlegroups.com> References: <37f5aff8-a571-43d9-b60e-468c35ad4438@g1g2000pre.googlegroups.com> Message-ID: <19f7c704f632d41e8c3f9034adb4085a@ruby-forum.com> Hey Patrick. > I have this in my controller action: > > from_address = Setting.find_by_name("shipping_from_address").address > > and my spec fails: > > NoMethodError in 'Admin::ShippingLabelsController should render a pdf > file' > undefined method `address' for nil:NilClass > > yet in the console I can do: > >>> Setting.find_by_name("shipping_from_address").address > > => #
> > and I get the address-- so I don't understand why it's failing in the > spec.. ? Your console was most likely running in the development environment, and thus using your development database. Specs run in the test environment, and use your test database. Thus, your specs won't see the data in your dev DB. Also, your test DB is wiped clean at the beginning of all of your tests. That way, existing data can't taint or skew the results of your specs. You probably want something along the lines of this: http://pastie.org/878189 However, that line of code of yours should be modified slightly. At the moment, it'll raise the error that you posted above if the setting isn't found. This is because Setting.find_by_name returns nil if the setting isn't found, and nil#address doesn't exist. You can put Object#try right before the call to #address, like this: Setting.find_by_name('...').try(:address) I'd probably break the line into a few: search for the setting, then check if it's nil, then grab the address or deal with the nil value. There're many solutions. Try a few and see what feels right to you. -- Posted via http://www.ruby-forum.com/. From patrick at collinatorstudios.com Sat Mar 20 03:28:50 2010 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Sat, 20 Mar 2010 00:28:50 -0700 (PDT) Subject: [rspec-users] lots of nil problems! In-Reply-To: <19f7c704f632d41e8c3f9034adb4085a@ruby-forum.com> References: <37f5aff8-a571-43d9-b60e-468c35ad4438@g1g2000pre.googlegroups.com> <19f7c704f632d41e8c3f9034adb4085a@ruby-forum.com> Message-ID: Hi Nick, Thank you very much for your reply. One thing I am finding incredibly frustrating with Rspec, is that I don't even know what questions to ask-- because I find the whole thing so confusing. So forgive me, but I am going to break down your code and ask specific questions to hopefully gain understanding. 1. Ok-- so in your example (which I greatly appreciate), you have this do_action method.. Is that where I would put something like get :create, :format => :pdf ? ... 2. Next in the before each block, you set @address.. Now, I have factory girl installed and have used it in cucumber, is that something that could be used instead of setting @address to "123 some st" ? Is that common practice and acceptable to do? 3. You set shipping_setting to mock the model Setting with :address set to @address.... >From my understanding of what I've read-- Mocking a model, simply means that it's a fake object, that acts like the real thing------ So, when you do that mock_model, is it virtually the same to have just done: @shipping_setting = Setting.create(:address => @address) ? That would be utilizing the test database, correct? By using mock_model, nothing is being stored, right? It's more just temporary data in memory... ? 4. You do .stub! ........... This is where I get really confused. From the peepcode screencast that I have watched several times, he explained that stubbing is the same as mocking-- except there is no expectation of what it returns. That made sense when he said it, but in all the examples I've seen with code (including yours), there is this .and_return at the end.. Which as far as I can tell, is an expectation.. I mean, you are asking it to return a specific thing-- that is an expectation is it not? Or does expectation really mean something else in this context? That aside, if I try to guess what this Setting.stub! this is doing-- it is pretending that you are actually looking for a record, and getting it..... but in this case, is that even worth doing? I mean, the shipping_setting record is really only important in the sense that the record is needed to provide a valid "from" address for a label.. But, if we're dealing with a test database where a from address doesn't exist-- then it seems kind of pointless.. To clarify, the importance for me would be to have a test that actually looks in my real database and makes sure there is a shipping from address in there... I have no idea if this paragraph will make sense to you, but hopefully it will. 5. the it "finds the shipping address setting" block-- totally confused by this, since it's doing the same thing as in the before :each block-- except it's mocking instead of stubbing..... agh.. totally confused.. don't get it.. don't even know what question to ask in hopes to get it. 6. same with the "gets the address from the setting" block... ........ I am sorry for being so confused!!!! If you can break this down, I'd really appreciate it. Thank you. Patrick J. Collins http://collinatorstudios.com On Sat, 20 Mar 2010, Nick Hoffman wrote: > Hey Patrick. > > > I have this in my controller action: > > > > from_address = Setting.find_by_name("shipping_from_address").address > > > > and my spec fails: > > > > NoMethodError in 'Admin::ShippingLabelsController should render a pdf > > file' > > undefined method `address' for nil:NilClass > > > > yet in the console I can do: > > > >>> Setting.find_by_name("shipping_from_address").address > > > > => #
> > > > and I get the address-- so I don't understand why it's failing in the > > spec.. ? > > Your console was most likely running in the development environment, and > thus using your development database. Specs run in the test environment, > and use your test database. Thus, your specs won't see the data in your > dev DB. > > Also, your test DB is wiped clean at the beginning of all of your tests. > That way, existing data can't taint or skew the results of your specs. > > You probably want something along the lines of this: > http://pastie.org/878189 > > However, that line of code of yours should be modified slightly. At the > moment, it'll raise the error that you posted above if the setting isn't > found. This is because Setting.find_by_name returns nil if the setting > isn't found, and nil#address doesn't exist. > > You can put Object#try right before the call to #address, like this: > Setting.find_by_name('...').try(:address) > I'd probably break the line into a few: search for the setting, then > check if it's nil, then grab the address or deal with the nil value. > > There're many solutions. Try a few and see what feels right to you. > -- > 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 Sat Mar 20 06:42:25 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 20 Mar 2010 05:42:25 -0500 Subject: [rspec-users] lots of nil problems! In-Reply-To: References: <37f5aff8-a571-43d9-b60e-468c35ad4438@g1g2000pre.googlegroups.com> <19f7c704f632d41e8c3f9034adb4085a@ruby-forum.com> Message-ID: <57c63afe1003200342o2df6648eo773f173c8deb76ca@mail.gmail.com> On Sat, Mar 20, 2010 at 2:28 AM, Patrick J. Collins wrote: > 4. ?You do .stub! ........... ?This is where I get really > confused. ?From the peepcode screencast that I have watched > several times, he explained that stubbing is the same as > mocking-- except there is no expectation of what it returns. > > That made sense when he said it, but in all the examples I've > seen with code (including yours), there is this .and_return at > the end.. ?Which as far as I can tell, is an expectation.. ?I > mean, you are asking it to return a specific thing-- that is > an expectation is it not? ?Or does expectation really mean > something else in this context? .and_xxx is admittedly confusing, as evidenced by your confusion. These are _not_ expectations, they are merely configuration. When you say foo.stub(:bar).and_return('this value') you're saying: hey, foo, you might receive the bar() message. If you do, return "this value". When you say foo.should_receive(:bar).and_return('this value') you're saying: hey, foo, you _should_ receive the bar() message. If you do, return "this value". If you don't, raise an ExpectationNotMet error. Neither are saying: hey, foo, you should return "this value", and if you don't, I'll consider it a failure. There are also and_raise, and_yield, and and_throw methods that operate similarly. They are instructions to the object that allow you to control how it behaves so you can set expectations on other objects as to how they should respond. Make sense? There is an alternate syntax that I'm using nearly exclusively at this point, which is to pass a block along with the stub() and should_receive() messages: foo.stub(:bar) { "return value" } foo.stub(:bar) { raise SomeError } foo.stub(:bar) { yield "value" } foo.stub(:bar) { throw :value } foo.should_receive(:bar) { "return value" } foo.should_receive(:bar) { raise SomeError } foo.should_receive(:bar) { yield "value" } foo.should_receive(:bar) { throw :value } As you can see, there is much less API to worry about here. You're just supplying an implementation. This approach also works with scoped arguments: input = Input.new calculator = Calculator.new(input) calculator.should_receive(:add).with(1,2) { 3 } input.type("1", "+", "2", "Enter") I've been thinking of deprecating the and_xxx methods in rspec-2. Does anybody think that's an awful idea? From dchelimsky at gmail.com Sat Mar 20 06:43:45 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 20 Mar 2010 05:43:45 -0500 Subject: [rspec-users] stub vs stub! In-Reply-To: References: <79bb04c3cf82c84e722e90dc92bc0dcd@ruby-forum.com> <925FF50B-83AB-4A03-AF49-93FAA50643E6@patmaddox.com> Message-ID: <57c63afe1003200343u676736a6m9513d09d1c130039@mail.gmail.com> On Fri, Mar 19, 2010 at 1:39 PM, David Chelimsky wrote: > On Mar 19, 2010, at 1:27 PM, Nick Hoffman wrote: > >> Pat Maddox wrote: >>> I've never heard of CurbFu, but according to >>> http://github.com/gdi/curb-fu/blob/master/lib/curb-fu.rb#L43 it defines >>> a stub method already. ?So you're hitting that one, which expects two >>> arguments. ?stub! goes to RSpec's mocking framework. >>> >>> Pat >> >> Good catch! Thanks, Pat. > > > This presents an interesting dilemma, in that I (now not so) secretly plan to deprecate and remove stub(). D'oh - stub!() - that's the one I plan to remove. So we would only have stub(). There is no need to have both, since they do the same thing, and there is nothing particularly bangy about the stub method. > > I also plan to offer up a mode in which you don't get stub and should_receive added to every object, but instead have to wrap each object you want to set stubs/message expectations on. i.e. > > double(Foo).stub(:bar) { return value } > > This is how flexmock works, and it helps to avoid problems exactly like the one you've uncovered. > > I guess these two changes will need to ship together :) > > Cheers, > David From phillipkoebbe at gmail.com Sat Mar 20 07:10:20 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Sat, 20 Mar 2010 06:10:20 -0500 Subject: [rspec-users] lots of nil problems! In-Reply-To: References: <37f5aff8-a571-43d9-b60e-468c35ad4438@g1g2000pre.googlegroups.com> <19f7c704f632d41e8c3f9034adb4085a@ruby-forum.com> Message-ID: <4BA4AD1C.2000103@gmail.com> Welcome to RSpec, Patrick. For some of us, it's pretty rocky at first. I started using it a couple of years ago with models, and understood that well enough (I think). Then I came to controllers and I just couldn't wrap my mind around it. I gave up for quite some time. When I came back to testing, it was on a project that was using test::unit, but at least I was working with someone who had more experience than I did, and I was able to gain some understanding that I lacked earlier. But during the use of test::unit, I realized I missed RSpec, so when I moved on, I put RSpec back into my workflow. I've been trudging along for a few months now, and while I still have lots and lots to learn, I think I am actually using it somewhat correctly and productively. So while I definitely don't want to try to supersede Nick's or anyone else's contributions to your questions, I thought I would chime with what I've learned. On 2010-03-20 2:28 AM, Patrick J. Collins wrote: > Hi Nick, > > Thank you very much for your reply. One thing I am finding incredibly > frustrating with Rspec, is that I don't even know what questions to ask-- > Ask everything. In my life, I've learned that the only stupid question is the one you didn't ask. Most of the people in the RSpec community are *very* understanding, patient, and incredibly helpful. No one is going to bite your head off! > because I find the whole thing so confusing. So forgive me, but I am going to > break down your code and ask specific questions to hopefully gain > understanding. > > 1. Ok-- so in your example (which I greatly appreciate), you have this do_action > method.. Is that where I would put something like > > get :create, :format => :pdf > > ? > > ... > > 2. Next in the before each block, you set @address.. > > Now, I have factory girl installed and have used it in cucumber, is that > something that could be used instead of setting @address to "123 some st" ? Is > that common practice and acceptable to do? > > 3. You set shipping_setting to mock the model Setting with > :address set to @address.... > > > From my understanding of what I've read-- Mocking a model, > simply means that it's a fake object, that acts like the real > thing------ So, when you do that mock_model, is it virtually > the same to have just done: > @shipping_setting = Setting.create(:address => @address) > > ? That would be utilizing the test database, correct? By > using mock_model, nothing is being stored, right? It's more > just temporary data in memory... ? > > No, you're not using the test database. That's the point of mocking: you want to break the dependency on another layer. When you test, you want to try to isolate what you are testing so you can specify how it behaves given certain criteria. For example, when you test a model, you don't want a controller involved. When you test a controller, you don't really want a model involved. Mocking and stubbing allow you to completely control all (or most) of the extenuating circumstances that your controller will find itself in. Then you can properly test something like "When the controller receives these params, it should do blah blah blah" > 4. You do .stub! ........... This is where I get really > confused. From the peepcode screencast that I have watched > several times, he explained that stubbing is the same as > mocking-- except there is no expectation of what it returns. > > Stubbing is creating the "plumbing" that your application expects to exist to function properly. If you have a person object and you want to do something with the name attribute, you code will be expecting "person.name" to work. If you have a fake object @person and call @person.name, you will get an error unless you stub it like @person.stub!(:name).and_return('John Doe') > That made sense when he said it, but in all the examples I've > seen with code (including yours), there is this .and_return at > the end.. Which as far as I can tell, is an expectation.. I > mean, you are asking it to return a specific thing-- that is > an expectation is it not? Or does expectation really mean > something else in this context? > > The .and_return() bit just says "for this stubbed method, return this value when it's called." Keep in mind that these objects you are creating are going to be interacting with your application code. So if your application code calls Person.new, it expects to receive back a person object. So you can do something like this in your specs: @person = stub_model(Person) Person.stub!(:new).and_return(@person) Then you will be bypassing your Person model completely but still sending something back for your code to play with. Now, I've introduced another method in this mess, stub_model. This is very similar to stub, except that it goes ahead and and stubs out the attribute methods that are on your model. So if you have Person with name, age, and gender, the single call to stub_model also does this for you: @person.stub!(:name) @person.stub!(:age) @person.stub!(:gender) By default, the stubs created with stub_model will return nil. If you need to specify return values, do something like this: @person = stub_model(Person, :name => 'John Doe', :age => 99, :gender => 'M') > That aside, if I try to guess what this Setting.stub! this is > doing-- it is pretending that you are actually looking for a > record, and getting it..... but in this case, is that even > worth doing? I mean, the shipping_setting record is really > only important in the sense that the record is needed to > provide a valid "from" address for a label.. But, if we're > dealing with a test database where a from address doesn't > exist-- then it seems kind of pointless.. To clarify, the > importance for me would be to have a test that actually looks > in my real database and makes sure there is a shipping from > address in there... I have no idea if this paragraph will > make sense to you, but hopefully it will. > > Here is where testing in isolation comes back into play. If you are testing a controller, you want to try to avoid the dependence on the database. Ideally, you want to use mocking and stubbing to create an artificial environment, that you completely control, to specify the behavior of your controller. Think about each situation you expect your controller to encounter. For each one of those situations, create the imaginary world that needs to exist, and then test that your controller behaves correctly. For example, if your controller needs to do one thing if a particular record is found and something else if it is not found, you should have two sets of specifications. I usually do something like this: context 'when records is found' do before :each do @record = stub_model(SomeClass) SomeClass.should_receive(:find).and_return(@record) end it 'should test something' do blah blah blah end end context 'when record is not found' do SomeClass.should_receive(:find).and_return(nil) it 'should test something else' do end end I've thrown in another method, .should_receive. This establishes an expectation that this method should be called during the execution of your code. If it does not get called, you will get a failure. Stub!, on the other hand, just creates the method *in case* it gets called. No error will be raised if it doesn't. So in the bogus code above, I am saying that I expect my controller to call SomeClass.find, and I want to test what it does when the find is successful and when it isn't. When it is successful, it will be returning something that the application will think is an instance of the class, and when it is not successful, it will be returning nil, which is what normally happens in AR. However, because I'm "mocking and stubbing", I'm bypassing AR completely. That's all I have time for right now. I hope this has helped a little bit. I encourage you to take deep breaths often and just hang in there. Keep asking questions. Soon or later, the light will click and you'll have an "Aha!" moment. Peace, Phillip From phillipkoebbe at gmail.com Sat Mar 20 07:13:52 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Sat, 20 Mar 2010 06:13:52 -0500 Subject: [rspec-users] lots of nil problems! In-Reply-To: <57c63afe1003200342o2df6648eo773f173c8deb76ca@mail.gmail.com> References: <37f5aff8-a571-43d9-b60e-468c35ad4438@g1g2000pre.googlegroups.com> <19f7c704f632d41e8c3f9034adb4085a@ruby-forum.com> <57c63afe1003200342o2df6648eo773f173c8deb76ca@mail.gmail.com> Message-ID: <4BA4ADF0.8070606@gmail.com> > There is an alternate syntax that I'm using nearly exclusively at this > point, which is to pass a block along with the stub() and > should_receive() messages: > > foo.stub(:bar) { "return value" } > foo.stub(:bar) { raise SomeError } > foo.stub(:bar) { yield "value" } > foo.stub(:bar) { throw :value } > foo.should_receive(:bar) { "return value" } > foo.should_receive(:bar) { raise SomeError } > foo.should_receive(:bar) { yield "value" } > foo.should_receive(:bar) { throw :value } > > As you can see, there is much less API to worry about here. You're > just supplying an implementation. > > This approach also works with scoped arguments: > > input = Input.new > calculator = Calculator.new(input) > calculator.should_receive(:add).with(1,2) { 3 } > input.type("1", "+", "2", "Enter") > > I've been thinking of deprecating the and_xxx methods in rspec-2. Does > anybody think that's an awful idea? > It may be because my RSpec-fu is relatively immature, but I like and_return and friends. It makes sense to my brain. Admittedly, I have not used the other syntax yet, so I really should give it a go and see what I think. At the present moment, I would be very disappointed if the and_ methods went away. -1 Peace, Phillip From patrick at collinatorstudios.com Sat Mar 20 07:16:03 2010 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Sat, 20 Mar 2010 04:16:03 -0700 (PDT) Subject: [rspec-users] lots of nil problems! In-Reply-To: <57c63afe1003200342o2df6648eo773f173c8deb76ca@mail.gmail.com> References: <37f5aff8-a571-43d9-b60e-468c35ad4438@g1g2000pre.googlegroups.com> <19f7c704f632d41e8c3f9034adb4085a@ruby-forum.com> <57c63afe1003200342o2df6648eo773f173c8deb76ca@mail.gmail.com> Message-ID: Hi David, > I've been thinking of deprecating the and_xxx methods in rspec-2. Does > anybody think that's an awful idea? Well I can tell you that this syntax you demonstrated: > foo.stub(:bar) { "return value" } > foo.stub(:bar) { raise SomeError } > foo.stub(:bar) { yield "value" } > foo.stub(:bar) { throw :value } is so much clearer to me, intuitive, and friendly.... Thank you very much for your explanations, they really help-- I finally get the whole stub / should_receive... The only thing that is still a bit fuzzy to me, is knowing when to use one over the other. With the case of should_receive, I am having a hard time imagining a useful test, because everything I am thinking of-- is something like: def index @blogs = Blog.all ... end # Blog.should_receve(:all) { @list_of_blogs } ... And that to me, seems like a pointless test because it's evident visually that the code is fine, flawless and will work exactly as expected. But I probably am missing something... Now, one other thing I might ask you to explain, since you do such a great job, is what are the differences between "mock" "mock_model" and "should_receive" since they all are "mocking"...? Patrick J. Collins http://collinatorstudios.com On Sat, 20 Mar 2010, David Chelimsky wrote: > On Sat, Mar 20, 2010 at 2:28 AM, Patrick J. Collins > wrote: > > 4. ?You do .stub! ........... ?This is where I get really > > confused. ?From the peepcode screencast that I have watched > > several times, he explained that stubbing is the same as > > mocking-- except there is no expectation of what it returns. > > > > That made sense when he said it, but in all the examples I've > > seen with code (including yours), there is this .and_return at > > the end.. ?Which as far as I can tell, is an expectation.. ?I > > mean, you are asking it to return a specific thing-- that is > > an expectation is it not? ?Or does expectation really mean > > something else in this context? > > .and_xxx is admittedly confusing, as evidenced by your confusion. > These are _not_ expectations, they are merely configuration. > > When you say > > foo.stub(:bar).and_return('this value') > > you're saying: hey, foo, you might receive the bar() message. If you > do, return "this value". > > When you say > > foo.should_receive(:bar).and_return('this value') > > you're saying: hey, foo, you _should_ receive the bar() message. If > you do, return "this value". If you don't, raise an ExpectationNotMet > error. > > Neither are saying: hey, foo, you should return "this value", and if > you don't, I'll consider it a failure. > > There are also and_raise, and_yield, and and_throw methods that > operate similarly. They are instructions to the object that allow you > to control how it behaves so you can set expectations on other objects > as to how they should respond. Make sense? > > There is an alternate syntax that I'm using nearly exclusively at this > point, which is to pass a block along with the stub() and > should_receive() messages: > > foo.stub(:bar) { "return value" } > foo.stub(:bar) { raise SomeError } > foo.stub(:bar) { yield "value" } > foo.stub(:bar) { throw :value } > foo.should_receive(:bar) { "return value" } > foo.should_receive(:bar) { raise SomeError } > foo.should_receive(:bar) { yield "value" } > foo.should_receive(:bar) { throw :value } > > As you can see, there is much less API to worry about here. You're > just supplying an implementation. > > This approach also works with scoped arguments: > > input = Input.new > calculator = Calculator.new(input) > calculator.should_receive(:add).with(1,2) { 3 } > input.type("1", "+", "2", "Enter") > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From tom at experthuman.com Sat Mar 20 07:41:29 2010 From: tom at experthuman.com (Tom Stuart) Date: Sat, 20 Mar 2010 11:41:29 +0000 Subject: [rspec-users] lots of nil problems! In-Reply-To: <57c63afe1003200342o2df6648eo773f173c8deb76ca@mail.gmail.com> References: <37f5aff8-a571-43d9-b60e-468c35ad4438@g1g2000pre.googlegroups.com> <19f7c704f632d41e8c3f9034adb4085a@ruby-forum.com> <57c63afe1003200342o2df6648eo773f173c8deb76ca@mail.gmail.com> Message-ID: <56B22194-025B-48F1-BEFD-85238D2A84A3@experthuman.com> Hi David, On 20 Mar 2010, at 10:42, David Chelimsky wrote: > There is an alternate syntax that I'm using nearly exclusively at this > point, which is to pass a block along with the stub() and > should_receive() messages: > [...] > I've been thinking of deprecating the and_xxx methods in rspec-2. Does > anybody think that's an awful idea? I don't think it's an awful idea -- less API is a laudable goal -- but I dislike it for two reasons: 1. I like the symmetry of ".with(...).and_return(...)". The alternative of ".with(...) { ... }" feels weird, lopsided and misleadingly implicit to me; #with is "merely configuration" too, so why does #and_return get the special treatment? 2. I like the semantics of #and_return, i.e. its argument gets eagerly evaluated by Ruby (at "stub time") and the return value sits there waiting to be returned whenever the stubbed message is received. I'm uncomfortable about *always* specifying the return value by providing a block whose evaluation happens later (at "message time") and potentially has side-effects, argument-dependent behaviour etc. I appreciate that #stub and #should_receive already give you the ability to pass a block for this purpose, and that's occasionally useful, but I much prefer being able to explicitly choose that style when it's absolutely necessary (e.g. when I absolutely must have a "dynamic stub" whose return value actually depends upon its arguments) but this is very much the exception rather than the rule. (Quoth rspec.info: "While this is possible, it is generally to be avoided. Calculating a value to return defeats the declarative nature of stubs.") It's nice to be able to see the difference syntactically rather than having to inspect the behaviour of the block to see whether it's doing anything clever; namely, #and_return serves as a nice annotation that you're doing "the normal thing". So basically I suspect that your proposal makes it easier for RSpec newbies to learn the API since the block form is potentially less surprising and "more Ruby", but I fear that it also makes things less explicit and therefore harder to understand & maintain further down the road. Cheers, -Tom From patrick at collinatorstudios.com Sat Mar 20 08:02:07 2010 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Sat, 20 Mar 2010 05:02:07 -0700 (PDT) Subject: [rspec-users] lots of nil problems! In-Reply-To: <4BA4AD1C.2000103@gmail.com> References: <37f5aff8-a571-43d9-b60e-468c35ad4438@g1g2000pre.googlegroups.com> <19f7c704f632d41e8c3f9034adb4085a@ruby-forum.com> <4BA4AD1C.2000103@gmail.com> Message-ID: On Sat, 20 Mar 2010, Phillip Koebbe wrote: > Welcome to RSpec, Patrick. For some of us, it's pretty rocky at first. I Thank you Phillip for your great explanation... After reading what you wrote, I have a few questions: 1. From what I understand of what you wrote, stub_model makes a fake object, with accessor methods for the AR columns, and they return nil. So what happens behind the scenes with mock_model? What is the difference? 2. I sort of asked this earlier, but didn't really get addressed--- What is the benefit to doing stubbing vs. using a factory or fixture? 3. In your code, you wrote: > context 'when record is not found' do > SomeClass.should_receive(:find).and_return(nil) I just wondered about this, because-- correct me if I am wrong, but a record not found would not return nil-- it returns a record not found error, correct? Or does an error actually equate to nil? I know in a lot of my controllers to avoid record not found errors, I do .find_by_id instead of .find, because that will return nil if it's not found. 4. should_receive... So, if you have a method that is calling other class and instance methods, isn't it a given that those calls are important and that they should be expected? In other words, I am finding myself asking the same question again-- Why use stub instead of should_receive? When would you actually not care whether a method gets called or not if you are testing something. I mean, I would assume if I am testing something, I want to test everything that happens-- so any real code in my app that deals with class/instance methods, those seem like they would be important and therefore those calls should be expected. ? 5. Since I learn really well from example, I just wrote up some random and strange code, which does a handful of things, and I would love it if you could go through and spec it-- and explain each step of the way, what you're doing and why. What is necessary to test, and what is not, and of course also-- why. def index type = params[:foo] value = params[:bar] @foo = type && value ? Foo.send("find_by_#{type}", value) : Foo.all @baz = /.*lower/.match(params[:baz]) ? @foo.lowered_name : @foo.upper_name flash[:notice] = "Something with #{@foo.numbers}" unless params[:bool].to_i.zero? respond_to do |format| format.html { render 'foo_listing' } format.js { render :json => { :foo => @foo }.to_json format.pdf { render :inline => @foo.pdf } end end # class Foo < AR::base def lowered_name name.downcase end def upper_name name.upcase end def numbers rand(id) end def pdf # return some prawn pdf object end ... If you could do that for me, it would be incredibly awesome... Thank you. Patrick J. Collins http://collinatorstudios.com > started using it a couple of years ago with models, and understood that well > enough (I think). Then I came to controllers and I just couldn't wrap my mind > around it. I gave up for quite some time. When I came back to testing, it was > on a project that was using test::unit, but at least I was working with > someone who had more experience than I did, and I was able to gain some > understanding that I lacked earlier. But during the use of test::unit, I > realized I missed RSpec, so when I moved on, I put RSpec back into my > workflow. I've been trudging along for a few months now, and while I still > have lots and lots to learn, I think I am actually using it somewhat correctly > and productively. So while I definitely don't want to try to supersede Nick's > or anyone else's contributions to your questions, I thought I would chime with > what I've learned. > > On 2010-03-20 2:28 AM, Patrick J. Collins wrote: > > Hi Nick, > > > > Thank you very much for your reply. One thing I am finding incredibly > > frustrating with Rspec, is that I don't even know what questions to ask-- > > > > Ask everything. In my life, I've learned that the only stupid question is the > one you didn't ask. Most of the people in the RSpec community are *very* > understanding, patient, and incredibly helpful. No one is going to bite your > head off! > > > because I find the whole thing so confusing. So forgive me, but I am going > > to > > break down your code and ask specific questions to hopefully gain > > understanding. > > > > 1. Ok-- so in your example (which I greatly appreciate), you have this > > do_action > > method.. Is that where I would put something like > > > > get :create, :format => :pdf > > > > ? > > > > ... > > > > 2. Next in the before each block, you set @address.. > > > > Now, I have factory girl installed and have used it in cucumber, is that > > something that could be used instead of setting @address to "123 some st" ? > > Is > > that common practice and acceptable to do? > > > > 3. You set shipping_setting to mock the model Setting with > > :address set to @address.... > > > > > From my understanding of what I've read-- Mocking a model, > > simply means that it's a fake object, that acts like the real > > thing------ So, when you do that mock_model, is it virtually > > the same to have just done: > > @shipping_setting = Setting.create(:address => @address) > > > > ? That would be utilizing the test database, correct? By > > using mock_model, nothing is being stored, right? It's more > > just temporary data in memory... ? > > > > > > No, you're not using the test database. That's the point of mocking: you want > to break the dependency on another layer. When you test, you want to try to > isolate what you are testing so you can specify how it behaves given certain > criteria. For example, when you test a model, you don't want a controller > involved. When you test a controller, you don't really want a model involved. > Mocking and stubbing allow you to completely control all (or most) of the > extenuating circumstances that your controller will find itself in. Then you > can properly test something like "When the controller receives these params, > it should do blah blah blah" > > > 4. You do .stub! ........... This is where I get really > > confused. From the peepcode screencast that I have watched > > several times, he explained that stubbing is the same as > > mocking-- except there is no expectation of what it returns. > > > > > > Stubbing is creating the "plumbing" that your application expects to exist to > function properly. If you have a person object and you want to do something > with the name attribute, you code will be expecting "person.name" to work. If > you have a fake object @person and call @person.name, you will get an error > unless you stub it like > > @person.stub!(:name).and_return('John Doe') > > > That made sense when he said it, but in all the examples I've > > seen with code (including yours), there is this .and_return at > > the end.. Which as far as I can tell, is an expectation.. I > > mean, you are asking it to return a specific thing-- that is > > an expectation is it not? Or does expectation really mean > > something else in this context? > > > > > > The .and_return() bit just says "for this stubbed method, return this value > when it's called." Keep in mind that these objects you are creating are going > to be interacting with your application code. So if your application code > calls Person.new, it expects to receive back a person object. So you can do > something like this in your specs: > > @person = stub_model(Person) > Person.stub!(:new).and_return(@person) > > Then you will be bypassing your Person model completely but still sending > something back for your code to play with. Now, I've introduced another method > in this mess, stub_model. This is very similar to stub, except that it goes > ahead and and stubs out the attribute methods that are on your model. So if > you have Person with name, age, and gender, the single call to stub_model also > does this for you: > > @person.stub!(:name) > @person.stub!(:age) > @person.stub!(:gender) > > By default, the stubs created with stub_model will return nil. If you need to > specify return values, do something like this: > > @person = stub_model(Person, :name => 'John Doe', :age => 99, :gender => 'M') > > > That aside, if I try to guess what this Setting.stub! this is > > doing-- it is pretending that you are actually looking for a > > record, and getting it..... but in this case, is that even > > worth doing? I mean, the shipping_setting record is really > > only important in the sense that the record is needed to > > provide a valid "from" address for a label.. But, if we're > > dealing with a test database where a from address doesn't > > exist-- then it seems kind of pointless.. To clarify, the > > importance for me would be to have a test that actually looks > > in my real database and makes sure there is a shipping from > > address in there... I have no idea if this paragraph will > > make sense to you, but hopefully it will. > > > > > Here is where testing in isolation comes back into play. If you are testing a > controller, you want to try to avoid the dependence on the database. Ideally, > you want to use mocking and stubbing to create an artificial environment, that > you completely control, to specify the behavior of your controller. Think > about each situation you expect your controller to encounter. For each one of > those situations, create the imaginary world that needs to exist, and then > test that your controller behaves correctly. > > For example, if your controller needs to do one thing if a particular record > is found and something else if it is not found, you should have two sets of > specifications. I usually do something like this: > > context 'when records is found' do > before :each do > @record = stub_model(SomeClass) > SomeClass.should_receive(:find).and_return(@record) > end > > it 'should test something' do > blah blah blah > end > end > > context 'when record is not found' do > SomeClass.should_receive(:find).and_return(nil) > > it 'should test something else' do > > end > end > > I've thrown in another method, .should_receive. This establishes an > expectation that this method should be called during the execution of your > code. If it does not get called, you will get a failure. Stub!, on the other > hand, just creates the method *in case* it gets called. No error will be > raised if it doesn't. So in the bogus code above, I am saying that I expect my > controller to call SomeClass.find, and I want to test what it does when the > find is successful and when it isn't. When it is successful, it will be > returning something that the application will think is an instance of the > class, and when it is not successful, it will be returning nil, which is what > normally happens in AR. However, because I'm "mocking and stubbing", I'm > bypassing AR completely. > > That's all I have time for right now. I hope this has helped a little bit. I > encourage you to take deep breaths often and just hang in there. Keep asking > questions. Soon or later, the light will click and you'll have an "Aha!" > moment. > > Peace, > Phillip > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From timo.roessner at googlemail.com Sat Mar 20 08:20:06 2010 From: timo.roessner at googlemail.com (jollyroger) Date: Sat, 20 Mar 2010 05:20:06 -0700 (PDT) Subject: [rspec-users] Insufficient database clean-up between specs In-Reply-To: <367FFA25-A694-452A-84F9-AB2AA07DB26B@mattwynne.net> References: <8f3fc0ea-02c0-46ec-a6fa-dbb58b0c9b9e@d2g2000yqa.googlegroups.com> <57c63afe1003150534v1f669136r26cd004430cfabb7@mail.gmail.com> <367FFA25-A694-452A-84F9-AB2AA07DB26B@mattwynne.net> Message-ID: <0b3dc922-3eaa-4ab8-aef4-2771f22b6e4a@e7g2000yqf.googlegroups.com> David and Matt, ok, i was under the impression that rspec would clean up the database. Got it working now, thanks for the help... On Mar 16, 11:10?am, Matt Wynne wrote: > On 15 Mar 2010, at 12:34, David Chelimsky wrote: > > > > > On Mon, Mar 15, 2010 at 7:24 AM, jollyroger > > wrote: > >> Hey guys, > > >> unfortunately I've got one more issue with rspec right now. > > >> It seems like rspec isnt properly cleaning up the database after each > >> spec. > > >> I have the following spec: > > >> ################################################################### > >> describe ProfilesController do > >> ?describe "GET 'index'" do > >> ? ?it 'should render active profiles' do > >> ? ? ?active_user = Factory(:user, :active => 1) > >> ? ? ?active_user.profile = Factory.build(:profile) > >> ? ? ?inactive_user = Factory(:user, :active => 0) > >> ? ? ?inactive_user.profile = Factory.build(:profile) > >> ? ? ?get 'index' > >> ? ? ?assigns[:profiles].should == [active_user.profile] > >> ? ?end > >> ?end > >> ?# ...... > >> end > >> ################################################################### > > >> This spec fails with: > > >> ################################################################### > >> 'ProfilesController GET 'index' should render active profiles' FAILED > >> expected: [# >> country: "Yemen, Rep.", icon_file_name: nil, icon_content_type: nil, > >> icon_file_size: nil, icon_updated_at: nil, description: "I've gotten > >> burned over Cheryl Tiegs and blown up f...", personal_website_url: > >> "www.google.com", social_network_of_choice: nil, twitter_name: > >> "Sarah", created_at: "2010-03-15 11:41:56", updated_at: "2010-03-15 > >> 11:41:56">], > >> ? ? got: [# >> country: "Yemen, Rep.", icon_file_name: nil, icon_content_type: nil, > >> icon_file_size: nil, icon_updated_at: nil, description: "I've gotten > >> burned over Cheryl Tiegs and blown up f...", personal_website_url: > >> "www.google.com", social_network_of_choice: nil, twitter_name: > >> "Sarah", created_at: "2010-03-15 11:41:56", updated_at: "2010-03-15 > >> 11:41:56">, # >> nil, icon_file_name: nil, icon_content_type: nil, icon_file_size: ? > >> nil, > >> icon_updated_at: nil, description: nil, personal_website_url: nil, > >> social_network_of_choice: nil, twitter_name: nil, created_at: > >> "2010-03-15 11:21:15", updated_at: "2010-03-15 11:21:15">, # >> id: 40, user_id: 40, real_name: nil, country: nil, icon_file_name: > >> nil, icon_content_type: nil, icon_file_size: nil, icon_updated_at: > >> nil, description: nil, personal_website_url: nil, > >> social_network_of_choice: nil, twitter_name: nil, created_at: > >> "2010-03-15 11:21:15", updated_at: "2010-03-15 11:21:15">, # >> id: 52, user_id: 52, real_name: nil, country: nil, icon_file_name: > >> nil, icon_content_type: nil, icon_file_size: nil, icon_updated_at: > >> nil, description: nil, personal_website_url: nil, > >> social_network_of_choice: nil, twitter_name: nil, created_at: > >> "2010-03-15 11:21:15", updated_at: "2010-03-15 11:21:15">] (using ==) > >> ################################################################### > > >> As you can see, the problem is that there are more profiles than > >> actually expected. > > >> Running this exact spec alone is ok: > > >> ################################################################### > >> spec spec/controllers/profiles_controller_spec.rb -l 17 > >> . > > >> Finished in 7.743924 seconds > > >> 1 example, 0 failures > >> ################################################################### > > >> The same goes for the whole spec-file itself: > > >> ################################################################### > >> spec spec/controllers/profiles_controller_spec.rb > >> ............ > > >> Finished in 6.108002 seconds > > >> 12 examples, 0 failures > >> ################################################################### > > >> A quick debugging via: > > >> ################################################################### > >> ? ?it 'should render active profiles' do > >> ? ? ?custom_log("Profile-count before: #{Profile.count.to_s}") > >> ? ? ?# ........ see code from before > >> ? ? ?get 'index' > >> ? ? ?custom_log("Profile-count after: #{Profile.count.to_s}") > >> ? ? ?assigns[:profiles].should == [active_user.profile] > >> ? ?end > >> ################################################################### > > >> shows: > > >> ################################################################### > >> Profile-count before: 3 > >> Profile-count after: 5 > >> ################################################################### > > >> Apparently the problem is, that there are still previously created > >> profiles around. > > >> As far as I've understood rspec, shouldn't the database be properly > >> cleaned up after each spec? > >> In other words, shouldn't there be zero profiles before running the > >> spec from above? > > > rspec-rails hooks into rails' transaction management, rolling back > > transactions after every example. It does not guarantee that your > > database is empty - just that it is in the same state after each > > example that it was in before. Now there are a couple of caveats here: > > > 1 - you have to have "config.use_transactional_fixtures = true" in > > spec/spec_helper.rb > > > This is rails' nomenclature and really means "run each example in a ? > > transaction" > > > 2 - if you use before(:all) anywhere in your suite, that code is _not_ > > run in a transaction and it is up to you to destroy any data you > > create. > > 3. If you make any dirty little direct SQL calls (using ? > ActiveRecord::Base.connection.execute) while the example runs, that ? > will commit the transaction so it's won't be rolled back. > > cheers, > Matt > > http://mattwynne.net > +447974 430184 > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From phillipkoebbe at gmail.com Sat Mar 20 09:53:39 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Sat, 20 Mar 2010 08:53:39 -0500 Subject: [rspec-users] lots of nil problems! In-Reply-To: References: <37f5aff8-a571-43d9-b60e-468c35ad4438@g1g2000pre.googlegroups.com> <19f7c704f632d41e8c3f9034adb4085a@ruby-forum.com> <4BA4AD1C.2000103@gmail.com> Message-ID: <4BA4D363.1050909@gmail.com> On 2010-03-20 7:02 AM, Patrick J. Collins wrote: > On Sat, 20 Mar 2010, Phillip Koebbe wrote: > > >> Welcome to RSpec, Patrick. For some of us, it's pretty rocky at first. I >> > Thank you Phillip for your great explanation... > > After reading what you wrote, I have a few questions: > > 1. From what I understand of what you wrote, stub_model makes a fake object, > with accessor methods for the AR columns, and they return nil. > > So what happens behind the scenes with mock_model? What is the difference? > > Looking at http://rspec.rubyforge.org/rspec-rails/1.3.2/, I can't see any difference between mock_model and stub_model. David? > > 2. I sort of asked this earlier, but didn't really get addressed--- What is the benefit to doing stubbing > vs. using a factory or fixture? > > > I passed on this question since I am not very familiar with projects like factory_girl or machinist. I'd like to look into them more at some point, but just don't have the time right now. As for fixtures, I can't stand them. We used fixtures on that project I mentioned earlier. At first, they were great. But as the project grew, it was a nightmare keeping them working right. I *much* prefer mocking and stubbing. > 3. In your code, you wrote: > > >> context 'when record is not found' do >> SomeClass.should_receive(:find).and_return(nil) >> > I just wondered about this, because-- correct me if I am wrong, but a record not found would not return > nil-- it returns a record not found error, correct? Or does an error actually equate to nil? I know in a > lot of my controllers to avoid record not found errors, I do .find_by_id instead of .find, because that > will return nil if it's not found. > Right. I goofed there. It should have been .find_by_id. The point that I was hoping to make, though, is that you can create the environment needed to test what your controller does when certain conditions are met. Consider the example of wanting to redirect to an error page if a resource is not found: context 'resource is found' do before :each do @some_object = stub_model(SomeClass) SomeClass.should_receive(:find_by_id).and_return(@some_object) get :show, :id => 1 end it 'should render the show page' do # not sure if my syntax is correct here...i use remarkable which has a macro for it response.should render(:show) end end context 'resource is not found' do before :each do SomeClass.should_receive(:find_by_id).and_return(nil) get :show, :id => 1 end it 'should redirect to error page' do # not sure if my syntax is correct here...i use remarkable which has a macro for redirects response.should redirect_to error_path end end You are validating that the controller code works correctly. It would look like: def show @some_object = SomeClass.find_by_id(params[:id]) redirect_to error_path and return unless @some_object end > > > 4. should_receive... So, if you have a method that is calling other class and instance methods, isn't it > a given that those calls are important and that they should be expected? In other words, I am finding > myself asking the same question again-- Why use stub instead of should_receive? When would you actually > not care whether a method gets called or not if you are testing something. I mean, I would assume if I am > testing something, I want to test everything that happens-- so any real code in my app that deals with > class/instance methods, those seem like they would be important and therefore those calls should be > expected. ? > > Think about testing in isolation, but now isolating specific pieces of functionality in your controller. If I have already tested one piece with expectations, when I move on to another piece, I can just stub them and focus on the code at hand. This example isn't necessarily controller-specific, but maybe it will help see the difference. Suppose you have a method that performs some calculation. At one point in your testing, you should verify that the method gets called when you expect it to. That's when you would use .should_receive. At this point, you don't really care what the result is, just that your application code is invoking the calculation at the right time. Now, when you are validating what the application does *in response* to the result of the calculation, that's when you would just stub it since you don't really care about the calling of it, but what it returns. So if you want to do one thing when the result is A and another when it is B, you would stub it .and_return(A) in one case and .and_return(B) in the other. > > 5. Since I learn really well from example, I just wrote up some random and strange code, which does a > handful of things, and I would love it if you could go through and spec it-- and explain each step of the > way, what you're doing and why. What is necessary to test, and what is not, and of course also-- why. > > def index > type = params[:foo] > value = params[:bar] > > @foo = type&& value ? Foo.send("find_by_#{type}", value) : Foo.all > > @baz = /.*lower/.match(params[:baz]) ? @foo.lowered_name : @foo.upper_name > > flash[:notice] = "Something with #{@foo.numbers}" unless params[:bool].to_i.zero? > > respond_to do |format| > format.html { render 'foo_listing' } > format.js { render :json => { :foo => @foo }.to_json > format.pdf { render :inline => @foo.pdf } > end > end > > # > class Foo< AR::base > > def lowered_name > name.downcase > end > > def upper_name > name.upcase > end > > def numbers > rand(id) > end > > def pdf > # return some prawn pdf object > end > > ... > > If you could do that for me, it would be incredibly awesome... > > I would be glad to help in this way, but it will have to be later today. And instead of using completely made-up code, I'll use some of my real-world code and tests as an example. I'll gist them later, unless one of the gurus comes along and provides enlightenment for you! Peace, Phillip From phillipkoebbe at gmail.com Sat Mar 20 11:19:14 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Sat, 20 Mar 2010 10:19:14 -0500 Subject: [rspec-users] lots of nil problems! In-Reply-To: <4BA4D363.1050909@gmail.com> References: <37f5aff8-a571-43d9-b60e-468c35ad4438@g1g2000pre.googlegroups.com> <19f7c704f632d41e8c3f9034adb4085a@ruby-forum.com> <4BA4AD1C.2000103@gmail.com> <4BA4D363.1050909@gmail.com> Message-ID: <4BA4E772.9090609@gmail.com> > I would be glad to help in this way, but it will have to be later > today. And instead of using completely made-up code, I'll use some of > my real-world code and tests as an example. I'll gist them later, > unless one of the gurus comes along and provides enlightenment for you! > I was able to get to it sooner than I thought. http://gist.github.com/338707 This is only one action on a controller. Hopefully it will be enough to help. I have other code, but it may take too much explanation about the business process for it to make sense, and that would defeat the purpose of helping you understand. It may help you if you try to think in terms of writing the specs first, before you have any code. After all, that's the point of T/BDD: to write tests/specs first, then the code that satisfies them. The whole red/green/refactor process. So when you establish an expectation that a method will be called, that expectation is satisfied when you have that code in your application. If you are writing specs to cover existing code, you don't have the luxury of thinking this way, and that makes it more difficult. In the gist, notice the helper methods to simulate someone being logged in. I'm using stub there because I don't want an expectation of the methods being called to potentially raise an error. I'll do that elsewhere. In this case, I just want the methods to be available when they are needed. Peace, Phillip From dchelimsky at gmail.com Sat Mar 20 13:17:58 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 20 Mar 2010 12:17:58 -0500 Subject: [rspec-users] lots of nil problems! In-Reply-To: <4BA4E772.9090609@gmail.com> References: <37f5aff8-a571-43d9-b60e-468c35ad4438@g1g2000pre.googlegroups.com> <19f7c704f632d41e8c3f9034adb4085a@ruby-forum.com> <4BA4AD1C.2000103@gmail.com> <4BA4D363.1050909@gmail.com> <4BA4E772.9090609@gmail.com> Message-ID: <57c63afe1003201017r6254b7e1rf85e9764a7fd4fc4@mail.gmail.com> On Sat, Mar 20, 2010 at 10:19 AM, Phillip Koebbe wrote: > >> I would be glad to help in this way, but it will have to be later today. >> And instead of using completely made-up code, I'll use some of my real-world >> code and tests as an example. I'll gist them later, unless one of the gurus >> comes along and provides enlightenment for you! >> > > I was able to get to it sooner than I thought. > > http://gist.github.com/338707 Hey Phillip, Thanks for taking time to do this. Your examples are clear, and the documentation very helpful. They do, however, violate a few guidelines that I try to follow and recommend. Note that I am not trying to change your mind, Phillip, about how you should be writing your specs. In the end, the whole purpose of writing specs is to help you build a system that you can understand and maintain, and provide confidence that the system works according to your assumptions by encoding them. For me, that confidence is tied directly to my ability to read specs and understand failures quickly, which is an admittedly subjective thing. Given that context ... 1. Keep setup local When an example fails, we want to understand the context as quickly as possible. The purpose of nested describe and context blocks is to group things together conceptually. While the before blocks happen to support cascading (i.e. the ones higher up the nesting chain get run first), using them that way makes it much harder to understand the context when an example fails. In order to understand why any of these examples fail, I'd have to look at the before block in the current context, then the before block in the describe block, then at the setup methods at the top. That might not seem so bad in a simple example like this, but it gets unwieldy quite quickly. 2. Setup context in before blocks, not expectations We want the example names to express the intent of each example. The before block in the "with valid id' context sets two expectations, and then each example sets one of its own. If "should_not_assign_to :message" fails because Message didn't receive :find_by_id, the failure has nothing to do with the intent expressed by that example. Same goes for @message.should_receive(:destroy). If you want those expectations to be part of the spec, then add examples for them. If you don't care that they are specified, then don't. Either way, prefer stub() over should_receive() in before blocks. 3. Use expressive names for helper methods When I see "before(:each) { setup_admin }", I don't really know what that means. In order to figure it out, I have to look up at the setup_user, setup_admin, and stub_user methods, and I need to understand them all to really understand the purpose of any of them. These could (and I'd say should) all be collapsed into this: def login_as(type) user.stub(:is_administrator).and_return(type == :admin) User.stub(:find_by_id).and_return(user) session[:user_id = user.id] end Now the before block can say "before(:each) { login_as :admin}" and a) I probably don't have to go looking at that method to understand its intent and b) I definitely don't have to go looking at three different methods. 4. Clarity trumps DRY DRY is a very important principle, but it is often misunderstood to mean "don't type the same thing twice." That is not its intent, and interpreting it as such often leads to less clarity. The bigger idea is that we shouldn't express the same concept in two different parts of a system. i.e. if we have two different parts of a codebase that validate an email address, for example, and the rules for a valid email address change (we decide to ping a service to see if the email address actually exists in addition to validating its format), we run the risk that we'll forget to change it in both cases. DRY helps us to avoid that risk. This is a completely different matter from organizing a spec. Consider http://gist.github.com/338767. There are 4 permutations of what is essentially the same spec. I'd argue that the two examples near the top are far easier to grok than the latter two, even though the latter two are DRYer. The first example spells out everything in each example with zero indirection and very little API to grok. The second one might be a bit DRYer but it requires more API (let). 5. Given/When/Then This probably shouldn't be last, but ... Express every example in the form Given/When/Then: given some context, when some event occurs, then the outcome should be ... Consider the first example group in http://gist.github.com/338767. Both examples in that express the givens (person and day) in the first two lines, the event (person walks on the day) on the third line, and the outcome on the last line. The symmetry between them makes it very easy to see the differences between them, even though that is probably the least DRY example in the gist. That's probably enough to chew on for now. All comments welcome. Cheers, David > > This is only one action on a controller. Hopefully it will be enough to > help. I have other code, but it may take too much explanation about the > business process for it to make sense, and that would defeat the purpose of > helping you understand. > > It may help you if you try to think in terms of writing the specs first, > before you have any code. After all, that's the point of T/BDD: to write > tests/specs first, then the code that satisfies them. The whole > red/green/refactor process. So when you establish an expectation that a > method will be called, that expectation is satisfied when you have that code > in your application. If you are writing specs to cover existing code, you > don't have the luxury of thinking this way, and that makes it more > difficult. > > In the gist, notice the helper methods to simulate someone being logged in. > I'm using stub there because I don't want an expectation of the methods > being called to potentially raise an error. I'll do that elsewhere. In this > case, I just want the methods to be available when they are needed. > > Peace, > Phillip > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From phillipkoebbe at gmail.com Sat Mar 20 14:22:44 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Sat, 20 Mar 2010 13:22:44 -0500 Subject: [rspec-users] lots of nil problems! In-Reply-To: <57c63afe1003201017r6254b7e1rf85e9764a7fd4fc4@mail.gmail.com> References: <37f5aff8-a571-43d9-b60e-468c35ad4438@g1g2000pre.googlegroups.com> <19f7c704f632d41e8c3f9034adb4085a@ruby-forum.com> <4BA4AD1C.2000103@gmail.com> <4BA4D363.1050909@gmail.com> <4BA4E772.9090609@gmail.com> <57c63afe1003201017r6254b7e1rf85e9764a7fd4fc4@mail.gmail.com> Message-ID: <4BA51274.7010104@gmail.com> On 2010-03-20 12:17 PM, David Chelimsky wrote: > On Sat, Mar 20, 2010 at 10:19 AM, Phillip Koebbe > wrote: > >> >>> I would be glad to help in this way, but it will have to be later today. >>> And instead of using completely made-up code, I'll use some of my real-world >>> code and tests as an example. I'll gist them later, unless one of the gurus >>> comes along and provides enlightenment for you! >>> >>> >> I was able to get to it sooner than I thought. >> >> http://gist.github.com/338707 >> > Hey Phillip, > > Thanks for taking time to do this. Your examples are clear, and the > documentation very helpful. They do, however, violate a few guidelines > that I try to follow and recommend. > Heh, that doesn't surprise me at all. All of my life, I've needed to do ABC, so I've figured out a way to do ABC. I frequently learn later, however, that I chose a hard way to do ABC and then must learn an easier way. Programming has shown itself to not be an exception to this pattern. :) > Note that I am not trying to change your mind, Phillip, about how you > should be writing your specs. In the end, the whole purpose of writing > specs is to help you build a system that you can understand and > maintain, and provide confidence that the system works according to > your assumptions by encoding them. For me, that confidence is tied > directly to my ability to read specs and understand failures quickly, > which is an admittedly subjective thing. > > I appreciate your perspective, David. I appreciate all of the perspectives that I see here. Some are presented in a more palatable manner than others, but they are all valuable. I don't let much get by without considering its place in my own workflow. > Given that context ... > > 1. Keep setup local > > When an example fails, we want to understand the context as quickly as possible. > > The purpose of nested describe and context blocks is to group things > together conceptually. While the before blocks happen to support > cascading (i.e. the ones higher up the nesting chain get run first), > using them that way makes it much harder to understand the context > when an example fails. In order to understand why any of these > examples fail, I'd have to look at the before block in the current > context, then the before block in the describe block, then at the > setup methods at the top. That might not seem so bad in a simple > example like this, but it gets unwieldy quite quickly. > > I confess that I have created nestings just to be able to share a before block. A typical spec file for one of my controllers is a nested mess, and now I know why. Funny that I wrote the silly things but didn't realize I was creating such a problem until someone else took a quick peek. Oh that I was in a position to pair with someone regularly. That would help tremendously. > 2. Setup context in before blocks, not expectations > > We want the example names to express the intent of each example. > > The before block in the "with valid id' context sets two expectations, > and then each example sets one of its own. If "should_not_assign_to > :message" fails because Message didn't receive :find_by_id, the > failure has nothing to do with the intent expressed by that example. > Same goes for @message.should_receive(:destroy). > > If you want those expectations to be part of the spec, then add > examples for them. If you don't care that they are specified, then > don't. Either way, prefer stub() over should_receive() in before > blocks. > Good point. By having the expectations in the setup, I also don't get the documentation when I run the examples. I didn't think of that before. > 3. Use expressive names for helper methods > > When I see "before(:each) { setup_admin }", I don't really know what > that means. In order to figure it out, I have to look up at the > setup_user, setup_admin, and stub_user methods, and I need to > understand them all to really understand the purpose of any of them. > These could (and I'd say should) all be collapsed into this: > > def login_as(type) > user.stub(:is_administrator).and_return(type == :admin) > User.stub(:find_by_id).and_return(user) > session[:user_id = user.id] > end > I like this much better than what I currently have. As a recovering perfectionist, I suffer from the "it's gotta be named just right" syndrome. I sometimes spend far too much time trying to figure out the best name for this or that, and I've taken to grabbing something that is remotely close and moving on so I don't spend my wheels too long. > Now the before block can say "before(:each) { login_as :admin}" and a) > I probably don't have to go looking at that method to understand its > intent and b) I definitely don't have to go looking at three different > methods. > Of course, *you* might have to wonder what's going on because you're not familiar with the project. But since *I* wrote it, I immediately understand what setup_admin means. But I still like login_as better ;) > 4. Clarity trumps DRY > > DRY is a very important principle, but it is often misunderstood to > mean "don't type the same thing twice." That is not its intent, and > interpreting it as such often leads to less clarity. The bigger idea > is that we shouldn't express the same concept in two different parts > of a system. i.e. if we have two different parts of a codebase that > validate an email address, for example, and the rules for a valid > email address change (we decide to ping a service to see if the email > address actually exists in addition to validating its format), we run > the risk that we'll forget to change it in both cases. DRY helps us to > avoid that risk. > > This is a completely different matter from organizing a spec. > > This is the rub, I think. Much of the "incorrectness" of my specs can be traced back to my effort to stay DRY. I truly appreciate your comment about people often misunderstanding DRY to mean "don't retype what you don't have to." I'm guilty of that. Admittedly, I have not done extensive reading about the topic, but most of what I catch when people mention it in forums is just that: keep something DRY by refactoring it. I can see that retyping is obviously part of it, but it is really much more than that. As with just about everything else in life, one must find the balance. > Consider http://gist.github.com/338767. There are 4 permutations of > what is essentially the same spec. I'd argue that the two examples > near the top are far easier to grok than the latter two, even though > the latter two are DRYer. The first example spells out everything in > each example with zero indirection and very little API to grok. The > second one might be a bit DRYer but it requires more API (let). > > The first two are most certainly easier on my eyes. That in and of itself would be worth changing how I do these things. [As an aside, I believe you have a copy/paste oops in your "without an umbrella" or "gets wet" contexts. Shouldn't it be person.should_not be_dry ?] > 5. Given/When/Then > > This probably shouldn't be last, but ... > > Express every example in the form Given/When/Then: given some context, > when some event occurs, then the outcome should be ... > > Consider the first example group in http://gist.github.com/338767. > Both examples in that express the givens (person and day) in the first > two lines, the event (person walks on the day) on the third line, and > the outcome on the last line. The symmetry between them makes it very > easy to see the differences between them, even though that is probably > the least DRY example in the gist. > > I should probably try to use that terminology more in my specs. It's proven valuable in the cucumber features, so it should be likewise so in rspec. > That's probably enough to chew on for now. All comments welcome. > > That's a mouthful, for sure! Thank you, David, for taking the time to generate such a thoughtful critique of my work. Not only do I get the benefit of your experience, knowledge and insight, but so does everyone following at home. Patrick, don't listen to me :) Listen to David. > Cheers, > David > > Peace, Phillip From brunopedroso at gmail.com Sun Mar 21 21:08:37 2010 From: brunopedroso at gmail.com (Bruno Pedroso) Date: Sun, 21 Mar 2010 22:08:37 -0300 Subject: [rspec-users] autotest, rails and view specs Message-ID: Hi, I've read in [1] that autotest "does not work with view specs for rails versions < 2.3", but I didn't find a reason about that. Is it just a bug? -- []'s Bruno [1] http://wiki.github.com/dchelimsky/rspec/spork-autospec-pure-bdd-joy -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Sun Mar 21 21:32:25 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 21 Mar 2010 20:32:25 -0500 Subject: [rspec-users] autotest, rails and view specs In-Reply-To: References: Message-ID: <57c63afe1003211832g2561edb9n8f32e7c411f3fb10@mail.gmail.com> On Sun, Mar 21, 2010 at 8:08 PM, Bruno Pedroso wrote: > Hi, > > I've read in [1] that autotest "does not work with view specs for rails > versions < 2.3", but I didn't find a reason about that. It's the combination of autotest and spork that results in inconsistent results. > Is it just a bug? You make it sound so simple :) To be honest I don't remember the specific issue. I believe it was related to rails' template caching. If you can get it to work reliably I'll be happy to accept a patch. Please file a ticket at http://rspec.lighthouseapp.com/ first, and then link to or attach a patch. > > -- > []'s Bruno > > > > [1] http://wiki.github.com/dchelimsky/rspec/spork-autospec-pure-bdd-joy From leopoldo.agdeppa at gmail.com Sun Mar 21 23:34:51 2010 From: leopoldo.agdeppa at gmail.com (Leopoldo Agdeppa) Date: Mon, 22 Mar 2010 11:34:51 +0800 Subject: [rspec-users] rspec bug, on Mysql::Error: MySQL server has gone away: ROLLBACK TO SAVEPOINT active_record_1 Message-ID: hello can anybody help me with this bug, (this sometimes occur sometimes passes) 1) ActiveRecord::StatementInvalid in 'MailReader on Simple Tasks should not accept duplicate email' Mysql::Error: MySQL server has gone away: ROLLBACK TO SAVEPOINT active_record_1 /home/poldz/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract_adapter.rb:219:in `log' /home/poldz/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/mysql_adapter.rb:323:in `execute' /home/poldz/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/mysql_adapter.rb:365:in `rollback_to_savepoint' /home/poldz/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/database_statements.rb:145:in `transaction' /home/poldz/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/transactions.rb:182:in `transaction' /home/poldz/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/transactions.rb:228:in `with_transaction_returning_status' /home/poldz/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/transactions.rb:196:in `save' /home/poldz/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/transactions.rb:208:in `rollback_active_record_state!' /home/poldz/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/transactions.rb:196:in `save' /home/poldz/projects/ruby/wruwo/app/models/user.rb:811:in `log_activity' /home/poldz/projects/ruby/wruwo/app/models/task.rb:490:in `notify_new_task' /home/poldz/projects/ruby/wruwo/app/models/mail_reader.rb:123:in `create_task' /home/poldz/projects/ruby/wruwo/app/models/mail_reader.rb:263:in `process_received_mail' ./spec/models/mail_reader_spec.rb:97: 2) ActiveRecord::StatementInvalid in 'MailReader on Tasks with Workspace workspace member (david) - should be able to email task to shadow-user using default: keyword' Mysql::Error: MySQL server has gone away: ROLLBACK TO SAVEPOINT active_record_1 /home/poldz/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract_adapter.rb:219:in `log' /home/poldz/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/mysql_adapter.rb:323:in `execute' /home/poldz/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/mysql_adapter.rb:365:in `rollback_to_savepoint' /home/poldz/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/database_statements.rb:145:in `transaction' /home/poldz/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/transactions.rb:182:in `transaction' /home/poldz/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/transactions.rb:200:in `save!' /home/poldz/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/transactions.rb:208:in `rollback_active_record_state!' /home/poldz/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/transactions.rb:200:in `save!' /home/poldz/projects/ruby/wruwo/app/models/mail_reader.rb:79:in `create_task' /home/poldz/projects/ruby/wruwo/app/models/mail_reader.rb:263:in `process_received_mail' ./spec/models/mail_reader_on_tasks_with_workspace_spec.rb:232: Finished in 61.718884 seconds 137 examples, 2 failures rake aborted! Command /usr/local/bin/ruby -I"lib" "/usr/local/lib/ruby/gems/1.8/gems/rspec-1.3.0/bin/spec" "spec/models/calendar_event_spec.rb" "spec/models/user_spec.rb" "spec/models/mail_reader_spec.rb" "spec/models/task_spec.rb" "spec/models/mail_reader_on_tasks_with_workspace_spec.rb" "spec/helpers/users_helper_spec.rb" "spec/lib/task_string_pattern_spec.rb" "spec/lib/task_question_answer_string_pattern_spec.rb" "spec/controllers/sessions_controller_spec.rb" "spec/controllers/users_controller_spec.rb" "spec/controllers/tasks_controller_spec.rb" "spec/controllers/workspace_with_workflow_tasks_controller_spec.rb" "spec/controllers/workspace_tasks_controller_spec.rb" --options "/home/poldz/projects/ruby/wruwo/spec/spec.opts" failed (See full trace by running task with --trace) -- Bong -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Mon Mar 22 10:30:17 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 22 Mar 2010 09:30:17 -0500 Subject: [rspec-users] lots of nil problems! In-Reply-To: <4BA51274.7010104@gmail.com> References: <37f5aff8-a571-43d9-b60e-468c35ad4438@g1g2000pre.googlegroups.com> <19f7c704f632d41e8c3f9034adb4085a@ruby-forum.com> <4BA4AD1C.2000103@gmail.com> <4BA4D363.1050909@gmail.com> <4BA4E772.9090609@gmail.com> <57c63afe1003201017r6254b7e1rf85e9764a7fd4fc4@mail.gmail.com> <4BA51274.7010104@gmail.com> Message-ID: On Mar 20, 2010, at 1:22 PM, Phillip Koebbe wrote: > Patrick, don't listen to me :) Listen to David. That's just silly. Patrick, please listen to both of us (and everyone else who contributes to this list). What Phillip wrote about the difference between mocks and stubs was dead on. I was commenting on the context. Cheers, David From brunopedroso at gmail.com Mon Mar 22 11:36:33 2010 From: brunopedroso at gmail.com (Bruno Pedroso) Date: Mon, 22 Mar 2010 12:36:33 -0300 Subject: [rspec-users] autotest, rails and view specs Message-ID: Hi, I've read in [1] that autotest "does not work with view specs for rails versions < 2.3", but I didn't find a reason for that. Is it just a bug? -- []'s Bruno [1] http://wiki.github.com/dchelimsky/rspec/spork-autospec-pure-bdd-joy -- []'s Bruno -------------- next part -------------- An HTML attachment was scrubbed... URL: From phillipkoebbe at gmail.com Mon Mar 22 15:53:28 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Mon, 22 Mar 2010 14:53:28 -0500 Subject: [rspec-users] lots of nil problems! In-Reply-To: <57c63afe1003201017r6254b7e1rf85e9764a7fd4fc4@mail.gmail.com> References: <37f5aff8-a571-43d9-b60e-468c35ad4438@g1g2000pre.googlegroups.com> <19f7c704f632d41e8c3f9034adb4085a@ruby-forum.com> <4BA4AD1C.2000103@gmail.com> <4BA4D363.1050909@gmail.com> <4BA4E772.9090609@gmail.com> <57c63afe1003201017r6254b7e1rf85e9764a7fd4fc4@mail.gmail.com> Message-ID: <4BA7CAB8.7070604@gmail.com> On 2010-03-20 12:17 PM, David Chelimsky wrote: > 2. Setup context in before blocks, not expectations > > We want the example names to express the intent of each example. > > The before block in the "with valid id' context sets two expectations, > and then each example sets one of its own. If "should_not_assign_to > :message" fails because Message didn't receive :find_by_id, the > failure has nothing to do with the intent expressed by that example. > Same goes for @message.should_receive(:destroy). > > If you want those expectations to be part of the spec, then add > examples for them. If you don't care that they are specified, then > don't. Either way, prefer stub() over should_receive() in before > blocks. > I just remembered why I started putting .should_receive in the setup. It was because I use Remarkable and I had the action (post :create, get :new, whatever) in the before block. Here's an example from what I'm working on today: http://gist.github.com/340458 Before I started using Remarkable, I think I would have put the expectation in an example (I can't remember how much I used should_receive at that point, so I don't know for sure). When I started using Remarkable, I ran into the issue of needing to set the expectation before the action was performed, so I moved it into the setup. I had forgotten that until today when I was merrily moving the expectations back to examples and only having the stub in the setup. So now my dilemma is to 1) continue doing it the way I have been even though it's not "proper" 2) wrap the Remarkable macros in a context so I can use a before block to execute the action 3) stop using Remarkable 4) some other solution I'm not currently aware of Funny enough, I'm actually leaning toward #3. Thoughts? Peace, Phillip From patrick at collinatorstudios.com Tue Mar 23 13:43:20 2010 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Tue, 23 Mar 2010 10:43:20 -0700 (PDT) Subject: [rspec-users] continuing on my quest to learn rspec... Message-ID: Ok, So... My first attempt at specing a method in my photo model didn't go so well.. http://gist.github.com/341447 Both of these tests are failing, and I am not even sure if I am structuring this anywhere near correct or not... In other words... HELP!!!!!!!!!! Patrick J. Collins http://collinatorstudios.com From phillipkoebbe at gmail.com Tue Mar 23 18:10:41 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Tue, 23 Mar 2010 17:10:41 -0500 Subject: [rspec-users] Link to current documentation Message-ID: <4BA93C61.3090400@gmail.com> I bookmark the RSpec documentation like http://rspec.rubyforge.org/rspec-rails/1.3.2/ I was wondering if the maintainer of the site (David?) would be willing to create "current" link that would redirect to the appropriate version. This would save people like myself from having to update bookmarks whenever a new version is released and the docs are updated. Unless I'm the only one this would affect... Peace, Phillip From matt at mattwynne.net Tue Mar 23 20:03:20 2010 From: matt at mattwynne.net (Matt Wynne) Date: Wed, 24 Mar 2010 00:03:20 +0000 Subject: [rspec-users] continuing on my quest to learn rspec... In-Reply-To: References: Message-ID: On 23 Mar 2010, at 17:43, Patrick J. Collins wrote: > Ok, > > So... My first attempt at specing a method in my photo model didn't > go so > well.. > > http://gist.github.com/341447 > > Both of these tests are failing, and I am not even sure if I am > structuring > this anywhere near correct or not... > > In other words... HELP!!!!!!!!!! > > Patrick J. Collins > http://collinatorstudios.com Okay I have a few thoughts for you Patrick, hopefully I'll be able to give you them in an order that makes some sense. Firstly I wonder why you're putting this behaviour on the photo class. Have you ever heard of the code smell 'feature envy'? Photo#set_cover seems to me to be talking mostly to the photo_album, so perhaps this behaviour should move there? Something like https://gist.github.com/341831/663bbef3cb55a70ce875df88643f54a6913193b1 Also, I'm not seeing anything in the specs that actually triggers any behaviour in the class. You set up a stub and then immediately assert what the photo album's cover should be - when are you expecting the code you want to test to be caused to actually run? > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users cheers, Matt http://mattwynne.net +447974 430184 From garren.smith at gmail.com Tue Mar 23 16:12:22 2010 From: garren.smith at gmail.com (garren) Date: Tue, 23 Mar 2010 13:12:22 -0700 (PDT) Subject: [rspec-users] Mock Global method Message-ID: Hi All, I'm very new to ruby and mocking a dynamic language. I would like to mock a helper method in Sinatra. So an example is this: helper do def my_helper_method puts "Should do something useful here..." end end How would I mock that method and how would I mock a method in general that is a global method. Is it better practice not to have global methods? Should I rather have an object inside the method call that does all the work and I can mock that? Thanks From patrick at collinatorstudios.com Wed Mar 24 04:46:53 2010 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Wed, 24 Mar 2010 01:46:53 -0700 (PDT) Subject: [rspec-users] continuing on my quest to learn rspec... In-Reply-To: References: Message-ID: > Firstly I wonder why you're putting this behaviour on the photo class. Have > you ever heard of the code smell 'feature envy'? Photo#set_cover seems to me > to be talking mostly to the photo_album, so perhaps this behaviour should move > there? Ok.. So I changed that code and put it in my photos_controller, and I took the gist you wrote, and modified it to what I *think* the behavior should be. I still am very much struggling as to what I am doing......... http://gist.github.com/342102 So, let me explain my idea of the behavior I am imagining, and see if perhaps you guys can guide me as to how I should be thinking, etc. Ok.. So... Form field, checkbox_tag :photo_album_cover.. If it's checked, when the photo is saved, it should set that photo to be the cover for the photo album. If it's not checked, and no cover is currently set, it should set the cover to the first photo in the album. If it's not checked, and this currently save photo is the only photo in the album, then it is 'the first photo in the album', and therefore it should be the cover. ...... That's the basis for this "behavior"... So, what am I doing wrong as far as my spec goes, because I am getting: 'PhotoAlbum saving a photo should set the cover of the album to the curent photo when 'album cover' is checked' FAILED expected: #, got: nil (using ==) ... Thank you in advance for your patience and guidance! Patrick J. Collins http://collinatorstudios.com On Wed, 24 Mar 2010, Matt Wynne wrote: > > On 23 Mar 2010, at 17:43, Patrick J. Collins wrote: > > > Ok, > > > > So... My first attempt at specing a method in my photo model didn't go so > > well.. > > > > http://gist.github.com/341447 > > > > Both of these tests are failing, and I am not even sure if I am structuring > > this anywhere near correct or not... > > > > In other words... HELP!!!!!!!!!! > > > > Patrick J. Collins > > http://collinatorstudios.com > > Okay I have a few thoughts for you Patrick, hopefully I'll be able to give you > them in an order that makes some sense. > > > Something like > https://gist.github.com/341831/663bbef3cb55a70ce875df88643f54a6913193b1 > > Also, I'm not seeing anything in the specs that actually triggers any > behaviour in the class. You set up a stub and then immediately assert what the > photo album's cover should be - when are you expecting the code you want to > test to be caused to actually run? > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > cheers, > Matt > > http://mattwynne.net > +447974 430184 > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From ben.fyvie at champsoftware.com Wed Mar 24 11:39:39 2010 From: ben.fyvie at champsoftware.com (Ben Fyvie) Date: Wed, 24 Mar 2010 10:39:39 -0500 Subject: [rspec-users] How to stub a has_many relationship in Rails 2.3.5 Message-ID: <01CDF8132E5248A0BC5BA1AFDE0C38F4@champ.net> We have a test that has been working find until we upgraded to rails 2.3.5. I'm not too familiar with mocks/stubs so maybe there is an easy solution. Here is a simple example of our scenario. Class Person < ActiveRecord::Base has_many :aliases, :dependent => :nullify before_destroy :mark_aliases_as_deleted def mark_aliases_as_deleted self.aliases.each do |alias| alias.mark_as_deleted end end end This is a test to ensure that when the Person is destroyed that all of their Aliases get their mark_as_deleted method called. I know this example isn't very practical, but it is the simplest way I could think of to describe our problem. it "should trigger mark_as_deleted in related aliases" do aliases = [] 3.times do |i| alias = mock("alias #{i}") alias.should_receive(:mark_as_deleted) aliases << alias end @person.stub!(:aliases).and_return(aliases) @person.destroy end So the problem we are encountering in our scenario is that we get a NoMethodError exception (undefined method `owner_quoted_id' for #) when trying to destroy the Person because the stubbed Aliases return an array and it appears it is expecting some sort of association object that responds to owner_quoted_id Like I said, we didn't have any problems until upgrading from Rails 2.3.4 to Rails 2.3.5 In case your interested, it is the configure_dependency_for_has_many method that calls: "#{reflection.primary_key_name} = \#{record.#{reflection.name}.send(:owner_quoted_id)}" Any help would be greatly appreciated! Ben Fyvie -------------- next part -------------- An HTML attachment was scrubbed... URL: From thoen at edgevaleinteractive.com Wed Mar 24 14:39:29 2010 From: thoen at edgevaleinteractive.com (thoen) Date: Wed, 24 Mar 2010 11:39:29 -0700 (PDT) Subject: [rspec-users] Mock "Consent_6335" received unexpected message :marked_for_destruction? with (no args) Message-ID: I have a mock object (Person) that is associated with another object (my_object) through a belongs_to association. When I check whether my_object is valid (my_object.should be_valid), I am getting an error like the following: Mock "Person_6338" received unexpected message :marked_for_destruction? with (no args) Checking the list of methods on the mock, "marked_for_destruction?" is not listed. Is this this something that i should expect to always stub? As a check, I added def @target.marked_for_destruction? false end to the mock_model definition and the test passed. Rails 2.3.5 rspec (1.3.0, 1.2.6, 1.1.3) rspec-rails (1.3.2, 1.2.6) From thoen at edgevaleinteractive.com Wed Mar 24 14:49:24 2010 From: thoen at edgevaleinteractive.com (thoen) Date: Wed, 24 Mar 2010 11:49:24 -0700 (PDT) Subject: [rspec-users] Mock "Consent_6335" received unexpected message :marked_for_destruction? with (no args) In-Reply-To: References: Message-ID: <817ccc64-687f-42ea-9503-9a826ca6f707@j21g2000yqh.googlegroups.com> Instead of def @target.marked_for_destruction? false end i added marked_for_destruction in the list of stubs included in mock_model options_and_stubs = options_and_stubs.reverse_merge({ :id => id, :to_param => id.to_s, :new_record? => false, :destroyed? => false, :marked_for_destruction? => false, :errors => stub("errors", :count => 0) }) This seemed like a better place. On Mar 24, 2:39?pm, thoen wrote: > I have a mock object (Person) that is associated with another object > (my_object) through a belongs_to association. When I check whether > my_object is valid (my_object.should be_valid), I am getting an error > like the following: > > Mock "Person_6338" received unexpected > message :marked_for_destruction? with (no args) > > Checking the list of methods on the mock, "marked_for_destruction?" is > not listed. Is this this something that i should expect to always > stub? > > As a check, I added > > ? ? ? ? ? def ?@target.marked_for_destruction? > ? ? ? ? ? ? false > ? ? ? ? ? end > > to the mock_model definition and the test passed. > > Rails 2.3.5 > rspec (1.3.0, 1.2.6, 1.1.3) > rspec-rails (1.3.2, 1.2.6) > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From peter.fitzgibbons at gmail.com Wed Mar 24 15:36:10 2010 From: peter.fitzgibbons at gmail.com (Peter Fitzgibbons) Date: Wed, 24 Mar 2010 14:36:10 -0500 Subject: [rspec-users] Specing Ruby Game Development ??? Message-ID: <4BAA69AA.2010700@gmail.com> HI Folks, Roll Call for anyone using Rspec for Ruby Game Development (Rubygame, GOSU, TkRuby, etc.) ??? I'm having trouble finding the latest-and-greatest with Google searches. Happy Gaming! -- Peter Fitzgibbons (847) 859-9550 peter.fitzgibbons at gmail.com IM GTalk: peter.fitzgibbons IM AOL: peter.fitzgibbons at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From mailinglists at patmaddox.com Wed Mar 24 23:15:14 2010 From: mailinglists at patmaddox.com (Pat Maddox) Date: Wed, 24 Mar 2010 20:15:14 -0700 Subject: [rspec-users] Specing Ruby Game Development ??? In-Reply-To: <4BAA69AA.2010700@gmail.com> References: <4BAA69AA.2010700@gmail.com> Message-ID: <2929DB31-538B-484A-8028-6270C25C9709@patmaddox.com> Not I, but let me know if you come across anything please. Sounds interesting. On Mar 24, 2010, at 12:36 PM, Peter Fitzgibbons wrote: > HI Folks, > > Roll Call for anyone using Rspec for Ruby Game Development (Rubygame, GOSU, TkRuby, etc.) ??? > > I'm having trouble finding the latest-and-greatest with Google searches. > > Happy Gaming! > -- > Peter Fitzgibbons > (847) 859-9550 > peter.fitzgibbons at gmail.com > IM GTalk: peter.fitzgibbons > IM AOL: peter.fitzgibbons at gmail.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -------------- next part -------------- An HTML attachment was scrubbed... URL: From mauricioaniche at gmail.com Wed Mar 24 23:39:12 2010 From: mauricioaniche at gmail.com (Mauricio Aniche) Date: Thu, 25 Mar 2010 00:39:12 -0300 Subject: [rspec-users] Problems testing destroy method in rspec2 Message-ID: <313e92a61003242039o162cb9c6l85b3d14dd98764e1@mail.gmail.com> Hi, I am trying to test the destroy method in my rails 3 controller, but I always get an "no route matches {}" error. But the route do exist, as I can see by running rake routes. I have something like this: delete :destroy, :id => "1" The stack trace: Failure/Error: delete :destroy, :id => "1" No route matches {} # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_dispatch/routing/route_set.rb:415:in `generate' # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/url_rewriter.rb:43:in `rewrite' # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/url_rewriter.rb:16:in `rewrite' # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/url_for.rb:145:in `url_for' # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/redirecting.rb:86:in `_compute_redirect_to_location' # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/redirecting.rb:58:in `redirect_to' # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/flash.rb:25:in `redirect_to' # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/instrumentation.rb:59:in `redirect_to' # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/notifications/instrumenter.rb:18:in `instrument' # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/notifications.rb:49:in `__send__' # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/notifications.rb:49:in `instrument' # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/instrumentation.rb:58:in `redirect_to' # /Users//dev/easyclinica/app/controllers/convenios_controller.rb:55 # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/mime_responds.rb:189:in `call' # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/mime_responds.rb:189:in `respond_to' # /Users//dev/easyclinica/app/controllers/convenios_controller.rb:53:in `destroy' # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/base.rb:44:in `send_action' # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/base.rb:44:in `send_action' # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/abstract_controller/base.rb:145:in `process_action' # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/abstract_controller/callbacks.rb:18:in `process_action' # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/callbacks.rb:438:in `_run__2086632925__process_action__988268021__callbacks' # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/callbacks.rb:403:in `send' # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/callbacks.rb:403:in `_run_process_action_callbacks' # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/callbacks.rb:88:in `send' # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/callbacks.rb:88:in `run_callbacks' # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/abstract_controller/callbacks.rb:17:in `process_action' # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/rendering.rb:12:in `process_action' # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/compatibility.rb:66:in `process_action' # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/instrumentation.rb:29:in `process_action' # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/notifications/instrumenter.rb:18:in `instrument' # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/notifications.rb:49:in `__send__' # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/notifications.rb:49:in `instrument' # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/instrumentation.rb:28:in `process_action' # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/rescue.rb:8:in `process_action' # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/abstract_controller/base.rb:115:in `process' # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal.rb:64:in `dispatch' # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/rack_delegation.rb:19:in `dispatch' # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal.rb:89:in `call' # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/rack-test-0.5.3/lib/rack/mock_session.rb:30:in `request' # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/rack-test-0.5.3/lib/rack/test.rb:207:in `process_request' # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/rack-test-0.5.3/lib/rack/test.rb:105:in `request' # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_dispatch/testing/integration.rb:272:in `process' # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_dispatch/testing/integration.rb:48:in `delete' # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_dispatch/testing/integration.rb:315:in `__send__' # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_dispatch/testing/integration.rb:315:in `delete' # (eval):3:in `delete' # ./spec/controllers/_spec.rb:49 Have you guys ever been through this problem? Thanks, Mauricio -------------- next part -------------- An HTML attachment was scrubbed... URL: From jbrainsberger at gmail.com Thu Mar 25 00:27:01 2010 From: jbrainsberger at gmail.com (J. B. Rainsberger) Date: Wed, 24 Mar 2010 21:27:01 -0700 Subject: [rspec-users] Mock Global method In-Reply-To: References: Message-ID: <4BAAE615.5060707@gmail.com> garren wrote: > I'm very new to ruby and mocking a dynamic language. I would like to > mock a helper method in Sinatra. So an example is this: > > helper do > def my_helper_method > puts "Should do something useful here..." > end > end > > > How would I mock that method and how would I mock a method in general > that is a global method. Is it better practice not to have global > methods? Should I rather have an object inside the method call that > does all the work and I can mock that? You can probably set an expectation on Kernel#puts, since although #puts looks global, it belongs to Kernel. As for whether you should use #puts directly here, or indirectly through another object that you can easily control, that depends on the situation. Try both and compare the results. In your situation, I'd probably just set expectations on Kernel#puts until that caused me problems, at which point I'd separate the behavior of deciding what to print from deciding where to print it. I find formatting messages much easier to check, in general, than displaying them. Have fun. -- J. B. Rainsberger :: http://www.jbrains.ca :: http://www.thecodewhisperer.com From julian at leviston.net Thu Mar 25 00:22:46 2010 From: julian at leviston.net (Julian Leviston) Date: Thu, 25 Mar 2010 15:22:46 +1100 Subject: [rspec-users] Problems testing destroy method in rspec2 In-Reply-To: <313e92a61003242039o162cb9c6l85b3d14dd98764e1@mail.gmail.com> References: <313e92a61003242039o162cb9c6l85b3d14dd98764e1@mail.gmail.com> Message-ID: Only thing that springs to mind is that perhaps you haven't specified the :method => :delete option on the link? Julian. On 25/03/2010, at 2:39 PM, Mauricio Aniche wrote: > Hi, > > I am trying to test the destroy method in my rails 3 controller, but I always get an "no route matches {}" error. But the route do exist, as I can see by running rake routes. > > I have something like this: > delete :destroy, :id => "1" > > The stack trace: > Failure/Error: delete :destroy, :id => "1" > No route matches {} > # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_dispatch/routing/route_set.rb:415:in `generate' > # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/url_rewriter.rb:43:in `rewrite' > # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/url_rewriter.rb:16:in `rewrite' > # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/url_for.rb:145:in `url_for' > # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/redirecting.rb:86:in `_compute_redirect_to_location' > # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/redirecting.rb:58:in `redirect_to' > # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/flash.rb:25:in `redirect_to' > # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/instrumentation.rb:59:in `redirect_to' > # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/notifications/instrumenter.rb:18:in `instrument' > # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/notifications.rb:49:in `__send__' > # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/notifications.rb:49:in `instrument' > # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/instrumentation.rb:58:in `redirect_to' > # /Users//dev/easyclinica/app/controllers/convenios_controller.rb:55 > # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/mime_responds.rb:189:in `call' > # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/mime_responds.rb:189:in `respond_to' > # /Users//dev/easyclinica/app/controllers/convenios_controller.rb:53:in `destroy' > # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/base.rb:44:in `send_action' > # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/base.rb:44:in `send_action' > # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/abstract_controller/base.rb:145:in `process_action' > # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/abstract_controller/callbacks.rb:18:in `process_action' > # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/callbacks.rb:438:in `_run__2086632925__process_action__988268021__callbacks' > # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/callbacks.rb:403:in `send' > # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/callbacks.rb:403:in `_run_process_action_callbacks' > # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/callbacks.rb:88:in `send' > # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/callbacks.rb:88:in `run_callbacks' > # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/abstract_controller/callbacks.rb:17:in `process_action' > # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/rendering.rb:12:in `process_action' > # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/compatibility.rb:66:in `process_action' > # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/instrumentation.rb:29:in `process_action' > # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/notifications/instrumenter.rb:18:in `instrument' > # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/notifications.rb:49:in `__send__' > # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/notifications.rb:49:in `instrument' > # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/instrumentation.rb:28:in `process_action' > # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/rescue.rb:8:in `process_action' > # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/abstract_controller/base.rb:115:in `process' > # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal.rb:64:in `dispatch' > # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/rack_delegation.rb:19:in `dispatch' > # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal.rb:89:in `call' > # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/rack-test-0.5.3/lib/rack/mock_session.rb:30:in `request' > # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/rack-test-0.5.3/lib/rack/test.rb:207:in `process_request' > # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/rack-test-0.5.3/lib/rack/test.rb:105:in `request' > # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_dispatch/testing/integration.rb:272:in `process' > # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_dispatch/testing/integration.rb:48:in `delete' > # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_dispatch/testing/integration.rb:315:in `__send__' > # /Users//.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_dispatch/testing/integration.rb:315:in `delete' > # (eval):3:in `delete' > # ./spec/controllers/_spec.rb:49 > > Have you guys ever been through this problem? > > Thanks, > Mauricio > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From rodrigo.benenson at gmail.com Thu Mar 25 06:11:07 2010 From: rodrigo.benenson at gmail.com (rodrigo benenson) Date: Thu, 25 Mar 2010 11:11:07 +0100 Subject: [rspec-users] Trivial controller spec fail In-Reply-To: References: Message-ID: Hello RSpec community ! I'm a Ruby on Rails newby trying to get my first application running. I already got some of the website running and now I'm writting the tests to verify that everything works as expected and that it will stay like that in future versions. However I'm having a really hard time getting RSpec to run correctly. Following the mailing list policy I have created a gist with: system configuration.txt -> my gem list and spec version teaser_controller.rb -> the 12 lines dummy controller teaser_controller_spec.rb -> the 14 lines spec that fails output.txt -> the error I get when I run "rake spec:controllers", with its traceback http://gist.github.com/343339 My controller does ?def index ? ? ? ?render :teaser_v1 ?end def teaser_v1 ?end My spec does ?it "renders :teaser_v1" do ? ? ?get :index ?end and then rake spec does ArgumentError in 'TeaserController GET index renders :teaser_v1' wrong number of arguments (2 for 1) /home/rodrigob/work/popster_work/popster_bzr/src/web/popster/app/controllers/teaser_controller.rb:6:in `index' /var/lib/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb:1331:in `send' The teaser_controller just renders a static html files, no templates, no partials, no nothing. Yet, the test fails. I have created a side test project where I ran ruby script/generate rspec_scaffold Stuff name:string category:name and compared the created files with mines. But I still cannot see why the test project specs pass, and mines do not. Your help is very welcome. Than you very much for creating such a nice specification tool. I hope I will be able to use and contribute to it in the future. Regards, rodrigob. From dchelimsky at gmail.com Thu Mar 25 07:08:31 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 25 Mar 2010 06:08:31 -0500 Subject: [rspec-users] Trivial controller spec fail In-Reply-To: References: Message-ID: <57c63afe1003250408v16417ba0h5e7c7f54be975968@mail.gmail.com> On Thu, Mar 25, 2010 at 5:11 AM, rodrigo benenson wrote: > Hello RSpec community ! Welcome, Rodrigo. > I'm a Ruby on Rails newby trying to get my first application running. > I already got some of the website running and now I'm writting the > tests to verify that everything works as expected and that it will > stay like that in future versions. > However I'm having a really hard time getting RSpec to run correctly. > > Following the mailing list policy I have created a gist with: > > system configuration.txt -> my gem list and spec version > teaser_controller.rb -> the 12 lines dummy controller > teaser_controller_spec.rb -> the 14 lines spec that fails > output.txt -> the error I get when I run "rake spec:controllers", with > its traceback > > http://gist.github.com/343339 > > My controller does > ?def index > ? ? ? ?render :teaser_v1 If you're rendering another action in Rails, this should read: render :action => "teaser_v1" Take a look at http://api.rubyonrails.org/classes/ActionController/Base.html#M000658 for more info. HTH, David > ?end > > def teaser_v1 > ?end > > My spec does > ?it "renders :teaser_v1" do > ? ? ?get :index > ?end > > and then rake spec does > ArgumentError in 'TeaserController GET index renders :teaser_v1' > wrong number of arguments (2 for 1) > /home/rodrigob/work/popster_work/popster_bzr/src/web/popster/app/controllers/teaser_controller.rb:6:in > `index' > /var/lib/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb:1331:in > `send' > > The teaser_controller just renders a static html files, no templates, > no partials, no nothing. Yet, the test fails. > > I have created a side test project where I ran > ruby script/generate rspec_scaffold Stuff name:string category:name > > and compared the created files with mines. But I still cannot see why > the test project specs pass, and mines do not. > > Your help is very welcome. > Than you very much for creating such a nice specification tool. > I hope I will be able to use and contribute to it in the future. > > Regards, > rodrigob. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Thu Mar 25 07:19:39 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 25 Mar 2010 06:19:39 -0500 Subject: [rspec-users] Problems testing destroy method in rspec2 In-Reply-To: <313e92a61003242039o162cb9c6l85b3d14dd98764e1@mail.gmail.com> References: <313e92a61003242039o162cb9c6l85b3d14dd98764e1@mail.gmail.com> Message-ID: <57c63afe1003250419t5ab699eew75e6695c9c6cfb92@mail.gmail.com> On Wed, Mar 24, 2010 at 10:39 PM, Mauricio Aniche wrote: > Hi, > I am trying to test the destroy method in my rails 3 controller, but I > always get an "no route matches {}" error. But the route do exist, as I can > see by running rake routes. What version of rspec and rspec-rails are you using? > I have something like this: > delete :destroy, :id => "1" > The stack trace: > ?? ?Failure/Error: delete :destroy, :id => "1" > ?? ?No route matches {} > ?? ?# /Users/ user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_dispatch/routing/route_set.rb:415:in > `generate' > ?? ?# /Users/ user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/url_rewriter.rb:43:in > `rewrite' > ?? ?# /Users/ user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/url_rewriter.rb:16:in > `rewrite' > ?? ?# /Users/ user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/url_for.rb:145:in > `url_for' > ?? ?# /Users/ user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/redirecting.rb:86:in > `_compute_redirect_to_location' > ?? ?# /Users/ user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/redirecting.rb:58:in > `redirect_to' > ?? ?# /Users/ user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/flash.rb:25:in > `redirect_to' > ?? ?# /Users/ user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/instrumentation.rb:59:in > `redirect_to' > ?? ?# /Users/ user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/notifications/instrumenter.rb:18:in > `instrument' > ?? ?# /Users/ user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/notifications.rb:49:in > `__send__' > ?? ?# /Users/ user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/notifications.rb:49:in > `instrument' > ?? ?# /Users/ user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/instrumentation.rb:58:in > `redirect_to' > ?? ?# /Users/ user>/dev/easyclinica/app/controllers/convenios_controller.rb:55 > ?? ?# /Users/ user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/mime_responds.rb:189:in > `call' > ?? ?# /Users/ user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/mime_responds.rb:189:in > `respond_to' > ?? ?# /Users/ user>/dev/easyclinica/app/controllers/convenios_controller.rb:53:in > `destroy' > ?? ?# /Users/ user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/base.rb:44:in > `send_action' > ?? ?# /Users/ user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/base.rb:44:in > `send_action' > ?? ?# /Users/ user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/abstract_controller/base.rb:145:in > `process_action' > ?? ?# /Users/ user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/abstract_controller/callbacks.rb:18:in > `process_action' > ?? ?# /Users/ user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/callbacks.rb:438:in > `_run__2086632925__process_action__988268021__callbacks' > ?? ?# /Users/ user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/callbacks.rb:403:in > `send' > ?? ?# /Users/ user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/callbacks.rb:403:in > `_run_process_action_callbacks' > ?? ?# /Users/ user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/callbacks.rb:88:in > `send' > ?? ?# /Users/ user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/callbacks.rb:88:in > `run_callbacks' > ?? ?# /Users/ user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/abstract_controller/callbacks.rb:17:in > `process_action' > ?? ?# /Users/ user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/rendering.rb:12:in > `process_action' > ?? ?# /Users/ user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/compatibility.rb:66:in > `process_action' > ?? ?# /Users/ user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/instrumentation.rb:29:in > `process_action' > ?? ?# /Users/ user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/notifications/instrumenter.rb:18:in > `instrument' > ?? ?# /Users/ user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/notifications.rb:49:in > `__send__' > ?? ?# /Users/ user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/notifications.rb:49:in > `instrument' > ?? ?# /Users/ user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/instrumentation.rb:28:in > `process_action' > ?? ?# /Users/ user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/rescue.rb:8:in > `process_action' > ?? ?# /Users/ user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/abstract_controller/base.rb:115:in > `process' > ?? ?# /Users/ user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal.rb:64:in > `dispatch' > ?? ?# /Users/ user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/rack_delegation.rb:19:in > `dispatch' > ?? ?# /Users/ user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal.rb:89:in > `call' > ?? ?# /Users/ user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/rack-test-0.5.3/lib/rack/mock_session.rb:30:in > `request' > ?? ?# /Users/ user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/rack-test-0.5.3/lib/rack/test.rb:207:in > `process_request' > ?? ?# /Users/ user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/rack-test-0.5.3/lib/rack/test.rb:105:in > `request' > ?? ?# /Users/ user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_dispatch/testing/integration.rb:272:in > `process' > ?? ?# /Users/ user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_dispatch/testing/integration.rb:48:in > `delete' > ?? ?# /Users/ user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_dispatch/testing/integration.rb:315:in > `__send__' > ?? ?# /Users/ user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_dispatch/testing/integration.rb:315:in > `delete' > ?? ?# (eval):3:in `delete' > ?? ?# ./spec/controllers/_spec.rb:49 > Have you guys ever been through this problem? > Thanks, > Mauricio > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Thu Mar 25 07:39:12 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 25 Mar 2010 06:39:12 -0500 Subject: [rspec-users] Mock "Consent_6335" received unexpected message :marked_for_destruction? with (no args) In-Reply-To: <817ccc64-687f-42ea-9503-9a826ca6f707@j21g2000yqh.googlegroups.com> References: <817ccc64-687f-42ea-9503-9a826ca6f707@j21g2000yqh.googlegroups.com> Message-ID: <57c63afe1003250439kd9341f3v4d888c6ebfc3ad44@mail.gmail.com> On Wed, Mar 24, 2010 at 1:49 PM, thoen wrote: > On Mar 24, 2:39?pm, thoen wrote: >> I have a mock object (Person) that is associated with another object >> (my_object) through a belongs_to association. When I check whether >> my_object is valid (my_object.should be_valid), I am getting an error >> like the following: >> >> Mock "Person_6338" received unexpected >> message :marked_for_destruction? with (no args) >> >> Checking the list of methods on the mock, "marked_for_destruction?" is >> not listed. Is this this something that i should expect to always >> stub? >> >> As a check, I added >> >> ? ? ? ? ? def ?@target.marked_for_destruction? >> ? ? ? ? ? ? false >> ? ? ? ? ? end >> >> to the mock_model definition and the test passed. >> >> Rails 2.3.5 >> rspec (1.3.0, 1.2.6, 1.1.3) >> rspec-rails (1.3.2, 1.2.6) > Instead of > > def ?@target.marked_for_destruction? > ? ?false > end > > i added marked_for_destruction in the list of stubs included in > mock_model > > ? ? ? ?options_and_stubs = options_and_stubs.reverse_merge({ > ? ? ? ? ?:id => id, > ? ? ? ? ?:to_param => id.to_s, > ? ? ? ? ?:new_record? => false, > ? ? ? ? ?:destroyed? => false, > ? ? ? ? ?:marked_for_destruction? => false, > ? ? ? ? ?:errors => stub("errors", :count => 0) > ? ? ? ?}) > > This seemed like a better place. http://github.com/dchelimsky/rspec-rails/commit/ad76867f28cb0ca05925e74eacb4cf81b934ce27 It'll be part of rspec-rails-1.3.3 From dchelimsky at gmail.com Thu Mar 25 07:51:26 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 25 Mar 2010 06:51:26 -0500 Subject: [rspec-users] How to stub a has_many relationship in Rails 2.3.5 In-Reply-To: <01CDF8132E5248A0BC5BA1AFDE0C38F4@champ.net> References: <01CDF8132E5248A0BC5BA1AFDE0C38F4@champ.net> Message-ID: <57c63afe1003250451h79f38a4emf50fcad0e676c224@mail.gmail.com> On Wed, Mar 24, 2010 at 10:39 AM, Ben Fyvie wrote: > We have a test that has been working find until we upgraded to rails 2.3.5. > I?m not too familiar with mocks/stubs so maybe there is an easy solution. > > Here is a simple example of our scenario. > > Class Person < ActiveRecord::Base > ? has_many :aliases, :dependent => :nullify > ? before_destroy :mark_aliases_as_deleted > ? def mark_aliases_as_deleted > ? ??self.aliases.each do |alias| > ????? alias.mark_as_deleted > ??? end > ? end > end > > This is a test to ensure that when the Person is destroyed that all of their > Aliases get their mark_as_deleted method called. I know this example isn?t > very practical, but it is the simplest way I could think of to describe our > problem. > > it ?should trigger mark_as_deleted in related aliases? do > ? aliases = [] > ? 3.times do |i| > ??? alias = mock(?alias #{i}?) > ??? alias.should_receive(:mark_as_deleted) > ??? aliases << alias > ? end > ? @person.stub!(:aliases).and_return(aliases) > ? @person.destroy > end > > So the problem we are encountering in our scenario is that we get a > NoMethodError exception (undefined method `owner_quoted_id' for > #) when trying to destroy the Person because the stubbed > Aliases return an array and it appears it is expecting some sort of > association object that responds to owner_quoted_id > > Like I said, we didn?t have any problems until upgrading from Rails 2.3.4 to > Rails 2.3.5 > > In case your interested, it is the configure_dependency_for_has_many method > that calls: "#{reflection.primary_key_name} = > \#{record.#{reflection.name}.send(:owner_quoted_id)}" > > Any help would be greatly appreciated! There are two ways I would try to go on this. One would be to add the aliases to the actual association: it ?should trigger mark_as_deleted in related aliases? do 3.times do |i| alias = mock(?alias #{i}?) alias.should_receive(:mark_as_deleted) @person.aliases << alias end @person.destroy end The other would be to stub owner_quoted_id on the array: it ?should trigger mark_as_deleted in related aliases? do aliases = [] aliases.stub(:owner_quoted_id) 3.times do |i| alias = mock(?alias #{i}?) alias.should_receive(:mark_as_deleted) aliases << alias end @person.stub!(:aliases).and_return(aliases) @person.destroy end I'm not sure that either would work :) But that's where I'd start. HTH, David From mauricioaniche at gmail.com Thu Mar 25 09:15:53 2010 From: mauricioaniche at gmail.com (Mauricio Aniche) Date: Thu, 25 Mar 2010 10:15:53 -0300 Subject: [rspec-users] Problems testing destroy method in rspec2 In-Reply-To: <57c63afe1003250419t5ab699eew75e6695c9c6cfb92@mail.gmail.com> References: <313e92a61003242039o162cb9c6l85b3d14dd98764e1@mail.gmail.com> <57c63afe1003250419t5ab699eew75e6695c9c6cfb92@mail.gmail.com> Message-ID: <313e92a61003250615l25f4823y8c39e2ad60be4654@mail.gmail.com> Hi David, I am using rspec2 beta4, which is the latest version in gemcutter. Hi Julian, The problem only happens in my spec. My rails3 applications works fine (I use a post with a hidden _method set as delete, but I guess this is a browser problem!) Regards, Mauricio On 3/25/10, David Chelimsky wrote: > On Wed, Mar 24, 2010 at 10:39 PM, Mauricio Aniche > wrote: >> Hi, >> I am trying to test the destroy method in my rails 3 controller, but I >> always get an "no route matches {}" error. But the route do exist, as I >> can >> see by running rake routes. > > What version of rspec and rspec-rails are you using? > >> I have something like this: >> delete :destroy, :id => "1" >> The stack trace: >> ?? ?Failure/Error: delete :destroy, :id => "1" >> ?? ?No route matches {} >> ?? ?# /Users/> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_dispatch/routing/route_set.rb:415:in >> `generate' >> ?? ?# /Users/> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/url_rewriter.rb:43:in >> `rewrite' >> ?? ?# /Users/> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/url_rewriter.rb:16:in >> `rewrite' >> ?? ?# /Users/> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/url_for.rb:145:in >> `url_for' >> ?? ?# /Users/> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/redirecting.rb:86:in >> `_compute_redirect_to_location' >> ?? ?# /Users/> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/redirecting.rb:58:in >> `redirect_to' >> ?? ?# /Users/> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/flash.rb:25:in >> `redirect_to' >> ?? ?# /Users/> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/instrumentation.rb:59:in >> `redirect_to' >> ?? ?# /Users/> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/notifications/instrumenter.rb:18:in >> `instrument' >> ?? ?# /Users/> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/notifications.rb:49:in >> `__send__' >> ?? ?# /Users/> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/notifications.rb:49:in >> `instrument' >> ?? ?# /Users/> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/instrumentation.rb:58:in >> `redirect_to' >> ?? ?# /Users/> user>/dev/easyclinica/app/controllers/convenios_controller.rb:55 >> ?? ?# /Users/> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/mime_responds.rb:189:in >> `call' >> ?? ?# /Users/> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/mime_responds.rb:189:in >> `respond_to' >> ?? ?# /Users/> user>/dev/easyclinica/app/controllers/convenios_controller.rb:53:in >> `destroy' >> ?? ?# /Users/> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/base.rb:44:in >> `send_action' >> ?? ?# /Users/> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/base.rb:44:in >> `send_action' >> ?? ?# /Users/> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/abstract_controller/base.rb:145:in >> `process_action' >> ?? ?# /Users/> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/abstract_controller/callbacks.rb:18:in >> `process_action' >> ?? ?# /Users/> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/callbacks.rb:438:in >> `_run__2086632925__process_action__988268021__callbacks' >> ?? ?# /Users/> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/callbacks.rb:403:in >> `send' >> ?? ?# /Users/> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/callbacks.rb:403:in >> `_run_process_action_callbacks' >> ?? ?# /Users/> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/callbacks.rb:88:in >> `send' >> ?? ?# /Users/> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/callbacks.rb:88:in >> `run_callbacks' >> ?? ?# /Users/> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/abstract_controller/callbacks.rb:17:in >> `process_action' >> ?? ?# /Users/> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/rendering.rb:12:in >> `process_action' >> ?? ?# /Users/> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/compatibility.rb:66:in >> `process_action' >> ?? ?# /Users/> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/instrumentation.rb:29:in >> `process_action' >> ?? ?# /Users/> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/notifications/instrumenter.rb:18:in >> `instrument' >> ?? ?# /Users/> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/notifications.rb:49:in >> `__send__' >> ?? ?# /Users/> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/notifications.rb:49:in >> `instrument' >> ?? ?# /Users/> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/instrumentation.rb:28:in >> `process_action' >> ?? ?# /Users/> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/rescue.rb:8:in >> `process_action' >> ?? ?# /Users/> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/abstract_controller/base.rb:115:in >> `process' >> ?? ?# /Users/> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal.rb:64:in >> `dispatch' >> ?? ?# /Users/> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/rack_delegation.rb:19:in >> `dispatch' >> ?? ?# /Users/> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal.rb:89:in >> `call' >> ?? ?# /Users/> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/rack-test-0.5.3/lib/rack/mock_session.rb:30:in >> `request' >> ?? ?# /Users/> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/rack-test-0.5.3/lib/rack/test.rb:207:in >> `process_request' >> ?? ?# /Users/> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/rack-test-0.5.3/lib/rack/test.rb:105:in >> `request' >> ?? ?# /Users/> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_dispatch/testing/integration.rb:272:in >> `process' >> ?? ?# /Users/> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_dispatch/testing/integration.rb:48:in >> `delete' >> ?? ?# /Users/> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_dispatch/testing/integration.rb:315:in >> `__send__' >> ?? ?# /Users/> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_dispatch/testing/integration.rb:315:in >> `delete' >> ?? ?# (eval):3:in `delete' >> ?? ?# ./spec/controllers/_spec.rb:49 >> Have you guys ever been through this problem? >> Thanks, >> Mauricio >> _______________________________________________ >> 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 garren.smith at gmail.com Thu Mar 25 09:44:41 2010 From: garren.smith at gmail.com (garren) Date: Thu, 25 Mar 2010 06:44:41 -0700 (PDT) Subject: [rspec-users] Mock Global method In-Reply-To: <4BAAE615.5060707@gmail.com> References: <4BAAE615.5060707@gmail.com> Message-ID: <9c5666ff-1f3c-441c-b5b8-f644c2a6ab65@b30g2000yqd.googlegroups.com> I'm actually looking to mock "my_helper_method" here. Or to be more general any method that is created outside of a class. On Mar 25, 6:27?am, "J. B. Rainsberger" wrote: > garren wrote: > > I'm very new to ruby and mocking a dynamic language. I would like to > > mock a helper method in Sinatra. So an example is this: > > > ? ? helper do > > ? ? ?def my_helper_method > > ? ? ? ?puts "Should do something useful here..." > > ? ? ?end > > ? ?end > > > How would I mock that method and how would I mock a method in general > > that is a global method. Is it better practice not to have global > > methods? Should I rather have an object inside the method call that > > does all the work and I can mock that? > > You can probably set an expectation on Kernel#puts, since although #puts > looks global, it belongs to Kernel. > > As for whether you should use #puts directly here, or indirectly through > another object that you can easily control, that depends on the > situation. Try both and compare the results. > > In your situation, I'd probably just set expectations on Kernel#puts > until that caused me problems, at which point I'd separate the behavior > of deciding what to print from deciding where to print it. I find > formatting messages much easier to check, in general, than displaying them. > > Have fun. > -- > J. B. Rainsberger ::http://www.jbrains.ca::http://www.thecodewhisperer.com > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Thu Mar 25 10:29:51 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 25 Mar 2010 09:29:51 -0500 Subject: [rspec-users] Mock Global method In-Reply-To: <9c5666ff-1f3c-441c-b5b8-f644c2a6ab65@b30g2000yqd.googlegroups.com> References: <4BAAE615.5060707@gmail.com> <9c5666ff-1f3c-441c-b5b8-f644c2a6ab65@b30g2000yqd.googlegroups.com> Message-ID: On Mar 25, 2010, at 8:44 AM, garren wrote: > I'm actually looking to mock "my_helper_method" here. Or to be more > general any method that is created outside of a class. When you create a method outside a class, it is available on every object: def foo "foo" end class Bar end describe Bar do it "responds to foo" do Bar.new.foo.should == "foo" end end In terms of mocking or stubbing that, just do it directly on the object. describe Widget do it "does something" do widget = Widget.new widget.stub(:some_method_i_defined_outside_a_class) { "this value" } # ... end end HTH, David PS, if you're mocking or stubbing a method, it doesn't need to actually exist. > On Mar 25, 6:27 am, "J. B. Rainsberger" > wrote: >> garren wrote: >>> I'm very new to ruby and mocking a dynamic language. I would like to >>> mock a helper method in Sinatra. So an example is this: >> >>> helper do >>> def my_helper_method >>> puts "Should do something useful here..." >>> end >>> end >> >>> How would I mock that method and how would I mock a method in general >>> that is a global method. Is it better practice not to have global >>> methods? Should I rather have an object inside the method call that >>> does all the work and I can mock that? >> >> You can probably set an expectation on Kernel#puts, since although #puts >> looks global, it belongs to Kernel. >> >> As for whether you should use #puts directly here, or indirectly through >> another object that you can easily control, that depends on the >> situation. Try both and compare the results. >> >> In your situation, I'd probably just set expectations on Kernel#puts >> until that caused me problems, at which point I'd separate the behavior >> of deciding what to print from deciding where to print it. I find >> formatting messages much easier to check, in general, than displaying them. >> >> Have fun. >> -- >> J. B. Rainsberger ::http://www.jbrains.ca::http://www.thecodewhisperer.com >> _______________________________________________ >> rspec-users mailing list >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From peter.fitzgibbons at gmail.com Thu Mar 25 11:04:31 2010 From: peter.fitzgibbons at gmail.com (Peter Fitzgibbons) Date: Thu, 25 Mar 2010 10:04:31 -0500 Subject: [rspec-users] Specing Ruby Game Development ??? In-Reply-To: <2929DB31-538B-484A-8028-6270C25C9709@patmaddox.com> References: <4BAA69AA.2010700@gmail.com> <2929DB31-538B-484A-8028-6270C25C9709@patmaddox.com> Message-ID: <670a00381003250804m290c7c5bj14f9d5cc67a92bd5@mail.gmail.com> Let the blogging begin : http://peter.fitzgibbons.info/2010/03/gosu-star-catcher-iteration-0/ Peter Fitzgibbons (847) 859-9550 Email: peter.fitzgibbons at gmail.com IM GTalk: peter.fitzgibbons IM AOL: peter.fitzgibbons at gmail.com On Wed, Mar 24, 2010 at 10:15 PM, Pat Maddox wrote: > Not I, but let me know if you come across anything please. Sounds > interesting. > > > On Mar 24, 2010, at 12:36 PM, Peter Fitzgibbons wrote: > > HI Folks, > > Roll Call for anyone using Rspec for Ruby Game Development (Rubygame, GOSU, > TkRuby, etc.) ??? > > I'm having trouble finding the latest-and-greatest with Google searches. > > Happy Gaming! > -- > Peter Fitzgibbons > (847) 859-9550 > peter.fitzgibbons at gmail.com > IM GTalk: peter.fitzgibbons > IM AOL: peter.fitzgibbons at gmail.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rodrigo.benenson at gmail.com Thu Mar 25 12:01:06 2010 From: rodrigo.benenson at gmail.com (rodrigo benenson) Date: Thu, 25 Mar 2010 17:01:06 +0100 Subject: [rspec-users] Trivial controller spec fail In-Reply-To: <57c63afe1003250408v16417ba0h5e7c7f54be975968@mail.gmail.com> References: <57c63afe1003250408v16417ba0h5e7c7f54be975968@mail.gmail.com> Message-ID: > If you're rendering another action in Rails, this should read: > ?render :action => "teaser_v1" I changed the teaser_controller.rb as mentioned. It makes no difference, I get the exact same error. Please notice that, as mentioned, the application does run correctly. I already tried it manually, the page does render as expected. Ruby on Rails is happy with the code. Thanks for the trial anyway. The problem seems to be strictly related to the rspec testing environment/method. Anyone got another idea ? Another test I could do to figure this out ? Regards, rodrigob. On Thu, Mar 25, 2010 at 12:08 PM, David Chelimsky wrote: > On Thu, Mar 25, 2010 at 5:11 AM, rodrigo benenson > wrote: >> Hello RSpec community ! > > Welcome, Rodrigo. > >> I'm a Ruby on Rails newby trying to get my first application running. >> I already got some of the website running and now I'm writting the >> tests to verify that everything works as expected and that it will >> stay like that in future versions. >> However I'm having a really hard time getting RSpec to run correctly. >> >> Following the mailing list policy I have created a gist with: >> >> system configuration.txt -> my gem list and spec version >> teaser_controller.rb -> the 12 lines dummy controller >> teaser_controller_spec.rb -> the 14 lines spec that fails >> output.txt -> the error I get when I run "rake spec:controllers", with >> its traceback >> >> http://gist.github.com/343339 >> >> My controller does >> ?def index >> ? ? ? ?render :teaser_v1 > > If you're rendering another action in Rails, this should read: > > ?render :action => "teaser_v1" > > Take a look at http://api.rubyonrails.org/classes/ActionController/Base.html#M000658 > for more info. > > HTH, > David > > >> ?end >> >> def teaser_v1 >> ?end >> >> My spec does >> ?it "renders :teaser_v1" do >> ? ? ?get :index >> ?end >> >> and then rake spec does >> ArgumentError in 'TeaserController GET index renders :teaser_v1' >> wrong number of arguments (2 for 1) >> /home/rodrigob/work/popster_work/popster_bzr/src/web/popster/app/controllers/teaser_controller.rb:6:in >> `index' >> /var/lib/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb:1331:in >> `send' >> >> The teaser_controller just renders a static html files, no templates, >> no partials, no nothing. Yet, the test fails. >> >> I have created a side test project where I ran >> ruby script/generate rspec_scaffold Stuff name:string category:name >> >> and compared the created files with mines. But I still cannot see why >> the test project specs pass, and mines do not. >> >> Your help is very welcome. >> Than you very much for creating such a nice specification tool. >> I hope I will be able to use and contribute to it in the future. >> >> Regards, >> rodrigob. >> _______________________________________________ >> 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 phillipkoebbe at gmail.com Thu Mar 25 14:42:44 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Thu, 25 Mar 2010 13:42:44 -0500 Subject: [rspec-users] view spec template.base_path Message-ID: <4BABAEA4.9030400@gmail.com> I have a helper method def partial_path_for(partial, options = {}) base_path = options[:base_path] || self.template.base_path "_partials/#{base_path}/#{partial}" end and use it in a template (haml) like = render :partial => partial_path_for(:details) I'd like to have a similar helper for view specs so I can do this describe 'web/admin/merchants/show.html.haml' do before(:each) do @merchant = stub_model(Merchant, :name => 'Some Merchant') assigns[:merchant] = @merchant end it 'should render the details partial' do partial_path = partial_path_for(:details, :base_path => self.template.base_path) template.should_receive(:render).with(:partial => partial_path) render end it_should_behave_like 'merchant details' end Unfortunately, if I debug right before the template.should_receive statement, self.template.base_path is nil. How can I get the path to the template? Thanks, Phillip From phillipkoebbe at gmail.com Thu Mar 25 14:50:47 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Thu, 25 Mar 2010 13:50:47 -0500 Subject: [rspec-users] view spec template.base_path In-Reply-To: <4BABAEA4.9030400@gmail.com> References: <4BABAEA4.9030400@gmail.com> Message-ID: <4BABB087.304@gmail.com> On 2010-03-25 1:42 PM, Phillip Koebbe wrote: > I have a helper method > > def partial_path_for(partial, options = {}) > base_path = options[:base_path] || self.template.base_path > "_partials/#{base_path}/#{partial}" > end > > and use it in a template (haml) like > > = render :partial => partial_path_for(:details) > > I'd like to have a similar helper for view specs so I can do this > > describe 'web/admin/merchants/show.html.haml' do > before(:each) do > @merchant = stub_model(Merchant, :name => 'Some Merchant') > assigns[:merchant] = @merchant > end > > it 'should render the details partial' do > partial_path = partial_path_for(:details, :base_path => > self.template.base_path) > template.should_receive(:render).with(:partial => partial_path) > render > end > > it_should_behave_like 'merchant details' > end > > Unfortunately, if I debug right before the template.should_receive > statement, self.template.base_path is nil. How can I get the path to > the template? > Right after I sent that message, I discovered I could set a variable before the initial describe statement and reuse it. This works: base_path = 'web/admin/merchants' describe "#{base_path}/show.html.haml" do ... partial_path = call_some_method(:details, base_path) ... end But I'd really rather have the value coming from somewhere else. This method depends on me creating a variable, which I don't like. Peace, Phillip > Thanks, > Phillip From david.spurr at gmail.com Fri Mar 26 07:16:56 2010 From: david.spurr at gmail.com (DEfusion) Date: Fri, 26 Mar 2010 04:16:56 -0700 (PDT) Subject: [rspec-users] RSpec 2.0.0.beta.4 stubbing rails controller method issue Message-ID: <594562f6-0101-44e0-aa82-064473c4a074@x12g2000yqx.googlegroups.com> I'm trying to stub a controller method using RSpec 2.0.0.beta.4 and Rails 3 and whenever I attempt to do it I get an error, e.g. controller.stub!(:current_host).and_return(Factory.build(:host)) post :create Results in: Failure/Error: post :create can't convert nil into String # (eval):3:in `post' Removing the stub doesn't cause the error and the post is fails as expected. In fact even trying to dump the controller before the post causes this error (as I wasn't sure if it was still controller or had been moved to an instance variable). From garren.smith at gmail.com Fri Mar 26 07:19:02 2010 From: garren.smith at gmail.com (garren) Date: Fri, 26 Mar 2010 04:19:02 -0700 (PDT) Subject: [rspec-users] Mock Global method In-Reply-To: References: <4BAAE615.5060707@gmail.com> <9c5666ff-1f3c-441c-b5b8-f644c2a6ab65@b30g2000yqd.googlegroups.com> Message-ID: Perfect thanks for that. On Mar 25, 4:29?pm, David Chelimsky wrote: > On Mar 25, 2010, at 8:44 AM, garren wrote: > > > I'm actually looking to mock "my_helper_method" here. Or to be more > > general any method that is created outside of a class. > > When you create a method outside a class, it is available on every object: > > def foo > ? "foo" > end > > class Bar > end > > describe Bar do > ? it "responds to foo" do > ? ? Bar.new.foo.should == "foo" > ? end > end > > In terms of mocking or stubbing that, just do it directly on the object. > > describe Widget do > ? it "does something" do > ? ? widget = Widget.new > ? ? widget.stub(:some_method_i_defined_outside_a_class) { "this value" } > ? ? # ... > ? end > end > > HTH, > David > > PS, if you're mocking or stubbing a method, it doesn't need to actually exist. > > > > > On Mar 25, 6:27 am, "J. B. Rainsberger" > > wrote: > >> garren wrote: > >>> I'm very new to ruby and mocking a dynamic language. I would like to > >>> mock a helper method in Sinatra. So an example is this: > > >>> ? ? helper do > >>> ? ? ?def my_helper_method > >>> ? ? ? ?puts "Should do something useful here..." > >>> ? ? ?end > >>> ? ?end > > >>> How would I mock that method and how would I mock a method in general > >>> that is a global method. Is it better practice not to have global > >>> methods? Should I rather have an object inside the method call that > >>> does all the work and I can mock that? > > >> You can probably set an expectation on Kernel#puts, since although #puts > >> looks global, it belongs to Kernel. > > >> As for whether you should use #puts directly here, or indirectly through > >> another object that you can easily control, that depends on the > >> situation. Try both and compare the results. > > >> In your situation, I'd probably just set expectations on Kernel#puts > >> until that caused me problems, at which point I'd separate the behavior > >> of deciding what to print from deciding where to print it. I find > >> formatting messages much easier to check, in general, than displaying them. > > >> Have fun. > >> -- > >> J. B. Rainsberger ::http://www.jbrains.ca::http://www.thecodewhisperer.com > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Fri Mar 26 07:21:26 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 26 Mar 2010 06:21:26 -0500 Subject: [rspec-users] RSpec 2.0.0.beta.4 stubbing rails controller method issue In-Reply-To: <594562f6-0101-44e0-aa82-064473c4a074@x12g2000yqx.googlegroups.com> References: <594562f6-0101-44e0-aa82-064473c4a074@x12g2000yqx.googlegroups.com> Message-ID: <880FFA24-B6B4-43D5-8B5D-3258786A5925@gmail.com> On Mar 26, 2010, at 6:16 AM, DEfusion wrote: > I'm trying to stub a controller method using RSpec 2.0.0.beta.4 and > Rails 3 and whenever I attempt to do it I get an error, e.g. > > controller.stub!(:current_host).and_return(Factory.build(:host)) > post :create > > Results in: > > Failure/Error: post :create > can't convert nil into String > # (eval):3:in `post' > > > Removing the stub doesn't cause the error and the post is fails as > expected. In fact even trying to dump the controller before the post > causes this error (as I wasn't sure if it was still controller or had > been moved to an instance variable). Controller specs are currently built on rails integration test behaviour. We're going to change that so it's built on rails functional test behaviour and that will solve your issue, but I'm not sure when that will happen. Definitely before final releases of both rspec-2 and rails-3, but there are lots of priorities being juggled in both projects. Please feel free to raise rspec-2 issues in the appropriate repo in github. In this case: http://github.com/rspec/rspec-rails/issues. Thanks! From rodrigo.benenson at gmail.com Fri Mar 26 18:42:32 2010 From: rodrigo.benenson at gmail.com (rodrigo benenson) Date: Fri, 26 Mar 2010 23:42:32 +0100 Subject: [rspec-users] Trivial controller spec fail In-Reply-To: References: <57c63afe1003250408v16417ba0h5e7c7f54be975968@mail.gmail.com> Message-ID: After hours searching the source of the problem I finally got it: RubyAmf http://code.google.com/p/rubyamf/issues/detail?id=85 this problem was already encountered in 2007 http://www.mail-archive.com/rspec-users at rubyforge.org/msg02556.html three years later I had the same problem (using the latest version of rubyamf and everything else). I'm discovering that ruby's "super flexibility" can generate some very nasty "across borders" effects. I hope this email will help future rspec + rubyamf users. Regards, rodrigob. On Thu, Mar 25, 2010 at 5:01 PM, rodrigo benenson wrote: >> If you're rendering another action in Rails, this should read: >> ?render :action => "teaser_v1" > > I changed the teaser_controller.rb as mentioned. It makes no > difference, I get the exact same error. > Please notice that, as mentioned, the application does run correctly. > I already tried it manually, ?the page does render as expected. Ruby > on Rails is happy with the code. > > Thanks for the trial anyway. > > The problem seems to be strictly related to the rspec testing > environment/method. > > Anyone got another idea ? Another test I could do to figure this out ? > > Regards, > rodrigob. > > On Thu, Mar 25, 2010 at 12:08 PM, David Chelimsky wrote: >> On Thu, Mar 25, 2010 at 5:11 AM, rodrigo benenson >> wrote: >>> Hello RSpec community ! >> >> Welcome, Rodrigo. >> >>> I'm a Ruby on Rails newby trying to get my first application running. >>> I already got some of the website running and now I'm writting the >>> tests to verify that everything works as expected and that it will >>> stay like that in future versions. >>> However I'm having a really hard time getting RSpec to run correctly. >>> >>> Following the mailing list policy I have created a gist with: >>> >>> system configuration.txt -> my gem list and spec version >>> teaser_controller.rb -> the 12 lines dummy controller >>> teaser_controller_spec.rb -> the 14 lines spec that fails >>> output.txt -> the error I get when I run "rake spec:controllers", with >>> its traceback >>> >>> http://gist.github.com/343339 >>> >>> My controller does >>> ?def index >>> ? ? ? ?render :teaser_v1 >> >> If you're rendering another action in Rails, this should read: >> >> ?render :action => "teaser_v1" >> >> Take a look at http://api.rubyonrails.org/classes/ActionController/Base.html#M000658 >> for more info. >> >> HTH, >> David >> >> >>> ?end >>> >>> def teaser_v1 >>> ?end >>> >>> My spec does >>> ?it "renders :teaser_v1" do >>> ? ? ?get :index >>> ?end >>> >>> and then rake spec does >>> ArgumentError in 'TeaserController GET index renders :teaser_v1' >>> wrong number of arguments (2 for 1) >>> /home/rodrigob/work/popster_work/popster_bzr/src/web/popster/app/controllers/teaser_controller.rb:6:in >>> `index' >>> /var/lib/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb:1331:in >>> `send' >>> >>> The teaser_controller just renders a static html files, no templates, >>> no partials, no nothing. Yet, the test fails. >>> >>> I have created a side test project where I ran >>> ruby script/generate rspec_scaffold Stuff name:string category:name >>> >>> and compared the created files with mines. But I still cannot see why >>> the test project specs pass, and mines do not. >>> >>> Your help is very welcome. >>> Than you very much for creating such a nice specification tool. >>> I hope I will be able to use and contribute to it in the future. >>> >>> Regards, >>> rodrigob. >>> _______________________________________________ >>> 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 phillipkoebbe at gmail.com Fri Mar 26 18:52:57 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Fri, 26 Mar 2010 15:52:57 -0700 (PDT) Subject: [rspec-users] view spec template.base_path In-Reply-To: <4BABB087.304@gmail.com> References: <4BABAEA4.9030400@gmail.com> <4BABB087.304@gmail.com> Message-ID: <75cefed8-1449-4a29-9d58-0bd019195094@j21g2000yqh.googlegroups.com> On Mar 25, 1:50?pm, Phillip Koebbe wrote: > Right after I sent that message, I discovered I could set a variable > before the initial describe statement and reuse it. This works: > > base_path = 'web/admin/merchants' > describe "#{base_path}/show.html.haml" do > ? ? ?... > ? ? ?partial_path = call_some_method(:details, base_path) > ? ? ?... > end > > But I'd really rather have the value coming from somewhere else. This > method depends on me creating a variable, which I don't like. On Mar 25, 1:50 pm, Phillip Koebbe wrote: > Right after I sent that message, I discovered I could set a variable > before the initial describe statement and reuse it. This works: > > base_path = 'web/admin/merchants' > describe "#{base_path}/show.html.haml" do > ... > partial_path = call_some_method(:details, base_path) > ... > end > > But I'd really rather have the value coming from somewhere else. This > method depends on me creating a variable, which I don't like. I've been looking over the available methods and I discovered that I can get the base path via File.dirname(self.description) That got me thinking about various things, and I eventually wound up adding before {ensure_that_base_view_path_is_set_correctly} def ensure_that_base_view_path_is_set_correctly @controller.template.base_path = File.dirname(self.class.description) end to lib/spec/rails/example/view_example_group.rb This accomplishes what I want, but I seriously doubt it is the right thing to do, so I created a ticket: https://rspec.lighthouseapp.com/projects/5645-rspec/tickets/973-templatebase_path-returns-nil-in-view-spec Phillip From mauricioaniche at gmail.com Mon Mar 29 12:20:54 2010 From: mauricioaniche at gmail.com (Mauricio Aniche) Date: Mon, 29 Mar 2010 13:20:54 -0300 Subject: [rspec-users] Problems testing destroy method in rspec2 In-Reply-To: <313e92a61003250615l25f4823y8c39e2ad60be4654@mail.gmail.com> References: <313e92a61003242039o162cb9c6l85b3d14dd98764e1@mail.gmail.com> <57c63afe1003250419t5ab699eew75e6695c9c6cfb92@mail.gmail.com> <313e92a61003250615l25f4823y8c39e2ad60be4654@mail.gmail.com> Message-ID: <313e92a61003290920m179fbd31na9dc0da3b201f494@mail.gmail.com> Hi, Is there anyone else who had this problem? Thanks, Mauricio On Thu, Mar 25, 2010 at 10:15 AM, Mauricio Aniche wrote: > Hi David, > > I am using rspec2 beta4, which is the latest version in gemcutter. > > Hi Julian, > > The problem only happens in my spec. My rails3 applications works fine > (I use a post with a hidden _method set as delete, but I guess this is > a browser problem!) > > Regards, > Mauricio > > On 3/25/10, David Chelimsky wrote: > > On Wed, Mar 24, 2010 at 10:39 PM, Mauricio Aniche > > wrote: > >> Hi, > >> I am trying to test the destroy method in my rails 3 controller, but I > >> always get an "no route matches {}" error. But the route do exist, as I > >> can > >> see by running rake routes. > > > > What version of rspec and rspec-rails are you using? > > > >> I have something like this: > >> delete :destroy, :id => "1" > >> The stack trace: > >> Failure/Error: delete :destroy, :id => "1" > >> No route matches {} > >> # /Users/ >> > user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_dispatch/routing/route_set.rb:415:in > >> `generate' > >> # /Users/ >> > user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/url_rewriter.rb:43:in > >> `rewrite' > >> # /Users/ >> > user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/url_rewriter.rb:16:in > >> `rewrite' > >> # /Users/ >> > user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/url_for.rb:145:in > >> `url_for' > >> # /Users/ >> > user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/redirecting.rb:86:in > >> `_compute_redirect_to_location' > >> # /Users/ >> > user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/redirecting.rb:58:in > >> `redirect_to' > >> # /Users/ >> > user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/flash.rb:25:in > >> `redirect_to' > >> # /Users/ >> > user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/instrumentation.rb:59:in > >> `redirect_to' > >> # /Users/ >> > user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/notifications/instrumenter.rb:18:in > >> `instrument' > >> # /Users/ >> > user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/notifications.rb:49:in > >> `__send__' > >> # /Users/ >> > user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/notifications.rb:49:in > >> `instrument' > >> # /Users/ >> > user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/instrumentation.rb:58:in > >> `redirect_to' > >> # /Users/ >> user>/dev/easyclinica/app/controllers/convenios_controller.rb:55 > >> # /Users/ >> > user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/mime_responds.rb:189:in > >> `call' > >> # /Users/ >> > user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/mime_responds.rb:189:in > >> `respond_to' > >> # /Users/ >> user>/dev/easyclinica/app/controllers/convenios_controller.rb:53:in > >> `destroy' > >> # /Users/ >> > user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/base.rb:44:in > >> `send_action' > >> # /Users/ >> > user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/base.rb:44:in > >> `send_action' > >> # /Users/ >> > user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/abstract_controller/base.rb:145:in > >> `process_action' > >> # /Users/ >> > user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/abstract_controller/callbacks.rb:18:in > >> `process_action' > >> # /Users/ >> > user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/callbacks.rb:438:in > >> `_run__2086632925__process_action__988268021__callbacks' > >> # /Users/ >> > user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/callbacks.rb:403:in > >> `send' > >> # /Users/ >> > user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/callbacks.rb:403:in > >> `_run_process_action_callbacks' > >> # /Users/ >> > user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/callbacks.rb:88:in > >> `send' > >> # /Users/ >> > user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/callbacks.rb:88:in > >> `run_callbacks' > >> # /Users/ >> > user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/abstract_controller/callbacks.rb:17:in > >> `process_action' > >> # /Users/ >> > user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/rendering.rb:12:in > >> `process_action' > >> # /Users/ >> > user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/compatibility.rb:66:in > >> `process_action' > >> # /Users/ >> > user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/instrumentation.rb:29:in > >> `process_action' > >> # /Users/ >> > user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/notifications/instrumenter.rb:18:in > >> `instrument' > >> # /Users/ >> > user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/notifications.rb:49:in > >> `__send__' > >> # /Users/ >> > user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/notifications.rb:49:in > >> `instrument' > >> # /Users/ >> > user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/instrumentation.rb:28:in > >> `process_action' > >> # /Users/ >> > user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/rescue.rb:8:in > >> `process_action' > >> # /Users/ >> > user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/abstract_controller/base.rb:115:in > >> `process' > >> # /Users/ >> > user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal.rb:64:in > >> `dispatch' > >> # /Users/ >> > user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/rack_delegation.rb:19:in > >> `dispatch' > >> # /Users/ >> > user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal.rb:89:in > >> `call' > >> # /Users/ >> > user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/rack-test-0.5.3/lib/rack/mock_session.rb:30:in > >> `request' > >> # /Users/ >> > user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/rack-test-0.5.3/lib/rack/test.rb:207:in > >> `process_request' > >> # /Users/ >> > user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/rack-test-0.5.3/lib/rack/test.rb:105:in > >> `request' > >> # /Users/ >> > user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_dispatch/testing/integration.rb:272:in > >> `process' > >> # /Users/ >> > user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_dispatch/testing/integration.rb:48:in > >> `delete' > >> # /Users/ >> > user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_dispatch/testing/integration.rb:315:in > >> `__send__' > >> # /Users/ >> > user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_dispatch/testing/integration.rb:315:in > >> `delete' > >> # (eval):3:in `delete' > >> # ./spec/controllers/_spec.rb:49 > >> Have you guys ever been through this problem? > >> Thanks, > >> Mauricio > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-users at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/rspec-users > >> > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ashley.moran at patchspace.co.uk Mon Mar 29 15:48:57 2010 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Mon, 29 Mar 2010 20:48:57 +0100 Subject: [rspec-users] Spork Message-ID: <5118849E-323E-4352-8F2C-6BEAD91DF86F@patchspace.co.uk> Hi Hopefully I'll get chance to finish Spork integration with RSpec 2 this weekend. I've got two questions... (1) What's the best way to merge my changes back in? My shockingly bad Git-fu has made it impossible to rebase on top of master. I suspect having a (now disabled) Textmate macro to clean EOL whitespace has not helped. I've restructured some code - I plan to do a proper refactoring when it all joins up (ie when I see Rails 3 working) but I'd rather get Spork merged as soon as it's runnable in case I make life even harder for myself. I know know that the Spork interface expects you to provide an argv and out/error streams when you call its DRb interface. It then calls the "CLI" interface to RSpec. This is one reason RSpec 2 integration is harder than I thought, because that RSpec API has been rewritten (and is much better now I've seen both). So... (2) Is there a stable API call we can settle on for this going forward? I was thinking along the lines of `Rspec.run(argv, err, out)` or `Rspec.run_command(argv, err, out)` or something. Any ideas? (2.5) Any reason why the new RSpec module is "Rspec" not "RSpec"? Cheers Ashley -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashleymoran From dchelimsky at gmail.com Mon Mar 29 16:04:47 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 29 Mar 2010 15:04:47 -0500 Subject: [rspec-users] Spork In-Reply-To: <5118849E-323E-4352-8F2C-6BEAD91DF86F@patchspace.co.uk> References: <5118849E-323E-4352-8F2C-6BEAD91DF86F@patchspace.co.uk> Message-ID: On Mar 29, 2010, at 2:48 PM, Ashley Moran wrote: > Hi > > Hopefully I'll get chance to finish Spork integration with RSpec 2 this weekend. I've got two questions... > > (1) What's the best way to merge my changes back in? My shockingly bad Git-fu has made it impossible to rebase on top of master. I suspect having a (now disabled) Textmate macro to clean EOL whitespace has not helped. I've restructured some code - I plan to do a proper refactoring when it all joins up (ie when I see Rails 3 working) but I'd rather get Spork merged as soon as it's runnable in case I make life even harder for myself. How wide-reaching are your changes? i.e. how many files, etc? > I know know that the Spork interface expects you to provide an argv and out/error streams when you call its DRb interface. It then calls the "CLI" interface to RSpec. This is one reason RSpec 2 integration is harder than I thought, because that RSpec API has been rewritten (and is much better now I've seen both). So... > > (2) Is there a stable API call we can settle on for this going forward? I was thinking along the lines of `Rspec.run(argv, err, out)` or `Rspec.run_command(argv, err, out)` or something. Any ideas? This is an interesting catch 22. The dependency appears to be from Spork to RSpec (i.e. RSpec doesn't know about Spork), but RSpec needs to commit to an API so support Spork, which is very likely the only tool that needs this API. I wonder if we got the dep backwards? i.e. why not have Spork expose and API and have RSpec hook into it? > > (2.5) Any reason why the new RSpec module is "Rspec" not "RSpec"? AFAIK, autoloaders (like in Rails and Autotest), assume a CamelCase convention for class names, which RSpec violates, and Rspec adheres to. If I'm wrong about this, I'd prefer to make it RSpec, since that's the name of the book and all :) Anybody have insights/opinions on this? > Cheers > Ashley > > -- > http://www.patchspace.co.uk/ > http://www.linkedin.com/in/ashleymoran > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From o at kojilab.com Mon Mar 29 17:41:08 2010 From: o at kojilab.com (kojilab) Date: Mon, 29 Mar 2010 14:41:08 -0700 (PDT) Subject: [rspec-users] undefined method Message-ID: <28075551.post@talk.nabble.com> Hi My test has the following line Account.stub(:find_by_slug_and_owner_id).with("my-account", '1').and_return(mock_account) In my model, I have def self.find_by_slug_and_owner_id(slug, owner_id) [code] end But I am getting NoMethodError in 'AccountsController GET add person to account GET add user page verifies the account is live' undefined method `find_by_slug_and_owner_id' for # It looks like the Account class isn't used. All my other calls to Account.stub are working fine. I just added the slug column and ran rake db:test:prepare and load. What am I doing wrong? Thanks -- View this message in context: http://old.nabble.com/undefined-method-tp28075551p28075551.html Sent from the rspec-users mailing list archive at Nabble.com. From cwdinfo at gmail.com Mon Mar 29 22:50:27 2010 From: cwdinfo at gmail.com (steve ross) Date: Mon, 29 Mar 2010 19:50:27 -0700 Subject: [rspec-users] Spork In-Reply-To: References: <5118849E-323E-4352-8F2C-6BEAD91DF86F@patchspace.co.uk> Message-ID: <7787DE0F-7595-4519-99CC-1870044A3249@gmail.com> On Mar 29, 2010, at 1:04 PM, David Chelimsky wrote: > On Mar 29, 2010, at 2:48 PM, Ashley Moran wrote: > >> (2.5) Any reason why the new RSpec module is "Rspec" not "RSpec"? > > AFAIK, autoloaders (like in Rails and Autotest), assume a CamelCase convention for class names, which RSpec violates, and Rspec adheres to. If I'm wrong about this, I'd prefer to make it RSpec, since that's the name of the book and all :) Anybody have insights/opinions on this? > Isn't CamelCase ([A-Z][a-zA-Z]*)+ If that's the case, RSpec is fine. If not, then classes like CGI are also hosed. My $.02 From jimmy.soho at gmail.com Mon Mar 29 23:36:55 2010 From: jimmy.soho at gmail.com (Jimmy Soho) Date: Tue, 30 Mar 2010 14:36:55 +1100 Subject: [rspec-users] describe blocks without before(:all) / after(:all) Message-ID: <5bb161c81003292036v138dbd55r84d5282f2d153a00@mail.gmail.com> Hi All, We have many specs like the pattern given below. The problem is that it's slow, because each inner context block will execute the before(:all) in the outer describe block. Is there a way to setup an inner context block that does not execute the before(:all) and after(:all), but does execute the before(:each) and after(:each) ? Based on some playing around (removing inner context blocks) we think this would speed up our tests by a factor of 10. Cheers, Jimmy ----- describe Project do before(:all) do # statements that set up an object graph, relatively slow end after(:all) do # tear down object graph end it { should ... } it { should ... } it { should ... } it { should ... } context "target calculations" do before(:each) do # non-expensive statements, just setting up for example the subject, Time.zone, locale, etc. end it { should ... } it { should ... } it { should ... } end context "duration calculations" do before(:each) do # non-expensive statements end it { should ... } it { should ... } it { should ... } end context ... context ... [ etc. ] end -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Tue Mar 30 00:23:39 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 29 Mar 2010 23:23:39 -0500 Subject: [rspec-users] describe blocks without before(:all) / after(:all) In-Reply-To: <5bb161c81003292036v138dbd55r84d5282f2d153a00@mail.gmail.com> References: <5bb161c81003292036v138dbd55r84d5282f2d153a00@mail.gmail.com> Message-ID: On Mar 29, 2010, at 10:36 PM, Jimmy Soho wrote: > Hi All, > > We have many specs like the pattern given below. > > The problem is that it's slow, because each inner context block will execute the before(:all) in the outer describe block. > > Is there a way to setup an inner context block that does not execute the before(:all) and after(:all), but does execute the before(:each) and after(:each) ? Not in rspec-1, but that's how rspec-2 works by default. I don't want to change this in rspec-1 because I don't plan to release any more major 1.x releases, and this would risk being a compatibility-breaking change. HTH, David > Based on some playing around (removing inner context blocks) we think this would speed up our tests by a factor of 10. > > > Cheers, > Jimmy > > ----- > > describe Project do > before(:all) do > # statements that set up an object graph, relatively slow > end > > after(:all) do > # tear down object graph > end > > it { should ... } > it { should ... } > it { should ... } > it { should ... } > > context "target calculations" do > before(:each) do > # non-expensive statements, just setting up for example the subject, Time.zone, locale, etc. > end > > it { should ... } > it { should ... } > it { should ... } > end > > context "duration calculations" do > before(:each) do > # non-expensive statements > end > > it { should ... } > it { should ... } > it { should ... } > end > > context ... > context ... > [ etc. ] > > end > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From ramon.tayag at gmail.com Tue Mar 30 06:17:24 2010 From: ramon.tayag at gmail.com (Ramon Tayag) Date: Tue, 30 Mar 2010 18:17:24 +0800 Subject: [rspec-users] Gem tutorials / setting up rspec in a gem Message-ID: Hey everyone! A few days ago, I tried my hand at creating a gem. I've been putting it off for a long time because of the lack of documentation (or the lack of my Googling skills). When I search how to create gems with RSpec, I get pages that talk about gem templates with the rspec option, as if that would solve it all. If there are no tutorials, maybe I could ask for your help in setting it up for a gem: Backgrounder I'm asking because it's a bit frustrating doing things by trial and error. A lot of the problems I've come across were that the files that rspec-rails loads for me aren't automatically available in the gem, so I have to manually include it. It became a problem when I had to test an ActiveRecord model, and worse when I had to test a controller. Currently, I'm stuck at the point where "get", "put", "post", "delete" aren't available in the spec. I asked about it in StackOverflow and got the answer, but it doesn't explain what I have to do to basically replicate those methods. What did I do? As part of my trial and error process, I started including what rspec-rails includes http://github.com/dchelimsky/rspec-rails/blob/master/lib/spec/rails.rb, and the REST actions don't seem to trigger an undefined error anymore, but now there's another "uninitialized constant Rails". So.. before I go further, maybe I'm approaching this wrong since I'm having such a difficult time. What's the best way to go about this? Is there a way to maybe include Rails and everything it has, for testing purposes? I know that you're supposed to make gems framework agnostic but for brevity's sake (and for my own sanity) I'm willing to make it very plugin-like for now. I've been reading and researching for 3 days you see :) Thanks, and I apologize for the novel! Ramon Tayag -------------- next part -------------- An HTML attachment was scrubbed... URL: From aslak.hellesoy at gmail.com Tue Mar 30 07:09:21 2010 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 30 Mar 2010 13:09:21 +0200 Subject: [rspec-users] Gem tutorials / setting up rspec in a gem In-Reply-To: References: Message-ID: <8d961d901003300409t46d31a7ch8ac2f37ca5bad99a@mail.gmail.com> On Tue, Mar 30, 2010 at 12:17 PM, Ramon Tayag wrote: > Hey everyone! > > A few days ago, I tried my hand at creating a gem. I've been putting it off > for a long time because of the lack of documentation (or the lack of my > Googling skills). When I search how to create gems with RSpec, I get pages > that talk about gem templates with the rspec option, as if that would solve > it all. > > Have you tried jeweler? Try this: gem install jeweler jeweler --help jeweler --rspec --summary "My awesome gem, which solves problems" --description "The awesome gem" awesome cd awesome rake -T rake spec # write a real spec rake version:write rake install See the Jeweler docs for more: http://wiki.github.com/technicalpickles/jeweler/ If there are no tutorials, maybe I could ask for your help in setting it up > for a gem: > > Backgrounder > I'm asking because it's a bit frustrating doing things by trial and error. > A lot of the problems I've come across were that the files that rspec-rails > loads for me aren't automatically available in the gem, so I have to > manually include it. It became a problem when I had to test an ActiveRecord > model, and worse when I had to test a controller. Currently, I'm stuck at > the point where "get", "put", "post", "delete" aren't available in the spec. > I asked about it in StackOverflow and got the answer, > but it doesn't explain what I have to do to basically replicate those > methods. > > What did I do? > As part of my trial and error process, I started including what rspec-rails > includes > http://github.com/dchelimsky/rspec-rails/blob/master/lib/spec/rails.rb, > and the REST actions don't seem to trigger an undefined error anymore, but > now there's another "uninitialized constant Rails". So.. before I go > further, maybe I'm approaching this wrong since I'm having such a difficult > time. > > What's the best way to go about this? Is there a way to maybe include Rails > and everything it has, for testing purposes? I know that you're supposed to > make gems framework agnostic but for brevity's sake (and for my own sanity) > I'm willing to make it very plugin-like for now. I've been reading and > researching for 3 days you see :) > > I'm not sure what your gem does, but if it has dependencies on Rails, the easiest way to develop it (in my experience) is to have a separate Rails app that _uses_ your gem, and that is not part of the gem's source code. Then that Rails app could have specs (and maybe Cucumber features) that rely on the correct implementation of your gem. Maybe you could say a little more about what your gem does? Aslak > Thanks, and I apologize for the novel! > Ramon Tayag > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ramon.tayag at gmail.com Tue Mar 30 11:22:39 2010 From: ramon.tayag at gmail.com (Ramon Tayag) Date: Tue, 30 Mar 2010 23:22:39 +0800 Subject: [rspec-users] Gem tutorials / setting up rspec in a gem In-Reply-To: <8d961d901003300409t46d31a7ch8ac2f37ca5bad99a@mail.gmail.com> References: <8d961d901003300409t46d31a7ch8ac2f37ca5bad99a@mail.gmail.com> Message-ID: Thanks for your reply aslak. Since then I've tried another approach - having a sample Rails application in the spec folder, much like shoulda. Still haven't gotten it to work, but I'll try anyway. If I have a separate Rails app (which sounds MUCH easier to do - thank you), won't it be slow doing TDD because I'd have to publish my gem, update it in the Rails app, run tests, then back to the gem source code to make changes? I wasn't too ambitious with my first gem. It allows subscriptions. The name "acts_as_subscribable" should be descriptive enough :) Ramon Tayag On Tue, Mar 30, 2010 at 7:09 PM, aslak hellesoy wrote: > > > On Tue, Mar 30, 2010 at 12:17 PM, Ramon Tayag wrote: > >> Hey everyone! >> >> A few days ago, I tried my hand at creating a gem. I've been putting it >> off for a long time because of the lack of documentation (or the lack of my >> Googling skills). When I search how to create gems with RSpec, I get pages >> that talk about gem templates with the rspec option, as if that would solve >> it all. >> >> > Have you tried jeweler? Try this: > > gem install jeweler > jeweler --help > jeweler --rspec --summary "My awesome gem, which solves problems" > --description "The awesome gem" awesome > cd awesome > rake -T > rake spec # write a real spec > rake version:write > rake install > > See the Jeweler docs for more: > http://wiki.github.com/technicalpickles/jeweler/ > > If there are no tutorials, maybe I could ask for your help in setting it up >> for a gem: >> >> Backgrounder >> I'm asking because it's a bit frustrating doing things by trial and error. >> A lot of the problems I've come across were that the files that rspec-rails >> loads for me aren't automatically available in the gem, so I have to >> manually include it. It became a problem when I had to test an ActiveRecord >> model, and worse when I had to test a controller. Currently, I'm stuck at >> the point where "get", "put", "post", "delete" aren't available in the spec. >> I asked about it in StackOverflow and got the answer, >> but it doesn't explain what I have to do to basically replicate those >> methods. >> >> What did I do? >> As part of my trial and error process, I started including what >> rspec-rails includes >> http://github.com/dchelimsky/rspec-rails/blob/master/lib/spec/rails.rb, >> and the REST actions don't seem to trigger an undefined error anymore, but >> now there's another "uninitialized constant Rails". So.. before I go >> further, maybe I'm approaching this wrong since I'm having such a difficult >> time. >> >> What's the best way to go about this? Is there a way to maybe include >> Rails and everything it has, for testing purposes? I know that you're >> supposed to make gems framework agnostic but for brevity's sake (and for my >> own sanity) I'm willing to make it very plugin-like for now. I've been >> reading and researching for 3 days you see :) >> >> > I'm not sure what your gem does, but if it has dependencies on Rails, the > easiest way to develop it (in my experience) is to have a separate Rails app > that _uses_ your gem, and that is not part of the gem's source code. Then > that Rails app could have specs (and maybe Cucumber features) that rely on > the correct implementation of your gem. > > Maybe you could say a little more about what your gem does? > > Aslak > > >> Thanks, and I apologize for the novel! >> Ramon Tayag >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ramon.tayag at gmail.com Tue Mar 30 11:26:39 2010 From: ramon.tayag at gmail.com (Ramon Tayag) Date: Tue, 30 Mar 2010 23:26:39 +0800 Subject: [rspec-users] Gem tutorials / setting up rspec in a gem In-Reply-To: <8d961d901003300409t46d31a7ch8ac2f37ca5bad99a@mail.gmail.com> References: <8d961d901003300409t46d31a7ch8ac2f37ca5bad99a@mail.gmail.com> Message-ID: Oh and yes, I'm using jeweler. :) Ramon Tayag On Tue, Mar 30, 2010 at 7:09 PM, aslak hellesoy wrote: > > > On Tue, Mar 30, 2010 at 12:17 PM, Ramon Tayag wrote: > >> Hey everyone! >> >> A few days ago, I tried my hand at creating a gem. I've been putting it >> off for a long time because of the lack of documentation (or the lack of my >> Googling skills). When I search how to create gems with RSpec, I get pages >> that talk about gem templates with the rspec option, as if that would solve >> it all. >> >> > Have you tried jeweler? Try this: > > gem install jeweler > jeweler --help > jeweler --rspec --summary "My awesome gem, which solves problems" > --description "The awesome gem" awesome > cd awesome > rake -T > rake spec # write a real spec > rake version:write > rake install > > See the Jeweler docs for more: > http://wiki.github.com/technicalpickles/jeweler/ > > If there are no tutorials, maybe I could ask for your help in setting it up >> for a gem: >> >> Backgrounder >> I'm asking because it's a bit frustrating doing things by trial and error. >> A lot of the problems I've come across were that the files that rspec-rails >> loads for me aren't automatically available in the gem, so I have to >> manually include it. It became a problem when I had to test an ActiveRecord >> model, and worse when I had to test a controller. Currently, I'm stuck at >> the point where "get", "put", "post", "delete" aren't available in the spec. >> I asked about it in StackOverflow and got the answer, >> but it doesn't explain what I have to do to basically replicate those >> methods. >> >> What did I do? >> As part of my trial and error process, I started including what >> rspec-rails includes >> http://github.com/dchelimsky/rspec-rails/blob/master/lib/spec/rails.rb, >> and the REST actions don't seem to trigger an undefined error anymore, but >> now there's another "uninitialized constant Rails". So.. before I go >> further, maybe I'm approaching this wrong since I'm having such a difficult >> time. >> >> What's the best way to go about this? Is there a way to maybe include >> Rails and everything it has, for testing purposes? I know that you're >> supposed to make gems framework agnostic but for brevity's sake (and for my >> own sanity) I'm willing to make it very plugin-like for now. I've been >> reading and researching for 3 days you see :) >> >> > I'm not sure what your gem does, but if it has dependencies on Rails, the > easiest way to develop it (in my experience) is to have a separate Rails app > that _uses_ your gem, and that is not part of the gem's source code. Then > that Rails app could have specs (and maybe Cucumber features) that rely on > the correct implementation of your gem. > > Maybe you could say a little more about what your gem does? > > Aslak > > >> Thanks, and I apologize for the novel! >> Ramon Tayag >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Tue Mar 30 11:51:05 2010 From: lists at ruby-forum.com (Matthew O'riordan) Date: Tue, 30 Mar 2010 17:51:05 +0200 Subject: [rspec-users] autotest - garbled output Message-ID: I recently reinstalled my gems for autotest, and since then I have unintelligible output coming from autotest like this (note everything after unit_diff -u) loading autotest/rails /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -I.:lib:test -rubygems -e "%w[test/unit test/unit/test.rb].each { |f| require f }" | unit_diff -u 76111971001011003211511710511610132451011083116971141161011001046107010511010511510410110032105110324846485255565332115101991111101001154610104932116101115116115443249329711511510111411610511111011544324832102971051081171141011154432483210111411411111411510 Strangely I have run my tests individually and they work fine. I have then tried running autotest in another Rails application and it works fine. I have uninstalled and reinstalled all gems related to autotest, and same problem. I then deleted my ~/.autotest file so it's vanilla and that makes no difference. Finally, I installed autotest-growl to see what output is coming through to that, and that works fine and I get the results of my passed / failed tests, but the console for autotest continues to just pump out a string of numbers instead of a description of the tests it is running. I am using ruby 1.8.7 The following gems are installed: autotest (4.2.9) autotest-growl (0.2.3) autotest-rails (4.1.0) I have tried enabling and disabling redgreen, but to no avail. Please can someone help me, I am absolutely stumped. Matt -- Posted via http://www.ruby-forum.com/. From george.jquery at SoftwareUnity.com Tue Mar 30 10:23:59 2010 From: george.jquery at SoftwareUnity.com (George) Date: Tue, 30 Mar 2010 07:23:59 -0700 (PDT) Subject: [rspec-users] Best way to match several attributes of an object? Message-ID: <65bd6a51-b455-40c2-ab8a-20a8399523be@33g2000yqj.googlegroups.com> When you need to check several properties of an object, what is the best way to match them all? I'm using the 'satisfy' matcher at the moment but perhaps there's a better way than this: flight.should satisfy { |f| f.booking_code == @parsed_pnr_data[:pnr_number] && f.depart_airport.code == @parsed_pnr_data[:flights][0] [:depart_airport_code] && f.arrive_airport.code == @parsed_pnr_data[:flights][0] [:arrive_airport_code] && f.depart_terminal == @parsed_pnr_data[:flights][0] [:depart_terminal] && f.arrive_terminal == @parsed_pnr_data[:flights][0] [:arrive_terminal] && f.start_date == @parsed_pnr_data[:flights][0] [:depart_date] && f.end_date == @parsed_pnr_data[:flights][0] [:arrive_date] } Many thanks From dchelimsky at gmail.com Tue Mar 30 12:43:48 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 30 Mar 2010 11:43:48 -0500 Subject: [rspec-users] Best way to match several attributes of an object? In-Reply-To: <65bd6a51-b455-40c2-ab8a-20a8399523be@33g2000yqj.googlegroups.com> References: <65bd6a51-b455-40c2-ab8a-20a8399523be@33g2000yqj.googlegroups.com> Message-ID: On Mar 30, 2010, at 9:23 AM, George wrote: > When you need to check several properties of an object, what is the > best way to match them all? > > I'm using the 'satisfy' matcher at the moment but perhaps there's a > better way than this: > flight.should satisfy { |f| > f.booking_code == @parsed_pnr_data[:pnr_number] && > f.depart_airport.code == @parsed_pnr_data[:flights][0] > [:depart_airport_code] && > f.arrive_airport.code == @parsed_pnr_data[:flights][0] > [:arrive_airport_code] && > f.depart_terminal == @parsed_pnr_data[:flights][0] > [:depart_terminal] && > f.arrive_terminal == @parsed_pnr_data[:flights][0] > [:arrive_terminal] && > f.start_date == @parsed_pnr_data[:flights][0] > [:depart_date] && > f.end_date == @parsed_pnr_data[:flights][0] > [:arrive_date] > } I don't know if this is workable in your case or not, but I like to design objects so you can compare them. Something like: flight.should == Flight.new :booking_code => @parsed_pnr_data[:pnr_number], ..... HTH, David From edgargonzalez at gmail.com Tue Mar 30 13:21:12 2010 From: edgargonzalez at gmail.com (Edgar Gonzalez) Date: Tue, 30 Mar 2010 12:51:12 -0430 Subject: [rspec-users] autotest - garbled output In-Reply-To: References: Message-ID: Hi Matt, I have the same misbehavior after update the gems,the autotest's output is garbled and if I hit Ctrl-C once (to run the specs again) I got this error: usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/runner/formatter/progress_bar_formatter.rb:16:in `write': Broken pipe (Errno::EPIPE) from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/runner/formatter/progress_bar_formatter.rb:16:in `print' from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/runner/formatter/progress_bar_formatter.rb:16:in `example_passed' from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/runner/reporter.rb:136:in `example_passed' from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/runner/reporter.rb:136:in `each' from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/runner/reporter.rb:136:in `example_passed' from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/runner/reporter.rb:31:in `example_finished' from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/example/example_methods.rb:55:in `execute' from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/example/example_group_methods.rb:214:in `run_examples' from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/example/example_group_methods.rb:212:in `each' from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/example/example_group_methods.rb:212:in `run_examples' from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/example/example_group_methods.rb:103:in `run' from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:23:in `run' from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:22:in `each' from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:22:in `run' from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/runner/options.rb:152:in `run_examples' from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/runner/command_line.rb:9:in `run' from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/bin/spec:5 ruby 1.8.6 (2007-09-24 patchlevel 111) [i486-linux] rspec: 1.3.0 rspec-rails: 1.3.2 ZenTest: 4.3.0 autotest-rails: 4.1.0 On Tue, Mar 30, 2010 at 11:21 AM, Matthew O'riordan wrote: > I recently reinstalled my gems for autotest, and since then I have > unintelligible output coming from autotest like this (note everything > after unit_diff -u) > > loading autotest/rails > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby > -I.:lib:test -rubygems -e "%w[test/unit test/unit/test.rb].each { |f| > require f }" | unit_diff -u > > 76111971001011003211511710511610132451011083116971141161011001046107010511010511510410110032105110324846485255565332115101991111101001154610104932116101115116115443249329711511510111411610511111011544324832102971051081171141011154432483210111411411111411510 > > Strangely I have run my tests individually and they work fine. > I have then tried running autotest in another Rails application and it > works fine. > I have uninstalled and reinstalled all gems related to autotest, and > same problem. > I then deleted my ~/.autotest file so it's vanilla and that makes no > difference. > Finally, I installed autotest-growl to see what output is coming through > to that, and that works fine and I get the results of my passed / failed > tests, but the console for autotest continues to just pump out a string > of numbers instead of a description of the tests it is running. > > I am using ruby 1.8.7 > > The following gems are installed: > autotest (4.2.9) > autotest-growl (0.2.3) > autotest-rails (4.1.0) > > I have tried enabling and disabling redgreen, but to no avail. > > Please can someone help me, I am absolutely stumped. > > Matt > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Edgar Gonz?lez Gonz?lez E-mail: edgargonzalez at gmail.com http://twitter.com/edgar http://www.hasmanydevelopers.com http://edgar.gonzalez.net.ve -- -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Tue Mar 30 13:34:46 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 30 Mar 2010 12:34:46 -0500 Subject: [rspec-users] autotest - garbled output In-Reply-To: References: Message-ID: <62C2A7F0-DB1B-469E-8D63-97C39E2D061E@gmail.com> Please see (and comment on) the bug report for autotest-rails that Matt raised: http://rubyforge.org/tracker/index.php?func=detail&aid=28034&group_id=419&atid=1678 On Mar 30, 2010, at 12:21 PM, Edgar Gonzalez wrote: > Hi Matt, > > I have the same misbehavior after update the gems,the autotest's output is garbled and if I hit Ctrl-C once (to run the specs again) I got this error: > > usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/runner/formatter/progress_bar_formatter.rb:16:in `write': Broken pipe (Errno::EPIPE) > from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/runner/formatter/progress_bar_formatter.rb:16:in `print' > from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/runner/formatter/progress_bar_formatter.rb:16:in `example_passed' > from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/runner/reporter.rb:136:in `example_passed' > from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/runner/reporter.rb:136:in `each' > from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/runner/reporter.rb:136:in `example_passed' > from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/runner/reporter.rb:31:in `example_finished' > from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/example/example_methods.rb:55:in `execute' > from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/example/example_group_methods.rb:214:in `run_examples' > from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/example/example_group_methods.rb:212:in `each' > from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/example/example_group_methods.rb:212:in `run_examples' > from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/example/example_group_methods.rb:103:in `run' > from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:23:in `run' > from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:22:in `each' > from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:22:in `run' > from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/runner/options.rb:152:in `run_examples' > from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/runner/command_line.rb:9:in `run' > from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/bin/spec:5 > > ruby 1.8.6 (2007-09-24 patchlevel 111) [i486-linux] > rspec: 1.3.0 > rspec-rails: 1.3.2 > ZenTest: 4.3.0 > autotest-rails: 4.1.0 > > > > On Tue, Mar 30, 2010 at 11:21 AM, Matthew O'riordan wrote: > I recently reinstalled my gems for autotest, and since then I have > unintelligible output coming from autotest like this (note everything > after unit_diff -u) > > loading autotest/rails > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby > -I.:lib:test -rubygems -e "%w[test/unit test/unit/test.rb].each { |f| > require f }" | unit_diff -u > 76111971001011003211511710511610132451011083116971141161011001046107010511010511510410110032105110324846485255565332115101991111101001154610104932116101115116115443249329711511510111411610511111011544324832102971051081171141011154432483210111411411111411510 > > Strangely I have run my tests individually and they work fine. > I have then tried running autotest in another Rails application and it > works fine. > I have uninstalled and reinstalled all gems related to autotest, and > same problem. > I then deleted my ~/.autotest file so it's vanilla and that makes no > difference. > Finally, I installed autotest-growl to see what output is coming through > to that, and that works fine and I get the results of my passed / failed > tests, but the console for autotest continues to just pump out a string > of numbers instead of a description of the tests it is running. > > I am using ruby 1.8.7 > > The following gems are installed: > autotest (4.2.9) > autotest-growl (0.2.3) > autotest-rails (4.1.0) > > I have tried enabling and disabling redgreen, but to no avail. > > Please can someone help me, I am absolutely stumped. > > Matt > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > > > -- > Edgar Gonz?lez Gonz?lez > E-mail: edgargonzalez at gmail.com > http://twitter.com/edgar > http://www.hasmanydevelopers.com > http://edgar.gonzalez.net.ve > -- > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Tue Mar 30 13:44:57 2010 From: lists at ruby-forum.com (Matthew O'riordan) Date: Tue, 30 Mar 2010 19:44:57 +0200 Subject: [rspec-users] autotest - garbled output In-Reply-To: References: Message-ID: <9675e5ba51bcc592cf3b9a4b0be055b2@ruby-forum.com> Hi Edgar I think the error you are saying is a direct result of you hitting Ctl-C in that you are killing the process and thus the output. Could be wrong, but I suspect that's the issue. I get different error messages every time I hit Ctl-C depending on where in the test execution autotest is at, so they seem to be transient issues. I think something to do with the update to the gem has caused the output to be formatted strangely, but for the life of me I have no idea what that is. Matt -- Posted via http://www.ruby-forum.com/. From ed.howland at gmail.com Tue Mar 30 16:53:01 2010 From: ed.howland at gmail.com (Ed Howland) Date: Tue, 30 Mar 2010 16:53:01 -0400 Subject: [rspec-users] Gem tutorials / setting up rspec in a gem In-Reply-To: References: <8d961d901003300409t46d31a7ch8ac2f37ca5bad99a@mail.gmail.com> Message-ID: Hi Ramon, Just a thought or 2. I'd still test/spec your gem outside of any Rails app, and I wouldn't use a sample Rails app in the spec folder. It sounds to me that you are writing a 'acts_as_xxxxx' type extension to ActiveRecord. You should only need the AR gem installed as a development dep for the gem. You'd need: gem.add_development_dependency "factory_girl", ">= 0" gem.add_development_dependency "rspec", ">= 0" gem.add_dependency 'activerecord', ">= 2.3" in your Rakefile. Note the use of FactoryGirl. This should help you fake stuff out for testing. No need for the full Rails stack, when all you need is to create some models. In my case, I created a models folder in my gem and put my usual model files in there. Then I require all of them in a Dir[].each block in my soec_helper.rb. With FactoryGirl, you don't even need to require them first, but in your case you probably need to to get the 'acts_as_xxxx' functionality. HTH Cheers, Ed Ed Howland http://greenprogrammer.wordpress.com http://twitter.com/ed_howland On Tue, Mar 30, 2010 at 11:22 AM, Ramon Tayag wrote: > Thanks for your reply aslak. Since then I've tried another approach - having > a sample Rails application in the spec folder, much like shoulda. Still > haven't gotten it to work, but I'll try anyway. > If I have a separate Rails app (which sounds MUCH easier to do - thank you), > won't it be slow doing TDD because I'd have to publish my gem, update it in > the Rails app, run tests, then back to the gem source code to make changes? > I wasn't too ambitious with my first gem. It allows subscriptions. The name > "acts_as_subscribable" should be descriptive enough :) > > Ramon Tayag > > On Tue, Mar 30, 2010 at 7:09 PM, aslak hellesoy > wrote: >> >> >> On Tue, Mar 30, 2010 at 12:17 PM, Ramon Tayag >> wrote: >>> >>> Hey everyone! >>> >>> A few days ago, I tried my hand at creating a gem. I've been putting it >>> off for a long time because of the lack of documentation (or the lack of my >>> Googling skills). When I search how to create gems with RSpec, I get pages >>> that talk about gem templates with the rspec option, as if that would solve >>> it all. >> >> Have you tried jeweler? Try this: >> >> gem install jeweler >> jeweler --help >> jeweler --rspec --summary "My awesome gem, which solves problems" >> --description "The awesome gem" awesome >> cd awesome >> rake -T >> rake spec # write a real spec >> rake version:write >> rake install >> >> See the Jeweler docs for more: >> http://wiki.github.com/technicalpickles/jeweler/ >> >>> If there are no tutorials, maybe I could ask for your help in setting it >>> up for a gem: >>> >>> Backgrounder >>> I'm asking because it's a bit frustrating doing things by trial and >>> error. A lot of the problems I've come across were that the files that >>> rspec-rails loads for me aren't automatically available in the gem, so I >>> have to manually include it. It became a problem when I had to test an >>> ActiveRecord model, and worse when I had to test a controller. Currently, >>> I'm stuck at the point where "get", "put", "post", "delete" aren't available >>> in the spec. I asked about it in StackOverflow and got the answer, but it >>> doesn't explain what I have to do to basically replicate those methods. >>> What did I do? >>> As part of my trial and error process, I started including what >>> rspec-rails >>> includes?http://github.com/dchelimsky/rspec-rails/blob/master/lib/spec/rails.rb, >>> and the REST actions don't seem to trigger an undefined error anymore, but >>> now there's another "uninitialized constant Rails". So.. before I go >>> further, maybe I'm approaching this wrong since I'm having such a difficult >>> time. >>> What's the best way to go about this? Is there a way to maybe include >>> Rails and everything it has, for testing purposes? I know that you're >>> supposed to make gems framework agnostic but for brevity's sake (and for my >>> own sanity) I'm willing to make it very plugin-like for now. I've been >>> reading and researching for 3 days you see :) >> >> I'm not sure what your gem does, but if it has dependencies on Rails, the >> easiest way to develop it (in my experience) is to have a separate Rails app >> that _uses_ your gem, and that is not part of the gem's source code. Then >> that Rails app could have specs (and maybe Cucumber features) that rely on >> the correct implementation of your gem. >> >> Maybe you could say a little more about what your gem does? >> >> Aslak >> >>> >>> Thanks, and I apologize for the novel! >>> Ramon Tayag >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Tue Mar 30 16:53:33 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 30 Mar 2010 15:53:33 -0500 Subject: [rspec-users] autotest - garbled output In-Reply-To: <9675e5ba51bcc592cf3b9a4b0be055b2@ruby-forum.com> References: <9675e5ba51bcc592cf3b9a4b0be055b2@ruby-forum.com> Message-ID: <57c63afe1003301353y2541c373kdba213489e6a4bf3@mail.gmail.com> FYI - I uninstalled ZenTest-4.3.0 and installed ZenTest-4.2.1 and all is well: [sudo] gem uninstall ZenTest [sudo] gem install ZenTest --version 4.2.1 HTH, David On Tue, Mar 30, 2010 at 12:44 PM, Matthew O'riordan wrote: > Hi Edgar > > I think the error you are saying is a direct result of you hitting Ctl-C > in that you are killing the process and thus the output. ?Could be > wrong, but I suspect that's the issue. ?I get different error messages > every time I hit Ctl-C depending on where in the test execution autotest > is at, so they seem to be transient issues. > > I think something to do with the update to the gem has caused the output > to be formatted strangely, but for the life of me I have no idea what > that is. > > Matt > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From george.jquery at SoftwareUnity.com Tue Mar 30 17:28:08 2010 From: george.jquery at SoftwareUnity.com (George) Date: Tue, 30 Mar 2010 14:28:08 -0700 (PDT) Subject: [rspec-users] Best way to match several attributes of an object? In-Reply-To: References: <65bd6a51-b455-40c2-ab8a-20a8399523be@33g2000yqj.googlegroups.com> Message-ID: <540ff3b4-62ec-4d4c-8100-d5e41597b010@j21g2000yqh.googlegroups.com> Yep, that's a fair point and may improve readability if I set up the compare object in a before method. Good idea, thanks David. George On Mar 30, 5:43?pm, David Chelimsky wrote: > On Mar 30, 2010, at 9:23 AM, George wrote: > > > > > When you need to check several properties of an object, what is the > > best way to match them all? > > > I'm using the 'satisfy' matcher at the moment but perhaps there's a > > better way than this: > > ? ? ?flight.should satisfy { |f| > > ? ? ? ?f.booking_code ? ? ? ? ? ?== @parsed_pnr_data[:pnr_number] && > > ? ? ? ?f.depart_airport.code ? ? == @parsed_pnr_data[:flights][0] > > [:depart_airport_code] && > > ? ? ? ?f.arrive_airport.code ? ? == @parsed_pnr_data[:flights][0] > > [:arrive_airport_code] && > > ? ? ? ?f.depart_terminal ? ? ? ? == @parsed_pnr_data[:flights][0] > > [:depart_terminal] && > > ? ? ? ?f.arrive_terminal ? ? ? ? == @parsed_pnr_data[:flights][0] > > [:arrive_terminal] && > > ? ? ? ?f.start_date ? ? ? ? ? ? ?== @parsed_pnr_data[:flights][0] > > [:depart_date] && > > ? ? ? ?f.end_date ? ? ? ? ? ? ? ?== @parsed_pnr_data[:flights][0] > > [:arrive_date] > > ? ? ?} > > I don't know if this is workable in your case or not, but I like to design objects so you can compare them. Something like: > > flight.should == Flight.new :booking_code => @parsed_pnr_data[:pnr_number], ..... > > HTH, > David > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From ramon.tayag at gmail.com Tue Mar 30 22:19:04 2010 From: ramon.tayag at gmail.com (Ramon Tayag) Date: Wed, 31 Mar 2010 10:19:04 +0800 Subject: [rspec-users] Gem tutorials / setting up rspec in a gem In-Reply-To: References: <8d961d901003300409t46d31a7ch8ac2f37ca5bad99a@mail.gmail.com> Message-ID: Thanks Ed I'll give this a shot too. I was able to get the activerecord part working though. My problem was testing the controller that I wanted to generate for the rails app. Things that I'm used to being in the controller spec (get, put, etc) aren't, because this RSpec installation is outside of rails. If I could do this without putting a whole app I'd gladly do so as it sounds cleaner. Those methods come from action_controller/test_unit or active_support/test_unit. I tried including both but it didn't work, and it's still fuzzy to me. Now, if I waste too much time figuring this out, I may just do what aslak suggested: put those tests in a rails app and write tests for the app that is using this gem. In my mind it sounds slow, as aslak probably has an automatic method to do this, but it definitely sounds easier than learning what needs to be included/required. On Wednesday, March 31, 2010, Ed Howland wrote: > Hi Ramon, > > Just a thought or 2. > > I'd still test/spec your gem outside of any Rails app, and I wouldn't > use a sample Rails app in the spec folder. > > It sounds to me that you are writing a 'acts_as_xxxxx' type extension > to ActiveRecord. You should only need the AR gem installed as a > development dep for the gem. > > You'd need: > ? ?gem.add_development_dependency "factory_girl", ">= 0" > ? ?gem.add_development_dependency "rspec", ">= 0" > ? ?gem.add_dependency 'activerecord', ">= 2.3" > > in your Rakefile. Note the use of FactoryGirl. This should help you > fake stuff out for testing. No need for the full Rails stack, when all > you need is to create > some models. > > In my case, I created a models folder in my gem and put my usual model > files in there. Then I require all of them in a Dir[].each block in my > soec_helper.rb. > With FactoryGirl, you don't even need to require them first, but in > your case you probably need to to get the 'acts_as_xxxx' > functionality. > > HTH > > > Cheers, > Ed > > Ed Howland > http://greenprogrammer.wordpress.com > http://twitter.com/ed_howland -- Ramon Tayag - what you think, we ink http://theinksquad.com From ashley.moran at patchspace.co.uk Wed Mar 31 05:10:22 2010 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Wed, 31 Mar 2010 10:10:22 +0100 Subject: [rspec-users] Spork In-Reply-To: References: <5118849E-323E-4352-8F2C-6BEAD91DF86F@patchspace.co.uk> Message-ID: <3FDE6268-4A61-4E7B-A2B9-A10D9CC4BDB9@patchspace.co.uk> On Mar 29, 2010, at 9:04 pm, David Chelimsky wrote: > How wide-reaching are your changes? i.e. how many files, etc? I think it's only really the Runner stuff that's changed. I've split it into InProcess and DRbProxy or some such... although I think really the DRb stuff belongs higher up. > This is an interesting catch 22. The dependency appears to be from Spork to RSpec (i.e. RSpec doesn't know about Spork), but RSpec needs to commit to an API so support Spork, which is very likely the only tool that needs this API. > > I wonder if we got the dep backwards? i.e. why not have Spork expose and API and have RSpec hook into it? Yep catch 22 indeed! It's a circular dependency. The way it works is Spork defines a DRb interface that takes arguments and the output streams. RSpec and Cucumber are both using this the same way. Seems like a stable interface so this dependency isn't a problem. Prob is that then Spork needs to know what to do to use RSpec. Currently that involves (and Cucumber does the same) just passing the ARGV along. Which felt weird to write - because at the point you want to pass the ARGV along you've already parsed it to find out if it's a --drb run*. But in theory you could pass anything as the args as long as the `Rspec.my_stable_api` call accepts it. One thought I had was that maybe the join should be separate... ie have independent gems rspec-core and spork, and spork-rspec, spork-cucumber, spork-testunit etc that depend on both. The prob with this is that while Spork is open to extension to new test frameworks, it doesn't provide an easy way to register them before Spork loads**. Seems to come down to *is* Spork the only thing that would need this API? Would you maybe want to run specs directly in eg Redcar? If not then I think you've talked me round that the dep is backwards. But Spork would need refactoring for RSpec to be able provide its own Spork adapter. Any thoughts based on that? > If I'm wrong about this, I'd prefer to make it RSpec, since that's the name of the book and all :) Anybody have insights/opinions on this? That's why I asked now, incase RSpec 3 changes it again and the circular dep bites once more ;) Cheers Ash * I'm not sure it's an easy one to solve because you have to figure out when to read in spec.opts. ** Sorta like how gem subcommands (eg gemedit) work. I'd love to know how that mojo does its stuff :) -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashleymoran From dchelimsky at gmail.com Wed Mar 31 08:33:14 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 31 Mar 2010 06:33:14 -0600 Subject: [rspec-users] autotest - garbled output In-Reply-To: <57c63afe1003301353y2541c373kdba213489e6a4bf3@mail.gmail.com> References: <9675e5ba51bcc592cf3b9a4b0be055b2@ruby-forum.com> <57c63afe1003301353y2541c373kdba213489e6a4bf3@mail.gmail.com> Message-ID: More FYI: Ryan released ZenTest 4.3.1 yesterday to address this issue, so you can upgrade to the latest and greatest. On Tue, Mar 30, 2010 at 2:53 PM, David Chelimsky wrote: > FYI - I uninstalled ZenTest-4.3.0 and installed ZenTest-4.2.1 and all is well: > > [sudo] gem uninstall ZenTest > [sudo] gem install ZenTest --version 4.2.1 > > HTH, > David > > On Tue, Mar 30, 2010 at 12:44 PM, Matthew O'riordan > wrote: >> Hi Edgar >> >> I think the error you are saying is a direct result of you hitting Ctl-C >> in that you are killing the process and thus the output. ?Could be >> wrong, but I suspect that's the issue. ?I get different error messages >> every time I hit Ctl-C depending on where in the test execution autotest >> is at, so they seem to be transient issues. >> >> I think something to do with the update to the gem has caused the output >> to be formatted strangely, but for the life of me I have no idea what >> that is. >> >> Matt >> -- >> Posted via http://www.ruby-forum.com/. >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > From mailinglists at patmaddox.com Wed Mar 31 11:27:09 2010 From: mailinglists at patmaddox.com (Pat Maddox) Date: Wed, 31 Mar 2010 08:27:09 -0700 Subject: [rspec-users] Best way to match several attributes of an object? In-Reply-To: <65bd6a51-b455-40c2-ab8a-20a8399523be@33g2000yqj.googlegroups.com> References: <65bd6a51-b455-40c2-ab8a-20a8399523be@33g2000yqj.googlegroups.com> Message-ID: On Mar 30, 2010, at 7:23 AM, George wrote: > When you need to check several properties of an object, what is the > best way to match them all? > > I'm using the 'satisfy' matcher at the moment but perhaps there's a > better way than this: > flight.should satisfy { |f| > f.booking_code == @parsed_pnr_data[:pnr_number] && > f.depart_airport.code == @parsed_pnr_data[:flights][0] > [:depart_airport_code] && > f.arrive_airport.code == @parsed_pnr_data[:flights][0] > [:arrive_airport_code] && > f.depart_terminal == @parsed_pnr_data[:flights][0] > [:depart_terminal] && > f.arrive_terminal == @parsed_pnr_data[:flights][0] > [:arrive_terminal] && > f.start_date == @parsed_pnr_data[:flights][0] > [:depart_date] && > f.end_date == @parsed_pnr_data[:flights][0] > [:arrive_date] > } > > Many thanks > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users I use a Comparable object whenever possible, as David said. Other than that, I just do one expectation per line. That way when one fails, I know exactly where the failure is. Pat From ben at benmabey.com Wed Mar 31 12:47:48 2010 From: ben at benmabey.com (Ben Mabey) Date: Wed, 31 Mar 2010 10:47:48 -0600 Subject: [rspec-users] Spork In-Reply-To: <3FDE6268-4A61-4E7B-A2B9-A10D9CC4BDB9@patchspace.co.uk> References: <5118849E-323E-4352-8F2C-6BEAD91DF86F@patchspace.co.uk> <3FDE6268-4A61-4E7B-A2B9-A10D9CC4BDB9@patchspace.co.uk> Message-ID: <4BB37CB4.2080105@benmabey.com> Ashley Moran wrote: > On Mar 29, 2010, at 9:04 pm, David Chelimsky wrote: > > >> How wide-reaching are your changes? i.e. how many files, etc? >> > > I think it's only really the Runner stuff that's changed. I've split it into InProcess and DRbProxy or some such... although I think really the DRb stuff belongs higher up. > > > >> This is an interesting catch 22. The dependency appears to be from Spork to RSpec (i.e. RSpec doesn't know about Spork), but RSpec needs to commit to an API so support Spork, which is very likely the only tool that needs this API. >> >> I wonder if we got the dep backwards? i.e. why not have Spork expose and API and have RSpec hook into it? >> > > Yep catch 22 indeed! It's a circular dependency. The way it works is Spork defines a DRb interface that takes arguments and the output streams. RSpec and Cucumber are both using this the same way. Seems like a stable interface so this dependency isn't a problem. > > Prob is that then Spork needs to know what to do to use RSpec. Currently that involves (and Cucumber does the same) just passing the ARGV along. Which felt weird to write - because at the point you want to pass the ARGV along you've already parsed it to find out if it's a --drb run*. But in theory you could pass anything as the args as long as the `Rspec.my_stable_api` call accepts it. > > One thought I had was that maybe the join should be separate... ie have independent gems rspec-core and spork, and spork-rspec, spork-cucumber, spork-testunit etc that depend on both. The prob with this is that while Spork is open to extension to new test frameworks, it doesn't provide an easy way to register them before Spork loads**. > > Seems to come down to *is* Spork the only thing that would need this API? Would you maybe want to run specs directly in eg Redcar? If not then I think you've talked me round that the dep is backwards. But Spork would need refactoring for RSpec to be able provide its own Spork adapter. > > Any thoughts based on that? > When we added Spork support for Cucumber we made it a point to say that we were not adding Spork support exclusively but rather a general purpose DRb client for Cucumber. The idea was that someone could create a DRb based solution, other than Spork, and have it just work with the current Cucumber --drb flag. For example, one could imagine setting up a DRb server that would run testjour to speed up large cucumber runs. This same thinking could be applied to RSpec as well. RSpec provides a DRb client that has simple API which people can write various libraries for and only have to worry about STDIN, STDOUT, and args. Maybe we are fooling ourselves to think that other people may be writing these in addition to spork though. David raises an interesting question about if we got the dependency backwards. I've been thinking a little about this and I'm not sure if we did or not. If you look at the Cucumber support for Spork we used the same interface that RSpec had, but in the end we had to do some special handling of Cucumber-specific needs (the StepMother) to make it work. You would only need to have this special handling if you were doing something similar to Spork, and that handling can not be done on the client side. Given that custom code has to be written to have the two play nicely the question is where does this code belong. I think where it is currently, in Spork, is the correct place. Since that is really the responsibility of Spork (serving up forked test runs that is) I think it makes sense from a maintenance point of view to have Spork responsible for that. I'm still thinking it over though so if someone has a concrete idea of how to switch the dependency and what advantages it would bring I'm all ears. :) -Ben > > >> If I'm wrong about this, I'd prefer to make it RSpec, since that's the name of the book and all :) Anybody have insights/opinions on this? >> > > That's why I asked now, incase RSpec 3 changes it again and the circular dep bites once more ;) > > Cheers > Ash > > > * I'm not sure it's an easy one to solve because you have to figure out when to read in spec.opts. > > ** Sorta like how gem subcommands (eg gemedit) work. I'd love to know how that mojo does its stuff :) > > > From bcardarella at gmail.com Wed Mar 31 16:54:47 2010 From: bcardarella at gmail.com (Brian Cardarella) Date: Wed, 31 Mar 2010 13:54:47 -0700 (PDT) Subject: [rspec-users] subject in the before block? Message-ID: <64174ba2-546f-48db-a930-267714d8428f@20g2000vbr.googlegroups.com> Is there a reason why I cannot access the subject in the before block? It seems to me that anything that I have access to in the it blocks should also be accessible in the before block. From dchelimsky at gmail.com Wed Mar 31 17:33:57 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 31 Mar 2010 16:33:57 -0500 Subject: [rspec-users] subject in the before block? In-Reply-To: <64174ba2-546f-48db-a930-267714d8428f@20g2000vbr.googlegroups.com> References: <64174ba2-546f-48db-a930-267714d8428f@20g2000vbr.googlegroups.com> Message-ID: <6F651928-BCA0-43F8-97A1-5C1003877A4D@gmail.com> On Mar 31, 2010, at 3:54 PM, Brian Cardarella wrote: > Is there a reason why I cannot access the subject in the before block? > It seems to me that anything that I have access to in the it blocks > should also be accessible in the before block. No reason. You using rspec 1 or 2? Also, before(:each) or before(:all)? From lists at ruby-forum.com Wed Mar 31 18:13:42 2010 From: lists at ruby-forum.com (Oren Golan) Date: Thu, 1 Apr 2010 00:13:42 +0200 Subject: [rspec-users] help me refactor a step for finding href in specific link Message-ID: <8a243488009b2a91d246316a695420a3@ruby-forum.com> I want to verify the href is correct:

Website

my step in the cucumber file: And the "website" class should have "www.happyhour.com" the step definition: Then /^the "([^\"]*)" class should have "([^\"]*)"$/ do |link, url| response.should have_selector(".#{link}") do |site| site.inner_html.include?(url).should be_true end end it's doesn't look good and would like to hear suggestion for improving it. Thanks! -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Wed Mar 31 19:09:53 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 31 Mar 2010 18:09:53 -0500 Subject: [rspec-users] help me refactor a step for finding href in specific link In-Reply-To: <8a243488009b2a91d246316a695420a3@ruby-forum.com> References: <8a243488009b2a91d246316a695420a3@ruby-forum.com> Message-ID: On Mar 31, 2010, at 5:13 PM, Oren Golan wrote: > I want to verify the href is correct: >

> Website >

> > my step in the cucumber file: > And the "website" class should have "www.happyhour.com" > > the step definition: > Then /^the "([^\"]*)" class should have "([^\"]*)"$/ do |link, url| > response.should have_selector(".#{link}") do |site| > site.inner_html.include?(url).should be_true > end > end > > it's doesn't look good and would like to hear suggestion for improving > it. > Thanks! Cucumber has its own list: http://groups.google.com/group/cukes, so you may get more responses there. I'd do something like this (incomplete and untested, but ....): And "Website" should link to "www.happyhour.com" Then /^"([^\"]*)" should link to "([^\"]*)"$/ do |text, href| response.should have_xpath(
) end From bcardarella at gmail.com Wed Mar 31 23:51:14 2010 From: bcardarella at gmail.com (Brian Cardarella) Date: Wed, 31 Mar 2010 20:51:14 -0700 (PDT) Subject: [rspec-users] subject in the before block? In-Reply-To: <6F651928-BCA0-43F8-97A1-5C1003877A4D@gmail.com> References: <64174ba2-546f-48db-a930-267714d8428f@20g2000vbr.googlegroups.com> <6F651928-BCA0-43F8-97A1-5C1003877A4D@gmail.com> Message-ID: RSpec 1 and before :each On Mar 31, 5:33?pm, David Chelimsky wrote: > On Mar 31, 2010, at 3:54 PM, Brian Cardarella wrote: > > > Is there a reason why I cannot access the subject in the before block? > > It seems to me that anything that I have access to in the it blocks > > should also be accessible in the before block. > > No reason. You using rspec 1 or 2? Also, before(:each) or before(:all)? > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users