Skip to content

Instantly share code, notes, and snippets.

View niku's full-sized avatar
💭
🍖

KITAMURA Daisuke niku

💭
🍖
View GitHub Profile
@niku
niku / list_delete.rb
Created November 28, 2010 04:23
指定したidのリストを削除する
# -*- coding: utf-8 -*-
require 'yaml'
require 'logger'
require 'net/http'
require 'twitter'
LOG = Logger.new('log')
LISTS = [22926920, 22919856, 22917276, 22914957, 22912272, 22898839]
USER= 'niku_name'
# -*- coding: utf-8 -*-
require 'rspec'
describe "stdout" do
def substitute_stdout
mock = double('stdout')
yield mock
$stdout = mock
end
@niku
niku / LRUCache.rb
Created January 22, 2011 10:21
TDDBC@Sapporo の ruby チームの実装/テストです
# -*- coding: utf-8 -*-
require 'rspec'
class LRUCache
attr_reader :order, :capacity
def initialize(capacity)
@capacity = capacity
@order = []
@hash = {}
@niku
niku / mocking_fork.rb
Created February 28, 2011 00:11
How to mocking 'fork' method twice.
require 'rspec'
class Foo
def my_fork
fork do
p 'forked once'
end
end
def my_fork_double
fork do
@niku
niku / foo.rb
Created March 6, 2011 13:32
How do I use expect{}.to change().from().to() ?
require 'rspec'
class Foo
attr_reader :ary
def initialize
@ary = []
@num = 0
end
def update
@ary << @num
@niku
niku / mock_block_spec.rb
Created March 8, 2011 23:02
How do I check block given?
require 'rspec'
class Foo
def bar &block
block.call(:called) if block
:done
end
end
# Foo.new.bar{ |m| p m }
@niku
niku / expect_spec.rb
Created March 15, 2011 15:41
How do I use expect{}.to change().from().to() on Array?
require 'rspec'
class Int
attr_reader :count
def initialize
@count = 0
end
def increment
@count += 1
end
@niku
niku / rspec_block_test.rb
Created March 28, 2011 04:59
how do I test block given parameter
require 'rspec'
class Foo
def bar
if block_given?
yield(1)
yield(2)
end
end
end
@niku
niku / send_with_block.rb
Created May 2, 2011 07:18
difference of block parameter
class Foo
def block
yield if block_given?
end
def call &b
b.call if b
end
end
Foo.new.send(:block) { 'block called' } # => "block called"
@niku
niku / gist:1021496
Created June 12, 2011 12:24
Rack::Lint::LintError occur
/Users/niku% ruby --version
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.7.0]
/Users/niku% curl -H host:pow localhost/config.json
{"bin":"/Users/niku/Library/Application Support/Pow/Versions/0.3.1/bin/pow","dstPort":80,"httpPort":20559,"dnsPort":20560,"timeout":900,"workers":2,"domains":["dev"],"extDomains":[],"hostRoot":"/Users/niku/Library/Application Support/Pow/Hosts","logRoot":"/Users/niku/Library/Logs/Pow","rvmPath":"/Users/niku/.rvm/scripts/rvm"}
/Users/niku% mkdir lint_test
/Users/niku% echo "require 'rack'\nrequire 'rack/lobster'\n\nuse Rack::Lint\nrun Rack::Lobster.new\n" > lint_test/config.ru
/Users/niku% cat lint_test/config.ru
require 'rack'
require 'rack/lobster'