test/controller_test.rb in cuco-0.0.7 vs test/controller_test.rb in cuco-0.1.0
- old
+ new
@@ -1,52 +1,52 @@
require "test_helper"
-require "timeout"
-require "controller"
-require "script"
describe Controller do
- let(:options) { {} }
let(:cuco) { Controller.instance }
- let(:script) { Script.new }
+ let(:regexp) { '.*\.rb' }
+ def setup
+ G.init({}, [])
+ end
+
def teardown
cuco.stop
end
it "stops" do
cuco.stop
assert_nil cuco.listener
end
- it "initializes" do
- cuco.init(options, [])
- end
-
it "runs" do
- cuco.init(options, [])
assert_raises(Timeout::Error) do
Timeout.timeout(0.1) { cuco.run }
end
assert cuco.listener
end
it "read .watchr" do
- filename = ".watchr"
+ assert_raises(Timeout::Error) do
+ Timeout.timeout(0.1) { cuco.run }
+ end
+ end
- script.load_file filename
- assert_equal 2, script.__rules.size
+ it "run" do
+ G.script = Script.new "watch('#{regexp}') { raise IOError }"
+
+ assert_raises(IOError) { cuco.file_run "a.rb" }
end
- private
+ it "does not run" do
+ G.script = Script.new "watch('#{regexp}') { raise IOError }"
- def test_files
- dir = File.join(Dir.pwd, "test", "files")
- files = find_files_in(dir)
- files.collect { |file| File.join(dir, file) }
+ cuco.file_run "a.no"
end
- def find_files_in(dir)
- entries = Dir.entries(dir)
- entries.reject { |entry| File.directory?(entry) }
+ it "receives a matchdata" do
+ G.script = Script.new "watch('ab(.)') { |m| [m[0], m[1]] }"
+
+ rule = G.script.__rules.last
+ assert_equal ["abc", "c"], cuco.match_run(rule, "abc")
end
end