Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Ivan Kulagin qd3v

🏠
Working from home
View GitHub Profile
View vcr_hooks.rb
module SpecHelpers
# See more on this: https://github.com/vcr/vcr/issues/600
module VCRHooks
# @return [Proc] registered proc
def register_vcr_hook(type, *args, &block)
check_hook_type_valid!(type)
# Do not use #hooks hash directly, VCR wrap block into FilteredHook struct
VCR.configuration.send(type, *args, &block); block
@qd3v
qd3v / only_ar_rspec-rails_import.rb
Last active Aug 29, 2015
If you need only use_transactional_fixtures option
View only_ar_rspec-rails_import.rb
# Gemfile
gem 'rspec-rails', require: false
# spec_helper.rb
#
# IMPORT ONLY FIXTURE-RELATED CODE FROM rspec-rails
#
require 'rspec/rails/adapters'
View rspec_xml_matching.rb
# spec_helper.rb
require 'nokogiri'
require 'equivalent-xml/rspec_matchers'
RSpec.configure do |config|
# Should be used with be_equivalent_to provided by 'equivalent-xml' gem
# @see http://www.rubydoc.info/github/sparklemotion/nokogiri/Nokogiri/XML/Builder
# @see https://github.com/mbklein/equivalent-xml
def xml_document(&block)
Nokogiri::XML::Builder.new(&block).doc
View Rakefile_with_custom_ar_rake_tasks_import.rb
require 'bundler/gem_tasks'
require 'active_record'
# Temporary switch to blank rake app, extract required tasks and import them to
# current rake task. Skip seed loader here, as we do not need it for tests.
# More info on AR tasks import: @see https://gist.github.com/drogus/6087979
def import_active_record_tasks(default_rake_app)
Rake.application = Rake::Application.new
Rake.application.rake_require('active_record/railties/databases')
@qd3v
qd3v / timecop.rb
Created Dec 24, 2014
Timecop explained
View timecop.rb
t = Time.local(2008, 9, 1, 10, 5, 0)
# Self-explained
Timecop.freeze(t) do
expect(Time.zone.now.sec).to eq 0
end
# The same as above
Timecop.freeze(new_time)
expect(Time.zone.now.sec).to eq 0
You can’t perform that action at this time.