psychic-runner 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  module Psychic
2
2
  class Runner
3
- VERSION = '0.0.7'
3
+ VERSION = '0.0.8'
4
4
  end
5
5
  end
@@ -37,7 +37,9 @@ module Psychic
37
37
  @logger = opts.delete(:logger) || logger
38
38
  @shell = Mixlib::ShellOut.new(command, opts)
39
39
  @shell.live_stream = IOToLog.new(@logger)
40
- @shell.run_command
40
+ Bundler.with_clean_env do
41
+ @shell.run_command
42
+ end
41
43
  execution_result
42
44
  rescue SystemCallError, *MIXLIB_SHELLOUT_EXCEPTION_CLASSES, TypeError => e
43
45
  # See https://github.com/opscode/mixlib-shellout/issues/62
@@ -0,0 +1,14 @@
1
+ module Psychic
2
+ class Runner
3
+ class Task < Strict.new(:name, :command)
4
+ def command
5
+ fail NotImplementedError, 'Subclasses must implement command'
6
+ end
7
+
8
+ def execute(opts)
9
+ puts "Executing: #{command}" if opts[:verbose]
10
+ executor.execute(command, opts)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,90 @@
1
+ module Psychic
2
+ class Runner
3
+ module Factories
4
+ RSpec.describe BundlerTaskFactory do
5
+ let(:shell) { Psychic::Shell.shell = double('shell') }
6
+ subject { described_class.new(cwd: current_dir) }
7
+
8
+ shared_context 'without bundler' do
9
+ before(:each) do
10
+ ENV['BUNDLE_GEMFILE'] = nil
11
+ end
12
+ end
13
+
14
+ shared_context 'with Gemfile' do
15
+ before(:each) do
16
+ ENV['BUNDLE_GEMFILE'] = nil
17
+ write_file 'Gemfile', ''
18
+ end
19
+ end
20
+
21
+ shared_context 'with .bundle/config' do
22
+ before(:each) do
23
+ ENV['BUNDLE_GEMFILE'] = nil
24
+ write_file '.bundle/config', <<-eos
25
+ ---
26
+ BUNDLE_GEMFILE: "../../Gemfile"
27
+ eos
28
+ end
29
+ end
30
+
31
+ shared_context 'with BUNDLE_GEMFILE environment variable' do
32
+ around(:each) do | example |
33
+ ENV['BUNDLE_GEMFILE'] = 'Gemfile'
34
+ example.run
35
+ ENV['BUNDLE_GEMFILE'] = nil
36
+ end
37
+ end
38
+
39
+ shared_examples 'does not use bundler' do
40
+ describe 'active?' do
41
+ it 'returns false' do
42
+ expect(subject.active?).to be false
43
+ end
44
+ end
45
+ end
46
+
47
+ shared_examples 'uses bundler' do
48
+ describe 'known_task?' do
49
+ it 'is true for bootstrap' do
50
+ expect(subject.known_task? :bootstrap).to be true
51
+ end
52
+ it 'is false for compile' do
53
+ expect(subject.known_task? :compile).to be false
54
+ end
55
+ end
56
+
57
+ describe '#bootstrap' do
58
+ it 'returns bundle install' do
59
+ expect(subject.build_task(:bootstrap)).to eq('bundle install')
60
+ end
61
+ end
62
+ end
63
+
64
+ context 'with Gemfile' do
65
+ include_context 'with Gemfile' do
66
+ include_examples 'uses bundler'
67
+ end
68
+ end
69
+
70
+ context 'with .bundle/config' do
71
+ include_context 'with .bundle/config' do
72
+ include_examples 'uses bundler'
73
+ end
74
+ end
75
+
76
+ context 'with BUNDLE_GEMFILE environment variable' do
77
+ include_context 'with BUNDLE_GEMFILE environment variable' do
78
+ include_examples 'uses bundler'
79
+ end
80
+ end
81
+
82
+ context 'without bundler' do
83
+ include_context 'without bundler' do
84
+ include_examples 'does not use bundler'
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -1,7 +1,7 @@
1
1
  module Psychic
2
2
  class Runner
3
- module Cold
4
- RSpec.describe ShellScriptRunner do
3
+ module Factories
4
+ RSpec.describe ShellScriptTaskFactory do
5
5
  let(:shell) { Psychic::Shell.shell = double('shell') }
6
6
  subject { described_class.new(cwd: current_dir) }
7
7
 
@@ -21,15 +21,15 @@ module Psychic
21
21
  end
22
22
  end
23
23
 
24
- describe 'respond_to?' do
24
+ describe 'known_task?' do
25
25
  shared_examples 'detects matching scripts' do
26
26
  it 'returns true if a matching script exists' do
27
- expect(subject.respond_to? :bootstrap).to be true
28
- expect(subject.respond_to? :compile).to be true
27
+ expect(subject.known_task? :bootstrap).to be true
28
+ expect(subject.known_task? :compile).to be true
29
29
  end
30
30
  it 'returns false if a matching script does not exists' do
31
- expect(subject.respond_to? :foo).to be false
32
- expect(subject.respond_to? :bar).to be false
31
+ expect(subject.known_task? :foo).to be false
32
+ expect(subject.known_task? :bar).to be false
33
33
  end
34
34
  end
35
35
 
@@ -46,13 +46,13 @@ module Psychic
46
46
  end
47
47
  end
48
48
 
49
- describe '#method_missing' do
49
+ describe '#execute_task' do
50
50
  context 'matching a task' do
51
51
  context 'with scripts/*.sh files' do
52
52
  include_context 'with scripts/*.sh files' do
53
53
  it 'executes the script command' do
54
54
  expect(shell).to receive(:execute).with('./scripts/bootstrap.sh', cwd: current_dir)
55
- subject.bootstrap
55
+ subject.execute_task :bootstrap
56
56
  end
57
57
  end
58
58
  end
@@ -61,7 +61,7 @@ module Psychic
61
61
  include_context 'with scripts/* (no extension) files' do
62
62
  it 'executes the script command' do
63
63
  expect(shell).to receive(:execute).with('./scripts/bootstrap', cwd: current_dir)
64
- subject.bootstrap
64
+ subject.execute_task :bootstrap
65
65
  end
66
66
  end
67
67
  end
@@ -1,6 +1,6 @@
1
1
  module Psychic
2
2
  class Runner
3
- RSpec.describe HotRunner do
3
+ RSpec.describe HotReadTaskFactory do
4
4
  let(:task_map) do
5
5
  {
6
6
  'bootstrap' => 'foo',
@@ -12,23 +12,22 @@ module Psychic
12
12
  subject { described_class.new(cwd: current_dir, hints: task_map) }
13
13
 
14
14
  shared_examples 'runs tasks' do
15
- describe 'respond_to?' do
15
+ describe 'known_task?' do
16
16
  it 'returns true for task ids' do
17
17
  task_map.each_key do |key|
18
- expect(subject.respond_to? key).to be true
18
+ expect(subject.known_task? key).to be true
19
19
  end
20
20
  end
21
21
 
22
22
  it 'returns false for anything else' do
23
- expect(subject.respond_to? 'max').to be false
23
+ expect(subject.known_task? 'max').to be false
24
24
  end
25
25
  end
26
26
 
27
- describe '#method_missing' do
27
+ describe '#task_for' do
28
28
  context 'matching a task' do
29
- it 'executes the task command' do
30
- expect(shell).to receive(:execute).with('foo', cwd: current_dir)
31
- subject.bootstrap
29
+ it 'builds the task command' do
30
+ expect(subject.task_for(:bootstrap)).to eq('foo')
32
31
  end
33
32
  end
34
33
 
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ module Psychic
4
+ class Runner
5
+ RSpec.describe SampleFinder do
6
+ context 'without hints' do
7
+ describe '#known_samples' do
8
+ it 'returns an empty list' do
9
+ expect(subject.known_samples).to be_empty
10
+ end
11
+ end
12
+ end
13
+
14
+ context 'with hints' do
15
+ let(:hints) do
16
+ {
17
+ 'foo' => '/path/to/foo.c',
18
+ 'bar' => '/path/to/bar.rb'
19
+ }
20
+ end
21
+ subject { described_class.new(Dir.pwd, hints) }
22
+
23
+ it 'returns the samples from the hints' do
24
+ samples = subject.known_samples
25
+ expect(samples.size).to eq(2)
26
+ expect(samples[0].name).to eq('foo')
27
+ expect(samples[0].source_file).to eq('/path/to/foo.c')
28
+ expect(samples[1].name).to eq('bar')
29
+ expect(samples[1].source_file).to eq('/path/to/bar.rb')
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -20,8 +20,10 @@ module Psychic
20
20
  end
21
21
 
22
22
  describe 'initialize' do
23
- it 'should create a HotRunner for the specified directory' do
24
- expect(subject.hot_runner).to be_an_instance_of(Psychic::Runner::HotRunner)
23
+ it 'should create a HotReadTaskFactory for the specified directory' do
24
+ expect(subject.hot_read_task_factory).to(
25
+ be_an_instance_of Psychic::Runner::HotReadTaskFactory
26
+ )
25
27
  expect(subject.cwd).to eq(current_dir)
26
28
  end
27
29
  end
@@ -34,9 +36,9 @@ module Psychic
34
36
  end
35
37
 
36
38
  describe 'initialize' do
37
- it 'should create a cold runner for ShellScriptRunner' do
38
- expect(subject.cold_runners).to include(
39
- an_instance_of(Psychic::Runner::Cold::ShellScriptRunner)
39
+ it 'should create a ShellScriptTaskFactory' do
40
+ expect(subject.task_factories).to include(
41
+ an_instance_of(Psychic::Runner::Factories::ShellScriptTaskFactory)
40
42
  )
41
43
  end
42
44
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: psychic-runner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Lincoln
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-29 00:00:00.000000000 Z
11
+ date: 2015-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -189,22 +189,31 @@ files:
189
189
  - bin/psychic
190
190
  - lib/psychic/cli.rb
191
191
  - lib/psychic/logger.rb
192
+ - lib/psychic/output_helper.rb
192
193
  - lib/psychic/runner.rb
193
194
  - lib/psychic/runner/base_runner.rb
194
195
  - lib/psychic/runner/cli.rb
195
- - lib/psychic/runner/cold/shell_script_runner.rb
196
- - lib/psychic/runner/cold_runner_registry.rb
197
- - lib/psychic/runner/hot_runner.rb
196
+ - lib/psychic/runner/code_helper.rb
197
+ - lib/psychic/runner/code_sample.rb
198
+ - lib/psychic/runner/factories/ruby_factories.rb
199
+ - lib/psychic/runner/factories/shell_script_factories.rb
200
+ - lib/psychic/runner/hot_read_task_factory.rb
201
+ - lib/psychic/runner/magic_task_factory.rb
202
+ - lib/psychic/runner/sample_finder.rb
198
203
  - lib/psychic/runner/sample_runner.rb
204
+ - lib/psychic/runner/task_factory_registry.rb
199
205
  - lib/psychic/runner/version.rb
200
206
  - lib/psychic/shell.rb
201
207
  - lib/psychic/shell/execution_result.rb
202
208
  - lib/psychic/shell/mixlib_shellout_executor.rb
209
+ - lib/psychic/task.rb
203
210
  - lib/psychic/tokens.rb
204
211
  - lib/psychic/util.rb
205
212
  - psychic-runner.gemspec
206
- - spec/psychic/runner/cold/shell_script_runner_spec.rb
207
- - spec/psychic/runner/hot_runner_spec.rb
213
+ - spec/psychic/runner/factories/bundler_detector_spec.rb
214
+ - spec/psychic/runner/factories/shell_script_runner_spec.rb
215
+ - spec/psychic/runner/hot_read_task_factory_spec.rb
216
+ - spec/psychic/runner/sample_finder_spec.rb
208
217
  - spec/psychic/runner_spec.rb
209
218
  - spec/spec_helper.rb
210
219
  homepage:
@@ -232,7 +241,9 @@ signing_key:
232
241
  specification_version: 4
233
242
  summary: Psychic runs anything.
234
243
  test_files:
235
- - spec/psychic/runner/cold/shell_script_runner_spec.rb
236
- - spec/psychic/runner/hot_runner_spec.rb
244
+ - spec/psychic/runner/factories/bundler_detector_spec.rb
245
+ - spec/psychic/runner/factories/shell_script_runner_spec.rb
246
+ - spec/psychic/runner/hot_read_task_factory_spec.rb
247
+ - spec/psychic/runner/sample_finder_spec.rb
237
248
  - spec/psychic/runner_spec.rb
238
249
  - spec/spec_helper.rb
@@ -1,31 +0,0 @@
1
- module Psychic
2
- class Runner
3
- class ColdRunnerRegistry
4
- include Psychic::Logger
5
-
6
- BUILT_IN_DIR = File.expand_path('../cold', __FILE__)
7
-
8
- class << self
9
- def autoload_runners!
10
- # Load built-in runners
11
- Dir["#{BUILT_IN_DIR}/*.rb"].each do |cold_runner_file|
12
- require cold_runner_file
13
- end
14
- end
15
-
16
- def runner_classes
17
- @runner_classes ||= Set.new
18
- end
19
-
20
- def register(klass)
21
- runner_classes.add klass
22
- end
23
-
24
- def active_runners(opts)
25
- runners = runner_classes.map { |k| k.new(opts) }
26
- runners.select(&:active?)
27
- end
28
- end
29
- end
30
- end
31
- end