Skip to content

Instantly share code, notes, and snippets.

@lucassus
lucassus / dates_spec.rb
Created April 14, 2011 14:32
Difference between Dolorean and simple stub
context "for time just before the end time" do
before { Delorean.time_travel_to Time.parse('2011-04-03 23:58') } # two minutes to midnight ;)
after { Delorean.back_to_the_present }
it { should_not be_ended }
end
# ..and without magic DLS
context "for time just before the end time" do
before { Time.stubs(:now).returns(Time.parse('2011-04-03 23:58')) } # two minutes to midnight ;)
@lucassus
lucassus / backtrace.txt
Created April 22, 2011 16:07
InheritedResources and RSpec mock_model
(rdb:1) ap e.backtrace
[
[ 0] "/home/lucassus/Projects/sample_project/vendor/gems/ruby/1.9.1/gems/actionpack-3.0.4/lib/action_dispatch/routing/polymorphic_routes.rb:114:in `polymorphic_url'",
[ 1] "/home/lucassus/Projects/sample_project/vendor/gems/ruby/1.9.1/gems/actionpack-3.0.4/lib/action_dispatch/routing/url_for.rb:133:in `url_for'",
[ 2] "/home/lucassus/Projects/sample_project/vendor/gems/ruby/1.9.1/gems/actionpack-3.0.4/lib/action_controller/metal/redirecting.rb:89:in `_compute_redirect_to_location'",
[ 3] "/home/lucassus/Projects/sample_project/vendor/gems/ruby/1.9.1/gems/actionpack-3.0.4/lib/action_controller/metal/redirecting.rb:61:in `redirect_to'",
[ 4] "/home/lucassus/Projects/sample_project/vendor/gems/ruby/1.9.1/gems/actionpack-3.0.4/lib/action_controller/metal/flash.rb:25:in `redirect_to'",
[ 5] "/home/lucassus/Projects/sample_project/vendor/gems/ruby/1.9.1/gems/actionpack-3.0.4/lib/action_controller/metal/instrumentation.rb:60:in `block in redirect_to'",
[ 6] "/hom
ruby-1.9.2-p180$ cat xvfb
#!/bin/bash
XVFB=/usr/bin/Xvfb
XVFBARGS="$DISPLAY -ac -screen 0 1024x768x16"
PIDFILE=/tmp/xvfb_${DISPLAY}.pid
case "$1" in
start)
echo -n "Starting virtual X frame buffer: Xvfb"
/sbin/start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile --background --exec $XVFB -- $XVFBARGS
echo "."
describe('when the code does not exists in the collection', function() {
var $browser;
beforeEach(function() {
$browser = scope.$service('$browser');
});
describe('when validation fails', function() {
beforeEach(function() {
var validationResponse = 'validation fail';
def shuffled_users
shuffled = users.sort_by { rand }
while shuffled == users
shuffled = users.sort_by { rand }
end
shuffled
end
describe('built-in matchers', function() {
describe('toBeTruthy', function() {
it('passes if subject is true', function() {
expect(true).toBeTruthy();
expect(false).not.toBeTruthy();
});
});
describe('toBeFalsy', function() {
it('passes if subject is false', function() {
/usr/local/lib/ruby/1.9.1/openssl/ssl-internal.rb:121:in `post_connection_check'
/usr/local/lib/ruby/1.9.1/net/http.rb:680:in `connect'
/usr/local/lib/ruby/1.9.1/net/http.rb:637:in `do_start'
/usr/local/lib/ruby/1.9.1/net/http.rb:626:in `start'
/usr/local/lib/ruby/1.9.1/net/http.rb:1168:in `request'
/usr/local/lib/ruby/1.9.1/net/http.rb:978:in `post'
vendor/bundle/ruby/1.9.1/gems/hoptoad_notifier-2.4.11/lib/hoptoad_notifier/sender.rb:37:in `send_to_hoptoad'
vendor/bundle/ruby/1.9.1/gems/hoptoad_notifier-2.4.11/lib/hoptoad_notifier.rb:128:in `send_notice'
vendor/bundle/ruby/1.9.1/gems/hoptoad_notifier-2.4.11/lib/hoptoad_notifier.rb:104:in `notify_or_ignore'
vendor/bundle/ruby/1.9.1/gems/hoptoad_notifier-2.4.11/lib/hoptoad_notifier/rack.rb:29:in `rescue in call'
index 549b6e0..55d1c5c 100644
--- a/vendor/assets/javascripts/jquery.mockjax.js
+++ b/vendor/assets/javascripts/jquery.mockjax.js
@@ -328,8 +328,8 @@
@@ -328,8 +328,8 @@
}
// Successful response
@lucassus
lucassus / spec.rb
Created September 12, 2012 10:18
Testing indexes for mongoid
describe 'indexes' do
it { should have_index_for({ company: 1, advisor_company: 1 }).with_options(unique: true) }
describe 'unique index for :company and :advisor_company' do
let!(:first_advisor_company) { create(:company, :advisor) }
let!(:second_advisor_company) { create(:company, :advisor) }
let!(:company) { create(:company) }
before { Rails::Mongoid.create_indexes("app/models/company/**/*.rb") }
@lucassus
lucassus / shared_context.rb
Created October 9, 2012 07:47
Smart fxitures for mongoid and factory_girl
Before
$ rspec spec/ --tag api
Run options: include {:api=>true}
..........................................
Finished in 3 minutes 59.73 seconds
After