minitest-stub_on_roids 0.0.1 → 0.0.3
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 +4 -4
- data/README.md +112 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aaef4c0cb77c912a56a222ad9bd287d5bf9f39f386917bea4a7c2ee0ff343498
|
4
|
+
data.tar.gz: 3dc69f5af5f646e6a3497ac3a4481f7d32651ae5e35a6db74cb832733724b378
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 743ed77b28fc873a00364634899354aae4cb686a5eee54317130885b27b2ff6899285d978c8dcf6b2e2b0ab72cffa1dd110efa87a58748866fb145a2319e4e5b
|
7
|
+
data.tar.gz: 11ae76fcc9956d9278f484910527d242f348c548020f44d5ff094bbd1368b82489eea606028c651396392c57a0a96669cb76546cbe80303ad3b4280a6e046ad3
|
data/README.md
CHANGED
@@ -1 +1,113 @@
|
|
1
1
|
# minitest-stub_on_roids
|
2
|
+
|
3
|
+
Provides a set of helper methods around Minitest's `Object#stub` method.
|
4
|
+
|
5
|
+
The following methods are available:
|
6
|
+
|
7
|
+
* `#stub_with_args`
|
8
|
+
1. Stubs a class method for the duration of the block.
|
9
|
+
2. *If* the method is called, asserts that it is called with the expected arguments.
|
10
|
+
3. Doesn't mind how many times the method is called, if at all.
|
11
|
+
* `#stub_and_expect`
|
12
|
+
1. Stubs a class method for the duration of the block.
|
13
|
+
2. Asserts that the method is called the exact amount of times as expected, and with the expected arguments.
|
14
|
+
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
Add this line to your application's Gemfile:
|
19
|
+
|
20
|
+
gem "minitest-stub_on_roids"
|
21
|
+
|
22
|
+
And then execute:
|
23
|
+
|
24
|
+
$ bundle
|
25
|
+
|
26
|
+
Or install it yourself as:
|
27
|
+
|
28
|
+
$ gem install minitest-stub_on_roids
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
|
32
|
+
Require `minitest/stub_on_roids` in your test:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
require 'minitest/stub_on_roids'
|
36
|
+
```
|
37
|
+
|
38
|
+
Extend the class you want to stub methods of:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
Banana.extend Minitest::StubOnRoids
|
42
|
+
```
|
43
|
+
|
44
|
+
This will add the following methods to the class:
|
45
|
+
|
46
|
+
### `#stub_with_args`
|
47
|
+
|
48
|
+
Use `#stub_with_args` to stub a class method as you normally would but also assert that if it is called - it is called with the expected arguments:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
Banana.stub_with_args(:new, banana_mock, [3.0, "Yellow"]) do
|
52
|
+
Banana.new(3.0, "Yellow")
|
53
|
+
end
|
54
|
+
|
55
|
+
# :new is stubbed and `banana_mock` is returned instead
|
56
|
+
|
57
|
+
Banana.stub_with_args(:new, banana_mock, [3.0, "Green"]) do
|
58
|
+
Banana.new(3.0, "Yellow")
|
59
|
+
end
|
60
|
+
|
61
|
+
# A StubbedMethodArgsError is raised because :new was called with the wrong arguments
|
62
|
+
```
|
63
|
+
|
64
|
+
Just like with Minitest's `Object#stub` method, there is no expectation on the amount of times the stubbed method is called in the block.
|
65
|
+
|
66
|
+
### `#stub_and_expect`
|
67
|
+
|
68
|
+
Use `#stub_and_expect` to stub a class method as you normally would but also set expectations on it, similarly to using `Minitest::Mock#expect`.
|
69
|
+
|
70
|
+
This means that a `MockExpectationError` will be thrown if inside the block:
|
71
|
+
* The method is called with a different set of arguments than expected.
|
72
|
+
* The method is called more or less the amount of times it was expected to be called.
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
Banana.stub_and_expect(:new, banana_mock, [3.0, "Yellow"]) do
|
76
|
+
# Not calling `Banana.new`
|
77
|
+
end
|
78
|
+
|
79
|
+
# => MockExpectationError raised
|
80
|
+
```
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
Banana.stub_and_expect(:new, banana_mock, [3.0, "Yellow"]) do
|
84
|
+
Banana.new(3.0, "Yellow")
|
85
|
+
Banana.new(3.0, "Yellow")
|
86
|
+
end
|
87
|
+
|
88
|
+
# => MockExpectationError raised
|
89
|
+
```
|
90
|
+
|
91
|
+
Use the `times` keyword argument to expect a method to be called a specific amount of times within the block (default is 1):
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
Banana.stub_and_expect(:new, banana_mock, [3.0, "Yellow"], times: 2) do
|
95
|
+
Banana.new(3.0, "Yellow")
|
96
|
+
Banana.new(3.0, "Yellow")
|
97
|
+
end
|
98
|
+
|
99
|
+
# => Works
|
100
|
+
```
|
101
|
+
|
102
|
+
### Limitations
|
103
|
+
|
104
|
+
* Nesting blocks is not supported, meaning you can't expect methods to be called with more than one set of arguments at a time.
|
105
|
+
* This gem might work with instance methods as well, but its intent is (and it's only tested for) using it on class methods.
|
106
|
+
|
107
|
+
## Contributing
|
108
|
+
|
109
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/thatguysimon/minitest-stub_on_roids. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](https://contributor-covenant.org) code of conduct.
|
110
|
+
|
111
|
+
## License
|
112
|
+
|
113
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minitest-stub_on_roids
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon Nizov
|
@@ -10,7 +10,7 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2019-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: '
|
13
|
+
description: A set of helper methods based around Minitest's Object#stub method.
|
14
14
|
email: simon.nizov@gmail.com
|
15
15
|
executables: []
|
16
16
|
extensions: []
|
@@ -21,7 +21,7 @@ files:
|
|
21
21
|
- README.md
|
22
22
|
- Rakefile
|
23
23
|
- lib/minitest/stub_on_roids.rb
|
24
|
-
homepage: https://
|
24
|
+
homepage: https://github.com/thatguysimon/minitest-stub_on_roids
|
25
25
|
licenses:
|
26
26
|
- MIT
|
27
27
|
metadata: {}
|
@@ -43,5 +43,5 @@ requirements: []
|
|
43
43
|
rubygems_version: 3.0.3
|
44
44
|
signing_key:
|
45
45
|
specification_version: 4
|
46
|
-
summary: 'Minitest''s #stub but
|
46
|
+
summary: 'Minitest''s #stub but on steroids'
|
47
47
|
test_files: []
|