tzu_mock 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +22 -1
- data/lib/tzu_mock.rb +1 -0
- data/lib/tzu_mock/mocker.rb +2 -1
- data/lib/tzu_mock/result_builder.rb +34 -0
- data/spec/tzu_mock_spec.rb +37 -0
- metadata +48 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: add3ea6e0b5d294529170a40e2cebd3b9f7c4e08
|
4
|
+
data.tar.gz: 1f56ebf946f95c2ac49c3d1c0554ed3a0da51e06
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 813afb83eaee56ea9a570f22081752872505ec4d6240bfd7e51b61eb2628eefd1a7a1ea246ac8f423e03dc12cf5779e2d9c50f60ed15380eadbac6fe8792cd43
|
7
|
+
data.tar.gz: 33acb4cd26ae3ff5b8154c76c64f9e9aa25d85ae2c37653dcf81081b096708cbd98ce786acd55e02bb5a4c4a455163c0dc50eec9ddc046ef1ef29f8454f82764
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Tzu Mock
|
1
|
+
# Tzu Mock [![Build Status](https://travis-ci.org/onfido/tzu_mock.svg)](https://travis-ci.org/onfido/tzu_mock)
|
2
2
|
|
3
3
|
A very simple library for mocking Tzu in RSpec
|
4
4
|
|
@@ -144,6 +144,27 @@ end
|
|
144
144
|
|
145
145
|
TzuMock effortlessly passes your desired outcome to the appropriate block.
|
146
146
|
|
147
|
+
## Hash Result
|
148
|
+
|
149
|
+
TzuMock converts your result hash attributes into methods by default.
|
150
|
+
|
151
|
+
```ruby
|
152
|
+
# if you return this result
|
153
|
+
before { TzuMock.success(UpdateUser).returns({name: 'me'}) }
|
154
|
+
|
155
|
+
# you can access it on this way
|
156
|
+
outcome = UpdateUser.run(params)
|
157
|
+
outcome.result.name
|
158
|
+
|
159
|
+
# even if you have result as array contains hashs
|
160
|
+
before { TzuMock.success(UpdateUser).returns([{name: 'me'}]) }
|
161
|
+
|
162
|
+
# you can access it on this way
|
163
|
+
outcome = UpdateUser.run(params)
|
164
|
+
outcome.result.first.name
|
165
|
+
|
166
|
+
```
|
167
|
+
|
147
168
|
## Configuration
|
148
169
|
|
149
170
|
By default, TzuMock mocks the `run` and `run!` methods,
|
data/lib/tzu_mock.rb
CHANGED
data/lib/tzu_mock/mocker.rb
CHANGED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'hashie'
|
2
|
+
|
3
|
+
module TzuMock
|
4
|
+
class HashResult < Hash
|
5
|
+
include Hashie::Extensions::MethodAccess
|
6
|
+
|
7
|
+
def initialize(attributes)
|
8
|
+
update(attributes)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class ResultBuilder
|
13
|
+
class << self
|
14
|
+
def build(result)
|
15
|
+
name = "build_#{result.class.name.downcase}".to_sym
|
16
|
+
if respond_to?(name, true)
|
17
|
+
send(name, result)
|
18
|
+
else
|
19
|
+
result
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def build_hash(result)
|
26
|
+
HashResult.new(result)
|
27
|
+
end
|
28
|
+
|
29
|
+
def build_array(result)
|
30
|
+
result.map { |r| r.is_a?(Hash) ? build_hash(r) : r}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/spec/tzu_mock_spec.rb
CHANGED
@@ -54,6 +54,43 @@ describe TzuMock do
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
+
context 'result builder' do
|
58
|
+
let(:outcome) { UpdateUser.run!(params) }
|
59
|
+
|
60
|
+
before { TzuMock.success(UpdateUser).returns(result) }
|
61
|
+
|
62
|
+
context 'hash' do
|
63
|
+
let(:result) { {name: 'me!'} }
|
64
|
+
it 'returns hash attributes as methods' do
|
65
|
+
expect(outcome.result.is_a?(Hash)).to be_truthy
|
66
|
+
expect(outcome.result.name).to eq(result[:name])
|
67
|
+
end
|
68
|
+
end
|
69
|
+
context 'array' do
|
70
|
+
context 'contains hash' do
|
71
|
+
let(:result) { [{name: 'other'}] }
|
72
|
+
it 'responds to name' do
|
73
|
+
expect(outcome.result.first.is_a?(Hash)).to be_truthy
|
74
|
+
expect(outcome.result.first.name).to eq(result.first[:name])
|
75
|
+
end
|
76
|
+
end
|
77
|
+
context 'does not ctonain hash' do
|
78
|
+
let(:result) { ['me'] }
|
79
|
+
it 'responds to name' do
|
80
|
+
expect(outcome.result.first.is_a?(String)).to be_truthy
|
81
|
+
expect(outcome.result).to eq(result)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
context 'string' do
|
86
|
+
let(:result) { 'me!' }
|
87
|
+
it 'responds to name' do
|
88
|
+
expect(outcome.result.is_a?(String)).to be_truthy
|
89
|
+
expect(outcome.result).to eq(result)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
57
94
|
context 'when invocation does not have a block' do
|
58
95
|
context 'success' do
|
59
96
|
before { TzuMock.success(UpdateUser).returns(result) }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tzu_mock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Blake Turner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: binding_of_caller
|
@@ -24,20 +24,34 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: hashie
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.4.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.4.0
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: tzu
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - "~>"
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.0.1
|
47
|
+
version: 0.0.1
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
52
|
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.0.1
|
54
|
+
version: 0.0.1
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rspec
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +80,34 @@ dependencies:
|
|
66
80
|
- - ">="
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: jeweler
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
69
111
|
description: Simple library for mocking Tzu in RSpec
|
70
112
|
email: mail@blakewilliamturner.com
|
71
113
|
executables: []
|
@@ -78,6 +120,7 @@ files:
|
|
78
120
|
- lib/tzu_mock/class_methods.rb
|
79
121
|
- lib/tzu_mock/configuration.rb
|
80
122
|
- lib/tzu_mock/mocker.rb
|
123
|
+
- lib/tzu_mock/result_builder.rb
|
81
124
|
- spec/spec_helper.rb
|
82
125
|
- spec/tzu_mock_spec.rb
|
83
126
|
homepage: https://github.com/onfido/tzu_mock
|
@@ -100,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
143
|
version: '0'
|
101
144
|
requirements: []
|
102
145
|
rubyforge_project:
|
103
|
-
rubygems_version: 2.
|
146
|
+
rubygems_version: 2.2.2
|
104
147
|
signing_key:
|
105
148
|
specification_version: 4
|
106
149
|
summary: TDD with Tzu!
|