Skip to content

Instantly share code, notes, and snippets.

module Spec
module Example
class ExampleGroupMethods
def run_examples(success, instance_variables, examples, run_options)
return [success, instance_variables] unless success
after_all_instance_variables = instance_variables
examples.each do |example|
example_group_instance = new(example, &example_implementations[example])
class LRUCache
def initialize(max_size)
@max_size = max_size
end
def put(name, value)
queue << name unless queue.include?(name)
data[name] = value
data[queue.shift] = nil if queue.size > @max_size
end
module RR
module DoubleDefinitions
class DoubleDefinition
def stub_chain(*args, &block)
eval(
args.flatten.inject('self') do |obj, name|
"#{obj}.stub!.#{name}"
end + ( block_given? ? ' { block.call }' : '' )
)
end
module RR::Adapters::RRMethods
def has_keys(*expected_keys)
RR::WildcardMatchers::HasKeys.new(expected_keys)
end
end
module RR::WildcardMatchers
class HasKeys
def initialize(keys)
@keys = keys.flatten
module RR::Adapters::RRMethods
def lazy(expected)
RR::WildcardMatchers::LazyMatcher.new(expected)
end
end
module RR::WildcardMatchers
class LazyMatcher
def initialize(value)
@value = value
describe MyController, '#index' do
include PureControllerTestHelper
let(:user) { MyModel.make_unsaved }
before do
mock(MyModel).find { user }
end
it 'should assign @user'
if [ $rvm_ruby_home ] ; then
alias gem='gem --config-file ~/.gemrc_for_rvm'
echo `type gem`
else
[ `type gem | awk '{print $4}'` = 'alias' ] && unalias gem
fi
@okitan
okitan / config
Created December 8, 2010 09:31
a part of .subversion/config
[auto-props]
### The format of the entries is:
### file-name-pattern = propname[=value][;propname[=value]...]
### The file-name-pattern can contain wildcards (such as '*' and
### '?'). All entries which match (case-insensitively) will be
### applied to the file. Note that auto-props functionality
### must be enabled, which is typically done by setting the
### 'enable-auto-props' option.
# *.c = svn:eol-style=native
# *.cpp = svn:eol-style=native
require 'ruby_gntp'
def your_app
#TODO:
end
def your_host
#TODO:
end
@okitan
okitan / gist:971950
Created May 14, 2011 05:40
こんな感じでAPIのspecを楽に書きたいんだけど
describe_jsonapi 'GET /users/:id' do
let(:id) { 1 }
context 'when user exists' do
before(:all) do
User.make(:id => id)
Article.make(:user_id => id, :article_id => 1)
end
after(:all) { DatabaseCleaner.clean }