karl-loris 0.0.5 → 0.0.6

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.
Files changed (48) hide show
  1. data/.autotest +12 -0
  2. data/.gitignore +1 -0
  3. data/TODO +21 -0
  4. data/VERSION +1 -0
  5. data/autotest/discover.rb +3 -0
  6. data/cucumber.yml +1 -0
  7. data/examples/self_test/jsl.conf +0 -0
  8. data/examples/self_test/spec/spec.rhino.js +6 -0
  9. data/features/run.feature +37 -0
  10. data/features/step_definitons/all.rb +61 -0
  11. data/features/support/env.rb +145 -0
  12. data/lib/always_continuer.rb +7 -0
  13. data/lib/extension_filter.rb +20 -0
  14. data/lib/file_actioner.rb +16 -0
  15. data/lib/file_filter.rb +14 -0
  16. data/lib/file_finder.rb +31 -0
  17. data/lib/icons/error.png +0 -0
  18. data/lib/icons/failure.png +0 -0
  19. data/lib/icons/info.png +0 -0
  20. data/lib/icons/success.png +0 -0
  21. data/lib/icons/warning.png +0 -0
  22. data/lib/loris.rb +108 -0
  23. data/lib/modified_filter.rb +21 -0
  24. data/lib/outputs/console_clearing_output.rb +14 -0
  25. data/lib/outputs/growl_output.rb +26 -0
  26. data/lib/outputs/output_collection.rb +23 -0
  27. data/lib/outputs/shell_output.rb +17 -0
  28. data/lib/poller.rb +16 -0
  29. data/lib/sleep_waiter.rb +11 -0
  30. data/lib/task_manager.rb +27 -0
  31. data/lib/tasks/javascript_lint_runner.rb +15 -0
  32. data/lib/tasks/javascript_lint_task.rb +63 -0
  33. data/lib/tasks/jspec_runner.rb +15 -0
  34. data/lib/tasks/jspec_task.rb +53 -0
  35. data/lib/tasks/list_task.rb +34 -0
  36. data/loris.tmproj +202 -0
  37. data/spec/file_actioner_spec.rb +41 -0
  38. data/spec/file_filter_spec.rb +28 -0
  39. data/spec/file_finder_spec.rb +73 -0
  40. data/spec/growl_output_spec.rb +33 -0
  41. data/spec/jspec_task_spec.rb +47 -0
  42. data/spec/list_task_spec.rb +58 -0
  43. data/spec/modified_filter_spec.rb +47 -0
  44. data/spec/poller_spec.rb +28 -0
  45. data/spec/shell_output_spec.rb +25 -0
  46. data/spec/task_manager_spec.rb +64 -0
  47. metadata +70 -19
  48. data/loris.gemspec +0 -33
@@ -0,0 +1,41 @@
1
+ require 'lib/file_actioner.rb'
2
+
3
+ describe FileActioner do
4
+
5
+ it "Should get filtered files and send them to action" do
6
+ files = {
7
+ :all => ['/path/to.file'],
8
+ :filtered => ['/path/to.file']
9
+ }
10
+
11
+ ff = mock('file finder')
12
+ ff.should_receive(:find).and_return(files)
13
+
14
+ tm = mock('TaskManager')
15
+ tm.should_receive(:run).with(files)
16
+
17
+ fa = FileActioner.new(ff, tm)
18
+ fa.run()
19
+
20
+ end
21
+
22
+ it "should not run the actions if no filtered files" do
23
+ files = {
24
+ :all => ['/path/to.file'],
25
+ :filtered => []
26
+ }
27
+
28
+ ff = mock('file finder')
29
+ ff.should_receive(:find).and_return(files)
30
+
31
+ tm = mock('TaskManager')
32
+ tm.should_not_receive(:run)
33
+
34
+ fa = FileActioner.new(ff, tm)
35
+ fa.run()
36
+
37
+ end
38
+
39
+ end
40
+
41
+
@@ -0,0 +1,28 @@
1
+ require 'lib/file_filter'
2
+
3
+ describe FileFilter do
4
+
5
+ before do
6
+ end
7
+
8
+ it 'should return true if a file' do
9
+ @path = '/path/to.file'
10
+ @file = mock('File class')
11
+ @file.should_receive(:file?).with(@path).and_return(true)
12
+
13
+ filter = FileFilter.new(@file)
14
+
15
+ filter.filter(@path).should be_true
16
+ end
17
+
18
+ it 'should return false if a directory' do
19
+ @path = '/path/to/dir'
20
+ @file = mock('File class')
21
+ @file.should_receive(:file?).with(@path).and_return(false)
22
+
23
+ filter = FileFilter.new(@file)
24
+
25
+ filter.filter(@path).should be_false
26
+ end
27
+
28
+ end
@@ -0,0 +1,73 @@
1
+ require 'lib/file_finder'
2
+
3
+ describe FileFinder do
4
+
5
+ before do
6
+ finder = mock('finder')
7
+ finder.should_receive(:find).with('/monkey').and_yield('/monkey/modified.txt').and_yield('/monkey/modified-2.txt').and_yield('/monkey/not-modified.txt')
8
+
9
+ @filter = mock('filter')
10
+ @filter.should_receive(:filter).at_most(1).with('/monkey/modified.txt').and_return(true)
11
+ @filter.should_receive(:filter).at_most(1).with('/monkey/modified-2.txt').and_return(true)
12
+ @filter.should_receive(:filter).at_most(1).with('/monkey/not-modified.txt').and_return(false)
13
+
14
+ @filter2 = mock('filter')
15
+ @filter2.should_receive(:filter).at_most(1).with('/monkey/modified.txt').and_return(true)
16
+ @filter2.should_receive(:filter).at_most(1).with('/monkey/modified-2.txt').and_return(false)
17
+ @filter2.should_receive(:filter).at_most(1).with('/monkey/not-modified.txt').and_return(true)
18
+
19
+ dir = '/monkey'
20
+ @ff = FileFinder.new(finder, dir)
21
+ end
22
+
23
+ it 'with no filters, should return all files' do
24
+ result = {
25
+ :all => ['/monkey/modified.txt', '/monkey/modified-2.txt', '/monkey/not-modified.txt'],
26
+ :filtered => ['/monkey/modified.txt', '/monkey/modified-2.txt', '/monkey/not-modified.txt']
27
+ }
28
+
29
+ files = @ff.find
30
+ files.should eql result
31
+ end
32
+
33
+ it 'with filter, should return only filtered' do
34
+ result = {
35
+ :all => ['/monkey/modified.txt', '/monkey/modified-2.txt', '/monkey/not-modified.txt'],
36
+ :filtered => ['/monkey/modified.txt', '/monkey/modified-2.txt']
37
+ }
38
+
39
+ @filter.should_receive(:complete)
40
+
41
+ @ff.add_filter(@filter)
42
+ files = @ff.find
43
+
44
+ files.should eql result
45
+ end
46
+
47
+ it 'should be able to accept multiple filters' do
48
+ result = {
49
+ :all => ['/monkey/modified.txt', '/monkey/modified-2.txt', '/monkey/not-modified.txt'],
50
+ :filtered => ['/monkey/modified.txt']
51
+ }
52
+
53
+ @filter.should_receive(:complete)
54
+ @filter2.should_receive(:complete)
55
+
56
+ @ff.add_filter(@filter)
57
+ @ff.add_filter(@filter2)
58
+ files = @ff.find
59
+
60
+ files.should eql result
61
+ end
62
+
63
+ it 'should call filter.complete methods at the end of find' do
64
+ @filter.should_receive(:complete)
65
+ @filter2.should_receive(:complete)
66
+
67
+ @ff.add_filter(@filter)
68
+ @ff.add_filter(@filter2)
69
+ files = @ff.find
70
+
71
+ end
72
+
73
+ end
@@ -0,0 +1,33 @@
1
+ require 'lib/outputs/growl_output.rb'
2
+
3
+ describe GrowlOutput do
4
+
5
+ it "should not notify if growl is not installed" do
6
+ result = {}
7
+
8
+ growl = mock('Growl')
9
+ growl.should_receive(:installed?).and_return(false)
10
+
11
+ growl_output = GrowlOutput.new(growl)
12
+ growl_output.add_result(result)
13
+ end
14
+
15
+ it "should call original add_result method" do
16
+ result = {
17
+ :state => :success,
18
+ :title => 'Example Title',
19
+ :summary => 'Example Summary',
20
+ :detail => 'Detail goes here...'
21
+ }
22
+
23
+ growl = mock('Growl')
24
+ growl.should_receive(:installed?).and_return(true)
25
+ growl.should_receive(:notify)
26
+
27
+ growl_output = GrowlOutput.new(growl)
28
+ growl_output.add_result(result)
29
+ end
30
+
31
+ end
32
+
33
+
@@ -0,0 +1,47 @@
1
+ require 'lib/tasks/jspec_task.rb'
2
+
3
+ describe JSpecTask do
4
+
5
+ before do
6
+ @files = {
7
+ :all => [],
8
+ :filtered => []
9
+ }
10
+ end
11
+
12
+ it "should return error if unable to parse jspec output" do
13
+ jspec = mock('JSpec Runner')
14
+ jspec.should_receive(:is_configured?).and_return(true)
15
+ jspec.should_receive(:execute).and_return('A JSpec error message here...')
16
+
17
+ jspec_task = JSpecTask.new(jspec)
18
+ result = jspec_task.run(@files)
19
+
20
+ result[:state].should eql :error
21
+ end
22
+
23
+ it "should return success if all tests pass" do
24
+ jspec = mock('JSpec Runner')
25
+ jspec.should_receive(:is_configured?).and_return(true)
26
+ jspec.should_receive(:execute).and_return('Passes: 3 Failures: 0')
27
+
28
+ jspec_task = JSpecTask.new(jspec)
29
+ result = jspec_task.run(@files)
30
+
31
+ result[:state].should eql :success
32
+ end
33
+
34
+ it "should return failure if any test fails" do
35
+ jspec = mock('JSpec Runner')
36
+ jspec.should_receive(:is_configured?).and_return(true)
37
+ jspec.should_receive(:execute).and_return('Passes: 2 Failures: 1')
38
+
39
+ jspec_task = JSpecTask.new(jspec)
40
+ result = jspec_task.run(@files)
41
+
42
+ result[:state].should eql :failure
43
+ end
44
+
45
+ end
46
+
47
+
@@ -0,0 +1,58 @@
1
+ require 'lib/tasks/list_task.rb'
2
+
3
+ describe ListTask do
4
+
5
+ before do
6
+ @files = {
7
+ :all => ['/path/to.file', '/not/in.filtered'],
8
+ :filtered => ['/path/to.file']
9
+ }
10
+ end
11
+
12
+ it "should output the given paths" do
13
+ oa = ListTask.new()
14
+ result = oa.run(@files)
15
+
16
+ result[:detail].should eql "/path/to.file\n"
17
+ end
18
+
19
+ it "should output the given paths using the given format string" do
20
+ format_string = "the file '%s' has been modified!"
21
+
22
+ oa = ListTask.new(format_string)
23
+ result = oa.run(@files)
24
+
25
+ result[:detail].should eql "the file '/path/to.file' has been modified!\n"
26
+ end
27
+
28
+ it "should return a title" do
29
+ oa = ListTask.new()
30
+ result = oa.run(@files)
31
+
32
+ result[:title].should eql "List"
33
+ end
34
+
35
+ it "should return success always" do
36
+ oa = ListTask.new()
37
+ result = oa.run(@files)
38
+
39
+ result[:state].should eql :success
40
+ end
41
+
42
+ it "should return summary for 1 file" do
43
+ oa = ListTask.new()
44
+ result = oa.run(@files)
45
+
46
+ result[:first].should eql @files[:filtered][0]
47
+ end
48
+
49
+ it "should return summary for 3 files" do
50
+ oa = ListTask.new()
51
+ result = oa.run({ :filtered => ['first.file','second.file','third.file'] })
52
+
53
+ result[:first].should eql "3 files."
54
+ end
55
+
56
+ end
57
+
58
+
@@ -0,0 +1,47 @@
1
+ require 'lib/modified_filter'
2
+ require 'time'
3
+
4
+ describe ModifiedFilter do
5
+
6
+ before do
7
+ @path = '/path/to.file'
8
+ @file = mock('File class')
9
+ @file.should_receive(:mtime).any_number_of_times.with(@path).and_return(Time.parse('2000/01/01'))
10
+ end
11
+
12
+ it 'should return true if no last modified date set' do
13
+ filter = ModifiedFilter.new(@file)
14
+
15
+ filter.filter(@path).should be_true
16
+ end
17
+
18
+ it 'should return false if file modified before given last modified date' do
19
+ last_modified = Time.parse('2000/01/02')
20
+ filter = ModifiedFilter.new(@file, last_modified)
21
+
22
+ filter.filter(@path).should be_false
23
+ end
24
+
25
+ it 'should remember the last modified date on complete method' do
26
+ filter = ModifiedFilter.new(@file)
27
+ filter.filter(@path)
28
+
29
+ filter.complete
30
+
31
+ filter.filter(@path).should be_false
32
+ end
33
+
34
+ it 'should remember the last modified date and recognise changed date on file' do
35
+ @file = mock('File class')
36
+ @file.should_receive(:mtime).with(@path).and_return(Time.parse('2000/01/01'))
37
+ @file.should_receive(:mtime).with(@path).and_return(Time.parse('2000/01/03'))
38
+
39
+ filter = ModifiedFilter.new(@file)
40
+ filter.filter(@path)
41
+
42
+ filter.complete
43
+
44
+ filter.filter(@path).should be_true
45
+ end
46
+
47
+ end
@@ -0,0 +1,28 @@
1
+ require 'lib/poller.rb'
2
+
3
+ describe Poller do
4
+
5
+ before do
6
+ continue = true
7
+ @continuer = mock('continuer')
8
+ @continuer.should_receive(:continue?).any_number_of_times {
9
+ continue
10
+ }
11
+
12
+ @waiter = mock('waiter')
13
+ @waiter.should_receive(:wait).ordered
14
+
15
+ @action = mock('actioner')
16
+ @action.should_receive(:run).ordered {
17
+ continue = false
18
+ }
19
+ end
20
+
21
+ it "should wait and call action while contunuer returns true" do
22
+ p = Poller.new(@waiter, @continuer, @action)
23
+ p.start()
24
+ end
25
+
26
+ end
27
+
28
+
@@ -0,0 +1,25 @@
1
+ require 'lib/outputs/shell_output.rb'
2
+
3
+ describe ShellOutput do
4
+
5
+ it "should output title, state, summary, and detail" do
6
+ result = {
7
+ :state => :success,
8
+ :title => 'Example Title',
9
+ :summary => 'Example Summary',
10
+ :detail => 'Detail goes here...'
11
+ }
12
+
13
+ output = mock('Output')
14
+ output.should_receive(:puts).with(:success)
15
+ output.should_receive(:puts).with('Example Title')
16
+ output.should_receive(:puts).with('Example Summary')
17
+ output.should_receive(:puts).with('Detail goes here...')
18
+
19
+ shell_output = ShellOutput.new(output)
20
+ shell_output.add_result(result)
21
+ end
22
+
23
+ end
24
+
25
+
@@ -0,0 +1,64 @@
1
+ require 'lib/task_manager.rb'
2
+
3
+ describe TaskManager do
4
+
5
+ before do
6
+ @files = ['/path/to.file']
7
+ @result = {
8
+ :state => :success,
9
+ :detail =>'task output'
10
+ }
11
+
12
+ @task1 = mock('Task 1')
13
+ @task2 = mock('Task 2')
14
+ @output = mock('Output')
15
+
16
+ end
17
+
18
+ it "should call start_run and then output a run task" do
19
+ @task1.should_receive(:run).with(@files).and_return(@result)
20
+ @output.should_receive(:start_run)
21
+ @output.should_receive(:add_result).with(@result)
22
+
23
+ task_manager = TaskManager.new(@output)
24
+ task_manager.add(@task1)
25
+ task_manager.run(@files)
26
+ end
27
+
28
+ it "should run multiple tasks in order added" do
29
+ @task1.should_receive(:run).ordered.with(@files).and_return(@result)
30
+ @task2.should_receive(:run).ordered.with(@files).and_return(@result)
31
+ @output.should_receive(:start_run)
32
+ @output.should_receive(:add_result).any_number_of_times
33
+
34
+ task_manager = TaskManager.new(@output)
35
+ task_manager.add(@task1)
36
+ task_manager.add(@task2)
37
+ task_manager.run(@files)
38
+ end
39
+
40
+ it "should stop running tasks on error state" do
41
+ @task1.should_receive(:run).ordered.with(@files).and_return({:state => :error})
42
+ @output.should_receive(:start_run)
43
+ @output.should_receive(:add_result).any_number_of_times
44
+
45
+ task_manager = TaskManager.new(@output)
46
+ task_manager.add(@task1)
47
+ task_manager.add(@task2)
48
+ task_manager.run(@files)
49
+ end
50
+
51
+ it "should stop running tasks on failure state" do
52
+ @task1.should_receive(:run).ordered.with(@files).and_return({:state => :failure})
53
+ @output.should_receive(:start_run)
54
+ @output.should_receive(:add_result).any_number_of_times
55
+
56
+ task_manager = TaskManager.new(@output)
57
+ task_manager.add(@task1)
58
+ task_manager.add(@task2)
59
+ task_manager.run(@files)
60
+ end
61
+
62
+ end
63
+
64
+