fixturama 0.0.7 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +100 -0
  3. data/README.md +71 -3
  4. data/lib/fixturama.rb +49 -20
  5. data/lib/fixturama/changes.rb +72 -0
  6. data/lib/fixturama/changes/base.rb +28 -0
  7. data/lib/fixturama/changes/chain.rb +64 -0
  8. data/lib/fixturama/changes/chain/actions.rb +31 -0
  9. data/lib/fixturama/changes/chain/arguments.rb +59 -0
  10. data/lib/fixturama/changes/chain/raise_action.rb +43 -0
  11. data/lib/fixturama/changes/chain/return_action.rb +33 -0
  12. data/lib/fixturama/changes/const.rb +30 -0
  13. data/lib/fixturama/changes/env.rb +35 -0
  14. data/lib/fixturama/changes/request.rb +91 -0
  15. data/lib/fixturama/changes/request/response.rb +62 -0
  16. data/lib/fixturama/changes/request/responses.rb +22 -0
  17. data/lib/fixturama/changes/seed.rb +39 -0
  18. data/lib/fixturama/config.rb +5 -0
  19. data/lib/fixturama/fixture_error.rb +31 -0
  20. data/lib/fixturama/loader.rb +1 -0
  21. data/lib/fixturama/loader/context.rb +1 -0
  22. data/lib/fixturama/loader/value.rb +1 -0
  23. data/lib/fixturama/version.rb +4 -0
  24. metadata +80 -50
  25. data/.gitignore +0 -12
  26. data/.rspec +0 -2
  27. data/.rubocop.yml +0 -22
  28. data/.travis.yml +0 -23
  29. data/Gemfile +0 -9
  30. data/LICENSE.txt +0 -21
  31. data/Rakefile +0 -6
  32. data/fixturama.gemspec +0 -23
  33. data/lib/fixturama/seed.rb +0 -15
  34. data/lib/fixturama/stubs.rb +0 -57
  35. data/lib/fixturama/stubs/chain.rb +0 -89
  36. data/lib/fixturama/stubs/chain/actions.rb +0 -39
  37. data/lib/fixturama/stubs/chain/actions/raise.rb +0 -21
  38. data/lib/fixturama/stubs/chain/actions/return.rb +0 -23
  39. data/lib/fixturama/stubs/chain/arguments.rb +0 -86
  40. data/lib/fixturama/stubs/const.rb +0 -42
  41. data/lib/fixturama/utils.rb +0 -39
  42. data/spec/fixturama/load_fixture/_spec.rb +0 -53
  43. data/spec/fixturama/load_fixture/data.json +0 -5
  44. data/spec/fixturama/load_fixture/data.yaml +0 -3
  45. data/spec/fixturama/load_fixture/data.yml +0 -3
  46. data/spec/fixturama/seed_fixture/_spec.rb +0 -33
  47. data/spec/fixturama/seed_fixture/seed.yml +0 -16
  48. data/spec/fixturama/stub_fixture/_spec.rb +0 -96
  49. data/spec/fixturama/stub_fixture/stub.yml +0 -60
  50. data/spec/spec_helper.rb +0 -26
@@ -1,3 +1,8 @@
1
+ #
2
+ # @private
3
+ # Configures the gem to exclude conflicts between
4
+ # ids auto-generated by database and hardcoded in fixtures
5
+ #
1
6
  module Fixturama::Config
2
7
  module_function
3
8
 
@@ -0,0 +1,31 @@
1
+ #
2
+ # The exception complaining about invalid definition in some fixture
3
+ #
4
+ class Fixturama::FixtureError < ArgumentError
5
+ # The error message
6
+ # @return [String]
7
+ def message
8
+ <<~MESSAGE
9
+ Cannot infer #{@object} from the following part of the fixture #{@file}:
10
+ #{@data}
11
+ MESSAGE
12
+ end
13
+
14
+ # @private
15
+ # Add reference to the path of the fixture file
16
+ # @param [String] file
17
+ # @return [self]
18
+ def with_file(file)
19
+ @file = file
20
+ self
21
+ end
22
+
23
+ private
24
+
25
+ def initialize(object, data, _cause = nil)
26
+ @object = object
27
+ @data = YAML.dump(data)
28
+
29
+ super message
30
+ end
31
+ end
@@ -1,4 +1,5 @@
1
1
  #
2
+ # @private
2
3
  # Load fixture with some options
3
4
  #
4
5
  class Fixturama::Loader
@@ -1,5 +1,6 @@
1
1
  class Fixturama::Loader
2
2
  #
3
+ # @private
3
4
  # The context of some fixture
4
5
  #
5
6
  class Context
@@ -1,5 +1,6 @@
1
1
  class Fixturama::Loader
2
2
  #
3
+ # @private
3
4
  # Wraps a value with a reference to its key
4
5
  # in the [Fixturama::Loader::Context]
5
6
  #
@@ -0,0 +1,4 @@
1
+ module Fixturama
2
+ # The current version of the gem
3
+ VERSION = "0.4.1"
4
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fixturama
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kozin (nepalez)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-01 00:00:00.000000000 Z
11
+ date: 2021-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: factory_bot
@@ -40,61 +40,99 @@ dependencies:
40
40
  version: '3.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: hashie
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">"
46
+ - !ruby/object:Gem::Version
47
+ version: '3'
48
+ - - "<"
49
+ - !ruby/object:Gem::Version
50
+ version: '5'
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">"
56
+ - !ruby/object:Gem::Version
57
+ version: '3'
58
+ - - "<"
59
+ - !ruby/object:Gem::Version
60
+ version: '5'
61
+ - !ruby/object:Gem::Dependency
62
+ name: webmock
43
63
  requirement: !ruby/object:Gem::Requirement
44
64
  requirements:
45
65
  - - "~>"
46
66
  - !ruby/object:Gem::Version
47
- version: '3.6'
67
+ version: '3.0'
48
68
  type: :runtime
49
69
  prerelease: false
50
70
  version_requirements: !ruby/object:Gem::Requirement
51
71
  requirements:
52
72
  - - "~>"
53
73
  - !ruby/object:Gem::Version
54
- version: '3.6'
74
+ version: '3.0'
55
75
  - !ruby/object:Gem::Dependency
56
76
  name: rake
57
77
  requirement: !ruby/object:Gem::Requirement
58
78
  requirements:
59
79
  - - "~>"
60
80
  - !ruby/object:Gem::Version
61
- version: '10'
81
+ version: '13.0'
62
82
  type: :development
63
83
  prerelease: false
64
84
  version_requirements: !ruby/object:Gem::Requirement
65
85
  requirements:
66
86
  - - "~>"
67
87
  - !ruby/object:Gem::Version
68
- version: '10'
88
+ version: '13.0'
69
89
  - !ruby/object:Gem::Dependency
70
90
  name: rspec-its
71
91
  requirement: !ruby/object:Gem::Requirement
72
92
  requirements:
73
93
  - - "~>"
74
94
  - !ruby/object:Gem::Version
75
- version: '1.2'
95
+ version: '1.3'
76
96
  type: :development
77
97
  prerelease: false
78
98
  version_requirements: !ruby/object:Gem::Requirement
79
99
  requirements:
80
100
  - - "~>"
81
101
  - !ruby/object:Gem::Version
82
- version: '1.2'
102
+ version: '1.3'
83
103
  - !ruby/object:Gem::Dependency
84
104
  name: rubocop
85
105
  requirement: !ruby/object:Gem::Requirement
86
106
  requirements:
87
107
  - - "~>"
88
108
  - !ruby/object:Gem::Version
89
- version: '0.49'
109
+ version: '0.80'
90
110
  type: :development
91
111
  prerelease: false
92
112
  version_requirements: !ruby/object:Gem::Requirement
93
113
  requirements:
94
114
  - - "~>"
95
115
  - !ruby/object:Gem::Version
96
- version: '0.49'
97
- description:
116
+ version: '0.80'
117
+ - !ruby/object:Gem::Dependency
118
+ name: rubocop-packaging
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ description: |
132
+ Use fixtures to extract verbosity from RSpec specifications:
133
+ - load data,
134
+ - stub classes, modules and constants,
135
+ - seed the database via FactoryBot.
98
136
  email: andrew.kozin@gmail.com
99
137
  executables: []
100
138
  extensions: []
@@ -102,46 +140,47 @@ extra_rdoc_files:
102
140
  - README.md
103
141
  - CHANGELOG.md
104
142
  files:
105
- - ".gitignore"
106
- - ".rspec"
107
- - ".rubocop.yml"
108
- - ".travis.yml"
109
143
  - CHANGELOG.md
110
- - Gemfile
111
- - LICENSE.txt
112
144
  - README.md
113
- - Rakefile
114
- - fixturama.gemspec
115
145
  - lib/fixturama.rb
146
+ - lib/fixturama/changes.rb
147
+ - lib/fixturama/changes/base.rb
148
+ - lib/fixturama/changes/chain.rb
149
+ - lib/fixturama/changes/chain/actions.rb
150
+ - lib/fixturama/changes/chain/arguments.rb
151
+ - lib/fixturama/changes/chain/raise_action.rb
152
+ - lib/fixturama/changes/chain/return_action.rb
153
+ - lib/fixturama/changes/const.rb
154
+ - lib/fixturama/changes/env.rb
155
+ - lib/fixturama/changes/request.rb
156
+ - lib/fixturama/changes/request/response.rb
157
+ - lib/fixturama/changes/request/responses.rb
158
+ - lib/fixturama/changes/seed.rb
116
159
  - lib/fixturama/config.rb
160
+ - lib/fixturama/fixture_error.rb
117
161
  - lib/fixturama/loader.rb
118
162
  - lib/fixturama/loader/context.rb
119
163
  - lib/fixturama/loader/value.rb
120
164
  - lib/fixturama/rspec.rb
121
- - lib/fixturama/seed.rb
122
- - lib/fixturama/stubs.rb
123
- - lib/fixturama/stubs/chain.rb
124
- - lib/fixturama/stubs/chain/actions.rb
125
- - lib/fixturama/stubs/chain/actions/raise.rb
126
- - lib/fixturama/stubs/chain/actions/return.rb
127
- - lib/fixturama/stubs/chain/arguments.rb
128
- - lib/fixturama/stubs/const.rb
129
- - lib/fixturama/utils.rb
130
- - spec/fixturama/load_fixture/_spec.rb
131
- - spec/fixturama/load_fixture/data.json
132
- - spec/fixturama/load_fixture/data.yaml
133
- - spec/fixturama/load_fixture/data.yml
134
- - spec/fixturama/seed_fixture/_spec.rb
135
- - spec/fixturama/seed_fixture/seed.yml
136
- - spec/fixturama/stub_fixture/_spec.rb
137
- - spec/fixturama/stub_fixture/stub.yml
138
- - spec/spec_helper.rb
165
+ - lib/fixturama/version.rb
139
166
  homepage: https://github.com/nepalez/fixturama
140
167
  licenses:
141
168
  - MIT
142
- metadata: {}
169
+ metadata:
170
+ bug_tracker_uri: https://github.com/nepalez/fixturama/issues
171
+ changelog_uri: https://github.com/nepalez/fixturama/blob/master/CHANGELOG.md
172
+ documentation_uri: https://www.rubydocs.info/gems/fixturama
173
+ homepage_uri: https://github.com/nepalez/fixturama
174
+ source_code_uri: https://github.com/nepalez/fixturama
143
175
  post_install_message:
144
- rdoc_options: []
176
+ rdoc_options:
177
+ - "--title"
178
+ - Fixturama - fixtures on steroids
179
+ - "--main"
180
+ - README.md
181
+ - "--line-numbers"
182
+ - "--inline-source"
183
+ - "--quiet"
145
184
  require_paths:
146
185
  - lib
147
186
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -155,17 +194,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
194
  - !ruby/object:Gem::Version
156
195
  version: '0'
157
196
  requirements: []
158
- rubygems_version: 3.0.3
197
+ rubygems_version: 3.0.8
159
198
  signing_key:
160
199
  specification_version: 4
161
200
  summary: A set of helpers to prettify specs with fixtures
162
- test_files:
163
- - spec/fixturama/load_fixture/_spec.rb
164
- - spec/fixturama/load_fixture/data.json
165
- - spec/fixturama/load_fixture/data.yaml
166
- - spec/fixturama/load_fixture/data.yml
167
- - spec/fixturama/seed_fixture/_spec.rb
168
- - spec/fixturama/seed_fixture/seed.yml
169
- - spec/fixturama/stub_fixture/_spec.rb
170
- - spec/fixturama/stub_fixture/stub.yml
171
- - spec/spec_helper.rb
201
+ test_files: []
data/.gitignore DELETED
@@ -1,12 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
- *.gem
11
- .rspec_status
12
- .idea/
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --require spec_helper
2
- --color
data/.rubocop.yml DELETED
@@ -1,22 +0,0 @@
1
- ---
2
- AllCops:
3
- DisplayCopNames: true
4
- DisplayStyleGuide: true
5
- StyleGuideCopsOnly: true
6
- TargetRubyVersion: 2.3
7
-
8
- Metrics/LineLength:
9
- AllowHeredoc: true
10
- AllowURI: true
11
- URISchemes:
12
- - http
13
- - https
14
-
15
- Style/ClassAndModuleChildren:
16
- Enabled: false
17
-
18
- Style/Documentation:
19
- Enabled: false
20
-
21
- Style/StringLiterals:
22
- EnforcedStyle: double_quotes
data/.travis.yml DELETED
@@ -1,23 +0,0 @@
1
- ---
2
- sudo: false
3
- language: ruby
4
- cache: bundler
5
- before_install:
6
- - gem install bundler --no-document
7
- - gem update --system
8
- script:
9
- - bundle exec rspec
10
- - bundle exec rubocop
11
- rvm:
12
- - 2.3.0
13
- - 2.6.0
14
- - jruby-9.2.0.0
15
- - ruby-head
16
- - jruby-head
17
- env:
18
- global:
19
- - JRUBY_OPTS='--dev -J-Xmx1024M'
20
- matrix:
21
- allow_failures:
22
- - rvm: ruby-head
23
- - rvm: jruby-head
data/Gemfile DELETED
@@ -1,9 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- # Specify your gem's dependencies in sms_aero.gemspec
4
- gemspec
5
-
6
- group :development, :test do
7
- gem "pry", platform: :mri
8
- gem "pry-byebug", platform: :mri
9
- end
data/LICENSE.txt DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2019 Andrew Kozin (aka nepalez)
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/Rakefile DELETED
@@ -1,6 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task default: :spec
data/fixturama.gemspec DELETED
@@ -1,23 +0,0 @@
1
- Gem::Specification.new do |gem|
2
- gem.name = "fixturama"
3
- gem.version = "0.0.7"
4
- gem.author = "Andrew Kozin (nepalez)"
5
- gem.email = "andrew.kozin@gmail.com"
6
- gem.homepage = "https://github.com/nepalez/fixturama"
7
- gem.summary = "A set of helpers to prettify specs with fixtures"
8
- gem.license = "MIT"
9
-
10
- gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
11
- gem.test_files = gem.files.grep(/^spec/)
12
- gem.extra_rdoc_files = Dir["README.md", "LICENSE", "CHANGELOG.md"]
13
-
14
- gem.required_ruby_version = ">= 2.2"
15
-
16
- gem.add_runtime_dependency "factory_bot", "~> 4.0"
17
- gem.add_runtime_dependency "rspec", "~> 3.0"
18
- gem.add_runtime_dependency "hashie", "~> 3.6"
19
-
20
- gem.add_development_dependency "rake", "~> 10"
21
- gem.add_development_dependency "rspec-its", "~> 1.2"
22
- gem.add_development_dependency "rubocop", "~> 0.49"
23
- end
@@ -1,15 +0,0 @@
1
- module Fixturama
2
- module Seed
3
- module_function
4
-
5
- def call(opts)
6
- opts = Utils.symbolize_hash(opts)
7
- type = opts[:type].to_sym
8
- traits = Utils.symbolize_array opts[:traits]
9
- params = Utils.symbolize_hash opts[:params]
10
- count = opts.fetch(:count, 1).to_i
11
-
12
- FactoryBot.create_list(type, count, *traits, **params) if count.positive?
13
- end
14
- end
15
- end
@@ -1,57 +0,0 @@
1
- module Fixturama
2
- #
3
- # Collection of stubbed calls
4
- #
5
- class Stubs
6
- require_relative "stubs/chain"
7
- require_relative "stubs/const"
8
-
9
- #
10
- # Register new action and apply the corresponding stub
11
- #
12
- # @params [Hash<#to_s, _>] options
13
- # @return [self] itself
14
- #
15
- def add(options)
16
- options = symbolize(options)
17
- find_or_create_stub!(options)&.update!(options)
18
- self
19
- end
20
-
21
- #
22
- # Applies the stub to RSpec example
23
- #
24
- def apply(example)
25
- @stubs.values.each { |stub| stub.apply!(example) }
26
- end
27
-
28
- private
29
-
30
- def initialize
31
- @stubs = {}
32
- end
33
-
34
- def find_or_create_stub!(options)
35
- stub = case stub_type(options)
36
- when :message_chain then Chain.new(options)
37
- when :constant then Const.new(options)
38
- end
39
-
40
- @stubs[stub.to_s] ||= stub if stub
41
- end
42
-
43
- def stub_type(options)
44
- return :message_chain if options[:class] || options[:object]
45
- return :constant if options[:const]
46
-
47
- raise ArgumentError, <<~MESSAGE
48
- Cannot figure out what to stub from #{options}.
49
- You should define either a class and a message chain, or some const.
50
- MESSAGE
51
- end
52
-
53
- def symbolize(options)
54
- Hash(options).transform_keys { |key| key.to_s.to_sym }
55
- end
56
- end
57
- end