jstdutil 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Christian Johansen
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,18 @@
1
+ = jstdutil
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but
13
+ bump version in a commit by itself I can ignore when I pull)
14
+ * Send me a pull request. Bonus points for topic branches.
15
+
16
+ == Copyright
17
+
18
+ Copyright (c) 2009 Christian Johansen. See LICENSE for details.
@@ -0,0 +1,64 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "jstdutil"
8
+ gem.summary = "Thin wrapper over Google's JsTestDriver that adds colors and autotest"
9
+ gem.description = "Thin wrapper over Google's JsTestDriver that adds colors and autotest"
10
+ gem.email = "christian@cjohansen.no"
11
+ gem.homepage = "http://github.com/cjohansen/jstdutil"
12
+ gem.authors = ["Christian Johansen"]
13
+ gem.rubyforge_project = "jstdutil"
14
+ gem.add_development_dependency "thoughtbot-shoulda"
15
+ gem.add_dependency "watchr"
16
+ gem.add_dependency "rake"
17
+ gem.executables = ["jstestdriver", "jsautotest"]
18
+ gem.files = FileList["[A-Z]*", "{bin,generators,lib,test}/**/*"]
19
+ end
20
+ Jeweler::GemcutterTasks.new
21
+ Jeweler::RubyforgeTasks.new do |rubyforge|
22
+ rubyforge.doc_task = "rdoc"
23
+ end
24
+ rescue LoadError
25
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
26
+ end
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/*_test.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ begin
36
+ require 'rcov/rcovtask'
37
+ Rcov::RcovTask.new do |test|
38
+ test.libs << 'test'
39
+ test.pattern = 'test/**/*_test.rb'
40
+ test.verbose = true
41
+ end
42
+ rescue LoadError
43
+ task :rcov do
44
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
45
+ end
46
+ end
47
+
48
+ task :test => :check_dependencies
49
+
50
+ task :default => :test
51
+
52
+ require 'rake/rdoctask'
53
+ Rake::RDocTask.new do |rdoc|
54
+ if File.exist?('VERSION')
55
+ version = File.read('VERSION')
56
+ else
57
+ version = ""
58
+ end
59
+
60
+ rdoc.rdoc_dir = 'rdoc'
61
+ rdoc.title = "jstdutil #{version}"
62
+ rdoc.rdoc_files.include('README*')
63
+ rdoc.rdoc_files.include('lib/**/*.rb')
64
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ require "jstdutil"
3
+ require "jstdutil/autotest"
4
+
5
+ Jstdutil::Autotest.new($*).run
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ begin
3
+ require "jstdutil"
4
+ require "jstdutil/cli"
5
+ rescue LoadError => err
6
+ exit
7
+ end
8
+
9
+ begin
10
+ $stdout.puts Jstdutil::Cli.run($*)
11
+ rescue StandardError => err
12
+ # Swallow...
13
+ end
@@ -0,0 +1,40 @@
1
+ require "jstdutil/redgreen"
2
+ #require "jstdutil/autotest"
3
+
4
+ module Jstdutil
5
+ def self.install_dir
6
+ File.expand_path(File.dirname(__FILE__))
7
+ end
8
+
9
+ #
10
+ # Locate Jar file from a given path. Default classpath is $JSTDUTIL_HOME
11
+ # Finds and returns the first file matching jstest*.jar (case insensitive).
12
+ # Also checks current working directory
13
+ #
14
+ def self.jar(classpath = ENV["JSTESTDRIVER_HOME"] || Dir.pwd)
15
+ files = Dir.glob(File.join(classpath, 'jstest*.jar'), File::FNM_CASEFOLD)
16
+ files.sort! { |f1, f2| f1.downcase <=> f2.downcase }
17
+
18
+ if !files || !files.first
19
+ msg = "Unable to load jar file from #{classpath}\n" <<
20
+ "Check that $JSTESTDRIVER_HOME is set correctly"
21
+ raise FileNotFoundError.new(msg)
22
+ end
23
+
24
+ files[-1]
25
+ end
26
+
27
+ #
28
+ # Run the jar through the java command
29
+ #
30
+ def self.run(args, jar)
31
+ begin
32
+ `java -jar #{jar} #{args}`
33
+ rescue Exception
34
+ puts "I N T E R R U P T"
35
+ end
36
+ end
37
+ end
38
+
39
+ class FileNotFoundError < StandardError
40
+ end
@@ -0,0 +1,39 @@
1
+ require "jstdutil/test_runner"
2
+ require "jstdutil/hooks"
3
+ require "watchr"
4
+
5
+ module Jstdutil
6
+ class Autotest
7
+ attr_reader :runner
8
+ AVAILABLE_HOOKS = [:initialize, :died, :quit, :ran_command, :run_command, :waiting]
9
+ include Hooks
10
+
11
+ def initialize(args)
12
+ absolute_path = Pathname(File.join(Jstdutil.install_dir, "watchr_script"))
13
+ script = Watchr::Script.new(absolute_path)
14
+ @watchr_controller = Watchr::Controller.new(script, Watchr.handler.new)
15
+ @runner = Jstdutil::TestRunner.new(args)
16
+ $jstestdriver_test_runner = @runner
17
+ @interrupted_at = nil
18
+ end
19
+
20
+ def run
21
+ hook(:initialize)
22
+
23
+ trap("INT") do
24
+ if @interrupted_at && Time.now - @interrupted_at < 2
25
+ puts "No more testing today, shutting down"
26
+ @runner.finalize
27
+ exit
28
+ else
29
+ @interrupted_at = Time.now
30
+ puts "Running all tests, hit Ctrl-c again to exit"
31
+ @runner.run
32
+ end
33
+ end
34
+
35
+ @runner.run
36
+ @watchr_controller.run
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,22 @@
1
+ module Jstdutil
2
+ #
3
+ # <tt>Jstdutil::Cli</tt> is a tiny wrapper to the JsTestDriver
4
+ # jar, simply allowing you to avoid the clunkiness of <tt>`java -jar FILE [ARGS]`</tt>
5
+ #
6
+ # The wrapper also formats output with <tt>JsRedGreen</tt>, yielding
7
+ # beautiful test reports.
8
+ #
9
+ # In addition to the JsTestDriver arguments you can specify the path
10
+ # to the jar file by --jar. This kinda defeats the purpose, though,
11
+ # so a better solution is to set the environment variable
12
+ # $JSTESTDRIVER_HOME to where the jar file lives (see <tt>JsTestDriver.jar</tt>).
13
+ #
14
+ class Cli
15
+ def self.run(args = [])
16
+ args = args.join(" ")
17
+ jar = (args.match(/--jar\s+([^\s]+)/) || [])[1] || Jstdutil.jar
18
+
19
+ Jstdutil::RedGreen.format(Jstdutil.run("#{args.sub(/--jar\s+[^\s]+/, '')}", jar))
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,29 @@
1
+ #
2
+ # Observer module/hooks module, modeled exactly like
3
+ # ZenTest::Autotest, in order to ease porting of addons like autotest-screen
4
+ #
5
+ # In order to use the hooks module, the including class needs to define an
6
+ # AVAILABLE_HOOKS constant hash. The rest is handled by the mixin module.
7
+ #
8
+ module Hooks
9
+ def self.included(target)
10
+ target.class_eval do
11
+ @@hooks = {}
12
+ target::AVAILABLE_HOOKS.each { |hook| @@hooks[hook] = [] }
13
+
14
+ def self.add_hook(hook, &block)
15
+ @@hooks[hook] << block
16
+ end
17
+
18
+ def self.hook(hook, *args)
19
+ @@hooks[hook].any? do |plugin|
20
+ plugin[self, *args]
21
+ end
22
+ end
23
+
24
+ def hook(hook)
25
+ self.class.hook(hook)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,39 @@
1
+ module Jstdutil
2
+ module JsTestDriver
3
+ # Simple interface to JsTestDriver configuration
4
+ # Can instantiate with either a configuration file or string contents
5
+ #
6
+ # config = Jstdutil::JsTestDriverConfig.new "jsTestDriver.conf"
7
+ # config.server #=> "http://localhost:4224"
8
+ #
9
+ class Config
10
+ def initialize(file)
11
+ begin
12
+ load_config(File.read(file))
13
+ rescue
14
+ load_config(file)
15
+ rescue
16
+ msg = "Configuration must be an existing file or valid JsTestDriver " <<
17
+ "configuration string (contain atleast server)"
18
+ raise ArgumentError.new(msg)
19
+ end
20
+ end
21
+
22
+ def method_missing(name, *args, &block)
23
+ return @contents[name.to_s] if @contents.key?(name.to_s)
24
+ super
25
+ end
26
+
27
+ private
28
+ def load_config(contents)
29
+ @contents = YAML.load(contents)
30
+
31
+ if !@contents.respond_to?(:key?) || !@contents.key?("server")
32
+ raise ArgumentError.new("Error: Missing 'server' setting")
33
+ end
34
+
35
+ @contents
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,58 @@
1
+ # require 'open3'
2
+ require "uri"
3
+
4
+ module Jstdutil
5
+ module JsTestDriver
6
+ class Server
7
+ def initialize(config, args = nil)
8
+ @uri = URI.parse(config.respond_to?(:server) ? config.server : config)
9
+ @args = args
10
+ # @server = nil
11
+ @pid = nil
12
+ end
13
+
14
+ def running?
15
+ response = nil
16
+
17
+ begin
18
+ Net::HTTP.start(@uri.host, @uri.port) { |http| response = http.head("/") }
19
+ rescue Errno::ECONNREFUSED => err
20
+ return false
21
+ end
22
+
23
+ response.code == "200"
24
+ end
25
+
26
+ def start
27
+ if !["localhost", "127.0.0.1", "0.0.0.0"].include?(@uri.host)
28
+ raise "Unable to start remote server on #{@uri.host}"
29
+ end
30
+
31
+ puts "Starting server on http://#{@uri.host}:#{@uri.port}"
32
+ # @server = IO.popen("jstestdriver #{@args} --port #{@uri.port}")
33
+ # [stdin, stdout, stderr] = Open3.popen3("jstestdriver #{@args} --port #{@uri.port}")
34
+ # @server = stderr
35
+
36
+ @pid = Process.fork do
37
+ io = `jstestdriver --port #{@uri.port}`
38
+
39
+ Signal.trap("HUP") do
40
+ puts "JsTestDriver at port #@port going down"
41
+ !io.closed? && io.close!
42
+ exit
43
+ end
44
+ end
45
+
46
+ # sleep 0.5
47
+ end
48
+
49
+ def stop
50
+ # @server && !@server.closed? && @server.close
51
+ if @pid
52
+ Process.kill("HUP", @pid)
53
+ Process.wait
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,40 @@
1
+ module Jstdutil
2
+ class RedGreen
3
+ # Borrowed from the ruby redgreen gem
4
+ # Not included as a gem dependency since it drags in Test::Unit
5
+ # and friends, which is overkill for our situation
6
+ module Color
7
+ COLORS = { :clear => 0, :red => 31, :green => 32, :yellow => 33 }
8
+
9
+ def self.method_missing(color_name, *args)
10
+ color(color_name) + args.first + color(:clear)
11
+ end
12
+
13
+ def self.color(color)
14
+ "\e[#{COLORS[color.to_sym]}m"
15
+ end
16
+ end
17
+
18
+ #
19
+ # Process report from JsTestDriver and colorize it with beautiful
20
+ # colors. Returns report with encoded colors.
21
+ #
22
+ def self.format(report)
23
+ report.split("\n").collect do |line|
24
+ if line =~ /Passed: \d+; Fails: (\d+); Errors:? (\d+)/
25
+ Color.send($1.to_i + $2.to_i != 0 ? :red : :green, line)
26
+ elsif line =~ /^[\.EF]+$/
27
+ line.gsub(/\./, Color.green(".")).gsub(/F/, Color.red("F")).gsub("E", Color.yellow("E"))
28
+ elsif line =~ /failed/
29
+ Color.red(line)
30
+ elsif line =~ /passed/
31
+ Color.green(line)
32
+ elsif line =~ /error/
33
+ Color.yellow(line)
34
+ else
35
+ line
36
+ end
37
+ end.join("\n")
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,33 @@
1
+ require "rake"
2
+
3
+ module Jstdutil
4
+ # Knows how to map source files to test files, how to extract test cases
5
+ # and so on.
6
+ #
7
+ class TestFile
8
+ def initialize(file)
9
+ @file = file
10
+ end
11
+
12
+ def test_files
13
+ return @test_files if @test_files
14
+
15
+ if @file =~ /(_test[^\/]+)|([^\/]+_test)\.js/
16
+ @test_files = [@file]
17
+ else
18
+ name = File.basename(@file).gsub(/(_test)|(test_)|(\.js)/, "")
19
+ @test_files = FileList["**/#{name}_test.js", "**/test_#{name}.js"].uniq
20
+ end
21
+ end
22
+
23
+ def test_cases
24
+ return @cases if @cases
25
+
26
+ @cases = test_files.collect do |file|
27
+ File.read(file).scan(/TestCase\(["']([^"']*)/)
28
+ end
29
+
30
+ @cases.flatten!
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,55 @@
1
+ require "jstdutil/jstestdriver/config"
2
+ require "jstdutil/jstestdriver/server"
3
+ require "jstdutil/cli"
4
+ require "jstdutil/test_file"
5
+ require "net/http"
6
+
7
+ module Jstdutil
8
+ class TestRunner
9
+ def initialize(args = [])
10
+ @args = strip_opt(args.join(" "), "tests")
11
+ config = @args.scan(/--config\s+([^\s]+)/).flatten
12
+ config = config.first || File.expand_path("jsTestDriver.conf")
13
+ config = JsTestDriver::Config.new(config)
14
+
15
+ if config && config.server
16
+ @server = JsTestDriver::Server.new(config, args({}, ["port"]).join(" "))
17
+ end
18
+ end
19
+
20
+ def test_cases(files)
21
+ files = files.respond_to?(:captures) ? files.captures : files
22
+ cases = files.collect { |file| TestFile.new(file).test_cases }.flatten.join(",")
23
+
24
+ cases == "" && "all" || cases
25
+ end
26
+
27
+ def run(tests = "all")
28
+ begin
29
+ @server.start unless @server.running?
30
+ rescue StandardError => err
31
+ puts err.message
32
+ end
33
+
34
+ puts(Time.now.strftime("%F %H:%M:%S Running #{tests}"))
35
+ puts(Jstdutil::Cli.run(args("tests" => tests)))
36
+ end
37
+
38
+ def finalize
39
+ @server.stop
40
+ end
41
+
42
+ private
43
+ def args(add = {}, remove = [])
44
+ args = @args
45
+ (remove + add.keys).uniq.each { |opt| args = strip_opt(args, opt) }
46
+ add.each { |opt, value| args += " --#{opt} #{value}" }
47
+ args.strip.split(/\s+/)
48
+ end
49
+
50
+ def strip_opt(str, opt)
51
+ str.sub(/--#{opt}\s+[^\s]+/, "")
52
+ str
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,4 @@
1
+ watch('(.*\.js)') do |match_data|
2
+ runner = $jstestdriver_test_runner
3
+ runner.run(runner.test_cases(match_data))
4
+ end
@@ -0,0 +1,26 @@
1
+ require "test_helper"
2
+ require "jstdutil/cli"
3
+ require "fileutils"
4
+
5
+ class JstdutilCliTest < Test::Unit::TestCase
6
+ context "running the cli" do
7
+ should "run jstestdriver command through JsRedGreen with given jar" do
8
+ jar = "path/to.jar"
9
+ result = "REPORT"
10
+ Jstdutil.expects(:run).with("--tests all ", jar).returns(result)
11
+ Jstdutil::RedGreen.expects(:format).with(result).returns(result * 2)
12
+
13
+ assert_equal result * 2, Jstdutil::Cli.run("--tests all --jar #{jar}".split(" "))
14
+ end
15
+
16
+ should "run jstestdriver command through JsRedGreen with jar from env" do
17
+ jar = "path/to.jar"
18
+ result = "REPORT"
19
+ Jstdutil.expects(:jar).returns(jar)
20
+ Jstdutil.expects(:run).with("--tests all", jar).returns(result)
21
+ Jstdutil::RedGreen.expects(:format).with(result).returns(result * 2)
22
+
23
+ assert_equal result * 2, Jstdutil::Cli.run("--tests all".split(" "))
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,32 @@
1
+ require "test_helper"
2
+
3
+ class JstdutilTest < Test::Unit::TestCase
4
+ context "locating jar file" do
5
+ setup do
6
+ @newest = "jstestdriver-1.1.jar"
7
+ @jars = ["JsTestDriver-1.0b.jar", "jstestdriver-1.0.jar", @newest]
8
+ end
9
+
10
+ should "use most recent test driver" do
11
+ with_jars(@jars) do |dir|
12
+ assert_equal @newest, File.basename(Jstdutil.jar(dir))
13
+ end
14
+ end
15
+
16
+ should "use $JSTESTDRIVER_HOME if no classpath is given" do
17
+ with_jars(@jars) do |dir|
18
+ with_env("JSTESTDRIVER_HOME", dir) do
19
+ assert_equal @newest, File.basename(Jstdutil.jar)
20
+ end
21
+ end
22
+ end
23
+
24
+ should "raise exception if no classpath is provided, and env not set" do
25
+ with_env("JSTESTDRIVER_HOME", nil) do
26
+ assert_raise FileNotFoundError do
27
+ Jstdutil.jar
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,42 @@
1
+ require "test_helper"
2
+ require "jstdutil/jstestdriver_config"
3
+
4
+ class JsTestDriverConfigTest < Test::Unit::TestCase
5
+ context "creating JsTestDriverConfig instances" do
6
+ setup do
7
+ @file = "__jstd.conf"
8
+ @server = "http://localhost:4242"
9
+ File.open(@file, "w") { |f| f.puts "server: #{@server}" }
10
+ end
11
+
12
+ teardown do
13
+ File.delete(@file) if File.exists?(@file)
14
+ end
15
+
16
+ should "work from existing file" do
17
+ config = nil
18
+
19
+ assert_nothing_raised do
20
+ config = Jstdutil::JsTestDriverConfig.new @file
21
+ end
22
+
23
+ assert_equal @server, config.server
24
+ end
25
+
26
+ should "work from string config" do
27
+ config = nil
28
+
29
+ assert_nothing_raised do
30
+ config = Jstdutil::JsTestDriverConfig.new "server: #{@server}"
31
+ end
32
+
33
+ assert_equal @server, config.server
34
+ end
35
+
36
+ should "raise error if no valid configuration is provided" do
37
+ assert_raise ArgumentError do
38
+ Jstdutil::JsTestDriverConfig.new "bogus"
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,24 @@
1
+ require "test_helper"
2
+
3
+ class JstdutilCliTest < Test::Unit::TestCase
4
+ def setup
5
+ @bin = File.join(File.dirname(__FILE__), "..", "bin", "jstestdriver")
6
+ end
7
+
8
+ context "running the binary" do
9
+ should "report success to $stdout" do
10
+ jar = "JsTestDriver.jar"
11
+ stdout = nil
12
+
13
+ capture_stderr do
14
+ stdout = capture_stdout do
15
+ with_jars(jar) do |dir|
16
+ `ruby -Ilib #@bin --jar #{File.join(dir, jar)}`
17
+ end
18
+ end
19
+ end
20
+
21
+ assert_equal "\n", stdout
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,45 @@
1
+ require "test_helper"
2
+
3
+ class RedGreenTest < Test::Unit::TestCase
4
+ context "formatting report" do
5
+ setup do
6
+ @report = <<-REPORT
7
+ .FE
8
+ Total 3 tests (Passed: 1; Fails: 1; Errors: 1) (2.00 ms)
9
+ Mozilla 1.9.1.2: Run 3 tests (Passed: 1; Fails: 1; Errors 1) (2.00 ms)
10
+ GreeterTest.testSomethingElse failed (1.00 ms): expected "1" but was "2"
11
+ ()@http://localhost:4224/test/test/greeter_test.js:10
12
+ [LOG] UH!
13
+ GreeterTest.testSomethingElseFails error (1.00 ms): assertEqual is not defined
14
+ ()@http://localhost:4224/test/test/greeter_test.js:14
15
+ REPORT
16
+ end
17
+
18
+ should "add pretty colors" do
19
+ report = Jstdutil::RedGreen.format(@report)
20
+
21
+ lines = @report.split("\n")
22
+
23
+ expected = Jstdutil::RedGreen::Color.green(".") +
24
+ Jstdutil::RedGreen::Color.red("F") +
25
+ Jstdutil::RedGreen::Color.yellow("E") + "\n"
26
+ expected << Jstdutil::RedGreen::Color.red(lines[1]) + "\n"
27
+ expected << Jstdutil::RedGreen::Color.red(lines[2]) + "\n"
28
+ expected << Jstdutil::RedGreen::Color.red(lines[3]) + "\n"
29
+ expected << lines[4] + "\n"
30
+ expected << lines[5] + "\n"
31
+ expected << Jstdutil::RedGreen::Color.yellow(lines[6]) + "\n"
32
+ expected << lines[7]
33
+
34
+ assert_equal expected.split("\n")[0], report.split("\n")[0]
35
+ assert_equal expected.split("\n")[1], report.split("\n")[1]
36
+ assert_equal expected.split("\n")[2], report.split("\n")[2]
37
+ assert_equal expected.split("\n")[3], report.split("\n")[3]
38
+ assert_equal expected.split("\n")[4], report.split("\n")[4]
39
+ assert_equal expected.split("\n")[5], report.split("\n")[5]
40
+ assert_equal expected.split("\n")[6], report.split("\n")[6]
41
+ assert_equal expected.split("\n")[7], report.split("\n")[7]
42
+ assert_equal expected, report
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,49 @@
1
+ require "test_helper"
2
+ require "jstdutil/test_file"
3
+ require "fileutils"
4
+
5
+ class TestFileTest < Test::Unit::TestCase
6
+ context "test files" do
7
+ should "be file itself if name is like _test.js" do
8
+ file = "some_test.js"
9
+ test_file = Jstdutil::TestFile.new(file)
10
+
11
+ assert_equal [file], test_file.test_files
12
+ end
13
+
14
+ should "find files like _test.js" do
15
+ file = "some.js"
16
+ test_file = Jstdutil::TestFile.new(file)
17
+ FileList.expects(:new).with("**/some_test.js", "**/test_some.js").returns([])
18
+
19
+ assert test_file.test_files
20
+ end
21
+ end
22
+
23
+ context "test cases" do
24
+ setup do
25
+ @dir = "__testdata"
26
+ @files = ["src/some.js", "test/some_test.js", "test/other_test.js"]
27
+ @cases = ["SomeTest", "OtherTest", "YetAnotherTest"]
28
+ @contents = { @files[1] => 'new TestCase("' + @cases[0] + '", {});',
29
+ @files[2] => "new TestCase('#{@cases[1]}', {});\nnew TestCase('#{@cases[2]}', {});" }
30
+
31
+ @files.each do |file|
32
+ content = @contents[file] || ""
33
+ file = File.join(@dir, file)
34
+ FileUtils.mkdir_p(File.dirname(file))
35
+ File.open(file, "w") { |f| f.puts(content) }
36
+ end
37
+ end
38
+
39
+ teardown do
40
+ FileUtils.rm_rf(@dir)
41
+ end
42
+
43
+ should "find test case in file" do
44
+ test_file = Jstdutil::TestFile.new(@files[0])
45
+
46
+ assert_equal @cases[0..0], test_file.test_cases
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,64 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+ require 'mocha'
5
+ require 'fileutils'
6
+ require 'redgreen'
7
+
8
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
9
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
10
+ require 'jstdutil'
11
+
12
+ class Test::Unit::TestCase
13
+ def capture_stdout
14
+ ios = StringIO.new
15
+ stdout = $stdout
16
+ $stdout = ios
17
+
18
+ begin
19
+ yield
20
+ ensure
21
+ $stdout = stdout
22
+ ios
23
+ end
24
+ end
25
+
26
+ def capture_stderr
27
+ ios = StringIO.new
28
+ stderr = $stderr
29
+ $stderr = ios
30
+
31
+ begin
32
+ yield
33
+ ensure
34
+ $stderr = stderr
35
+ ios
36
+ end
37
+ end
38
+
39
+ def with_jars(jars = "JsTestDriver-1.0b.jar", dir = "data")
40
+ FileUtils.rm_rf(dir)
41
+ Dir.mkdir(dir)
42
+
43
+ [jars].flatten.each do |lib|
44
+ File.open(File.join(dir, lib), "w") { |f| f.puts "" }
45
+ end
46
+
47
+ begin
48
+ yield dir
49
+ ensure
50
+ FileUtils.rm_rf(dir)
51
+ end
52
+ end
53
+
54
+ def with_env(name, value)
55
+ env = ENV[name]
56
+ ENV[name] = value
57
+
58
+ begin
59
+ yield
60
+ ensure
61
+ ENV[name] = value
62
+ end
63
+ end
64
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jstdutil
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Christian Johansen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-04 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: thoughtbot-shoulda
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: watchr
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: rake
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ description: Thin wrapper over Google's JsTestDriver that adds colors and autotest
46
+ email: christian@cjohansen.no
47
+ executables:
48
+ - jstestdriver
49
+ - jsautotest
50
+ extensions: []
51
+
52
+ extra_rdoc_files:
53
+ - LICENSE
54
+ - README.rdoc
55
+ files:
56
+ - LICENSE
57
+ - README.rdoc
58
+ - Rakefile
59
+ - VERSION
60
+ - bin/jsautotest
61
+ - bin/jstestdriver
62
+ - lib/jstdutil.rb
63
+ - lib/jstdutil/autotest.rb
64
+ - lib/jstdutil/cli.rb
65
+ - lib/jstdutil/hooks.rb
66
+ - lib/jstdutil/jstestdriver/config.rb
67
+ - lib/jstdutil/jstestdriver/server.rb
68
+ - lib/jstdutil/redgreen.rb
69
+ - lib/jstdutil/test_file.rb
70
+ - lib/jstdutil/test_runner.rb
71
+ - lib/watchr_script
72
+ - test/cli_test.rb
73
+ - test/jstdutil_test.rb
74
+ - test/jstestdriver_config_test.rb
75
+ - test/jstestdriver_test.rb
76
+ - test/redgreen_test.rb
77
+ - test/test_file_test.rb
78
+ - test/test_helper.rb
79
+ has_rdoc: true
80
+ homepage: http://github.com/cjohansen/jstdutil
81
+ licenses: []
82
+
83
+ post_install_message:
84
+ rdoc_options:
85
+ - --charset=UTF-8
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: "0"
93
+ version:
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: "0"
99
+ version:
100
+ requirements: []
101
+
102
+ rubyforge_project: jstdutil
103
+ rubygems_version: 1.3.5
104
+ signing_key:
105
+ specification_version: 3
106
+ summary: Thin wrapper over Google's JsTestDriver that adds colors and autotest
107
+ test_files:
108
+ - test/cli_test.rb
109
+ - test/jstdutil_test.rb
110
+ - test/jstestdriver_config_test.rb
111
+ - test/jstestdriver_test.rb
112
+ - test/redgreen_test.rb
113
+ - test/test_file_test.rb
114
+ - test/test_helper.rb