mockable 0.1.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 +7 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +99 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/mockable/version.rb +3 -0
- data/lib/mockable.rb +18 -0
- data/mockable.gemspec +25 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: afbee1549c1de88e86e03d98455b6f6d2146bc83
|
4
|
+
data.tar.gz: 569ecd8beb60e08734112444706ac7f07f4f6c90
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9c4047f6a28e7c4a6a9e6971c5d91728476987deeef710023af364227dfae5e1ffb4d91e6d1d98df0fe87282e812c4ed379115140298ba939f9821ead96f4e39
|
7
|
+
data.tar.gz: 920a4e3aca4191011b2328cc2a28118360fb5c5b0f4bcbea401b16828d71ae166b8339396399cd79afcfc94a3ceb41c34ae816c467c08e6925b33aece79bf733
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
mockable
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.0
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Dennis Walters
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
# Mockable #
|
2
|
+
|
3
|
+
Mockable is a quick and dirty interface that lets you know if your user wants
|
4
|
+
you to use mocked interfaces and such.
|
5
|
+
|
6
|
+
## WHY?!?!?!?! ##
|
7
|
+
|
8
|
+
Well, because I write a lot of API clients and such, and then I end up using
|
9
|
+
them in my apps. When I run tests against those apps, I find it easiest if
|
10
|
+
the library itself provides a transparent mocked interface.
|
11
|
+
|
12
|
+
I prefer to decide if mocking is desired by checking an environment variable,
|
13
|
+
because I write a lot of my app-level tests in languages other than Go. As
|
14
|
+
I do this sort of thing quite a lot, occasionallly needing to enable mocking
|
15
|
+
for several clients at once, it finally made sense to just go ahead and
|
16
|
+
formalize the process and use a uniform environment variable, MOCKABLE,
|
17
|
+
for everything.
|
18
|
+
|
19
|
+
|
20
|
+
## Installation ##
|
21
|
+
|
22
|
+
Add this line to your application's Gemfile:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
gem 'mockable'
|
26
|
+
```
|
27
|
+
|
28
|
+
And then execute:
|
29
|
+
|
30
|
+
$ bundle
|
31
|
+
|
32
|
+
Or install it yourself as:
|
33
|
+
|
34
|
+
$ gem install mockable
|
35
|
+
|
36
|
+
## Usage ##
|
37
|
+
|
38
|
+
Here's a quasi-real-world example. Let's say your library generates widgets.
|
39
|
+
Now, in production, you really want to make good, real, quality widgets. Under
|
40
|
+
test, though, the app that uses your widget generator may just need to ensure
|
41
|
+
that a widget gets generated. Here's how I like to handle that:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
require 'mockable'
|
45
|
+
|
46
|
+
module Factory
|
47
|
+
Widget = Struct.new(:name)
|
48
|
+
|
49
|
+
class Generator
|
50
|
+
def generate(name)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class Real < Generator
|
55
|
+
def generate(name)
|
56
|
+
# do a bunch of stuff that hits the real widget service out there in space
|
57
|
+
# ...
|
58
|
+
|
59
|
+
generated_widget
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
class Fake < Generator
|
64
|
+
def generate(name)
|
65
|
+
Widget.new(name)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.generator
|
70
|
+
Mockable.mocked? ? Fake : Real).new
|
71
|
+
end
|
72
|
+
end
|
73
|
+
```
|
74
|
+
|
75
|
+
Now, when the above is used and `Factory.generator` is called, a fake
|
76
|
+
generator is returned if mocking is enabled (by setting the `MOCKABLE`
|
77
|
+
environment variable to pretty much anything), but a real generator otherwise.
|
78
|
+
|
79
|
+
## Development ##
|
80
|
+
|
81
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
82
|
+
|
83
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
84
|
+
|
85
|
+
## Contributing
|
86
|
+
|
87
|
+
***NOTE: This project uses git-flow. Please base your feature branches off of the develop branch.***
|
88
|
+
|
89
|
+
1. Fork it ( https://github.com/ess/mockable/fork )
|
90
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
91
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
92
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
93
|
+
5. Create a new Pull Request
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
## History ##
|
98
|
+
|
99
|
+
* 0.1.0 - Initial port from Go
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "mockable"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/mockable.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "mockable/version"
|
2
|
+
|
3
|
+
module Mockable
|
4
|
+
VARNAME = 'MOCKABLE'
|
5
|
+
|
6
|
+
def self.mocked?
|
7
|
+
ENV[VARNAME] ? true : false
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.enable
|
11
|
+
ENV[VARNAME] = '1' unless mocked?
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.disable
|
15
|
+
ENV.delete(VARNAME) if mocked?
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
data/mockable.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'mockable/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mockable"
|
8
|
+
spec.version = Mockable::VERSION
|
9
|
+
spec.authors = ["Dennis Walters"]
|
10
|
+
spec.email = ["dwalters@engineyard.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Declare your intention to mock}
|
13
|
+
spec.homepage = "https://github.com/ess/mockable-ruby"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.9'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
spec.add_development_dependency 'rspec', '~> 3.6.0'
|
24
|
+
spec.add_development_dependency 'simplecov', '~> 0.14.1'
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mockable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dennis Walters
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-05-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.9'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.6.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.6.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.14.1
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.14.1
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- dwalters@engineyard.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".ruby-gemset"
|
79
|
+
- ".ruby-version"
|
80
|
+
- ".travis.yml"
|
81
|
+
- Gemfile
|
82
|
+
- LICENSE.txt
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- bin/console
|
86
|
+
- bin/setup
|
87
|
+
- lib/mockable.rb
|
88
|
+
- lib/mockable/version.rb
|
89
|
+
- mockable.gemspec
|
90
|
+
homepage: https://github.com/ess/mockable-ruby
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.4.6
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: Declare your intention to mock
|
114
|
+
test_files: []
|