Skip to content

Instantly share code, notes, and snippets.

# spec_helper.rb
require 'fakefs/spec_helpers'
RSpec.configure do |config|
config.include FakeFS::SpecHelpers, fakefs: true
end
group :test
gem 'fakefs', require: "fakefs/safe"
end
# Reads /etc/passwd and returns an array of arrays
# representing the users on the system.
def users
File.readlines("/etc/passwd").
reject { |line| line =~ /^\s*#/ }.
map { |line| line.split(":") }
end
describe "#users" do
it "reads /etc/passwd and returns user information" do
File.stubs(:read).returns("andy:*:100:100\nbob:*:101:101")
users.should == [["andy", "*", "100", "100"],
["bob", "*", "101", "101"]]
end
end
# Reads /etc/passwd and returns an array of arrays
# representing the users on the system.
def users
File.read("/etc/passwd").
split(/\r?\n/).
reject { |line| line =~ /^\s*#/ }.
map { |line| line.split(":") }
end
adl91macbook:~ alindeman$ irb
ruby-1.9.2-p290 :001 > Float::INFINITY
=> Infinity
ruby-1.9.2-p290 :002 > Float::INFINITY == 1/0.0
=> true
ruby-1.9.2-p290 :003 > exit
adl91macbook:~ alindeman$ rvm jruby
adl91macbook:~ alindeman$ irb
jruby-1.6.3 :001 > Float::INFINITY
NameError: uninitialized constant Float::INFINITY
(12:37:08) < ziikutv> How can I write a test for a system command?
(12:38:10) < alindeman> ziikutv: Expound a bit?
(12:40:12) < ziikutv> What ever one places in a textbox, I want the server (dedicated) to copy it to a clipboard
(12:40:14) < ziikutv> is that possible
(12:42:20) < alindeman> Copy it to the server's clipboard?
(12:42:26) < ziikutv> Yes.
(12:42:32) < alindeman> That's a weird use case
(12:42:38) < ziikutv> yeah
(12:42:41) < ziikutv> because
(12:42:44) < ziikutv> I have this software
def current_user
if cookies[:auth_token]
@current_user ||= User.find_by_auth_token!(cookies[:auth_token])
end
end
module Vectorize
class Surface
extend FFI::Library
# TODO: How to make this portable?
ffi_lib "/usr/X11/lib/libcairo.dylib"
attach_function :cairo_create, [:pointer], :pointer
CAIRO_FORMAT_INVALID = -1
CAIRO_FORMAT_ARGB32 = 0
blog_post = BlogPost.find("4e13cda850b86112c9000001")
begin
# .. do work ..
blog_post.save
rescue MongoMapper::StaleDocumentError
blog_post.reload
retry
end