grasshopper 0.4.5 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ca14809dc6ae3ea56989eec5d085f4f7f859ab66
4
+ data.tar.gz: 43b93e283310ad88a9f736cf1c7513711914100f
5
+ SHA512:
6
+ metadata.gz: 769db71c56192c654fc4df2e837275c8ba38e3c43171a43107a7dd3fd2336d93ba199061192a4c8cdcc67f33c89386ce2374bdd76c64b7a4cb94ef821e2ec89d
7
+ data.tar.gz: 0df196f3b8f1e1cc68606ce0801fa44fbcf27627b8c483f501843e3b6e412884e1776f0529cba5aa507d99512818cfd3f11f6cea798794bb87531d7593af0888
data/README.md CHANGED
@@ -11,11 +11,11 @@ For more examples, see the [unit tests](https://github.com/mattraibert/grasshopp
11
11
  Mock is a person who listens carefully but never says anything. You can say anything to Mock, but you'll only get crickets back.
12
12
 
13
13
  ```ruby
14
- mock = Mock.new
14
+ mock = Grasshopper::Mock.new
15
15
  mock.hello #=> nil
16
16
  mock.how_are_you? #=> nil
17
- Mock.verify(mock).hello # yes, someone did tell me hello.
18
- Mock.verify(mock).goodbye # wait(AssertionFailed)! they left without saying goodbye!
17
+ Grasshopper::Mock.verify(mock).hello # yes, someone did tell me hello.
18
+ Grasshopper::Mock.verify(mock).goodbye # wait(AssertionFailed)! they left without saying goodbye!
19
19
  ```
20
20
 
21
21
  ### Stub
@@ -23,9 +23,9 @@ Mock.verify(mock).goodbye # wait(AssertionFailed)! they left without saying g
23
23
  Stub is a person who holds something for you and gives it to anyone who knows how to ask. You can ask Stub for anything, but you'll only get out what you put into it.
24
24
 
25
25
  ```ruby
26
- stub = Stub.new
27
- Stub.when(stub.keys).then_return([:door_key, :mail_key])
28
- Stub.when(stub.money("gimmie")).then_return(5)
26
+ stub = Grasshopper::Stub.new
27
+ Grasshopper::Stub.when(stub.keys).then_return([:door_key, :mail_key])
28
+ Grasshopper::Stub.when(stub.money("gimmie")).then_return(5)
29
29
  stub.keys #=> [:door_key, :mail_key]
30
30
  stub.money("gimmie") #=> 5
31
31
  stub.monkey #=> nil
@@ -34,7 +34,7 @@ stub.monkey #=> nil
34
34
  or you can use this shorter style if you prefer:
35
35
 
36
36
  ```ruby
37
- Stub.like(:keys => [:door_key, :mail_key], :money => 5)
37
+ Grasshopper::Stub.like(:keys => [:door_key, :mail_key], :money => 5)
38
38
  stub.keys #=> [:door_key, :mail_key]
39
39
  stub.money("gimmie") #=> 5
40
40
  stub.monkey #=> nil
@@ -46,5 +46,10 @@ Grasshopper is named for a [restaurant](http://grasshoppervegan.com/) in Allston
46
46
 
47
47
  ## Copyright
48
48
 
49
- Copyright (c) 2011-2012 Matt Raibert.
50
- Grasshopper is available under the GPL v3 see LICENSE.txt for further details.
49
+ Copyright 2011-2017 Position Development, LLC.
50
+
51
+ Grasshopper is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
52
+
53
+ Grasshopper is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
54
+
55
+ You should have received a copy of the GNU Lesser General Public License along with Grasshopper. If not, see http://www.gnu.org/licenses/.
@@ -1,26 +1,30 @@
1
- require 'minitest/unit'
2
-
3
- class Mock
4
- include MiniTest::Assertions
1
+ module Grasshopper
2
+ class Mock
3
+ def initialize
4
+ @verify_next = false
5
+ end
5
6
 
6
- def verify_next
7
- @verify_next = true
8
- end
7
+ def verify_next
8
+ @verify_next = true
9
+ end
9
10
 
10
- def method_missing(message, *args, &block)
11
- @messages ||= []
12
- if @verify_next
13
- index = @messages.index { |item| message == item[0] and item[1] == args }
14
- assert(index, "Should have seen an invocation of #{message}(#{args.join(", ")})\n#{@messages.inspect}")
15
- @messages.delete_at(index || @messages.length)
16
- else
17
- @messages << [message, args]
11
+ def method_missing(message, *args, &block)
12
+ @messages ||= []
13
+ if @verify_next
14
+ index = @messages.index { |item| message == item[0] and item[1] == args }
15
+ unless index
16
+ raise "Should have seen an invocation of #{message}(#{args.join(", ")})\n#{@messages.inspect}"
17
+ end
18
+ @messages.delete_at(index || @messages.length)
19
+ else
20
+ @messages << [message, args]
21
+ end
22
+ nil
18
23
  end
19
- nil
20
- end
21
24
 
22
- def self.verify mock
23
- mock.verify_next
24
- mock
25
+ def self.verify mock
26
+ mock.verify_next
27
+ mock
28
+ end
25
29
  end
26
30
  end
@@ -1,38 +1,40 @@
1
- class Stub
2
- def initialize
3
- @stubs = {}
4
- end
1
+ module Grasshopper
2
+ class Stub
3
+ def initialize
4
+ @stubs = {}
5
+ end
5
6
 
6
- def add_a_stub(message, retval)
7
- @stubs[message] = retval
8
- end
7
+ def add_a_stub(message, retval)
8
+ @stubs[message] = retval
9
+ end
9
10
 
10
- def self.when(whatever)
11
- StubHelper.new(@@stub, @@message)
12
- end
11
+ def self.when(whatever)
12
+ StubHelper.new(@@stub, @@message)
13
+ end
13
14
 
14
- def method_missing(sym, *args)
15
- @@stub = self
16
- @@message = [sym, args]
17
- @stubs[[sym, args]]
18
- end
15
+ def method_missing(sym, *args)
16
+ @@stub = self
17
+ @@message = [sym, args]
18
+ @stubs[[sym, args]]
19
+ end
19
20
 
20
- def self.like(stubs)
21
- stub = Stub.new
22
- stubs.each do |method, retval|
23
- Stub.when(stub.send(method)).then_return(retval)
21
+ def self.like(stubs)
22
+ stub = Stub.new
23
+ stubs.each do |method, retval|
24
+ Stub.when(stub.send(method)).then_return(retval)
25
+ end
26
+ stub
24
27
  end
25
- stub
26
28
  end
27
- end
28
29
 
29
- class StubHelper
30
- def initialize(stub, message)
31
- @stub = stub
32
- @message = message
33
- end
30
+ class StubHelper
31
+ def initialize(stub, message)
32
+ @stub = stub
33
+ @message = message
34
+ end
34
35
 
35
- def then_return(retval)
36
- @stub.add_a_stub(@message, retval)
36
+ def then_return(retval)
37
+ @stub.add_a_stub(@message, retval)
38
+ end
37
39
  end
38
40
  end
@@ -1,68 +1,68 @@
1
1
  require 'test_helper'
2
2
  require 'grasshopper/mock'
3
3
 
4
- class MockTest < MiniTest::Unit::TestCase
4
+ class MockTest < MiniTest::Test
5
5
  def test_fails_verify_if_no_such_message
6
- mock = Mock.new
6
+ mock = Grasshopper::Mock.new
7
7
 
8
- assert_raises MiniTest::Assertion do
9
- Mock.verify(mock).never_sent
8
+ assert_raises RuntimeError do
9
+ Grasshopper::Mock.verify(mock).never_sent
10
10
  end
11
11
  end
12
12
 
13
13
  def test_no_failure_if_message_was_sent
14
- mock = Mock.new
14
+ mock = Grasshopper::Mock.new
15
15
  mock.message_was_sent
16
- Mock.verify(mock).message_was_sent
16
+ Grasshopper::Mock.verify(mock).message_was_sent
17
17
  end
18
18
 
19
19
  def test_can_verify_number_of_invocations
20
- mock = Mock.new
20
+ mock = Grasshopper::Mock.new
21
21
  2.times { mock.message_sent_twice }
22
- 2.times { Mock.verify(mock).message_sent_twice }
22
+ 2.times { Grasshopper::Mock.verify(mock).message_sent_twice }
23
23
  end
24
24
 
25
25
  def test_fails_if_too_few_invocations
26
- mock = Mock.new
26
+ mock = Grasshopper::Mock.new
27
27
  mock.message_sent_once
28
28
 
29
- assert_raises MiniTest::Assertion do
30
- 2.times { Mock.verify(mock).message_sent_once }
29
+ assert_raises RuntimeError do
30
+ 2.times { Grasshopper::Mock.verify(mock).message_sent_once }
31
31
  end
32
32
  end
33
33
 
34
34
  def test_validate_param
35
- mock = Mock.new
35
+ mock = Grasshopper::Mock.new
36
36
  mock.message_with_param("to verify")
37
- Mock.verify(mock).message_with_param("to verify")
37
+ Grasshopper::Mock.verify(mock).message_with_param("to verify")
38
38
  end
39
39
 
40
40
  def test_validate_two_params
41
- mock = Mock.new
41
+ mock = Grasshopper::Mock.new
42
42
  mock.message_with_params("to", "verify")
43
- Mock.verify(mock).message_with_params("to", "verify")
43
+ Grasshopper::Mock.verify(mock).message_with_params("to", "verify")
44
44
  end
45
45
 
46
46
  def test_validate_wrong_param_explodes
47
- mock = Mock.new
47
+ mock = Grasshopper::Mock.new
48
48
  mock.message_with_param("param")
49
49
 
50
- assert_raises MiniTest::Assertion do
51
- Mock.verify(mock).message_with_param("wrong param")
50
+ assert_raises RuntimeError do
51
+ Grasshopper::Mock.verify(mock).message_with_param("wrong param")
52
52
  end
53
53
  end
54
54
 
55
55
  def test_validate_wrong_number_params_explodes
56
- mock = Mock.new
56
+ mock = Grasshopper::Mock.new
57
57
  mock.message_with_param("param", "two")
58
58
 
59
- assert_raises MiniTest::Assertion do
60
- Mock.verify(mock).message_with_param("param")
59
+ assert_raises RuntimeError do
60
+ Grasshopper::Mock.verify(mock).message_with_param("param")
61
61
  end
62
62
  end
63
63
 
64
64
  def test_always_returns_nil
65
- mock = Mock.new
65
+ mock = Grasshopper::Mock.new
66
66
  assert_nil mock.anything
67
67
  assert_nil mock.anything("even with params")
68
68
  assert_nil mock.anything(["even with array params"])
@@ -1,41 +1,41 @@
1
1
  require 'test_helper'
2
2
  require 'grasshopper/stub'
3
3
 
4
- class StubTest < MiniTest::Unit::TestCase
4
+ class StubTest < MiniTest::Test
5
5
  def test_stub_returns_nil
6
- assert_nil(Stub.new.unknown_method)
6
+ assert_nil(Grasshopper::Stub.new.unknown_method)
7
7
  end
8
8
 
9
9
  def test_can_stub_a_method
10
- stub = Stub.new
11
- Stub.when(stub.this_message).then_return(9)
10
+ stub = Grasshopper::Stub.new
11
+ Grasshopper::Stub.when(stub.this_message).then_return(9)
12
12
  assert_equal(9, stub.this_message)
13
13
  end
14
14
 
15
15
  def test_two_stubs
16
- stub1 = Stub.new
17
- stub2 = Stub.new
18
- Stub.when(stub1.this_message).then_return(9)
19
- Stub.when(stub2.that_message).then_return(99)
16
+ stub1 = Grasshopper::Stub.new
17
+ stub2 = Grasshopper::Stub.new
18
+ Grasshopper::Stub.when(stub1.this_message).then_return(9)
19
+ Grasshopper::Stub.when(stub2.that_message).then_return(99)
20
20
 
21
- assert_equal(nil, stub1.that_message)
21
+ assert_nil(stub1.that_message)
22
22
  assert_equal(9, stub1.this_message)
23
- assert_equal(nil, stub2.this_message)
23
+ assert_nil(stub2.this_message)
24
24
  assert_equal(99, stub2.that_message)
25
25
  end
26
26
 
27
27
  def test_can_stub_a_method_with_param
28
- stub = Stub.new
29
- Stub.when(stub.secret(22)).then_return(9)
28
+ stub = Grasshopper::Stub.new
29
+ Grasshopper::Stub.when(stub.secret(22)).then_return(9)
30
30
 
31
- assert_equal(nil, stub.secret(21))
31
+ assert_nil(stub.secret(21))
32
32
  assert_equal(9, stub.secret(22))
33
33
  end
34
34
 
35
35
  def test_can_stub_two_methods_with_param
36
- stub = Stub.new
37
- Stub.when(stub.keys).then_return([:door_key, :mail_key])
38
- Stub.when(stub.money("gimmie")).then_return(5)
36
+ stub = Grasshopper::Stub.new
37
+ Grasshopper::Stub.when(stub.keys).then_return([:door_key, :mail_key])
38
+ Grasshopper::Stub.when(stub.money("gimmie")).then_return(5)
39
39
 
40
40
  assert_equal([:door_key, :mail_key], stub.keys)
41
41
  assert_equal(5, stub.money("gimmie"))
@@ -43,18 +43,18 @@ class StubTest < MiniTest::Unit::TestCase
43
43
  end
44
44
 
45
45
  def test_another_call_doesnt_confuse
46
- stub = Stub.new
46
+ stub = Grasshopper::Stub.new
47
47
  stub.bang
48
- Stub.when(stub.bop).then_return("pow")
48
+ Grasshopper::Stub.when(stub.bop).then_return("pow")
49
49
  assert_equal("pow", stub.bop)
50
- assert_equal(nil, stub.bang)
50
+ assert_nil(stub.bang)
51
51
  end
52
52
 
53
53
  def test_stub_like
54
- stub = Stub.like(:zap => "kapow!", :zip => [:one => 1, :two => 2])
54
+ stub = Grasshopper::Stub.like(:zap => "kapow!", :zip => [:one => 1, :two => 2])
55
55
 
56
56
  assert_equal("kapow!", stub.zap)
57
57
  assert_equal([:one => 1, :two => 2], stub.zip)
58
- assert_equal(nil, stub.bop)
58
+ assert_nil(stub.bop)
59
59
  end
60
60
  end
metadata CHANGED
@@ -1,122 +1,112 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grasshopper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
5
- prerelease:
4
+ version: 1.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Matt J Raibert
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-10-12 00:00:00.000000000 Z
11
+ date: 2017-04-09 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: minitest
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
- type: :runtime
20
+ type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: minitest-reporters
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: 0.5.0
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: 0.5.0
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: bundler
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - ">="
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - ">="
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: posto
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - ">="
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - ">="
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  description: A tiny mocking framework focused on the Arrage-Act-Assert test pattern.
79
70
  Grasshopper is heavily modeled after Mockito.
80
- email: mattraibert@gmail.com
71
+ email: mattraibert@positiondev.com
81
72
  executables: []
82
73
  extensions: []
83
74
  extra_rdoc_files: []
84
75
  files:
85
- - Rakefile
86
- - README.md
87
76
  - LICENSE.txt
77
+ - README.md
78
+ - Rakefile
79
+ - lib/grasshopper.rb
88
80
  - lib/grasshopper/mock.rb
89
81
  - lib/grasshopper/stub.rb
90
- - lib/grasshopper.rb
91
- - test/test_helper.rb
92
82
  - test/mock_test.rb
93
83
  - test/stub_test.rb
84
+ - test/test_helper.rb
94
85
  homepage: http://github.com/mattraibert/grasshopper
95
86
  licenses:
96
- - GPLv3
87
+ - LGPL-3.0
88
+ metadata: {}
97
89
  post_install_message:
98
90
  rdoc_options: []
99
91
  require_paths:
100
92
  - lib
101
93
  required_ruby_version: !ruby/object:Gem::Requirement
102
- none: false
103
94
  requirements:
104
- - - ! '>='
95
+ - - ">="
105
96
  - !ruby/object:Gem::Version
106
97
  version: '0'
107
98
  required_rubygems_version: !ruby/object:Gem::Requirement
108
- none: false
109
99
  requirements:
110
- - - ! '>='
100
+ - - ">="
111
101
  - !ruby/object:Gem::Version
112
102
  version: '0'
113
103
  requirements: []
114
104
  rubyforge_project:
115
- rubygems_version: 1.8.24
105
+ rubygems_version: 2.5.1
116
106
  signing_key:
117
- specification_version: 3
107
+ specification_version: 4
118
108
  summary: A tiny mocking framework focused on the Arrange-Act-Assert test pattern
119
109
  test_files:
120
- - test/test_helper.rb
121
110
  - test/mock_test.rb
122
111
  - test/stub_test.rb
112
+ - test/test_helper.rb