Skip to content

Instantly share code, notes, and snippets.

def round_to(num, places) # Pass in both parameters
(num * 10 ** places).round.to_f / 10 ** places
end
def ftoc(num)
answerc = ((num - 32) / 1.8)
puts "ftoc spits out #{self.class}"
round_to(answerc, 1)
end
describe "a thing" do
10.times do |i|
it "#{i} is #{i}" do
i.should eql i
end
end
end
var x = function(userid) {
return function(resp) {
var user_name = JSON.parse(resp)["full_name"];
console.log(userid);
build += "<li><a class='user' id='user-" + userid + "' href='#show-" + userid + "'>" + user_name + "</a></li>";
remaining -= 1;
if (remaining == 0) {
make_users_list(obj, build);
hide_spinner();
$("#login").hide();
describe ApplicationsService do
# start using `double`
let(:user) { double(:full_name => "bar") }
let(:task) { double(
:contractor => double,
:client => double,
:name => "foo"
)}
$ drip kill
$ time jruby -e 'puts 1'
1
real 0m1.272s
user 0m2.090s
sys 0m0.134s
$ time jruby -e 'puts 1'
@shepmaster
shepmaster / gist:4340028
Created December 19, 2012 20:08
JRuby 1.7.1 `ant test` failures. Done as `ant clean; ant; ant test` Commit 30a153bd697045bfb19e0116f881473b0bc0aa56
Failures:
1) Dir globs (Dir.glob and Dir.[]) finds the contents inside a jar with Dir.[] in a dir inside the jar
Failure/Error: FileUtils.cp "glob-test.jar", 'glob_test/'
Errno::ENOENT:
No such file or directory - /Users/shep/Projects/jruby/glob-test.jar
# org/jruby/RubyFile.java:810:in `stat'
# ./lib/ruby/1.8/fileutils.rb:1207:in `lstat'
# ./lib/ruby/1.8/fileutils.rb:1185:in `stat'
# ./lib/ruby/1.8/fileutils.rb:1267:in `copy_file'
class Wrapper
include Java::java.lang.Comparable
attr_reader :a
def initialize(a)
@a = a
end
def compare_to(x)
module X
def type(code, name)
instance_eval do
define_method "#{name}?" do |type|
type == code
end
end
end
end
describe 'match_time' do
(0..12).each do |h|
(0..59).each do |m|
it "should match #{h}:#{m} AM" do
match_time("%02i:%02i AM" % [h, m]).should_not be_nil
end
end
end
end
@shepmaster
shepmaster / spec.rb
Created January 28, 2013 16:05
Expect one param, ignoring others
class Foo
end
describe Foo do
it 'Expecting one param, ignoring others' do
subject.stub(:cool)
subject.should_receive(:cool).with(1)
subject.cool(1)
subject.cool(2)