grasshopper 0.4.0 → 0.4.1

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.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Grasshopper
2
2
 
3
- A tiny mocking framework based on [Mockito](http://code.google.com/p/mockito/). I built it so that I could write unit tests in the [Arrage-Act-Assert](http://c2.com/cgi/wiki?ArrangeActAssert) style.
3
+ A tiny mocking framework focused on the [Arrage-Act-Assert](http://c2.com/cgi/wiki?ArrangeActAssert) test pattern. Grasshopper is heavily modeled after [Mockito](http://code.google.com/p/mockito/).
4
4
 
5
5
  ## Examples
6
6
 
@@ -31,7 +31,7 @@ stub.money("gimmie") #=> 5
31
31
  stub.monkey #=> nil
32
32
  ```
33
33
 
34
- or you can use this shorter syntax if you prefer:
34
+ or you can use this shorter style if you prefer:
35
35
 
36
36
  ```ruby
37
37
  Stub.like(:keys => [:door_key, :mail_key], :money => 5)
@@ -0,0 +1,119 @@
1
+ require 'test_helper'
2
+ require 'grasshopper'
3
+
4
+ class MockTest < MiniTest::Unit::TestCase
5
+ def test_fails_verify_if_no_such_message
6
+ mock = Mock.new
7
+
8
+ assert_raises MiniTest::Assertion do
9
+ Mock.verify(mock).never_sent
10
+ end
11
+ end
12
+
13
+ def test_no_failure_if_message_was_sent
14
+ mock = Mock.new
15
+ mock.message_was_sent
16
+ Mock.verify(mock).message_was_sent
17
+ end
18
+
19
+ def test_can_verify_number_of_invocations
20
+ mock = Mock.new
21
+ 2.times { mock.message_sent_twice }
22
+ 2.times { Mock.verify(mock).message_sent_twice }
23
+ end
24
+
25
+ def test_fails_if_too_few_invocations
26
+ mock = Mock.new
27
+ mock.message_sent_once
28
+
29
+ assert_raises MiniTest::Assertion do
30
+ 2.times { Mock.verify(mock).message_sent_once }
31
+ end
32
+ end
33
+
34
+ def test_validate_param
35
+ mock = Mock.new
36
+ mock.message_with_param("to verify")
37
+ Mock.verify(mock).message_with_param("to verify")
38
+ end
39
+
40
+ def test_validate_two_params
41
+ mock = Mock.new
42
+ mock.message_with_params("to", "verify")
43
+ Mock.verify(mock).message_with_params("to", "verify")
44
+ end
45
+
46
+ def test_validate_wrong_param_explodes
47
+ mock = Mock.new
48
+ mock.message_with_param("param")
49
+
50
+ assert_raises MiniTest::Assertion do
51
+ Mock.verify(mock).message_with_param("wrong param")
52
+ end
53
+ end
54
+
55
+ def test_validate_wrong_number_params_explodes
56
+ mock = Mock.new
57
+ mock.message_with_param("param", "two")
58
+
59
+ assert_raises MiniTest::Assertion do
60
+ Mock.verify(mock).message_with_param("param")
61
+ end
62
+ end
63
+
64
+ def test_stub_returns_nil
65
+ assert_nil(Stub.new.unknown_method)
66
+ end
67
+
68
+ def test_can_stub_a_method
69
+ stub = Stub.new
70
+ Stub.when(stub.this_message).then_return(9)
71
+ assert_equal(9, stub.this_message)
72
+ end
73
+
74
+ def test_two_stubs
75
+ stub1 = Stub.new
76
+ stub2 = Stub.new
77
+ Stub.when(stub1.this_message).then_return(9)
78
+ Stub.when(stub2.that_message).then_return(99)
79
+
80
+ assert_equal(nil, stub1.that_message)
81
+ assert_equal(9, stub1.this_message)
82
+ assert_equal(nil, stub2.this_message)
83
+ assert_equal(99, stub2.that_message)
84
+ end
85
+
86
+ def test_can_stub_a_method_with_param
87
+ stub = Stub.new
88
+ Stub.when(stub.secret(22)).then_return(9)
89
+
90
+ assert_equal(nil, stub.secret(21))
91
+ assert_equal(9, stub.secret(22))
92
+ end
93
+
94
+ def test_can_stub_two_methods_with_param
95
+ stub = Stub.new
96
+ Stub.when(stub.keys).then_return([:door_key, :mail_key])
97
+ Stub.when(stub.money("gimmie")).then_return(5)
98
+
99
+ assert_equal([:door_key, :mail_key], stub.keys)
100
+ assert_equal(5, stub.money("gimmie"))
101
+ assert_nil(stub.monkey)
102
+ end
103
+
104
+ def test_another_call_doesnt_confuse
105
+ stub = Stub.new
106
+ stub.bang
107
+ Stub.when(stub.bop).then_return("pow")
108
+ assert_equal("pow", stub.bop)
109
+ assert_equal(nil, stub.bang)
110
+ end
111
+
112
+ def test_stub_like
113
+ stub = Stub.like(:zap => "kapow!", :zip => [:one => 1, :two => 2])
114
+
115
+ assert_equal("kapow!", stub.zap)
116
+ assert_equal([:one => 1, :two => 2], stub.zip)
117
+ assert_equal(nil, stub.bop)
118
+ end
119
+ end
@@ -0,0 +1,3 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/reporters'
3
+ MiniTest::Reporters.use!
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grasshopper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
- - Matt Raibert
8
+ - Matt J Raibert
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
@@ -75,7 +75,8 @@ dependencies:
75
75
  - - ! '>='
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
- description: A tiny mocking framework based on Mockito
78
+ description: A tiny mocking framework focused on the [Arrage-Act-Assert](http://c2.com/cgi/wiki?ArrangeActAssert)
79
+ test pattern. Grasshopper is heavily modeled after [Mockito](http://code.google.com/p/mockito/).
79
80
  email: mattraibert@gmail.com
80
81
  executables: []
81
82
  extensions: []
@@ -86,9 +87,11 @@ files:
86
87
  - lib/grasshopper.rb
87
88
  - LICENSE.txt
88
89
  - README.md
90
+ - test/grasshopper_test.rb
91
+ - test/test_helper.rb
89
92
  homepage: http://github.com/mattraibert/grasshopper
90
93
  licenses:
91
- - GPL
94
+ - GPLv3
92
95
  post_install_message:
93
96
  rdoc_options: []
94
97
  require_paths:
@@ -101,17 +104,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
101
104
  version: '0'
102
105
  segments:
103
106
  - 0
104
- hash: -2097041632477700683
107
+ hash: 3373509623248960979
105
108
  required_rubygems_version: !ruby/object:Gem::Requirement
106
109
  none: false
107
110
  requirements:
108
111
  - - ! '>='
109
112
  - !ruby/object:Gem::Version
110
- version: 1.3.6
113
+ version: '0'
111
114
  requirements: []
112
- rubyforge_project: nowarning
115
+ rubyforge_project:
113
116
  rubygems_version: 1.8.24
114
117
  signing_key:
115
118
  specification_version: 3
116
- summary: A tiny mocking framework based on Mockito
117
- test_files: []
119
+ summary: A tiny mocking framework focused on the Arrange-Act-Assert test pattern
120
+ test_files:
121
+ - test/grasshopper_test.rb
122
+ - test/test_helper.rb