guard-phpunit 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -4,7 +4,7 @@ Guard::PHPUnit [![Build Status](https://secure.travis-ci.org/Maher4Ever/guard-ph
4
4
  PHPUnit guard allows to automatically & intelligently launch tests when files
5
5
  are modified.
6
6
 
7
- Tested on MRI Ruby 1.8.7, 1.9.2 and 1.9.3.
7
+ Tested on MRI Ruby (1.8.7, 1.9.2, 1.9.3), REE and Rubinius.
8
8
 
9
9
  Install
10
10
  -------
@@ -61,6 +61,15 @@ The following options can be passed to Guard::PHPUnit:
61
61
  :all_on_start => false # Run all tests on startup.
62
62
  # default: true
63
63
 
64
+ :all_after_pass => false # Run all tests after changed tests pass. This ensures
65
+ # that the process of making changed tests pass didn't
66
+ # break something else.
67
+ # default: true
68
+
69
+ :keep_failed => false # Remember failed tests and keep running them with
70
+ # each change until they pass.
71
+ # default: true
72
+
64
73
  :tests_path => 'tests' # Relative path to the tests directory. This path
65
74
  # is used when running all the tests.
66
75
  # default: the current working directory (pwd)
@@ -10,11 +10,15 @@ module Guard
10
10
 
11
11
  autoload :Inspector, 'guard/phpunit/inspector'
12
12
  autoload :Formatter, 'guard/phpunit/formatter'
13
+ autoload :Notifier, 'guard/phpunit/notifier'
13
14
  autoload :Runner, 'guard/phpunit/runner'
14
15
 
15
16
  DEFAULT_OPTIONS = {
16
- :all_on_start => true,
17
- :tests_path => Dir.pwd
17
+ :all_on_start => true,
18
+ :all_after_pass => true,
19
+ :keep_failed => true,
20
+ :cli => nil,
21
+ :tests_path => Dir.pwd
18
22
  }
19
23
 
20
24
  # Initialize Guard::PHPUnit.
@@ -29,6 +33,10 @@ module Guard
29
33
  defaults = DEFAULT_OPTIONS.clone
30
34
  @options = defaults.merge(options)
31
35
  super(watchers, @options)
36
+
37
+ @failed_paths = []
38
+ @previous_failed = false
39
+
32
40
  Inspector.tests_path = @options[:tests_path]
33
41
  end
34
42
 
@@ -48,6 +56,8 @@ module Guard
48
56
  success = Runner.run(options[:tests_path], options.merge(
49
57
  :message => 'Running all tests'
50
58
  ))
59
+
60
+ @previous_failed = !success
51
61
  throw :task_has_failed unless success
52
62
  end
53
63
 
@@ -57,8 +67,44 @@ module Guard
57
67
  # @raise (see #start)
58
68
  #
59
69
  def run_on_change(paths)
60
- success = Runner.run(Inspector.clean(paths), options)
70
+ paths = Inspector.clean(paths + @failed_paths)
71
+ success = Runner.run(paths, options)
72
+
73
+ update_failed_paths(success, paths)
74
+ run_all_after_pass(success)
61
75
  throw :task_has_failed unless success
62
76
  end
77
+
78
+ private
79
+
80
+ # Adds or removes path to the failed_paths bassed
81
+ # on the tests result.
82
+ #
83
+ # @param [Boolean] tests_passed whether the tests passed or not
84
+ # @param [Array<String>] paths the tests paths
85
+ #
86
+ def update_failed_paths(tests_passed, paths)
87
+ return unless @options[:keep_failed]
88
+
89
+ if tests_passed
90
+ @failed_paths -= paths
91
+ else
92
+ @failed_paths += paths
93
+ end
94
+ end
95
+
96
+ # Runs all tests after the failed tests pass.
97
+ #
98
+ # @param (see .update_failed_paths)
99
+ #
100
+ def run_all_after_pass(tests_passed)
101
+ return unless @options[:all_after_pass]
102
+
103
+ if tests_passed
104
+ run_all if @previous_failed
105
+ else
106
+ @previous_failed = true
107
+ end
108
+ end
63
109
  end
64
110
  end
@@ -3,8 +3,7 @@ module Guard
3
3
 
4
4
  # The Guard::PHPUnit formatter parses the output
5
5
  # of phpunit which gets printed by the progress
6
- # printer and formats the parsed results
7
- # for the notifier.
6
+ # printer.
8
7
  #
9
8
  module Formatter
10
9
  class << self
@@ -25,22 +24,6 @@ module Guard
25
24
  results.freeze
26
25
  end
27
26
 
28
- # Outputs a system notification.
29
- #
30
- # @param [Hash] test_results the parsed tests results
31
- # @option test_results [Integer] :tests tests count
32
- # @option test_results [Integer] :failures failures count
33
- # @option test_results [Integer] :errors count count
34
- # @option test_results [Integer] :pending pending tests count
35
- # @option test_results [Integer] :duration tests duration
36
- #
37
- def notify(test_results)
38
- ::Guard::Notifier.notify(notifier_message(test_results), {
39
- :title => 'PHPUnit results',
40
- :image => notifier_image(test_results)
41
- })
42
- end
43
-
44
27
  private
45
28
 
46
29
  # Searches for a list of strings in the tests output
@@ -75,35 +58,6 @@ module Guard
75
58
  text =~ %r{Finished in (\d)+ seconds?.*\Z}m
76
59
  $1.nil? ? 0 : $1.to_i
77
60
  end
78
-
79
- # Formats the message for the Notifier.
80
- #
81
- # @param (see .notify)
82
- # @return [String] the message
83
- #
84
- def notifier_message(results)
85
- message = "#{results[:tests]} tests, #{results[:failures]} failures"
86
- message << "\n#{results[:errors]} errors" if results[:errors] > 0
87
- message << " (#{results[:pending]} pending)" if results[:pending] > 0
88
- message << "\nin #{results[:duration]} seconds"
89
- message
90
- end
91
-
92
- # Returns the appropriate image for the tests results
93
- #
94
- # @param (see .notify)
95
- # @return [Symbol] the image symbol
96
- #
97
- def notifier_image(results)
98
- case
99
- when results[:failures] + results[:errors] > 0
100
- :failed
101
- when results[:pending] > 0
102
- :pending
103
- else
104
- :success
105
- end
106
- end
107
61
  end
108
62
  end
109
63
  end
@@ -0,0 +1,68 @@
1
+ module Guard
2
+ class PHPUnit
3
+
4
+ # The Guard::PHPUnit notifier displays a notification pop-up
5
+ # with the tests results.
6
+ #
7
+ module Notifier
8
+ class << self
9
+
10
+ # Displays a system notification.
11
+ #
12
+ # @param [String] message the message to show
13
+ # @param [Hash] options the notifier options
14
+ #
15
+ def notify(message, options)
16
+ ::Guard::Notifier.notify(message, options)
17
+ end
18
+
19
+ # Displays a notification about the tests results.
20
+ #
21
+ # @param [Hash] test_results the parsed tests results
22
+ # @option test_results [Integer] :tests tests count
23
+ # @option test_results [Integer] :failures failures count
24
+ # @option test_results [Integer] :errors count count
25
+ # @option test_results [Integer] :pending pending tests count
26
+ # @option test_results [Integer] :duration tests duration
27
+ #
28
+ def notify_results(test_results)
29
+ notify(message(test_results), {
30
+ :title => 'PHPUnit results',
31
+ :image => image(test_results)
32
+ })
33
+ end
34
+
35
+ private
36
+
37
+ # Formats the message for the tests results notifier.
38
+ #
39
+ # @param (see .notify)
40
+ # @return [String] the message
41
+ #
42
+ def message(results)
43
+ message = "#{results[:tests]} tests, #{results[:failures]} failures"
44
+ message << "\n#{results[:errors]} errors" if results[:errors] > 0
45
+ message << " (#{results[:pending]} pending)" if results[:pending] > 0
46
+ message << "\nin #{results[:duration]} seconds"
47
+ message
48
+ end
49
+
50
+ # Returns the appropriate image for the tests results.
51
+ #
52
+ # @param (see .notify)
53
+ # @return [Symbol] the image symbol
54
+ #
55
+ def image(results)
56
+ case
57
+ when results[:failures] + results[:errors] > 0
58
+ :failed
59
+ when results[:pending] > 0
60
+ :pending
61
+ else
62
+ :success
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -27,44 +27,38 @@ module Guard
27
27
  #
28
28
  def run(paths, options = {})
29
29
  paths = Array(paths)
30
+
30
31
  return false if paths.empty?
31
-
32
- notify_start(paths, options)
33
- output = run_tests(paths, options)
34
32
 
35
- print_output output
36
-
37
- # return false in case the system call fails with no status!
38
- return false if $?.nil?
39
-
40
- if $?.success? or tests_contain_failures? or tests_contain_errors?
41
- notify_results(output, options)
42
- else
43
- notify_failure(options)
33
+ unless phpunit_exists?
34
+ UI.error('phpunit is not installed on your machine.', :reset => true)
35
+ return false
44
36
  end
45
37
 
46
- $?.success?
38
+ run_tests(paths, options)
47
39
  end
48
40
 
49
41
  private
50
42
 
51
- # Displays the start testing notification.
43
+ # Checks that phpunit is installed on the user's
44
+ # machine.
52
45
  #
53
- # @param (see #run)
54
- # @param (see #run)
46
+ # @return [Boolean] The status of phpunit
55
47
  #
56
- def notify_start(paths, options)
57
- message = options[:message] || "Running: #{paths.join(' ')}"
58
- UI.info(message, :reset => true)
48
+ def phpunit_exists?
49
+ system('which phpunit > /dev/null 2>&1')
59
50
  end
60
51
 
61
- # Executes the testing commandon the tests
62
- # and returns the output.
52
+ # Executes the testing command on the tests
53
+ # and returns the status of this process.
63
54
  #
64
55
  # @param (see #run)
65
56
  # @param (see #run)
66
57
  #
67
58
  def run_tests(paths, options)
59
+
60
+ notify_start(paths, options)
61
+
68
62
  if paths.length == 1
69
63
  tests_path = paths.first
70
64
  output = execute_command phpunit_command(tests_path, options)
@@ -73,15 +67,30 @@ module Guard
73
67
  output = execute_command phpunit_command(tests_folder, options)
74
68
  end
75
69
  end
76
- output
70
+
71
+ # print the output to the terminal
72
+ UI.info output
73
+
74
+ # return false in case the system call fails with no status!
75
+ return false if $?.nil?
76
+
77
+ if $?.success? or tests_contain_failures? or tests_contain_errors?
78
+ notify_results(output, options)
79
+ else
80
+ notify_failure(options)
81
+ end
82
+
83
+ $?.success?
77
84
  end
78
85
 
79
- # Prints the tests output to the terminal.
86
+ # Displays the start testing notification.
80
87
  #
81
- # @param [String] output the tests output
88
+ # @param (see #run)
89
+ # @param (see #run)
82
90
  #
83
- def print_output(output)
84
- UI.info output
91
+ def notify_start(paths, options)
92
+ message = options[:message] || "Running: #{paths.join(' ')}"
93
+ UI.info(message, :reset => true)
85
94
  end
86
95
 
87
96
  # Displays a notification about the tests results.
@@ -92,7 +101,7 @@ module Guard
92
101
  def notify_results(output, options)
93
102
  return if options[:notification] == false
94
103
  results = Formatter.parse_output(output)
95
- Formatter.notify(results)
104
+ Notifier.notify_results(results)
96
105
  end
97
106
 
98
107
  # Displays a notification about failing to run the tests
@@ -101,7 +110,7 @@ module Guard
101
110
  #
102
111
  def notify_failure(options)
103
112
  return if options[:notification] == false
104
- ::Guard::Notifier.notify('Failed! Check the console', :title => 'PHPUnit results', :image => :failed)
113
+ Notifier.notify('Failed! Check the console', :title => 'PHPUnit results', :image => :failed)
105
114
  end
106
115
 
107
116
  # Checks the exitstatus of the phpunit command
@@ -1,6 +1,6 @@
1
1
  module Guard
2
2
  # Guard::PHPUnitVersion is used in the gem specification.
3
3
  module PHPUnitVersion
4
- VERSION = '0.0.3'
4
+ VERSION = '0.1.0'
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guard-phpunit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-25 00:00:00.000000000 Z
12
+ date: 2011-11-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: guard
16
- requirement: &12540940 !ruby/object:Gem::Requirement
16
+ requirement: &8010520 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.8.8
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *12540940
24
+ version_requirements: *8010520
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
27
- requirement: &12540280 !ruby/object:Gem::Requirement
27
+ requirement: &8008620 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '1.0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *12540280
35
+ version_requirements: *8008620
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &12539720 !ruby/object:Gem::Requirement
38
+ requirement: &8007340 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '2.7'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *12539720
46
+ version_requirements: *8007340
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: guard-rspec
49
- requirement: &12539080 !ruby/object:Gem::Requirement
49
+ requirement: &8006780 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,7 +54,29 @@ dependencies:
54
54
  version: '0.5'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *12539080
57
+ version_requirements: *8006780
58
+ - !ruby/object:Gem::Dependency
59
+ name: yard
60
+ requirement: &8005020 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: '0.7'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *8005020
69
+ - !ruby/object:Gem::Dependency
70
+ name: redcarpet
71
+ requirement: &8001860 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: '1.17'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *8001860
58
80
  description: Guard::PHPUnit automatically run your unit-tests written with the PHPUnit
59
81
  testing framework.
60
82
  email:
@@ -66,6 +88,7 @@ files:
66
88
  - lib/guard/phpunit.rb
67
89
  - lib/guard/phpunit/formatter.rb
68
90
  - lib/guard/phpunit/inspector.rb
91
+ - lib/guard/phpunit/notifier.rb
69
92
  - lib/guard/phpunit/runner.rb
70
93
  - lib/guard/phpunit/templates/Guardfile
71
94
  - lib/guard/phpunit/version.rb