aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test
diff options
context:
space:
mode:
authorrohit <rohit.arondekar@gmail.com>2010-06-22 18:44:46 +0530
committerJosé Valim <jose.valim@gmail.com>2010-06-22 15:20:28 +0200
commit9be0b509628388a290b117e6b02df871d97f8c2d (patch)
tree32cbb5ffb1844fb55b66d427a96edde5e1836a99 /railties/test
parent70c932f794073812818a1bd6b9d7de422b5ef679 (diff)
downloadrails-9be0b509628388a290b117e6b02df871d97f8c2d.tar.gz
rails-9be0b509628388a290b117e6b02df871d97f8c2d.tar.bz2
rails-9be0b509628388a290b117e6b02df871d97f8c2d.zip
Added 4 tests for Rails Runner. 2 failing tests for $0 and $PROGRAM_NAME [#2244 state:open]
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'railties/test')
-rw-r--r--railties/test/application/runner_test.rb49
1 files changed, 49 insertions, 0 deletions
diff --git a/railties/test/application/runner_test.rb b/railties/test/application/runner_test.rb
new file mode 100644
index 0000000000..d37b7649e2
--- /dev/null
+++ b/railties/test/application/runner_test.rb
@@ -0,0 +1,49 @@
+require 'isolation/abstract_unit'
+
+module ApplicationTests
+ class RunnerTest < Test::Unit::TestCase
+ include ActiveSupport::Testing::Isolation
+
+ def setup
+ build_app
+ boot_rails
+
+ # Lets create a model so we have something to play with
+ app_file "app/models/user.rb", <<-MODEL
+ class User
+ def self.count
+ 42
+ end
+ end
+ MODEL
+ end
+
+ def test_should_run_ruby_statement
+ assert_match "42", Dir.chdir(app_path) { `bundle exec rails runner "puts User.count"` }
+ end
+
+ def test_should_run_file
+ app_file "script/count_users.rb", <<-SCRIPT
+ puts User.count
+ SCRIPT
+
+ assert_match "42", Dir.chdir(app_path) { `bundle exec rails runner "script/count_users.rb"` }
+ end
+
+ def test_should_set_dollar_0_to_file
+ app_file "script/dollar0.rb", <<-SCRIPT
+ puts $0
+ SCRIPT
+
+ assert_match "script/dollar0.rb", Dir.chdir(app_path) { `bundle exec rails runner "script/dollar0.rb"` }
+ end
+
+ def test_should_set_dollar_program_name_to_file
+ app_file "script/program_name.rb", <<-SCRIPT
+ puts $PROGRAM_NAME
+ SCRIPT
+
+ assert_match "script/program_name.rb", Dir.chdir(app_path) { `bundle exec rails runner "script/program_name.rb"` }
+ end
+ end
+end