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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f202d6de79548ad6a24fa224f63c1a59950c2424
4
- data.tar.gz: 8a776194a29eb70e0a52beac890ea53f4bef443f
3
+ metadata.gz: e6bee36fb1dea4254f77d5b2d55c45a027dee038
4
+ data.tar.gz: bc1abfc09c2576d0f3a14c93071b049922148903
5
5
  SHA512:
6
- metadata.gz: f816371cc3fe946d1f6d41af925910cfe9894c2ca99bad470439d2223eebc528b608b82aa327e3f7d224b74eac4ead7d375e76015a985ac6736fe0ee15ecfc47
7
- data.tar.gz: 6ac5fe40a256ba2d0f3e950d0d7311ed8c5af2198941126c59fae70c8cf2f613698a350cf47db153c46ae0460d4223f6b382470a9e791a763634b1eeb20a5cf7
6
+ metadata.gz: eca8db2c4367a4a5c1566d962beb4c3933f78a95f3a460043b68f74475d9ea47b112af7065520a5ba1273f39da92cf7c7d26687ec86424cfec5df80602bf47f9
7
+ data.tar.gz: ca8a3701aba1af16b053d724b421df95f5df26fbc2969ee4c5a50d7d2bd2cd19e4a88c8f7131ef5627006f1069c5b2c30207495a8233845f7898d61f894339f7
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --drb
3
+ --tag ~driver:selenium_chrome
4
+ --profile
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
- run described_class.new.salute do
52
- type 'bonzo'
53
- output.should be('Hi bonzo')
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'
@@ -1,5 +1,5 @@
1
1
  require 'open3'
2
- module Cancun
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
- @w = nil
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
@@ -1,60 +1,63 @@
1
- module Cancun
2
- module Highline
3
- attr_reader :exit_code
1
+ require 'timeout'
2
+ require 'sourcify'
4
3
 
5
- class << self
6
- def no_timeout!
7
- @no_timeout = true
8
- end
4
+ class Cancun
5
+ module Highline
6
+ attr_reader :exit_code, :output_read
7
+ attr_accessor :input_write
9
8
 
10
- def timeout?
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
- @exit_code = nil
12
+ @high_line = HighLine.new(@input_read, @output_write)
13
+ allow(HighLine).to receive(:new).and_return(@high_line)
14
+ end
18
15
 
19
- high_line = HighLine.new(@input_read, @output_write)
20
- # HighLine.track_eof = false
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 type(*args)
25
- @input_write << [*args].flatten.join("\n") + "\n"
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
- if Cancun::Highline.timeout?
35
- Timeout.timeout(0.3){ @exit_code = yield }
36
- else
37
- @exit_code = yield
25
+ class TestCase
26
+ def initialize(model)
27
+ @model = model
28
+ end
38
29
 
39
- end
40
- rescue Timeout::Error
41
- warn 'WARNING: cancun timeout, you can set Cancun::Highline.no_timeout!'
42
- end
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
- def run_sync
48
- run { yield }.join
49
- end
50
- def output
51
- @output ||= ''
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
- def last_line
57
- output.split("\n").last
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
@@ -1,3 +1,3 @@
1
- module Cancun
2
- VERSION = "0.0.4"
1
+ class Cancun
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/cancun.rb CHANGED
@@ -1,6 +1,15 @@
1
1
  require "cancun/version"
2
2
 
3
- module Cancun
3
+ class Cancun
4
+ class << self
5
+ def no_timeout!
6
+ @no_timeout = true
7
+ end
8
+
9
+ def timeout?
10
+ !@no_timeout
11
+ end
12
+ end
4
13
  end
5
14
 
6
15
  require 'cancun/executable'
data/spec/dummy/foo.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'highline'
2
2
 
3
3
  class Foo
4
+ :q
4
5
  def salute
5
6
  h = HighLine.new
6
7
  name = h.ask 'what is your name?'
@@ -3,9 +3,9 @@ require 'spec_helper'
3
3
  describe 'excutable spec' do
4
4
  include Cancun::Executable
5
5
 
6
- it 'works for highline' do
6
+ pending 'works for executables' do
7
7
  init_cancun
8
- type 'Bonzo'
8
+ type 'Bonzo'
9
9
  run './spec/dummy/bin/foo'
10
10
  output.should include('Hi Bonzo')
11
11
  end
@@ -8,9 +8,10 @@ describe 'highline spec' do
8
8
  end
9
9
 
10
10
  it 'works for highline' do
11
- type 'bonzo'
12
- run_sync {Foo.new.salute}
13
- output.should include('Hi Bonzo')
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
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: 2013-11-13 00:00:00.000000000 Z
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.1.5
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