tzu_mock 0.1.2 → 1.0.0

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
  SHA1:
3
- metadata.gz: a374a7e23ecbd322adc0388add8d727efdaf0f39
4
- data.tar.gz: d37787c1dc7664177fefa8e6e0b8d65f4a801106
3
+ metadata.gz: a623fe290d3bf0e2ecaeda8f7891272261115576
4
+ data.tar.gz: 5408759d91670c24cd7e3660f60ea83ac7fd9b5f
5
5
  SHA512:
6
- metadata.gz: 2a8c33e3c20f176ef1125ce3c98c2a74f3d737d6736b27b0ef3317db0cf41743c5d6451ce61f5d7d78ba31f0278c0ac8645499ae4c273e2b6036a825c5fb94a4
7
- data.tar.gz: 1760d50fcc90d31cff53ea5c449d56f1d0f85d6879e077912ad0dc1398a23641ee762a50d0c1200494d852728e4306e7a1d0a220135d78c56f78b4e938c05fe3
6
+ metadata.gz: ec7f5e5796be2ec05e37b94138d8e9cf66712e9fe989727dedb4da04688d7d2cc8477c35b3321216c71ba2c71fd7671c478db406bdd822f844ee783680d95e96
7
+ data.tar.gz: 85e762fa6f101ae45d7fbcf540cb3ed0ea7f08a8d4bcc2f305ac36bb68b73a39e9bf2bab705c89d7ca3d6e8f0944d2fd73c0317aed6b2e3153f431df2bd89f3f
data/README.md CHANGED
@@ -5,9 +5,9 @@ A very simple library for mocking Tzu in RSpec
5
5
  ## Usage
6
6
 
7
7
  ```ruby
8
- TzuMock.success(klass, result) #=> Successful Outcome
9
- TzuMock.invalid(klass, error) #=> Invalid Outcome
10
- TzuMock.failure(klass, error) #=> Failed Outcome
8
+ TzuMock.success(klass).returns(result) #=> Successful Outcome
9
+ TzuMock.invalid(klass).returns(error) #=> Invalid Outcome
10
+ TzuMock.failure(klass).returns(error) #=> Failed Outcome
11
11
  ```
12
12
 
13
13
  Consider this Tzu command:
@@ -59,7 +59,7 @@ describe UpdateUser do
59
59
  let(:params) { { last_name: 'Turner' } }
60
60
 
61
61
  context 'success' do
62
- before { TzuMock.success(UpdateUser, result) }
62
+ before { TzuMock.success(UpdateUser).returns(result) }
63
63
 
64
64
  let(:outcome) { UpdateUser.run(params) }
65
65
 
@@ -72,7 +72,7 @@ describe UpdateUser do
72
72
  end
73
73
 
74
74
  context 'invalid' do
75
- before { TzuMock.invalid(UpdateUser, error) }
75
+ before { TzuMock.invalid(UpdateUser).returns(error) }
76
76
 
77
77
  let(:outcome) { UpdateUser.run(params) }
78
78
 
@@ -85,7 +85,7 @@ describe UpdateUser do
85
85
  end
86
86
 
87
87
  context 'failure' do
88
- before { TzuMock.failure(UpdateUser, error) }
88
+ before { TzuMock.failure(UpdateUser).returns(error) }
89
89
 
90
90
  let(:outcome) { UpdateUser.run!(params) }
91
91
 
@@ -111,7 +111,7 @@ describe UpdateUser do
111
111
  let(:controller) { MockController.new }
112
112
 
113
113
  context 'success' do
114
- before { TzuMock.success(UpdateUser, result) }
114
+ before { TzuMock.success(UpdateUser).returns(result) }
115
115
 
116
116
  it 'mocks a successful outcome and allows parameters to be verified' do
117
117
  controller.update(params)
@@ -121,7 +121,7 @@ describe UpdateUser do
121
121
  end
122
122
 
123
123
  context 'invalid' do
124
- before { TzuMock.invalid(UpdateUser, error) }
124
+ before { TzuMock.invalid(UpdateUser).returns(error) }
125
125
 
126
126
  it 'mocks a successful outcome and allows parameters to be verified' do
127
127
  controller.update(params)
@@ -131,7 +131,7 @@ describe UpdateUser do
131
131
  end
132
132
 
133
133
  context 'failure' do
134
- before { TzuMock.failure(UpdateUser, error) }
134
+ before { TzuMock.failure(UpdateUser).returns(error) }
135
135
 
136
136
  it 'mocks a successful outcome and allows parameters to be verified' do
137
137
  controller.update(params)
@@ -143,3 +143,13 @@ end
143
143
  ```
144
144
 
145
145
  TzuMock effortlessly passes your desired outcome to the appropriate block.
146
+
147
+ ## Configuration
148
+
149
+ By default, TzuMock mocks the `run` and `run!` methods,
150
+ but you can add more methods to that list if your Tzu classes have another interface.
151
+
152
+ ```ruby
153
+ # spec/spec_helper.rb
154
+ TzuMock.configure { |config| config.stub_methods = [:go, :go!] }
155
+ ```
@@ -5,12 +5,12 @@ module TzuMock
5
5
  prepare(method, *args)
6
6
  end
7
7
 
8
- def prepare(type, klass, result, method = nil)
8
+ def prepare(type, klass, method = nil)
9
9
  # Get the rspec block context. Will not work if you call TzuMock#prepare directly.
10
10
  # Call TzuMock#success, TzuMock#invalid, or TzuMock#failure instead
11
11
  rspec_context = binding.of_caller(2).eval('self')
12
12
 
13
- Mocker.new(type, klass, result, rspec_context, method).mock
13
+ Mocker.new(type, klass, rspec_context, method)
14
14
  end
15
15
  end
16
16
  end
@@ -1,13 +1,18 @@
1
1
  module TzuMock
2
2
  class Mocker
3
- def initialize(type, klass, result, rspec_context, method)
4
- @type, @klass, @result, @rspec_context, @method = type, klass, result, rspec_context, method
3
+ def initialize(type, klass, rspec_context, method)
4
+ @type, @klass, @rspec_context, @method = type, klass, rspec_context, method
5
5
  end
6
6
 
7
7
  def mock
8
8
  @rspec_context.instance_eval(&mock_proc(@klass, mock_methods, success?, @result, error_type))
9
9
  end
10
10
 
11
+ def returns(result)
12
+ @result = result
13
+ mock
14
+ end
15
+
11
16
  private
12
17
 
13
18
  # Need to pass variables in explicity to give the Proc access to them
@@ -56,7 +56,7 @@ describe TzuMock do
56
56
 
57
57
  context 'when invocation does not have a block' do
58
58
  context 'success' do
59
- before { TzuMock.success(UpdateUser, result) }
59
+ before { TzuMock.success(UpdateUser).returns(result) }
60
60
 
61
61
  let(:outcome) { UpdateUser.run!(params) }
62
62
 
@@ -69,7 +69,7 @@ describe TzuMock do
69
69
  end
70
70
 
71
71
  context 'invalid' do
72
- before { TzuMock.invalid(UpdateUser, error) }
72
+ before { TzuMock.invalid(UpdateUser).returns(error) }
73
73
 
74
74
  let(:outcome) { UpdateUser.run!(params) }
75
75
 
@@ -82,7 +82,7 @@ describe TzuMock do
82
82
  end
83
83
 
84
84
  context 'failure' do
85
- before { TzuMock.failure(UpdateUser, error) }
85
+ before { TzuMock.failure(UpdateUser).returns(error) }
86
86
 
87
87
  let(:outcome) { UpdateUser.run(params) }
88
88
 
@@ -97,7 +97,7 @@ describe TzuMock do
97
97
 
98
98
  context 'when invocation has a block' do
99
99
  context 'success' do
100
- before { TzuMock.success(UpdateUser, result) }
100
+ before { TzuMock.success(UpdateUser).returns(result) }
101
101
 
102
102
  let(:controller) { MockController.new }
103
103
 
@@ -109,7 +109,7 @@ describe TzuMock do
109
109
  end
110
110
 
111
111
  context 'invalid' do
112
- before { TzuMock.invalid(UpdateUser, error) }
112
+ before { TzuMock.invalid(UpdateUser).returns(error) }
113
113
 
114
114
  let(:controller) { MockController.new }
115
115
 
@@ -121,7 +121,7 @@ describe TzuMock do
121
121
  end
122
122
 
123
123
  context 'failure' do
124
- before { TzuMock.failure(UpdateUser, error) }
124
+ before { TzuMock.failure(UpdateUser).returns(error) }
125
125
 
126
126
  let(:controller) { MockController.new }
127
127
 
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: 0.1.2
4
+ version: 1.0.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-06-23 00:00:00.000000000 Z
11
+ date: 2015-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: binding_of_caller