fixturama 0.2.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +77 -0
- data/README.md +44 -0
- data/lib/fixturama.rb +1 -1
- data/lib/fixturama/changes.rb +2 -1
- data/lib/fixturama/changes/base.rb +1 -1
- data/lib/fixturama/changes/chain.rb +1 -1
- data/lib/fixturama/changes/chain/raise_action.rb +13 -5
- data/lib/fixturama/changes/env.rb +35 -0
- data/lib/fixturama/loader.rb +5 -2
- data/lib/fixturama/loader/context.rb +13 -5
- data/lib/fixturama/version.rb +4 -0
- metadata +55 -43
- 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/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 -37
- data/spec/fixturama/seed_fixture/seed.yml +0 -11
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 222290b374b18f7f1e7cd95844e1a8f37d79bb79ee5aa6938fd47de8322800c2
|
4
|
+
data.tar.gz: 915dd027bd5aef3e76d69d21ca5e9cb7b2e367aa0c0a2d5105a4c14e9e9119dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1697a3dbda65ccae635338c933ae0c3267e98573d225796139f9997275a810469cf9e9f0429e14a0edad4044a6ddbaa089015658ff769e3f843a0b6245585289
|
7
|
+
data.tar.gz: 64f98e4b799ca9cf5ac572f8924e3ba537bcb01b284db932b0a81fbaca5ab1695bf444d6ae70494570852de327f77946aab045abeeb4cd7ddcfb6b7ab15b7c13
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,78 @@ All notable changes to this project will be documented in this file.
|
|
5
5
|
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
6
6
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
7
7
|
|
8
|
+
## [0.5.1] - [2021-04-12]
|
9
|
+
|
10
|
+
### Fixed
|
11
|
+
|
12
|
+
- Marshalling of short strings (nepalez)
|
13
|
+
|
14
|
+
## [0.5.0] - [2021-04-03]
|
15
|
+
|
16
|
+
### Added
|
17
|
+
|
18
|
+
- Support for <de>serialization PORO objects (nepalez)
|
19
|
+
|
20
|
+
```yaml
|
21
|
+
# target.yml
|
22
|
+
---
|
23
|
+
number: <%= object(be_positive) %>
|
24
|
+
```
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
RSpec.describe "something" do
|
28
|
+
subject { { "number" => 42 } }
|
29
|
+
|
30
|
+
# no explicit params is needed here
|
31
|
+
let(:target) { load_fixture "target.yml" }
|
32
|
+
|
33
|
+
it { is_expected.to match(target) }
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
## [0.4.1] - [2021-03-31]
|
38
|
+
|
39
|
+
### Fixed
|
40
|
+
|
41
|
+
- Dependency from hashie updated to allow v4+ (nepalez)
|
42
|
+
|
43
|
+
## [0.4.0] - [2020-03-15]
|
44
|
+
|
45
|
+
### Added
|
46
|
+
|
47
|
+
- Support for stubbing ENV variables (nepalez)
|
48
|
+
|
49
|
+
```yaml
|
50
|
+
---
|
51
|
+
- env: GOOGLE_CLOUD_KEY
|
52
|
+
value: foo
|
53
|
+
|
54
|
+
- env: GOOGLE_CLOUD_PASSWORD
|
55
|
+
value: bar
|
56
|
+
```
|
57
|
+
|
58
|
+
This would stub selected variables only, not touching the others
|
59
|
+
|
60
|
+
## [0.3.0] - [2020-03-08]
|
61
|
+
|
62
|
+
### Added
|
63
|
+
|
64
|
+
- Support for exception arguments (nepalez)
|
65
|
+
|
66
|
+
```yaml
|
67
|
+
---
|
68
|
+
- class: API
|
69
|
+
chain: get_product
|
70
|
+
arguments:
|
71
|
+
- 1
|
72
|
+
actions:
|
73
|
+
- raise: API::NotFoundError
|
74
|
+
arguments: # <--- that's that
|
75
|
+
- "Cannot find a product by id: 1"
|
76
|
+
```
|
77
|
+
|
78
|
+
which would raise `API::NotFoundError.new("Cannot find a product by id: 1")`
|
79
|
+
|
8
80
|
## [0.2.0] - [2020-02-17]
|
9
81
|
|
10
82
|
### Added
|
@@ -229,3 +301,8 @@ This is a first public release with features extracted from production app.
|
|
229
301
|
[0.0.7]: https://github.com/nepalez/fixturama/compare/v0.0.6...v0.0.7
|
230
302
|
[0.1.0]: https://github.com/nepalez/fixturama/compare/v0.0.7...v0.1.0
|
231
303
|
[0.2.0]: https://github.com/nepalez/fixturama/compare/v0.1.0...v0.2.0
|
304
|
+
[0.3.0]: https://github.com/nepalez/fixturama/compare/v0.2.0...v0.3.0
|
305
|
+
[0.4.0]: https://github.com/nepalez/fixturama/compare/v0.3.0...v0.4.0
|
306
|
+
[0.4.1]: https://github.com/nepalez/fixturama/compare/v0.4.0...v0.4.1
|
307
|
+
[0.5.0]: https://github.com/nepalez/fixturama/compare/v0.4.1...v0.5.0
|
308
|
+
[0.5.1]: https://github.com/nepalez/fixturama/compare/v0.5.0...v0.5.1
|
data/README.md
CHANGED
@@ -99,6 +99,38 @@ This feature can also be useful to produce a "partially defined" fixtures with [
|
|
99
99
|
subject { load_fixture "#{__dir__}/data.yml", user: kind_of(ActiveRecord::Base) }
|
100
100
|
```
|
101
101
|
|
102
|
+
Since the v0.5.0 we support another way to serialize PORO objects in fixtures. Just wrap them to the `object()` method:
|
103
|
+
|
104
|
+
```yaml
|
105
|
+
---
|
106
|
+
:account: <%= object(user) %>
|
107
|
+
```
|
108
|
+
|
109
|
+
This time you don't need sending objects explicitly.
|
110
|
+
|
111
|
+
```ruby
|
112
|
+
RSpec.describe "example" do
|
113
|
+
subject { load_fixture "#{__dir__}/data.yml" }
|
114
|
+
|
115
|
+
let(:user) { FactoryBot.create(:user) }
|
116
|
+
|
117
|
+
# The same object will be returned
|
118
|
+
it { is_expected.to eq(account: user) }
|
119
|
+
end
|
120
|
+
```
|
121
|
+
|
122
|
+
Under the hood we use `Marshal.dump` and `Marshal.restore` to serialize and deserialize the object back.
|
123
|
+
|
124
|
+
**Notice**, that deserialization creates a new instance of the object which is not equivalent to the source (`user` in the example above)!
|
125
|
+
In most cases this is enough. For example, you can provide matchers like:
|
126
|
+
|
127
|
+
```yaml
|
128
|
+
---
|
129
|
+
number: <%= object(be_positive) %>
|
130
|
+
```
|
131
|
+
|
132
|
+
The loaded object would contain `{ "number" => be_positive }`.
|
133
|
+
|
102
134
|
### Seeding
|
103
135
|
|
104
136
|
The seed (`seed_fixture`) file should be a YAML/JSON with opinionated parameters, namely:
|
@@ -141,6 +173,11 @@ For constants:
|
|
141
173
|
- `const` for stubbed constant
|
142
174
|
- `value` for a value of the constant
|
143
175
|
|
176
|
+
For environment variables:
|
177
|
+
|
178
|
+
- `env` for the name of a variable
|
179
|
+
`value` for a value of the variable
|
180
|
+
|
144
181
|
For http requests:
|
145
182
|
|
146
183
|
- `url` or `uri` for the URI of the request (treats values like `/.../` as regular expressions)
|
@@ -183,10 +220,17 @@ For http requests:
|
|
183
220
|
- return: true
|
184
221
|
repeate: 1 # this is the default value
|
185
222
|
- raise: ActiveRecord::RecordNotFound
|
223
|
+
arguments:
|
224
|
+
- "Profile with id: 1 not found" # for error message
|
186
225
|
|
226
|
+
# Here we stubbing a constant
|
187
227
|
- const: NOTIFIER_TIMEOUT_SEC
|
188
228
|
value: 10
|
189
229
|
|
230
|
+
# This is a stub for ENV['DEFAULT_EMAIL']
|
231
|
+
- env: DEFAULT_EMAIL
|
232
|
+
value: foo@example.com
|
233
|
+
|
190
234
|
# Examples for stubbing HTTP
|
191
235
|
- uri: /example.com/foo/ # regexp!
|
192
236
|
method: delete
|
data/lib/fixturama.rb
CHANGED
data/lib/fixturama/changes.rb
CHANGED
@@ -7,6 +7,7 @@ module Fixturama
|
|
7
7
|
require_relative "changes/base"
|
8
8
|
require_relative "changes/chain"
|
9
9
|
require_relative "changes/const"
|
10
|
+
require_relative "changes/env"
|
10
11
|
require_relative "changes/request"
|
11
12
|
require_relative "changes/seed"
|
12
13
|
|
@@ -20,6 +21,7 @@ module Fixturama
|
|
20
21
|
class: Chain,
|
21
22
|
const: Const,
|
22
23
|
count: Seed,
|
24
|
+
env: Env,
|
23
25
|
headers: Request,
|
24
26
|
http_method: Request,
|
25
27
|
object: Chain,
|
@@ -31,7 +33,6 @@ module Fixturama
|
|
31
33
|
type: Seed,
|
32
34
|
uri: Request,
|
33
35
|
url: Request,
|
34
|
-
value: Const,
|
35
36
|
}.freeze
|
36
37
|
|
37
38
|
# Adds new change to the registry
|
@@ -14,7 +14,7 @@ class Fixturama::Changes
|
|
14
14
|
# @return [Fixturama::Changes::Base]
|
15
15
|
def merge(other)
|
16
16
|
# By default just take the other change if applicable
|
17
|
-
other.
|
17
|
+
other.instance_of?(self.class) && other.key == key ? other : self
|
18
18
|
end
|
19
19
|
|
20
20
|
# @abstract
|
@@ -14,7 +14,7 @@ class Fixturama::Changes
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def merge(other)
|
17
|
-
return self unless other.
|
17
|
+
return self unless other.instance_of?(self.class) && other.key == key
|
18
18
|
|
19
19
|
tap { @arguments = (other.arguments | arguments).sort_by(&:order) }
|
20
20
|
end
|
@@ -15,16 +15,24 @@ class Fixturama::Changes::Chain
|
|
15
15
|
def initialize(**options)
|
16
16
|
@error = error_from options
|
17
17
|
@repeat = repeat_from options
|
18
|
+
rescue StandardError => err
|
19
|
+
raise Fixturama::FixtureError.new("an exception class", options, err)
|
18
20
|
end
|
19
21
|
|
20
22
|
def error_from(options)
|
21
|
-
|
22
|
-
|
23
|
-
|
23
|
+
klass = klass_from(options)
|
24
|
+
params = options[:arguments]
|
25
|
+
params.is_a?(Array) ? klass.new(*params) : klass
|
26
|
+
end
|
27
|
+
|
28
|
+
def klass_from(options)
|
29
|
+
klass = case value = options[:raise]
|
30
|
+
when NilClass, TrueClass, "true" then StandardError
|
31
|
+
when Class then value
|
24
32
|
else Kernel.const_get(value)
|
25
33
|
end
|
26
|
-
|
27
|
-
raise
|
34
|
+
|
35
|
+
klass < Exception ? klass : raise("#{klass} is not an exception")
|
28
36
|
end
|
29
37
|
|
30
38
|
def repeat_from(options)
|
@@ -0,0 +1,35 @@
|
|
1
|
+
class Fixturama::Changes
|
2
|
+
#
|
3
|
+
# @private
|
4
|
+
# Stub an environment variable
|
5
|
+
#
|
6
|
+
class Env < Base
|
7
|
+
# All changes has the same +key+
|
8
|
+
# They will be merged before stubbing (see +call+)
|
9
|
+
def key
|
10
|
+
"ENV"
|
11
|
+
end
|
12
|
+
|
13
|
+
# When we merge 2 env-s, we just merge their options
|
14
|
+
def merge(other)
|
15
|
+
return self unless other.is_a?(self.class)
|
16
|
+
dup.tap { |env| env.options.update(other.options) }
|
17
|
+
end
|
18
|
+
|
19
|
+
def call(example)
|
20
|
+
original = Hash ENV
|
21
|
+
example.send(:stub_const, "ENV", original.merge(options))
|
22
|
+
self
|
23
|
+
end
|
24
|
+
|
25
|
+
protected
|
26
|
+
|
27
|
+
attr_reader :options
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def initialize(**options)
|
32
|
+
@options = { options[:env].to_s => options[:value].to_s }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/fixturama/loader.rb
CHANGED
@@ -15,7 +15,8 @@ class Fixturama::Loader
|
|
15
15
|
|
16
16
|
private
|
17
17
|
|
18
|
-
def initialize(path, opts = {})
|
18
|
+
def initialize(example, path, opts = {})
|
19
|
+
@example = example
|
19
20
|
@path = path
|
20
21
|
@opts = opts.to_h
|
21
22
|
end
|
@@ -33,7 +34,7 @@ class Fixturama::Loader
|
|
33
34
|
end
|
34
35
|
|
35
36
|
def context
|
36
|
-
@context ||=
|
37
|
+
@context ||= Context.new(@example, @opts)
|
37
38
|
end
|
38
39
|
|
39
40
|
def content
|
@@ -71,6 +72,8 @@ class Fixturama::Loader
|
|
71
72
|
# @param [String] string
|
72
73
|
# @return [Object]
|
73
74
|
def finalize_string(string)
|
75
|
+
Marshal.restore(string)
|
76
|
+
rescue StandardError
|
74
77
|
key = string.match(Value::MATCHER)&.captures&.first&.to_s
|
75
78
|
key ? context[key] : string
|
76
79
|
end
|
@@ -1,9 +1,13 @@
|
|
1
1
|
class Fixturama::Loader
|
2
2
|
#
|
3
3
|
# @private
|
4
|
-
# The context
|
4
|
+
# The context bound to some fixture
|
5
5
|
#
|
6
6
|
class Context
|
7
|
+
def object(value)
|
8
|
+
Marshal.dump(value).dump
|
9
|
+
end
|
10
|
+
|
7
11
|
# Get value by key
|
8
12
|
# @param [#to_s] key
|
9
13
|
# @return [Object]
|
@@ -13,7 +17,8 @@ class Fixturama::Loader
|
|
13
17
|
|
14
18
|
private
|
15
19
|
|
16
|
-
def initialize(values)
|
20
|
+
def initialize(example, values)
|
21
|
+
@example = example
|
17
22
|
@values = \
|
18
23
|
Hash(values).each_with_object(Hashie::Mash.new) do |(key, val), obj|
|
19
24
|
obj[key] = Value.new(key, val)
|
@@ -21,11 +26,14 @@ class Fixturama::Loader
|
|
21
26
|
end
|
22
27
|
|
23
28
|
def respond_to_missing?(name, *)
|
24
|
-
@values.respond_to?(name) || super
|
29
|
+
@values.key?(name) || @example.respond_to?(name) || super
|
25
30
|
end
|
26
31
|
|
27
|
-
def method_missing(name, *args)
|
28
|
-
@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)
|
29
37
|
end
|
30
38
|
end
|
31
39
|
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.
|
4
|
+
version: 0.5.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:
|
11
|
+
date: 2021-04-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: factory_bot
|
@@ -42,16 +42,22 @@ dependencies:
|
|
42
42
|
name: hashie
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '3
|
47
|
+
version: '3'
|
48
|
+
- - "<"
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '5'
|
48
51
|
type: :runtime
|
49
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
|
56
62
|
name: webmock
|
57
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,43 +78,61 @@ dependencies:
|
|
72
78
|
requirements:
|
73
79
|
- - "~>"
|
74
80
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
81
|
+
version: '13.0'
|
76
82
|
type: :development
|
77
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
|
84
90
|
name: rspec-its
|
85
91
|
requirement: !ruby/object:Gem::Requirement
|
86
92
|
requirements:
|
87
93
|
- - "~>"
|
88
94
|
- !ruby/object:Gem::Version
|
89
|
-
version: '1.
|
95
|
+
version: '1.3'
|
90
96
|
type: :development
|
91
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
|
98
104
|
name: rubocop
|
99
105
|
requirement: !ruby/object:Gem::Requirement
|
100
106
|
requirements:
|
101
107
|
- - "~>"
|
102
108
|
- !ruby/object:Gem::Version
|
103
|
-
version: '0.
|
109
|
+
version: '0.80'
|
104
110
|
type: :development
|
105
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,16 +140,8 @@ 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
|
130
146
|
- lib/fixturama/changes.rb
|
131
147
|
- lib/fixturama/changes/base.rb
|
@@ -135,6 +151,7 @@ files:
|
|
135
151
|
- lib/fixturama/changes/chain/raise_action.rb
|
136
152
|
- lib/fixturama/changes/chain/return_action.rb
|
137
153
|
- lib/fixturama/changes/const.rb
|
154
|
+
- lib/fixturama/changes/env.rb
|
138
155
|
- lib/fixturama/changes/request.rb
|
139
156
|
- lib/fixturama/changes/request/response.rb
|
140
157
|
- lib/fixturama/changes/request/responses.rb
|
@@ -145,21 +162,25 @@ files:
|
|
145
162
|
- lib/fixturama/loader/context.rb
|
146
163
|
- lib/fixturama/loader/value.rb
|
147
164
|
- lib/fixturama/rspec.rb
|
148
|
-
-
|
149
|
-
- spec/fixturama/load_fixture/data.json
|
150
|
-
- spec/fixturama/load_fixture/data.yaml
|
151
|
-
- spec/fixturama/load_fixture/data.yml
|
152
|
-
- spec/fixturama/seed_fixture/_spec.rb
|
153
|
-
- spec/fixturama/seed_fixture/seed.yml
|
154
|
-
- spec/fixturama/stub_fixture/_spec.rb
|
155
|
-
- spec/fixturama/stub_fixture/stub.yml
|
156
|
-
- spec/spec_helper.rb
|
165
|
+
- lib/fixturama/version.rb
|
157
166
|
homepage: https://github.com/nepalez/fixturama
|
158
167
|
licenses:
|
159
168
|
- MIT
|
160
|
-
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
|
161
175
|
post_install_message:
|
162
|
-
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"
|
163
184
|
require_paths:
|
164
185
|
- lib
|
165
186
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -173,17 +194,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
173
194
|
- !ruby/object:Gem::Version
|
174
195
|
version: '0'
|
175
196
|
requirements: []
|
176
|
-
rubygems_version: 3.0.
|
197
|
+
rubygems_version: 3.0.8
|
177
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: []
|
data/.gitignore
DELETED
data/.rspec
DELETED
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
|
-
Layout/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,17 +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.7.0
|
14
|
-
- ruby-head
|
15
|
-
matrix:
|
16
|
-
allow_failures:
|
17
|
-
- rvm: ruby-head
|
data/Gemfile
DELETED
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
data/fixturama.gemspec
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
Gem::Specification.new do |gem|
|
2
|
-
gem.name = "fixturama"
|
3
|
-
gem.version = "0.2.0"
|
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.0"
|
19
|
-
gem.add_runtime_dependency "webmock", "~> 3.0"
|
20
|
-
|
21
|
-
gem.add_development_dependency "rake", "~> 10"
|
22
|
-
gem.add_development_dependency "rspec-its", "~> 1.0"
|
23
|
-
gem.add_development_dependency "rubocop", "~> 0.49"
|
24
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
RSpec.describe "load_fixture" do
|
2
|
-
let(:expected) { { "foo" => { "bar" => 42 } } }
|
3
|
-
|
4
|
-
context "YAML" do
|
5
|
-
subject { load_fixture("#{__dir__}/data.yaml", id: 42) }
|
6
|
-
|
7
|
-
it { is_expected.to eq expected }
|
8
|
-
end
|
9
|
-
|
10
|
-
context "YML" do
|
11
|
-
subject { load_fixture("#{__dir__}/data.yml", id: 42) }
|
12
|
-
|
13
|
-
it { is_expected.to eq expected }
|
14
|
-
end
|
15
|
-
|
16
|
-
context "YAML with ruby object" do
|
17
|
-
subject { load_fixture("#{__dir__}/data.yaml", id: foobar) }
|
18
|
-
|
19
|
-
before { class Test::Foobar; end }
|
20
|
-
|
21
|
-
let(:foobar) { Test::Foobar.new }
|
22
|
-
let(:expected) { { "foo" => { "bar" => foobar } } }
|
23
|
-
|
24
|
-
it { is_expected.to eq expected }
|
25
|
-
end
|
26
|
-
|
27
|
-
context "JSON" do
|
28
|
-
subject { load_fixture("#{__dir__}/data.json", id: 42) }
|
29
|
-
|
30
|
-
it { is_expected.to eq expected }
|
31
|
-
end
|
32
|
-
|
33
|
-
context "JSON with ruby object" do
|
34
|
-
subject { load_fixture("#{__dir__}/data.json", id: foobar) }
|
35
|
-
|
36
|
-
before { class Test::Foobar; end }
|
37
|
-
|
38
|
-
let(:foobar) { Test::Foobar.new }
|
39
|
-
let(:expected) { { "foo" => { "bar" => foobar } } }
|
40
|
-
|
41
|
-
it { is_expected.to eq expected }
|
42
|
-
end
|
43
|
-
|
44
|
-
context "with RSpec argument matchers" do
|
45
|
-
subject { load_fixture("#{__dir__}/data.yaml", id: kind_of(Numeric)) }
|
46
|
-
|
47
|
-
it "loads the matcher", aggregate_failures: true do
|
48
|
-
expect("foo" => { "bar" => 42 }).to include subject
|
49
|
-
expect("foo" => { "bar" => 99 }).to include subject
|
50
|
-
expect("foo" => { "bar" => :a }).not_to include subject
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
RSpec.describe "seed_fixture" do
|
2
|
-
subject { seed_fixture "#{__dir__}/seed.yml" }
|
3
|
-
|
4
|
-
before do
|
5
|
-
FactoryBot.define do
|
6
|
-
factory :foo, class: Hash do
|
7
|
-
transient do
|
8
|
-
bar { 0 }
|
9
|
-
baz { 0 }
|
10
|
-
qux { 0 }
|
11
|
-
end
|
12
|
-
|
13
|
-
trait :bar do
|
14
|
-
bar { 99 }
|
15
|
-
end
|
16
|
-
|
17
|
-
trait :baz do
|
18
|
-
baz { 77 }
|
19
|
-
end
|
20
|
-
|
21
|
-
skip_create
|
22
|
-
initialize_with { { bar: bar, baz: baz, qux: qux } }
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
it "runs the factory", aggregate_failures: true do
|
28
|
-
expect(FactoryBot).to receive(:create_list).with(:foo, 1, :baz, qux: 42)
|
29
|
-
|
30
|
-
expect(FactoryBot).to receive(:create_list) do |*args, **opts|
|
31
|
-
expect(args).to eq [:foo, 3, :bar]
|
32
|
-
expect(opts).to be_empty
|
33
|
-
end
|
34
|
-
|
35
|
-
subject
|
36
|
-
end
|
37
|
-
end
|
@@ -1,120 +0,0 @@
|
|
1
|
-
RSpec.describe "stub_fixture" do
|
2
|
-
subject { arguments.map { |argument| Payment.new.pay(argument) } }
|
3
|
-
|
4
|
-
before do
|
5
|
-
class Payment
|
6
|
-
def pay(_)
|
7
|
-
5
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
context "without stubbing" do
|
13
|
-
let(:arguments) { [0] }
|
14
|
-
|
15
|
-
it { is_expected.to eq [5] }
|
16
|
-
end
|
17
|
-
|
18
|
-
context "when message chain stubbed" do
|
19
|
-
before { stub_fixture "#{__dir__}/stub.yml" }
|
20
|
-
|
21
|
-
context "with a :raise option" do
|
22
|
-
let(:arguments) { [0] }
|
23
|
-
|
24
|
-
it "raises an exception" do
|
25
|
-
expect { subject }.to raise_error ArgumentError
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
context "with a :return option" do
|
30
|
-
let(:arguments) { [1] }
|
31
|
-
|
32
|
-
it "returns stubbed value" do
|
33
|
-
expect(subject).to eq [8]
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
context "with several actions" do
|
38
|
-
let(:arguments) { [2] * 4 }
|
39
|
-
|
40
|
-
it "calls the consecutive actions and then repeates the last one" do
|
41
|
-
expect(subject).to eq [4, 2, 0, 0]
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context "with multi-count actions" do
|
46
|
-
let(:arguments) { [3] * 4 }
|
47
|
-
|
48
|
-
it "repeats the action a specified number of times" do
|
49
|
-
expect(subject).to eq [6, 6, 0, 0]
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
context "with several arguments" do
|
54
|
-
let(:arguments) { [2, 3, 2, 3, 2, 3] }
|
55
|
-
|
56
|
-
it "counts actions for every stub in isolation from the others" do
|
57
|
-
expect(subject).to eq [4, 6, 2, 6, 0, 0]
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
context "with partially defined options" do
|
62
|
-
subject { Payment.new.pay(10, overdraft: true, notiy: true) }
|
63
|
-
|
64
|
-
it "uses the stub" do
|
65
|
-
expect(subject).to eq(-5)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
context "when options differ" do
|
70
|
-
subject { Payment.new.pay(10, overdraft: false) }
|
71
|
-
|
72
|
-
it "uses universal stub" do
|
73
|
-
expect(subject).to eq(-1)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
context "with unspecified argument" do
|
78
|
-
let(:arguments) { [4] }
|
79
|
-
|
80
|
-
it "uses universal stub" do
|
81
|
-
expect(subject).to eq [-1]
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
context "when constant stubbed" do
|
87
|
-
before do
|
88
|
-
TIMEOUT = 20
|
89
|
-
stub_fixture "#{__dir__}/stub.yml"
|
90
|
-
end
|
91
|
-
|
92
|
-
it "stubs the constant" do
|
93
|
-
expect(TIMEOUT).to eq 10
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
context "when http request stubbed" do
|
98
|
-
before { stub_fixture "#{__dir__}/stub.yml" }
|
99
|
-
|
100
|
-
it "stubs the request properly" do
|
101
|
-
req = Net::HTTP::Get.new("/foo")
|
102
|
-
res = Net::HTTP.start("www.example.com") { |http| http.request(req) }
|
103
|
-
|
104
|
-
expect(res.code).to eq "200"
|
105
|
-
expect(res.body).to eq "foo"
|
106
|
-
expect(res["Content-Length"]).to eq "3"
|
107
|
-
end
|
108
|
-
|
109
|
-
def delete_request
|
110
|
-
req = Net::HTTP::Delete.new("/foo")
|
111
|
-
Net::HTTP.start("www.example.com") { |http| http.request(req) }
|
112
|
-
end
|
113
|
-
|
114
|
-
it "stubs repetitive requests properly" do
|
115
|
-
expect(delete_request.code).to eq "200"
|
116
|
-
expect(delete_request.code).to eq "404"
|
117
|
-
expect(delete_request.code).to eq "404"
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
@@ -1,73 +0,0 @@
|
|
1
|
-
---
|
2
|
-
- class: Payment
|
3
|
-
chain:
|
4
|
-
- new
|
5
|
-
- pay
|
6
|
-
actions:
|
7
|
-
- return: -1
|
8
|
-
|
9
|
-
- class: Payment
|
10
|
-
chain:
|
11
|
-
- new
|
12
|
-
- pay
|
13
|
-
arguments:
|
14
|
-
- 0
|
15
|
-
actions:
|
16
|
-
- raise: ArgumentError
|
17
|
-
|
18
|
-
- class: Payment
|
19
|
-
chain:
|
20
|
-
- new
|
21
|
-
- pay
|
22
|
-
arguments:
|
23
|
-
- 1
|
24
|
-
actions:
|
25
|
-
- return: 8
|
26
|
-
|
27
|
-
- class: Payment
|
28
|
-
chain:
|
29
|
-
- new
|
30
|
-
- pay
|
31
|
-
arguments:
|
32
|
-
- 2
|
33
|
-
actions:
|
34
|
-
- return: 4
|
35
|
-
- return: 2
|
36
|
-
- return: 0
|
37
|
-
|
38
|
-
- object: Payment.itself
|
39
|
-
chain:
|
40
|
-
- new
|
41
|
-
- pay
|
42
|
-
arguments:
|
43
|
-
- 3
|
44
|
-
actions:
|
45
|
-
- return: 6
|
46
|
-
repeat: 2
|
47
|
-
- return: 0
|
48
|
-
|
49
|
-
- class: Payment
|
50
|
-
chain:
|
51
|
-
- new
|
52
|
-
- pay
|
53
|
-
arguments:
|
54
|
-
- 10
|
55
|
-
- :overdraft: true
|
56
|
-
actions:
|
57
|
-
- return: -5
|
58
|
-
|
59
|
-
- const: TIMEOUT
|
60
|
-
value: 10
|
61
|
-
|
62
|
-
- method: get
|
63
|
-
uri: www.example.com/foo
|
64
|
-
responses:
|
65
|
-
- body: foo
|
66
|
-
headers:
|
67
|
-
Content-Length: 3
|
68
|
-
|
69
|
-
- method: delete
|
70
|
-
uri: /example.com/foo/ # Regexp!
|
71
|
-
responses:
|
72
|
-
- status: 200
|
73
|
-
- status: 404 # for any request except for the first one
|
data/spec/spec_helper.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require "pry"
|
3
|
-
rescue LoadError
|
4
|
-
nil
|
5
|
-
end
|
6
|
-
|
7
|
-
require "bundler/setup"
|
8
|
-
require "fixturama/rspec"
|
9
|
-
|
10
|
-
RSpec.configure do |config|
|
11
|
-
# Enable flags like --only-failures and --next-failure
|
12
|
-
config.example_status_persistence_file_path = ".rspec_status"
|
13
|
-
|
14
|
-
# Disable RSpec exposing methods globally on `Module` and `main`
|
15
|
-
config.disable_monkey_patching!
|
16
|
-
|
17
|
-
config.expect_with :rspec do |c|
|
18
|
-
c.syntax = :expect
|
19
|
-
end
|
20
|
-
|
21
|
-
config.around do |example|
|
22
|
-
module Test; end
|
23
|
-
example.run
|
24
|
-
Object.send(:remove_const, :Test)
|
25
|
-
end
|
26
|
-
end
|