minitest-stub_on_roids 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c0b8760d30284aeb26f44e7771f8b32db37a78d00ea8d04af20f90cbf6c8b439
4
+ data.tar.gz: c6c64beec89ab4d501d073ab34f4f865c5ecaa9519c5370d660d2ef07f8c0de8
5
+ SHA512:
6
+ metadata.gz: 4d0bbc8b817dd275724080971a3a457e9f4eadae6dfc97dabd3b8fbadfd8b264156bd0d5897c3e4764653b633b5af29fe222b08f360476501298165d58787196
7
+ data.tar.gz: d565173266a7c2731ea36a0d02c2a1a93da885996ec4a5a57003d6cb345ecc57b1c810289e4fc3a25c2fb68486e4166b59e2774ab7d2a49ab8f4fe2cfee6df62
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,17 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ minitest-stub_on_roids (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+
10
+ PLATFORMS
11
+ ruby
12
+
13
+ DEPENDENCIES
14
+ minitest-stub_on_roids!
15
+
16
+ BUNDLED WITH
17
+ 2.0.1
data/README.md ADDED
@@ -0,0 +1 @@
1
+ # minitest-stub_on_roids
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.test_files = FileList['test/minitest/test*.rb']
5
+ end
6
+
7
+ desc "Run tests"
8
+ task :default => :test
@@ -0,0 +1,41 @@
1
+ require "minitest/autorun"
2
+
3
+ class StubbedMethodArgsError < StandardError; end
4
+ class MethodAlreadyStubbedError < StandardError; end
5
+
6
+ module Minitest
7
+ module StubOnRoids
8
+ def stub_with_args(name, val_or_callable, expected_args, &block)
9
+ raise MethodAlreadyStubbedError, "Method :#{name} already stubbed" if self.respond_to? "__minitest_stub__#{name}"
10
+
11
+ asserted_callable = lambda do |*actual_args|
12
+ expected_args.zip(actual_args).each do |expected_arg, actual_arg|
13
+ next if expected_arg == actual_arg
14
+ raise StubbedMethodArgsError, "stubbed method :#{name} called on #{self} with unexpected arguments #{actual_args}"
15
+ end
16
+
17
+ val_or_callable
18
+ end
19
+
20
+ stub(name, asserted_callable) do
21
+ yield
22
+ end
23
+ end
24
+
25
+ def stub_and_expect(name, val_or_callable = nil, expected_args = [], times: 1)
26
+ raise MethodAlreadyStubbedError, "Method :#{name} already stubbed" if self.respond_to? "__minitest_stub__#{name}"
27
+
28
+ mock = Minitest::Mock.new
29
+ times.times { mock.expect :call, val_or_callable, expected_args }
30
+
31
+ stub(name, mock) do
32
+ yield
33
+ end
34
+
35
+ mock.verify
36
+ rescue StandardError => e
37
+ # Monkeypatching the error message for better readability
38
+ raise e.class, e.message.gsub(":call", ":#{name}")
39
+ end
40
+ end
41
+ end
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: minitest-stub_on_roids
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Simon Nizov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-08-05 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: ''
14
+ email: simon.nizov@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - Gemfile
20
+ - Gemfile.lock
21
+ - README.md
22
+ - Rakefile
23
+ - lib/minitest/stub_on_roids.rb
24
+ homepage: https://rubygems.org/gems/minitest-stub_on_roids
25
+ licenses:
26
+ - MIT
27
+ metadata: {}
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubygems_version: 3.0.3
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: 'Minitest''s #stub but with arguments assertion and expectation'
47
+ test_files: []