2010-01-04 18:13:45 -05:00
|
|
|
require 'isolation/abstract_unit'
|
|
|
|
|
|
|
|
module ApplicationTests
|
2012-01-05 20:30:17 -05:00
|
|
|
class TestTest < ActiveSupport::TestCase
|
2010-01-04 18:13:45 -05:00
|
|
|
include ActiveSupport::Testing::Isolation
|
|
|
|
|
|
|
|
def setup
|
|
|
|
build_app
|
|
|
|
boot_rails
|
|
|
|
end
|
|
|
|
|
2011-06-06 08:54:05 -04:00
|
|
|
def teardown
|
|
|
|
teardown_app
|
|
|
|
end
|
|
|
|
|
2010-01-04 18:13:45 -05:00
|
|
|
test "truth" do
|
|
|
|
app_file 'test/unit/foo_test.rb', <<-RUBY
|
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
class FooTest < ActiveSupport::TestCase
|
|
|
|
def test_truth
|
|
|
|
assert true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2011-11-30 02:36:12 -05:00
|
|
|
run_test_file 'unit/foo_test.rb'
|
2010-01-04 18:13:45 -05:00
|
|
|
end
|
|
|
|
|
2010-01-05 12:47:10 -05:00
|
|
|
test "integration test" do
|
|
|
|
controller 'posts', <<-RUBY
|
|
|
|
class PostsController < ActionController::Base
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
app_file 'app/views/posts/index.html.erb', <<-HTML
|
|
|
|
Posts#index
|
|
|
|
HTML
|
|
|
|
|
|
|
|
app_file 'test/integration/posts_test.rb', <<-RUBY
|
|
|
|
require 'test_helper'
|
|
|
|
|
2010-09-24 20:15:52 -04:00
|
|
|
class PostsTest < ActionDispatch::IntegrationTest
|
2010-01-05 12:47:10 -05:00
|
|
|
def test_index
|
|
|
|
get '/posts'
|
|
|
|
assert_response :success
|
|
|
|
assert_template "index"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2011-11-30 02:36:12 -05:00
|
|
|
run_test_file 'integration/posts_test.rb'
|
2010-01-05 12:47:10 -05:00
|
|
|
end
|
|
|
|
|
2010-01-04 18:13:45 -05:00
|
|
|
private
|
2011-11-30 02:36:12 -05:00
|
|
|
def run_test_file(name)
|
2010-01-04 18:13:45 -05:00
|
|
|
result = ruby '-Itest', "#{app_path}/test/#{name}"
|
|
|
|
assert_equal 0, $?.to_i, result
|
|
|
|
end
|
|
|
|
|
|
|
|
def ruby(*args)
|
|
|
|
Dir.chdir(app_path) do
|
|
|
|
`RUBYLIB='#{$:.join(':')}' #{Gem.ruby} #{args.join(' ')}`
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|