spec/punchblock/client_spec.rb in punchblock-1.6.1 vs spec/punchblock/client_spec.rb in punchblock-1.7.0
- old
+ new
@@ -11,31 +11,31 @@
its(:event_queue) { should be_a Queue }
its(:connection) { should be connection }
its(:component_registry) { should be_a Client::ComponentRegistry }
let(:call_id) { 'abc123' }
- let(:mock_event) { stub_everything 'Event' }
+ let(:mock_event) { stub('Event').as_null_object }
let(:component_id) { 'abc123' }
let(:mock_component) { stub 'Component', :component_id => component_id }
let(:mock_command) { stub 'Command' }
describe '#run' do
it 'should start up the connection' do
- connection.expects(:run).once
+ connection.should_receive(:run).once
subject.run
end
end
describe '#stop' do
it 'should stop the connection' do
- connection.expects(:stop).once
+ connection.should_receive(:stop).once
subject.stop
end
end
it 'should handle connection events' do
- subject.expects(:handle_event).with(mock_event).once
+ subject.should_receive(:handle_event).with(mock_event).once
connection.event_handler.call mock_event
end
describe '#handle_event' do
it "sets the event's client" do
@@ -44,38 +44,40 @@
event.client.should be subject
end
context 'if the event can be associated with a source component' do
before do
- mock_event.stubs(:source).returns mock_component
- mock_component.expects(:add_event).with mock_event
+ mock_event.stub :source => mock_component
+ mock_component.should_receive(:add_event).with mock_event
end
it 'should not queue up the event' do
subject.handle_event mock_event
subject.event_queue.should be_empty
end
it 'should not call event handlers' do
handler = mock 'handler'
- handler.expects(:call).never
+ handler.should_receive(:call).never
subject.register_event_handler do |event|
handler.call event
- throw :halt
end
subject.handle_event mock_event
end
end
context 'if the event cannot be associated with a source component' do
+ before do
+ mock_event.stub :source => nil
+ end
+
context 'if event handlers have been set' do
it 'should call the event handler and not queue up the event' do
handler = mock 'handler'
- handler.expects(:call).once.with mock_event
+ handler.should_receive(:call).once.with mock_event
subject.register_event_handler do |event|
handler.call event
- throw :halt
end
subject.handle_event mock_event
subject.event_queue.should be_empty
end
end
@@ -97,11 +99,11 @@
describe '#execute_command' do
let(:component) { Component::Output.new }
let(:event) { Event::Complete.new }
before do
- connection.expects(:write).once.with component, :call_id => call_id
+ connection.should_receive(:write).once.with component, :call_id => call_id
end
let :execute_command do
subject.execute_command component, :call_id => call_id
end
@@ -114,10 +116,10 @@
execute_command
component.client.should be subject
end
it "should handle a component's events" do
- subject.expects(:trigger_handler).with(:event, event).once
+ subject.should_receive(:trigger_handler).with(:event, event).once
execute_command
component.request!
component.execute!
component.add_event event
end