rspec-support 3.2.2 → 3.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/Changelog.md +20 -0
- data/lib/rspec/support.rb +35 -0
- data/lib/rspec/support/differ.rb +16 -16
- data/lib/rspec/support/directory_maker.rb +2 -0
- data/lib/rspec/support/encoded_string.rb +7 -0
- data/lib/rspec/support/fuzzy_matcher.rb +1 -1
- data/lib/rspec/support/object_formatter.rb +93 -0
- data/lib/rspec/support/ruby_features.rb +2 -0
- data/lib/rspec/support/spec.rb +8 -3
- data/lib/rspec/support/spec/deprecation_helpers.rb +4 -0
- data/lib/rspec/support/spec/in_sub_process.rb +7 -2
- data/lib/rspec/support/spec/library_wide_checks.rb +145 -0
- data/lib/rspec/support/spec/shell_out.rb +4 -2
- data/lib/rspec/support/spec/stderr_splitter.rb +2 -2
- data/lib/rspec/support/spec/string_matcher.rb +46 -0
- data/lib/rspec/support/version.rb +1 -1
- metadata +7 -5
- metadata.gz.sig +0 -0
- data/lib/rspec/support/spec/prevent_load_time_warnings.rb +0 -56
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a74da896e672529b21b1753eb56081e6f5f8f5d7
|
4
|
+
data.tar.gz: 9b5f92e7bf487974d55cf1e086a113479542554d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ea71400d27d790bc32e8a208e4d371f11a4c32a1941a77013f87ae94bc309368746b2fd893397b284ffa95aeb75fc099c06a027611a2b79ce73705864cdaf2e
|
7
|
+
data.tar.gz: 8902798fc1ebc40eb8c0b6d407307520434c4bf0ac1f322890d5b2d53214b45bb154fc6d1e9dc296d3ee3c6541a562d17529e8515f6c845ac3a1dc518c272dab
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/Changelog.md
CHANGED
@@ -1,4 +1,24 @@
|
|
1
|
+
### 3.3.0 / 2015-06-12
|
2
|
+
[Full Changelog](http://github.com/rspec/rspec-support/compare/v3.2.2...v3.3.0)
|
3
|
+
|
4
|
+
Enhancements:
|
5
|
+
|
6
|
+
* Improve formatting of arrays and hashes in failure messages so they
|
7
|
+
use our custom formatting of matchers, time objects, etc.
|
8
|
+
(Myron Marston, Nicholas Chmielewski, #205)
|
9
|
+
* Use improved formatting for diffs as well. (Nicholas Chmielewski, #205)
|
10
|
+
|
11
|
+
Bug Fixes:
|
12
|
+
|
13
|
+
* Fix `FuzzyMatcher` so that it checks `expected == actual` rather than
|
14
|
+
`actual == expected`, which avoids errors in situations where the
|
15
|
+
`actual` object's `==` is improperly implemented to assume that only
|
16
|
+
objects of the same type will be given. This allows rspec-mocks'
|
17
|
+
`anything` to match against objects with buggy `==` definitions.
|
18
|
+
(Myron Marston, #193)
|
19
|
+
|
1
20
|
### 3.2.2 / 2015-02-23
|
21
|
+
[Full Changelog](http://github.com/rspec/rspec-support/compare/v3.2.1...v3.2.2)
|
2
22
|
|
3
23
|
Bug Fixes:
|
4
24
|
|
data/lib/rspec/support.rb
CHANGED
@@ -72,5 +72,40 @@ module RSpec
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
end
|
75
|
+
|
76
|
+
# A single thread local variable so we don't excessively pollute that namespace.
|
77
|
+
def self.thread_local_data
|
78
|
+
Thread.current[:__rspec] ||= {}
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.failure_notifier=(callable)
|
82
|
+
thread_local_data[:failure_notifier] = callable
|
83
|
+
end
|
84
|
+
|
85
|
+
# @private
|
86
|
+
DEFAULT_FAILURE_NOTIFIER = lambda { |failure, _opts| raise failure }
|
87
|
+
|
88
|
+
def self.failure_notifier
|
89
|
+
thread_local_data[:failure_notifier] || DEFAULT_FAILURE_NOTIFIER
|
90
|
+
end
|
91
|
+
|
92
|
+
def self.notify_failure(failure, options={})
|
93
|
+
failure_notifier.call(failure, options)
|
94
|
+
end
|
95
|
+
|
96
|
+
def self.with_failure_notifier(callable)
|
97
|
+
orig_notifier = failure_notifier
|
98
|
+
self.failure_notifier = callable
|
99
|
+
yield
|
100
|
+
ensure
|
101
|
+
self.failure_notifier = orig_notifier
|
102
|
+
end
|
103
|
+
|
104
|
+
# The Differ is only needed when a a spec fails with a diffable failure.
|
105
|
+
# In the more common case of all specs passing or the only failures being
|
106
|
+
# non-diffable, we can avoid the extra cost of loading the differ, diff-lcs,
|
107
|
+
# pp, etc by avoiding an unnecessary require. Instead, autoload will take
|
108
|
+
# care of loading the differ on first use.
|
109
|
+
autoload :Differ, "rspec/support/differ"
|
75
110
|
end
|
76
111
|
end
|
data/lib/rspec/support/differ.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
RSpec::Support.require_rspec_support 'encoded_string'
|
2
2
|
RSpec::Support.require_rspec_support 'hunk_generator'
|
3
|
+
RSpec::Support.require_rspec_support "object_formatter"
|
3
4
|
|
4
5
|
require 'pp'
|
5
6
|
|
@@ -25,7 +26,7 @@ module RSpec
|
|
25
26
|
|
26
27
|
# rubocop:disable MethodLength
|
27
28
|
def diff_as_string(actual, expected)
|
28
|
-
encoding = pick_encoding(actual, expected)
|
29
|
+
encoding = EncodedString.pick_encoding(actual, expected)
|
29
30
|
|
30
31
|
actual = EncodedString.new(actual, encoding)
|
31
32
|
expected = EncodedString.new(expected, encoding)
|
@@ -59,8 +60,9 @@ module RSpec
|
|
59
60
|
diff_as_string(actual_as_string, expected_as_string)
|
60
61
|
end
|
61
62
|
|
62
|
-
|
63
|
-
|
63
|
+
def color?
|
64
|
+
@color
|
65
|
+
end
|
64
66
|
|
65
67
|
def initialize(opts={})
|
66
68
|
@color = opts.fetch(:color, false)
|
@@ -177,12 +179,9 @@ module RSpec
|
|
177
179
|
object = @object_preparer.call(object)
|
178
180
|
case object
|
179
181
|
when Hash
|
180
|
-
object
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
"#{pp_key} => #{pp_value},"
|
185
|
-
end.join("\n")
|
182
|
+
hash_to_string(object)
|
183
|
+
when Array
|
184
|
+
PP.pp(ObjectFormatter.prepare_for_inspection(object), "")
|
186
185
|
when String
|
187
186
|
object =~ /\n/ ? object : object.inspect
|
188
187
|
else
|
@@ -190,13 +189,14 @@ module RSpec
|
|
190
189
|
end
|
191
190
|
end
|
192
191
|
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
192
|
+
def hash_to_string(hash)
|
193
|
+
formatted_hash = ObjectFormatter.prepare_for_inspection(hash)
|
194
|
+
formatted_hash.keys.sort_by { |k| k.to_s }.map do |key|
|
195
|
+
pp_key = PP.singleline_pp(key, "")
|
196
|
+
pp_value = PP.singleline_pp(formatted_hash[key], "")
|
197
|
+
|
198
|
+
"#{pp_key} => #{pp_value},"
|
199
|
+
end.join("\n")
|
200
200
|
end
|
201
201
|
|
202
202
|
def handle_encoding_errors(actual, expected)
|
@@ -131,8 +131,15 @@ module RSpec
|
|
131
131
|
def detect_source_encoding(string)
|
132
132
|
string.encoding
|
133
133
|
end
|
134
|
+
|
135
|
+
def self.pick_encoding(source_a, source_b)
|
136
|
+
Encoding.compatible?(source_a, source_b) || Encoding.default_external
|
137
|
+
end
|
134
138
|
else
|
135
139
|
|
140
|
+
def self.pick_encoding(_source_a, _source_b)
|
141
|
+
end
|
142
|
+
|
136
143
|
private
|
137
144
|
|
138
145
|
def matching_encoding(string)
|
@@ -0,0 +1,93 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Support
|
3
|
+
# Provide additional output details beyond what `inspect` provides when
|
4
|
+
# printing Time, DateTime, or BigDecimal
|
5
|
+
module ObjectFormatter
|
6
|
+
# @api private
|
7
|
+
def self.format(object)
|
8
|
+
prepare_for_inspection(object).inspect
|
9
|
+
end
|
10
|
+
|
11
|
+
# rubocop:disable MethodLength
|
12
|
+
|
13
|
+
# @private
|
14
|
+
# Prepares the provided object to be formatted by wrapping it as needed
|
15
|
+
# in something that, when `inspect` is called on it, will produce the
|
16
|
+
# desired output.
|
17
|
+
#
|
18
|
+
# This allows us to apply the desired formatting to hash/array data structures
|
19
|
+
# at any level of nesting, simply by walking that structure and replacing items
|
20
|
+
# with custom items that have `inspect` defined to return the desired output
|
21
|
+
# for that item. Then we can just use `Array#inspect` or `Hash#inspect` to
|
22
|
+
# format the entire thing.
|
23
|
+
def self.prepare_for_inspection(object)
|
24
|
+
case object
|
25
|
+
when Array
|
26
|
+
return object.map { |o| prepare_for_inspection(o) }
|
27
|
+
when Hash
|
28
|
+
return prepare_hash(object)
|
29
|
+
when Time
|
30
|
+
inspection = format_time(object)
|
31
|
+
else
|
32
|
+
if defined?(DateTime) && DateTime === object
|
33
|
+
inspection = format_date_time(object)
|
34
|
+
elsif defined?(BigDecimal) && BigDecimal === object
|
35
|
+
inspection = "#{object.to_s 'F'} (#{object.inspect})"
|
36
|
+
elsif RSpec::Support.is_a_matcher?(object) && object.respond_to?(:description)
|
37
|
+
inspection = object.description
|
38
|
+
else
|
39
|
+
return object
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
InspectableItem.new(inspection)
|
44
|
+
end
|
45
|
+
# rubocop:enable MethodLength
|
46
|
+
|
47
|
+
# @private
|
48
|
+
def self.prepare_hash(input)
|
49
|
+
input.inject({}) do |hash, (k, v)|
|
50
|
+
hash[prepare_for_inspection(k)] = prepare_for_inspection(v)
|
51
|
+
hash
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
TIME_FORMAT = "%Y-%m-%d %H:%M:%S"
|
56
|
+
|
57
|
+
if Time.method_defined?(:nsec)
|
58
|
+
# @private
|
59
|
+
def self.format_time(time)
|
60
|
+
time.strftime("#{TIME_FORMAT}.#{"%09d" % time.nsec} %z")
|
61
|
+
end
|
62
|
+
else # for 1.8.7
|
63
|
+
# @private
|
64
|
+
def self.format_time(time)
|
65
|
+
time.strftime("#{TIME_FORMAT}.#{"%06d" % time.usec} %z")
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
DATE_TIME_FORMAT = "%a, %d %b %Y %H:%M:%S.%N %z"
|
70
|
+
# ActiveSupport sometimes overrides inspect. If `ActiveSupport` is
|
71
|
+
# defined use a custom format string that includes more time precision.
|
72
|
+
# @private
|
73
|
+
def self.format_date_time(date_time)
|
74
|
+
if defined?(ActiveSupport)
|
75
|
+
date_time.strftime(DATE_TIME_FORMAT)
|
76
|
+
else
|
77
|
+
date_time.inspect
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# @private
|
82
|
+
InspectableItem = Struct.new(:inspection) do
|
83
|
+
def inspect
|
84
|
+
inspection
|
85
|
+
end
|
86
|
+
|
87
|
+
def pretty_print(pp)
|
88
|
+
pp.text inspection
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
data/lib/rspec/support/spec.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
require 'rspec/support'
|
2
|
+
require 'rspec/support/spec/in_sub_process'
|
3
|
+
|
2
4
|
RSpec::Support.require_rspec_support "spec/deprecation_helpers"
|
3
5
|
RSpec::Support.require_rspec_support "spec/with_isolated_stderr"
|
4
6
|
RSpec::Support.require_rspec_support "spec/stderr_splitter"
|
@@ -12,14 +14,15 @@ RSpec.configure do |c|
|
|
12
14
|
c.include RSpecHelpers
|
13
15
|
c.include RSpec::Support::WithIsolatedStdErr
|
14
16
|
c.include RSpec::Support::FormattingSupport
|
17
|
+
c.include RSpec::Support::InSubProcess
|
15
18
|
|
16
19
|
unless defined?(Debugger) # debugger causes warnings when used
|
17
20
|
c.before do
|
18
21
|
warning_preventer.reset!
|
19
22
|
end
|
20
23
|
|
21
|
-
c.after do
|
22
|
-
warning_preventer.
|
24
|
+
c.after do
|
25
|
+
warning_preventer.verify_no_warnings!
|
23
26
|
end
|
24
27
|
end
|
25
28
|
|
@@ -30,6 +33,7 @@ RSpec.configure do |c|
|
|
30
33
|
|
31
34
|
c.filter_run :focus
|
32
35
|
c.run_all_when_everything_filtered = true
|
36
|
+
c.example_status_persistence_file_path = "./spec/examples.txt"
|
33
37
|
|
34
38
|
c.define_derived_metadata :failing_on_appveyor do |meta|
|
35
39
|
meta[:pending] ||= "This spec fails on AppVeyor and needs someone to fix it."
|
@@ -43,7 +47,8 @@ module RSpec
|
|
43
47
|
# Simplecov emits some ruby warnings when loaded, so silence them.
|
44
48
|
old_verbose, $VERBOSE = $VERBOSE, false
|
45
49
|
|
46
|
-
return if ENV['NO_COVERAGE'] || RUBY_VERSION < '1.9.3'
|
50
|
+
return if ENV['NO_COVERAGE'] || RUBY_VERSION < '1.9.3'
|
51
|
+
return if RUBY_ENGINE != 'ruby' || RSpec::Support::OS.windows?
|
47
52
|
|
48
53
|
# Don't load it when we're running a single isolated
|
49
54
|
# test file rather than the whole suite.
|
@@ -15,7 +15,7 @@ module RSpec
|
|
15
15
|
|
16
16
|
begin
|
17
17
|
yield
|
18
|
-
warning_preventer.
|
18
|
+
warning_preventer.verify_no_warnings! if prevent_warnings
|
19
19
|
rescue Exception => e
|
20
20
|
exception = e
|
21
21
|
end
|
@@ -35,13 +35,18 @@ module RSpec
|
|
35
35
|
|
36
36
|
raise exception if exception
|
37
37
|
end
|
38
|
+
# rubocop:enable MethodLength
|
39
|
+
alias :in_sub_process_if_possible :in_sub_process
|
38
40
|
else
|
39
41
|
def in_sub_process(*)
|
40
42
|
skip "This spec requires forking to work properly, " \
|
41
43
|
"and your platform does not support forking"
|
42
44
|
end
|
45
|
+
|
46
|
+
def in_sub_process_if_possible(*)
|
47
|
+
yield
|
48
|
+
end
|
43
49
|
end
|
44
|
-
# rubocop:enable MethodLength
|
45
50
|
end
|
46
51
|
end
|
47
52
|
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
require 'rspec/support/spec/shell_out'
|
2
|
+
|
3
|
+
RSpec.shared_examples_for "library wide checks" do |lib, options|
|
4
|
+
consider_a_test_env_file = options.fetch(:consider_a_test_env_file, /MATCHES NOTHING/)
|
5
|
+
allowed_loaded_feature_regexps = options.fetch(:allowed_loaded_feature_regexps, [])
|
6
|
+
preamble_for_lib = options[:preamble_for_lib]
|
7
|
+
preamble_for_spec = "require 'rspec/core'; require 'spec_helper'"
|
8
|
+
skip_spec_files = options.fetch(:skip_spec_files, /MATCHES NOTHING/)
|
9
|
+
|
10
|
+
include RSpec::Support::ShellOut
|
11
|
+
|
12
|
+
define_method :files_to_require_for do |sub_dir|
|
13
|
+
slash = File::SEPARATOR
|
14
|
+
lib_path_re = /#{slash + lib}[^#{slash}]*#{slash}lib/
|
15
|
+
load_path = $LOAD_PATH.grep(lib_path_re).first
|
16
|
+
directory = load_path.sub(/lib$/, sub_dir)
|
17
|
+
files = Dir["#{directory}/**/*.rb"]
|
18
|
+
extract_regex = /#{Regexp.escape(directory) + File::SEPARATOR}(.+)\.rb$/
|
19
|
+
|
20
|
+
# We sort to ensure the files are loaded in a consistent order, regardless
|
21
|
+
# of OS. Otherwise, it could load in a different order on Travis than
|
22
|
+
# locally, and potentially trigger a "circular require considered harmful"
|
23
|
+
# warning or similar.
|
24
|
+
files.sort.map { |file| file[extract_regex, 1] }
|
25
|
+
end
|
26
|
+
|
27
|
+
def command_from(code_lines)
|
28
|
+
code_lines.join("\n")
|
29
|
+
end
|
30
|
+
|
31
|
+
def load_all_files(files, preamble, postamble=nil)
|
32
|
+
requires = files.map { |f| "require '#{f}'" }
|
33
|
+
command = command_from(Array(preamble) + requires + Array(postamble))
|
34
|
+
|
35
|
+
stdout, stderr, status = with_env 'NO_COVERAGE' => '1' do
|
36
|
+
options = %w[ -w ]
|
37
|
+
options << "--disable=gem" if RUBY_VERSION.to_f >= 1.9 && RSpec::Support::Ruby.mri?
|
38
|
+
run_ruby_with_current_load_path(command, *options)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Ignore bundler warning.
|
42
|
+
stderr = stderr.split("\n").reject { |l| l =~ %r{bundler/source/rubygems} }.join("\n")
|
43
|
+
[stdout, stderr, status.exitstatus]
|
44
|
+
end
|
45
|
+
|
46
|
+
define_method :load_all_lib_files do
|
47
|
+
files = all_lib_files - lib_test_env_files
|
48
|
+
preamble = ['orig_loaded_features = $".dup', preamble_for_lib]
|
49
|
+
postamble = ['puts(($" - orig_loaded_features).join("\n"))']
|
50
|
+
|
51
|
+
@loaded_feature_lines, stderr, exitstatus = load_all_files(files, preamble, postamble)
|
52
|
+
["", stderr, exitstatus]
|
53
|
+
end
|
54
|
+
|
55
|
+
define_method :load_all_spec_files do
|
56
|
+
files = files_to_require_for("spec") + lib_test_env_files
|
57
|
+
files = files.reject { |f| f =~ skip_spec_files }
|
58
|
+
load_all_files(files, preamble_for_spec)
|
59
|
+
end
|
60
|
+
|
61
|
+
attr_reader :all_lib_files, :lib_test_env_files,
|
62
|
+
:lib_file_results, :spec_file_results
|
63
|
+
|
64
|
+
before(:context) do
|
65
|
+
@all_lib_files = files_to_require_for("lib")
|
66
|
+
@lib_test_env_files = all_lib_files.grep(consider_a_test_env_file)
|
67
|
+
|
68
|
+
@lib_file_results, @spec_file_results = [
|
69
|
+
# Load them in parallel so it's faster...
|
70
|
+
Thread.new { load_all_lib_files },
|
71
|
+
Thread.new { load_all_spec_files }
|
72
|
+
].map(&:join).map(&:value)
|
73
|
+
end
|
74
|
+
|
75
|
+
def have_successful_no_warnings_output
|
76
|
+
eq ["", "", 0]
|
77
|
+
end
|
78
|
+
|
79
|
+
it "issues no warnings when loaded", :slow do
|
80
|
+
expect(lib_file_results).to have_successful_no_warnings_output
|
81
|
+
end
|
82
|
+
|
83
|
+
it "issues no warnings when the spec files are loaded", :slow do
|
84
|
+
expect(spec_file_results).to have_successful_no_warnings_output
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'only loads a known set of stdlibs so gem authors are forced ' \
|
88
|
+
'to load libs they use to have passing specs', :slow do
|
89
|
+
loaded_features = @loaded_feature_lines.split("\n")
|
90
|
+
if RUBY_VERSION == '1.8.7'
|
91
|
+
# On 1.8.7, $" returns the relative require path if that was used
|
92
|
+
# to require the file. LIB_REGEX will not match the relative version
|
93
|
+
# since it has a `/lib` prefix. Here we deal with this by expanding
|
94
|
+
# relative files relative to the $LOAD_PATH dir (lib).
|
95
|
+
Dir.chdir("lib") { loaded_features.map! { |f| File.expand_path(f) } }
|
96
|
+
end
|
97
|
+
|
98
|
+
loaded_features.reject! { |feature| RSpec::CallerFilter::LIB_REGEX =~ feature }
|
99
|
+
loaded_features.reject! { |feature| allowed_loaded_feature_regexps.any? { |r| r =~ feature } }
|
100
|
+
|
101
|
+
expect(loaded_features).to eq([])
|
102
|
+
end
|
103
|
+
|
104
|
+
# This malformed whitespace detection logic has been borrowed from bundler:
|
105
|
+
# https://github.com/bundler/bundler/blob/v1.8.0/spec/quality_spec.rb
|
106
|
+
def check_for_tab_characters(filename)
|
107
|
+
failing_lines = []
|
108
|
+
File.readlines(filename).each_with_index do |line, number|
|
109
|
+
failing_lines << number + 1 if line =~ /\t/
|
110
|
+
end
|
111
|
+
|
112
|
+
return if failing_lines.empty?
|
113
|
+
"#{filename} has tab characters on lines #{failing_lines.join(', ')}"
|
114
|
+
end
|
115
|
+
|
116
|
+
def check_for_extra_spaces(filename)
|
117
|
+
failing_lines = []
|
118
|
+
File.readlines(filename).each_with_index do |line, number|
|
119
|
+
next if line =~ /^\s+#.*\s+\n$/
|
120
|
+
failing_lines << number + 1 if line =~ /\s+\n$/
|
121
|
+
end
|
122
|
+
|
123
|
+
return if failing_lines.empty?
|
124
|
+
"#{filename} has spaces on the EOL on lines #{failing_lines.join(', ')}"
|
125
|
+
end
|
126
|
+
|
127
|
+
RSpec::Matchers.define :be_well_formed do
|
128
|
+
match do |actual|
|
129
|
+
actual.empty?
|
130
|
+
end
|
131
|
+
|
132
|
+
failure_message do |actual|
|
133
|
+
actual.join("\n")
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
it "has no malformed whitespace", :slow do
|
138
|
+
error_messages = []
|
139
|
+
`git ls-files -z`.split("\x0").each do |filename|
|
140
|
+
error_messages << check_for_tab_characters(filename)
|
141
|
+
error_messages << check_for_extra_spaces(filename)
|
142
|
+
end
|
143
|
+
expect(error_messages.compact).to be_well_formed
|
144
|
+
end
|
145
|
+
end
|
@@ -22,6 +22,9 @@ module RSpec
|
|
22
22
|
return stdout, filter(stderr), status
|
23
23
|
end
|
24
24
|
else # 1.8.7
|
25
|
+
# popen3 doesn't provide the exit status so we fake it out.
|
26
|
+
FakeProcessStatus = Struct.new(:exitstatus)
|
27
|
+
|
25
28
|
def shell_out(*command)
|
26
29
|
stdout = stderr = nil
|
27
30
|
|
@@ -30,8 +33,7 @@ module RSpec
|
|
30
33
|
stderr = err.read
|
31
34
|
end
|
32
35
|
|
33
|
-
|
34
|
-
status = instance_double(Process::Status, :exitstatus => 0)
|
36
|
+
status = FakeProcessStatus.new(0)
|
35
37
|
return stdout, filter(stderr), status
|
36
38
|
end
|
37
39
|
end
|
@@ -50,8 +50,8 @@ module RSpec
|
|
50
50
|
@output_tracker = ::StringIO.new
|
51
51
|
end
|
52
52
|
|
53
|
-
def
|
54
|
-
|
53
|
+
def verify_no_warnings!
|
54
|
+
raise "Warnings were generated: #{output}" if has_output?
|
55
55
|
reset!
|
56
56
|
end
|
57
57
|
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'rspec/matchers'
|
2
|
+
# Special matcher for comparing encoded strings so that
|
3
|
+
# we don't run any expectation failures through the Differ,
|
4
|
+
# which also relies on EncodedString. Instead, confirm the
|
5
|
+
# strings have the same bytes.
|
6
|
+
RSpec::Matchers.define :be_identical_string do |expected|
|
7
|
+
|
8
|
+
if String.method_defined?(:encoding)
|
9
|
+
match do
|
10
|
+
expected_encoding? &&
|
11
|
+
actual.bytes.to_a == expected.bytes.to_a
|
12
|
+
end
|
13
|
+
|
14
|
+
failure_message do
|
15
|
+
"expected\n#{actual.inspect} (#{actual.encoding.name}) to be identical to\n"\
|
16
|
+
"#{expected.inspect} (#{expected.encoding.name})\n"\
|
17
|
+
"The exact bytes are printed below for more detail:\n"\
|
18
|
+
"#{actual.bytes.to_a}\n"\
|
19
|
+
"#{expected.bytes.to_a}\n"\
|
20
|
+
end
|
21
|
+
|
22
|
+
# Depends on chaining :with_same_encoding for it to
|
23
|
+
# check for string encoding.
|
24
|
+
def expected_encoding?
|
25
|
+
if defined?(@expect_same_encoding) && @expect_same_encoding
|
26
|
+
actual.encoding == expected.encoding
|
27
|
+
else
|
28
|
+
true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
else
|
32
|
+
match do
|
33
|
+
actual.split(//) == expected.split(//)
|
34
|
+
end
|
35
|
+
|
36
|
+
failure_message do
|
37
|
+
"expected\n#{actual.inspect} to be identical to\n#{expected.inspect}\n"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
chain :with_same_encoding do
|
42
|
+
@expect_same_encoding ||= true
|
43
|
+
end
|
44
|
+
end
|
45
|
+
RSpec::Matchers.alias_matcher :a_string_identical_to, :be_identical_string
|
46
|
+
RSpec::Matchers.alias_matcher :be_diffed_as, :be_identical_string
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-support
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Chelimsky
|
@@ -48,7 +48,7 @@ cert_chain:
|
|
48
48
|
ZsVDj6a7lH3cNqtWXZxrb2wO38qV5AkYj8SQK7Hj3/Yui9myUX3crr+PdetazSqQ
|
49
49
|
F3MdtaDehhjC
|
50
50
|
-----END CERTIFICATE-----
|
51
|
-
date: 2015-
|
51
|
+
date: 2015-06-12 00:00:00.000000000 Z
|
52
52
|
dependencies:
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
54
|
name: bundler
|
@@ -96,15 +96,17 @@ files:
|
|
96
96
|
- lib/rspec/support/hunk_generator.rb
|
97
97
|
- lib/rspec/support/matcher_definition.rb
|
98
98
|
- lib/rspec/support/method_signature_verifier.rb
|
99
|
+
- lib/rspec/support/object_formatter.rb
|
99
100
|
- lib/rspec/support/recursive_const_methods.rb
|
100
101
|
- lib/rspec/support/ruby_features.rb
|
101
102
|
- lib/rspec/support/spec.rb
|
102
103
|
- lib/rspec/support/spec/deprecation_helpers.rb
|
103
104
|
- lib/rspec/support/spec/formatting_support.rb
|
104
105
|
- lib/rspec/support/spec/in_sub_process.rb
|
105
|
-
- lib/rspec/support/spec/
|
106
|
+
- lib/rspec/support/spec/library_wide_checks.rb
|
106
107
|
- lib/rspec/support/spec/shell_out.rb
|
107
108
|
- lib/rspec/support/spec/stderr_splitter.rb
|
109
|
+
- lib/rspec/support/spec/string_matcher.rb
|
108
110
|
- lib/rspec/support/spec/with_isolated_directory.rb
|
109
111
|
- lib/rspec/support/spec/with_isolated_stderr.rb
|
110
112
|
- lib/rspec/support/version.rb
|
@@ -130,9 +132,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
130
132
|
- !ruby/object:Gem::Version
|
131
133
|
version: '0'
|
132
134
|
requirements: []
|
133
|
-
rubyforge_project:
|
135
|
+
rubyforge_project:
|
134
136
|
rubygems_version: 2.2.2
|
135
137
|
signing_key:
|
136
138
|
specification_version: 4
|
137
|
-
summary: rspec-support-3.
|
139
|
+
summary: rspec-support-3.3.0
|
138
140
|
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|
@@ -1,56 +0,0 @@
|
|
1
|
-
require 'rspec/support/spec/shell_out'
|
2
|
-
|
3
|
-
module RSpec
|
4
|
-
module Support
|
5
|
-
module WarningsPrevention
|
6
|
-
def files_to_require_for(lib, sub_dir)
|
7
|
-
slash = File::SEPARATOR
|
8
|
-
lib_path_re = /#{slash + lib}[^#{slash}]*#{slash}lib/
|
9
|
-
load_path = $LOAD_PATH.grep(lib_path_re).first
|
10
|
-
directory = load_path.sub(/lib$/, sub_dir)
|
11
|
-
files = Dir["#{directory}/**/*.rb"]
|
12
|
-
extract_regex = /#{Regexp.escape(directory) + File::SEPARATOR}(.+)\.rb$/
|
13
|
-
|
14
|
-
# We sort to ensure the files are loaded in a consistent order, regardless
|
15
|
-
# of OS. Otherwise, it could load in a different order on Travis than
|
16
|
-
# locally, and potentially trigger a "circular require considered harmful"
|
17
|
-
# warning or similar.
|
18
|
-
files.sort.map { |file| file[extract_regex, 1] }
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
RSpec.shared_examples_for "a library that issues no warnings when loaded" do |lib, *preamble_stmnts|
|
25
|
-
include RSpec::Support::ShellOut
|
26
|
-
include RSpec::Support::WarningsPrevention
|
27
|
-
|
28
|
-
define_method :expect_no_warnings_from_files_in do |sub_dir, *pre_stmnts|
|
29
|
-
# We want to explicitly load every file because each lib has some files that
|
30
|
-
# aren't automatically loaded, instead being delayed based on an autoload
|
31
|
-
# (such as for rspec-expectations' matchers) or based on a config option
|
32
|
-
# (e.g. `config.mock_with :rr` => 'rspec/core/mocking_adapters/rr').
|
33
|
-
files_to_require = files_to_require_for(lib, sub_dir)
|
34
|
-
statements = pre_stmnts + files_to_require.map do |file|
|
35
|
-
"require '#{file}'"
|
36
|
-
end
|
37
|
-
|
38
|
-
command = statements.join("; ")
|
39
|
-
|
40
|
-
stdout, stderr, status = with_env 'NO_COVERAGE' => '1' do
|
41
|
-
run_ruby_with_current_load_path(command, "-w")
|
42
|
-
end
|
43
|
-
|
44
|
-
expect(stdout).to eq("")
|
45
|
-
expect(stderr).to eq("")
|
46
|
-
expect(status.exitstatus).to eq(0)
|
47
|
-
end
|
48
|
-
|
49
|
-
it "issues no warnings when loaded", :slow do
|
50
|
-
expect_no_warnings_from_files_in "lib", *preamble_stmnts
|
51
|
-
end
|
52
|
-
|
53
|
-
it "issues no warnings when the spec files are loaded", :slow do
|
54
|
-
expect_no_warnings_from_files_in "spec", "require 'rspec/core'; require 'spec_helper'"
|
55
|
-
end
|
56
|
-
end
|