fakefs 0.5.4 → 0.6.0

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.
@@ -9,5 +9,5 @@ require 'fakefs/fileutils'
9
9
  require 'fakefs/file'
10
10
  require 'fakefs/file_test'
11
11
  require 'fakefs/dir'
12
- require 'fakefs/pathname' if RUBY_VERSION >= "1.9.3"
12
+ require 'fakefs/pathname' if RUBY_VERSION >= '1.9.3'
13
13
  require 'fakefs/kernel'
@@ -1,6 +1,8 @@
1
- # FakeFS::SpecHelpers provides a simple macro for RSpec example groups to turn FakeFS on and off.
2
- # To use it simply require 'fakefs/spec_helpers', then include FakeFS::SpecHelpers into any
3
- # example groups that you wish to use FakeFS in. For example:
1
+ # FakeFS::SpecHelpers provides a simple macro for RSpec example
2
+ # groups to turn FakeFS on and off.
3
+ # To use it simply require 'fakefs/spec_helpers', then include
4
+ # FakeFS::SpecHelpers into any example groups that you wish
5
+ # to use FakeFS in. For example:
4
6
  #
5
7
  # require 'fakefs/spec_helpers'
6
8
  #
@@ -9,12 +11,14 @@
9
11
  # ...
10
12
  # end
11
13
  #
12
- # By default, including FakeFS::SpecHelpers will run for each example inside a describe block.
13
- # If you want to turn on FakeFS one time only for all your examples, you will need to
14
- # include FakeFS::SpecHelpers::All.
14
+ # By default, including FakeFS::SpecHelpers will run for each
15
+ # example inside a describe block.
16
+ # If you want to turn on FakeFS one time only for all your examples,
17
+ # you will need to include FakeFS::SpecHelpers::All.
15
18
  #
16
- # Alternatively, you can include FakeFS::SpecHelpers in all your example groups using RSpec's
17
- # configuration block in your spec helper:
19
+ # Alternatively, you can include FakeFS::SpecHelpers in all your
20
+ # example groups using RSpec's configuration block in
21
+ # your spec helper:
18
22
  #
19
23
  # require 'fakefs/spec_helpers'
20
24
  #
@@ -22,10 +26,12 @@
22
26
  # config.include FakeFS::SpecHelpers
23
27
  # end
24
28
  #
25
- # If you do the above then use_fakefs will be available in all of your example groups.
29
+ # If you do the above then use_fakefs will be available in all of
30
+ # your example groups.
26
31
  #
27
32
  require 'fakefs/safe'
28
33
 
34
+ # FakeFS module
29
35
  module FakeFS
30
36
  def use_fakefs(describe_block, opts)
31
37
  describe_block.before opts[:with] do
@@ -38,22 +44,24 @@ module FakeFS
38
44
  end
39
45
  end
40
46
 
47
+ # Module SpecHelpers
41
48
  module SpecHelpers
42
49
  include ::FakeFS
43
50
 
44
51
  def self.extended(example_group)
45
- example_group.use_fakefs(example_group, :with => :each)
52
+ example_group.use_fakefs(example_group, with: :each)
46
53
  end
47
54
 
48
55
  def self.included(example_group)
49
56
  example_group.extend self
50
57
  end
51
58
 
59
+ # Module All
52
60
  module All
53
61
  include ::FakeFS
54
62
 
55
63
  def self.extended(example_group)
56
- example_group.use_fakefs(example_group, :with => :all)
64
+ example_group.use_fakefs(example_group, with: :all)
57
65
  end
58
66
 
59
67
  def self.included(example_group)
@@ -1,6 +1,7 @@
1
1
  module FakeFS
2
+ # Version module
2
3
  module Version
3
- VERSION = "0.5.4"
4
+ VERSION = '0.6.0'
4
5
 
5
6
  def self.to_s
6
7
  VERSION
@@ -3,11 +3,11 @@ require 'fakefs/spec_helpers'
3
3
 
4
4
  RSpec.configure do |c|
5
5
  c.mock_with(:rspec)
6
- c.include(FakeFS::SpecHelpers, :fakefs => true)
6
+ c.include(FakeFS::SpecHelpers, fakefs: true)
7
7
  end
8
8
 
9
9
  if RUBY_VERSION >= '2.1'
10
- describe 'Find.find', :fakefs => true do
10
+ describe 'Find.find', fakefs: true do
11
11
  it 'does not give an ArgumentError' do
12
12
  FileUtils.mkdir_p('/tmp/foo')
13
13
  found = Find.find('/tmp').to_a
@@ -1,52 +1,53 @@
1
1
  require 'spec_helper'
2
2
 
3
+ # FakeFs module for tests
3
4
  module FakeFS
4
5
  describe SpecHelpers do
5
6
  before do
6
7
  @rspec_example_group = Class.new do
7
- def self.before(sym = :each)
8
+ def self.before(_sym = :each)
8
9
  yield if block_given?
9
10
  end
10
11
 
11
- def self.after(sym = :each)
12
+ def self.after(_sym = :each)
12
13
  yield if block_given?
13
14
  end
14
15
  end
15
16
  end
16
17
 
17
- describe "when extending" do
18
- context "before each" do
19
- it "should call it" do
18
+ describe 'when extending' do
19
+ context 'before each' do
20
+ it 'should call it' do
20
21
  @rspec_example_group.should_receive(:before).with(:each)
21
22
  @rspec_example_group.extend FakeFS::SpecHelpers
22
23
  end
23
24
 
24
- it "should call FakeFS.activate!" do
25
+ it 'should call FakeFS.activate!' do
25
26
  FakeFS.should_receive(:activate!)
26
27
  @rspec_example_group.extend FakeFS::SpecHelpers
27
28
  end
28
29
  end
29
30
 
30
- context "after each" do
31
- it "should call it" do
31
+ context 'after each' do
32
+ it 'should call it' do
32
33
  @rspec_example_group.should_receive(:after).with(:each)
33
34
  @rspec_example_group.extend FakeFS::SpecHelpers
34
35
  end
35
36
 
36
- it "should deactivate fakefs" do
37
+ it 'should deactivate fakefs' do
37
38
  FakeFS.should_receive(:deactivate!)
38
39
  @rspec_example_group.extend FakeFS::SpecHelpers
39
40
  end
40
41
 
41
- it "should clear the fakefs filesystem for the next run" do
42
+ it 'should clear the fakefs filesystem for the next run' do
42
43
  FakeFS::FileSystem.should_receive(:clear)
43
44
  @rspec_example_group.extend FakeFS::SpecHelpers
44
45
  end
45
46
  end
46
47
  end
47
48
 
48
- describe "when including" do
49
- it "should call before :each" do
49
+ describe 'when including' do
50
+ it 'should call before :each' do
50
51
  @rspec_example_group.should_receive(:before)
51
52
  @rspec_example_group.class_eval do
52
53
  include FakeFS::SpecHelpers
@@ -55,40 +56,40 @@ module FakeFS
55
56
  end
56
57
 
57
58
  describe SpecHelpers::All do
58
- describe "when extending" do
59
- context "before :all" do
60
- it "should call it" do
59
+ describe 'when extending' do
60
+ context 'before :all' do
61
+ it 'should call it' do
61
62
  @rspec_example_group.should_receive(:before).with(:all)
62
63
  @rspec_example_group.extend FakeFS::SpecHelpers::All
63
64
  end
64
65
 
65
- it "should call FakeFS.activate!" do
66
+ it 'should call FakeFS.activate!' do
66
67
  FakeFS.should_receive(:activate!)
67
68
  @rspec_example_group.extend FakeFS::SpecHelpers::All
68
69
  end
69
70
  end
70
71
 
71
- context "after :all" do
72
- it "should call it" do
72
+ context 'after :all' do
73
+ it 'should call it' do
73
74
  @rspec_example_group.should_receive(:after).with(:all)
74
75
  @rspec_example_group.extend FakeFS::SpecHelpers::All
75
76
  end
76
77
 
77
- it "should call FakeFS.deactivate!" do
78
+ it 'should call FakeFS.deactivate!' do
78
79
  FakeFS.should_receive(:deactivate!)
79
80
  @rspec_example_group.extend FakeFS::SpecHelpers::All
80
81
  end
81
82
 
82
- it "should not call FakeFS::FileSystem.clear" do
83
+ it 'should not call FakeFS::FileSystem.clear' do
83
84
  FakeFS::FileSystem.should_not_receive(:clear)
84
85
  @rspec_example_group.extend FakeFS::SpecHelpers::All
85
86
  end
86
87
  end
87
88
  end
88
89
 
89
- describe "when including" do
90
- context "before :all" do
91
- it "should call it" do
90
+ describe 'when including' do
91
+ context 'before :all' do
92
+ it 'should call it' do
92
93
  @rspec_example_group.should_receive(:before)
93
94
  @rspec_example_group.class_eval do
94
95
  include FakeFS::SpecHelpers::All
@@ -1,6 +1,7 @@
1
1
  require 'test_helper'
2
2
  require 'tempfile'
3
3
 
4
+ # Tempfile test class
4
5
  class TempfileTest < Test::Unit::TestCase
5
6
  include FakeFS
6
7
 
@@ -1,5 +1,6 @@
1
- require "test_helper"
1
+ require 'test_helper'
2
2
 
3
+ # File join test class
3
4
  class FileJoin < Test::Unit::TestCase
4
5
  def setup
5
6
  FakeFS.activate!
@@ -10,10 +11,10 @@ class FileJoin < Test::Unit::TestCase
10
11
  end
11
12
 
12
13
  [
13
- ["a", "b"], ["a/", "b"], ["a", "/b"], ["a/", "/b"], ["a", "/", "b"]
14
+ %w(a b), %w(a/ b), %w(a /b), %w(a/ /b), %w(a / b)
14
15
  ].each_with_index do |args, i|
15
16
  define_method "test_file_join_#{i}" do
16
17
  assert_equal RealFile.join(args), File.join(args)
17
18
  end
18
19
  end
19
- end
20
+ end
@@ -1,5 +1,6 @@
1
- require "test_helper"
1
+ require 'test_helper'
2
2
 
3
+ # File stat test class
3
4
  class FileStat < Test::Unit::TestCase
4
5
  def setup
5
6
  FakeFS.activate!
@@ -11,49 +12,49 @@ class FileStat < Test::Unit::TestCase
11
12
  end
12
13
 
13
14
  def test_calling_lstat_should_create_a_new_file_stat_object
14
- File.open("foo", "w") do |f|
15
- f << "bar"
15
+ File.open('foo', 'w') do |f|
16
+ f << 'bar'
16
17
  end
17
18
 
18
- File.open("foo") do |f|
19
+ File.open('foo') do |f|
19
20
  assert_equal File::Stat, f.lstat.class
20
21
  end
21
22
  end
22
23
 
23
24
  def test_lstat_should_use_correct_file
24
- File.open("bar", "w") do |f|
25
- f << "1"
25
+ File.open('bar', 'w') do |f|
26
+ f << '1'
26
27
  end
27
28
 
28
- File.open("bar") do |f|
29
+ File.open('bar') do |f|
29
30
  assert_equal 1, f.lstat.size
30
31
  end
31
32
  end
32
33
 
33
34
  def test_lstat_should_report_on_symlink_itself
34
- File.open("foo", "w") { |f| f << "some content" }
35
- File.symlink "foo", "my_symlink"
35
+ File.open('foo', 'w') { |f| f << 'some content' }
36
+ File.symlink 'foo', 'my_symlink'
36
37
 
37
- assert_not_equal File.lstat("my_symlink").size, File.lstat("foo").size
38
+ assert_not_equal File.lstat('my_symlink').size, File.lstat('foo').size
38
39
  end
39
40
 
40
41
  def test_should_report_on_symlink_itself_with_size_instance_method
41
- File.open("foo", "w") { |f| f << "some content" }
42
- File.symlink "foo", "my_symlink"
42
+ File.open('foo', 'w') { |f| f << 'some content' }
43
+ File.symlink 'foo', 'my_symlink'
43
44
 
44
- file = File.open("foo")
45
- symlink = File.open("my_symlink")
45
+ file = File.open('foo')
46
+ symlink = File.open('my_symlink')
46
47
 
47
48
  assert_not_equal file.lstat.size, symlink.lstat.size
48
49
  end
49
50
 
50
51
  def test_symlink_size_is_size_of_path_pointed_to
51
- File.open("a", "w") { |x| x << "foobarbazfoobarbaz" }
52
- File.symlink "a", "one_char_symlink"
53
- assert_equal 1, File.lstat("one_char_symlink").size
52
+ File.open('a', 'w') { |x| x << 'foobarbazfoobarbaz' }
53
+ File.symlink 'a', 'one_char_symlink'
54
+ assert_equal 1, File.lstat('one_char_symlink').size
54
55
 
55
- File.open("ab", "w") { |x| x << "foobarbazfoobarbaz" }
56
- File.symlink "ab", "two_char_symlink"
57
- assert_equal 2, File.lstat("two_char_symlink").size
56
+ File.open('ab', 'w') { |x| x << 'foobarbazfoobarbaz' }
57
+ File.symlink 'ab', 'two_char_symlink'
58
+ assert_equal 2, File.lstat('two_char_symlink').size
58
59
  end
59
- end
60
+ end
@@ -1,5 +1,6 @@
1
- require "test_helper"
1
+ require 'test_helper'
2
2
 
3
+ # File stat test class
3
4
  class FileStat < Test::Unit::TestCase
4
5
  def setup
5
6
  FakeFS.activate!
@@ -11,29 +12,29 @@ class FileStat < Test::Unit::TestCase
11
12
  end
12
13
 
13
14
  def test_calling_stat_should_create_a_new_file_stat_object
14
- File.open("foo", "w") do |f|
15
- f << "bar"
15
+ File.open('foo', 'w') do |f|
16
+ f << 'bar'
16
17
  end
17
18
 
18
- File.open("foo") do |f|
19
+ File.open('foo') do |f|
19
20
  assert_equal File::Stat, f.stat.class
20
21
  end
21
22
  end
22
23
 
23
24
  def test_stat_should_use_correct_file
24
- File.open("bar", "w") do |f|
25
- f << "1"
25
+ File.open('bar', 'w') do |f|
26
+ f << '1'
26
27
  end
27
28
 
28
- File.open("bar") do |f|
29
+ File.open('bar') do |f|
29
30
  assert_equal 1, f.stat.size
30
31
  end
31
32
  end
32
33
 
33
34
  def test_stat_should_report_on_symlink_pointer
34
- File.open("foo", "w") { |f| f << "some content" }
35
- File.symlink "foo", "my_symlink"
35
+ File.open('foo', 'w') { |f| f << 'some content' }
36
+ File.symlink 'foo', 'my_symlink'
36
37
 
37
- assert_equal File.stat("my_symlink").size, File.stat("foo").size
38
+ assert_equal File.stat('my_symlink').size, File.stat('foo').size
38
39
  end
39
- end
40
+ end
@@ -1,5 +1,6 @@
1
- require "test_helper"
1
+ require 'test_helper'
2
2
 
3
+ # File SysSeek test class
3
4
  class FileSysSeek < Test::Unit::TestCase
4
5
  def setup
5
6
  FakeFS.activate!
@@ -11,11 +12,11 @@ class FileSysSeek < Test::Unit::TestCase
11
12
  end
12
13
 
13
14
  def test_should_seek_to_position
14
- file = File.open("foo", "w") do |f|
15
- f << "0123456789"
15
+ File.open('foo', 'w') do |f|
16
+ f << '0123456789'
16
17
  end
17
18
 
18
- File.open("foo", "r") do |f|
19
+ File.open('foo', 'r') do |f|
19
20
  f.sysseek(3)
20
21
  assert_equal 3, f.pos
21
22
 
@@ -25,20 +26,20 @@ class FileSysSeek < Test::Unit::TestCase
25
26
  end
26
27
 
27
28
  def test_seek_returns_offset_into_file
28
- File.open("foo", "w") do |f|
29
+ File.open('foo', 'w') do |f|
29
30
  # 66 chars long
30
- str = "0123456789" +
31
- "0123456789" +
32
- "0123456789" +
33
- "0123456789" +
34
- "0123456789" +
35
- "0123456789" +
36
- "012345"
31
+ str = '0123456789' \
32
+ '0123456789' \
33
+ '0123456789' \
34
+ '0123456789' \
35
+ '0123456789' \
36
+ '0123456789' \
37
+ '012345'
37
38
 
38
39
  f << str
39
40
  end
40
41
 
41
- f = File.open("foo")
42
+ f = File.open('foo')
42
43
  assert_equal 53, f.sysseek(-13, IO::SEEK_END)
43
44
  end
44
- end
45
+ end
@@ -1,5 +1,6 @@
1
- require "test_helper"
1
+ require 'test_helper'
2
2
 
3
+ # File SysWrite test class
3
4
  class FileSysWriteTest < Test::Unit::TestCase
4
5
  def setup
5
6
  FakeFS.activate!
@@ -11,52 +12,52 @@ class FileSysWriteTest < Test::Unit::TestCase
11
12
  end
12
13
 
13
14
  def test_returns_one_byte_when_written
14
- f = File.open "foo", "w"
15
- result = f.syswrite "a"
15
+ f = File.open 'foo', 'w'
16
+ result = f.syswrite 'a'
16
17
  assert_equal 1, result
17
18
  end
18
19
 
19
20
  def test_returns_two_bytes_when_two_written
20
- f = File.open "foo", "w"
21
- result = f.syswrite "ab"
21
+ f = File.open 'foo', 'w'
22
+ result = f.syswrite 'ab'
22
23
  assert_equal 2, result
23
24
  end
24
25
 
25
26
  def test_syswrite_writes_file
26
- f = File.open "foo", "w"
27
- f.syswrite "abcdef"
27
+ f = File.open 'foo', 'w'
28
+ f.syswrite 'abcdef'
28
29
  f.close
29
30
 
30
- assert_equal "abcdef", File.read("foo")
31
+ assert_equal 'abcdef', File.read('foo')
31
32
  end
32
33
 
33
34
  def test_writes_to_the_actual_position_when_called_after_buffered_io_read
34
- File.open("foo", "w") do |file|
35
- file.syswrite("012345678901234567890123456789")
35
+ File.open('foo', 'w') do |file|
36
+ file.syswrite('012345678901234567890123456789')
36
37
  end
37
38
 
38
- file = File.open("foo", "r+")
39
+ file = File.open('foo', 'r+')
39
40
  file.read(5)
40
- file.syswrite("abcde")
41
+ file.syswrite('abcde')
41
42
 
42
- File.open("foo") do |file|
43
- assert_equal "01234abcde", file.sysread(10)
43
+ File.open('foo') do |f|
44
+ assert_equal '01234abcde', f.sysread(10)
44
45
  end
45
46
  end
46
47
 
47
48
  def test_writes_all_of_the_strings_bytes_but_does_not_buffer_them
48
- File.open("foo", "w") do |file|
49
- file.syswrite("012345678901234567890123456789")
49
+ File.open('foo', 'w') do |file|
50
+ file.syswrite('012345678901234567890123456789')
50
51
  end
51
52
 
52
- file = File.open("foo", "r+")
53
- written = file.syswrite("abcde")
53
+ file = File.open('foo', 'r+')
54
+ file.syswrite('abcde')
54
55
 
55
- File.open("foo") do |file|
56
- assert_equal "abcde56789", file.sysread(10)
57
- file.seek(0)
58
- file.fsync
59
- assert_equal "abcde56789", file.sysread(10)
56
+ File.open('foo') do |f|
57
+ assert_equal 'abcde56789', f.sysread(10)
58
+ f.seek(0)
59
+ f.fsync
60
+ assert_equal 'abcde56789', f.sysread(10)
60
61
  end
61
62
  end
62
- end
63
+ end