outputhandler 0.1.3beta → 0.2.0.1

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
  SHA256:
3
- metadata.gz: fa2c1260ae74bb1f296417d69cd039fa429029d8a1d5058002045bb68133e4d6
4
- data.tar.gz: 75fe96764a08dd4b11be692cbf161953c0975fc775b18dcaba0f3895e55ebeb7
3
+ metadata.gz: 36c29394cfd2a794e2a3e6ace2f46f91fcd96937355c8eba5d59c8704354d54c
4
+ data.tar.gz: 27239e7d2a98fcad01469f13b8d06a036641b7933c9f39ba50b254d2c4aa6f26
5
5
  SHA512:
6
- metadata.gz: 31978d557201555266b1ee15c48d01664c3c04db51bd521fc61a7a69c51e917bfd82aa2e30a772a0047f44bf7d2882b8b01578db472829a27ce7ed325983561f
7
- data.tar.gz: 9b8708f025c23602dcb99f8a5caf7027cc62801b04cbe5a7f42bb277f95914ac0edea0a78884a9ed066915d4dee618d2169a4f9a31b1b282e075452723ddef94
6
+ metadata.gz: 14b0d507ce50c0dbd4de4b33be6ff4f522eb33ef9c2bc2b60bf665f53762f6f7ae0a0eeeac04ed61a603bd0aa0c2987862d44e3d48c503b8178112b8d10f7ed6
7
+ data.tar.gz: 7057997fa97cd1d2aeae1af997bb7bfdac9db0cc18a9eba85c409a0f4892740ccdd1b0e2c357e0b3dfb37de7bec82fae1220933533758d601c727cefba784a84
data/CHANGELOG.md ADDED
@@ -0,0 +1,17 @@
1
+ ## 0.2.0.1 (November 07, 2021)
2
+ - minor fix
3
+
4
+ ## 0.2.0 (November 07, 2021)
5
+ - minor fix
6
+
7
+ ## 0.1.0 (November 07, 2021)
8
+ - adopting positional arguments
9
+ - fixes in README.md
10
+ - added #print(\!), #puts(\!) as more convenient way of use; added #inspect; updated README; version set to BETA
11
+ - Small fix in README.md
12
+ - Added HISTORY, added Rakefile, added YARD documentation
13
+ - Added basic gemspec
14
+ - Initial commit for the outputhandler. Included Cukes and RSpec
15
+ - Create README.md
16
+ - Initial commit
17
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.0.1
data/cucumber.yml ADDED
@@ -0,0 +1,17 @@
1
+ <%
2
+ cucumber_pro_opts = ENV['ENABLE_CUCUMBER_PRO'] ? "--format Cucumber::Pro --out /dev/null" : ""
3
+ std_opts = "--format pretty features -r features --strict #{cucumber_pro_opts}".dup
4
+ std_opts << " --color"
5
+ std_opts << " --tags 'not @wip'"
6
+ std_opts << " --tags 'not @wip-jruby'" if defined?(JRUBY_VERSION)
7
+ wip_opts = "--color -r features".dup
8
+ wip_opts << " --tags @wip" if !defined?(JRUBY_VERSION)
9
+ wip_opts << " --tags '@wip or @wip-jruby'" if defined?(JRUBY_VERSION)
10
+ %>
11
+ default: <%= std_opts %> --tags "not @jruby"
12
+ jruby: <%= std_opts %> --tags "not @wire"
13
+ jruby_win: <%= std_opts %> --tags "not @wire" CUCUMBER_FORWARD_SLASH_PATHS=true
14
+ windows_mri: <%= std_opts %> --tags "not @jruby" --tags "not @wire" --tags "not @needs-many-fonts" --tags "not @todo-windows" CUCUMBER_FORWARD_SLASH_PATHS=true
15
+ wip: --wip <%= wip_opts %> features <%= cucumber_pro_opts %>
16
+ none: --format pretty --format Cucumber::Pro --out /dev/null
17
+ autotest: <%= std_opts %>
data/lib/outputhandler.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'date'
1
2
  #The main class of this gem
2
3
  class OutputHandler
3
4
 
@@ -12,16 +13,26 @@ class OutputHandler
12
13
  # @option opts [Boolean] :console If set to true (default), the handler will output to STDOUT.
13
14
  # @option opts [String] :logfile If set to a target and the target is valid, the handler will output to logfile.
14
15
  #
15
- def initialize(opts = {}, *args, &block)
16
- raise TypeError unless opts.is_a? Hash
17
- @outputQueue = Queue.new
18
- @console = opts[:console].nil? ? true : opts[:console]
19
- @logfile = opts[:logfile].nil? ? nil : opts[:logfile]
20
- @file = @logfile.nil? ? false : true
21
- @paused = false
16
+ def initialize(
17
+ console: true,
18
+ location: nil,
19
+ logfile: -> { "#{Date.today.strftime('%Y-%m-%d')}.log" },
20
+ carriage: false,
21
+ debug: false,
22
+ &block)
23
+
24
+ @debug = debug
25
+ @file = location.nil? ? false : true
26
+ @console = console
27
+ @location = location
28
+ @logfile = logfile.lambda? ? logfile : (-> { "#{logfile}" } )
29
+ @paused = false
30
+ @defaultCR = carriage
22
31
  @outputMonitor = Monitor.new
23
- system("touch #{@logfile}") unless @logfile.nil?
24
- self.spawn_output
32
+ @outputQueue = Queue.new
33
+ @block = block.to_proc if block_given?
34
+ system("mkdir -p #{location}") unless location.nil? or File.exist?(location)
35
+ spawn_output
25
36
  end
26
37
 
27
38
  # Convenience method, accepts a second parameter to force carriage return
@@ -29,23 +40,23 @@ class OutputHandler
29
40
  #
30
41
  # @param chunk [printable Object]
31
42
  # @param cr [Boolean] for carriage return
32
- def puts(chunk = "", cr = false)
33
- self.out(chunk, true, cr)
43
+ def puts(chunk = "", cr: @defaultCR)
44
+ self.out(chunk: chunk, newline: true, cr: cr)
34
45
  end
35
46
 
36
47
  # (see #puts)
37
- def puts!(chunk = "", cr = false)
38
- self.out!(chunk, true, cr)
48
+ def puts!(chunk = "", cr: @defaultCR)
49
+ self.out!(chunk: chunk, newline: true, cr: cr)
39
50
  end
40
51
 
41
52
  # (see #puts)
42
- def print(chunk = "", cr = false)
43
- self.out(chunk, false, cr)
53
+ def print(chunk = "", cr: @defaultCR)
54
+ self.out(chunk: chunk, newline: false, cr: cr)
44
55
  end
45
56
 
46
57
  # (see #puts)
47
- def print!(chunk = "", cr = false)
48
- self.out!(chunk, false, cr)
58
+ def print!(chunk = "", cr: @defaultCR)
59
+ self.out!(chunk: chunk, newline: false, cr: cr)
49
60
  end
50
61
 
51
62
  # Returns whether output currently is paused.
@@ -55,8 +66,7 @@ class OutputHandler
55
66
  @paused
56
67
  end
57
68
 
58
- # Pauses the output. If parameter is sent, output will autoresume after delay. Overrides currently
59
- # set delay.
69
+ # Pauses the output. If parameter is sent, output will automatically resume after delay.
60
70
  #
61
71
  # @param limit [Numeric] Time to pause.
62
72
  def pause(limit = 0)
@@ -78,38 +88,59 @@ class OutputHandler
78
88
  @paused = false
79
89
  end
80
90
 
91
+ alias_method :resume, :unpause
92
+
81
93
  # Flushes currently suspended output.
82
94
  #
83
95
  # @param silent [Boolean] If set to true, flushes to /dev/null, else
84
96
  # to configured output(s).
85
- def flush(silent = false)
97
+ def flush(silent: false)
98
+ while not outputQueue.empty?
99
+ el = outputQueue.pop
100
+ self.out!(**el) unless silent
101
+ end
102
+ end
103
+
104
+ # Provides inspection
105
+ #
106
+ def inspect
107
+ arr = []
108
+ tmpQueue = Queue.new
86
109
  while not @outputQueue.empty?
87
110
  el = @outputQueue.pop
88
- self.out!(el[:chunk], el[:newline], el[:cr]) unless silent
111
+ arr << el
112
+ tmpQueue << el
89
113
  end
114
+ @outputQueue = tmpQueue
115
+ return "<#OutputHandler:0x#{self.object_id.to_s(16)}, paused: #{@paused}, queueLength: #{@outputQueue.size}, outputQueue: #{arr.inspect}>"
90
116
  end
91
117
 
118
+ private
119
+
120
+ attr_reader :console, :logfile, :location, :file, :outputQueue, :debug
121
+
92
122
  # Sends next chunk to outputs. Will be queued if #paused, otherwise
93
123
  # sent to output(s).
94
124
  #
95
125
  # @param chunk [printable Object]
96
- # @param newline [Boolean] Indicates whether (default) or not to end
126
+ # @param newline [Boolean] Indicates whether (default) or not to end
97
127
  # line with a newline character.
98
- def out(chunk = "", newline = true, cr = false)
99
- el = { chunk: chunk, newline: newline, cr: cr}
100
- @outputQueue << el
128
+ def out(chunk: "", newline: true, cr: false)
129
+ outputQueue << { chunk: chunk, newline: newline, cr: cr }
101
130
  end
102
131
 
103
132
  # Sends next chunk to output(s) directly, regardless of #paused.
104
133
  #
105
134
  # @param (see #out)
106
- def out!(chunk = "", newline = true, cr = false)
107
- superprint "#{cr ? "\r" : ""
135
+ def out!(chunk: "", newline: true, cr: false)
136
+ binding.irb if debug
137
+ superprint("#{cr ? "\r" : ""
108
138
  }#{chunk.chomp
109
- }#{newline ? "\n" : ""}" if @console
110
- File.open(@logfile,'a+'){|f| f.write "#{cr ? "\r" : ""
111
- }#{chunk.chomp
112
- }#{newline ? "\n" : "" }" } if @file
139
+ }#{newline ? "\n" : ""}") if console
140
+ File.open("#{location}/#{logfile.call}",'a+'){|f| f.write "#{cr ? "\r" : ""
141
+ }#{chunk.chomp
142
+ }#{newline ? "\n" : "" }" } if file
143
+ @block.call(chunk) if @block.is_a? Proc
113
144
  end
114
145
 
115
146
  # Spawns output thread
@@ -120,35 +151,13 @@ class OutputHandler
120
151
  if self.paused?
121
152
  sleep 0.1
122
153
  else
123
- o = @outputQueue.pop
124
- superprint "#{o[:cr] ? "\r" : ""
125
- }#{o[:chunk]
126
- }#{o[:newline] ? "\n" : ""}" if @console
127
- File.open(@logfile,'a+') do |f|
128
- f.write "#{o[:cr] ? "\r" : ""
129
- }#{o[:chunk]
130
- }#{o[:newline] ? "\n" : "" }"
131
- end if @file
154
+ o = outputQueue.pop
155
+ out!(**o)
132
156
  end
133
157
  end
134
158
  end
135
159
  end
136
160
 
137
- # Provides inspection
138
- #
139
- # @!visibility private
140
- def inspect
141
- arr = []
142
- tmpQueue = Queue.new
143
- while not @outputQueue.empty?
144
- el = @outputQueue.pop
145
- arr << el
146
- tmpQueue << el
147
- end
148
- @outputQueue = tmpQueue
149
- return "<#OutputHandler:0x#{self.object_id.to_s(16)}, paused: #{@paused}, queueLength: #{@outputQueue.size}, outputQueue: #{arr.inspect}>"
150
- end
151
-
152
161
  # Spawns a thread that creates some random output
153
162
  #
154
163
  # @!visibility private
@@ -0,0 +1,28 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "outputhandler"
3
+ s.version = File.read("#{__dir__}/VERSION")
4
+ s.date = File.mtime("#{__dir__}/VERSION").strftime('%Y-%m-%d')
5
+ s.summary = "Wrapper class that enables asynchronious output (pausing / unpausing)"
6
+ s.description = "Wrapper class that enables asynchronious output (pausing / unpausing) "
7
+ s.authors = [ "Benjamin L. Tischendorf" ]
8
+ s.email = "github@jtown.eu"
9
+ s.homepage = "https://github.com/donkeybridge/outputhandler"
10
+ s.platform = Gem::Platform::RUBY
11
+ s.license = "BSD-4-Clause"
12
+ s.required_ruby_version = '~> 2.7'
13
+
14
+ versioned = `git ls-files -z`.split("\0")
15
+
16
+ s.files = Dir.chdir(File.expand_path(__dir__)) do
17
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ end
19
+ s.bindir = 'bin'
20
+ s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ s.require_paths = ['lib']
22
+
23
+ # s.add_dependency 'bundler', '>= 1.1.16'
24
+ s.add_development_dependency 'rspec','~>3.6'
25
+ s.add_development_dependency 'cucumber','~>3.1'
26
+ s.add_development_dependency 'yard', '~>0.9'
27
+ end
28
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: outputhandler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3beta
4
+ version: 0.2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin L. Tischendorf
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-10 00:00:00.000000000 Z
11
+ date: 2021-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -58,21 +58,15 @@ executables: []
58
58
  extensions: []
59
59
  extra_rdoc_files: []
60
60
  files:
61
- - ".gitignore"
61
+ - CHANGELOG.md
62
62
  - HISTORY
63
63
  - LICENSE
64
64
  - README.md
65
65
  - Rakefile
66
- - features/01-outputhandler_new.feature
67
- - features/02-outputhandler_pause.feature
68
- - features/03-outputhandler_opts.feature
69
- - features/04-outputhandler_output.feature
70
- - features/step_definitions/01-outputhandler_new_steps.rb
71
- - features/step_definitions/02-outputhander_pause.steps.rb
72
- - features/step_definitions/03-outputhandler_opts_steps.rb
73
- - features/step_definitions/04-outputhandler_output_steps.rb
74
- - features/support/env.rb
66
+ - VERSION
67
+ - cucumber.yml
75
68
  - lib/outputhandler.rb
69
+ - outputhandler.gemspec
76
70
  homepage: https://github.com/donkeybridge/outputhandler
77
71
  licenses:
78
72
  - BSD-4-Clause
@@ -85,15 +79,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
85
79
  requirements:
86
80
  - - "~>"
87
81
  - !ruby/object:Gem::Version
88
- version: '2.0'
82
+ version: '2.7'
89
83
  required_rubygems_version: !ruby/object:Gem::Requirement
90
84
  requirements:
91
- - - ">"
85
+ - - ">="
92
86
  - !ruby/object:Gem::Version
93
- version: 1.3.1
87
+ version: '0'
94
88
  requirements: []
95
- rubyforge_project:
96
- rubygems_version: 2.7.8
89
+ rubygems_version: 3.1.6
97
90
  signing_key:
98
91
  specification_version: 4
99
92
  summary: Wrapper class that enables asynchronious output (pausing / unpausing)
data/.gitignore DELETED
@@ -1,50 +0,0 @@
1
- *.gem
2
- *.rbc
3
- /.config
4
- /coverage/
5
- /InstalledFiles
6
- /pkg/
7
- /spec/reports/
8
- /spec/examples.txt
9
- /test/tmp/
10
- /test/version_tmp/
11
- /tmp/
12
-
13
- # Used by dotenv library to load environment variables.
14
- # .env
15
-
16
- ## Specific to RubyMotion:
17
- .dat*
18
- .repl_history
19
- build/
20
- *.bridgesupport
21
- build-iPhoneOS/
22
- build-iPhoneSimulator/
23
-
24
- ## Specific to RubyMotion (use of CocoaPods):
25
- #
26
- # We recommend against adding the Pods directory to your .gitignore. However
27
- # you should judge for yourself, the pros and cons are mentioned at:
28
- # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
- #
30
- # vendor/Pods/
31
-
32
- ## Documentation cache and generated files:
33
- /.yardoc/
34
- /_yardoc/
35
- /doc/
36
- /rdoc/
37
-
38
- ## Environment normalization:
39
- /.bundle/
40
- /vendor/bundle
41
- /lib/bundler/man/
42
-
43
- # for a library or gem, you might want to ignore these files since the code is
44
- # intended to run in multiple environments; otherwise, check them in:
45
- # Gemfile.lock
46
- # .ruby-version
47
- # .ruby-gemset
48
-
49
- # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
- .rvmrc
@@ -1,37 +0,0 @@
1
- Feature: Initialization
2
-
3
- Scenario: Create a new OutputHandler from scratch without any options
4
- Given a new OutputHandler is created without options
5
- Then it should return an object of class OutputHandler
6
- Then it should have an instance variable "@outputQueue"
7
- And "@outputQueue" should be a "Queue"
8
- And it should have an instance variable "@console"
9
- And "@console" should be a Boolean
10
- And it should have an instance variable "@file"
11
- And "@file" should be a Boolean
12
- And it should have an instance variable "@logfile"
13
- And "@logfile" should be nil
14
- And it should be not paused?
15
- And it should not respond to #foo
16
- And #out! should send output with newline to console
17
- And #out should send output with newline to console
18
- And #out! should send output to console without newline when added parameter false
19
- And #out should send output to console without newline when added parameter false
20
-
21
-
22
-
23
- Scenario Outline: Checking whether it is responding to methods
24
- Given a new OutputHandler is created
25
- Then it should respond to "<method>"
26
- Examples:
27
- | method |
28
- | paused? |
29
- | pause |
30
- | unpause |
31
- | out |
32
- | out! |
33
- | flush |
34
- | puts |
35
- | puts! |
36
- | print |
37
- | print! |
@@ -1,33 +0,0 @@
1
- Feature: Pausing and unpausing the Outputhandler
2
-
3
- Scenario: Creating and pausing the outputhandler should send output via #out! but not via #out
4
- Given a new instance is created
5
- And it is paused
6
- Then #out! should send output
7
- But #out should not send output
8
-
9
- Scenario: Creating and pausing the outputHandler should not send output via #out, but after unpausing it should
10
-
11
- Given a new instance is created
12
- And it is paused
13
- Then #out should not send immediate output
14
- And #out should send immediate output when unpausing
15
-
16
- Scenario: Creating and pausing the outputHandler for 2 second should not print anything, but after 2 seconds it should
17
-
18
- Given a new instance is created
19
- And it is paused for 2 seconds
20
- Then #out should not send immediate output
21
- But should arrive after 2 seconds
22
-
23
- Scenario: Creating and pausing the outputhandler, output should not be sent immediately, but upon #flush
24
- Given a new instance is created
25
- And it is paused
26
- And output is send to #out
27
- And output is send to #out
28
- Then it should send immediate upon #flush
29
- Given output is send to #out
30
- Then it should not send immediate upon silent #flush
31
- And #out should not send immediate output when unpausing
32
-
33
-
@@ -1,15 +0,0 @@
1
- Feature: A new OutputHandler can react to options hash
2
-
3
- Scenario: Only Hash as Parameter is accepted
4
- Given a OutputHandler will be created
5
- Then with a String as parameter is should raise a TypeError
6
- Then with a Hash as parameter it should not raise
7
-
8
- Scenario: Parameter "console: false" disables default console output
9
- Given an OutputHandler is created with parameter "console" set to "false"
10
- Then #out should not send output
11
-
12
- Scenario: Parameter "logile: filename" enables output to filename
13
- Given an OutputHandler is created with parameter "logfile" set to "/tmp/foofile"
14
- And output "ramses" is send to #out
15
- Then file "/tmp/foofile" should contain output "ramses"
@@ -1,31 +0,0 @@
1
- Feature: outputhandler should be aware of CR and NL
2
-
3
- Scenario: #puts and #puts! should send with newline but without CR
4
- Given a new instance is created
5
- Then output should contain a NL but no CR when sent to "puts"
6
- Then output should contain a NL but no CR when sent to "puts!"
7
-
8
-
9
- Scenario: #puts(true) and #puts!(true) should send with NL but also with CR
10
- Given a new instance is created
11
- Then output should contain a NL with leading CR when sent to "puts" with param true
12
- Then output should contain a NL with leading CR when sent to "puts!" with param true
13
-
14
-
15
- Scenario: #print and #print! should send without newline
16
- Given a new instance is created
17
- Then output should contain neither NL nor CR when sent to "print"
18
- Then output should contain neither NL nor CR when sent to "print!"
19
-
20
- Scenario: #print(true) and #print!(true) should send without NL but with CR
21
- Given a new instance is created
22
- Then output should contain a leading CR but no NL when sent to "print" with param true
23
- Then output should contain a leading CR but no NL when sent to "print!" with param true
24
-
25
- Scenario: #print(true) overwrite former #print(true)
26
- Given an OutputHandler is created with parameter "logfile" set to "/tmp/barfile"
27
- And "foo" is sent to the handler with print
28
- Then file "/tmp/barfile" should contain output "foo"
29
- And "bar" is sent to the handler with print and param true
30
- Then file "/tmp/barfile" should contain output "bar"
31
-
@@ -1,47 +0,0 @@
1
- Given /a new OutputHandler is created/ do
2
- require './lib/outputhandler.rb'
3
- @output_handler = OutputHandler.new
4
- end
5
-
6
- Then "it should return an object of class OutputHandler" do
7
- expect(@output_handler).to be_instance_of(OutputHandler)
8
- end
9
-
10
- Then /^it should have an instance variable "([^"]*)"$/ do |var|
11
- expect(@output_handler.instance_variable_defined?(var.to_sym)).to be true
12
- end
13
-
14
- Then /^"([^"]*)" should be a Boolean$/ do |var|
15
- expect(@output_handler.instance_variable_get(var.to_sym)).to be_instance_of(TrueClass).or be_instance_of(FalseClass)
16
- end
17
-
18
- Then /^"([^"]*)" should be nil$/ do |var|
19
- expect(@output_handler.instance_variable_get(var.to_sym)).to be_nil
20
- end
21
-
22
- Then /^"([^"]*)" should be a "([^"]*)"$/ do |var, klass|
23
- expect(@output_handler.instance_variable_get(var.to_sym)).to be_instance_of(Object.const_get(klass))
24
- end
25
-
26
- Then "it should be not paused?" do
27
- expect(@output_handler.paused?).to be false
28
- end
29
-
30
- Then "it should not respond to #foo" do
31
- expect(@output_handler).not_to respond_to(:foo)
32
- end
33
-
34
- Then /^it should respond to "([^"]*)"$/ do |method|
35
- expect(@output_handler).to respond_to(method.to_sym)
36
- end
37
-
38
-
39
- Then /^#(out!?) should send output with newline to console$/ do |method|
40
- expect{@output_handler.send(method.to_sym,"foo"); sleep 0.25}.to output("foo\n").to_stdout_from_any_process
41
- end
42
-
43
- Then /^#(out!?) should send output to console without newline when added parameter false$/ do |method|
44
- expect{@output_handler.send(method.to_sym,"foo",false); sleep 0.1}.to output("foo").to_stdout
45
- end
46
-
47
-
@@ -1,57 +0,0 @@
1
- Given("a new instance is created") do
2
- require './lib/outputhandler.rb'
3
- @output_handler = OutputHandler.new
4
- end
5
-
6
- Given("it is paused") do
7
- @output_handler.pause
8
- end
9
-
10
- Then("#out! should send output") do
11
- expect { @output_handler.out!("foo")}.to output("foo\n").to_stdout
12
- end
13
-
14
- Then("#out should not send output") do
15
- expect { @output_handler.out("foo")}.not_to output().to_stdout_from_any_process
16
- end
17
-
18
- Given("output is send to #out") do
19
- @output_handler.out("foo")
20
- end
21
-
22
- Given /^output "([^"]*)" is send to #out$/ do |str|
23
- @output_handler.out(str)
24
- sleep 0.1
25
- end
26
-
27
- Then "#out should not send immediate output" do
28
- expect { @output_handler.out("foo"); sleep 0.25 }.not_to output.to_stdout_from_any_process
29
- end
30
-
31
- Then "#out should send immediate output when unpausing" do
32
- expect { @output_handler.unpause; sleep 0.25 }.to output("foo\n").to_stdout_from_any_process
33
- end
34
-
35
- Given /^it is paused for (\d+) seconds$/ do |seconds|
36
- @output_handler.pause(seconds)
37
- end
38
-
39
- Then /^should arrive after (\d+) seconds$/ do |seconds|
40
- expect{ sleep seconds; }.to output("foo\n").to_stdout_from_any_process
41
- end
42
-
43
- Then "it should send immediate upon #flush" do
44
- expect { @output_handler.flush; sleep 0.25 }.to output("foo\nfoo\n").to_stdout_from_any_process
45
- end
46
-
47
- Then "it should not send immediate upon silent #flush" do
48
- expect { @output_handler.flush(true); sleep 0.25 }.not_to output.to_stdout_from_any_process
49
- end
50
-
51
- Then "#out should not send immediate output when unpausing" do
52
- expect { @output_handler.unpause; sleep 0.25}.not_to output.to_stdout_from_any_process
53
- end
54
-
55
-
56
-
57
-
@@ -1,22 +0,0 @@
1
- require './lib/outputhandler.rb'
2
-
3
- Given "a OutputHandler will be created" do
4
- end
5
-
6
- But "with a String as parameter is should raise a TypeError" do
7
- expect { OutputHandler.new("foo")}.to raise_error(TypeError)
8
- end
9
-
10
- But "with a Hash as parameter it should not raise" do
11
- expect { OutputHandler.new({})}.not_to raise_error
12
- end
13
-
14
- Given /^an OutputHandler is created with parameter "([^"]*)" set to "([^"]*)"$/ do |param, value|
15
- File.open(value, "w"){|f| f.write "" } if param == "logfile"
16
- eval "@output_handler = OutputHandler.new(#{param}:\"#{value}\")"
17
- end
18
-
19
- Then /^file "([^"]*)" should contain output "([^"]*)"$/ do |filename, str|
20
- expect( `cat #{filename} | tail -n1`.split("\r").last.chomp).to eq(str.chomp)
21
- end
22
-
@@ -1,37 +0,0 @@
1
- require './lib/outputhandler.rb'
2
-
3
- Then /^output should contain a NL but no CR when sent to "([^"]*)"$/ do |method|
4
- expect { @output_handler.send(method.to_sym, "foo"); sleep 0.25}.
5
- to output("foo\n").to_stdout_from_any_process
6
- end
7
-
8
- Then /^output should contain a NL with leading CR when sent to "([^"]*)" with param true$/ do |method|
9
- expect { @output_handler.send(method.to_sym, "foo", true); sleep 0.25}.
10
- to output("\rfoo\n").to_stdout_from_any_process
11
- end
12
-
13
- Then /^output should contain neither NL nor CR when sent to "([^"]*)"$/ do |method|
14
- expect { @output_handler.send(method.to_sym, "foo"); sleep 0.25 }.
15
- to output("foo").to_stdout_from_any_process
16
- end
17
-
18
- Then /^output should contain a leading CR but no NL when sent to "([^"]*)" with param true$/ do |method|
19
- expect { @output_handler.send(method.to_sym, "foo", true); sleep 0.25 }.
20
- to output("\rfoo").to_stdout_from_any_process
21
- end
22
-
23
- Given "{string} is sent to the handler with print" do |string|
24
- puts "sent str is #{string}"
25
- @output_handler.print(string)
26
- sleep 0.1
27
- end
28
-
29
- Given "{string} is sent to the handler with print and param true" do |string|
30
- puts "sent string is #{string}"
31
- @output_handler.print(string, true)
32
- sleep 0.1
33
- end
34
-
35
- #Then /^file "([^"]*)" should contain "([^"]*)"$/ do |filename, str|
36
- # expect(File.read(filename)).to eq("\r#{str}")
37
- #end
@@ -1,6 +0,0 @@
1
- require 'rspec'
2
- RSpec.configure do |config|
3
- config.expect_with :rspec do |c|
4
- c.syntax = :expect
5
- end
6
- end