given_filesystem 0.1.2 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a37adf41c7d8b7794308031e8b4a8ea85fef4f93
4
- data.tar.gz: 0bbe94f7a57c0f418b8a5f321047e95f50e7ff03
3
+ metadata.gz: 06be97bc39f061126037e6f7ed7e21581bdce16b
4
+ data.tar.gz: 1abc20b941f24f30f7caea95065126f286bb99f6
5
5
  SHA512:
6
- metadata.gz: be97672d47aee8a66d4cd06b6e649fc1a67cc95414841de7d6c6abc0c9cba0011ac83dbb312002b37fb2773193036389dc5180e9f827c85a3f41241fc6327971
7
- data.tar.gz: edfb0e6c40550d33ea19bc4ca0ffe718cdc05050e2e954da38aaac0a5bb50a3e2bd40a4addf89911e087790a28af8c34246102538950b5ee62bad12610a38013
6
+ metadata.gz: 2bc0d5f0bb84bcdc9b8c512942c894640eeb76b7eff4546401775fe57c073a7f6ea3ef9deb9298fccc642a45e0d275b4e8e65a9af60e88faa641f02362d8675f
7
+ data.tar.gz: 548e6eb38db34e22bd4ffee2577466dd20d7c14ea93ee37043734b4a6f064f6f5d8f81670ec13ba35b03b79478ceec42d4da369cb1b678b2b3b3f8bc2f84af46
@@ -1,6 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - "1.9.3"
4
3
  - "2.1.1"
5
- - jruby-19mode # JRuby in 1.9 mode
4
+ - "2.3.1"
6
5
  script: bundle exec rspec spec
@@ -1,6 +1,8 @@
1
+ require_relative "lib/version.rb"
2
+
1
3
  Gem::Specification.new do |s|
2
4
  s.name = 'given_filesystem'
3
- s.version = '0.1.2'
5
+ s.version = VERSION
4
6
  s.license = 'MIT'
5
7
  s.platform = Gem::Platform::RUBY
6
8
  s.authors = ['Cornelius Schumacher']
@@ -35,16 +35,19 @@ class GivenFilesystem
35
35
  end
36
36
  end
37
37
 
38
- def directory dir_name = nil
38
+ def directory user_provided_directory = nil
39
39
  create_random_base_path unless path_has_base?
40
40
 
41
- @path_elements.push dir_name || random_name
41
+ directory_to_create = user_provided_directory || random_name
42
+
43
+ @path_elements.push directory_to_create
42
44
 
43
45
  created_path = path
44
46
  FileUtils.mkdir_p created_path
45
47
  yield if block_given?
46
48
  @path_elements.pop
47
- created_path
49
+
50
+ File.join path, first_segment_of_path(directory_to_create)
48
51
  end
49
52
 
50
53
  def directory_from_data to, from = nil
@@ -110,4 +113,8 @@ class GivenFilesystem
110
113
  def test_data_path name
111
114
  File.expand_path('spec/data/' + name)
112
115
  end
116
+
117
+ def first_segment_of_path path
118
+ path.split(File::SEPARATOR).reject(&:empty?).first
119
+ end
113
120
  end
@@ -10,11 +10,13 @@ describe GivenFilesystem do
10
10
  @given.cleanup
11
11
  end
12
12
 
13
+ let(:os_specific_tmp_path) { Dir.tmpdir }
14
+
13
15
  it "creates directory" do
14
16
  path = @given.directory
15
17
  expect( File.exists? path ).to be(true)
16
18
  expect( File.directory? path ).to be(true)
17
- expect( path ).to match /tmp/
19
+ expect( path ).to be_located_under os_specific_tmp_path
18
20
  expect( path.split("/").length).to be > 3
19
21
  end
20
22
 
@@ -30,7 +32,7 @@ describe GivenFilesystem do
30
32
  it "creates named directory" do
31
33
  path = @given.directory "abc"
32
34
  expect( File.exists? path ).to be(true)
33
- expect( path ).to match /tmp/
35
+ expect( path ).to be_located_under os_specific_tmp_path
34
36
  expect( path.split("/").length).to be > 4
35
37
  expect( path ).to match /abc$/
36
38
  end
@@ -40,12 +42,12 @@ describe GivenFilesystem do
40
42
  deep_path = @given.directory "x/y/z"
41
43
  expect( File.exists? deep_path ).to be(true)
42
44
  expect( File.directory? deep_path ).to be(true)
43
- expect( deep_path.split("/").count ).to eq path.split("/").count + 2
45
+ expect( deep_path.split("/").count ).to eq path.split("/").count
44
46
  end
45
47
 
46
48
  it "creates file" do
47
49
  path = @given.file
48
- expect( path ).to match /tmp/
50
+ expect( path ).to be_located_under os_specific_tmp_path
49
51
  expect( path.split("/").length).to be > 3
50
52
  expect( File.exists? path ).to be(true)
51
53
  expect( File.directory? path ).to be(false)
@@ -53,7 +55,7 @@ describe GivenFilesystem do
53
55
 
54
56
  it "creates named file" do
55
57
  path = @given.file "def"
56
- expect( path ).to match /tmp/
58
+ expect( path ).to be_located_under os_specific_tmp_path
57
59
  expect( path.split("/").length).to be > 4
58
60
  expect( path ).to match /def$/
59
61
  end
@@ -72,7 +74,7 @@ describe GivenFilesystem do
72
74
 
73
75
  it "creates file with content" do
74
76
  path = @given.file "def", :from => "testcontent"
75
- expect( path ).to match /tmp/
77
+ expect( path ).to be_located_under os_specific_tmp_path
76
78
  expect( path.split("/").length).to be > 4
77
79
  expect( path ).to match /def$/
78
80
  expect( File.read(path) ).to eq "This is my test content.\n"
@@ -81,11 +83,11 @@ describe GivenFilesystem do
81
83
  it "creates directory tree" do
82
84
  path = @given.directory do
83
85
  @given.directory "one" do
84
- @given.file "first"
86
+ @given.file "first"
85
87
  end
86
88
  @given.directory "two" do
87
- @given.file "second"
88
- @given.file "third"
89
+ @given.file "second"
90
+ @given.file "third"
89
91
  end
90
92
  end
91
93
 
@@ -140,15 +142,15 @@ describe GivenFilesystem do
140
142
 
141
143
  it "returns paths" do
142
144
  path1 = @given.directory "one"
143
- expect( path1 ).to match /^\/tmp\/given_filesystem\/[\d-]+\/one$/
145
+ expect( path1 ).to match /^#{Regexp.quote os_specific_tmp_path}\/given_filesystem\/[\d-]+\/one$/
144
146
 
145
147
  path2 = @given.directory "two"
146
- expect( path2 ).to match /^\/tmp\/given_filesystem\/[\d-]+\/two$/
148
+ expect( path2 ).to match /^#{Regexp.quote os_specific_tmp_path}\/given_filesystem\/[\d-]+\/two$/
147
149
 
148
150
  path3 = @given.directory "three" do
149
151
  @given.file "first"
150
152
  end
151
- expect( path3 ).to match /^\/tmp\/given_filesystem\/[\d-]+\/three$/
153
+ expect( path3 ).to match /^#{Regexp.quote os_specific_tmp_path}\/given_filesystem\/[\d-]+\/three$/
152
154
  end
153
155
 
154
156
  it "cleans up directory tree" do
@@ -56,6 +56,11 @@ describe GivenFilesystemSpecHelpers do
56
56
  expect( path ).to match /\/hello$/
57
57
  end
58
58
 
59
+ it "creates entire directory structure" do
60
+ path = given_directory "some/directory/structure"
61
+ expect( path ).to match /\/some$/
62
+ end
63
+
59
64
  it "creates nested directory" do
60
65
  path = nil
61
66
  given_directory "hello" do
@@ -1,8 +1,6 @@
1
1
  require 'coveralls'
2
2
  Coveralls.wear!
3
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
4
- Coveralls::SimpleCov::Formatter,
5
- SimpleCov::Formatter::HTMLFormatter
6
- ]
7
3
 
8
4
  require_relative('../lib/given_filesystem/spec_helpers')
5
+
6
+ require_relative 'support/matchers/file_location_matcher'
@@ -0,0 +1,8 @@
1
+ require 'pathname'
2
+ require 'rspec/expectations'
3
+
4
+ RSpec::Matchers.define :be_located_under do |expected|
5
+ match do |actual|
6
+ Pathname.new(actual).fnmatch? File.join(expected, '**')
7
+ end
8
+ end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: given_filesystem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cornelius Schumacher
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-14 00:00:00.000000000 Z
11
+ date: 2017-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.0'
27
27
  description: GivenFilesystem is a set of helpers for testing code which operates on
@@ -32,9 +32,9 @@ executables: []
32
32
  extensions: []
33
33
  extra_rdoc_files: []
34
34
  files:
35
- - .gitignore
36
- - .rspec
37
- - .travis.yml
35
+ - ".gitignore"
36
+ - ".rspec"
37
+ - ".travis.yml"
38
38
  - CONTRIBUTING.md
39
39
  - Gemfile
40
40
  - MIT-LICENSE
@@ -49,6 +49,7 @@ files:
49
49
  - spec/given_filesystem_spec.rb
50
50
  - spec/given_filesystem_spec_helpers_spec.rb
51
51
  - spec/spec_helper.rb
52
+ - spec/support/matchers/file_location_matcher.rb
52
53
  homepage: https://github.com/cornelius/given_filesystem
53
54
  licenses:
54
55
  - MIT
@@ -59,17 +60,17 @@ require_paths:
59
60
  - lib
60
61
  required_ruby_version: !ruby/object:Gem::Requirement
61
62
  requirements:
62
- - - '>='
63
+ - - ">="
63
64
  - !ruby/object:Gem::Version
64
65
  version: '0'
65
66
  required_rubygems_version: !ruby/object:Gem::Requirement
66
67
  requirements:
67
- - - '>='
68
+ - - ">="
68
69
  - !ruby/object:Gem::Version
69
70
  version: 1.3.6
70
71
  requirements: []
71
72
  rubyforge_project: given_filesystem
72
- rubygems_version: 2.0.3
73
+ rubygems_version: 2.5.1
73
74
  signing_key:
74
75
  specification_version: 4
75
76
  summary: A library for setting up files as test data