rogue-objects 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c58f3c07599c88b2d74a99c3c3d28773c2a1b93a960f710de7ffcedfae18465e
4
- data.tar.gz: 89b38e4437dff20aaede7ac2b4d1cf73da4a4f4785fd5cdcb62728e154b77314
3
+ metadata.gz: 8a00d660d2fa64fb76770f2ea019a8499004e8e11a063c41fe6451e80bf4e5e4
4
+ data.tar.gz: f9a168d5eddab272e1bf64e60699a71ef1ab58cc1a86842b38bc2a24056777b5
5
5
  SHA512:
6
- metadata.gz: 62eaf057ee2f413906349cdec1d66c178d0ee21a03aacf3948255ee2e93df309ac0dbefdccd677921a8facab147d74a6278b01952dc039cd61faf30636bbb2ea
7
- data.tar.gz: 5ade40a2340f6cae1ce7e95b03595296e5925e23f90f44d31879bd67d9599cf24b2f7caa451b8503a6ab1893905a533e6fc847e9a1710f362247651a04eaeb15
6
+ metadata.gz: 46517199996109d101d02331ccb0dd90e53cb1eb0d8deffb21647d83496679c4412efa39912d7ed228c2c07d69351d3a5414e6ed8e5cdf63ccc71801dec546d8
7
+ data.tar.gz: a7bcdf49ed289f8d6d063d9e2282218fdead7e603796c2d94227d323cf2a02d36036f942e1cf30747560e84390378281e32eca3033f80ccffa03440ff2223c40
data/Gemfile.lock ADDED
@@ -0,0 +1,21 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rogue-objects (0.2.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ minitest (5.8.5)
10
+ rake (10.4.2)
11
+
12
+ PLATFORMS
13
+ x86_64-darwin-19
14
+
15
+ DEPENDENCIES
16
+ minitest (~> 5.0)
17
+ rake (~> 10.0)
18
+ rogue-objects!
19
+
20
+ BUNDLED WITH
21
+ 2.2.11
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
- # Rogue
1
+ # Rogue-Objects
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rogue`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ Rogue-Objects is a set of utilities to help developers write focused unit tests. It includes
4
+ a Rogue-Object component which is a dynamic object that can be created with properties & functions
5
+ that can be accessed via dot notation.
6
6
 
7
7
  ## Installation
8
8
 
@@ -22,7 +22,34 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- TODO: Write usage instructions here
25
+ Scenario:
26
+ You need to test a DuckHunter which requires an object that looks like a duck and quacks like a duck
27
+ but you don't want to create an actual duck. Rogue-Objects give you an `obj` expression you can use
28
+ to create a lightweight object that looks like a duck and quacks like a duck. This is an object with
29
+ all the properties/methods of a duck. See the following:
30
+
31
+ ```ruby
32
+ duck = obj(feathers:true, color:'black', name: 'Daffy',
33
+ speak: proc{ "Quack!"},
34
+ fly: proc {|location| location.y += 100})
35
+ ```
36
+
37
+ Consider a DuckHunter which looks for this animal and calls methods and accesses properties via dot
38
+ notation.
39
+ ```ruby
40
+ class DuckHunter
41
+ def hunt
42
+ if @duck.feathers && @duck.color == 'black'
43
+ @duck.fly
44
+ while @duck.speak == 'Quack!'
45
+ shoot(@duck)
46
+ end
47
+ end
48
+ end
49
+ end
50
+ ```
51
+ This hunter can be supplied with our duck without the need to load the actual Duck class, formally create
52
+ a Duck class substitution class, or use too much noise code from mock frameworks.
26
53
 
27
54
  ## Development
28
55
 
@@ -0,0 +1,39 @@
1
+ require 'minitest/autorun'
2
+
3
+ module Rogue
4
+ module Support
5
+ module MockMethods
6
+ # Chained method calls in the form of mock.first.second.third
7
+ # can be made on a mock with this auxillary method
8
+ def expect_chained_call(mock, chain_call, ret_val, args = [])
9
+ calls = chain_call.split('.')
10
+ calls[0, calls.length - 1].each do |each|
11
+ mock.expect(each.to_sym, mock)
12
+ end
13
+ mock.expect(calls.last, ret_val, args) unless block_given?
14
+ if block_given?
15
+ mock.expect(calls.last, ret_val) do |*var_args|
16
+ yield var_args
17
+ end
18
+ end
19
+ end
20
+
21
+ # A Mock context allows us to code the mock expectations AFTER the tested method
22
+ class MockContext
23
+ def initialize(block)
24
+ @block = block
25
+ @mock = ::Minitest::Mock.new
26
+ end
27
+
28
+ def verify_the_mock(&verify_block)
29
+ verify_block&.call(@mock)
30
+ @block.call(@mock)
31
+ @mock.verify
32
+ end
33
+ end
34
+ def with_new_mock(&block)
35
+ MockContext.new(block)
36
+ end
37
+ end
38
+ end
39
+ end
data/lib/rogue/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rogue
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
@@ -10,13 +10,13 @@ Gem::Specification.new do |spec|
10
10
 
11
11
  spec.summary = "A gem to augment unit testing"
12
12
  spec.description = "Ruby MiniTest utilities"
13
- spec.homepage = "https://github.com/cliff76/rogue"
13
+ spec.homepage = "https://github.com/cliff76/rogue-objects"
14
14
  spec.license = "MIT"
15
15
  spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
16
16
 
17
17
  spec.metadata["homepage_uri"] = spec.homepage
18
- spec.metadata["source_code_uri"] = "https://github.com/cliff76/rogue"
19
- spec.metadata["changelog_uri"] = "https://github.com/cliff76/rogue/CHANGELOG.md"
18
+ spec.metadata["source_code_uri"] = "https://github.com/cliff76/rogue-objects"
19
+ spec.metadata["changelog_uri"] = "https://github.com/cliff76/rogue-objects/CHANGELOG.md"
20
20
 
21
21
  # Specify which files should be added to the gem when it is released.
22
22
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rogue-objects
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Clifton Craig
@@ -21,21 +21,23 @@ files:
21
21
  - CHANGELOG.md
22
22
  - CODE_OF_CONDUCT.md
23
23
  - Gemfile
24
+ - Gemfile.lock
24
25
  - LICENSE.txt
25
26
  - README.md
26
27
  - Rakefile
27
28
  - bin/console
28
29
  - bin/setup
29
30
  - lib/rogue.rb
31
+ - lib/rogue/support/mock_methods.rb
30
32
  - lib/rogue/version.rb
31
33
  - rogue-objects.gemspec
32
- homepage: https://github.com/cliff76/rogue
34
+ homepage: https://github.com/cliff76/rogue-objects
33
35
  licenses:
34
36
  - MIT
35
37
  metadata:
36
- homepage_uri: https://github.com/cliff76/rogue
37
- source_code_uri: https://github.com/cliff76/rogue
38
- changelog_uri: https://github.com/cliff76/rogue/CHANGELOG.md
38
+ homepage_uri: https://github.com/cliff76/rogue-objects
39
+ source_code_uri: https://github.com/cliff76/rogue-objects
40
+ changelog_uri: https://github.com/cliff76/rogue-objects/CHANGELOG.md
39
41
  post_install_message:
40
42
  rdoc_options: []
41
43
  require_paths: