cancun 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b3ca94770ee376416da95e6989144638bf8499ba
4
- data.tar.gz: 40a137a6f821e04360f338e09a4f925a5b39707b
3
+ metadata.gz: 84b8d158bc5a21247c93bd015f3980a69fbf44f4
4
+ data.tar.gz: 0e3f721f036794332d448d5eccbfae9c25ce1a15
5
5
  SHA512:
6
- metadata.gz: 05e648f03b08ae9e3ad45d50cdcc4ac6af9bfc408a48387f8124a2a30a6f73c435f4a00ee0e36050c7a9fd274b2f94bf9f1354c9ffc7e85a14ab4ddd982c75ba
7
- data.tar.gz: 2b88306b4747ca7da1285e3a6cbf21b8a47b63c8f61fd5ec18b743d50b7265e7358d1ceff25eb393e51dccdb158a3486326cfe5379ed369ac61b3f206cbed7a5
6
+ metadata.gz: 25183361d4ab917554abe86dc0d0d518cd437d48b287aac95990fbd4397039eb14518aea68cc48e99a2789d9d116f00faa88683731d51ea10660fbe0fbdbb96d
7
+ data.tar.gz: a35931bd69932e4465fb4a35135696c577fe289cd1ed5b4ee2a4330b0776b01c12b19f7fc23ae16e9edb9208e725586d8f3ea2b3e58c5c5517eb296a938ba43c
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Cancun
2
2
 
3
- TODO: Write a gem description
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
- TODO: Write usage instructions here
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
@@ -1,7 +1,7 @@
1
1
  require "cancun/version"
2
2
 
3
3
  module Cancun
4
- # Your code goes here...
5
4
  end
5
+
6
6
  require 'cancun/executable'
7
7
  require 'cancun/highline'
@@ -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
- IO.popen(executable, 'w') do |w|
7
- @w = w
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(*stream)
13
- @w.puts stream
14
- @w.flush
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
@@ -1,6 +1,17 @@
1
1
  module Cancun
2
2
  module Highline
3
- def init_highline_test
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
- rescue Timeout::Error => e
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
@@ -1,3 +1,3 @@
1
1
  module Cancun
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../foo'
4
+ Foo.new.salute
data/spec/dummy/foo.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'highline'
2
+
3
+ class Foo
4
+ def salute
5
+ h = HighLine.new
6
+ name = h.ask 'what is your name?'
7
+ h.say "Hi #{name}"
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'excutable spec' do
4
+ include Cancun::Executable
5
+
6
+ it 'works for highline' do
7
+ init_cancun
8
+ type 'Bonzo'
9
+ run './spec/dummy/bin/foo'
10
+ output.should include('Hi Bonzo')
11
+ end
12
+ end
13
+
@@ -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
+
@@ -0,0 +1,6 @@
1
+ require 'cancun'
2
+ require 'dummy/foo'
3
+ require 'debugger'
4
+
5
+ RSpec.configure do |config|
6
+ end
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.2
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-10-24 00:00:00.000000000 Z
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