autowatchr 0.0.0

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/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Jeremy Stephens
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.
data/README.rdoc ADDED
@@ -0,0 +1,24 @@
1
+ = autowatchr
2
+
3
+ Provides some autotest-like behavior for watchr (http://github.com/mynyml/watchr).
4
+
5
+ == Installation
6
+
7
+ gem install autowatchr --source http://gemcutter.org
8
+
9
+ == Example use
10
+
11
+ test.watchr
12
+ require 'autowatchr'
13
+
14
+ Autowatchr.new(self) do |config|
15
+ config.ruby = "jruby" # default: "ruby"
16
+ config.lib_dir = "leet_lib" # default: "lib"
17
+ config.test_dir = "leet_test" # default: "test"
18
+ end
19
+
20
+ Also see: test.watchr[http://github.com/viking/autowatchr/blob/master/test.watchr].
21
+
22
+ == Copyright
23
+
24
+ Copyright (c) 2009 Jeremy Stephens. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,58 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "autowatchr"
8
+ gem.summary = %Q{Provides some autotest-like behavior for watchr}
9
+ gem.description = %Q{Provides some autotest-like behavior for watchr (http://github.com/mynyml/watchr).}
10
+ gem.email = "viking415@gmail.com"
11
+ gem.homepage = "http://github.com/viking/autowatchr"
12
+ gem.authors = ["Jeremy Stephens"]
13
+ gem.add_dependency "watchr"
14
+ gem.add_development_dependency "mocha"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
20
+ end
21
+
22
+ require 'rake/testtask'
23
+ Rake::TestTask.new(:test) do |test|
24
+ test.libs << 'lib' << 'test'
25
+ test.pattern = 'test/test_*.rb'
26
+ test.verbose = true
27
+ end
28
+
29
+ begin
30
+ require 'rcov/rcovtask'
31
+ Rcov::RcovTask.new do |test|
32
+ test.libs << 'test'
33
+ test.pattern = 'test/test_*.rb'
34
+ test.verbose = true
35
+ end
36
+ rescue LoadError
37
+ task :rcov do
38
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
39
+ end
40
+ end
41
+
42
+ task :test => :check_dependencies
43
+
44
+ task :default => :test
45
+
46
+ require 'rake/rdoctask'
47
+ Rake::RDocTask.new do |rdoc|
48
+ if File.exist?('VERSION')
49
+ version = File.read('VERSION')
50
+ else
51
+ version = ""
52
+ end
53
+
54
+ rdoc.rdoc_dir = 'rdoc'
55
+ rdoc.title = "autowatchr #{version}"
56
+ rdoc.rdoc_files.include('README*')
57
+ rdoc.rdoc_files.include('lib/*.rb')
58
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,64 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{autowatchr}
8
+ s.version = "0.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Jeremy Stephens"]
12
+ s.date = %q{2009-09-30}
13
+ s.description = %q{Provides some autotest-like behavior for watchr (http://github.com/mynyml/watchr).}
14
+ s.email = %q{viking415@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "autowatchr.gemspec",
27
+ "lib/autowatchr.rb",
28
+ "test.watchr",
29
+ "test/fixtures/lib/foo.rb",
30
+ "test/fixtures/results/foo.txt",
31
+ "test/fixtures/test/helper.rb",
32
+ "test/fixtures/test/test_foo.rb",
33
+ "test/helper.rb",
34
+ "test/test_autowatchr.rb"
35
+ ]
36
+ s.homepage = %q{http://github.com/viking/autowatchr}
37
+ s.rdoc_options = ["--charset=UTF-8"]
38
+ s.require_paths = ["lib"]
39
+ s.rubygems_version = %q{1.3.5}
40
+ s.summary = %q{Provides some autotest-like behavior for watchr}
41
+ s.test_files = [
42
+ "test/fixtures/test/test_foo.rb",
43
+ "test/fixtures/test/helper.rb",
44
+ "test/fixtures/lib/foo.rb",
45
+ "test/test_autowatchr.rb",
46
+ "test/helper.rb"
47
+ ]
48
+
49
+ if s.respond_to? :specification_version then
50
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
51
+ s.specification_version = 3
52
+
53
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
54
+ s.add_runtime_dependency(%q<watchr>, [">= 0"])
55
+ s.add_development_dependency(%q<mocha>, [">= 0"])
56
+ else
57
+ s.add_dependency(%q<watchr>, [">= 0"])
58
+ s.add_dependency(%q<mocha>, [">= 0"])
59
+ end
60
+ else
61
+ s.add_dependency(%q<watchr>, [">= 0"])
62
+ s.add_dependency(%q<mocha>, [">= 0"])
63
+ end
64
+ end
data/lib/autowatchr.rb ADDED
@@ -0,0 +1,69 @@
1
+ class Autowatchr
2
+ attr_writer :ruby, :include, :lib_dir, :test_dir
3
+
4
+ def initialize(script, options = {})
5
+ options.each_pair do |key, value|
6
+ method = "#{key}="
7
+ if self.respond_to?(method)
8
+ self.send(method, value)
9
+ end
10
+ end
11
+ yield self if block_given?
12
+
13
+ @script = script
14
+ start_watching_files
15
+ end
16
+
17
+ def ruby
18
+ @ruby ||= "ruby"
19
+ end
20
+
21
+ def include
22
+ @include ||= ".:#{self.lib_dir}:#{self.test_dir}"
23
+ end
24
+
25
+ def lib_dir
26
+ @lib_dir ||= "lib"
27
+ end
28
+
29
+ def test_dir
30
+ @test_dir ||= "test"
31
+ end
32
+
33
+ def run_lib_file(file)
34
+ md = file.match(%r{^#{@lib_dir}#{File::SEPARATOR}?(.+)$})
35
+ parts = md[1].split(File::SEPARATOR)
36
+ parts[-1] = "test_#{parts[-1]}"
37
+ file = "#{@test_dir}/" + File.join(parts)
38
+ run_test_file(file)
39
+ end
40
+
41
+ def run_test_file(file)
42
+ cmd = "%s -I%s %s" % [ self.ruby, self.include, file ]
43
+
44
+ # straight outta autotest
45
+ results = []
46
+ line = []
47
+ open("| #{cmd}", "r") do |f|
48
+ until f.eof? do
49
+ c = f.getc
50
+ putc c
51
+ line << c
52
+ if c == ?\n then
53
+ results << if RUBY_VERSION >= "1.9" then
54
+ line.join
55
+ else
56
+ line.pack "c*"
57
+ end
58
+ line.clear
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ private
65
+ def start_watching_files
66
+ @script.watch("^#{self.test_dir}.*/test_.*\.rb") { |md| run_test_file(md[0]) }
67
+ @script.watch("^#{self.lib_dir}.*/.*\.rb") { |md| run_lib_file(md[0]) }
68
+ end
69
+ end
data/test.watchr ADDED
@@ -0,0 +1,3 @@
1
+ require 'lib/autowatchr'
2
+
3
+ Autowatchr.new(self)
@@ -0,0 +1,2 @@
1
+ class Foo
2
+ end
@@ -0,0 +1,10 @@
1
+ Loaded suite test/test_foo
2
+ Started
3
+ F.
4
+ Finished in 0.000871 seconds.
5
+
6
+ 1) Failure:
7
+ test_flunk(TestFoo) [test/test_foo.rb:7]:
8
+ Flunked.
9
+
10
+ 2 tests, 2 assertions, 1 failures, 0 errors
@@ -0,0 +1 @@
1
+ require 'test/unit'
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + "/helper"
2
+
3
+ class TestFoo < Test::Unit::TestCase
4
+ def test_pass
5
+ assert true
6
+ end
7
+
8
+ def test_flunk
9
+ flunk
10
+ end
11
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,23 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'mocha'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'autowatchr'
8
+
9
+ class Test::Unit::TestCase
10
+ def fake_result(name)
11
+ StringIO.new(open(File.dirname(__FILE__) + "/fixtures/results/#{name}.txt").read)
12
+ end
13
+
14
+ # File vendor/rails/activesupport/lib/active_support/core_ext/kernel/reporting.rb, line 36
15
+ def silence_stream(stream)
16
+ old_stream = stream.dup
17
+ stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
18
+ stream.sync = true
19
+ yield
20
+ ensure
21
+ stream.reopen(old_stream)
22
+ end
23
+ end
@@ -0,0 +1,83 @@
1
+ require 'helper'
2
+
3
+ class TestAutowatchr < Test::Unit::TestCase
4
+ def new_autowatchr(options = {})
5
+ Autowatchr.new(@script, {
6
+ :ruby => "/usr/local/bin/ruby",
7
+ :lib_dir => @lib_dir,
8
+ :test_dir => @test_dir
9
+ }.merge(options))
10
+ end
11
+
12
+ def setup
13
+ @script = stub("fake watchr script", :watch => nil)
14
+ @lib_dir = File.dirname(__FILE__) + "/fixtures/lib"
15
+ @test_dir = File.dirname(__FILE__) + "/fixtures/test"
16
+ Autowatchr.any_instance.stubs(:open)
17
+ end
18
+
19
+ def test_new_with_hash
20
+ aw = Autowatchr.new(@script, {
21
+ :ruby => "/usr/local/bin/ruby",
22
+ :include => ".:lib:test"
23
+ })
24
+ assert_equal "/usr/local/bin/ruby", aw.ruby
25
+ assert_equal ".:lib:test", aw.include
26
+ end
27
+
28
+ def test_new_with_block
29
+ aw = Autowatchr.new(@script) do |config|
30
+ config.ruby = "/usr/local/bin/ruby"
31
+ config.include = ".:lib:test"
32
+ config.lib_dir = @lib_dir
33
+ config.test_dir = @test_dir
34
+ end
35
+ assert_equal "/usr/local/bin/ruby", aw.ruby
36
+ assert_equal ".:lib:test", aw.include
37
+ assert_equal @lib_dir, aw.lib_dir
38
+ assert_equal @test_dir, aw.test_dir
39
+ end
40
+
41
+ def test_auto_includes
42
+ aw = Autowatchr.new(@script) do |config|
43
+ config.ruby = "/usr/local/bin/ruby"
44
+ config.lib_dir = @lib_dir
45
+ config.test_dir = @test_dir
46
+ end
47
+ assert_equal ".:#{@lib_dir}:#{@test_dir}", aw.include
48
+ end
49
+
50
+ def test_defaults
51
+ aw = Autowatchr.new(@script)
52
+ assert_equal "ruby", aw.ruby
53
+ assert_equal ".:lib:test", aw.include
54
+ assert_equal "lib", aw.lib_dir
55
+ assert_equal "test", aw.test_dir
56
+ end
57
+
58
+ def test_watches_test_files
59
+ md = ["#{@test_dir}/test_foo.rb"]
60
+ Autowatchr.any_instance.expects(:run_test_file).with("#{@test_dir}/test_foo.rb")
61
+ @script.expects(:watch).with("^#{@test_dir}.*/test_.*\.rb").yields(md)
62
+ new_autowatchr
63
+ end
64
+
65
+ def test_watches_lib_files
66
+ md = ["#{@lib_dir}/foo.rb"]
67
+ Autowatchr.any_instance.expects(:run_lib_file).with("#{@lib_dir}/foo.rb")
68
+ @script.expects(:watch).with("^#{@lib_dir}.*/.*\.rb").yields(md)
69
+ new_autowatchr
70
+ end
71
+
72
+ def test_run_lib_file
73
+ aw = new_autowatchr
74
+ result = fake_result("foo")
75
+ aw.expects(:open).with(
76
+ "| /usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} #{@test_dir}/test_foo.rb", "r"
77
+ ).yields(result)
78
+
79
+ silence_stream(STDOUT) do
80
+ aw.run_lib_file("#{@lib_dir}/foo.rb")
81
+ end
82
+ end
83
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: autowatchr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jeremy Stephens
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-30 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: watchr
17
+ type: :runtime
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: mocha
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ description: Provides some autotest-like behavior for watchr (http://github.com/mynyml/watchr).
36
+ email: viking415@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.rdoc
44
+ files:
45
+ - .document
46
+ - .gitignore
47
+ - LICENSE
48
+ - README.rdoc
49
+ - Rakefile
50
+ - VERSION
51
+ - autowatchr.gemspec
52
+ - lib/autowatchr.rb
53
+ - test.watchr
54
+ - test/fixtures/lib/foo.rb
55
+ - test/fixtures/results/foo.txt
56
+ - test/fixtures/test/helper.rb
57
+ - test/fixtures/test/test_foo.rb
58
+ - test/helper.rb
59
+ - test/test_autowatchr.rb
60
+ has_rdoc: true
61
+ homepage: http://github.com/viking/autowatchr
62
+ licenses: []
63
+
64
+ post_install_message:
65
+ rdoc_options:
66
+ - --charset=UTF-8
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0"
74
+ version:
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ version:
81
+ requirements: []
82
+
83
+ rubyforge_project:
84
+ rubygems_version: 1.3.5
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: Provides some autotest-like behavior for watchr
88
+ test_files:
89
+ - test/fixtures/test/test_foo.rb
90
+ - test/fixtures/test/helper.rb
91
+ - test/fixtures/lib/foo.rb
92
+ - test/test_autowatchr.rb
93
+ - test/helper.rb