Skip to content
This repository
Browse code

switch the testing tests to use rake

  • Loading branch information...
commit 328814b0004552d7be009f66d16141d7225bb3f3 1 parent 37154c0
Aaron Patterson authored March 29, 2013
43  railties/test/application/test_runner_test.rb
@@ -15,14 +15,6 @@ def teardown
15 15
       teardown_app
16 16
     end
17 17
 
18  
-    def test_should_not_display_heading
19  
-      create_test_file
20  
-      run_test_command.tap do |output|
21  
-        assert_no_match "Run options:", output
22  
-        assert_no_match "Running tests:", output
23  
-      end
24  
-    end
25  
-
26 18
     def test_run_in_test_environment
27 19
       app_file 'test/unit/env_test.rb', <<-RUBY
28 20
         require 'test_helper'
@@ -45,6 +37,7 @@ def test_run_shortcut
45 37
 
46 38
     def test_run_single_file
47 39
       create_test_file :models, 'foo'
  40
+      create_test_file :models, 'bar'
48 41
       assert_match "1 tests, 1 assertions, 0 failures", run_test_command("test/models/foo_test.rb")
49 42
     end
50 43
 
@@ -62,7 +55,7 @@ def test_run_file_with_syntax_error
62 55
 
63 56
       error_stream = Tempfile.new('error')
64 57
       redirect_stderr(error_stream) { run_test_command('test/models/error_test.rb') }
65  
-      assert_match "SyntaxError", error_stream.read
  58
+      assert_match "syntax error", error_stream.read
66 59
     end
67 60
 
68 61
     def test_invoke_rake_db_test_load
@@ -79,7 +72,7 @@ def test_run_models
79 72
       create_test_file :models, 'foo'
80 73
       create_test_file :models, 'bar'
81 74
       create_test_file :controllers, 'foobar_controller'
82  
-      run_test_command("models").tap do |output|
  75
+      run_test_models_command.tap do |output|
83 76
         assert_match "FooTest", output
84 77
         assert_match "BarTest", output
85 78
         assert_match "2 tests, 2 assertions, 0 failures", output
@@ -90,7 +83,7 @@ def test_run_helpers
90 83
       create_test_file :helpers, 'foo_helper'
91 84
       create_test_file :helpers, 'bar_helper'
92 85
       create_test_file :controllers, 'foobar_controller'
93  
-      run_test_command('helpers').tap do |output|
  86
+      run_test_helpers_command.tap do |output|
94 87
         assert_match "FooHelperTest", output
95 88
         assert_match "BarHelperTest", output
96 89
         assert_match "2 tests, 2 assertions, 0 failures", output
@@ -102,7 +95,7 @@ def test_run_units
102 95
       create_test_file :helpers, 'bar_helper'
103 96
       create_test_file :unit, 'baz_unit'
104 97
       create_test_file :controllers, 'foobar_controller'
105  
-      run_test_command('units').tap do |output|
  98
+      run_test_units_command.tap do |output|
106 99
         assert_match "FooTest", output
107 100
         assert_match "BarHelperTest", output
108 101
         assert_match "BazUnitTest", output
@@ -114,7 +107,7 @@ def test_run_controllers
114 107
       create_test_file :controllers, 'foo_controller'
115 108
       create_test_file :controllers, 'bar_controller'
116 109
       create_test_file :models, 'foo'
117  
-      run_test_command('controllers').tap do |output|
  110
+      run_test_controllers_command.tap do |output|
118 111
         assert_match "FooControllerTest", output
119 112
         assert_match "BarControllerTest", output
120 113
         assert_match "2 tests, 2 assertions, 0 failures", output
@@ -125,7 +118,7 @@ def test_run_mailers
125 118
       create_test_file :mailers, 'foo_mailer'
126 119
       create_test_file :mailers, 'bar_mailer'
127 120
       create_test_file :models, 'foo'
128  
-      run_test_command('mailers').tap do |output|
  121
+      run_test_mailers_command.tap do |output|
129 122
         assert_match "FooMailerTest", output
130 123
         assert_match "BarMailerTest", output
131 124
         assert_match "2 tests, 2 assertions, 0 failures", output
@@ -137,7 +130,7 @@ def test_run_functionals
137 130
       create_test_file :controllers, 'bar_controller'
138 131
       create_test_file :functional, 'baz_functional'
139 132
       create_test_file :models, 'foo'
140  
-      run_test_command('functionals').tap do |output|
  133
+      run_test_functionals_command.tap do |output|
141 134
         assert_match "FooMailerTest", output
142 135
         assert_match "BarControllerTest", output
143 136
         assert_match "BazFunctionalTest", output
@@ -148,7 +141,7 @@ def test_run_functionals
148 141
     def test_run_integration
149 142
       create_test_file :integration, 'foo_integration'
150 143
       create_test_file :models, 'foo'
151  
-      run_test_command('integration').tap do |output|
  144
+      run_test_integration_command.tap do |output|
152 145
         assert_match "FooIntegration", output
153 146
         assert_match "1 tests, 1 assertions, 0 failures", output
154 147
       end
@@ -178,7 +171,7 @@ def test_sanae
178 171
         end
179 172
       RUBY
180 173
 
181  
-      run_test_command('test/unit/chu_2_koi_test.rb -n test_rikka').tap do |output|
  174
+      run_test_command('test/unit/chu_2_koi_test.rb TESTOPTS="-n test_rikka"').tap do |output|
182 175
         assert_match "Rikka", output
183 176
         assert_no_match "Sanae", output
184 177
       end
@@ -192,7 +185,7 @@ def test_load_fixtures_when_running_test_suites
192 185
       suites.each do |suite, directory|
193 186
         directory ||= suite
194 187
         create_fixture_test directory
195  
-        assert_match "3 users", run_test_command(suite)
  188
+        assert_match "3 users", run_task(["test:#{suite}"])
196 189
         Dir.chdir(app_path) { FileUtils.rm_f "test/#{directory}" }
197 190
       end
198 191
     end
@@ -213,6 +206,7 @@ def test_env
213 206
     end
214 207
 
215 208
     def test_run_different_environment_using_e_tag
  209
+      env = "development"
216 210
       app_file 'test/unit/env_test.rb', <<-RUBY
217 211
         require 'test_helper'
218 212
 
@@ -223,7 +217,7 @@ def test_env
223 217
         end
224 218
       RUBY
225 219
 
226  
-      assert_match "development", run_test_command('-e development test/unit/env_test.rb')
  220
+      assert_match env, run_test_command("test/unit/env_test.rb RAILS_ENV=#{env}")
227 221
     end
228 222
 
229 223
     def test_generated_scaffold_works_with_rails_test
@@ -232,8 +226,17 @@ def test_generated_scaffold_works_with_rails_test
232 226
     end
233 227
 
234 228
     private
  229
+      def run_task(tasks)
  230
+        Dir.chdir(app_path) { `bundle exec rake #{tasks.join ' '}` }
  231
+      end
  232
+
235 233
       def run_test_command(arguments = 'test/unit/test_test.rb')
236  
-        Dir.chdir(app_path) { `bundle exec rails test #{arguments}` }
  234
+        run_task ['test', arguments]
  235
+      end
  236
+      %w{ mailers models helpers units controllers functionals integration }.each do |type|
  237
+        define_method("run_test_#{type}_command") do
  238
+          run_task ["test:#{type}"]
  239
+        end
237 240
       end
238 241
 
239 242
       def create_model_with_fixture

0 notes on commit 328814b

Please sign in to comment.
Something went wrong with that request. Please try again.