shell_mock 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 54058f03e95498441696ce9dff390125a2ccf449
4
- data.tar.gz: ed0f28fb6dd37453acc2a572dfe749a206902ec2
3
+ metadata.gz: b82fb0b1848c54881355c530fcf8fa4f22d292a4
4
+ data.tar.gz: cf94368b1e001a8f7ecc80a10ff1b0ff94655cc7
5
5
  SHA512:
6
- metadata.gz: 6b4b69fa6683b81bd1e883be39ef8208a470a6a9f6e6b5a7aa353205eb1209d01df259ec04ffb9cec271b16093d1a080f0934034ba58aa22012a54ca5510389d
7
- data.tar.gz: cf7cc2f513631057cc999494c085a47d718bdef8564ac902c78d488abb2f00d502e7530d243e4c0392269b3092f97329e29f3a28842c7cbe3b46009d719df88a
6
+ metadata.gz: e1e789a08c56339d8356d97d585bf405754582ad03a4c574f10873a05eb63951bd6ba867e725bb795a034cb096b19a6fd467d70cf9a760062462295c3dc1eb63
7
+ data.tar.gz: 07bc5c7aa946c4a34d932c61812d970da5cfb31cfea5bf35aca899b965011290a2e13a2fce010677354bf89cb51a2bc98241b2362ab4f70341af5aff2695140b
@@ -0,0 +1,11 @@
1
+ ## ROADMAP 1.0.0
2
+
3
+ * add `with_side_effect(&blk)` for specifying desired side effects
4
+
5
+ ## RELEASE 0.3.0
6
+
7
+ * FEATURE: you can now stub & mock `Kernel#exec`.
8
+
9
+ ## RELEASE 0.2.2
10
+
11
+ * FIX: fixed a test ordering bug
data/Rakefile CHANGED
@@ -1,5 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
+ require 'structured_changelog/tasks'
3
4
 
4
5
  RSpec::Core::RakeTask.new(:spec)
5
6
 
@@ -29,24 +29,34 @@ module ShellMock
29
29
 
30
30
  def self.enable
31
31
  Kernel.module_exec do
32
- if Kernel.respond_to?(:__shell_mocked_system)
33
- define_method(:__un_shell_mocked_system, &method(:system).to_proc)
34
- define_method(:system, &method(:__shell_mocked_system).to_proc)
35
- end
36
-
37
- if Kernel.respond_to?(:__shell_mocked_backtick)
38
- define_method(:__un_shell_mocked_backtick, &method(:`).to_proc)
39
- define_method(:`, &method(:__shell_mocked_backtick).to_proc)
32
+ ShellMock.alias_specifications.each do |spec|
33
+ if respond_to?(spec.replacement)
34
+ define_method(spec.alias_for_original, &method(spec.original).to_proc)
35
+ define_method(spec.original, &method(spec.replacement).to_proc)
36
+ end
40
37
  end
41
38
  end
42
39
  end
43
40
 
44
41
  def self.disable
45
42
  Kernel.module_exec do
46
- define_method(:system, &method(:__un_shell_mocked_system).to_proc) if Kernel.respond_to?(:__un_shell_mocked_system)
47
- define_method(:`, &method(:__un_shell_mocked_backtick).to_proc) if Kernel.respond_to?(:__un_shell_mocked_backtick)
43
+ ShellMock.alias_specifications.each do |spec|
44
+ if respond_to?(spec.alias_for_original)
45
+ define_method(spec.original, &method(spec.alias_for_original).to_proc)
46
+ end
47
+ end
48
48
  end
49
49
 
50
50
  StubRegistry.clear
51
51
  end
52
+
53
+ AliasSpecification = Struct.new(:original, :alias_for_original, :replacement)
54
+
55
+ def self.alias_specifications
56
+ [
57
+ AliasSpecification.new(:system, :__un_shell_mocked_system, :__shell_mocked_system),
58
+ AliasSpecification.new(:exec, :__un_shell_mocked_exec, :__shell_mocked_exec),
59
+ AliasSpecification.new(:`, :__un_shell_mocked_backtick, :__shell_mocked_backtick),
60
+ ]
61
+ end
52
62
  end
@@ -23,6 +23,32 @@ module Kernel
23
23
  end
24
24
  end
25
25
 
26
+ # This feels very boilerplatey because Kernel::system and Kernel::exec
27
+ # have very similar if not identical method signatures. I'm not sure
28
+ # whether extracting the commonalities would be worth it or just
29
+ # confuse.
30
+ def __shell_mocked_exec(env, command = nil, **options)
31
+ env, command = {}, env if command.nil?
32
+
33
+ # other arg manipulation
34
+
35
+ stub = ShellMock::StubRegistry.stub_matching(env, command, options)
36
+
37
+ if stub
38
+ stub.side_effect.call
39
+ `exit #{stub.exitstatus}`
40
+ stub.called_with(env, command, options)
41
+
42
+ return stub.exitstatus == 0
43
+ else
44
+ if ShellMock.let_commands_run?
45
+ __un_shell_mocked_exec(env, command, **options)
46
+ else
47
+ raise ShellMock::NoStubSpecified.new(env, command, options)
48
+ end
49
+ end
50
+ end
51
+
26
52
  def __shell_mocked_backtick(command)
27
53
  stub = ShellMock::StubRegistry.stub_matching({}, command, {})
28
54
 
@@ -1,3 +1,3 @@
1
1
  module ShellMock
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -24,4 +24,5 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "rspec", "~> 3.0"
25
25
  spec.add_development_dependency 'simplecov'
26
26
  spec.add_development_dependency 'pry-byebug'
27
+ spec.add_development_dependency "structured_changelog", "~> 0.8"
27
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shell_mock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Hoffman
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-28 00:00:00.000000000 Z
11
+ date: 2017-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: structured_changelog
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.8'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.8'
83
97
  description: WebMock for shell commands
84
98
  email:
85
99
  - yarmiganosca@gmail.com
@@ -91,6 +105,7 @@ files:
91
105
  - ".gitignore"
92
106
  - ".rspec"
93
107
  - ".travis.yml"
108
+ - CHANGELOG.md
94
109
  - CODE_OF_CONDUCT.md
95
110
  - Gemfile
96
111
  - LICENSE.txt
@@ -128,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
143
  version: '0'
129
144
  requirements: []
130
145
  rubyforge_project:
131
- rubygems_version: 2.5.1
146
+ rubygems_version: 2.6.3
132
147
  signing_key:
133
148
  specification_version: 4
134
149
  summary: WebMock for shell commands