cancun 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +4 -0
- data/README.md +3 -33
- data/cancun.gemspec +1 -0
- data/lib/cancun/executable.rb +2 -10
- data/lib/cancun/highline.rb +45 -42
- data/lib/cancun/version.rb +2 -2
- data/lib/cancun.rb +10 -1
- data/spec/dummy/foo.rb +1 -0
- data/spec/lib/executable_spec.rb +2 -2
- data/spec/lib/highline_spec.rb +4 -3
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6bee36fb1dea4254f77d5b2d55c45a027dee038
|
4
|
+
data.tar.gz: bc1abfc09c2576d0f3a14c93071b049922148903
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eca8db2c4367a4a5c1566d962beb4c3933f78a95f3a460043b68f74475d9ea47b112af7065520a5ba1273f39da92cf7c7d26687ec86424cfec5df80602bf47f9
|
7
|
+
data.tar.gz: ca8a3701aba1af16b053d724b421df95f5df26fbc2969ee4c5a50d7d2bd2cd19e4a88c8f7131ef5627006f1069c5b2c30207495a8233845f7898d61f894339f7
|
data/.rspec
ADDED
data/README.md
CHANGED
@@ -48,42 +48,12 @@ describe Foo do
|
|
48
48
|
|
49
49
|
describe '#hello' do
|
50
50
|
it 'says hello correctly' do
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
end
|
55
|
-
end
|
51
|
+
execute do
|
52
|
+
Foo.new.salute
|
53
|
+
end.and_type 'bonzo'
|
56
54
|
end
|
57
55
|
```
|
58
56
|
|
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
|
-
```
|
87
57
|
|
88
58
|
## Contributing
|
89
59
|
|
data/cancun.gemspec
CHANGED
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
+
spec.add_dependency "sourcify"
|
21
22
|
spec.add_development_dependency "bundler", "~> 1.3"
|
22
23
|
spec.add_development_dependency 'rspec'
|
23
24
|
spec.add_development_dependency 'highline'
|
data/lib/cancun/executable.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'open3'
|
2
|
-
|
2
|
+
class Cancun
|
3
3
|
module Executable
|
4
4
|
def init_cancun
|
5
5
|
@output_read, @output_write = IO.pipe
|
@@ -7,9 +7,7 @@ module Cancun
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def run(executable)
|
10
|
-
@
|
11
|
-
|
12
|
-
IO.popen(executable, out: @output_write, in: @input_read)
|
10
|
+
IO.popen(executable, out: @output_read, in: @input_write)
|
13
11
|
end
|
14
12
|
|
15
13
|
def type(*args)
|
@@ -17,12 +15,6 @@ module Cancun
|
|
17
15
|
sleep 0.01
|
18
16
|
end
|
19
17
|
|
20
|
-
# def type(*stream)
|
21
|
-
|
22
|
-
# @w.puts stream
|
23
|
-
# @w.flush
|
24
|
-
# end
|
25
|
-
|
26
18
|
def output
|
27
19
|
@output ||= ''
|
28
20
|
@output << @output_read.dup.read_nonblock(4096) rescue Errno::EAGAIN
|
data/lib/cancun/highline.rb
CHANGED
@@ -1,60 +1,63 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
attr_reader :exit_code
|
1
|
+
require 'timeout'
|
2
|
+
require 'sourcify'
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
class Cancun
|
5
|
+
module Highline
|
6
|
+
attr_reader :exit_code, :output_read
|
7
|
+
attr_accessor :input_write
|
9
8
|
|
10
|
-
|
11
|
-
!@no_timeout
|
12
|
-
end
|
13
|
-
end
|
14
|
-
def init_cancun_highline
|
9
|
+
def init_cancun_highline
|
15
10
|
@input_read, @input_write = IO.pipe
|
16
11
|
@output_read, @output_write = IO.pipe
|
17
|
-
@
|
12
|
+
@high_line = HighLine.new(@input_read, @output_write)
|
13
|
+
allow(HighLine).to receive(:new).and_return(@high_line)
|
14
|
+
end
|
18
15
|
|
19
|
-
|
20
|
-
|
21
|
-
HighLine.stub(:new).and_return(high_line)
|
16
|
+
def execute(&cmd)
|
17
|
+
TestCase.new(self).execute(&cmd)
|
22
18
|
end
|
23
19
|
|
24
|
-
def
|
25
|
-
|
26
|
-
sleep 0.01
|
20
|
+
def output
|
21
|
+
TestCase.new(self).output
|
27
22
|
end
|
28
23
|
|
29
|
-
def run
|
30
|
-
Thread.new do
|
31
|
-
Thread.abort_on_exception = true
|
32
|
-
begin
|
33
24
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
25
|
+
class TestCase
|
26
|
+
def initialize(model)
|
27
|
+
@model = model
|
28
|
+
end
|
38
29
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
30
|
+
def execute(&block)
|
31
|
+
@block = block
|
32
|
+
self
|
33
|
+
end
|
43
34
|
|
35
|
+
def output
|
36
|
+
@output ||= ''
|
37
|
+
@output << @model.output_read.dup.read_nonblock(4096) rescue Errno::EAGAIN
|
38
|
+
@output
|
44
39
|
end
|
45
|
-
end
|
46
40
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
@output << @output_read.dup.read_nonblock(4096) rescue Errno::EAGAIN
|
53
|
-
@output
|
54
|
-
end
|
41
|
+
def and_type(*args)
|
42
|
+
run
|
43
|
+
@model.input_write << [*args].flatten.join("\n") + "\n"
|
44
|
+
sleep 0.01
|
45
|
+
end
|
55
46
|
|
56
|
-
|
57
|
-
|
47
|
+
def run
|
48
|
+
Thread.new do
|
49
|
+
Thread.abort_on_exception = true
|
50
|
+
begin
|
51
|
+
if Cancun.timeout?
|
52
|
+
Timeout.timeout(0.3){ @exit_code = @block.call }
|
53
|
+
else
|
54
|
+
@exit_code = @block.call
|
55
|
+
end
|
56
|
+
rescue ::Timeout::Error
|
57
|
+
warn 'WARNING: cancun timeout, you can set Cancun::Highline.no_timeout!'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
58
61
|
end
|
59
62
|
end
|
60
63
|
end
|
data/lib/cancun/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "0.0.
|
1
|
+
class Cancun
|
2
|
+
VERSION = "0.0.5"
|
3
3
|
end
|
data/lib/cancun.rb
CHANGED
data/spec/dummy/foo.rb
CHANGED
data/spec/lib/executable_spec.rb
CHANGED
@@ -3,9 +3,9 @@ require 'spec_helper'
|
|
3
3
|
describe 'excutable spec' do
|
4
4
|
include Cancun::Executable
|
5
5
|
|
6
|
-
|
6
|
+
pending 'works for executables' do
|
7
7
|
init_cancun
|
8
|
-
|
8
|
+
type 'Bonzo'
|
9
9
|
run './spec/dummy/bin/foo'
|
10
10
|
output.should include('Hi Bonzo')
|
11
11
|
end
|
data/spec/lib/highline_spec.rb
CHANGED
@@ -8,9 +8,10 @@ describe 'highline spec' do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'works for highline' do
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
execute do
|
12
|
+
Foo.new.salute
|
13
|
+
end.and_type 'bonzo'
|
14
|
+
expect(output).to include('Hi bonzo')
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
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.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bonzofenix
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sourcify
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -89,6 +103,7 @@ extensions: []
|
|
89
103
|
extra_rdoc_files: []
|
90
104
|
files:
|
91
105
|
- .gitignore
|
106
|
+
- .rspec
|
92
107
|
- Gemfile
|
93
108
|
- LICENSE.txt
|
94
109
|
- README.md
|
@@ -123,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
138
|
version: '0'
|
124
139
|
requirements: []
|
125
140
|
rubyforge_project:
|
126
|
-
rubygems_version: 2.
|
141
|
+
rubygems_version: 2.0.3
|
127
142
|
signing_key:
|
128
143
|
specification_version: 4
|
129
144
|
summary: this gem should provide a simple DSL solution for unit and integration tests
|