debian-mirror-gitlab/spec/initializers/sawyer_patch_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

50 lines
1.7 KiB
Ruby
Raw Normal View History

2022-09-01 20:07:04 +05:30
# frozen_string_literal: true
2023-01-13 00:05:48 +05:30
2022-11-25 23:54:43 +05:30
require 'spec_helper'
2022-09-01 20:07:04 +05:30
require 'sawyer'
require_relative '../../config/initializers/sawyer_patch'
RSpec.describe 'sawyer_patch' do
2023-01-13 00:05:48 +05:30
it 'raises error when acessing Sawyer Resource dynamic methods' do
2022-09-01 20:07:04 +05:30
sawyer_resource = Sawyer::Resource.new(
Sawyer::Agent.new(''),
{
to_s: 'Overriding method',
2023-01-13 00:05:48 +05:30
nil?: 'value',
login: 'Login',
2022-09-01 20:07:04 +05:30
user: { to_s: 'Overriding method', name: 'User name' }
}
)
2023-01-13 00:05:48 +05:30
expect { sawyer_resource.to_s }.to raise_error(Sawyer::Error)
expect { sawyer_resource.to_s? }.to raise_error(Sawyer::Error)
expect { sawyer_resource.to_s = 'new value' }.to raise_error(Sawyer::Error)
2022-09-01 20:07:04 +05:30
expect { sawyer_resource.nil? }.to raise_error(Sawyer::Error)
2023-01-13 00:05:48 +05:30
expect { sawyer_resource.user.to_s }.to raise_error(Sawyer::Error)
expect { sawyer_resource.login }.to raise_error(Sawyer::Error)
expect { sawyer_resource.login? }.to raise_error(Sawyer::Error)
expect { sawyer_resource.login = 'New value' }.to raise_error(Sawyer::Error)
expect { sawyer_resource.user.name }.to raise_error(Sawyer::Error)
expect { sawyer_resource.user.name? }.to raise_error(Sawyer::Error)
expect { sawyer_resource.user.name = 'New value' }.to raise_error(Sawyer::Error)
2022-09-01 20:07:04 +05:30
end
it 'raises error when acessing a method that expects an argument' do
sawyer_resource = Sawyer::Resource.new(
Sawyer::Agent.new(''),
{
'user': 'value',
'user=': 'value',
'==': 'value',
'!=': 'value',
'+': 'value'
}
)
expect { sawyer_resource == true }.to raise_error(ArgumentError)
expect { sawyer_resource != true }.to raise_error(ArgumentError)
expect { sawyer_resource + 1 }.to raise_error(ArgumentError)
end
end