diff --git a/.travis.yml b/.travis.yml index 31ff307..aabac48 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,19 @@ +dist: xenial language: ruby -sudo: false rvm: - - 2.2.5 - - 2.3.1 - - jruby-9.1.2.0 + - 2.2.10 + - 2.3.8 + - 2.4.5 + - 2.5.3 + - 2.6.3 + - jruby-9.1.17.0 + - jruby - ruby-head +jdk: + - openjdk8 # for jruby matrix: allow_failures: - rvm: ruby-head +before_install: rvm list notifications: irc: "irc.freenode.org#adhearsion" diff --git a/cucumber.yml b/cucumber.yml index 6455645..8ef1b52 100644 --- a/cucumber.yml +++ b/cucumber.yml @@ -1,2 +1,2 @@ -default: --tags ~@wip +default: --strict --tags ~@wip wip: --wip --tags @wip diff --git a/ruby_ami.gemspec b/ruby_ami.gemspec index 64d8452..d502928 100644 --- a/ruby_ami.gemspec +++ b/ruby_ami.gemspec @@ -23,9 +23,9 @@ Gem::Specification.new do |s| s.add_runtime_dependency %q, ["~> 0.13"] s.add_runtime_dependency %q, ["~> 0.16.0"] - s.add_development_dependency %q, ["~> 1.0"] - s.add_development_dependency %q, ["~> 2.5"] - s.add_development_dependency %q, [">= 0"] + s.add_development_dependency %q, [">= 1.0"] + s.add_development_dependency %q, [">= 3.0"] + s.add_development_dependency %q, ["< 3.0"] s.add_development_dependency %q, ["~> 0.6"] s.add_development_dependency %q, [">= 0"] s.add_development_dependency %q diff --git a/spec/ruby_ami/action_spec.rb b/spec/ruby_ami/action_spec.rb index 278d4e5..7ca79ba 100644 --- a/spec/ruby_ami/action_spec.rb +++ b/spec/ruby_ami/action_spec.rb @@ -12,30 +12,30 @@ module RubyAMI end end - it { should_not be_complete } + it { is_expected.not_to be_complete } describe "SIPPeers actions" do it "has causal events" do - Action.new('SIPPeers').has_causal_events?.should be true + expect(Action.new('SIPPeers').has_causal_events?).to be true end end describe "the ParkedCalls terminator event" do it "knows its causal event terminator name" do - Action.new('ParkedCalls').causal_event_terminator_name.should == "parkedcallscomplete" + expect(Action.new('ParkedCalls').causal_event_terminator_name).to eq("parkedcallscomplete") end end it "should properly convert itself into a String when additional headers are given" do string = Action.new("Hawtsawce", "Monkey" => "Zoo").to_s - string.should =~ /^Action: Hawtsawce\r\n/i - string.should =~ /[^\n]\r\n\r\n$/ - string.should =~ /^(\w+:\s*[\w-]+\r\n){3}\r\n$/ + expect(string).to match(/^Action: Hawtsawce\r\n/i) + expect(string).to match(/[^\n]\r\n\r\n$/) + expect(string).to match(/^(\w+:\s*[\w-]+\r\n){3}\r\n$/) end it "should properly convert itself into a String when no additional headers are given" do - Action.new("Ping").to_s.should =~ /^Action: Ping\r\nActionID: [\w-]+\r\n\r\n$/i - Action.new("ParkedCalls").to_s.should =~ /^Action: ParkedCalls\r\nActionID: [\w-]+\r\n\r\n$/i + expect(Action.new("Ping").to_s).to match(/^Action: Ping\r\nActionID: [\w-]+\r\n\r\n$/i) + expect(Action.new("ParkedCalls").to_s).to match(/^Action: ParkedCalls\r\nActionID: [\w-]+\r\n\r\n$/i) end describe '#<<' do @@ -46,14 +46,14 @@ module RubyAMI before { subject << response } it 'should set the response' do - subject.response.should be response + expect(subject.response).to be response end it 'should call the callback' do - @callback_result.should be response + expect(@callback_result).to be response end - it { should be_complete } + it { is_expected.to be_complete } end context 'with an error' do @@ -62,15 +62,15 @@ module RubyAMI before { subject << error } it 'should set the response' do - subject.response.should == error + expect(subject.response).to eq(error) end - it { should be_complete } + it { is_expected.to be_complete } end context 'with an event' do it 'should raise an error' do - lambda { subject << Event.new('foo') }.should raise_error StandardError, /causal action/ + expect { subject << Event.new('foo') }.to raise_error StandardError, /causal action/ end end end @@ -82,7 +82,7 @@ module RubyAMI context 'with a response' do before { subject << response } - it { should_not be_complete } + it { is_expected.not_to be_complete } end context 'with an event' do @@ -91,7 +91,7 @@ module RubyAMI before { subject << response << event } it "should add the events to the response" do - subject.response.events.should == [event] + expect(subject.response.events).to eq([event]) end end @@ -100,17 +100,17 @@ module RubyAMI before do subject << response - subject.should_not be_complete + expect(subject).not_to be_complete subject << event end it "should add the events to the response" do - subject.response.events.should == [event] + expect(subject.response.events).to eq([event]) end - it { should be_complete } + it { is_expected.to be_complete } - it { subject.response.should be response } + it { expect(subject.response).to be response } end end end @@ -119,21 +119,21 @@ module RubyAMI describe 'with another Action' do context 'with identical name and headers' do let(:other) { Action.new name, headers } - it { should == other } + it { is_expected.to eq(other) } end context 'with identical name and different headers' do let(:other) { Action.new name, 'boo' => 'baz' } - it { should_not == other } + it { is_expected.not_to eq(other) } end context 'with different name and identical headers' do let(:other) { Action.new 'BARBAZ', headers } - it { should_not == other } + it { is_expected.not_to eq(other) } end end - it { should_not == :foo } + it { is_expected.not_to eq(:foo) } end end # Action end # RubyAMI diff --git a/spec/ruby_ami/agi_result_parser_spec.rb b/spec/ruby_ami/agi_result_parser_spec.rb index 8359e27..d61c56d 100644 --- a/spec/ruby_ami/agi_result_parser_spec.rb +++ b/spec/ruby_ami/agi_result_parser_spec.rb @@ -16,46 +16,46 @@ module RubyAMI context 'with a simple result with no data' do let(:result_string) { "200%20result=123%0A" } - it { subject.code.should == 200 } - it { subject.result.should == 123 } - it { subject.data.should == '' } - it { subject.data_hash.should == nil } + it { expect(subject.code).to eq(200) } + it { expect(subject.result).to eq(123) } + it { expect(subject.data).to eq('') } + it { expect(subject.data_hash).to eq(nil) } end context 'with a simple unescaped result with no data' do let(:result_string) { "200 result=123" } - it { subject.code.should == 200 } - it { subject.result.should == 123 } - it { subject.data.should == '' } - it { subject.data_hash.should == nil } + it { expect(subject.code).to eq(200) } + it { expect(subject.result).to eq(123) } + it { expect(subject.data).to eq('') } + it { expect(subject.data_hash).to eq(nil) } end context 'with a result and data in parens' do let(:result_string) { "200%20result=-123%20(timeout)%0A" } - it { subject.code.should == 200 } - it { subject.result.should == -123 } - it { subject.data.should == 'timeout' } - it { subject.data_hash.should == nil } + it { expect(subject.code).to eq(200) } + it { expect(subject.result).to eq(-123) } + it { expect(subject.data).to eq('timeout') } + it { expect(subject.data_hash).to eq(nil) } end context 'with a result and key-value data' do let(:result_string) { "200%20result=123%20foo=bar%0A" } - it { subject.code.should == 200 } - it { subject.result.should == 123 } - it { subject.data.should == 'foo=bar' } - it { subject.data_hash.should == {'foo' => 'bar'} } + it { expect(subject.code).to eq(200) } + it { expect(subject.result).to eq(123) } + it { expect(subject.data).to eq('foo=bar') } + it { expect(subject.data_hash).to eq({'foo' => 'bar'}) } end context 'with a 5xx error' do let(:result_string) { "510%20Invalid%20or%20unknown%20command%0A" } - it { subject.code.should == 510 } - it { subject.result.should be_nil } - it { subject.data.should == 'Invalid or unknown command' } - it { subject.data_hash.should be_nil } + it { expect(subject.code).to eq(510) } + it { expect(subject.result).to be_nil } + it { expect(subject.data).to eq('Invalid or unknown command') } + it { expect(subject.data_hash).to be_nil } end end end diff --git a/spec/ruby_ami/async_agi_environment_parser_spec.rb b/spec/ruby_ami/async_agi_environment_parser_spec.rb index f7e6593..2bff8da 100644 --- a/spec/ruby_ami/async_agi_environment_parser_spec.rb +++ b/spec/ruby_ami/async_agi_environment_parser_spec.rb @@ -9,12 +9,12 @@ module RubyAMI subject { described_class.new environment_string } - it { subject.to_s.should == environment_string } - it { subject.to_s.should_not be environment_string } + it { expect(subject.to_s).to eq(environment_string) } + it { expect(subject.to_s).not_to be environment_string } describe 'retrieving a hash representation' do it "should return a hash of attributes" do - subject.to_hash.should == { + expect(subject.to_hash).to eq({ :agi_request => 'async', :agi_channel => 'SIP/1234-00000000', :agi_language => 'en', @@ -35,11 +35,11 @@ module RubyAMI :agi_enhanced => '0.0', :agi_accountcode => '', :agi_threadid => '4366221312' - } + }) end it "should not return the same hash object every time" do - subject.to_hash.should_not be subject.to_hash + expect(subject.to_hash).not_to be subject.to_hash end end end diff --git a/spec/ruby_ami/event_spec.rb b/spec/ruby_ami/event_spec.rb index 104b4b3..e8c0723 100644 --- a/spec/ruby_ami/event_spec.rb +++ b/spec/ruby_ami/event_spec.rb @@ -8,11 +8,11 @@ module RubyAMI describe "#receipt_time" do before do @now = DateTime.now - DateTime.stub now: @now + allow(DateTime).to receive_messages now: @now end it "should be the time the object was created (event receipt time)" do - subject.receipt_time.should == @now + expect(subject.receipt_time).to eq(@now) end end @@ -21,13 +21,13 @@ module RubyAMI describe "#timestamp" do it "should be a time object representing the event's timestamp (assuming UTC)" do - subject.timestamp.should == DateTime.new(2014, 2, 25, 22, 46, 20) + expect(subject.timestamp).to eq(DateTime.new(2014, 2, 25, 22, 46, 20)) end end describe "#best_time" do it "should be the timestamp" do - subject.best_time.should == subject.timestamp + expect(subject.best_time).to eq(subject.timestamp) end end end @@ -35,13 +35,13 @@ module RubyAMI context "when the event does not have a timestamp" do describe "#timestamp" do it "should be nil" do - subject.timestamp.should be_nil + expect(subject.timestamp).to be_nil end end describe "#best_time" do it "should be the receipt_time" do - subject.best_time.should == subject.receipt_time + expect(subject.best_time).to eq(subject.receipt_time) end end end @@ -63,7 +63,7 @@ module RubyAMI end it "should be equal" do - event1.should be == event2 + expect(event1).to eq(event2) end end @@ -83,7 +83,7 @@ module RubyAMI end it "should not be equal" do - event1.should_not be == event2 + expect(event1).not_to eq(event2) end end @@ -103,7 +103,7 @@ module RubyAMI end it "should not be equal" do - event1.should_not be == event2 + expect(event1).not_to eq(event2) end end end diff --git a/spec/ruby_ami/response_spec.rb b/spec/ruby_ami/response_spec.rb index cec5e47..be9fccb 100644 --- a/spec/ruby_ami/response_spec.rb +++ b/spec/ruby_ami/response_spec.rb @@ -18,7 +18,7 @@ module RubyAMI end it "should be equal" do - event1.should be == event2 + expect(event1).to eq(event2) end end @@ -36,7 +36,7 @@ module RubyAMI end it "should not be equal" do - event1.should_not be == event2 + expect(event1).not_to eq(event2) end end end diff --git a/spec/ruby_ami/stream_spec.rb b/spec/ruby_ami/stream_spec.rb index 1c1c8e5..41d4b0a 100644 --- a/spec/ruby_ami/stream_spec.rb +++ b/spec/ruby_ami/stream_spec.rb @@ -29,9 +29,11 @@ def client.messages let(:username) { nil } let(:password) { nil } - def mocked_server(times = nil, fake_client = nil, &block) + def mocked_server(times = nil, fake_client = nil, &argument_matcher) mock_target = MockServer.new - mock_target.should_receive(:receive_data).send(*(times ? [:exactly, times] : [:at_least, 1]), &block) + expect(mock_target).to receive(:receive_data) do |*args| + argument_matcher.call *args + end.send(*(times ? [:exactly, times] : [:at_least, 1])) s = ServerMock.new '127.0.0.1', server_port, mock_target @stream = Stream.new '127.0.0.1', server_port, username, password, lambda { |m, stream| client.message_received m, stream } fake_client.call if fake_client.respond_to? :call @@ -46,11 +48,11 @@ def mocked_server(times = nil, fake_client = nil, &block) describe "after connection" do it "should be started" do - mocked_server 0, -> { @stream.started?.should be true } - client_messages.should be == [ + mocked_server 0, -> { expect(@stream.started?).to be true } + expect(client_messages).to eq([ [Stream::Connected.new, @stream], [Stream::Disconnected.new, @stream], - ] + ]) end it "stores the reported AMI version" do @@ -72,7 +74,7 @@ def mocked_server(times = nil, fake_client = nil, &block) it "can send an action" do mocked_server(1, lambda { @stream.send_action('Command') }) do |val, server| - val.should == <<-ACTION + expect(val).to eq <<-ACTION Action: command\r ActionID: #{RubyAMI.new_uuid}\r \r @@ -89,7 +91,7 @@ def mocked_server(times = nil, fake_client = nil, &block) it "can send an action with headers" do mocked_server(1, lambda { @stream.send_action('Command', 'Command' => 'RECORD FILE evil') }) do |val, server| - val.should == <<-ACTION + expect(val).to eq <<-ACTION Action: command\r ActionID: #{RubyAMI.new_uuid}\r Command: RECORD FILE evil\r @@ -109,7 +111,7 @@ def mocked_server(times = nil, fake_client = nil, &block) action_id = RubyAMI.new_uuid response = nil mocked_server(1, lambda { response = @stream.send_action('Command', 'Command' => 'dialplan add extension 1,1,AGI,agi:async into adhearsion-redirect') }) do |val, server| - val.should == <<-ACTION + expect(val).to eq <<-ACTION Action: command\r ActionID: #{action_id}\r Command: dialplan add extension 1,1,AGI,agi:async into adhearsion-redirect\r @@ -128,7 +130,7 @@ def mocked_server(times = nil, fake_client = nil, &block) expected_response = Response.new 'Privilege' => 'Command', 'ActionID' => action_id expected_response.text_body = %q{Extension '1,1,AGI(agi:async)' added into 'adhearsion-redirect' context} - response.should == expected_response + expect(response).to eq(expected_response) end context "with a username and password set" do @@ -137,7 +139,7 @@ def mocked_server(times = nil, fake_client = nil, &block) it "should log itself in" do mocked_server(1, lambda { }) do |val, server| - val.should == <<-ACTION + expect(val).to eq <<-ACTION Action: login\r ActionID: #{RubyAMI.new_uuid}\r Username: fred\r @@ -168,11 +170,11 @@ def mocked_server(times = nil, fake_client = nil, &block) EVENT end - client_messages.should be == [ + expect(client_messages).to eq([ [Stream::Connected.new, @stream], [Event.new('Hangup', 'Channel' => 'SIP/101-3f3f', 'Uniqueid' => '1094154427.10', 'Cause' => '0'), @stream], [Stream::Disconnected.new, @stream], - ] + ]) end describe 'when a response is received' do @@ -187,7 +189,7 @@ def mocked_server(times = nil, fake_client = nil, &block) EVENT end - response.should == Response.new('ActionID' => RubyAMI.new_uuid, 'Message' => 'Recording started') + expect(response).to eq(Response.new('ActionID' => RubyAMI.new_uuid, 'Message' => 'Recording started')) end it 'should handle disconnect as a Response' do @@ -201,7 +203,7 @@ def mocked_server(times = nil, fake_client = nil, &block) EVENT end - response.should == Response.new('ActionID' => RubyAMI.new_uuid, 'Message' => 'Thanks for all the fish.') + expect(response).to eq(Response.new('ActionID' => RubyAMI.new_uuid, 'Message' => 'Thanks for all the fish.')) end describe 'when it is an error' do @@ -209,7 +211,7 @@ def mocked_server(times = nil, fake_client = nil, &block) it 'should be raised by #send_action, but not kill the stream' do send_action = lambda do expect { @stream.send_action 'status' }.to raise_error(RubyAMI::Error, 'Action failed') - @stream.should be_alive + expect(@stream).to be_alive end mocked_server(1, send_action) do |val, server| @@ -225,11 +227,11 @@ def mocked_server(times = nil, fake_client = nil, &block) describe 'when there is an error handler' do it 'should call the error handler' do - error_handler = lambda { |resp| resp.should be_a_kind_of RubyAMI::Error } + error_handler = lambda { |resp| expect(resp).to be_a_kind_of RubyAMI::Error } send_action = lambda do expect { @stream.send_action 'status', {}, error_handler }.to_not raise_error - @stream.should be_alive + expect(@stream).to be_alive end mocked_server(1, send_action) do |val, server| @@ -279,32 +281,32 @@ def mocked_server(times = nil, fake_client = nil, &block) EVENT end - response.should == expected_response + expect(response).to eq(expected_response) end end end it 'puts itself in the stopped state and fires a disconnected event when unbound' do mocked_server(1, lambda { @stream.send_data 'Foo' }) do |val, server| - @stream.stopped?.should be false + expect(@stream.stopped?).to be false end - @stream.alive?.should be false - client_messages.should be == [ + expect(@stream.alive?).to be false + expect(client_messages).to eq([ [Stream::Connected.new, @stream], [Stream::Disconnected.new, @stream], - ] + ]) end end describe Stream::Connected do it "has a name matching the class" do - subject.name.should == 'RubyAMI::Stream::Connected' + expect(subject.name).to eq('RubyAMI::Stream::Connected') end end describe Stream::Disconnected do it "has a name matching the class" do - subject.name.should == 'RubyAMI::Stream::Disconnected' + expect(subject.name).to eq('RubyAMI::Stream::Disconnected') end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 97744f5..debfcb0 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -14,6 +14,6 @@ config.before :each do uuid = RubyAMI.new_uuid - RubyAMI.stub :new_uuid => uuid + allow(RubyAMI).to receive_messages :new_uuid => uuid end end