stub_shell 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,10 @@
1
1
  # StubShell [![Build Status](https://secure.travis-ci.org/stackbuilders/stub_shell.png)](http://travis-ci.org/stackbuilders/stub_shell)
2
2
 
3
+ StubShell helps you to test your libraries that interact with the system through the Kernel backquote and system methods.
4
+ It does this by providing a DSL to describe the messages that you expect the shell to receive in the order that you expect
5
+ to receive them. StubShell can be used to stub simple interactions, or ones that cause the system that you're working with
6
+ to change state.
7
+
3
8
  ## Installation
4
9
 
5
10
  gem install stub_shell
@@ -14,14 +19,72 @@
14
19
 
15
20
  ## Usage
16
21
 
22
+ StubShell can handle simple cases where you want to stub a system call in Ruby or more complex interactions
23
+ where commands may change the state and return values of subsequent commands.
24
+
25
+ ### Simple Usage
26
+
27
+ You use StubShell simply by describing the commands that you want stubbed out, along with the value that they
28
+ should return in STDOUT and STDERR, as well as their exit status.
29
+
17
30
  it ... do
18
31
  stub_shell do
19
32
  command "ls /tmp/foobar" do
20
33
  stdout "hey there"
34
+ stderr "some error"
35
+ exitstatus 2
36
+ end
37
+ end
38
+ end
39
+
40
+ By default, StubShell assumes that STDOUT and STDERR are nil, and that the exit status is 0 (success), so you
41
+ can leave these options out if you want.
42
+
43
+ ### Stubbing Complex Shell Interactions
44
+
45
+ You can stub more complex interactions with the shell, including cases where commands that you execute will
46
+ change the output of subsequent commands.
47
+
48
+ stub_shell do
49
+ command 'ls /tmp/foobar' do
50
+ stdout 'yes, foobar exists'
51
+ end
52
+
53
+ command "rm /tmp/foobar" do
54
+ stub_shell do
55
+ command 'ls /tmp/foobar' do
56
+ stderr 'the file no longer exists'
57
+ exitstatus 2
58
+ end
21
59
  end
22
60
  end
23
61
  end
24
62
 
63
+ StubShell starts looking for defined commands at the current level of the execution hierarchy, so if you
64
+ invoke the command to remove /tmp/foobar above, it will always look at the stub_shell context nested below
65
+ that command for matches to subsequent commands. If no matching commands are found at that level, StubShell
66
+ searches recursively upwards in the tree for matches until it either finds one or it runs out of options and
67
+ raises an error indicating that no matches were found.
68
+
69
+ ### Regular Expression Matching of Commands
70
+
71
+ You can use regular expressions to match commands in StubShell.
72
+
73
+ stub_shell do
74
+ command /ls \/tmp.*foo/' do
75
+ stdout 'yes, your directory exists'
76
+ end
77
+ end
78
+
79
+ ### Additional Documentation
80
+
81
+ We suggest that you read the acceptance tests included with this library to help understand the
82
+ way that it works.
83
+
84
+ ## Authors
85
+
86
+ Justin Leitgeb (@jsl) and @itsmeduncan.
87
+
25
88
  ## Contribute
26
89
 
27
90
  1. [Fork](http://help.github.com/forking/) stub_shell
@@ -1,3 +1,3 @@
1
1
  module StubShell
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stub_shell
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-02-04 00:00:00.000000000 Z
13
+ date: 2012-02-05 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
17
- requirement: &70197553821800 !ruby/object:Gem::Requirement
17
+ requirement: &70219775244760 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 0.9.2.2
23
23
  type: :development
24
24
  prerelease: false
25
- version_requirements: *70197553821800
25
+ version_requirements: *70219775244760
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rspec
28
- requirement: &70197553821080 !ruby/object:Gem::Requirement
28
+ requirement: &70219775244020 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 2.8.0
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *70197553821080
36
+ version_requirements: *70219775244020
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: simplecov
39
- requirement: &70197553820460 !ruby/object:Gem::Requirement
39
+ requirement: &70219775243460 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,7 +44,7 @@ dependencies:
44
44
  version: 0.5.4
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *70197553820460
47
+ version_requirements: *70219775243460
48
48
  description: Stubs a set of shell commands and their return values using the backquote
49
49
  operator.
50
50
  email: