rspec-shell-expectations 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.ruby-version +1 -0
- data/.travis.yml +6 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +70 -0
- data/Rakefile +11 -0
- data/bin/stub +1 -0
- data/lib/rspec/shell/expectations.rb +2 -0
- data/lib/rspec/shell/expectations/stubbed_env.rb +35 -0
- data/lib/rspec/shell/expectations/version.rb +8 -0
- data/rspec-shell-expectations.gemspec +26 -0
- data/spec/fixtures/simple_script.sh +1 -0
- data/spec/replace_shell_commands_spec.rb +33 -0
- metadata +91 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 127a017e7189b42bb60796d4f67541565be8a18f
|
4
|
+
data.tar.gz: 46b7ccd1ed98f6be39cdc15f4a9bf966d13ead8b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d9e2a19a358068276dd5d873ec897330d6f1475d96896348277cee4154c3419c6138badd467b282d507c24bad2b2cf873978664150350b0097bc599bdb4389ae
|
7
|
+
data.tar.gz: b1fa23150c66df71f1d2aaa6b05253eb0deddfffc5203046cff84dc39b4a661d736af1cbd7167e3ad12a38949ebf3728ade0731ea6a22fc38d5d20111494c664
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.2
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Matthijs Groen
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# Rspec::Shell::Expectations
|
2
|
+
[![Build Status](https://travis-ci.org/matthijsgroen/rspec-shell-expectations.png?branch=master)](https://travis-ci.org/matthijsgroen/rspec-shell-expectations)
|
3
|
+
|
4
|
+
Run your shell script in a mocked environment to test its behaviour
|
5
|
+
using RSpec.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'rspec-shell-expectations'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install rspec-shell-expectations
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
see specs in `spec/` folder:
|
26
|
+
|
27
|
+
### Running script through stubbed env:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
require 'English'
|
31
|
+
|
32
|
+
describe 'my shell script' do
|
33
|
+
include Rspec::Shell::Expectations
|
34
|
+
|
35
|
+
let(:stubbed_env) { create_stubbed_env }
|
36
|
+
|
37
|
+
it 'runs the script' do
|
38
|
+
stubbed_env.execute 'my-shell-script.sh'
|
39
|
+
expect($CHILD_STATUS.exitstatus).to eq 0
|
40
|
+
end
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
44
|
+
### Stubbing commands:
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
require 'English'
|
48
|
+
|
49
|
+
describe 'my shell script' do
|
50
|
+
include Rspec::Shell::Expectations
|
51
|
+
|
52
|
+
let(:stubbed_env) { create_stubbed_env }
|
53
|
+
before do
|
54
|
+
stubbed_env.stub_command('rake')
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'runs the script' do
|
58
|
+
stubbed_env.execute 'my-shell-script.sh'
|
59
|
+
expect($CHILD_STATUS.exitstatus).to eq 0
|
60
|
+
end
|
61
|
+
end
|
62
|
+
```
|
63
|
+
|
64
|
+
## Contributing
|
65
|
+
|
66
|
+
1. Fork it ( https://github.com/matthijsgroen/rspec-shell-expectations/fork )
|
67
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
68
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
69
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
70
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/stub
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'tmpdir'
|
2
|
+
|
3
|
+
module Rspec
|
4
|
+
module Shell
|
5
|
+
# Define stubbed environment to set and assert expectations
|
6
|
+
module Expectations
|
7
|
+
def create_stubbed_env
|
8
|
+
StubbedEnv.new
|
9
|
+
end
|
10
|
+
|
11
|
+
# A shell environment that can manipulate behaviour
|
12
|
+
# of executables
|
13
|
+
class StubbedEnv
|
14
|
+
def initialize
|
15
|
+
@dir = Dir.mktmpdir
|
16
|
+
at_exit { FileUtils.remove_entry_secure @dir }
|
17
|
+
end
|
18
|
+
|
19
|
+
def stub_command(command)
|
20
|
+
FileUtils.cp('bin/stub', File.join(@dir, command))
|
21
|
+
end
|
22
|
+
|
23
|
+
def execute(command)
|
24
|
+
`#{stub_path} #{command}`
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def stub_path
|
30
|
+
"PATH=#{@dir}:$PATH"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rspec/shell/expectations/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'rspec-shell-expectations'
|
8
|
+
spec.version = Rspec::Shell::Expectations::VERSION
|
9
|
+
spec.authors = ['Matthijs Groen']
|
10
|
+
spec.email = ['matthijs.groen@gmail.com']
|
11
|
+
spec.summary = 'Fake execution environments to TDD shell scripts'
|
12
|
+
spec.description = <<-DESCRIPTION
|
13
|
+
Stub results of commands.
|
14
|
+
Assert calls and input using RSpec for your shell scripts
|
15
|
+
DESCRIPTION
|
16
|
+
spec.homepage = ''
|
17
|
+
spec.license = 'MIT'
|
18
|
+
|
19
|
+
spec.files = `git ls-files -z`.split("\x0")
|
20
|
+
spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
|
21
|
+
spec.test_files = spec.files.grep(/^(test|spec|features)\//)
|
22
|
+
spec.require_paths = ['lib']
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler', '>= 1.6'
|
25
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
26
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
command1
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'English'
|
2
|
+
require 'rspec/shell/expectations'
|
3
|
+
|
4
|
+
describe 'Replace shell commands' do
|
5
|
+
include Rspec::Shell::Expectations
|
6
|
+
|
7
|
+
describe 'running a file with non-existing commands' do
|
8
|
+
it 'exits with an error' do
|
9
|
+
`spec/fixtures/simple_script.sh 2>&1`
|
10
|
+
expect($CHILD_STATUS.exitstatus).not_to eq 0
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'with stubbed environment' do
|
14
|
+
let(:stubbed_env) { create_stubbed_env }
|
15
|
+
|
16
|
+
it 'exits with an error' do
|
17
|
+
stubbed_env.execute 'spec/fixtures/simple_script.sh 2>&1'
|
18
|
+
expect($CHILD_STATUS.exitstatus).not_to eq 0
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'with a stubbed command' do
|
22
|
+
before do
|
23
|
+
stubbed_env.stub_command('command1')
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'exits with status code 0' do
|
27
|
+
stubbed_env.execute 'spec/fixtures/simple_script.sh 2>&1'
|
28
|
+
expect($CHILD_STATUS.exitstatus).to eq 0
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec-shell-expectations
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthijs Groen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: |2
|
42
|
+
Stub results of commands.
|
43
|
+
Assert calls and input using RSpec for your shell scripts
|
44
|
+
email:
|
45
|
+
- matthijs.groen@gmail.com
|
46
|
+
executables:
|
47
|
+
- stub
|
48
|
+
extensions: []
|
49
|
+
extra_rdoc_files: []
|
50
|
+
files:
|
51
|
+
- ".gitignore"
|
52
|
+
- ".ruby-version"
|
53
|
+
- ".travis.yml"
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE.txt
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- bin/stub
|
59
|
+
- lib/rspec/shell/expectations.rb
|
60
|
+
- lib/rspec/shell/expectations/stubbed_env.rb
|
61
|
+
- lib/rspec/shell/expectations/version.rb
|
62
|
+
- rspec-shell-expectations.gemspec
|
63
|
+
- spec/fixtures/simple_script.sh
|
64
|
+
- spec/replace_shell_commands_spec.rb
|
65
|
+
homepage: ''
|
66
|
+
licenses:
|
67
|
+
- MIT
|
68
|
+
metadata: {}
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 2.2.2
|
86
|
+
signing_key:
|
87
|
+
specification_version: 4
|
88
|
+
summary: Fake execution environments to TDD shell scripts
|
89
|
+
test_files:
|
90
|
+
- spec/fixtures/simple_script.sh
|
91
|
+
- spec/replace_shell_commands_spec.rb
|