fixturama 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +0 -21
- data/.travis.yml +4 -1
- data/CHANGELOG.md +30 -0
- data/README.md +21 -6
- data/fixturama.gemspec +1 -1
- data/lib/fixturama/stubs/actions/raise.rb +21 -0
- data/lib/fixturama/stubs/actions/return.rb +23 -0
- data/lib/fixturama/stubs/actions.rb +30 -18
- data/lib/fixturama/stubs/arguments.rb +77 -0
- data/lib/fixturama/stubs/chain.rb +78 -0
- data/lib/fixturama/stubs.rb +31 -19
- data/lib/fixturama/utils.rb +15 -3
- data/spec/fixturama/stub_fixture/_spec.rb +47 -25
- data/spec/fixturama/stub_fixture/stub.yml +43 -4
- metadata +8 -5
- data/lib/fixturama/stubs/raise.rb +0 -15
- data/lib/fixturama/stubs/return.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bba5ba59d906e247aaa4e798664b7ec30802e960
|
4
|
+
data.tar.gz: b2bfc9b12596884af5dc875a9caede9c343522bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c94ee6bb71480fc429ee9074d48eda1b8cb09914a5184ae676e6cbe07495754fbcaad3dccb6c74812c56866b7c60d6cf148b4c7cd2e0ae3003c0d0d745db7953
|
7
|
+
data.tar.gz: e1ecad3d926147300425c474757ecd0d1e80d6427c37bc5ef1d29d122680104f8913cea4511dec84e64b779588c1247e0326508de0226e0bb5d521bb7c8f608f
|
data/.rubocop.yml
CHANGED
@@ -12,32 +12,11 @@ Metrics/LineLength:
|
|
12
12
|
- http
|
13
13
|
- https
|
14
14
|
|
15
|
-
Layout/SpaceInLambdaLiteral:
|
16
|
-
Enabled: false
|
17
|
-
|
18
|
-
Style/CaseEquality:
|
19
|
-
Enabled: false
|
20
|
-
|
21
15
|
Style/ClassAndModuleChildren:
|
22
16
|
Enabled: false
|
23
17
|
|
24
18
|
Style/Documentation:
|
25
19
|
Enabled: false
|
26
20
|
|
27
|
-
Style/DoubleNegation:
|
28
|
-
Enabled: false # by intention
|
29
|
-
|
30
|
-
Style/FrozenStringLiteralComment:
|
31
|
-
Enabled: false
|
32
|
-
|
33
|
-
Style/Lambda:
|
34
|
-
Enabled: false
|
35
|
-
|
36
|
-
Style/PercentLiteralDelimiters:
|
37
|
-
Enabled: false
|
38
|
-
|
39
|
-
Style/RaiseArgs:
|
40
|
-
Enabled: false
|
41
|
-
|
42
21
|
Style/StringLiterals:
|
43
22
|
EnforcedStyle: double_quotes
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,11 +1,41 @@
|
|
1
1
|
# Change Log
|
2
|
+
|
2
3
|
All notable changes to this project will be documented in this file.
|
3
4
|
|
4
5
|
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
5
6
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
6
7
|
|
8
|
+
## [0.0.2] - [2018-04-27]
|
9
|
+
|
10
|
+
### Added
|
11
|
+
|
12
|
+
- Restriction of stub by arguments (nepalez)
|
13
|
+
|
14
|
+
```yaml
|
15
|
+
---
|
16
|
+
- class: Balance
|
17
|
+
chain: debet
|
18
|
+
arguments: 0
|
19
|
+
actions:
|
20
|
+
- return: 1
|
21
|
+
|
22
|
+
- class: Balance
|
23
|
+
chain: debet
|
24
|
+
arguments: 1
|
25
|
+
actions:
|
26
|
+
- return: 0
|
27
|
+
- raise: UnsifficientFunds
|
28
|
+
|
29
|
+
- class: Balance
|
30
|
+
chain: debet
|
31
|
+
arguments: 2
|
32
|
+
actions:
|
33
|
+
- raise: UnsifficientFunds
|
34
|
+
```
|
35
|
+
|
7
36
|
## [0.0.1] - [2018-03-01]
|
8
37
|
|
9
38
|
This is a first public release with features extracted from production app.
|
10
39
|
|
11
40
|
[0.0.1]: https://github.com/nepalez/fixturama/releases/tag/v0.0.1
|
41
|
+
[0.0.2]: https://github.com/nepalez/fixturama/compare/v0.0.1...v0.0.2
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Fixturama
|
2
2
|
|
3
|
-
Collection of helpers for dealing with fixtures in RSpec
|
3
|
+
Collection of helpers for dealing with fixtures in [RSpec][rspec]
|
4
4
|
|
5
5
|
<a href="https://evilmartians.com/">
|
6
6
|
<img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" alt="Sponsored by Evil Martians" width="236" height="54"></a>
|
@@ -24,7 +24,7 @@ require "fixturama/rspec"
|
|
24
24
|
The gem defines 3 helpers (support ERB bindings):
|
25
25
|
|
26
26
|
- `load_fixture(path, **opts)` to load data from a fixture, and deserialize YAML and JSON
|
27
|
-
- `seed_fixture(path_to_yaml, **opts)` to prepare database
|
27
|
+
- `seed_fixture(path_to_yaml, **opts)` to prepare database using the [FactoryBot][factory-bot]
|
28
28
|
- `stub_fixture(path_to_yaml, **opts)` to stub some classes
|
29
29
|
|
30
30
|
```ruby
|
@@ -79,6 +79,7 @@ Another opinionated format we use for stubs (`stub_fixture`):
|
|
79
79
|
|
80
80
|
- `class` for stubbed class
|
81
81
|
- `chain` for messages chain
|
82
|
+
- `arguments` (optional) for specific arguments
|
82
83
|
- `actions` for an array of actions for consecutive invocations of the chain
|
83
84
|
|
84
85
|
Every action either `return` some value, or `raise` some exception
|
@@ -87,14 +88,26 @@ Every action either `return` some value, or `raise` some exception
|
|
87
88
|
# ./stubs.yml
|
88
89
|
#
|
89
90
|
# The first invocation acts like
|
90
|
-
# allow(Events).to receive_message_chain(:create).and_return true
|
91
91
|
#
|
92
|
-
#
|
93
|
-
#
|
92
|
+
# allow(Notifier)
|
93
|
+
# .to receive_message_chain(:create)
|
94
|
+
# .with(:profileDeleted, 42)
|
95
|
+
# .and_return true
|
96
|
+
#
|
97
|
+
# then it will act like
|
98
|
+
#
|
99
|
+
# allow(Notifier)
|
100
|
+
# .to receive_message_chain(:create)
|
101
|
+
# .with(:profileDeleted, 42)
|
102
|
+
# .and_raise AlreadyRegisteredError
|
103
|
+
#
|
94
104
|
---
|
95
|
-
- class:
|
105
|
+
- class: Notifier
|
96
106
|
chain:
|
97
107
|
- create
|
108
|
+
arguments:
|
109
|
+
- :profileDeleted
|
110
|
+
- <%= profile_id %>
|
98
111
|
actions:
|
99
112
|
- return: true
|
100
113
|
- raise: AlreadyRegisteredError
|
@@ -138,3 +151,5 @@ The gem is available as open source under the terms of the [MIT License][license
|
|
138
151
|
[gem]: https://rubygems.org/gems/fixturama
|
139
152
|
[travis]: https://travis-ci.org/nepalez/fixturama
|
140
153
|
[license]: http://opensource.org/licenses/MIT
|
154
|
+
[factory-bot]: https://github.com/thoughtbot/factory_bot
|
155
|
+
[rspec]: https://rspec.info/
|
data/fixturama.gemspec
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
class Fixturama::Stubs::Actions::Raise
|
2
|
+
def call
|
3
|
+
raise @exception
|
4
|
+
end
|
5
|
+
|
6
|
+
#
|
7
|
+
# Human-readable representation of the expectation
|
8
|
+
# @return [String]
|
9
|
+
#
|
10
|
+
def to_s
|
11
|
+
"#{@stub} # raise #{@exception}"
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def initialize(stub, name)
|
17
|
+
@stub = stub
|
18
|
+
name = name.to_s
|
19
|
+
@exception = name == "true" ? StandardError : Kernel.const_get(name)
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class Fixturama::Stubs::Actions::Return
|
2
|
+
attr_reader :stub, :call
|
3
|
+
|
4
|
+
#
|
5
|
+
# Human-readable representation of the expectation
|
6
|
+
# @return [String]
|
7
|
+
#
|
8
|
+
def to_s
|
9
|
+
"#{@stub} # => #{call}"
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def initialize(stub, output)
|
15
|
+
@stub = stub
|
16
|
+
@call = \
|
17
|
+
begin # in ruby 2.3.0 Fixnum#dup is defined, but raises TypeError
|
18
|
+
output.respond_to?(:dup) ? output.dup : output
|
19
|
+
rescue TypeError
|
20
|
+
output
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,27 +1,39 @@
|
|
1
1
|
module Fixturama
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
2
|
+
#
|
3
|
+
# Factory to provide a specific action from options
|
4
|
+
#
|
5
|
+
module Stubs::Actions
|
6
|
+
extend self
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
end
|
8
|
+
require_relative "actions/raise"
|
9
|
+
require_relative "actions/return"
|
12
10
|
|
13
|
-
|
11
|
+
#
|
12
|
+
# Builds an action
|
13
|
+
# @option [#to_s] :raise
|
14
|
+
# @option [Object] :return
|
15
|
+
# @option [true] :call_original
|
16
|
+
# @return [#call] a callable action
|
17
|
+
#
|
18
|
+
def build(stub, **options)
|
19
|
+
check!(stub, options)
|
20
|
+
key, value = options.to_a.first
|
21
|
+
TYPES[key].new(stub, value)
|
22
|
+
end
|
14
23
|
|
15
|
-
|
16
|
-
opts = Utils.symbolize_hash(opts)
|
17
|
-
return Raise.new opts[:raise] if opts.key?(:raise)
|
24
|
+
private
|
18
25
|
|
19
|
-
|
20
|
-
|
26
|
+
def check!(stub, options)
|
27
|
+
keys = options.keys & TYPES.keys
|
28
|
+
return if keys.count == 1
|
21
29
|
|
22
|
-
|
23
|
-
|
24
|
-
|
30
|
+
raise SyntaxError, <<~MESSAGE.squish
|
31
|
+
Invalid settings for stubbing message chain #{stub}: #{options}.
|
32
|
+
The action MUST have one and only one of the keys:
|
33
|
+
`#{TYPES.keys.join('`, `')}`.
|
34
|
+
MESSAGE
|
25
35
|
end
|
36
|
+
|
37
|
+
TYPES = { raise: Raise, return: Return }.freeze
|
26
38
|
end
|
27
39
|
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module Fixturama
|
2
|
+
#
|
3
|
+
# Collection of arguments for a stub with a list of actions to be called
|
4
|
+
#
|
5
|
+
class Stubs::Arguments
|
6
|
+
attr_reader :chain, :arguments
|
7
|
+
|
8
|
+
#
|
9
|
+
# Register new action for these set of arguments
|
10
|
+
# @option [#to_i] :repeat (1)
|
11
|
+
# How much the action should be repeated during the consecutive calls
|
12
|
+
# @return [self] itself
|
13
|
+
#
|
14
|
+
def add!(*actions)
|
15
|
+
actions.each do |settings|
|
16
|
+
settings = Utils.symbolize_hash(settings)
|
17
|
+
repeat = [0, settings.fetch(:repeat, 1).to_i].max
|
18
|
+
repeat.times { list << Stubs::Actions.build(self, settings) }
|
19
|
+
end
|
20
|
+
|
21
|
+
self
|
22
|
+
end
|
23
|
+
|
24
|
+
#
|
25
|
+
# Whether the current stub is applicable to actual arguments
|
26
|
+
# @param [Array<Object>] actual_arguments
|
27
|
+
# @return [Boolean]
|
28
|
+
#
|
29
|
+
def applicable_to?(actual_arguments)
|
30
|
+
@arguments.zip(actual_arguments).map { |(x, y)| x == y }.reduce(true, :&)
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
# Reset the counter of calls
|
35
|
+
# @return [self] itself
|
36
|
+
#
|
37
|
+
def reset!
|
38
|
+
@counter = 0
|
39
|
+
self
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
# Calls the next action for these set of agruments
|
44
|
+
# @return [Object]
|
45
|
+
# @raise [StandardError]
|
46
|
+
#
|
47
|
+
def call_next!
|
48
|
+
list.fetch(counter) { list.last }.call.tap { @counter += 1 }
|
49
|
+
end
|
50
|
+
|
51
|
+
#
|
52
|
+
# Human-readable representation of arguments
|
53
|
+
# @return [String]
|
54
|
+
#
|
55
|
+
def to_s
|
56
|
+
args = [*arguments.map(&:to_s), "*"].join(", ")
|
57
|
+
"#{chain}(#{args})"
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
# @param [Fixturama::Stubs::Chain] chain Back reference
|
63
|
+
# @param [Array<Object>] list Definition of arguments
|
64
|
+
def initialize(chain, list)
|
65
|
+
@chain = chain
|
66
|
+
@arguments = Utils.array(list)
|
67
|
+
end
|
68
|
+
|
69
|
+
def counter
|
70
|
+
@counter ||= 0
|
71
|
+
end
|
72
|
+
|
73
|
+
def list
|
74
|
+
@list ||= []
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module Fixturama
|
2
|
+
#
|
3
|
+
# Stubbed chain of messages
|
4
|
+
#
|
5
|
+
class Stubs::Chain
|
6
|
+
attr_reader :receiver, :messages
|
7
|
+
|
8
|
+
#
|
9
|
+
# Register new action for some arguments
|
10
|
+
#
|
11
|
+
# @option [Array<#to_s>, #to_s] :arguments The specific arguments
|
12
|
+
# @option (see Fixturama::Stubs::Arguments#add_action)
|
13
|
+
# @return [self]
|
14
|
+
#
|
15
|
+
def add(actions:, arguments: nil, **)
|
16
|
+
Utils.array(arguments).tap do |args|
|
17
|
+
stub = find_by(args)
|
18
|
+
unless stub
|
19
|
+
stub = Stubs::Arguments.new(self, args)
|
20
|
+
stubs << stub
|
21
|
+
end
|
22
|
+
stub.add!(*actions)
|
23
|
+
stubs.sort_by! { |stub| -stub.arguments.count }
|
24
|
+
end
|
25
|
+
|
26
|
+
self
|
27
|
+
end
|
28
|
+
|
29
|
+
#
|
30
|
+
# Resets all counters
|
31
|
+
# @return [self] itself
|
32
|
+
#
|
33
|
+
def reset!
|
34
|
+
tap { stubs.each(&:reset!) }
|
35
|
+
end
|
36
|
+
|
37
|
+
#
|
38
|
+
# Executes the corresponding action
|
39
|
+
# @return [Object]
|
40
|
+
# @raise [StandardError]
|
41
|
+
#
|
42
|
+
def call!(actual_arguments)
|
43
|
+
stub = stubs.find { |item| item.applicable_to?(actual_arguments) }
|
44
|
+
raise "Unexpected arguments #{actual_arguments}" unless stub
|
45
|
+
|
46
|
+
stub.call_next!
|
47
|
+
end
|
48
|
+
|
49
|
+
#
|
50
|
+
# Human-readable representation of the chain
|
51
|
+
# @return [String]
|
52
|
+
#
|
53
|
+
def to_s
|
54
|
+
"#{receiver}.#{messages.join(".")}"
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def initialize(**options)
|
60
|
+
@receiver = Utils.constantize options[:class]
|
61
|
+
@messages = Utils.symbolize_array options[:chain]
|
62
|
+
return if messages.any?
|
63
|
+
|
64
|
+
raise SyntaxError, <<~MESSAGE.squish
|
65
|
+
Indefined message chain for stubbing #{receiver}.
|
66
|
+
Use option `chain` to define it.
|
67
|
+
MESSAGE
|
68
|
+
end
|
69
|
+
|
70
|
+
def stubs
|
71
|
+
@stubs ||= []
|
72
|
+
end
|
73
|
+
|
74
|
+
def find_by(arguments)
|
75
|
+
stubs.find { |stub| stub.arguments == arguments }
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
data/lib/fixturama/stubs.rb
CHANGED
@@ -1,37 +1,49 @@
|
|
1
1
|
module Fixturama
|
2
|
+
#
|
3
|
+
# Collection of stubbed calls
|
4
|
+
#
|
2
5
|
class Stubs
|
3
6
|
require_relative "stubs/actions"
|
4
|
-
require_relative "stubs/
|
5
|
-
require_relative "stubs/
|
7
|
+
require_relative "stubs/arguments"
|
8
|
+
require_relative "stubs/chain"
|
6
9
|
|
10
|
+
#
|
11
|
+
# Register new action and apply the corresponding stub
|
12
|
+
#
|
13
|
+
# @option [#to_s] :class Class to stub
|
14
|
+
# @option [Array<#to_s>] :chain Methods chain for stubbing
|
15
|
+
# @option (see Fixturama::Stubs::Method#add)
|
16
|
+
# @return [self] itself
|
17
|
+
#
|
7
18
|
def add(options)
|
8
|
-
|
9
|
-
|
19
|
+
tap do
|
20
|
+
options = Utils.symbolize_hash(options)
|
10
21
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
Array(actions).each do |action|
|
16
|
-
collection[[klass, chain]] ||= Actions.new
|
17
|
-
collection[[klass, chain]].add action
|
22
|
+
options.select { |key| %i[class chain].include?(key) }.tap do |anchors|
|
23
|
+
chains[anchors] ||= Chain.new(anchors)
|
24
|
+
chains[anchors].add(options)
|
25
|
+
end
|
18
26
|
end
|
19
|
-
|
20
|
-
self
|
21
27
|
end
|
22
28
|
|
29
|
+
#
|
30
|
+
# Applies the stub to RSpec example
|
31
|
+
#
|
23
32
|
def apply(example)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
33
|
+
chains.values.each do |chain|
|
34
|
+
chain.reset!
|
35
|
+
call_action = \
|
36
|
+
example.send(:receive_message_chain, *chain.messages) do |*args|
|
37
|
+
chain.call! args
|
38
|
+
end
|
39
|
+
example.send(:allow, chain.receiver).to call_action
|
28
40
|
end
|
29
41
|
end
|
30
42
|
|
31
43
|
private
|
32
44
|
|
33
|
-
def
|
34
|
-
@
|
45
|
+
def chains
|
46
|
+
@chains ||= {}
|
35
47
|
end
|
36
48
|
end
|
37
49
|
end
|
data/lib/fixturama/utils.rb
CHANGED
@@ -2,20 +2,32 @@ module Fixturama
|
|
2
2
|
module Utils
|
3
3
|
module_function
|
4
4
|
|
5
|
+
def symbolize(item)
|
6
|
+
item.to_s.to_sym
|
7
|
+
end
|
8
|
+
|
5
9
|
def symbolize_hash(data)
|
6
|
-
Hash(data).transform_keys { |key| key
|
10
|
+
Hash(data).transform_keys { |key| symbolize(key)}
|
7
11
|
end
|
8
12
|
|
9
13
|
def symbolize_array(data)
|
10
|
-
Array(data).map { |item| item
|
14
|
+
Array(data).map { |item| symbolize(item) }
|
11
15
|
end
|
12
16
|
|
13
17
|
def constantize(item)
|
14
|
-
item.to_s
|
18
|
+
Kernel.const_get(item.to_s)
|
15
19
|
end
|
16
20
|
|
17
21
|
def clone(item)
|
18
22
|
item.respond_to?(:dup) ? item.dup : item
|
19
23
|
end
|
24
|
+
|
25
|
+
def array(list)
|
26
|
+
case list
|
27
|
+
when NilClass then []
|
28
|
+
when Array then list
|
29
|
+
else [list]
|
30
|
+
end
|
31
|
+
end
|
20
32
|
end
|
21
33
|
end
|
@@ -1,47 +1,69 @@
|
|
1
1
|
RSpec.describe "stub_fixture" do
|
2
|
-
subject {
|
2
|
+
subject { arguments.map { |argument| Payment.new.pay(argument) } }
|
3
3
|
|
4
4
|
before do
|
5
|
-
class
|
6
|
-
def
|
7
|
-
|
5
|
+
class Payment
|
6
|
+
def pay(_)
|
7
|
+
5
|
8
8
|
end
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
12
|
context "without stubbing" do
|
13
|
-
|
13
|
+
let(:arguments) { [0] }
|
14
|
+
|
15
|
+
it { is_expected.to eq [5] }
|
14
16
|
end
|
15
17
|
|
16
|
-
context "with
|
18
|
+
context "with stubbing" do
|
17
19
|
before { stub_fixture "#{__dir__}/stub.yml" }
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
+
context "with a :raise option" do
|
22
|
+
let(:arguments) { [0] }
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
Foo.new.bar
|
24
|
+
it "raises an exception" do
|
25
|
+
expect { subject }.to raise_error ArgumentError
|
26
|
+
end
|
26
27
|
end
|
27
28
|
|
28
|
-
|
29
|
-
|
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
|
30
35
|
end
|
31
|
-
end
|
32
36
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
41
51
|
end
|
42
52
|
|
43
|
-
|
44
|
-
|
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 unspecified argument" do
|
62
|
+
let(:arguments) { [4] }
|
63
|
+
|
64
|
+
it "uses universal stub" do
|
65
|
+
expect(subject).to eq [-1]
|
66
|
+
end
|
45
67
|
end
|
46
68
|
end
|
47
69
|
end
|
@@ -1,8 +1,47 @@
|
|
1
1
|
---
|
2
|
-
- class:
|
2
|
+
- class: Payment
|
3
3
|
chain:
|
4
4
|
- new
|
5
|
-
-
|
5
|
+
- pay
|
6
6
|
actions:
|
7
|
-
- return:
|
8
|
-
|
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
|
+
- class: Payment
|
39
|
+
chain:
|
40
|
+
- new
|
41
|
+
- pay
|
42
|
+
arguments:
|
43
|
+
- 3
|
44
|
+
actions:
|
45
|
+
- return: 6
|
46
|
+
repeat: 2
|
47
|
+
- return: 0
|
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.2
|
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-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: factory_bot
|
@@ -117,8 +117,10 @@ files:
|
|
117
117
|
- lib/fixturama/seed.rb
|
118
118
|
- lib/fixturama/stubs.rb
|
119
119
|
- lib/fixturama/stubs/actions.rb
|
120
|
-
- lib/fixturama/stubs/raise.rb
|
121
|
-
- lib/fixturama/stubs/return.rb
|
120
|
+
- lib/fixturama/stubs/actions/raise.rb
|
121
|
+
- lib/fixturama/stubs/actions/return.rb
|
122
|
+
- lib/fixturama/stubs/arguments.rb
|
123
|
+
- lib/fixturama/stubs/chain.rb
|
122
124
|
- lib/fixturama/utils.rb
|
123
125
|
- spec/fixturama/load_fixture/_spec.rb
|
124
126
|
- spec/fixturama/load_fixture/data.json
|
@@ -148,7 +150,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
148
150
|
- !ruby/object:Gem::Version
|
149
151
|
version: '0'
|
150
152
|
requirements: []
|
151
|
-
|
153
|
+
rubyforge_project:
|
154
|
+
rubygems_version: 2.6.14
|
152
155
|
signing_key:
|
153
156
|
specification_version: 4
|
154
157
|
summary: A set of helpers to prettify specs with fixtures
|