-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_framework_interface.rb
77 lines (60 loc) · 1.4 KB
/
test_framework_interface.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
require 'spec'
class Testee
def switch; 'off' end
def on?; switch == 'on' end
def off?; switch == 'off' end
end
module Gourmet
# Define a single stub that is installed
# on the testee for the duration of the context.
#
def context stubs, &context
tongue = Tongue.new
tongue.stubs = stubs
tongue.instance_eval &context
end
class Tongue
attr_accessor :tastebuds, :stubs
def context stubs, &context
# TODO refactor
tongue = Tongue.new
tongue.stubs = self.stubs.merge stubs
tongue.instance_eval &context
end
# What gourmet expects (in a context or elsewhere).
#
def expects definitions
@expectations = definitions
end
# Run the tests.
#
def sample testee
install testee, stubs
test testee, expectations
end
def install testee, stubs
testee.stub! stubs
end
def test testee, expectations
expectations.each_pair do |message, expected|
it "should respond to #{message} with #{expected}" do
testee.send(message).should == expected
end
end
end
end
# Stub external objects.
#
def stub stubbees, definitions
end
end
extend Gourmet
testee = Testee.new
describe testee do
context switch:'on' do
expects on?:true, off?:false
end
context switch:'off' do
expects on?:false, off?:true
end
end