mocoso 1.2.0 → 1.2.1

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: f9f6f53b3e3a29820c1944832ff3de637d468e4e
4
- data.tar.gz: 3fbc9ff9e2c65770153c6936ef7824acf9e89575
3
+ metadata.gz: a9e2aa9efa0e9a7ee708596a4b5a61e2002095a7
4
+ data.tar.gz: 24436b667651fe1c7e46d6760606e0227cad3232
5
5
  SHA512:
6
- metadata.gz: 91c1c78830ff902b84e0f5c27e6f431e9d0dcac1b21634f3b2ab1dfc1156426dd7f84d5109d2c1656a8eb977cf65dd4a5ad3782a4c77da185a647a18540220ae
7
- data.tar.gz: bd5ec6b9bec963f5f73e8bbec7a88f6d8f182cd9e5abaf9dad1a83118246878cfb3a3758929be195002eb9697f6a8e14bc0a469ae18358adb28efe19129bc9fc
6
+ metadata.gz: 44f71138c4743ed1781f769f221233840cbb35752ff060a50240bc2831ad71f7c3ccc412366ec1569a0e024e97d36ad66071234bf320f4e9f6cf9f1df341692f
7
+ data.tar.gz: 1feed015661391e4ebc10bd2a604397ae4d5a02962e1a7d90c4ad8b989543187bd88d9a72bb62838b3c737c33a3f89864d44fd647178447d22ff4bc10216031a
data/.gems ADDED
@@ -0,0 +1 @@
1
+ cutest -v 1.2.1
data/README.md CHANGED
@@ -29,25 +29,25 @@ Usage
29
29
 
30
30
  A quick example (uses [Cutest][cutest]):
31
31
 
32
- require 'cutest'
33
- require 'mocoso'
32
+ require "cutest"
33
+ require "mocoso"
34
34
 
35
35
  include Mocoso
36
36
 
37
- test 'mocking a class method' do
37
+ test "mocking a class method" do
38
38
  user = User.new
39
39
 
40
- expect User, :find, with: [1], return: user do
40
+ expect(User, :find, with: [1], return: user) do
41
41
  assert_equal user, User.find(1)
42
42
  end
43
43
 
44
44
  assert_equal nil, User.find(1)
45
45
  end
46
46
 
47
- test 'stubbing an instance method' do
47
+ test "stubbing an instance method" do
48
48
  user = User.new
49
49
 
50
- stub user, :valid?, true do
50
+ stub(user, :valid?, true) do
51
51
  assert user.valid?
52
52
  end
53
53
 
@@ -55,32 +55,3 @@ A quick example (uses [Cutest][cutest]):
55
55
  end
56
56
 
57
57
  Check [Official Documentation][docs] for more details.
58
-
59
- License
60
- -------
61
-
62
- Copyright (c) 2013 Francesco Rodríguez
63
-
64
- Permission is hereby granted, free of charge, to any person obtaining a copy
65
- of this software and associated documentation files (the "Software"), to deal
66
- in the Software without restriction, including without limitation the rights
67
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
68
- copies of the Software, and to permit persons to whom the Software is
69
- furnished to do so, subject to the following conditions:
70
-
71
- The above copyright notice and this permission notice shall be included in
72
- all copies or substantial portions of the Software.
73
-
74
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
75
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
76
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
77
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
78
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
79
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
80
- THE SOFTWARE.
81
-
82
- [docs]: http://rubydoc.info/github/frodsan/mocoso/
83
- [cutest]: https://github.com/djanowski/cutest/
84
- [override]: https://github.com/soveran/override/
85
- [minitest]: https://github.com/seattlerb/minitest/
86
- [mocha]: https://github.com/freerange/mocha/
@@ -0,0 +1,24 @@
1
+ This is free and unencumbered software released into the public domain.
2
+
3
+ Anyone is free to copy, modify, publish, use, compile, sell, or
4
+ distribute this software, either in source code form or as a compiled
5
+ binary, for any purpose, commercial or non-commercial, and by any
6
+ means.
7
+
8
+ In jurisdictions that recognize copyright laws, the author or authors
9
+ of this software dedicate any and all copyright interest in the
10
+ software to the public domain. We make this dedication for the benefit
11
+ of the public at large and to the detriment of our heirs and
12
+ successors. We intend this dedication to be an overt act of
13
+ relinquishment in perpetuity of all present and future rights to this
14
+ software under copyright law.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ For more information, please refer to <http://unlicense.org/>
@@ -15,25 +15,25 @@
15
15
  #
16
16
  # Quick start:
17
17
  #
18
- # require 'cutest'
19
- # require 'mocoso'
18
+ # require "cutest"
19
+ # require "mocoso"
20
20
  #
21
21
  # include Mocoso
22
22
  #
23
- # test 'mocking a class method' do
23
+ # test "mocking a class method" do
24
24
  # user = User.new
25
25
  #
26
- # expect User, :find, with: [1], return: user do
26
+ # expect(User, :find, with: [1], return: user) do
27
27
  # assert_equal user, User.find(1)
28
28
  # end
29
29
  #
30
30
  # assert_equal nil, User.find(1)
31
31
  # end
32
32
  #
33
- # test 'stubbing an instance method' do
33
+ # test "stubbing an instance method" do
34
34
  # user = User.new
35
35
  #
36
- # stub user, :valid?, true do
36
+ # stub(user, :valid?, true) do
37
37
  # assert user.valid?
38
38
  # end
39
39
  #
@@ -59,32 +59,32 @@ module Mocoso
59
59
  #
60
60
  # signup.valid? # => false
61
61
  #
62
- # Mocoso.stub signup, :valid?, true do
62
+ # Mocoso.stub(signup, :valid?, true) do
63
63
  # signup.valid? # => true
64
64
  # end
65
65
  #
66
66
  # You can pass a callable object (responds to +call+) as a value:
67
67
  #
68
- # Mocoso.stub subject, :foo, -> { 'foo' } do
68
+ # Mocoso.stub(subject, :foo, -> { "foo" }) do
69
69
  # subject.foo # => "foo"
70
70
  # end
71
71
  #
72
- # Mocoso.stub subject, :bar, ->(value) { value } do
73
- # subject.bar('foo') # => "foo"
72
+ # Mocoso.stub(subject, :bar, ->(value) { value }) do
73
+ # subject.bar("foo") # => "foo"
74
74
  # end
75
75
  #
76
- def stub object, method, result
76
+ def stub(object, method, result)
77
77
  metaclass = object.singleton_class
78
- original = object.method method
78
+ original = object.method(method)
79
79
 
80
- metaclass.send :define_method, method do |*args|
80
+ metaclass.send(:define_method, method) do |*args|
81
81
  result.respond_to?(:call) ? result.(*args) : result
82
82
  end
83
83
 
84
84
  yield
85
85
  ensure
86
- metaclass.send :undef_method, method
87
- metaclass.send :define_method, method, original
86
+ metaclass.send(:undef_method, method)
87
+ metaclass.send(:define_method, method, original)
88
88
  end
89
89
 
90
90
  # Expects that method +method+ is called with the arguments specified in the
@@ -98,30 +98,30 @@ module Mocoso
98
98
  #
99
99
  # user = User[1]
100
100
  #
101
- # Mocoso.expect user, :update, with: [{ name: 'new name' }], return: true do
102
- # subject.update unexpected: nil
101
+ # Mocoso.expect(user, :update, with: [{ name: "new name" }], return: true) do
102
+ # subject.update(unexpected: nil)
103
103
  # # => Mocoso::ExpectationError: Expected [{:name=>"new name"}], got [{:unexpected=>nil}]
104
104
  #
105
- # user.update name: 'new name'
105
+ # user.update(name: "new name")
106
106
  # # => true
107
107
  # end
108
108
  #
109
- def expect object, method, options
110
- expectation = -> *params {
111
- with = options.fetch :with, []
109
+ def expect(object, method, options)
110
+ expectation = ->(*params) {
111
+ with = options.fetch(:with, [])
112
112
  raise ExpectationError, "Expected #{with}, got #{params}" if params != with
113
- options.fetch :return
113
+ options.fetch(:return)
114
114
  }
115
115
 
116
- stub object, method, expectation, &proc
116
+ stub(object, method, expectation, &proc)
117
117
  end
118
118
 
119
119
  # Raised by #expect when a expectation is not fulfilled.
120
120
  #
121
- # Mocoso.expect object, :method, with: 'argument', return: nil do
122
- # object.method 'unexpected argument'
121
+ # Mocoso.expect(object, :method, with: "argument", return: nil) do
122
+ # object.method("unexpected argument")
123
123
  # # => Mocoso::ExpectationError: Expected ["argument"], got ["unexpected argument"]
124
124
  # end
125
125
  #
126
- ExpectationError = Class.new StandardError
126
+ ExpectationError = Class.new(StandardError)
127
127
  end
@@ -1,22 +1,14 @@
1
- # encoding: utf-8
2
-
3
1
  Gem::Specification.new do |s|
4
- s.name = 'mocoso'
5
- s.version = '1.2.0'
6
- s.summary = 'A simple stub & mock library'
2
+ s.name = "mocoso"
3
+ s.version = "1.2.1"
4
+ s.summary = "A simple stub & mock library."
7
5
  s.description = s.summary
8
- s.authors = ['Francesco Rodríguez']
9
- s.email = ['lrodriguezsanc@gmail.com']
10
- s.homepage = 'https://github.com/frodsan/mocoso'
11
- s.license = 'MIT'
6
+ s.authors = ["Francesco Rodríguez"]
7
+ s.email = ["lrodriguezsanc@gmail.com"]
8
+ s.homepage = "https://github.com/frodsan/mocoso"
9
+ s.license = "Unlicense"
12
10
 
13
- s.files = Dir[
14
- 'LICENSE',
15
- 'README.md',
16
- 'lib/**/*.rb',
17
- '*.gemspec',
18
- 'test/*.*'
19
- ]
11
+ s.files = `git ls-files`.split("\n")
20
12
 
21
- s.add_development_dependency 'cutest'
13
+ s.add_development_dependency "cutest"
22
14
  end
@@ -1,13 +1,13 @@
1
- require 'cutest'
2
- require_relative '../lib/mocoso'
1
+ require "cutest"
2
+ require_relative "../lib/mocoso"
3
3
 
4
4
  class Subject
5
- def foo; 'foo'; end
6
- def bar; 'bar'; end
5
+ def foo; "foo"; end
6
+ def bar; "bar"; end
7
7
  def baz(value); value; end
8
8
 
9
9
  def self.foo
10
- 'foo'
10
+ "foo"
11
11
  end
12
12
  end
13
13
 
@@ -17,66 +17,66 @@ setup do
17
17
  Subject.new
18
18
  end
19
19
 
20
- test 'raises error if block is not given' do |subject|
21
- assert_raise { stub(subject, :foo, 'foo') }
20
+ test "raises error if block is not given" do |subject|
21
+ assert_raise { stub(subject, :foo, "foo") }
22
22
  end
23
23
 
24
- test 'raises error if object not respond to the given method' do |subject|
24
+ test "raises error if object not respond to the given method" do |subject|
25
25
  assert_raise(NameError) { stub(subject, :nan, nil) }
26
26
  end
27
27
 
28
- test 'stubbed method return new value' do |subject|
28
+ test "stubbed method return new value" do |subject|
29
29
  before = subject.foo
30
30
 
31
- stub subject, :foo, 'new foo' do
32
- assert_equal 'new foo', subject.foo
31
+ stub(subject, :foo, "new foo") do
32
+ assert_equal "new foo", subject.foo
33
33
  end
34
34
 
35
35
  assert_equal before, subject.foo
36
36
  end
37
37
 
38
- test 'stubs method with a callable object' do |subject|
38
+ test "stubs method with a callable object" do |subject|
39
39
  before = subject.foo
40
40
 
41
- stub subject, :foo, -> { 'new foo' } do
42
- assert_equal 'new foo', subject.foo
41
+ stub(subject, :foo, -> { "new foo" }) do
42
+ assert_equal "new foo", subject.foo
43
43
  end
44
44
 
45
45
  assert_equal before, subject.foo
46
46
  end
47
47
 
48
- test 'stubs method with a callable object that requires arguments' do |subject|
48
+ test "stubs method with a callable object that requires arguments" do |subject|
49
49
  before = subject.foo
50
50
 
51
- stub subject, :foo, ->(a) { "new #{a}" } do
52
- assert_equal 'new foo', subject.foo('foo')
51
+ stub(subject, :foo, ->(a) { "new #{a}" }) do
52
+ assert_equal "new foo", subject.foo("foo")
53
53
  end
54
54
 
55
55
  assert_equal before, subject.foo
56
56
  end
57
57
 
58
- test 'succeeds if expectations are met' do |subject|
59
- expect subject, :baz, with: ['value'], return: 'result' do
60
- assert_equal 'result', subject.baz('value')
58
+ test "succeeds if expectations are met" do |subject|
59
+ expect(subject, :baz, with: ["value"], return: "result") do
60
+ assert_equal "result", subject.baz("value")
61
61
  end
62
62
 
63
- assert_equal 'baz', subject.baz('baz')
63
+ assert_equal "baz", subject.baz("baz")
64
64
  end
65
65
 
66
- test 'raises an error if expectation are not met' do |subject|
67
- expect subject, :baz, with: ['value'], return: 'result' do
68
- assert_raise(Mocoso::ExpectationError) { subject.baz('another') }
66
+ test "raises an error if expectation are not met" do |subject|
67
+ expect(subject, :baz, with: ["value"], return: "result") do
68
+ assert_raise(Mocoso::ExpectationError) { subject.baz("another") }
69
69
  end
70
70
  end
71
71
 
72
- test 'expectation without with option defaults to empty array' do |subject|
73
- expect subject, :foo, return: 'new foo' do
74
- assert_equal 'new foo', subject.foo
72
+ test "expectation without with option defaults to empty array" do |subject|
73
+ expect(subject, :foo, return: "new foo") do
74
+ assert_equal "new foo", subject.foo
75
75
  end
76
76
  end
77
77
 
78
- test 'expectation with multiple arguments' do |subject|
79
- expect subject, :foo, with: ['new foo', { optional: true }], return: 'new foo' do
80
- assert_equal 'new foo', subject.foo('new foo', optional: true)
78
+ test "expectation with multiple arguments" do |subject|
79
+ expect(subject, :foo, with: ["new foo", { optional: true }], return: "new foo") do
80
+ assert_equal "new foo", subject.foo("new foo", optional: true)
81
81
  end
82
82
  end
metadata CHANGED
@@ -1,44 +1,45 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mocoso
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
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: 2013-11-01 00:00:00.000000000 Z
11
+ date: 2014-01-18 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
19
  version: '0'
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
26
  version: '0'
27
- description: A simple stub & mock library
27
+ description: A simple stub & mock library.
28
28
  email:
29
29
  - lrodriguezsanc@gmail.com
30
30
  executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
- - LICENSE
34
+ - ".gems"
35
35
  - README.md
36
+ - UNLICENSE
36
37
  - lib/mocoso.rb
37
38
  - mocoso.gemspec
38
39
  - test/scary_mocks_and_nice_stubs.rb
39
40
  homepage: https://github.com/frodsan/mocoso
40
41
  licenses:
41
- - MIT
42
+ - Unlicense
42
43
  metadata: {}
43
44
  post_install_message:
44
45
  rdoc_options: []
@@ -46,18 +47,18 @@ require_paths:
46
47
  - lib
47
48
  required_ruby_version: !ruby/object:Gem::Requirement
48
49
  requirements:
49
- - - '>='
50
+ - - ">="
50
51
  - !ruby/object:Gem::Version
51
52
  version: '0'
52
53
  required_rubygems_version: !ruby/object:Gem::Requirement
53
54
  requirements:
54
- - - '>='
55
+ - - ">="
55
56
  - !ruby/object:Gem::Version
56
57
  version: '0'
57
58
  requirements: []
58
59
  rubyforge_project:
59
- rubygems_version: 2.0.3
60
+ rubygems_version: 2.2.0
60
61
  signing_key:
61
62
  specification_version: 4
62
- summary: A simple stub & mock library
63
+ summary: A simple stub & mock library.
63
64
  test_files: []
data/LICENSE DELETED
@@ -1,19 +0,0 @@
1
- Copyright (c) 2013 Francesco Rodríguez
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy
4
- of this software and associated documentation files (the "Software"), to deal
5
- in the Software without restriction, including without limitation the rights
6
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- copies of the Software, and to permit persons to whom the Software is
8
- furnished to do so, subject to the following conditions:
9
-
10
- The above copyright notice and this permission notice shall be included in
11
- all copies or substantial portions of the Software.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- THE SOFTWARE.