Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0fe366f

Browse files
committed
refactor tests
1 parent 59c9106 commit 0fe366f

File tree

13 files changed

+25
-14
lines changed

13 files changed

+25
-14
lines changed

test/assets_test.rb

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,45 @@
11
require 'test_helper'
22
require 'typescript-rails'
33

4+
require "action_controller/railtie"
5+
require "sprockets/railtie"
6+
7+
48
class AssetsTest < ActiveSupport::TestCase
9+
include Minitest::PowerAssert::Assertions
10+
511
def setup
6-
require "rails"
7-
require 'tzinfo'
8-
require "action_controller/railtie"
9-
require "sprockets/railtie"
12+
FileUtils.mkdir_p tmp_path
1013

1114
@app = Class.new(Rails::Application)
1215
@app.config.eager_load = false
1316
@app.config.active_support.deprecation = :stderr
1417
@app.config.assets.enabled = true
1518
@app.config.assets.cache_store = [ :file_store, "#{tmp_path}/cache" ]
19+
@app.config.assets.paths << "#{File.dirname(__FILE__)}/fixtures/assets"
1620
@app.paths["log"] = "#{tmp_path}/log/test.log"
1721
@app.initialize!
1822
end
1923

2024
def teardown
21-
FileUtils.rm_rf "#{tmp_path}/cache"
22-
FileUtils.rm_rf "#{tmp_path}/log"
23-
#File.delete "#{tmp_path}/typescript.js"
25+
FileUtils.rm_rf tmp_path
2426
end
2527

26-
test "typescript.js is included in Sprockets environment" do
27-
@app.assets["typescript"].write_to("#{tmp_path}/typescript.js")
28+
def tmp_path
29+
"#{File.dirname(__FILE__)}/tmp"
30+
end
2831

29-
assert_match "/lib/assets/javascripts/typescript.js.erb", @app.assets["typescript"].pathname.to_s
30-
assert_match "var TypeScript", File.open("#{tmp_path}/typescript.js").read
32+
def assets
33+
@app.assets
3134
end
3235

33-
def tmp_path
34-
"#{File.dirname(__FILE__)}/tmp"
36+
test "typescript.js is included in Sprockets environment" do
37+
assert { assets["typescript"].pathname.to_s.end_with?('/lib/assets/javascripts/typescript.js.erb') }
38+
assert { assets["typescript"].body.include?('var TypeScript') }
39+
end
40+
41+
test "assets .js.ts is compiled from TypeScript to JavaScript" do
42+
assert { assets["javascripts/hello"].present? }
43+
assert { assets["javascripts/hello"].body.include?('var s = "Hello, world!";') }
3544
end
3645
end
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
var s: string = "Hello, world!";
2+
console.log(s)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

test/template_handler_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require 'typescript-rails'
44

55
class SiteController < ActionController::Base
6-
self.view_paths = File.expand_path("../support", __FILE__)
6+
self.view_paths = File.expand_path("../fixtures", __FILE__)
77
end
88

99
DummyApp = ActionDispatch::Routing::RouteSet.new

0 commit comments

Comments
 (0)