em-dextras 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,3 @@
1
- require "em-dextras/spec/event_machine_probes"
2
- require "em-dextras/spec/spec_matchers.rb"
3
-
4
1
  require "eventmachine"
5
2
 
6
3
  module EMDextras
@@ -8,3 +5,8 @@ module EMDextras
8
5
  # Your code goes here...
9
6
  end
10
7
  end
8
+
9
+ require "em-dextras/spec/event_machine_probes"
10
+ require "em-dextras/spec/spec_matchers.rb"
11
+ require "em-dextras/spec/spy.rb"
12
+
@@ -0,0 +1,34 @@
1
+ module EMDextras::Spec
2
+ class Spy
3
+ def initialize
4
+ @calls = []
5
+ end
6
+
7
+ def called?(method_name, *args)
8
+ @calls.include? :name => method_name, :args => args
9
+ end
10
+
11
+ def received_call!(method_name, *args)
12
+ probe_event_machine check: (Proc.new do
13
+ check_if_received_call(method_name, *args)
14
+ end)
15
+ end
16
+
17
+ def method_missing(method_name, *args, &block)
18
+ @calls << { :name => method_name, :args => args }
19
+ end
20
+
21
+ private
22
+
23
+ def check_if_received_call(method_name, *args)
24
+ unless self.called?(method_name, *args)
25
+ raise ExpectationFailed, "Expected #{method_name} to have been called with parameters [#{args.join(",")}] but only received calls #{@calls.inspect}"
26
+ end
27
+ end
28
+
29
+ end
30
+
31
+ class ExpectationFailed < Exception
32
+ end
33
+
34
+ end
@@ -1,5 +1,5 @@
1
1
  module Em
2
2
  module Dextras
3
- VERSION = "0.0.1"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ describe EMDextras::Spec::Spy do
4
+ subject { described_class.new }
5
+ describe :"called?" do
6
+ it "should record calls" do
7
+ subject.foo(1, :a => "b")
8
+
9
+ subject.called?(:foo, 1, :a => "b").should be_true
10
+ subject.called?(:bar, 1, :a => "b").should be_false
11
+ subject.called?(:foo, 1, :a => "c").should be_false
12
+ end
13
+ end
14
+
15
+ describe :received_call! do
16
+ it "should do nothing if the call was really received" do
17
+ EM.run do
18
+ subject.foo(1, :a => "b")
19
+
20
+ subject.received_call!(:foo, 1, :a => "b")
21
+ end
22
+ end
23
+
24
+ it "should raise an exception if the call was not received" do
25
+ expect {
26
+ EM.run do
27
+ subject.foo(1, :a => "b")
28
+
29
+ subject.received_call!(:bar, 1, :a => "b")
30
+ end
31
+ }.to raise_error(/bar.*foo/)
32
+ end
33
+
34
+ context "when the method is triggered asynchronously" do
35
+ it "should should probe until the call is received" do
36
+ EM.run do
37
+ EM.next_tick do
38
+ subject.foo(1,2,3)
39
+ end
40
+
41
+ subject.received_call!(:foo, 1,2,3)
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: em-dextras
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
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: 2013-03-22 00:00:00.000000000 Z
12
+ date: 2013-03-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: eventmachine
@@ -112,10 +112,12 @@ files:
112
112
  - lib/em-dextras/spec.rb
113
113
  - lib/em-dextras/spec/event_machine_probes.rb
114
114
  - lib/em-dextras/spec/spec_matchers.rb
115
+ - lib/em-dextras/spec/spy.rb
115
116
  - lib/em-dextras/spec/version.rb
116
117
  - lib/em-dextras/version.rb
117
118
  - spec/em-dextras/chains/synchronous_stage_spec.rb
118
119
  - spec/em-dextras/chains_spec.rb
120
+ - spec/em-dextras/spec/spy_spec.rb
119
121
  - spec/spec_helper
120
122
  - spec/spec_helper.rb
121
123
  homepage: ''
@@ -146,5 +148,6 @@ summary: Utilities to help working with EventMachine Deferrables. Includes probe
146
148
  test_files:
147
149
  - spec/em-dextras/chains/synchronous_stage_spec.rb
148
150
  - spec/em-dextras/chains_spec.rb
151
+ - spec/em-dextras/spec/spy_spec.rb
149
152
  - spec/spec_helper
150
153
  - spec/spec_helper.rb