fakecmd 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.md +36 -81
  2. data/lib/fakecmd.rb +8 -5
  3. data/lib/fakecmd/version.rb +1 -1
  4. metadata +86 -90
data/README.md CHANGED
@@ -1,90 +1,20 @@
1
1
  fakecmd
2
2
  =======
3
3
 
4
- * [Homepage](http://github.com/blom/fakecmd)
5
- * [Documentation](http://rdoc.info/github/blom/fakecmd)
4
+ [![Build Status](https://travis-ci.org/blom/fakecmd.png)](https://travis-ci.org/blom/fakecmd)
5
+ [![Gem Version](https://badge.fury.io/rb/fakecmd.png)](http://badge.fury.io/rb/fakecmd)
6
6
 
7
- Fakes system commands. Intended for use in tests. If your code relies heavily
8
- on system commands and verifies their exit status, you may not want to rely on
9
- the OS to be able to run your tests. That's the basic idea.
7
+ * [Homepage](https://github.com/blom/fakecmd)
8
+ * [Documentation](http://rubydoc.info/gems/fakecmd)
10
9
 
11
- Originally inspired by [FakeFS](http://github.com/defunkt/fakefs).
10
+ Fakes system commands. Intended for use in tests. If your code relies on system
11
+ commands and perhaps verifies their exit status, you may not want to rely on
12
+ the OS to be able to run your tests. Especially so if these commands have side
13
+ effects or take a long time to run. Originally inspired by
14
+ [FakeFS](https://github.com/defunkt/fakefs).
12
15
 
13
- Installation
14
- ------------
15
-
16
- gem install fakecmd
17
-
18
- Usage
19
- -----
20
-
21
- ### Require
22
-
23
- require "fakecmd"
24
-
25
- ### Add some commands
26
-
27
- FakeCmd.add "bar", 0, "pork"
28
- FakeCmd.add :foo, 1, "chop"
29
- FakeCmd.add /hat/, 2, "good"
30
-
31
- *Command*, *exit status*, and *output*.
32
-
33
- #### Everything is a regular expression internally
34
-
35
- "hi"
36
- :hi
37
- /hi/
38
-
39
- All equal.
40
-
41
- ### Enable
42
-
43
- Faking only happens between `on!` and `off!`, or in a block.
44
-
45
- #### `on!` and `off!`
46
-
47
- FakeCmd.on!
48
- # ...
49
- FakeCmd.off!
50
-
51
- #### Block
52
-
53
- FakeCmd do
54
- # ...
55
- end
56
-
57
- ### Run
58
-
59
- #### Using the examples above
60
-
61
- `bar mitzva` # => "pork"
62
- $?.exitstatus # => 0
63
-
64
- %x(fool) # => "chop"
65
- $?.exitstatus # => 1
66
-
67
- %x(nice hat) # => "good"
68
- $?.exitstatus # => 2
69
-
70
- #### No match
71
-
72
- `nope` # => false
73
- $?.exitstatus # => 127
74
-
75
- ### Which calls are faked
76
-
77
- ``
78
- %x
79
-
80
- For now.
81
-
82
- ### Clear the collection
83
-
84
- FakeCmd.clear!
85
-
86
- A simple example
87
- ----------------
16
+ Example
17
+ -------
88
18
 
89
19
  module Users
90
20
  def self.count
@@ -110,3 +40,28 @@ A simple example
110
40
  assert_equal 1, $?.exitstatus
111
41
  end
112
42
  end
43
+
44
+ * `FakeCmd.clear!` clears the current collection of faked commands, if any.
45
+
46
+ * `FakeCmd.add :users, 0, "a b c"` fakes the `users` command, defines its exit
47
+ status to be 0, and its output to be `a b c`. `:users` could have been a
48
+ string or regular expression as well; internally, everything is a regular
49
+ expression.
50
+
51
+ * `FakeCmd { Users.count }` calls `Users.count` in the faked environment. You
52
+ can also use `FakeCmd.on!` and `FakeCmd.off!` to turn it on and off,
53
+ respectively. No system command using the backtick or `%x` notation will be
54
+ executed in the block or between `.on!` and `.off!`. `system ""` will be
55
+ executed if the command is not found in the collection.
56
+
57
+ * `$?.exitstatus` reflects the exit status given to `.add`.
58
+
59
+ Keep in mind that only the following calls will be faked:
60
+
61
+ ``
62
+ %x
63
+
64
+ Installation
65
+ ------------
66
+
67
+ gem install fakecmd
data/lib/fakecmd.rb CHANGED
@@ -3,7 +3,6 @@ require File.expand_path("../fakecmd/version", __FILE__)
3
3
 
4
4
  module FakeCmd
5
5
  module_function
6
- @@enabled = false
7
6
 
8
7
  def add(cmd, status = 0, output = "", &block)
9
8
  cmd = cmd.to_s if cmd.is_a?(Symbol)
@@ -22,25 +21,29 @@ module FakeCmd
22
21
  @_commands ||= Set.new
23
22
  end
24
23
 
24
+ def on?
25
+ Kernel.private_methods.map(&:to_sym).include?(:fakecmd_backquote)
26
+ end
27
+
25
28
  def off!
26
- if @@enabled
29
+ if on?
27
30
  Kernel.class_eval do
28
31
  alias_method :`, :fakecmd_backquote
29
32
  remove_method :fakecmd_backquote
30
33
  end
31
- !@@enabled = false
34
+ true
32
35
  end
33
36
  end
34
37
 
35
38
  def on!
36
- unless @@enabled
39
+ unless on?
37
40
  Kernel.class_eval do
38
41
  alias_method :fakecmd_backquote, :`
39
42
  def `(cmd)
40
43
  FakeCmd.process_command(cmd)
41
44
  end
42
45
  end
43
- @@enabled = true
46
+ true
44
47
  end
45
48
  end
46
49
 
@@ -2,7 +2,7 @@ module FakeCmd
2
2
  module VERSION
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- PATCH = 2
5
+ PATCH = 3
6
6
 
7
7
  def self.to_s
8
8
  [MAJOR, MINOR, PATCH] * "."
metadata CHANGED
@@ -1,133 +1,129 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: fakecmd
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 2
9
- version: 0.0.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
12
- - "\xC3\x98rjan Blom"
7
+ authors:
8
+ - Ørjan Blom
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2010-11-06 00:00:00 +01:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- name: bluecloth
22
- requirement: &id001 !ruby/object:Gem::Requirement
12
+ date: 2013-04-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: kramdown
16
+ requirement: !ruby/object:Gem::Requirement
23
17
  none: false
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- segments:
28
- - 0
29
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
30
22
  type: :development
31
23
  prerelease: false
32
- version_requirements: *id001
33
- - !ruby/object:Gem::Dependency
34
- name: mg
35
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
36
33
  none: false
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- segments:
41
- - 0
42
- version: "0"
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
43
38
  type: :development
44
39
  prerelease: false
45
- version_requirements: *id002
46
- - !ruby/object:Gem::Dependency
47
- name: rcov
48
- requirement: &id003 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
49
41
  none: false
50
- requirements:
51
- - - ">="
52
- - !ruby/object:Gem::Version
53
- segments:
54
- - 0
55
- version: "0"
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '2'
56
54
  type: :development
57
55
  prerelease: false
58
- version_requirements: *id003
59
- - !ruby/object:Gem::Dependency
60
- name: rspec
61
- requirement: &id004 !ruby/object:Gem::Requirement
56
+ version_requirements: !ruby/object:Gem::Requirement
62
57
  none: false
63
- requirements:
58
+ requirements:
64
59
  - - ~>
65
- - !ruby/object:Gem::Version
66
- segments:
67
- - 2
68
- version: "2"
60
+ - !ruby/object:Gem::Version
61
+ version: '2'
62
+ - !ruby/object:Gem::Dependency
63
+ name: simplecov
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
69
70
  type: :development
70
71
  prerelease: false
71
- version_requirements: *id004
72
- - !ruby/object:Gem::Dependency
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
73
79
  name: yard
74
- requirement: &id005 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
75
81
  none: false
76
- requirements:
77
- - - ">="
78
- - !ruby/object:Gem::Version
79
- segments:
80
- - 0
81
- version: "0"
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
82
86
  type: :development
83
87
  prerelease: false
84
- version_requirements: *id005
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
85
94
  description: Fakes system commands. Intended for use in tests.
86
95
  email: blom@blom.tv
87
96
  executables: []
88
-
89
97
  extensions: []
90
-
91
98
  extra_rdoc_files: []
92
-
93
- files:
99
+ files:
94
100
  - LICENSE
95
101
  - README.md
96
102
  - lib/fakecmd/version.rb
97
103
  - lib/fakecmd.rb
98
- has_rdoc: true
99
- homepage: http://github.com/blom/fakecmd
104
+ homepage: https://github.com/blom/fakecmd
100
105
  licenses: []
101
-
102
106
  post_install_message:
103
107
  rdoc_options: []
104
-
105
- require_paths:
108
+ require_paths:
106
109
  - lib
107
- required_ruby_version: !ruby/object:Gem::Requirement
110
+ required_ruby_version: !ruby/object:Gem::Requirement
108
111
  none: false
109
- requirements:
110
- - - ">="
111
- - !ruby/object:Gem::Version
112
- hash: 2149922095191616200
113
- segments:
114
- - 0
115
- version: "0"
116
- required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ! '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  none: false
118
- requirements:
119
- - - ">="
120
- - !ruby/object:Gem::Version
121
- hash: 2149922095191616200
122
- segments:
123
- - 0
124
- version: "0"
118
+ requirements:
119
+ - - ! '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
125
122
  requirements: []
126
-
127
123
  rubyforge_project:
128
- rubygems_version: 1.3.7
124
+ rubygems_version: 1.8.25
129
125
  signing_key:
130
126
  specification_version: 3
131
127
  summary: Fakes system commands.
132
128
  test_files: []
133
-
129
+ has_rdoc: