stdout 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
data/doc/ChangeLog ADDED
@@ -0,0 +1,5 @@
1
+ === 0.0.1 / 2013-11-11
2
+
3
+ * First release.
4
+
5
+
data/doc/LICENSE ADDED
@@ -0,0 +1,8 @@
1
+ You can redistribute it and/or modify it under either the terms of the GPL
2
+ version 3, or LGPL version 3 (Dual License).
3
+
4
+ See the file doc/COPYING or doc/COPYING.LESSER.
5
+
6
+ Copyright (c) 774 All Rights Reserved.
7
+ Web: http://id774.net
8
+ E-Mail: 774@id774.net, idnanashi@gmail.com
data/lib/stdout.rb ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ # Name:: Stdout
3
+ # Author:: 774 <http://id774.net>
4
+ # Created:: Nov 11, 2013
5
+ # Updated:: Nov 11, 2013
6
+ # Copyright:: 774 <http://id774.net> Copyright (c) 2013
7
+ # License:: Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0.
8
+
9
+ module Stdout
10
+ VERSION = "0.0.1"
11
+ require File.dirname(__FILE__) + "/stdout/output"
12
+ end
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+ # Name:: Stdout
3
+ # Author:: 774 <http://id774.net>
4
+ # Created:: Nov 11, 2013
5
+ # Updated:: Nov 11, 2013
6
+ # Copyright:: 774 <http://id774.net> Copyright (c) 2013
7
+ # License:: Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0.
8
+
9
+ module Stdout
10
+ class Output
11
+ attr_accessor :print, :dump
12
+
13
+ def initialize
14
+ @print = []
15
+ @dump = []
16
+ end
17
+
18
+ def write(msg); @print.push(msg); end
19
+
20
+ class << self
21
+ def capture(sep = $/)
22
+ output = self.new
23
+ $stdout = output
24
+ yield
25
+ $stdout = STDOUT
26
+ output.print.join.each_line(sep = sep) {|line|
27
+ output.dump.push(line)
28
+ }
29
+ return output.dump
30
+ end
31
+ end
32
+ end
33
+ end
data/script/.gitkeep ADDED
File without changes
data/script/build ADDED
@@ -0,0 +1,32 @@
1
+ #!/bin/sh
2
+ #
3
+ ########################################################################
4
+ # Integration Build Script
5
+ #
6
+ # Maintainer: id774 <idnanashi@gmail.com>
7
+ #
8
+ # v1.2 3/15,2013
9
+ # Change rake task to simplecov.
10
+ # v1.1 3/14,2013
11
+ # Show ruby version.
12
+ # v1.0 3/16,2012
13
+ # First.
14
+ ########################################################################
15
+
16
+ kickstart() {
17
+ export RACK_ROOT="."
18
+ export RACK_ENV="test"
19
+ ruby -v
20
+ }
21
+
22
+ run_tests() {
23
+ rake simplecov
24
+ }
25
+
26
+ main() {
27
+ kickstart
28
+ run_tests
29
+ }
30
+
31
+ set -ex
32
+ main
@@ -0,0 +1,136 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/../../spec_helper'
4
+
5
+ describe Stdout::Output do
6
+
7
+ context 'capture method with no arguments' do
8
+
9
+ describe 'giving block of a put' do
10
+ it "should return array object" do
11
+ expected = ["hoge\n"]
12
+
13
+ result = Stdout::Output.capture { puts "hoge" }
14
+ result.should eq expected
15
+ end
16
+ end
17
+
18
+ describe 'giving block of puts' do
19
+ it "should return array object" do
20
+
21
+ expected = [
22
+ "aaa\n",
23
+ "bbb\n",
24
+ "ccc\n"
25
+ ]
26
+
27
+ result = Stdout::Output.capture {
28
+ puts "aaa"
29
+ puts "bbb"
30
+ puts "ccc"
31
+ }
32
+
33
+ result.should eq expected
34
+ end
35
+ end
36
+
37
+ describe 'giving block of print method' do
38
+ it "should return array object" do
39
+
40
+ def print_method
41
+ result = 1 + 2
42
+ puts "Answer is #{result}."
43
+ end
44
+
45
+ expected = [
46
+ "Answer is 3.\n"
47
+ ]
48
+
49
+ result = Stdout::Output.capture {
50
+ print_method
51
+ }
52
+
53
+ result.should eq expected
54
+ end
55
+ end
56
+
57
+ describe 'giving block of prints method' do
58
+ it "should return array object" do
59
+
60
+ def prints_method
61
+ puts "Job start"
62
+ puts "Now processing..."
63
+ puts "Done!"
64
+ end
65
+
66
+ expected = [
67
+ "Job start\n",
68
+ "Now processing...\n",
69
+ "Done!\n"
70
+ ]
71
+
72
+ result = Stdout::Output.capture {
73
+ prints_method
74
+ }
75
+
76
+ result.should eq expected
77
+ end
78
+ end
79
+
80
+ end
81
+
82
+ context 'capture method with separator "\r"' do
83
+
84
+ describe 'giving block of prints method' do
85
+ it "should return array object" do
86
+
87
+ def prints_method_with_r
88
+ print "Job start\r"
89
+ print "Now processing...\r"
90
+ print "Done!\r"
91
+ end
92
+
93
+ expected = [
94
+ "Job start\r",
95
+ "Now processing...\r",
96
+ "Done!\r"
97
+ ]
98
+
99
+ result = Stdout::Output.capture (sep = "\r") {
100
+ prints_method_with_r
101
+ }
102
+
103
+ result.should eq expected
104
+ end
105
+ end
106
+
107
+ end
108
+
109
+ context 'capture method with separator "\n"' do
110
+
111
+ describe 'giving block of prints method' do
112
+ it "should return array object" do
113
+
114
+ def prints_method_with_n
115
+ print "Job start\n"
116
+ print "Now processing...\n"
117
+ print "Done!\n"
118
+ end
119
+
120
+ expected = [
121
+ "Job start\n",
122
+ "Now processing...\n",
123
+ "Done!\n"
124
+ ]
125
+
126
+ result = Stdout::Output.capture (sep = "\n") {
127
+ prints_method_with_n
128
+ }
129
+
130
+ result.should eq expected
131
+ end
132
+ end
133
+
134
+ end
135
+
136
+ end
@@ -0,0 +1,13 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/../spec_helper'
4
+
5
+ describe Stdout do
6
+ context 'const get :VERSION should' do
7
+ it "return right version number" do
8
+ expect = '0.0.1'
9
+ Stdout.const_get(:VERSION).should be_true
10
+ Stdout.const_get(:VERSION).should eq expect
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,25 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), ".."))
4
+ $LOAD_PATH.unshift APP_ROOT
5
+ $LOAD_PATH.unshift File.join(APP_ROOT)
6
+ $LOAD_PATH.unshift File.join(APP_ROOT, 'lib')
7
+ require File.dirname(__FILE__) + '/../lib/stdout'
8
+
9
+ if ENV['COVERAGE'] == 'on'
10
+ require 'simplecov'
11
+ require 'simplecov-rcov'
12
+ SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
13
+
14
+ SimpleCov.start do
15
+ add_filter "spec"
16
+ add_filter "vendor"
17
+ end
18
+ end
19
+
20
+ unless /^1\.8\./ =~ RUBY_VERSION
21
+ require 'rspec'
22
+ end
23
+
24
+ RSpec.configure do |config|
25
+ end
data/stdout.gemspec ADDED
@@ -0,0 +1,65 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: stdout 0.0.1 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "stdout"
9
+ s.version = "0.0.1"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.authors = ["id774"]
13
+ s.date = "2013-11-11"
14
+ s.description = "Change stdout to array object"
15
+ s.email = "idnanashi@gmail.com"
16
+ s.extra_rdoc_files = [
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ "Gemfile",
21
+ "README.md",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "demo.rb",
25
+ "demo2.rb",
26
+ "doc/AUTHORS",
27
+ "doc/COPYING",
28
+ "doc/COPYING.LESSER",
29
+ "doc/ChangeLog",
30
+ "doc/LICENSE",
31
+ "lib/stdout.rb",
32
+ "lib/stdout/output.rb",
33
+ "script/.gitkeep",
34
+ "script/build",
35
+ "spec/lib/stdout/stdout_spec.rb",
36
+ "spec/lib/stdout_spec.rb",
37
+ "spec/spec_helper.rb",
38
+ "stdout.gemspec",
39
+ "vendor/.gitkeep"
40
+ ]
41
+ s.homepage = "http://github.com/id774/stdout"
42
+ s.licenses = ["GPL"]
43
+ s.require_paths = ["lib"]
44
+ s.rubygems_version = "2.1.9"
45
+ s.summary = "Stdout"
46
+
47
+ if s.respond_to? :specification_version then
48
+ s.specification_version = 4
49
+
50
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
51
+ s.add_development_dependency(%q<cucumber>, [">= 0"])
52
+ s.add_development_dependency(%q<bundler>, [">= 0"])
53
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
54
+ else
55
+ s.add_dependency(%q<cucumber>, [">= 0"])
56
+ s.add_dependency(%q<bundler>, [">= 0"])
57
+ s.add_dependency(%q<jeweler>, [">= 0"])
58
+ end
59
+ else
60
+ s.add_dependency(%q<cucumber>, [">= 0"])
61
+ s.add_dependency(%q<bundler>, [">= 0"])
62
+ s.add_dependency(%q<jeweler>, [">= 0"])
63
+ end
64
+ end
65
+