guard-jstd 0.0.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.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,5 @@
1
+ guard 'rspec', :bundler => false, :cli => "-d" do
2
+ watch(%r{^spec/.+_spec\.rb})
3
+ watch(%r{^lib/(.+)\.rb}) { |m| "spec/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Guard::Jstd
2
+
3
+ Guard::Jstd provides autotest functionality for your test driven JavaScript development with JsTestDriver. This gem was inspired by the [jstdutil gem](http://cjohansen.no/en/javascript/jstdutil_a_ruby_wrapper_over_jstestdriver) and modeled after the [Guard::RSpec gem.](https://github.com/guard/guard-rspec)
4
+
5
+ ## Installing the gem:
6
+
7
+ From the command line:
8
+
9
+ $ gem install guard-jstd
10
+
11
+ Or in your Gemfile:
12
+
13
+ group :test do
14
+ gem "guard-jstd"
15
+ end
16
+
17
+ Generate the suggested Guardfile with:
18
+
19
+ guard init jstd
20
+
21
+ ## Usage
22
+
23
+ See the [Guard](http://github.com/guard/guard) gem README for more information about using Guard.
24
+
25
+ If you want to use CoffeeScript in your development, add the [guard-coffeescript gem.](https://github.com/guard/guard-coffeescript)
26
+
27
+ ## JsTestDriver
28
+
29
+ Currently, Guard::Jstd requires that you define an environment variable, $JSTESTDRIVER_HOME, to specify where JsTestDriver .jar file is located at on your system. More information about setting up JsTestDriver on your system can be [found here.](http://www.arailsdemo.com/posts/46) or on the JsTestDriver [homepage.](http://code.google.com/p/js-test-driver/)
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "guard/jstd/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "guard-jstd"
7
+ s.version = Guard::JstdVersion::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["aRailsDemo"]
10
+ s.email = ["arailsdemo@gmail.com"]
11
+ s.homepage = "https://github.com/arailsdemo/guard-jstd"
12
+ s.summary = %q{A Guard for JsTestDriver}
13
+ s.description = %q{This will watch for changes in your JavaScript project and automatically run JsTestDriver}
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_dependency("guard", ">= 0.3.0")
21
+ s.add_development_dependency("rspec", "~> 2.4.0")
22
+ end
@@ -0,0 +1,12 @@
1
+ module Guard
2
+ class Jstd
3
+ module CaseFinder
4
+ def self.find(paths)
5
+ paths.collect do |path|
6
+ contents = File.read(path)
7
+ contents.scan(/TestCase\s*\(\s*["']([^"']+)/)
8
+ end.flatten.join(',')
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,64 @@
1
+ module Guard
2
+ class Jstd
3
+ class Formatter
4
+ TITLES =
5
+ {
6
+ :failed => 'You have failing tests.',
7
+ :success => "All of your tests passed."
8
+ }
9
+
10
+ COLORS =
11
+ {
12
+ :success => "\e[32m",
13
+ :failed => "\e[31m"
14
+ }
15
+
16
+ def self.notify(results)
17
+ formatter = self.new(results)
18
+ formatter.notify
19
+ formatter.to_terminal
20
+ end
21
+
22
+ attr_reader :results, :lines
23
+
24
+ def initialize(results)
25
+ @results = results
26
+ @lines = results.split("\n")
27
+ end
28
+
29
+ def any_failed?
30
+ @failed ||= results.match(/failed/)
31
+ end
32
+
33
+ def notify
34
+ status = any_failed? ? :failed : :success
35
+ ::Guard::Notifier.notify( lines[1].lstrip,
36
+ { :title => TITLES[status], :image => status }
37
+ )
38
+ end
39
+
40
+ def colorize_results
41
+ lines.collect do |line|
42
+ if line =~ /failed/
43
+ colorize(line, :failed)
44
+ elsif line =~ /Fails: (\d+);/
45
+ status = $1.to_i == 0 ? :success : :failed
46
+ colorize(line, status)
47
+ else
48
+ line
49
+ end
50
+ end.join("\n")
51
+ end
52
+
53
+ def to_terminal
54
+ UI.info(colorize_results, :reset => true)
55
+ end
56
+
57
+ private
58
+
59
+ def colorize(text, status)
60
+ "#{COLORS[status]}#{text}\e[0m"
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,17 @@
1
+ module Guard
2
+ class Jstd
3
+ module Runner
4
+ class << self
5
+ def java_command
6
+ "java -jar $JSTESTDRIVER_HOME/JsTestDriver-1.3.2.jar --tests"
7
+ end
8
+
9
+ def run(tests="all")
10
+ UI.info("Running #{tests}")
11
+ results = `#{java_command} #{tests}`
12
+ Formatter.notify(results)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,4 @@
1
+ guard "jstd" do
2
+ watch(%r{^javascripts/.+_test\.js})
3
+ watch(%r{^javascripts/src/(.+)\.js}) { |m| "javascripts/test/#{m[1]}_test.js"}
4
+ end
@@ -0,0 +1,5 @@
1
+ module Guard
2
+ module JstdVersion
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
data/lib/guard/jstd.rb ADDED
@@ -0,0 +1,23 @@
1
+ require 'guard'
2
+ require 'guard/guard'
3
+
4
+ module Guard
5
+ class Jstd < Guard
6
+ autoload :Runner, 'guard/jstd/runner'
7
+ autoload :CaseFinder, 'guard/jstd/case_finder'
8
+ autoload :Formatter, 'guard/jstd/formatter'
9
+
10
+ def start
11
+ UI.info "Guard::Jstd is running."
12
+ end
13
+
14
+ def run_all
15
+ Runner.run
16
+ end
17
+
18
+ def run_on_change(paths)
19
+ cases = CaseFinder.find(paths)
20
+ Runner.run(cases)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,33 @@
1
+ require "spec_helper"
2
+
3
+ describe Guard::Jstd::CaseFinder do
4
+ def file1
5
+ <<-CASES
6
+ TestCase("First", {\][pw458asdf,vc]})
7
+ TestCase ( "Second" , {/?';,~'})
8
+ CASES
9
+ end
10
+
11
+ def file2
12
+ <<-CASES
13
+ TestCase('Third' , {})
14
+ TestCase("Fourth", {
15
+ "test": function () {
16
+ assert(false)
17
+ }
18
+ });
19
+ CASES
20
+ end
21
+
22
+ describe ".find" do
23
+ context "--given an array of paths--" do
24
+ it "finds the TestCases in the corresponding files" do
25
+ path = 'foo/bar.js'
26
+ path2 = 'hand/foot.js'
27
+ File.should_receive(:read).with(path) { file1 }
28
+ File.should_receive(:read).with(path2) { file2 }
29
+ subject.find([path, path2]).should == "First,Second,Third,Fourth"
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,93 @@
1
+ require "spec_helper"
2
+
3
+ describe Guard::Jstd::Formatter do
4
+ let(:failed) do
5
+ <<-FAILED
6
+ ..
7
+ Total 2 tests (Passed: 1; Fails: 1; Errors: 0) (1.00 ms)
8
+ Chrome 10.0.648.204 Mac OS: Run 2 tests (Passed: 1; Fails: 1; Errors 0) (1.00 ms)
9
+ Sneaky3.test failed (1.00 ms): AssertError: expected true but was false
10
+ AssertError: expected true but was false
11
+ at Object.test (http://0.0.0.0:4224/test/javascripts/test/extra_test.js:9:5)
12
+ FAILED
13
+ end
14
+
15
+ let(:passed) do
16
+ <<-PASSED
17
+ ....
18
+ Total 4 tests (Passed: 4; Fails: 0; Errors: 0) (4.00 ms)
19
+ Chrome 10.0.648.204 Mac OS: Run 4 tests (Passed: 4; Fails: 0; Errors 0) (4.00 ms)
20
+ PASSED
21
+ end
22
+
23
+ let(:klass) { ::Guard::Jstd::Formatter }
24
+
25
+ context "--failed test--" do
26
+ subject { klass.new(failed) }
27
+
28
+ its(:any_failed?) { should be_true }
29
+
30
+ it "#notify sends :failed arguments to Nofitier" do
31
+ message = "Total 2 tests (Passed: 1; Fails: 1; Errors: 0) (1.00 ms)"
32
+ ::Guard::Notifier.should_receive(:notify).with(
33
+ message, { :title => klass::TITLES[:failed], :image => :failed }
34
+ )
35
+ subject.notify
36
+ end
37
+
38
+ describe "#colorized_results" do
39
+ it "adds color to the failed test" do
40
+ subject.colorize_results.should match /\[31m\s+Sneaky3.test/
41
+ end
42
+
43
+ it "adds color to the failed overview line" do
44
+ subject.colorize_results.should match /\[31m\s+Chrome/
45
+ end
46
+ end
47
+
48
+ it "#to_terminal sends colorized results to UI" do
49
+ subject.stub(:colorize_results) { failed }
50
+ ::Guard::UI.should_receive(:info).with(
51
+ failed, {:reset => true}
52
+ )
53
+ subject.to_terminal
54
+ end
55
+ end
56
+
57
+ context "--all tests passed--" do
58
+ subject { klass.new(passed) }
59
+
60
+ its(:any_failed?) { should be_false }
61
+
62
+ it "#notify should send :success arguments to Nofitier" do
63
+ message = "Total 4 tests (Passed: 4; Fails: 0; Errors: 0) (4.00 ms)"
64
+ ::Guard::Notifier.should_receive(:notify).with(
65
+ message, { :title => klass::TITLES[:success], :image => :success }
66
+ )
67
+ subject.notify
68
+ end
69
+
70
+ it "#colorized_results adds color to the successful overview line" do
71
+ subject.colorize_results.should match /\[32m\s+Total/
72
+ end
73
+ end
74
+
75
+ context ".notify" do
76
+ subject { klass }
77
+
78
+ before do
79
+ @formatter = double.as_null_object
80
+ subject.should_receive(:new).with(failed) { @formatter }
81
+ end
82
+
83
+ it "calls #notify" do
84
+ @formatter.should_receive(:notify)
85
+ subject.notify(failed)
86
+ end
87
+
88
+ it "call #display" do
89
+ @formatter.should_receive(:to_terminal)
90
+ subject.notify(failed)
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,42 @@
1
+ require "spec_helper"
2
+
3
+ describe Guard::Jstd::Runner do
4
+ describe ".run" do
5
+ let(:test) { "HelloTest" }
6
+
7
+ it "sends the test results to the Formatter" do
8
+ subject.stub(:"`") { 'results' }
9
+ Guard::Jstd::Formatter.should_receive(:notify).with('results')
10
+ subject.run
11
+ end
12
+
13
+ context "--JsTestDriver command--" do
14
+ let(:java_command) { Guard::Jstd::Runner::java_command }
15
+
16
+ before { Guard::Jstd::Formatter.stub(:notify) }
17
+
18
+ it "can run all tests" do
19
+ subject.should_receive(:"`").with(
20
+ "#{java_command} all"
21
+ )
22
+ subject.run
23
+ end
24
+
25
+ it "can run a single TestCase" do
26
+ subject.should_receive(:"`").with(
27
+ "#{java_command} #{test}"
28
+ )
29
+ subject.run(test)
30
+ end
31
+ end
32
+
33
+ it "tells UI which tests are running" do
34
+ Guard::Jstd::Formatter.stub(:notify)
35
+ subject.stub(:"`")
36
+ Guard::UI.should_receive(:info).with(
37
+ "Running #{test}"
38
+ )
39
+ subject.run(test)
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,31 @@
1
+ require "spec_helper"
2
+
3
+ describe Guard::Jstd do
4
+ let(:klass) { Guard::Jstd }
5
+
6
+ it "inherits from Guard" do
7
+ klass.ancestors.should include Guard::Guard
8
+ end
9
+
10
+ it "#start sends a message to UI" do
11
+ ::Guard::UI.should_receive(:info).with(
12
+ "Guard::Jstd is running."
13
+ )
14
+ subject.start
15
+ end
16
+
17
+ it " #run_all runs all tests" do
18
+ klass::Runner.should_receive(:run)
19
+ subject.run_all
20
+ end
21
+
22
+ describe "#run_on_change" do
23
+ it "starts the Runner with the corresponding TestCases" do
24
+ paths = ['foo/bar.js', 'hand/foot.js']
25
+ cases = 'First,Second'
26
+ klass::CaseFinder.should_receive(:find).with(paths) { cases }
27
+ klass::Runner.should_receive(:run).with(cases)
28
+ subject.run_on_change(paths)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,12 @@
1
+ require 'rspec'
2
+ require 'guard/jstd'
3
+
4
+ RSpec.configure do |config|
5
+ config.before(:each) do
6
+ ENV["GUARD_ENV"] = 'test'
7
+ end
8
+
9
+ config.after(:each) do
10
+ ENV["GUARD_ENV"] = nil
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guard-jstd
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - aRailsDemo
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-04-07 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: guard
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 19
29
+ segments:
30
+ - 0
31
+ - 3
32
+ - 0
33
+ version: 0.3.0
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ hash: 31
45
+ segments:
46
+ - 2
47
+ - 4
48
+ - 0
49
+ version: 2.4.0
50
+ type: :development
51
+ version_requirements: *id002
52
+ description: This will watch for changes in your JavaScript project and automatically run JsTestDriver
53
+ email:
54
+ - arailsdemo@gmail.com
55
+ executables: []
56
+
57
+ extensions: []
58
+
59
+ extra_rdoc_files: []
60
+
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - Guardfile
65
+ - README.md
66
+ - Rakefile
67
+ - guard-jstd.gemspec
68
+ - lib/guard/jstd.rb
69
+ - lib/guard/jstd/case_finder.rb
70
+ - lib/guard/jstd/formatter.rb
71
+ - lib/guard/jstd/runner.rb
72
+ - lib/guard/jstd/templates/Guardfile
73
+ - lib/guard/jstd/version.rb
74
+ - spec/guard/jstd/case_finder_spec.rb
75
+ - spec/guard/jstd/formatter_spec.rb
76
+ - spec/guard/jstd/runner_spec.rb
77
+ - spec/guard/jstd_spec.rb
78
+ - spec/spec_helper.rb
79
+ homepage: https://github.com/arailsdemo/guard-jstd
80
+ licenses: []
81
+
82
+ post_install_message:
83
+ rdoc_options: []
84
+
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ hash: 3
93
+ segments:
94
+ - 0
95
+ version: "0"
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ hash: 3
102
+ segments:
103
+ - 0
104
+ version: "0"
105
+ requirements: []
106
+
107
+ rubyforge_project:
108
+ rubygems_version: 1.7.2
109
+ signing_key:
110
+ specification_version: 3
111
+ summary: A Guard for JsTestDriver
112
+ test_files:
113
+ - spec/guard/jstd/case_finder_spec.rb
114
+ - spec/guard/jstd/formatter_spec.rb
115
+ - spec/guard/jstd/runner_spec.rb
116
+ - spec/guard/jstd_spec.rb
117
+ - spec/spec_helper.rb
118
+ has_rdoc: