fixturama 0.0.6 → 0.0.7
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 +4 -4
- data/CHANGELOG.md +42 -0
- data/fixturama.gemspec +1 -1
- data/lib/fixturama/stubs.rb +7 -9
- data/lib/fixturama/stubs/chain.rb +5 -2
- data/lib/fixturama/stubs/chain/arguments.rb +10 -1
- data/lib/fixturama/utils.rb +6 -0
- data/spec/fixturama/stub_fixture/_spec.rb +16 -0
- data/spec/fixturama/stub_fixture/stub.yml +11 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 64d9722c641abfd4aa64fbf45b8f1177f768d1b8d2b99a89aa824e1f64db9417
|
4
|
+
data.tar.gz: e1186c8944916943bbab46584747553b07b9d5cfc4e9d875d1a401fc8bd7017a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29d44cd1b06c482ba40df2d4397c064888a64ae1f9a0a4151aa581bf81a83e9ca1a5e84c052340d515032d0f580f11418f9838a5efe00fd722401117248a0311
|
7
|
+
data.tar.gz: 2b8a86f7fffdb20bae92839790254e052d2dbbbb39172003c9cfb4439620c782e4bc3f2ccdd985540dcba4d19e1fc228a3f7d940d58a865ad289f2f265427589
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,47 @@ 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.0.7] - [2019-07-01]
|
9
|
+
|
10
|
+
### Added
|
11
|
+
|
12
|
+
- Stubbing of an arbitrary option (nepalez)
|
13
|
+
|
14
|
+
```yaml
|
15
|
+
---
|
16
|
+
- object: Rails.application
|
17
|
+
chain:
|
18
|
+
- env
|
19
|
+
actions:
|
20
|
+
- return: production
|
21
|
+
```
|
22
|
+
|
23
|
+
### Changed
|
24
|
+
|
25
|
+
- Partially defined options will satisfy an expectation (nepalez)
|
26
|
+
|
27
|
+
```yaml
|
28
|
+
---
|
29
|
+
- class: Payment
|
30
|
+
chain:
|
31
|
+
- call
|
32
|
+
arguments:
|
33
|
+
- 1
|
34
|
+
- :overdraft: true
|
35
|
+
actions:
|
36
|
+
- return: 3
|
37
|
+
```
|
38
|
+
|
39
|
+
This works even though the key `:notify` was not defined by the stub:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
Payment.call 1, overdraft: true, notify: true
|
43
|
+
```
|
44
|
+
|
45
|
+
Notice, that these method works for key arguments only
|
46
|
+
(symbolized hash as the last argument).
|
47
|
+
|
48
|
+
|
8
49
|
## [0.0.6] - [2019-06-09]
|
9
50
|
|
10
51
|
### Added
|
@@ -133,3 +174,4 @@ This is a first public release with features extracted from production app.
|
|
133
174
|
[0.0.4]: https://github.com/nepalez/fixturama/compare/v0.0.3...v0.0.4
|
134
175
|
[0.0.5]: https://github.com/nepalez/fixturama/compare/v0.0.4...v0.0.5
|
135
176
|
[0.0.6]: https://github.com/nepalez/fixturama/compare/v0.0.5...v0.0.6
|
177
|
+
[0.0.7]: https://github.com/nepalez/fixturama/compare/v0.0.6...v0.0.7
|
data/fixturama.gemspec
CHANGED
data/lib/fixturama/stubs.rb
CHANGED
@@ -32,18 +32,16 @@ module Fixturama
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def find_or_create_stub!(options)
|
35
|
-
case stub_type(options)
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
@stubs[anchor] ||= Const.new(anchor)
|
42
|
-
end
|
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
|
43
41
|
end
|
44
42
|
|
45
43
|
def stub_type(options)
|
46
|
-
return :message_chain if options[:class]
|
44
|
+
return :message_chain if options[:class] || options[:object]
|
47
45
|
return :constant if options[:const]
|
48
46
|
|
49
47
|
raise ArgumentError, <<~MESSAGE
|
@@ -54,12 +54,15 @@ module Fixturama
|
|
54
54
|
private
|
55
55
|
|
56
56
|
def initialize(**options)
|
57
|
-
@receiver = Utils.constantize options[:class]
|
57
|
+
@receiver = Utils.constantize options[:class] if options.key?(:class)
|
58
|
+
@receiver ||= Object.send :eval, options[:object] if options.key?(:object)
|
59
|
+
raise SyntaxError, "Undefined receiver of messages" unless receiver
|
60
|
+
|
58
61
|
@messages = Utils.symbolize_array options[:chain]
|
59
62
|
return if messages.any?
|
60
63
|
|
61
64
|
raise SyntaxError, <<~MESSAGE.squish
|
62
|
-
|
65
|
+
Undefined message chain for stubbing #{receiver}.
|
63
66
|
Use option `chain` to define it.
|
64
67
|
MESSAGE
|
65
68
|
end
|
@@ -27,7 +27,16 @@ module Fixturama
|
|
27
27
|
# @return [Boolean]
|
28
28
|
#
|
29
29
|
def applicable_to?(actual_arguments)
|
30
|
-
|
30
|
+
last_index = actual_arguments.count
|
31
|
+
@arguments.zip(actual_arguments)
|
32
|
+
.each.with_index(1)
|
33
|
+
.reduce(true) do |obj, ((expected, actual), index)|
|
34
|
+
obj && (
|
35
|
+
expected == actual ||
|
36
|
+
index == last_index &&
|
37
|
+
Fixturama::Utils.matched_hash_args?(actual, expected)
|
38
|
+
)
|
39
|
+
end
|
31
40
|
end
|
32
41
|
|
33
42
|
#
|
data/lib/fixturama/utils.rb
CHANGED
@@ -58,6 +58,22 @@ RSpec.describe "stub_fixture" do
|
|
58
58
|
end
|
59
59
|
end
|
60
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
|
+
|
61
77
|
context "with unspecified argument" do
|
62
78
|
let(:arguments) { [4] }
|
63
79
|
|
@@ -35,7 +35,7 @@
|
|
35
35
|
- return: 2
|
36
36
|
- return: 0
|
37
37
|
|
38
|
-
-
|
38
|
+
- object: Payment.itself
|
39
39
|
chain:
|
40
40
|
- new
|
41
41
|
- pay
|
@@ -46,5 +46,15 @@
|
|
46
46
|
repeat: 2
|
47
47
|
- return: 0
|
48
48
|
|
49
|
+
- class: Payment
|
50
|
+
chain:
|
51
|
+
- new
|
52
|
+
- pay
|
53
|
+
arguments:
|
54
|
+
- 10
|
55
|
+
- :overdraft: true
|
56
|
+
actions:
|
57
|
+
- return: -5
|
58
|
+
|
49
59
|
- const: TIMEOUT
|
50
60
|
value: 10
|
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.
|
4
|
+
version: 0.0.7
|
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-
|
11
|
+
date: 2019-07-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: factory_bot
|