guard-rspec 4.3.1 → 4.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.hound.yml +262 -0
- data/.rspec +2 -0
- data/.rubocop.yml +2 -0
- data/.rubocop_todo.yml +10 -0
- data/.travis.yml +2 -3
- data/CONTRIBUTING.md +1 -1
- data/Gemfile +9 -2
- data/Guardfile +11 -4
- data/README.md +8 -4
- data/Rakefile +23 -2
- data/gemfiles/Gemfile.rspec-2.14 +1 -0
- data/gemfiles/Gemfile.rspec-2.99 +14 -0
- data/gemfiles/Gemfile.rspec-3.0 +1 -0
- data/guard-rspec.gemspec +18 -16
- data/lib/guard/rspec.rb +13 -8
- data/lib/guard/rspec/command.rb +30 -12
- data/lib/guard/rspec/deprecator.rb +32 -11
- data/lib/guard/rspec/inspectors/base_inspector.rb +36 -15
- data/lib/guard/rspec/inspectors/factory.rb +7 -8
- data/lib/guard/rspec/inspectors/focused_inspector.rb +2 -2
- data/lib/guard/rspec/inspectors/keeping_inspector.rb +7 -6
- data/lib/guard/rspec/inspectors/simple_inspector.rb +3 -3
- data/lib/guard/rspec/notifier.rb +9 -5
- data/lib/guard/rspec/options.rb +12 -10
- data/lib/guard/rspec/runner.rb +41 -25
- data/lib/guard/rspec/templates/Guardfile +43 -15
- data/lib/guard/rspec/version.rb +1 -1
- data/lib/guard/rspec_formatter.rb +111 -0
- data/spec/lib/guard/rspec/command_spec.rb +48 -12
- data/spec/lib/guard/rspec/deprecator_spec.rb +37 -18
- data/spec/lib/guard/rspec/inspectors/base_inspector_spec.rb +129 -18
- data/spec/lib/guard/rspec/inspectors/factory_spec.rb +20 -15
- data/spec/lib/guard/rspec/inspectors/focused_inspector_spec.rb +79 -13
- data/spec/lib/guard/rspec/inspectors/keeping_inspector_spec.rb +103 -33
- data/spec/lib/guard/rspec/inspectors/shared_examples.rb +93 -31
- data/spec/lib/guard/rspec/inspectors/simple_inspector_spec.rb +52 -16
- data/spec/lib/guard/rspec/notifier_spec.rb +49 -27
- data/spec/lib/guard/rspec/runner_spec.rb +120 -77
- data/spec/lib/guard/rspec_formatter_spec.rb +144 -0
- data/spec/lib/guard/rspec_spec.rb +23 -18
- data/spec/spec_helper.rb +99 -14
- metadata +12 -7
- data/lib/guard/rspec/formatter.rb +0 -99
- data/spec/lib/guard/rspec/formatter_spec.rb +0 -122
@@ -1,99 +0,0 @@
|
|
1
|
-
require 'guard/rspec'
|
2
|
-
require 'rspec/core/formatters/base_formatter'
|
3
|
-
|
4
|
-
module Guard
|
5
|
-
class RSpec
|
6
|
-
class Formatter < ::RSpec::Core::Formatters::BaseFormatter
|
7
|
-
TEMPORARY_FILE_PATH ||= File.expand_path('./tmp/rspec_guard_result')
|
8
|
-
|
9
|
-
def self.rspec_3?
|
10
|
-
::RSpec::Core::Version::STRING.split('.').first == "3"
|
11
|
-
end
|
12
|
-
|
13
|
-
if rspec_3?
|
14
|
-
::RSpec::Core::Formatters.register self, :dump_summary, :example_failed
|
15
|
-
|
16
|
-
def example_failed(failure)
|
17
|
-
examples.push failure.example
|
18
|
-
end
|
19
|
-
|
20
|
-
def examples
|
21
|
-
@examples ||= []
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
# rspec issue https://github.com/rspec/rspec-core/issues/793
|
26
|
-
def self.extract_spec_location(metadata)
|
27
|
-
root_metadata = metadata
|
28
|
-
location = metadata[:location]
|
29
|
-
|
30
|
-
until spec_path?(location)
|
31
|
-
metadata = metadata[:example_group]
|
32
|
-
|
33
|
-
if !metadata
|
34
|
-
Guard::UI.warning "no spec file found for #{root_metadata[:location]}"
|
35
|
-
return root_metadata[:location]
|
36
|
-
end
|
37
|
-
|
38
|
-
location = (metadata[:location] || "").split(':').first # rspec issue https://github.com/rspec/rspec-core/issues/1243
|
39
|
-
end
|
40
|
-
|
41
|
-
location
|
42
|
-
end
|
43
|
-
|
44
|
-
def self.spec_path?(path)
|
45
|
-
path ||= ""
|
46
|
-
flags = File::FNM_PATHNAME | File::FNM_DOTMATCH
|
47
|
-
if File.const_defined?(:FNM_EXTGLOB) # ruby >= 2
|
48
|
-
flags |= File::FNM_EXTGLOB
|
49
|
-
end
|
50
|
-
File.fnmatch(::RSpec.configuration.pattern, path.sub(/:\d+\z/, ''), flags)
|
51
|
-
end
|
52
|
-
|
53
|
-
def dump_summary(*args)
|
54
|
-
if self.class.rspec_3?
|
55
|
-
notification = args[0]
|
56
|
-
write_summary(
|
57
|
-
notification.duration,
|
58
|
-
notification.example_count,
|
59
|
-
notification.failure_count,
|
60
|
-
notification.pending_count
|
61
|
-
)
|
62
|
-
else
|
63
|
-
write_summary(*args)
|
64
|
-
end
|
65
|
-
rescue
|
66
|
-
# nothing really we can do, at least don't kill the test runner
|
67
|
-
end
|
68
|
-
|
69
|
-
# Write summary to temporary file for runner
|
70
|
-
def write_summary(duration, total, failures, pending)
|
71
|
-
_write do |f|
|
72
|
-
f.puts _message(total, failures, pending, duration)
|
73
|
-
f.puts _failed_paths.join("\n") if failures > 0
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
private
|
78
|
-
|
79
|
-
def _write(&block)
|
80
|
-
FileUtils.mkdir_p(File.dirname(TEMPORARY_FILE_PATH))
|
81
|
-
File.open(TEMPORARY_FILE_PATH, 'w', &block)
|
82
|
-
end
|
83
|
-
|
84
|
-
def _failed_paths
|
85
|
-
failed = examples.select { |e| e.execution_result[:status].to_s == 'failed' }
|
86
|
-
failed.map { |e| self.class.extract_spec_location(e.metadata) }.sort.uniq
|
87
|
-
end
|
88
|
-
|
89
|
-
def _message(example_count, failure_count, pending_count, duration)
|
90
|
-
message = "#{example_count} examples, #{failure_count} failures"
|
91
|
-
if pending_count > 0
|
92
|
-
message << " (#{pending_count} pending)"
|
93
|
-
end
|
94
|
-
message << " in #{duration.round(4)} seconds"
|
95
|
-
message
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
@@ -1,122 +0,0 @@
|
|
1
|
-
require 'spec_helper.rb'
|
2
|
-
require 'guard/rspec/formatter'
|
3
|
-
|
4
|
-
describe Guard::RSpec::Formatter do
|
5
|
-
describe '::TEMPORARY_FILE_PATH' do
|
6
|
-
it 'is absolute path' do
|
7
|
-
require 'pathname'
|
8
|
-
temporary_file_path = described_class.const_get(:TEMPORARY_FILE_PATH)
|
9
|
-
expect(Pathname.new(temporary_file_path).absolute?).to eq(true)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
describe '#write_summary' do
|
14
|
-
let(:writer) {
|
15
|
-
StringIO.new
|
16
|
-
}
|
17
|
-
let(:formatter) {
|
18
|
-
Guard::RSpec::Formatter.new(StringIO.new).tap do |formatter|
|
19
|
-
formatter.stub(:_write) do |&block|
|
20
|
-
block.call writer
|
21
|
-
end
|
22
|
-
end
|
23
|
-
}
|
24
|
-
let(:result) {
|
25
|
-
writer.rewind
|
26
|
-
writer.read
|
27
|
-
}
|
28
|
-
|
29
|
-
context 'without stubbed IO' do
|
30
|
-
let(:formatter) {
|
31
|
-
Guard::RSpec::Formatter.new(StringIO.new)
|
32
|
-
}
|
33
|
-
|
34
|
-
it 'creates temporary file and and writes to it' do
|
35
|
-
temporary_file_path = described_class.const_get(:TEMPORARY_FILE_PATH)
|
36
|
-
expect(FileUtils).to receive(:mkdir_p).with(File.dirname(temporary_file_path)) {}
|
37
|
-
expect(File).to receive(:open).with(temporary_file_path, 'w') { |filename, mode, &block| block.call writer }
|
38
|
-
formatter.write_summary(123, 1, 2, 3)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
context 'with failures' do
|
43
|
-
let(:spec_filename) {
|
44
|
-
'failed_location_spec.rb'
|
45
|
-
}
|
46
|
-
let(:failed_example) { double(
|
47
|
-
execution_result: { status: 'failed' },
|
48
|
-
metadata: { location: spec_filename }
|
49
|
-
) }
|
50
|
-
|
51
|
-
it 'writes summary line and failed location in tmp dir' do
|
52
|
-
allow(formatter).to receive(:examples) { [failed_example] }
|
53
|
-
formatter.write_summary(123, 3, 1, 0)
|
54
|
-
expect(result).to match /^3 examples, 1 failures in 123\.0 seconds\n#{spec_filename}\n$/
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'writes only uniq filenames out' do
|
58
|
-
allow(formatter).to receive(:examples) { [failed_example, failed_example] }
|
59
|
-
formatter.write_summary(123, 3, 1, 0)
|
60
|
-
expect(result).to match /^3 examples, 1 failures in 123\.0 seconds\n#{spec_filename}\n$/
|
61
|
-
end
|
62
|
-
|
63
|
-
context "for rspec 3" do
|
64
|
-
let(:notification) {
|
65
|
-
Struct.new(:duration, :example_count, :failure_count, :pending_count).new(123, 3, 1, 0)
|
66
|
-
}
|
67
|
-
before do
|
68
|
-
formatter.class.stub(:rspec_3?).and_return(true)
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'writes summary line and failed location' do
|
72
|
-
allow(formatter).to receive(:examples) { [failed_example] }
|
73
|
-
formatter.dump_summary(notification)
|
74
|
-
expect(result).to match /^3 examples, 1 failures in 123\.0 seconds\n#{spec_filename}\n$/
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'should find the spec file for shared examples' do
|
80
|
-
metadata = {
|
81
|
-
location: './spec/support/breadcrumbs.rb:75',
|
82
|
-
example_group: { location: './spec/requests/breadcrumbs_spec.rb:218' }
|
83
|
-
}
|
84
|
-
|
85
|
-
expect(described_class.extract_spec_location(metadata)).to start_with './spec/requests/breadcrumbs_spec.rb'
|
86
|
-
end
|
87
|
-
|
88
|
-
# Skip location because of rspec issue https://github.com/rspec/rspec-core/issues/1243
|
89
|
-
it 'should return only the spec file without line number for shared examples' do
|
90
|
-
metadata = {
|
91
|
-
location: './spec/support/breadcrumbs.rb:75',
|
92
|
-
example_group: { location: './spec/requests/breadcrumbs_spec.rb:218' }
|
93
|
-
}
|
94
|
-
|
95
|
-
expect(described_class.extract_spec_location(metadata)).to eq './spec/requests/breadcrumbs_spec.rb'
|
96
|
-
end
|
97
|
-
|
98
|
-
it 'should return location of the root spec when a shared examples has no location' do
|
99
|
-
metadata = {
|
100
|
-
location: './spec/support/breadcrumbs.rb:75',
|
101
|
-
example_group: {}
|
102
|
-
}
|
103
|
-
|
104
|
-
expect(Guard::UI).to receive(:warning).with("no spec file found for #{metadata[:location]}") {}
|
105
|
-
expect(described_class.extract_spec_location(metadata)).to eq metadata[:location]
|
106
|
-
end
|
107
|
-
|
108
|
-
context 'with only success' do
|
109
|
-
it 'notifies success' do
|
110
|
-
formatter.write_summary(123, 3, 0, 0)
|
111
|
-
expect(result).to match /^3 examples, 0 failures in 123\.0 seconds\n$/
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
context 'with pending' do
|
116
|
-
it "notifies pending too" do
|
117
|
-
formatter.write_summary(123, 3, 0, 1)
|
118
|
-
expect(result).to match /^3 examples, 0 failures \(1 pending\) in 123\.0 seconds\n$/
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|