cancun 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +67 -2
- data/cancun.gemspec +3 -0
- data/lib/cancun.rb +1 -1
- data/lib/cancun/executable.rb +22 -7
- data/lib/cancun/highline.rb +20 -3
- data/lib/cancun/version.rb +1 -1
- data/spec/dummy/bin/foo +4 -0
- data/spec/dummy/foo.rb +9 -0
- data/spec/lib/executable_spec.rb +13 -0
- data/spec/lib/highline_spec.rb +16 -0
- data/spec/spec_helper.rb +6 -0
- metadata +55 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84b8d158bc5a21247c93bd015f3980a69fbf44f4
|
4
|
+
data.tar.gz: 0e3f721f036794332d448d5eccbfae9c25ce1a15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25183361d4ab917554abe86dc0d0d518cd437d48b287aac95990fbd4397039eb14518aea68cc48e99a2789d9d116f00faa88683731d51ea10660fbe0fbdbb96d
|
7
|
+
data.tar.gz: a35931bd69932e4465fb4a35135696c577fe289cd1ed5b4ee2a4330b0776b01c12b19f7fc23ae16e9edb9208e725586d8f3ea2b3e58c5c5517eb296a938ba43c
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Cancun
|
2
2
|
|
3
|
-
|
3
|
+
DSL for testing command line applications in ruby
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -18,7 +18,72 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
Require cancun on your spec_helper.rb when using *Rspec*:
|
22
|
+
```ruby
|
23
|
+
require 'cancun'
|
24
|
+
```
|
25
|
+
|
26
|
+
|
27
|
+
### Testing highline with Rspec:
|
28
|
+
|
29
|
+
For testing this ruby class:
|
30
|
+
```ruby
|
31
|
+
class Foo
|
32
|
+
def salute
|
33
|
+
h = HighLine.new
|
34
|
+
h.ask 'what is your name?'
|
35
|
+
h.say "Hi #{name}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
```
|
40
|
+
cancun would work the following way:
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
require 'spec_helper'
|
44
|
+
|
45
|
+
describe Foo do
|
46
|
+
include Cancun::Highline
|
47
|
+
before { init_highline_test }
|
48
|
+
|
49
|
+
describe '#hello' do
|
50
|
+
it 'says hello correctly' do
|
51
|
+
run described_class.new.salute do
|
52
|
+
type 'bonzo'
|
53
|
+
output.should be('Hi bonzo')
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
```
|
58
|
+
|
59
|
+
###testing executable with Rspec:
|
60
|
+
|
61
|
+
For testing this ./executable:
|
62
|
+
|
63
|
+
```bash
|
64
|
+
#!/usr/bin/env ruby
|
65
|
+
|
66
|
+
puts 'who are you?'
|
67
|
+
name = gets
|
68
|
+
puts "Hi #{name}"
|
69
|
+
```
|
70
|
+
|
71
|
+
You would use this code:
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
require 'spec_helper'
|
75
|
+
|
76
|
+
describe 'executable' do
|
77
|
+
include Cancun::Executable
|
78
|
+
|
79
|
+
it 'test executable' do
|
80
|
+
run './executable' do
|
81
|
+
type 'bonzo'
|
82
|
+
output.should be('Hi bonzo')
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
```
|
22
87
|
|
23
88
|
## Contributing
|
24
89
|
|
data/cancun.gemspec
CHANGED
@@ -19,5 +19,8 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency 'rspec'
|
23
|
+
spec.add_development_dependency 'highline'
|
24
|
+
spec.add_development_dependency 'debugger'
|
22
25
|
spec.add_development_dependency "rake"
|
23
26
|
end
|
data/lib/cancun.rb
CHANGED
data/lib/cancun/executable.rb
CHANGED
@@ -1,17 +1,32 @@
|
|
1
1
|
require 'open3'
|
2
2
|
module Cancun
|
3
3
|
module Executable
|
4
|
+
def init_cancun
|
5
|
+
@output_read, @output_write = IO.pipe
|
6
|
+
@input_read, @input_write = IO.pipe
|
7
|
+
end
|
8
|
+
|
4
9
|
def run(executable)
|
5
10
|
@w = nil
|
6
|
-
|
7
|
-
|
8
|
-
yield if block_given?
|
9
|
-
end
|
11
|
+
|
12
|
+
IO.popen(executable, out: @output_write, in: @input_read)
|
10
13
|
end
|
11
14
|
|
12
|
-
def type(*
|
13
|
-
@
|
14
|
-
|
15
|
+
def type(*args)
|
16
|
+
@input_write << [*args].flatten.join("\n") + "\n"
|
17
|
+
sleep 0.01
|
18
|
+
end
|
19
|
+
|
20
|
+
# def type(*stream)
|
21
|
+
|
22
|
+
# @w.puts stream
|
23
|
+
# @w.flush
|
24
|
+
# end
|
25
|
+
|
26
|
+
def output
|
27
|
+
@output ||= ''
|
28
|
+
@output << @output_read.dup.read_nonblock(4096) rescue Errno::EAGAIN
|
29
|
+
@output
|
15
30
|
end
|
16
31
|
end
|
17
32
|
end
|
data/lib/cancun/highline.rb
CHANGED
@@ -1,6 +1,17 @@
|
|
1
1
|
module Cancun
|
2
2
|
module Highline
|
3
|
-
|
3
|
+
attr_reader :exit_code
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def no_timeout!
|
7
|
+
@no_timeout = true
|
8
|
+
end
|
9
|
+
|
10
|
+
def timeout?
|
11
|
+
!!@no_timeout
|
12
|
+
end
|
13
|
+
end
|
14
|
+
def init_cancun_highline
|
4
15
|
@input_read, @input_write = IO.pipe
|
5
16
|
@output_read, @output_write = IO.pipe
|
6
17
|
@exit_code = nil
|
@@ -19,17 +30,23 @@ module Cancun
|
|
19
30
|
Thread.new do
|
20
31
|
Thread.abort_on_exception = true
|
21
32
|
begin
|
33
|
+
|
34
|
+
if Cancun::Highline.timeout?
|
22
35
|
Timeout.timeout(0.3){ @exit_code = yield }
|
23
|
-
|
36
|
+
else
|
37
|
+
@exit_code = yield
|
24
38
|
|
25
39
|
end
|
40
|
+
rescue Timeout::Error
|
41
|
+
warn 'WARNING: cancun timeout, you can set Cancun::Highline.no_timeout!'
|
42
|
+
end
|
43
|
+
|
26
44
|
end
|
27
45
|
end
|
28
46
|
|
29
47
|
def run_sync
|
30
48
|
run { yield }.join
|
31
49
|
end
|
32
|
-
attr_reader :exit_code
|
33
50
|
def output
|
34
51
|
@output ||= ''
|
35
52
|
@output << @output_read.dup.read_nonblock(4096) rescue Errno::EAGAIN
|
data/lib/cancun/version.rb
CHANGED
data/spec/dummy/bin/foo
ADDED
data/spec/dummy/foo.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'highline spec' do
|
4
|
+
include Cancun::Highline
|
5
|
+
|
6
|
+
before do
|
7
|
+
init_cancun_highline
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'works for highline' do
|
11
|
+
type 'bonzo'
|
12
|
+
run_sync {Foo.new.salute}
|
13
|
+
output.should include('Hi Bonzo')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cancun
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bonzofenix
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -24,6 +24,48 @@ dependencies:
|
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: highline
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
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: debugger
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
27
69
|
- !ruby/object:Gem::Dependency
|
28
70
|
name: rake
|
29
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -56,6 +98,11 @@ files:
|
|
56
98
|
- lib/cancun/executable.rb
|
57
99
|
- lib/cancun/highline.rb
|
58
100
|
- lib/cancun/version.rb
|
101
|
+
- spec/dummy/bin/foo
|
102
|
+
- spec/dummy/foo.rb
|
103
|
+
- spec/lib/executable_spec.rb
|
104
|
+
- spec/lib/highline_spec.rb
|
105
|
+
- spec/spec_helper.rb
|
59
106
|
homepage: https://github.com/bonzofenix/cancun
|
60
107
|
licenses:
|
61
108
|
- MIT
|
@@ -81,4 +128,9 @@ signing_key:
|
|
81
128
|
specification_version: 4
|
82
129
|
summary: this gem should provide a simple DSL solution for unit and integration tests
|
83
130
|
of Command Line apps
|
84
|
-
test_files:
|
131
|
+
test_files:
|
132
|
+
- spec/dummy/bin/foo
|
133
|
+
- spec/dummy/foo.rb
|
134
|
+
- spec/lib/executable_spec.rb
|
135
|
+
- spec/lib/highline_spec.rb
|
136
|
+
- spec/spec_helper.rb
|