newjs 1.0.4 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (28) hide show
  1. data/History.txt +16 -0
  2. data/Manifest.txt +9 -5
  3. data/README.txt +6 -0
  4. data/app_generators/newjs/newjs_generator.rb +4 -2
  5. data/app_generators/newjs/templates/README.txt.erb +13 -0
  6. data/app_generators/newjs/templates/Rakefile.erb +31 -4
  7. data/app_generators/newjs/templates/lib/jstest.rb +5 -5
  8. data/app_generators/newjs/templates/script/js_autotest +1 -1
  9. data/app_generators/newjs/templates/tasks/javascript_test_autotest_tasks.rake +2 -2
  10. data/javascript_test_generators/functional_test/USAGE +2 -0
  11. data/javascript_test_generators/functional_test/functional_test_generator.rb +55 -0
  12. data/javascript_test_generators/functional_test/templates/test/test.html.erb +58 -0
  13. data/javascript_test_generators/{javascript_test → unit_test}/USAGE +0 -0
  14. data/javascript_test_generators/{javascript_test → unit_test}/templates/test/test.html.erb +4 -4
  15. data/javascript_test_generators/{javascript_test/javascript_test_generator.rb → unit_test/unit_test_generator.rb} +5 -5
  16. data/lib/newjs/jstest.rb +5 -5
  17. data/lib/newjs/version.rb +2 -2
  18. data/newjs_generators/install_website/templates/tasks/website.rake +1 -1
  19. data/newjs_generators/install_website/templates/website/index.txt +7 -1
  20. data/newjs_theme_generators/plain_theme/templates/website/stylesheets/screen.css +3 -3
  21. data/newjs_theme_generators/plain_theme/templates/website/template.html.erb +0 -2
  22. data/test/test_functional_test_generator.rb +56 -0
  23. data/test/{test_javascript_test_generator.rb → test_unit_test_generator.rb} +17 -4
  24. data/website/index.html +6 -8
  25. data/website/index.txt +63 -35
  26. data/website/template.html.erb +0 -2
  27. metadata +13 -9
  28. data/app_generators/newjs/templates/README.txt +0 -1
@@ -1,3 +1,19 @@
1
+ == 1.1.0 2008-02-17
2
+
3
+ MAJOR CHANGE - test files in test/unit
4
+ HOWTO UPGRADE:
5
+ * Run 'newjs .' within your project
6
+ * Take note of differences and apply them to your files
7
+ * Move all tests to test/unit and add '../' to all <script> + <link> in test HTML
8
+ * Use 'script/generate unit_test' instead of 'script/generate javascript_test'
9
+ CHANGES
10
+ * unit_test: Added specific unit_test generator placing tests in test/unit folder
11
+ * functional_test: Added specific functional_test generator for tests of dist/xxx.js
12
+ * javascript_test: REMOVED - replaced by unit_test + functional_test
13
+ * install_website: index.txt has Git repo instructions too - just delete svn/git if unnecessary
14
+ * rake dist: distribution files stored to website/dist (if folder website exists)
15
+ * newjs: url option now works
16
+
1
17
  == 1.0.4 2008-02-16
2
18
 
3
19
  * newjs - added missing newjs/rubyforge.rb file
@@ -7,7 +7,7 @@ app_generators/newjs/USAGE
7
7
  app_generators/newjs/newjs_generator.rb
8
8
  app_generators/newjs/templates/History.txt.erb
9
9
  app_generators/newjs/templates/License.txt.erb
10
- app_generators/newjs/templates/README.txt
10
+ app_generators/newjs/templates/README.txt.erb
11
11
  app_generators/newjs/templates/Rakefile.erb
12
12
  app_generators/newjs/templates/config/javascript_test_autotest.yml.sample
13
13
  app_generators/newjs/templates/lib/jstest.rb
@@ -25,9 +25,12 @@ app_generators/newjs/templates/test/assets/unittest.js
25
25
  bin/newjs
26
26
  config/hoe.rb
27
27
  config/requirements.rb
28
- javascript_test_generators/javascript_test/USAGE
29
- javascript_test_generators/javascript_test/javascript_test_generator.rb
30
- javascript_test_generators/javascript_test/templates/test/test.html.erb
28
+ javascript_test_generators/functional_test/USAGE
29
+ javascript_test_generators/functional_test/functional_test_generator.rb
30
+ javascript_test_generators/functional_test/templates/test/test.html.erb
31
+ javascript_test_generators/unit_test/USAGE
32
+ javascript_test_generators/unit_test/templates/test/test.html.erb
33
+ javascript_test_generators/unit_test/unit_test_generator.rb
31
34
  lib/newjs.rb
32
35
  lib/newjs/autotest.rb
33
36
  lib/newjs/autotest/javascript_test_autotest.rb
@@ -57,12 +60,13 @@ setup.rb
57
60
  tasks/deployment.rake
58
61
  tasks/environment.rake
59
62
  tasks/website.rake
63
+ test/test_functional_test_generator.rb
60
64
  test/test_generator_helper.rb
61
65
  test/test_helper.rb
62
66
  test/test_install_website_generator.rb
63
- test/test_javascript_test_generator.rb
64
67
  test/test_newjs_generator.rb
65
68
  test/test_plain_theme_generator.rb
69
+ test/test_unit_test_generator.rb
66
70
  website/images/example-unittest-log.jpg
67
71
  website/index.html
68
72
  website/index.txt
data/README.txt CHANGED
@@ -7,3 +7,9 @@ Example:
7
7
 
8
8
  This generates a skeletal JavaScript project/application
9
9
  installation in path/to/my-app-name
10
+
11
+ More information:
12
+ http://newjs.rubyforge.org
13
+
14
+ Author:
15
+ Dr Nic Williams, http://drnicwilliams.com, drnicwilliams@gmail.com
@@ -40,8 +40,7 @@ class NewjsGenerator < RubiGen::Base
40
40
  m.file_copy_each %w[javascript_test_autotest_tasks.rake environment.rake deploy.rake], "tasks"
41
41
  m.file_copy_each %w[javascript_test_autotest.yml.sample], "config"
42
42
  m.file_copy_each %w[protodoc.rb jstest.rb], "lib"
43
- m.file_copy_each %w[README.txt]
44
- m.template_copy_each %w[Rakefile.erb History.txt.erb License.txt.erb]
43
+ m.template_copy_each %w[Rakefile.erb README.txt.erb History.txt.erb License.txt.erb]
45
44
  m.template_copy_each %w[HEADER.erb], "src"
46
45
  m.template "src/library.js.erb", "src/#{name}.js"
47
46
 
@@ -98,6 +97,7 @@ EOS
98
97
  @author ||= rubyforge_config.full_name
99
98
  @email ||= rubyforge_config.email
100
99
  end
100
+ @url = options[:url]
101
101
  end
102
102
 
103
103
  # Installation skeleton. Intermediate directories are automatically
@@ -109,5 +109,7 @@ EOS
109
109
  script
110
110
  tasks
111
111
  test/assets
112
+ test/unit
113
+ test/functional
112
114
  )
113
115
  end
@@ -0,0 +1,13 @@
1
+ <%= title %>
2
+
3
+ Description:
4
+ This JavaScript project ...
5
+
6
+ Example:
7
+ ...
8
+
9
+ More information:
10
+ <%= url %>
11
+
12
+ Author:
13
+ <%= author %>, <%= email %>
@@ -42,6 +42,11 @@ task :dist do
42
42
  Dir.chdir(APP_DIST_DIR) do
43
43
  FileUtils.copy_file APP_FILE_NAME, "#{APP_NAME}-#{APP_VERSION}.js"
44
44
  end
45
+ if File.directory?("website")
46
+ FileUtils.mkdir_p "website/dist"
47
+ FileUtils.copy_file "dist/#{APP_FILE_NAME}", "website/dist/#{APP_FILE_NAME}"
48
+ FileUtils.copy_file "dist/#{APP_FILE_NAME}", "website/dist/#{APP_NAME}-#{APP_VERSION}.js"
49
+ end
45
50
  end
46
51
 
47
52
  Rake::PackageTask.new(APP_NAME, APP_VERSION) do |package|
@@ -60,12 +65,33 @@ Rake::PackageTask.new(APP_NAME, APP_VERSION) do |package|
60
65
  )
61
66
  end
62
67
 
63
- desc "Builds the distribution, runs the JavaScript unit tests and collects their results."
64
- task :test => [:dist, :test_units]
68
+ desc "Builds the distribution, runs the JavaScript unit + functional tests and collects their results."
69
+ task :test => [:dist, :test_units, :test_functionals]
65
70
 
66
71
  require 'jstest'
67
72
  desc "Runs all the JavaScript unit tests and collects the results"
68
- JavaScriptTestTask.new(:test_units) do |t|
73
+ JavaScriptTestTask.new(:test_units, 4711) do |t|
74
+ testcases = ENV['TESTCASES']
75
+ tests_to_run = ENV['TESTS'] && ENV['TESTS'].split(',')
76
+ browsers_to_test = ENV['BROWSERS'] && ENV['BROWSERS'].split(',')
77
+
78
+ t.mount("/dist")
79
+ t.mount("/src")
80
+ t.mount("/test")
81
+
82
+ Dir["test/unit/*_test.html"].sort.each do |test_file|
83
+ tests = testcases ? { :url => "/#{test_file}", :testcases => testcases } : "/#{test_file}"
84
+ test_filename = test_file[/.*\/(.+?)\.html/, 1]
85
+ t.run(tests) unless tests_to_run && !tests_to_run.include?(test_filename)
86
+ end
87
+
88
+ %w( safari firefox ie konqueror opera ).each do |browser|
89
+ t.browser(browser.to_sym) unless browsers_to_test && !browsers_to_test.include?(browser)
90
+ end
91
+ end
92
+
93
+ desc "Runs all the JavaScript functional tests and collects the results"
94
+ JavaScriptTestTask.new(:test_functionals, 4712) do |t|
69
95
  testcases = ENV['TESTCASES']
70
96
  tests_to_run = ENV['TESTS'] && ENV['TESTS'].split(',')
71
97
  browsers_to_test = ENV['BROWSERS'] && ENV['BROWSERS'].split(',')
@@ -74,7 +100,7 @@ JavaScriptTestTask.new(:test_units) do |t|
74
100
  t.mount("/src")
75
101
  t.mount("/test")
76
102
 
77
- Dir["test/*_test.html"].sort.each do |test_file|
103
+ Dir["test/functional/*_test.html"].sort.each do |test_file|
78
104
  tests = testcases ? { :url => "/#{test_file}", :testcases => testcases } : "/#{test_file}"
79
105
  test_filename = test_file[/.*\/(.+?)\.html/, 1]
80
106
  t.run(tests) unless tests_to_run && !tests_to_run.include?(test_filename)
@@ -85,6 +111,7 @@ JavaScriptTestTask.new(:test_units) do |t|
85
111
  end
86
112
  end
87
113
 
114
+
88
115
  task :clean_package_source do
89
116
  rm_rf File.join(APP_PKG_DIR, "#{APP_NAME}-#{APP_VERSION}")
90
117
  end
@@ -268,14 +268,14 @@ end
268
268
 
269
269
  class JavaScriptTestTask < ::Rake::TaskLib
270
270
 
271
- def initialize(name=:test)
271
+ def initialize(name=:test, port=4711)
272
272
  @name = name
273
273
  @tests = []
274
274
  @browsers = []
275
-
275
+ @port = port
276
276
  @queue = Queue.new
277
277
 
278
- @server = WEBrick::HTTPServer.new(:Port => 4711) # TODO: make port configurable
278
+ @server = WEBrick::HTTPServer.new(:Port => @port) # TODO: make port configurable
279
279
  @server.mount_proc("/results") do |req, res|
280
280
  @queue.push({
281
281
  :tests => req.query['tests'].to_i,
@@ -308,12 +308,12 @@ class JavaScriptTestTask < ::Rake::TaskLib
308
308
  browser.setup
309
309
  puts "\nStarted tests in #{browser}"
310
310
  @tests.each do |test|
311
- params = "resultsURL=http://localhost:4711/results&t=" + ("%.6f" % Time.now.to_f)
311
+ params = "resultsURL=http://localhost:#{@port}/results&t=" + ("%.6f" % Time.now.to_f)
312
312
  if test.is_a?(Hash)
313
313
  params << "&tests=#{test[:testcases]}" if test[:testcases]
314
314
  test = test[:url]
315
315
  end
316
- browser.visit("http://localhost:4711#{test}?#{params}")
316
+ browser.visit("http://localhost:#{@port}#{test}?#{params}")
317
317
 
318
318
  result = @queue.pop
319
319
  result.each { |k, v| results[k] += v }
@@ -1 +1 @@
1
- script/rstakeout "rake test:recent:javascript" test/*_test.html src/*.js
1
+ script/rstakeout "rake test:recent:javascript" test/unit/*_test.html src/*.js
@@ -10,7 +10,7 @@ namespace :test do
10
10
 
11
11
  since = TEST_CHANGES_SINCE
12
12
  touched = FileList[
13
- 'test/*_test.html',
13
+ 'test/unit/*_test.html',
14
14
  'src/*.js'].select { |path| File.mtime(path) > since }
15
15
  next if touched.blank?
16
16
 
@@ -20,7 +20,7 @@ namespace :test do
20
20
 
21
21
  touched.each do |file|
22
22
  if file =~ /\/([^\/]+)\.js$/
23
- file = "test/#{$1}_test.html"
23
+ file = "test/unit/#{$1}_test.html"
24
24
  end
25
25
  file = "#{APP_ROOT}/#{file}"
26
26
  unless File.exists?(file)
@@ -0,0 +1,2 @@
1
+ Description:
2
+ Creates a functional test file for the final distribution JavaScript file(s).
@@ -0,0 +1,55 @@
1
+ class FunctionalTestGenerator < RubiGen::Base
2
+
3
+ attr_reader :name, :dist_name
4
+
5
+ def initialize(runtime_args, runtime_options = {})
6
+ super
7
+ usage if args.empty?
8
+ @destination_root = File.expand_path(".")
9
+ @name = args.shift
10
+ @dist_name = args.shift || base_name
11
+ extract_options
12
+ end
13
+
14
+ def manifest
15
+ record do |m|
16
+ # Ensure appropriate folder(s) exists
17
+ m.directory 'test/functional'
18
+
19
+ # Create stubs
20
+ m.template "test/test.html.erb", "test/functional/#{name}_test.html"
21
+ end
22
+ end
23
+
24
+ protected
25
+ def banner
26
+ <<-EOS
27
+ Creates a functional test file for the final distribution JavaScript file(s).
28
+
29
+ USAGE: #{$0} #{spec.name} name [dist_name]"
30
+
31
+ NOTES:
32
+ * name - creates a file test/functional/name_test.html
33
+ * dist_name - is for a file dist/base_name.js or dist/dist_name.js
34
+
35
+ EOS
36
+ end
37
+
38
+ def add_options!(opts)
39
+ # opts.separator ''
40
+ # opts.separator 'Options:'
41
+ # For each option below, place the default
42
+ # at the top of the file next to "default_options"
43
+ # opts.on("-a", "--author=\"Your Name\"", String,
44
+ # "Some comment about this option",
45
+ # "Default: none") { |options[:author]| }
46
+ # opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
47
+ end
48
+
49
+ def extract_options
50
+ # for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
51
+ # Templates can access these value via the attr_reader-generated methods, but not the
52
+ # raw instance variable value.
53
+ # @author = options[:author]
54
+ end
55
+ end
@@ -0,0 +1,58 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <title>JavaScript unit test file</title>
6
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
7
+ <script src="../assets/prototype.js" type="text/javascript"></script>
8
+ <script src="../assets/unittest.js" type="text/javascript"></script>
9
+
10
+ <script src="../../dist/<%= dist_name %>.js" type="text/javascript"></script>
11
+
12
+ <link rel="stylesheet" href="../assets/unittest.css" type="text/css" />
13
+ </head>
14
+ <body>
15
+
16
+ <div id="content">
17
+
18
+ <div id="header">
19
+ <h1>JavaScript unit test file</h1>
20
+ <p>
21
+ Functional tests for <strong>dist/<%= name %>.js</strong>.
22
+ </p>
23
+ </div>
24
+
25
+ <!-- Log output (one per Runner, via {testLog: "testlog"} option)-->
26
+ <div id="testlog"></div>
27
+
28
+ <!-- Put sample/test html here -->
29
+ <div id="sample"></div>
30
+ </div>
31
+
32
+ <script type="text/javascript">
33
+ // <![CDATA[
34
+
35
+ new Test.Unit.Runner({
36
+ // replace this with your real tests
37
+ setup: function() {
38
+
39
+ },
40
+
41
+ teardown: function() {
42
+
43
+ },
44
+
45
+ testTruth: function() { with(this) {
46
+ assert(true);
47
+ }}
48
+
49
+ }, {testLog: "testlog"});
50
+ // For each Test.UnitRunner instance, specify the element id where results will be
51
+ // published; e.g. <div id="testlog"/> above.
52
+ // That is, you can have multiple "new Test.Unit.Runner() { ... }" on this page, just
53
+ // create more <div id="testlog2"></div> etc, and pass the element id to the hash above:
54
+ // e.g. {testLog: "testlog2"}
55
+ // ]]>
56
+ </script>
57
+ </body>
58
+ </html>
@@ -4,12 +4,12 @@
4
4
  <head>
5
5
  <title>JavaScript unit test file</title>
6
6
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
7
- <script src="assets/prototype.js" type="text/javascript"></script>
8
- <script src="assets/unittest.js" type="text/javascript"></script>
7
+ <script src="../assets/prototype.js" type="text/javascript"></script>
8
+ <script src="../assets/unittest.js" type="text/javascript"></script>
9
9
 
10
- <script src="../src/<%= library_name %>.js" type="text/javascript"></script>
10
+ <script src="../../src/<%= library_name %>.js" type="text/javascript"></script>
11
11
 
12
- <link rel="stylesheet" href="assets/unittest.css" type="text/css" />
12
+ <link rel="stylesheet" href="../assets/unittest.css" type="text/css" />
13
13
  </head>
14
14
  <body>
15
15
 
@@ -1,4 +1,4 @@
1
- class JavascriptTestGenerator < RubiGen::Base
1
+ class UnitTestGenerator < RubiGen::Base
2
2
 
3
3
  attr_reader :name, :library_name
4
4
 
@@ -13,22 +13,22 @@ class JavascriptTestGenerator < RubiGen::Base
13
13
  def manifest
14
14
  record do |m|
15
15
  # Ensure appropriate folder(s) exists
16
- m.directory 'test'
16
+ m.directory 'test/unit'
17
17
 
18
18
  # Create stubs
19
- m.template "test/test.html.erb", "test/#{name}_test.html"
19
+ m.template "test/test.html.erb", "test/unit/#{name}_test.html"
20
20
  end
21
21
  end
22
22
 
23
23
  protected
24
24
  def banner
25
25
  <<-EOS
26
- Creates an HTML test file for a JavaScript library.
26
+ Creates an HTML unit test file for a JavaScript library.
27
27
 
28
28
  USAGE: #{$0} #{spec.name} name [library_name]"
29
29
 
30
30
  NOTES:
31
- * name - creates a file test/name_test.html
31
+ * name - creates a file test/unit/name_test.html
32
32
  * library_name - is for a file src/library_name.js
33
33
 
34
34
  EOS
@@ -268,14 +268,14 @@ end
268
268
 
269
269
  class JavaScriptTestTask < ::Rake::TaskLib
270
270
 
271
- def initialize(name=:test)
271
+ def initialize(name=:test, port=4711)
272
272
  @name = name
273
273
  @tests = []
274
274
  @browsers = []
275
-
275
+ @port = port
276
276
  @queue = Queue.new
277
277
 
278
- @server = WEBrick::HTTPServer.new(:Port => 4711) # TODO: make port configurable
278
+ @server = WEBrick::HTTPServer.new(:Port => @port) # TODO: make port configurable
279
279
  @server.mount_proc("/results") do |req, res|
280
280
  @queue.push({
281
281
  :tests => req.query['tests'].to_i,
@@ -308,12 +308,12 @@ class JavaScriptTestTask < ::Rake::TaskLib
308
308
  browser.setup
309
309
  puts "\nStarted tests in #{browser}"
310
310
  @tests.each do |test|
311
- params = "resultsURL=http://localhost:4711/results&t=" + ("%.6f" % Time.now.to_f)
311
+ params = "resultsURL=http://localhost:#{@port}/results&t=" + ("%.6f" % Time.now.to_f)
312
312
  if test.is_a?(Hash)
313
313
  params << "&tests=#{test[:testcases]}" if test[:testcases]
314
314
  test = test[:url]
315
315
  end
316
- browser.visit("http://localhost:4711#{test}?#{params}")
316
+ browser.visit("http://localhost:#{@port}#{test}?#{params}")
317
317
 
318
318
  result = @queue.pop
319
319
  result.each { |k, v| results[k] += v }
@@ -1,8 +1,8 @@
1
1
  module Newjs #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 1
4
- MINOR = 0
5
- TINY = 4
4
+ MINOR = 1
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -17,7 +17,7 @@ EOS
17
17
  end
18
18
 
19
19
  desc 'Generate website files'
20
- task :website_generate => :ruby_env do
20
+ task :website_generate => [:ruby_env, :dist] do
21
21
  (Dir['website/**/*.txt'] - Dir['website/version*.txt']).each do |txt|
22
22
  sh %{ #{RUBY_APP} script/txt2html #{txt} > #{txt.gsub(/txt$/,'html')} }
23
23
  end
@@ -6,7 +6,8 @@ This JavaScript project ...
6
6
 
7
7
  h2. Downloading
8
8
 
9
- TODO - where to download the library file?
9
+ <a href="dist/<%= name %>.js"><%= name %>.js</a>
10
+
10
11
 
11
12
  h2. The basics
12
13
 
@@ -27,6 +28,11 @@ Read the "8 steps for fixing other people's code":http://drnicwilliams.com/2007/
27
28
 
28
29
  The trunk repository is <code>svn://rubyforge.org/var/svn/<%= name %>/trunk</code> for anonymous access.
29
30
 
31
+ OR
32
+
33
+ The source project is a "Git":http://git.or.cz/ repository. See <%= author %>'s "master branch":http://github.com/<%= username %>/<%= name %>/tree/master for clone/checkout details.
34
+
35
+
30
36
  h2. License
31
37
 
32
38
  This code is free to use under the terms of the MIT license.
@@ -1,5 +1,5 @@
1
1
  body {
2
- background-color: #8DBD82;
2
+ background-color: #E9C000;
3
3
  font-family: "Georgia", sans-serif;
4
4
  font-size: 16px;
5
5
  line-height: 1.6em;
@@ -24,7 +24,7 @@ li {
24
24
  }
25
25
  a {
26
26
  color: #5E5AFF;
27
- background-color: #A1DDB1;
27
+ background-color: #DDDA89;
28
28
  font-weight: normal;
29
29
  text-decoration: underline;
30
30
  }
@@ -39,7 +39,7 @@ blockquote {
39
39
  }
40
40
 
41
41
  #main {
42
- width: 50em;
42
+ width: 45em;
43
43
  padding: 0;
44
44
  margin: 0 auto;
45
45
  }
@@ -8,9 +8,7 @@
8
8
  <%%= title %>
9
9
  </title>
10
10
  <script src="javascripts/rounded_corners_lite.inc.js" type="text/javascript"></script>
11
- <style>
12
11
 
13
- </style>
14
12
  <script type="text/javascript">
15
13
  window.onload = function() {
16
14
  settings = {
@@ -0,0 +1,56 @@
1
+ require File.join(File.dirname(__FILE__), "test_generator_helper.rb")
2
+
3
+ class TestFunctionalTestGenerator < Test::Unit::TestCase
4
+ include RubiGen::GeneratorTestHelper
5
+
6
+ def setup
7
+ bare_setup
8
+ end
9
+
10
+ def teardown
11
+ bare_teardown
12
+ end
13
+
14
+ # Some generator-related assertions:
15
+ # assert_generated_file(name, &block) # block passed the file contents
16
+ # assert_directory_exists(name)
17
+ # assert_generated_class(name, &block)
18
+ # assert_generated_module(name, &block)
19
+ # assert_generated_test_for(name, &block)
20
+ # The assert_generated_(class|module|test_for) &block is passed the body of the class/module within the file
21
+ # assert_has_method(body, *methods) # check that the body has a list of methods (methods with parentheses not supported yet)
22
+ #
23
+ # Other helper methods are:
24
+ # app_root_files - put this in teardown to show files generated by the test method (e.g. p app_root_files)
25
+ # bare_setup - place this in setup method to create the APP_ROOT folder for each test
26
+ # bare_teardown - place this in teardown method to destroy the TMP_ROOT or APP_ROOT folder after each test
27
+
28
+ def test_generator_without_arguments
29
+ name = "library"
30
+ run_generator('functional_test', [name], sources)
31
+ assert_generated_file("test/functional/library_test.html") do |body|
32
+ expected = %Q{src="../../dist/myproject.js"}
33
+ assert_match(expected, body)
34
+ end
35
+ end
36
+
37
+ def test_generator_with_dist_name_argument
38
+ name = "library"
39
+ dist_name = "foobar"
40
+ run_generator('functional_test', [name, dist_name], sources)
41
+ assert_generated_file("test/functional/library_test.html") do |body|
42
+ expected = %Q{src="../../dist/foobar.js"}
43
+ assert_match(expected, body)
44
+ end
45
+ end
46
+
47
+ private
48
+ def sources
49
+ [RubiGen::PathSource.new(:test, File.join(File.dirname(__FILE__),"..", generator_path))
50
+ ]
51
+ end
52
+
53
+ def generator_path
54
+ "javascript_test_generators"
55
+ end
56
+ end
@@ -1,6 +1,6 @@
1
1
  require File.join(File.dirname(__FILE__), "test_generator_helper.rb")
2
2
 
3
- class TestJavascriptTestGenerator < Test::Unit::TestCase
3
+ class TestUnitTestGenerator < Test::Unit::TestCase
4
4
  include RubiGen::GeneratorTestHelper
5
5
 
6
6
  def setup
@@ -25,10 +25,23 @@ class TestJavascriptTestGenerator < Test::Unit::TestCase
25
25
  # bare_setup - place this in setup method to create the APP_ROOT folder for each test
26
26
  # bare_teardown - place this in teardown method to destroy the TMP_ROOT or APP_ROOT folder after each test
27
27
 
28
- def test_generator_without_options
28
+ def test_generator_without_arguments
29
29
  name = "library"
30
- run_generator('javascript_test', [name], sources)
31
- assert_generated_file("test/library_test.html")
30
+ run_generator('unit_test', [name], sources)
31
+ assert_generated_file("test/unit/library_test.html") do |body|
32
+ expected = %Q{src="../../src/library.js"}
33
+ assert_match(expected, body)
34
+ end
35
+ end
36
+
37
+ def test_generator_with_library
38
+ name = "default_library"
39
+ library = "library"
40
+ run_generator('unit_test', [name, library], sources)
41
+ assert_generated_file("test/unit/default_library_test.html") do |body|
42
+ expected = %Q{src="../../src/library.js"}
43
+ assert_match(expected, body)
44
+ end
32
45
  end
33
46
 
34
47
  private
@@ -8,9 +8,7 @@
8
8
  JavaScript Project Generator
9
9
  </title>
10
10
  <script src="javascripts/rounded_corners_lite.inc.js" type="text/javascript"></script>
11
- <style>
12
11
 
13
- </style>
14
12
  <script type="text/javascript">
15
13
  window.onload = function() {
16
14
  settings = {
@@ -146,11 +144,11 @@ here. That is, your JavaScript project comes with a generator to create new
146
144
  test <span class="caps">HTML</span> files, ready to rock and roll.</p>
147
145
 
148
146
 
149
- <pre>$ script/generate javascript_test some_lib
147
+ <pre>$ script/generate unit_test some_lib
150
148
  exists test
151
- create test/some_lib_test.html</pre>
149
+ create test/unit/some_lib_test.html</pre>
152
150
 
153
- <p>Now edit <code>test/some_lib_test.html</code> and follow the comments
151
+ <p>Now edit <code>test/unit/some_lib_test.html</code> and follow the comments
154
152
  that tell you what to do to write your unit tests.</p>
155
153
 
156
154
 
@@ -158,9 +156,9 @@ that tell you what to do to write your unit tests.</p>
158
156
  library as an additional parameter.</p>
159
157
 
160
158
 
161
- <pre>$ script/generate javascript_test my_library_tests some_lib
159
+ <pre>$ script/generate unit_test my_library_tests some_lib
162
160
  exists test
163
- create test/my_library_tests_test.html</pre>
161
+ create test/unit/my_library_tests_test.html</pre>
164
162
 
165
163
  <h2>Running unit tests</h2>
166
164
 
@@ -378,7 +376,7 @@ and you&#8217;ll love every minute of it.</p>
378
376
 
379
377
  <p>Comments are welcome. Send an email to <a href="mailto:drnicwilliams@gmail.com">Dr Nic Williams</a> via the <a href="http://groups.google.com/group/javascript-project-generator">forum</a></p>
380
378
  <p class="coda">
381
- <a href="drnicwilliams@gmail.com">Dr Nic Williams</a>, 15th February 2008<br>
379
+ <a href="drnicwilliams@gmail.com">Dr Nic Williams</a>, 17th February 2008<br>
382
380
  Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
383
381
  </p>
384
382
  </div>
@@ -37,32 +37,34 @@ h2. Getting started
37
37
 
38
38
  To kick-off your new project/library, run the command-line app <code>newjs</code>:
39
39
 
40
- <pre>$ newjs mylib
41
- create config
42
- create lib
43
- create src
44
- create script
45
- create tasks
46
- create test/assets
47
- create test/assets/unittest.css
48
- create test/assets/unittest.js
49
- create test/assets/prototype.js
50
- create tasks/javascript_test_autotest_tasks.rake
51
- create tasks/environment.rake
52
- create config/javascript_test_autotest.yml.sample
53
- create lib/protodoc.rb
54
- create README.txt
55
- create Rakefile
56
- create History.txt
57
- create License.txt
58
- create src/HEADER
59
- create src/mylib.js
60
- create script/rstakeout
61
- create script/js_autotest
62
- dependency install_rubigen_scripts
63
- exists script
64
- create script/generate
65
- create script/destroy
40
+ <pre>$ newjs mylib -a "Dr Nic" -e "drnicwilliams@gmail.com" -u "http://mylib.rubyforge.org"
41
+ create config
42
+ create lib
43
+ create src
44
+ create script
45
+ create tasks
46
+ create test/assets
47
+ create test/assets/unittest.css
48
+ create test/assets/unittest.js
49
+ create test/assets/prototype.js
50
+ create tasks/javascript_test_autotest_tasks.rake
51
+ create tasks/environment.rake
52
+ create tasks/deploy.rake
53
+ create config/javascript_test_autotest.yml.sample
54
+ create lib/protodoc.rb
55
+ create lib/jstest.rb
56
+ create Rakefile
57
+ create README.txt
58
+ create History.txt
59
+ create License.txt
60
+ create src/HEADER
61
+ create src/mylib.js
62
+ create script/rstakeout
63
+ create script/js_autotest
64
+ dependency install_rubigen_scripts
65
+ exists script
66
+ create script/generate
67
+ create script/destroy
66
68
  </pre>
67
69
 
68
70
  Look at all that!
@@ -80,11 +82,13 @@ When you've got a new version to release, edit <code>Rakefile</code> and modify
80
82
 
81
83
  To merge your <code>src/</code> files into a distribution file, see below.
82
84
 
83
- h2. Generating test HTML files
85
+ h2. Unit testing
84
86
 
85
87
  If you are going to have a <code>src/some_lib.js</code> file, then you'll want a unit
86
88
  test file(s). By default you'd call it <code>test/some_lib_test.html</code>.
87
89
 
90
+ h3. Generating test HTML files
91
+
88
92
  And then what? Personally, I can never remember what basic HTML + JavaScript
89
93
  goes in the test HTML files. I quite like the "javascript_test plugin":http://drnicwilliams.com/2008/01/04/autotesting-javascript-in-rails/ for "Ruby
90
94
  on Rails":http://www.rubyonrails.org/, which allows you to generate a
@@ -92,21 +96,21 @@ test HTML stub. So I've included a version of it
92
96
  here. That is, your JavaScript project comes with a generator to create new
93
97
  test HTML files, ready to rock and roll.
94
98
 
95
- <pre>$ script/generate javascript_test some_lib
96
- exists test
97
- create test/some_lib_test.html</pre>
99
+ <pre>$ script/generate unit_test some_lib
100
+ create test/unit
101
+ create test/unit/some_lib_test.html</pre>
98
102
 
99
- Now edit <code>test/some_lib_test.html</code> and follow the comments
103
+ Now edit <code>test/unit/some_lib_test.html</code> and follow the comments
100
104
  that tell you what to do to write your unit tests.
101
105
 
102
106
  Want to name your test file something different? Specify the target
103
107
  library as an additional parameter.
104
108
 
105
- <pre>$ script/generate javascript_test my_library_tests some_lib
106
- exists test
107
- create test/my_library_tests_test.html</pre>
109
+ <pre>$ script/generate unit_test my_library_tests some_lib
110
+ exists test/unit
111
+ create test/unit/my_library_tests_test.html</pre>
108
112
 
109
- h2. Running unit tests
113
+ h3. Running unit tests
110
114
 
111
115
  Each test HTML file should be self-executable: just open it in a target
112
116
  browser. That is, to run the <code>test/some_lib_test.html</code> tests
@@ -116,6 +120,30 @@ It will print out a beautiful log success/error messages for each test.
116
120
 
117
121
  <img src="images/example-unittest-log.jpg" width="647" height="427" alt="Example Unittest Log">
118
122
 
123
+ h2. Functional tests
124
+
125
+ End-to-end functional tests will test the final distribution file(s), rather than
126
+ the <code>src/</code> files.
127
+
128
+ As shown below, your <code>src/</code> files will be merged into (commonly) one
129
+ distribution file - a merging of your source files.
130
+
131
+ h3. Generating test HTML files
132
+
133
+ To create functional tests, there is another generator:
134
+
135
+ <pre>$ script/generate functional_test basic_usage
136
+ create test/functional
137
+ create test/functional/basic_usage_test.html</pre>
138
+
139
+ h3. Running functional tests
140
+
141
+ <pre>rake test_functionals</pre>
142
+
143
+ The generated HTML file uses the <code>dist/mylib.js</code> file. So, if
144
+ you are running these tests it is best to use the <code>rake test_functionals</code>
145
+ as it pre-builds the distribution files first.
146
+
119
147
  h2. Distribution of library
120
148
 
121
149
  Your project comes with the ability to concatenate all your <code>src/*.js</code>
@@ -8,9 +8,7 @@
8
8
  <%= title %>
9
9
  </title>
10
10
  <script src="javascripts/rounded_corners_lite.inc.js" type="text/javascript"></script>
11
- <style>
12
11
 
13
- </style>
14
12
  <script type="text/javascript">
15
13
  window.onload = function() {
16
14
  settings = {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: newjs
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dr Nic Williams
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-02-16 00:00:00 +10:00
12
+ date: 2008-02-17 00:00:00 +10:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -60,7 +60,6 @@ extra_rdoc_files:
60
60
  - License.txt
61
61
  - Manifest.txt
62
62
  - README.txt
63
- - app_generators/newjs/templates/README.txt
64
63
  - newjs_generators/install_website/templates/website/index.txt
65
64
  - website/index.txt
66
65
  files:
@@ -73,7 +72,7 @@ files:
73
72
  - app_generators/newjs/newjs_generator.rb
74
73
  - app_generators/newjs/templates/History.txt.erb
75
74
  - app_generators/newjs/templates/License.txt.erb
76
- - app_generators/newjs/templates/README.txt
75
+ - app_generators/newjs/templates/README.txt.erb
77
76
  - app_generators/newjs/templates/Rakefile.erb
78
77
  - app_generators/newjs/templates/config/javascript_test_autotest.yml.sample
79
78
  - app_generators/newjs/templates/lib/jstest.rb
@@ -91,9 +90,12 @@ files:
91
90
  - bin/newjs
92
91
  - config/hoe.rb
93
92
  - config/requirements.rb
94
- - javascript_test_generators/javascript_test/USAGE
95
- - javascript_test_generators/javascript_test/javascript_test_generator.rb
96
- - javascript_test_generators/javascript_test/templates/test/test.html.erb
93
+ - javascript_test_generators/functional_test/USAGE
94
+ - javascript_test_generators/functional_test/functional_test_generator.rb
95
+ - javascript_test_generators/functional_test/templates/test/test.html.erb
96
+ - javascript_test_generators/unit_test/USAGE
97
+ - javascript_test_generators/unit_test/templates/test/test.html.erb
98
+ - javascript_test_generators/unit_test/unit_test_generator.rb
97
99
  - lib/newjs.rb
98
100
  - lib/newjs/autotest.rb
99
101
  - lib/newjs/autotest/javascript_test_autotest.rb
@@ -123,12 +125,13 @@ files:
123
125
  - tasks/deployment.rake
124
126
  - tasks/environment.rake
125
127
  - tasks/website.rake
128
+ - test/test_functional_test_generator.rb
126
129
  - test/test_generator_helper.rb
127
130
  - test/test_helper.rb
128
131
  - test/test_install_website_generator.rb
129
- - test/test_javascript_test_generator.rb
130
132
  - test/test_newjs_generator.rb
131
133
  - test/test_plain_theme_generator.rb
134
+ - test/test_unit_test_generator.rb
132
135
  - website/images/example-unittest-log.jpg
133
136
  - website/index.html
134
137
  - website/index.txt
@@ -163,9 +166,10 @@ signing_key:
163
166
  specification_version: 2
164
167
  summary: "Description: The +newjs+ command creates a new JavaScript project/application with a default directory structure and configuration at the path you specify."
165
168
  test_files:
169
+ - test/test_functional_test_generator.rb
166
170
  - test/test_generator_helper.rb
167
171
  - test/test_helper.rb
168
172
  - test/test_install_website_generator.rb
169
- - test/test_javascript_test_generator.rb
170
173
  - test/test_newjs_generator.rb
171
174
  - test/test_plain_theme_generator.rb
175
+ - test/test_unit_test_generator.rb