spec/nexmos/account_spec.rb in nexmos-0.2 vs spec/nexmos/account_spec.rb in nexmos-0.3

- old
+ new

@@ -43,11 +43,11 @@ {"code" => "24405", "network" => "elisa", "ranges" => ["35846", "35850"], "mtPrice" => "0.05000000"}], "name" => "Finland" - } + }.to_json end let(:prefix_prices) do {"count" => 1, "prices" => @@ -78,11 +78,11 @@ {"code" => "24405", "network" => "elisa", "ranges" => nil, "mtPrice" => "0.05000000"}], "name" => "Finland"}], - } + }.to_json end before(:each) do ::Nexmos.reset! ::Nexmos.setup do |c| @@ -95,93 +95,99 @@ context '#get_balance' do it 'should return value' do request = stub_request(:get, "https://rest.nexmo.com/account/get-balance?api_key=default_key&api_secret=default_secret"). - with(webmock_default_headers).to_return(:status => 200, :body => {"value" => 4.107}, :headers => {}) + with(webmock_default_headers).to_return(:status => 200, :body => {"value" => 4.107}.to_json, headers: {'Content-Type' => 'application/json'}) res = subject.get_balance - res.should be_kind_of(::Hash) - res.value.should == 4.107 - request.should have_been_made.once + expect(res).to be_kind_of(::Hash) + expect(res.value).to eq(4.107) + expect(request).to have_been_made.once end end context '#get_pricing' do it 'should return error on missed param' do expect { subject.get_pricing }.to raise_error('country params required') end it 'should be success' do request = stub_request(:get, "https://rest.nexmo.com/account/get-pricing/outbound?api_key=default_key&api_secret=default_secret&country=FI"). - with(webmock_default_headers).to_return(:status => 200, :body => finland_prices, :headers => {}) + with(webmock_default_headers).to_return(:status => 200, :body => finland_prices, :headers => {'Content-Type' => 'application/json'}) res = subject.get_pricing(:country => 'FI') - res.should be_kind_of(::Hash) - res.success?.should be_true - res.country.should == 'FI' - res.keys.sort.should == %w(country name prefix mt networks success?).sort - res.networks.should be_kind_of(::Array) - res.networks[0].keys.sort.should == %w(code network mt_price ranges).sort - request.should have_been_made.once + expect(res).to be_kind_of(::Hash) + expect(res.success?).to be_truthy + expect(res.country).to eq('FI') + expect(res.keys.sort).to eq(%w(country name prefix mt networks success?).sort) + expect(res.networks).to be_kind_of(::Array) + expect(res.networks[0].keys.sort).to eq(%w(code network mt_price ranges).sort) + expect(request).to have_been_made.once end end context '#get_prefix_pricing' do it 'should return error on missed param' do expect { subject.get_prefix_pricing }.to raise_error('prefix params required') end it 'should be success' do request = stub_request(:get, "https://rest.nexmo.com/account/get-prefix-pricing/outbound?api_key=default_key&api_secret=default_secret&prefix=358"). - with(webmock_default_headers).to_return(:status => 200, :body => prefix_prices, :headers => {}) + with(webmock_default_headers).to_return(:status => 200, :body => prefix_prices, :headers => {'Content-Type' => 'application/json'}) res = subject.get_prefix_pricing(:prefix => '358') - res.should be_kind_of(::Hash) - res.success?.should be_true - res.keys.sort.should == %w(count prices success?).sort - res.prices.should be_kind_of(::Array) - res.prices[0].keys.sort.should == %w(country name prefix mt networks).sort - res.prices[0].networks.should be_kind_of(::Array) - res.prices[0].networks[0].keys.sort.should == %w(code network mt_price ranges).sort - request.should have_been_made.once + expect(res).to be_kind_of(::Hash) + expect(res.success?).to be_truthy + expect(res.keys.sort).to eq(%w(count prices success?).sort) + expect(res.prices).to be_kind_of(::Array) + expect(res.prices[0].keys.sort).to eq(%w(country name prefix mt networks).sort) + expect(res.prices[0].networks).to be_kind_of(::Array) + expect(res.prices[0].networks[0].keys.sort).to eq(%w(code network mt_price ranges).sort) + expect(request).to have_been_made.once end end context '#get_numbers' do it 'should return only count on empty numbers' do request = stub_request(:get, "https://rest.nexmo.com/account/numbers?api_key=default_key&api_secret=default_secret"). - with(webmock_default_headers).to_return(:status => 200, :body => {:count => 0}, :headers => {}) + with(webmock_default_headers).to_return(:status => 200, :body => {:count => 0}.to_json, :headers => {'Content-Type' => 'application/json'}) res = subject.get_numbers - res.should be_kind_of(::Hash) - res.success?.should be_true - res['count'].should == 0 - request.should have_been_made.once + expect(res).to be_kind_of(::Hash) + expect(res.success?).to be_truthy + expect(res['count']).to eq(0) + expect(request).to have_been_made.once end it 'should return numbers array' do request = stub_request(:get, "https://rest.nexmo.com/account/numbers?api_key=default_key&api_secret=default_secret"). - with(webmock_default_headers).to_return(:status => 200, :body => { "count" => 1,"numbers" => [{"country" => "ES","msisdn" => "34911067000","type" => "landline"}]}, :headers => {}) + with(webmock_default_headers).to_return(:status => 200, + :body => { + "count" => 1, + "numbers" => [ + {"country" => "ES","msisdn" => "34911067000","type" => "landline"} + ] + }.to_json, :headers => {'Content-Type' => 'application/json'}) res = subject.get_numbers - res.should be_kind_of(::Hash) - res.success?.should be_true - res['count'].should == 1 - res['numbers'].should be_kind_of(::Array) - res['numbers'].first.should be_kind_of(::Hash) - res['numbers'].first.should == {"country" => "ES","msisdn" => "34911067000","type" => "landline"} - request.should have_been_made.once + expect(res).to be_kind_of(::Hash) + expect(res.success?).to be_truthy + expect(res['count']).to eq(1) + expect(res['numbers']).to be_kind_of(::Array) + expect(res['numbers'].first).to be_kind_of(::Hash) + expect(res['numbers'].first).to eq({"country" => "ES","msisdn" => "34911067000","type" => "landline"}) + expect(request).to have_been_made.once end end context '#top_up' do it 'should return error on missed param' do expect { subject.top_up }.to raise_error('trx params required') end it 'should success top up' do request = stub_request(:get, "https://rest.nexmo.com/account/top-up?api_key=default_key&api_secret=default_secret&trx=test_trx"). - with(webmock_default_headers).to_return(:status => 200, :body => '', :headers => {}) + with(webmock_default_headers).to_return(:status => 200, :body => '', :headers => {'Content-Type' => 'application/json'}) res = subject.top_up :trx => 'test_trx' - res.should be_kind_of(::Hash) - res.success?.should be_true - request.should have_been_made.once + expect(res).to be_kind_of(::Hash) + expect(res.success?).to be_truthy + expect(request).to have_been_made.once end end end