rspec-file_fixtures 0.1.3 → 0.1.6

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
  SHA256:
3
- metadata.gz: c18279790c66bd029a549c0ea4445c0c0b4e90df69530aca58c23297116379e4
4
- data.tar.gz: 359c4a1c967b8ba42309129bb3228557db85ad12ad98883860dabf42edfe5b3c
3
+ metadata.gz: c78567396d3fd63b7f4daafa0cb226bcb0356889a6a55b7998e1121b49c7657e
4
+ data.tar.gz: 00a465a84406eaa3e859b0c1afc1f1bb9f811d2efe5771c33cfabc31be0c8f48
5
5
  SHA512:
6
- metadata.gz: 4477a4266dd1144e6f0b0aaea2b0e6a62efe7d260c48601124fb20795c8160e57f56138ddfa7df0d5d082cdd81da969f93977fa1c620ad4ff14bffc92ccac697
7
- data.tar.gz: d4f5ce52deb8bcb9a2a00afbd21c7472773f5481234fd94cb215f2af956eb42e1ecaf2e15aef531607d3709eb9dd2603ac1283f7dae08dfe9cfb11f572a97190
6
+ metadata.gz: aa6d335a04dc1271cc4f46323ea06f12431edbce2935414e5c7cf838eb5df2d3d945be8b54707292494e3201d26f90d40a8c982c11e371f69b428c0546fe5164
7
+ data.tar.gz: 04b06c35060234ca74e00bcdc5b747681fc5ae71cd2b184839393f269bb61c23a5bd0524a0675ccb9f838ba7eec878f72e6a5c2be98e2fcdab873d89b0996d20
data/.rubocop.yml ADDED
@@ -0,0 +1,6 @@
1
+ AllCops:
2
+ NewCops: enable
3
+
4
+ Metrics/BlockLength:
5
+ Exclude:
6
+ - 'spec/**/*_spec.rb'
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.5.3
1
+ 2.5.8
data/Gemfile CHANGED
@@ -5,7 +5,7 @@ source 'https://rubygems.org'
5
5
  # Specify your gem's dependencies in rspec-file_fixtures.gemspec
6
6
  gemspec
7
7
 
8
- gem 'devpack', '~> 0.3.2'
8
+ gem 'devpack', '~> 0.4.0'
9
9
  gem 'nokogiri', '~> 1.11'
10
10
  gem 'rake', '~> 12.0'
11
11
  gem 'rspec', '~> 3.0'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rspec-file_fixtures (0.1.3)
4
+ rspec-file_fixtures (0.1.6)
5
5
  rspec (~> 3.0)
6
6
 
7
7
  GEM
@@ -9,7 +9,7 @@ GEM
9
9
  specs:
10
10
  ast (2.4.2)
11
11
  concurrent-ruby (1.1.8)
12
- devpack (0.3.2)
12
+ devpack (0.4.0)
13
13
  diff-lcs (1.4.4)
14
14
  i18n (1.8.9)
15
15
  concurrent-ruby (~> 1.0)
@@ -68,7 +68,7 @@ PLATFORMS
68
68
  ruby
69
69
 
70
70
  DEPENDENCIES
71
- devpack (~> 0.3.2)
71
+ devpack (~> 0.4.0)
72
72
  nokogiri (~> 1.11)
73
73
  rake (~> 12.0)
74
74
  rspec (~> 3.0)
@@ -80,4 +80,4 @@ DEPENDENCIES
80
80
  strong_versions (~> 0.4.5)
81
81
 
82
82
  BUNDLED WITH
83
- 2.1.4
83
+ 2.2.33
data/README.md CHANGED
@@ -7,7 +7,7 @@ A simple and convenient file fixture loader for [_RSpec_](https://rspec.info/).
7
7
  Add this line to your application's Gemfile:
8
8
 
9
9
  ```ruby
10
- gem 'rspec-file_fixtures', '~> 0.1.3'
10
+ gem 'rspec-file_fixtures', '~> 0.1.6'
11
11
  ```
12
12
 
13
13
  And then execute:
@@ -35,8 +35,15 @@ let(:my_fixture) { fixture('fixture.json') }
35
35
  Use the returned `Fixture` object's various methods in your tests:
36
36
 
37
37
  ```ruby
38
- it 'loads data' do
39
- expect(subject.load(my_fixture.read)).to eql my_fixture.json
38
+ it 'parses JSON data' do
39
+ expect(subject.load(my_fixture.read)).to eql my_fixture.from_json
40
+ end
41
+ ```
42
+
43
+ ```ruby
44
+ it 'contains same filenames as fixture directory' do
45
+ # `#dirname` delegated to underlying `Pathname` object, returning a new `Pathname` instance:
46
+ expect(subject.created_files).to eql my_fixture.dirname.entries
40
47
  end
41
48
  ```
42
49
 
@@ -46,9 +53,22 @@ The following methods are provided on the `Fixture` object:
46
53
  |-|-|
47
54
  |`#read`|Read the contents of the fixture file as a string|
48
55
  |`#path`|The absolute path to the fixture file|
49
- |`#json`|The parsed _JSON_ content from the file|
50
- |`#yaml`|The parsed _YAML_ content from the file|
51
- |`#xml`|The parsed _XML_ content from the file (requires the [_Nokogiri_](https://nokogiri.org/) gem and returns a `Nokogiri::XML::Document`)|
56
+ |`#from_json`|The parsed _JSON_ content from the file|
57
+ |`#from_yaml`|The parsed _YAML_ content from the file (aliased as `#from_yml`)|
58
+ |`#from_xml`|The parsed _XML_ content from the file (requires the [_Nokogiri_](https://nokogiri.org/) gem and returns a `Nokogiri::XML::Document`)|
59
+
60
+ Methods not specifically defined above are delegated to the underlying `Pathname` object (`#join`, `#dirname`, `#mkpath`, etc.). See the [Pathname documentation](https://ruby-doc.org/stdlib-2.7.5/libdoc/pathname/rdoc/Pathname.html) for more details.
61
+
62
+ ### Symbolize Names
63
+
64
+ By default `Fixture#from_yaml` and `Fixture#from_json` symbolize all keys in their output. To disable this behaviour, pass `symbolize_names: false` to either method. A shorthand version of this is available by simply passing `false` as the only parameter:
65
+
66
+ ```ruby
67
+ expect(subject.load(my_fixture.from_yaml(symbolize_names: false))).to eql({ 'foo' => 'bar' })
68
+ expect(subject.load(my_fixture.from_json(symbolize_names: false))).to eql({ 'foo' => 'bar' })
69
+ expect(subject.load(my_fixture.from_yaml(false))).to eql({ 'foo' => 'bar' })
70
+ expect(subject.load(my_fixture.from_json(false))).to eql({ 'foo' => 'bar' })
71
+ ```
52
72
 
53
73
  ## License
54
74
 
@@ -11,13 +11,7 @@ module RSpecFileFixtures
11
11
  pathname.read
12
12
  end
13
13
 
14
- def yaml
15
- YAML.safe_load(read, symbolize_names: true)
16
- end
17
-
18
- alias yml yaml
19
-
20
- def xml
14
+ def from_xml
21
15
  require 'nokogiri'
22
16
  Nokogiri::XML.parse(read)
23
17
  end
@@ -28,12 +22,39 @@ module RSpecFileFixtures
28
22
  pathname.expand_path.to_s
29
23
  end
30
24
 
31
- def json
32
- JSON.parse(read, symbolize_names: true)
25
+ # rubocop:disable Style/OptionalBooleanParameter
26
+ def from_json(symbolize_names_shorthand = true, symbolize_names: true)
27
+ JSON.parse(read, symbolize_names: symbolize_names & symbolize_names_shorthand)
33
28
  end
34
29
 
30
+ def from_yaml(symbolize_names_shorthand = true, symbolize_names: true)
31
+ YAML.safe_load(read, symbolize_names: symbolize_names & symbolize_names_shorthand)
32
+ end
33
+ # rubocop:enable Style/OptionalBooleanParameter
34
+
35
+ alias from_yml from_yaml
36
+
37
+ # Backward compatibility
38
+ alias yml from_yml
39
+ alias yaml from_yaml
40
+ alias xml from_xml
41
+ alias json from_json
42
+ # /Backward compatibility
43
+
35
44
  private
36
45
 
46
+ def method_missing(method_name, *args)
47
+ return pathname.public_send(method_name, *args) if respond_to_missing?(method_name)
48
+
49
+ super
50
+ end
51
+
52
+ def respond_to_missing?(method_name, _ = false)
53
+ return true if pathname.respond_to?(method_name)
54
+
55
+ super
56
+ end
57
+
37
58
  def pathname
38
59
  @pathname ||= base_path.join(@raw_path)
39
60
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RSpecFileFixtures
4
- VERSION = '0.1.3'
4
+ VERSION = '0.1.6'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-file_fixtures
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Farrell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-03 00:00:00.000000000 Z
11
+ date: 2022-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -33,6 +33,7 @@ extra_rdoc_files: []
33
33
  files:
34
34
  - ".gitignore"
35
35
  - ".rspec"
36
+ - ".rubocop.yml"
36
37
  - ".ruby-version"
37
38
  - Gemfile
38
39
  - Gemfile.lock
@@ -68,8 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
69
  - !ruby/object:Gem::Version
69
70
  version: '0'
70
71
  requirements: []
71
- rubyforge_project:
72
- rubygems_version: 2.7.6
72
+ rubygems_version: 3.3.9
73
73
  signing_key:
74
74
  specification_version: 4
75
75
  summary: Simple file fixture loader for RSpec