Skip to content

Instantly share code, notes, and snippets.

it "should support one API key" do
key = stub_model(ApiKey, :valid? => true)
p = Provider.new(@valid_attributes)
p.api_keys << key
p.api_keys.should have(1).items # <= don't forget to add .items!!
end
#
# Author:: Adam Jacob (<adam@hjksolutions.com>)
# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
# License:: GNU General Public License version 2 or later
#
# This program and entire repository is free software; you can
# redistribute it and/or modify it under the terms of the GNU
# General Public License as published by the Free Software
# Foundation; either version 2 of the License, or any later version.
#
@radamant
radamant / 1_sample_usage.rb
Created September 3, 2008 04:45
Simple Web Benchmarking
w = Webench.new "localhost", 3000
# authenticate / create session
w.init_steps << Webench::Step.new do |http, cookie|
http.post('/account/login', 'login=username&password=password')
end
# main test steps
w.steps << Webench::Step.new do |http, cookie|
http.get('/articles/1',{'COOKIE' => cookie})
@radamant
radamant / RestfulAuth.feature
Created March 30, 2009 04:59
Is this really how cucumber .features _should_ be?
# Taken from RESTful authentication cucumber features
Scenario: Anonymous user can not create an account with bad email
Given an anonymous user
And no user with login: 'Oona' exists
When she registers an account with login: 'oona', password: 'monkey', password_confirmation: 'monkey' and email: ''
Then she should be at the 'users/new' page
And she should see an errorExplanation message 'Email can't be blank'
And no user with login: 'oona' should exist
When she registers an account with login: 'oona', password: 'monkey', password_confirmation: 'monkey' and email: 'unactivated@example.com'
Then she should be redirected to the home page
[apearson@aipnode ~]$ sudo chef-client
/usr/lib/ruby/1.8/net/http.rb:2097:in `error!': 400 "Bad Request" (Net::HTTPServerException)
from /usr/lib/ruby/gems/1.8/gems/chef-0.6.2/lib/chef/rest.rb:227:in `run_request'
from /usr/lib/ruby/gems/1.8/gems/chef-0.6.2/lib/chef/rest.rb:90:in `post_rest'
from /usr/lib/ruby/gems/1.8/gems/chef-0.6.2/lib/chef/client.rb:205:in `authenticate'
from /usr/lib/ruby/gems/1.8/gems/chef-0.6.2/lib/chef/client.rb:70:in `run'
from /usr/lib/ruby/gems/1.8/gems/chef-0.6.2/bin/chef-client:125
from /usr/lib/ruby/gems/1.8/gems/chef-0.6.2/bin/chef-client:119:in `loop'
from /usr/lib/ruby/gems/1.8/gems/chef-0.6.2/bin/chef-client:119
from /usr/bin/chef-client:19:in `load'
require 'mq'
Signal.trap('INT') { AMQP.stop{ EM.stop } }
Signal.trap('TERM'){ AMQP.stop{ EM.stop } }
AMQP.start(:host => 'aiprabbitmq.amer.gettywan.com') do
queue = MQ.queue('foobar')
queue.pop{ |msg|
unless msg
# queue was empty
p [Time.now, :queue_empty!]
[aip@aipnode ~]$ sudo chef-client
/srv/chef/cache/cookbooks/openldap/attributes/openldap.rb:21:in `from_file': private method `split' called for nil:NilClass (NoMethodError)
from /usr/lib/ruby/gems/1.8/gems/chef-0.6.2/lib/chef/cookbook.rb:73:in `load_attributes'
from /usr/lib/ruby/gems/1.8/gems/chef-0.6.2/lib/chef/cookbook.rb:71:in `each'
from /usr/lib/ruby/gems/1.8/gems/chef-0.6.2/lib/chef/cookbook.rb:71:in `load_attributes'
from /usr/lib/ruby/gems/1.8/gems/chef-0.6.2/lib/chef/compile.rb:61:in `load_attributes'
from /usr/lib/ruby/gems/1.8/gems/chef-0.6.2/lib/chef/cookbook_loader.rb:107:in `each'
from /usr/lib/ruby/gems/1.8/gems/chef-0.6.2/lib/chef/cookbook_loader.rb:106:in `each_value'
from /usr/lib/ruby/gems/1.8/gems/chef-0.6.2/lib/chef/cookbook_loader.rb:106:in `each'
from /usr/lib/ruby/gems/1.8/gems/chef-0.6.2/lib/chef/compile.rb:60:in `load_attributes'
service "apache2" do
service_name "httpd"
action :enable
end
@radamant
radamant / git_rails_prompt.sh
Created May 28, 2009 19:12
show rails environment and git branch in prompt
function parse_git_branch {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo "("${ref#refs/heads/}")"
}
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
PS1="$RED\$(date +%H:%M) \w$GREEN\${RAILS_ENV:+ ($RAILS_ENV)}$YELLOW \$(parse_git_branch) "
require 'webrat'
Webrat.configure do |config|
config.mode = :sinatra
end
class WebratTester
include Webrat::Methods
include Webrat::Matchers
def test_it
visit "http://www.google.com"