guard-phpunit2 0.2.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 +7 -0
- data/CHANGELOG.md +37 -0
- data/LICENSE +19 -0
- data/README.md +106 -0
- data/lib/guard/phpunit2/formatter.rb +64 -0
- data/lib/guard/phpunit2/inspector.rb +54 -0
- data/lib/guard/phpunit2/notifier.rb +68 -0
- data/lib/guard/phpunit2/runner.rb +193 -0
- data/lib/guard/phpunit2/templates/Guardfile +3 -0
- data/lib/guard/phpunit2/version.rb +5 -0
- data/lib/guard/phpunit2.rb +112 -0
- data/spec/fixtures/emptyTest.php +0 -0
- data/spec/fixtures/results/errors.txt +11 -0
- data/spec/fixtures/results/failing.txt +15 -0
- data/spec/fixtures/results/mixed.txt +26 -0
- data/spec/fixtures/results/passing.txt +4 -0
- data/spec/fixtures/results/skipped_and_incomplete.txt +4 -0
- data/spec/fixtures/sampleTest.php +13 -0
- data/spec/guard/phpunit2/formatter_spec.rb +49 -0
- data/spec/guard/phpunit2/inspector_spec.rb +34 -0
- data/spec/guard/phpunit2/notifier_spec.rb +72 -0
- data/spec/guard/phpunit2/runner_spec.rb +168 -0
- data/spec/guard/phpunit2_spec.rb +191 -0
- data/spec/spec_helper.rb +24 -0
- metadata +180 -0
@@ -0,0 +1,15 @@
|
|
1
|
+
FF
|
2
|
+
|
3
|
+
Failures:
|
4
|
+
|
5
|
+
1) NumberTest::testThatMyMathTeacherSucked
|
6
|
+
Failed asserting that 10 is identical to 1.
|
7
|
+
# /home/maher/Projects/php/PHPUnit-Progress/Tests/_files/NumberTest.php:62
|
8
|
+
|
9
|
+
|
10
|
+
2) NumberTest::testThatMyMathTeacherSuckedEvenMore
|
11
|
+
Failed asserting that 'I don't know!' is identical to -1.
|
12
|
+
# /home/maher/Projects/php/PHPUnit-Progress/Tests/_files/NumberTest.php:72
|
13
|
+
|
14
|
+
Finished in 0 seconds
|
15
|
+
2 tests, 2 assertions, 2 failures
|
@@ -0,0 +1,26 @@
|
|
1
|
+
......SSFFEIF
|
2
|
+
|
3
|
+
Errors:
|
4
|
+
|
5
|
+
1) NumberTest::testMathStillWorks
|
6
|
+
NumberException: Division by zero!
|
7
|
+
# /home/maher/Projects/php/PHPUnit-Progress/Tests/_files/Number.php:61
|
8
|
+
# /home/maher/Projects/php/PHPUnit-Progress/Tests/_files/NumberTest.php:81
|
9
|
+
|
10
|
+
Failures:
|
11
|
+
|
12
|
+
1) NumberTest::testThatMyMathTeacherSucked
|
13
|
+
Failed asserting that 10 is identical to 1.
|
14
|
+
# /home/maher/Projects/php/PHPUnit-Progress/Tests/_files/NumberTest.php:62
|
15
|
+
|
16
|
+
|
17
|
+
2) NumberTest::testThatMyMathTeacherSuckedEvenMore
|
18
|
+
Failed asserting that 'I don't know!' is identical to -1.
|
19
|
+
# /home/maher/Projects/php/PHPUnit-Progress/Tests/_files/NumberTest.php:72
|
20
|
+
|
21
|
+
|
22
|
+
3) Warning
|
23
|
+
No tests found in class "emptyTest".
|
24
|
+
|
25
|
+
Finished in 2 seconds
|
26
|
+
13 tests, 4 assertions, 3 failures, 1 errors, 1 incomplete, 2 skipped
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Guard::PHPUnit2::Formatter do
|
4
|
+
describe '.parse_output' do
|
5
|
+
context 'when all tests pass' do
|
6
|
+
it 'returns a hash containing the tests result' do
|
7
|
+
output = load_phpunit_output('passing')
|
8
|
+
subject.parse_output(output).should == {
|
9
|
+
:tests => 2, :failures => 0,
|
10
|
+
:errors => 0, :pending => 0,
|
11
|
+
:duration => 0
|
12
|
+
}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'when all tests fail' do
|
17
|
+
it 'returns a hash containing the tests result' do
|
18
|
+
output = load_phpunit_output('failing')
|
19
|
+
subject.parse_output(output).should == {
|
20
|
+
:tests => 2, :failures => 2,
|
21
|
+
:errors => 0, :pending => 0,
|
22
|
+
:duration => 0
|
23
|
+
}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'when tests are skipped or incomplete' do
|
28
|
+
it 'returns a hash containing the tests result' do
|
29
|
+
output = load_phpunit_output('skipped_and_incomplete')
|
30
|
+
subject.parse_output(output).should == {
|
31
|
+
:tests => 3, :failures => 0,
|
32
|
+
:errors => 0, :pending => 3,
|
33
|
+
:duration => 0
|
34
|
+
}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'when tests have mixed statuses' do
|
39
|
+
it 'returns a hash containing the tests result' do
|
40
|
+
output = load_phpunit_output('mixed')
|
41
|
+
subject.parse_output(output).should == {
|
42
|
+
:tests => 13, :failures => 3,
|
43
|
+
:errors => 1, :pending => 3,
|
44
|
+
:duration => 2
|
45
|
+
}
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Guard::PHPUnit2::Inspector do
|
4
|
+
before do
|
5
|
+
subject.tests_path = 'spec/fixtures'
|
6
|
+
end
|
7
|
+
|
8
|
+
describe 'clean' do
|
9
|
+
it 'removes non-tests files' do
|
10
|
+
subject.clean(['spec/fixtures/sampleTest.php', 'foo.php']).should == ['spec/fixtures/sampleTest.php']
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'removes test-looking but non-existing files' do
|
14
|
+
subject.clean(['spec/fixtures/sampleTest.php', 'fooTest.rb']).should == ['spec/fixtures/sampleTest.php']
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'removes test-looking but non-existing files (2)' do
|
18
|
+
subject.clean(['spec/fixtures/fooTest.php']).should == []
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'removes duplicate files' do
|
22
|
+
subject.clean(['spec/fixtures/sampleTest.php', 'spec/fixtures/sampleTest.php']).should == ['spec/fixtures/sampleTest.php']
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'remove nil files' do
|
26
|
+
subject.clean(['spec/fixtures/sampleTest.php', nil]).should == ['spec/fixtures/sampleTest.php']
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'frees up the list of tests files' do
|
30
|
+
subject.should_receive(:clear_tests_files_list)
|
31
|
+
subject.clean(['classTest.php'])
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Guard::PHPUnit2::Notifier do
|
4
|
+
|
5
|
+
let(:guard_notifier) { Guard::Notifier }
|
6
|
+
|
7
|
+
describe '.notify' do
|
8
|
+
it 'calls the guard notifier' do
|
9
|
+
guard_notifier.should_receive(:notify).with('My awesome message!', :image => :success)
|
10
|
+
subject.notify('My awesome message!', :image => :success)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '.notify_results' do
|
15
|
+
context 'with no errors, failures or pending tests' do
|
16
|
+
it 'displays a notification' do
|
17
|
+
subject.should_receive(:notify).with(
|
18
|
+
"10 tests, 0 failures\nin 5 seconds",
|
19
|
+
:title => 'PHPUnit results',
|
20
|
+
:image => :success
|
21
|
+
)
|
22
|
+
subject.notify_results(
|
23
|
+
:tests => 10, :failures => 0,
|
24
|
+
:errors => 0, :pending => 0,
|
25
|
+
:duration => 5
|
26
|
+
)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
context 'with errors or failures' do
|
30
|
+
it 'displays a notification' do
|
31
|
+
subject.should_receive(:notify).with(
|
32
|
+
"10 tests, 3 failures\n4 errors\nin 6 seconds",
|
33
|
+
:title => 'PHPUnit results',
|
34
|
+
:image => :failed
|
35
|
+
)
|
36
|
+
subject.notify_results(
|
37
|
+
:tests => 10, :failures => 3,
|
38
|
+
:errors => 4, :pending => 0,
|
39
|
+
:duration => 6
|
40
|
+
)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'with pending tests' do
|
45
|
+
it 'displays a notification' do
|
46
|
+
subject.should_receive(:notify).with(
|
47
|
+
"10 tests, 0 failures (2 pending)\nin 4 seconds",
|
48
|
+
:title => 'PHPUnit results',
|
49
|
+
:image => :pending
|
50
|
+
)
|
51
|
+
subject.notify_results(
|
52
|
+
:tests => 10, :failures => 0,
|
53
|
+
:errors => 0, :pending => 2,
|
54
|
+
:duration => 4
|
55
|
+
)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'displays a notification (2)' do
|
59
|
+
subject.should_receive(:notify).with(
|
60
|
+
"10 tests, 0 failures\n3 errors (2 pending)\nin 4 seconds",
|
61
|
+
:title => 'PHPUnit results',
|
62
|
+
:image => :failed
|
63
|
+
)
|
64
|
+
subject.notify_results(
|
65
|
+
:tests => 10, :failures => 0,
|
66
|
+
:errors => 3, :pending => 2,
|
67
|
+
:duration => 4
|
68
|
+
)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,168 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Guard::PHPUnit2::Runner do
|
4
|
+
|
5
|
+
let(:formatter) { Guard::PHPUnit2::Formatter }
|
6
|
+
let(:notifier) { Guard::PHPUnit2::Notifier }
|
7
|
+
let(:ui) { Guard::UI }
|
8
|
+
|
9
|
+
describe '#run' do
|
10
|
+
before do
|
11
|
+
FileUtils.stub(:ln_s)
|
12
|
+
FileUtils.stub(:mkdir_p)
|
13
|
+
|
14
|
+
subject.stub(:execute_command)
|
15
|
+
subject.stub(:phpunit_exists?).and_return(true)
|
16
|
+
notifier.stub(:notify_results)
|
17
|
+
|
18
|
+
$?.stub(:success?).and_return(true)
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'when passed an empty paths list' do
|
22
|
+
it 'returns false' do
|
23
|
+
subject.run([]).should be_false
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
shared_examples_for 'paths list not empty' do
|
28
|
+
it 'checks that phpunit is installed' do
|
29
|
+
subject.should_receive(:phpunit_exists?)
|
30
|
+
subject.run( ['tests'] )
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'displays an error when phpunit is not installed' do
|
34
|
+
subject.stub(:phpunit_exists?).and_return(false)
|
35
|
+
ui.should_receive(:error).with('phpunit is not installed on your machine.', anything)
|
36
|
+
|
37
|
+
subject.run( ['tests'] )
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'notifies about running the tests' do
|
41
|
+
subject.should_receive(:notify_start).with( ['tests'], anything )
|
42
|
+
subject.run( ['tests'] )
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'runs phpunit tests' do
|
46
|
+
subject.should_receive(:execute_command).with(
|
47
|
+
%r{^phpunit .+$}
|
48
|
+
).and_return(true)
|
49
|
+
subject.run( ['tests'] )
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'prints the tests output to the console' do
|
53
|
+
output = load_phpunit_output('passing')
|
54
|
+
subject.stub(:notify_start)
|
55
|
+
subject.stub(:execute_command).and_return(output)
|
56
|
+
|
57
|
+
ui.should_receive(:info).with(output)
|
58
|
+
|
59
|
+
subject.run( ['tests'] )
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'when PHPUnit executes the tests' do
|
63
|
+
it 'parses the tests output' do
|
64
|
+
output = load_phpunit_output('passing')
|
65
|
+
subject.stub(:execute_command).and_return(output)
|
66
|
+
|
67
|
+
formatter.should_receive(:parse_output).with(output)
|
68
|
+
|
69
|
+
subject.run( ['tests'] )
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'notifies about the tests output' do
|
73
|
+
output = load_phpunit_output('passing')
|
74
|
+
subject.stub(:execute_command).and_return(output)
|
75
|
+
subject.should_receive(:notify_results).with(output, anything())
|
76
|
+
|
77
|
+
subject.run( ['tests'] )
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'notifies about the tests output even when they contain failures' do
|
81
|
+
$?.stub(:success? => false, :exitstatus => 1)
|
82
|
+
|
83
|
+
output = load_phpunit_output('failing')
|
84
|
+
subject.stub(:execute_command).and_return(output)
|
85
|
+
subject.should_receive(:notify_results).with(output, anything())
|
86
|
+
|
87
|
+
subject.run( ['tests'] )
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'notifies about the tests output even when they contain errors' do
|
91
|
+
$?.stub(:success? => false, :exitstatus => 2)
|
92
|
+
|
93
|
+
output = load_phpunit_output('errors')
|
94
|
+
subject.stub(:execute_command).and_return(output)
|
95
|
+
subject.should_receive(:notify_results).with(output, anything())
|
96
|
+
|
97
|
+
subject.run( ['tests'] )
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'does not notify about failures' do
|
101
|
+
subject.should_receive(:execute_command)
|
102
|
+
subject.should_not_receive(:notify_failure)
|
103
|
+
subject.run( ['tests'] )
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context 'when PHPUnit fails to execute' do
|
108
|
+
before do
|
109
|
+
$?.stub(:success? => false, :exitstatus => 255)
|
110
|
+
notifier.stub(:notify)
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'notifies about the failure' do
|
114
|
+
subject.should_receive(:execute_command)
|
115
|
+
subject.should_receive(:notify_failure)
|
116
|
+
subject.run( ['tests'] )
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'does not notify about the tests output' do
|
120
|
+
subject.should_not_receive(:notify_results)
|
121
|
+
subject.run( ['tests'] )
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
describe 'options' do
|
126
|
+
describe ':cli' do
|
127
|
+
it 'runs with CLI options passed to PHPUnit' do
|
128
|
+
cli_options = '--colors --verbose'
|
129
|
+
subject.should_receive(:execute_command).with(
|
130
|
+
%r{^phpunit #{cli_options} .+$}
|
131
|
+
).and_return(true)
|
132
|
+
subject.run( ['tests'], :cli => cli_options )
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe ':notification' do
|
137
|
+
it 'does not notify about tests output with notification option set to false' do
|
138
|
+
formatter.should_not_receive(:notify)
|
139
|
+
subject.run( ['tests'], :notification => false )
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
context 'when passed one path' do
|
146
|
+
it_should_behave_like 'paths list not empty'
|
147
|
+
|
148
|
+
it 'should not create a test folder' do
|
149
|
+
Dir.should_not_receive(:mktmpdir)
|
150
|
+
subject.run( ['spec/fixtures/sampleTest.php'] )
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
context 'when passed multiple paths' do
|
155
|
+
it_should_behave_like 'paths list not empty'
|
156
|
+
|
157
|
+
it 'creates a tests folder (tmpdir)' do
|
158
|
+
subject.should_receive(:create_tests_folder_for).with(instance_of(Array))
|
159
|
+
subject.run( ['spec/fixtures/sampleTest.php', 'spec/fixtures/emptyTest.php'] )
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'symlinks passed paths to the tests folder' do
|
163
|
+
subject.should_receive(:symlink_paths_to_tests_folder).with(anything(), anything())
|
164
|
+
subject.run( ['spec/fixtures/sampleTest.php', 'spec/fixtures/emptyTest.php'] )
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
@@ -0,0 +1,191 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Guard::PHPUnit2 do
|
4
|
+
|
5
|
+
let(:runner) { Guard::PHPUnit2::Runner }
|
6
|
+
let(:inspector) { Guard::PHPUnit2::Inspector }
|
7
|
+
let(:defaults) { Guard::PHPUnit2::DEFAULT_OPTIONS }
|
8
|
+
|
9
|
+
describe '#initialize' do
|
10
|
+
context 'when no options are provided' do
|
11
|
+
it 'sets a default :all_on_start option' do
|
12
|
+
subject.options[:all_on_start].should be_true
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'sets a default :all_after_pass option' do
|
16
|
+
subject.options[:all_after_pass].should be_true
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'sets a default :keep_failed option' do
|
20
|
+
subject.options[:keep_failed].should be_true
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'sets a default :tests_path option' do
|
24
|
+
subject.options[:tests_path].should == @project_path.to_s
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'when other options are provided' do
|
29
|
+
|
30
|
+
subject { Guard::PHPUnit2.new(nil, { :all_on_start => false,
|
31
|
+
:all_after_pass => false,
|
32
|
+
:keep_failed => false,
|
33
|
+
:cli => '--colors',
|
34
|
+
:tests_path => 'tests' }) }
|
35
|
+
|
36
|
+
it 'sets :all_on_start with the provided option' do
|
37
|
+
subject.options[:all_on_start].should be_false
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'sets :all_after_pass with the provided option' do
|
41
|
+
subject.options[:all_after_pass].should be_false
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'sets :keep_failed with the provided option' do
|
45
|
+
subject.options[:keep_failed].should be_false
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'sets :cli with the provided option' do
|
49
|
+
subject.options[:cli].should == '--colors'
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'sets :tests_path with the provided option' do
|
53
|
+
subject.options[:tests_path].should == 'tests'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'sets the tests path for the inspector' do
|
58
|
+
inspector.should_receive(:tests_path=).with(@project_path.to_s)
|
59
|
+
subject
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# ----------------------------------------------------------
|
64
|
+
|
65
|
+
describe '#start' do
|
66
|
+
it 'calls #run_all' do
|
67
|
+
subject.should_receive(:run_all)
|
68
|
+
subject.start
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'with the :all_on_start option set to false' do
|
72
|
+
subject { Guard::PHPUnit2.new(nil, :all_on_start => false) }
|
73
|
+
|
74
|
+
it 'calls #run_all' do
|
75
|
+
subject.should_not_receive(:run_all)
|
76
|
+
subject.start
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe '#run_all' do
|
82
|
+
it 'runs all tests in the tests path' do
|
83
|
+
runner.should_receive(:run).with(defaults[:tests_path], anything).and_return(true)
|
84
|
+
subject.run_all
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'throws :task_has_failed when an error occurs' do
|
88
|
+
runner.should_receive(:run).with(defaults[:tests_path], anything).and_return(false)
|
89
|
+
expect { subject.run_all }.to throw_symbol :task_has_failed
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'passes the options to the runner' do
|
93
|
+
runner.should_receive(:run).with(anything, hash_including(defaults)).and_return(true)
|
94
|
+
subject.run_all
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe '#run_on_changes' do
|
99
|
+
before do
|
100
|
+
inspector.stub(:clean).and_return { |paths| paths }
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'cleans the changed paths before running the tests' do
|
104
|
+
runner.stub(:run).and_return(true)
|
105
|
+
inspector.should_receive(:clean).with(['tests/firstTest.php', 'tests/secondTest.php'])
|
106
|
+
subject.run_on_changes ['tests/firstTest.php', 'tests/secondTest.php']
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'runs the changed tests' do
|
110
|
+
runner.should_receive(:run).with(['tests/firstTest.php', 'tests/secondTest.php'], anything).and_return(true)
|
111
|
+
subject.run_on_changes ['tests/firstTest.php', 'tests/secondTest.php']
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'throws :task_has_failed when an error occurs' do
|
115
|
+
runner.should_receive(:run).with(['tests/firstTest.php', 'tests/secondTest.php'], anything).and_return(false)
|
116
|
+
expect { subject.run_on_changes ['tests/firstTest.php', 'tests/secondTest.php'] }.to throw_symbol :task_has_failed
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'passes the options to the runner' do
|
120
|
+
runner.should_receive(:run).with(anything, hash_including(defaults)).and_return(true)
|
121
|
+
subject.run_on_changes ['tests/firstTest.php', 'tests/secondTest.php']
|
122
|
+
end
|
123
|
+
|
124
|
+
context 'when tests fail' do
|
125
|
+
before do
|
126
|
+
runner.stub(:run).and_return(false)
|
127
|
+
subject.stub(:run_all).and_return(true)
|
128
|
+
end
|
129
|
+
|
130
|
+
context 'with the :keep_failed option set to true' do
|
131
|
+
it 'runs the next changed files plus the failed tests' do
|
132
|
+
expect { subject.run_on_changes ['tests/firstTest.php'] }.to throw_symbol :task_has_failed
|
133
|
+
runner.should_receive(:run).with(
|
134
|
+
['tests/secondTest.php', 'tests/firstTest.php'], anything
|
135
|
+
).and_return(true)
|
136
|
+
|
137
|
+
subject.run_on_changes ['tests/secondTest.php']
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
context 'with the :keep_failed option set to false' do
|
142
|
+
subject { Guard::PHPUnit2.new(nil, :keep_failed => false) }
|
143
|
+
|
144
|
+
it 'runs the next changed files normally without the failed tests' do
|
145
|
+
expect { subject.run_on_changes ['tests/firstTest.php'] }.to throw_symbol :task_has_failed
|
146
|
+
runner.should_receive(:run).with(
|
147
|
+
['tests/secondTest.php'], anything
|
148
|
+
).and_return(true)
|
149
|
+
|
150
|
+
subject.run_on_changes ['tests/secondTest.php']
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
context 'when tests fail then pass' do
|
156
|
+
before do
|
157
|
+
runner.stub(:run).and_return(false, true)
|
158
|
+
end
|
159
|
+
|
160
|
+
context 'with the :all_after_pass option set to true' do
|
161
|
+
it 'calls #run_all' do
|
162
|
+
subject.should_receive(:run_all)
|
163
|
+
expect { subject.run_on_changes ['tests/firstTest.php'] }.to throw_symbol :task_has_failed
|
164
|
+
subject.run_on_changes ['tests/firstTest.php']
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'calls #run_all (2)' do
|
168
|
+
expect { subject.run_all }.to throw_symbol :task_has_failed
|
169
|
+
subject.should_receive(:run_all)
|
170
|
+
subject.run_on_changes ['tests/firstTest.php']
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
context 'with the :all_after_pass option set to false' do
|
175
|
+
subject { Guard::PHPUnit2.new(nil, :all_after_pass => false) }
|
176
|
+
|
177
|
+
it 'does not call #run_all' do
|
178
|
+
subject.should_not_receive(:run_all)
|
179
|
+
expect { subject.run_on_changes ['tests/firstTest.php'] }.to throw_symbol :task_has_failed
|
180
|
+
subject.run_on_changes ['tests/firstTest.php']
|
181
|
+
end
|
182
|
+
|
183
|
+
it 'does not call #run_all (2)' do
|
184
|
+
expect { subject.run_all }.to throw_symbol :task_has_failed
|
185
|
+
subject.should_not_receive(:run_all)
|
186
|
+
subject.run_on_changes ['tests/firstTest.php']
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'guard/phpunit2'
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
|
6
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
7
|
+
config.run_all_when_everything_filtered = true
|
8
|
+
config.color_enabled = true
|
9
|
+
config.filter_run :focus
|
10
|
+
|
11
|
+
config.before(:each) do
|
12
|
+
ENV['GUARD_ENV'] = 'test'
|
13
|
+
@project_path = Pathname.new(File.expand_path('../../', __FILE__))
|
14
|
+
end
|
15
|
+
|
16
|
+
config.after(:each) do
|
17
|
+
ENV['GUARD_ENV'] = nil
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
def load_phpunit_output(name)
|
23
|
+
File.read(File.expand_path("fixtures/results/#{name}.txt", File.dirname(__FILE__)))
|
24
|
+
end
|