rspec-rayo 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,8 @@
1
+ # develop
2
+
3
+ # 0.3.0
4
+ * Update everything to work again (new PB, changes to Rayo, etc)
5
+ * Remove Tropo
6
+
7
+ # 0.2.0
8
+ * Ancient history
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
- source "http://rubygems.org"
1
+ source :rubygems
2
2
 
3
3
  gemspec
@@ -0,0 +1,5 @@
1
+ guard 'rspec', :version => 2, :cli => '--format documentation' do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec/" }
5
+ end
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  rspec-rayo
2
2
  ============
3
3
 
4
- This library extends the Rspec testing library for Rayo specific expectations. The library also provides classes for Tropo1 and Rayo drivers.
4
+ This library extends the Rspec testing library for Rayo specific expectations. The library also provides a Rayo driver using Punchblock.
5
5
 
6
6
  Howto Install
7
7
  -------------
@@ -11,15 +11,11 @@ Howto Install
11
11
  Example Driver Setup
12
12
  --------------------
13
13
 
14
- ap "Starting RayoDriver to manage events over XMPP."
15
14
  @rayo = RSpecRayo::RayoDriver.new :username => @config['rayo_server']['jid'],
16
15
  :password => @config['rayo_server']['password'],
17
16
  :wire_logger => Logger.new(@config['rayo_server']['wire_log']),
18
17
  :transport_logger => Logger.new(@config['rayo_server']['transport_log'])
19
18
 
20
- ap "Starting Tropo1Driver to host scripts via DRb and launch calls via HTTP."
21
- @tropo1 = RSpecRayo::Tropo1Driver.new(@config['tropo1']['druby_uri'])
22
-
23
19
  Custom Matchers
24
20
  ---------------
25
21
 
@@ -1,7 +1,36 @@
1
1
  %w{
2
- rspec-rayo/tropo1/driver
2
+ punchblock
3
3
 
4
- rspec-rayo/rayo/driver
5
- rspec-rayo/rayo/call
6
- rspec-rayo/rayo/matchers
4
+ rspec-rayo/version
5
+ rspec-rayo/driver
6
+ rspec-rayo/call
7
+ rspec-rayo/matchers
7
8
  }.each { |lib| require lib }
9
+
10
+ module Punchblock
11
+ class CommandNode
12
+ def await_completion(timeout = 60)
13
+ tap do |c|
14
+ c.response timeout
15
+ end
16
+ end
17
+ end
18
+
19
+ module Component
20
+ class ComponentNode
21
+ attr_accessor :event_queue
22
+
23
+ def initialize(*args)
24
+ super
25
+ @event_queue = Queue.new
26
+ register_event_handler do |event|
27
+ @event_queue << event
28
+ end
29
+ end
30
+
31
+ def next_event(timeout = nil)
32
+ Timeout::timeout(timeout || $config['rayo_queue']['connection_timeout']) { event_queue.pop }
33
+ end
34
+ end
35
+ end
36
+ end
@@ -6,13 +6,14 @@ module RSpecRayo
6
6
  attr_reader :queue
7
7
 
8
8
  def initialize(options)
9
- @call_event = FutureResource.new
10
- self.call_event = options[:call_event] if options[:call_event]
9
+ @offer_event = FutureResource.new
11
10
  @ring_event = FutureResource.new
11
+ @queue = Queue.new
12
+
12
13
  @client = options[:client]
13
- @queue = options[:queue]
14
14
  @read_timeout = options[:read_timeout] || 5
15
15
  @write_timeout = options[:write_timeout] || 5
16
+
16
17
  @status = :offered
17
18
  end
18
19
 
@@ -26,14 +27,6 @@ module RSpecRayo
26
27
  write Punchblock::Command::Answer.new
27
28
  end
28
29
 
29
- def ask(options = {})
30
- write Punchblock::Component::Tropo::Ask.new(options)
31
- end
32
-
33
- def conference(options = {})
34
- write Punchblock::Component::Tropo::Conference.new(options)
35
- end
36
-
37
30
  def dial(options = {})
38
31
  write Punchblock::Command::Dial.new(options)
39
32
  end
@@ -54,14 +47,6 @@ module RSpecRayo
54
47
  end
55
48
  end
56
49
 
57
- def say(options = {})
58
- write Punchblock::Component::Tropo::Say.new(options)
59
- end
60
-
61
- def transfer(options = {})
62
- write Punchblock::Component::Tropo::Transfer.new(options)
63
- end
64
-
65
50
  def record(options = {})
66
51
  write Punchblock::Component::Record.new(options)
67
52
  end
@@ -106,30 +91,45 @@ module RSpecRayo
106
91
  Timeout::timeout(timeout || @read_timeout) { @queue.pop }
107
92
  end
108
93
 
109
- def call_event
110
- @call_event.resource @write_timeout
94
+ def offer_event
95
+ @offer_event.resource @read_timeout
111
96
  end
112
97
 
113
- def call_event=(other)
114
- raise ArgumentError, 'Call event must be a Punchblock::Event::Offer' unless other.is_a? Punchblock::Event::Offer
115
- @call_event.resource = other
116
- @call_id = other.call_id
98
+ def offer_event=(other)
99
+ pb_logger.debug "Setting offer_event to #{other.inspect}"
100
+ @offer_event.resource = other
101
+ @offer_id = other.call_id
117
102
  end
118
103
 
119
- def ring_event
120
- @ring_event.resource @write_timeout
104
+ def ring_event(timeout = @read_timeout)
105
+ @ring_event.resource timeout
121
106
  end
122
107
 
123
108
  def ring_event=(other)
124
- raise ArgumentError, 'Ring event must be a Punchblock::Event::Ringing' unless other.is_a? Punchblock::Event::Ringing
109
+ pb_logger.debug "Setting ring_event to #{other.inspect}"
125
110
  @ring_event.resource = other
126
111
  end
127
112
 
113
+ def <<(event)
114
+ pb_logger.debug "Processing event #{event.inspect}"
115
+ case event
116
+ when Punchblock::Event::Offer
117
+ pb_logger.debug "Received an offer event"
118
+ self.offer_event = event
119
+ when Punchblock::Event::Ringing
120
+ pb_logger.debug "Received a ringing event"
121
+ self.ring_event = event
122
+ when Punchblock::Event::End
123
+ pb_logger.debug "Received an end event"
124
+ @status = :finished
125
+ end
126
+ @queue << event if event
127
+ end
128
+
128
129
  private
129
130
 
130
131
  def write(msg)
131
132
  response = @client.execute_command msg, :call_id => @call_id, :async => false
132
- raise response if response.is_a?(Exception)
133
133
  msg if response
134
134
  end
135
135
  end
@@ -0,0 +1,82 @@
1
+ require 'countdownlatch'
2
+
3
+ module RSpecRayo
4
+ class RayoDriver
5
+ attr_reader :call_queue, :calls
6
+
7
+ def initialize(options)
8
+ @calls = {}
9
+ @call_queue = Queue.new
10
+ @queue_timeout = options.delete(:queue_timeout) || 5
11
+ @write_timeout = options.delete(:write_timeout) || 5
12
+ @threads = []
13
+ @connection_latch = CountDownLatch.new 1
14
+
15
+ initialize_punchblock options
16
+ end
17
+
18
+ def wait_for_connection(timeout = nil)
19
+ @connection_latch.wait timeout
20
+ end
21
+
22
+ def get_call
23
+ Timeout::timeout(@queue_timeout) { @call_queue.pop }
24
+ end
25
+
26
+ def cleanup_calls
27
+ @calls.each_pair do |call_id, call|
28
+ call.hangup unless call.status == :finished
29
+ end
30
+ @calls = {}
31
+ end
32
+
33
+ def dial(options)
34
+ new_call.tap do |call|
35
+ dial = call.dial options
36
+ call.call_id = dial.call_id
37
+ @calls[call.call_id] = call
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ def new_call
44
+ Call.new :client => @pb_client,
45
+ :read_timeout => @queue_timeout,
46
+ :write_timeout => @write_timeout
47
+ end
48
+
49
+ def initialize_punchblock(options)
50
+ logger = Logger.new 'punchblock.log'
51
+
52
+ def logger.trace(*args)
53
+ debug *args
54
+ end
55
+
56
+ Punchblock.logger = logger
57
+
58
+ connection = Punchblock::Connection::XMPP.new options
59
+
60
+ @pb_client = Punchblock::Client.new :connection => connection,
61
+ :write_timeout => options[:write_timeout]
62
+
63
+ @pb_client.register_event_handler do |event|
64
+ if event.is_a?(Punchblock::Connection::Connected)
65
+ logger.info "Connected!"
66
+ @connection_latch.countdown!
67
+ throw :pass
68
+ end
69
+
70
+ if call = @calls[event.call_id]
71
+ @calls[event.call_id] << event
72
+ else
73
+ call = new_call
74
+ @calls[event.call_id] = call
75
+ @call_queue.push call
76
+ end
77
+ end
78
+
79
+ Thread.new { @pb_client.run }
80
+ end
81
+ end
82
+ end
@@ -12,20 +12,17 @@ def match_type(object, type)
12
12
  end
13
13
 
14
14
  %w{
15
- ask
16
15
  call_control
17
- conference
18
16
  dtmf
19
17
  input
20
18
  join
21
19
  output
22
20
  recording
23
- say
24
- transfer
25
- }.each { |matcher| require "rspec-rayo/rayo/matchers/#{matcher}" }
21
+ }.each { |matcher| require "rspec-rayo/matchers/#{matcher}" }
26
22
 
27
23
  RSpec::Matchers.define :have_executed_correctly do
28
24
  match_for_should do |command|
25
+ command.await_completion
29
26
  match_type command, Punchblock::CommandNode do
30
27
  unless command.executing?
31
28
  @error = "expected status to be #{:executing.inspect}, got #{command.state_name}"
@@ -45,9 +42,7 @@ end
45
42
 
46
43
  RSpec::Matchers.define :have_dialed_correctly do
47
44
  match_for_should do |call|
48
- match_type call, RSpecRayo::Call do
49
- call.ring_event.should be_a_valid_ringing_event
50
- end
45
+ match_type call, RSpecRayo::Call
51
46
  end
52
47
 
53
48
  failure_message_for_should do |actual|
@@ -3,14 +3,14 @@ RSpec::Matchers.define :be_a_valid_joined_event do
3
3
  @other_call_id = other_call_id
4
4
  end
5
5
 
6
- chain :with_mixer_id do |mixer_id|
7
- @mixer_id = mixer_id
6
+ chain :with_mixer_name do |mixer_name|
7
+ @mixer_name = mixer_name
8
8
  end
9
9
 
10
10
  match_for_should do |event|
11
11
  match_type event, Punchblock::Event::Joined do
12
12
  @error = "The other call ID was not correct. Expected '#{@other_call_id}', got '#{event.other_call_id}'" if @other_call_id && event.other_call_id != @other_call_id
13
- @error = "The mixer ID was not correct. Expected '#{@mixer_id}', got '#{event.mixer_id}'" if @mixer_id && event.mixer_id != @mixer_id
13
+ @error = "The mixer ID was not correct. Expected '#{@mixer_name}', got '#{event.mixer_name}'" if @mixer_name && event.mixer_name != @mixer_name
14
14
  end
15
15
  end
16
16
 
@@ -21,7 +21,7 @@ RSpec::Matchers.define :be_a_valid_joined_event do
21
21
  description do
22
22
  "be a valid joined event".tap do |d|
23
23
  d << " with other call ID '#{@other_call_id}'" if @other_call_id
24
- d << " with mixer ID '#{@mixer_id}'" if @mixer_id
24
+ d << " with mixer ID '#{@mixer_name}'" if @mixer_name
25
25
  end
26
26
  end
27
27
  end
@@ -31,14 +31,14 @@ RSpec::Matchers.define :be_a_valid_unjoined_event do
31
31
  @other_call_id = other_call_id
32
32
  end
33
33
 
34
- chain :with_mixer_id do |mixer_id|
35
- @mixer_id = mixer_id
34
+ chain :with_mixer_name do |mixer_name|
35
+ @mixer_name = mixer_name
36
36
  end
37
37
 
38
38
  match_for_should do |event|
39
39
  match_type event, Punchblock::Event::Unjoined do
40
40
  @error = "The other call ID was not correct. Expected '#{@other_call_id}', got '#{event.other_call_id}'" if @other_call_id && event.other_call_id != @other_call_id
41
- @error = "The mixer ID was not correct. Expected '#{@mixer_id}', got '#{event.mixer_id}'" if @mixer_id && event.mixer_id != @mixer_id
41
+ @error = "The mixer ID was not correct. Expected '#{@mixer_name}', got '#{event.mixer_name}'" if @mixer_name && event.mixer_name != @mixer_name
42
42
  end
43
43
  end
44
44
 
@@ -49,7 +49,7 @@ RSpec::Matchers.define :be_a_valid_unjoined_event do
49
49
  description do
50
50
  "be a valid unjoined event".tap do |d|
51
51
  d << " with other call ID '#{@other_call_id}'" if @other_call_id
52
- d << " with mixer ID '#{@mixer_id}'" if @mixer_id
52
+ d << " with mixer ID '#{@mixer_name}'" if @mixer_name
53
53
  end
54
54
  end
55
55
  end
@@ -1,3 +1,3 @@
1
1
  module RSpecRayo
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -18,14 +18,14 @@ Gem::Specification.new do |s|
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
20
 
21
- s.add_dependency %q<rspec>, [">= 2.6.0"]
22
- s.add_dependency %q<punchblock>, [">= 0.5.0"]
21
+ s.add_dependency %q<rspec>, [">= 2.9.0.rc1"]
22
+ s.add_dependency %q<punchblock>, [">= 0.9.2"]
23
23
  s.add_dependency %q<countdownlatch>, [">= 1.0.0"]
24
- s.add_dependency %q<future-resource>, [">= 0.0.2"]
24
+ s.add_dependency %q<future-resource>, [">= 1.0.0"]
25
25
 
26
- s.add_development_dependency %q<yard>, ["~> 0.6.0"]
27
- s.add_development_dependency %q<bundler>, ["~> 1.0.0"]
28
- s.add_development_dependency %q<rcov>, [">= 0"]
26
+ s.add_development_dependency %q<yard>, [">= 0.6.0"]
27
+ s.add_development_dependency %q<bundler>, [">= 1.0.0"]
29
28
  s.add_development_dependency %q<rake>, [">= 0"]
30
29
  s.add_development_dependency %q<ci_reporter>, [">= 1.6.3"]
30
+ s.add_development_dependency %q<guard-rspec>
31
31
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe "Rayo call control matchers" do
4
4
  describe "a joined event" do
5
5
  subject do
6
- Punchblock::Event::Joined.new(:other_call_id => 'foo', :mixer_id => 'foo1').tap do |event|
6
+ Punchblock::Event::Joined.new(:other_call_id => 'foo', :mixer_name => 'foo1').tap do |event|
7
7
  event.call_id = '5d6fe904-103d-4551-bd47-cf212c37b8c7'
8
8
  event.component_id = '6d5bf745-8fa9-4e78-be18-6e6a48393f13'
9
9
  end
@@ -12,13 +12,13 @@ describe "Rayo call control matchers" do
12
12
  it { should be_a_valid_joined_event }
13
13
  it { should be_a_valid_joined_event.with_other_call_id('foo') }
14
14
  it { should_not be_a_valid_joined_event.with_other_call_id('bar') }
15
- it { should be_a_valid_joined_event.with_mixer_id('foo1') }
16
- it { should_not be_a_valid_joined_event.with_mixer_id('bar1') }
15
+ it { should be_a_valid_joined_event.with_mixer_name('foo1') }
16
+ it { should_not be_a_valid_joined_event.with_mixer_name('bar1') }
17
17
  end
18
18
 
19
19
  describe "an unjoined event" do
20
20
  subject do
21
- Punchblock::Event::Unjoined.new(:other_call_id => 'foo', :mixer_id => 'foo1').tap do |event|
21
+ Punchblock::Event::Unjoined.new(:other_call_id => 'foo', :mixer_name => 'foo1').tap do |event|
22
22
  event.call_id = '5d6fe904-103d-4551-bd47-cf212c37b8c7'
23
23
  event.component_id = '6d5bf745-8fa9-4e78-be18-6e6a48393f13'
24
24
  end
@@ -27,7 +27,7 @@ describe "Rayo call control matchers" do
27
27
  it { should be_a_valid_unjoined_event }
28
28
  it { should be_a_valid_unjoined_event.with_other_call_id('foo') }
29
29
  it { should_not be_a_valid_unjoined_event.with_other_call_id('bar') }
30
- it { should be_a_valid_unjoined_event.with_mixer_id('foo1') }
31
- it { should_not be_a_valid_unjoined_event.with_mixer_id('bar1') }
30
+ it { should be_a_valid_unjoined_event.with_mixer_name('foo1') }
31
+ it { should_not be_a_valid_unjoined_event.with_mixer_name('bar1') }
32
32
  end
33
33
  end
@@ -1,6 +1,5 @@
1
1
  require 'rspec'
2
2
  require 'rspec-rayo'
3
- require 'punchblock'
4
3
 
5
4
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
6
5
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-rayo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,34 +10,33 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-10-30 01:00:00.000000000 +01:00
14
- default_executable:
13
+ date: 2012-03-14 00:00:00.000000000 Z
15
14
  dependencies:
16
15
  - !ruby/object:Gem::Dependency
17
16
  name: rspec
18
- requirement: &2156850680 !ruby/object:Gem::Requirement
17
+ requirement: &2152810580 !ruby/object:Gem::Requirement
19
18
  none: false
20
19
  requirements:
21
20
  - - ! '>='
22
21
  - !ruby/object:Gem::Version
23
- version: 2.6.0
22
+ version: 2.9.0.rc1
24
23
  type: :runtime
25
24
  prerelease: false
26
- version_requirements: *2156850680
25
+ version_requirements: *2152810580
27
26
  - !ruby/object:Gem::Dependency
28
27
  name: punchblock
29
- requirement: &2156850160 !ruby/object:Gem::Requirement
28
+ requirement: &2152809920 !ruby/object:Gem::Requirement
30
29
  none: false
31
30
  requirements:
32
31
  - - ! '>='
33
32
  - !ruby/object:Gem::Version
34
- version: 0.5.0
33
+ version: 0.9.2
35
34
  type: :runtime
36
35
  prerelease: false
37
- version_requirements: *2156850160
36
+ version_requirements: *2152809920
38
37
  - !ruby/object:Gem::Dependency
39
38
  name: countdownlatch
40
- requirement: &2156849660 !ruby/object:Gem::Requirement
39
+ requirement: &2152809360 !ruby/object:Gem::Requirement
41
40
  none: false
42
41
  requirements:
43
42
  - - ! '>='
@@ -45,43 +44,43 @@ dependencies:
45
44
  version: 1.0.0
46
45
  type: :runtime
47
46
  prerelease: false
48
- version_requirements: *2156849660
47
+ version_requirements: *2152809360
49
48
  - !ruby/object:Gem::Dependency
50
49
  name: future-resource
51
- requirement: &2156849160 !ruby/object:Gem::Requirement
50
+ requirement: &2152824660 !ruby/object:Gem::Requirement
52
51
  none: false
53
52
  requirements:
54
53
  - - ! '>='
55
54
  - !ruby/object:Gem::Version
56
- version: 0.0.2
55
+ version: 1.0.0
57
56
  type: :runtime
58
57
  prerelease: false
59
- version_requirements: *2156849160
58
+ version_requirements: *2152824660
60
59
  - !ruby/object:Gem::Dependency
61
60
  name: yard
62
- requirement: &2156848580 !ruby/object:Gem::Requirement
61
+ requirement: &2152823860 !ruby/object:Gem::Requirement
63
62
  none: false
64
63
  requirements:
65
- - - ~>
64
+ - - ! '>='
66
65
  - !ruby/object:Gem::Version
67
66
  version: 0.6.0
68
67
  type: :development
69
68
  prerelease: false
70
- version_requirements: *2156848580
69
+ version_requirements: *2152823860
71
70
  - !ruby/object:Gem::Dependency
72
71
  name: bundler
73
- requirement: &2156847980 !ruby/object:Gem::Requirement
72
+ requirement: &2152822380 !ruby/object:Gem::Requirement
74
73
  none: false
75
74
  requirements:
76
- - - ~>
75
+ - - ! '>='
77
76
  - !ruby/object:Gem::Version
78
77
  version: 1.0.0
79
78
  type: :development
80
79
  prerelease: false
81
- version_requirements: *2156847980
80
+ version_requirements: *2152822380
82
81
  - !ruby/object:Gem::Dependency
83
- name: rcov
84
- requirement: &2156847440 !ruby/object:Gem::Requirement
82
+ name: rake
83
+ requirement: &2152820500 !ruby/object:Gem::Requirement
85
84
  none: false
86
85
  requirements:
87
86
  - - ! '>='
@@ -89,29 +88,29 @@ dependencies:
89
88
  version: '0'
90
89
  type: :development
91
90
  prerelease: false
92
- version_requirements: *2156847440
91
+ version_requirements: *2152820500
93
92
  - !ruby/object:Gem::Dependency
94
- name: rake
95
- requirement: &2156846840 !ruby/object:Gem::Requirement
93
+ name: ci_reporter
94
+ requirement: &2152818700 !ruby/object:Gem::Requirement
96
95
  none: false
97
96
  requirements:
98
97
  - - ! '>='
99
98
  - !ruby/object:Gem::Version
100
- version: '0'
99
+ version: 1.6.3
101
100
  type: :development
102
101
  prerelease: false
103
- version_requirements: *2156846840
102
+ version_requirements: *2152818700
104
103
  - !ruby/object:Gem::Dependency
105
- name: ci_reporter
106
- requirement: &2156846240 !ruby/object:Gem::Requirement
104
+ name: guard-rspec
105
+ requirement: &2152665400 !ruby/object:Gem::Requirement
107
106
  none: false
108
107
  requirements:
109
108
  - - ! '>='
110
109
  - !ruby/object:Gem::Version
111
- version: 1.6.3
110
+ version: '0'
112
111
  type: :development
113
112
  prerelease: false
114
- version_requirements: *2156846240
113
+ version_requirements: *2152665400
115
114
  description: Rspec2 Matchers for Rayo
116
115
  email: jsgoecke@voxeo.com, ben@langfeld.me
117
116
  executables: []
@@ -121,39 +120,31 @@ files:
121
120
  - .document
122
121
  - .gitignore
123
122
  - .rspec
123
+ - CHANGELOG.md
124
124
  - Gemfile
125
+ - Guardfile
125
126
  - LICENSE.txt
126
127
  - README.md
127
128
  - Rakefile
128
129
  - lib/rspec-rayo.rb
129
- - lib/rspec-rayo/rayo/call.rb
130
- - lib/rspec-rayo/rayo/driver.rb
131
- - lib/rspec-rayo/rayo/matchers.rb
132
- - lib/rspec-rayo/rayo/matchers/ask.rb
133
- - lib/rspec-rayo/rayo/matchers/call_control.rb
134
- - lib/rspec-rayo/rayo/matchers/conference.rb
135
- - lib/rspec-rayo/rayo/matchers/dtmf.rb
136
- - lib/rspec-rayo/rayo/matchers/input.rb
137
- - lib/rspec-rayo/rayo/matchers/join.rb
138
- - lib/rspec-rayo/rayo/matchers/output.rb
139
- - lib/rspec-rayo/rayo/matchers/recording.rb
140
- - lib/rspec-rayo/rayo/matchers/say.rb
141
- - lib/rspec-rayo/rayo/matchers/transfer.rb
142
- - lib/rspec-rayo/tropo1/driver.rb
130
+ - lib/rspec-rayo/call.rb
131
+ - lib/rspec-rayo/driver.rb
132
+ - lib/rspec-rayo/matchers.rb
133
+ - lib/rspec-rayo/matchers/call_control.rb
134
+ - lib/rspec-rayo/matchers/dtmf.rb
135
+ - lib/rspec-rayo/matchers/input.rb
136
+ - lib/rspec-rayo/matchers/join.rb
137
+ - lib/rspec-rayo/matchers/output.rb
138
+ - lib/rspec-rayo/matchers/recording.rb
143
139
  - lib/rspec-rayo/version.rb
144
140
  - rspec-rayo.gemspec
145
- - spec/rspec-rayo/rayo/matchers/ask_spec.rb
146
141
  - spec/rspec-rayo/rayo/matchers/call_control_spec.rb
147
- - spec/rspec-rayo/rayo/matchers/conference_spec.rb
148
142
  - spec/rspec-rayo/rayo/matchers/dtmf_spec.rb
149
143
  - spec/rspec-rayo/rayo/matchers/input_spec.rb
150
144
  - spec/rspec-rayo/rayo/matchers/join_spec.rb
151
145
  - spec/rspec-rayo/rayo/matchers/output_spec.rb
152
- - spec/rspec-rayo/rayo/matchers/say_spec.rb
153
- - spec/rspec-rayo/rayo/matchers/transfer_spec.rb
154
146
  - spec/rspec-rayo/rayo/matchers_spec.rb
155
147
  - spec/spec_helper.rb
156
- has_rdoc: true
157
148
  homepage: http://github.com/tropo/rspec-rayo
158
149
  licenses:
159
150
  - MIT
@@ -175,19 +166,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
166
  version: '0'
176
167
  requirements: []
177
168
  rubyforge_project:
178
- rubygems_version: 1.6.2
169
+ rubygems_version: 1.8.10
179
170
  signing_key:
180
171
  specification_version: 3
181
172
  summary: Rspec2 for Rayo
182
173
  test_files:
183
- - spec/rspec-rayo/rayo/matchers/ask_spec.rb
184
174
  - spec/rspec-rayo/rayo/matchers/call_control_spec.rb
185
- - spec/rspec-rayo/rayo/matchers/conference_spec.rb
186
175
  - spec/rspec-rayo/rayo/matchers/dtmf_spec.rb
187
176
  - spec/rspec-rayo/rayo/matchers/input_spec.rb
188
177
  - spec/rspec-rayo/rayo/matchers/join_spec.rb
189
178
  - spec/rspec-rayo/rayo/matchers/output_spec.rb
190
- - spec/rspec-rayo/rayo/matchers/say_spec.rb
191
- - spec/rspec-rayo/rayo/matchers/transfer_spec.rb
192
179
  - spec/rspec-rayo/rayo/matchers_spec.rb
193
180
  - spec/spec_helper.rb
181
+ has_rdoc:
@@ -1,113 +0,0 @@
1
- module RSpecRayo
2
- class RayoDriver
3
- attr_reader :call_queue, :event_queue, :threads
4
- attr_accessor :calls
5
-
6
- def initialize(options)
7
- @calls = {}
8
- @call_queue = Queue.new
9
- @queue_timeout = options[:queue_timeout] || 5
10
- @write_timeout = options[:write_timeout] || 5
11
- @threads = []
12
-
13
- initialize_rayo options
14
- end
15
-
16
- def get_call
17
- read_queue @call_queue
18
- end
19
-
20
- def cleanup_calls
21
- @calls.each_pair do |call_id, call|
22
- call.hangup unless call.status == :finished
23
- end
24
- @calls = {}
25
- end
26
-
27
- def dial(options)
28
- Call.new(:client => @rayo, :queue => Queue.new, :read_timeout => @queue_timeout, :write_timeout => @write_timeout).tap do |call|
29
- dial = call.dial options
30
- call.call_id = dial.call_id
31
- @calls.merge! call.call_id => call
32
- end
33
- end
34
-
35
- def start_event_dispatcher
36
- @threads << Thread.new do
37
- event = nil
38
-
39
- until event == 'STOP' do
40
- event = @event_queue.pop
41
- case event
42
- when Punchblock::Event::Offer
43
- call = Call.new :call_event => event,
44
- :client => @rayo,
45
- :queue => Queue.new,
46
- :read_timeout => @queue_timeout,
47
- :write_timeout => @write_timeout
48
- @calls.merge! event.call_id => call
49
- @call_queue.push call
50
- when Punchblock::Event::Ringing
51
- call = @calls[event.call_id]
52
- call.ring_event = event if call
53
- else
54
- # Temp based on this nil returned on conference: https://github.com/tropo/punchblock/issues/27
55
- begin
56
- if event.is_a?(Punchblock::Event::End)
57
- @calls[event.call_id].status = :finished
58
- end
59
- @calls[event.call_id].queue.push event unless event.nil?
60
- rescue => error
61
- # Event nil issue to be addressed here: https://github.com/tropo/rspec-rayo/issues/2
62
- end
63
- end
64
- end
65
-
66
- end
67
- end
68
-
69
- def read_queue(queue)
70
- Timeout::timeout(@queue_timeout) { queue.pop }
71
- end
72
-
73
- def initialize_rayo(options)
74
- initialize_logging options
75
-
76
- # Setup our Rayo environment
77
- connection = Punchblock::Connection::XMPP.new :username => options[:username],
78
- :password => options[:password],
79
- :host => options[:host],
80
- :port => options[:port],
81
- :wire_logger => @wire_logger,
82
- :transport_logger => @transport_logger,
83
- :auto_reconnect => false
84
- @rayo = Punchblock::Client.new :connection => connection,
85
- :write_timeout => options[:write_timeout]
86
- @event_queue = @rayo.event_queue
87
-
88
- start_rayo
89
- end
90
-
91
- def initialize_logging(options)
92
- @wire_logger = options[:wire_logger]
93
- @wire_logger.level = options[:log_level]
94
- #@wire_logger.info "Starting up..." if @wire_logger
95
-
96
- @transport_logger = options[:transport_logger]
97
- @transport_logger.level = options[:log_level]
98
- #@transport_logger.info "Starting up..." if @transport_logger
99
- end
100
-
101
- def start_rayo
102
- # Launch the Rayo thread
103
- @threads << Thread.new do
104
- begin
105
- @rayo.run
106
- rescue => e
107
- puts "Exception in XMPP thread! #{e.message}"
108
- puts e.backtrace.join("\t\n")
109
- end
110
- end
111
- end
112
- end
113
- end
@@ -1,60 +0,0 @@
1
- RSpec::Matchers.define :be_a_valid_successful_ask_event do
2
- chain :with_utterance do |utterance|
3
- @utterance = utterance
4
- end
5
-
6
- chain :with_interpretation do |interpretation|
7
- @interpretation = interpretation
8
- end
9
-
10
- match_for_should do |event|
11
- match_type event, Punchblock::Event::Complete do
12
- match_type event.reason, Punchblock::Component::Tropo::Ask::Complete::Success
13
- @error = "The utterance was not correct. Expected '#{@utterance}', got '#{event.reason.utterance}'" if @utterance && event.reason.utterance != @utterance
14
- @error = "The interpretation was not correct. Expected '#{@interpretation}', got '#{event.reason.interpretation}'" if @interpretation && event.reason.interpretation != @interpretation
15
- end
16
- end
17
-
18
- failure_message_for_should do |actual|
19
- "The ask event was not valid: #{@error}"
20
- end
21
-
22
- description do
23
- "be a valid successful ask event".tap do |d|
24
- d << " with utterance '#{@utterance}'" if @utterance
25
- d << " with interpretation '#{@interpretation}'" if @interpretation
26
- end
27
- end
28
- end
29
-
30
- RSpec::Matchers.define :be_a_valid_ask_noinput_event do
31
- match_for_should do |event|
32
- match_type event, Punchblock::Event::Complete do
33
- match_type event.reason, Punchblock::Component::Tropo::Ask::Complete::NoInput
34
- end
35
- end
36
-
37
- failure_message_for_should do |actual|
38
- "The ask event was not valid: #{@error}"
39
- end
40
-
41
- description do
42
- "be a valid noinput ask event"
43
- end
44
- end
45
-
46
- RSpec::Matchers.define :be_a_valid_ask_nomatch_event do
47
- match_for_should do |event|
48
- match_type event, Punchblock::Event::Complete do
49
- match_type event.reason, Punchblock::Component::Tropo::Ask::Complete::NoMatch
50
- end
51
- end
52
-
53
- failure_message_for_should do |actual|
54
- "The ask event was not valid: #{@error}"
55
- end
56
-
57
- description do
58
- "be a valid nomatch ask event"
59
- end
60
- end
@@ -1,73 +0,0 @@
1
- RSpec::Matchers.define :be_a_valid_conference_offhold_event do
2
- match_for_should do |event|
3
- match_type event, Punchblock::Component::Tropo::Conference::OffHold
4
- end
5
-
6
- failure_message_for_should do |actual|
7
- "The ask event was not valid: #{@error}"
8
- end
9
-
10
- description do
11
- "Validate an ask event"
12
- end
13
- end
14
-
15
- RSpec::Matchers.define :be_a_valid_speaking_event do
16
- chain :for_call_id do |call_id|
17
- @call_id = call_id
18
- end
19
-
20
- match_for_should do |event|
21
- match_type event, Punchblock::Component::Tropo::Conference::Speaking do
22
- @error = "The speaking call ID was not correct. Expected '#{@call_id}', got '#{event.speaking_call_id}'" if @call_id && event.speaking_call_id != @call_id
23
- end
24
- end
25
-
26
- failure_message_for_should do |actual|
27
- "The speaking event was not valid: #{@error}"
28
- end
29
-
30
- description do
31
- "be a valid speaking event".tap do |d|
32
- d << " with call ID '#{@call_id}'" if @call_id
33
- end
34
- end
35
- end
36
-
37
- RSpec::Matchers.define :be_a_valid_finished_speaking_event do
38
- chain :for_call_id do |call_id|
39
- @call_id = call_id
40
- end
41
-
42
- match_for_should do |event|
43
- match_type event, Punchblock::Component::Tropo::Conference::FinishedSpeaking do
44
- @error = "The finished-speaking call ID was not correct. Expected '#{@call_id}', got '#{event.speaking_call_id}'" if @call_id && event.speaking_call_id != @call_id
45
- end
46
- end
47
-
48
- failure_message_for_should do |actual|
49
- "The finished speaking event was not valid: #{@error}"
50
- end
51
-
52
- description do
53
- "be a valid finished speaking event".tap do |d|
54
- d << " with call ID '#{@call_id}'" if @call_id
55
- end
56
- end
57
- end
58
-
59
- RSpec::Matchers.define :be_a_valid_conference_complete_terminator_event do
60
- match_for_should do |event|
61
- match_type event, Punchblock::Event::Complete do
62
- match_type event.reason, Punchblock::Component::Tropo::Conference::Complete::Terminator
63
- end
64
- end
65
-
66
- failure_message_for_should do |actual|
67
- "The conference complete terminator event was not valid: #{@error}"
68
- end
69
-
70
- description do
71
- "be a valid conference complete terminator event"
72
- end
73
- end
@@ -1,15 +0,0 @@
1
- RSpec::Matchers.define :be_a_valid_say_event do
2
- match_for_should do |event|
3
- match_type event, Punchblock::Event::Complete do
4
- match_type event.reason, Punchblock::Component::Tropo::Say::Complete::Success
5
- end
6
- end
7
-
8
- failure_message_for_should do |actual|
9
- "The say event was not valid: #{@error}"
10
- end
11
-
12
- description do
13
- "be a valid successful say event"
14
- end
15
- end
@@ -1,31 +0,0 @@
1
- RSpec::Matchers.define :be_a_valid_transfer_event do
2
- match_for_should do |event|
3
- match_type event, Punchblock::Event::Complete do
4
- match_type event.reason, Punchblock::Component::Tropo::Transfer::Complete::Success
5
- end
6
- end
7
-
8
- failure_message_for_should do |actual|
9
- "The transfer event was not valid: #{@error}"
10
- end
11
-
12
- description do
13
- "be a valid transfer event"
14
- end
15
- end
16
-
17
- RSpec::Matchers.define :be_a_valid_transfer_timeout_event do
18
- match_for_should do |event|
19
- match_type event, Punchblock::Event::Complete do
20
- match_type event.reason, Punchblock::Component::Tropo::Transfer::Complete::Timeout
21
- end
22
- end
23
-
24
- failure_message_for_should do |actual|
25
- "The transfer event was not valid: #{@error}"
26
- end
27
-
28
- description do
29
- "be a valid transfer timeout event"
30
- end
31
- end
@@ -1,51 +0,0 @@
1
- module RSpecRayo
2
- class Tropo1Driver
3
- require 'drb'
4
- require 'net/http'
5
- require 'uri'
6
- require 'countdownlatch'
7
-
8
- attr_accessor :script_content, :result, :drb, :config
9
-
10
- def initialize(uri = nil, latch_timeout = 5)
11
- @uri = uri || "druby://0.0.0.0:8787"
12
- @latch_timeout = latch_timeout
13
- @config = {}
14
- reset!
15
- end
16
-
17
- def start_drb
18
- @drb = DRb.start_service @uri, self
19
- end
20
-
21
- def stop_drb
22
- @drb.stop_service
23
- end
24
-
25
- def reset!
26
- @script_content = nil
27
- @result = nil
28
- @latches = {}
29
- end
30
-
31
- def trigger(latch_name)
32
- latch = @latches[latch_name]
33
- raise RuntimeError, "No latch by that name" unless latch
34
- latch.countdown!
35
- end
36
-
37
- def add_latch(latch_name, count = 1)
38
- @latches[latch_name] = CountDownLatch.new count
39
- end
40
-
41
- def wait(latch_name)
42
- latch = @latches[latch_name]
43
- raise RuntimeError, "No latch by that name" unless latch
44
- latch.wait @latch_timeout
45
- end
46
-
47
- def place_call(session_url)
48
- Net::HTTP.get URI.parse(session_url)
49
- end
50
- end
51
- end
@@ -1,43 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Rayo Ask matchers" do
4
- describe "an ask complete event" do
5
- subject do
6
- Punchblock::Event::Complete.new.tap do |event|
7
- event.call_id = '5d6fe904-103d-4551-bd47-cf212c37b8c7'
8
- event.component_id = '6d5bf745-8fa9-4e78-be18-6e6a48393f13'
9
- event << reason
10
- end
11
- end
12
-
13
- describe "that's successful" do
14
- let :reason do
15
- Punchblock::Component::Tropo::Ask::Complete::Success.new.tap do |success|
16
- success << '<utterance>blah</utterance>'
17
- success << '<interpretation>blah</interpretation>'
18
- end
19
- end
20
-
21
- it { should be_a_valid_successful_ask_event }
22
- it { should be_a_valid_successful_ask_event.with_utterance('blah') }
23
- it { should_not be_a_valid_successful_ask_event.with_utterance('woo') }
24
- it { should be_a_valid_successful_ask_event.with_interpretation('blah') }
25
- it { should_not be_a_valid_successful_ask_event.with_interpretation('woo') }
26
- end
27
-
28
- describe "that stopped" do
29
- let(:reason) { Punchblock::Event::Complete::Stop.new }
30
- it { should be_a_valid_complete_stopped_event }
31
- end
32
-
33
- describe "that got no input" do
34
- let(:reason) { Punchblock::Component::Tropo::Ask::Complete::NoInput.new }
35
- it { should be_a_valid_ask_noinput_event }
36
- end
37
-
38
- describe "that got no match" do
39
- let(:reason) { Punchblock::Component::Tropo::Ask::Complete::NoMatch.new }
40
- it { should be_a_valid_ask_nomatch_event }
41
- end
42
- end
43
- end
@@ -1,54 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Rayo Conference matchers" do
4
- describe "a conference event" do
5
- subject do
6
- Punchblock::Component::Tropo::Conference::OffHold.new.tap do |event|
7
- event.call_id = '5d6fe904-103d-4551-bd47-cf212c37b8c7'
8
- event.component_id = '6d5bf745-8fa9-4e78-be18-6e6a48393f13'
9
- end
10
- end
11
-
12
- it { should be_a_valid_conference_offhold_event }
13
- end
14
-
15
- describe "a speaking event" do
16
- subject do
17
- Punchblock::Component::Tropo::Conference::Speaking.new.tap do |event|
18
- event.call_id = '5d6fe904-103d-4551-bd47-cf212c37b8c7'
19
- event.component_id = '6d5bf745-8fa9-4e78-be18-6e6a48393f13'
20
- event.write_attr :'call-id', 'abc123'
21
- end
22
- end
23
-
24
- it { should be_a_valid_speaking_event }
25
- it { should be_a_valid_speaking_event.for_call_id('abc123') }
26
- it { should_not be_a_valid_speaking_event.for_call_id('123abc') }
27
- end
28
-
29
- describe "a finished-speaking event" do
30
- subject do
31
- Punchblock::Component::Tropo::Conference::FinishedSpeaking.new.tap do |event|
32
- event.call_id = '5d6fe904-103d-4551-bd47-cf212c37b8c7'
33
- event.component_id = '6d5bf745-8fa9-4e78-be18-6e6a48393f13'
34
- event.write_attr :'call-id', 'abc123'
35
- end
36
- end
37
-
38
- it { should be_a_valid_finished_speaking_event }
39
- it { should be_a_valid_finished_speaking_event.for_call_id('abc123') }
40
- it { should_not be_a_valid_finished_speaking_event.for_call_id('123abc') }
41
- end
42
-
43
- describe "a conference complete terminator event" do
44
- subject do
45
- Punchblock::Event::Complete.new.tap do |event|
46
- event.call_id = '5d6fe904-103d-4551-bd47-cf212c37b8c7'
47
- event.component_id = '6d5bf745-8fa9-4e78-be18-6e6a48393f13'
48
- event << Punchblock::Component::Tropo::Conference::Complete::Terminator.new
49
- end
50
- end
51
-
52
- it { should be_a_valid_conference_complete_terminator_event }
53
- end
54
- end
@@ -1,23 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Rayo Say matchers" do
4
- describe "a say complete event" do
5
- subject do
6
- Punchblock::Event::Complete.new.tap do |event|
7
- event.call_id = '5d6fe904-103d-4551-bd47-cf212c37b8c7'
8
- event.component_id = '6d5bf745-8fa9-4e78-be18-6e6a48393f13'
9
- event << reason
10
- end
11
- end
12
-
13
- describe "that's successful" do
14
- let(:reason) { Punchblock::Component::Tropo::Say::Complete::Success.new }
15
- it { should be_a_valid_say_event }
16
- end
17
-
18
- describe "that stopped" do
19
- let(:reason) { Punchblock::Event::Complete::Stop.new }
20
- it { should be_a_valid_complete_stopped_event }
21
- end
22
- end
23
- end
@@ -1,23 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Rayo call control matchers" do
4
- describe "a transfer complete event" do
5
- subject do
6
- Punchblock::Event::Complete.new.tap do |event|
7
- event.call_id = '5d6fe904-103d-4551-bd47-cf212c37b8c7'
8
- event.component_id = '6d5bf745-8fa9-4e78-be18-6e6a48393f13'
9
- event << reason
10
- end
11
- end
12
-
13
- describe "that's successful" do
14
- let(:reason) { Punchblock::Component::Tropo::Transfer::Complete::Success.new }
15
- it { should be_a_valid_transfer_event }
16
- end
17
-
18
- describe "that timed out" do
19
- let(:reason) { Punchblock::Component::Tropo::Transfer::Complete::Timeout.new }
20
- it { should be_a_valid_transfer_timeout_event }
21
- end
22
- end
23
- end