2016-06-07 20:17:31 -04:00
|
|
|
# Copyright (c) 2010-2016 Michael Dvorkin and contributors
|
2010-10-31 22:21:26 -04:00
|
|
|
#
|
|
|
|
# Awesome Print is freely distributable under the terms of MIT license.
|
|
|
|
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
#
|
2011-05-06 18:20:52 -04:00
|
|
|
# Running specs from the command line:
|
2011-05-06 20:35:49 -04:00
|
|
|
# $ rake spec # Entire spec suite.
|
2012-09-03 14:54:32 -04:00
|
|
|
# $ rspec spec/objects_spec.rb # Individual spec file.
|
2010-10-31 22:21:26 -04:00
|
|
|
#
|
2012-09-03 15:23:31 -04:00
|
|
|
# NOTE: To successfully run specs with Ruby 1.8.6 the older versions of
|
|
|
|
# Bundler and RSpec gems are required:
|
|
|
|
#
|
|
|
|
# $ gem install bundler -v=1.0.2
|
|
|
|
# $ gem install rspec -v=2.6.0
|
|
|
|
#
|
2015-01-20 14:52:27 -05:00
|
|
|
require 'codeclimate-test-reporter'
|
|
|
|
CodeClimate::TestReporter.start
|
2010-03-25 00:31:59 -04:00
|
|
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
|
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
|
|
|
2014-12-31 10:04:42 -05:00
|
|
|
Dir[File.dirname(__FILE__) + '/support/**/*.rb'].each do |file|
|
|
|
|
require file
|
|
|
|
end
|
|
|
|
|
2014-12-31 15:59:32 -05:00
|
|
|
ExtVerifier.require_dependencies!(%w{rails active_record action_view
|
2014-01-07 02:10:56 -05:00
|
|
|
active_support/all mongoid mongo_mapper ripple nobrainer})
|
2014-12-31 15:59:32 -05:00
|
|
|
require 'nokogiri'
|
|
|
|
require 'awesome_print'
|
|
|
|
|
|
|
|
RSpec.configure do |config|
|
|
|
|
config.disable_monkey_patching!
|
|
|
|
# TODO: Make specs not order dependent
|
|
|
|
# config.order = :random
|
|
|
|
Kernel.srand config.seed
|
|
|
|
config.filter_run focus: true
|
|
|
|
config.run_all_when_everything_filtered = true
|
|
|
|
config.expect_with :rspec do |expectations|
|
|
|
|
expectations.syntax = :expect
|
|
|
|
end
|
|
|
|
config.mock_with :rspec do |mocks|
|
|
|
|
mocks.syntax = :expect
|
|
|
|
mocks.verify_partial_doubles = true
|
|
|
|
end
|
|
|
|
if config.files_to_run.one?
|
|
|
|
config.default_formatter = 'doc'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-05-09 10:04:42 -04:00
|
|
|
# This matcher handles the normalization of objects to replace non deterministic
|
|
|
|
# parts (such as object IDs) with simple placeholder strings before doing a
|
|
|
|
# comparison with a given string. It's important that this method only matches
|
|
|
|
# a string which strictly conforms to the expected object ID format.
|
2016-05-09 16:12:59 -04:00
|
|
|
RSpec::Matchers.define :be_similar_to do |expected, options|
|
2016-05-09 10:04:42 -04:00
|
|
|
match do |actual|
|
2016-05-09 16:12:59 -04:00
|
|
|
options ||= {}
|
|
|
|
@actual = normalize_object_id_strings(actual, options)
|
2016-05-09 10:04:42 -04:00
|
|
|
values_match? expected, @actual
|
|
|
|
end
|
|
|
|
|
|
|
|
diffable
|
|
|
|
end
|
|
|
|
|
|
|
|
# Override the Object IDs with a placeholder so that we are only checking
|
|
|
|
# that an ID is present and not that it matches a certain value. This is
|
|
|
|
# necessary as the Object IDs are not deterministic.
|
2016-05-09 16:12:59 -04:00
|
|
|
def normalize_object_id_strings(str, options)
|
|
|
|
str = str.gsub(/#<(.*?):0x[a-f\d]+/, '#<\1:placeholder_id') unless options[:skip_standard]
|
|
|
|
str = str.gsub(/BSON::ObjectId\('[a-f\d]{24}'\)/, 'placeholder_bson_id') unless options[:skip_bson]
|
|
|
|
str
|
2016-05-09 10:04:42 -04:00
|
|
|
end
|
|
|
|
|
2010-04-08 22:57:58 -04:00
|
|
|
def stub_dotfile!
|
|
|
|
dotfile = File.join(ENV["HOME"], ".aprc")
|
2014-05-15 16:47:57 -04:00
|
|
|
expect(File).to receive(:readable?).at_least(:once).with(dotfile).and_return(false)
|
2010-03-25 00:31:59 -04:00
|
|
|
end
|
2011-05-04 20:20:07 -04:00
|
|
|
|
2012-09-06 00:55:04 -04:00
|
|
|
def capture!
|
|
|
|
standard, $stdout = $stdout, StringIO.new
|
|
|
|
yield
|
|
|
|
ensure
|
|
|
|
$stdout = standard
|
|
|
|
end
|