I am fairly new to rspec test and I have an issue trying to test the location of a user. This a test to mock the behaviour of a country_code to block spam from specific zones.
Here is the code of my service :
class GeocodeUserAuthorizer
def initialize(user_country_code:)
@user_country_code = user_country_code
end
def authorize!
user_continent = ISO3166::Country.new(user_country_code).continent
if user_continent == 'Africa'
return true
else
return false
end
end
end
Here is the code of my spec file:
require 'spec_helper'
describe GeocodeUserAuthorizer do
context 'with a user connecting from an authorized country' do
it { expect(GeocodeUserAuthorizer.new.authorize!(user_country_code: { "CA" })).to eql(true) }
end
end
And here is the failure code:
Failures:
1) GeocodeUserAuthorizer with a user connecting from an authorized country Failure/Error: it { expect(GeocodeUserAuthorizer.new.authorize!(user_country_code: { "CA" })).to eql(true) } ArgumentError: missing keyword: user_country_code # ./app/services/geocode_user_authorizer.rb:2:in
initialize' # ./spec/services/geocode_user_authorizer_spec.rb:16:innew' # ./spec/services/geocode_user_authorizer_spec.rb:16:inblock (3 levels) in <top (required)>' # ./spec/spec_helper.rb:56:inblock (3 levels) in ' # ./spec/spec_helper.rb:56:in `block (2 levels) in '
Can anybody help?