Skip to content

Instantly share code, notes, and snippets.

@dnagir
dnagir / controller_spec_plain.rb
Created January 24, 2012 02:54
How the simples thing (its gem) makes specs much easier to read
# Controller spec using plain old matchers
describe "#create" do
let(:participation) { stub 'Participation' }
let(:params) { {:participation => {}} }
before { InviteUser.stub(:into_company_by_params => participation) }
context "with success" do
before { participation.stub(:valid? => true) }
@dnagir
dnagir / gist:1630480
Created January 18, 2012 02:34
When Ruby undefined becomes defined
> irb
1.9.3p0 :001 > a
NameError: undefined local variable or method `a' for main:Object
from (irb):1
from /Users/dnagir/.rvm/rubies/ruby-1.9.3-p0/bin/irb:16:in `<main>'
1.9.3p0 :002 > b
NameError: undefined local variable or method `b' for main:Object
from (irb):2
from /Users/dnagir/.rvm/rubies/ruby-1.9.3-p0/bin/irb:16:in `<main>'
1.9.3p0 :003 > a = b
@dnagir
dnagir / ste3-automactially-run.sh
Created January 13, 2012 09:43
RVM JRuby 1.9 mode
> if [[ "$RUBY_VERSION" == "jruby-19" ]]; then export export PROJECT_JRUBY_OPTS=( --1.9 ); fi
> rvm use $RUBY_VERSION
@dnagir
dnagir / terminal.sh
Created January 9, 2012 07:42
JRuby 1.7.dev bundle install issue
> bundle
Fetching source index for http://rubygems.org/
Using rake (0.9.2.2)
Using multi_json (1.0.4)
Using activesupport (3.1.3)
Using builder (3.0.0)
Using i18n (0.6.0)
Using activemodel (3.1.3)
Using erubis (2.7.0)
Using rack (1.3.5)
@dnagir
dnagir / terminal.sh
Created January 9, 2012 05:52
JRuby --server & MRI call vs send
> sh run.sh
======================== JRUBY =========================
Using /Users/dnagir/.rvm/gems/jruby-1.6.5.1
jruby 1.6.5.1 (ruby-1.9.2-p136) (2011-12-27 1bf37c2) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_29) [darwin-x86_64-java]
Benchmark for 100000 iterations
user system total real
send 0.266000 0.000000 0.266000 ( 0.266000)
call 0.069000 0.000000 0.069000 ( 0.069000)
Benchmark for 1000000 iterations
user system total real
@dnagir
dnagir / run.sh
Created January 9, 2012 05:19
JRuby & MRI call vs send
#!/bin/sh
source ~/.bash_profile
echo "======================== JRUBY ========================="
rvm use jruby &&
ruby -v &&
TIMES=100_000 ruby test.rb
TIMES=1000_000 ruby test.rb
@dnagir
dnagir / -X+C
Created January 7, 2012 03:12
Updating RSpec breaks JRuby
CachingCallSite.java:418:in `pollAndGetClass': java.lang.NullPointerException
from CachingCallSite.java:164:in `call'
from /Users/dnagir/.rvm/gems/jruby-1.6.5.1/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:193:in `method__9$RUBY$initialize'
from Users$dnagir$$_dot_rvm$gems$jruby_minus_1_dot_6_dot_5_dot_1$gems$rspec_minus_core_minus_2_dot_8_dot_0$lib$rspec$core$configuration$method__9$RUBY$initialize:65535:in `call'
from CachingCallSite.java:302:in `cacheAndCall'
from CachingCallSite.java:144:in `callBlock'
from CachingCallSite.java:148:in `call'
from RubyClass.java:806:in `newInstance'
from RubyClass$i$newInstance.gen:65535:in `call'
from JavaMethod.java:249:in `call'
@dnagir
dnagir / gist:1573414
Created January 7, 2012 01:36 — forked from freshtonic/gist:1390291
Run Postgres Specs in Ramdisk
  • This creates a 560mb ramdisk. Adjust the size accordingly. I think the number at the end of the command is the number of disk blocks. They are 2kb in size for me.
  • Restarting postgres is not necessary; you can create the ramdisk and tablespace while postgres is running.
  • You will lose all data in the ramdisk tablespace when you shut your machine down

  $ diskutil erasevolume HFS+ "postgres_ramdisk" `hdiutil attach -nomount ram://1165430`
  Started erase on disk1
  Unmounting disk
  Erasing
 Initialized /dev/rdisk1 as a 569 MB HFS Plus volume
@dnagir
dnagir / terminal.sh
Created January 4, 2012 06:47
Profiling RSpec-s with JRuby
> bundle install --binstubs
> jruby --profile bin/rspec spec/
........ etc .....
Finished in 56.58 seconds
204 examples, 0 failures, 59 pending
main thread profile results:
Total time: 60.30
@dnagir
dnagir / shell.sh
Created December 14, 2011 08:01
neo4j one spec is failing (locally only)
> bundle exec rake
/Users/dnagir/.rvm/rubies/jruby-1.6.5/bin/jruby -S bundle exec rcov -Ispec:lib --rails --include views -Ispec --exclude gems\/,spec\/,features\/,seeds\/ ./spec/event_handler_spec.rb ./spec/identity_map_spec.rb ./spec/load_spec.rb ./spec/neo4j_spec.rb ./spec/node_spec.rb ./spec/paginate_spec.rb ./spec/relationship_set_spec.rb ./spec/relationship_spec.rb ./spec/transaction_spec.rb ./spec/algo/graph_algo_spec.rb ./spec/batch/indexer_spec.rb ./spec/batch/inserter_spec.rb ./spec/batch/lucene_inserter_spec.rb ./spec/batch/rule_inserter_spec.rb ./spec/cypher/cypher_spec.rb ./spec/has_list/timeline_spec.rb ./spec/has_n/has_n_spec.rb ./spec/has_n/has_one_spec.rb ./spec/index/index_spec.rb ./spec/index/shared_index_spec.rb ./spec/migrations/global_migration_spec.rb ./spec/migrations/lazy_node_mixin_spec.rb ./spec/migrations/node_mixin_spec.rb ./spec/node_mixin/node_mixin_find_spec.rb ./spec/node_mixin/node_mixin_spec.rb ./spec/orm_adapter/adapters/neo4j_spec.rb ./spec/property/property_spec.rb ./spec