rspec-launchbox 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 +15 -0
- data/.rspec +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +80 -0
- data/Rakefile +2 -0
- data/lib/rspec/launchbox.rb +7 -0
- data/lib/rspec/launchbox/describe_executable.rb +71 -0
- data/lib/rspec/launchbox/in_presence_of.rb +36 -0
- data/lib/rspec/launchbox/timeout_matchers.rb +39 -0
- data/lib/rspec/launchbox/version.rb +5 -0
- data/rspec-launchbox.gemspec +26 -0
- data/spec/describe_executable_spec.rb +14 -0
- data/spec/in-presence-of_spec.rb +8 -0
- data/spec/spec_helper.rb +14 -0
- data/spec/timeouts_spec.rb +38 -0
- metadata +121 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5c00ce31529ca3732c0fc6e5b930185fac4be632
|
4
|
+
data.tar.gz: ea7c107c0a5688911f48e2feaaa1ce1ea50eb984
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d4e73a5fbf734687c39a20ead035f863526c561237a60d612fea8a9f3db37da1a80fc856bb79dd1800bd7f0b4a691b17988a1752d0252d910a6125b5e05b6b58
|
7
|
+
data.tar.gz: 701a8acfd4ff108e2cdfee8d86061a1f71a22652b3598804ed8b46aacd0413701bfecfcca5e70c5c1dcd0afcd7a951524f5f7649b487ab946415ad42c949ef7a
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 d-theus
|
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,80 @@
|
|
1
|
+
# Rspec::Launchbox
|
2
|
+
|
3
|
+
Bundle of RSpec DSL helpers, providing
|
4
|
+
timeout matchers, service runners. Work in progress.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'rspec-launchbox'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install rspec-launchbox
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
### in_presence_of
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
#spec/spec_helper.rb
|
28
|
+
|
29
|
+
require 'rspec/launchbox'
|
30
|
+
|
31
|
+
RSpec.configure do |config|
|
32
|
+
#...
|
33
|
+
config.extend RSpec::InPresenceOf
|
34
|
+
config.include RSpec::Matchers::Timeout
|
35
|
+
end
|
36
|
+
include RSpec::DescribeExecutable
|
37
|
+
```
|
38
|
+
|
39
|
+
Then in spec file:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
describe MyClass do
|
43
|
+
in_presence_of 'external_program' do
|
44
|
+
it 'should listen on port' do
|
45
|
+
#here goes expectation
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
```
|
50
|
+
|
51
|
+
### describe_executable
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
describe_executable 'ls' do
|
55
|
+
its_stdout do
|
56
|
+
it { is_expected.to be_a String }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
```
|
60
|
+
|
61
|
+
### expect { }.to persist
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
expect do
|
65
|
+
#routine
|
66
|
+
end.to persist.at_least(3) # or 3.seconds if you use ActiveSupport
|
67
|
+
```
|
68
|
+
|
69
|
+
This snippet runs binary called external_program (should be in path, or pass absolute path),
|
70
|
+
and makes sure process started by that command is dead.
|
71
|
+
|
72
|
+
_TODO:_ One day there will be optional parameters e.g. signal to send to process.
|
73
|
+
|
74
|
+
## Contributing
|
75
|
+
|
76
|
+
1. Fork it ( https://github.com/[my-github-username]/rspec-launchbox/fork )
|
77
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
78
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
79
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
80
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
module RSpec
|
2
|
+
module DescribeExecutable
|
3
|
+
# Outmost describe block.
|
4
|
+
# @param [String] cmd executable name
|
5
|
+
# @yields block like ordinary #describe
|
6
|
+
# @example
|
7
|
+
# describe_executable 'ls' do
|
8
|
+
# its_stdout do
|
9
|
+
# it { is_expected.to be_a String }
|
10
|
+
# end
|
11
|
+
# end
|
12
|
+
def describe_executable(cmd, &block)
|
13
|
+
$_command_line = cmd
|
14
|
+
$_process_stdout = ''
|
15
|
+
RSpec.describe "#{$_command_line} executable" do
|
16
|
+
before(:each) do
|
17
|
+
Thread.abort_on_exception = true
|
18
|
+
Thread.new do
|
19
|
+
IO.popen($_command_line) do |io|
|
20
|
+
$_process_stdout << io.read(256) until io.eof?
|
21
|
+
end
|
22
|
+
end
|
23
|
+
sleep 1
|
24
|
+
end
|
25
|
+
|
26
|
+
after(:each) do
|
27
|
+
`killall -INT #{$_command_line.split(/\W/)[0]} &>/dev/null`
|
28
|
+
sleep 0.1
|
29
|
+
`killall -KILL #{$_command_line.split(/\W/)[0]} &>/dev/null`
|
30
|
+
end
|
31
|
+
|
32
|
+
class_eval &block
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Opens new 'describe',
|
37
|
+
# sets it's subject to process stdout
|
38
|
+
# @yields block like ordinary describe
|
39
|
+
# @see #describe_executable for an example
|
40
|
+
def its_stdout(&block)
|
41
|
+
describe "it's stdout" do
|
42
|
+
subject { $_process_stdout }
|
43
|
+
|
44
|
+
class_eval &block
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# Opens new 'context',
|
49
|
+
# where options are appended to
|
50
|
+
# command line before execution.
|
51
|
+
# @param [String] flag e.g. `-f`
|
52
|
+
# @param [String] parameter
|
53
|
+
# @example
|
54
|
+
# describe_executable 'ls' do
|
55
|
+
# given_option '-a' do
|
56
|
+
# its_stdout do
|
57
|
+
# #you need rspec-its gem for `its`
|
58
|
+
# its(:lines) { is_expected.to include ".\n" }
|
59
|
+
# end
|
60
|
+
# end
|
61
|
+
# end
|
62
|
+
def given_option(flag, parameter = nil, &block)
|
63
|
+
context "given option #{flag}#{parameter ? parameter + ' ' : nil}" do
|
64
|
+
$_command_line__old = $_command_line.dup
|
65
|
+
$_command_line << ' ' << [flag, parameter].join(' ')
|
66
|
+
|
67
|
+
class_eval &block
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module RSpec
|
2
|
+
module InPresenceOf
|
3
|
+
def self.extended(*args)
|
4
|
+
# Launches particular service
|
5
|
+
# and makes sure it's dead afterwards.
|
6
|
+
# @param [String] service
|
7
|
+
# @yields block as `describe` does
|
8
|
+
# @example
|
9
|
+
# describe MyClass do
|
10
|
+
# in_presence_of 'some_service' do
|
11
|
+
# # `some_service` executable is running
|
12
|
+
# it 'can establish connection' do
|
13
|
+
# #assert connecton presence
|
14
|
+
# end
|
15
|
+
# # and now it's being killed
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
def in_presence_of(service, &block)
|
19
|
+
before do
|
20
|
+
@_service_pid = fork do
|
21
|
+
$stdout.reopen '/dev/null'
|
22
|
+
$stderr.reopen '/dev/null'
|
23
|
+
exec service
|
24
|
+
end
|
25
|
+
fail "Failed to execute #{service}" unless @_service_pid
|
26
|
+
end
|
27
|
+
|
28
|
+
after do
|
29
|
+
Process.kill(:INT, @_service_pid) if @_service_pid
|
30
|
+
end
|
31
|
+
|
32
|
+
context("in presence of #{service} service", &block)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Matchers
|
3
|
+
# #persist matcher defined here
|
4
|
+
# @example
|
5
|
+
# expect do
|
6
|
+
# #routine
|
7
|
+
# end.to persist.at_least(3) # or 3.seconds if you use ActiveSupport
|
8
|
+
module Timeout
|
9
|
+
def self.included(*args)
|
10
|
+
RSpec::Matchers.define :persist do
|
11
|
+
supports_block_expectations
|
12
|
+
@should_complete_block = nil
|
13
|
+
|
14
|
+
chain :at_least do |time|
|
15
|
+
@time = time
|
16
|
+
@should_complete_block = false
|
17
|
+
end
|
18
|
+
|
19
|
+
chain :at_most do |time|
|
20
|
+
@time = time
|
21
|
+
@should_complete_block = true
|
22
|
+
end
|
23
|
+
|
24
|
+
match do |actual|
|
25
|
+
fail "Block expected, got #{actual.class}" unless actual.respond_to? :call
|
26
|
+
fail "Expected 'persist.at_least(<seconds>)' or 'persist.at_most(<seconds>)'" if @should_complete_block.nil?
|
27
|
+
begin
|
28
|
+
::Timeout.timeout(@time, &actual)
|
29
|
+
@block_complete = true
|
30
|
+
rescue ::Timeout::Error
|
31
|
+
@block_complete = false
|
32
|
+
end
|
33
|
+
@block_complete == @should_complete_block
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
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/launchbox/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rspec-launchbox"
|
8
|
+
spec.version = Rspec::Launchbox::VERSION
|
9
|
+
spec.authors = ["d-theus"]
|
10
|
+
spec.email = ["slma0x02@gmail.com"]
|
11
|
+
spec.summary = %q{RSpec DSL extension for effortless process control}
|
12
|
+
spec.description = %q{Launchbox makes it easy to start or stop external service, manage timeouts.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
|
24
|
+
spec.add_dependency 'rspec'
|
25
|
+
spec.add_dependency 'rspec-its'
|
26
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
describe_executable 'ls' do
|
2
|
+
its_stdout do
|
3
|
+
it { is_expected.to be_a String }
|
4
|
+
it { is_expected.not_to be_empty }
|
5
|
+
end
|
6
|
+
|
7
|
+
given_option '-a' do
|
8
|
+
its_stdout do
|
9
|
+
it { is_expected.to be_a String }
|
10
|
+
its(:lines) { is_expected.to include ".\n" }
|
11
|
+
its(:lines) { is_expected.not_to include "ohwowwhatisit\n" }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rspec/launchbox'
|
2
|
+
|
3
|
+
RSpec.configure do |config|
|
4
|
+
config.expect_with :rspec do |expectations|
|
5
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
6
|
+
end
|
7
|
+
config.mock_with :rspec do |mocks|
|
8
|
+
mocks.verify_partial_doubles = true
|
9
|
+
end
|
10
|
+
config.extend RSpec::InPresenceOf
|
11
|
+
config.include RSpec::Matchers::Timeout
|
12
|
+
end
|
13
|
+
|
14
|
+
include RSpec::DescribeExecutable
|
@@ -0,0 +1,38 @@
|
|
1
|
+
describe '#persist' do
|
2
|
+
context 'with jush value passed' do
|
3
|
+
it 'raises exceptions' do
|
4
|
+
expect(5).to persist 5
|
5
|
+
end
|
6
|
+
end
|
7
|
+
context 'with block passed' do
|
8
|
+
context 'with no boundary' do
|
9
|
+
it 'd' do
|
10
|
+
expect do
|
11
|
+
'string'
|
12
|
+
end.to persist
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'with boudary' do
|
17
|
+
it 'succeeds' do
|
18
|
+
expect do
|
19
|
+
'string'
|
20
|
+
end.to persist.at_most 1
|
21
|
+
|
22
|
+
expect do
|
23
|
+
'string'
|
24
|
+
sleep 2
|
25
|
+
end.to persist.at_least 1
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'with block which raises exception' do
|
31
|
+
it 'rethrows' do
|
32
|
+
expect do
|
33
|
+
'string'
|
34
|
+
fail 'Exception in subject block'
|
35
|
+
end.to persist
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec-launchbox
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- d-theus
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-06 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.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
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
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec-its
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Launchbox makes it easy to start or stop external service, manage timeouts.
|
70
|
+
email:
|
71
|
+
- slma0x02@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- .rspec
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- lib/rspec/launchbox.rb
|
83
|
+
- lib/rspec/launchbox/describe_executable.rb
|
84
|
+
- lib/rspec/launchbox/in_presence_of.rb
|
85
|
+
- lib/rspec/launchbox/timeout_matchers.rb
|
86
|
+
- lib/rspec/launchbox/version.rb
|
87
|
+
- rspec-launchbox.gemspec
|
88
|
+
- spec/describe_executable_spec.rb
|
89
|
+
- spec/in-presence-of_spec.rb
|
90
|
+
- spec/spec_helper.rb
|
91
|
+
- spec/timeouts_spec.rb
|
92
|
+
homepage: ''
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.0.14
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: RSpec DSL extension for effortless process control
|
116
|
+
test_files:
|
117
|
+
- spec/describe_executable_spec.rb
|
118
|
+
- spec/in-presence-of_spec.rb
|
119
|
+
- spec/spec_helper.rb
|
120
|
+
- spec/timeouts_spec.rb
|
121
|
+
has_rdoc:
|