fixturama 0.1.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +99 -0
- data/README.md +76 -4
- data/lib/fixturama.rb +48 -20
- data/lib/fixturama/changes.rb +72 -0
- data/lib/fixturama/changes/base.rb +28 -0
- data/lib/fixturama/changes/chain.rb +64 -0
- data/lib/fixturama/changes/chain/actions.rb +31 -0
- data/lib/fixturama/changes/chain/arguments.rb +59 -0
- data/lib/fixturama/changes/chain/raise_action.rb +43 -0
- data/lib/fixturama/changes/chain/return_action.rb +33 -0
- data/lib/fixturama/changes/const.rb +30 -0
- data/lib/fixturama/changes/env.rb +35 -0
- data/lib/fixturama/changes/request.rb +91 -0
- data/lib/fixturama/changes/request/response.rb +62 -0
- data/lib/fixturama/changes/request/responses.rb +22 -0
- data/lib/fixturama/changes/seed.rb +39 -0
- data/lib/fixturama/config.rb +5 -0
- data/lib/fixturama/fixture_error.rb +31 -0
- data/lib/fixturama/loader.rb +6 -2
- data/lib/fixturama/loader/context.rb +14 -5
- data/lib/fixturama/loader/value.rb +1 -0
- data/lib/fixturama/version.rb +4 -0
- metadata +85 -73
- data/.gitignore +0 -12
- data/.rspec +0 -2
- data/.rubocop.yml +0 -22
- data/.travis.yml +0 -17
- data/Gemfile +0 -9
- data/LICENSE.txt +0 -21
- data/Rakefile +0 -6
- data/fixturama.gemspec +0 -24
- data/lib/fixturama/seed.rb +0 -15
- data/lib/fixturama/stubs.rb +0 -79
- data/lib/fixturama/stubs/chain.rb +0 -90
- data/lib/fixturama/stubs/chain/actions.rb +0 -39
- data/lib/fixturama/stubs/chain/actions/raise.rb +0 -21
- data/lib/fixturama/stubs/chain/actions/return.rb +0 -23
- data/lib/fixturama/stubs/chain/arguments.rb +0 -86
- data/lib/fixturama/stubs/const.rb +0 -43
- data/lib/fixturama/stubs/request.rb +0 -98
- data/lib/fixturama/stubs/request/response.rb +0 -43
- data/lib/fixturama/stubs/request/responses.rb +0 -20
- data/lib/fixturama/utils.rb +0 -39
- data/spec/fixturama/load_fixture/_spec.rb +0 -53
- data/spec/fixturama/load_fixture/data.json +0 -5
- data/spec/fixturama/load_fixture/data.yaml +0 -3
- data/spec/fixturama/load_fixture/data.yml +0 -3
- data/spec/fixturama/seed_fixture/_spec.rb +0 -36
- data/spec/fixturama/seed_fixture/seed.yml +0 -16
- data/spec/fixturama/stub_fixture/_spec.rb +0 -120
- data/spec/fixturama/stub_fixture/stub.yml +0 -73
- data/spec/spec_helper.rb +0 -26
@@ -0,0 +1,22 @@
|
|
1
|
+
class Fixturama::Changes::Request
|
2
|
+
#
|
3
|
+
# @private
|
4
|
+
# Iterate by a consecutive responses to the request
|
5
|
+
#
|
6
|
+
class Responses
|
7
|
+
# @return [Fixturama::Changes::Request::Response]
|
8
|
+
def next
|
9
|
+
@list.count > 1 ? @list.pop : @list.first
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def initialize(*list)
|
15
|
+
list = [{ status: 200 }] if list.empty?
|
16
|
+
@list = list.flatten.reverse.flat_map do |item|
|
17
|
+
response = Response.new(item)
|
18
|
+
[response.to_h] * response.repeat
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
class Fixturama::Changes
|
2
|
+
#
|
3
|
+
# @private
|
4
|
+
# Seed objects using the +FactoryBot+
|
5
|
+
#
|
6
|
+
class Seed < Base
|
7
|
+
private
|
8
|
+
|
9
|
+
def initialize(**options)
|
10
|
+
@type = type_from(options)
|
11
|
+
@traits = traits_from(options)
|
12
|
+
@params = params_from(options)
|
13
|
+
@count = count_from(options)
|
14
|
+
create_object
|
15
|
+
end
|
16
|
+
|
17
|
+
def type_from(options)
|
18
|
+
options[:type]&.to_sym&.tap { |value| return value }
|
19
|
+
raise Fixturama::FixtureError.new("a factory", options)
|
20
|
+
end
|
21
|
+
|
22
|
+
def traits_from(options)
|
23
|
+
Array(options[:traits]).map(&:to_sym)
|
24
|
+
end
|
25
|
+
|
26
|
+
def params_from(options)
|
27
|
+
Hash(options[:params]).transform_keys(&:to_sym)
|
28
|
+
end
|
29
|
+
|
30
|
+
def count_from(options)
|
31
|
+
options.fetch(:count, 1).to_i.tap { |val| return val if val.positive? }
|
32
|
+
raise Fixturama::FixtureError.new("a valid number of objects", options)
|
33
|
+
end
|
34
|
+
|
35
|
+
def create_object
|
36
|
+
FactoryBot.create_list(@type, @count, *@traits, **@params)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/fixturama/config.rb
CHANGED
@@ -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
|
data/lib/fixturama/loader.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#
|
2
|
+
# @private
|
2
3
|
# Load fixture with some options
|
3
4
|
#
|
4
5
|
class Fixturama::Loader
|
@@ -14,7 +15,8 @@ class Fixturama::Loader
|
|
14
15
|
|
15
16
|
private
|
16
17
|
|
17
|
-
def initialize(path, opts = {})
|
18
|
+
def initialize(example, path, opts = {})
|
19
|
+
@example = example
|
18
20
|
@path = path
|
19
21
|
@opts = opts.to_h
|
20
22
|
end
|
@@ -32,7 +34,7 @@ class Fixturama::Loader
|
|
32
34
|
end
|
33
35
|
|
34
36
|
def context
|
35
|
-
@context ||=
|
37
|
+
@context ||= Context.new(@example, @opts)
|
36
38
|
end
|
37
39
|
|
38
40
|
def content
|
@@ -70,6 +72,8 @@ class Fixturama::Loader
|
|
70
72
|
# @param [String] string
|
71
73
|
# @return [Object]
|
72
74
|
def finalize_string(string)
|
75
|
+
Marshal.restore(string)
|
76
|
+
rescue TypeError, RuntimeError
|
73
77
|
key = string.match(Value::MATCHER)&.captures&.first&.to_s
|
74
78
|
key ? context[key] : string
|
75
79
|
end
|
@@ -1,8 +1,13 @@
|
|
1
1
|
class Fixturama::Loader
|
2
2
|
#
|
3
|
-
#
|
3
|
+
# @private
|
4
|
+
# The context bound to some fixture
|
4
5
|
#
|
5
6
|
class Context
|
7
|
+
def object(value)
|
8
|
+
Marshal.dump(value).dump
|
9
|
+
end
|
10
|
+
|
6
11
|
# Get value by key
|
7
12
|
# @param [#to_s] key
|
8
13
|
# @return [Object]
|
@@ -12,7 +17,8 @@ class Fixturama::Loader
|
|
12
17
|
|
13
18
|
private
|
14
19
|
|
15
|
-
def initialize(values)
|
20
|
+
def initialize(example, values)
|
21
|
+
@example = example
|
16
22
|
@values = \
|
17
23
|
Hash(values).each_with_object(Hashie::Mash.new) do |(key, val), obj|
|
18
24
|
obj[key] = Value.new(key, val)
|
@@ -20,11 +26,14 @@ class Fixturama::Loader
|
|
20
26
|
end
|
21
27
|
|
22
28
|
def respond_to_missing?(name, *)
|
23
|
-
@values.respond_to?(name) || super
|
29
|
+
@values.key?(name) || @example.respond_to?(name) || super
|
24
30
|
end
|
25
31
|
|
26
|
-
def method_missing(name, *args)
|
27
|
-
@values
|
32
|
+
def method_missing(name, *args, &block)
|
33
|
+
return @values[name] if @values.key?(name)
|
34
|
+
return super unless @example.respond_to?(name)
|
35
|
+
|
36
|
+
@example.send(name, *args, &block)
|
28
37
|
end
|
29
38
|
end
|
30
39
|
end
|
metadata
CHANGED
@@ -1,114 +1,138 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fixturama
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kozin (nepalez)
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
+
name: factory_bot
|
14
15
|
requirement: !ruby/object:Gem::Requirement
|
15
16
|
requirements:
|
16
17
|
- - "~>"
|
17
18
|
- !ruby/object:Gem::Version
|
18
19
|
version: '4.0'
|
19
|
-
name: factory_bot
|
20
|
-
prerelease: false
|
21
20
|
type: :runtime
|
21
|
+
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '4.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
28
29
|
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
31
|
- - "~>"
|
31
32
|
- !ruby/object:Gem::Version
|
32
33
|
version: '3.0'
|
33
|
-
name: rspec
|
34
|
-
prerelease: false
|
35
34
|
type: :runtime
|
35
|
+
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '3.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
+
name: hashie
|
42
43
|
requirement: !ruby/object:Gem::Requirement
|
43
44
|
requirements:
|
44
|
-
- - "
|
45
|
+
- - ">"
|
45
46
|
- !ruby/object:Gem::Version
|
46
|
-
version: '3
|
47
|
-
|
48
|
-
|
47
|
+
version: '3'
|
48
|
+
- - "<"
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '5'
|
49
51
|
type: :runtime
|
52
|
+
prerelease: false
|
50
53
|
version_requirements: !ruby/object:Gem::Requirement
|
51
54
|
requirements:
|
52
|
-
- - "
|
55
|
+
- - ">"
|
53
56
|
- !ruby/object:Gem::Version
|
54
|
-
version: '3
|
57
|
+
version: '3'
|
58
|
+
- - "<"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '5'
|
55
61
|
- !ruby/object:Gem::Dependency
|
62
|
+
name: webmock
|
56
63
|
requirement: !ruby/object:Gem::Requirement
|
57
64
|
requirements:
|
58
65
|
- - "~>"
|
59
66
|
- !ruby/object:Gem::Version
|
60
67
|
version: '3.0'
|
61
|
-
name: webmock
|
62
|
-
prerelease: false
|
63
68
|
type: :runtime
|
69
|
+
prerelease: false
|
64
70
|
version_requirements: !ruby/object:Gem::Requirement
|
65
71
|
requirements:
|
66
72
|
- - "~>"
|
67
73
|
- !ruby/object:Gem::Version
|
68
74
|
version: '3.0'
|
69
75
|
- !ruby/object:Gem::Dependency
|
76
|
+
name: rake
|
70
77
|
requirement: !ruby/object:Gem::Requirement
|
71
78
|
requirements:
|
72
79
|
- - "~>"
|
73
80
|
- !ruby/object:Gem::Version
|
74
|
-
version: '
|
75
|
-
name: rake
|
76
|
-
prerelease: false
|
81
|
+
version: '13.0'
|
77
82
|
type: :development
|
83
|
+
prerelease: false
|
78
84
|
version_requirements: !ruby/object:Gem::Requirement
|
79
85
|
requirements:
|
80
86
|
- - "~>"
|
81
87
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
88
|
+
version: '13.0'
|
83
89
|
- !ruby/object:Gem::Dependency
|
90
|
+
name: rspec-its
|
84
91
|
requirement: !ruby/object:Gem::Requirement
|
85
92
|
requirements:
|
86
93
|
- - "~>"
|
87
94
|
- !ruby/object:Gem::Version
|
88
|
-
version: '1.
|
89
|
-
name: rspec-its
|
90
|
-
prerelease: false
|
95
|
+
version: '1.3'
|
91
96
|
type: :development
|
97
|
+
prerelease: false
|
92
98
|
version_requirements: !ruby/object:Gem::Requirement
|
93
99
|
requirements:
|
94
100
|
- - "~>"
|
95
101
|
- !ruby/object:Gem::Version
|
96
|
-
version: '1.
|
102
|
+
version: '1.3'
|
97
103
|
- !ruby/object:Gem::Dependency
|
104
|
+
name: rubocop
|
98
105
|
requirement: !ruby/object:Gem::Requirement
|
99
106
|
requirements:
|
100
107
|
- - "~>"
|
101
108
|
- !ruby/object:Gem::Version
|
102
|
-
version: '0.
|
103
|
-
name: rubocop
|
104
|
-
prerelease: false
|
109
|
+
version: '0.80'
|
105
110
|
type: :development
|
111
|
+
prerelease: false
|
106
112
|
version_requirements: !ruby/object:Gem::Requirement
|
107
113
|
requirements:
|
108
114
|
- - "~>"
|
109
115
|
- !ruby/object:Gem::Version
|
110
|
-
version: '0.
|
111
|
-
|
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.
|
112
136
|
email: andrew.kozin@gmail.com
|
113
137
|
executables: []
|
114
138
|
extensions: []
|
@@ -116,49 +140,47 @@ extra_rdoc_files:
|
|
116
140
|
- README.md
|
117
141
|
- CHANGELOG.md
|
118
142
|
files:
|
119
|
-
- ".gitignore"
|
120
|
-
- ".rspec"
|
121
|
-
- ".rubocop.yml"
|
122
|
-
- ".travis.yml"
|
123
143
|
- CHANGELOG.md
|
124
|
-
- Gemfile
|
125
|
-
- LICENSE.txt
|
126
144
|
- README.md
|
127
|
-
- Rakefile
|
128
|
-
- fixturama.gemspec
|
129
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
|
130
159
|
- lib/fixturama/config.rb
|
160
|
+
- lib/fixturama/fixture_error.rb
|
131
161
|
- lib/fixturama/loader.rb
|
132
162
|
- lib/fixturama/loader/context.rb
|
133
163
|
- lib/fixturama/loader/value.rb
|
134
164
|
- lib/fixturama/rspec.rb
|
135
|
-
- lib/fixturama/
|
136
|
-
- lib/fixturama/stubs.rb
|
137
|
-
- lib/fixturama/stubs/chain.rb
|
138
|
-
- lib/fixturama/stubs/chain/actions.rb
|
139
|
-
- lib/fixturama/stubs/chain/actions/raise.rb
|
140
|
-
- lib/fixturama/stubs/chain/actions/return.rb
|
141
|
-
- lib/fixturama/stubs/chain/arguments.rb
|
142
|
-
- lib/fixturama/stubs/const.rb
|
143
|
-
- lib/fixturama/stubs/request.rb
|
144
|
-
- lib/fixturama/stubs/request/response.rb
|
145
|
-
- lib/fixturama/stubs/request/responses.rb
|
146
|
-
- lib/fixturama/utils.rb
|
147
|
-
- spec/fixturama/load_fixture/_spec.rb
|
148
|
-
- spec/fixturama/load_fixture/data.json
|
149
|
-
- spec/fixturama/load_fixture/data.yaml
|
150
|
-
- spec/fixturama/load_fixture/data.yml
|
151
|
-
- spec/fixturama/seed_fixture/_spec.rb
|
152
|
-
- spec/fixturama/seed_fixture/seed.yml
|
153
|
-
- spec/fixturama/stub_fixture/_spec.rb
|
154
|
-
- spec/fixturama/stub_fixture/stub.yml
|
155
|
-
- spec/spec_helper.rb
|
165
|
+
- lib/fixturama/version.rb
|
156
166
|
homepage: https://github.com/nepalez/fixturama
|
157
167
|
licenses:
|
158
168
|
- MIT
|
159
|
-
metadata:
|
160
|
-
|
161
|
-
|
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
|
175
|
+
post_install_message:
|
176
|
+
rdoc_options:
|
177
|
+
- "--title"
|
178
|
+
- Fixturama - fixtures on steroids
|
179
|
+
- "--main"
|
180
|
+
- README.md
|
181
|
+
- "--line-numbers"
|
182
|
+
- "--inline-source"
|
183
|
+
- "--quiet"
|
162
184
|
require_paths:
|
163
185
|
- lib
|
164
186
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -172,18 +194,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
172
194
|
- !ruby/object:Gem::Version
|
173
195
|
version: '0'
|
174
196
|
requirements: []
|
175
|
-
|
176
|
-
|
177
|
-
signing_key:
|
197
|
+
rubygems_version: 3.0.8
|
198
|
+
signing_key:
|
178
199
|
specification_version: 4
|
179
200
|
summary: A set of helpers to prettify specs with fixtures
|
180
|
-
test_files:
|
181
|
-
- spec/fixturama/load_fixture/_spec.rb
|
182
|
-
- spec/fixturama/load_fixture/data.json
|
183
|
-
- spec/fixturama/load_fixture/data.yaml
|
184
|
-
- spec/fixturama/load_fixture/data.yml
|
185
|
-
- spec/fixturama/seed_fixture/_spec.rb
|
186
|
-
- spec/fixturama/seed_fixture/seed.yml
|
187
|
-
- spec/fixturama/stub_fixture/_spec.rb
|
188
|
-
- spec/fixturama/stub_fixture/stub.yml
|
189
|
-
- spec/spec_helper.rb
|
201
|
+
test_files: []
|