grift 0.1.0 → 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
  SHA256:
3
- metadata.gz: 27b2eccd337c396229e197435ace7c447cc7575b1a0a65deddd350a3e63a3faa
4
- data.tar.gz: 3be36076623ba83a2654a827b5375da903168b8594390678fe461d74a9a5baef
3
+ metadata.gz: d0691b07f2ab035b9c6110605b00bc162822394c078cf27271e458fd60026a18
4
+ data.tar.gz: b14b4078f42413059aab0114a62c0785c8ed19acb30a6f743e8c0c7fcab771fb
5
5
  SHA512:
6
- metadata.gz: c8080f30c6fd6a9dcdad37e500a575f6056eddb404a155bce5e153761227040684200e00d45d1c06c4e42355ea077fede56e52c7ba29a454a1eefc7717cad806
7
- data.tar.gz: c34f2ac31553fba7687503926e5fc5baa1b282516258fb48d669d157ff1e7b9b6ab8650297cf4ccd0d6741c79045836a18942dff42da90a6bcf2c764193d99a1
6
+ metadata.gz: 3719002c8f0a986c3ecd97555b7008ef21b34f5397fed8de7e721eca0a5767d101493d9b8c2852c85bc27f9742b88d2ad8c23c700d6487b6bf2e16a9baf131fa
7
+ data.tar.gz: 6d7eb236900d1be7c8928b33f5c0e5649fd96bf443f8ff1542da71f5818e8e5b8aa4d0247a10c829537bd6879bc4e741ef8015f795f18083b2b80c7af7534ace
@@ -0,0 +1 @@
1
+ .github/ @clarkedb
@@ -0,0 +1,37 @@
1
+ # How to become a contributor and submit your own code
2
+
3
+ 1. Submit an issue on GitHub describing your proposed change to this repo
4
+ 1. A repo owner will respond to your issue promptly
5
+ 1. Fork the repo, develop and test your code changes
6
+ 1. Ensure that your code adheres to the existing style in the code to which you are contributing
7
+ 1. Ensure that your code has an appropriate set of tests which all pass
8
+ 1. Title your pull request following [Conventional Commits](https://www.conventionalcommits.org/) styling
9
+ 1. Submit a pull request.
10
+
11
+ ## Policy on inclusive language
12
+
13
+ To make Grift a pleasant and effective experience for everyone, we use try to use inclusive language.
14
+
15
+ These resources can help:
16
+
17
+ - Google's tutorial [Writing inclusive documentation](https://developers.google.com/style/inclusive-documentation) teaches by example, how to reword non-inclusive things.
18
+ - Linux kernel mailing list's [Coding Style: Inclusive Terminology](https://lkml.org/lkml/2020/7/4/229) said "Add no new instances of non-inclusive words, here is a list of words not include new ones of."
19
+ - Linguistic Society of America published [Guidelines for Inclusive Language](https://www.linguisticsociety.org/resource/guidelines-inclusive-language) which concluded: "We encourage all linguists to consider the possible reactions of their potential audience to their writing and, in so doing, to choose expository practices and content that is positive, inclusive, and respectful."
20
+
21
+ This project attempts to improve in these areas. Join us in doing that important work.
22
+
23
+ ## Required checks
24
+
25
+ Before pushing your code and opening a PR, we recommend you run the following checks to avoid
26
+ our GitHub Actions Workflow to block your contribution.
27
+
28
+ ```bash
29
+ # install dependencies
30
+ $ bundle install
31
+
32
+ # Run unit tests and check code coverage
33
+ $ bundle exec rake test
34
+
35
+ # Check code style
36
+ $ bundle exec rubocop
37
+ ```
@@ -0,0 +1,11 @@
1
+ version: 2
2
+
3
+ updates:
4
+ - directory: /
5
+ open-pull-requests-limit: 10
6
+ package-ecosystem: bundler
7
+ target-branch: develop
8
+ schedule:
9
+ interval: weekly
10
+ labels:
11
+ - dependencies
@@ -0,0 +1,46 @@
1
+ name: CI
2
+
3
+ on: push
4
+
5
+ env:
6
+ GIT_COMMIT_SHA: ${{ github.sha }}
7
+ GIT_BRANCH: ${{ github.ref }}
8
+
9
+ jobs:
10
+ linting:
11
+ runs-on: ubuntu-latest
12
+ env:
13
+ BUNDLE_WITH: lint
14
+ BUNDLE_WITHOUT: development:test
15
+
16
+ steps:
17
+ - uses: actions/checkout@v2
18
+
19
+ - name: Set up Ruby 2.7
20
+ uses: ruby/setup-ruby@v1
21
+ with:
22
+ ruby-version: 2.7
23
+ bundler-cache: true
24
+
25
+ - name: Rubocop
26
+ run: bundle exec rubocop --format progress
27
+
28
+ build:
29
+ needs: [ linting ]
30
+ runs-on: ubuntu-latest
31
+ name: build (ruby v${{ matrix.ruby }})
32
+ strategy:
33
+ fail-fast: false
34
+ matrix:
35
+ ruby: [ '2.5', '2.6', '2.7', '3.0' ]
36
+
37
+ steps:
38
+ - uses: actions/checkout@v2
39
+ - uses: ruby/setup-ruby@v1
40
+ with:
41
+ ruby-version: ${{ matrix.ruby }}
42
+ bundler-cache: true
43
+
44
+ - name: Test
45
+ continue-on-error: ${{ matrix.experimental }}
46
+ run: bundle exec rake test
data/.gitignore CHANGED
@@ -11,27 +11,11 @@
11
11
  /tmp/
12
12
 
13
13
  # Used by dotenv library to load environment variables.
14
- # .env
14
+ .env
15
15
 
16
16
  # Ignore Byebug command history file.
17
17
  .byebug_history
18
18
 
19
- ## Specific to RubyMotion:
20
- .dat*
21
- .repl_history
22
- build/
23
- *.bridgesupport
24
- build-iPhoneOS/
25
- build-iPhoneSimulator/
26
-
27
- ## Specific to RubyMotion (use of CocoaPods):
28
- #
29
- # We recommend against adding the Pods directory to your .gitignore. However
30
- # you should judge for yourself, the pros and cons are mentioned at:
31
- # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
32
- #
33
- # vendor/Pods/
34
-
35
19
  ## Documentation cache and generated files:
36
20
  /.yardoc/
37
21
  /_yardoc/
@@ -46,11 +30,15 @@ build-iPhoneSimulator/
46
30
  # for a library or gem, you might want to ignore these files since the code is
47
31
  # intended to run in multiple environments; otherwise, check them in:
48
32
  # Gemfile.lock
49
- # .ruby-version
50
- # .ruby-gemset
33
+ .ruby-version
34
+ .ruby-gemset
51
35
 
52
36
  # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
53
37
  .rvmrc
54
38
 
55
39
  # Used by RuboCop. Remote config files pulled in from inherit_from directive.
56
40
  # .rubocop-https?--*
41
+
42
+ # IDE and system files
43
+ .vscode/
44
+ **/.DS_STORE
data/.rubocop.yml ADDED
@@ -0,0 +1,159 @@
1
+ # The behavior of RuboCop can be controlled via the .rubocop.yml
2
+ # configuration file. It makes it possible to enable/disable
3
+ # certain cops (checks) and to alter their behavior if they accept
4
+ # any parameters. The file can be placed either in your home
5
+ # directory or in some project directory.
6
+ #
7
+ # RuboCop will start looking for the configuration file in the directory
8
+ # where the inspected file is and continue its way up to the root directory.
9
+ #
10
+ # See https://docs.rubocop.org/rubocop/configuration
11
+
12
+ # General
13
+ AllCops:
14
+ NewCops: enable
15
+ SuggestExtensions: false
16
+
17
+ # Layout
18
+ Layout/BlockAlignment:
19
+ Enabled: true
20
+ EnforcedStyleAlignWith: start_of_block
21
+
22
+ Layout/ClassStructure:
23
+ Enabled: true
24
+
25
+ Layout/DotPosition:
26
+ Enabled: true
27
+ EnforcedStyle: leading
28
+
29
+ Layout/FirstArrayElementIndentation:
30
+ Enabled: true
31
+ EnforcedStyle: consistent
32
+
33
+ Layout/FirstHashElementIndentation:
34
+ Enabled: true
35
+ EnforcedStyle: consistent
36
+
37
+ Layout/HashAlignment:
38
+ Enabled: true
39
+ EnforcedColonStyle: key
40
+ EnforcedLastArgumentHashStyle: always_inspect
41
+
42
+ Layout/LineEndStringConcatenationIndentation:
43
+ Enabled: true
44
+ EnforcedStyle: aligned
45
+
46
+ Layout/LineLength:
47
+ Enabled: true
48
+ Max: 120
49
+
50
+ Layout/MultilineArrayLineBreaks:
51
+ Enabled: true
52
+
53
+ Layout/MultilineAssignmentLayout:
54
+ Enabled: false
55
+
56
+ Layout/MultilineHashKeyLineBreaks:
57
+ Enabled: true
58
+
59
+ Layout/MultilineMethodArgumentLineBreaks:
60
+ Enabled: true
61
+
62
+ Layout/MultilineMethodCallIndentation:
63
+ Enabled: true
64
+ EnforcedStyle: indented_relative_to_receiver
65
+
66
+ Layout/MultilineOperationIndentation:
67
+ Enabled: true
68
+ EnforcedStyle: indented
69
+
70
+ Layout/ParameterAlignment:
71
+ Enabled: true
72
+ EnforcedStyle: with_first_parameter
73
+
74
+ Layout/RedundantLineBreak:
75
+ Enabled: true
76
+ InspectBlocks: false
77
+
78
+ Layout/SingleLineBlockChain:
79
+ Enabled: false
80
+
81
+ Layout/SpaceBeforeBrackets:
82
+ Enabled: true
83
+
84
+ Layout/TrailingEmptyLines:
85
+ Enabled: true
86
+ EnforcedStyle: final_newline
87
+
88
+ # Lint
89
+ Lint/AmbiguousAssignment:
90
+ Enabled: true
91
+
92
+ Lint/AmbiguousOperatorPrecedence:
93
+ Enabled: true
94
+
95
+ Lint/AmbiguousRange:
96
+ Enabled: true
97
+
98
+ # Metrics
99
+ Metrics/AbcSize:
100
+ Max: 20
101
+ Exclude:
102
+ - "test/**/*"
103
+
104
+ Metrics/ClassLength:
105
+ Max: 150
106
+ CountAsOne:
107
+ - array
108
+ - hash
109
+ - heredoc
110
+ Exclude:
111
+ - "test/**/*"
112
+
113
+ Metrics/MethodLength:
114
+ Max: 20
115
+ CountAsOne:
116
+ - array
117
+ - hash
118
+ - heredoc
119
+ Exclude:
120
+ - "test/**/*"
121
+
122
+ # Naming
123
+ Naming/InclusiveLanguage:
124
+ Enabled: true
125
+
126
+ Naming/VariableNumber:
127
+ EnforcedStyle: snake_case
128
+
129
+ # Style
130
+ Style/AndOr:
131
+ EnforcedStyle: always
132
+
133
+ Style/ArrayCoercion:
134
+ Enabled: true
135
+
136
+ Style/CollectionCompact:
137
+ Enabled: true
138
+
139
+ Style/ConstantVisibility:
140
+ Enabled: true
141
+ IgnoreModules: true
142
+
143
+ Style/Documentation:
144
+ Exclude:
145
+ - "test/**/*"
146
+
147
+ Style/DocumentationMethod:
148
+ Enabled: true
149
+ Exclude:
150
+ - "test/**/*"
151
+
152
+ Style/SelectByRegexp:
153
+ Enabled: false
154
+
155
+ Style/SwapValues:
156
+ Enabled: true
157
+
158
+ Style/TrailingCommaInArrayLiteral:
159
+ EnforcedStyleForMultiline: comma
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ -o ./docs - LICENSE
data/CHANGELOG.md CHANGED
@@ -0,0 +1,26 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## Unreleased
8
+
9
+ N/A
10
+
11
+ ## [1.0.0](https://github.com/clarkedb/grift/releases/tag/v1.0.0) - 2021-11-06
12
+
13
+ The first major version of Grift! 100% documentation and 100% code coverage.
14
+
15
+ ### Added
16
+
17
+ * Spying on method
18
+ * Mocking method return values
19
+ * Mocking method implementation
20
+ * Restricted methods that cannot be mocked
21
+ * MiniTest Plugin to use hooks and clean up after tests
22
+ * Documentation!
23
+
24
+ ## [0.1.0](https://github.com/clarkedb/grift/releases/tag/v0.1.0) - 2021-10-12
25
+
26
+ The initial version of Grift. This was never intended for use and should be considered **deprecated**.
data/Gemfile CHANGED
@@ -1,7 +1,21 @@
1
- source "https://rubygems.org"
1
+ # frozen_string_literal: true
2
2
 
3
- # Specify your gem's dependencies in grift.gemspec
3
+ source 'https://rubygems.org'
4
+
5
+ # Grift's gem dependencies are defined in grift.gemspec
4
6
  gemspec
5
7
 
6
- gem "minitest", "~> 5.0"
7
- gem "rake", "~> 12.0"
8
+ gem 'rake', '>= 12.0'
9
+
10
+ group :development, :test do
11
+ gem 'minitest', '>= 5.0'
12
+ gem 'minitest-reporters', '>= 1.4.3'
13
+ gem 'simplecov', '>= 0.21.2'
14
+ end
15
+
16
+ group :development, :lint do
17
+ gem 'rubocop'
18
+ gem 'rubocop-minitest'
19
+ gem 'rubocop-packaging', '>= 0.5'
20
+ gem 'rubocop-performance', '>= 1.0'
21
+ end
data/Gemfile.lock CHANGED
@@ -1,21 +1,68 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- grift (0.1.0)
4
+ grift (1.0.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
+ ansi (1.5.0)
10
+ ast (2.4.2)
11
+ builder (3.2.4)
12
+ docile (1.4.0)
9
13
  minitest (5.14.4)
14
+ minitest-reporters (1.4.3)
15
+ ansi
16
+ builder
17
+ minitest (>= 5.0)
18
+ ruby-progressbar
19
+ parallel (1.21.0)
20
+ parser (3.0.2.0)
21
+ ast (~> 2.4.1)
22
+ rainbow (3.0.0)
10
23
  rake (12.3.3)
24
+ regexp_parser (2.1.1)
25
+ rexml (3.2.5)
26
+ rubocop (1.22.3)
27
+ parallel (~> 1.10)
28
+ parser (>= 3.0.0.0)
29
+ rainbow (>= 2.2.2, < 4.0)
30
+ regexp_parser (>= 1.8, < 3.0)
31
+ rexml
32
+ rubocop-ast (>= 1.12.0, < 2.0)
33
+ ruby-progressbar (~> 1.7)
34
+ unicode-display_width (>= 1.4.0, < 3.0)
35
+ rubocop-ast (1.12.0)
36
+ parser (>= 3.0.1.1)
37
+ rubocop-minitest (0.15.2)
38
+ rubocop (>= 0.90, < 2.0)
39
+ rubocop-packaging (0.5.1)
40
+ rubocop (>= 0.89, < 2.0)
41
+ rubocop-performance (1.11.5)
42
+ rubocop (>= 1.7.0, < 2.0)
43
+ rubocop-ast (>= 0.4.0)
44
+ ruby-progressbar (1.11.0)
45
+ simplecov (0.21.2)
46
+ docile (~> 1.1)
47
+ simplecov-html (~> 0.11)
48
+ simplecov_json_formatter (~> 0.1)
49
+ simplecov-html (0.12.3)
50
+ simplecov_json_formatter (0.1.3)
51
+ unicode-display_width (2.1.0)
11
52
 
12
53
  PLATFORMS
13
54
  ruby
14
55
 
15
56
  DEPENDENCIES
16
57
  grift!
17
- minitest (~> 5.0)
18
- rake (~> 12.0)
58
+ minitest (>= 5.0)
59
+ minitest-reporters (>= 1.4.3)
60
+ rake (>= 12.0)
61
+ rubocop
62
+ rubocop-minitest
63
+ rubocop-packaging (>= 0.5)
64
+ rubocop-performance (>= 1.0)
65
+ simplecov (>= 0.21.2)
19
66
 
20
67
  BUNDLED WITH
21
68
  2.1.4
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Grift
2
2
 
3
+ [![gem version](https://badge.fury.io/rb/grift.svg)](https://rubygems.org/gems/grift)
4
+ [![downloads](https://ruby-gem-downloads-badge.herokuapp.com/grift)](https://rubygems.org/gems/grift)
5
+ [![build](https://github.com/clarkedb/grift/actions/workflows/ci.yml/badge.svg)](https://github.com/clarkedb/grift/actions?query=workflow%3ACI)
6
+
3
7
  Mocking and spying in Ruby's MiniTest framework
4
8
 
5
9
  ## Installation
@@ -22,16 +26,84 @@ Or install it yourself as:
22
26
  gem install grift
23
27
  ```
24
28
 
29
+ ### MiniTest Plugin
30
+
31
+ We recommend using the plugin so that mocks are cleaned up after each test automatically. To enable the plugin, add the following lines of code to your `test_helper` file.
32
+
33
+ ```ruby
34
+ class Minitest::Test
35
+ include Grift::MinitestPlugin
36
+ end
37
+ ```
38
+
25
39
  ## Usage
26
40
 
27
- TODO: Write usage instructions here
41
+ For complete usage guide, see the [docs](https://clarkedb.github.io/grift/).
42
+
43
+ ### Spy
44
+
45
+ To "mock" a method and spy on its call args and results without changing the behavior of the method:
46
+
47
+ ```ruby
48
+ my_mock = Grift.spy_on(MyClass, :my_method)
49
+ ```
50
+
51
+ ### Mock
52
+
53
+ To mock a method and its return value:
54
+
55
+ ```ruby
56
+ my_mock = Grift.mock(MyClass, :my_method, return_value)
57
+
58
+ my_spy = Grift.spy_on(MyClass, :my_method)
59
+ my_spy.mock_return_value(return_value)
60
+ ```
61
+
62
+ To mock the implementation:
63
+
64
+ ```ruby
65
+ my_spy = Grift.spy_on(MyClass, :my_method)
66
+ my_spy.mock_implementation do |arg1, arg2|
67
+ x = do_something(arg1, arg2)
68
+ do_something_else(x) # the last line will be returned
69
+ end
70
+ ```
71
+
72
+ ### Chaining
73
+
74
+ You can chain `mock_return_value` and `mock_implementation` after initializing the mock.
75
+
76
+ ```ruby
77
+ my_mock = Grift.spy_on(MyClass, :my_method).mock_implementation do |*args|
78
+ do_something(*args)
79
+ end
80
+ #=> Grift::MockMethod object is returned
81
+ ```
82
+
83
+ ### Results
84
+
85
+ To get the results and details of the calls, call `mock` on your mock method object.
86
+
87
+ ```ruby
88
+ # get the number of times the mocked method has been called
89
+ my_mock.mock.count
90
+ #=> 2
91
+
92
+ # get args for each call to the method while mocked
93
+ my_mock.mock.calls
94
+ #=> [['first_arg1', 'second_arg1'], ['first_arg2', 'second_arg2']]
95
+
96
+ # get results (return value) for each call to the method while mocked
97
+ my_mock.mock.results
98
+ #=> ['result1', 'result2']
99
+ ```
28
100
 
29
101
  ## Development
30
102
 
31
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
103
+ After forking the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
32
104
 
33
- 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`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
105
+ When developing, to install Grift whith your changes 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` , which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
34
106
 
35
107
  ## Contributing
36
108
 
37
- Bug reports and pull requests are welcome on GitHub at [clarkedb/grift](https://github.com/clarkedb/grift).
109
+ Bug reports and pull requests are welcome on GitHub at [clarkedb/grift](https://github.com/clarkedb/grift). Before submitting a pull request, see [CONTRIBUTING](.github/CONTRIBUTING.md).
data/bin/console CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'bundler/setup'
4
5
  require 'grift'
data/grift.gemspec CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'lib/grift/version'
2
4
 
3
5
  Gem::Specification.new do |spec|
@@ -0,0 +1,31 @@
1
+ Grift:
2
+ - "*"
3
+
4
+ Minitest:
5
+ - "*"
6
+
7
+ # ruby classes
8
+ Array:
9
+ - count
10
+ - empty?
11
+ - include?
12
+ - map
13
+ - push
14
+
15
+ Class:
16
+ - "*"
17
+
18
+ Hash:
19
+ - "[]"
20
+ - "[]="
21
+ - include?
22
+ - select
23
+
24
+ String:
25
+ - "=="
26
+ - "[]"
27
+ - to_sym
28
+
29
+ Symbol:
30
+ - "=="
31
+ - to_s
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+
5
+ module Grift
6
+ ##
7
+ # The config for Grift. This is readonly for now.
8
+ #
9
+ module Config
10
+ @restricted_methods = YAML.safe_load(File.read('lib/grift/config/restricted.yml'))
11
+
12
+ class << self
13
+ ##
14
+ # The restricted methods as a hash organized by class as the key and then the
15
+ # methods in an array as the value. A '*' means all methods are restricted.
16
+ # A '^' preceding a method overrides the wildcard restriction.
17
+ #
18
+ # @example
19
+ # Grift::Config.restricted_methods
20
+ # #=> { 'Class' => ['method1', ...], ... }
21
+ #
22
+ # @return [Hash] the restricted methods organized by class
23
+ #
24
+ attr_reader :restricted_methods
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Grift
4
+ ##
5
+ # The error used for all of Grift.
6
+ #
7
+ class Error < StandardError; end
8
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Grift
4
+ ##
5
+ # A plugin to clean up mocks after tests in Minitest.
6
+ # It is recommended that you include this plugin to avoid
7
+ # needing to cleanup the mocks after each test.
8
+ #
9
+ # To setup the plugin for your tests, you should include the
10
+ # following code in your `test_helper`
11
+ #
12
+ # class Minitest::Test
13
+ # include Grift::MinitestPlugin
14
+ # end
15
+ #
16
+ module MinitestPlugin
17
+ ##
18
+ # After each test restores all mocks with no watching.
19
+ #
20
+ # @return [Grift::MockStore]
21
+ #
22
+ def after_teardown
23
+ super
24
+ Grift.restore_all_mocks(watch: false)
25
+ end
26
+ end
27
+ end