mocoso 1.2.2 → 1.2.3

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
  SHA1:
3
- metadata.gz: 84fde22389db6d310917952800c3a3464ced1fb5
4
- data.tar.gz: 408db6f0dafa0234cd1e627816dc85e804e39ba3
3
+ metadata.gz: 4ce992af24ab54bbc81b79a79d7dbdf724100e4b
4
+ data.tar.gz: b227a941453ebab128714128ce3890d75e866d99
5
5
  SHA512:
6
- metadata.gz: 822cc257ce2fee101df1202af9a172a499d646fd71585fa210dae2daf44904f42ab2bafdbba0a9faf23db01186da3b638a44b2e98fe19bac5708b866de92a34b
7
- data.tar.gz: 312f6a5d353fd08fe169551ec6586a0e8b12fe231108b710d1a432e75bf335e3f36bdae52f9ad4d997983a4f9a6f3de727bee3681a73b1e7dc2be7df9fa0284d
6
+ metadata.gz: 6534712d4d2499d1fcf5ea3a2edafac02c0349402b7e1570f9cdc8bfcce4fb25187d3f5176253de2a5fa8439c8ff13206dc40784f3160e9e36f871a804e65b6e
7
+ data.tar.gz: 232c690c99d95153e499298299de93fe9adef13a6652e005820dff63316ffe04793483a93a60b89db47c04893ea48503c102c65fb7cc491a1e16de0e0ef9c990
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014-2015 Francesco Rodríguez
1
+ Copyright (c) 2014-2016 Francesco Rodríguez
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- Mocoso
1
+ Mocoso [![Build Status](https://travis-ci.org/frodsan/mocoso.svg)](https://travis-ci.org/frodsan/mocoso)
2
2
  ======
3
3
 
4
4
  Yet Another Simple Stub & Mock library. This is inspired by
@@ -15,6 +15,27 @@ Mocoso meets the following criteria:
15
15
  * Doesn't monkey-patch any class or object.
16
16
  * Test-framework agnostic. No integration code.
17
17
 
18
+ Installation
19
+ ------------
20
+
21
+ Add this line to your application's Gemfile:
22
+
23
+ ```ruby
24
+ gem "mocoso"
25
+ ```
26
+
27
+ And then execute:
28
+
29
+ ```
30
+ $ bundle
31
+ ```
32
+
33
+ Or install it yourself as:
34
+
35
+ ```
36
+ $ gem install mocoso
37
+ ```
38
+
18
39
  Usage
19
40
  -----
20
41
 
@@ -49,14 +70,37 @@ end
49
70
 
50
71
  Check [Official Documentation][docs] for more details.
51
72
 
52
- Installation
73
+ Contributing
53
74
  ------------
54
75
 
55
- ```bash
56
- $ gem install mocoso
76
+ Fork the project with:
77
+
78
+ ```
79
+ $ git clone git@github.com:frodsan/mocoso.git
80
+ ```
81
+
82
+ To install dependencies, use:
83
+
84
+ ```
85
+ $ bundle install
86
+ ```
87
+
88
+ To run the test suite, do:
89
+
57
90
  ```
91
+ $ rake test
92
+ ```
93
+
94
+ For bug reports and pull requests use [GitHub][issues].
95
+
96
+ License
97
+ -------
98
+
99
+ Mocoso is released under the [MIT License][mit].
58
100
 
59
101
  [docs]: http://rubydoc.info/github/harmoni/mocoso/
60
102
  [cutest]: https://github.com/djanowski/cutest/
61
- [override]: https://github.com/soveran/override/
103
+ [issues]: https://github.com/frodsan/mocoso/issues
62
104
  [minitest]: https://github.com/seattlerb/minitest/
105
+ [mit]: http://www.opensource.org/licenses/MIT
106
+ [override]: https://github.com/soveran/override/
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Yet Another Simple Stub & Mock library, that also:
2
4
  #
3
5
  # - Always restore stubbed methods to their original implementations.
@@ -42,7 +44,7 @@
42
44
  #
43
45
  # Note: this example uses the test framework Cutest[1]:
44
46
  #
45
- # Mocoso is inspired by (stolen from) Override[2], Minitest::Mock[3] and Mocha[4].
47
+ # Mocoso is inspired by Override[2], Minitest::Mock[3] and Mocha[4].
46
48
  #
47
49
  # * [1]: https://github.com/djanowski/cutest/
48
50
  # * [2]: https://github.com/soveran/override/
@@ -77,8 +79,9 @@ module Mocoso
77
79
  metaclass = object.singleton_class
78
80
  original = object.method(method)
79
81
 
82
+ metaclass.send(:undef_method, method)
80
83
  metaclass.send(:define_method, method) do |*args|
81
- result.respond_to?(:call) ? result.(*args) : result
84
+ result.respond_to?(:call) ? result.call(*args) : result
82
85
  end
83
86
 
84
87
  yield
@@ -98,20 +101,25 @@ module Mocoso
98
101
  #
99
102
  # user = User[1]
100
103
  #
101
- # Mocoso.expect(user, :update, with: [{ name: "new name" }], return: true) do
102
- # subject.update(unexpected: nil)
103
- # # => Mocoso::ExpectationError: Expected [{:name=>"new name"}], got [{:unexpected=>nil}]
104
+ # Mocoso.expect(user, :update, with: [:age, 18], return: true) do
105
+ # user.update(:name, "new name")
106
+ # # => Mocoso::ExpectationError:
107
+ # # Expected [:age, 18], got [:name, "new name"]
104
108
  #
105
- # user.update(name: "new name")
109
+ # user.update(:age, 18)
106
110
  # # => true
107
111
  # end
108
112
  #
109
113
  def expect(object, method, options, &block)
110
- expectation = ->(*params) {
114
+ expectation = ->(*params) do
111
115
  with = options.fetch(:with, [])
112
- raise ExpectationError, "Expected #{with}, got #{params}" if params != with
116
+
117
+ if params != with
118
+ raise ExpectationError, "Expected #{ with }, got #{ params }"
119
+ end
120
+
113
121
  options.fetch(:return)
114
- }
122
+ end
115
123
 
116
124
  stub(object, method, expectation, &block)
117
125
  end
@@ -120,7 +128,8 @@ module Mocoso
120
128
  #
121
129
  # Mocoso.expect(object, :method, with: "argument", return: nil) do
122
130
  # object.method("unexpected argument")
123
- # # => Mocoso::ExpectationError: Expected ["argument"], got ["unexpected argument"]
131
+ # # => Mocoso::ExpectationError:
132
+ # # Expected ["argument"], got ["unexpected argument"]
124
133
  # end
125
134
  #
126
135
  ExpectationError = Class.new(StandardError)
@@ -1,10 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/setup"
1
4
  require "cutest"
2
5
  require_relative "../lib/mocoso"
3
6
 
4
7
  class Subject
5
- def foo; "foo"; end
6
- def bar; "bar"; end
7
- def baz(value); value; end
8
+ def foo
9
+ "foo"
10
+ end
11
+
12
+ def bar
13
+ "bar"
14
+ end
15
+
16
+ def baz(value)
17
+ value
18
+ end
8
19
 
9
20
  def self.foo
10
21
  "foo"
@@ -58,7 +69,7 @@ end
58
69
  test "stubs method with a callable object that requires arguments" do |subject|
59
70
  before = subject.foo
60
71
 
61
- stub(subject, :foo, ->(a) { "new #{a}" }) do
72
+ stub(subject, :foo, ->(a) { "new #{ a }" }) do
62
73
  assert_equal "new foo", subject.foo("foo")
63
74
  end
64
75
 
@@ -86,7 +97,12 @@ test "expectation without with option defaults to empty array" do |subject|
86
97
  end
87
98
 
88
99
  test "expectation with multiple arguments" do |subject|
89
- expect(subject, :foo, with: ["new foo", { optional: true }], return: "new foo") do
100
+ expect(
101
+ subject,
102
+ :foo,
103
+ with: ["new foo", { optional: true }],
104
+ return: "new foo"
105
+ ) do
90
106
  assert_equal "new foo", subject.foo("new foo", optional: true)
91
107
  end
92
108
  end
metadata CHANGED
@@ -1,44 +1,68 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mocoso
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francesco Rodríguez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-26 00:00:00.000000000 Z
11
+ date: 2016-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cutest
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '='
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.2.2
19
+ version: '1.2'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '='
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.2.2
26
+ version: '1.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '11.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '11.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.39'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.39'
27
55
  description: A simple stub & mock library.
28
- email:
29
- - frodsan@protonmail.ch
56
+ email: hello@frodsan.com
30
57
  executables: []
31
58
  extensions: []
32
59
  extra_rdoc_files: []
33
60
  files:
34
- - ".gems"
35
61
  - LICENSE
36
62
  - README.md
37
63
  - lib/mocoso.rb
38
- - makefile
39
- - mocoso.gemspec
40
64
  - test/scary_mocks_and_nice_stubs.rb
41
- homepage: https://github.com/harmoni/mocoso
65
+ homepage: https://github.com/frodsan/mocoso
42
66
  licenses:
43
67
  - MIT
44
68
  metadata: {}
@@ -58,8 +82,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
82
  version: '0'
59
83
  requirements: []
60
84
  rubyforge_project:
61
- rubygems_version: 2.4.8
85
+ rubygems_version: 2.5.1
62
86
  signing_key:
63
87
  specification_version: 4
64
88
  summary: A simple stub & mock library.
65
- test_files: []
89
+ test_files:
90
+ - test/scary_mocks_and_nice_stubs.rb
data/.gems DELETED
@@ -1 +0,0 @@
1
- cutest -v 1.2.2
data/makefile DELETED
@@ -1,2 +0,0 @@
1
- default:
2
- cutest test/*.rb
@@ -1,14 +0,0 @@
1
- Gem::Specification.new do |s|
2
- s.name = "mocoso"
3
- s.version = "1.2.2"
4
- s.summary = "A simple stub & mock library."
5
- s.description = s.summary
6
- s.authors = ["Francesco Rodríguez"]
7
- s.email = ["frodsan@protonmail.ch"]
8
- s.homepage = "https://github.com/harmoni/mocoso"
9
- s.license = "MIT"
10
-
11
- s.files = `git ls-files`.split("\n")
12
-
13
- s.add_development_dependency "cutest", "1.2.2"
14
- end