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.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.hound.yml +262 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +2 -0
  5. data/.rubocop_todo.yml +10 -0
  6. data/.travis.yml +2 -3
  7. data/CONTRIBUTING.md +1 -1
  8. data/Gemfile +9 -2
  9. data/Guardfile +11 -4
  10. data/README.md +8 -4
  11. data/Rakefile +23 -2
  12. data/gemfiles/Gemfile.rspec-2.14 +1 -0
  13. data/gemfiles/Gemfile.rspec-2.99 +14 -0
  14. data/gemfiles/Gemfile.rspec-3.0 +1 -0
  15. data/guard-rspec.gemspec +18 -16
  16. data/lib/guard/rspec.rb +13 -8
  17. data/lib/guard/rspec/command.rb +30 -12
  18. data/lib/guard/rspec/deprecator.rb +32 -11
  19. data/lib/guard/rspec/inspectors/base_inspector.rb +36 -15
  20. data/lib/guard/rspec/inspectors/factory.rb +7 -8
  21. data/lib/guard/rspec/inspectors/focused_inspector.rb +2 -2
  22. data/lib/guard/rspec/inspectors/keeping_inspector.rb +7 -6
  23. data/lib/guard/rspec/inspectors/simple_inspector.rb +3 -3
  24. data/lib/guard/rspec/notifier.rb +9 -5
  25. data/lib/guard/rspec/options.rb +12 -10
  26. data/lib/guard/rspec/runner.rb +41 -25
  27. data/lib/guard/rspec/templates/Guardfile +43 -15
  28. data/lib/guard/rspec/version.rb +1 -1
  29. data/lib/guard/rspec_formatter.rb +111 -0
  30. data/spec/lib/guard/rspec/command_spec.rb +48 -12
  31. data/spec/lib/guard/rspec/deprecator_spec.rb +37 -18
  32. data/spec/lib/guard/rspec/inspectors/base_inspector_spec.rb +129 -18
  33. data/spec/lib/guard/rspec/inspectors/factory_spec.rb +20 -15
  34. data/spec/lib/guard/rspec/inspectors/focused_inspector_spec.rb +79 -13
  35. data/spec/lib/guard/rspec/inspectors/keeping_inspector_spec.rb +103 -33
  36. data/spec/lib/guard/rspec/inspectors/shared_examples.rb +93 -31
  37. data/spec/lib/guard/rspec/inspectors/simple_inspector_spec.rb +52 -16
  38. data/spec/lib/guard/rspec/notifier_spec.rb +49 -27
  39. data/spec/lib/guard/rspec/runner_spec.rb +120 -77
  40. data/spec/lib/guard/rspec_formatter_spec.rb +144 -0
  41. data/spec/lib/guard/rspec_spec.rb +23 -18
  42. data/spec/spec_helper.rb +99 -14
  43. metadata +12 -7
  44. data/lib/guard/rspec/formatter.rb +0 -99
  45. data/spec/lib/guard/rspec/formatter_spec.rb +0 -122
@@ -1,58 +1,120 @@
1
- require 'spec_helper'
2
-
3
- shared_examples 'inspector' do |klass|
4
- let(:spec_paths) { %w[spec myspec] }
5
- let(:options) { { custom: 'value', spec_paths: spec_paths } }
1
+ RSpec.shared_examples "inspector" do |klass|
2
+ let(:spec_paths) { %w(spec myspec) }
3
+ let(:options) { { custom: "value", spec_paths: spec_paths } }
6
4
  let(:inspector) { klass.new(options) }
7
5
 
8
6
  # Use real paths because BaseInspector#_clean will be used to clean them
9
- let(:paths) { [
10
- 'spec/lib/guard/rspec/inspectors/base_inspector_spec.rb',
11
- 'spec/lib/guard/rspec/runner_spec.rb',
12
- 'spec/lib/guard/rspec/deprecator_spec.rb'
13
- ] }
14
- let(:failed_locations) { [
15
- './spec/lib/guard/rspec/runner_spec.rb:12',
16
- './spec/lib/guard/rspec/deprecator_spec.rb:55'
17
- ] }
18
-
19
- describe '.initialize' do
20
- it 'sets options and spec_paths' do
7
+ let(:paths) do
8
+ [
9
+ "spec/lib/guard/rspec/inspectors/base_inspector_spec.rb",
10
+ "spec/lib/guard/rspec/runner_spec.rb",
11
+ "spec/lib/guard/rspec/deprecator_spec.rb"
12
+ ]
13
+ end
14
+ let(:failed_locations) do
15
+ [
16
+ "./spec/lib/guard/rspec/runner_spec.rb:12",
17
+ "./spec/lib/guard/rspec/deprecator_spec.rb:55"
18
+ ]
19
+ end
20
+
21
+ describe ".initialize" do
22
+ it "sets options and spec_paths" do
21
23
  expect(inspector.options).to include(:custom, :spec_paths)
22
- expect(inspector.options[:custom]).to eq('value')
24
+ expect(inspector.options[:custom]).to eq("value")
23
25
  expect(inspector.spec_paths).to eq(spec_paths)
24
26
  end
25
27
  end
26
28
 
27
- describe '#paths' do
28
- it 'returns paths when called first time' do
29
+ describe "#paths" do
30
+ before do
31
+ allow(Dir).to receive(:[]).with("myspec/**{,/*/**}/*[_.]spec.rb").
32
+ and_return([])
33
+
34
+ allow(Dir).to receive(:[]).with("myspec/**{,/*/**}/*.feature").
35
+ and_return([])
36
+
37
+ allow(Dir).to receive(:[]).with("spec/**{,/*/**}/*.feature").
38
+ and_return([])
39
+ end
40
+
41
+ it "returns paths when called first time" do
42
+ allow(File).to receive(:directory?).
43
+ with("spec/lib/guard/rspec/inspectors/base_inspector_spec.rb").
44
+ and_return(false)
45
+
46
+ allow(File).to receive(:directory?).
47
+ with("spec/lib/guard/rspec/runner_spec.rb").
48
+ and_return(false)
49
+
50
+ allow(File).to receive(:directory?).
51
+ with("spec/lib/guard/rspec/deprecator_spec.rb").
52
+ and_return(false)
53
+
54
+ allow(Dir).to receive(:[]).with("spec/**{,/*/**}/*[_.]spec.rb").
55
+ and_return(paths)
56
+
29
57
  expect(inspector.paths(paths)).to match_array(paths)
30
58
  end
31
59
 
32
- it 'does not return non-spec paths' do
33
- paths = %w[not_a_spec_path.rb spec/not_exist_spec.rb]
60
+ it "does not return non-spec paths" do
61
+ paths = %w(not_a_spec_path.rb spec/not_exist_spec.rb)
62
+
63
+ allow(File).to receive(:directory?).with("not_a_spec_path.rb").
64
+ and_return(false)
65
+
66
+ allow(File).to receive(:directory?).with("spec/not_exist_spec.rb").
67
+ and_return(false)
68
+
69
+ allow(Dir).to receive(:[]).with("spec/**{,/*/**}/*[_.]spec.rb").
70
+ and_return([])
71
+
34
72
  expect(inspector.paths(paths)).to eq([])
35
73
  end
36
74
 
37
- it 'uniq and compact paths' do
38
- expect(inspector.paths(paths + paths + [nil, nil, nil])).to match_array(paths)
75
+ it "uniq and compact paths" do
76
+ allow(File).to receive(:directory?).
77
+ with("spec/lib/guard/rspec/inspectors/base_inspector_spec.rb").
78
+ and_return(false)
79
+
80
+ allow(File).to receive(:directory?).
81
+ with("spec/lib/guard/rspec/runner_spec.rb").
82
+ and_return(false)
83
+
84
+ allow(File).to receive(:directory?).
85
+ with("spec/lib/guard/rspec/deprecator_spec.rb").
86
+ and_return(false)
87
+
88
+ allow(Dir).to receive(:[]).with("spec/**{,/*/**}/*[_.]spec.rb").
89
+ and_return(paths)
90
+
91
+ expect(inspector.paths(paths + paths + [nil, nil, nil])).
92
+ to match_array(paths)
39
93
  end
40
94
 
41
95
  # NOTE: I'm not sure that it is totally correct behaviour
42
- it 'return spec_paths and directories too' do
43
- paths = %w[myspec lib/guard not_exist_dir]
44
- expect(inspector.paths(paths)).to match_array(paths - ['not_exist_dir'])
96
+ it "return spec_paths and directories too" do
97
+ allow(File).to receive(:directory?).with("myspec").and_return(true)
98
+ allow(File).to receive(:directory?).with("lib/guard").and_return(true)
99
+ allow(File).to receive(:directory?).
100
+ with("not_exist_dir").and_return(false)
101
+
102
+ allow(Dir).to receive(:[]).with("spec/**{,/*/**}/*[_.]spec.rb").
103
+ and_return([])
104
+
105
+ paths = %w(myspec lib/guard not_exist_dir)
106
+ expect(inspector.paths(paths)).to match_array(paths - ["not_exist_dir"])
45
107
  end
46
108
  end
47
109
 
48
- describe '#failed' do
49
- it 'is callable' do
110
+ describe "#failed" do
111
+ it "is callable" do
50
112
  expect { inspector.failed(failed_locations) }.not_to raise_error
51
113
  end
52
114
  end
53
115
 
54
- describe '#reload' do
55
- it 'is callable' do
116
+ describe "#reload" do
117
+ it "is callable" do
56
118
  expect { inspector.reload }.not_to raise_error
57
119
  end
58
120
  end
@@ -1,23 +1,59 @@
1
- require 'spec_helper'
2
- require 'lib/guard/rspec/inspectors/shared_examples'
1
+ require "guard/compat/test/helper"
2
+
3
+ require "lib/guard/rspec/inspectors/shared_examples"
4
+
5
+ require "guard/rspec/inspectors/simple_inspector"
3
6
 
4
7
  klass = Guard::RSpec::Inspectors::SimpleInspector
5
8
 
6
- describe klass do
7
- include_examples 'inspector', klass
9
+ RSpec.describe klass do
10
+ include_examples "inspector", klass
8
11
 
9
12
  # Use real paths because BaseInspector#_clean will be used to clean them
10
- let(:other_paths) { [
11
- 'spec/lib/guard/rspec/inspectors/simple_inspector_spec.rb',
12
- 'spec/lib/guard/rspec/runner_spec.rb'
13
- ] }
14
-
15
- it 'returns paths and do not bothers about failed locations' do
16
- 2.times do
17
- expect(inspector.paths(paths)).to eq(paths)
18
- inspector.failed(failed_locations)
19
- expect(inspector.paths(other_paths)).to eq(other_paths)
20
- inspector.failed([])
21
- end
13
+ let(:other_paths) do
14
+ [
15
+ "spec/lib/guard/rspec/inspectors/simple_inspector_spec.rb",
16
+ "spec/lib/guard/rspec/runner_spec.rb"
17
+ ]
18
+ end
19
+
20
+ it "returns paths and do not bothers about failed locations" do
21
+ allow(File).to receive(:directory?).
22
+ with("spec/lib/guard/rspec/inspectors/base_inspector_spec.rb").
23
+ and_return(false)
24
+
25
+ allow(File).to receive(:directory?).
26
+ with("spec/lib/guard/rspec/inspectors/simple_inspector_spec.rb").
27
+ and_return(false)
28
+
29
+ allow(File).to receive(:directory?).
30
+ with("spec/lib/guard/rspec/runner_spec.rb").
31
+ and_return(false)
32
+
33
+ allow(File).to receive(:directory?).
34
+ with("spec/lib/guard/rspec/deprecator_spec.rb").
35
+ and_return(false)
36
+
37
+ allow(Dir).to receive(:[]).with("spec/**{,/*/**}/*[_.]spec.rb").
38
+ and_return(paths + other_paths)
39
+
40
+ allow(Dir).to receive(:[]).with("spec/**{,/*/**}/*.feature").
41
+ and_return([])
42
+
43
+ allow(Dir).to receive(:[]).with("myspec/**{,/*/**}/*[_.]spec.rb").
44
+ and_return([])
45
+
46
+ allow(Dir).to receive(:[]).with("myspec/**{,/*/**}/*.feature").
47
+ and_return([])
48
+
49
+ expect(inspector.paths(paths)).to eq(paths)
50
+ inspector.failed(failed_locations)
51
+ expect(inspector.paths(other_paths)).to eq(other_paths)
52
+ inspector.failed([])
53
+
54
+ expect(inspector.paths(paths)).to eq(paths)
55
+ inspector.failed(failed_locations)
56
+ expect(inspector.paths(other_paths)).to eq(other_paths)
57
+ inspector.failed([])
22
58
  end
23
59
  end
@@ -1,68 +1,90 @@
1
- require 'spec_helper'
1
+ require "guard/compat/test/helper"
2
2
 
3
- describe Guard::RSpec::Notifier do
4
- let(:options) { { notification: true } }
3
+ require "guard/rspec/notifier"
4
+
5
+ RSpec.describe Guard::RSpec::Notifier do
6
+ let(:options) { { notification: true, title: "RSpec results" } }
5
7
  let(:notifier) { Guard::RSpec::Notifier.new(options) }
6
8
 
7
- def expect_notification(message, image, priority)
8
- expect(Guard::Notifier).to receive(:notify).with(message, { title: 'RSpec results', image: image, priority: priority })
9
+ def expect_notification(title = "RSpec results", message, image, priority)
10
+ expect(Guard::Notifier).
11
+ to receive(:notify).
12
+ with(message, title: title, image: image, priority: priority)
9
13
  end
10
14
 
11
- describe '#notify_failure' do
12
- it 'notifies about failure' do
13
- expect_notification('Failed', :failed, 2)
15
+ describe "#notify_failure" do
16
+ it "notifies about failure" do
17
+ expect_notification("Failed", :failed, 2)
14
18
  notifier.notify_failure
15
19
  end
20
+
21
+ context "with a custom title" do
22
+ let(:options) { { notification: true, title: "Failure title" } }
23
+
24
+ it "notifies with the title" do
25
+ expect_notification("Failure title", "Failed", :failed, 2)
26
+ notifier.notify_failure
27
+ end
28
+ end
16
29
  end
17
30
 
18
- describe '#notify' do
19
- it 'notifies about success' do
20
- expect_notification('This is summary', :success, -2)
21
- notifier.notify('This is summary')
31
+ describe "#notify" do
32
+ it "notifies about success" do
33
+ expect_notification("This is summary", :success, -2)
34
+ notifier.notify("This is summary")
22
35
  end
23
36
 
24
- context 'with pendings' do
25
- let(:summary) { '5 examples, 0 failures (1 pending) in 4.0000 seconds' }
37
+ context "with pendings" do
38
+ let(:summary) { "5 examples, 0 failures (1 pending) in 4.0000 seconds" }
26
39
 
27
- it 'notifies about pendings' do
40
+ it "notifies about pendings" do
28
41
  expect_notification(summary, :pending, -1)
29
42
  notifier.notify(summary)
30
43
  end
31
44
  end
32
45
 
33
- context 'with failures' do
34
- let(:summary) { '5 examples, 1 failures in 4.0000 seconds' }
46
+ context "with failures" do
47
+ let(:summary) { "5 examples, 1 failures in 4.0000 seconds" }
35
48
 
36
- it 'notifies about failures' do
49
+ it "notifies about failures" do
37
50
  expect_notification(summary, :failed, 2)
38
51
  notifier.notify(summary)
39
52
  end
40
53
 
41
- context 'even if there is pendings' do
42
- let(:summary) { '5 examples, 1 failures (1 pending) in 4.0000 seconds' }
54
+ context "even if there is pendings" do
55
+ let(:summary) { "5 examples, 1 failures (1 pending) in 4.0000 seconds" }
43
56
 
44
- it 'still notifies about failures' do
57
+ it "still notifies about failures" do
45
58
  expect_notification(summary, :failed, 2)
46
59
  notifier.notify(summary)
47
60
  end
48
61
  end
49
62
  end
63
+
64
+ context "with a custom title" do
65
+ let(:options) { { notification: true, title: "Custom title" } }
66
+
67
+ it "notifies with the title" do
68
+ expect_notification("Custom title", "This is summary", :success, -2)
69
+ notifier.notify("This is summary")
70
+ end
71
+ end
50
72
  end
51
73
 
52
- context 'with notifications turned off' do
74
+ context "with notifications turned off" do
53
75
  let(:options) { { notification: false } }
54
76
 
55
- describe '#notify_failure' do
56
- it 'keeps quiet' do
77
+ describe "#notify_failure" do
78
+ it "keeps quiet" do
57
79
  expect(Guard::Notifier).not_to receive(:notify)
58
80
  notifier.notify_failure
59
81
  end
60
82
  end
61
83
 
62
- describe '#notify' do
63
- it 'keeps quiet' do
84
+ describe "#notify" do
85
+ it "keeps quiet" do
64
86
  expect(Guard::Notifier).not_to receive(:notify)
65
- notifier.notify('Summary')
87
+ notifier.notify("Summary")
66
88
  end
67
89
  end
68
90
  end
@@ -1,195 +1,238 @@
1
- require 'spec_helper'
2
- require 'launchy'
1
+ require "guard/compat/test/helper"
3
2
 
4
- describe Guard::RSpec::Runner do
5
- let(:options) { {cmd: 'rspec'} }
3
+ require "launchy"
4
+
5
+ require "guard/rspec/runner"
6
+
7
+ RSpec.describe Guard::RSpec::Runner do
8
+ let(:options) { { cmd: "rspec" } }
6
9
  let(:runner) { Guard::RSpec::Runner.new(options) }
7
10
  let(:inspector) { double(Guard::RSpec::Inspectors::SimpleInspector) }
8
11
  let(:notifier) { double(Guard::RSpec::Notifier) }
9
- let(:formatter_tmp_file) { Guard::RSpec::Formatter::TEMPORARY_FILE_PATH }
10
- before {
12
+
13
+ before do
11
14
  allow(Guard::UI).to receive(:info)
12
15
  allow(Kernel).to receive(:system) { true }
13
16
  allow(Guard::RSpec::Inspectors::Factory).to receive(:create) { inspector }
14
17
  allow(Guard::RSpec::Notifier).to receive(:new) { notifier }
15
- allow(Guard::RSpec::Command).to receive(:new) { 'rspec' }
18
+ allow(Guard::RSpec::Command).to receive(:new) { "rspec" }
16
19
  allow(notifier).to receive(:notify)
17
20
  allow(notifier).to receive(:notify_failure)
18
- }
19
21
 
20
- describe '.initialize' do
21
- context 'with custom options' do
22
+ $CHILD_STATUS = double("exitstatus", exitstatus: 0)
23
+ end
24
+
25
+ describe ".initialize" do
26
+ context "with custom options" do
22
27
  let(:options) { { foo: :bar } }
23
28
 
24
- it 'instanciates inspector via Inspectors::Factory with custom options' do
25
- expect(Guard::RSpec::Inspectors::Factory).to receive(:create).with(foo: :bar)
29
+ it "instanciates inspector via Inspectors::Factory with custom options" do
30
+ expect(Guard::RSpec::Inspectors::Factory).
31
+ to receive(:create).with(foo: :bar)
26
32
  runner
27
33
  end
28
34
 
29
- it 'instanciates notifier with custom options' do
35
+ it "instanciates notifier with custom options" do
30
36
  expect(Guard::RSpec::Notifier).to receive(:new).with(foo: :bar)
31
37
  runner
32
38
  end
33
39
  end
34
40
  end
35
41
 
36
- describe '#reload' do
42
+ describe "#reload" do
37
43
  it 'calls inspector\'s #reload' do
38
44
  expect(inspector).to receive(:reload)
39
45
  runner.reload
40
46
  end
41
47
  end
42
48
 
43
- shared_examples 'abort' do
44
- it 'aborts' do
49
+ shared_examples "abort" do
50
+ it "aborts" do
45
51
  expect(Guard::UI).to_not receive(:info)
46
52
  subject
47
53
  end
48
54
 
49
- it 'returns true' do
55
+ it "returns true" do
50
56
  expect(subject).to be true
51
57
  end
52
58
  end
53
59
 
54
- describe '#run_all' do
55
- let(:options) { {
56
- spec_paths: %w[spec1 spec2],
57
- cmd: 'rspec',
58
- run_all: { message: 'Custom message' }
59
- } }
60
- before { allow(inspector).to receive(:failed) }
60
+ describe "#run_all" do
61
+ let(:options) do
62
+ {
63
+ spec_paths: %w(spec1 spec2),
64
+ cmd: "rspec",
65
+ run_all: { message: "Custom message" }
66
+ }
67
+ end
61
68
 
62
- it 'builds commands with spec paths' do
63
- expect(Guard::RSpec::Command).to receive(:new).with(%w[spec1 spec2], kind_of(Hash))
69
+ before do
70
+ allow(inspector).to receive(:failed)
71
+ allow(File).to receive(:readlines).and_return([])
72
+ end
73
+
74
+ it "builds commands with spec paths" do
75
+ expect(Guard::RSpec::Command).to receive(:new).
76
+ with(%w(spec1 spec2), kind_of(Hash))
64
77
  runner.run_all
65
78
  end
66
79
 
67
- it 'prints message' do
68
- expect(Guard::UI).to receive(:info).with('Custom message', reset: true)
80
+ it "prints message" do
81
+ expect(Guard::UI).to receive(:info).with("Custom message", reset: true)
69
82
  runner.run_all
70
83
  end
71
84
 
72
- context 'when no paths are given' do
85
+ context "when no paths are given" do
73
86
  subject { runner.run_all }
74
87
 
75
- let(:options) { {
76
- spec_paths: [],
77
- run_all: { message: 'Custom message' }
78
- } }
88
+ let(:options) do
89
+ {
90
+ spec_paths: [],
91
+ run_all: { message: "Custom message" }
92
+ }
93
+ end
79
94
 
80
- include_examples 'abort'
95
+ include_examples "abort"
81
96
  end
82
97
 
83
- context 'with custom cmd' do
84
- before {
85
- options[:run_all][:cmd] = 'rspec -t ~slow'
86
- }
98
+ context "with custom cmd" do
99
+ before do
100
+ options[:run_all][:cmd] = "rspec -t ~slow"
101
+ end
87
102
 
88
- it 'builds command with custom cmd' do
89
- expect(Guard::RSpec::Command).to receive(:new).with(kind_of(Array), hash_including(cmd: 'rspec -t ~slow'))
103
+ it "builds command with custom cmd" do
104
+ expect(Guard::RSpec::Command).to receive(:new).
105
+ with(kind_of(Array), hash_including(cmd: "rspec -t ~slow"))
90
106
  runner.run_all
91
107
  end
92
108
  end
93
109
 
94
- context 'with no cmd' do
95
- before {
110
+ context "with no cmd" do
111
+ before do
96
112
  options[:cmd] = nil
97
113
  allow(Guard::RSpec::Command).to receive(:new)
98
114
  allow(Guard::UI).to receive(:error).with(an_instance_of(String))
99
115
  allow(notifier).to receive(:notify_failure)
100
116
  runner.run_all
101
- }
117
+ end
102
118
 
103
- it 'does not build' do
119
+ it "does not build" do
104
120
  expect(Guard::RSpec::Command).to_not have_received(:new)
105
121
  end
106
122
 
107
- it 'issues a warning to the user' do
123
+ it "issues a warning to the user" do
108
124
  expect(Guard::UI).to have_received(:error).with(an_instance_of(String))
109
125
  end
110
126
 
111
- it 'notifies the notifer of failure' do
127
+ it "notifies the notifer of failure" do
112
128
  expect(notifier).to have_received(:notify_failure)
113
129
  end
114
130
  end
115
131
  end
116
132
 
117
- describe '#run' do
118
- let(:paths) { %w[spec_path1 spec_path2] }
119
- before {
120
- allow(File).to receive(:readlines).with(formatter_tmp_file) { %W{Summary\n} }
133
+ describe "#run" do
134
+ let(:paths) { %w(spec_path1 spec_path2) }
135
+ before do
136
+ tmp_file = "tmp/rspec_guard_result"
137
+ allow(File).to receive(:readlines).with(tmp_file) { ["Summary\n"] }
121
138
  allow(inspector).to receive(:paths) { paths }
122
139
  allow(inspector).to receive(:clear_paths) { true }
123
140
  allow(inspector).to receive(:failed)
124
- }
141
+ end
125
142
 
126
- it 'prints running message' do
127
- expect(Guard::UI).to receive(:info).with('Running: spec_path1 spec_path2', reset: true)
143
+ it "prints running message" do
144
+ expect(Guard::UI).to receive(:info).
145
+ with("Running: spec_path1 spec_path2", reset: true)
128
146
  runner.run(paths)
129
147
  end
130
148
 
131
- context 'when no paths are given' do
149
+ context "when no paths are given" do
132
150
  subject { runner.run([]) }
133
151
 
134
152
  before do
135
153
  allow(inspector).to receive(:paths) { [] }
136
154
  end
137
155
 
138
- include_examples 'abort'
156
+ include_examples "abort"
139
157
  end
140
158
 
141
- it 'builds commands with spec paths' do
142
- expect(Guard::RSpec::Command).to receive(:new).with(%w[spec_path1 spec_path2], kind_of(Hash))
159
+ it "builds commands with spec paths" do
160
+ expect(Guard::RSpec::Command).to receive(:new).
161
+ with(%w(spec_path1 spec_path2), kind_of(Hash))
143
162
  runner.run(paths)
144
163
  end
145
164
 
146
- context 'with all_after_pass option' do
147
- let(:options) { { cmd: 'rspec', all_after_pass: true } }
165
+ context "with all_after_pass option" do
166
+ let(:options) { { cmd: "rspec", all_after_pass: true } }
148
167
 
149
- it 're-runs all if run is success' do
168
+ it "re-runs all if run is success" do
150
169
  expect(runner).to receive(:run_all)
151
170
  runner.run(paths)
152
171
  end
153
172
  end
154
173
 
155
- context 'with launchy option' do
156
- let(:options) { { cmd: 'rspec', launchy: 'launchy_path' } }
174
+ context "with launchy option" do
175
+ let(:options) { { cmd: "rspec", launchy: "launchy_path" } }
157
176
 
158
- before {
159
- allow(Pathname).to receive(:new).with('launchy_path') { double(exist?: true) }
160
- }
177
+ before do
178
+ allow(Pathname).to receive(:new).
179
+ with("launchy_path") { double(exist?: true) }
180
+ end
161
181
 
162
- it 'opens Launchy' do
163
- expect(Launchy).to receive(:open).with('launchy_path')
182
+ it "opens Launchy" do
183
+ expect(Launchy).to receive(:open).with("launchy_path")
164
184
  runner.run(paths)
165
185
  end
166
186
  end
167
187
 
168
- it 'notifies inspector about failed paths' do
188
+ it "notifies inspector about failed paths" do
169
189
  expect(inspector).to receive(:failed).with([])
170
190
  runner.run(paths)
171
191
  end
172
192
 
173
- context 'with failed paths' do
174
- before {
175
- allow(File).to receive(:readlines).with(formatter_tmp_file) { %W{Summary\n ./failed_spec.rb:123\n ./other/failed_spec.rb:77\n} }
176
- }
193
+ context "with failed paths" do
194
+ before do
195
+ allow(File).to receive(:readlines).
196
+ with("tmp/rspec_guard_result") do
197
+ [
198
+ "Summary\n",
199
+ "./failed_spec.rb:123\n",
200
+ "./other/failed_spec.rb:77\n"
201
+ ]
202
+ end
203
+ end
204
+ it "notifies inspector about failed paths" do
205
+ expect(inspector).to receive(:failed).
206
+ with(["./failed_spec.rb:123", "./other/failed_spec.rb:77"])
177
207
 
178
- it 'notifies inspector about failed paths' do
179
- expect(inspector).to receive(:failed).with(%w[./failed_spec.rb:123 ./other/failed_spec.rb:77])
180
208
  runner.run(paths)
181
209
  end
182
210
  end
183
211
 
184
- it 'notifies success' do
185
- expect(notifier).to receive(:notify).with('Summary')
212
+ it "notifies success" do
213
+ expect(notifier).to receive(:notify).with("Summary")
186
214
  runner.run(paths)
187
215
  end
188
216
 
189
- it 'notifies failure' do
217
+ it "notifies failure" do
190
218
  allow(Kernel).to receive(:system) { nil }
191
219
  expect(notifier).to receive(:notify_failure)
192
220
  runner.run(paths)
193
221
  end
194
222
  end
223
+
224
+ # TODO: remove / cleanup
225
+ describe "_tmp_file" do
226
+ subject { described_class.new.send(:_tmp_file, chdir) }
227
+
228
+ context "with no chdir option" do
229
+ let(:chdir) { nil }
230
+ it { is_expected.to eq("tmp/rspec_guard_result") }
231
+ end
232
+
233
+ context "chdir option" do
234
+ let(:chdir) { "moduleA" }
235
+ it { is_expected.to eq("moduleA/tmp/rspec_guard_result") }
236
+ end
237
+ end
195
238
  end