tempfile-fixture 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rubocop.yml +8 -0
- data/.travis.yml +5 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +22 -0
- data/LICENSE.txt +21 -0
- data/README.md +70 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/tempfile/fixture.rb +77 -0
- data/lib/tempfile/fixture/version.rb +7 -0
- data/tempfile-fixture.gemspec +41 -0
- metadata +104 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d9ae187a31c857bced9c5113942e3aa4f881c19e
|
4
|
+
data.tar.gz: ba102455221cd6a401a8d0cc923ea6a71c744ea5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2741c37535e72ab6a1cac4dcc91ab2eca3f91d0017eabeca1b2a1781316c06d3a7aecef78c8f59d2855ee6d0c1051a3985bb782ecc6200a25210651de1b1071c
|
7
|
+
data.tar.gz: b1fd6b428c796ec9f18cb40e607e06a2ec22b3433cfe85325d2f05b1aece471c16a0ea0788d2ad83a454c17863f389e242b425e008e98fb023de4edad34f67f5
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
tempfile-fixture (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
minitest (5.11.3)
|
10
|
+
rake (10.5.0)
|
11
|
+
|
12
|
+
PLATFORMS
|
13
|
+
x64-mingw32
|
14
|
+
|
15
|
+
DEPENDENCIES
|
16
|
+
bundler (~> 1.16)
|
17
|
+
minitest (~> 5.0)
|
18
|
+
rake (~> 10.0)
|
19
|
+
tempfile-fixture!
|
20
|
+
|
21
|
+
BUNDLED WITH
|
22
|
+
1.16.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Derk-Jan Karrenbeld
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# Tempfile::Fixture
|
2
|
+
|
3
|
+
Have tempfile serve you IO fixtures.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'tempfile-fixture'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install tempfile-fixture
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
You can use the `Fixture` functionality anywhere. This is how you might use it:
|
24
|
+
|
25
|
+
```Ruby
|
26
|
+
# /test/test_helper.rb
|
27
|
+
|
28
|
+
require 'tempfile/fixture'
|
29
|
+
|
30
|
+
def path_to_fixture(file)
|
31
|
+
File.expand_path(File.join('files', file), __dir__)
|
32
|
+
end
|
33
|
+
```
|
34
|
+
```Text
|
35
|
+
# /test/files/data.txt
|
36
|
+
42
|
37
|
+
11
|
38
|
+
99
|
39
|
+
23
|
40
|
+
12
|
41
|
+
```
|
42
|
+
```Ruby
|
43
|
+
# /test/my_fixture_test.rb
|
44
|
+
|
45
|
+
require_relative 'test_helper'
|
46
|
+
|
47
|
+
def test_calculate_sum
|
48
|
+
Tempfile.Fixture(path_to_fixture('data.txt')) do |data_file|
|
49
|
+
answer = calculate_sum(data_file.readlines)
|
50
|
+
assert_equal 187, answer
|
51
|
+
end
|
52
|
+
end
|
53
|
+
```
|
54
|
+
|
55
|
+
Under the hood it's doing a `FileUtils` copy_file, so it will fail on directories (yay); you can pass `binary: true` to
|
56
|
+
force the tempfile to have a binary encoding. This probably doesn't do anything :'), because it's copying metadata as
|
57
|
+
well.
|
58
|
+
|
59
|
+
## Development
|
60
|
+
|
61
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can
|
62
|
+
also run `bin/console` for an interactive prompt that will allow you to experiment.
|
63
|
+
|
64
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the
|
65
|
+
version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version,
|
66
|
+
push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
67
|
+
|
68
|
+
## Contributing
|
69
|
+
|
70
|
+
Bug reports and pull requests are welcome on GitHub at [https://github.com/SleeplessByte/tempfile-fixture](https://github.com/SleeplessByte/tempfile-fixture).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'tempfile/fixture'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'tempfile'
|
3
|
+
require 'tempfile/fixture/version'
|
4
|
+
|
5
|
+
# Do a class eval to get around supercall mismatch across versions / implementations
|
6
|
+
# rubocop:disable Metrics/BlockLength
|
7
|
+
Tempfile.class_eval do
|
8
|
+
|
9
|
+
##
|
10
|
+
# Fixture class for Tempfiles.
|
11
|
+
#
|
12
|
+
# @example Load a fixture file as a tempfile
|
13
|
+
#
|
14
|
+
# Tempfile.Fixture('/path/to/data.txt').copy do |tempfile|
|
15
|
+
# # do something with the tempfile
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# # the tempfile should be gone
|
19
|
+
#
|
20
|
+
# @example Don't unlink the tempfile
|
21
|
+
#
|
22
|
+
# tempfile = Tempfile::Fixture.new('/path/to/data.txt').copy!
|
23
|
+
# tempfile # => the tempfile
|
24
|
+
#
|
25
|
+
class Fixture
|
26
|
+
def initialize(path, tempfile_options: {})
|
27
|
+
self.fixture = path
|
28
|
+
self.tempfile_options = tempfile_options
|
29
|
+
end
|
30
|
+
|
31
|
+
def copy!
|
32
|
+
file = Tempfile.new(tempfile_args, tempfile_options)
|
33
|
+
FileUtils.copy_file(fixture, file.path, true)
|
34
|
+
yield file if block_given?
|
35
|
+
file
|
36
|
+
end
|
37
|
+
|
38
|
+
def copy(&block)
|
39
|
+
file = copy!(&block)
|
40
|
+
self
|
41
|
+
ensure
|
42
|
+
file.close unless file.closed?
|
43
|
+
|
44
|
+
# Silently fail (hello windows)
|
45
|
+
file.unlink rescue nil # rubocop:disable Style/RescueModifier
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def tempfile_args
|
52
|
+
name = File.basename(fixture)
|
53
|
+
ext = File.extname(fixture)
|
54
|
+
|
55
|
+
# Some files don't have an extension!
|
56
|
+
return name unless ext && ext.length.positive?
|
57
|
+
|
58
|
+
[name, ext.start_with?('.') ? ext : ".#{ext}"]
|
59
|
+
end
|
60
|
+
|
61
|
+
attr_accessor :fixture, :tempfile_options
|
62
|
+
end
|
63
|
+
|
64
|
+
# noinspection RubyConstantNamingConvention
|
65
|
+
TempfileFixture = Fixture
|
66
|
+
|
67
|
+
# noinspection RubyClassMethodNamingConvention
|
68
|
+
def self.Fixture(path, binary: false, &block)
|
69
|
+
raise ArgumentError, 'no block given' unless block_given?
|
70
|
+
raise ArgumentError, 'no path given' unless path && path.length.positive?
|
71
|
+
encoding = binary ? 'ascii-8bit' : 'utf-8'
|
72
|
+
|
73
|
+
TempfileFixture.new(path, tempfile_options: { encoding: encoding })
|
74
|
+
.copy(&block)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
# rubocop:enable Metrics/BlockLength
|
@@ -0,0 +1,41 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path('lib', __dir__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'tempfile/fixture/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'tempfile-fixture'
|
8
|
+
spec.version = Tempfile::Fixture::VERSION
|
9
|
+
spec.authors = ['Derk-Jan Karrenbeld']
|
10
|
+
spec.email = ['derk-jan+github@karrenbeld.info']
|
11
|
+
|
12
|
+
spec.license = 'MIT'
|
13
|
+
spec.summary = 'Temporarily copy a file to a Tempfile, for testing'
|
14
|
+
|
15
|
+
spec.metadata = {
|
16
|
+
'bug_tracker_uri' => 'https://github.com/SleeplessByte/tempfile-fixture/issues',
|
17
|
+
'changelog_uri' => 'https://github.com/SleeplessByte/tempfile-fixture/CHANGELOG.md',
|
18
|
+
'homepage_uri' => 'https://github.com/SleeplessByte/tempfile-fixture',
|
19
|
+
'source_code_uri' => 'https://github.com/SleeplessByte/tempfile-fixture'
|
20
|
+
}
|
21
|
+
|
22
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
23
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
24
|
+
if spec.respond_to?(:metadata)
|
25
|
+
# spec.metadata['allowed_push_host'] = 'https://gems.sleeplessbyte.technology'
|
26
|
+
else
|
27
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
28
|
+
'public gem pushes.'
|
29
|
+
end
|
30
|
+
|
31
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
32
|
+
f.match(%r{^(test|spec|features)/})
|
33
|
+
end
|
34
|
+
spec.bindir = 'exe'
|
35
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
36
|
+
spec.require_paths = ['lib']
|
37
|
+
|
38
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
39
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
40
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
41
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tempfile-fixture
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Derk-Jan Karrenbeld
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-06-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- derk-jan+github@karrenbeld.info
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rubocop.yml"
|
64
|
+
- ".travis.yml"
|
65
|
+
- CHANGELOG.md
|
66
|
+
- Gemfile
|
67
|
+
- Gemfile.lock
|
68
|
+
- LICENSE.txt
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- bin/console
|
72
|
+
- bin/setup
|
73
|
+
- lib/tempfile/fixture.rb
|
74
|
+
- lib/tempfile/fixture/version.rb
|
75
|
+
- tempfile-fixture.gemspec
|
76
|
+
homepage:
|
77
|
+
licenses:
|
78
|
+
- MIT
|
79
|
+
metadata:
|
80
|
+
bug_tracker_uri: https://github.com/SleeplessByte/tempfile-fixture/issues
|
81
|
+
changelog_uri: https://github.com/SleeplessByte/tempfile-fixture/CHANGELOG.md
|
82
|
+
homepage_uri: https://github.com/SleeplessByte/tempfile-fixture
|
83
|
+
source_code_uri: https://github.com/SleeplessByte/tempfile-fixture
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
requirements: []
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 2.6.14.1
|
101
|
+
signing_key:
|
102
|
+
specification_version: 4
|
103
|
+
summary: Temporarily copy a file to a Tempfile, for testing
|
104
|
+
test_files: []
|