testme 0.5.85 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +28 -7
- data/bin/testme +5 -0
- data/lib/formatter.rb +3 -63
- data/lib/logic.rb +11 -2
- data/lib/testme.rb +1 -1
- data/test/testme.test.rb +0 -1
- metadata +8 -3
- data/test/formatter.test.rb +0 -13
data/README.md
CHANGED
@@ -5,6 +5,23 @@
|
|
5
5
|
given simple: true
|
6
6
|
is? :simple
|
7
7
|
|
8
|
+
## Cheatsheet
|
9
|
+
- ` -'this is a test description'` - Describe the context (if necessary)
|
10
|
+
- `test Player` - Defines the topic of the test
|
11
|
+
- `test 'My Scenario'` - Non-unit test e.g scenario tests (all features still work)
|
12
|
+
- `topic` - Retrieve the topic of the test
|
13
|
+
- `given name: 'Flavie', class: 'Rogue'` - Provide a context
|
14
|
+
- `given { topic.talk_to 'Deckard' }` - Create a context using a block
|
15
|
+
- `given { topic.name = 'Flavie; topic.class = 'Rogue' }` - Code run inside a block will still automatically stub for you
|
16
|
+
- `given :deckard_cains_name, name: Name.new(first: 'Deckard', last: 'Cain')` - Store a context
|
17
|
+
- `given :deckard_cains_name` - Load a context
|
18
|
+
- `given { topic.name.first = 'Deckard' }` - Create a stub chain
|
19
|
+
- `also class: 'Rogue'` - Provide a context over the existing context
|
20
|
+
- `is? :name, 'Flavie'` - Create an assertion
|
21
|
+
- `is? :inventory[1], 'Arrows'` - Assertion with arguments
|
22
|
+
- `is? { topic.inventory(1) == 'Arrows' }` - Assertion with block
|
23
|
+
- `before do <block> end ` - Create a base context
|
24
|
+
|
8
25
|
## Detailed Example
|
9
26
|
|
10
27
|
test Pizza
|
@@ -190,6 +207,10 @@ default test folder: `/test/**/*`
|
|
190
207
|
|
191
208
|
test App::Account
|
192
209
|
|
210
|
+
> For scenario testing, or testing a blank Object (all features will still work)
|
211
|
+
|
212
|
+
test 'An Idea'
|
213
|
+
|
193
214
|
> This automatically creates an instance which you access with `topic`
|
194
215
|
|
195
216
|
topic.name
|
@@ -202,6 +223,13 @@ default test folder: `/test/**/*`
|
|
202
223
|
|
203
224
|
***
|
204
225
|
|
226
|
+
#### Describing or Commenting
|
227
|
+
Use `-` followed by a String
|
228
|
+
|
229
|
+
-'this is a test description'
|
230
|
+
|
231
|
+
***
|
232
|
+
|
205
233
|
#### `given`
|
206
234
|
> Set the context
|
207
235
|
|
@@ -310,13 +338,6 @@ default test folder: `/test/**/*`
|
|
310
338
|
|
311
339
|
***
|
312
340
|
|
313
|
-
#### Describing or Commenting
|
314
|
-
Use `-` followed by a String
|
315
|
-
|
316
|
-
-'this is a test description'
|
317
|
-
|
318
|
-
***
|
319
|
-
|
320
341
|
## "This is too easy! How can I make this more challenging?"
|
321
342
|
|
322
343
|
There is something about you that troubles me. Your manner is strange for a lonely code warrior.
|
data/bin/testme
CHANGED
data/lib/formatter.rb
CHANGED
@@ -5,8 +5,6 @@ module TestMe
|
|
5
5
|
case format
|
6
6
|
when :none
|
7
7
|
return Formatter::None.new
|
8
|
-
when :text
|
9
|
-
return Formatter::Text.new
|
10
8
|
when :console
|
11
9
|
return Formatter::Console.new
|
12
10
|
when :html
|
@@ -49,11 +47,9 @@ module TestMe
|
|
49
47
|
log " also " + context_to_string(desc, stubs, &block)
|
50
48
|
end
|
51
49
|
|
52
|
-
def is? method, actual, expected
|
53
|
-
success = actual == expected
|
54
|
-
|
50
|
+
def is? method, actual, expected, success
|
55
51
|
if method.class == Proc
|
56
|
-
log ' is ' + block_to_string(&method) + '? ' + (success ? 'YES'.bright.green : "NO
|
52
|
+
log ' is ' + block_to_string(&method) + '? ' + (success ? 'YES'.bright.green : "NO".bright.red) + "\n\n"
|
57
53
|
else
|
58
54
|
log ' is ' + method.to_s + ', ' + expected.to_s.yellow + '? ' + (success ? 'YES'.bright.green : "NO, it was '#{actual}'".bright.red) + "\n\n"
|
59
55
|
end
|
@@ -66,7 +62,7 @@ module TestMe
|
|
66
62
|
def describe msg
|
67
63
|
log ' ' + msg.bright.yellow
|
68
64
|
end
|
69
|
-
|
65
|
+
|
70
66
|
private
|
71
67
|
def block_to_string &block
|
72
68
|
loc = block.source_location
|
@@ -100,61 +96,5 @@ module TestMe
|
|
100
96
|
end
|
101
97
|
|
102
98
|
end
|
103
|
-
|
104
|
-
class Text < Console
|
105
|
-
def test topic
|
106
|
-
log "test " + topic.to_s
|
107
|
-
end
|
108
|
-
|
109
|
-
def given desc=nil, stubs=nil, &block
|
110
|
-
log "given " + context_to_string(desc, stubs, &block)
|
111
|
-
end
|
112
|
-
|
113
|
-
def also desc=nil, stubs=nil, &block
|
114
|
-
log "also " + context_to_string(desc, stubs, &block)
|
115
|
-
end
|
116
|
-
|
117
|
-
def is? method, actual, expected
|
118
|
-
success = actual == expected
|
119
|
-
|
120
|
-
log 'is ' + method.to_s + ', ' + expected.to_s + '? ' + (success ? 'YES' : "NO, it was '#{actual}'")
|
121
|
-
end
|
122
|
-
|
123
|
-
def compile
|
124
|
-
#do nothing
|
125
|
-
end
|
126
|
-
|
127
|
-
def describe msg
|
128
|
-
log msg
|
129
|
-
end
|
130
|
-
|
131
|
-
private
|
132
|
-
def block_to_string &block
|
133
|
-
"(block)"
|
134
|
-
end
|
135
|
-
|
136
|
-
def context_to_string desc=nil, stubs=nil, &block
|
137
|
-
str = ""
|
138
|
-
|
139
|
-
if desc.class == String || desc.class == Symbol
|
140
|
-
str += ":#{desc}: "
|
141
|
-
end
|
142
|
-
|
143
|
-
if desc.class == Hash
|
144
|
-
stubs = desc
|
145
|
-
end
|
146
|
-
|
147
|
-
if stubs
|
148
|
-
str += stubs.map{|k,v| (k.to_s + ': ' + v.to_s)}.join(', ')
|
149
|
-
end
|
150
|
-
|
151
|
-
if block
|
152
|
-
str += block_to_string(&block)
|
153
|
-
end
|
154
|
-
|
155
|
-
return str
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
99
|
end
|
160
100
|
end
|
data/lib/logic.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
module TestMe
|
2
|
+
@@failed = false
|
3
|
+
|
2
4
|
def topic
|
3
5
|
@topic
|
4
6
|
end
|
@@ -84,7 +86,9 @@ module TestMe
|
|
84
86
|
result = actual == expected
|
85
87
|
end
|
86
88
|
|
87
|
-
@@formatter.is? method, actual, expected
|
89
|
+
@@formatter.is? method, actual, expected, result
|
90
|
+
|
91
|
+
@@failed = true if result == false
|
88
92
|
|
89
93
|
result
|
90
94
|
end
|
@@ -94,10 +98,15 @@ module TestMe
|
|
94
98
|
end
|
95
99
|
|
96
100
|
def self.formatter
|
97
|
-
|
101
|
+
@@formatter
|
102
|
+
end
|
103
|
+
|
104
|
+
def self.failed?
|
105
|
+
@@failed
|
98
106
|
end
|
99
107
|
|
100
108
|
private
|
109
|
+
|
101
110
|
class Context
|
102
111
|
attr_accessor :name, :block, :stubs
|
103
112
|
end
|
data/lib/testme.rb
CHANGED
data/test/testme.test.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: testme
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rainbow
|
@@ -87,7 +87,6 @@ files:
|
|
87
87
|
- spec/spec_helper.rb
|
88
88
|
- spec/testme_spec.rb
|
89
89
|
- test/double.test.rb
|
90
|
-
- test/formatter.test.rb
|
91
90
|
- test/testme.test.rb
|
92
91
|
- testme.gemspec
|
93
92
|
homepage: http://github.com/danielshuey/testme
|
@@ -102,12 +101,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
102
101
|
- - ! '>='
|
103
102
|
- !ruby/object:Gem::Version
|
104
103
|
version: '0'
|
104
|
+
segments:
|
105
|
+
- 0
|
106
|
+
hash: 1897896740676466632
|
105
107
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
108
|
none: false
|
107
109
|
requirements:
|
108
110
|
- - ! '>='
|
109
111
|
- !ruby/object:Gem::Version
|
110
112
|
version: '0'
|
113
|
+
segments:
|
114
|
+
- 0
|
115
|
+
hash: 1897896740676466632
|
111
116
|
requirements: []
|
112
117
|
rubyforge_project:
|
113
118
|
rubygems_version: 1.8.24
|
data/test/formatter.test.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
module TestMe::Formatter
|
2
|
-
class Text
|
3
|
-
def log msg
|
4
|
-
return msg
|
5
|
-
end
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
test TestMe::Formatter::Text
|
10
|
-
is? :test[TestMe::Formatter::Text], 'test TestMe::Formatter::Text'
|
11
|
-
is? :given[{description: "I format things"}], 'given description: I format things'
|
12
|
-
is? :also[{description: "I format things"}], 'also description: I format things'
|
13
|
-
is? :describe['testme'], 'testme'
|