This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RSpec.configure do |config| | |
config.on_error do |example| | |
if example.example_group.metadata[:type] == :request | |
example.instance_eval { save_and_open_page } | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class H < Array | |
def a | |
reject {|i| i == :a} | |
end | |
def b | |
select {|i| i == :b} | |
end | |
def c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'forwardable' | |
class BenArray | |
extend Forwardable | |
def initialize | |
@array = [] | |
end | |
def_delegators :@array, :select, :reject, :<< |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module RSpec | |
module Mocks | |
module AnyInstance | |
class Chains < Array | |
def add(chain) | |
push(chain) | |
chain | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module RPN | |
def self.start | |
loop { stack.add(Line.new) } | |
end | |
def self.stack | |
@stack ||= Stack.new | |
end | |
class Stack |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe PostsController do | |
describe "PUT #update" do | |
let(:post) { Factory(:post) } | |
context "when logged in as post's author" do | |
before { sign_in post.author } | |
it "allows the post to be updated" do | |
do_action | |
response.should be_success |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
desc 'Execute a task in the background' | |
task :background, :task do |t, args| | |
rake_path = `which rake`.chomp | |
app_path = Dir.pwd | |
cmd = "#{rake_path} #{args.task} --trace --rakefile #{app_path}/Rakefile >> #{app_path}/log/rake.log 2>&1 &" | |
puts 'Executing:' | |
puts " #{cmd}" | |
system cmd | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# In spec/support/callback_disabler.rb | |
module CallbackDisabler | |
def self.store_callbacks(model, filters) | |
model = constantize(model) | |
filters.each do |filter| | |
model.send("_#{filter}_callbacks").each do |callback| | |
stored_callbacks[model] << { | |
filter: filter, kind: callback.kind, raw_filter: callback.raw_filter | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ViewDecorator | |
include RailsViewHelpers | |
def link_to_root | |
link_to # ... | |
end | |
end | |
# Most likely you won't do this because you need to | |
# pass some kind of data/state |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def find_in_batches(model) | |
current_batch, count = 0, model.count | |
while count > 0 do | |
model.all.skip(current_batch * 1000).limit(1000).each do |doc| | |
yield doc | |
end | |
count -= 1000 | |
current_batch += 1 | |
end |