fixturama 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0daca457009dcadf8dcc794d28a0694e093671af9f2f17a121066caf45eea73a
4
- data.tar.gz: 3e256c4e345e0975b4099f459265915af5abf69c2d34a4b95422e0083e7d26a8
3
+ metadata.gz: 64d9722c641abfd4aa64fbf45b8f1177f768d1b8d2b99a89aa824e1f64db9417
4
+ data.tar.gz: e1186c8944916943bbab46584747553b07b9d5cfc4e9d875d1a401fc8bd7017a
5
5
  SHA512:
6
- metadata.gz: b28b4759ba2ca263f0cc956be4dda523197039acb263d436c1a1ac6484aa7f1a08876ded66a3bf13c0e7a3214931f5926bb81d8419965f3d3c6c3156eb1c6a79
7
- data.tar.gz: f7e50dd435f64e97e115487ccd462279a72012dec62c346a0a093645220396858eddda13cc02707259d6de5046717f0b43f2eec9ad0dfbce7a6250a5fe7be21a
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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = "fixturama"
3
- gem.version = "0.0.6"
3
+ gem.version = "0.0.7"
4
4
  gem.author = "Andrew Kozin (nepalez)"
5
5
  gem.email = "andrew.kozin@gmail.com"
6
6
  gem.homepage = "https://github.com/nepalez/fixturama"
@@ -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
- when :message_chain
37
- anchor = options.slice(:class, :chain)
38
- @stubs[anchor] ||= Chain.new(anchor)
39
- when :constant
40
- anchor = options.slice(:const)
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
- Indefined message chain for stubbing #{receiver}.
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
- @arguments.zip(actual_arguments).map { |(x, y)| x == y }.reduce(true, :&)
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
  #
@@ -29,5 +29,11 @@ module Fixturama
29
29
  else [list]
30
30
  end
31
31
  end
32
+
33
+ def matched_hash_args?(actual, expected)
34
+ return unless actual.is_a?(Hash) && expected.is_a?(Hash)
35
+
36
+ expected.all? { |key, val| actual[key] == val }
37
+ end
32
38
  end
33
39
  end
@@ -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
- - class: Payment
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.6
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-06-10 00:00:00.000000000 Z
11
+ date: 2019-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: factory_bot