Skip to content

Instantly share code, notes, and snippets.

View JonRowe's full-sized avatar
💭
⛵️

Jon Rowe JonRowe

💭
⛵️
View GitHub Profile
@JonRowe
JonRowe / capistrano.rb
Created August 18, 2013 10:23
Show broken sudo support in sprinkle pre/post hooks.
set :use_sudo, false
set :ssh_options, forward_agent: true
role :app, ENV['hostname'], primary: true
default_run_options[:pty] = true
@JonRowe
JonRowe / til.rb
Created August 8, 2013 03:16
TIL, local variables are scoped / defined even if never executed.
def test
begin
raise
local = 'b'
rescue
ensure
return defined?(local) || false
end
end
class Thing
def [] a, &block
block.call a
end
end
thing = Thing.new
lass One
2 def original arg
3 2
4 end
5 end
6
7 describe "one" do
8 it 'does things' do
9 one = One.new
10 one.stub(:original) do |arg|
@JonRowe
JonRowe / auth.rb
Last active December 17, 2015 08:29
Omniauth setup
Warden::Strategies.add(:login) do
def authenticate!
throw :warden
end
end
WardenOmniAuth.on_callback do |hash|
HandleAuthentication.new(hash).user
end
@JonRowe
JonRowe / pure_rspec.md
Last active December 16, 2015 03:19
Ancestry of `let` definitions in `rspec-core` vs `rspec-rails`
RSpec::Core::ExampleGroup::Nested_1::Nested_1
RSpec::Core::ExampleGroup::Nested_1
>> **RSpec::Core::ExampleGroup::Nested_1::LetDefinitions** <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
RSpec::Core::ExampleGroup::Nested_1::NamedSubjectPreventSuper
>> **RequestHelpers** <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
RSpec::Core::ExampleGroup
RSpec::Matchers
RSpec::Core::MockFrameworkAdapter
RSpec::Core::SharedExampleGroup

RSpec::Core::Pending

require 'rspec'
spec_file = 'spec/sample_spec.rb'
File.open(spec_file, 'w') { |file| file.write 'describe { specify { expect(true).to eq false } }' }
1.upto(5) do |i|
puts "Running spec from within ruby runtime"
::RSpec::Core::Runner.run([spec_file], STDERR, STDOUT)
@JonRowe
JonRowe / class_detector.rb
Created March 14, 2013 01:40
Fetch all the classes in the Object namespace...
def blacklist
[
:Object, :Module, :Class, :BasicObject, :Kernel, :NilClass, :NIL, :Data,
:TrueClass, :TRUE, :FalseClass, :FALSE, :Encoding, :Comparable, :Method,
:String, :Symbol, :Exception, :SystemExit, :SignalException, :Interrupt,
:StandardError, :TypeError, :ArgumentError, :IndexError, :KeyError, :Dir,
:RangeError, :ScriptError, :SyntaxError, :LoadError, :NotImplementedError,
:NameError, :NoMethodError, :RuntimeError, :SecurityError, :NoMemoryError,
:EncodingError, :SystemCallError, :Errno, :ZeroDivisionError, :Enumerable,
:FloatDomainError, :Numeric, :Integer, :Fixnum, :Float, :Bignum, :Array,
@JonRowe
JonRowe / Gemfile.lock
Created March 8, 2013 04:35
Dependencies for middleman-sprockets
GIT
remote: git://github.com/middleman/middleman.git
revision: 3ce35149ec0ef33a52937e8f0ae11226810e04f6
branch: 3.0-stable
specs:
middleman (3.0.12)
middleman-core (= 3.0.12)
middleman-more (= 3.0.12)
middleman-sprockets (~> 3.0.8)
middleman-core (3.0.12)
#interestingly... this line fixes the issue...
include RSpec::Matchers
describe do
specify do
obj1 = Object.new
def obj1.blah?; true; end
obj1.should be_blah
obj2 = Object.new