Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added 4 tests for Rails Runner. 2 failing tests for $0 and $PROGRAM_N…
…AME [#2244 state:open] Signed-off-by: José Valim <jose.valim@gmail.com>
- Loading branch information
1 parent
70c932f
commit 9be0b50
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |