tradesman 1.0.2 → 1.0.3

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: ff0c272af8227151aed9bfd3117d3e9e563a2421
4
- data.tar.gz: cfd71b052b452a8c03b9661b58c5de9780bb8a6f
3
+ metadata.gz: 11e364aa8aa559b1fde2cc8dbe60a017ceae2b99
4
+ data.tar.gz: 490d82d0fdd65109eb01f8a1a3a6d9f0282029c2
5
5
  SHA512:
6
- metadata.gz: cda47f9fbfa8af03503eefc79f27752efa57688c02a847a30fa909cc6d5576bdcefea4e296b44925b42c87fae104d6850778d8c0133105c8fc069411a31bfc45
7
- data.tar.gz: 507e619be7e917d84a4c4d657c7e2b77d3a22fa346a3bd40b94fce02383f43d83c3afb0a409cf3dbe91d42a7c450c2ee88151f13df70acb70b4f61313fc64d1a
6
+ metadata.gz: d6924c2f37b47fefe39b121951b52407d7f8a7251e931a5207b2d6c8df6be6c297f0b7c1f5395f12f0211c53d31edbac90e8b41979f61893d95be67cc01b4db7
7
+ data.tar.gz: 635b74cfa73a87ae22900419d71d11c0c7c1110468079f39087cda3b25b3d5008c3e9e269253bf7a3a8ba8d374111aaa4da3747e843c565e62db9cafce844637
data/README.md CHANGED
@@ -263,6 +263,82 @@ end
263
263
  Tradesman.reset
264
264
  ```
265
265
 
266
+ ## Mocking & Stubbing in Tests
267
+
268
+ Tradesman uses the [Tzu](https://github.com/onfido/tzu) command library,
269
+ which has a specialized (and well-documented) gem for mocking/stubbing, [TzuMock](https://github.com/onfido/tzu_mock).
270
+
271
+ Since Tradesman classes are just dynamically generated Tzu commands with a slightly different interface,
272
+ you must configure TzuMock to accept the Tradesman interface.
273
+
274
+ ```ruby
275
+ # spec/spec_helper.rb
276
+ TzuMock.configure { |config| config.stub_methods = [:go, :go!] }
277
+ ```
278
+
279
+ Then, you can use TzuMock to stub any Tradesman outcome - `success`, `invalid`, and `failure`.
280
+
281
+ ```ruby
282
+ # app/controllers/users_controller.rb
283
+ class UsersController < ActionController::Base
284
+ def create
285
+ Tradesman::CreateUser.go(params) do
286
+ success do |result|
287
+ @user = result
288
+ render 'user'
289
+ end
290
+
291
+ invalid do |error|
292
+ render 'error'
293
+ end
294
+ end
295
+ end
296
+ end
297
+
298
+ # spec/controllers/users_controller.rb
299
+ describe '#create' do
300
+ context 'on success' do
301
+ let(:entity) { Horza.single(FactoryGirl.attributes_for(:user)) }
302
+
303
+ before do
304
+ TzuMock.success(Tradesman::CreateUser, entity)
305
+ post :create, request
306
+ end
307
+
308
+ it 'assigns user' do
309
+ expect(assigns(:user)).to eq entity
310
+ end
311
+
312
+ it 'renders the user template' do
313
+ expect(response).to render_template('user')
314
+ end
315
+ end
316
+
317
+ context 'on invalid' do
318
+ before do
319
+ TzuMock.invalid(Tradesman::CreateUser, { error: 'invalid path' })
320
+ post :create, request
321
+ end
322
+
323
+ it 'renders the error template' do
324
+ expect(response).to render_template('error')
325
+ end
326
+ end
327
+ end
328
+ ```
329
+
330
+ Note that Tradesman returns [Horza](https://github.com/onfido/horza) entities by default, so it is recommended to return Horza entities when stubbing.
331
+ Horza provides two shortcuts for this:
332
+
333
+ ```ruby
334
+ # Single entity, takes a hash
335
+ Horza.single(hash) #=> Horza::Entities::Single
336
+
337
+ # Collection, takes an array
338
+ Horza.collection(items) #=> Horza::Entities::Collection
339
+ ```
340
+
341
+
266
342
  ## Edge Cases
267
343
 
268
344
  **Models ending with double 's'**
@@ -3,7 +3,7 @@ module Tradesman
3
3
  def run_and_convert_exceptions(&block)
4
4
  block.call
5
5
  rescue *expected_errors_map.keys => e
6
- raise tradesman_error_from_gem_error(e.class)
6
+ raise tradesman_error_from_gem_error(e.class).new(e.message)
7
7
  end
8
8
 
9
9
  def tradesman_error_from_gem_error(gem_error)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tradesman
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blake Turner
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-06-23 00:00:00.000000000 Z
12
+ date: 2015-07-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: horza
@@ -17,28 +17,28 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: 0.3.6
20
+ version: 0.3.8
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: 0.3.6
27
+ version: 0.3.8
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: tzu
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: 0.0.1.0
34
+ version: 0.0.2.0
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: 0.0.1.0
41
+ version: 0.0.2.0
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: bundler
44
44
  requirement: !ruby/object:Gem::Requirement