sugar_utils 0.5.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/ci.yml +17 -0
- data/.gitignore +0 -1
- data/.rubocop.yml +30 -3
- data/.ruby-version +1 -0
- data/CHANGELOG.md +23 -0
- data/README.md +47 -19
- data/Rakefile +36 -8
- data/doc/dependency_decisions.yml +25 -0
- data/features/append_file.feature +46 -0
- data/features/atomic_write_file.feature +46 -0
- data/features/change_file_access.feature +27 -0
- data/features/ensure_boolean.feature +34 -0
- data/features/ensure_integer.feature +19 -0
- data/features/lock_file.feature +26 -0
- data/features/read_file.feature +30 -0
- data/features/read_json_file.feature +43 -0
- data/features/scrub_encoding.feature +25 -0
- data/features/step_definitions/steps.rb +38 -0
- data/features/support/env.rb +34 -0
- data/features/touch_file.feature +28 -0
- data/features/write_file.feature +46 -0
- data/features/write_json_file.feature +52 -0
- data/lib/sugar_utils/file/write_options.rb +56 -0
- data/lib/sugar_utils/file.rb +219 -76
- data/lib/sugar_utils/version.rb +1 -2
- data/lib/sugar_utils.rb +34 -4
- data/spec/spec_helper.rb +8 -6
- data/spec/sugar_utils/file/write_options_spec.rb +77 -0
- data/spec/sugar_utils/file_spec.rb +392 -80
- data/spec/sugar_utils_spec.rb +41 -13
- data/sugar_utils.gemspec +21 -13
- metadata +125 -40
- data/.travis.yml +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a82e583baf8090370611445ae00050bf247d2687d947d84d98fbbac7f8cd1cbe
|
4
|
+
data.tar.gz: 134411bdbc2a675dfc799d73a6d25d5dc0d8760bd8bc3a0583611a7cd1cb50a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3fe928e0ec9a19db849034a7691cd44231282f7dbb58dba921d50f62f3403f9f2abf6fdb9c576182c4abc22b50498aee871a3faa7f82879aabe14678cc831845
|
7
|
+
data.tar.gz: d54adcfcaf340cbbf81fb40bd520c772e80c825b3dc02788d0c70fb608f58abf66d84811e163e830968b13cee3e1b6789c6096df24c02ef297fd6fa3fe147e83
|
@@ -0,0 +1,17 @@
|
|
1
|
+
name: CI
|
2
|
+
on: [push]
|
3
|
+
jobs:
|
4
|
+
test:
|
5
|
+
strategy:
|
6
|
+
fail-fast: false
|
7
|
+
matrix:
|
8
|
+
os: [ubuntu-latest, macos-latest]
|
9
|
+
ruby: ['2.6', '2.7', '3.0', '3.1', '3.2', head]
|
10
|
+
runs-on: ${{ matrix.os }}
|
11
|
+
steps:
|
12
|
+
- uses: actions/checkout@v3
|
13
|
+
- uses: ruby/setup-ruby@v1
|
14
|
+
with:
|
15
|
+
ruby-version: ${{ matrix.ruby }}
|
16
|
+
bundler-cache: true
|
17
|
+
- run: bundle exec rake
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -1,13 +1,40 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require: rubocop-rspec
|
2
|
+
|
3
|
+
AllCops:
|
4
|
+
TargetRubyVersion: 2.6
|
5
|
+
NewCops: enable
|
3
6
|
|
4
|
-
|
7
|
+
Layout/HashAlignment:
|
8
|
+
EnforcedHashRocketStyle: table
|
9
|
+
EnforcedColonStyle: table
|
10
|
+
|
11
|
+
Layout/LineLength:
|
5
12
|
Max: 150
|
6
13
|
Include:
|
7
14
|
- 'spec/**/*'
|
8
15
|
|
16
|
+
RSpec/EmptyExampleGroup:
|
17
|
+
Enabled: false
|
18
|
+
|
9
19
|
# Because of the way that blocks are used in RSpecs can end up being long when
|
10
20
|
# example groups are nested or many examples are checked.
|
21
|
+
# A similar pattern exists in the DSL for gemspec files.
|
11
22
|
Metrics/BlockLength:
|
23
|
+
Exclude:
|
24
|
+
- '*.gemspec'
|
25
|
+
- 'spec/**/*'
|
26
|
+
|
27
|
+
RSpec/ExpectInHook:
|
28
|
+
Enabled: false
|
29
|
+
|
30
|
+
RSpec/MessageSpies:
|
31
|
+
Enabled: false
|
32
|
+
|
33
|
+
RSpec/EmptyLineAfterExample:
|
34
|
+
Enabled: false
|
35
|
+
|
36
|
+
# NOTE: The rspec-tabular commands get confused with the default syntax is used
|
37
|
+
# for Hashes, so disabling this check for specs so that `Hash[]` can be used.
|
38
|
+
Style/HashConversion:
|
12
39
|
Exclude:
|
13
40
|
- 'spec/**/*'
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.6.2
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,29 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [0.7.0] - 2022-10-07
|
10
|
+
### Changed
|
11
|
+
- update the required ruby version from v2.2 to v2.6
|
12
|
+
- Sugar::Utils.ensure_boolean to consider `0` to be false
|
13
|
+
- Sugar::Utils.ensure_boolean to ignore whitespace around strings before
|
14
|
+
checking if they are 'false'
|
15
|
+
|
16
|
+
## [0.6.0] - 2019-05-31
|
17
|
+
### Added
|
18
|
+
- SugarUtils::File.append, which is explicitly for appending to a file. It will
|
19
|
+
also create a new file if it does not yet exist
|
20
|
+
- SugarUtils::scrub_encoding, which is used for cleaning badly encoded
|
21
|
+
characters out of a string
|
22
|
+
- SugarUtils::File.change_access, a wrapper for changing ownership and
|
23
|
+
permissions of a file
|
24
|
+
- SugarUtils::File.atomic_write, to atomically write a file
|
25
|
+
### Removed
|
26
|
+
- append support in SugarUtils::File.write (could have been specified by { mode: 'a })
|
27
|
+
### Changed
|
28
|
+
- :mode and :perm are now aliases for setting permissions on files in all the
|
29
|
+
related methods (i.e., .write, .write_json, .touch, .append)
|
30
|
+
- convert SugarUtils::File.write_json to use .atomic_write
|
31
|
+
|
9
32
|
## [0.5.0] - 2018-05-01
|
10
33
|
### Changed
|
11
34
|
- bring back :perm as option to set the permissions in SugarUtils::File.write and SugarUtils::File.touch methods
|
data/README.md
CHANGED
@@ -1,39 +1,31 @@
|
|
1
1
|
# sugar_utils
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/sugar_utils.svg)](http://badge.fury.io/rb/sugar_utils)
|
4
|
-
[![
|
5
|
-
[![Build Status](https://travis-ci.org/sugarcrm/sugar_utils.svg?branch=master)](https://travis-ci.org/sugarcrm/sugar_utils)
|
4
|
+
[![Build Status](https://github.com/sugarcrm/sugar_utils/actions/workflows/ci.yml/badge.svg)](https://github.com/sugarcrm/sugar_utils/actions/workflows/ci.yml)
|
6
5
|
[![Code Climate](https://codeclimate.com/github/sugarcrm/sugar_utils/badges/gpa.svg)](https://codeclimate.com/github/sugarcrm/sugar_utils)
|
7
6
|
[![Test Coverage](https://codeclimate.com/github/sugarcrm/sugar_utils/badges/coverage.svg)](https://codeclimate.com/github/sugarcrm/sugar_utils/coverage)
|
8
|
-
[![Inline docs](http://inch-ci.org/github/sugarcrm/sugar_utils.svg)](http://inch-ci.org/github/sugarcrm/sugar_utils)
|
9
7
|
[![License](http://img.shields.io/badge/license-Apache2-green.svg?style=flat)](LICENSE)
|
10
8
|
|
9
|
+
[![Inline docs](http://inch-ci.org/github/sugarcrm/sugar_utils.svg)](http://inch-ci.org/github/sugarcrm/sugar_utils)
|
10
|
+
[![RubyDoc](http://img.shields.io/badge/docs-rdoc.info-blue.svg)](http://rubydoc.org/gems/sugar_utils)
|
11
|
+
[![CucumberPro](https://img.shields.io/badge/cucumber.pro-sugar_utils-3d10af.svg)](https://app.cucumber.pro/projects/sugar_utils)
|
12
|
+
|
11
13
|
Utility methods extracted from SugarCRM Ruby projects.
|
12
14
|
|
13
15
|
These methods are included:
|
14
16
|
|
15
17
|
* SugarUtils.ensure_boolean
|
16
18
|
* SugarUtils.ensure_integer
|
19
|
+
* SugarUtils.scrub_encoding
|
17
20
|
* SugarUtils::File.flock_shared
|
18
21
|
* SugarUtils::File.flock_exclusive
|
22
|
+
* SugarUtils::File.change_access
|
19
23
|
* SugarUtils::File.read
|
20
24
|
* SugarUtils::File.write
|
25
|
+
* SugarUtils::File.atomic_write
|
21
26
|
* SugarUtils::File.read_json
|
22
27
|
* SugarUtils::File.write_json
|
23
|
-
|
24
|
-
These methods will probably be included in the future:
|
25
|
-
|
26
|
-
* sizeof_dir
|
27
|
-
* find_files
|
28
|
-
* find_file!
|
29
|
-
* gzip
|
30
|
-
* gunzip
|
31
|
-
* tarball
|
32
|
-
* untarball
|
33
|
-
* tarball_list
|
34
|
-
* encrypt
|
35
|
-
* http_get_file
|
36
|
-
* timeout_retry
|
28
|
+
* SugarUtils::File.append
|
37
29
|
|
38
30
|
## Installation
|
39
31
|
|
@@ -55,10 +47,46 @@ Or install it yourself as:
|
|
55
47
|
$ gem install sugar_utils
|
56
48
|
```
|
57
49
|
|
50
|
+
## Roadmap
|
51
|
+
|
52
|
+
These methods might be added in the future:
|
53
|
+
|
54
|
+
* sizeof_dir
|
55
|
+
* find_files
|
56
|
+
* find_file!
|
57
|
+
* gzip
|
58
|
+
* gunzip
|
59
|
+
* tarball
|
60
|
+
* untarball
|
61
|
+
* tarball_list
|
62
|
+
* encrypt
|
63
|
+
* http_get_file
|
64
|
+
* timeout_retry
|
65
|
+
|
66
|
+
## Elsewhere on the web
|
67
|
+
|
68
|
+
Links to other places on the web where this projects exists:
|
69
|
+
|
70
|
+
* [Code Climate](https://codeclimate.com/github/sugarcrm/sugar_utils)
|
71
|
+
* [CucumberPro](https://app.cucumber.pro/projects/sugar_utils)
|
72
|
+
* [InchCI](http://inch-ci.org/github/sugarcrm/sugar_utils)
|
73
|
+
* [Github](https://github.com/sugarcrm/sugar_utils)
|
74
|
+
* [OpenHub](https://www.openhub.net/p/sugar_utils)
|
75
|
+
* [RubyDoc](http://rubydoc.org/gems/sugar_utils)
|
76
|
+
* [RubyGems](https://rubygems.org/gems/sugar_utils)
|
77
|
+
* [Ruby LibHunt](https://ruby.libhunt.com/sugar_utils-alternatives)
|
78
|
+
* [Ruby Toolbox](https://www.ruby-toolbox.com/projects/sugar_utils)
|
79
|
+
|
58
80
|
## Contributing
|
59
81
|
|
60
82
|
See [CONTRIBUTING](CONTRIBUTING.md) for how you can contribute changes back into this project.
|
61
83
|
|
62
|
-
##
|
84
|
+
## Contributors
|
85
|
+
|
86
|
+
* [Andrew Sullivan Cant](https://github.com/acant)
|
87
|
+
* [Robert Lockstone](https://github.com/lockstone)
|
88
|
+
* [Vadim Kazakov](https://github.com/yads)
|
89
|
+
|
90
|
+
## Acknowledgements
|
63
91
|
|
64
|
-
Copyright
|
92
|
+
Copyright 2019 [SugarCRM Inc.](http://sugarcrm.com), released under the Apache2 License.
|
data/Rakefile
CHANGED
@@ -1,18 +1,48 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
# frozen_string_literal: true
|
3
2
|
|
4
3
|
require 'bundler/gem_tasks'
|
5
4
|
require 'rspec/core/rake_task'
|
5
|
+
require 'cucumber'
|
6
|
+
require 'cucumber/rake/task'
|
6
7
|
require 'rubocop/rake_task'
|
8
|
+
require 'bundler/audit/task'
|
7
9
|
require 'yard'
|
8
10
|
require 'yardstick/rake/measurement'
|
9
|
-
require '
|
11
|
+
require 'pathname'
|
12
|
+
require 'license_finder'
|
13
|
+
require 'English'
|
10
14
|
|
11
|
-
RSpec::Core::RakeTask.new(:spec)
|
15
|
+
RSpec::Core::RakeTask.new(:spec) do |task|
|
16
|
+
# task.rspec_opts = '--warnings'
|
17
|
+
end
|
18
|
+
|
19
|
+
Cucumber::Rake::Task.new(:features) do |task|
|
20
|
+
task.cucumber_opts = '--publish-quiet'
|
21
|
+
end
|
12
22
|
|
13
23
|
RuboCop::RakeTask.new(:rubocop) do |task|
|
14
|
-
|
15
|
-
|
24
|
+
rubocop_report_pathname =
|
25
|
+
Pathname(Rake.application.original_dir).join('tmp', 'rubocop.txt')
|
26
|
+
rubocop_report_pathname.dirname.mkpath
|
27
|
+
task.options =
|
28
|
+
%w[
|
29
|
+
--display-cop-names
|
30
|
+
--extra-details
|
31
|
+
--display-style-guide
|
32
|
+
--fail-level error
|
33
|
+
--format progress
|
34
|
+
--format simple
|
35
|
+
--out
|
36
|
+
].push(rubocop_report_pathname.to_s)
|
37
|
+
end
|
38
|
+
|
39
|
+
Bundler::Audit::Task.new
|
40
|
+
|
41
|
+
desc 'Check dependency licenses'
|
42
|
+
task :license_finder do
|
43
|
+
puts `license_finder --quiet --format text`
|
44
|
+
|
45
|
+
abort('LicenseFinder failed') unless $CHILD_STATUS.success?
|
16
46
|
end
|
17
47
|
|
18
48
|
YARD::Rake::YardocTask.new do |t|
|
@@ -24,6 +54,4 @@ Yardstick::Rake::Measurement.new(:yardstick_measure) do |measurement|
|
|
24
54
|
measurement.output = 'tmp/yard_coverage.txt'
|
25
55
|
end
|
26
56
|
|
27
|
-
task
|
28
|
-
|
29
|
-
task default: %i[spec]
|
57
|
+
task default: %i[spec features rubocop yardstick_measure bundle:audit license_finder]
|
@@ -0,0 +1,25 @@
|
|
1
|
+
---
|
2
|
+
- - :ignore_group
|
3
|
+
- development
|
4
|
+
- :who: Andrew Sullivan Cant <mail@andrewsullivancant.ca>
|
5
|
+
:why:
|
6
|
+
:versions: []
|
7
|
+
:when: 2018-06-13 15:20:17.351348000 Z
|
8
|
+
- - :permit
|
9
|
+
- Apache 2.0
|
10
|
+
- :who: Andrew Sullivan Cant <mail@andrewsullivancant.ca>
|
11
|
+
:why: SugarCRM's primary approved open source license
|
12
|
+
:versions: []
|
13
|
+
:when: 2018-06-18 19:28:33.314061000 Z
|
14
|
+
- - :permit
|
15
|
+
- MIT
|
16
|
+
- :who: Andrew Sullivan Cant <mail@andrewsullivancant.ca>
|
17
|
+
:why: SugarCRM's secondary approved open source license
|
18
|
+
:versions: []
|
19
|
+
:when: 2018-06-13 15:18:36.240771000 Z
|
20
|
+
- - :permit
|
21
|
+
- BSD
|
22
|
+
- :who: Andrew Sullivan Cant <mail@andrewsullivancant.ca>
|
23
|
+
:why: SugarCRM's secondary approved open source license
|
24
|
+
:versions: []
|
25
|
+
:when: 2018-06-18 19:29:15.003697000 Z
|
@@ -0,0 +1,46 @@
|
|
1
|
+
Feature: Append to a file
|
2
|
+
|
3
|
+
Scenario: Append a missing file
|
4
|
+
When I run the following Ruby code:
|
5
|
+
"""ruby
|
6
|
+
require 'sugar_utils'
|
7
|
+
SugarUtils::File.append('dir/test', 'foobar')
|
8
|
+
"""
|
9
|
+
Then the file named "dir/test" should contain exactly:
|
10
|
+
"""
|
11
|
+
foobar
|
12
|
+
"""
|
13
|
+
|
14
|
+
Scenario: Append an existing file
|
15
|
+
Given a file named "dir/test" with "foobar"
|
16
|
+
When I run the following Ruby code:
|
17
|
+
"""ruby
|
18
|
+
require 'sugar_utils'
|
19
|
+
SugarUtils::File.append('dir/test', 'deadbeef')
|
20
|
+
"""
|
21
|
+
Then the file named "dir/test" should contain exactly:
|
22
|
+
"""
|
23
|
+
foobardeadbeef
|
24
|
+
"""
|
25
|
+
|
26
|
+
# TODO: Fix the owner/group setting check
|
27
|
+
Scenario: Append a file and reset its permissions
|
28
|
+
Given a file named "dir/test" with "foobar"
|
29
|
+
When I run the following Ruby code:
|
30
|
+
"""ruby
|
31
|
+
require 'sugar_utils'
|
32
|
+
SugarUtils::File.append(
|
33
|
+
'dir/test',
|
34
|
+
'deadbeef',
|
35
|
+
# owner: 'nobody',
|
36
|
+
# group: 'nogroup',
|
37
|
+
mode: 0o777
|
38
|
+
)
|
39
|
+
"""
|
40
|
+
Then the file named "dir/test" should contain exactly:
|
41
|
+
"""
|
42
|
+
foobardeadbeef
|
43
|
+
"""
|
44
|
+
And the file named "dir/test" should have permissions "777"
|
45
|
+
# And the file named "dir/test" should have owner "nobody"
|
46
|
+
# And the file named "dir/test" should have group "nogroup"
|
@@ -0,0 +1,46 @@
|
|
1
|
+
Feature: Write to a file atomically
|
2
|
+
|
3
|
+
Scenario: Write a file atomically
|
4
|
+
When I run the following Ruby code:
|
5
|
+
"""ruby
|
6
|
+
require 'sugar_utils'
|
7
|
+
puts SugarUtils::File.atomic_write('dir/test', 'foobar')
|
8
|
+
"""
|
9
|
+
Then the file named "dir/test" should contain exactly:
|
10
|
+
"""
|
11
|
+
foobar
|
12
|
+
"""
|
13
|
+
|
14
|
+
Scenario: Overwrite a file atomically
|
15
|
+
Given a file named "dir/test" with "deadbeef"
|
16
|
+
When I run the following Ruby code:
|
17
|
+
"""ruby
|
18
|
+
require 'sugar_utils'
|
19
|
+
puts SugarUtils::File.atomic_write('dir/test', 'foobar')
|
20
|
+
"""
|
21
|
+
Then the file named "dir/test" should contain exactly:
|
22
|
+
"""
|
23
|
+
foobar
|
24
|
+
"""
|
25
|
+
|
26
|
+
# TODO: Fix the owner/group setting check
|
27
|
+
Scenario: Overwrite a file and reset its permissions atomically
|
28
|
+
Given a file named "dir/test" with "deadbeef"
|
29
|
+
When I run the following Ruby code:
|
30
|
+
"""ruby
|
31
|
+
require 'sugar_utils'
|
32
|
+
puts SugarUtils::File.atomic_write(
|
33
|
+
'dir/test',
|
34
|
+
'foobar',
|
35
|
+
# owner: 'nobody',
|
36
|
+
# group: 'nogroup',
|
37
|
+
mode: 0o777
|
38
|
+
)
|
39
|
+
"""
|
40
|
+
Then the file named "dir/test" should contain exactly:
|
41
|
+
"""
|
42
|
+
foobar
|
43
|
+
"""
|
44
|
+
And the file named "dir/test" should have permissions "777"
|
45
|
+
# And the file named "dir/test" should have owner "nobody"
|
46
|
+
# And the file named "dir/test" should have group "nogroup"
|
@@ -0,0 +1,27 @@
|
|
1
|
+
Feature: Change a files ownership and permissions
|
2
|
+
|
3
|
+
# TODO: Fix the owner/group setting check. I need to figure out how to execute
|
4
|
+
# these scenarios correctly across various environments.
|
5
|
+
|
6
|
+
Scenario: All the values are skipped
|
7
|
+
Given a file named "test" with "foobar"
|
8
|
+
When I run the following Ruby code:
|
9
|
+
"""ruby
|
10
|
+
require 'sugar_utils'
|
11
|
+
SugarUtils::File.change_access('test', nil, nil, nil)
|
12
|
+
"""
|
13
|
+
# Then the file named "test" should have permissions "644"
|
14
|
+
# And the file named "test" should have owner "nobody"
|
15
|
+
# And the file named "test" should have group "nogroup"
|
16
|
+
|
17
|
+
Scenario: All the values are set
|
18
|
+
Given a file named "test" with "foobar"
|
19
|
+
When I run the following Ruby code:
|
20
|
+
"""ruby
|
21
|
+
require 'sugar_utils'
|
22
|
+
# SugarUtils::File.change_access('test', 'nobody', 'nogroup', 0o777)
|
23
|
+
SugarUtils::File.change_access('test', nil, nil, 0o777)
|
24
|
+
"""
|
25
|
+
Then the file named "test" should have permissions "777"
|
26
|
+
# And the file named "test" should have owner "nobody"
|
27
|
+
# And the file named "test" should have group "nogroup"
|
@@ -0,0 +1,34 @@
|
|
1
|
+
|
2
|
+
Feature: Ensure the specified value is a boolean
|
3
|
+
|
4
|
+
Scenario: nil is false
|
5
|
+
When I run the following Ruby code:
|
6
|
+
"""ruby
|
7
|
+
require 'sugar_utils'
|
8
|
+
puts SugarUtils.ensure_boolean(nil)
|
9
|
+
"""
|
10
|
+
Then the output should contain "false"
|
11
|
+
|
12
|
+
Scenario: false is false
|
13
|
+
When I run the following Ruby code:
|
14
|
+
"""ruby
|
15
|
+
require 'sugar_utils'
|
16
|
+
puts SugarUtils.ensure_boolean(false)
|
17
|
+
"""
|
18
|
+
Then the output should contain "false"
|
19
|
+
|
20
|
+
Scenario: String of 'false' is false
|
21
|
+
When I run the following Ruby code:
|
22
|
+
"""ruby
|
23
|
+
require 'sugar_utils'
|
24
|
+
puts SugarUtils.ensure_boolean('false')
|
25
|
+
"""
|
26
|
+
Then the output should contain "false"
|
27
|
+
|
28
|
+
Scenario: Any other value is true
|
29
|
+
When I run the following Ruby code:
|
30
|
+
"""ruby
|
31
|
+
require 'sugar_utils'
|
32
|
+
puts SugarUtils.ensure_boolean('value')
|
33
|
+
"""
|
34
|
+
Then the output should contain "true"
|
@@ -0,0 +1,19 @@
|
|
1
|
+
Feature: Ensure the specified value is an integer
|
2
|
+
|
3
|
+
Scenario: Convert Floats to Integers
|
4
|
+
When I run the following Ruby code:
|
5
|
+
"""ruby
|
6
|
+
require 'sugar_utils'
|
7
|
+
puts SugarUtils.ensure_integer(123.456)
|
8
|
+
"""
|
9
|
+
Then the output should contain "123"
|
10
|
+
|
11
|
+
Scenario: Convert Strings of Integers to Integers
|
12
|
+
When I run the following Ruby code:
|
13
|
+
"""ruby
|
14
|
+
require 'sugar_utils'
|
15
|
+
puts SugarUtils.ensure_integer('123.456')
|
16
|
+
"""
|
17
|
+
Then the output should contain "123"
|
18
|
+
|
19
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# TODO: Fill in this feature
|
2
|
+
Feature: Operate locks on files
|
3
|
+
|
4
|
+
Scenario: Shared lock
|
5
|
+
Given a file named "test" with "foobar"
|
6
|
+
When I run the following Ruby code:
|
7
|
+
"""ruby
|
8
|
+
require 'sugar_utils'
|
9
|
+
File.open('test') do |file|
|
10
|
+
SugarUtils::File.flock_shared(file)
|
11
|
+
puts file.read
|
12
|
+
end
|
13
|
+
"""
|
14
|
+
Then the file named "test" should contain "foobar"
|
15
|
+
|
16
|
+
Scenario: Exclusive lock
|
17
|
+
Given a file named "test" with "foobar"
|
18
|
+
When I run the following Ruby code:
|
19
|
+
"""ruby
|
20
|
+
require 'sugar_utils'
|
21
|
+
File.open('test') do |file|
|
22
|
+
SugarUtils::File.flock_exclusive(file)
|
23
|
+
puts file.read
|
24
|
+
end
|
25
|
+
"""
|
26
|
+
Then the file named "test" should contain "foobar"
|
@@ -0,0 +1,30 @@
|
|
1
|
+
Feature: Read a file
|
2
|
+
|
3
|
+
Scenario: Read a missing file with a default value
|
4
|
+
When I run the following Ruby code:
|
5
|
+
"""ruby
|
6
|
+
require 'sugar_utils'
|
7
|
+
puts SugarUtils::File.read(
|
8
|
+
'test', value_on_missing: 'missing', raise_on_missing: false
|
9
|
+
)
|
10
|
+
"""
|
11
|
+
Then the output should contain "missing"
|
12
|
+
|
13
|
+
Scenario: Read an existing file
|
14
|
+
Given a file named "test" with "foobar"
|
15
|
+
When I run the following Ruby code:
|
16
|
+
"""ruby
|
17
|
+
require 'sugar_utils'
|
18
|
+
puts SugarUtils::File.read('test')
|
19
|
+
"""
|
20
|
+
Then the output should contain "foobar"
|
21
|
+
|
22
|
+
Scenario: Read an existing file and scurb encoding errors
|
23
|
+
Given a file named "test" with "test"
|
24
|
+
When I run the following Ruby code:
|
25
|
+
"""ruby
|
26
|
+
require 'sugar_utils'
|
27
|
+
File.write('test', %(foo\\x92bar\\x93))
|
28
|
+
puts SugarUtils::File.read('test', scrub_encoding: true)
|
29
|
+
"""
|
30
|
+
Then the output should contain "foobar"
|
@@ -0,0 +1,43 @@
|
|
1
|
+
Feature: Read a file
|
2
|
+
|
3
|
+
Scenario: Read a missing file with a default value
|
4
|
+
When I run the following Ruby code:
|
5
|
+
"""ruby
|
6
|
+
require 'sugar_utils'
|
7
|
+
MultiJson.use(:ok_json)
|
8
|
+
|
9
|
+
puts SugarUtils::File.read_json('test.json', raise_on_missing: false)
|
10
|
+
"""
|
11
|
+
Then the output should contain "{}"
|
12
|
+
|
13
|
+
Scenario: Read an existing file
|
14
|
+
Given a file named "test.json" with:
|
15
|
+
"""
|
16
|
+
{"key":"value"}
|
17
|
+
"""
|
18
|
+
When I run the following Ruby code:
|
19
|
+
"""ruby
|
20
|
+
require 'sugar_utils'
|
21
|
+
MultiJson.use(:ok_json)
|
22
|
+
|
23
|
+
puts SugarUtils::File.read_json('test.json')
|
24
|
+
"""
|
25
|
+
Then the output should contain:
|
26
|
+
"""
|
27
|
+
{"key"=>"value"}
|
28
|
+
"""
|
29
|
+
|
30
|
+
Scenario: Read an existing file and scurb encoding errors
|
31
|
+
Given a file named "test.json" with "test"
|
32
|
+
When I run the following Ruby code:
|
33
|
+
"""ruby
|
34
|
+
require 'sugar_utils'
|
35
|
+
MultiJson.use(:ok_json)
|
36
|
+
|
37
|
+
File.write('test.json', %({\"key\":\"foo\\x92bar\\x93\"}))
|
38
|
+
puts SugarUtils::File.read_json('test.json', scrub_encoding: true)
|
39
|
+
"""
|
40
|
+
Then the output should contain:
|
41
|
+
"""
|
42
|
+
{"key"=>"foobar"}
|
43
|
+
"""
|
@@ -0,0 +1,25 @@
|
|
1
|
+
Feature: Ensure the specified value is an integer
|
2
|
+
|
3
|
+
Scenario: Pass through string without encoding errors
|
4
|
+
When I run the following Ruby code:
|
5
|
+
"""ruby
|
6
|
+
require 'sugar_utils'
|
7
|
+
puts SugarUtils.scrub_encoding('foobar')
|
8
|
+
"""
|
9
|
+
Then the output should contain "foobar"
|
10
|
+
|
11
|
+
Scenario: Erase encoding errors in the string
|
12
|
+
When I run the following Ruby code:
|
13
|
+
"""ruby
|
14
|
+
require 'sugar_utils'
|
15
|
+
puts SugarUtils.scrub_encoding(%(foo\\x92bar\\x93))
|
16
|
+
"""
|
17
|
+
Then the output should contain "foobar"
|
18
|
+
|
19
|
+
Scenario: Replace encoding errors in the string
|
20
|
+
When I run the following Ruby code:
|
21
|
+
"""ruby
|
22
|
+
require 'sugar_utils'
|
23
|
+
puts SugarUtils.scrub_encoding(%(foo\\x92bar\\x93), 'xxx')
|
24
|
+
"""
|
25
|
+
Then the output should contain "fooxxxbarxxx"
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
When('I run the following Ruby code:') do |code|
|
4
|
+
run_command_and_stop %(ruby -e "#{code}")
|
5
|
+
end
|
6
|
+
|
7
|
+
# Copying the pattern for this step from the default Aruba step for checking
|
8
|
+
# the permissions of a file.
|
9
|
+
# @see lib/aruba/cucumber/file.rb
|
10
|
+
Then(/^the (?:file|directory)(?: named)? "([^"]*)" should( not)? have owner "([^"]*)"$/) do |path, negated, owner|
|
11
|
+
if negated
|
12
|
+
expect(path).not_to have_owner(owner)
|
13
|
+
else
|
14
|
+
expect(path).to have_owner(owner)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# Copying the pattern for this step from the default Aruba step for checking
|
19
|
+
# the permissions of a file.
|
20
|
+
# @see lib/aruba/cucumber/file.rb
|
21
|
+
Then(/^the (?:file|directory)(?: named)? "([^"]*)" should( not)? have group "([^"]*)"$/) do |path, negated, group|
|
22
|
+
if negated
|
23
|
+
expect(path).not_to have_group(group)
|
24
|
+
else
|
25
|
+
expect(path).to have_group(group)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Copying the pattern for this step from the default Aruba step for checking
|
30
|
+
# the permissions of a file.
|
31
|
+
# @see lib/aruba/cucumber/file.rb
|
32
|
+
Then(/^the (?:file|directory)(?: named)? "([^"]*)" should( not)? have modification time "([^"]*)"$/) do |path, negated, modification_time|
|
33
|
+
if negated
|
34
|
+
expect(expand_path(path)).not_to have_mtime(modification_time.to_i)
|
35
|
+
else
|
36
|
+
expect(expand_path(path)).to have_mtime(modification_time.to_i)
|
37
|
+
end
|
38
|
+
end
|