kicker 2.4.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,104 +0,0 @@
1
- require File.expand_path('../test_helper', __FILE__)
2
-
3
- describe "Kicker, when a change occurs" do
4
- before do
5
- remove_tmp_files!
6
-
7
- Kicker.any_instance.stubs(:last_command_succeeded?).returns(true)
8
- Kicker.any_instance.stubs(:log)
9
- @kicker = Kicker.new
10
- end
11
-
12
- it "should store the current time as when the last change occurred" do
13
- now = Time.now
14
- Time.stubs(:now).returns(now)
15
-
16
- @kicker.send(:finished_processing!)
17
- @kicker.last_event_processed_at.should.be now
18
- end
19
-
20
- it "should return an array of files that have changed since the last event" do
21
- file1 = touch('1')
22
- file2 = touch('2')
23
- file3 = touch('3')
24
- file4 = touch('4')
25
- @kicker.send(:finished_processing!)
26
-
27
- events = [event(file1, file2), event(file3, file4)]
28
-
29
- @kicker.send(:changed_files, events).should == []
30
- @kicker.send(:finished_processing!)
31
-
32
- sleep(1)
33
- touch('2')
34
-
35
- @kicker.send(:changed_files, events).should == [file2]
36
- @kicker.send(:finished_processing!)
37
-
38
- sleep(1)
39
- touch('1')
40
- touch('3')
41
-
42
- @kicker.send(:changed_files, events).should == [file1, file3]
43
- end
44
-
45
- it "should return an empty array when a directory doesn't exist while collecting the files in it" do
46
- @kicker.send(:files_in_directory, '/does/not/exist').should == []
47
- end
48
-
49
- it "should not break when determining changed files from events with missing files" do
50
- file1 = touch('1')
51
- file2 = touch('2')
52
- @kicker.send(:finished_processing!)
53
- sleep(1)
54
- touch('2')
55
-
56
- events = [event(file1, file2), event('/does/not/exist')]
57
- @kicker.send(:changed_files, events).should == [file2]
58
- end
59
-
60
- it "should return relative file paths if the path is relative to the current work dir" do
61
- sleep(1)
62
- file = touch('1')
63
-
64
- Dir.stubs(:pwd).returns('/tmp')
65
- @kicker.send(:changed_files, [event(file)]).should == [File.basename(file)]
66
- end
67
-
68
- it "should call the full_chain with all changed files" do
69
- files = %w{ /file/1 /file/2 }
70
- events = [event('/file/1'), event('/file/2')]
71
-
72
- @kicker.expects(:changed_files).with(events).returns(files)
73
- @kicker.full_chain.expects(:call).with(files)
74
- @kicker.expects(:finished_processing!)
75
-
76
- @kicker.send(:process, events)
77
- end
78
-
79
- it "should not call the full_chain if there were no changed files" do
80
- @kicker.stubs(:changed_files).returns([])
81
- @kicker.full_chain.expects(:call).never
82
- @kicker.expects(:finished_processing!).never
83
-
84
- @kicker.send(:process, [event()])
85
- end
86
-
87
- private
88
-
89
- def touch(file)
90
- file = "/tmp/kicker_test_tmp_#{file}"
91
- `touch #{file}`
92
- file
93
- end
94
-
95
- def event(*files)
96
- event = stub('FSEvent')
97
- event.stubs(:path).returns('/tmp')
98
- event
99
- end
100
-
101
- def remove_tmp_files!
102
- Dir.glob("/tmp/kicker_test_tmp_*").each { |f| File.delete(f) }
103
- end
104
- end
@@ -1,2 +0,0 @@
1
- $FROM_RELOADED_FILE ||= 0
2
- $FROM_RELOADED_FILE += 1
@@ -1,35 +0,0 @@
1
- require File.expand_path('../test_helper', __FILE__)
2
-
3
- class FakeFSEvent
4
- def watch(paths, options={}, &block)
5
- @paths = paths
6
- @block = block
7
- end
8
-
9
- def run
10
- end
11
-
12
- def fake_event(paths)
13
- @block.call(paths)
14
- end
15
- end
16
-
17
- describe "Kicker::FSEvents" do
18
- it "calls the provided block with changed directories wrapped in an event instance" do
19
- events = nil
20
- faker = FakeFSEvent.new
21
- ::FSEvent.expects(:new).returns(faker)
22
- Kicker::FSEvents.start_watching(%w(/path/to/first /path/to/second)) do |events|
23
- end
24
- paths = %w(/path/to/first)
25
- faker.fake_event(paths)
26
- events.map { |e| e.path }.should == paths
27
- end
28
- end
29
-
30
- describe "Kicker::FSEvents::FSEvent" do
31
- it "returns the files from the changed directory ordered by mtime and filename" do
32
- fsevent = Kicker::FSEvents::FSEvent.new(File.expand_path('../fixtures', __FILE__))
33
- fsevent.files.should == [File.expand_path('../fixtures/a_file_thats_reloaded.rb', __FILE__)]
34
- end
35
- end
data/test/growl_test.rb DELETED
@@ -1,87 +0,0 @@
1
- require File.expand_path('../test_helper', __FILE__)
2
-
3
- if Kicker::Growl.usable?
4
- describe "Kicker::Growl" do
5
- before do
6
- @growler = Kicker::Growl
7
- end
8
-
9
- after do
10
- Kicker.silent = false
11
- end
12
-
13
- it "should growl that an event occurred" do
14
- status = Kicker::LogStatusHelper.new(nil, 'ls -l')
15
- @growler.expects(:growl).with(@growler.notifications[:change], 'Kicker: Executing', 'ls -l')
16
- @growler.change_occured(status)
17
- end
18
-
19
- it "should growl that an event occurred with the status callback" do
20
- status = Kicker::LogStatusHelper.new(proc { |s| 'foo' if s.growl? }, 'ls -l')
21
- @growler.expects(:growl).with(@growler.notifications[:change], 'Kicker: Executing', 'foo')
22
- @growler.change_occured(status)
23
- end
24
-
25
- it "should use the default click callback if a command succeeded and no user callback is defined" do
26
- status = Kicker::LogStatusHelper.new(nil, 'ls -l')
27
- status.result("line 1\nline 2", true, 0)
28
-
29
- OSX::NSWorkspace.sharedWorkspace.expects(:launchApplication).with('Terminal')
30
- @growler.expects(:growl).with(
31
- @growler.notifications[:succeeded],
32
- 'Kicker: Success',
33
- "line 1\nline 2"
34
- ).yields
35
-
36
- @growler.result(status)
37
- end
38
-
39
- it "should use the default click callback if a command failed and no user callback is defined" do
40
- status = Kicker::LogStatusHelper.new(nil, 'ls -l')
41
- status.result("line 1\nline 2", false, 123)
42
-
43
- OSX::NSWorkspace.sharedWorkspace.expects(:launchApplication).with('Terminal')
44
- @growler.expects(:growl).with(
45
- @growler.notifications[:failed],
46
- 'Kicker: Failed (123)',
47
- "line 1\nline 2"
48
- ).yields
49
-
50
- @growler.failed(status)
51
- end
52
-
53
- it "should only growl that the command succeeded in silent mode" do
54
- Kicker.silent = true
55
- status = Kicker::LogStatusHelper.new(nil, 'ls -l')
56
- status.result("line 1\nline 2", true, 0)
57
-
58
- @growler.expects(:growl).with(@growler.notifications[:succeeded], 'Kicker: Success', '')
59
- @growler.result(status)
60
- end
61
-
62
- it "should only growl that the command failed in silent mode" do
63
- Kicker.silent = true
64
- status = Kicker::LogStatusHelper.new(nil, 'ls -l')
65
- status.result("line 1\nline 2", false, 123)
66
-
67
- @growler.expects(:growl).with(@growler.notifications[:failed], 'Kicker: Failed (123)', '')
68
- @growler.failed(status)
69
- end
70
-
71
- it "should growl that the command succeeded with the status callback" do
72
- status = Kicker::LogStatusHelper.new(proc { |s| 'foo' if s.growl? }, 'ls -l')
73
- status.result("line 1\nline 2", true, 0)
74
-
75
- @growler.expects(:growl).with(@growler.notifications[:succeeded], 'Kicker: Success', 'foo')
76
- @growler.succeeded(status)
77
- end
78
-
79
- it "should growl that the command failed with the status callback" do
80
- status = Kicker::LogStatusHelper.new(proc { |s| 'foo' if s.growl? }, 'ls -l')
81
- status.result("line 1\nline 2", false, 123)
82
-
83
- @growler.expects(:growl).with(@growler.notifications[:failed], 'Kicker: Failed (123)', 'foo')
84
- @growler.failed(status)
85
- end
86
- end
87
- end
@@ -1,137 +0,0 @@
1
- require File.expand_path('../test_helper', __FILE__)
2
-
3
- module ReloadDotKick; end
4
-
5
- describe "Kicker" do
6
- before do
7
- Kicker.any_instance.stubs(:start)
8
- end
9
-
10
- it "should return the default paths to watch" do
11
- Kicker.paths.should == %w{ . }
12
- end
13
-
14
- it "should default the FSEvents latency to 1" do
15
- Kicker.latency.should == 1
16
- end
17
- end
18
-
19
- describe "Kicker, when initializing" do
20
- after do
21
- Kicker.paths = %w{ . }
22
- end
23
-
24
- it "should return the extended paths to watch" do
25
- Kicker.paths = %w{ /some/dir a/relative/path }
26
- Kicker.new.paths.should == ['/some/dir', File.expand_path('a/relative/path')]
27
- end
28
-
29
- it "should have assigned the current time to last_event_processed_at" do
30
- now = Time.now; Time.stubs(:now).returns(now)
31
- Kicker.new.last_event_processed_at.should == now
32
- end
33
-
34
- it "should use the default paths if no paths were given" do
35
- Kicker.new.paths.should == [File.expand_path('.')]
36
- end
37
- end
38
-
39
- describe "Kicker, when starting" do
40
- before do
41
- Kicker.paths = %w{ /some/file.rb }
42
- @kicker = Kicker.new
43
- @kicker.stubs(:log)
44
- @kicker.startup_chain.stubs(:call)
45
- Kicker::FSEvents.stubs(:start_watching)
46
- end
47
-
48
- after do
49
- Kicker.latency = 1
50
- Kicker.paths = %w{ . }
51
- end
52
-
53
- it "should show the usage banner and exit when there are no callbacks defined at all" do
54
- @kicker.stubs(:validate_paths_exist!)
55
- Kicker.stubs(:startup_chain).returns(Kicker::CallbackChain.new)
56
- Kicker.stubs(:process_chain).returns(Kicker::CallbackChain.new)
57
- Kicker.stubs(:pre_process_chain).returns(Kicker::CallbackChain.new)
58
-
59
- Kicker::Options.stubs(:parser).returns(mock('OptionParser', :help => 'help'))
60
- @kicker.expects(:puts).with("help")
61
- @kicker.expects(:exit)
62
-
63
- @kicker.start
64
- end
65
-
66
- it "should warn the user and exit if any of the given paths doesn't exist" do
67
- @kicker.stubs(:validate_paths_and_command!)
68
-
69
- @kicker.expects(:puts).with("The given path `/some/file.rb' does not exist")
70
- @kicker.expects(:exit).with(1)
71
-
72
- @kicker.start
73
- end
74
-
75
- it "should start a FSEvents stream with the assigned latency" do
76
- @kicker.stubs(:validate_options!)
77
-
78
- Kicker.latency = 2.34
79
- Kicker::FSEvents.expects(:start_watching).with(['/some'], :latency => 2.34)
80
- @kicker.start
81
- end
82
-
83
- it "should start a FSEvents stream which watches all paths, but the dirnames of paths if they're files" do
84
- @kicker.stubs(:validate_options!)
85
- File.stubs(:directory?).with('/some/file.rb').returns(false)
86
-
87
- Kicker::FSEvents.expects(:start_watching).with(['/some'], :latency => Kicker.latency)
88
- @kicker.start
89
- end
90
-
91
- it "should start a FSEvents stream with a block which calls #process with any generated events" do
92
- @kicker.stubs(:validate_options!)
93
-
94
- Kicker::FSEvents.expects(:start_watching).yields(['event'])
95
- @kicker.expects(:process).with(['event'])
96
-
97
- @kicker.start
98
- end
99
-
100
- it "should setup a signal handler for `INT' which stops the FSEvents stream and exits" do
101
- @kicker.stubs(:validate_options!)
102
-
103
- watch_dog = stub('Kicker::FSEvents')
104
- Kicker::FSEvents.stubs(:start_watching).returns(watch_dog)
105
-
106
- @kicker.expects(:trap).with('INT').yields
107
- watch_dog.expects(:stop)
108
- @kicker.expects(:exit)
109
-
110
- @kicker.start
111
- end
112
-
113
- if Kicker::Growl.usable?
114
- it "should register with growl if growl should be used" do
115
- @kicker.stubs(:validate_options!)
116
- Kicker::Growl.use = true
117
-
118
- Growl::Notifier.sharedInstance.expects(:register).with('Kicker', Kicker::Growl::NOTIFICATIONS.values)
119
- @kicker.start
120
- end
121
-
122
- it "should _not_ register with growl if growl should not be used" do
123
- @kicker.stubs(:validate_options!)
124
- Kicker::Growl.use = false
125
-
126
- Growl::Notifier.sharedInstance.expects(:register).never
127
- @kicker.start
128
- end
129
- end
130
-
131
- it "should call the startup chain" do
132
- @kicker.stubs(:validate_options!)
133
-
134
- @kicker.startup_chain.expects(:call).with([], false)
135
- @kicker.start
136
- end
137
- end
@@ -1,56 +0,0 @@
1
- require File.expand_path('../test_helper', __FILE__)
2
-
3
- describe "Kicker::LogStatus" do
4
- yielded = nil
5
-
6
- before do
7
- @status = Kicker::LogStatusHelper.new(proc { |s| yielded = s; 'out' if s.growl? }, 'ls -l')
8
- end
9
-
10
- it "should return whether or not it's for a stdout logger" do
11
- @status.call(:stdout)
12
- yielded.should.be.stdout
13
- yielded.should.not.be.growl
14
- end
15
-
16
- it "should return whether or not it's for a growl logger" do
17
- @status.call(:growl)
18
- yielded.should.not.be.stdout
19
- yielded.should.be.growl
20
- end
21
-
22
- it "should return the command" do
23
- @status.call(:growl)
24
- yielded.command.should == 'ls -l'
25
- end
26
-
27
- it "should return if it's before executing the command" do
28
- @status.call(:growl)
29
- yielded.should.be.before
30
- yielded.should.be.not.after
31
- end
32
-
33
- it "should return if it's after executing the command" do
34
- @status.result('output', true, 0)
35
- @status.call(:growl)
36
- yielded.should.not.be.before
37
- yielded.should.be.after
38
- end
39
-
40
- it "should return the output and status" do
41
- @status.result('output', true, 123)
42
- @status.call(:growl)
43
- yielded.output.should == "output"
44
- yielded.should.be.success
45
- yielded.exit_code.should.be 123
46
- end
47
-
48
- it "should set the logger type, call the proc with self, and return the output" do
49
- @status.call(:growl).should == "out"
50
- end
51
-
52
- it "should not try to call the block if none was given and return nil" do
53
- status = Kicker::LogStatusHelper.new(nil, 'ls -l')
54
- status.call(:growl).should.be nil
55
- end
56
- end
data/test/options_test.rb DELETED
@@ -1,80 +0,0 @@
1
- require File.expand_path('../test_helper', __FILE__)
2
-
3
- describe "Kicker::Options.parse" do
4
- after do
5
- Kicker.latency = 1
6
- Kicker.paths = %w{ . }
7
- Kicker.silent = false
8
- Kicker.quiet = false
9
- Kicker::Growl.use = true
10
- Kicker::Growl.command = nil
11
- end
12
-
13
- it "should parse the paths" do
14
- Kicker::Options.parse([])
15
- Kicker.paths.should == %w{ . }
16
-
17
- Kicker::Options.parse(%w{ /some/file.rb })
18
- Kicker.paths.should == %w{ /some/file.rb }
19
-
20
- Kicker::Options.parse(%w{ /some/file.rb /a/dir /and/some/other/file.rb })
21
- Kicker.paths.should == %w{ /some/file.rb /a/dir /and/some/other/file.rb }
22
- end
23
-
24
- if Kicker::Growl.usable?
25
- it "should parse if growl shouldn't be used" do
26
- Kicker::Options.parse([])
27
- Kicker::Growl.should.use
28
-
29
- Kicker::Options.parse(%w{ --no-growl })
30
- Kicker::Growl.should.not.use
31
- end
32
- end
33
-
34
- it "should parse if we should keep output to a minimum" do
35
- Kicker::Options.parse([])
36
- Kicker.should.not.be.silent
37
-
38
- Kicker::Options.parse(%w{ -s })
39
- Kicker.should.be.silent
40
- end
41
-
42
- it 'should parse whether or not to run in quiet mode and enable silent mode if quiet' do
43
- Kicker::Options.parse([])
44
- Kicker.should.not.be.quiet
45
- Kicker.should.not.be.silent
46
-
47
- Kicker::Options.parse(%w{ --quiet })
48
- Kicker.should.be.quiet
49
- Kicker.should.be.silent
50
- end
51
-
52
- it "should parse whether or not to clear the console before running" do
53
- Kicker::Options.parse([])
54
- Kicker.should.not.clear_console
55
-
56
- Kicker::Options.parse(%w{ --clear })
57
- Kicker.should.clear_console
58
- end
59
-
60
- if Kicker::Growl.usable?
61
- it "should parse the Growl command to use when the user clicks the Growl succeeded message" do
62
- Kicker::Options.parse(%w{ --growl-command ls })
63
- Kicker::Growl.command.should == 'ls'
64
- end
65
- end
66
-
67
- it "should parse the latency to pass to FSEvents" do
68
- Kicker::Options.parse(%w{ -l 2.5 })
69
- Kicker.latency.should == 2.5
70
-
71
- Kicker::Options.parse(%w{ --latency 3.5 })
72
- Kicker.latency.should == 3.5
73
- end
74
-
75
- it "should parse recipe requires" do
76
- Kicker::Recipes.expects(:recipe).with('rails')
77
- Kicker::Recipes.expects(:recipe).with('jstest')
78
- Kicker::Options.parse(%w{ -r rails --recipe jstest })
79
- end
80
- end