fake_execution 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Readme.markdown ADDED
@@ -0,0 +1,80 @@
1
+ Fake Execution
2
+ ======
3
+
4
+ [![Build Status](https://secure.travis-ci.org/josephwilk/fake-execution.png)](http://travis-ci.org/josephwilk/fake-execution)
5
+
6
+
7
+ Execution, but... like... fake.
8
+
9
+ Usage
10
+ -----
11
+
12
+ Using fake-execution safe which does not automatically activate FakeExecution, you have to do that manually:
13
+
14
+ require 'fake_execution/safe'
15
+
16
+ FakeExecution.activate!
17
+
18
+ `echo *` # This is not executed
19
+
20
+ `git checkout git://github.com/josephwilk/fake-execution.git`
21
+ `touch monkeys`
22
+ system("git add monkeys")
23
+ system('git commit -m "needs more monkeys"')
24
+ `git push`
25
+
26
+ FakeExecution.deactivate!
27
+
28
+ cmds[0].should =~ /echo/
29
+ cmds[1].should =~ /git checkout/
30
+ cmds[2].should == 'touch monkeys'
31
+
32
+ `echo *` # outputs: echo *
33
+
34
+
35
+ Using Rspec:
36
+
37
+ require 'fake_execution/spec_helper'
38
+
39
+ describe "monkeys" do
40
+ include FakeExecution::SpecHelpers
41
+
42
+ it "should touch the monkey" do
43
+ `touch monkey`
44
+
45
+ cmds[0].should == 'touch monkey'
46
+ end
47
+ end
48
+
49
+ Using Unsafe mode:
50
+
51
+ require 'fake_execution'
52
+
53
+ `touch monkey`
54
+ puts cmds[0] # outputs: touch monkey
55
+
56
+ License
57
+ -------
58
+
59
+ (The MIT License)
60
+
61
+ Copyright (c) 2011 Joseph Wilk
62
+
63
+ Permission is hereby granted, free of charge, to any person obtaining
64
+ a copy of this software and associated documentation files (the
65
+ 'Software'), to deal in the Software without restriction, including
66
+ without limitation the rights to use, copy, modify, merge, publish,
67
+ distribute, sublicense, and/or sell copies of the Software, and to
68
+ permit persons to whom the Software is furnished to do so, subject to
69
+ the following conditions:
70
+
71
+ The above copyright notice and this permission notice shall be
72
+ included in all copies or substantial portions of the Software.
73
+
74
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
75
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
76
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
77
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
78
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
79
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
80
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,3 @@
1
+ require 'fake_execution/safe'
2
+
3
+ FakeExecution.activate!
@@ -0,0 +1,38 @@
1
+ module FakeExecution
2
+ def self.activate!
3
+ Kernel.class_eval do
4
+ alias_method :real_system, :system
5
+ alias_method :system, :fake_system
6
+
7
+ alias_method :real_exec, :exec
8
+ alias_method :exec, :fake_exec
9
+
10
+ alias_method :real_backtick, :`
11
+ alias_method :`, :fake_backtick
12
+ end
13
+ true
14
+ end
15
+
16
+ def self.deactivate!
17
+ Kernel.class_eval do
18
+ alias_method :fake_backtick, :`
19
+ alias_method :`, :real_backtick
20
+
21
+ alias_method :fake_system, :system
22
+ alias_method :system, :real_system
23
+
24
+ alias_method :fake_exec, :exec
25
+ alias_method :exec, :real_exec
26
+ end
27
+ true
28
+ end
29
+ end
30
+
31
+ def FakeExecution
32
+ return ::FakeExecution unless block_given?
33
+ ::FakeExecution.activate!
34
+ yield
35
+ ensure
36
+ ::FakeExecution.deactivate!
37
+ end
38
+
@@ -0,0 +1,20 @@
1
+ Kernel.class_eval do
2
+ attr_reader :cmds
3
+
4
+ def fake_backtick(cmd)
5
+ @cmds ||= []
6
+ @cmds << cmd
7
+ ""
8
+ end
9
+
10
+ def fake_exec(cmd)
11
+ @cmds ||= []
12
+ @cmds << cmd
13
+ end
14
+
15
+ def fake_system(cmd)
16
+ @cmds ||= []
17
+ @cmds << cmd
18
+ true
19
+ end
20
+ end
@@ -0,0 +1,2 @@
1
+ require 'fake_execution/base'
2
+ require 'fake_execution/kernel'
@@ -0,0 +1,23 @@
1
+ require 'fake_execution/safe'
2
+
3
+ module FakeExecution
4
+ module SpecHelpers
5
+ def self.extended(example_group)
6
+ example_group.use_fake_execution(example_group)
7
+ end
8
+
9
+ def self.included(example_group)
10
+ example_group.extend self
11
+ end
12
+
13
+ def use_fake_execution(describe_block)
14
+ describe_block.before :each do
15
+ FakeExecution.activate!
16
+ end
17
+
18
+ describe_block.after :each do
19
+ FakeExecution.deactivate!
20
+ end
21
+ end
22
+ end
23
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fake_execution
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - Joseph Wilk
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-12-09 00:00:00 +00:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :development
34
+ version_requirements: *id001
35
+ description: "Fake out execution in Ruby and instead of running them log them. Allows inspection of the commands that where executed. "
36
+ email:
37
+ - joe@josephwilk.net
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files: []
43
+
44
+ files:
45
+ - lib/fake_execution.rb
46
+ - lib/fake_execution/kernel.rb
47
+ - lib/fake_execution/safe.rb
48
+ - lib/fake_execution/base.rb
49
+ - lib/fake_execution/spec_helpers.rb
50
+ - Readme.markdown
51
+ has_rdoc: true
52
+ homepage: http://github.com/josephwilk/fake_execution
53
+ licenses: []
54
+
55
+ post_install_message:
56
+ rdoc_options: []
57
+
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ hash: 3
66
+ segments:
67
+ - 0
68
+ version: "0"
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ hash: 3
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ requirements: []
79
+
80
+ rubyforge_project:
81
+ rubygems_version: 1.3.7
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: Fake out execution in Ruby to make testing easier
85
+ test_files: []
86
+