idler 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +7 -0
  2. data/.drone.yml +10 -0
  3. data/.gitignore +9 -0
  4. data/.idler.rb +7 -0
  5. data/.rspec +2 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +79 -0
  9. data/Rakefile +1 -0
  10. data/bin/idler +6 -0
  11. data/circle.yml +9 -0
  12. data/idler.gemspec +28 -0
  13. data/lib/idler.rb +38 -0
  14. data/lib/idler/branch.rb +37 -0
  15. data/lib/idler/descriptions.rb +42 -0
  16. data/lib/idler/dsl.rb +12 -0
  17. data/lib/idler/errors.rb +7 -0
  18. data/lib/idler/git_branch.rb +11 -0
  19. data/lib/idler/install.rb +11 -0
  20. data/lib/idler/version.rb +3 -0
  21. data/lib/idler/workers.rb +26 -0
  22. data/lib/templates/idler.rb +7 -0
  23. data/spec/idler/branch_spec.rb +120 -0
  24. data/spec/idler/descriptions_spec.rb +133 -0
  25. data/spec/idler/dsl_spec.rb +32 -0
  26. data/spec/idler/git_branch_spec.rb +25 -0
  27. data/spec/idler/install_spec.rb +21 -0
  28. data/spec/idler/workers_spec.rb +105 -0
  29. data/spec/idler_spec.rb +90 -0
  30. data/spec/spec_helper.rb +12 -0
  31. data/spec/supports/.idler.rb +17 -0
  32. data/spec/supports/development +1 -0
  33. data/spec/supports/git/COMMIT_EDITMSG +1 -0
  34. data/spec/supports/git/HEAD +1 -0
  35. data/spec/supports/git/config +7 -0
  36. data/spec/supports/git/description +1 -0
  37. data/spec/supports/git/hooks/applypatch-msg.sample +15 -0
  38. data/spec/supports/git/hooks/commit-msg.sample +24 -0
  39. data/spec/supports/git/hooks/post-update.sample +8 -0
  40. data/spec/supports/git/hooks/pre-applypatch.sample +14 -0
  41. data/spec/supports/git/hooks/pre-commit.sample +49 -0
  42. data/spec/supports/git/hooks/pre-push.sample +53 -0
  43. data/spec/supports/git/hooks/pre-rebase.sample +169 -0
  44. data/spec/supports/git/hooks/prepare-commit-msg.sample +36 -0
  45. data/spec/supports/git/hooks/update.sample +128 -0
  46. data/spec/supports/git/index +0 -0
  47. data/spec/supports/git/info/exclude +6 -0
  48. data/spec/supports/git/logs/HEAD +3 -0
  49. data/spec/supports/git/logs/refs/heads/development +2 -0
  50. data/spec/supports/git/logs/refs/heads/master +1 -0
  51. data/spec/supports/git/objects/26/7415b535950497a6fe509c590aae53b8aa8371 +0 -0
  52. data/spec/supports/git/objects/3e/6bfeeb8e007bfdaea40081872e8d6148e571ea +2 -0
  53. data/spec/supports/git/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904 +0 -0
  54. data/spec/supports/git/objects/97/ead751ee1b140cf8f560247f934987dcb88ee1 +0 -0
  55. data/spec/supports/git/objects/b2/ced74c2ca4e1f4bb69a2a937b71f411606cade +0 -0
  56. data/spec/supports/git/objects/ba/1959001cdfe38905402ad8dbfdd43e8da6d7ea +0 -0
  57. data/spec/supports/git/objects/ce/37909c3bed60d7e414d5904e54af0ae3b774f7 +0 -0
  58. data/spec/supports/git/objects/e7/4160f0955857b33155e6366b08abb2e17938dc +2 -0
  59. data/spec/supports/git/refs/heads/development +1 -0
  60. data/spec/supports/git/refs/heads/master +1 -0
  61. data/spec/supports/master +1 -0
  62. metadata +229 -0
@@ -0,0 +1,133 @@
1
+ require 'spec_helper'
2
+
3
+ describe Idler::Descriptions do
4
+
5
+ describe '.new' do
6
+ subject { described_class.new }
7
+
8
+ it { is_expected.to be_a Idler::Descriptions }
9
+ it '@descriptions should be set {}' do
10
+ expect(subject.instance_variable_get(:@descriptions)).to eq({})
11
+ end
12
+ end
13
+
14
+ describe '#add_branch' do
15
+ let(:instance) { described_class.new }
16
+ let(:branch) { nil }
17
+ subject { instance.add_branch(branch) }
18
+
19
+ context 'without branch name' do
20
+ it { expect { subject }.to raise_error(Idler::NothingBranchNameError) }
21
+ end
22
+
23
+ context 'with branch name' do
24
+ let(:branch) { 'test' }
25
+
26
+ it { expect { subject }.to_not raise_error }
27
+ it { is_expected.to eq({}) }
28
+
29
+ it '@descriptions should be set branch with blank hash' do
30
+ subject
31
+ expect(instance.instance_variable_get(:@descriptions)).to eq({'test'=> {}})
32
+ end
33
+ end
34
+ end
35
+
36
+ describe '#add_desc' do
37
+ let(:instance) { described_class.new }
38
+ let(:branch) { nil }
39
+ let(:desc) { nil }
40
+
41
+ subject { instance.add_desc branch, desc }
42
+
43
+ context 'not yet #add_branch' do
44
+ let(:branch) { 'test' }
45
+ it { expect { subject }.to raise_error(Idler::NotYetAddBranchError) }
46
+ end
47
+
48
+ context 'without branch name' do
49
+ before { instance.add_branch 'test' }
50
+ it { expect { subject }.to raise_error(Idler::NothingBranchNameError) }
51
+ end
52
+
53
+ context 'with branch name' do
54
+ let(:branch) { 'test' }
55
+ let(:desc) { 'test branch description' }
56
+
57
+ before { instance.add_branch branch }
58
+ it { expect { subject }.to_not raise_error }
59
+ it { is_expected.to eq(desc) }
60
+
61
+ it '@descriptions should be set test branch description' do
62
+ subject
63
+ expected_hash = {
64
+ 'test' => {
65
+ description: desc
66
+ }
67
+ }
68
+ expect(instance.instance_variable_get(:@descriptions)).to match(expected_hash)
69
+ end
70
+ end
71
+
72
+ end
73
+
74
+ describe '#add_detail' do
75
+ let(:instance) { described_class.new }
76
+ let(:branch) { nil }
77
+ let(:detail) { nil }
78
+
79
+ subject { instance.add_detail branch, detail }
80
+
81
+ context 'not yet #add_branch' do
82
+ let(:branch) { 'test' }
83
+ it { expect { subject }.to raise_error(Idler::NotYetAddBranchError) }
84
+ end
85
+
86
+ context 'without branch name' do
87
+ before { instance.add_branch 'test' }
88
+ it { expect { subject }.to raise_error(Idler::NothingBranchNameError) }
89
+ end
90
+
91
+ context 'with branch name' do
92
+ let(:branch) { 'test' }
93
+ let(:detail) { 'test branch detail' }
94
+
95
+ before { instance.add_branch branch }
96
+ it { expect { subject }.to_not raise_error }
97
+ it { is_expected.to eq(detail) }
98
+
99
+ it '@descriptions should be set test branch description' do
100
+ subject
101
+ expected_hash = {
102
+ 'test' => {
103
+ detail: detail
104
+ }
105
+ }
106
+ expect(instance.instance_variable_get(:@descriptions)).to match(expected_hash)
107
+ end
108
+ end
109
+
110
+ end
111
+
112
+ describe '#info' do
113
+ let(:instance) { described_class.new }
114
+ subject { instance.info }
115
+
116
+ context 'without branch descriptions' do
117
+ it 'should be print nothing branch' do
118
+ expect { subject }.to output("--- Branches Info ---\n").to_stdout
119
+ end
120
+ end
121
+
122
+ context 'with branch' do
123
+ before do
124
+ instance.add_branch 'test'
125
+ end
126
+ it 'should be print branches' do
127
+ expect { subject }.to output("--- Branches Info ---\n* \e[1mtest\e[0m\n").to_stdout
128
+ end
129
+ end
130
+
131
+ end
132
+
133
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+ require './lib/idler/dsl'
3
+
4
+ module Idler
5
+ class DummyDSL
6
+ include Idler::DSL
7
+
8
+ describe Idler::DSL do
9
+ let(:dsl) { DummyDSL.new }
10
+
11
+ describe '#branch' do
12
+ let(:branch_name) { nil }
13
+ let(:block) { Proc.new { nil } }
14
+
15
+ subject { dsl.branch branch_name, &block }
16
+
17
+ context 'without branch name' do
18
+ it { expect{ subject }.to raise_error(NothingBranchNameError) }
19
+ end
20
+
21
+ context 'with branch name' do
22
+ let(:branch_name) { 'test' }
23
+
24
+ it { expect{ subject }.to_not raise_error }
25
+ it { is_expected.to be_a Idler::Branch }
26
+ end
27
+
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Idler::GitBranch do
4
+
5
+ before do
6
+ class Dir
7
+ def self.pwd
8
+ 'spec/supports'
9
+ end
10
+ end
11
+ end
12
+
13
+ describe '#current_branch' do
14
+
15
+ subject do
16
+ class DummyClass
17
+ class << self
18
+ include Idler::GitBranch
19
+ end
20
+ end
21
+ DummyClass.current_branch
22
+ end
23
+ it { is_expected.to eq("development") }
24
+ end
25
+ end
@@ -0,0 +1,21 @@
1
+ require 'tmpdir'
2
+
3
+ describe Idler::Install do
4
+
5
+ before do
6
+ class Dir
7
+ def self.pwd
8
+ @tmpdir ||= Dir.mktmpdir
9
+ end
10
+ end
11
+ end
12
+
13
+ describe '.copy' do
14
+ subject { Idler::Install.copy }
15
+ it 'should be copy .idler.rb' do
16
+ subject
17
+ expect(File.exist?(Dir.pwd+"/.idler.rb")).to be_truthy
18
+ end
19
+ end
20
+
21
+ end
@@ -0,0 +1,105 @@
1
+ require 'spec_helper'
2
+
3
+ describe Idler::Workers do
4
+
5
+ describe '.new' do
6
+ subject { described_class.new }
7
+
8
+ it { is_expected.to be_a Idler::Workers }
9
+ it '@workers should be set {}' do
10
+ expect(subject.instance_variable_get(:@workers)).to eq({})
11
+ end
12
+ end
13
+
14
+ describe '#add_branch' do
15
+ let(:instance) { described_class.new }
16
+ let(:branch) { nil }
17
+ subject { instance.add_branch(branch) }
18
+
19
+ context 'without branch name' do
20
+ it { expect { subject }.to raise_error(Idler::NothingBranchNameError) }
21
+ end
22
+
23
+ context 'with branch name' do
24
+ let(:branch) { 'test' }
25
+
26
+ it { expect { subject }.to_not raise_error }
27
+ it { is_expected.to be_nil }
28
+
29
+ it '@workers should be set branch' do
30
+ subject
31
+ expect(instance.instance_variable_get(:@workers)).to eq({'test'=>nil})
32
+ end
33
+ end
34
+
35
+ end
36
+
37
+ describe '#add_worker' do
38
+ let(:instance) { described_class.new }
39
+ let(:branch) { nil }
40
+ let(:block) { Proc.new { nil } }
41
+
42
+ subject { instance.add_worker(branch, block) }
43
+
44
+ context 'not yet #add_branch' do
45
+ let(:branch) { 'test' }
46
+ it { expect { subject }.to raise_error(Idler::NotYetAddBranchError) }
47
+ end
48
+
49
+ context 'without branch_name' do
50
+ before { instance.add_branch 'test' }
51
+ it { expect { subject }.to raise_error(Idler::NothingBranchNameError) }
52
+ end
53
+
54
+ context 'without block' do
55
+ before { instance.add_branch 'test' }
56
+ let(:branch) { 'test' }
57
+ let(:block) { nil }
58
+ it { expect { subject }.to raise_error(Idler::NotProcError) }
59
+ end
60
+
61
+ context 'with branch' do
62
+ let(:branch) { 'test' }
63
+
64
+ before { instance.add_branch branch }
65
+ it { expect { subject }.to_not raise_error }
66
+
67
+ it 'should eq give proc' do
68
+ is_expected.to eq(block)
69
+ end
70
+
71
+ it '@workers should be set test branch worker' do
72
+ subject
73
+ expected_hash = {
74
+ 'test' => block
75
+ }
76
+ expect(instance.instance_variable_get(:@workers)).to match(expected_hash)
77
+ end
78
+ end
79
+
80
+ end
81
+
82
+ describe '#run' do
83
+ let(:instance) { described_class.new }
84
+ let(:branch) { nil }
85
+ let(:block) { Proc.new { branch } }
86
+
87
+ subject { instance.run branch }
88
+
89
+ context 'without branch' do
90
+ it { expect { subject }.to raise_error(Idler::NothingBranchNameError) }
91
+ end
92
+
93
+ context 'with branch' do
94
+ let(:branch) { 'test' }
95
+ before do
96
+ instance.add_branch branch
97
+ instance.add_worker branch, block
98
+ end
99
+
100
+ it { expect { subject }.to_not raise_error }
101
+ it { is_expected.to eq(branch) }
102
+ end
103
+
104
+ end
105
+ end
@@ -0,0 +1,90 @@
1
+ require 'spec_helper'
2
+
3
+ describe Idler do
4
+ it 'has a version number' do
5
+ expect(Idler::VERSION).not_to be nil
6
+ end
7
+
8
+ describe '.descriptions' do
9
+ subject { Idler.descriptions }
10
+ it { is_expected.to be_instance_of(Idler::Descriptions) }
11
+ end
12
+
13
+ describe '.workers' do
14
+ subject { Idler.workers }
15
+ it { is_expected.to be_instance_of(Idler::Workers) }
16
+ end
17
+
18
+ describe '.run' do
19
+ let(:argv) { nil }
20
+
21
+ subject { Idler.run(argv) }
22
+
23
+ context 'init action' do
24
+ let(:argv) { [ 'init' ] }
25
+
26
+ before do
27
+ class Dir
28
+ def self.pwd
29
+ @tmpdir ||= Dir.mktmpdir
30
+ end
31
+ end
32
+ end
33
+
34
+ it 'should copy .idler.rb' do
35
+ expect(File.exist?(Dir.pwd+"/.idler.rb")).to be_truthy
36
+ end
37
+ end
38
+
39
+ context 'info action' do
40
+ let(:argv) { [ 'info' ] }
41
+ before { Idler.remove_instance_variable(:@descriptions) }
42
+ it 'should be print nothing branch' do
43
+ expect { subject }.to output("--- Branches Info ---\n").to_stdout
44
+ end
45
+ end
46
+
47
+ context 'run specified branch' do
48
+ let(:argv) { [ 'test' ] }
49
+ context 'not found' do
50
+ before { Idler.remove_instance_variable(:@workers) }
51
+ it { is_expected.to be_nil }
52
+ end
53
+
54
+ context 'success' do
55
+ let(:workers) do
56
+ workers_instance = Idler::Workers.new
57
+ workers_instance.instance_variable_set(:@workers, {'test' => Proc.new { 'ok' } })
58
+ workers_instance
59
+ end
60
+ before { Idler.instance_variable_set(:@workers, workers) }
61
+ it { is_expected.to eq('ok') }
62
+ end
63
+ end
64
+
65
+ context 'run current_branch' do
66
+ before do
67
+ class Dir
68
+ def self.pwd
69
+ 'spec/supports'
70
+ end
71
+ end
72
+ end
73
+
74
+ context 'not found' do
75
+ before { Idler.remove_instance_variable(:@workers) }
76
+ it { is_expected.to be_nil }
77
+ end
78
+
79
+ context 'success' do
80
+ let(:workers) do
81
+ workers_instance = Idler::Workers.new
82
+ workers_instance.instance_variable_set(:@workers, {'development' => Proc.new { 'ok' } })
83
+ workers_instance
84
+ end
85
+ before { Idler.instance_variable_set(:@workers, workers) }
86
+ it { is_expected.to eq('ok') }
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,12 @@
1
+ require 'idler'
2
+
3
+ RSpec.configure do |config|
4
+
5
+ config.before(:each) do
6
+ FileUtils.mv('spec/supports/git', 'spec/supports/.git')
7
+ end
8
+
9
+ config.after(:each) do
10
+ FileUtils.mv('spec/supports/.git', 'spec/supports/git')
11
+ end
12
+ end
@@ -0,0 +1,17 @@
1
+ require 'idler/dsl'
2
+
3
+ branch 'master' do
4
+ desc 'master description'
5
+ detail 'master detail'
6
+ worker do
7
+ `cat master`
8
+ end
9
+ end
10
+
11
+ branch 'development' do
12
+ desc 'development description'
13
+ detail 'development detail'
14
+ worker do
15
+ `cat development`
16
+ end
17
+ end
@@ -0,0 +1 @@
1
+ Development Branch!