fakecmd 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. data/LICENSE +13 -0
  2. data/README.md +7 -0
  3. data/lib/fakecmd/version.rb +11 -0
  4. data/lib/fakecmd.rb +63 -0
  5. metadata +139 -0
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2010 Ørjan Blom <blom@blom.tv>
2
+
3
+ Permission to use, copy, modify, and distribute this software for any
4
+ purpose with or without fee is hereby granted, provided that the above
5
+ copyright notice and this permission notice appear in all copies.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,7 @@
1
+ fakecmd
2
+ =======
3
+
4
+ Fakes system commands. Intended for use in tests. Inspired by
5
+ [FakeFS](http://github.com/defunkt/fakefs).
6
+
7
+ Undocumented and undone.
@@ -0,0 +1,11 @@
1
+ module FakeCmd
2
+ module VERSION
3
+ const_defined?(:MAJOR) || MAJOR = 0
4
+ const_defined?(:MINOR) || MINOR = 0
5
+ const_defined?(:PATCH) || PATCH = 1
6
+
7
+ def self.to_s
8
+ [MAJOR, MINOR, PATCH] * "."
9
+ end
10
+ end
11
+ end
data/lib/fakecmd.rb ADDED
@@ -0,0 +1,63 @@
1
+ require "set"
2
+ require File.expand_path("../fakecmd/version", __FILE__)
3
+
4
+ module FakeCmd
5
+ module_function
6
+ @@enabled = false
7
+
8
+ def on!
9
+ unless @@enabled
10
+ Kernel.class_eval do
11
+ alias_method :fakecmd_backquote, :`
12
+ def `(cmd)
13
+ FakeCmd.process_command(cmd)
14
+ end
15
+ end
16
+ @@enabled = true
17
+ end
18
+ end
19
+
20
+ def off!
21
+ if @@enabled
22
+ Kernel.class_eval do
23
+ alias_method :`, :fakecmd_backquote
24
+ remove_method :fakecmd_backquote
25
+ end
26
+ !@@enabled = false
27
+ end
28
+ end
29
+
30
+ def clear!
31
+ commands.clear
32
+ end
33
+
34
+ def commands
35
+ @_commands ||= Set.new
36
+ end
37
+
38
+ def process_command(cmd)
39
+ commands.each do |h|
40
+ if cmd[h[:regexp]]
41
+ fakecmd_backquote("(exit #{h[:status]})")
42
+ return h[:output]
43
+ end
44
+ end
45
+ system ""
46
+ end
47
+
48
+ def add(cmd, status = 0, output = "", &block)
49
+ cmd = cmd.to_s if cmd.is_a?(Symbol)
50
+ commands << {
51
+ :regexp => Regexp.new(cmd),
52
+ :output => block ? block.call : output,
53
+ :status => status
54
+ }
55
+ end
56
+ end
57
+
58
+ def FakeCmd
59
+ FakeCmd.on!
60
+ yield
61
+ ensure
62
+ FakeCmd.off!
63
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fakecmd
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - "\xC3\x98rjan Blom"
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-09-27 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ version_requirements: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ hash: 3
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ requirement: *id001
32
+ type: :development
33
+ name: bluecloth
34
+ prerelease: false
35
+ - !ruby/object:Gem::Dependency
36
+ version_requirements: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ hash: 3
42
+ segments:
43
+ - 0
44
+ version: "0"
45
+ requirement: *id002
46
+ type: :development
47
+ name: mg
48
+ prerelease: false
49
+ - !ruby/object:Gem::Dependency
50
+ version_requirements: &id003 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ hash: 3
56
+ segments:
57
+ - 0
58
+ version: "0"
59
+ requirement: *id003
60
+ type: :development
61
+ name: rcov
62
+ prerelease: false
63
+ - !ruby/object:Gem::Dependency
64
+ version_requirements: &id004 !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ hash: 3
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ requirement: *id004
74
+ type: :development
75
+ name: rspec
76
+ prerelease: false
77
+ - !ruby/object:Gem::Dependency
78
+ version_requirements: &id005 !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ hash: 3
84
+ segments:
85
+ - 0
86
+ version: "0"
87
+ requirement: *id005
88
+ type: :development
89
+ name: yard
90
+ prerelease: false
91
+ description: Fakes system commands. Intended for use in tests.
92
+ email: blom@blom.tv
93
+ executables: []
94
+
95
+ extensions: []
96
+
97
+ extra_rdoc_files: []
98
+
99
+ files:
100
+ - LICENSE
101
+ - README.md
102
+ - lib/fakecmd/version.rb
103
+ - lib/fakecmd.rb
104
+ has_rdoc: true
105
+ homepage: http://github.com/blom/fakecmd
106
+ licenses: []
107
+
108
+ post_install_message:
109
+ rdoc_options: []
110
+
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ hash: 3
119
+ segments:
120
+ - 0
121
+ version: "0"
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ hash: 3
128
+ segments:
129
+ - 0
130
+ version: "0"
131
+ requirements: []
132
+
133
+ rubyforge_project:
134
+ rubygems_version: 1.3.7
135
+ signing_key:
136
+ specification_version: 3
137
+ summary: Fakes system commands.
138
+ test_files: []
139
+