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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5af8bd49ab18c5df87f95597d85710931e43b70c
4
- data.tar.gz: f10cda26754deeb775e208ac09c9af549d33437c
3
+ metadata.gz: d124d7ab40773a1143eb66c8b7b051c53c485e84
4
+ data.tar.gz: 4d475bee1504ad520e2907ecfdc2e6ce426effd5
5
5
  SHA512:
6
- metadata.gz: 45e37d875c7a30f6cd2aff30b316f7c1cb5a72ec0283339fe23e0c81415ac9b6d8515d825ea9cbbfa5d9d095809088b4ca0e063e2f8178b7a2787a14df9b2db7
7
- data.tar.gz: dfd14c8623329403908f6ae11add774b1256a517c135b06a8876007e34d9bac0edc694cb618ea584cece2e591647baef701795b6fde18dfa3a57aa12864ddec4
6
+ metadata.gz: 8e31ea456c5ab61d6276ad23dc35331e40759ed44b7eb3302b3290ca05e5b14944b7bae7db8b7cb3f3e38949184412f7d1fa7908bb8ccbeadb222185bd63f618
7
+ data.tar.gz: 847853d24e172c0c64fddf4fabcc4c9adc7adb21d20cefd715d4241e8f6584e5e0472267285628ecd8e581d8f880e3ea6e91d8293c07f2b59a133dfb632b9a80
@@ -1,12 +1,12 @@
1
1
  module Tengu
2
2
  class Allow
3
- def initialize(runner, object)
4
- @runner = runner
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(@runner, @object)
9
+ receiver.setup_allow(@listeners, @object)
10
10
  end
11
11
  end
12
12
  end
@@ -9,8 +9,8 @@ module Tengu
9
9
  load_test_cases
10
10
  end
11
11
 
12
- def run(runner, listeners = [])
13
- run_test_cases(runner, listeners)
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(runner, listeners = [])
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(runner, listeners)
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
@@ -6,8 +6,8 @@ module Tengu
6
6
  load_tests
7
7
  end
8
8
 
9
- def run(runner, listeners = [])
10
- run_tests(runner, listeners)
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(runner, listeners= [])
36
- @describes.each { |describe| describe.run(runner, listeners) }
35
+ def run_tests(listeners= [])
36
+ @describes.each { |describe| describe.run(listeners) }
37
37
  end
38
38
 
39
39
  def describe(description, &block)
@@ -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(runner, listeners = [])
20
- @runner = runner
20
+ def run(listeners = [])
21
+ @listeners = listeners
21
22
  instance_eval(&@block)
22
- @runner.reset_overrides
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(@runner, object)
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
@@ -18,7 +18,7 @@ module Tengu
18
18
  self
19
19
  end
20
20
 
21
- def setup_allow(runner, object)
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
- runner.record_override(object, original_method)
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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Tengu
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -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(nil, [])
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(nil, [])
34
+ DescribeBlock.new("test", code).run([])
35
35
  expect(expected).to have_received(:call)
36
36
  end
37
37
  end
@@ -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
@@ -17,6 +17,15 @@ describe "True" do
17
17
  expect($foo).to eq("bar")
18
18
  end
19
19
 
20
+ it "can call methods" do
21
+ wombat
22
+ expect($foo).to eq("numbat")
23
+ end
24
+
25
+ def wombat
26
+ $foo = "numbat"
27
+ end
28
+
20
29
  after(:each) do
21
30
  $foo = "bar"
22
31
  end
@@ -18,4 +18,8 @@ describe Tengu::ItBlock do
18
18
  it "returns pending" do
19
19
  pending
20
20
  end
21
+
22
+ it "can define methods" do
23
+
24
+ end
21
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tengu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - halogenandtoast