newjs 1.3.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,7 @@
1
+ == 1.3.1 2008-02-18
2
+
3
+ * rails/javascript_test: unpacks rstakeout/js_autotest too
4
+
1
5
  == 1.3.0 2008-02-18
2
6
 
3
7
  * rails: javascript_test generator - creates HTML test, plus installs assets + rake tasks
@@ -14,6 +14,7 @@ app_generators/newjs/templates/lib/jstest.rb
14
14
  app_generators/newjs/templates/lib/protodoc.rb
15
15
  app_generators/newjs/templates/script/js_autotest
16
16
  app_generators/newjs/templates/script/rstakeout
17
+ app_generators/newjs/templates/script/win_script.cmd
17
18
  app_generators/newjs/templates/src/HEADER.erb
18
19
  app_generators/newjs/templates/src/library.js.erb
19
20
  app_generators/newjs/templates/tasks/deploy.rake
@@ -58,9 +59,17 @@ rails_generators/javascript_test/USAGE
58
59
  rails_generators/javascript_test/javascript_test_generator.rb
59
60
  rails_generators/javascript_test/templates/assets/jsunittest.js
60
61
  rails_generators/javascript_test/templates/assets/unittest.css
62
+ rails_generators/javascript_test/templates/config/javascript_test_autotest.yml.sample
61
63
  rails_generators/javascript_test/templates/plugins/javascript_unittest/README
64
+ rails_generators/javascript_test/templates/plugins/javascript_unittest/lib/autotest/javascript_test_autotest.rb
65
+ rails_generators/javascript_test/templates/plugins/javascript_unittest/lib/autotest/javascript_test_autotest/config.rb
66
+ rails_generators/javascript_test/templates/plugins/javascript_unittest/lib/autotest/javascript_test_ext.rb
62
67
  rails_generators/javascript_test/templates/plugins/javascript_unittest/lib/jstest.rb
68
+ rails_generators/javascript_test/templates/plugins/javascript_unittest/tasks/autotest.rake
63
69
  rails_generators/javascript_test/templates/plugins/javascript_unittest/tasks/runner.rake
70
+ rails_generators/javascript_test/templates/script/js_autotest
71
+ rails_generators/javascript_test/templates/script/rstakeout
72
+ rails_generators/javascript_test/templates/script/win_script.cmd
64
73
  rails_generators/javascript_test/templates/test.html.erb
65
74
  script/destroy
66
75
  script/generate
@@ -33,9 +33,6 @@ class NewjsGenerator < RubiGen::Base
33
33
  m.directory ''
34
34
  BASEDIRS.each { |path| m.directory path }
35
35
 
36
- # Create stubs
37
- # m.template "template.rb", "some_file_after_erb.rb"
38
- # m.file "file", "some_file_copied"
39
36
  m.file_copy_each %w[unittest.css jsunittest.js], "test/assets"
40
37
  m.file_copy_each %w[javascript_test_autotest_tasks.rake environment.rake deploy.rake], "tasks"
41
38
  m.file_copy_each %w[javascript_test_autotest.yml.sample], "config"
@@ -0,0 +1 @@
1
+ @ruby <%= File.join("script", filename) %> %*
@@ -24,9 +24,10 @@ namespace :test do
24
24
  end
25
25
  file = "#{APP_ROOT}/#{file}"
26
26
  unless File.exists?(file)
27
- puts "Notice: Test file does not exist: #{file}"
27
+ # puts "Notice: Test file does not exist: #{file}"
28
28
  next
29
29
  end
30
+ puts "Launching test: #{file}"
30
31
  browsers = JavascriptTestAutotest::Config.get :browsers
31
32
  if browsers.blank?
32
33
  puts "WARNING: No browsers setup in config/javascript_test_autotest.yml"
@@ -2,7 +2,7 @@ module Newjs #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 1
4
4
  MINOR = 3
5
- TINY = 0
5
+ TINY = 1
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -1,4 +1,6 @@
1
1
  class JavascriptTestGenerator < Rails::Generator::Base
2
+ DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
3
+ Config::CONFIG['ruby_install_name'])
2
4
 
3
5
  default_options :author => nil
4
6
 
@@ -13,8 +15,13 @@ class JavascriptTestGenerator < Rails::Generator::Base
13
15
  end
14
16
 
15
17
  def manifest
18
+ script_options = { :chmod => 0755, :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang] }
19
+ windows = (RUBY_PLATFORM =~ /dos|win32|cygwin/i) || (RUBY_PLATFORM =~ /(:?mswin|mingw)/)
20
+
16
21
  record do |m|
17
22
  # Ensure appropriate folder(s) exists
23
+ m.directory 'config'
24
+ m.directory 'script'
18
25
  m.directory 'test/javascript/assets'
19
26
  m.directory 'vendor/plugins/javascript_unittest/lib'
20
27
  m.directory 'vendor/plugins/javascript_unittest/tasks'
@@ -22,13 +29,25 @@ class JavascriptTestGenerator < Rails::Generator::Base
22
29
  # Create stubs
23
30
  m.file "assets/jsunittest.js", "test/javascript/assets/jsunittest.js"
24
31
  m.file "assets/unittest.css", "test/javascript/assets/unittest.css"
32
+
33
+ m.file "config/javascript_test_autotest.yml.sample",
34
+ "config/javascript_test_autotest.yml.sample"
35
+
25
36
  m.file "plugins/javascript_unittest/lib/jstest.rb",
26
37
  "vendor/plugins/javascript_unittest/lib/jstest.rb"
27
38
  m.file "plugins/javascript_unittest/tasks/runner.rake",
28
39
  "vendor/plugins/javascript_unittest/tasks/runner.rake"
40
+ m.file "plugins/javascript_unittest/tasks/autotest.rake",
41
+ "vendor/plugins/javascript_unittest/tasks/autotest.rake"
29
42
  m.file "plugins/javascript_unittest/README",
30
43
  "vendor/plugins/javascript_unittest/README"
31
44
  m.template "test.html.erb", "test/javascript/#{name}_test.html"
45
+
46
+ %w[rstakeout js_autotest].each do |file|
47
+ m.template "script/#{file}", "script/#{file}", script_options
48
+ m.template "script/win_script.cmd", "script/#{file}.cmd",
49
+ :assigns => { :filename => file } if windows
50
+ end
32
51
  end
33
52
  end
34
53
 
@@ -0,0 +1,15 @@
1
+ # This file has been copied here by the javascript_test_autotest plugin.
2
+ # Comment/uncomment the browsers you wish to autotest with.
3
+ # Same schema as per selenium-on-rails plugin, which is nice.
4
+ browsers:
5
+ # Windows
6
+ # firefox: 'c:\Program Files\Mozilla Firefox\firefox.exe'
7
+ # ie: 'c:\Program Files\Internet Explorer\iexplore.exe'
8
+
9
+ # Mac OS X
10
+ # firefox: '/Applications/Firefox.app/Contents/MacOS/firefox-bin'
11
+ safari: '/Applications/Safari.app/Contents/MacOS/Safari'
12
+
13
+ # Unix
14
+ # ?
15
+ # ?
@@ -0,0 +1,22 @@
1
+ module JavascriptTestAutotest
2
+ class Browser
3
+ class << self
4
+ def browser(browser, path)
5
+ case(browser.to_sym)
6
+ when :firefox
7
+ JavaScriptTest::FirefoxBrowser.new(path)
8
+ when :safari
9
+ JavaScriptTest::SafariBrowser.new(path)
10
+ when :ie
11
+ JavaScriptTest::IEBrowser.new(path)
12
+ when :konqueror
13
+ JavaScriptTest::KonquerorBrowser.new(path)
14
+ else
15
+ browser
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ require "javascript_test_autotest/config"
@@ -0,0 +1,20 @@
1
+ require 'yaml'
2
+
3
+ class JavascriptTestAutotest::Config
4
+ def self.get var, default = nil
5
+ value = configs[var.to_s]
6
+ value ||= default
7
+ value ||= yield if block_given?
8
+ value
9
+ end
10
+
11
+ private
12
+ def self.configs
13
+ unless defined? @@configs
14
+ file = File.expand_path("#{RAILS_ROOT}/config/javascript_test_autotest.yml")
15
+ @@configs = File.exist?(file) ? YAML.load_file(file) : {}
16
+ end
17
+ @@configs
18
+ end
19
+
20
+ end
@@ -0,0 +1,16 @@
1
+ class JavaScriptTest::Browser
2
+ def initialize(path)
3
+ @path = path
4
+ end
5
+ end
6
+
7
+ if JavaScriptTest::Browser.new('').macos?
8
+ class JavaScriptTest::SafariBrowser
9
+ def setup; end # no need to create new Browser, as open command automates this
10
+ def visit(file)
11
+ @path ||= 'Safari.app'
12
+ `open #{file} -a #{@path} -g`
13
+ end
14
+ def setup; end # no need to destroy Browser
15
+ end
16
+ end
@@ -0,0 +1,40 @@
1
+ namespace :test do
2
+ namespace :recent do
3
+ desc "Open recently modified files into browser"
4
+ task :javascript => :environment do
5
+ APP_ROOT = RAILS_ROOT unless Object.const_defined?("APP_ROOT")
6
+ since = TEST_CHANGES_SINCE
7
+ touched = FileList[
8
+ 'test/javascript/*_test.html',
9
+ 'public/javascripts/*.js'].select { |path| File.mtime(path) > since }
10
+ next if touched.blank?
11
+
12
+ gem 'newjs'
13
+ require 'newjs'
14
+ require 'newjs/autotest'
15
+
16
+ touched.each do |file|
17
+ if file =~ /\/([^\/]+)\.js$/
18
+ file = "test/unit/#{$1}_test.html"
19
+ end
20
+ file = "#{RAILS_ROOT}/#{file}"
21
+ unless File.exists?(file)
22
+ # puts "Notice: Test file does not exist: #{file}"
23
+ next
24
+ end
25
+ puts "Launching test: #{file}"
26
+ browsers = JavascriptTestAutotest::Config.get :browsers
27
+ if browsers.blank?
28
+ puts "WARNING: No browsers setup in config/javascript_test_autotest.yml"
29
+ next
30
+ end
31
+ browsers.each_pair do |name, path|
32
+ browser = JavascriptTestAutotest::Browser.browser(name, path)
33
+ browser.setup
34
+ browser.visit(file)
35
+ browser.teardown
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1 @@
1
+ script/rstakeout "rake test:recent:javascript" test/javascript/*_test.html public/javascripts/*.js
@@ -0,0 +1,98 @@
1
+ #!/usr/local/bin/ruby -w
2
+
3
+
4
+ config = File.dirname(__FILE__) + "/../config/javascript_test_autotest.yml"
5
+ unless File.exists?(config)
6
+ puts <<-EOS
7
+ Edit config/javascript_test_autotest.yml for the browser(s) to use for autotesting.
8
+ See config/javascript_test_autotest.yml.sample for examples.
9
+ EOS
10
+ exit
11
+ end
12
+
13
+ ##
14
+ # Originally by Mike Clark.
15
+ #
16
+ # From http://www.pragmaticautomation.com/cgi-bin/pragauto.cgi/Monitor/StakingOutFileChanges.rdoc
17
+ #
18
+ # Runs a user-defined command when files are modified.
19
+ #
20
+ # Like autotest, but more customizable. This is useful when you want to do
21
+ # something other than run tests. For example, generate a PDF book, run
22
+ # a single test, or run a legacy Test::Unit suite in an app that also
23
+ # has an rSpec suite.
24
+ #
25
+ # Can use Ruby's Dir[] to get file glob. Quote your args to take advantage of this.
26
+ #
27
+ # rstakeout 'rake test:recent' **/*.rb
28
+ # => Only watches Ruby files one directory down (no quotes)
29
+ #
30
+ # rstakeout 'rake test:recent' '**/*.rb'
31
+ # => Watches all Ruby files in all directories and subdirectories
32
+ #
33
+ # Modified (with permission) by Geoffrey Grosenbach to call growlnotify for
34
+ # rspec and Test::Unit output.
35
+ #
36
+ # See the PeepCode screencast on rSpec or other blog articles for instructions on
37
+ # setting up growlnotify.
38
+
39
+ def growl(title, msg, img, pri=0, sticky="")
40
+ system "growlnotify -n autotest --image ~/.autotest_images/#{img} -p #{pri} -m #{msg.inspect} #{title} #{sticky}"
41
+ end
42
+
43
+ def self.growl_fail(output)
44
+ growl "FAIL", "#{output}", "fail.png", 2
45
+ end
46
+
47
+ def self.growl_pass(output)
48
+ growl "Pass", "#{output}", "pass.png"
49
+ end
50
+
51
+ command = ARGV.shift
52
+ files = {}
53
+
54
+ ARGV.each do |arg|
55
+ Dir[arg].each { |file|
56
+ files[file] = File.mtime(file)
57
+ }
58
+ end
59
+
60
+ puts "Watching #{files.keys.join(', ')}\n\nFiles: #{files.keys.length}"
61
+
62
+ trap('INT') do
63
+ puts "\nQuitting..."
64
+ exit
65
+ end
66
+
67
+
68
+ loop do
69
+
70
+ sleep 1
71
+
72
+ changed_file, last_changed = files.find { |file, last_changed|
73
+ File.mtime(file) > last_changed
74
+ }
75
+
76
+ if changed_file
77
+ files[changed_file] = File.mtime(changed_file)
78
+ puts "=> #{changed_file} changed, running #{command}"
79
+ results = `#{command}`
80
+ puts results
81
+
82
+ if results.include? 'tests'
83
+ output = results.slice(/(\d+)\s+tests?,\s*(\d+)\s+assertions?,\s*(\d+)\s+failures?(,\s*(\d+)\s+errors)?/)
84
+ if output
85
+ $~[3].to_i + $~[5].to_i > 0 ? growl_fail(output) : growl_pass(output)
86
+ end
87
+ else
88
+ output = results.slice(/(\d+)\s+examples?,\s*(\d+)\s+failures?(,\s*(\d+)\s+not implemented)?/)
89
+ if output
90
+ $~[2].to_i > 0 ? growl_fail(output) : growl_pass(output)
91
+ end
92
+ end
93
+ # TODO Generic growl notification for other actions
94
+
95
+ puts "=> done"
96
+ end
97
+
98
+ end
@@ -0,0 +1 @@
1
+ @ruby <%= File.join("script", filename) %> %*
@@ -37,14 +37,19 @@ class TestJavascriptTestGenerator < Test::Unit::TestCase
37
37
  run_generator('javascript_test', [name], sources)
38
38
  assert_directory_exists "test/javascript/assets"
39
39
  assert_directory_exists "vendor/plugins/javascript_unittest"
40
+ assert_directory_exists "script"
40
41
  assert_generated_file "test/javascript/assets/jsunittest.js"
41
42
  assert_generated_file "test/javascript/assets/unittest.css"
42
43
  assert_generated_file "test/javascript/#{name}_test.html" do |body|
43
44
  expected = %Q{src="assets/jsunittest.js"}
44
45
  assert_match(expected, body)
45
46
  end
47
+ assert_generated_file "script/rstakeout"
48
+ assert_generated_file "script/js_autotest"
49
+ assert_generated_file "config/javascript_test_autotest.yml.sample"
46
50
  assert_generated_file "vendor/plugins/javascript_unittest/lib/jstest.rb"
47
51
  assert_generated_file "vendor/plugins/javascript_unittest/tasks/runner.rake"
52
+ assert_generated_file "vendor/plugins/javascript_unittest/tasks/autotest.rake"
48
53
  assert_generated_file "vendor/plugins/javascript_unittest/README"
49
54
  end
50
55
 
@@ -31,7 +31,7 @@
31
31
  <h1>JavaScript Project Generator</h1>
32
32
  <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/newjs"; return false'>
33
33
  <p>Get Version</p>
34
- <a href="http://rubyforge.org/projects/newjs" class="numbers">1.3.0</a>
34
+ <a href="http://rubyforge.org/projects/newjs" class="numbers">1.3.1</a>
35
35
  </div>
36
36
  <h1>&#x2192; &#8216;newjs&#8217;</h1>
37
37
 
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.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dr Nic Williams
@@ -79,6 +79,7 @@ files:
79
79
  - app_generators/newjs/templates/lib/protodoc.rb
80
80
  - app_generators/newjs/templates/script/js_autotest
81
81
  - app_generators/newjs/templates/script/rstakeout
82
+ - app_generators/newjs/templates/script/win_script.cmd
82
83
  - app_generators/newjs/templates/src/HEADER.erb
83
84
  - app_generators/newjs/templates/src/library.js.erb
84
85
  - app_generators/newjs/templates/tasks/deploy.rake
@@ -123,9 +124,17 @@ files:
123
124
  - rails_generators/javascript_test/javascript_test_generator.rb
124
125
  - rails_generators/javascript_test/templates/assets/jsunittest.js
125
126
  - rails_generators/javascript_test/templates/assets/unittest.css
127
+ - rails_generators/javascript_test/templates/config/javascript_test_autotest.yml.sample
126
128
  - rails_generators/javascript_test/templates/plugins/javascript_unittest/README
129
+ - rails_generators/javascript_test/templates/plugins/javascript_unittest/lib/autotest/javascript_test_autotest.rb
130
+ - rails_generators/javascript_test/templates/plugins/javascript_unittest/lib/autotest/javascript_test_autotest/config.rb
131
+ - rails_generators/javascript_test/templates/plugins/javascript_unittest/lib/autotest/javascript_test_ext.rb
127
132
  - rails_generators/javascript_test/templates/plugins/javascript_unittest/lib/jstest.rb
133
+ - rails_generators/javascript_test/templates/plugins/javascript_unittest/tasks/autotest.rake
128
134
  - rails_generators/javascript_test/templates/plugins/javascript_unittest/tasks/runner.rake
135
+ - rails_generators/javascript_test/templates/script/js_autotest
136
+ - rails_generators/javascript_test/templates/script/rstakeout
137
+ - rails_generators/javascript_test/templates/script/win_script.cmd
129
138
  - rails_generators/javascript_test/templates/test.html.erb
130
139
  - script/destroy
131
140
  - script/generate