Skip to content

Instantly share code, notes, and snippets.

flexmock(User).should_receive(:find).with('42').and_return(jane) # Flexmock
User.should_receive(:find).with('42').and_return(jane) # Rspec
User.expects(:find).with('42').returns {jane} # Mocha
User.should_receive(:find).with('42') {jane} # Rspec using return value blocks
mock(User).find('42') {jane} # RR
@farnoy
farnoy / main-window.cc
Created March 10, 2012 13:05
Print first n lines from a file
void MainWindow::show_message()
{
std::stringstream title, content;
title << "The first [" << m_spin_button.get_value_as_int() << "] lines";
Gtk::MessageDialog dialog(title.str());
std::ifstream file;
file.open(m_file_chooser_button.get_filename().c_str(), std::ifstream::in);
char buffer[512];
short i = 0;
task :minitest do
path = File.expand_path('test', Rails.root)
require File.expand_path('test_helper', path)
Dir[path + '/*_test.rb'].each do |file|
require file
end
end
kuba:Blog$ tree spec/
spec/
├── controllers
│   └── posts_controller_spec.rb
├── helpers
│   └── posts_helper_spec.rb
├── models
│   └── post_spec.rb
├── requests
│   └── posts_spec.rb
$:.unshift './'
require 'calculator'
describe Calculator do
describe :constructor do
it 'should take many arguments' do
args = [1, 2, 3, 4]
Calculator.new(*args).values.should eq(args)
end
end
@farnoy
farnoy / gist:1838021
Created February 15, 2012 18:32
gosab deps
kuba:gosab$ tree
.
|-- src
| `-- gosab
| |-- api
| | |-- sab_api.go
| | `-- sab_api_test.go
| |-- backend
| | |-- connector
| | | `-- connector.go
@farnoy
farnoy / main.go
Created February 12, 2012 10:38
golang websockets
package main
import (
"websocket"
"http"
"fmt"
"io"
)
func EchoServer(ws *websocket.Conn) {
@farnoy
farnoy / gist:1800782
Created February 11, 2012 15:25
Test output for SO question
[48 32 50 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0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require('example');
goog.require('goog.dom');
goog.require('goog.dom.NodeType');
var testHtmlEscaping = function() {
example.sayHello('<b>greeting</b>');
var greetingEl = goog.dom.getElement('greeting');
assertEquals('The <h1 id="greeting"> element should only have one child node',