bzip2-ruby 0.2.6 → 0.2.7

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.
@@ -1,5 +1,13 @@
1
1
  # encoding: UTF-8
2
- require 'bzip2_ext'
2
+ require 'bundler/setup'
3
+
4
+ require 'rspec/core'
5
+ require 'bzip2'
6
+
7
+
8
+ RSpec.configure do |config|
9
+ config.color_enabled = true
10
+ end
3
11
 
4
12
  # back-port 1.9 method so the tests will pass in 1.8 as well
5
13
  if RUBY_VERSION.include?("1.8")
@@ -1,57 +1,58 @@
1
1
  # encoding: UTF-8
2
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper.rb')
2
+ require 'spec_helper'
3
3
 
4
- describe "Bzip2::Writer" do
4
+ describe Bzip2::Writer do
5
5
  class Dummy
6
6
  def to_s
7
7
  "dummy"
8
8
  end
9
9
  end
10
10
 
11
- before(:all) do
12
- @file = "_10lines_"
11
+ before(:each) do
12
+ @file = File.expand_path('../_10lines_', __FILE__)
13
13
  end
14
14
 
15
- after(:all) do
16
- File.unlink(@file)
15
+ after(:each) do
16
+ File.delete(@file) if File.exists?(@file)
17
17
  end
18
18
 
19
- def test_f_LSHIFT # '<<'
20
- Bzip2::Writer.open($file, "w") do |file|
19
+ it "performs like IO#<< when using the #<< method" do
20
+ Bzip2::Writer.open(@file, "w") do |file|
21
21
  file << 1 << "\n" << Dummy.new << "\n" << "cat\n"
22
22
  end
23
23
  expected = [ "1\n", "dummy\n", "cat\n"]
24
- Bzip2::Reader.foreach($file) do |line|
25
- expected.shift.should == line
26
- end
27
- [].should == expected
24
+ actual = []
25
+ Bzip2::Reader.foreach(@file){ |line| actual.push line }
26
+ actual.should == expected
28
27
  end
29
28
 
30
- def test_f_error
31
- io = File.new($file, "w")
29
+ it "doesn't immediately flush the data when written to" do
30
+ io = File.new(@file, "w")
32
31
  bz2 = Bzip2::Writer.new(io)
33
32
  bz2 << 1 << "\n" << Dummy.new << "\n" << "cat\n"
34
- bz = Bzip2::Reader.new($file)
35
- lambda { bz.gets }.should raise_error(Bzip2::EOZError)
36
- bz = Bzip2::Reader.open($file)
37
- lambda { bz.gets }.should raise_error(Bzip2::EOZError)
33
+ bz = Bzip2::Reader.new(@file)
34
+ lambda { bz.gets }.should raise_error(Bzip2::Error)
35
+ bz = Bzip2::Reader.open(@file)
36
+ lambda { bz.gets }.should raise_error(Bzip2::Error)
38
37
  io.close
39
38
  lambda { Bzip2::Reader.new(io) }.should raise_error(IOError)
40
39
  end
41
40
 
42
- def test_f_gets_para
43
- Bzip2::Writer.open($file) do |file|
44
- file.print "foo\n"*4096, "\n"*4096, "bar"*4096, "\n"*4096, "zot\n"*1024
41
+ it "behaves the same as IO#print when using #print" do
42
+ Bzip2::Writer.open(@file) do |file|
43
+ file.print "foo\n" * 4096, "\n" * 4096,
44
+ "bar" * 4096, "\n" * 4096, "zot\n" * 1024
45
45
  end
46
- Bzip2::Reader.open($file) do |file|
47
- ("foo\n"*4096+"\n").should == file.gets("")
48
- ("bar"*4096+"\n\n").should == file.gets("")
49
- ("zot\n"*1024).should == file.gets("")
46
+
47
+ Bzip2::Reader.open(@file) do |file|
48
+ file.gets('').should == "foo\n" * 4096 + "\n"
49
+ file.gets('').should == "bar" * 4096 + "\n\n"
50
+ file.gets('').should == "zot\n" * 1024
50
51
  end
51
52
  end
52
53
 
53
- def test_f_print
54
- Bzip2::Writer.open($file) do |file|
54
+ it "respects specific global variables like IO#print does via #print" do
55
+ Bzip2::Writer.open(@file) do |file|
55
56
  file.print "hello"
56
57
  file.print 1,2
57
58
  $_ = "wombat\n"
@@ -65,75 +66,64 @@ describe "Bzip2::Writer" do
65
66
  $, = nil
66
67
  end
67
68
 
68
- Bzip2::Reader.open($file) do |file|
69
- content = file.gets(nil)
70
- "hello12wombat\n3,4:5,6:\n".should == content
69
+ Bzip2::Reader.open(@file) do |file|
70
+ file.gets(nil).should == "hello12wombat\n3,4:5,6:\n"
71
71
  end
72
72
  end
73
73
 
74
- def test_f_putc
75
- Bzip2::Writer.open($file, "wb") do |file|
74
+ it "only writes one byte via the #putc method" do
75
+ Bzip2::Writer.open(@file, "wb") do |file|
76
76
  file.putc "A"
77
77
  0.upto(255) { |ch| file.putc ch }
78
78
  end
79
79
 
80
- Bzip2::Reader.open($file, "rb") do |file|
81
- ?A.should == file.getc
82
- 0.upto(255) { |ch| ch.should == file.getc }
80
+ Bzip2::Reader.open(@file, "rb") do |file|
81
+ file.getc.should == 'A'.bytes.first
82
+ 0.upto(255) { |ch| file.getc.should == ch }
83
83
  end
84
84
  end
85
85
 
86
- def test_f_puts
87
- Bzip2::Writer.open($file, "w") do |file|
86
+ it "behaves the same as IO#puts when using #puts" do
87
+ Bzip2::Writer.open(@file, "w") do |file|
88
88
  file.puts "line 1", "line 2"
89
89
  file.puts [ Dummy.new, 4 ]
90
90
  end
91
91
 
92
- Bzip2::Reader.open($file) do |file|
93
- "line 1\n".should == file.gets
94
- "line 2\n".should == file.gets
95
- "dummy\n".should == file.gets
96
- "4\n".should == file.gets
92
+ Bzip2::Reader.open(@file) do |file|
93
+ file.gets.should == "line 1\n"
94
+ file.gets.should == "line 2\n"
95
+ file.gets.should == "dummy\n"
96
+ file.gets.should == "4\n"
97
97
  end
98
98
  end
99
99
 
100
- def test_f_write
101
- Bzip2::Writer.open($file, "w") do |file|
102
- 10.should == file.write('*' * 10)
103
- 5.should == file.write('!' * 5)
104
- 0.should == file.write('')
105
- 1.should == file.write(1)
106
- 3.should == file.write(2.30000)
107
- 1.should == file.write("\n")
100
+ it "writes data successfully to a file and returns the length of the data" do
101
+ Bzip2::Writer.open(@file, "w") do |file|
102
+ file.write('*' * 10).should == 10
103
+ file.write('!' * 5).should == 5
104
+ file.write('').should == 0
105
+ file.write(1).should == 1
106
+ file.write(2.30000).should == 3
107
+ file.write("\n").should == 1
108
108
  end
109
109
 
110
- Bzip2::Reader.open($file) do |file|
111
- "**********!!!!!12.3\n".should == file.gets
110
+ Bzip2::Reader.open(@file) do |file|
111
+ file.gets.should == "**********!!!!!12.3\n"
112
112
  end
113
113
  end
114
114
 
115
- def test_s_string
115
+ it "returns the compressed data when no constructor argument is specified" do
116
116
  file = Bzip2::Writer.new
117
- 10.should == file.write('*' * 10)
118
- 5.should == file.write('!' * 5)
119
- 0.should == file.write('')
120
- 1.should == file.write(1)
121
- 3.should == file.write(2.30000)
122
- 1.should == file.write("\n")
123
- line = Bzip2::bunzip2(file.flush)
124
- "**********!!!!!12.3\n".should == line
125
-
126
- line = Bzip2::bunzip2(Bzip2::bzip2("**********!!!!!12.3\n"))
127
- "**********!!!!!12.3\n".should == line
128
-
129
- test = "foo\n"*4096 + "\n"*4096 + "bar"*4096 + "\n"*4096 + "zot\n"*1024
130
- line = Bzip2::bunzip2(Bzip2::bzip2(test))
131
- test.should == line
132
-
133
- Bzip2::bzip2("aaaaaaaaa".taint).tainted?.should be_true
134
- Bzip2::bunzip2(Bzip2::bzip2("aaaaaaaaa".taint)).tainted?.should be_true
135
- (!Bzip2::bzip2("aaaaaaaaa").tainted?).should be_false
136
- (!Bzip2::bunzip2(Bzip2::bzip2("aaaaaaaaa")).tainted?).should be_false
117
+ file << ('*' * 10) << ('!' * 5) << '' << 1 << 2.3000 << "\n"
118
+ Bzip2::bunzip2(file.flush).should == "**********!!!!!12.3\n"
119
+ end
137
120
 
121
+ it "compresses data via the #bzip2 shortcut" do
122
+ data = ["**********!!!!!12.3\n"]
123
+ data << "foo\n"*4096 + "\n"*4096 + "bar"*4096 + "\n"*4096 + "zot\n"*1024
124
+
125
+ data.each do |test|
126
+ Bzip2::bunzip2(Bzip2::bzip2(test)).should == test
127
+ end
138
128
  end
139
- end
129
+ end
metadata CHANGED
@@ -1,68 +1,101 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bzip2-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ hash: 25
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 2
9
+ - 7
10
+ version: 0.2.7
5
11
  platform: ruby
6
12
  authors:
7
13
  - Guy Decoux
8
- - Brian Lopez
14
+ - Brian Lopezs
9
15
  autorequire:
10
16
  bindir: bin
11
17
  cert_chain: []
12
18
 
13
- date: 2009-10-06 00:00:00 -07:00
19
+ date: 2010-11-16 00:00:00 -08:00
14
20
  default_executable:
15
- dependencies: []
16
-
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: rspec
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 15
31
+ segments:
32
+ - 2
33
+ - 0
34
+ - 0
35
+ version: 2.0.0
36
+ type: :development
37
+ version_requirements: *id001
17
38
  description:
18
- email: seniorlopez@gmail.com
39
+ email:
40
+ - seniorlopez@gmail.com
19
41
  executables: []
20
42
 
21
43
  extensions:
22
44
  - ext/extconf.rb
23
- extra_rdoc_files:
24
- - CHANGELOG.rdoc
25
- - README.rdoc
45
+ extra_rdoc_files: []
46
+
26
47
  files:
48
+ - .gitignore
49
+ - .yardopts
27
50
  - CHANGELOG.rdoc
51
+ - Gemfile
52
+ - Gemfile.lock
28
53
  - README.rdoc
29
54
  - Rakefile
30
- - VERSION.yml
31
55
  - bzip2-ruby.gemspec
32
56
  - ext/bzip2.c
33
57
  - ext/extconf.rb
58
+ - lib/bzip2-ruby.rb
34
59
  - lib/bzip2.rb
60
+ - lib/bzip2/internals.rb
61
+ - lib/bzip2/reader.rb
62
+ - lib/bzip2/version.rb
63
+ - lib/bzip2/writer.rb
35
64
  - spec/reader_spec.rb
36
65
  - spec/spec_helper.rb
37
66
  - spec/writer_spec.rb
38
- - tasks/extconf.rake
39
- - tasks/extconf/bz2.rake
40
67
  has_rdoc: true
41
68
  homepage: http://github.com/brianmario/bzip2-ruby
42
69
  licenses: []
43
70
 
44
71
  post_install_message:
45
- rdoc_options:
46
- - --charset=UTF-8
72
+ rdoc_options: []
73
+
47
74
  require_paths:
48
75
  - lib
49
76
  - ext
50
77
  required_ruby_version: !ruby/object:Gem::Requirement
78
+ none: false
51
79
  requirements:
52
80
  - - ">="
53
81
  - !ruby/object:Gem::Version
82
+ hash: 3
83
+ segments:
84
+ - 0
54
85
  version: "0"
55
- version:
56
86
  required_rubygems_version: !ruby/object:Gem::Requirement
87
+ none: false
57
88
  requirements:
58
89
  - - ">="
59
90
  - !ruby/object:Gem::Version
91
+ hash: 3
92
+ segments:
93
+ - 0
60
94
  version: "0"
61
- version:
62
95
  requirements: []
63
96
 
64
97
  rubyforge_project:
65
- rubygems_version: 1.3.5
98
+ rubygems_version: 1.3.7
66
99
  signing_key:
67
100
  specification_version: 3
68
101
  summary: Ruby C bindings to libbzip2.
@@ -1,4 +0,0 @@
1
- ---
2
- :minor: 2
3
- :patch: 6
4
- :major: 0
@@ -1,13 +0,0 @@
1
- namespace :extconf do
2
- desc "Compiles the Ruby extension"
3
- task :compile
4
- end
5
-
6
- task :compile => "extconf:compile"
7
-
8
- task :test => :compile
9
-
10
- BIN = "*.{bundle,jar,so,obj,pdb,lib,def,exp}"
11
- $hoe.clean_globs |= ["ext/**/#{BIN}", "lib/**/#{BIN}", 'ext/**/Makefile']
12
- $hoe.spec.require_paths = Dir['{lib,ext/*}']
13
- $hoe.spec.extensions = FileList["ext/**/extconf.rb"].to_a
@@ -1,43 +0,0 @@
1
- namespace :extconf do
2
- extension = File.basename(__FILE__, '.rake')
3
-
4
- ext = "ext/#{extension}"
5
- ext_so = "#{ext}/#{extension}.#{Config::CONFIG['DLEXT']}"
6
- ext_files = FileList[
7
- "#{ext}/*.c",
8
- "#{ext}/*.h",
9
- "#{ext}/*.rl",
10
- "#{ext}/extconf.rb",
11
- "#{ext}/Makefile",
12
- # "lib"
13
- ]
14
-
15
-
16
- task :compile => extension do
17
- if Dir.glob("**/#{extension}.{o,so,dll}").length == 0
18
- STDERR.puts "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
19
- STDERR.puts "Gem actually failed to build. Your system is"
20
- STDERR.puts "NOT configured properly to build #{GEM_NAME}."
21
- STDERR.puts "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
22
- exit(1)
23
- end
24
- end
25
-
26
- desc "Builds just the #{extension} extension"
27
- task extension.to_sym => ["#{ext}/Makefile", ext_so ]
28
-
29
- file "#{ext}/Makefile" => ["#{ext}/extconf.rb"] do
30
- Dir.chdir(ext) do ruby "extconf.rb" end
31
- end
32
-
33
- file ext_so => ext_files do
34
- Dir.chdir(ext) do
35
- sh(PLATFORM =~ /win32/ ? 'nmake' : 'make') do |ok, res|
36
- if !ok
37
- require "fileutils"
38
- FileUtils.rm Dir.glob('*.{so,o,dll,bundle}')
39
- end
40
- end
41
- end
42
- end
43
- end