runnerbean 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6db84c5833b28b6b42632acadeaa26ca0229359d
4
+ data.tar.gz: 3f99346b043a96c2c944a48000c59ef3aa1ddf1f
5
+ SHA512:
6
+ metadata.gz: a8a3f81f604839a6828e1be2fdf7e162d2cf7d93b8aff0cef040d2e118acf40ff52e60e54c5ab65110c4dfd2fae0ec40213d7fd8c2e64c273fc37c5b72b70208
7
+ data.tar.gz: ea4f22990d4a4dc4a696d3d9f8c58e2f7274ae868e0e9f5bc2d4a0f5574e30bc1f446be494fab272ea4754682480f75c7edfc02439330b87ac99398adf38f7a6
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,7 @@
1
+ Metrics/LineLength:
2
+ Description: 'Limit lines to 120 characters.'
3
+ Max: 120
4
+
5
+ Style/Documentation:
6
+ Enabled: false
7
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in runnerbean.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,58 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features) \
6
+ # .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
7
+
8
+ ## Note: if you are using the `directories` clause above and you are not
9
+ ## watching the project directory ('.'), then you will want to move
10
+ ## the Guardfile to a watched dir and symlink it back, e.g.
11
+ #
12
+ # $ mkdir config
13
+ # $ mv Guardfile config/
14
+ # $ ln -s config/Guardfile .
15
+ #
16
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17
+
18
+ group :all_plugins, halt_on_fail: true do
19
+ guard :bundler do
20
+ require 'guard/bundler'
21
+ require 'guard/bundler/verify'
22
+ helper = Guard::Bundler::Verify.new
23
+
24
+ files = ['Gemfile']
25
+ files += Dir['*.gemspec'] if files.any? { |f| helper.uses_gemspec?(f) }
26
+
27
+ # Assume files are symlinked from somewhere
28
+ files.each { |file| watch(helper.real_path(file)) }
29
+ end
30
+
31
+ # Note: The cmd option is now required due to the increasing number of ways
32
+ # rspec may be run, below are examples of the most common uses.
33
+ # * bundler: 'bundle exec rspec'
34
+ # * bundler binstubs: 'bin/rspec'
35
+ # * spring: 'bin/rspec' (This will use spring if running and you have
36
+ # installed the spring binstubs per the docs)
37
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
38
+ # * 'just' rspec: 'rspec'
39
+
40
+ guard :rspec, cmd: 'bundle exec rspec', all_on_start: true, all_after_pass: true do
41
+ require 'guard/rspec/dsl'
42
+ dsl = Guard::RSpec::Dsl.new(self)
43
+
44
+ # RSpec files
45
+ rspec = dsl.rspec
46
+ watch(rspec.spec_helper) { rspec.spec_dir }
47
+ watch(rspec.spec_support) { rspec.spec_dir }
48
+ watch(rspec.spec_files)
49
+
50
+ # Ruby files
51
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
52
+ end
53
+
54
+ guard :rubocop do
55
+ watch(/.+\.rb$/)
56
+ watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
57
+ end
58
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 baob
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Runnerbean
2
+
3
+ Automates starting and stopping processes for testing.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'runnerbean'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install runnerbean
20
+
21
+ ## Usage
22
+
23
+ See examples folder for examples of use.
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/runnerbean/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ APP_ROOT = File.expand_path('..', __dir__)
4
+ $LOAD_PATH.unshift(File.join(APP_ROOT, 'lib'))
5
+
6
+ require 'runnerbean'
7
+
8
+ class Frontend
9
+ attr_accessor :log_file_prefix
10
+
11
+ def start_command
12
+ "echo 'This would be the Frontend start command'"
13
+ end
14
+
15
+ def sleep_after_start
16
+ 1
17
+ end
18
+
19
+ def kill_command
20
+ "echo 'This would be the Frontend kill command'"
21
+ end
22
+
23
+ def sleep_after_kill
24
+ 1
25
+ end
26
+ end
27
+
28
+ class Backend
29
+ attr_accessor :log_file_prefix
30
+
31
+ def start_command
32
+ "echo 'This would be the Backend start command'"
33
+ end
34
+
35
+ def sleep_after_start
36
+ 1
37
+ end
38
+
39
+ def kill_command
40
+ "echo 'This would be the Backend kill command'"
41
+ end
42
+
43
+ def sleep_after_kill
44
+ 1
45
+ end
46
+ end
47
+
48
+ runner = Runnerbean.runner('front_and_back')
49
+ runner.add_process(frontend: Frontend.new,
50
+ backend: Backend.new)
51
+
52
+ runner.start!(:frontend)
53
+ puts 'Frontend only Tests would run here ...'
54
+ runner.kill!(:frontend)
55
+
56
+ puts "\n .... and .... \n\n"
57
+
58
+ runner.start!(:frontend, :backend)
59
+ puts 'combined Frontend and Backend Tests would run here ...'
60
+ runner.kill!(:frontend, :backend)
@@ -0,0 +1,64 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ APP_ROOT = File.expand_path('..', __dir__)
4
+ $LOAD_PATH.unshift(File.join(APP_ROOT, 'lib'))
5
+
6
+ require 'runnerbean'
7
+
8
+ class Frontend
9
+ attr_accessor :log_file_prefix
10
+
11
+ def start_command
12
+ "echo 'This would be the Frontend start command'"
13
+ end
14
+
15
+ def sleep_after_start
16
+ 1
17
+ end
18
+
19
+ def kill_command
20
+ "echo 'This would be the Frontend kill command'"
21
+ end
22
+
23
+ def sleep_after_kill
24
+ 1
25
+ end
26
+ end
27
+
28
+ class Backend
29
+ attr_accessor :log_file_prefix
30
+
31
+ def start_command
32
+ "echo 'This would be the Backend start command'"
33
+ end
34
+
35
+ def sleep_after_start
36
+ 1
37
+ end
38
+
39
+ def kill_command
40
+ "echo 'This would be the Backend kill command'"
41
+ end
42
+
43
+ def sleep_after_kill
44
+ 1
45
+ end
46
+ end
47
+
48
+ runner = Runnerbean.runner
49
+ runner.add_process(frontend: Frontend.new,
50
+ backend: Backend.new)
51
+
52
+ smoke_test_group = runner.group(:frontend, :backend)
53
+ smoke_test_group.name = ('smoke_test')
54
+ backend = runner.group(:backend)
55
+
56
+ backend.start!
57
+ puts 'Backend only Tests would run here ...'
58
+ backend.kill!
59
+
60
+ puts "\n .... and .... \n\n"
61
+
62
+ smoke_test_group.start!
63
+ puts 'combined Frontend and Backend Tests would run here ...'
64
+ smoke_test_group.kill!
data/examples/simple ADDED
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ APP_ROOT = File.expand_path('..', __dir__)
4
+ $LOAD_PATH.unshift(File.join(APP_ROOT, 'lib'))
5
+
6
+ require 'runnerbean'
7
+
8
+ class MyTestProcess
9
+ attr_accessor :log_file_prefix
10
+
11
+ def start_command
12
+ "echo 'This would be the start command, logging to prefix of #{log_file_prefix}' &&" \
13
+ "echo '... with a following delay of #{sleep_after_start}'"
14
+ end
15
+
16
+ def sleep_after_start
17
+ 7
18
+ end
19
+
20
+ def kill_command
21
+ "echo 'This would be the kill command, logging to prefix of #{log_file_prefix}' &&" \
22
+ "echo '... with a following delay of #{sleep_after_kill}'"
23
+ end
24
+
25
+ def sleep_after_kill
26
+ 4
27
+ end
28
+ end
29
+
30
+ runner = Runnerbean.runner('simple')
31
+ runner.add_process(my_process: MyTestProcess.new)
32
+
33
+ runner.start!(:my_process)
34
+ puts 'Tests would run here ...'
35
+ runner.kill!(:my_process)
@@ -0,0 +1,62 @@
1
+ module Runnerbean
2
+ class ProcessGroup
3
+ attr_reader :processes
4
+ attr_writer :name
5
+
6
+ def initialize(*processes)
7
+ @processes = processes
8
+ end
9
+
10
+ def kill!
11
+ generic_command(:kill)
12
+ end
13
+
14
+ def start!
15
+ generic_command(:start)
16
+ end
17
+
18
+ def name
19
+ @name ||= default_process_group_name
20
+ end
21
+
22
+ private
23
+
24
+ def default_process_group_name
25
+ return processes.map(&:name).join('_and_')
26
+ rescue
27
+ 'default_process_group_name'
28
+ end
29
+
30
+ def generic_command(command)
31
+ request_log_files
32
+
33
+ commands = find_commands(command)
34
+ execute(*commands)
35
+
36
+ sleep_times = find_sleep_times(command)
37
+ sleep_for(*sleep_times)
38
+ end
39
+
40
+ def request_log_files
41
+ processes.each { |p| p.log_file_prefix = name }
42
+ end
43
+
44
+ def find_commands(command)
45
+ command_getter = "#{command}_command".to_sym
46
+ processes.map(&command_getter).compact
47
+ end
48
+
49
+ def execute(*commands)
50
+ commands.map { |k| Kernel.system(k) } unless commands.size == 0
51
+ end
52
+
53
+ def find_sleep_times(command)
54
+ sleep_getter = "sleep_after_#{command}".to_sym
55
+ processes.map(&sleep_getter).compact
56
+ end
57
+
58
+ def sleep_for(*sleep_times)
59
+ Kernel.sleep(sleep_times.max) unless sleep_times.size == 0
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,56 @@
1
+ require 'runnerbean/process_group'
2
+
3
+ module Runnerbean
4
+ class Runner
5
+ attr_reader :name
6
+
7
+ def initialize(opts = {})
8
+ @name = opts[:name] || 'runner'
9
+ end
10
+
11
+ def add_process(opts)
12
+ opts.each do |key, value|
13
+ process_index[key] = value
14
+ end
15
+ end
16
+
17
+ def kill!(*process_names)
18
+ pg = process_group(*process_names)
19
+ pg.name = name
20
+ pg.kill!
21
+ pg # allows chaining
22
+ end
23
+
24
+ def start!(*process_names)
25
+ pg = process_group(*process_names)
26
+ pg.name = name
27
+ pg.start!
28
+ pg # allows chaining
29
+ end
30
+
31
+ def group(*process_names)
32
+ process_group(*process_names)
33
+ end
34
+
35
+ private
36
+
37
+ def process_group(*process_names)
38
+ processes = processes_from_names(*process_names)
39
+ ProcessGroup.new(*processes)
40
+ end
41
+
42
+ def processes_from_names(*process_names)
43
+ process_names.map { |pn| process_from_name(pn) }
44
+ end
45
+
46
+ def process_from_name(name)
47
+ process_index.fetch(name)
48
+ rescue KeyError => e
49
+ raise ProcessNotDefined, e.message
50
+ end
51
+
52
+ def process_index
53
+ @process_index ||= {}
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,3 @@
1
+ module Runnerbean
2
+ VERSION = '0.0.1'
3
+ end
data/lib/runnerbean.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'runnerbean/version'
2
+ require 'runnerbean/runner'
3
+
4
+ module Runnerbean
5
+ def self.runner(name = 'runnerbean')
6
+ Runnerbean::Runner.new(name: name)
7
+ end
8
+
9
+ class ProcessNotDefined < Exception; end
10
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'runnerbean/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'runnerbean'
8
+ spec.version = Runnerbean::VERSION
9
+ spec.authors = ['baob']
10
+ spec.email = ['coder@onesandthrees.com']
11
+ spec.summary = 'Automates starting and stopping processes for testing.'
12
+ # spec.description = %q{TODO: Write a longer description. Optional.}
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.7'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency 'rspec'
24
+ spec.add_development_dependency 'guard'
25
+ spec.add_development_dependency 'guard-rspec'
26
+ spec.add_development_dependency 'terminal-notifier-guard'
27
+ spec.add_development_dependency 'rubocop'
28
+ spec.add_development_dependency 'guard-rubocop'
29
+ spec.add_development_dependency 'guard-bundler'
30
+ spec.add_development_dependency 'pry'
31
+ end
@@ -0,0 +1,122 @@
1
+ require 'runnerbean'
2
+ require 'runnerbean/process_group'
3
+
4
+ module Runnerbean
5
+ RSpec.describe ProcessGroup do
6
+ let(:group) { described_class.new(*processes) }
7
+ let(:name) { 'default_process_group_name' }
8
+ let(:the_frontend_kill) { 'kill_that_frontend' }
9
+ let(:the_frontend_start) { 'start_that_frontend' }
10
+ let(:the_frontend) do
11
+ double('the frontend',
12
+ name: 'name_of_the_frontend',
13
+ kill_command: the_frontend_kill,
14
+ start_command: the_frontend_start,
15
+ sleep_after_start: 7,
16
+ sleep_after_kill: 2,
17
+ :'log_file_prefix=' => nil
18
+ )
19
+ end
20
+ let(:the_worker_kill) { 'kill_that_worker' }
21
+ let(:the_worker) do
22
+ double('the worker',
23
+ name: 'name_of_the_worker',
24
+ kill_command: the_worker_kill,
25
+ sleep_after_kill: 4,
26
+ :'log_file_prefix=' => nil
27
+ )
28
+ end
29
+ before { allow(Kernel).to receive(:system).with(anything) }
30
+ before { allow(Kernel).to receive(:sleep).with(anything) }
31
+
32
+ context 'with an incomplete process defined' do
33
+ let(:bad_process) do
34
+ class BadProcess; end
35
+ BadProcess
36
+ end
37
+ let(:processes) { [bad_process] }
38
+
39
+ describe '#start!' do
40
+ subject { group.start! }
41
+
42
+ it 'raises no method error' do
43
+ expect { subject }.to raise_error(NoMethodError)
44
+ end
45
+ end
46
+ end
47
+
48
+ context 'with a :frontend process injected' do
49
+ let(:processes) { [the_frontend] }
50
+
51
+ describe '#name' do
52
+ specify { expect(group.name).to eq(the_frontend.name) }
53
+ end
54
+
55
+ describe '#kill!' do
56
+ subject { group.kill! }
57
+
58
+ it 'runs shell command specified for frontend' do
59
+ expect(Kernel).to receive(:system).with(the_frontend_kill)
60
+ subject
61
+ end
62
+
63
+ it 'sleeps for specified time' do
64
+ expect(Kernel).to receive(:sleep).with(the_frontend.sleep_after_kill)
65
+ subject
66
+ end
67
+ end
68
+
69
+ describe '#start!' do
70
+ subject { group.start! }
71
+
72
+ it 'runs shell command specified for frontend' do
73
+ expect(Kernel).to receive(:system).with(the_frontend_start)
74
+ subject
75
+ end
76
+
77
+ it 'instructs process to log to logfile, prefixed with group name' do
78
+ expect(the_frontend).to receive(:log_file_prefix=).with(group.name)
79
+ subject
80
+ end
81
+
82
+ it 'sleeps for specified time' do
83
+ expect(Kernel).to receive(:sleep).with(the_frontend.sleep_after_start)
84
+ subject
85
+ end
86
+ end
87
+
88
+ context 'with a :worker process injected' do
89
+ let(:processes) { [the_frontend, the_worker] }
90
+
91
+ describe '#name' do
92
+ let(:expected_name) { [the_frontend.name, the_worker.name].join('_and_') }
93
+
94
+ specify { expect(group.name).to eq(expected_name) }
95
+ end
96
+
97
+ describe '#kill!' do
98
+ subject { group.kill! }
99
+
100
+ it 'runs shell command specified for worker' do
101
+ expect(Kernel).to receive(:system).with(the_worker_kill)
102
+ subject
103
+ end
104
+
105
+ it 'runs shell command specified for frontend' do
106
+ expect(Kernel).to receive(:system).with(the_frontend_kill)
107
+ subject
108
+ end
109
+ end
110
+
111
+ context 'and with the name overridden' do
112
+ describe '#name' do
113
+ let(:new_name) { 'override_name' }
114
+ before { group.name = new_name }
115
+
116
+ specify { expect(group.name).to eq(new_name) }
117
+ end
118
+ end
119
+ end # context 'with a :worker process injected' do
120
+ end # context 'with a :frontend process injected' do
121
+ end
122
+ end
@@ -0,0 +1,87 @@
1
+ require 'runnerbean'
2
+ require 'runnerbean/runner'
3
+
4
+ module Runnerbean
5
+ RSpec.describe Runner do
6
+ let(:runner) { described_class.new(init_options) }
7
+ let(:init_options) { { name: name } }
8
+ let(:name) { 'a_name' }
9
+ let(:the_frontend_kill) { 'kill_that_frontend' }
10
+ let(:the_frontend_start) { 'start_that_frontend' }
11
+ let(:the_frontend) do
12
+ double('the frontend',
13
+ kill_command: the_frontend_kill,
14
+ start_command: the_frontend_start,
15
+ sleep_after_start: 7,
16
+ sleep_after_kill: 2,
17
+ :'log_file_prefix=' => nil
18
+ )
19
+ end
20
+ let(:the_worker_kill) { 'kill_that_worker' }
21
+ let(:the_worker) do
22
+ double('the worker',
23
+ kill_command: the_worker_kill,
24
+ sleep_after_kill: 4,
25
+ :'log_file_prefix=' => nil
26
+ )
27
+ end
28
+ before { allow(Kernel).to receive(:system).with(anything) }
29
+ before { allow(Kernel).to receive(:sleep).with(anything) }
30
+
31
+ describe 'integration with process groups' do
32
+ context 'with a :frontend process injected' do
33
+ before { runner.add_process(frontend: the_frontend) }
34
+
35
+ describe '#kill!(:frontend)' do
36
+ subject { runner.kill!(:frontend) }
37
+
38
+ it 'runs shell command specified for frontend' do
39
+ expect(Kernel).to receive(:system).with(the_frontend_kill)
40
+ subject
41
+ end
42
+ end
43
+
44
+ describe '#start!(:frontend)' do
45
+ subject { runner.start!(:frontend) }
46
+
47
+ it 'runs shell command specified for frontend' do
48
+ expect(Kernel).to receive(:system).with(the_frontend_start)
49
+ subject
50
+ end
51
+ end
52
+
53
+ context 'with a :worker process injected' do
54
+ before { runner.add_process(worker: the_worker) }
55
+
56
+ describe '#kill!(:worker)' do
57
+ subject { runner.kill!(:worker) }
58
+
59
+ it 'runs shell command specified for worker' do
60
+ expect(Kernel).to receive(:system).with(the_worker_kill)
61
+ subject
62
+ end
63
+
64
+ it 'does not runs shell command specified for frontend' do
65
+ expect(Kernel).to_not receive(:system).with(the_frontend_kill)
66
+ subject
67
+ end
68
+ end
69
+
70
+ describe '#kill!(:worker, :frontend)' do
71
+ subject { runner.kill!(:worker, :frontend) }
72
+
73
+ it 'runs shell command specified for worker' do
74
+ expect(Kernel).to receive(:system).with(the_worker_kill)
75
+ subject
76
+ end
77
+
78
+ it 'runs shell command specified for frontend' do
79
+ expect(Kernel).to receive(:system).with(the_frontend_kill)
80
+ subject
81
+ end
82
+ end
83
+ end # context 'with a :worker process injected' do
84
+ end # context 'with a :frontend process injected' do
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,90 @@
1
+ require 'runnerbean'
2
+ require 'runnerbean/runner'
3
+
4
+ module Runnerbean
5
+ RSpec.describe Runner do
6
+ let(:runner) { described_class.new(init_options) }
7
+ let(:init_options) { { name: the_runner_name } }
8
+ let(:the_frontend) { double('the frontend') }
9
+ let(:the_worker) { double('the worker') }
10
+ let(:a_process_group) { double('a process group', :'name=' => nil) }
11
+
12
+ describe 'initalised with a name' do
13
+ let(:the_runner_name) { 'a_name' }
14
+
15
+ describe '#name' do
16
+ specify { expect(runner.name).to be(the_runner_name) }
17
+ end
18
+
19
+ context 'with a :frontend process injected' do
20
+ before { runner.add_process(frontend: the_frontend) }
21
+
22
+ context 'and with a :worker process injected' do
23
+ before { runner.add_process(worker: the_worker) }
24
+
25
+ describe '#group(:worker)' do
26
+ subject { runner.group(:worker) }
27
+
28
+ it 'returns process_group initialised with worker' do
29
+ expect(ProcessGroup).to receive(:new).with(the_worker).and_return(a_process_group)
30
+ expect(subject).to be(a_process_group)
31
+ end
32
+ end
33
+
34
+ describe '#group(:worker, :frontend)' do
35
+ subject { runner.group(:worker, :frontend) }
36
+
37
+ it 'returns process_group initialised with worker and frontend' do
38
+ expect(ProcessGroup).to receive(:new).with(the_worker, the_frontend).and_return(a_process_group)
39
+ expect(subject).to be(a_process_group)
40
+ end
41
+ end
42
+
43
+ describe '#start!(:frontend)' do
44
+ subject { runner.start!(:frontend) }
45
+ before do
46
+ allow(a_process_group).to receive(:start!)
47
+ allow(ProcessGroup).to receive(:new).with(the_frontend).and_return(a_process_group)
48
+ end
49
+
50
+ it 'returns process_group initialised with frontend' do
51
+ expect(ProcessGroup).to receive(:new).with(the_frontend).and_return(a_process_group)
52
+ expect(subject).to be(a_process_group)
53
+ end
54
+
55
+ it 'calls .start! on the process group' do
56
+ expect(a_process_group).to receive(:start!)
57
+ subject
58
+ end
59
+ end
60
+
61
+ describe '#kill!(:worker)' do
62
+ subject { runner.kill!(:worker) }
63
+ before do
64
+ allow(a_process_group).to receive(:kill!)
65
+ allow(ProcessGroup).to receive(:new).with(the_worker).and_return(a_process_group)
66
+ end
67
+
68
+ it 'returns process_group initialised with worker' do
69
+ expect(ProcessGroup).to receive(:new).with(the_worker).and_return(a_process_group)
70
+ expect(subject).to be(a_process_group)
71
+ end
72
+
73
+ it 'calls .kill! on the process group' do
74
+ expect(a_process_group).to receive(:kill!)
75
+ subject
76
+ end
77
+ end
78
+
79
+ describe '#start!(:backend)' do
80
+ subject { runner.start!(:backend) }
81
+
82
+ it 'raises not defined exception' do
83
+ expect { subject }.to raise_error(::Runnerbean::ProcessNotDefined)
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,10 @@
1
+ require 'runnerbean'
2
+ require 'runnerbean/runner'
3
+
4
+ RSpec.describe Runnerbean do
5
+ describe '.runner' do
6
+ subject { described_class.runner }
7
+
8
+ specify { expect(subject).to be_instance_of(Runnerbean::Runner) }
9
+ end
10
+ end
@@ -0,0 +1,98 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+
19
+ APP_ROOT = File.expand_path('..', __dir__)
20
+ $LOAD_PATH.unshift(File.join(APP_ROOT, 'lib'))
21
+
22
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
23
+ RSpec.configure do |config|
24
+ # rspec-expectations config goes here. You can use an alternate
25
+ # assertion/expectation library such as wrong or the stdlib/minitest
26
+ # assertions if you prefer.
27
+ config.expect_with :rspec do |expectations|
28
+ # This option will default to `true` in RSpec 4. It makes the `description`
29
+ # and `failure_message` of custom matchers include text for helper methods
30
+ # defined using `chain`, e.g.:
31
+ # be_bigger_than(2).and_smaller_than(4).description
32
+ # # => "be bigger than 2 and smaller than 4"
33
+ # ...rather than:
34
+ # # => "be bigger than 2"
35
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
36
+ end
37
+
38
+ # rspec-mocks config goes here. You can use an alternate test double
39
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
40
+ config.mock_with :rspec do |mocks|
41
+ # Prevents you from mocking or stubbing a method that does not exist on
42
+ # a real object. This is generally recommended, and will default to
43
+ # `true` in RSpec 4.
44
+ mocks.verify_partial_doubles = true
45
+ end
46
+
47
+ # The settings below are suggested to provide a good initial experience
48
+ # with RSpec, but feel free to customize to your heart's content.
49
+ # # These two settings work together to allow you to limit a spec run
50
+ # # to individual examples or groups you care about by tagging them with
51
+ # # `:focus` metadata. When nothing is tagged with `:focus`, all examples
52
+ # # get run.
53
+ # config.filter_run :focus
54
+ # config.run_all_when_everything_filtered = true
55
+ #
56
+ # # Allows RSpec to persist some state between runs in order to support
57
+ # # the `--only-failures` and `--next-failure` CLI options. We recommend
58
+ # # you configure your source control system to ignore this file.
59
+ # config.example_status_persistence_file_path = "spec/examples.txt"
60
+ #
61
+ # # Limits the available syntax to the non-monkey patched syntax that is
62
+ # # recommended. For more details, see:
63
+ # # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
64
+ # # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
65
+ # # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
66
+ config.disable_monkey_patching!
67
+ #
68
+ # # This setting enables warnings. It's recommended, but in some cases may
69
+ # # be too noisy due to issues in dependencies.
70
+ # config.warnings = true
71
+ #
72
+ # # Many RSpec users commonly either run the entire suite or an individual
73
+ # # file, and it's useful to allow more verbose output when running an
74
+ # # individual spec file.
75
+ if config.files_to_run.one?
76
+ # Use the documentation formatter for detailed output,
77
+ # unless a formatter has already been configured
78
+ # (e.g. via a command-line flag).
79
+ config.default_formatter = 'doc'
80
+ end
81
+ #
82
+ # # Print the 10 slowest examples and example groups at the
83
+ # # end of the spec run, to help surface which specs are running
84
+ # # particularly slow.
85
+ # config.profile_examples = 10
86
+ #
87
+ # # Run specs in random order to surface order dependencies. If you find an
88
+ # # order dependency and want to debug it, you can fix the order by providing
89
+ # # the seed, which is printed after each run.
90
+ # # --seed 1234
91
+ config.order = :random
92
+ #
93
+ # # Seed global randomization in this process using the `--seed` CLI option.
94
+ # # Setting this allows you to use `--seed` to deterministically reproduce
95
+ # # test failures related to randomization by passing the same `--seed` value
96
+ # # as the one that triggered the failure.
97
+ Kernel.srand config.seed
98
+ end
metadata ADDED
@@ -0,0 +1,210 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: runnerbean
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - baob
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard-rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: terminal-notifier-guard
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: guard-rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: guard-bundler
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: pry
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description:
154
+ email:
155
+ - coder@onesandthrees.com
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - ".gitignore"
161
+ - ".rspec"
162
+ - ".rubocop.yml"
163
+ - Gemfile
164
+ - Guardfile
165
+ - LICENSE.txt
166
+ - README.md
167
+ - Rakefile
168
+ - examples/front_and_back
169
+ - examples/process_groups
170
+ - examples/simple
171
+ - lib/runnerbean.rb
172
+ - lib/runnerbean/process_group.rb
173
+ - lib/runnerbean/runner.rb
174
+ - lib/runnerbean/version.rb
175
+ - runnerbean.gemspec
176
+ - spec/runnerbean/process_group_spec.rb
177
+ - spec/runnerbean/runner_integration_spec.rb
178
+ - spec/runnerbean/runner_spec.rb
179
+ - spec/runnerbean_spec.rb
180
+ - spec/spec_helper.rb
181
+ homepage: ''
182
+ licenses:
183
+ - MIT
184
+ metadata: {}
185
+ post_install_message:
186
+ rdoc_options: []
187
+ require_paths:
188
+ - lib
189
+ required_ruby_version: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - ">="
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
194
+ required_rubygems_version: !ruby/object:Gem::Requirement
195
+ requirements:
196
+ - - ">="
197
+ - !ruby/object:Gem::Version
198
+ version: '0'
199
+ requirements: []
200
+ rubyforge_project:
201
+ rubygems_version: 2.4.3
202
+ signing_key:
203
+ specification_version: 4
204
+ summary: Automates starting and stopping processes for testing.
205
+ test_files:
206
+ - spec/runnerbean/process_group_spec.rb
207
+ - spec/runnerbean/runner_integration_spec.rb
208
+ - spec/runnerbean/runner_spec.rb
209
+ - spec/runnerbean_spec.rb
210
+ - spec/spec_helper.rb