forked from SFEley/autowatchr
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added #new, #run, and some accessors
- Loading branch information
Jeremy Stephens
committed
Sep 30, 2009
1 parent
d90750e
commit 2c9fbcb
Showing
8 changed files
with
138 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
class Autowatch | ||
attr_writer :ruby, :include, :lib_dir, :test_dir | ||
|
||
def initialize(options = {}) | ||
options.each_pair do |key, value| | ||
method = "#{key}=" | ||
if self.respond_to?(method) | ||
self.send(method, value) | ||
end | ||
end | ||
yield self if block_given? | ||
end | ||
|
||
def ruby | ||
@ruby ||= "ruby" | ||
end | ||
|
||
def include | ||
@include ||= ".:#{self.lib_dir}:#{self.test_dir}" | ||
end | ||
|
||
def lib_dir | ||
@lib_dir ||= "lib" | ||
end | ||
|
||
def test_dir | ||
@test_dir ||= "test" | ||
end | ||
|
||
def run(file) | ||
if file =~ %r{^#{@lib_dir}#{File::SEPARATOR}?(.+)$} | ||
# lib file | ||
parts = $1.split(File::SEPARATOR) | ||
parts[-1] = "test_#{parts[-1]}" | ||
file = "#{@test_dir}/" + File.join(parts) | ||
end | ||
run_test_file(file) | ||
end | ||
|
||
private | ||
def run_test_file(file) | ||
cmd = "%s -I%s %s" % [ @ruby, @include, file ] | ||
open("| #{cmd}", "r") do |f| | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class Foo | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Loaded suite test/test_foo | ||
Started | ||
F. | ||
Finished in 0.000871 seconds. | ||
|
||
1) Failure: | ||
test_flunk(TestFoo) [test/test_foo.rb:7]: | ||
Flunked. | ||
|
||
2 tests, 2 assertions, 1 failures, 0 errors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require 'test/unit' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require File.dirname(__FILE__) + "/helper" | ||
|
||
class TestFoo < Test::Unit::TestCase | ||
def test_pass | ||
assert true | ||
end | ||
|
||
def test_flunk | ||
flunk | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
require 'rubygems' | ||
require 'test/unit' | ||
require 'shoulda' | ||
require 'mocha' | ||
|
||
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) | ||
$LOAD_PATH.unshift(File.dirname(__FILE__)) | ||
require 'autowatch' | ||
|
||
class Test::Unit::TestCase | ||
def fake_result(name) | ||
StringIO.new(open(File.dirname(__FILE__) + "/fixtures/results/#{name}.txt").read) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,66 @@ | ||
require 'helper' | ||
|
||
class TestAutowatch < Test::Unit::TestCase | ||
should "probably rename this file and start testing for real" do | ||
flunk "hey buddy, you should probably rename this file and start testing for real" | ||
def new_autowatch(options = {}) | ||
Autowatch.new({ | ||
:ruby => "/usr/local/bin/ruby", | ||
:include => ".:lib:test", | ||
:lib_dir => @lib_dir, | ||
:test_dir => @test_dir | ||
}.merge(options)) | ||
end | ||
|
||
def setup | ||
@lib_dir = File.dirname(__FILE__) + "/fixtures/lib" | ||
@test_dir = File.dirname(__FILE__) + "/fixtures/test" | ||
end | ||
|
||
def test_new_with_hash | ||
aw = Autowatch.new({ | ||
:ruby => "/usr/local/bin/ruby", | ||
:include => ".:lib:test" | ||
}) | ||
assert_equal "/usr/local/bin/ruby", aw.ruby | ||
assert_equal ".:lib:test", aw.include | ||
end | ||
|
||
def test_new_with_block | ||
aw = Autowatch.new do |config| | ||
config.ruby = "/usr/local/bin/ruby" | ||
config.include = ".:lib:test" | ||
config.lib_dir = @lib_dir | ||
config.test_dir = @test_dir | ||
end | ||
assert_equal "/usr/local/bin/ruby", aw.ruby | ||
assert_equal ".:lib:test", aw.include | ||
assert_equal @lib_dir, aw.lib_dir | ||
assert_equal @test_dir, aw.test_dir | ||
end | ||
|
||
def test_auto_includes | ||
aw = Autowatch.new do |config| | ||
config.ruby = "/usr/local/bin/ruby" | ||
config.lib_dir = @lib_dir | ||
config.test_dir = @test_dir | ||
end | ||
assert_equal ".:#{@lib_dir}:#{@test_dir}", aw.include | ||
end | ||
|
||
def test_defaults | ||
aw = Autowatch.new | ||
assert_equal "ruby", aw.ruby | ||
assert_equal ".:lib:test", aw.include | ||
assert_equal "lib", aw.lib_dir | ||
assert_equal "test", aw.test_dir | ||
end | ||
|
||
def test_run_with_lib_file | ||
aw = new_autowatch | ||
result = fake_result("foo") | ||
aw.expects(:open).with( | ||
"| /usr/local/bin/ruby -I.:lib:test #{@test_dir}/test_foo.rb", "r" | ||
).yields(result) | ||
|
||
aw.run("#{@lib_dir}/foo.rb") | ||
end | ||
end |