tengu 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tengu/allow.rb +3 -3
- data/lib/tengu/describe_block.rb +5 -5
- data/lib/tengu/file.rb +4 -4
- data/lib/tengu/it_block.rb +11 -6
- data/lib/tengu/receiver.rb +2 -2
- data/lib/tengu/runner.rb +18 -9
- data/lib/tengu/version.rb +1 -1
- data/spec/describe_block_spec.rb +2 -2
- data/spec/file_spec.rb +2 -2
- data/spec/fixtures/example.rb +9 -0
- data/spec/it_block_spec.rb +4 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d124d7ab40773a1143eb66c8b7b051c53c485e84
|
4
|
+
data.tar.gz: 4d475bee1504ad520e2907ecfdc2e6ce426effd5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e31ea456c5ab61d6276ad23dc35331e40759ed44b7eb3302b3290ca05e5b14944b7bae7db8b7cb3f3e38949184412f7d1fa7908bb8ccbeadb222185bd63f618
|
7
|
+
data.tar.gz: 847853d24e172c0c64fddf4fabcc4c9adc7adb21d20cefd715d4241e8f6584e5e0472267285628ecd8e581d8f880e3ea6e91d8293c07f2b59a133dfb632b9a80
|
data/lib/tengu/allow.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
module Tengu
|
2
2
|
class Allow
|
3
|
-
def initialize(
|
4
|
-
@
|
3
|
+
def initialize(listeners, object)
|
4
|
+
@listeners = listeners
|
5
5
|
@object = object
|
6
6
|
end
|
7
7
|
|
8
8
|
def to(receiver)
|
9
|
-
receiver.setup_allow(@
|
9
|
+
receiver.setup_allow(@listeners, @object)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
data/lib/tengu/describe_block.rb
CHANGED
@@ -9,8 +9,8 @@ module Tengu
|
|
9
9
|
load_test_cases
|
10
10
|
end
|
11
11
|
|
12
|
-
def run(
|
13
|
-
run_test_cases(
|
12
|
+
def run(listeners = [])
|
13
|
+
run_test_cases(listeners)
|
14
14
|
end
|
15
15
|
|
16
16
|
def success_count
|
@@ -48,16 +48,16 @@ module Tengu
|
|
48
48
|
instance_eval &@block
|
49
49
|
end
|
50
50
|
|
51
|
-
def run_test_cases(
|
51
|
+
def run_test_cases(listeners = [])
|
52
52
|
@test_cases.each do |test_case|
|
53
53
|
@before_each_hooks.each { |hook| hook.call }
|
54
|
-
test_case.run(
|
54
|
+
test_case.run(listeners)
|
55
55
|
@after_each_hooks.each { |hook| hook.call }
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
59
|
def it(description = nil, &block)
|
60
|
-
@test_cases << ItBlock.new(description, block)
|
60
|
+
@test_cases << ItBlock.new(self, description, block)
|
61
61
|
end
|
62
62
|
|
63
63
|
def xit(description, &block); end
|
data/lib/tengu/file.rb
CHANGED
@@ -6,8 +6,8 @@ module Tengu
|
|
6
6
|
load_tests
|
7
7
|
end
|
8
8
|
|
9
|
-
def run(
|
10
|
-
run_tests(
|
9
|
+
def run(listeners = [])
|
10
|
+
run_tests(listeners)
|
11
11
|
end
|
12
12
|
|
13
13
|
def success_count
|
@@ -32,8 +32,8 @@ module Tengu
|
|
32
32
|
instance_eval(code)
|
33
33
|
end
|
34
34
|
|
35
|
-
def run_tests(
|
36
|
-
@describes.each { |describe| describe.run(
|
35
|
+
def run_tests(listeners= [])
|
36
|
+
@describes.each { |describe| describe.run(listeners) }
|
37
37
|
end
|
38
38
|
|
39
39
|
def describe(description, &block)
|
data/lib/tengu/it_block.rb
CHANGED
@@ -8,7 +8,8 @@ module Tengu
|
|
8
8
|
include Matchers
|
9
9
|
attr_reader :description, :expectations
|
10
10
|
|
11
|
-
def initialize(description, block)
|
11
|
+
def initialize(describe_block, description, block)
|
12
|
+
@describe_block = describe_block
|
12
13
|
@description = description
|
13
14
|
@block = block
|
14
15
|
@success = true
|
@@ -16,11 +17,10 @@ module Tengu
|
|
16
17
|
@expectations = []
|
17
18
|
end
|
18
19
|
|
19
|
-
def run(
|
20
|
-
@
|
20
|
+
def run(listeners = [])
|
21
|
+
@listeners = listeners
|
21
22
|
instance_eval(&@block)
|
22
|
-
@
|
23
|
-
notify(listeners)
|
23
|
+
notify(@listeners)
|
24
24
|
end
|
25
25
|
|
26
26
|
def success?
|
@@ -36,7 +36,7 @@ module Tengu
|
|
36
36
|
private
|
37
37
|
|
38
38
|
def allow(object)
|
39
|
-
Allow.new(@
|
39
|
+
Allow.new(@listeners, object)
|
40
40
|
end
|
41
41
|
|
42
42
|
def receive(message)
|
@@ -50,6 +50,7 @@ module Tengu
|
|
50
50
|
def notify(listeners)
|
51
51
|
listeners.each do |listener|
|
52
52
|
listener.notify(success_state, self)
|
53
|
+
listener.notify(:finished_case, self)
|
53
54
|
end
|
54
55
|
end
|
55
56
|
|
@@ -73,5 +74,9 @@ module Tengu
|
|
73
74
|
@expectations << expectation
|
74
75
|
expectation
|
75
76
|
end
|
77
|
+
|
78
|
+
def method_missing(method, *args, &block)
|
79
|
+
@describe_block.send(method, *args, &block)
|
80
|
+
end
|
76
81
|
end
|
77
82
|
end
|
data/lib/tengu/receiver.rb
CHANGED
@@ -18,7 +18,7 @@ module Tengu
|
|
18
18
|
self
|
19
19
|
end
|
20
20
|
|
21
|
-
def setup_allow(
|
21
|
+
def setup_allow(listeners, object)
|
22
22
|
unless object.respond_to?(:_tengu_received?)
|
23
23
|
object.instance_eval do
|
24
24
|
define_singleton_method(:_tengu_received) do
|
@@ -43,7 +43,7 @@ module Tengu
|
|
43
43
|
end
|
44
44
|
else
|
45
45
|
original_method = object.method(@message.to_sym)
|
46
|
-
|
46
|
+
listeners.each { |listener| listener.notify(:override, [object, original_method]) }
|
47
47
|
object.instance_eval do
|
48
48
|
define_singleton_method message, -> (*args) { _tengu_received[message] << args; return_value }
|
49
49
|
end
|
data/lib/tengu/runner.rb
CHANGED
@@ -5,10 +5,28 @@ module Tengu
|
|
5
5
|
@overrides = []
|
6
6
|
end
|
7
7
|
|
8
|
+
def notify(event, object)
|
9
|
+
case event
|
10
|
+
when :finished_case then reset_overrides
|
11
|
+
when :override then record_override(*object)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def run(ios, formatters = [])
|
16
|
+
@files = ios.map { |io| Tengu::File.new(io) }
|
17
|
+
formatters.each { |formatter| formatter.notify(:started, self) }
|
18
|
+
@files.each { |file| file.run([self] + formatters) }
|
19
|
+
result = Result.new(@files)
|
20
|
+
formatters.each { |formatter| formatter.notify(:finished, result) }
|
21
|
+
result
|
22
|
+
end
|
23
|
+
|
8
24
|
def record_override(object, method)
|
9
25
|
@overrides << [object, method]
|
10
26
|
end
|
11
27
|
|
28
|
+
private
|
29
|
+
|
12
30
|
def reset_overrides
|
13
31
|
@overrides.reverse.each do |object, method|
|
14
32
|
object.instance_eval do
|
@@ -16,14 +34,5 @@ module Tengu
|
|
16
34
|
end
|
17
35
|
end
|
18
36
|
end
|
19
|
-
|
20
|
-
def run(ios, formatters = [])
|
21
|
-
@files = ios.map { |io| Tengu::File.new(io) }
|
22
|
-
formatters.each { |formatter| formatter.notify(:started, self) }
|
23
|
-
@files.each { |file| file.run(self, formatters) }
|
24
|
-
result = Result.new(@files)
|
25
|
-
formatters.each { |formatter| formatter.notify(:finished, result) }
|
26
|
-
result
|
27
|
-
end
|
28
37
|
end
|
29
38
|
end
|
data/lib/tengu/version.rb
CHANGED
data/spec/describe_block_spec.rb
CHANGED
@@ -22,7 +22,7 @@ describe Tengu::DescribeBlock do
|
|
22
22
|
allow(expected).to receive(:call)
|
23
23
|
allow(ItBlock).to receive(:new).and_return(double(ItBlock, run: true))
|
24
24
|
code = -> (wombat) { before :each, &expected; it {} }
|
25
|
-
DescribeBlock.new("test", code).run(
|
25
|
+
DescribeBlock.new("test", code).run([])
|
26
26
|
expect(expected).to have_received(:call)
|
27
27
|
end
|
28
28
|
|
@@ -31,7 +31,7 @@ describe Tengu::DescribeBlock do
|
|
31
31
|
allow(expected).to receive(:call)
|
32
32
|
allow(ItBlock).to receive(:new).and_return(double(ItBlock, run: true))
|
33
33
|
code = -> (wombat) { after :each, &expected; it {} }
|
34
|
-
DescribeBlock.new("test", code).run(
|
34
|
+
DescribeBlock.new("test", code).run([])
|
35
35
|
expect(expected).to have_received(:call)
|
36
36
|
end
|
37
37
|
end
|
data/spec/file_spec.rb
CHANGED
@@ -15,8 +15,8 @@ describe Tengu::File do
|
|
15
15
|
code = double(File, read: "describe('test') {}")
|
16
16
|
file = File.new(code)
|
17
17
|
runner = double
|
18
|
-
file.run(runner)
|
19
|
-
expect(describe_block).to have_received(:run).with(runner
|
18
|
+
file.run([runner])
|
19
|
+
expect(describe_block).to have_received(:run).with([runner])
|
20
20
|
end
|
21
21
|
|
22
22
|
it "returns the success count" do
|
data/spec/fixtures/example.rb
CHANGED
data/spec/it_block_spec.rb
CHANGED