Bambinos RSS

New Bamboo

Bamboo Blog

Archive

Sep
12th
Fri
permalink ollylegg
permalink gwyn

cache + content_for = fail

Tumblr is useless and can’t display text without mangling it. To view this post, go to http://gist.github.com/10444 .

Sep
10th
Wed
permalink dctanner
permalink ollylegg
Sep
2nd
Tue
permalink bartoszblimke

Removing mocha stubs and expectations

The following code removes all the method stubs and expectations created with mocha.

require 'mocha/standalone'
include Mocha::Standalone

mocha_teardown
Aug
29th
Fri
permalink dctanner
My new framework goes one better than Caffeine. It’s called Cocaine… Cocaine handles the differences between data abstractions, personalities, sexual preferences, file storage, templating, sexual preferences, syntax, bugs, user models, fashion models, and sexual preferences.
Aug
25th
Mon
permalink dctanner
Aug
22nd
Fri
permalink wildfalcon

Net::HTTP missing delete -- a reprieve

Earlier today I wrote

bambinos:

I just got really screwed over by Net::HTTP

The docs talk about a nice delete method for sending HTTP DELETE requests, however it turns out that it does not exist

>> Net::HTTP.methods.include?("delete")
=> false

I am somewhat annoyed, especially given we asked a third-party to respond to DELETE requests, and now have to figure out a way to send them! Bad ruby! Bad Net HTTP!

Turns out it was mostly my mistake (isn’t it always), but i blame rdoc for being somewhat less than clear!

Delete is not a class method (though given that Get is, i think Delete should be too), so the correct way to use it is

  uri = URI.parse("http://server.example.com:8080/path/to/resource?var=value")
  request = Net::HTTP.new(uri.host, uri.port)
  response = request.delete(uri.request_uri)

Make sure you only give the uri.host to Net::HTTP.new and not uri.to_s otherwise you get annoying errors; and that you use uri.request_uri not request.path when creating the path for the delete method, as the path does not include any query params

permalink wildfalcon

Net::HTTP missing delete

I just got really screwed over by Net::HTTP

The docs talk about a nice delete method for sending HTTP DELETE requests, however it turns out that it does not exist

>> Net::HTTP.methods.include?("delete")
=> false

I am somewhat annoyed, especially given we asked a third-party to respond to DELETE requests, and now have to figure out a way to send them! Bad ruby! Bad Net HTTP!

permalink dctanner
permalink bartoszblimke

How to mock Rails view helpers with RSpec

If you want to stub view helper method in some view spec, you can do the following:

 @controller.template.stub!(:helper_method_name).with(:some_args).and_return("some result")
Aug
21st
Thu
permalink wildfalcon

should_receive in rspec stories

In Test 1 I do this

SSO::SSO.should_receive(:authorize).with(“foo@bar.com”, “pass”).and_return(“asdf”)

So now:

SSO::SSO.authorize(“foo@bar.com”, “pass”) -> “asdf”

Then in test 2 I do

SSO::SSO.should_receive(:authorize).with(“foo@bar.com”, “pass”).and_return(“qwer”)

But I still get…..

SSO::SSO.authorize(“foo@bar.com”, “pass”) -> “asdf”

:(

Aug
20th
Wed
permalink dctanner
Creativity : flow and the psychology of discovery and invention.

Creativity : flow and the psychology of discovery and invention.

permalink bartoszblimke
Aug
19th
Tue
permalink dctanner