given_filesystem 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2d439246630c6831a20ad883f60acebde851cc0e
4
+ data.tar.gz: 648b3037218f4fa22b546f5be02660b21b7b51ee
5
+ SHA512:
6
+ metadata.gz: 217cc2eed4e97eb76c986711e81458edbdb23f5317d190cb4294c6c0c5fd6697a3d1a1694787d8b1563ee7877e76e44a65ade3a0cdf19ad6a86fabebe1376e10
7
+ data.tar.gz: e5b0679e414abae396084caf4a1cb38ae6ef2be3117f42594ec1e044ca95cd1cabaaa2e3920d65037bec0eb548f1d1eca21edc4d3e46ca86e9becd71b8a930c1
data/.gitignore CHANGED
@@ -1 +1,4 @@
1
1
  .rspec
2
+ Gemfile.lock
3
+ *.gem
4
+ coverage
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.9.3"
4
+ - "2.1.1"
5
+ - jruby-19mode # JRuby in 1.9 mode
6
+ script: bundle exec rspec spec
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,23 @@
1
+ # How to contribute
2
+
3
+ Contributions to GivenFilesystem are welcome. Its home project is at
4
+ https://github.com/cornelius/given_filesystem.
5
+
6
+ ## Reporting bugs
7
+
8
+ If you find a bug please report it as an issue on the GitHub project. If
9
+ possible include a test case. If you want to go for the perfect bug report
10
+ include a patch and open a pull request.
11
+
12
+ ## Contributing code
13
+
14
+ If you want to fix bugs, add new functionality, or improve existing one, open
15
+ a pull request. All code has to come with tests and be written according to
16
+ the style used in the rest of the code. I also welcome proof-of-concept code
17
+ which is meant to be discussed, and be polished into production code later.
18
+ Code review is fun.
19
+
20
+ ## Sending feedback and asking questions
21
+
22
+ If you have any feedback to share or would just like to ask a question, please
23
+ don't hesitate to [send me an email](mailto:schumacher@kde.org).
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem 'coveralls', require: false
data/README.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # GivenFilesystem
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/given_filesystem.svg)](http://badge.fury.io/rb/given_filesystem)
4
+ [![Build Status](https://travis-ci.org/cornelius/given_filesystem.svg?branch=master)](https://travis-ci.org/cornelius/given_filesystem)
5
+ [![Coverage Status](https://coveralls.io/repos/cornelius/given_filesystem/badge.png?branch=master)](https://coveralls.io/r/cornelius/given_filesystem?branch=master)
6
+ [![Code Climate](https://codeclimate.com/github/cornelius/given_filesystem.png)](https://codeclimate.com/github/cornelius/given_filesystem)
7
+
3
8
  GivenFilesystem is a set of helpers for testing code which operates on file
4
9
  systems. It lets you create temporary directories and files with given content as
5
10
  test data. You can write to these directories and GivenFilesystem takes care of
@@ -17,7 +22,9 @@ To use the GivenFilesystem helpers in a RSpec test you have to include the
17
22
  set up the temporary test directory by calling `use_given_filesystem`:
18
23
 
19
24
  ```ruby
20
- include GivenFileSystemSpecHelpers
25
+ require "given_filesystem/spec_helpers"
26
+
27
+ include GivenFilesystemSpecHelpers
21
28
 
22
29
  describe "some test" do
23
30
  use_given_filesystem
@@ -0,0 +1,17 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'given_filesystem'
3
+ s.version = '0.1.1'
4
+ s.license = 'MIT'
5
+ s.platform = Gem::Platform::RUBY
6
+ s.authors = ['Cornelius Schumacher']
7
+ s.email = ['schumacher@kde.org']
8
+ s.homepage = 'https://github.com/cornelius/given_filesystem'
9
+ s.summary = 'A library for setting up files as test data'
10
+ s.description = 'GivenFilesystem is a set of helpers for testing code which operates on file systems.'
11
+ s.required_rubygems_version = '>= 1.3.6'
12
+ s.rubyforge_project = 'given_filesystem'
13
+
14
+ s.add_development_dependency 'rspec', '~> 3.0'
15
+ s.files = `git ls-files`.split("\n")
16
+ s.require_path = 'lib'
17
+ end
@@ -26,17 +26,17 @@ module GivenFilesystemSpecHelpers
26
26
  end
27
27
 
28
28
  def use_given_filesystem options = {}
29
- before do
29
+ around do |example|
30
30
  @__given_filesystem = GivenFilesystem.new
31
- end
32
31
 
33
- if !options[:keep_files]
34
- after do
32
+ example.run
33
+
34
+ if !options[:keep_files]
35
35
  @__given_filesystem.cleanup
36
36
  end
37
37
  end
38
38
  end
39
-
39
+
40
40
  def given_directory directory_name = nil
41
41
  check_initialization
42
42
  if block_given?
@@ -48,12 +48,12 @@ module GivenFilesystemSpecHelpers
48
48
  end
49
49
  path
50
50
  end
51
-
51
+
52
52
  def given_directory_from_data directory_name, options = {}
53
53
  check_initialization
54
54
  path = @__given_filesystem.directory_from_data directory_name, options[:from]
55
55
  end
56
-
56
+
57
57
  def given_file file_name, options = {}
58
58
  check_initialization
59
59
  if !options[:from]
@@ -61,14 +61,14 @@ module GivenFilesystemSpecHelpers
61
61
  end
62
62
  @__given_filesystem.file file_name, options
63
63
  end
64
-
64
+
65
65
  def given_dummy_file file_name = nil
66
66
  check_initialization
67
67
  @__given_filesystem.file file_name
68
68
  end
69
-
69
+
70
70
  private
71
-
71
+
72
72
  def check_initialization
73
73
  if !@__given_filesystem
74
74
  raise "Call use_given_filesystem before calling other methods"
File without changes
@@ -1,75 +1,75 @@
1
- require File.expand_path('../spec_helper', __FILE__)
1
+ require_relative 'spec_helper'
2
2
 
3
3
  describe GivenFilesystem do
4
-
4
+
5
5
  before(:each) do
6
6
  @given = GivenFilesystem.new
7
7
  end
8
-
8
+
9
9
  after(:each) do
10
10
  @given.cleanup
11
11
  end
12
-
12
+
13
13
  it "creates directory" do
14
14
  path = @given.directory
15
- expect( File.exists? path ).to be_true
16
- expect( File.directory? path ).to be_true
15
+ expect( File.exists? path ).to be(true)
16
+ expect( File.directory? path ).to be(true)
17
17
  expect( path ).to match /tmp/
18
18
  expect( path.split("/").length).to be > 3
19
19
  end
20
-
20
+
21
21
  it "creates nested unnamed directories" do
22
22
  nested_path = nil
23
23
  path = @given.directory do
24
24
  nested_path = @given.directory
25
25
  end
26
- expect( File.exists? nested_path ).to be_true
26
+ expect( File.exists? nested_path ).to be(true)
27
27
  expect( nested_path.split("/").count ).to eq path.split("/").count + 1
28
28
  end
29
-
29
+
30
30
  it "creates named directory" do
31
31
  path = @given.directory "abc"
32
- expect( File.exists? path ).to be_true
32
+ expect( File.exists? path ).to be(true)
33
33
  expect( path ).to match /tmp/
34
34
  expect( path.split("/").length).to be > 4
35
- expect( path ).to match /abc$/
35
+ expect( path ).to match /abc$/
36
36
  end
37
-
37
+
38
38
  it "creates named directory including path" do
39
39
  path = @given.directory "abc"
40
40
  deep_path = @given.directory "x/y/z"
41
- expect( File.exists? deep_path ).to be_true
42
- expect( File.directory? deep_path ).to be_true
41
+ expect( File.exists? deep_path ).to be(true)
42
+ expect( File.directory? deep_path ).to be(true)
43
43
  expect( deep_path.split("/").count ).to eq path.split("/").count + 2
44
44
  end
45
-
45
+
46
46
  it "creates file" do
47
47
  path = @given.file
48
48
  expect( path ).to match /tmp/
49
49
  expect( path.split("/").length).to be > 3
50
- expect( File.exists? path ).to be_true
51
- expect( File.directory? path ).to be_false
50
+ expect( File.exists? path ).to be(true)
51
+ expect( File.directory? path ).to be(false)
52
52
  end
53
-
53
+
54
54
  it "creates named file" do
55
55
  path = @given.file "def"
56
56
  expect( path ).to match /tmp/
57
57
  expect( path.split("/").length).to be > 4
58
58
  expect( path ).to match /def$/
59
59
  end
60
-
60
+
61
61
  it "creates named file including path" do
62
62
  path = @given.file "def"
63
63
  deep_path = @given.file "x/y/z"
64
- expect( File.exists? deep_path ).to be_true
65
- expect( File.directory? deep_path ).to be_false
66
- expect( deep_path.split("/").count ).to eq path.split("/").count + 2
64
+ expect( File.exists? deep_path ).to be(true)
65
+ expect( File.directory? deep_path ).to be(false)
66
+ expect( deep_path.split("/").count ).to eq path.split("/").count + 2
67
67
  end
68
-
68
+
69
69
  it "throws error on invalid test data file name" do
70
70
  expect{@given.file "def", :from => "invalidname"}.to raise_error
71
71
  end
72
-
72
+
73
73
  it "creates file with content" do
74
74
  path = @given.file "def", :from => "testcontent"
75
75
  expect( path ).to match /tmp/
@@ -77,7 +77,7 @@ describe GivenFilesystem do
77
77
  expect( path ).to match /def$/
78
78
  expect( File.read(path) ).to eq "This is my test content.\n"
79
79
  end
80
-
80
+
81
81
  it "creates directory tree" do
82
82
  path = @given.directory do
83
83
  @given.directory "one" do
@@ -88,53 +88,53 @@ describe GivenFilesystem do
88
88
  @given.file "third"
89
89
  end
90
90
  end
91
-
92
- expect( File.exists? path).to be_true
93
- expect( File.directory? path).to be_true
94
- expect( File.exists? File.join(path,"one")).to be_true
95
- expect( File.exists? File.join(path,"one")).to be_true
96
- expect( File.directory? File.join(path,"one")).to be_true
97
- expect( File.directory? File.join(path,"two")).to be_true
98
- expect( File.exists? File.join(path,"one","first")).to be_true
99
- expect( File.exists? File.join(path,"two","second")).to be_true
100
- expect( File.exists? File.join(path,"two","third")).to be_true
101
- end
102
-
91
+
92
+ expect( File.exists? path).to be(true)
93
+ expect( File.directory? path).to be(true)
94
+ expect( File.exists? File.join(path,"one")).to be(true)
95
+ expect( File.exists? File.join(path,"one")).to be(true)
96
+ expect( File.directory? File.join(path,"one")).to be(true)
97
+ expect( File.directory? File.join(path,"two")).to be(true)
98
+ expect( File.exists? File.join(path,"one","first")).to be(true)
99
+ expect( File.exists? File.join(path,"two","second")).to be(true)
100
+ expect( File.exists? File.join(path,"two","third")).to be(true)
101
+ end
102
+
103
103
  it "creates directory from data" do
104
104
  path = @given.directory_from_data( "welcome" )
105
105
  expect( path ).to match /\/welcome$/
106
- expect( File.exists? path ).to be_true
107
- expect( File.directory? path ).to be_true
108
-
109
- expect( File.exist? File.join( path, "universe" ) ).to be_true
110
- expect( File.directory? File.join( path, "universe" ) ).to be_false
106
+ expect( File.exists? path ).to be(true)
107
+ expect( File.directory? path ).to be(true)
108
+
109
+ expect( File.exist? File.join( path, "universe" ) ).to be(true)
110
+ expect( File.directory? File.join( path, "universe" ) ).to be(false)
111
111
  expect( File.read( File.join( path, "universe" ) ) ).to eq "I was here\n"
112
-
113
- expect( File.exist? File.join( path, "space" ) ).to be_true
114
- expect( File.directory? File.join( path, "space" ) ).to be_true
112
+
113
+ expect( File.exist? File.join( path, "space" ) ).to be(true)
114
+ expect( File.directory? File.join( path, "space" ) ).to be(true)
115
115
  end
116
-
116
+
117
117
  it "creates directory from data under different name" do
118
118
  path = @given.directory_from_data( "hi", "welcome" )
119
119
  expect( path ).to match /\/hi$/
120
- expect( File.exists? path ).to be_true
121
- expect( File.directory? path ).to be_true
122
-
123
- expect( File.exist? File.join( path, "universe" ) ).to be_true
124
- expect( File.directory? File.join( path, "universe" ) ).to be_false
120
+ expect( File.exists? path ).to be(true)
121
+ expect( File.directory? path ).to be(true)
122
+
123
+ expect( File.exist? File.join( path, "universe" ) ).to be(true)
124
+ expect( File.directory? File.join( path, "universe" ) ).to be(false)
125
125
  expect( File.read( File.join( path, "universe" ) ) ).to eq "I was here\n"
126
-
127
- expect( File.exist? File.join( path, "space" ) ).to be_true
128
- expect( File.directory? File.join( path, "space" ) ).to be_true
126
+
127
+ expect( File.exist? File.join( path, "space" ) ).to be(true)
128
+ expect( File.directory? File.join( path, "space" ) ).to be(true)
129
129
  end
130
-
130
+
131
131
  it "returns paths" do
132
132
  path1 = @given.directory "one"
133
133
  expect( path1 ).to match /^\/tmp\/given_filesystem\/[\d-]+\/one$/
134
134
 
135
135
  path2 = @given.directory "two"
136
136
  expect( path2 ).to match /^\/tmp\/given_filesystem\/[\d-]+\/two$/
137
-
137
+
138
138
  path3 = @given.directory "three" do
139
139
  @given.file "first"
140
140
  end
@@ -145,14 +145,14 @@ describe GivenFilesystem do
145
145
  given = GivenFilesystem.new
146
146
  path1 = given.directory
147
147
  path2 = given.directory
148
-
149
- expect( File.exists? path1).to be_true
150
- expect( File.exists? path2).to be_true
151
-
148
+
149
+ expect( File.exists? path1).to be(true)
150
+ expect( File.exists? path2).to be(true)
151
+
152
152
  given.cleanup
153
-
154
- expect( File.exists? path1).to be_false
155
- expect( File.exists? path2).to be_false
153
+
154
+ expect( File.exists? path1).to be(false)
155
+ expect( File.exists? path2).to be(false)
156
156
  end
157
157
 
158
158
  end
@@ -1,6 +1,6 @@
1
- require File.expand_path('../spec_helper', __FILE__)
1
+ require_relative 'spec_helper'
2
2
 
3
- describe GivenFilesystem do
3
+ describe GivenFilesystemSpecHelpers do
4
4
 
5
5
  include GivenFilesystemSpecHelpers
6
6
 
@@ -10,41 +10,52 @@ describe GivenFilesystem do
10
10
  expect{ given_directory }.to raise_error /given_filesystem/
11
11
  end
12
12
  end
13
-
13
+
14
14
  describe "#given_file" do
15
15
  it "raises error" do
16
16
  expect{ given_directory }.to raise_error /given_filesystem/
17
17
  end
18
18
  end
19
19
  end
20
-
20
+
21
21
  context "with keeping of files enabled" do
22
22
  use_given_filesystem :keep_files => true
23
-
23
+
24
24
  it "creates directories" do
25
25
  path = given_directory "hello"
26
- expect( File.exists? path ).to be_true
27
-
26
+ expect( File.exists? path ).to be(true)
27
+
28
28
  # Manually clean up, so test doesn't leave files around
29
29
  @__given_filesystem.cleanup
30
- end
30
+ end
31
31
  end
32
-
32
+
33
33
  context "using the module" do
34
34
  use_given_filesystem
35
35
 
36
+ context "in around filters" do
37
+ around(:each) do |example|
38
+ given_directory
39
+ example.run
40
+ end
41
+
42
+ it "works" do
43
+ expect(true).to be true
44
+ end
45
+ end
46
+
36
47
  describe "#given_directory" do
37
48
  it "creates unnamed directory" do
38
49
  path = given_directory
39
- expect( File.exists? path ).to be_true
40
- expect( File.directory? path ).to be_true
50
+ expect( File.exists? path ).to be(true)
51
+ expect( File.directory? path ).to be(true)
41
52
  end
42
-
53
+
43
54
  it "creates directory" do
44
55
  path = given_directory "hello"
45
- expect( path ).to match /\/hello$/
56
+ expect( path ).to match /\/hello$/
46
57
  end
47
-
58
+
48
59
  it "creates nested directory" do
49
60
  path = nil
50
61
  given_directory "hello" do
@@ -53,13 +64,13 @@ describe GivenFilesystem do
53
64
  expect( path ).to match /\/hello\/world$/
54
65
  end
55
66
  end
56
-
67
+
57
68
  describe "#give_directory_from_data" do
58
69
  it "creates directory with content from data" do
59
70
  path = given_directory_from_data "welcome"
60
71
  expect( path ).to match /\/welcome$/
61
72
  end
62
-
73
+
63
74
  it "creates directory with content from named data" do
64
75
  path = given_directory_from_data "hi", :from => "welcome"
65
76
  expect( path ).to match /\/hi$/
@@ -69,15 +80,15 @@ describe GivenFilesystem do
69
80
  describe "#given_dummy_file" do
70
81
  it "creates unnamed dummy file" do
71
82
  path = given_dummy_file
72
- expect( File.exists? path ).to be_true
73
- expect( File.directory? path ).to be_false
83
+ expect( File.exists? path ).to be(true)
84
+ expect( File.directory? path ).to be(false)
74
85
  end
75
-
86
+
76
87
  it "creates named dummy file" do
77
88
  path = given_dummy_file "welcome"
78
89
  expect( path ).to match /\/welcome$/
79
- expect( File.exists? path ).to be_true
80
- expect( File.directory? path ).to be_false
90
+ expect( File.exists? path ).to be(true)
91
+ expect( File.directory? path ).to be(false)
81
92
  end
82
93
  end
83
94
 
@@ -87,19 +98,19 @@ describe GivenFilesystem do
87
98
  expect( path ).to match /\/testcontent$/
88
99
  expect( File.read( path ) ).to eq "This is my test content.\n"
89
100
  end
90
-
101
+
91
102
  it "creates file with content and given filename" do
92
103
  path = given_file "welcome", :from => "testcontent"
93
104
  expect( path ).to match /\/welcome$/
94
105
  expect( File.read( path ) ).to eq "This is my test content.\n"
95
106
  end
96
-
107
+
97
108
  it "creates file in directory" do
98
109
  path = nil
99
110
  given_directory "hello" do
100
111
  path = given_file "world", :from => "testcontent"
101
112
  end
102
- expect( File.exists? path ).to be_true
113
+ expect( File.exists? path ).to be(true)
103
114
  expect( File.read( path ) ).to eq "This is my test content.\n"
104
115
  end
105
116
  end
data/spec/spec_helper.rb CHANGED
@@ -1 +1,8 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
4
+ Coveralls::SimpleCov::Formatter,
5
+ SimpleCov::Formatter::HTMLFormatter
6
+ ]
7
+
1
8
  require_relative('../lib/given_filesystem/spec_helpers')
metadata CHANGED
@@ -1,32 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: given_filesystem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
5
- prerelease:
4
+ version: 0.1.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Cornelius Schumacher
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-04-20 00:00:00.000000000 Z
11
+ date: 2014-12-09 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rspec
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ~>
20
18
  - !ruby/object:Gem::Version
21
- version: '0'
19
+ version: '3.0'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ~>
28
25
  - !ruby/object:Gem::Version
29
- version: '0'
26
+ version: '3.0'
30
27
  description: GivenFilesystem is a set of helpers for testing code which operates on
31
28
  file systems.
32
29
  email:
@@ -37,38 +34,43 @@ extra_rdoc_files: []
37
34
  files:
38
35
  - .gitignore
39
36
  - .rspec
37
+ - .travis.yml
38
+ - CONTRIBUTING.md
39
+ - Gemfile
40
40
  - MIT-LICENSE
41
41
  - README.md
42
+ - given_filesystem.gemspec
42
43
  - lib/given_filesystem.rb
43
44
  - lib/given_filesystem/spec_helpers.rb
44
45
  - spec/data/testcontent
46
+ - spec/data/welcome/space/.gitkeep
45
47
  - spec/data/welcome/universe
46
48
  - spec/given_filesystem_spec.rb
47
49
  - spec/given_filesystem_spec_helpers_spec.rb
48
50
  - spec/spec_helper.rb
49
- homepage: http://github.com/cornelius/given_filesystem
51
+ homepage: https://github.com/cornelius/given_filesystem
50
52
  licenses:
51
53
  - MIT
54
+ metadata: {}
52
55
  post_install_message:
53
56
  rdoc_options: []
54
57
  require_paths:
55
58
  - lib
56
59
  required_ruby_version: !ruby/object:Gem::Requirement
57
- none: false
58
60
  requirements:
59
- - - ! '>='
61
+ - - '>='
60
62
  - !ruby/object:Gem::Version
61
63
  version: '0'
62
64
  required_rubygems_version: !ruby/object:Gem::Requirement
63
- none: false
64
65
  requirements:
65
- - - ! '>='
66
+ - - '>='
66
67
  - !ruby/object:Gem::Version
67
68
  version: 1.3.6
68
69
  requirements: []
69
70
  rubyforge_project: given_filesystem
70
- rubygems_version: 1.8.23
71
+ rubygems_version: 2.0.3
71
72
  signing_key:
72
- specification_version: 3
73
+ specification_version: 4
73
74
  summary: A library for setting up files as test data
74
75
  test_files: []
76
+ has_rdoc: