Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sleeplessbyte/tempfile-fixture
:clipboard: Have tempfile serve you IO fixtures.
https://github.com/sleeplessbyte/tempfile-fixture
fixtures minitest rspec tempfile
Last synced: 21 days ago
JSON representation
:clipboard: Have tempfile serve you IO fixtures.
- Host: GitHub
- URL: https://github.com/sleeplessbyte/tempfile-fixture
- Owner: SleeplessByte
- License: mit
- Created: 2018-06-04T15:26:10.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-08-21T16:11:52.000Z (6 months ago)
- Last Synced: 2024-10-18T19:46:18.462Z (4 months ago)
- Topics: fixtures, minitest, rspec, tempfile
- Language: Ruby
- Homepage:
- Size: 18.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Tempfile::Fixture
[![Build Status](https://travis-ci.com/SleeplessByte/tempfile-fixture.svg?branch=master)](https://travis-ci.com/SleeplessByte/tempfile-fixture)
[![Gem Version](https://badge.fury.io/rb/tempfile-fixture.svg)](https://badge.fury.io/rb/tempfile-fixture)
[![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT)
[![Maintainability](https://api.codeclimate.com/v1/badges/81343312052cc8900382/maintainability)](https://codeclimate.com/github/SleeplessByte/tempfile-fixture/maintainability)Have tempfile serve you IO fixtures.
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'tempfile-fixture'
```And then execute:
$ bundle
Or install it yourself as:
$ gem install tempfile-fixture
## Usage
You can use the `Fixture` functionality anywhere. This is how you might use it:
```Ruby
# /test/test_helper.rb
require 'tempfile/fixture'def path_to_fixture(file)
File.expand_path(File.join('files', file), __dir__)
end
```
```Text
# /test/files/data.txt
42
11
99
23
12
```
```Ruby
# /test/my_fixture_test.rbrequire_relative 'test_helper'
def test_calculate_sum
Tempfile.Fixture(path_to_fixture('data.txt')) do |data_file|
answer = calculate_sum(data_file.readlines)
assert_equal 187, answer
end
end
```Under the hood it's doing a `FileUtils` copy_file, so it will fail on directories (yay); you can pass `binary: true` to
force the tempfile to have a binary encoding. This probably doesn't do anything :'), because it's copying metadata as
well.## Development
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can
also run `bin/console` for an interactive prompt that will allow you to experiment.To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the
version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version,
push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).## Contributing
Bug reports and pull requests are welcome on GitHub at [https://github.com/SleeplessByte/tempfile-fixture](https://github.com/SleeplessByte/tempfile-fixture).