infinity_test 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. data/.gitignore +3 -0
  2. data/.infinity_test +30 -2
  3. data/.rspec +2 -0
  4. data/.rvmrc +1 -1
  5. data/Gemfile +10 -2
  6. data/Gemfile.lock +52 -12
  7. data/History.markdown +86 -2
  8. data/LICENSE.txt +22 -0
  9. data/Rakefile +25 -9
  10. data/Readme.markdown +47 -23
  11. data/TODO.markdown +12 -0
  12. data/Tasks +2 -3
  13. data/VERSION.yml +2 -2
  14. data/bin/infinity_test +1 -1
  15. data/features/heuristics.feature +23 -0
  16. data/features/support/env.rb +2 -0
  17. data/images/fuuu/failure.png +0 -0
  18. data/images/fuuu/pending.png +0 -0
  19. data/images/fuuu/sucess.png +0 -0
  20. data/infinity_test.gemspec +62 -29
  21. data/lib/infinity_test.rb +29 -9
  22. data/lib/infinity_test/application.rb +222 -68
  23. data/lib/infinity_test/application_library/rails.rb +94 -0
  24. data/lib/infinity_test/application_library/rubygems.rb +43 -0
  25. data/lib/infinity_test/binary_path.rb +30 -8
  26. data/lib/infinity_test/builder.rb +56 -0
  27. data/lib/infinity_test/command.rb +18 -24
  28. data/lib/infinity_test/configuration.rb +96 -44
  29. data/lib/infinity_test/continuous_testing.rb +17 -39
  30. data/lib/infinity_test/dependencies.rb +76 -41
  31. data/lib/infinity_test/environment.rb +15 -0
  32. data/lib/infinity_test/heuristics.rb +36 -0
  33. data/lib/infinity_test/heuristics_helper.rb +9 -0
  34. data/lib/infinity_test/options.rb +56 -19
  35. data/lib/infinity_test/runner.rb +25 -17
  36. data/lib/infinity_test/test_framework.rb +109 -0
  37. data/lib/infinity_test/test_library/bacon.rb +55 -0
  38. data/lib/infinity_test/test_library/cucumber.rb +22 -0
  39. data/lib/infinity_test/test_library/rspec.rb +58 -0
  40. data/lib/infinity_test/test_library/test_unit.rb +46 -0
  41. data/spec/factories/company/Gemfile +0 -0
  42. data/spec/factories/infinity_test_example +2 -2
  43. data/spec/infinity_test/application_library/rails_spec.rb +140 -0
  44. data/spec/infinity_test/application_library/rubygems_spec.rb +52 -0
  45. data/spec/infinity_test/application_spec.rb +274 -50
  46. data/spec/infinity_test/binary_path_spec.rb +72 -0
  47. data/spec/infinity_test/builder_spec.rb +7 -0
  48. data/spec/infinity_test/command_spec.rb +13 -14
  49. data/spec/infinity_test/configuration_spec.rb +183 -57
  50. data/spec/infinity_test/continuous_testing_spec.rb +19 -1
  51. data/spec/infinity_test/environment_spec.rb +23 -0
  52. data/spec/infinity_test/heuristics_helper_spec.rb +15 -0
  53. data/spec/infinity_test/heuristics_spec.rb +127 -0
  54. data/spec/infinity_test/options_spec.rb +48 -26
  55. data/spec/infinity_test/runner_spec.rb +37 -29
  56. data/spec/infinity_test/test_framework_spec.rb +127 -0
  57. data/spec/infinity_test/test_library/bacon_spec.rb +150 -0
  58. data/spec/infinity_test/test_library/cucumber_spec.rb +8 -0
  59. data/spec/infinity_test/test_library/rspec_spec.rb +185 -0
  60. data/spec/infinity_test/test_library/test_unit_spec.rb +184 -0
  61. data/spec/infinity_test_spec.rb +23 -12
  62. data/spec/spec_helper.rb +86 -30
  63. metadata +62 -32
  64. data/lib/infinity_test/notifications/growl.rb +0 -15
  65. data/lib/infinity_test/notifications/lib_notify.rb +0 -11
  66. data/lib/infinity_test/rspec.rb +0 -87
  67. data/lib/infinity_test/test_unit.rb +0 -74
  68. data/spec/infinity_test/notifications/growl_spec.rb +0 -9
  69. data/spec/infinity_test/notifications/lib_notify_spec.rb +0 -9
  70. data/spec/infinity_test/rspec_spec.rb +0 -189
  71. data/spec/infinity_test/test_unit_spec.rb +0 -182
  72. data/spec/spec.opts +0 -1
@@ -0,0 +1,12 @@
1
+ Future
2
+ ======
3
+
4
+ - Support Rails apps
5
+ - Support Cucumber
6
+ - Make Infinity Test support Rubinius (I tried to run without success - Investigate this!)
7
+ - Run with failed tests (Focus mode!!)
8
+
9
+ Bugs
10
+ ====
11
+
12
+ - Coloring the output (maybe using RedGreen)
data/Tasks CHANGED
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
2
  class InfinityTest < Morpheus::Base
3
- rspec :spec, :rvm_versions => %w(1.8.7-p249, 1.9.1, 1.9.2 jruby)
4
- cucumber :features, :rvm_versions => %w(1.9.2), :format => :pretty
5
- end
3
+ rspec :spec, :rvm_versions => %w(1.8.7 ree 1.9.2 jruby)
4
+ end
@@ -1,5 +1,5 @@
1
1
  ---
2
- :major: 0
3
- :minor: 2
2
+ :major: 1
3
+ :minor: 0
4
4
  :patch: 0
5
5
  :build:
@@ -2,6 +2,6 @@
2
2
 
3
3
  infinity_test_directory = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
4
4
  $LOAD_PATH.unshift(infinity_test_directory) unless $LOAD_PATH.include?(infinity_test_directory)
5
- require 'infinity_test'
6
5
 
6
+ require 'infinity_test'
7
7
  InfinityTest.start!
@@ -0,0 +1,23 @@
1
+ Feature: Infinity test Heuristics
2
+ In order to add or remove the paths to monitoring
3
+ As a user
4
+ I want to add/remove my own patterns to monitoring changes
5
+
6
+ Scenario: Show the default patterns to RubyGems
7
+ When I run "ruby ../../bin/infinity_test --heuristics --rubygems --rspec"
8
+ Then the output should contain:
9
+ """
10
+ - "^lib/*/(.*).rb"
11
+ - "^spec/*/(.*)_spec.rb"
12
+ - "^spec/*/spec_helper.rb"
13
+ """
14
+
15
+ Scenario: Show the default patterns to RubyGems
16
+ When I run "ruby ../../bin/infinity_test --heuristics --rubygems --test-unit"
17
+ Then the output should contain:
18
+ """
19
+ - "^lib/*/(.*).rb"
20
+ - "^test/*/(.*)_test.rb"
21
+ - "^test/*/test_helper.rb"
22
+ """
23
+
@@ -0,0 +1,2 @@
1
+ require 'cucumber'
2
+ require 'aruba'
Binary file
Binary file
Binary file
@@ -5,15 +5,18 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{infinity_test}
8
- s.version = "0.2.0"
8
+ s.version = "1.0.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Tomas D'Stefano"]
12
- s.date = %q{2010-09-29}
12
+ s.date = %q{2010-11-16}
13
13
  s.default_executable = %q{infinity_test}
14
- s.description = %q{Infinity Test is a continuous testing library and a flexible alternative to Autotest, using Watchr library with Rspec OR Test::Unit with RVM funcionality, giving the possibility to test with all Rubies that you have in your RVM configuration.}
14
+ s.description = %q{Infinity Test is a continuous testing library and a flexible alternative to Autotest, using Watchr library with Rspec, Test::Unit or Bacon with RVM funcionality, giving the possibility to test with all Rubies that you have in your RVM configuration.}
15
15
  s.email = %q{tomasdestefi@gmail.com}
16
16
  s.executables = ["infinity_test"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE.txt"
19
+ ]
17
20
  s.files = [
18
21
  ".gitignore",
19
22
  ".infinity_test",
@@ -22,17 +25,24 @@ Gem::Specification.new do |s|
22
25
  "Gemfile",
23
26
  "Gemfile.lock",
24
27
  "History.markdown",
28
+ "LICENSE.txt",
25
29
  "Rakefile",
26
30
  "Readme.markdown",
31
+ "TODO.markdown",
27
32
  "Tasks",
28
33
  "VERSION.yml",
29
34
  "bin/infinity_test",
30
35
  "buzz_images/buzz_lightyear.jpg",
31
36
  "buzz_images/buzz_lightyear_continencia.gif",
32
37
  "buzz_images/to_infinity_and_beyond.png",
38
+ "features/heuristics.feature",
39
+ "features/support/env.rb",
33
40
  "images/faces/failure.png",
34
41
  "images/faces/pending.png",
35
42
  "images/faces/sucess.png",
43
+ "images/fuuu/failure.png",
44
+ "images/fuuu/pending.png",
45
+ "images/fuuu/sucess.png",
36
46
  "images/hands/failure.png",
37
47
  "images/hands/pending.png",
38
48
  "images/hands/sucess.png",
@@ -57,20 +67,28 @@ Gem::Specification.new do |s|
57
67
  "infinity_test.gemspec",
58
68
  "lib/infinity_test.rb",
59
69
  "lib/infinity_test/application.rb",
70
+ "lib/infinity_test/application_library/rails.rb",
71
+ "lib/infinity_test/application_library/rubygems.rb",
60
72
  "lib/infinity_test/binary_path.rb",
73
+ "lib/infinity_test/builder.rb",
61
74
  "lib/infinity_test/command.rb",
62
75
  "lib/infinity_test/configuration.rb",
63
76
  "lib/infinity_test/continuous_testing.rb",
64
77
  "lib/infinity_test/dependencies.rb",
65
- "lib/infinity_test/notifications/growl.rb",
66
- "lib/infinity_test/notifications/lib_notify.rb",
78
+ "lib/infinity_test/environment.rb",
79
+ "lib/infinity_test/heuristics.rb",
80
+ "lib/infinity_test/heuristics_helper.rb",
67
81
  "lib/infinity_test/options.rb",
68
- "lib/infinity_test/rspec.rb",
69
82
  "lib/infinity_test/runner.rb",
70
- "lib/infinity_test/test_unit.rb",
83
+ "lib/infinity_test/test_framework.rb",
84
+ "lib/infinity_test/test_library/bacon.rb",
85
+ "lib/infinity_test/test_library/cucumber.rb",
86
+ "lib/infinity_test/test_library/rspec.rb",
87
+ "lib/infinity_test/test_library/test_unit.rb",
71
88
  "lib/infinity_test/test_unit_loader.rb",
72
89
  "spec/factories/buzz/lib/buzz.rb",
73
90
  "spec/factories/buzz/spec/buzz_spec.rb",
91
+ "spec/factories/company/Gemfile",
74
92
  "spec/factories/company/lib/company.rb",
75
93
  "spec/factories/company/test/company_test.rb",
76
94
  "spec/factories/images/failure.png",
@@ -84,18 +102,25 @@ Gem::Specification.new do |s|
84
102
  "spec/factories/travel/test/travel_test.rb",
85
103
  "spec/factories/wood/lib/wood.rb",
86
104
  "spec/factories/wood/spec/wood_spec.rb",
105
+ "spec/infinity_test/application_library/rails_spec.rb",
106
+ "spec/infinity_test/application_library/rubygems_spec.rb",
87
107
  "spec/infinity_test/application_spec.rb",
108
+ "spec/infinity_test/binary_path_spec.rb",
109
+ "spec/infinity_test/builder_spec.rb",
88
110
  "spec/infinity_test/command_spec.rb",
89
111
  "spec/infinity_test/configuration_spec.rb",
90
112
  "spec/infinity_test/continuous_testing_spec.rb",
91
- "spec/infinity_test/notifications/growl_spec.rb",
92
- "spec/infinity_test/notifications/lib_notify_spec.rb",
113
+ "spec/infinity_test/environment_spec.rb",
114
+ "spec/infinity_test/heuristics_helper_spec.rb",
115
+ "spec/infinity_test/heuristics_spec.rb",
93
116
  "spec/infinity_test/options_spec.rb",
94
- "spec/infinity_test/rspec_spec.rb",
95
117
  "spec/infinity_test/runner_spec.rb",
96
- "spec/infinity_test/test_unit_spec.rb",
118
+ "spec/infinity_test/test_framework_spec.rb",
119
+ "spec/infinity_test/test_library/bacon_spec.rb",
120
+ "spec/infinity_test/test_library/cucumber_spec.rb",
121
+ "spec/infinity_test/test_library/rspec_spec.rb",
122
+ "spec/infinity_test/test_library/test_unit_spec.rb",
97
123
  "spec/infinity_test_spec.rb",
98
- "spec/spec.opts",
99
124
  "spec/spec_helper.rb"
100
125
  ]
101
126
  s.homepage = %q{http://github.com/tomas-stefano/infinity_test}
@@ -103,17 +128,17 @@ Gem::Specification.new do |s|
103
128
  --------------------------------------------------------------------------------
104
129
  T O I N F I N I T Y A N D B E Y O N D !!!
105
130
 
106
- The Infinity uses the awesome RVM to run.
131
+ The Infinity uses the awesome RVM to run.
107
132
  If you don't have the RVM installed, stop what you doing =p.
108
133
  RVM Installation Instructions:
109
- http://rvm.beginrescueend.com/rvm/install/
110
- And don't forget to see how you can customize Infinity Test here:
134
+ http://rvm.beginrescueend.com/rvm/install/
135
+ And don't forget to see how you can customize Infinity Test here:
111
136
  http://github.com/tomas-stefano/infinity_test/wiki/Customize-Infinity-Test
112
137
 
113
138
  Happy Coding! :)
114
139
 
115
140
  --------------------------------------------------------------------------------
116
-
141
+
117
142
  }
118
143
  s.rdoc_options = ["--charset=UTF-8"]
119
144
  s.require_paths = ["lib"]
@@ -130,16 +155,24 @@ Gem::Specification.new do |s|
130
155
  "spec/factories/travel/test/travel_test.rb",
131
156
  "spec/factories/wood/lib/wood.rb",
132
157
  "spec/factories/wood/spec/wood_spec.rb",
158
+ "spec/infinity_test/application_library/rails_spec.rb",
159
+ "spec/infinity_test/application_library/rubygems_spec.rb",
133
160
  "spec/infinity_test/application_spec.rb",
161
+ "spec/infinity_test/binary_path_spec.rb",
162
+ "spec/infinity_test/builder_spec.rb",
134
163
  "spec/infinity_test/command_spec.rb",
135
164
  "spec/infinity_test/configuration_spec.rb",
136
165
  "spec/infinity_test/continuous_testing_spec.rb",
137
- "spec/infinity_test/notifications/growl_spec.rb",
138
- "spec/infinity_test/notifications/lib_notify_spec.rb",
166
+ "spec/infinity_test/environment_spec.rb",
167
+ "spec/infinity_test/heuristics_helper_spec.rb",
168
+ "spec/infinity_test/heuristics_spec.rb",
139
169
  "spec/infinity_test/options_spec.rb",
140
- "spec/infinity_test/rspec_spec.rb",
141
170
  "spec/infinity_test/runner_spec.rb",
142
- "spec/infinity_test/test_unit_spec.rb",
171
+ "spec/infinity_test/test_framework_spec.rb",
172
+ "spec/infinity_test/test_library/bacon_spec.rb",
173
+ "spec/infinity_test/test_library/cucumber_spec.rb",
174
+ "spec/infinity_test/test_library/rspec_spec.rb",
175
+ "spec/infinity_test/test_library/test_unit_spec.rb",
143
176
  "spec/infinity_test_spec.rb",
144
177
  "spec/spec_helper.rb"
145
178
  ]
@@ -150,20 +183,20 @@ Gem::Specification.new do |s|
150
183
 
151
184
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
152
185
  s.add_runtime_dependency(%q<watchr>, [">= 0.7"])
153
- s.add_development_dependency(%q<rspec>, [">= 1.3.0"])
154
- s.add_development_dependency(%q<cucumber>, [">= 0.6.2"])
155
- s.add_development_dependency(%q<aruba>, [">= 0.1.7"])
186
+ s.add_runtime_dependency(%q<notifiers>, [">= 1.1.0"])
187
+ s.add_development_dependency(%q<rspec>, [">= 2.0.1"])
188
+ s.add_development_dependency(%q<jeweler>, [">= 1.4.0"])
156
189
  else
157
190
  s.add_dependency(%q<watchr>, [">= 0.7"])
158
- s.add_dependency(%q<rspec>, [">= 1.3.0"])
159
- s.add_dependency(%q<cucumber>, [">= 0.6.2"])
160
- s.add_dependency(%q<aruba>, [">= 0.1.7"])
191
+ s.add_dependency(%q<notifiers>, [">= 1.1.0"])
192
+ s.add_dependency(%q<rspec>, [">= 2.0.1"])
193
+ s.add_dependency(%q<jeweler>, [">= 1.4.0"])
161
194
  end
162
195
  else
163
196
  s.add_dependency(%q<watchr>, [">= 0.7"])
164
- s.add_dependency(%q<rspec>, [">= 1.3.0"])
165
- s.add_dependency(%q<cucumber>, [">= 0.6.2"])
166
- s.add_dependency(%q<aruba>, [">= 0.1.7"])
197
+ s.add_dependency(%q<notifiers>, [">= 1.1.0"])
198
+ s.add_dependency(%q<rspec>, [">= 2.0.1"])
199
+ s.add_dependency(%q<jeweler>, [">= 1.4.0"])
167
200
  end
168
201
  end
169
202
 
@@ -1,31 +1,51 @@
1
1
  require 'infinity_test/dependencies'
2
2
 
3
3
  module InfinityTest
4
+
4
5
  autoload :Application, 'infinity_test/application'
5
6
  autoload :BinaryPath, 'infinity_test/binary_path'
7
+ autoload :Builder, 'infinity_test/builder'
6
8
  autoload :Command, 'infinity_test/command'
7
9
  autoload :Configuration, 'infinity_test/configuration'
8
10
  autoload :ContinuousTesting, 'infinity_test/continuous_testing'
11
+ autoload :Environment, 'infinity_test/environment'
12
+ autoload :Heuristics, 'infinity_test/heuristics'
13
+ autoload :HeuristicsHelper, 'infinity_test/heuristics_helper'
9
14
  autoload :Options, 'infinity_test/options'
10
- autoload :Rspec, 'infinity_test/rspec'
11
15
  autoload :Runner, 'infinity_test/runner'
12
- autoload :TestUnit, 'infinity_test/test_unit'
16
+ autoload :TestFramework, 'infinity_test/test_framework'
17
+
18
+ module ApplicationLibrary
19
+ autoload :Rails , 'infinity_test/application_library/rails'
20
+ autoload :RubyGems, 'infinity_test/application_library/rubygems'
21
+ end
22
+
23
+ module TestLibrary
24
+ autoload :Bacon, 'infinity_test/test_library/bacon'
25
+ autoload :Cucumber, 'infinity_test/test_library/cucumber'
26
+ autoload :Rspec, 'infinity_test/test_library/rspec'
27
+ autoload :TestUnit, 'infinity_test/test_library/test_unit'
28
+ end
13
29
 
14
30
  def self.application
15
31
  @application ||= Application.new
16
32
  end
17
-
33
+
18
34
  def self.configuration
19
35
  @configuration ||= Configuration.new
20
36
  end
21
-
37
+
38
+ def self.watchr
39
+ @watchr ||= Watchr::Script.new
40
+ end
41
+
22
42
  def self.start!
23
- Runner.new(Options.new(ARGV)).run!
43
+ Runner.new(ARGV).run!
24
44
  end
25
45
 
26
- module Notifications
27
- autoload :Growl, 'infinity_test/notifications/growl'
28
- autoload :LibNotify, 'infinity_test/notifications/lib_notify'
46
+ def self.version
47
+ version = YAML.load_file(File.dirname(__FILE__) + '/../VERSION.yml')
48
+ [version[:major], version[:minor], version[:patch]].compact.join(".")
29
49
  end
30
50
 
31
- end
51
+ end
@@ -1,23 +1,33 @@
1
1
  module InfinityTest
2
2
  class Application
3
- include Notifications
4
-
5
- attr_accessor :config, :library_directory_pattern
6
-
7
- # Initialize the Application object with the configuration instance to
3
+ include InfinityTest::TestLibrary
4
+ include InfinityTest::ApplicationLibrary
5
+ include Notifiers
6
+
7
+ attr_accessor :config, :watchr, :global_commands
8
+
9
+ # Initialize the Application object with the configuration instance to
8
10
  # load configuration and set properly
9
11
  #
10
12
  def initialize
11
13
  @config = InfinityTest.configuration
12
- @library_directory_pattern = "^lib/*/(.*)\.rb"
14
+ @watchr = InfinityTest.watchr
15
+ end
16
+
17
+ def load_configuration_file_or_read_the_options!(options)
18
+ load_configuration_file
19
+ setup!(options)
13
20
  end
14
-
21
+
15
22
  # Load the Configuration file
16
23
  #
17
- # Load first global file in => ~/.infinity_test
18
- # After load the project file => ./.infinity_test
24
+ # Command line options can be persisted in a .infinity_test file in a project.
25
+ # You can also store a .infinity_test file in your home directory (~/.infinity_test) with global options.
19
26
  #
20
- # If the Project file has the same methods in the global, will override the configurations
27
+ # Precedence is:
28
+ # command line
29
+ # ./.infinity_test
30
+ # ~/.infinity_test
21
31
  #
22
32
  # Example:
23
33
  #
@@ -31,89 +41,193 @@ module InfinityTest
31
41
  load_global_configuration # Separate global and local configuration
32
42
  load_project_configuration # because it's more easy to test
33
43
  end
34
-
44
+
45
+ # Setup over a precendence show below.
46
+ #
47
+ # THIS IS NOT RESPONSABILITY OF Application instances!!!
48
+ #
49
+ def setup!(options)
50
+ config.use(
51
+ :rubies => (options[:rubies] || rubies),
52
+ :test_framework => (options[:test_framework] || config.test_framework),
53
+ :app_framework => (options[:app_framework] || config.app_framework),
54
+ :cucumber => options[:cucumber],
55
+ :verbose => options[:verbose] || config.verbose)
56
+ config.skip_bundler! if options[:skip_bundler?]
57
+ add_heuristics!
58
+ heuristics_users_high_priority!
59
+ end
60
+
61
+ # Run the global commands
62
+ #
63
+ def run_global_commands!
64
+ run!(global_commands)
65
+ end
66
+
67
+ # Construct the Global Commands and cache for all suite
68
+ #
69
+ def global_commands
70
+ @global_commands ||= construct_commands
71
+ end
72
+
73
+ # Return the sucess image to show in the notifications
74
+ #
35
75
  def sucess_image
36
76
  config.sucess_image
37
77
  end
38
-
78
+
79
+ # Return the failure image to show in the notifications
80
+ #
39
81
  def failure_image
40
82
  config.failure_image
41
83
  end
42
-
84
+
85
+ # Return the pending image to show in the notifications
86
+ #
43
87
  def pending_image
44
88
  config.pending_image
45
89
  end
46
-
90
+
47
91
  # Return the block object setting in the config file
48
- #
92
+ #
49
93
  def before_callback
50
94
  config.before_callback
51
95
  end
52
-
96
+
53
97
  # Return the block object setting in the config file
54
98
  #
55
99
  def after_callback
56
100
  config.after_callback
57
101
  end
58
-
102
+
103
+ # Return the block object setting in the before(:each_ruby) block
104
+ #
59
105
  def before_each_ruby_callback
60
106
  config.before_each_ruby_callback
61
107
  end
62
-
108
+
109
+ # Return the block object setting in the after(:each_ruby) block
110
+ #
63
111
  def after_each_ruby_callback
64
112
  config.after_each_ruby_callback
65
113
  end
66
-
114
+
67
115
  # Return the rubies setting in the config file or the command line
68
116
  #
69
117
  def rubies
70
118
  config.rubies
71
119
  end
72
-
120
+
121
+ # Return true if verbose mode is on
122
+ # Verbose mode is false as default
123
+ #
124
+ def verbose?
125
+ config.verbose
126
+ end
127
+
128
+ # Return true if the user application has a Gemfile
129
+ # Return false if not exist the Gemfile
130
+ #
131
+ def have_gemfile?
132
+ File.exist?(gemfile)
133
+ end
134
+
135
+ # Return false if you want the InfinityTest run with bundler
136
+ # Return true otherwise
137
+ #
138
+ def skip_bundler?
139
+ config.skip_bundler?
140
+ end
141
+
142
+ # Contruct all the commands for the test framework
143
+ #
73
144
  def construct_commands
74
145
  test_framework.construct_commands
75
146
  end
76
-
77
- def test_directory_pattern
78
- test_framework.test_directory_pattern
79
- end
80
-
147
+
81
148
  # Return a instance of the test framework class
82
149
  #
83
150
  def test_framework
84
151
  @test_framework ||= setting_test_framework
85
152
  end
86
-
87
- # Return a instance of the Notification Framework class
153
+
154
+ # Return true if the application is using Test::Unit
155
+ # Return false otherwise
88
156
  #
89
- def notification_framework
90
- @notification_framework ||= setting_notification
157
+ def using_test_unit?
158
+ test_framework.instance_of?(TestUnit)
159
+ end
160
+
161
+ # Return a instance of the app framework class
162
+ #
163
+ def app_framework
164
+ @app_framework ||= setting_app_framework
165
+ end
166
+
167
+ # Return all the Heuristics of the application
168
+ #
169
+ def heuristics
170
+ config.instance_variable_get(:@heuristics)
171
+ end
172
+
173
+ # Triggers the #add_heuristics! method in the application_framework
174
+ #
175
+ def add_heuristics!
176
+ app_framework.add_heuristics!
91
177
  end
92
-
178
+
179
+ def heuristics_users_high_priority!
180
+ @watchr.rules.reverse!
181
+ end
182
+
183
+ # Pass many commands(expecting something that talk like Hash) and run them
184
+ # First, triggers all the before each callbacks, run the commands
185
+ # and last, triggers after each callbacks
186
+ #
93
187
  def run!(commands)
94
188
  before_callback.call if before_callback
189
+
95
190
  commands.each do |ruby_version, command|
96
191
  call_each_ruby_callback(:before_each_ruby_callback, ruby_version)
97
192
  command = say_the_ruby_version_and_run_the_command!(ruby_version, command) # This method exist because it's more easier to test
98
193
  notify!(:results => command.results, :ruby_version => ruby_version)
99
194
  call_each_ruby_callback(:after_each_ruby_callback, ruby_version)
100
195
  end
196
+
101
197
  after_callback.call if after_callback
102
198
  end
103
-
199
+
200
+ # Return the notification_framework setting in the configuration file
201
+ # Maybe is: :growl, :lib_notify
202
+ #
203
+ def notification_framework
204
+ config.notification_framework
205
+ end
206
+
207
+ # Send the message,image and the actual ruby version to show in the notification system
208
+ #
104
209
  def notify!(options)
105
- if notification_framework
210
+ if notification_framework
106
211
  message = parse_results(options[:results])
107
- notification_framework.notify(:title => options[:ruby_version], :message => message, :image => image_to_show)
212
+ title = options[:ruby_version]
213
+ send(notification_framework).title(title).message(message).image(image_to_show).notify!
108
214
  else
109
215
  # skip(do nothing) when not have notification framework
110
216
  end
111
217
  end
112
-
218
+
219
+ # Parse the results for each command to the test framework
220
+ #
221
+ # app.parse_results(['.....','108 examples']) # => '108 examples'
222
+ #
113
223
  def parse_results(results)
114
224
  test_framework.parse_results(results)
115
225
  end
116
226
 
227
+ # If the test pass, show the sucess image
228
+ # If is some pending test, show the pending image
229
+ # If the test fails, show the failure image
230
+ #
117
231
  def image_to_show
118
232
  if test_framework.failure?
119
233
  failure_image
@@ -121,70 +235,110 @@ module InfinityTest
121
235
  pending_image
122
236
  else
123
237
  sucess_image
124
- end
238
+ end
239
+ end
240
+
241
+ # Return the files that match by the options
242
+ # This very used in the #run method called in the heuristics instances
243
+ #
244
+ # Example:
245
+ #
246
+ # files_to_run!(:all => :files) # => Return all test files
247
+ # files_to_run!(:all => :files, :in_dir => :models) # => Return all the test files in the models directory
248
+ # files_to_run!(:test_for => match_data) # => Return the tests that match with the MatchData Object
249
+ # files_to_run!(:test_for => match_data, :in_dir => :controllers) # => Return the tests that match with the MatchData Object
250
+ # files_to_run!(match_data) # => return the test file
251
+ #
252
+ def files_to_run!(options)
253
+ return options.to_s if options.is_a?(MatchData)
254
+ if options.equal?(:all) or options.include?(:all)
255
+ search_files_in_dir(all_test_files, :in_dir => options[:in_dir]).join(' ')
256
+ else
257
+ search_file(:pattern => options[:test_for][1], :in_dir => options[:in_dir]) if options.include?(:test_for)
258
+ end
259
+ end
260
+
261
+ # Search files under the dir(s) specified
262
+ #
263
+ def search_files_in_dir(files, options)
264
+ dirs = [options[:in_dir]].compact.flatten
265
+ match_files = dirs.collect do |directory|
266
+ files.select { |file| file.match(directory.to_s) }
267
+ end
268
+ match_files.empty? ? files : match_files
125
269
  end
126
-
127
- def run_changed_lib_file(file)
128
- file = File.basename(file[1])
129
- files = test_framework.all_files.grep(/#{file}/i)
130
- run_commands_for_file(files.join(' ')) unless files.empty?
270
+
271
+ # Search files that matches with the pattern
272
+ #
273
+ def search_file(options)
274
+ files = all_test_files.grep(/#{options[:pattern]}/i)
275
+ search_files_in_dir(files, :in_dir => options[:in_dir]).join(' ')
131
276
  end
132
-
133
- def run_changed_test_file(file)
134
- run_commands_for_file(file)
277
+
278
+ # Return all the tests files in the User application
279
+ #
280
+ def all_test_files
281
+ test_framework.all_files
135
282
  end
136
-
283
+
284
+ # Run commands for a file
285
+ # If dont have a file, do nothing
286
+ #
137
287
  def run_commands_for_file(file)
138
- commands = test_framework.construct_commands(file)
139
- run!(commands)
288
+ if file and !file.empty?
289
+ commands = test_framework.construct_commands(file)
290
+ run!(commands)
291
+ end
140
292
  end
141
-
142
- def verbose?
143
- config.verbose
293
+
294
+ def say_the_ruby_version_and_run_the_command!(ruby_version, command)
295
+ puts; puts "* { :ruby => #{ruby_version} }"
296
+ puts command if verbose?
297
+ Command.new(:ruby_version => ruby_version, :command => command).run!
144
298
  end
145
-
299
+
146
300
  private
147
-
301
+
148
302
  def call_each_ruby_callback(callback_type, ruby_version)
149
303
  callback = send(callback_type)
150
304
  callback.call(RVM::Environment.new(ruby_version)) if callback
151
305
  end
152
-
153
- def say_the_ruby_version_and_run_the_command!(ruby_version, command)
154
- puts; puts "* { :ruby => #{ruby_version} }"
155
- puts command if verbose?
156
- Command.new(:ruby_version => ruby_version, :command => command).run!
157
- end
158
-
306
+
159
307
  def setting_test_framework
160
308
  case config.test_framework
161
309
  when :rspec
162
310
  Rspec.new :rubies => rubies
163
311
  when :test_unit
164
312
  TestUnit.new :rubies => rubies
313
+ when :bacon
314
+ Bacon.new :rubies => rubies
165
315
  end
166
316
  end
167
-
168
- def setting_notification
169
- case config.notification_framework
170
- when :growl
171
- Growl.new
172
- when :lib_notify
173
- LibNotify.new
317
+
318
+ def setting_app_framework
319
+ case config.app_framework
320
+ when :rails
321
+ Rails.new
322
+ when :rubygems
323
+ RubyGems.new
174
324
  end
175
325
  end
176
326
 
177
327
  def load_global_configuration
178
328
  load_file(File.expand_path('~/.infinity_test'))
179
329
  end
180
-
330
+
181
331
  def load_project_configuration
182
332
  load_file('./.infinity_test')
183
333
  end
184
-
334
+
185
335
  def load_file(file)
186
336
  load(file) if File.exist?(file)
187
337
  end
188
338
 
339
+ def gemfile
340
+ File.join(Dir.pwd, 'Gemfile')
341
+ end
342
+
189
343
  end
190
- end
344
+ end