Skip to content

Commit

Permalink
Add more status methods
Browse files Browse the repository at this point in the history
Add `#closing?`, `#closed?` and aliases `#open?` -> `#connected?`.
  • Loading branch information
syndbg committed Mar 28, 2016
1 parent 31afe42 commit 43a5eb4
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 4 deletions.
21 changes: 19 additions & 2 deletions lib/bunny_mock/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ def start
# @return [BunnyMock::Session] self
# @api public
def stop

@status = :closed

self
Expand All @@ -64,9 +63,27 @@ def stop
# @return [Boolean] true if status is connected, false otherwise
# @api public
def open?

@status == :connected
end
alias connected? open?

##
# Tests if connection is closed
#
# @return [Boolean] true if status is closed, false otherwise
# @api public
def closed?
@status == :closed
end

##
# Tests if connection is closing
#
# @return [Boolean] true if status is closing, false otherwise
# @api public
def closing?
@status == :closing
end

##
# Creates a new {BunnyMock::Channel} instance
Expand Down
65 changes: 63 additions & 2 deletions spec/unit/bunny_mock/session_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
end
end

context '#open?' do
context '#open? (connected?)' do

it 'should return true if status is open' do
@session.start
Expand All @@ -45,8 +45,69 @@
end
end

context '#create_channel (channel)' do
describe '#closed?' do
context 'with `not_connected` status' do
it do
expect(@session.closed?).to be_falsey
end
end

context 'with `connected` status' do
it do
@session.start
expect(@session.closed?).to be_falsey
end
end

context 'with `closing` status' do
it do
# Mock `closing` status
@session.instance_variable_set('@status', :closing)
expect(@session.closed?).to be_falsey
end
end

context 'with `closed` status' do
it do
@session.start
@session.close
expect(@session.closed?).to be_truthy
end
end
end

describe '#closing?' do
context 'with `not_connected` status' do
it do
expect(@session.closing?).to be_falsey
end
end

context 'with `connected` status' do
it do
@session.start
expect(@session.closing?).to be_falsey
end
end

context 'with `closing` status' do
it do
# Mock `closing` status
@session.instance_variable_set('@status', :closing)
expect(@session.closing?).to be_truthy
end
end

context 'with `closed` status' do
it do
@session.start
@session.close
expect(@session.closing?).to be_falsey
end
end
end

context '#create_channel (channel)' do
it 'should create a new channel with no arguments' do
first = @session.create_channel
second = @session.create_channel
Expand Down

0 comments on commit 43a5eb4

Please sign in to comment.