Skip to content

Instantly share code, notes, and snippets.

View cfcosta's full-sized avatar

Cainã Costa cfcosta

  • São Paulo, Brazil
View GitHub Profile
#encoding: utf-8
# GIT configuration
git :init
git :add => '.', :commit => %(-m "Initial Commit")
append_file '.gitignore', "*~"
append_file '.gitignore', "\n#*#"
append_file '.gitignore', "\n*.swp"
append_file '.gitignore', "\nnbproject"
#!/usr/bin/env ruby
#
# Brute-force way to retrieve all Github's repositories at once
# Usage:
# github_repos.rb clone # will clone all the user's repositories
# github_repos.rb clone test # will just clone 6 repositories for testing purposes
# github_repos.rb pull # will update all of the user's local repositories
#
# If you have forked repositories, the original sources will be added
# as remotes with the default 'forked_from' name, and a new 'forked_from'
@cfcosta
cfcosta / correct_capitalization.rb
Created March 10, 2011 19:44
Pequeno script para consertar a capitalização de nomes de cidades, por exemplo.
require 'unicode'
class String
def downcase
Unicode.downcase self
end
def capitalize
Unicode.capitalize self
end
@cfcosta
cfcosta / gist:978725
Created May 18, 2011 14:50
Turning your vim more emacs-likey
imap <C-f> <C-o>l
imap <C-b> <C-o>h
imap <C-n> <C-o>j
imap <C-p> <C-o>k
imap <C-a> <C-o>0
imap <C-e> <C-o>$
imap <C-k> <C-o>D
imap <C-y> <C-o>p
@cfcosta
cfcosta / gist:1149139
Created August 16, 2011 13:55
Implementation of Webrat's #table_at for using with Capybara. Not the cleanest implementation ever, but it works correctly.
def table_at(selector)
Nokogiri::HTML(page.body).css(selector).map do |table|
table.css('tr').map do |tr|
tr.css('td').map { |td| td.text }
end
end[0].reject(&:empty?)
end
require 'test_helper'
class IrcProtocolParserTest < MiniTest::Unit::TestCase
def setup
@protocol = Stewie::IrcProtocolParser.new
end
def test_parse_channel_nick_change
assert_equal [:nick, 'WiZ', 'Kilroy'], @protocol.parse(':WiZ NICK Kilroy')
end
#!/usr/bin/env ruby
require 'socket'
require_relative 'lib/stewie/irc_protocol_parser'
nick = 'stewiebot'
server = 'irc.freenode.org'
channel = '#moarbottest'
port = 6667

MiniTest::FireMock

This gem was designed do make isolated tests more resilient. In isolated tests, a FireMock is no different than a common mock. The only difference is when the test is called on a not-isolated environment. It checks for the presence of the method on the mocked class, and fails if it isn't there. This adds another layer of security for suit tests, without compromising the isolation of unit tests.

It's based on the awesome rspec-fire from Xavier Shay.

Usage

module Stewie
autoload :PluginManager, 'stewie/plugin_manager'
autoload :IrcProtocolParser, 'stewie/irc_protocol_parser'
autoload :Connection, 'stewie/connection'
class << self
def configure
yield self
end
require 'integration_test_helper'
module FakeServer
def self.received_messages ; @@received_messages ||= [] ; end
def receive_data(data)
received_messages << data
end
end