Re: [rspec-users] Stubbing calls to the command line

2008-08-14 Thread Andy Croll
Scott Taylor wrote: > Use Kernel.stub!(:`, "wget..."), and use Kernel.send(:`, "wget") > instead of literal backticks. Interestingly this doesn't quite work, but I used the principle. The Kernel module is mixed into Object so when you use `shellcommand... ` you can intercept the call on the obje

[rspec-users] Stubbing calls to the command line

2008-08-14 Thread Andy Croll
I'm using a call to wget to download a large datafile (multiple megabytes) having assumed this will be quicker than using open-uri. How can I spec the behaviour? Ideally I'd also like to not be hitting the internet every time I test! in my_object_spec.rb describe ".get_data" do before(:eac

Re: [rspec-users] Spec the Application Controller application.rb

2008-04-23 Thread Andy Croll
This bit however, replaces your other routes, so you cannot use them in your tests > before(:each) do > ActionController::Routing::Routes.draw do |map| > map.resources :foo > end > end Is there a sensible way to append to the routes.rb that I'm missing? Andy -- Posted via htt

Re: [rspec-users] Spec the Application Controller application.rb

2008-04-23 Thread Andy Croll
Pat Maddox wrote: > You can still use the technique that I showed, you would just call > before_filter in the fake controller. That would allow you to specify > and implement the filter in isolation. Aha! Success, although I needed to add in a little Route fixing to make it work. application_s

Re: [rspec-users] Spec the Application Controller application.rb

2008-04-22 Thread Andy Croll
Pat Maddox wrote: > You can define a controller method on the fly in order to test this > out. I just did a quick experiment to demonstrate it...obviously > modify to suit your needs. Thanks Pat. I think I'm confusing two issues. 1) How to test before filters for something like authentication 2

[rspec-users] Spec the Application Controller application.rb

2008-04-21 Thread Andy Croll
How would I go about writing specs for methods in the Application Controller: I'm thinking of simple methods that do authentication, through before filters or for example how might I spec this method in an application_spec.rb? def store_location session[:return_to] = request.request_uri e

Re: [rspec-users] redirect_to

2008-04-18 Thread Andy Croll
Jarkko Laine wrote: > I would perhaps use > >> it "should redirect to the previous page" do >>response.should redirect_to "/prev/page" >> end Yeah, I'd pulled it back to see what *really* simple mistake I was making. :-) I reintroduced it in my next 'write test -> fail -> write code -> p

Re: [rspec-users] redirect_to

2008-04-18 Thread Andy Croll
Pat Maddox wrote: > do_delete :) I do so love mistakes in public, don't you? -- Posted via http://www.ruby-forum.com/. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users

[rspec-users] redirect_to

2008-04-18 Thread Andy Croll
OK I'm back and surely missing stuff again... In my controller tests I'm checking for a redirect after a destroy action. First up it's a single resource ("map.resource :cart" in routes.rb) in CartsController.rb def destroy @cart = Cart.find(session[:cart], :include => :items) if session[:

Re: [rspec-users] Testing Layout

2008-04-16 Thread Andy Croll
> Perhaps you should try giving the full path to load, eg. load > (RAILS_ROOT + "/app/controllers/my_controller.rb"). That seemed to do it... was perhaps a typo originally. My bad. Thanks. -- Posted via http://www.ruby-forum.com/. ___ rspec-users mail

Re: [rspec-users] Testing Layout

2008-04-16 Thread Andy Croll
Bart Zonneveld wrote: > On 16-apr-2008, at 13:57, Andy Croll wrote: >> Is there a way to specify which layout an action should use in a >> controller? > > Off the top of my head, not tested: > > describe MyController do >it "should use the foo layout&quo

[rspec-users] Testing Layout

2008-04-16 Thread Andy Croll
Is there a way to specify which layout an action should use in a controller? Andy -- Posted via http://www.ruby-forum.com/. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users

Re: [rspec-users] Testing with has_many associations

2008-04-09 Thread Andy Croll
Chris Parsons wrote: > it "should increment quantity when it does find a product" do >@cart.should_receive(:find_items_by_name).with("name").and > return(@product) >@cart.add_product(@product) >@cart.items.should have(1).item > end My final solution for this was to write... describe

Re: [rspec-users] Testing with has_many associations

2008-04-09 Thread Andy Croll
Chris Parsons wrote: > I'm guessing this spec will fail with your current code as I don't > think CartItem::new_from_product is working. Wow. I've never had code I hadn't posted correctly debugged before. You were absolutely right, thanks! Seems my testing approach in that spec was somehow fakin

[rspec-users] Testing with has_many associations

2008-04-08 Thread Andy Croll
Hi I'm trying to be good and practice full BDD on my current project, and don't want to abandon it as I have previously (expediency triumphed unfortunately). So expect me to be making frequent 'noob' style posts... My current issue is with testing assignation across a has_many relationship. I'm aw