lookout 2.2.0 → 2.3.0

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 CHANGED
@@ -259,7 +259,14 @@
259
259
  s.a + s.b
260
260
  end
261
261
 
262
- and we can stub out a specific method on an object:
262
+ Blocks are also allowed:
263
+
264
+ expect 3 do
265
+ s = stub(:a => proc{ |a, b| a + b })
266
+ s.a(1, 2)
267
+ end
268
+
269
+ If need be, we can stub out a specific method on an object:
263
270
 
264
271
  expect 'def' do
265
272
  a = 'abc'
@@ -28,7 +28,11 @@ module Lookout::Expectation
28
28
  when Hash
29
29
  Lookout::Stub::Object.new.tap{ |stub|
30
30
  args[0].each do |name, value|
31
- @stubs.define(stub, name){ value }
31
+ if value.respond_to? :to_proc
32
+ @stubs.define(stub, name, &value)
33
+ else
34
+ @stubs.define(stub, name){ value }
35
+ end
32
36
  end
33
37
  }
34
38
  else
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  module Lookout
4
- Version = '2.2.0'
4
+ Version = '2.3.0'
5
5
  end
@@ -146,6 +146,12 @@ Expectations do
146
146
  s.a + s.b
147
147
  end
148
148
 
149
+ # Use a stub that’s set up with a set of procs as methods.
150
+ expect 3 do
151
+ s = stub(:a => proc{ |a, b| a + b })
152
+ s.a(1, 2)
153
+ end
154
+
149
155
  # Use a contrete mock to verify that a method is called.
150
156
  expect Object.to.receive.deal do
151
157
  Object.deal
@@ -36,4 +36,12 @@ Expectations do
36
36
  expect Lookout::Results::Fulfilled do
37
37
  Lookout::Expectation.on([1, 2, 3].to.include?(1), nil, nil).evaluate
38
38
  end
39
+
40
+ expect Lookout::Results::Fulfilled do
41
+ Lookout::Expectation.on(1, nil, nil){ stub(:a => 1).a }.evaluate
42
+ end
43
+
44
+ expect Lookout::Results::Fulfilled do
45
+ Lookout::Expectation.on(1, nil, nil){ stub(:a => proc{ 1 }).a }.evaluate
46
+ end
39
47
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lookout
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-14 00:00:00.000000000 Z
12
+ date: 2011-10-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: yard
16
- requirement: &14599272 !ruby/object:Gem::Requirement
16
+ requirement: &14532168 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: 0.6.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *14599272
24
+ version_requirements: *14532168
25
25
  description: ! " Lookout\n\n Lookout is a lightweight
26
26
  unit testing framework. Tests (expectations) can be\n written as follows\n\n expect
27
27
  2 do\n 1 + 1\n end\n\n expect NoMethodError do\n Object.invalid_method_call\n
@@ -116,21 +116,23 @@ description: ! " Lookout\n\n Lookout is a lightw
116
116
  stub.to.receive.dial('2125551212').twice do |phone|\n phone.dial('2125551212')\n
117
117
  \ phone.hangup\n phone.dial('2125551212')\n end\n\n We
118
118
  can also use stubs without any expectations on them:\n\n expect 3 do\n s
119
- = stub(:a => 1, :b => 2)\n s.a + s.b\n end\n\n and we can stub
120
- out a specific method on an object:\n\n expect 'def' do\n a = 'abc'\n
121
- \ stub(a).to_str{ 'def' }\n a.to_str\n end\n\n You
122
- don’t have to use a mock object to verify that a method is called:\n\n expect
123
- Object.to.receive.deal do\n Object.deal\n end\n\n As you have
124
- figured out by now, the expected method call is set up by\n calling ‹#receive›
125
- after ‹#to›. ‹#Receive› is followed by a call to the\n method to expect with
126
- any expected arguments. The body of the mocked\n method can be given as the
127
- block to the method. Finally, an expected\n invocation count may follow the
128
- method. Let’s look at this formal\n specification in more detail.\n\n The
129
- expected method arguments may be given in a variety of ways. Let’s\n introduce
130
- them by giving some examples:\n\n expect mock.to.receive.a do |m|\n …\n
131
- \ end\n\n Here, the method ‹#a› must be called with any number of arguments.
132
- \ It\n may be called any number of times, but it must be called at least once.\n\n
133
- \ If a method must receive exactly one argument, you can use ‹arg›:\n\n expect
119
+ = stub(:a => 1, :b => 2)\n s.a + s.b\n end\n\n Blocks are also
120
+ allowed:\n\n expect 3 do\n s = stub(:a => proc{ |a, b| a + b })\n
121
+ \ s.a(1, 2)\n end\n\n If need be, we can stub out a specific
122
+ method on an object:\n\n expect 'def' do\n a = 'abc'\n stub(a).to_str{
123
+ 'def' }\n a.to_str\n end\n\n You don’t have to use a mock object
124
+ to verify that a method is called:\n\n expect Object.to.receive.deal do\n
125
+ \ Object.deal\n end\n\n As you have figured out by now, the
126
+ expected method call is set up by\n calling ‹#receive› after ‹#to›. ‹#Receive›
127
+ is followed by a call to the\n method to expect with any expected arguments.
128
+ \ The body of the mocked\n method can be given as the block to the method.
129
+ \ Finally, an expected\n invocation count may follow the method. Let’s look
130
+ at this formal\n specification in more detail.\n\n The expected method
131
+ arguments may be given in a variety of ways. Let’s\n introduce them by giving
132
+ some examples:\n\n expect mock.to.receive.a do |m|\n …\n end\n\n
133
+ \ Here, the method ‹#a› must be called with any number of arguments. It\n may
134
+ be called any number of times, but it must be called at least once.\n\n If
135
+ a method must receive exactly one argument, you can use ‹arg›:\n\n expect
134
136
  mock.to.receive.a(arg) do |m|\n …\n end\n\n If a method must
135
137
  receive a specific argument, you can use that argument:\n\n expect mock.to.receive.a(1..2)
136
138
  do |m|\n …\n end\n\n The same matching rules apply for arguments