strictly_fake 0.1.0 → 0.1.4

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: 12c67d1493c17fbe736895b8fa5bf60bd96959e16290a8e38b35a82fc0c21013
4
- data.tar.gz: '0088588b7626d8aeee1f80f0171f828aca5e8c558a28538a2321ba9bc7ca1d41'
3
+ metadata.gz: f2747dee35aba648497c6bb49ba37eb96281f5ca6b31c162ac6e46b55f85282c
4
+ data.tar.gz: 87a07c562759d7ad1bc59a70ee3d3ac690505fbe0eb2e4edc2c3ae1d7518734f
5
5
  SHA512:
6
- metadata.gz: 347ae7e5cdec81ab141f47c98b93b59cd272344bcc5ef7246468bab280977d215e050ccf8815de613992457f97ba15d1ddc9a82ca4a0f2d796daac290a6003cc
7
- data.tar.gz: 7febf5c8242d3144924297de781d1e2cc6fff1ea31cd873f42b0029e90343233668726a06a418daf3d8d98367306821370545d7fd2fc79aa7f851b866d9fb38a
6
+ metadata.gz: db55c532a8f87ace74be84f84f4b5d74b667ac8b0ba6852da5c7217729b8c45f4056a91ad113d34f2f1e1c5738a19353ff4c9f4218cb0a660c8dea5971ac3e57
7
+ data.tar.gz: 45bea78790f826fd0c1f798c437f9ca0594c1e870ad2d2d4766f8984bb9c2faacddd42ab949b8bcbe96fc97e8f5480343d53f40df44736d41de1a602ca50f016
@@ -0,0 +1,37 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on:
11
+ push:
12
+ branches: [ master ]
13
+ pull_request:
14
+ branches: [ master ]
15
+
16
+ jobs:
17
+ test:
18
+
19
+ runs-on: ubuntu-latest
20
+ strategy:
21
+ matrix:
22
+ ruby-version: ['2.7', '3.0']
23
+
24
+ steps:
25
+ - uses: actions/checkout@v2
26
+ - name: Set up Ruby
27
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
28
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
29
+ uses: ruby/setup-ruby@v1
30
+ # uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
31
+ with:
32
+ ruby-version: ${{ matrix.ruby-version }}
33
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
34
+ - name: lint
35
+ run: bundle exec rubocop
36
+ - name: test
37
+ run: bundle exec rspec
data/Gemfile.lock CHANGED
@@ -1,53 +1,55 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- strict_fake (0.1.0)
4
+ strictly_fake (0.1.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- ast (2.4.1)
10
- awesome_print (1.8.0)
11
- diff-lcs (1.4.4)
12
- docile (1.3.2)
13
- minitest (5.14.2)
14
- parallel (1.19.2)
15
- parser (2.7.2.0)
9
+ ast (2.4.2)
10
+ awesome_print (1.9.2)
11
+ diff-lcs (1.5.0)
12
+ docile (1.4.0)
13
+ minitest (5.15.0)
14
+ parallel (1.21.0)
15
+ parser (3.1.0.0)
16
16
  ast (~> 2.4.1)
17
- rainbow (3.0.0)
18
- rake (13.0.1)
19
- regexp_parser (1.8.2)
20
- rexml (3.2.4)
17
+ rainbow (3.1.1)
18
+ rake (13.0.6)
19
+ regexp_parser (2.2.0)
20
+ rexml (3.2.5)
21
21
  rspec (3.10.0)
22
22
  rspec-core (~> 3.10.0)
23
23
  rspec-expectations (~> 3.10.0)
24
24
  rspec-mocks (~> 3.10.0)
25
- rspec-core (3.10.0)
25
+ rspec-core (3.10.1)
26
26
  rspec-support (~> 3.10.0)
27
- rspec-expectations (3.10.0)
27
+ rspec-expectations (3.10.1)
28
28
  diff-lcs (>= 1.2.0, < 2.0)
29
29
  rspec-support (~> 3.10.0)
30
- rspec-mocks (3.10.0)
30
+ rspec-mocks (3.10.2)
31
31
  diff-lcs (>= 1.2.0, < 2.0)
32
32
  rspec-support (~> 3.10.0)
33
- rspec-support (3.10.0)
34
- rubocop (1.1.0)
33
+ rspec-support (3.10.3)
34
+ rubocop (1.24.1)
35
35
  parallel (~> 1.10)
36
- parser (>= 2.7.1.5)
36
+ parser (>= 3.0.0.0)
37
37
  rainbow (>= 2.2.2, < 4.0)
38
- regexp_parser (>= 1.8)
38
+ regexp_parser (>= 1.8, < 3.0)
39
39
  rexml
40
- rubocop-ast (>= 1.0.1)
40
+ rubocop-ast (>= 1.15.1, < 2.0)
41
41
  ruby-progressbar (~> 1.7)
42
- unicode-display_width (>= 1.4.0, < 2.0)
43
- rubocop-ast (1.1.0)
44
- parser (>= 2.7.1.5)
45
- ruby-progressbar (1.10.1)
46
- simplecov (0.19.1)
42
+ unicode-display_width (>= 1.4.0, < 3.0)
43
+ rubocop-ast (1.15.1)
44
+ parser (>= 3.0.1.1)
45
+ ruby-progressbar (1.11.0)
46
+ simplecov (0.21.2)
47
47
  docile (~> 1.1)
48
48
  simplecov-html (~> 0.11)
49
+ simplecov_json_formatter (~> 0.1)
49
50
  simplecov-html (0.12.3)
50
- unicode-display_width (1.7.0)
51
+ simplecov_json_formatter (0.1.3)
52
+ unicode-display_width (2.1.0)
51
53
 
52
54
  PLATFORMS
53
55
  ruby
@@ -59,7 +61,7 @@ DEPENDENCIES
59
61
  rspec
60
62
  rubocop
61
63
  simplecov
62
- strict_fake!
64
+ strictly_fake!
63
65
 
64
66
  BUNDLED WITH
65
67
  2.1.4
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # StrictlyFake [![Build Status](https://travis-ci.org/featurist/strictly_fake.svg?branch=master)](https://travis-ci.org/featurist/strictly_fake)
1
+ # StrictlyFake [![Build status](https://github.com/featurist/strictly_fake/actions/workflows/ruby.yml/badge.svg)](https://travis-ci.org/featurist/strictly_fakehttps://github.com/featurist/strictly_fake/actions/workflows/ruby.yml) [![Gem Version](https://badge.fury.io/rb/strictly_fake.svg)](https://badge.fury.io/rb/strictly_fake)
2
2
 
3
3
  Sometimes fakes are a good choice. But the price is high. In particular, they make changing code harder. You rename a method, but all tests that stub the previous version _keep_ passing. It would be nice if those started to fail so that when they're green again, you can be certain that everything that had to be updated was updated. Well, now you can.
4
4
 
@@ -6,8 +6,8 @@ To be fair, you already can in Rspec with their [verifying double](https://relis
6
6
 
7
7
  - here you need to supply real objects to create fakes. That's controversial - as it goes against the idea of testing in isolation - but realistically, at least in Rails, everything is loaded anyway, so that's a moot point;
8
8
  - strictly_fake is aware of autogenerated methods (e.g. ActiveRecord model accessors);
9
- - strictly_fake does not stub constants (e.g. classes). You can, of course, create a fake of a class, but it'll need to be explicitely "injected" into the consumer code;
10
- - strictly_fake performs a full parameter check, comparing required, optional and keyword arguments (veryfing double only checks arity).
9
+ - strictly_fake does not stub constants (e.g. classes). You can, however, pass a fake to Minitest's `Object#stub` to achieve this (see example below);
10
+ - strictly_fake performs a full parameter check, comparing required, optional and keyword arguments (veryfing double only checks arity afaik).
11
11
 
12
12
  ## Installation
13
13
 
@@ -36,7 +36,7 @@ end
36
36
  # We can use a fake instead
37
37
  payment_gateway = StrictlyFake.new(PaymentGateway.new)
38
38
 
39
- # Let's stub a method that isn't defined in PaymentGateway:
39
+ # Let's stub a method that _isn't_ defined in PaymentGateway:
40
40
  payment_gateway.stub(:bar)
41
41
  # => throws "Can't stub non-existent method PaymentGateway#bar (StrictlyFake::Error)"
42
42
 
@@ -60,6 +60,7 @@ end
60
60
 
61
61
  payment_gateway.pay('Dave', Money.new(10))
62
62
  assert(invoked)
63
+ # => Pass
63
64
 
64
65
  # Stubbing class methods is no different
65
66
  time = StrictlyFake.new(Time)
@@ -67,6 +68,12 @@ time = StrictlyFake.new(Time)
67
68
  time.stub(:now) { 'XYZ' }
68
69
  time.now
69
70
  # => 'XYZ'
71
+
72
+ # Combine with Minitest stub to actually stub constant
73
+ Time.stub :now, time.now do
74
+ Time.now
75
+ # => 'XYZ'
76
+ end
70
77
  ```
71
78
 
72
79
  Note: Minitest is required for `assert*` to work.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class StrictlyFake
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.4'
5
5
  end
data/lib/strictly_fake.rb CHANGED
@@ -40,20 +40,18 @@ class StrictlyFake
40
40
  stub_method(meth, &block)
41
41
  end
42
42
 
43
- # rubocop:disable Lint/MissingSuper
44
- def method_missing(meth, *args)
45
- @fake.send(meth, *args)
43
+ def method_missing(meth, *args, **kwargs, &block)
44
+ @fake.send(meth, *args, **kwargs, &block)
46
45
  end
47
- # rubocop:enable Lint/MissingSuper
48
46
 
49
- def respond_to_missing?(meth, *_args)
47
+ def respond_to_missing?(meth, include_private = false)
50
48
  @fake.respond_to?(meth) || super
51
49
  end
52
50
 
53
51
  private
54
52
 
55
53
  def stub_method(meth, &block)
56
- if respond_to?(meth)
54
+ if Object.respond_to?(meth)
57
55
  (class << self; self; end).class_eval do
58
56
  undef_method meth
59
57
  end
@@ -84,6 +82,7 @@ class StrictlyFake
84
82
  "accept (#{format_parametes(expected_parameters)}), but was (#{format_parametes(actual_parameters)})"
85
83
  end
86
84
 
85
+ # rubocop:disable Metrics/MethodLength
87
86
  def format_parametes(parameters)
88
87
  parameters.map do |(type, name)|
89
88
  {
@@ -92,10 +91,12 @@ class StrictlyFake
92
91
  rest: '*rest',
93
92
  key: ":#{name}",
94
93
  keyreq: ":#{name}",
95
- keyrest: '**keyrest'
94
+ keyrest: '**keyrest',
95
+ block: '&block'
96
96
  }.fetch(type)
97
97
  end.join(', ')
98
98
  end
99
+ # rubocop:enable Metrics/MethodLength
99
100
 
100
101
  def method_signatures_match?(expected_parameters, actual_parameters)
101
102
  expected_keyword_parameters, expected_positional_parameters = split_parameters_by_type(expected_parameters)
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative 'lib/strictly_fake/version'
4
4
 
5
+ # rubocop:disable Layout/LineLength
5
6
  Gem::Specification.new do |spec|
6
7
  spec.name = 'strictly_fake'
7
8
  spec.version = StrictlyFake::VERSION
@@ -9,10 +10,10 @@ Gem::Specification.new do |spec|
9
10
  spec.email = ['artemave@gmail.com']
10
11
 
11
12
  spec.summary = 'Stub that automatically verifies that stubbed methods exist and the signatures match the original.'
12
- spec.description = "This is similar to Rspec's Veryfing Double, but standalone. So can be used in Minitest."
13
+ spec.description = spec.summary
13
14
  spec.homepage = 'https://github.com/featurist/strictly_fake'
14
15
  spec.license = 'MIT'
15
- spec.required_ruby_version = Gem::Requirement.new('>= 2.4.0')
16
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.7.0')
16
17
 
17
18
  spec.metadata['homepage_uri'] = spec.homepage
18
19
  spec.metadata['source_code_uri'] = spec.homepage
@@ -26,3 +27,4 @@ Gem::Specification.new do |spec|
26
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
28
  spec.require_paths = ['lib']
28
29
  end
30
+ # rubocop:enable Layout/LineLength
metadata CHANGED
@@ -1,25 +1,25 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: strictly_fake
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - artemave
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-11-24 00:00:00.000000000 Z
11
+ date: 2022-01-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: This is similar to Rspec's Veryfing Double, but standalone. So can be
14
- used in Minitest.
13
+ description: Stub that automatically verifies that stubbed methods exist and the signatures
14
+ match the original.
15
15
  email:
16
16
  - artemave@gmail.com
17
17
  executables: []
18
18
  extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
+ - ".github/workflows/ruby.yml"
21
22
  - ".gitignore"
22
- - ".travis.yml"
23
23
  - Gemfile
24
24
  - Gemfile.lock
25
25
  - LICENSE.txt
@@ -43,14 +43,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
- version: 2.4.0
46
+ version: 2.7.0
47
47
  required_rubygems_version: !ruby/object:Gem::Requirement
48
48
  requirements:
49
49
  - - ">="
50
50
  - !ruby/object:Gem::Version
51
51
  version: '0'
52
52
  requirements: []
53
- rubygems_version: 3.0.3
53
+ rubygems_version: 3.1.6
54
54
  signing_key:
55
55
  specification_version: 4
56
56
  summary: Stub that automatically verifies that stubbed methods exist and the signatures
data/.travis.yml DELETED
@@ -1,10 +0,0 @@
1
- ---
2
- language: ruby
3
- cache: bundler
4
- rvm:
5
- - 2.6.6
6
- before_install: gem install bundler -v 2.1.4
7
- install: bundle
8
- script:
9
- - bundle exec rubocop
10
- - COVERAGE=1 bundle exec rspec