12th
Tumblr is useless and can’t display text without mangling it. To view this post, go to http://gist.github.com/10444 .
The following code removes all the method stubs and expectations created with mocha.
require 'mocha/standalone'
include Mocha::Standalone
mocha_teardown
Markdown implementation with extensions such as support for setting classes (very useful when you need to set the class of a <code> block)
Example:
some.ruby('code')
{:lang=ruby}
Earlier today I wrote
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") => falseI 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
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!
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")
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”
:(