blob: c7ad2fba8f8c383c8050d1129177e6307a4b61dd (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
require 'isolation/abstract_unit'
module ApplicationTests
class TestTest < ActiveSupport::TestCase
include ActiveSupport::Testing::Isolation
def setup
build_app
boot_rails
end
def teardown
teardown_app
end
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
run_test_file 'unit/foo_test.rb'
end
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'
class PostsTest < ActionDispatch::IntegrationTest
def test_index
get '/posts'
assert_response :success
assert_template "index"
end
end
RUBY
run_test_file 'integration/posts_test.rb'
end
private
def run_test_file(name)
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
|